Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 1 | /* |
| 2 | * drivers/usb/otg/ab8500_usb.c |
| 3 | * |
| 4 | * USB transceiver driver for AB8500 chip |
| 5 | * |
| 6 | * Copyright (C) 2010 ST-Ericsson AB |
| 7 | * Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #include <linux/module.h> |
| 26 | #include <linux/platform_device.h> |
| 27 | #include <linux/usb/otg.h> |
| 28 | #include <linux/slab.h> |
| 29 | #include <linux/notifier.h> |
| 30 | #include <linux/interrupt.h> |
| 31 | #include <linux/delay.h> |
| 32 | #include <linux/mfd/abx500.h> |
Linus Walleij | ee66e65 | 2011-12-02 14:16:33 +0100 | [diff] [blame] | 33 | #include <linux/mfd/abx500/ab8500.h> |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 34 | #include <linux/usb/musb-ux500.h> |
Fabio Baltieri | e65b36c | 2013-04-03 10:45:06 +0200 | [diff] [blame] | 35 | #include <linux/regulator/consumer.h> |
Patrice Chotard | 899f0f5 | 2013-04-03 10:45:11 +0200 | [diff] [blame^] | 36 | #include <linux/pinctrl/consumer.h> |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 37 | |
Sakethram Bommisetti | 7124631 | 2013-04-03 10:45:04 +0200 | [diff] [blame] | 38 | /* Bank AB8500_SYS_CTRL2_BLOCK */ |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 39 | #define AB8500_MAIN_WD_CTRL_REG 0x01 |
Sakethram Bommisetti | 7124631 | 2013-04-03 10:45:04 +0200 | [diff] [blame] | 40 | |
| 41 | /* Bank AB8500_USB */ |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 42 | #define AB8500_USB_LINE_STAT_REG 0x80 |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 43 | #define AB8505_USB_LINE_STAT_REG 0x94 |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 44 | #define AB8500_USB_PHY_CTRL_REG 0x8A |
| 45 | |
Sakethram Bommisetti | 7124631 | 2013-04-03 10:45:04 +0200 | [diff] [blame] | 46 | /* Bank AB8500_DEVELOPMENT */ |
| 47 | #define AB8500_BANK12_ACCESS 0x00 |
| 48 | |
| 49 | /* Bank AB8500_DEBUG */ |
| 50 | #define AB8500_USB_PHY_TUNE1 0x05 |
| 51 | #define AB8500_USB_PHY_TUNE2 0x06 |
| 52 | #define AB8500_USB_PHY_TUNE3 0x07 |
| 53 | |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 54 | #define AB8500_BIT_OTG_STAT_ID (1 << 0) |
| 55 | #define AB8500_BIT_PHY_CTRL_HOST_EN (1 << 0) |
| 56 | #define AB8500_BIT_PHY_CTRL_DEVICE_EN (1 << 1) |
| 57 | #define AB8500_BIT_WD_CTRL_ENABLE (1 << 0) |
| 58 | #define AB8500_BIT_WD_CTRL_KICK (1 << 1) |
| 59 | |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 60 | #define AB8500_WD_KICK_DELAY_US 100 /* usec */ |
| 61 | #define AB8500_WD_V11_DISABLE_DELAY_US 100 /* usec */ |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 62 | #define AB8500_V20_31952_DISABLE_DELAY_US 100 /* usec */ |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 63 | |
| 64 | /* Usb line status register */ |
| 65 | enum ab8500_usb_link_status { |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 66 | USB_LINK_NOT_CONFIGURED_8500 = 0, |
| 67 | USB_LINK_STD_HOST_NC_8500, |
| 68 | USB_LINK_STD_HOST_C_NS_8500, |
| 69 | USB_LINK_STD_HOST_C_S_8500, |
| 70 | USB_LINK_HOST_CHG_NM_8500, |
| 71 | USB_LINK_HOST_CHG_HS_8500, |
| 72 | USB_LINK_HOST_CHG_HS_CHIRP_8500, |
| 73 | USB_LINK_DEDICATED_CHG_8500, |
| 74 | USB_LINK_ACA_RID_A_8500, |
| 75 | USB_LINK_ACA_RID_B_8500, |
| 76 | USB_LINK_ACA_RID_C_NM_8500, |
| 77 | USB_LINK_ACA_RID_C_HS_8500, |
| 78 | USB_LINK_ACA_RID_C_HS_CHIRP_8500, |
| 79 | USB_LINK_HM_IDGND_8500, |
| 80 | USB_LINK_RESERVED_8500, |
| 81 | USB_LINK_NOT_VALID_LINK_8500, |
| 82 | }; |
| 83 | |
| 84 | enum ab8505_usb_link_status { |
| 85 | USB_LINK_NOT_CONFIGURED_8505 = 0, |
| 86 | USB_LINK_STD_HOST_NC_8505, |
| 87 | USB_LINK_STD_HOST_C_NS_8505, |
| 88 | USB_LINK_STD_HOST_C_S_8505, |
| 89 | USB_LINK_CDP_8505, |
| 90 | USB_LINK_RESERVED0_8505, |
| 91 | USB_LINK_RESERVED1_8505, |
| 92 | USB_LINK_DEDICATED_CHG_8505, |
| 93 | USB_LINK_ACA_RID_A_8505, |
| 94 | USB_LINK_ACA_RID_B_8505, |
| 95 | USB_LINK_ACA_RID_C_NM_8505, |
| 96 | USB_LINK_RESERVED2_8505, |
| 97 | USB_LINK_RESERVED3_8505, |
| 98 | USB_LINK_HM_IDGND_8505, |
| 99 | USB_LINK_CHARGERPORT_NOT_OK_8505, |
| 100 | USB_LINK_CHARGER_DM_HIGH_8505, |
| 101 | USB_LINK_PHYEN_NO_VBUS_NO_IDGND_8505, |
| 102 | USB_LINK_STD_UPSTREAM_NO_IDGNG_NO_VBUS_8505, |
| 103 | USB_LINK_STD_UPSTREAM_8505, |
| 104 | USB_LINK_CHARGER_SE1_8505, |
| 105 | USB_LINK_CARKIT_CHGR_1_8505, |
| 106 | USB_LINK_CARKIT_CHGR_2_8505, |
| 107 | USB_LINK_ACA_DOCK_CHGR_8505, |
| 108 | USB_LINK_SAMSUNG_BOOT_CBL_PHY_EN_8505, |
| 109 | USB_LINK_SAMSUNG_BOOT_CBL_PHY_DISB_8505, |
| 110 | USB_LINK_SAMSUNG_UART_CBL_PHY_EN_8505, |
| 111 | USB_LINK_SAMSUNG_UART_CBL_PHY_DISB_8505, |
| 112 | USB_LINK_MOTOROLA_FACTORY_CBL_PHY_EN_8505, |
| 113 | }; |
| 114 | |
| 115 | enum ab8500_usb_mode { |
| 116 | USB_IDLE = 0, |
| 117 | USB_PERIPHERAL, |
| 118 | USB_HOST, |
| 119 | USB_DEDICATED_CHG |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | struct ab8500_usb { |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 123 | struct usb_phy phy; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 124 | struct device *dev; |
Fabio Baltieri | 73f226c | 2013-03-08 10:27:08 +0800 | [diff] [blame] | 125 | struct ab8500 *ab8500; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 126 | unsigned vbus_draw; |
| 127 | struct delayed_work dwork; |
| 128 | struct work_struct phy_dis_work; |
| 129 | unsigned long link_status_wait; |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 130 | enum ab8500_usb_mode mode; |
Fabio Baltieri | e65b36c | 2013-04-03 10:45:06 +0200 | [diff] [blame] | 131 | struct regulator *v_ape; |
| 132 | struct regulator *v_musb; |
| 133 | struct regulator *v_ulpi; |
Fabio Baltieri | 54dfbb0 | 2013-04-03 10:45:08 +0200 | [diff] [blame] | 134 | int saved_v_ulpi; |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 135 | int previous_link_status_state; |
Patrice Chotard | 899f0f5 | 2013-04-03 10:45:11 +0200 | [diff] [blame^] | 136 | struct pinctrl *pinctrl; |
| 137 | struct pinctrl_state *pins_sleep; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 138 | }; |
| 139 | |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 140 | static inline struct ab8500_usb *phy_to_ab(struct usb_phy *x) |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 141 | { |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 142 | return container_of(x, struct ab8500_usb, phy); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | static void ab8500_usb_wd_workaround(struct ab8500_usb *ab) |
| 146 | { |
| 147 | abx500_set_register_interruptible(ab->dev, |
| 148 | AB8500_SYS_CTRL2_BLOCK, |
| 149 | AB8500_MAIN_WD_CTRL_REG, |
| 150 | AB8500_BIT_WD_CTRL_ENABLE); |
| 151 | |
| 152 | udelay(AB8500_WD_KICK_DELAY_US); |
| 153 | |
| 154 | abx500_set_register_interruptible(ab->dev, |
| 155 | AB8500_SYS_CTRL2_BLOCK, |
| 156 | AB8500_MAIN_WD_CTRL_REG, |
| 157 | (AB8500_BIT_WD_CTRL_ENABLE |
| 158 | | AB8500_BIT_WD_CTRL_KICK)); |
| 159 | |
Fabio Baltieri | 73f226c | 2013-03-08 10:27:08 +0800 | [diff] [blame] | 160 | udelay(AB8500_WD_V11_DISABLE_DELAY_US); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 161 | |
| 162 | abx500_set_register_interruptible(ab->dev, |
| 163 | AB8500_SYS_CTRL2_BLOCK, |
| 164 | AB8500_MAIN_WD_CTRL_REG, |
| 165 | 0); |
| 166 | } |
| 167 | |
Fabio Baltieri | 54dfbb0 | 2013-04-03 10:45:08 +0200 | [diff] [blame] | 168 | static void ab8500_usb_regulator_enable(struct ab8500_usb *ab) |
| 169 | { |
| 170 | int ret, volt; |
| 171 | |
| 172 | regulator_enable(ab->v_ape); |
| 173 | |
| 174 | if (!is_ab8500_2p0_or_earlier(ab->ab8500)) { |
| 175 | ab->saved_v_ulpi = regulator_get_voltage(ab->v_ulpi); |
| 176 | if (ab->saved_v_ulpi < 0) |
| 177 | dev_err(ab->dev, "Failed to get v_ulpi voltage\n"); |
| 178 | |
| 179 | ret = regulator_set_voltage(ab->v_ulpi, 1300000, 1350000); |
| 180 | if (ret < 0) |
| 181 | dev_err(ab->dev, "Failed to set the Vintcore to 1.3V, ret=%d\n", |
| 182 | ret); |
| 183 | |
| 184 | ret = regulator_set_optimum_mode(ab->v_ulpi, 28000); |
| 185 | if (ret < 0) |
| 186 | dev_err(ab->dev, "Failed to set optimum mode (ret=%d)\n", |
| 187 | ret); |
| 188 | } |
| 189 | |
| 190 | regulator_enable(ab->v_ulpi); |
| 191 | |
| 192 | if (!is_ab8500_2p0_or_earlier(ab->ab8500)) { |
| 193 | volt = regulator_get_voltage(ab->v_ulpi); |
| 194 | if ((volt != 1300000) && (volt != 1350000)) |
| 195 | dev_err(ab->dev, "Vintcore is not set to 1.3V volt=%d\n", |
| 196 | volt); |
| 197 | } |
| 198 | |
| 199 | regulator_enable(ab->v_musb); |
| 200 | } |
| 201 | |
| 202 | static void ab8500_usb_regulator_disable(struct ab8500_usb *ab) |
| 203 | { |
| 204 | int ret; |
| 205 | |
| 206 | regulator_disable(ab->v_musb); |
| 207 | |
| 208 | regulator_disable(ab->v_ulpi); |
| 209 | |
| 210 | /* USB is not the only consumer of Vintcore, restore old settings */ |
| 211 | if (!is_ab8500_2p0_or_earlier(ab->ab8500)) { |
| 212 | if (ab->saved_v_ulpi > 0) { |
| 213 | ret = regulator_set_voltage(ab->v_ulpi, |
| 214 | ab->saved_v_ulpi, ab->saved_v_ulpi); |
| 215 | if (ret < 0) |
| 216 | dev_err(ab->dev, "Failed to set the Vintcore to %duV, ret=%d\n", |
| 217 | ab->saved_v_ulpi, ret); |
| 218 | } |
| 219 | |
| 220 | ret = regulator_set_optimum_mode(ab->v_ulpi, 0); |
| 221 | if (ret < 0) |
| 222 | dev_err(ab->dev, "Failed to set optimum mode (ret=%d)\n", |
| 223 | ret); |
| 224 | } |
| 225 | |
| 226 | regulator_disable(ab->v_ape); |
| 227 | } |
| 228 | |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 229 | static void ab8500_usb_wd_linkstatus(struct ab8500_usb *ab, u8 bit) |
| 230 | { |
| 231 | /* Workaround for v2.0 bug # 31952 */ |
| 232 | if (is_ab8500_2p0(ab->ab8500)) { |
| 233 | abx500_mask_and_set_register_interruptible(ab->dev, |
| 234 | AB8500_USB, AB8500_USB_PHY_CTRL_REG, |
| 235 | bit, bit); |
| 236 | udelay(AB8500_V20_31952_DISABLE_DELAY_US); |
| 237 | } |
| 238 | } |
| 239 | |
Fabio Baltieri | c0ea706 | 2013-04-03 10:45:07 +0200 | [diff] [blame] | 240 | static void ab8500_usb_phy_enable(struct ab8500_usb *ab, bool sel_host) |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 241 | { |
Fabio Baltieri | c0ea706 | 2013-04-03 10:45:07 +0200 | [diff] [blame] | 242 | u8 bit; |
| 243 | bit = sel_host ? AB8500_BIT_PHY_CTRL_HOST_EN : |
| 244 | AB8500_BIT_PHY_CTRL_DEVICE_EN; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 245 | |
Patrice Chotard | 899f0f5 | 2013-04-03 10:45:11 +0200 | [diff] [blame^] | 246 | /* mux and configure USB pins to DEFAULT state */ |
| 247 | ab->pinctrl = pinctrl_get_select(ab->dev, PINCTRL_STATE_DEFAULT); |
| 248 | if (IS_ERR(ab->pinctrl)) |
| 249 | dev_err(ab->dev, "could not get/set default pinstate\n"); |
| 250 | |
Fabio Baltieri | 54dfbb0 | 2013-04-03 10:45:08 +0200 | [diff] [blame] | 251 | ab8500_usb_regulator_enable(ab); |
| 252 | |
Fabio Baltieri | c0ea706 | 2013-04-03 10:45:07 +0200 | [diff] [blame] | 253 | abx500_mask_and_set_register_interruptible(ab->dev, |
| 254 | AB8500_USB, AB8500_USB_PHY_CTRL_REG, |
| 255 | bit, bit); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 256 | } |
| 257 | |
Fabio Baltieri | c0ea706 | 2013-04-03 10:45:07 +0200 | [diff] [blame] | 258 | static void ab8500_usb_phy_disable(struct ab8500_usb *ab, bool sel_host) |
| 259 | { |
| 260 | u8 bit; |
| 261 | bit = sel_host ? AB8500_BIT_PHY_CTRL_HOST_EN : |
| 262 | AB8500_BIT_PHY_CTRL_DEVICE_EN; |
| 263 | |
| 264 | ab8500_usb_wd_linkstatus(ab, bit); |
| 265 | |
| 266 | abx500_mask_and_set_register_interruptible(ab->dev, |
| 267 | AB8500_USB, AB8500_USB_PHY_CTRL_REG, |
| 268 | bit, 0); |
| 269 | |
| 270 | /* Needed to disable the phy.*/ |
| 271 | ab8500_usb_wd_workaround(ab); |
Fabio Baltieri | 54dfbb0 | 2013-04-03 10:45:08 +0200 | [diff] [blame] | 272 | |
| 273 | ab8500_usb_regulator_disable(ab); |
Patrice Chotard | 899f0f5 | 2013-04-03 10:45:11 +0200 | [diff] [blame^] | 274 | |
| 275 | if (!IS_ERR(ab->pinctrl)) { |
| 276 | /* configure USB pins to SLEEP state */ |
| 277 | ab->pins_sleep = pinctrl_lookup_state(ab->pinctrl, |
| 278 | PINCTRL_STATE_SLEEP); |
| 279 | |
| 280 | if (IS_ERR(ab->pins_sleep)) |
| 281 | dev_dbg(ab->dev, "could not get sleep pinstate\n"); |
| 282 | else if (pinctrl_select_state(ab->pinctrl, ab->pins_sleep)) |
| 283 | dev_err(ab->dev, "could not set pins to sleep state\n"); |
| 284 | |
| 285 | /* as USB pins are shared with idddet, release them to allow |
| 286 | * iddet to request them |
| 287 | */ |
| 288 | pinctrl_put(ab->pinctrl); |
| 289 | } |
Fabio Baltieri | c0ea706 | 2013-04-03 10:45:07 +0200 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | #define ab8500_usb_host_phy_en(ab) ab8500_usb_phy_enable(ab, true) |
| 293 | #define ab8500_usb_host_phy_dis(ab) ab8500_usb_phy_disable(ab, true) |
| 294 | #define ab8500_usb_peri_phy_en(ab) ab8500_usb_phy_enable(ab, false) |
| 295 | #define ab8500_usb_peri_phy_dis(ab) ab8500_usb_phy_disable(ab, false) |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 296 | |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 297 | static int ab8505_usb_link_status_update(struct ab8500_usb *ab, |
| 298 | enum ab8505_usb_link_status lsts) |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 299 | { |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 300 | enum ux500_musb_vbus_id_status event = 0; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 301 | |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 302 | dev_dbg(ab->dev, "ab8505_usb_link_status_update %d\n", lsts); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 303 | |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 304 | /* |
| 305 | * Spurious link_status interrupts are seen at the time of |
| 306 | * disconnection of a device in RIDA state |
| 307 | */ |
| 308 | if (ab->previous_link_status_state == USB_LINK_ACA_RID_A_8505 && |
| 309 | (lsts == USB_LINK_STD_HOST_NC_8505)) |
| 310 | return 0; |
| 311 | |
| 312 | ab->previous_link_status_state = lsts; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 313 | |
| 314 | switch (lsts) { |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 315 | case USB_LINK_ACA_RID_B_8505: |
| 316 | event = UX500_MUSB_RIDB; |
| 317 | case USB_LINK_NOT_CONFIGURED_8505: |
| 318 | case USB_LINK_RESERVED0_8505: |
| 319 | case USB_LINK_RESERVED1_8505: |
| 320 | case USB_LINK_RESERVED2_8505: |
| 321 | case USB_LINK_RESERVED3_8505: |
| 322 | ab->mode = USB_IDLE; |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 323 | ab->phy.otg->default_a = false; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 324 | ab->vbus_draw = 0; |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 325 | if (event != UX500_MUSB_RIDB) |
| 326 | event = UX500_MUSB_NONE; |
| 327 | /* |
| 328 | * Fallback to default B_IDLE as nothing |
| 329 | * is connected |
| 330 | */ |
| 331 | ab->phy.state = OTG_STATE_B_IDLE; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 332 | break; |
| 333 | |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 334 | case USB_LINK_ACA_RID_C_NM_8505: |
| 335 | event = UX500_MUSB_RIDC; |
| 336 | case USB_LINK_STD_HOST_NC_8505: |
| 337 | case USB_LINK_STD_HOST_C_NS_8505: |
| 338 | case USB_LINK_STD_HOST_C_S_8505: |
| 339 | case USB_LINK_CDP_8505: |
| 340 | if (ab->mode == USB_IDLE) { |
| 341 | ab->mode = USB_PERIPHERAL; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 342 | ab8500_usb_peri_phy_en(ab); |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 343 | atomic_notifier_call_chain(&ab->phy.notifier, |
| 344 | UX500_MUSB_PREPARE, &ab->vbus_draw); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 345 | } |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 346 | if (event != UX500_MUSB_RIDC) |
| 347 | event = UX500_MUSB_VBUS; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 348 | break; |
| 349 | |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 350 | case USB_LINK_ACA_RID_A_8505: |
| 351 | case USB_LINK_ACA_DOCK_CHGR_8505: |
| 352 | event = UX500_MUSB_RIDA; |
| 353 | case USB_LINK_HM_IDGND_8505: |
| 354 | if (ab->mode == USB_IDLE) { |
| 355 | ab->mode = USB_HOST; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 356 | ab8500_usb_host_phy_en(ab); |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 357 | atomic_notifier_call_chain(&ab->phy.notifier, |
| 358 | UX500_MUSB_PREPARE, &ab->vbus_draw); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 359 | } |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 360 | ab->phy.otg->default_a = true; |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 361 | if (event != UX500_MUSB_RIDA) |
| 362 | event = UX500_MUSB_ID; |
| 363 | atomic_notifier_call_chain(&ab->phy.notifier, |
| 364 | event, &ab->vbus_draw); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 365 | break; |
| 366 | |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 367 | case USB_LINK_DEDICATED_CHG_8505: |
| 368 | ab->mode = USB_DEDICATED_CHG; |
| 369 | event = UX500_MUSB_CHARGER; |
| 370 | atomic_notifier_call_chain(&ab->phy.notifier, |
| 371 | event, &ab->vbus_draw); |
| 372 | break; |
| 373 | |
| 374 | default: |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 375 | break; |
| 376 | } |
| 377 | |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 378 | return 0; |
| 379 | } |
| 380 | |
| 381 | static int ab8500_usb_link_status_update(struct ab8500_usb *ab, |
| 382 | enum ab8500_usb_link_status lsts) |
| 383 | { |
| 384 | enum ux500_musb_vbus_id_status event = 0; |
| 385 | |
| 386 | dev_dbg(ab->dev, "ab8500_usb_link_status_update %d\n", lsts); |
| 387 | |
| 388 | /* |
| 389 | * Spurious link_status interrupts are seen in case of a |
| 390 | * disconnection of a device in IDGND and RIDA stage |
| 391 | */ |
| 392 | if (ab->previous_link_status_state == USB_LINK_HM_IDGND_8500 && |
| 393 | (lsts == USB_LINK_STD_HOST_C_NS_8500 || |
| 394 | lsts == USB_LINK_STD_HOST_NC_8500)) |
| 395 | return 0; |
| 396 | |
| 397 | if (ab->previous_link_status_state == USB_LINK_ACA_RID_A_8500 && |
| 398 | lsts == USB_LINK_STD_HOST_NC_8500) |
| 399 | return 0; |
| 400 | |
| 401 | ab->previous_link_status_state = lsts; |
| 402 | |
| 403 | switch (lsts) { |
| 404 | case USB_LINK_ACA_RID_B_8500: |
| 405 | event = UX500_MUSB_RIDB; |
| 406 | case USB_LINK_NOT_CONFIGURED_8500: |
| 407 | case USB_LINK_NOT_VALID_LINK_8500: |
| 408 | ab->mode = USB_IDLE; |
| 409 | ab->phy.otg->default_a = false; |
| 410 | ab->vbus_draw = 0; |
| 411 | if (event != UX500_MUSB_RIDB) |
| 412 | event = UX500_MUSB_NONE; |
| 413 | /* Fallback to default B_IDLE as nothing is connected */ |
| 414 | ab->phy.state = OTG_STATE_B_IDLE; |
| 415 | break; |
| 416 | |
| 417 | case USB_LINK_ACA_RID_C_NM_8500: |
| 418 | case USB_LINK_ACA_RID_C_HS_8500: |
| 419 | case USB_LINK_ACA_RID_C_HS_CHIRP_8500: |
| 420 | event = UX500_MUSB_RIDC; |
| 421 | case USB_LINK_STD_HOST_NC_8500: |
| 422 | case USB_LINK_STD_HOST_C_NS_8500: |
| 423 | case USB_LINK_STD_HOST_C_S_8500: |
| 424 | case USB_LINK_HOST_CHG_NM_8500: |
| 425 | case USB_LINK_HOST_CHG_HS_8500: |
| 426 | case USB_LINK_HOST_CHG_HS_CHIRP_8500: |
| 427 | if (ab->mode == USB_IDLE) { |
| 428 | ab->mode = USB_PERIPHERAL; |
| 429 | ab8500_usb_peri_phy_en(ab); |
| 430 | atomic_notifier_call_chain(&ab->phy.notifier, |
| 431 | UX500_MUSB_PREPARE, &ab->vbus_draw); |
| 432 | } |
| 433 | if (event != UX500_MUSB_RIDC) |
| 434 | event = UX500_MUSB_VBUS; |
| 435 | break; |
| 436 | |
| 437 | case USB_LINK_ACA_RID_A_8500: |
| 438 | event = UX500_MUSB_RIDA; |
| 439 | case USB_LINK_HM_IDGND_8500: |
| 440 | if (ab->mode == USB_IDLE) { |
| 441 | ab->mode = USB_HOST; |
| 442 | ab8500_usb_host_phy_en(ab); |
| 443 | atomic_notifier_call_chain(&ab->phy.notifier, |
| 444 | UX500_MUSB_PREPARE, &ab->vbus_draw); |
| 445 | } |
| 446 | ab->phy.otg->default_a = true; |
| 447 | if (event != UX500_MUSB_RIDA) |
| 448 | event = UX500_MUSB_ID; |
| 449 | atomic_notifier_call_chain(&ab->phy.notifier, |
| 450 | event, &ab->vbus_draw); |
| 451 | break; |
| 452 | |
| 453 | case USB_LINK_DEDICATED_CHG_8500: |
| 454 | ab->mode = USB_DEDICATED_CHG; |
| 455 | event = UX500_MUSB_CHARGER; |
| 456 | atomic_notifier_call_chain(&ab->phy.notifier, |
| 457 | event, &ab->vbus_draw); |
| 458 | break; |
| 459 | |
| 460 | case USB_LINK_RESERVED_8500: |
| 461 | break; |
| 462 | } |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 463 | |
| 464 | return 0; |
| 465 | } |
| 466 | |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 467 | /* |
| 468 | * Connection Sequence: |
| 469 | * 1. Link Status Interrupt |
| 470 | * 2. Enable AB clock |
| 471 | * 3. Enable AB regulators |
| 472 | * 4. Enable USB phy |
| 473 | * 5. Reset the musb controller |
| 474 | * 6. Switch the ULPI GPIO pins to fucntion mode |
| 475 | * 7. Enable the musb Peripheral5 clock |
| 476 | * 8. Restore MUSB context |
| 477 | */ |
| 478 | static int abx500_usb_link_status_update(struct ab8500_usb *ab) |
| 479 | { |
| 480 | u8 reg; |
| 481 | int ret = 0; |
| 482 | |
| 483 | if (is_ab8500(ab->ab8500)) { |
| 484 | enum ab8500_usb_link_status lsts; |
| 485 | |
| 486 | abx500_get_register_interruptible(ab->dev, |
| 487 | AB8500_USB, AB8500_USB_LINE_STAT_REG, ®); |
| 488 | lsts = (reg >> 3) & 0x0F; |
| 489 | ret = ab8500_usb_link_status_update(ab, lsts); |
| 490 | } else if (is_ab8505(ab->ab8500)) { |
| 491 | enum ab8505_usb_link_status lsts; |
| 492 | |
| 493 | abx500_get_register_interruptible(ab->dev, |
| 494 | AB8500_USB, AB8505_USB_LINE_STAT_REG, ®); |
| 495 | lsts = (reg >> 3) & 0x1F; |
| 496 | ret = ab8505_usb_link_status_update(ab, lsts); |
| 497 | } |
| 498 | |
| 499 | return ret; |
| 500 | } |
| 501 | |
| 502 | /* |
| 503 | * Disconnection Sequence: |
| 504 | * 1. Disconect Interrupt |
| 505 | * 2. Disable regulators |
| 506 | * 3. Disable AB clock |
| 507 | * 4. Disable the Phy |
| 508 | * 5. Link Status Interrupt |
| 509 | * 6. Disable Musb Clock |
| 510 | */ |
| 511 | static irqreturn_t ab8500_usb_disconnect_irq(int irq, void *data) |
| 512 | { |
| 513 | struct ab8500_usb *ab = (struct ab8500_usb *) data; |
| 514 | enum usb_phy_events event = UX500_MUSB_NONE; |
| 515 | |
| 516 | /* Link status will not be updated till phy is disabled. */ |
| 517 | if (ab->mode == USB_HOST) { |
| 518 | ab->phy.otg->default_a = false; |
| 519 | ab->vbus_draw = 0; |
| 520 | atomic_notifier_call_chain(&ab->phy.notifier, |
| 521 | event, &ab->vbus_draw); |
| 522 | ab8500_usb_host_phy_dis(ab); |
| 523 | ab->mode = USB_IDLE; |
| 524 | } |
| 525 | |
| 526 | if (ab->mode == USB_PERIPHERAL) { |
| 527 | atomic_notifier_call_chain(&ab->phy.notifier, |
| 528 | event, &ab->vbus_draw); |
| 529 | ab8500_usb_peri_phy_dis(ab); |
| 530 | atomic_notifier_call_chain(&ab->phy.notifier, |
| 531 | UX500_MUSB_CLEAN, &ab->vbus_draw); |
| 532 | ab->mode = USB_IDLE; |
| 533 | ab->phy.otg->default_a = false; |
| 534 | ab->vbus_draw = 0; |
| 535 | } |
| 536 | |
| 537 | if (is_ab8500_2p0(ab->ab8500)) { |
| 538 | if (ab->mode == USB_DEDICATED_CHG) { |
| 539 | ab8500_usb_wd_linkstatus(ab, |
| 540 | AB8500_BIT_PHY_CTRL_DEVICE_EN); |
| 541 | abx500_mask_and_set_register_interruptible(ab->dev, |
| 542 | AB8500_USB, AB8500_USB_PHY_CTRL_REG, |
| 543 | AB8500_BIT_PHY_CTRL_DEVICE_EN, 0); |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | return IRQ_HANDLED; |
| 548 | } |
| 549 | |
| 550 | static irqreturn_t ab8500_usb_link_status_irq(int irq, void *data) |
| 551 | { |
| 552 | struct ab8500_usb *ab = (struct ab8500_usb *) data; |
| 553 | |
| 554 | abx500_usb_link_status_update(ab); |
| 555 | |
| 556 | return IRQ_HANDLED; |
| 557 | } |
| 558 | |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 559 | static void ab8500_usb_delayed_work(struct work_struct *work) |
| 560 | { |
| 561 | struct ab8500_usb *ab = container_of(work, struct ab8500_usb, |
| 562 | dwork.work); |
| 563 | |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 564 | abx500_usb_link_status_update(ab); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | static void ab8500_usb_phy_disable_work(struct work_struct *work) |
| 568 | { |
| 569 | struct ab8500_usb *ab = container_of(work, struct ab8500_usb, |
| 570 | phy_dis_work); |
| 571 | |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 572 | if (!ab->phy.otg->host) |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 573 | ab8500_usb_host_phy_dis(ab); |
| 574 | |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 575 | if (!ab->phy.otg->gadget) |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 576 | ab8500_usb_peri_phy_dis(ab); |
| 577 | } |
| 578 | |
Sakethram Bommisetti | c2a0ab6 | 2013-04-03 10:45:05 +0200 | [diff] [blame] | 579 | static unsigned ab8500_eyediagram_workaroud(struct ab8500_usb *ab, unsigned mA) |
| 580 | { |
| 581 | /* |
| 582 | * AB8500 V2 has eye diagram issues when drawing more than 100mA from |
| 583 | * VBUS. Set charging current to 100mA in case of standard host |
| 584 | */ |
| 585 | if (is_ab8500_2p0_or_earlier(ab->ab8500)) |
| 586 | if (mA > 100) |
| 587 | mA = 100; |
| 588 | |
| 589 | return mA; |
| 590 | } |
| 591 | |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 592 | static int ab8500_usb_set_power(struct usb_phy *phy, unsigned mA) |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 593 | { |
| 594 | struct ab8500_usb *ab; |
| 595 | |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 596 | if (!phy) |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 597 | return -ENODEV; |
| 598 | |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 599 | ab = phy_to_ab(phy); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 600 | |
Sakethram Bommisetti | c2a0ab6 | 2013-04-03 10:45:05 +0200 | [diff] [blame] | 601 | mA = ab8500_eyediagram_workaroud(ab, mA); |
| 602 | |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 603 | ab->vbus_draw = mA; |
| 604 | |
Fabio Baltieri | 77f4396 | 2013-04-03 10:45:10 +0200 | [diff] [blame] | 605 | atomic_notifier_call_chain(&ab->phy.notifier, |
| 606 | UX500_MUSB_VBUS, &ab->vbus_draw); |
| 607 | |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 608 | return 0; |
| 609 | } |
| 610 | |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame] | 611 | static int ab8500_usb_set_suspend(struct usb_phy *x, int suspend) |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 612 | { |
| 613 | /* TODO */ |
| 614 | return 0; |
| 615 | } |
| 616 | |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 617 | static int ab8500_usb_set_peripheral(struct usb_otg *otg, |
| 618 | struct usb_gadget *gadget) |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 619 | { |
| 620 | struct ab8500_usb *ab; |
| 621 | |
| 622 | if (!otg) |
| 623 | return -ENODEV; |
| 624 | |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 625 | ab = phy_to_ab(otg->phy); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 626 | |
| 627 | /* Some drivers call this function in atomic context. |
| 628 | * Do not update ab8500 registers directly till this |
| 629 | * is fixed. |
| 630 | */ |
| 631 | |
| 632 | if (!gadget) { |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 633 | otg->gadget = NULL; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 634 | schedule_work(&ab->phy_dis_work); |
| 635 | } else { |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 636 | otg->gadget = gadget; |
| 637 | otg->phy->state = OTG_STATE_B_IDLE; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 638 | |
| 639 | /* Phy will not be enabled if cable is already |
| 640 | * plugged-in. Schedule to enable phy. |
| 641 | * Use same delay to avoid any race condition. |
| 642 | */ |
| 643 | schedule_delayed_work(&ab->dwork, ab->link_status_wait); |
| 644 | } |
| 645 | |
| 646 | return 0; |
| 647 | } |
| 648 | |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 649 | static int ab8500_usb_set_host(struct usb_otg *otg, struct usb_bus *host) |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 650 | { |
| 651 | struct ab8500_usb *ab; |
| 652 | |
| 653 | if (!otg) |
| 654 | return -ENODEV; |
| 655 | |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 656 | ab = phy_to_ab(otg->phy); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 657 | |
| 658 | /* Some drivers call this function in atomic context. |
| 659 | * Do not update ab8500 registers directly till this |
| 660 | * is fixed. |
| 661 | */ |
| 662 | |
| 663 | if (!host) { |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 664 | otg->host = NULL; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 665 | schedule_work(&ab->phy_dis_work); |
| 666 | } else { |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 667 | otg->host = host; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 668 | /* Phy will not be enabled if cable is already |
| 669 | * plugged-in. Schedule to enable phy. |
| 670 | * Use same delay to avoid any race condition. |
| 671 | */ |
| 672 | schedule_delayed_work(&ab->dwork, ab->link_status_wait); |
| 673 | } |
| 674 | |
| 675 | return 0; |
| 676 | } |
| 677 | |
Fabio Baltieri | e65b36c | 2013-04-03 10:45:06 +0200 | [diff] [blame] | 678 | static int ab8500_usb_regulator_get(struct ab8500_usb *ab) |
| 679 | { |
| 680 | int err; |
| 681 | |
| 682 | ab->v_ape = devm_regulator_get(ab->dev, "v-ape"); |
| 683 | if (IS_ERR(ab->v_ape)) { |
| 684 | dev_err(ab->dev, "Could not get v-ape supply\n"); |
| 685 | err = PTR_ERR(ab->v_ape); |
| 686 | return err; |
| 687 | } |
| 688 | |
| 689 | ab->v_ulpi = devm_regulator_get(ab->dev, "vddulpivio18"); |
| 690 | if (IS_ERR(ab->v_ulpi)) { |
| 691 | dev_err(ab->dev, "Could not get vddulpivio18 supply\n"); |
| 692 | err = PTR_ERR(ab->v_ulpi); |
| 693 | return err; |
| 694 | } |
| 695 | |
| 696 | ab->v_musb = devm_regulator_get(ab->dev, "musb_1v8"); |
| 697 | if (IS_ERR(ab->v_musb)) { |
| 698 | dev_err(ab->dev, "Could not get musb_1v8 supply\n"); |
| 699 | err = PTR_ERR(ab->v_musb); |
| 700 | return err; |
| 701 | } |
| 702 | |
| 703 | return 0; |
| 704 | } |
| 705 | |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 706 | static int ab8500_usb_irq_setup(struct platform_device *pdev, |
| 707 | struct ab8500_usb *ab) |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 708 | { |
| 709 | int err; |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 710 | int irq; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 711 | |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 712 | irq = platform_get_irq_byname(pdev, "USB_LINK_STATUS"); |
| 713 | if (irq < 0) { |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 714 | dev_err(&pdev->dev, "Link status irq not found\n"); |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 715 | return irq; |
| 716 | } |
| 717 | err = devm_request_threaded_irq(&pdev->dev, irq, NULL, |
| 718 | ab8500_usb_link_status_irq, |
| 719 | IRQF_NO_SUSPEND | IRQF_SHARED, "usb-link-status", ab); |
| 720 | if (err < 0) { |
| 721 | dev_err(ab->dev, "request_irq failed for link status irq\n"); |
| 722 | return err; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 723 | } |
| 724 | |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 725 | irq = platform_get_irq_byname(pdev, "ID_WAKEUP_F"); |
| 726 | if (irq < 0) { |
| 727 | dev_err(&pdev->dev, "ID fall irq not found\n"); |
| 728 | return irq; |
| 729 | } |
| 730 | err = devm_request_threaded_irq(&pdev->dev, irq, NULL, |
| 731 | ab8500_usb_disconnect_irq, |
| 732 | IRQF_NO_SUSPEND | IRQF_SHARED, "usb-id-fall", ab); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 733 | if (err < 0) { |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 734 | dev_err(ab->dev, "request_irq failed for ID fall irq\n"); |
| 735 | return err; |
| 736 | } |
| 737 | |
| 738 | irq = platform_get_irq_byname(pdev, "VBUS_DET_F"); |
| 739 | if (irq < 0) { |
| 740 | dev_err(&pdev->dev, "VBUS fall irq not found\n"); |
| 741 | return irq; |
| 742 | } |
| 743 | err = devm_request_threaded_irq(&pdev->dev, irq, NULL, |
| 744 | ab8500_usb_disconnect_irq, |
| 745 | IRQF_NO_SUSPEND | IRQF_SHARED, "usb-vbus-fall", ab); |
| 746 | if (err < 0) { |
| 747 | dev_err(ab->dev, "request_irq failed for Vbus fall irq\n"); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 748 | return err; |
| 749 | } |
| 750 | |
| 751 | return 0; |
| 752 | } |
| 753 | |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 754 | static int ab8500_usb_probe(struct platform_device *pdev) |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 755 | { |
| 756 | struct ab8500_usb *ab; |
Fabio Baltieri | 73f226c | 2013-03-08 10:27:08 +0800 | [diff] [blame] | 757 | struct ab8500 *ab8500; |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 758 | struct usb_otg *otg; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 759 | int err; |
| 760 | int rev; |
| 761 | |
Fabio Baltieri | 73f226c | 2013-03-08 10:27:08 +0800 | [diff] [blame] | 762 | ab8500 = dev_get_drvdata(pdev->dev.parent); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 763 | rev = abx500_get_chip_id(&pdev->dev); |
Fabio Baltieri | 73f226c | 2013-03-08 10:27:08 +0800 | [diff] [blame] | 764 | |
| 765 | if (is_ab8500_1p1_or_earlier(ab8500)) { |
| 766 | dev_err(&pdev->dev, "Unsupported AB8500 chip rev=%d\n", rev); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 767 | return -ENODEV; |
| 768 | } |
| 769 | |
Fabio Baltieri | 81ef672 | 2013-04-03 10:45:03 +0200 | [diff] [blame] | 770 | ab = devm_kzalloc(&pdev->dev, sizeof(*ab), GFP_KERNEL); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 771 | if (!ab) |
| 772 | return -ENOMEM; |
| 773 | |
Fabio Baltieri | 81ef672 | 2013-04-03 10:45:03 +0200 | [diff] [blame] | 774 | otg = devm_kzalloc(&pdev->dev, sizeof(*otg), GFP_KERNEL); |
| 775 | if (!otg) |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 776 | return -ENOMEM; |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 777 | |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 778 | ab->dev = &pdev->dev; |
Fabio Baltieri | 73f226c | 2013-03-08 10:27:08 +0800 | [diff] [blame] | 779 | ab->ab8500 = ab8500; |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 780 | ab->phy.dev = ab->dev; |
| 781 | ab->phy.otg = otg; |
| 782 | ab->phy.label = "ab8500"; |
| 783 | ab->phy.set_suspend = ab8500_usb_set_suspend; |
| 784 | ab->phy.set_power = ab8500_usb_set_power; |
| 785 | ab->phy.state = OTG_STATE_UNDEFINED; |
| 786 | |
| 787 | otg->phy = &ab->phy; |
| 788 | otg->set_host = ab8500_usb_set_host; |
| 789 | otg->set_peripheral = ab8500_usb_set_peripheral; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 790 | |
| 791 | platform_set_drvdata(pdev, ab); |
| 792 | |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 793 | ATOMIC_INIT_NOTIFIER_HEAD(&ab->phy.notifier); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 794 | |
| 795 | /* v1: Wait for link status to become stable. |
| 796 | * all: Updates form set_host and set_peripheral as they are atomic. |
| 797 | */ |
| 798 | INIT_DELAYED_WORK(&ab->dwork, ab8500_usb_delayed_work); |
| 799 | |
| 800 | /* all: Disable phy when called from set_host and set_peripheral */ |
| 801 | INIT_WORK(&ab->phy_dis_work, ab8500_usb_phy_disable_work); |
| 802 | |
Fabio Baltieri | e65b36c | 2013-04-03 10:45:06 +0200 | [diff] [blame] | 803 | err = ab8500_usb_regulator_get(ab); |
| 804 | if (err) |
| 805 | return err; |
| 806 | |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 807 | err = ab8500_usb_irq_setup(pdev, ab); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 808 | if (err < 0) |
Fabio Baltieri | 81ef672 | 2013-04-03 10:45:03 +0200 | [diff] [blame] | 809 | return err; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 810 | |
Kishon Vijay Abraham I | 662dca5 | 2012-06-22 17:02:46 +0530 | [diff] [blame] | 811 | err = usb_add_phy(&ab->phy, USB_PHY_TYPE_USB2); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 812 | if (err) { |
| 813 | dev_err(&pdev->dev, "Can't register transceiver\n"); |
Fabio Baltieri | 81ef672 | 2013-04-03 10:45:03 +0200 | [diff] [blame] | 814 | return err; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 815 | } |
| 816 | |
Sakethram Bommisetti | 7124631 | 2013-04-03 10:45:04 +0200 | [diff] [blame] | 817 | /* Phy tuning values for AB8500 */ |
| 818 | if (!is_ab8500_2p0_or_earlier(ab->ab8500)) { |
| 819 | /* Enable the PBT/Bank 0x12 access */ |
| 820 | err = abx500_set_register_interruptible(ab->dev, |
| 821 | AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS, 0x01); |
| 822 | if (err < 0) |
| 823 | dev_err(ab->dev, "Failed to enable bank12 access err=%d\n", |
| 824 | err); |
| 825 | |
| 826 | err = abx500_set_register_interruptible(ab->dev, |
| 827 | AB8500_DEBUG, AB8500_USB_PHY_TUNE1, 0xC8); |
| 828 | if (err < 0) |
| 829 | dev_err(ab->dev, "Failed to set PHY_TUNE1 register err=%d\n", |
| 830 | err); |
| 831 | |
| 832 | err = abx500_set_register_interruptible(ab->dev, |
| 833 | AB8500_DEBUG, AB8500_USB_PHY_TUNE2, 0x00); |
| 834 | if (err < 0) |
| 835 | dev_err(ab->dev, "Failed to set PHY_TUNE2 register err=%d\n", |
| 836 | err); |
| 837 | |
| 838 | err = abx500_set_register_interruptible(ab->dev, |
| 839 | AB8500_DEBUG, AB8500_USB_PHY_TUNE3, 0x78); |
| 840 | if (err < 0) |
| 841 | dev_err(ab->dev, "Failed to set PHY_TUNE3 regester err=%d\n", |
| 842 | err); |
| 843 | |
| 844 | /* Switch to normal mode/disable Bank 0x12 access */ |
| 845 | err = abx500_set_register_interruptible(ab->dev, |
| 846 | AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS, 0x00); |
| 847 | if (err < 0) |
| 848 | dev_err(ab->dev, "Failed to switch bank12 access err=%d\n", |
| 849 | err); |
| 850 | } |
| 851 | |
| 852 | /* Phy tuning values for AB8505 */ |
| 853 | if (is_ab8505(ab->ab8500)) { |
| 854 | /* Enable the PBT/Bank 0x12 access */ |
| 855 | err = abx500_mask_and_set_register_interruptible(ab->dev, |
| 856 | AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS, |
| 857 | 0x01, 0x01); |
| 858 | if (err < 0) |
| 859 | dev_err(ab->dev, "Failed to enable bank12 access err=%d\n", |
| 860 | err); |
| 861 | |
| 862 | err = abx500_mask_and_set_register_interruptible(ab->dev, |
| 863 | AB8500_DEBUG, AB8500_USB_PHY_TUNE1, |
| 864 | 0xC8, 0xC8); |
| 865 | if (err < 0) |
| 866 | dev_err(ab->dev, "Failed to set PHY_TUNE1 register err=%d\n", |
| 867 | err); |
| 868 | |
| 869 | err = abx500_mask_and_set_register_interruptible(ab->dev, |
| 870 | AB8500_DEBUG, AB8500_USB_PHY_TUNE2, |
| 871 | 0x60, 0x60); |
| 872 | if (err < 0) |
| 873 | dev_err(ab->dev, "Failed to set PHY_TUNE2 register err=%d\n", |
| 874 | err); |
| 875 | |
| 876 | err = abx500_mask_and_set_register_interruptible(ab->dev, |
| 877 | AB8500_DEBUG, AB8500_USB_PHY_TUNE3, |
| 878 | 0xFC, 0x80); |
| 879 | |
| 880 | if (err < 0) |
| 881 | dev_err(ab->dev, "Failed to set PHY_TUNE3 regester err=%d\n", |
| 882 | err); |
| 883 | |
| 884 | /* Switch to normal mode/disable Bank 0x12 access */ |
| 885 | err = abx500_mask_and_set_register_interruptible(ab->dev, |
| 886 | AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS, |
| 887 | 0x00, 0x00); |
| 888 | if (err < 0) |
| 889 | dev_err(ab->dev, "Failed to switch bank12 access err=%d\n", |
| 890 | err); |
| 891 | } |
| 892 | |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 893 | /* Needed to enable ID detection. */ |
| 894 | ab8500_usb_wd_workaround(ab); |
| 895 | |
Fabio Baltieri | 73f226c | 2013-03-08 10:27:08 +0800 | [diff] [blame] | 896 | dev_info(&pdev->dev, "revision 0x%2x driver initialized\n", rev); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 897 | |
| 898 | return 0; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 899 | } |
| 900 | |
Bill Pemberton | fb4e98a | 2012-11-19 13:26:20 -0500 | [diff] [blame] | 901 | static int ab8500_usb_remove(struct platform_device *pdev) |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 902 | { |
| 903 | struct ab8500_usb *ab = platform_get_drvdata(pdev); |
| 904 | |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 905 | cancel_delayed_work_sync(&ab->dwork); |
| 906 | |
| 907 | cancel_work_sync(&ab->phy_dis_work); |
| 908 | |
Kishon Vijay Abraham I | 662dca5 | 2012-06-22 17:02:46 +0530 | [diff] [blame] | 909 | usb_remove_phy(&ab->phy); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 910 | |
Mian Yousaf Kaukab | f5ef7b4 | 2013-04-03 10:45:09 +0200 | [diff] [blame] | 911 | if (ab->mode == USB_HOST) |
| 912 | ab8500_usb_host_phy_dis(ab); |
| 913 | else if (ab->mode == USB_PERIPHERAL) |
| 914 | ab8500_usb_peri_phy_dis(ab); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 915 | |
| 916 | platform_set_drvdata(pdev, NULL); |
| 917 | |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 918 | return 0; |
| 919 | } |
| 920 | |
| 921 | static struct platform_driver ab8500_usb_driver = { |
| 922 | .probe = ab8500_usb_probe, |
Bill Pemberton | 7690417 | 2012-11-19 13:21:08 -0500 | [diff] [blame] | 923 | .remove = ab8500_usb_remove, |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 924 | .driver = { |
| 925 | .name = "ab8500-usb", |
| 926 | .owner = THIS_MODULE, |
| 927 | }, |
| 928 | }; |
| 929 | |
| 930 | static int __init ab8500_usb_init(void) |
| 931 | { |
| 932 | return platform_driver_register(&ab8500_usb_driver); |
| 933 | } |
| 934 | subsys_initcall(ab8500_usb_init); |
| 935 | |
| 936 | static void __exit ab8500_usb_exit(void) |
| 937 | { |
| 938 | platform_driver_unregister(&ab8500_usb_driver); |
| 939 | } |
| 940 | module_exit(ab8500_usb_exit); |
| 941 | |
| 942 | MODULE_ALIAS("platform:ab8500_usb"); |
| 943 | MODULE_AUTHOR("ST-Ericsson AB"); |
| 944 | MODULE_DESCRIPTION("AB8500 usb transceiver driver"); |
| 945 | MODULE_LICENSE("GPL"); |