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