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