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