15fd54aceSGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0+ 2d6f94504SPeter Korsgaard /* 3d6f94504SPeter Korsgaard * c67x00-ll-hpi.c: Cypress C67X00 USB Low level interface using HPI 4d6f94504SPeter Korsgaard * 5d6f94504SPeter Korsgaard * Copyright (C) 2006-2008 Barco N.V. 6d6f94504SPeter Korsgaard * Derived from the Cypress cy7c67200/300 ezusb linux driver and 7d6f94504SPeter Korsgaard * based on multiple host controller drivers inside the linux kernel. 8d6f94504SPeter Korsgaard */ 9d6f94504SPeter Korsgaard 10d6f94504SPeter Korsgaard #include <asm/byteorder.h> 118f668fbbSMax Filippov #include <linux/delay.h> 12d6f94504SPeter Korsgaard #include <linux/io.h> 139f1a0735SFernando Luis Vázquez Cao #include <linux/jiffies.h> 14d6f94504SPeter Korsgaard #include <linux/usb/c67x00.h> 15d6f94504SPeter Korsgaard #include "c67x00.h" 16d6f94504SPeter Korsgaard 17d6f94504SPeter Korsgaard #define COMM_REGS 14 18d6f94504SPeter Korsgaard 19d6f94504SPeter Korsgaard struct c67x00_lcp_int_data { 20d6f94504SPeter Korsgaard u16 regs[COMM_REGS]; 21d6f94504SPeter Korsgaard }; 22d6f94504SPeter Korsgaard 23d6f94504SPeter Korsgaard /* -------------------------------------------------------------------------- */ 24d6f94504SPeter Korsgaard /* Interface definitions */ 25d6f94504SPeter Korsgaard 26d6f94504SPeter Korsgaard #define COMM_ACK 0x0FED 27d6f94504SPeter Korsgaard #define COMM_NAK 0xDEAD 28d6f94504SPeter Korsgaard 29d6f94504SPeter Korsgaard #define COMM_RESET 0xFA50 30d6f94504SPeter Korsgaard #define COMM_EXEC_INT 0xCE01 31d6f94504SPeter Korsgaard #define COMM_INT_NUM 0x01C2 32d6f94504SPeter Korsgaard 33d6f94504SPeter Korsgaard /* Registers 0 to COMM_REGS-1 */ 34d6f94504SPeter Korsgaard #define COMM_R(x) (0x01C4 + 2 * (x)) 35d6f94504SPeter Korsgaard 36d6f94504SPeter Korsgaard #define HUSB_SIE_pCurrentTDPtr(x) ((x) ? 0x01B2 : 0x01B0) 37d6f94504SPeter Korsgaard #define HUSB_SIE_pTDListDone_Sem(x) ((x) ? 0x01B8 : 0x01B6) 38d6f94504SPeter Korsgaard #define HUSB_pEOT 0x01B4 39d6f94504SPeter Korsgaard 40d6f94504SPeter Korsgaard /* Software interrupts */ 41d6f94504SPeter Korsgaard /* 114, 115: */ 42d6f94504SPeter Korsgaard #define HUSB_SIE_INIT_INT(x) ((x) ? 0x0073 : 0x0072) 43d6f94504SPeter Korsgaard #define HUSB_RESET_INT 0x0074 44d6f94504SPeter Korsgaard 45d6f94504SPeter Korsgaard #define SUSB_INIT_INT 0x0071 46d6f94504SPeter Korsgaard #define SUSB_INIT_INT_LOC (SUSB_INIT_INT * 2) 47d6f94504SPeter Korsgaard 48d6f94504SPeter Korsgaard /* ----------------------------------------------------------------------- 49d6f94504SPeter Korsgaard * HPI implementation 50d6f94504SPeter Korsgaard * 51d6f94504SPeter Korsgaard * The c67x00 chip also support control via SPI or HSS serial 52d6f94504SPeter Korsgaard * interfaces. However, this driver assumes that register access can 53f3c1f515SRahul Bedarkar * be performed from IRQ context. While this is a safe assumption with 54d6f94504SPeter Korsgaard * the HPI interface, it is not true for the serial interfaces. 55d6f94504SPeter Korsgaard */ 56d6f94504SPeter Korsgaard 57d6f94504SPeter Korsgaard /* HPI registers */ 58d6f94504SPeter Korsgaard #define HPI_DATA 0 59d6f94504SPeter Korsgaard #define HPI_MAILBOX 1 60d6f94504SPeter Korsgaard #define HPI_ADDR 2 61d6f94504SPeter Korsgaard #define HPI_STATUS 3 62d6f94504SPeter Korsgaard 638f668fbbSMax Filippov /* 648f668fbbSMax Filippov * According to CY7C67300 specification (tables 140 and 141) HPI read and 658f668fbbSMax Filippov * write cycle duration Tcyc must be at least 6T long, where T is 1/48MHz, 668f668fbbSMax Filippov * which is 125ns. 678f668fbbSMax Filippov */ 688f668fbbSMax Filippov #define HPI_T_CYC_NS 125 698f668fbbSMax Filippov 70d6f94504SPeter Korsgaard static inline u16 hpi_read_reg(struct c67x00_device *dev, int reg) 71d6f94504SPeter Korsgaard { 728f668fbbSMax Filippov ndelay(HPI_T_CYC_NS); 73d6f94504SPeter Korsgaard return __raw_readw(dev->hpi.base + reg * dev->hpi.regstep); 74d6f94504SPeter Korsgaard } 75d6f94504SPeter Korsgaard 76d6f94504SPeter Korsgaard static inline void hpi_write_reg(struct c67x00_device *dev, int reg, u16 value) 77d6f94504SPeter Korsgaard { 788f668fbbSMax Filippov ndelay(HPI_T_CYC_NS); 79d6f94504SPeter Korsgaard __raw_writew(value, dev->hpi.base + reg * dev->hpi.regstep); 80d6f94504SPeter Korsgaard } 81d6f94504SPeter Korsgaard 82d6f94504SPeter Korsgaard static inline u16 hpi_read_word_nolock(struct c67x00_device *dev, u16 reg) 83d6f94504SPeter Korsgaard { 84d6f94504SPeter Korsgaard hpi_write_reg(dev, HPI_ADDR, reg); 85d6f94504SPeter Korsgaard return hpi_read_reg(dev, HPI_DATA); 86d6f94504SPeter Korsgaard } 87d6f94504SPeter Korsgaard 88d6f94504SPeter Korsgaard static u16 hpi_read_word(struct c67x00_device *dev, u16 reg) 89d6f94504SPeter Korsgaard { 90d6f94504SPeter Korsgaard u16 value; 91d6f94504SPeter Korsgaard unsigned long flags; 92d6f94504SPeter Korsgaard 93d6f94504SPeter Korsgaard spin_lock_irqsave(&dev->hpi.lock, flags); 94d6f94504SPeter Korsgaard value = hpi_read_word_nolock(dev, reg); 95d6f94504SPeter Korsgaard spin_unlock_irqrestore(&dev->hpi.lock, flags); 96d6f94504SPeter Korsgaard 97d6f94504SPeter Korsgaard return value; 98d6f94504SPeter Korsgaard } 99d6f94504SPeter Korsgaard 100d6f94504SPeter Korsgaard static void hpi_write_word_nolock(struct c67x00_device *dev, u16 reg, u16 value) 101d6f94504SPeter Korsgaard { 102d6f94504SPeter Korsgaard hpi_write_reg(dev, HPI_ADDR, reg); 103d6f94504SPeter Korsgaard hpi_write_reg(dev, HPI_DATA, value); 104d6f94504SPeter Korsgaard } 105d6f94504SPeter Korsgaard 106d6f94504SPeter Korsgaard static void hpi_write_word(struct c67x00_device *dev, u16 reg, u16 value) 107d6f94504SPeter Korsgaard { 108d6f94504SPeter Korsgaard unsigned long flags; 109d6f94504SPeter Korsgaard 110d6f94504SPeter Korsgaard spin_lock_irqsave(&dev->hpi.lock, flags); 111d6f94504SPeter Korsgaard hpi_write_word_nolock(dev, reg, value); 112d6f94504SPeter Korsgaard spin_unlock_irqrestore(&dev->hpi.lock, flags); 113d6f94504SPeter Korsgaard } 114d6f94504SPeter Korsgaard 115d6f94504SPeter Korsgaard /* 116d6f94504SPeter Korsgaard * Only data is little endian, addr has cpu endianess 117d6f94504SPeter Korsgaard */ 118d6f94504SPeter Korsgaard static void hpi_write_words_le16(struct c67x00_device *dev, u16 addr, 11976e6f252SAl Viro __le16 *data, u16 count) 120d6f94504SPeter Korsgaard { 121d6f94504SPeter Korsgaard unsigned long flags; 122d6f94504SPeter Korsgaard int i; 123d6f94504SPeter Korsgaard 124d6f94504SPeter Korsgaard spin_lock_irqsave(&dev->hpi.lock, flags); 125d6f94504SPeter Korsgaard 126d6f94504SPeter Korsgaard hpi_write_reg(dev, HPI_ADDR, addr); 127d6f94504SPeter Korsgaard for (i = 0; i < count; i++) 12876e6f252SAl Viro hpi_write_reg(dev, HPI_DATA, le16_to_cpu(*data++)); 129d6f94504SPeter Korsgaard 130d6f94504SPeter Korsgaard spin_unlock_irqrestore(&dev->hpi.lock, flags); 131d6f94504SPeter Korsgaard } 132d6f94504SPeter Korsgaard 133d6f94504SPeter Korsgaard /* 134d6f94504SPeter Korsgaard * Only data is little endian, addr has cpu endianess 135d6f94504SPeter Korsgaard */ 136d6f94504SPeter Korsgaard static void hpi_read_words_le16(struct c67x00_device *dev, u16 addr, 13776e6f252SAl Viro __le16 *data, u16 count) 138d6f94504SPeter Korsgaard { 139d6f94504SPeter Korsgaard unsigned long flags; 140d6f94504SPeter Korsgaard int i; 141d6f94504SPeter Korsgaard 142d6f94504SPeter Korsgaard spin_lock_irqsave(&dev->hpi.lock, flags); 143d6f94504SPeter Korsgaard hpi_write_reg(dev, HPI_ADDR, addr); 144d6f94504SPeter Korsgaard for (i = 0; i < count; i++) 14576e6f252SAl Viro *data++ = cpu_to_le16(hpi_read_reg(dev, HPI_DATA)); 146d6f94504SPeter Korsgaard 147d6f94504SPeter Korsgaard spin_unlock_irqrestore(&dev->hpi.lock, flags); 148d6f94504SPeter Korsgaard } 149d6f94504SPeter Korsgaard 150d6f94504SPeter Korsgaard static void hpi_set_bits(struct c67x00_device *dev, u16 reg, u16 mask) 151d6f94504SPeter Korsgaard { 152d6f94504SPeter Korsgaard u16 value; 153d6f94504SPeter Korsgaard unsigned long flags; 154d6f94504SPeter Korsgaard 155d6f94504SPeter Korsgaard spin_lock_irqsave(&dev->hpi.lock, flags); 156d6f94504SPeter Korsgaard value = hpi_read_word_nolock(dev, reg); 157d6f94504SPeter Korsgaard hpi_write_word_nolock(dev, reg, value | mask); 158d6f94504SPeter Korsgaard spin_unlock_irqrestore(&dev->hpi.lock, flags); 159d6f94504SPeter Korsgaard } 160d6f94504SPeter Korsgaard 161d6f94504SPeter Korsgaard static void hpi_clear_bits(struct c67x00_device *dev, u16 reg, u16 mask) 162d6f94504SPeter Korsgaard { 163d6f94504SPeter Korsgaard u16 value; 164d6f94504SPeter Korsgaard unsigned long flags; 165d6f94504SPeter Korsgaard 166d6f94504SPeter Korsgaard spin_lock_irqsave(&dev->hpi.lock, flags); 167d6f94504SPeter Korsgaard value = hpi_read_word_nolock(dev, reg); 168d6f94504SPeter Korsgaard hpi_write_word_nolock(dev, reg, value & ~mask); 169d6f94504SPeter Korsgaard spin_unlock_irqrestore(&dev->hpi.lock, flags); 170d6f94504SPeter Korsgaard } 171d6f94504SPeter Korsgaard 172d6f94504SPeter Korsgaard static u16 hpi_recv_mbox(struct c67x00_device *dev) 173d6f94504SPeter Korsgaard { 174d6f94504SPeter Korsgaard u16 value; 175d6f94504SPeter Korsgaard unsigned long flags; 176d6f94504SPeter Korsgaard 177d6f94504SPeter Korsgaard spin_lock_irqsave(&dev->hpi.lock, flags); 178d6f94504SPeter Korsgaard value = hpi_read_reg(dev, HPI_MAILBOX); 179d6f94504SPeter Korsgaard spin_unlock_irqrestore(&dev->hpi.lock, flags); 180d6f94504SPeter Korsgaard 181d6f94504SPeter Korsgaard return value; 182d6f94504SPeter Korsgaard } 183d6f94504SPeter Korsgaard 184d6f94504SPeter Korsgaard static u16 hpi_send_mbox(struct c67x00_device *dev, u16 value) 185d6f94504SPeter Korsgaard { 186d6f94504SPeter Korsgaard unsigned long flags; 187d6f94504SPeter Korsgaard 188d6f94504SPeter Korsgaard spin_lock_irqsave(&dev->hpi.lock, flags); 189d6f94504SPeter Korsgaard hpi_write_reg(dev, HPI_MAILBOX, value); 190d6f94504SPeter Korsgaard spin_unlock_irqrestore(&dev->hpi.lock, flags); 191d6f94504SPeter Korsgaard 192d6f94504SPeter Korsgaard return value; 193d6f94504SPeter Korsgaard } 194d6f94504SPeter Korsgaard 195d6f94504SPeter Korsgaard u16 c67x00_ll_hpi_status(struct c67x00_device *dev) 196d6f94504SPeter Korsgaard { 197d6f94504SPeter Korsgaard u16 value; 198d6f94504SPeter Korsgaard unsigned long flags; 199d6f94504SPeter Korsgaard 200d6f94504SPeter Korsgaard spin_lock_irqsave(&dev->hpi.lock, flags); 201d6f94504SPeter Korsgaard value = hpi_read_reg(dev, HPI_STATUS); 202d6f94504SPeter Korsgaard spin_unlock_irqrestore(&dev->hpi.lock, flags); 203d6f94504SPeter Korsgaard 204d6f94504SPeter Korsgaard return value; 205d6f94504SPeter Korsgaard } 206d6f94504SPeter Korsgaard 207d6f94504SPeter Korsgaard void c67x00_ll_hpi_reg_init(struct c67x00_device *dev) 208d6f94504SPeter Korsgaard { 209d6f94504SPeter Korsgaard int i; 210d6f94504SPeter Korsgaard 211d6f94504SPeter Korsgaard hpi_recv_mbox(dev); 212d6f94504SPeter Korsgaard c67x00_ll_hpi_status(dev); 213d6f94504SPeter Korsgaard hpi_write_word(dev, HPI_IRQ_ROUTING_REG, 0); 214d6f94504SPeter Korsgaard 215d6f94504SPeter Korsgaard for (i = 0; i < C67X00_SIES; i++) { 216d6f94504SPeter Korsgaard hpi_write_word(dev, SIEMSG_REG(i), 0); 217d6f94504SPeter Korsgaard hpi_read_word(dev, SIEMSG_REG(i)); 218d6f94504SPeter Korsgaard } 219d6f94504SPeter Korsgaard } 220d6f94504SPeter Korsgaard 221d6f94504SPeter Korsgaard void c67x00_ll_hpi_enable_sofeop(struct c67x00_sie *sie) 222d6f94504SPeter Korsgaard { 223d6f94504SPeter Korsgaard hpi_set_bits(sie->dev, HPI_IRQ_ROUTING_REG, 224d6f94504SPeter Korsgaard SOFEOP_TO_HPI_EN(sie->sie_num)); 225d6f94504SPeter Korsgaard } 226d6f94504SPeter Korsgaard 227d6f94504SPeter Korsgaard void c67x00_ll_hpi_disable_sofeop(struct c67x00_sie *sie) 228d6f94504SPeter Korsgaard { 229d6f94504SPeter Korsgaard hpi_clear_bits(sie->dev, HPI_IRQ_ROUTING_REG, 230d6f94504SPeter Korsgaard SOFEOP_TO_HPI_EN(sie->sie_num)); 231d6f94504SPeter Korsgaard } 232d6f94504SPeter Korsgaard 233d6f94504SPeter Korsgaard /* -------------------------------------------------------------------------- */ 234d6f94504SPeter Korsgaard /* Transactions */ 235d6f94504SPeter Korsgaard 236a29c4085SDan Carpenter static inline int ll_recv_msg(struct c67x00_device *dev) 237d6f94504SPeter Korsgaard { 238d6f94504SPeter Korsgaard u16 res; 239d6f94504SPeter Korsgaard 240d6f94504SPeter Korsgaard res = wait_for_completion_timeout(&dev->hpi.lcp.msg_received, 5 * HZ); 241d6f94504SPeter Korsgaard WARN_ON(!res); 242d6f94504SPeter Korsgaard 243d6f94504SPeter Korsgaard return (res == 0) ? -EIO : 0; 244d6f94504SPeter Korsgaard } 245d6f94504SPeter Korsgaard 246d6f94504SPeter Korsgaard /* -------------------------------------------------------------------------- */ 247d6f94504SPeter Korsgaard /* General functions */ 248d6f94504SPeter Korsgaard 249d6f94504SPeter Korsgaard u16 c67x00_ll_fetch_siemsg(struct c67x00_device *dev, int sie_num) 250d6f94504SPeter Korsgaard { 251d6f94504SPeter Korsgaard u16 val; 252d6f94504SPeter Korsgaard 253d6f94504SPeter Korsgaard val = hpi_read_word(dev, SIEMSG_REG(sie_num)); 254d6f94504SPeter Korsgaard /* clear register to allow next message */ 255d6f94504SPeter Korsgaard hpi_write_word(dev, SIEMSG_REG(sie_num), 0); 256d6f94504SPeter Korsgaard 257d6f94504SPeter Korsgaard return val; 258d6f94504SPeter Korsgaard } 259d6f94504SPeter Korsgaard 260d6f94504SPeter Korsgaard u16 c67x00_ll_get_usb_ctl(struct c67x00_sie *sie) 261d6f94504SPeter Korsgaard { 262d6f94504SPeter Korsgaard return hpi_read_word(sie->dev, USB_CTL_REG(sie->sie_num)); 263d6f94504SPeter Korsgaard } 264d6f94504SPeter Korsgaard 265*b5993881SLee Jones /* 266d6f94504SPeter Korsgaard * c67x00_ll_usb_clear_status - clear the USB status bits 267d6f94504SPeter Korsgaard */ 268d6f94504SPeter Korsgaard void c67x00_ll_usb_clear_status(struct c67x00_sie *sie, u16 bits) 269d6f94504SPeter Korsgaard { 270d6f94504SPeter Korsgaard hpi_write_word(sie->dev, USB_STAT_REG(sie->sie_num), bits); 271d6f94504SPeter Korsgaard } 272d6f94504SPeter Korsgaard 273d6f94504SPeter Korsgaard u16 c67x00_ll_usb_get_status(struct c67x00_sie *sie) 274d6f94504SPeter Korsgaard { 275d6f94504SPeter Korsgaard return hpi_read_word(sie->dev, USB_STAT_REG(sie->sie_num)); 276d6f94504SPeter Korsgaard } 277d6f94504SPeter Korsgaard 278d6f94504SPeter Korsgaard /* -------------------------------------------------------------------------- */ 279d6f94504SPeter Korsgaard 280d6f94504SPeter Korsgaard static int c67x00_comm_exec_int(struct c67x00_device *dev, u16 nr, 281d6f94504SPeter Korsgaard struct c67x00_lcp_int_data *data) 282d6f94504SPeter Korsgaard { 283d6f94504SPeter Korsgaard int i, rc; 284d6f94504SPeter Korsgaard 285d6f94504SPeter Korsgaard mutex_lock(&dev->hpi.lcp.mutex); 286d6f94504SPeter Korsgaard hpi_write_word(dev, COMM_INT_NUM, nr); 287d6f94504SPeter Korsgaard for (i = 0; i < COMM_REGS; i++) 288d6f94504SPeter Korsgaard hpi_write_word(dev, COMM_R(i), data->regs[i]); 289d6f94504SPeter Korsgaard hpi_send_mbox(dev, COMM_EXEC_INT); 290d6f94504SPeter Korsgaard rc = ll_recv_msg(dev); 291d6f94504SPeter Korsgaard mutex_unlock(&dev->hpi.lcp.mutex); 292d6f94504SPeter Korsgaard 293d6f94504SPeter Korsgaard return rc; 294d6f94504SPeter Korsgaard } 295d6f94504SPeter Korsgaard 296d6f94504SPeter Korsgaard /* -------------------------------------------------------------------------- */ 297e9b29ffcSPeter Korsgaard /* Host specific functions */ 298e9b29ffcSPeter Korsgaard 299e9b29ffcSPeter Korsgaard void c67x00_ll_set_husb_eot(struct c67x00_device *dev, u16 value) 300e9b29ffcSPeter Korsgaard { 301e9b29ffcSPeter Korsgaard mutex_lock(&dev->hpi.lcp.mutex); 302e9b29ffcSPeter Korsgaard hpi_write_word(dev, HUSB_pEOT, value); 303e9b29ffcSPeter Korsgaard mutex_unlock(&dev->hpi.lcp.mutex); 304e9b29ffcSPeter Korsgaard } 305e9b29ffcSPeter Korsgaard 306e9b29ffcSPeter Korsgaard static inline void c67x00_ll_husb_sie_init(struct c67x00_sie *sie) 307e9b29ffcSPeter Korsgaard { 308e9b29ffcSPeter Korsgaard struct c67x00_device *dev = sie->dev; 309e9b29ffcSPeter Korsgaard struct c67x00_lcp_int_data data; 310e9b29ffcSPeter Korsgaard int rc; 311e9b29ffcSPeter Korsgaard 312e9b29ffcSPeter Korsgaard rc = c67x00_comm_exec_int(dev, HUSB_SIE_INIT_INT(sie->sie_num), &data); 313e9b29ffcSPeter Korsgaard BUG_ON(rc); /* No return path for error code; crash spectacularly */ 314e9b29ffcSPeter Korsgaard } 315e9b29ffcSPeter Korsgaard 316e9b29ffcSPeter Korsgaard void c67x00_ll_husb_reset(struct c67x00_sie *sie, int port) 317e9b29ffcSPeter Korsgaard { 318e9b29ffcSPeter Korsgaard struct c67x00_device *dev = sie->dev; 319e9b29ffcSPeter Korsgaard struct c67x00_lcp_int_data data; 320e9b29ffcSPeter Korsgaard int rc; 321e9b29ffcSPeter Korsgaard 322e9b29ffcSPeter Korsgaard data.regs[0] = 50; /* Reset USB port for 50ms */ 323e9b29ffcSPeter Korsgaard data.regs[1] = port | (sie->sie_num << 1); 324e9b29ffcSPeter Korsgaard rc = c67x00_comm_exec_int(dev, HUSB_RESET_INT, &data); 325e9b29ffcSPeter Korsgaard BUG_ON(rc); /* No return path for error code; crash spectacularly */ 326e9b29ffcSPeter Korsgaard } 327e9b29ffcSPeter Korsgaard 328e9b29ffcSPeter Korsgaard void c67x00_ll_husb_set_current_td(struct c67x00_sie *sie, u16 addr) 329e9b29ffcSPeter Korsgaard { 330e9b29ffcSPeter Korsgaard hpi_write_word(sie->dev, HUSB_SIE_pCurrentTDPtr(sie->sie_num), addr); 331e9b29ffcSPeter Korsgaard } 332e9b29ffcSPeter Korsgaard 333e9b29ffcSPeter Korsgaard u16 c67x00_ll_husb_get_current_td(struct c67x00_sie *sie) 334e9b29ffcSPeter Korsgaard { 335e9b29ffcSPeter Korsgaard return hpi_read_word(sie->dev, HUSB_SIE_pCurrentTDPtr(sie->sie_num)); 336e9b29ffcSPeter Korsgaard } 337e9b29ffcSPeter Korsgaard 338e9b29ffcSPeter Korsgaard u16 c67x00_ll_husb_get_frame(struct c67x00_sie *sie) 339e9b29ffcSPeter Korsgaard { 340e9b29ffcSPeter Korsgaard return hpi_read_word(sie->dev, HOST_FRAME_REG(sie->sie_num)); 341e9b29ffcSPeter Korsgaard } 342e9b29ffcSPeter Korsgaard 343e9b29ffcSPeter Korsgaard void c67x00_ll_husb_init_host_port(struct c67x00_sie *sie) 344e9b29ffcSPeter Korsgaard { 345e9b29ffcSPeter Korsgaard /* Set port into host mode */ 346e9b29ffcSPeter Korsgaard hpi_set_bits(sie->dev, USB_CTL_REG(sie->sie_num), HOST_MODE); 347e9b29ffcSPeter Korsgaard c67x00_ll_husb_sie_init(sie); 348e9b29ffcSPeter Korsgaard /* Clear interrupts */ 349e9b29ffcSPeter Korsgaard c67x00_ll_usb_clear_status(sie, HOST_STAT_MASK); 350e9b29ffcSPeter Korsgaard /* Check */ 351e9b29ffcSPeter Korsgaard if (!(hpi_read_word(sie->dev, USB_CTL_REG(sie->sie_num)) & HOST_MODE)) 352e9b29ffcSPeter Korsgaard dev_warn(sie_dev(sie), 353e9b29ffcSPeter Korsgaard "SIE %d not set to host mode\n", sie->sie_num); 354e9b29ffcSPeter Korsgaard } 355e9b29ffcSPeter Korsgaard 356e9b29ffcSPeter Korsgaard void c67x00_ll_husb_reset_port(struct c67x00_sie *sie, int port) 357e9b29ffcSPeter Korsgaard { 358e9b29ffcSPeter Korsgaard /* Clear connect change */ 359e9b29ffcSPeter Korsgaard c67x00_ll_usb_clear_status(sie, PORT_CONNECT_CHANGE(port)); 360e9b29ffcSPeter Korsgaard 361e9b29ffcSPeter Korsgaard /* Enable interrupts */ 362e9b29ffcSPeter Korsgaard hpi_set_bits(sie->dev, HPI_IRQ_ROUTING_REG, 363e9b29ffcSPeter Korsgaard SOFEOP_TO_CPU_EN(sie->sie_num)); 364e9b29ffcSPeter Korsgaard hpi_set_bits(sie->dev, HOST_IRQ_EN_REG(sie->sie_num), 365e9b29ffcSPeter Korsgaard SOF_EOP_IRQ_EN | DONE_IRQ_EN); 366e9b29ffcSPeter Korsgaard 367e9b29ffcSPeter Korsgaard /* Enable pull down transistors */ 368e9b29ffcSPeter Korsgaard hpi_set_bits(sie->dev, USB_CTL_REG(sie->sie_num), PORT_RES_EN(port)); 369e9b29ffcSPeter Korsgaard } 370e9b29ffcSPeter Korsgaard 371e9b29ffcSPeter Korsgaard /* -------------------------------------------------------------------------- */ 372d6f94504SPeter Korsgaard 373d6f94504SPeter Korsgaard void c67x00_ll_irq(struct c67x00_device *dev, u16 int_status) 374d6f94504SPeter Korsgaard { 375d6f94504SPeter Korsgaard if ((int_status & MBX_OUT_FLG) == 0) 376d6f94504SPeter Korsgaard return; 377d6f94504SPeter Korsgaard 378d6f94504SPeter Korsgaard dev->hpi.lcp.last_msg = hpi_recv_mbox(dev); 379d6f94504SPeter Korsgaard complete(&dev->hpi.lcp.msg_received); 380d6f94504SPeter Korsgaard } 381d6f94504SPeter Korsgaard 382d6f94504SPeter Korsgaard /* -------------------------------------------------------------------------- */ 383d6f94504SPeter Korsgaard 384d6f94504SPeter Korsgaard int c67x00_ll_reset(struct c67x00_device *dev) 385d6f94504SPeter Korsgaard { 386d6f94504SPeter Korsgaard int rc; 387d6f94504SPeter Korsgaard 388d6f94504SPeter Korsgaard mutex_lock(&dev->hpi.lcp.mutex); 389d6f94504SPeter Korsgaard hpi_send_mbox(dev, COMM_RESET); 390d6f94504SPeter Korsgaard rc = ll_recv_msg(dev); 391d6f94504SPeter Korsgaard mutex_unlock(&dev->hpi.lcp.mutex); 392d6f94504SPeter Korsgaard 393d6f94504SPeter Korsgaard return rc; 394d6f94504SPeter Korsgaard } 395d6f94504SPeter Korsgaard 396d6f94504SPeter Korsgaard /* -------------------------------------------------------------------------- */ 397d6f94504SPeter Korsgaard 398*b5993881SLee Jones /* 399d6f94504SPeter Korsgaard * c67x00_ll_write_mem_le16 - write into c67x00 memory 400d6f94504SPeter Korsgaard * Only data is little endian, addr has cpu endianess. 401d6f94504SPeter Korsgaard */ 402d6f94504SPeter Korsgaard void c67x00_ll_write_mem_le16(struct c67x00_device *dev, u16 addr, 403d6f94504SPeter Korsgaard void *data, int len) 404d6f94504SPeter Korsgaard { 405d6f94504SPeter Korsgaard u8 *buf = data; 406d6f94504SPeter Korsgaard 407d6f94504SPeter Korsgaard /* Sanity check */ 408d6f94504SPeter Korsgaard if (addr + len > 0xffff) { 409d6f94504SPeter Korsgaard dev_err(&dev->pdev->dev, 410d6f94504SPeter Korsgaard "Trying to write beyond writable region!\n"); 411d6f94504SPeter Korsgaard return; 412d6f94504SPeter Korsgaard } 413d6f94504SPeter Korsgaard 414d6f94504SPeter Korsgaard if (addr & 0x01) { 415d6f94504SPeter Korsgaard /* unaligned access */ 416d6f94504SPeter Korsgaard u16 tmp; 417d6f94504SPeter Korsgaard tmp = hpi_read_word(dev, addr - 1); 418d6f94504SPeter Korsgaard tmp = (tmp & 0x00ff) | (*buf++ << 8); 419d6f94504SPeter Korsgaard hpi_write_word(dev, addr - 1, tmp); 420d6f94504SPeter Korsgaard addr++; 421d6f94504SPeter Korsgaard len--; 422d6f94504SPeter Korsgaard } 423d6f94504SPeter Korsgaard 42476e6f252SAl Viro hpi_write_words_le16(dev, addr, (__le16 *)buf, len / 2); 425d6f94504SPeter Korsgaard buf += len & ~0x01; 426d6f94504SPeter Korsgaard addr += len & ~0x01; 427d6f94504SPeter Korsgaard len &= 0x01; 428d6f94504SPeter Korsgaard 429d6f94504SPeter Korsgaard if (len) { 430d6f94504SPeter Korsgaard u16 tmp; 431d6f94504SPeter Korsgaard tmp = hpi_read_word(dev, addr); 432d6f94504SPeter Korsgaard tmp = (tmp & 0xff00) | *buf; 433d6f94504SPeter Korsgaard hpi_write_word(dev, addr, tmp); 434d6f94504SPeter Korsgaard } 435d6f94504SPeter Korsgaard } 436d6f94504SPeter Korsgaard 437*b5993881SLee Jones /* 438d6f94504SPeter Korsgaard * c67x00_ll_read_mem_le16 - read from c67x00 memory 439d6f94504SPeter Korsgaard * Only data is little endian, addr has cpu endianess. 440d6f94504SPeter Korsgaard */ 441d6f94504SPeter Korsgaard void c67x00_ll_read_mem_le16(struct c67x00_device *dev, u16 addr, 442d6f94504SPeter Korsgaard void *data, int len) 443d6f94504SPeter Korsgaard { 444d6f94504SPeter Korsgaard u8 *buf = data; 445d6f94504SPeter Korsgaard 446d6f94504SPeter Korsgaard if (addr & 0x01) { 447d6f94504SPeter Korsgaard /* unaligned access */ 448d6f94504SPeter Korsgaard u16 tmp; 449d6f94504SPeter Korsgaard tmp = hpi_read_word(dev, addr - 1); 450d6f94504SPeter Korsgaard *buf++ = (tmp >> 8) & 0x00ff; 451d6f94504SPeter Korsgaard addr++; 452d6f94504SPeter Korsgaard len--; 453d6f94504SPeter Korsgaard } 454d6f94504SPeter Korsgaard 45576e6f252SAl Viro hpi_read_words_le16(dev, addr, (__le16 *)buf, len / 2); 456d6f94504SPeter Korsgaard buf += len & ~0x01; 457d6f94504SPeter Korsgaard addr += len & ~0x01; 458d6f94504SPeter Korsgaard len &= 0x01; 459d6f94504SPeter Korsgaard 460d6f94504SPeter Korsgaard if (len) { 461d6f94504SPeter Korsgaard u16 tmp; 462d6f94504SPeter Korsgaard tmp = hpi_read_word(dev, addr); 463d6f94504SPeter Korsgaard *buf = tmp & 0x00ff; 464d6f94504SPeter Korsgaard } 465d6f94504SPeter Korsgaard } 466d6f94504SPeter Korsgaard 467d6f94504SPeter Korsgaard /* -------------------------------------------------------------------------- */ 468d6f94504SPeter Korsgaard 469d6f94504SPeter Korsgaard void c67x00_ll_init(struct c67x00_device *dev) 470d6f94504SPeter Korsgaard { 471d6f94504SPeter Korsgaard mutex_init(&dev->hpi.lcp.mutex); 472d6f94504SPeter Korsgaard init_completion(&dev->hpi.lcp.msg_received); 473d6f94504SPeter Korsgaard } 474d6f94504SPeter Korsgaard 475d6f94504SPeter Korsgaard void c67x00_ll_release(struct c67x00_device *dev) 476d6f94504SPeter Korsgaard { 477d6f94504SPeter Korsgaard } 478