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