Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * isp1301_omap - ISP 1301 USB transceiver, talking to OMAP OTG controller |
| 3 | * |
| 4 | * Copyright (C) 2004 Texas Instruments |
| 5 | * Copyright (C) 2004 David Brownell |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/kernel.h> |
| 23 | #include <linux/module.h> |
| 24 | #include <linux/init.h> |
| 25 | #include <linux/slab.h> |
| 26 | #include <linux/interrupt.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 27 | #include <linux/platform_device.h> |
David Brownell | d1846b0 | 2008-11-28 15:24:38 +0100 | [diff] [blame] | 28 | #include <linux/gpio.h> |
David Brownell | 5f84813 | 2006-12-16 15:34:53 -0800 | [diff] [blame] | 29 | #include <linux/usb/ch9.h> |
David Brownell | 187426e | 2007-12-12 13:45:25 +0100 | [diff] [blame] | 30 | #include <linux/usb/gadget.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <linux/usb.h> |
David Brownell | 3a16f7b | 2006-06-29 12:27:23 -0700 | [diff] [blame] | 32 | #include <linux/usb/otg.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/i2c.h> |
| 34 | #include <linux/workqueue.h> |
| 35 | |
| 36 | #include <asm/irq.h> |
David Brownell | d1846b0 | 2008-11-28 15:24:38 +0100 | [diff] [blame] | 37 | #include <asm/mach-types.h> |
| 38 | |
Tony Lindgren | 70c494c | 2012-09-19 10:46:56 -0700 | [diff] [blame] | 39 | #include <mach/mux.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Tony Lindgren | b924b20 | 2012-06-04 00:56:15 -0700 | [diff] [blame] | 41 | #include <mach/usb.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
Greg Kroah-Hartman | 523e531 | 2013-06-28 11:32:55 -0700 | [diff] [blame] | 43 | #undef VERBOSE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
| 45 | |
| 46 | #define DRIVER_VERSION "24 August 2004" |
David Brownell | 25da383 | 2007-08-14 18:37:14 +0200 | [diff] [blame] | 47 | #define DRIVER_NAME (isp1301_driver.driver.name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | MODULE_DESCRIPTION("ISP1301 USB OTG Transceiver Driver"); |
| 50 | MODULE_LICENSE("GPL"); |
| 51 | |
| 52 | struct isp1301 { |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 53 | struct usb_phy phy; |
Felipe Balbi | a5f08a3 | 2008-10-14 17:30:02 +0200 | [diff] [blame] | 54 | struct i2c_client *client; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | void (*i2c_release)(struct device *dev); |
| 56 | |
David Brownell | 25da383 | 2007-08-14 18:37:14 +0200 | [diff] [blame] | 57 | int irq_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
| 59 | u32 last_otg_ctrl; |
| 60 | unsigned working:1; |
| 61 | |
| 62 | struct timer_list timer; |
| 63 | |
| 64 | /* use keventd context to change the state for us */ |
| 65 | struct work_struct work; |
David Brownell | 25da383 | 2007-08-14 18:37:14 +0200 | [diff] [blame] | 66 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | unsigned long todo; |
| 68 | # define WORK_UPDATE_ISP 0 /* update ISP from OTG */ |
| 69 | # define WORK_UPDATE_OTG 1 /* update OTG from ISP */ |
| 70 | # define WORK_HOST_RESUME 4 /* resume host */ |
| 71 | # define WORK_TIMER 6 /* timer fired */ |
| 72 | # define WORK_STOP 7 /* don't resubmit */ |
| 73 | }; |
| 74 | |
| 75 | |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 76 | /* bits in OTG_CTRL */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
| 78 | #define OTG_XCEIV_OUTPUTS \ |
| 79 | (OTG_ASESSVLD|OTG_BSESSEND|OTG_BSESSVLD|OTG_VBUSVLD|OTG_ID) |
| 80 | #define OTG_XCEIV_INPUTS \ |
| 81 | (OTG_PULLDOWN|OTG_PULLUP|OTG_DRV_VBUS|OTG_PD_VBUS|OTG_PU_VBUS|OTG_PU_ID) |
| 82 | #define OTG_CTRL_BITS \ |
| 83 | (OTG_A_BUSREQ|OTG_A_SETB_HNPEN|OTG_B_BUSREQ|OTG_B_HNPEN|OTG_BUSDROP) |
| 84 | /* and OTG_PULLUP is sometimes written */ |
| 85 | |
| 86 | #define OTG_CTRL_MASK (OTG_DRIVER_SEL| \ |
| 87 | OTG_XCEIV_OUTPUTS|OTG_XCEIV_INPUTS| \ |
| 88 | OTG_CTRL_BITS) |
| 89 | |
| 90 | |
| 91 | /*-------------------------------------------------------------------------*/ |
| 92 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | /* board-specific PM hooks */ |
| 94 | |
David Brownell | d1846b0 | 2008-11-28 15:24:38 +0100 | [diff] [blame] | 95 | #if defined(CONFIG_MACH_OMAP_H2) || defined(CONFIG_MACH_OMAP_H3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
| 97 | #if defined(CONFIG_TPS65010) || defined(CONFIG_TPS65010_MODULE) |
| 98 | |
David Brownell | 6d16bfb | 2008-01-27 18:14:49 +0100 | [diff] [blame] | 99 | #include <linux/i2c/tps65010.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
| 101 | #else |
| 102 | |
| 103 | static inline int tps65010_set_vbus_draw(unsigned mA) |
| 104 | { |
| 105 | pr_debug("tps65010: draw %d mA (STUB)\n", mA); |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | #endif |
| 110 | |
| 111 | static void enable_vbus_draw(struct isp1301 *isp, unsigned mA) |
| 112 | { |
| 113 | int status = tps65010_set_vbus_draw(mA); |
| 114 | if (status < 0) |
| 115 | pr_debug(" VBUS %d mA error %d\n", mA, status); |
| 116 | } |
| 117 | |
Anand Gadiyar | d77282c | 2009-08-24 20:14:45 +0530 | [diff] [blame] | 118 | #else |
David Brownell | d1846b0 | 2008-11-28 15:24:38 +0100 | [diff] [blame] | 119 | |
| 120 | static void enable_vbus_draw(struct isp1301 *isp, unsigned mA) |
| 121 | { |
| 122 | /* H4 controls this by DIP switch S2.4; no soft control. |
| 123 | * ON means the charger is always enabled. Leave it OFF |
| 124 | * unless the OTG port is used only in B-peripheral mode. |
| 125 | */ |
| 126 | } |
| 127 | |
Anand Gadiyar | d77282c | 2009-08-24 20:14:45 +0530 | [diff] [blame] | 128 | #endif |
| 129 | |
David Brownell | d1846b0 | 2008-11-28 15:24:38 +0100 | [diff] [blame] | 130 | static void enable_vbus_source(struct isp1301 *isp) |
| 131 | { |
| 132 | /* this board won't supply more than 8mA vbus power. |
| 133 | * some boards can switch a 100ma "unit load" (or more). |
| 134 | */ |
| 135 | } |
| 136 | |
| 137 | |
| 138 | /* products will deliver OTG messages with LEDs, GUI, etc */ |
| 139 | static inline void notresponding(struct isp1301 *isp) |
| 140 | { |
| 141 | printk(KERN_NOTICE "OTG device not responding.\n"); |
| 142 | } |
| 143 | |
| 144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | /*-------------------------------------------------------------------------*/ |
| 146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | static struct i2c_driver isp1301_driver; |
| 148 | |
| 149 | /* smbus apis are used for portability */ |
| 150 | |
| 151 | static inline u8 |
| 152 | isp1301_get_u8(struct isp1301 *isp, u8 reg) |
| 153 | { |
Felipe Balbi | a5f08a3 | 2008-10-14 17:30:02 +0200 | [diff] [blame] | 154 | return i2c_smbus_read_byte_data(isp->client, reg + 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | static inline int |
| 158 | isp1301_get_u16(struct isp1301 *isp, u8 reg) |
| 159 | { |
Felipe Balbi | a5f08a3 | 2008-10-14 17:30:02 +0200 | [diff] [blame] | 160 | return i2c_smbus_read_word_data(isp->client, reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | static inline int |
| 164 | isp1301_set_bits(struct isp1301 *isp, u8 reg, u8 bits) |
| 165 | { |
Felipe Balbi | a5f08a3 | 2008-10-14 17:30:02 +0200 | [diff] [blame] | 166 | return i2c_smbus_write_byte_data(isp->client, reg + 0, bits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | static inline int |
| 170 | isp1301_clear_bits(struct isp1301 *isp, u8 reg, u8 bits) |
| 171 | { |
Felipe Balbi | a5f08a3 | 2008-10-14 17:30:02 +0200 | [diff] [blame] | 172 | return i2c_smbus_write_byte_data(isp->client, reg + 1, bits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | /*-------------------------------------------------------------------------*/ |
| 176 | |
| 177 | /* identification */ |
| 178 | #define ISP1301_VENDOR_ID 0x00 /* u16 read */ |
| 179 | #define ISP1301_PRODUCT_ID 0x02 /* u16 read */ |
| 180 | #define ISP1301_BCD_DEVICE 0x14 /* u16 read */ |
| 181 | |
| 182 | #define I2C_VENDOR_ID_PHILIPS 0x04cc |
| 183 | #define I2C_PRODUCT_ID_PHILIPS_1301 0x1301 |
| 184 | |
| 185 | /* operational registers */ |
| 186 | #define ISP1301_MODE_CONTROL_1 0x04 /* u8 read, set, +1 clear */ |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 187 | # define MC1_SPEED (1 << 0) |
| 188 | # define MC1_SUSPEND (1 << 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | # define MC1_DAT_SE0 (1 << 2) |
| 190 | # define MC1_TRANSPARENT (1 << 3) |
| 191 | # define MC1_BDIS_ACON_EN (1 << 4) |
| 192 | # define MC1_OE_INT_EN (1 << 5) |
| 193 | # define MC1_UART_EN (1 << 6) |
| 194 | # define MC1_MASK 0x7f |
| 195 | #define ISP1301_MODE_CONTROL_2 0x12 /* u8 read, set, +1 clear */ |
| 196 | # define MC2_GLOBAL_PWR_DN (1 << 0) |
| 197 | # define MC2_SPD_SUSP_CTRL (1 << 1) |
| 198 | # define MC2_BI_DI (1 << 2) |
| 199 | # define MC2_TRANSP_BDIR0 (1 << 3) |
| 200 | # define MC2_TRANSP_BDIR1 (1 << 4) |
| 201 | # define MC2_AUDIO_EN (1 << 5) |
| 202 | # define MC2_PSW_EN (1 << 6) |
| 203 | # define MC2_EN2V7 (1 << 7) |
| 204 | #define ISP1301_OTG_CONTROL_1 0x06 /* u8 read, set, +1 clear */ |
| 205 | # define OTG1_DP_PULLUP (1 << 0) |
| 206 | # define OTG1_DM_PULLUP (1 << 1) |
| 207 | # define OTG1_DP_PULLDOWN (1 << 2) |
| 208 | # define OTG1_DM_PULLDOWN (1 << 3) |
| 209 | # define OTG1_ID_PULLDOWN (1 << 4) |
| 210 | # define OTG1_VBUS_DRV (1 << 5) |
| 211 | # define OTG1_VBUS_DISCHRG (1 << 6) |
| 212 | # define OTG1_VBUS_CHRG (1 << 7) |
| 213 | #define ISP1301_OTG_STATUS 0x10 /* u8 readonly */ |
| 214 | # define OTG_B_SESS_END (1 << 6) |
| 215 | # define OTG_B_SESS_VLD (1 << 7) |
| 216 | |
| 217 | #define ISP1301_INTERRUPT_SOURCE 0x08 /* u8 read */ |
| 218 | #define ISP1301_INTERRUPT_LATCH 0x0A /* u8 read, set, +1 clear */ |
| 219 | |
| 220 | #define ISP1301_INTERRUPT_FALLING 0x0C /* u8 read, set, +1 clear */ |
| 221 | #define ISP1301_INTERRUPT_RISING 0x0E /* u8 read, set, +1 clear */ |
| 222 | |
| 223 | /* same bitfields in all interrupt registers */ |
| 224 | # define INTR_VBUS_VLD (1 << 0) |
| 225 | # define INTR_SESS_VLD (1 << 1) |
| 226 | # define INTR_DP_HI (1 << 2) |
| 227 | # define INTR_ID_GND (1 << 3) |
| 228 | # define INTR_DM_HI (1 << 4) |
| 229 | # define INTR_ID_FLOAT (1 << 5) |
| 230 | # define INTR_BDIS_ACON (1 << 6) |
| 231 | # define INTR_CR_INT (1 << 7) |
| 232 | |
| 233 | /*-------------------------------------------------------------------------*/ |
| 234 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | static inline const char *state_name(struct isp1301 *isp) |
| 236 | { |
Felipe Balbi | 42c0bf1 | 2013-03-07 10:39:57 +0200 | [diff] [blame] | 237 | return usb_otg_state_string(isp->phy.state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | } |
| 239 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | /*-------------------------------------------------------------------------*/ |
| 241 | |
| 242 | /* NOTE: some of this ISP1301 setup is specific to H2 boards; |
| 243 | * not everything is guarded by board-specific checks, or even using |
| 244 | * omap_usb_config data to deduce MC1_DAT_SE0 and MC2_BI_DI. |
| 245 | * |
| 246 | * ALSO: this currently doesn't use ISP1301 low-power modes |
| 247 | * while OTG is running. |
| 248 | */ |
| 249 | |
| 250 | static void power_down(struct isp1301 *isp) |
| 251 | { |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 252 | isp->phy.state = OTG_STATE_UNDEFINED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | |
| 254 | // isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2, MC2_GLOBAL_PWR_DN); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 255 | isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_SUSPEND); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | |
| 257 | isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_ID_PULLDOWN); |
| 258 | isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0); |
| 259 | } |
| 260 | |
| 261 | static void power_up(struct isp1301 *isp) |
| 262 | { |
| 263 | // isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_2, MC2_GLOBAL_PWR_DN); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 264 | isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, MC1_SUSPEND); |
David Brownell | 25da383 | 2007-08-14 18:37:14 +0200 | [diff] [blame] | 265 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | /* do this only when cpu is driving transceiver, |
| 267 | * so host won't see a low speed device... |
| 268 | */ |
| 269 | isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0); |
| 270 | } |
| 271 | |
| 272 | #define NO_HOST_SUSPEND |
| 273 | |
| 274 | static int host_suspend(struct isp1301 *isp) |
| 275 | { |
| 276 | #ifdef NO_HOST_SUSPEND |
| 277 | return 0; |
| 278 | #else |
| 279 | struct device *dev; |
| 280 | |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 281 | if (!isp->phy.otg->host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | return -ENODEV; |
| 283 | |
| 284 | /* Currently ASSUMES only the OTG port matters; |
| 285 | * other ports could be active... |
| 286 | */ |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 287 | dev = isp->phy.otg->host->controller; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | return dev->driver->suspend(dev, 3, 0); |
| 289 | #endif |
| 290 | } |
| 291 | |
| 292 | static int host_resume(struct isp1301 *isp) |
| 293 | { |
| 294 | #ifdef NO_HOST_SUSPEND |
| 295 | return 0; |
| 296 | #else |
| 297 | struct device *dev; |
| 298 | |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 299 | if (!isp->phy.otg->host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | return -ENODEV; |
| 301 | |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 302 | dev = isp->phy.otg->host->controller; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | return dev->driver->resume(dev, 0); |
| 304 | #endif |
| 305 | } |
| 306 | |
| 307 | static int gadget_suspend(struct isp1301 *isp) |
| 308 | { |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 309 | isp->phy.otg->gadget->b_hnp_enable = 0; |
| 310 | isp->phy.otg->gadget->a_hnp_support = 0; |
| 311 | isp->phy.otg->gadget->a_alt_hnp_support = 0; |
| 312 | return usb_gadget_vbus_disconnect(isp->phy.otg->gadget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | /*-------------------------------------------------------------------------*/ |
| 316 | |
| 317 | #define TIMER_MINUTES 10 |
| 318 | #define TIMER_JIFFIES (TIMER_MINUTES * 60 * HZ) |
| 319 | |
| 320 | /* Almost all our I2C messaging comes from a work queue's task context. |
| 321 | * NOTE: guaranteeing certain response times might mean we shouldn't |
| 322 | * share keventd's work queue; a realtime task might be safest. |
| 323 | */ |
David Brownell | d1846b0 | 2008-11-28 15:24:38 +0100 | [diff] [blame] | 324 | static void isp1301_defer_work(struct isp1301 *isp, int work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | { |
| 326 | int status; |
| 327 | |
| 328 | if (isp && !test_and_set_bit(work, &isp->todo)) { |
Felipe Balbi | a5f08a3 | 2008-10-14 17:30:02 +0200 | [diff] [blame] | 329 | (void) get_device(&isp->client->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | status = schedule_work(&isp->work); |
| 331 | if (!status && !isp->working) |
Felipe Balbi | a5f08a3 | 2008-10-14 17:30:02 +0200 | [diff] [blame] | 332 | dev_vdbg(&isp->client->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | "work item %d may be lost\n", work); |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | /* called from irq handlers */ |
| 338 | static void a_idle(struct isp1301 *isp, const char *tag) |
| 339 | { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 340 | u32 l; |
| 341 | |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 342 | if (isp->phy.state == OTG_STATE_A_IDLE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | return; |
| 344 | |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 345 | isp->phy.otg->default_a = 1; |
| 346 | if (isp->phy.otg->host) { |
| 347 | isp->phy.otg->host->is_b_host = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | host_suspend(isp); |
| 349 | } |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 350 | if (isp->phy.otg->gadget) { |
| 351 | isp->phy.otg->gadget->is_a_peripheral = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | gadget_suspend(isp); |
| 353 | } |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 354 | isp->phy.state = OTG_STATE_A_IDLE; |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 355 | l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS; |
| 356 | omap_writel(l, OTG_CTRL); |
| 357 | isp->last_otg_ctrl = l; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | pr_debug(" --> %s/%s\n", state_name(isp), tag); |
| 359 | } |
| 360 | |
| 361 | /* called from irq handlers */ |
| 362 | static void b_idle(struct isp1301 *isp, const char *tag) |
| 363 | { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 364 | u32 l; |
| 365 | |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 366 | if (isp->phy.state == OTG_STATE_B_IDLE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | return; |
| 368 | |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 369 | isp->phy.otg->default_a = 0; |
| 370 | if (isp->phy.otg->host) { |
| 371 | isp->phy.otg->host->is_b_host = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | host_suspend(isp); |
| 373 | } |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 374 | if (isp->phy.otg->gadget) { |
| 375 | isp->phy.otg->gadget->is_a_peripheral = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | gadget_suspend(isp); |
| 377 | } |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 378 | isp->phy.state = OTG_STATE_B_IDLE; |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 379 | l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS; |
| 380 | omap_writel(l, OTG_CTRL); |
| 381 | isp->last_otg_ctrl = l; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | pr_debug(" --> %s/%s\n", state_name(isp), tag); |
| 383 | } |
| 384 | |
| 385 | static void |
| 386 | dump_regs(struct isp1301 *isp, const char *label) |
| 387 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | u8 ctrl = isp1301_get_u8(isp, ISP1301_OTG_CONTROL_1); |
| 389 | u8 status = isp1301_get_u8(isp, ISP1301_OTG_STATUS); |
| 390 | u8 src = isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE); |
| 391 | |
| 392 | pr_debug("otg: %06x, %s %s, otg/%02x stat/%02x.%02x\n", |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 393 | omap_readl(OTG_CTRL), label, state_name(isp), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | ctrl, status, src); |
| 395 | /* mode control and irq enables don't change much */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | /*-------------------------------------------------------------------------*/ |
| 399 | |
| 400 | #ifdef CONFIG_USB_OTG |
| 401 | |
| 402 | /* |
| 403 | * The OMAP OTG controller handles most of the OTG state transitions. |
| 404 | * |
| 405 | * We translate isp1301 outputs (mostly voltage comparator status) into |
| 406 | * OTG inputs; OTG outputs (mostly pullup/pulldown controls) and HNP state |
| 407 | * flags into isp1301 inputs ... and infer state transitions. |
| 408 | */ |
| 409 | |
| 410 | #ifdef VERBOSE |
| 411 | |
| 412 | static void check_state(struct isp1301 *isp, const char *tag) |
| 413 | { |
| 414 | enum usb_otg_state state = OTG_STATE_UNDEFINED; |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 415 | u8 fsm = omap_readw(OTG_TEST) & 0x0ff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | unsigned extra = 0; |
| 417 | |
| 418 | switch (fsm) { |
| 419 | |
| 420 | /* default-b */ |
| 421 | case 0x0: |
| 422 | state = OTG_STATE_B_IDLE; |
| 423 | break; |
| 424 | case 0x3: |
| 425 | case 0x7: |
| 426 | extra = 1; |
| 427 | case 0x1: |
| 428 | state = OTG_STATE_B_PERIPHERAL; |
| 429 | break; |
| 430 | case 0x11: |
| 431 | state = OTG_STATE_B_SRP_INIT; |
| 432 | break; |
| 433 | |
| 434 | /* extra dual-role default-b states */ |
| 435 | case 0x12: |
| 436 | case 0x13: |
| 437 | case 0x16: |
| 438 | extra = 1; |
| 439 | case 0x17: |
| 440 | state = OTG_STATE_B_WAIT_ACON; |
| 441 | break; |
| 442 | case 0x34: |
| 443 | state = OTG_STATE_B_HOST; |
| 444 | break; |
| 445 | |
| 446 | /* default-a */ |
| 447 | case 0x36: |
| 448 | state = OTG_STATE_A_IDLE; |
| 449 | break; |
| 450 | case 0x3c: |
| 451 | state = OTG_STATE_A_WAIT_VFALL; |
| 452 | break; |
| 453 | case 0x7d: |
| 454 | state = OTG_STATE_A_VBUS_ERR; |
| 455 | break; |
| 456 | case 0x9e: |
| 457 | case 0x9f: |
| 458 | extra = 1; |
| 459 | case 0x89: |
| 460 | state = OTG_STATE_A_PERIPHERAL; |
| 461 | break; |
| 462 | case 0xb7: |
| 463 | state = OTG_STATE_A_WAIT_VRISE; |
| 464 | break; |
| 465 | case 0xb8: |
| 466 | state = OTG_STATE_A_WAIT_BCON; |
| 467 | break; |
| 468 | case 0xb9: |
| 469 | state = OTG_STATE_A_HOST; |
| 470 | break; |
| 471 | case 0xba: |
| 472 | state = OTG_STATE_A_SUSPEND; |
| 473 | break; |
| 474 | default: |
| 475 | break; |
| 476 | } |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 477 | if (isp->phy.state == state && !extra) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | return; |
| 479 | pr_debug("otg: %s FSM %s/%02x, %s, %06x\n", tag, |
Felipe Balbi | 42c0bf1 | 2013-03-07 10:39:57 +0200 | [diff] [blame] | 480 | usb_otg_state_string(state), fsm, state_name(isp), |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 481 | omap_readl(OTG_CTRL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | #else |
| 485 | |
| 486 | static inline void check_state(struct isp1301 *isp, const char *tag) { } |
| 487 | |
| 488 | #endif |
| 489 | |
| 490 | /* outputs from ISP1301_INTERRUPT_SOURCE */ |
| 491 | static void update_otg1(struct isp1301 *isp, u8 int_src) |
| 492 | { |
| 493 | u32 otg_ctrl; |
| 494 | |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 495 | otg_ctrl = omap_readl(OTG_CTRL) & OTG_CTRL_MASK; |
| 496 | otg_ctrl &= ~OTG_XCEIV_INPUTS; |
| 497 | otg_ctrl &= ~(OTG_ID|OTG_ASESSVLD|OTG_VBUSVLD); |
| 498 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | if (int_src & INTR_SESS_VLD) |
| 500 | otg_ctrl |= OTG_ASESSVLD; |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 501 | else if (isp->phy.state == OTG_STATE_A_WAIT_VFALL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | a_idle(isp, "vfall"); |
| 503 | otg_ctrl &= ~OTG_CTRL_BITS; |
| 504 | } |
| 505 | if (int_src & INTR_VBUS_VLD) |
| 506 | otg_ctrl |= OTG_VBUSVLD; |
| 507 | if (int_src & INTR_ID_GND) { /* default-A */ |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 508 | if (isp->phy.state == OTG_STATE_B_IDLE |
| 509 | || isp->phy.state |
| 510 | == OTG_STATE_UNDEFINED) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | a_idle(isp, "init"); |
| 512 | return; |
| 513 | } |
| 514 | } else { /* default-B */ |
| 515 | otg_ctrl |= OTG_ID; |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 516 | if (isp->phy.state == OTG_STATE_A_IDLE |
| 517 | || isp->phy.state == OTG_STATE_UNDEFINED) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | b_idle(isp, "init"); |
| 519 | return; |
| 520 | } |
| 521 | } |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 522 | omap_writel(otg_ctrl, OTG_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | /* outputs from ISP1301_OTG_STATUS */ |
| 526 | static void update_otg2(struct isp1301 *isp, u8 otg_status) |
| 527 | { |
| 528 | u32 otg_ctrl; |
| 529 | |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 530 | otg_ctrl = omap_readl(OTG_CTRL) & OTG_CTRL_MASK; |
| 531 | otg_ctrl &= ~OTG_XCEIV_INPUTS; |
| 532 | otg_ctrl &= ~(OTG_BSESSVLD | OTG_BSESSEND); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | if (otg_status & OTG_B_SESS_VLD) |
| 534 | otg_ctrl |= OTG_BSESSVLD; |
| 535 | else if (otg_status & OTG_B_SESS_END) |
| 536 | otg_ctrl |= OTG_BSESSEND; |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 537 | omap_writel(otg_ctrl, OTG_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | /* inputs going to ISP1301 */ |
| 541 | static void otg_update_isp(struct isp1301 *isp) |
| 542 | { |
| 543 | u32 otg_ctrl, otg_change; |
| 544 | u8 set = OTG1_DM_PULLDOWN, clr = OTG1_DM_PULLUP; |
| 545 | |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 546 | otg_ctrl = omap_readl(OTG_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | otg_change = otg_ctrl ^ isp->last_otg_ctrl; |
| 548 | isp->last_otg_ctrl = otg_ctrl; |
| 549 | otg_ctrl = otg_ctrl & OTG_XCEIV_INPUTS; |
| 550 | |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 551 | switch (isp->phy.state) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | case OTG_STATE_B_IDLE: |
| 553 | case OTG_STATE_B_PERIPHERAL: |
| 554 | case OTG_STATE_B_SRP_INIT: |
| 555 | if (!(otg_ctrl & OTG_PULLUP)) { |
| 556 | // if (otg_ctrl & OTG_B_HNPEN) { |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 557 | if (isp->phy.otg->gadget->b_hnp_enable) { |
| 558 | isp->phy.state = OTG_STATE_B_WAIT_ACON; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | pr_debug(" --> b_wait_acon\n"); |
| 560 | } |
| 561 | goto pulldown; |
| 562 | } |
| 563 | pullup: |
| 564 | set |= OTG1_DP_PULLUP; |
| 565 | clr |= OTG1_DP_PULLDOWN; |
| 566 | break; |
| 567 | case OTG_STATE_A_SUSPEND: |
| 568 | case OTG_STATE_A_PERIPHERAL: |
| 569 | if (otg_ctrl & OTG_PULLUP) |
| 570 | goto pullup; |
| 571 | /* FALLTHROUGH */ |
| 572 | // case OTG_STATE_B_WAIT_ACON: |
| 573 | default: |
| 574 | pulldown: |
| 575 | set |= OTG1_DP_PULLDOWN; |
| 576 | clr |= OTG1_DP_PULLUP; |
| 577 | break; |
| 578 | } |
| 579 | |
| 580 | # define toggle(OTG,ISP) do { \ |
| 581 | if (otg_ctrl & OTG) set |= ISP; \ |
| 582 | else clr |= ISP; \ |
| 583 | } while (0) |
| 584 | |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 585 | if (!(isp->phy.otg->host)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | otg_ctrl &= ~OTG_DRV_VBUS; |
| 587 | |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 588 | switch (isp->phy.state) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | case OTG_STATE_A_SUSPEND: |
| 590 | if (otg_ctrl & OTG_DRV_VBUS) { |
| 591 | set |= OTG1_VBUS_DRV; |
| 592 | break; |
| 593 | } |
| 594 | /* HNP failed for some reason (A_AIDL_BDIS timeout) */ |
| 595 | notresponding(isp); |
| 596 | |
| 597 | /* FALLTHROUGH */ |
| 598 | case OTG_STATE_A_VBUS_ERR: |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 599 | isp->phy.state = OTG_STATE_A_WAIT_VFALL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | pr_debug(" --> a_wait_vfall\n"); |
| 601 | /* FALLTHROUGH */ |
| 602 | case OTG_STATE_A_WAIT_VFALL: |
| 603 | /* FIXME usbcore thinks port power is still on ... */ |
| 604 | clr |= OTG1_VBUS_DRV; |
| 605 | break; |
| 606 | case OTG_STATE_A_IDLE: |
| 607 | if (otg_ctrl & OTG_DRV_VBUS) { |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 608 | isp->phy.state = OTG_STATE_A_WAIT_VRISE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | pr_debug(" --> a_wait_vrise\n"); |
| 610 | } |
| 611 | /* FALLTHROUGH */ |
| 612 | default: |
| 613 | toggle(OTG_DRV_VBUS, OTG1_VBUS_DRV); |
| 614 | } |
| 615 | |
| 616 | toggle(OTG_PU_VBUS, OTG1_VBUS_CHRG); |
| 617 | toggle(OTG_PD_VBUS, OTG1_VBUS_DISCHRG); |
| 618 | |
| 619 | # undef toggle |
| 620 | |
| 621 | isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, set); |
| 622 | isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, clr); |
| 623 | |
| 624 | /* HNP switch to host or peripheral; and SRP */ |
| 625 | if (otg_change & OTG_PULLUP) { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 626 | u32 l; |
| 627 | |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 628 | switch (isp->phy.state) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | case OTG_STATE_B_IDLE: |
| 630 | if (clr & OTG1_DP_PULLUP) |
| 631 | break; |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 632 | isp->phy.state = OTG_STATE_B_PERIPHERAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | pr_debug(" --> b_peripheral\n"); |
| 634 | break; |
| 635 | case OTG_STATE_A_SUSPEND: |
| 636 | if (clr & OTG1_DP_PULLUP) |
| 637 | break; |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 638 | isp->phy.state = OTG_STATE_A_PERIPHERAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | pr_debug(" --> a_peripheral\n"); |
| 640 | break; |
| 641 | default: |
| 642 | break; |
| 643 | } |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 644 | l = omap_readl(OTG_CTRL); |
| 645 | l |= OTG_PULLUP; |
| 646 | omap_writel(l, OTG_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | } |
| 648 | |
Harvey Harrison | 08882d2 | 2008-04-22 22:16:47 +0200 | [diff] [blame] | 649 | check_state(isp, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | dump_regs(isp, "otg->isp1301"); |
| 651 | } |
| 652 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 653 | static irqreturn_t omap_otg_irq(int irq, void *_isp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 655 | u16 otg_irq = omap_readw(OTG_IRQ_SRC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | u32 otg_ctrl; |
| 657 | int ret = IRQ_NONE; |
| 658 | struct isp1301 *isp = _isp; |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 659 | struct usb_otg *otg = isp->phy.otg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | |
Joe Perches | 7c9d440 | 2011-06-23 11:39:20 -0700 | [diff] [blame] | 661 | /* update ISP1301 transceiver from OTG controller */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | if (otg_irq & OPRT_CHG) { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 663 | omap_writew(OPRT_CHG, OTG_IRQ_SRC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | isp1301_defer_work(isp, WORK_UPDATE_ISP); |
| 665 | ret = IRQ_HANDLED; |
| 666 | |
| 667 | /* SRP to become b_peripheral failed */ |
| 668 | } else if (otg_irq & B_SRP_TMROUT) { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 669 | pr_debug("otg: B_SRP_TIMEOUT, %06x\n", omap_readl(OTG_CTRL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | notresponding(isp); |
| 671 | |
| 672 | /* gadget drivers that care should monitor all kinds of |
| 673 | * remote wakeup (SRP, normal) using their own timer |
| 674 | * to give "check cable and A-device" messages. |
| 675 | */ |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 676 | if (isp->phy.state == OTG_STATE_B_SRP_INIT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | b_idle(isp, "srp_timeout"); |
| 678 | |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 679 | omap_writew(B_SRP_TMROUT, OTG_IRQ_SRC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | ret = IRQ_HANDLED; |
| 681 | |
| 682 | /* HNP to become b_host failed */ |
| 683 | } else if (otg_irq & B_HNP_FAIL) { |
| 684 | pr_debug("otg: %s B_HNP_FAIL, %06x\n", |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 685 | state_name(isp), omap_readl(OTG_CTRL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | notresponding(isp); |
| 687 | |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 688 | otg_ctrl = omap_readl(OTG_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | otg_ctrl |= OTG_BUSDROP; |
| 690 | otg_ctrl &= OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS; |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 691 | omap_writel(otg_ctrl, OTG_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | |
| 693 | /* subset of b_peripheral()... */ |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 694 | isp->phy.state = OTG_STATE_B_PERIPHERAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | pr_debug(" --> b_peripheral\n"); |
| 696 | |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 697 | omap_writew(B_HNP_FAIL, OTG_IRQ_SRC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | ret = IRQ_HANDLED; |
| 699 | |
| 700 | /* detect SRP from B-device ... */ |
| 701 | } else if (otg_irq & A_SRP_DETECT) { |
| 702 | pr_debug("otg: %s SRP_DETECT, %06x\n", |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 703 | state_name(isp), omap_readl(OTG_CTRL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | |
| 705 | isp1301_defer_work(isp, WORK_UPDATE_OTG); |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 706 | switch (isp->phy.state) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | case OTG_STATE_A_IDLE: |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 708 | if (!otg->host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | break; |
| 710 | isp1301_defer_work(isp, WORK_HOST_RESUME); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 711 | otg_ctrl = omap_readl(OTG_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | otg_ctrl |= OTG_A_BUSREQ; |
| 713 | otg_ctrl &= ~(OTG_BUSDROP|OTG_B_BUSREQ) |
| 714 | & ~OTG_XCEIV_INPUTS |
| 715 | & OTG_CTRL_MASK; |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 716 | omap_writel(otg_ctrl, OTG_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | break; |
| 718 | default: |
| 719 | break; |
| 720 | } |
| 721 | |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 722 | omap_writew(A_SRP_DETECT, OTG_IRQ_SRC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | ret = IRQ_HANDLED; |
| 724 | |
| 725 | /* timer expired: T(a_wait_bcon) and maybe T(a_wait_vrise) |
| 726 | * we don't track them separately |
| 727 | */ |
| 728 | } else if (otg_irq & A_REQ_TMROUT) { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 729 | otg_ctrl = omap_readl(OTG_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | pr_info("otg: BCON_TMOUT from %s, %06x\n", |
| 731 | state_name(isp), otg_ctrl); |
| 732 | notresponding(isp); |
| 733 | |
| 734 | otg_ctrl |= OTG_BUSDROP; |
| 735 | otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS; |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 736 | omap_writel(otg_ctrl, OTG_CTRL); |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 737 | isp->phy.state = OTG_STATE_A_WAIT_VFALL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 739 | omap_writew(A_REQ_TMROUT, OTG_IRQ_SRC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | ret = IRQ_HANDLED; |
| 741 | |
| 742 | /* A-supplied voltage fell too low; overcurrent */ |
| 743 | } else if (otg_irq & A_VBUS_ERR) { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 744 | otg_ctrl = omap_readl(OTG_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | printk(KERN_ERR "otg: %s, VBUS_ERR %04x ctrl %06x\n", |
| 746 | state_name(isp), otg_irq, otg_ctrl); |
| 747 | |
| 748 | otg_ctrl |= OTG_BUSDROP; |
| 749 | otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS; |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 750 | omap_writel(otg_ctrl, OTG_CTRL); |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 751 | isp->phy.state = OTG_STATE_A_VBUS_ERR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 753 | omap_writew(A_VBUS_ERR, OTG_IRQ_SRC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | ret = IRQ_HANDLED; |
| 755 | |
Joe Perches | 7c9d440 | 2011-06-23 11:39:20 -0700 | [diff] [blame] | 756 | /* switch driver; the transceiver code activates it, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | * ungating the udc clock or resuming OHCI. |
| 758 | */ |
| 759 | } else if (otg_irq & DRIVER_SWITCH) { |
| 760 | int kick = 0; |
| 761 | |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 762 | otg_ctrl = omap_readl(OTG_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | printk(KERN_NOTICE "otg: %s, SWITCH to %s, ctrl %06x\n", |
| 764 | state_name(isp), |
| 765 | (otg_ctrl & OTG_DRIVER_SEL) |
| 766 | ? "gadget" : "host", |
| 767 | otg_ctrl); |
| 768 | isp1301_defer_work(isp, WORK_UPDATE_ISP); |
| 769 | |
| 770 | /* role is peripheral */ |
| 771 | if (otg_ctrl & OTG_DRIVER_SEL) { |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 772 | switch (isp->phy.state) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | case OTG_STATE_A_IDLE: |
Harvey Harrison | 08882d2 | 2008-04-22 22:16:47 +0200 | [diff] [blame] | 774 | b_idle(isp, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | break; |
| 776 | default: |
| 777 | break; |
| 778 | } |
| 779 | isp1301_defer_work(isp, WORK_UPDATE_ISP); |
| 780 | |
| 781 | /* role is host */ |
| 782 | } else { |
| 783 | if (!(otg_ctrl & OTG_ID)) { |
David Brownell | 25da383 | 2007-08-14 18:37:14 +0200 | [diff] [blame] | 784 | otg_ctrl &= OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS; |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 785 | omap_writel(otg_ctrl | OTG_A_BUSREQ, OTG_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | } |
| 787 | |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 788 | if (otg->host) { |
| 789 | switch (isp->phy.state) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | case OTG_STATE_B_WAIT_ACON: |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 791 | isp->phy.state = OTG_STATE_B_HOST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | pr_debug(" --> b_host\n"); |
| 793 | kick = 1; |
| 794 | break; |
| 795 | case OTG_STATE_A_WAIT_BCON: |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 796 | isp->phy.state = OTG_STATE_A_HOST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | pr_debug(" --> a_host\n"); |
| 798 | break; |
| 799 | case OTG_STATE_A_PERIPHERAL: |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 800 | isp->phy.state = OTG_STATE_A_WAIT_BCON; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | pr_debug(" --> a_wait_bcon\n"); |
| 802 | break; |
| 803 | default: |
| 804 | break; |
| 805 | } |
| 806 | isp1301_defer_work(isp, WORK_HOST_RESUME); |
| 807 | } |
| 808 | } |
| 809 | |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 810 | omap_writew(DRIVER_SWITCH, OTG_IRQ_SRC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | ret = IRQ_HANDLED; |
| 812 | |
| 813 | if (kick) |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 814 | usb_bus_start_enum(otg->host, otg->host->otg_port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | } |
| 816 | |
Harvey Harrison | 08882d2 | 2008-04-22 22:16:47 +0200 | [diff] [blame] | 817 | check_state(isp, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | return ret; |
| 819 | } |
| 820 | |
| 821 | static struct platform_device *otg_dev; |
| 822 | |
Felipe Balbi | 465f829 | 2009-12-15 23:19:52 +0200 | [diff] [blame] | 823 | static int isp1301_otg_init(struct isp1301 *isp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 825 | u32 l; |
| 826 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | if (!otg_dev) |
| 828 | return -ENODEV; |
| 829 | |
Harvey Harrison | 08882d2 | 2008-04-22 22:16:47 +0200 | [diff] [blame] | 830 | dump_regs(isp, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | /* some of these values are board-specific... */ |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 832 | l = omap_readl(OTG_SYSCON_2); |
| 833 | l |= OTG_EN |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | /* for B-device: */ |
| 835 | | SRP_GPDATA /* 9msec Bdev D+ pulse */ |
| 836 | | SRP_GPDVBUS /* discharge after VBUS pulse */ |
| 837 | // | (3 << 24) /* 2msec VBUS pulse */ |
| 838 | /* for A-device: */ |
| 839 | | (0 << 20) /* 200ms nominal A_WAIT_VRISE timer */ |
| 840 | | SRP_DPW /* detect 167+ns SRP pulses */ |
| 841 | | SRP_DATA | SRP_VBUS /* accept both kinds of SRP pulse */ |
| 842 | ; |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 843 | omap_writel(l, OTG_SYSCON_2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | |
| 845 | update_otg1(isp, isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE)); |
| 846 | update_otg2(isp, isp1301_get_u8(isp, ISP1301_OTG_STATUS)); |
| 847 | |
Harvey Harrison | 08882d2 | 2008-04-22 22:16:47 +0200 | [diff] [blame] | 848 | check_state(isp, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | pr_debug("otg: %s, %s %06x\n", |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 850 | state_name(isp), __func__, omap_readl(OTG_CTRL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 852 | omap_writew(DRIVER_SWITCH | OPRT_CHG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | | B_SRP_TMROUT | B_HNP_FAIL |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 854 | | A_VBUS_ERR | A_SRP_DETECT | A_REQ_TMROUT, OTG_IRQ_EN); |
| 855 | |
| 856 | l = omap_readl(OTG_SYSCON_2); |
| 857 | l |= OTG_EN; |
| 858 | omap_writel(l, OTG_SYSCON_2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | |
| 860 | return 0; |
| 861 | } |
| 862 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 863 | static int otg_probe(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | { |
| 865 | // struct omap_usb_config *config = dev->platform_data; |
| 866 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 867 | otg_dev = dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | return 0; |
| 869 | } |
| 870 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 871 | static int otg_remove(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | { |
David Brownell | d1846b0 | 2008-11-28 15:24:38 +0100 | [diff] [blame] | 873 | otg_dev = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | return 0; |
| 875 | } |
| 876 | |
David Brownell | d1846b0 | 2008-11-28 15:24:38 +0100 | [diff] [blame] | 877 | static struct platform_driver omap_otg_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | .probe = otg_probe, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 879 | .remove = otg_remove, |
| 880 | .driver = { |
| 881 | .owner = THIS_MODULE, |
| 882 | .name = "omap_otg", |
| 883 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | }; |
| 885 | |
| 886 | static int otg_bind(struct isp1301 *isp) |
| 887 | { |
| 888 | int status; |
| 889 | |
| 890 | if (otg_dev) |
| 891 | return -EBUSY; |
| 892 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 893 | status = platform_driver_register(&omap_otg_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | if (status < 0) |
| 895 | return status; |
| 896 | |
| 897 | if (otg_dev) |
| 898 | status = request_irq(otg_dev->resource[1].start, omap_otg_irq, |
Yong Zhang | b5dd18d | 2011-09-07 16:10:52 +0800 | [diff] [blame] | 899 | 0, DRIVER_NAME, isp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | else |
| 901 | status = -ENODEV; |
| 902 | |
| 903 | if (status < 0) |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 904 | platform_driver_unregister(&omap_otg_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | return status; |
| 906 | } |
| 907 | |
| 908 | static void otg_unbind(struct isp1301 *isp) |
| 909 | { |
| 910 | if (!otg_dev) |
| 911 | return; |
| 912 | free_irq(otg_dev->resource[1].start, isp); |
| 913 | } |
| 914 | |
| 915 | #else |
| 916 | |
| 917 | /* OTG controller isn't clocked */ |
| 918 | |
| 919 | #endif /* CONFIG_USB_OTG */ |
| 920 | |
| 921 | /*-------------------------------------------------------------------------*/ |
| 922 | |
| 923 | static void b_peripheral(struct isp1301 *isp) |
| 924 | { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 925 | u32 l; |
| 926 | |
| 927 | l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS; |
| 928 | omap_writel(l, OTG_CTRL); |
| 929 | |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 930 | usb_gadget_vbus_connect(isp->phy.otg->gadget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | |
| 932 | #ifdef CONFIG_USB_OTG |
| 933 | enable_vbus_draw(isp, 8); |
| 934 | otg_update_isp(isp); |
| 935 | #else |
| 936 | enable_vbus_draw(isp, 100); |
| 937 | /* UDC driver just set OTG_BSESSVLD */ |
| 938 | isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_DP_PULLUP); |
| 939 | isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_DP_PULLDOWN); |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 940 | isp->phy.state = OTG_STATE_B_PERIPHERAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | pr_debug(" --> b_peripheral\n"); |
| 942 | dump_regs(isp, "2periph"); |
| 943 | #endif |
| 944 | } |
| 945 | |
| 946 | static void isp_update_otg(struct isp1301 *isp, u8 stat) |
| 947 | { |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 948 | struct usb_otg *otg = isp->phy.otg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | u8 isp_stat, isp_bstat; |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 950 | enum usb_otg_state state = isp->phy.state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | |
| 952 | if (stat & INTR_BDIS_ACON) |
| 953 | pr_debug("OTG: BDIS_ACON, %s\n", state_name(isp)); |
| 954 | |
| 955 | /* start certain state transitions right away */ |
| 956 | isp_stat = isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE); |
| 957 | if (isp_stat & INTR_ID_GND) { |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 958 | if (otg->default_a) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | switch (state) { |
| 960 | case OTG_STATE_B_IDLE: |
| 961 | a_idle(isp, "idle"); |
| 962 | /* FALLTHROUGH */ |
| 963 | case OTG_STATE_A_IDLE: |
| 964 | enable_vbus_source(isp); |
| 965 | /* FALLTHROUGH */ |
| 966 | case OTG_STATE_A_WAIT_VRISE: |
| 967 | /* we skip over OTG_STATE_A_WAIT_BCON, since |
| 968 | * the HC will transition to A_HOST (or |
| 969 | * A_SUSPEND!) without our noticing except |
| 970 | * when HNP is used. |
| 971 | */ |
| 972 | if (isp_stat & INTR_VBUS_VLD) |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 973 | isp->phy.state = OTG_STATE_A_HOST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | break; |
| 975 | case OTG_STATE_A_WAIT_VFALL: |
| 976 | if (!(isp_stat & INTR_SESS_VLD)) |
| 977 | a_idle(isp, "vfell"); |
| 978 | break; |
| 979 | default: |
| 980 | if (!(isp_stat & INTR_VBUS_VLD)) |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 981 | isp->phy.state = OTG_STATE_A_VBUS_ERR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | break; |
| 983 | } |
| 984 | isp_bstat = isp1301_get_u8(isp, ISP1301_OTG_STATUS); |
| 985 | } else { |
| 986 | switch (state) { |
| 987 | case OTG_STATE_B_PERIPHERAL: |
| 988 | case OTG_STATE_B_HOST: |
| 989 | case OTG_STATE_B_WAIT_ACON: |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 990 | usb_gadget_vbus_disconnect(otg->gadget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | break; |
| 992 | default: |
| 993 | break; |
| 994 | } |
| 995 | if (state != OTG_STATE_A_IDLE) |
| 996 | a_idle(isp, "id"); |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 997 | if (otg->host && state == OTG_STATE_A_IDLE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | isp1301_defer_work(isp, WORK_HOST_RESUME); |
| 999 | isp_bstat = 0; |
| 1000 | } |
| 1001 | } else { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1002 | u32 l; |
| 1003 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | /* if user unplugged mini-A end of cable, |
| 1005 | * don't bypass A_WAIT_VFALL. |
| 1006 | */ |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1007 | if (otg->default_a) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | switch (state) { |
| 1009 | default: |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1010 | isp->phy.state = OTG_STATE_A_WAIT_VFALL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | break; |
| 1012 | case OTG_STATE_A_WAIT_VFALL: |
| 1013 | state = OTG_STATE_A_IDLE; |
Petr Mladek | 37ebb54 | 2014-09-19 17:32:23 +0200 | [diff] [blame] | 1014 | /* hub_wq may take a while to notice and |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | * handle this disconnect, so don't go |
| 1016 | * to B_IDLE quite yet. |
| 1017 | */ |
| 1018 | break; |
| 1019 | case OTG_STATE_A_IDLE: |
| 1020 | host_suspend(isp); |
| 1021 | isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, |
| 1022 | MC1_BDIS_ACON_EN); |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1023 | isp->phy.state = OTG_STATE_B_IDLE; |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1024 | l = omap_readl(OTG_CTRL) & OTG_CTRL_MASK; |
| 1025 | l &= ~OTG_CTRL_BITS; |
| 1026 | omap_writel(l, OTG_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | break; |
| 1028 | case OTG_STATE_B_IDLE: |
| 1029 | break; |
| 1030 | } |
| 1031 | } |
| 1032 | isp_bstat = isp1301_get_u8(isp, ISP1301_OTG_STATUS); |
| 1033 | |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1034 | switch (isp->phy.state) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | case OTG_STATE_B_PERIPHERAL: |
| 1036 | case OTG_STATE_B_WAIT_ACON: |
| 1037 | case OTG_STATE_B_HOST: |
| 1038 | if (likely(isp_bstat & OTG_B_SESS_VLD)) |
| 1039 | break; |
| 1040 | enable_vbus_draw(isp, 0); |
| 1041 | #ifndef CONFIG_USB_OTG |
| 1042 | /* UDC driver will clear OTG_BSESSVLD */ |
| 1043 | isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, |
| 1044 | OTG1_DP_PULLDOWN); |
| 1045 | isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, |
| 1046 | OTG1_DP_PULLUP); |
Harvey Harrison | 08882d2 | 2008-04-22 22:16:47 +0200 | [diff] [blame] | 1047 | dump_regs(isp, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | #endif |
| 1049 | /* FALLTHROUGH */ |
| 1050 | case OTG_STATE_B_SRP_INIT: |
Harvey Harrison | 08882d2 | 2008-04-22 22:16:47 +0200 | [diff] [blame] | 1051 | b_idle(isp, __func__); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1052 | l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS; |
| 1053 | omap_writel(l, OTG_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | /* FALLTHROUGH */ |
| 1055 | case OTG_STATE_B_IDLE: |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1056 | if (otg->gadget && (isp_bstat & OTG_B_SESS_VLD)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | #ifdef CONFIG_USB_OTG |
| 1058 | update_otg1(isp, isp_stat); |
| 1059 | update_otg2(isp, isp_bstat); |
| 1060 | #endif |
| 1061 | b_peripheral(isp); |
| 1062 | } else if (!(isp_stat & (INTR_VBUS_VLD|INTR_SESS_VLD))) |
| 1063 | isp_bstat |= OTG_B_SESS_END; |
| 1064 | break; |
| 1065 | case OTG_STATE_A_WAIT_VFALL: |
| 1066 | break; |
| 1067 | default: |
| 1068 | pr_debug("otg: unsupported b-device %s\n", |
| 1069 | state_name(isp)); |
| 1070 | break; |
| 1071 | } |
| 1072 | } |
| 1073 | |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1074 | if (state != isp->phy.state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | pr_debug(" isp, %s -> %s\n", |
Felipe Balbi | 42c0bf1 | 2013-03-07 10:39:57 +0200 | [diff] [blame] | 1076 | usb_otg_state_string(state), state_name(isp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | |
| 1078 | #ifdef CONFIG_USB_OTG |
| 1079 | /* update the OTG controller state to match the isp1301; may |
| 1080 | * trigger OPRT_CHG irqs for changes going to the isp1301. |
| 1081 | */ |
| 1082 | update_otg1(isp, isp_stat); |
| 1083 | update_otg2(isp, isp_bstat); |
Harvey Harrison | 08882d2 | 2008-04-22 22:16:47 +0200 | [diff] [blame] | 1084 | check_state(isp, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | #endif |
| 1086 | |
| 1087 | dump_regs(isp, "isp1301->otg"); |
| 1088 | } |
| 1089 | |
| 1090 | /*-------------------------------------------------------------------------*/ |
| 1091 | |
| 1092 | static u8 isp1301_clear_latch(struct isp1301 *isp) |
| 1093 | { |
| 1094 | u8 latch = isp1301_get_u8(isp, ISP1301_INTERRUPT_LATCH); |
| 1095 | isp1301_clear_bits(isp, ISP1301_INTERRUPT_LATCH, latch); |
| 1096 | return latch; |
| 1097 | } |
| 1098 | |
| 1099 | static void |
David Brownell | 25da383 | 2007-08-14 18:37:14 +0200 | [diff] [blame] | 1100 | isp1301_work(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | { |
David Brownell | 25da383 | 2007-08-14 18:37:14 +0200 | [diff] [blame] | 1102 | struct isp1301 *isp = container_of(work, struct isp1301, work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | int stop; |
| 1104 | |
| 1105 | /* implicit lock: we're the only task using this device */ |
| 1106 | isp->working = 1; |
| 1107 | do { |
| 1108 | stop = test_bit(WORK_STOP, &isp->todo); |
| 1109 | |
| 1110 | #ifdef CONFIG_USB_OTG |
| 1111 | /* transfer state from otg engine to isp1301 */ |
| 1112 | if (test_and_clear_bit(WORK_UPDATE_ISP, &isp->todo)) { |
| 1113 | otg_update_isp(isp); |
Felipe Balbi | a5f08a3 | 2008-10-14 17:30:02 +0200 | [diff] [blame] | 1114 | put_device(&isp->client->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | } |
| 1116 | #endif |
| 1117 | /* transfer state from isp1301 to otg engine */ |
| 1118 | if (test_and_clear_bit(WORK_UPDATE_OTG, &isp->todo)) { |
| 1119 | u8 stat = isp1301_clear_latch(isp); |
| 1120 | |
| 1121 | isp_update_otg(isp, stat); |
Felipe Balbi | a5f08a3 | 2008-10-14 17:30:02 +0200 | [diff] [blame] | 1122 | put_device(&isp->client->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | } |
| 1124 | |
| 1125 | if (test_and_clear_bit(WORK_HOST_RESUME, &isp->todo)) { |
| 1126 | u32 otg_ctrl; |
| 1127 | |
| 1128 | /* |
| 1129 | * skip A_WAIT_VRISE; hc transitions invisibly |
| 1130 | * skip A_WAIT_BCON; same. |
| 1131 | */ |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1132 | switch (isp->phy.state) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | case OTG_STATE_A_WAIT_BCON: |
| 1134 | case OTG_STATE_A_WAIT_VRISE: |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1135 | isp->phy.state = OTG_STATE_A_HOST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | pr_debug(" --> a_host\n"); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1137 | otg_ctrl = omap_readl(OTG_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | otg_ctrl |= OTG_A_BUSREQ; |
| 1139 | otg_ctrl &= ~(OTG_BUSDROP|OTG_B_BUSREQ) |
| 1140 | & OTG_CTRL_MASK; |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1141 | omap_writel(otg_ctrl, OTG_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | break; |
| 1143 | case OTG_STATE_B_WAIT_ACON: |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1144 | isp->phy.state = OTG_STATE_B_HOST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | pr_debug(" --> b_host (acon)\n"); |
| 1146 | break; |
| 1147 | case OTG_STATE_B_HOST: |
| 1148 | case OTG_STATE_B_IDLE: |
| 1149 | case OTG_STATE_A_IDLE: |
| 1150 | break; |
| 1151 | default: |
| 1152 | pr_debug(" host resume in %s\n", |
| 1153 | state_name(isp)); |
| 1154 | } |
| 1155 | host_resume(isp); |
| 1156 | // mdelay(10); |
Felipe Balbi | a5f08a3 | 2008-10-14 17:30:02 +0200 | [diff] [blame] | 1157 | put_device(&isp->client->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | if (test_and_clear_bit(WORK_TIMER, &isp->todo)) { |
| 1161 | #ifdef VERBOSE |
| 1162 | dump_regs(isp, "timer"); |
| 1163 | if (!stop) |
| 1164 | mod_timer(&isp->timer, jiffies + TIMER_JIFFIES); |
| 1165 | #endif |
Felipe Balbi | a5f08a3 | 2008-10-14 17:30:02 +0200 | [diff] [blame] | 1166 | put_device(&isp->client->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1167 | } |
| 1168 | |
| 1169 | if (isp->todo) |
Felipe Balbi | a5f08a3 | 2008-10-14 17:30:02 +0200 | [diff] [blame] | 1170 | dev_vdbg(&isp->client->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | "work done, todo = 0x%lx\n", |
| 1172 | isp->todo); |
| 1173 | if (stop) { |
Felipe Balbi | a5f08a3 | 2008-10-14 17:30:02 +0200 | [diff] [blame] | 1174 | dev_dbg(&isp->client->dev, "stop\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | break; |
| 1176 | } |
| 1177 | } while (isp->todo); |
| 1178 | isp->working = 0; |
| 1179 | } |
| 1180 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1181 | static irqreturn_t isp1301_irq(int irq, void *isp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | { |
| 1183 | isp1301_defer_work(isp, WORK_UPDATE_OTG); |
| 1184 | return IRQ_HANDLED; |
| 1185 | } |
| 1186 | |
| 1187 | static void isp1301_timer(unsigned long _isp) |
| 1188 | { |
| 1189 | isp1301_defer_work((void *)_isp, WORK_TIMER); |
| 1190 | } |
| 1191 | |
| 1192 | /*-------------------------------------------------------------------------*/ |
| 1193 | |
| 1194 | static void isp1301_release(struct device *dev) |
| 1195 | { |
| 1196 | struct isp1301 *isp; |
| 1197 | |
Felipe Balbi | a5f08a3 | 2008-10-14 17:30:02 +0200 | [diff] [blame] | 1198 | isp = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | |
David Brownell | d1846b0 | 2008-11-28 15:24:38 +0100 | [diff] [blame] | 1200 | /* FIXME -- not with a "new style" driver, it doesn't!! */ |
| 1201 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1202 | /* ugly -- i2c hijacks our memory hook to wait_for_completion() */ |
| 1203 | if (isp->i2c_release) |
| 1204 | isp->i2c_release(dev); |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1205 | kfree(isp->phy.otg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | kfree (isp); |
| 1207 | } |
| 1208 | |
| 1209 | static struct isp1301 *the_transceiver; |
| 1210 | |
Dmitry Torokhov | 39d3568 | 2013-02-24 00:55:07 -0800 | [diff] [blame] | 1211 | static int isp1301_remove(struct i2c_client *i2c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | { |
| 1213 | struct isp1301 *isp; |
| 1214 | |
Felipe Balbi | a5f08a3 | 2008-10-14 17:30:02 +0200 | [diff] [blame] | 1215 | isp = i2c_get_clientdata(i2c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | |
| 1217 | isp1301_clear_bits(isp, ISP1301_INTERRUPT_FALLING, ~0); |
| 1218 | isp1301_clear_bits(isp, ISP1301_INTERRUPT_RISING, ~0); |
Jean Delvare | 9df013b | 2008-10-14 17:30:02 +0200 | [diff] [blame] | 1219 | free_irq(i2c->irq, isp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | #ifdef CONFIG_USB_OTG |
| 1221 | otg_unbind(isp); |
| 1222 | #endif |
| 1223 | if (machine_is_omap_h2()) |
David Brownell | d1846b0 | 2008-11-28 15:24:38 +0100 | [diff] [blame] | 1224 | gpio_free(2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | |
| 1226 | isp->timer.data = 0; |
| 1227 | set_bit(WORK_STOP, &isp->todo); |
| 1228 | del_timer_sync(&isp->timer); |
Tejun Heo | 4382973 | 2012-08-20 14:51:24 -0700 | [diff] [blame] | 1229 | flush_work(&isp->work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | |
| 1231 | put_device(&i2c->dev); |
David Brownell | d1846b0 | 2008-11-28 15:24:38 +0100 | [diff] [blame] | 1232 | the_transceiver = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | |
Jean Delvare | 9df013b | 2008-10-14 17:30:02 +0200 | [diff] [blame] | 1234 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | /*-------------------------------------------------------------------------*/ |
| 1238 | |
| 1239 | /* NOTE: three modes are possible here, only one of which |
| 1240 | * will be standards-conformant on any given system: |
| 1241 | * |
| 1242 | * - OTG mode (dual-role), required if there's a Mini-AB connector |
| 1243 | * - HOST mode, for when there's one or more A (host) connectors |
| 1244 | * - DEVICE mode, for when there's a B/Mini-B (device) connector |
| 1245 | * |
| 1246 | * As a rule, you won't have an isp1301 chip unless it's there to |
David Brownell | 25da383 | 2007-08-14 18:37:14 +0200 | [diff] [blame] | 1247 | * support the OTG mode. Other modes help testing USB controllers |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | * in isolation from (full) OTG support, or maybe so later board |
| 1249 | * revisions can help to support those feature. |
| 1250 | */ |
| 1251 | |
| 1252 | #ifdef CONFIG_USB_OTG |
| 1253 | |
| 1254 | static int isp1301_otg_enable(struct isp1301 *isp) |
| 1255 | { |
| 1256 | power_up(isp); |
Felipe Balbi | 465f829 | 2009-12-15 23:19:52 +0200 | [diff] [blame] | 1257 | isp1301_otg_init(isp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | |
| 1259 | /* NOTE: since we don't change this, this provides |
| 1260 | * a few more interrupts than are strictly needed. |
| 1261 | */ |
| 1262 | isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING, |
David Brownell | 25da383 | 2007-08-14 18:37:14 +0200 | [diff] [blame] | 1263 | INTR_VBUS_VLD | INTR_SESS_VLD | INTR_ID_GND); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING, |
David Brownell | 25da383 | 2007-08-14 18:37:14 +0200 | [diff] [blame] | 1265 | INTR_VBUS_VLD | INTR_SESS_VLD | INTR_ID_GND); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1266 | |
Felipe Balbi | a5f08a3 | 2008-10-14 17:30:02 +0200 | [diff] [blame] | 1267 | dev_info(&isp->client->dev, "ready for dual-role USB ...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | |
| 1269 | return 0; |
| 1270 | } |
| 1271 | |
| 1272 | #endif |
| 1273 | |
| 1274 | /* add or disable the host device+driver */ |
| 1275 | static int |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1276 | isp1301_set_host(struct usb_otg *otg, struct usb_bus *host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | { |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1278 | struct isp1301 *isp = container_of(otg->phy, struct isp1301, phy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | |
Aaro Koskinen | 8b42a74 | 2013-12-21 20:37:37 +0200 | [diff] [blame] | 1280 | if (isp != the_transceiver) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | return -ENODEV; |
| 1282 | |
| 1283 | if (!host) { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1284 | omap_writew(0, OTG_IRQ_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | power_down(isp); |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1286 | otg->host = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1287 | return 0; |
| 1288 | } |
| 1289 | |
| 1290 | #ifdef CONFIG_USB_OTG |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1291 | otg->host = host; |
Felipe Balbi | a5f08a3 | 2008-10-14 17:30:02 +0200 | [diff] [blame] | 1292 | dev_dbg(&isp->client->dev, "registered host\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | host_suspend(isp); |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1294 | if (otg->gadget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | return isp1301_otg_enable(isp); |
| 1296 | return 0; |
| 1297 | |
Paul Bolle | 77c2f02 | 2014-05-16 12:00:57 +0200 | [diff] [blame] | 1298 | #elif !IS_ENABLED(CONFIG_USB_OMAP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | // FIXME update its refcount |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1300 | otg->host = host; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | |
| 1302 | power_up(isp); |
| 1303 | |
| 1304 | if (machine_is_omap_h2()) |
| 1305 | isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0); |
| 1306 | |
Felipe Balbi | a5f08a3 | 2008-10-14 17:30:02 +0200 | [diff] [blame] | 1307 | dev_info(&isp->client->dev, "A-Host sessions ok\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING, |
David Brownell | 25da383 | 2007-08-14 18:37:14 +0200 | [diff] [blame] | 1309 | INTR_ID_GND); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1310 | isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING, |
David Brownell | 25da383 | 2007-08-14 18:37:14 +0200 | [diff] [blame] | 1311 | INTR_ID_GND); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | |
| 1313 | /* If this has a Mini-AB connector, this mode is highly |
| 1314 | * nonstandard ... but can be handy for testing, especially with |
| 1315 | * the Mini-A end of an OTG cable. (Or something nonstandard |
| 1316 | * like MiniB-to-StandardB, maybe built with a gender mender.) |
| 1317 | */ |
| 1318 | isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_VBUS_DRV); |
| 1319 | |
Harvey Harrison | 08882d2 | 2008-04-22 22:16:47 +0200 | [diff] [blame] | 1320 | dump_regs(isp, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | |
| 1322 | return 0; |
| 1323 | |
| 1324 | #else |
Felipe Balbi | a5f08a3 | 2008-10-14 17:30:02 +0200 | [diff] [blame] | 1325 | dev_dbg(&isp->client->dev, "host sessions not allowed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | return -EINVAL; |
| 1327 | #endif |
| 1328 | |
| 1329 | } |
| 1330 | |
| 1331 | static int |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1332 | isp1301_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | { |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1334 | struct isp1301 *isp = container_of(otg->phy, struct isp1301, phy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1335 | |
Aaro Koskinen | 8b42a74 | 2013-12-21 20:37:37 +0200 | [diff] [blame] | 1336 | if (isp != the_transceiver) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | return -ENODEV; |
| 1338 | |
| 1339 | if (!gadget) { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1340 | omap_writew(0, OTG_IRQ_EN); |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1341 | if (!otg->default_a) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | enable_vbus_draw(isp, 0); |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1343 | usb_gadget_vbus_disconnect(otg->gadget); |
| 1344 | otg->gadget = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | power_down(isp); |
| 1346 | return 0; |
| 1347 | } |
| 1348 | |
| 1349 | #ifdef CONFIG_USB_OTG |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1350 | otg->gadget = gadget; |
Felipe Balbi | a5f08a3 | 2008-10-14 17:30:02 +0200 | [diff] [blame] | 1351 | dev_dbg(&isp->client->dev, "registered gadget\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | /* gadget driver may be suspended until vbus_connect () */ |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1353 | if (otg->host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | return isp1301_otg_enable(isp); |
| 1355 | return 0; |
| 1356 | |
| 1357 | #elif !defined(CONFIG_USB_OHCI_HCD) && !defined(CONFIG_USB_OHCI_HCD_MODULE) |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1358 | otg->gadget = gadget; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | // FIXME update its refcount |
| 1360 | |
Paul Walmsley | 79d6680 | 2012-04-20 15:29:20 -0600 | [diff] [blame] | 1361 | { |
| 1362 | u32 l; |
| 1363 | |
| 1364 | l = omap_readl(OTG_CTRL) & OTG_CTRL_MASK; |
| 1365 | l &= ~(OTG_XCEIV_OUTPUTS|OTG_CTRL_BITS); |
| 1366 | l |= OTG_ID; |
| 1367 | omap_writel(l, OTG_CTRL); |
| 1368 | } |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1369 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | power_up(isp); |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1371 | isp->phy.state = OTG_STATE_B_IDLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | |
David Brownell | d1846b0 | 2008-11-28 15:24:38 +0100 | [diff] [blame] | 1373 | if (machine_is_omap_h2() || machine_is_omap_h3()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0); |
| 1375 | |
| 1376 | isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING, |
David Brownell | 25da383 | 2007-08-14 18:37:14 +0200 | [diff] [blame] | 1377 | INTR_SESS_VLD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING, |
David Brownell | 25da383 | 2007-08-14 18:37:14 +0200 | [diff] [blame] | 1379 | INTR_VBUS_VLD); |
Felipe Balbi | a5f08a3 | 2008-10-14 17:30:02 +0200 | [diff] [blame] | 1380 | dev_info(&isp->client->dev, "B-Peripheral sessions ok\n"); |
Harvey Harrison | 08882d2 | 2008-04-22 22:16:47 +0200 | [diff] [blame] | 1381 | dump_regs(isp, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | |
| 1383 | /* If this has a Mini-AB connector, this mode is highly |
| 1384 | * nonstandard ... but can be handy for testing, so long |
| 1385 | * as you don't plug a Mini-A cable into the jack. |
| 1386 | */ |
| 1387 | if (isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE) & INTR_VBUS_VLD) |
| 1388 | b_peripheral(isp); |
| 1389 | |
| 1390 | return 0; |
| 1391 | |
| 1392 | #else |
Felipe Balbi | a5f08a3 | 2008-10-14 17:30:02 +0200 | [diff] [blame] | 1393 | dev_dbg(&isp->client->dev, "peripheral sessions not allowed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1394 | return -EINVAL; |
| 1395 | #endif |
| 1396 | } |
| 1397 | |
| 1398 | |
| 1399 | /*-------------------------------------------------------------------------*/ |
| 1400 | |
| 1401 | static int |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame] | 1402 | isp1301_set_power(struct usb_phy *dev, unsigned mA) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | { |
| 1404 | if (!the_transceiver) |
| 1405 | return -ENODEV; |
| 1406 | if (dev->state == OTG_STATE_B_PERIPHERAL) |
| 1407 | enable_vbus_draw(the_transceiver, mA); |
| 1408 | return 0; |
| 1409 | } |
| 1410 | |
| 1411 | static int |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1412 | isp1301_start_srp(struct usb_otg *otg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1413 | { |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1414 | struct isp1301 *isp = container_of(otg->phy, struct isp1301, phy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | u32 otg_ctrl; |
| 1416 | |
Aaro Koskinen | 8b42a74 | 2013-12-21 20:37:37 +0200 | [diff] [blame] | 1417 | if (isp != the_transceiver || isp->phy.state != OTG_STATE_B_IDLE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1418 | return -ENODEV; |
| 1419 | |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1420 | otg_ctrl = omap_readl(OTG_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1421 | if (!(otg_ctrl & OTG_BSESSEND)) |
| 1422 | return -EINVAL; |
| 1423 | |
| 1424 | otg_ctrl |= OTG_B_BUSREQ; |
| 1425 | otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK; |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1426 | omap_writel(otg_ctrl, OTG_CTRL); |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1427 | isp->phy.state = OTG_STATE_B_SRP_INIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1428 | |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1429 | pr_debug("otg: SRP, %s ... %06x\n", state_name(isp), |
| 1430 | omap_readl(OTG_CTRL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | #ifdef CONFIG_USB_OTG |
Harvey Harrison | 08882d2 | 2008-04-22 22:16:47 +0200 | [diff] [blame] | 1432 | check_state(isp, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1433 | #endif |
| 1434 | return 0; |
| 1435 | } |
| 1436 | |
| 1437 | static int |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1438 | isp1301_start_hnp(struct usb_otg *otg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1439 | { |
| 1440 | #ifdef CONFIG_USB_OTG |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1441 | struct isp1301 *isp = container_of(otg->phy, struct isp1301, phy); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1442 | u32 l; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1443 | |
Aaro Koskinen | 8b42a74 | 2013-12-21 20:37:37 +0200 | [diff] [blame] | 1444 | if (isp != the_transceiver) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 | return -ENODEV; |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1446 | if (otg->default_a && (otg->host == NULL || !otg->host->b_hnp_enable)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | return -ENOTCONN; |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1448 | if (!otg->default_a && (otg->gadget == NULL |
| 1449 | || !otg->gadget->b_hnp_enable)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1450 | return -ENOTCONN; |
| 1451 | |
| 1452 | /* We want hardware to manage most HNP protocol timings. |
| 1453 | * So do this part as early as possible... |
| 1454 | */ |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1455 | switch (isp->phy.state) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | case OTG_STATE_B_HOST: |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1457 | isp->phy.state = OTG_STATE_B_PERIPHERAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | /* caller will suspend next */ |
| 1459 | break; |
| 1460 | case OTG_STATE_A_HOST: |
| 1461 | #if 0 |
| 1462 | /* autoconnect mode avoids irq latency bugs */ |
| 1463 | isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, |
| 1464 | MC1_BDIS_ACON_EN); |
| 1465 | #endif |
| 1466 | /* caller must suspend then clear A_BUSREQ */ |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1467 | usb_gadget_vbus_connect(otg->gadget); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1468 | l = omap_readl(OTG_CTRL); |
| 1469 | l |= OTG_A_SETB_HNPEN; |
| 1470 | omap_writel(l, OTG_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1471 | |
| 1472 | break; |
| 1473 | case OTG_STATE_A_PERIPHERAL: |
| 1474 | /* initiated by B-Host suspend */ |
| 1475 | break; |
| 1476 | default: |
| 1477 | return -EILSEQ; |
| 1478 | } |
| 1479 | pr_debug("otg: HNP %s, %06x ...\n", |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1480 | state_name(isp), omap_readl(OTG_CTRL)); |
Harvey Harrison | 08882d2 | 2008-04-22 22:16:47 +0200 | [diff] [blame] | 1481 | check_state(isp, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | return 0; |
| 1483 | #else |
| 1484 | /* srp-only */ |
| 1485 | return -EINVAL; |
| 1486 | #endif |
| 1487 | } |
| 1488 | |
| 1489 | /*-------------------------------------------------------------------------*/ |
| 1490 | |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 1491 | static int |
David Brownell | d1846b0 | 2008-11-28 15:24:38 +0100 | [diff] [blame] | 1492 | isp1301_probe(struct i2c_client *i2c, const struct i2c_device_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1493 | { |
| 1494 | int status; |
| 1495 | struct isp1301 *isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | |
| 1497 | if (the_transceiver) |
| 1498 | return 0; |
| 1499 | |
Pekka Enberg | 82ca76b | 2005-09-06 15:18:35 -0700 | [diff] [blame] | 1500 | isp = kzalloc(sizeof *isp, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | if (!isp) |
| 1502 | return 0; |
| 1503 | |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1504 | isp->phy.otg = kzalloc(sizeof *isp->phy.otg, GFP_KERNEL); |
| 1505 | if (!isp->phy.otg) { |
| 1506 | kfree(isp); |
| 1507 | return 0; |
| 1508 | } |
| 1509 | |
David Brownell | 25da383 | 2007-08-14 18:37:14 +0200 | [diff] [blame] | 1510 | INIT_WORK(&isp->work, isp1301_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1511 | init_timer(&isp->timer); |
| 1512 | isp->timer.function = isp1301_timer; |
| 1513 | isp->timer.data = (unsigned long) isp; |
| 1514 | |
Jean Delvare | 9df013b | 2008-10-14 17:30:02 +0200 | [diff] [blame] | 1515 | i2c_set_clientdata(i2c, isp); |
| 1516 | isp->client = i2c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1517 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1518 | /* verify the chip (shouldn't be necessary) */ |
Jean Delvare | 9df013b | 2008-10-14 17:30:02 +0200 | [diff] [blame] | 1519 | status = isp1301_get_u16(isp, ISP1301_VENDOR_ID); |
| 1520 | if (status != I2C_VENDOR_ID_PHILIPS) { |
| 1521 | dev_dbg(&i2c->dev, "not philips id: %d\n", status); |
| 1522 | goto fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 | } |
Jean Delvare | 9df013b | 2008-10-14 17:30:02 +0200 | [diff] [blame] | 1524 | status = isp1301_get_u16(isp, ISP1301_PRODUCT_ID); |
| 1525 | if (status != I2C_PRODUCT_ID_PHILIPS_1301) { |
| 1526 | dev_dbg(&i2c->dev, "not isp1301, %d\n", status); |
| 1527 | goto fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1528 | } |
| 1529 | isp->i2c_release = i2c->dev.release; |
| 1530 | i2c->dev.release = isp1301_release; |
| 1531 | |
| 1532 | /* initial development used chiprev 2.00 */ |
| 1533 | status = i2c_smbus_read_word_data(i2c, ISP1301_BCD_DEVICE); |
| 1534 | dev_info(&i2c->dev, "chiprev %x.%02x, driver " DRIVER_VERSION "\n", |
| 1535 | status >> 8, status & 0xff); |
| 1536 | |
| 1537 | /* make like power-on reset */ |
| 1538 | isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, MC1_MASK); |
| 1539 | |
| 1540 | isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2, MC2_BI_DI); |
| 1541 | isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_2, ~MC2_BI_DI); |
| 1542 | |
| 1543 | isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, |
| 1544 | OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN); |
| 1545 | isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, |
| 1546 | ~(OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN)); |
| 1547 | |
| 1548 | isp1301_clear_bits(isp, ISP1301_INTERRUPT_LATCH, ~0); |
| 1549 | isp1301_clear_bits(isp, ISP1301_INTERRUPT_FALLING, ~0); |
| 1550 | isp1301_clear_bits(isp, ISP1301_INTERRUPT_RISING, ~0); |
| 1551 | |
| 1552 | #ifdef CONFIG_USB_OTG |
| 1553 | status = otg_bind(isp); |
| 1554 | if (status < 0) { |
| 1555 | dev_dbg(&i2c->dev, "can't bind OTG\n"); |
Jean Delvare | 9df013b | 2008-10-14 17:30:02 +0200 | [diff] [blame] | 1556 | goto fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | } |
| 1558 | #endif |
| 1559 | |
| 1560 | if (machine_is_omap_h2()) { |
| 1561 | /* full speed signaling by default */ |
| 1562 | isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, |
Dmitry Baryshkov | cbbcb9b | 2008-08-07 16:29:24 +0400 | [diff] [blame] | 1563 | MC1_SPEED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2, |
| 1565 | MC2_SPD_SUSP_CTRL); |
| 1566 | |
| 1567 | /* IRQ wired at M14 */ |
| 1568 | omap_cfg_reg(M14_1510_GPIO2); |
David Brownell | 25da383 | 2007-08-14 18:37:14 +0200 | [diff] [blame] | 1569 | if (gpio_request(2, "isp1301") == 0) |
| 1570 | gpio_direction_input(2); |
| 1571 | isp->irq_type = IRQF_TRIGGER_FALLING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1572 | } |
| 1573 | |
Jean Delvare | 9df013b | 2008-10-14 17:30:02 +0200 | [diff] [blame] | 1574 | status = request_irq(i2c->irq, isp1301_irq, |
David Brownell | 25da383 | 2007-08-14 18:37:14 +0200 | [diff] [blame] | 1575 | isp->irq_type, DRIVER_NAME, isp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1576 | if (status < 0) { |
| 1577 | dev_dbg(&i2c->dev, "can't get IRQ %d, err %d\n", |
Jean Delvare | 9df013b | 2008-10-14 17:30:02 +0200 | [diff] [blame] | 1578 | i2c->irq, status); |
| 1579 | goto fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 | } |
| 1581 | |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1582 | isp->phy.dev = &i2c->dev; |
| 1583 | isp->phy.label = DRIVER_NAME; |
| 1584 | isp->phy.set_power = isp1301_set_power, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1585 | |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1586 | isp->phy.otg->phy = &isp->phy; |
| 1587 | isp->phy.otg->set_host = isp1301_set_host, |
| 1588 | isp->phy.otg->set_peripheral = isp1301_set_peripheral, |
| 1589 | isp->phy.otg->start_srp = isp1301_start_srp, |
| 1590 | isp->phy.otg->start_hnp = isp1301_start_hnp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | |
| 1592 | enable_vbus_draw(isp, 0); |
| 1593 | power_down(isp); |
| 1594 | the_transceiver = isp; |
| 1595 | |
| 1596 | #ifdef CONFIG_USB_OTG |
| 1597 | update_otg1(isp, isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE)); |
| 1598 | update_otg2(isp, isp1301_get_u8(isp, ISP1301_OTG_STATUS)); |
| 1599 | #endif |
| 1600 | |
Harvey Harrison | 08882d2 | 2008-04-22 22:16:47 +0200 | [diff] [blame] | 1601 | dump_regs(isp, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1602 | |
| 1603 | #ifdef VERBOSE |
| 1604 | mod_timer(&isp->timer, jiffies + TIMER_JIFFIES); |
| 1605 | dev_dbg(&i2c->dev, "scheduled timer, %d min\n", TIMER_MINUTES); |
| 1606 | #endif |
| 1607 | |
Kishon Vijay Abraham I | 662dca5 | 2012-06-22 17:02:46 +0530 | [diff] [blame] | 1608 | status = usb_add_phy(&isp->phy, USB_PHY_TYPE_USB2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 | if (status < 0) |
| 1610 | dev_err(&i2c->dev, "can't register transceiver, %d\n", |
| 1611 | status); |
| 1612 | |
| 1613 | return 0; |
Jean Delvare | 9df013b | 2008-10-14 17:30:02 +0200 | [diff] [blame] | 1614 | |
| 1615 | fail: |
Heikki Krogerus | 819d1c7 | 2012-02-13 13:24:08 +0200 | [diff] [blame] | 1616 | kfree(isp->phy.otg); |
Jean Delvare | 9df013b | 2008-10-14 17:30:02 +0200 | [diff] [blame] | 1617 | kfree(isp); |
| 1618 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1619 | } |
| 1620 | |
Jean Delvare | 9df013b | 2008-10-14 17:30:02 +0200 | [diff] [blame] | 1621 | static const struct i2c_device_id isp1301_id[] = { |
| 1622 | { "isp1301_omap", 0 }, |
| 1623 | { } |
| 1624 | }; |
| 1625 | MODULE_DEVICE_TABLE(i2c, isp1301_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1626 | |
| 1627 | static struct i2c_driver isp1301_driver = { |
Laurent Riffard | a9718b0 | 2005-11-26 20:36:00 +0100 | [diff] [blame] | 1628 | .driver = { |
Laurent Riffard | a9718b0 | 2005-11-26 20:36:00 +0100 | [diff] [blame] | 1629 | .name = "isp1301_omap", |
| 1630 | }, |
Jean Delvare | 9df013b | 2008-10-14 17:30:02 +0200 | [diff] [blame] | 1631 | .probe = isp1301_probe, |
Dmitry Torokhov | 39d3568 | 2013-02-24 00:55:07 -0800 | [diff] [blame] | 1632 | .remove = isp1301_remove, |
Jean Delvare | 9df013b | 2008-10-14 17:30:02 +0200 | [diff] [blame] | 1633 | .id_table = isp1301_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1634 | }; |
| 1635 | |
| 1636 | /*-------------------------------------------------------------------------*/ |
| 1637 | |
| 1638 | static int __init isp_init(void) |
| 1639 | { |
| 1640 | return i2c_add_driver(&isp1301_driver); |
| 1641 | } |
Viral Mehta | 94a8248 | 2010-04-06 11:51:00 +0530 | [diff] [blame] | 1642 | subsys_initcall(isp_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1643 | |
| 1644 | static void __exit isp_exit(void) |
| 1645 | { |
| 1646 | if (the_transceiver) |
Kishon Vijay Abraham I | 662dca5 | 2012-06-22 17:02:46 +0530 | [diff] [blame] | 1647 | usb_remove_phy(&the_transceiver->phy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1648 | i2c_del_driver(&isp1301_driver); |
| 1649 | } |
| 1650 | module_exit(isp_exit); |
| 1651 | |