Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 1 | /* |
| 2 | * drivers/usb/otg/ab8500_usb.c |
| 3 | * |
Fabio Baltieri | 0c380c0 | 2013-05-15 14:03:32 +0200 | [diff] [blame^] | 4 | * USB transceiver driver for AB8500 family chips |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 5 | * |
Fabio Baltieri | 0c380c0 | 2013-05-15 14:03:32 +0200 | [diff] [blame^] | 6 | * Copyright (C) 2010-2013 ST-Ericsson AB |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 7 | * Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com> |
Fabio Baltieri | 0c380c0 | 2013-05-15 14:03:32 +0200 | [diff] [blame^] | 8 | * Avinash Kumar <avinash.kumar@stericsson.com> |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/platform_device.h> |
| 28 | #include <linux/usb/otg.h> |
| 29 | #include <linux/slab.h> |
| 30 | #include <linux/notifier.h> |
| 31 | #include <linux/interrupt.h> |
| 32 | #include <linux/delay.h> |
Mian Yousaf Kaukab | d0ed064 | 2013-05-15 14:03:26 +0200 | [diff] [blame] | 33 | #include <linux/clk.h> |
| 34 | #include <linux/err.h> |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 35 | #include <linux/mfd/abx500.h> |
Linus Walleij | ee66e65 | 2011-12-02 14:16:33 +0100 | [diff] [blame] | 36 | #include <linux/mfd/abx500/ab8500.h> |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 37 | #include <linux/usb/musb-ux500.h> |
Fabio Baltieri | e65b36c | 2013-04-03 10:45:06 +0200 | [diff] [blame] | 38 | #include <linux/regulator/consumer.h> |
Patrice Chotard | 899f0f5 | 2013-04-03 10:45:11 +0200 | [diff] [blame] | 39 | #include <linux/pinctrl/consumer.h> |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 40 | |
Sakethram Bommisetti | 7124631 | 2013-04-03 10:45:04 +0200 | [diff] [blame] | 41 | /* Bank AB8500_SYS_CTRL2_BLOCK */ |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 42 | #define AB8500_MAIN_WD_CTRL_REG 0x01 |
Sakethram Bommisetti | 7124631 | 2013-04-03 10:45:04 +0200 | [diff] [blame] | 43 | |
| 44 | /* Bank AB8500_USB */ |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 45 | #define AB8500_USB_LINE_STAT_REG 0x80 |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 46 | #define AB8505_USB_LINE_STAT_REG 0x94 |
Fabio Baltieri | 0c380c0 | 2013-05-15 14:03:32 +0200 | [diff] [blame^] | 47 | #define AB8540_USB_LINK_STAT_REG 0x94 |
| 48 | #define AB8540_USB_OTG_CTL_REG 0x87 |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 49 | #define AB8500_USB_PHY_CTRL_REG 0x8A |
Fabio Baltieri | 0c380c0 | 2013-05-15 14:03:32 +0200 | [diff] [blame^] | 50 | #define AB8540_VBUS_CTRL_REG 0x82 |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 51 | |
Sakethram Bommisetti | 7124631 | 2013-04-03 10:45:04 +0200 | [diff] [blame] | 52 | /* Bank AB8500_DEVELOPMENT */ |
| 53 | #define AB8500_BANK12_ACCESS 0x00 |
| 54 | |
| 55 | /* Bank AB8500_DEBUG */ |
Fabio Baltieri | 0c380c0 | 2013-05-15 14:03:32 +0200 | [diff] [blame^] | 56 | #define AB8540_DEBUG 0x32 |
Sakethram Bommisetti | 7124631 | 2013-04-03 10:45:04 +0200 | [diff] [blame] | 57 | #define AB8500_USB_PHY_TUNE1 0x05 |
| 58 | #define AB8500_USB_PHY_TUNE2 0x06 |
| 59 | #define AB8500_USB_PHY_TUNE3 0x07 |
| 60 | |
Fabio Baltieri | 0c380c0 | 2013-05-15 14:03:32 +0200 | [diff] [blame^] | 61 | /* Bank AB8500_INTERRUPT */ |
| 62 | #define AB8500_IT_SOURCE2_REG 0x01 |
| 63 | |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 64 | #define AB8500_BIT_OTG_STAT_ID (1 << 0) |
| 65 | #define AB8500_BIT_PHY_CTRL_HOST_EN (1 << 0) |
| 66 | #define AB8500_BIT_PHY_CTRL_DEVICE_EN (1 << 1) |
| 67 | #define AB8500_BIT_WD_CTRL_ENABLE (1 << 0) |
| 68 | #define AB8500_BIT_WD_CTRL_KICK (1 << 1) |
Fabio Baltieri | 0c380c0 | 2013-05-15 14:03:32 +0200 | [diff] [blame^] | 69 | #define AB8500_BIT_SOURCE2_VBUSDET (1 << 7) |
| 70 | #define AB8540_BIT_OTG_CTL_VBUS_VALID_ENA (1 << 0) |
| 71 | #define AB8540_BIT_OTG_CTL_ID_HOST_ENA (1 << 1) |
| 72 | #define AB8540_BIT_OTG_CTL_ID_DEV_ENA (1 << 5) |
| 73 | #define AB8540_BIT_VBUS_CTRL_CHARG_DET_ENA (1 << 0) |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 74 | |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 75 | #define AB8500_WD_KICK_DELAY_US 100 /* usec */ |
| 76 | #define AB8500_WD_V11_DISABLE_DELAY_US 100 /* usec */ |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 77 | #define AB8500_V20_31952_DISABLE_DELAY_US 100 /* usec */ |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 78 | |
| 79 | /* Usb line status register */ |
| 80 | enum ab8500_usb_link_status { |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 81 | USB_LINK_NOT_CONFIGURED_8500 = 0, |
| 82 | USB_LINK_STD_HOST_NC_8500, |
| 83 | USB_LINK_STD_HOST_C_NS_8500, |
| 84 | USB_LINK_STD_HOST_C_S_8500, |
| 85 | USB_LINK_HOST_CHG_NM_8500, |
| 86 | USB_LINK_HOST_CHG_HS_8500, |
| 87 | USB_LINK_HOST_CHG_HS_CHIRP_8500, |
| 88 | USB_LINK_DEDICATED_CHG_8500, |
| 89 | USB_LINK_ACA_RID_A_8500, |
| 90 | USB_LINK_ACA_RID_B_8500, |
| 91 | USB_LINK_ACA_RID_C_NM_8500, |
| 92 | USB_LINK_ACA_RID_C_HS_8500, |
| 93 | USB_LINK_ACA_RID_C_HS_CHIRP_8500, |
| 94 | USB_LINK_HM_IDGND_8500, |
| 95 | USB_LINK_RESERVED_8500, |
| 96 | USB_LINK_NOT_VALID_LINK_8500, |
| 97 | }; |
| 98 | |
| 99 | enum ab8505_usb_link_status { |
| 100 | USB_LINK_NOT_CONFIGURED_8505 = 0, |
| 101 | USB_LINK_STD_HOST_NC_8505, |
| 102 | USB_LINK_STD_HOST_C_NS_8505, |
| 103 | USB_LINK_STD_HOST_C_S_8505, |
| 104 | USB_LINK_CDP_8505, |
| 105 | USB_LINK_RESERVED0_8505, |
| 106 | USB_LINK_RESERVED1_8505, |
| 107 | USB_LINK_DEDICATED_CHG_8505, |
| 108 | USB_LINK_ACA_RID_A_8505, |
| 109 | USB_LINK_ACA_RID_B_8505, |
| 110 | USB_LINK_ACA_RID_C_NM_8505, |
| 111 | USB_LINK_RESERVED2_8505, |
| 112 | USB_LINK_RESERVED3_8505, |
| 113 | USB_LINK_HM_IDGND_8505, |
| 114 | USB_LINK_CHARGERPORT_NOT_OK_8505, |
| 115 | USB_LINK_CHARGER_DM_HIGH_8505, |
| 116 | USB_LINK_PHYEN_NO_VBUS_NO_IDGND_8505, |
| 117 | USB_LINK_STD_UPSTREAM_NO_IDGNG_NO_VBUS_8505, |
| 118 | USB_LINK_STD_UPSTREAM_8505, |
| 119 | USB_LINK_CHARGER_SE1_8505, |
| 120 | USB_LINK_CARKIT_CHGR_1_8505, |
| 121 | USB_LINK_CARKIT_CHGR_2_8505, |
| 122 | USB_LINK_ACA_DOCK_CHGR_8505, |
| 123 | USB_LINK_SAMSUNG_BOOT_CBL_PHY_EN_8505, |
| 124 | USB_LINK_SAMSUNG_BOOT_CBL_PHY_DISB_8505, |
| 125 | USB_LINK_SAMSUNG_UART_CBL_PHY_EN_8505, |
| 126 | USB_LINK_SAMSUNG_UART_CBL_PHY_DISB_8505, |
| 127 | USB_LINK_MOTOROLA_FACTORY_CBL_PHY_EN_8505, |
| 128 | }; |
| 129 | |
Fabio Baltieri | 0c380c0 | 2013-05-15 14:03:32 +0200 | [diff] [blame^] | 130 | enum ab8540_usb_link_status { |
| 131 | USB_LINK_NOT_CONFIGURED_8540 = 0, |
| 132 | USB_LINK_STD_HOST_NC_8540, |
| 133 | USB_LINK_STD_HOST_C_NS_8540, |
| 134 | USB_LINK_STD_HOST_C_S_8540, |
| 135 | USB_LINK_CDP_8540, |
| 136 | USB_LINK_RESERVED0_8540, |
| 137 | USB_LINK_RESERVED1_8540, |
| 138 | USB_LINK_DEDICATED_CHG_8540, |
| 139 | USB_LINK_ACA_RID_A_8540, |
| 140 | USB_LINK_ACA_RID_B_8540, |
| 141 | USB_LINK_ACA_RID_C_NM_8540, |
| 142 | USB_LINK_RESERVED2_8540, |
| 143 | USB_LINK_RESERVED3_8540, |
| 144 | USB_LINK_HM_IDGND_8540, |
| 145 | USB_LINK_CHARGERPORT_NOT_OK_8540, |
| 146 | USB_LINK_CHARGER_DM_HIGH_8540, |
| 147 | USB_LINK_PHYEN_NO_VBUS_NO_IDGND_8540, |
| 148 | USB_LINK_STD_UPSTREAM_NO_IDGNG_VBUS_8540, |
| 149 | USB_LINK_STD_UPSTREAM_8540, |
| 150 | USB_LINK_CHARGER_SE1_8540, |
| 151 | USB_LINK_CARKIT_CHGR_1_8540, |
| 152 | USB_LINK_CARKIT_CHGR_2_8540, |
| 153 | USB_LINK_ACA_DOCK_CHGR_8540, |
| 154 | USB_LINK_SAMSUNG_BOOT_CBL_PHY_EN_8540, |
| 155 | USB_LINK_SAMSUNG_BOOT_CBL_PHY_DISB_8540, |
| 156 | USB_LINK_SAMSUNG_UART_CBL_PHY_EN_8540, |
| 157 | USB_LINK_SAMSUNG_UART_CBL_PHY_DISB_8540, |
| 158 | USB_LINK_MOTOROLA_FACTORY_CBL_PHY_EN_8540 |
| 159 | }; |
| 160 | |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 161 | enum ab8500_usb_mode { |
| 162 | USB_IDLE = 0, |
| 163 | USB_PERIPHERAL, |
| 164 | USB_HOST, |
| 165 | USB_DEDICATED_CHG |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 166 | }; |
| 167 | |
Fabio Baltieri | bd4c9f0 | 2013-05-15 14:03:31 +0200 | [diff] [blame] | 168 | /* Register USB_LINK_STATUS interrupt */ |
| 169 | #define AB8500_USB_FLAG_USE_LINK_STATUS_IRQ (1 << 0) |
| 170 | /* Register ID_WAKEUP_F interrupt */ |
| 171 | #define AB8500_USB_FLAG_USE_ID_WAKEUP_IRQ (1 << 1) |
| 172 | /* Register VBUS_DET_F interrupt */ |
| 173 | #define AB8500_USB_FLAG_USE_VBUS_DET_IRQ (1 << 2) |
| 174 | /* Driver is using the ab-iddet driver*/ |
| 175 | #define AB8500_USB_FLAG_USE_AB_IDDET (1 << 3) |
| 176 | /* Enable setting regulators voltage */ |
| 177 | #define AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE (1 << 4) |
Fabio Baltieri | 0c380c0 | 2013-05-15 14:03:32 +0200 | [diff] [blame^] | 178 | /* Enable the check_vbus_status workaround */ |
| 179 | #define AB8500_USB_FLAG_USE_CHECK_VBUS_STATUS (1 << 5) |
| 180 | /* Enable the vbus host workaround */ |
| 181 | #define AB8500_USB_FLAG_USE_VBUS_HOST_QUIRK (1 << 6) |
Fabio Baltieri | bd4c9f0 | 2013-05-15 14:03:31 +0200 | [diff] [blame] | 182 | |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 183 | struct ab8500_usb { |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 184 | struct usb_phy phy; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 185 | struct device *dev; |
Fabio Baltieri | 73f226c | 2013-03-08 10:27:08 +0800 | [diff] [blame] | 186 | struct ab8500 *ab8500; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 187 | unsigned vbus_draw; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 188 | struct work_struct phy_dis_work; |
Fabio Baltieri | 0c380c0 | 2013-05-15 14:03:32 +0200 | [diff] [blame^] | 189 | struct work_struct vbus_event_work; |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 190 | enum ab8500_usb_mode mode; |
Mian Yousaf Kaukab | d0ed064 | 2013-05-15 14:03:26 +0200 | [diff] [blame] | 191 | struct clk *sysclk; |
Fabio Baltieri | e65b36c | 2013-04-03 10:45:06 +0200 | [diff] [blame] | 192 | struct regulator *v_ape; |
| 193 | struct regulator *v_musb; |
| 194 | struct regulator *v_ulpi; |
Fabio Baltieri | 54dfbb0 | 2013-04-03 10:45:08 +0200 | [diff] [blame] | 195 | int saved_v_ulpi; |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 196 | int previous_link_status_state; |
Patrice Chotard | 899f0f5 | 2013-04-03 10:45:11 +0200 | [diff] [blame] | 197 | struct pinctrl *pinctrl; |
| 198 | struct pinctrl_state *pins_sleep; |
Fabio Baltieri | 0c380c0 | 2013-05-15 14:03:32 +0200 | [diff] [blame^] | 199 | bool enabled_charging_detection; |
Fabio Baltieri | bd4c9f0 | 2013-05-15 14:03:31 +0200 | [diff] [blame] | 200 | unsigned int flags; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 201 | }; |
| 202 | |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 203 | 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] | 204 | { |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 205 | return container_of(x, struct ab8500_usb, phy); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | static void ab8500_usb_wd_workaround(struct ab8500_usb *ab) |
| 209 | { |
| 210 | abx500_set_register_interruptible(ab->dev, |
| 211 | AB8500_SYS_CTRL2_BLOCK, |
| 212 | AB8500_MAIN_WD_CTRL_REG, |
| 213 | AB8500_BIT_WD_CTRL_ENABLE); |
| 214 | |
| 215 | udelay(AB8500_WD_KICK_DELAY_US); |
| 216 | |
| 217 | abx500_set_register_interruptible(ab->dev, |
| 218 | AB8500_SYS_CTRL2_BLOCK, |
| 219 | AB8500_MAIN_WD_CTRL_REG, |
| 220 | (AB8500_BIT_WD_CTRL_ENABLE |
| 221 | | AB8500_BIT_WD_CTRL_KICK)); |
| 222 | |
Fabio Baltieri | 73f226c | 2013-03-08 10:27:08 +0800 | [diff] [blame] | 223 | udelay(AB8500_WD_V11_DISABLE_DELAY_US); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 224 | |
| 225 | abx500_set_register_interruptible(ab->dev, |
| 226 | AB8500_SYS_CTRL2_BLOCK, |
| 227 | AB8500_MAIN_WD_CTRL_REG, |
| 228 | 0); |
| 229 | } |
| 230 | |
Fabio Baltieri | 54dfbb0 | 2013-04-03 10:45:08 +0200 | [diff] [blame] | 231 | static void ab8500_usb_regulator_enable(struct ab8500_usb *ab) |
| 232 | { |
| 233 | int ret, volt; |
| 234 | |
Fabio Baltieri | 88b1c78 | 2013-04-03 16:02:25 +0200 | [diff] [blame] | 235 | ret = regulator_enable(ab->v_ape); |
| 236 | if (ret) |
| 237 | dev_err(ab->dev, "Failed to enable v-ape\n"); |
Fabio Baltieri | 54dfbb0 | 2013-04-03 10:45:08 +0200 | [diff] [blame] | 238 | |
Fabio Baltieri | bd4c9f0 | 2013-05-15 14:03:31 +0200 | [diff] [blame] | 239 | if (ab->flags & AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE) { |
Fabio Baltieri | 54dfbb0 | 2013-04-03 10:45:08 +0200 | [diff] [blame] | 240 | ab->saved_v_ulpi = regulator_get_voltage(ab->v_ulpi); |
| 241 | if (ab->saved_v_ulpi < 0) |
| 242 | dev_err(ab->dev, "Failed to get v_ulpi voltage\n"); |
| 243 | |
| 244 | ret = regulator_set_voltage(ab->v_ulpi, 1300000, 1350000); |
| 245 | if (ret < 0) |
| 246 | dev_err(ab->dev, "Failed to set the Vintcore to 1.3V, ret=%d\n", |
| 247 | ret); |
| 248 | |
| 249 | ret = regulator_set_optimum_mode(ab->v_ulpi, 28000); |
| 250 | if (ret < 0) |
| 251 | dev_err(ab->dev, "Failed to set optimum mode (ret=%d)\n", |
| 252 | ret); |
| 253 | } |
| 254 | |
Fabio Baltieri | 88b1c78 | 2013-04-03 16:02:25 +0200 | [diff] [blame] | 255 | ret = regulator_enable(ab->v_ulpi); |
| 256 | if (ret) |
| 257 | dev_err(ab->dev, "Failed to enable vddulpivio18\n"); |
Fabio Baltieri | 54dfbb0 | 2013-04-03 10:45:08 +0200 | [diff] [blame] | 258 | |
Fabio Baltieri | bd4c9f0 | 2013-05-15 14:03:31 +0200 | [diff] [blame] | 259 | if (ab->flags & AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE) { |
Fabio Baltieri | 54dfbb0 | 2013-04-03 10:45:08 +0200 | [diff] [blame] | 260 | volt = regulator_get_voltage(ab->v_ulpi); |
| 261 | if ((volt != 1300000) && (volt != 1350000)) |
| 262 | dev_err(ab->dev, "Vintcore is not set to 1.3V volt=%d\n", |
| 263 | volt); |
| 264 | } |
| 265 | |
Fabio Baltieri | 88b1c78 | 2013-04-03 16:02:25 +0200 | [diff] [blame] | 266 | ret = regulator_enable(ab->v_musb); |
| 267 | if (ret) |
| 268 | dev_err(ab->dev, "Failed to enable musb_1v8\n"); |
Fabio Baltieri | 54dfbb0 | 2013-04-03 10:45:08 +0200 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | static void ab8500_usb_regulator_disable(struct ab8500_usb *ab) |
| 272 | { |
| 273 | int ret; |
| 274 | |
| 275 | regulator_disable(ab->v_musb); |
| 276 | |
| 277 | regulator_disable(ab->v_ulpi); |
| 278 | |
| 279 | /* USB is not the only consumer of Vintcore, restore old settings */ |
Fabio Baltieri | bd4c9f0 | 2013-05-15 14:03:31 +0200 | [diff] [blame] | 280 | if (ab->flags & AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE) { |
Fabio Baltieri | 54dfbb0 | 2013-04-03 10:45:08 +0200 | [diff] [blame] | 281 | if (ab->saved_v_ulpi > 0) { |
| 282 | ret = regulator_set_voltage(ab->v_ulpi, |
| 283 | ab->saved_v_ulpi, ab->saved_v_ulpi); |
| 284 | if (ret < 0) |
| 285 | dev_err(ab->dev, "Failed to set the Vintcore to %duV, ret=%d\n", |
| 286 | ab->saved_v_ulpi, ret); |
| 287 | } |
| 288 | |
| 289 | ret = regulator_set_optimum_mode(ab->v_ulpi, 0); |
| 290 | if (ret < 0) |
| 291 | dev_err(ab->dev, "Failed to set optimum mode (ret=%d)\n", |
| 292 | ret); |
| 293 | } |
| 294 | |
| 295 | regulator_disable(ab->v_ape); |
| 296 | } |
| 297 | |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 298 | static void ab8500_usb_wd_linkstatus(struct ab8500_usb *ab, u8 bit) |
| 299 | { |
| 300 | /* Workaround for v2.0 bug # 31952 */ |
| 301 | if (is_ab8500_2p0(ab->ab8500)) { |
| 302 | abx500_mask_and_set_register_interruptible(ab->dev, |
| 303 | AB8500_USB, AB8500_USB_PHY_CTRL_REG, |
| 304 | bit, bit); |
| 305 | udelay(AB8500_V20_31952_DISABLE_DELAY_US); |
| 306 | } |
| 307 | } |
| 308 | |
Fabio Baltieri | c0ea706 | 2013-04-03 10:45:07 +0200 | [diff] [blame] | 309 | 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] | 310 | { |
Fabio Baltieri | c0ea706 | 2013-04-03 10:45:07 +0200 | [diff] [blame] | 311 | u8 bit; |
| 312 | bit = sel_host ? AB8500_BIT_PHY_CTRL_HOST_EN : |
| 313 | AB8500_BIT_PHY_CTRL_DEVICE_EN; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 314 | |
Patrice Chotard | 899f0f5 | 2013-04-03 10:45:11 +0200 | [diff] [blame] | 315 | /* mux and configure USB pins to DEFAULT state */ |
| 316 | ab->pinctrl = pinctrl_get_select(ab->dev, PINCTRL_STATE_DEFAULT); |
| 317 | if (IS_ERR(ab->pinctrl)) |
| 318 | dev_err(ab->dev, "could not get/set default pinstate\n"); |
| 319 | |
Mian Yousaf Kaukab | d0ed064 | 2013-05-15 14:03:26 +0200 | [diff] [blame] | 320 | if (clk_prepare_enable(ab->sysclk)) |
| 321 | dev_err(ab->dev, "can't prepare/enable clock\n"); |
| 322 | |
Fabio Baltieri | 54dfbb0 | 2013-04-03 10:45:08 +0200 | [diff] [blame] | 323 | ab8500_usb_regulator_enable(ab); |
| 324 | |
Fabio Baltieri | c0ea706 | 2013-04-03 10:45:07 +0200 | [diff] [blame] | 325 | abx500_mask_and_set_register_interruptible(ab->dev, |
| 326 | AB8500_USB, AB8500_USB_PHY_CTRL_REG, |
| 327 | bit, bit); |
Fabio Baltieri | 0c380c0 | 2013-05-15 14:03:32 +0200 | [diff] [blame^] | 328 | |
| 329 | if (ab->flags & AB8500_USB_FLAG_USE_VBUS_HOST_QUIRK) { |
| 330 | if (sel_host) |
| 331 | abx500_set_register_interruptible(ab->dev, |
| 332 | AB8500_USB, AB8540_USB_OTG_CTL_REG, |
| 333 | AB8540_BIT_OTG_CTL_VBUS_VALID_ENA | |
| 334 | AB8540_BIT_OTG_CTL_ID_HOST_ENA | |
| 335 | AB8540_BIT_OTG_CTL_ID_DEV_ENA); |
| 336 | } |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 337 | } |
| 338 | |
Fabio Baltieri | c0ea706 | 2013-04-03 10:45:07 +0200 | [diff] [blame] | 339 | static void ab8500_usb_phy_disable(struct ab8500_usb *ab, bool sel_host) |
| 340 | { |
| 341 | u8 bit; |
| 342 | bit = sel_host ? AB8500_BIT_PHY_CTRL_HOST_EN : |
| 343 | AB8500_BIT_PHY_CTRL_DEVICE_EN; |
| 344 | |
| 345 | ab8500_usb_wd_linkstatus(ab, bit); |
| 346 | |
| 347 | abx500_mask_and_set_register_interruptible(ab->dev, |
| 348 | AB8500_USB, AB8500_USB_PHY_CTRL_REG, |
| 349 | bit, 0); |
| 350 | |
| 351 | /* Needed to disable the phy.*/ |
| 352 | ab8500_usb_wd_workaround(ab); |
Fabio Baltieri | 54dfbb0 | 2013-04-03 10:45:08 +0200 | [diff] [blame] | 353 | |
Mian Yousaf Kaukab | d0ed064 | 2013-05-15 14:03:26 +0200 | [diff] [blame] | 354 | clk_disable_unprepare(ab->sysclk); |
| 355 | |
Fabio Baltieri | 54dfbb0 | 2013-04-03 10:45:08 +0200 | [diff] [blame] | 356 | ab8500_usb_regulator_disable(ab); |
Patrice Chotard | 899f0f5 | 2013-04-03 10:45:11 +0200 | [diff] [blame] | 357 | |
| 358 | if (!IS_ERR(ab->pinctrl)) { |
| 359 | /* configure USB pins to SLEEP state */ |
| 360 | ab->pins_sleep = pinctrl_lookup_state(ab->pinctrl, |
| 361 | PINCTRL_STATE_SLEEP); |
| 362 | |
| 363 | if (IS_ERR(ab->pins_sleep)) |
| 364 | dev_dbg(ab->dev, "could not get sleep pinstate\n"); |
| 365 | else if (pinctrl_select_state(ab->pinctrl, ab->pins_sleep)) |
| 366 | dev_err(ab->dev, "could not set pins to sleep state\n"); |
| 367 | |
Fabio Baltieri | 3147dad | 2013-05-15 14:03:25 +0200 | [diff] [blame] | 368 | /* |
| 369 | * as USB pins are shared with iddet, release them to allow |
Patrice Chotard | 899f0f5 | 2013-04-03 10:45:11 +0200 | [diff] [blame] | 370 | * iddet to request them |
| 371 | */ |
| 372 | pinctrl_put(ab->pinctrl); |
| 373 | } |
Fabio Baltieri | c0ea706 | 2013-04-03 10:45:07 +0200 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | #define ab8500_usb_host_phy_en(ab) ab8500_usb_phy_enable(ab, true) |
| 377 | #define ab8500_usb_host_phy_dis(ab) ab8500_usb_phy_disable(ab, true) |
| 378 | #define ab8500_usb_peri_phy_en(ab) ab8500_usb_phy_enable(ab, false) |
| 379 | #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] | 380 | |
Fabio Baltieri | 0c380c0 | 2013-05-15 14:03:32 +0200 | [diff] [blame^] | 381 | static int ab8540_usb_link_status_update(struct ab8500_usb *ab, |
| 382 | enum ab8540_usb_link_status lsts) |
| 383 | { |
| 384 | enum ux500_musb_vbus_id_status event = 0; |
| 385 | |
| 386 | dev_dbg(ab->dev, "ab8540_usb_link_status_update %d\n", lsts); |
| 387 | |
| 388 | if (ab->enabled_charging_detection) { |
| 389 | /* Disable USB Charger detection */ |
| 390 | abx500_mask_and_set_register_interruptible(ab->dev, |
| 391 | AB8500_USB, AB8540_VBUS_CTRL_REG, |
| 392 | AB8540_BIT_VBUS_CTRL_CHARG_DET_ENA, 0x00); |
| 393 | ab->enabled_charging_detection = false; |
| 394 | } |
| 395 | |
| 396 | /* |
| 397 | * Spurious link_status interrupts are seen in case of a |
| 398 | * disconnection of a device in IDGND and RIDA stage |
| 399 | */ |
| 400 | if (ab->previous_link_status_state == USB_LINK_HM_IDGND_8540 && |
| 401 | (lsts == USB_LINK_STD_HOST_C_NS_8540 || |
| 402 | lsts == USB_LINK_STD_HOST_NC_8540)) |
| 403 | return 0; |
| 404 | |
| 405 | if (ab->previous_link_status_state == USB_LINK_ACA_RID_A_8540 && |
| 406 | (lsts == USB_LINK_STD_HOST_NC_8540)) |
| 407 | return 0; |
| 408 | |
| 409 | ab->previous_link_status_state = lsts; |
| 410 | |
| 411 | switch (lsts) { |
| 412 | case USB_LINK_ACA_RID_B_8540: |
| 413 | event = UX500_MUSB_RIDB; |
| 414 | case USB_LINK_NOT_CONFIGURED_8540: |
| 415 | case USB_LINK_RESERVED0_8540: |
| 416 | case USB_LINK_RESERVED1_8540: |
| 417 | case USB_LINK_RESERVED2_8540: |
| 418 | case USB_LINK_RESERVED3_8540: |
| 419 | ab->mode = USB_IDLE; |
| 420 | ab->phy.otg->default_a = false; |
| 421 | ab->vbus_draw = 0; |
| 422 | if (event != UX500_MUSB_RIDB) |
| 423 | event = UX500_MUSB_NONE; |
| 424 | /* |
| 425 | * Fallback to default B_IDLE as nothing |
| 426 | * is connected |
| 427 | */ |
| 428 | ab->phy.state = OTG_STATE_B_IDLE; |
| 429 | break; |
| 430 | |
| 431 | case USB_LINK_ACA_RID_C_NM_8540: |
| 432 | event = UX500_MUSB_RIDC; |
| 433 | case USB_LINK_STD_HOST_NC_8540: |
| 434 | case USB_LINK_STD_HOST_C_NS_8540: |
| 435 | case USB_LINK_STD_HOST_C_S_8540: |
| 436 | case USB_LINK_CDP_8540: |
| 437 | if (ab->mode == USB_IDLE) { |
| 438 | ab->mode = USB_PERIPHERAL; |
| 439 | ab8500_usb_peri_phy_en(ab); |
| 440 | atomic_notifier_call_chain(&ab->phy.notifier, |
| 441 | UX500_MUSB_PREPARE, &ab->vbus_draw); |
| 442 | } |
| 443 | if (event != UX500_MUSB_RIDC) |
| 444 | event = UX500_MUSB_VBUS; |
| 445 | break; |
| 446 | |
| 447 | case USB_LINK_ACA_RID_A_8540: |
| 448 | case USB_LINK_ACA_DOCK_CHGR_8540: |
| 449 | event = UX500_MUSB_RIDA; |
| 450 | case USB_LINK_HM_IDGND_8540: |
| 451 | case USB_LINK_STD_UPSTREAM_8540: |
| 452 | if (ab->mode == USB_IDLE) { |
| 453 | ab->mode = USB_HOST; |
| 454 | ab8500_usb_host_phy_en(ab); |
| 455 | atomic_notifier_call_chain(&ab->phy.notifier, |
| 456 | UX500_MUSB_PREPARE, &ab->vbus_draw); |
| 457 | } |
| 458 | ab->phy.otg->default_a = true; |
| 459 | if (event != UX500_MUSB_RIDA) |
| 460 | event = UX500_MUSB_ID; |
| 461 | atomic_notifier_call_chain(&ab->phy.notifier, |
| 462 | event, &ab->vbus_draw); |
| 463 | break; |
| 464 | |
| 465 | case USB_LINK_DEDICATED_CHG_8540: |
| 466 | ab->mode = USB_DEDICATED_CHG; |
| 467 | event = UX500_MUSB_CHARGER; |
| 468 | atomic_notifier_call_chain(&ab->phy.notifier, |
| 469 | event, &ab->vbus_draw); |
| 470 | break; |
| 471 | |
| 472 | case USB_LINK_PHYEN_NO_VBUS_NO_IDGND_8540: |
| 473 | case USB_LINK_STD_UPSTREAM_NO_IDGNG_VBUS_8540: |
| 474 | event = UX500_MUSB_NONE; |
| 475 | if (ab->mode == USB_HOST) { |
| 476 | ab->phy.otg->default_a = false; |
| 477 | ab->vbus_draw = 0; |
| 478 | atomic_notifier_call_chain(&ab->phy.notifier, |
| 479 | event, &ab->vbus_draw); |
| 480 | ab8500_usb_host_phy_dis(ab); |
| 481 | ab->mode = USB_IDLE; |
| 482 | } |
| 483 | if (ab->mode == USB_PERIPHERAL) { |
| 484 | atomic_notifier_call_chain(&ab->phy.notifier, |
| 485 | event, &ab->vbus_draw); |
| 486 | ab8500_usb_peri_phy_dis(ab); |
| 487 | atomic_notifier_call_chain(&ab->phy.notifier, |
| 488 | UX500_MUSB_CLEAN, &ab->vbus_draw); |
| 489 | ab->mode = USB_IDLE; |
| 490 | ab->phy.otg->default_a = false; |
| 491 | ab->vbus_draw = 0; |
| 492 | } |
| 493 | break; |
| 494 | |
| 495 | default: |
| 496 | event = UX500_MUSB_NONE; |
| 497 | break; |
| 498 | } |
| 499 | |
| 500 | return 0; |
| 501 | } |
| 502 | |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 503 | static int ab8505_usb_link_status_update(struct ab8500_usb *ab, |
| 504 | enum ab8505_usb_link_status lsts) |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 505 | { |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 506 | enum ux500_musb_vbus_id_status event = 0; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 507 | |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 508 | 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] | 509 | |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 510 | /* |
| 511 | * Spurious link_status interrupts are seen at the time of |
| 512 | * disconnection of a device in RIDA state |
| 513 | */ |
| 514 | if (ab->previous_link_status_state == USB_LINK_ACA_RID_A_8505 && |
| 515 | (lsts == USB_LINK_STD_HOST_NC_8505)) |
| 516 | return 0; |
| 517 | |
| 518 | ab->previous_link_status_state = lsts; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 519 | |
| 520 | switch (lsts) { |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 521 | case USB_LINK_ACA_RID_B_8505: |
| 522 | event = UX500_MUSB_RIDB; |
| 523 | case USB_LINK_NOT_CONFIGURED_8505: |
| 524 | case USB_LINK_RESERVED0_8505: |
| 525 | case USB_LINK_RESERVED1_8505: |
| 526 | case USB_LINK_RESERVED2_8505: |
| 527 | case USB_LINK_RESERVED3_8505: |
| 528 | ab->mode = USB_IDLE; |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 529 | ab->phy.otg->default_a = false; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 530 | ab->vbus_draw = 0; |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 531 | if (event != UX500_MUSB_RIDB) |
| 532 | event = UX500_MUSB_NONE; |
| 533 | /* |
| 534 | * Fallback to default B_IDLE as nothing |
| 535 | * is connected |
| 536 | */ |
| 537 | ab->phy.state = OTG_STATE_B_IDLE; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 538 | break; |
| 539 | |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 540 | case USB_LINK_ACA_RID_C_NM_8505: |
| 541 | event = UX500_MUSB_RIDC; |
| 542 | case USB_LINK_STD_HOST_NC_8505: |
| 543 | case USB_LINK_STD_HOST_C_NS_8505: |
| 544 | case USB_LINK_STD_HOST_C_S_8505: |
| 545 | case USB_LINK_CDP_8505: |
| 546 | if (ab->mode == USB_IDLE) { |
| 547 | ab->mode = USB_PERIPHERAL; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 548 | ab8500_usb_peri_phy_en(ab); |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 549 | atomic_notifier_call_chain(&ab->phy.notifier, |
| 550 | UX500_MUSB_PREPARE, &ab->vbus_draw); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 551 | } |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 552 | if (event != UX500_MUSB_RIDC) |
| 553 | event = UX500_MUSB_VBUS; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 554 | break; |
| 555 | |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 556 | case USB_LINK_ACA_RID_A_8505: |
| 557 | case USB_LINK_ACA_DOCK_CHGR_8505: |
| 558 | event = UX500_MUSB_RIDA; |
| 559 | case USB_LINK_HM_IDGND_8505: |
| 560 | if (ab->mode == USB_IDLE) { |
| 561 | ab->mode = USB_HOST; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 562 | ab8500_usb_host_phy_en(ab); |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 563 | atomic_notifier_call_chain(&ab->phy.notifier, |
| 564 | UX500_MUSB_PREPARE, &ab->vbus_draw); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 565 | } |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 566 | ab->phy.otg->default_a = true; |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 567 | if (event != UX500_MUSB_RIDA) |
| 568 | event = UX500_MUSB_ID; |
| 569 | atomic_notifier_call_chain(&ab->phy.notifier, |
| 570 | event, &ab->vbus_draw); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 571 | break; |
| 572 | |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 573 | case USB_LINK_DEDICATED_CHG_8505: |
| 574 | ab->mode = USB_DEDICATED_CHG; |
| 575 | event = UX500_MUSB_CHARGER; |
| 576 | atomic_notifier_call_chain(&ab->phy.notifier, |
| 577 | event, &ab->vbus_draw); |
| 578 | break; |
| 579 | |
| 580 | default: |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 581 | break; |
| 582 | } |
| 583 | |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 584 | return 0; |
| 585 | } |
| 586 | |
| 587 | static int ab8500_usb_link_status_update(struct ab8500_usb *ab, |
| 588 | enum ab8500_usb_link_status lsts) |
| 589 | { |
| 590 | enum ux500_musb_vbus_id_status event = 0; |
| 591 | |
| 592 | dev_dbg(ab->dev, "ab8500_usb_link_status_update %d\n", lsts); |
| 593 | |
| 594 | /* |
| 595 | * Spurious link_status interrupts are seen in case of a |
| 596 | * disconnection of a device in IDGND and RIDA stage |
| 597 | */ |
| 598 | if (ab->previous_link_status_state == USB_LINK_HM_IDGND_8500 && |
| 599 | (lsts == USB_LINK_STD_HOST_C_NS_8500 || |
| 600 | lsts == USB_LINK_STD_HOST_NC_8500)) |
| 601 | return 0; |
| 602 | |
| 603 | if (ab->previous_link_status_state == USB_LINK_ACA_RID_A_8500 && |
| 604 | lsts == USB_LINK_STD_HOST_NC_8500) |
| 605 | return 0; |
| 606 | |
| 607 | ab->previous_link_status_state = lsts; |
| 608 | |
| 609 | switch (lsts) { |
| 610 | case USB_LINK_ACA_RID_B_8500: |
| 611 | event = UX500_MUSB_RIDB; |
| 612 | case USB_LINK_NOT_CONFIGURED_8500: |
| 613 | case USB_LINK_NOT_VALID_LINK_8500: |
| 614 | ab->mode = USB_IDLE; |
| 615 | ab->phy.otg->default_a = false; |
| 616 | ab->vbus_draw = 0; |
| 617 | if (event != UX500_MUSB_RIDB) |
| 618 | event = UX500_MUSB_NONE; |
| 619 | /* Fallback to default B_IDLE as nothing is connected */ |
| 620 | ab->phy.state = OTG_STATE_B_IDLE; |
| 621 | break; |
| 622 | |
| 623 | case USB_LINK_ACA_RID_C_NM_8500: |
| 624 | case USB_LINK_ACA_RID_C_HS_8500: |
| 625 | case USB_LINK_ACA_RID_C_HS_CHIRP_8500: |
| 626 | event = UX500_MUSB_RIDC; |
| 627 | case USB_LINK_STD_HOST_NC_8500: |
| 628 | case USB_LINK_STD_HOST_C_NS_8500: |
| 629 | case USB_LINK_STD_HOST_C_S_8500: |
| 630 | case USB_LINK_HOST_CHG_NM_8500: |
| 631 | case USB_LINK_HOST_CHG_HS_8500: |
| 632 | case USB_LINK_HOST_CHG_HS_CHIRP_8500: |
| 633 | if (ab->mode == USB_IDLE) { |
| 634 | ab->mode = USB_PERIPHERAL; |
| 635 | ab8500_usb_peri_phy_en(ab); |
| 636 | atomic_notifier_call_chain(&ab->phy.notifier, |
| 637 | UX500_MUSB_PREPARE, &ab->vbus_draw); |
| 638 | } |
| 639 | if (event != UX500_MUSB_RIDC) |
| 640 | event = UX500_MUSB_VBUS; |
| 641 | break; |
| 642 | |
| 643 | case USB_LINK_ACA_RID_A_8500: |
| 644 | event = UX500_MUSB_RIDA; |
| 645 | case USB_LINK_HM_IDGND_8500: |
| 646 | if (ab->mode == USB_IDLE) { |
| 647 | ab->mode = USB_HOST; |
| 648 | ab8500_usb_host_phy_en(ab); |
| 649 | atomic_notifier_call_chain(&ab->phy.notifier, |
| 650 | UX500_MUSB_PREPARE, &ab->vbus_draw); |
| 651 | } |
| 652 | ab->phy.otg->default_a = true; |
| 653 | if (event != UX500_MUSB_RIDA) |
| 654 | event = UX500_MUSB_ID; |
| 655 | atomic_notifier_call_chain(&ab->phy.notifier, |
| 656 | event, &ab->vbus_draw); |
| 657 | break; |
| 658 | |
| 659 | case USB_LINK_DEDICATED_CHG_8500: |
| 660 | ab->mode = USB_DEDICATED_CHG; |
| 661 | event = UX500_MUSB_CHARGER; |
| 662 | atomic_notifier_call_chain(&ab->phy.notifier, |
| 663 | event, &ab->vbus_draw); |
| 664 | break; |
| 665 | |
| 666 | case USB_LINK_RESERVED_8500: |
| 667 | break; |
| 668 | } |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 669 | |
| 670 | return 0; |
| 671 | } |
| 672 | |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 673 | /* |
| 674 | * Connection Sequence: |
| 675 | * 1. Link Status Interrupt |
| 676 | * 2. Enable AB clock |
| 677 | * 3. Enable AB regulators |
| 678 | * 4. Enable USB phy |
| 679 | * 5. Reset the musb controller |
| 680 | * 6. Switch the ULPI GPIO pins to fucntion mode |
| 681 | * 7. Enable the musb Peripheral5 clock |
| 682 | * 8. Restore MUSB context |
| 683 | */ |
| 684 | static int abx500_usb_link_status_update(struct ab8500_usb *ab) |
| 685 | { |
| 686 | u8 reg; |
| 687 | int ret = 0; |
| 688 | |
| 689 | if (is_ab8500(ab->ab8500)) { |
| 690 | enum ab8500_usb_link_status lsts; |
| 691 | |
| 692 | abx500_get_register_interruptible(ab->dev, |
| 693 | AB8500_USB, AB8500_USB_LINE_STAT_REG, ®); |
| 694 | lsts = (reg >> 3) & 0x0F; |
| 695 | ret = ab8500_usb_link_status_update(ab, lsts); |
| 696 | } else if (is_ab8505(ab->ab8500)) { |
| 697 | enum ab8505_usb_link_status lsts; |
| 698 | |
| 699 | abx500_get_register_interruptible(ab->dev, |
| 700 | AB8500_USB, AB8505_USB_LINE_STAT_REG, ®); |
| 701 | lsts = (reg >> 3) & 0x1F; |
| 702 | ret = ab8505_usb_link_status_update(ab, lsts); |
Fabio Baltieri | 0c380c0 | 2013-05-15 14:03:32 +0200 | [diff] [blame^] | 703 | } else if (is_ab8540(ab->ab8500)) { |
| 704 | enum ab8540_usb_link_status lsts; |
| 705 | |
| 706 | abx500_get_register_interruptible(ab->dev, |
| 707 | AB8500_USB, AB8540_USB_LINK_STAT_REG, ®); |
| 708 | lsts = (reg >> 3) & 0xFF; |
| 709 | ret = ab8540_usb_link_status_update(ab, lsts); |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | return ret; |
| 713 | } |
| 714 | |
| 715 | /* |
| 716 | * Disconnection Sequence: |
| 717 | * 1. Disconect Interrupt |
| 718 | * 2. Disable regulators |
| 719 | * 3. Disable AB clock |
| 720 | * 4. Disable the Phy |
| 721 | * 5. Link Status Interrupt |
| 722 | * 6. Disable Musb Clock |
| 723 | */ |
| 724 | static irqreturn_t ab8500_usb_disconnect_irq(int irq, void *data) |
| 725 | { |
| 726 | struct ab8500_usb *ab = (struct ab8500_usb *) data; |
| 727 | enum usb_phy_events event = UX500_MUSB_NONE; |
| 728 | |
| 729 | /* Link status will not be updated till phy is disabled. */ |
| 730 | if (ab->mode == USB_HOST) { |
| 731 | ab->phy.otg->default_a = false; |
| 732 | ab->vbus_draw = 0; |
| 733 | atomic_notifier_call_chain(&ab->phy.notifier, |
| 734 | event, &ab->vbus_draw); |
| 735 | ab8500_usb_host_phy_dis(ab); |
| 736 | ab->mode = USB_IDLE; |
| 737 | } |
| 738 | |
| 739 | if (ab->mode == USB_PERIPHERAL) { |
| 740 | atomic_notifier_call_chain(&ab->phy.notifier, |
| 741 | event, &ab->vbus_draw); |
| 742 | ab8500_usb_peri_phy_dis(ab); |
| 743 | atomic_notifier_call_chain(&ab->phy.notifier, |
| 744 | UX500_MUSB_CLEAN, &ab->vbus_draw); |
| 745 | ab->mode = USB_IDLE; |
| 746 | ab->phy.otg->default_a = false; |
| 747 | ab->vbus_draw = 0; |
| 748 | } |
| 749 | |
| 750 | if (is_ab8500_2p0(ab->ab8500)) { |
| 751 | if (ab->mode == USB_DEDICATED_CHG) { |
| 752 | ab8500_usb_wd_linkstatus(ab, |
| 753 | AB8500_BIT_PHY_CTRL_DEVICE_EN); |
| 754 | abx500_mask_and_set_register_interruptible(ab->dev, |
| 755 | AB8500_USB, AB8500_USB_PHY_CTRL_REG, |
| 756 | AB8500_BIT_PHY_CTRL_DEVICE_EN, 0); |
| 757 | } |
| 758 | } |
| 759 | |
| 760 | return IRQ_HANDLED; |
| 761 | } |
| 762 | |
| 763 | static irqreturn_t ab8500_usb_link_status_irq(int irq, void *data) |
| 764 | { |
Fabio Baltieri | 3147dad | 2013-05-15 14:03:25 +0200 | [diff] [blame] | 765 | struct ab8500_usb *ab = (struct ab8500_usb *)data; |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 766 | |
| 767 | abx500_usb_link_status_update(ab); |
| 768 | |
| 769 | return IRQ_HANDLED; |
| 770 | } |
| 771 | |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 772 | static void ab8500_usb_phy_disable_work(struct work_struct *work) |
| 773 | { |
| 774 | struct ab8500_usb *ab = container_of(work, struct ab8500_usb, |
| 775 | phy_dis_work); |
| 776 | |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 777 | if (!ab->phy.otg->host) |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 778 | ab8500_usb_host_phy_dis(ab); |
| 779 | |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 780 | if (!ab->phy.otg->gadget) |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 781 | ab8500_usb_peri_phy_dis(ab); |
| 782 | } |
| 783 | |
Fabio Baltieri | 0c380c0 | 2013-05-15 14:03:32 +0200 | [diff] [blame^] | 784 | /* Check if VBUS is set and linkstatus has not detected a cable. */ |
| 785 | static bool ab8500_usb_check_vbus_status(struct ab8500_usb *ab) |
| 786 | { |
| 787 | u8 isource2; |
| 788 | u8 reg; |
| 789 | enum ab8540_usb_link_status lsts; |
| 790 | |
| 791 | abx500_get_register_interruptible(ab->dev, |
| 792 | AB8500_INTERRUPT, AB8500_IT_SOURCE2_REG, |
| 793 | &isource2); |
| 794 | |
| 795 | /* If Vbus is below 3.6V abort */ |
| 796 | if (!(isource2 & AB8500_BIT_SOURCE2_VBUSDET)) |
| 797 | return false; |
| 798 | |
| 799 | abx500_get_register_interruptible(ab->dev, |
| 800 | AB8500_USB, AB8540_USB_LINK_STAT_REG, |
| 801 | ®); |
| 802 | |
| 803 | lsts = (reg >> 3) & 0xFF; |
| 804 | |
| 805 | /* Check if linkstatus has detected a cable */ |
| 806 | if (lsts) |
| 807 | return false; |
| 808 | |
| 809 | return true; |
| 810 | } |
| 811 | |
| 812 | /* re-trigger charger detection again with watchdog re-kick. */ |
| 813 | static void ab8500_usb_vbus_turn_on_event_work(struct work_struct *work) |
| 814 | { |
| 815 | struct ab8500_usb *ab = container_of(work, struct ab8500_usb, |
| 816 | vbus_event_work); |
| 817 | |
| 818 | if (ab->mode != USB_IDLE) |
| 819 | return; |
| 820 | |
| 821 | abx500_set_register_interruptible(ab->dev, |
| 822 | AB8500_SYS_CTRL2_BLOCK, AB8500_MAIN_WD_CTRL_REG, |
| 823 | AB8500_BIT_WD_CTRL_ENABLE); |
| 824 | |
| 825 | udelay(100); |
| 826 | |
| 827 | abx500_set_register_interruptible(ab->dev, |
| 828 | AB8500_SYS_CTRL2_BLOCK, AB8500_MAIN_WD_CTRL_REG, |
| 829 | AB8500_BIT_WD_CTRL_ENABLE | AB8500_BIT_WD_CTRL_KICK); |
| 830 | |
| 831 | udelay(100); |
| 832 | |
| 833 | /* Disable Main watchdog */ |
| 834 | abx500_set_register_interruptible(ab->dev, |
| 835 | AB8500_SYS_CTRL2_BLOCK, AB8500_MAIN_WD_CTRL_REG, |
| 836 | 0x0); |
| 837 | |
| 838 | /* Enable USB Charger detection */ |
| 839 | abx500_mask_and_set_register_interruptible(ab->dev, |
| 840 | AB8500_USB, AB8540_VBUS_CTRL_REG, |
| 841 | AB8540_BIT_VBUS_CTRL_CHARG_DET_ENA, |
| 842 | AB8540_BIT_VBUS_CTRL_CHARG_DET_ENA); |
| 843 | |
| 844 | ab->enabled_charging_detection = true; |
| 845 | } |
| 846 | |
Sakethram Bommisetti | c2a0ab6 | 2013-04-03 10:45:05 +0200 | [diff] [blame] | 847 | static unsigned ab8500_eyediagram_workaroud(struct ab8500_usb *ab, unsigned mA) |
| 848 | { |
| 849 | /* |
| 850 | * AB8500 V2 has eye diagram issues when drawing more than 100mA from |
| 851 | * VBUS. Set charging current to 100mA in case of standard host |
| 852 | */ |
| 853 | if (is_ab8500_2p0_or_earlier(ab->ab8500)) |
| 854 | if (mA > 100) |
| 855 | mA = 100; |
| 856 | |
| 857 | return mA; |
| 858 | } |
| 859 | |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 860 | 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] | 861 | { |
| 862 | struct ab8500_usb *ab; |
| 863 | |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 864 | if (!phy) |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 865 | return -ENODEV; |
| 866 | |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 867 | ab = phy_to_ab(phy); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 868 | |
Sakethram Bommisetti | c2a0ab6 | 2013-04-03 10:45:05 +0200 | [diff] [blame] | 869 | mA = ab8500_eyediagram_workaroud(ab, mA); |
| 870 | |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 871 | ab->vbus_draw = mA; |
| 872 | |
Fabio Baltieri | 77f4396 | 2013-04-03 10:45:10 +0200 | [diff] [blame] | 873 | atomic_notifier_call_chain(&ab->phy.notifier, |
| 874 | UX500_MUSB_VBUS, &ab->vbus_draw); |
| 875 | |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 876 | return 0; |
| 877 | } |
| 878 | |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame] | 879 | 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] | 880 | { |
| 881 | /* TODO */ |
| 882 | return 0; |
| 883 | } |
| 884 | |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 885 | static int ab8500_usb_set_peripheral(struct usb_otg *otg, |
| 886 | struct usb_gadget *gadget) |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 887 | { |
| 888 | struct ab8500_usb *ab; |
| 889 | |
| 890 | if (!otg) |
| 891 | return -ENODEV; |
| 892 | |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 893 | ab = phy_to_ab(otg->phy); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 894 | |
Sakethram Bommisetti | 5882337 | 2013-04-03 10:45:13 +0200 | [diff] [blame] | 895 | ab->phy.otg->gadget = gadget; |
| 896 | |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 897 | /* Some drivers call this function in atomic context. |
| 898 | * Do not update ab8500 registers directly till this |
| 899 | * is fixed. |
| 900 | */ |
| 901 | |
Fabio Baltieri | 3147dad | 2013-05-15 14:03:25 +0200 | [diff] [blame] | 902 | if ((ab->mode != USB_IDLE) && !gadget) { |
Sakethram Bommisetti | 5882337 | 2013-04-03 10:45:13 +0200 | [diff] [blame] | 903 | ab->mode = USB_IDLE; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 904 | schedule_work(&ab->phy_dis_work); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 905 | } |
| 906 | |
| 907 | return 0; |
| 908 | } |
| 909 | |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 910 | 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] | 911 | { |
| 912 | struct ab8500_usb *ab; |
| 913 | |
| 914 | if (!otg) |
| 915 | return -ENODEV; |
| 916 | |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 917 | ab = phy_to_ab(otg->phy); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 918 | |
Sakethram Bommisetti | 5882337 | 2013-04-03 10:45:13 +0200 | [diff] [blame] | 919 | ab->phy.otg->host = host; |
| 920 | |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 921 | /* Some drivers call this function in atomic context. |
| 922 | * Do not update ab8500 registers directly till this |
| 923 | * is fixed. |
| 924 | */ |
| 925 | |
Fabio Baltieri | 3147dad | 2013-05-15 14:03:25 +0200 | [diff] [blame] | 926 | if ((ab->mode != USB_IDLE) && !host) { |
Sakethram Bommisetti | 5882337 | 2013-04-03 10:45:13 +0200 | [diff] [blame] | 927 | ab->mode = USB_IDLE; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 928 | schedule_work(&ab->phy_dis_work); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | return 0; |
| 932 | } |
| 933 | |
Sakethram Bommisetti | fb21f37 | 2013-05-15 14:03:27 +0200 | [diff] [blame] | 934 | static void ab8500_usb_restart_phy(struct ab8500_usb *ab) |
| 935 | { |
| 936 | abx500_mask_and_set_register_interruptible(ab->dev, |
| 937 | AB8500_USB, AB8500_USB_PHY_CTRL_REG, |
| 938 | AB8500_BIT_PHY_CTRL_DEVICE_EN, |
| 939 | AB8500_BIT_PHY_CTRL_DEVICE_EN); |
| 940 | |
| 941 | udelay(100); |
| 942 | |
| 943 | abx500_mask_and_set_register_interruptible(ab->dev, |
| 944 | AB8500_USB, AB8500_USB_PHY_CTRL_REG, |
| 945 | AB8500_BIT_PHY_CTRL_DEVICE_EN, |
| 946 | 0); |
| 947 | |
| 948 | abx500_mask_and_set_register_interruptible(ab->dev, |
| 949 | AB8500_USB, AB8500_USB_PHY_CTRL_REG, |
| 950 | AB8500_BIT_PHY_CTRL_HOST_EN, |
| 951 | AB8500_BIT_PHY_CTRL_HOST_EN); |
| 952 | |
| 953 | udelay(100); |
| 954 | |
| 955 | abx500_mask_and_set_register_interruptible(ab->dev, |
| 956 | AB8500_USB, AB8500_USB_PHY_CTRL_REG, |
| 957 | AB8500_BIT_PHY_CTRL_HOST_EN, |
| 958 | 0); |
| 959 | } |
| 960 | |
Fabio Baltieri | e65b36c | 2013-04-03 10:45:06 +0200 | [diff] [blame] | 961 | static int ab8500_usb_regulator_get(struct ab8500_usb *ab) |
| 962 | { |
| 963 | int err; |
| 964 | |
| 965 | ab->v_ape = devm_regulator_get(ab->dev, "v-ape"); |
| 966 | if (IS_ERR(ab->v_ape)) { |
| 967 | dev_err(ab->dev, "Could not get v-ape supply\n"); |
| 968 | err = PTR_ERR(ab->v_ape); |
| 969 | return err; |
| 970 | } |
| 971 | |
| 972 | ab->v_ulpi = devm_regulator_get(ab->dev, "vddulpivio18"); |
| 973 | if (IS_ERR(ab->v_ulpi)) { |
| 974 | dev_err(ab->dev, "Could not get vddulpivio18 supply\n"); |
| 975 | err = PTR_ERR(ab->v_ulpi); |
| 976 | return err; |
| 977 | } |
| 978 | |
| 979 | ab->v_musb = devm_regulator_get(ab->dev, "musb_1v8"); |
| 980 | if (IS_ERR(ab->v_musb)) { |
| 981 | dev_err(ab->dev, "Could not get musb_1v8 supply\n"); |
| 982 | err = PTR_ERR(ab->v_musb); |
| 983 | return err; |
| 984 | } |
| 985 | |
| 986 | return 0; |
| 987 | } |
| 988 | |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 989 | static int ab8500_usb_irq_setup(struct platform_device *pdev, |
| 990 | struct ab8500_usb *ab) |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 991 | { |
| 992 | int err; |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 993 | int irq; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 994 | |
Fabio Baltieri | bd4c9f0 | 2013-05-15 14:03:31 +0200 | [diff] [blame] | 995 | if (ab->flags & AB8500_USB_FLAG_USE_LINK_STATUS_IRQ) { |
| 996 | irq = platform_get_irq_byname(pdev, "USB_LINK_STATUS"); |
| 997 | if (irq < 0) { |
| 998 | dev_err(&pdev->dev, "Link status irq not found\n"); |
| 999 | return irq; |
| 1000 | } |
| 1001 | err = devm_request_threaded_irq(&pdev->dev, irq, NULL, |
| 1002 | ab8500_usb_link_status_irq, |
| 1003 | IRQF_NO_SUSPEND | IRQF_SHARED, |
| 1004 | "usb-link-status", ab); |
| 1005 | if (err < 0) { |
| 1006 | dev_err(ab->dev, "request_irq failed for link status irq\n"); |
| 1007 | return err; |
| 1008 | } |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 1009 | } |
| 1010 | |
Fabio Baltieri | bd4c9f0 | 2013-05-15 14:03:31 +0200 | [diff] [blame] | 1011 | if (ab->flags & AB8500_USB_FLAG_USE_ID_WAKEUP_IRQ) { |
| 1012 | irq = platform_get_irq_byname(pdev, "ID_WAKEUP_F"); |
| 1013 | if (irq < 0) { |
| 1014 | dev_err(&pdev->dev, "ID fall irq not found\n"); |
| 1015 | return irq; |
| 1016 | } |
| 1017 | err = devm_request_threaded_irq(&pdev->dev, irq, NULL, |
| 1018 | ab8500_usb_disconnect_irq, |
| 1019 | IRQF_NO_SUSPEND | IRQF_SHARED, |
| 1020 | "usb-id-fall", ab); |
| 1021 | if (err < 0) { |
| 1022 | dev_err(ab->dev, "request_irq failed for ID fall irq\n"); |
| 1023 | return err; |
| 1024 | } |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 1025 | } |
| 1026 | |
Fabio Baltieri | bd4c9f0 | 2013-05-15 14:03:31 +0200 | [diff] [blame] | 1027 | if (ab->flags & AB8500_USB_FLAG_USE_VBUS_DET_IRQ) { |
| 1028 | irq = platform_get_irq_byname(pdev, "VBUS_DET_F"); |
| 1029 | if (irq < 0) { |
| 1030 | dev_err(&pdev->dev, "VBUS fall irq not found\n"); |
| 1031 | return irq; |
| 1032 | } |
| 1033 | err = devm_request_threaded_irq(&pdev->dev, irq, NULL, |
| 1034 | ab8500_usb_disconnect_irq, |
| 1035 | IRQF_NO_SUSPEND | IRQF_SHARED, |
| 1036 | "usb-vbus-fall", ab); |
| 1037 | if (err < 0) { |
| 1038 | dev_err(ab->dev, "request_irq failed for Vbus fall irq\n"); |
| 1039 | return err; |
| 1040 | } |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | return 0; |
| 1044 | } |
| 1045 | |
Fabio Baltieri | 16604a3 | 2013-05-15 14:03:30 +0200 | [diff] [blame] | 1046 | static void ab8500_usb_set_ab8500_tuning_values(struct ab8500_usb *ab) |
| 1047 | { |
| 1048 | int err; |
| 1049 | |
| 1050 | /* Enable the PBT/Bank 0x12 access */ |
| 1051 | err = abx500_set_register_interruptible(ab->dev, |
| 1052 | AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS, 0x01); |
| 1053 | if (err < 0) |
| 1054 | dev_err(ab->dev, "Failed to enable bank12 access err=%d\n", |
| 1055 | err); |
| 1056 | |
| 1057 | err = abx500_set_register_interruptible(ab->dev, |
| 1058 | AB8500_DEBUG, AB8500_USB_PHY_TUNE1, 0xC8); |
| 1059 | if (err < 0) |
| 1060 | dev_err(ab->dev, "Failed to set PHY_TUNE1 register err=%d\n", |
| 1061 | err); |
| 1062 | |
| 1063 | err = abx500_set_register_interruptible(ab->dev, |
| 1064 | AB8500_DEBUG, AB8500_USB_PHY_TUNE2, 0x00); |
| 1065 | if (err < 0) |
| 1066 | dev_err(ab->dev, "Failed to set PHY_TUNE2 register err=%d\n", |
| 1067 | err); |
| 1068 | |
| 1069 | err = abx500_set_register_interruptible(ab->dev, |
| 1070 | AB8500_DEBUG, AB8500_USB_PHY_TUNE3, 0x78); |
| 1071 | if (err < 0) |
| 1072 | dev_err(ab->dev, "Failed to set PHY_TUNE3 regester err=%d\n", |
| 1073 | err); |
| 1074 | |
| 1075 | /* Switch to normal mode/disable Bank 0x12 access */ |
| 1076 | err = abx500_set_register_interruptible(ab->dev, |
| 1077 | AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS, 0x00); |
| 1078 | if (err < 0) |
| 1079 | dev_err(ab->dev, "Failed to switch bank12 access err=%d\n", |
| 1080 | err); |
| 1081 | } |
| 1082 | |
| 1083 | static void ab8500_usb_set_ab8505_tuning_values(struct ab8500_usb *ab) |
| 1084 | { |
| 1085 | int err; |
| 1086 | |
| 1087 | /* Enable the PBT/Bank 0x12 access */ |
| 1088 | err = abx500_mask_and_set_register_interruptible(ab->dev, |
| 1089 | AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS, |
| 1090 | 0x01, 0x01); |
| 1091 | if (err < 0) |
| 1092 | dev_err(ab->dev, "Failed to enable bank12 access err=%d\n", |
| 1093 | err); |
| 1094 | |
| 1095 | err = abx500_mask_and_set_register_interruptible(ab->dev, |
| 1096 | AB8500_DEBUG, AB8500_USB_PHY_TUNE1, |
| 1097 | 0xC8, 0xC8); |
| 1098 | if (err < 0) |
| 1099 | dev_err(ab->dev, "Failed to set PHY_TUNE1 register err=%d\n", |
| 1100 | err); |
| 1101 | |
| 1102 | err = abx500_mask_and_set_register_interruptible(ab->dev, |
| 1103 | AB8500_DEBUG, AB8500_USB_PHY_TUNE2, |
| 1104 | 0x60, 0x60); |
| 1105 | if (err < 0) |
| 1106 | dev_err(ab->dev, "Failed to set PHY_TUNE2 register err=%d\n", |
| 1107 | err); |
| 1108 | |
| 1109 | err = abx500_mask_and_set_register_interruptible(ab->dev, |
| 1110 | AB8500_DEBUG, AB8500_USB_PHY_TUNE3, |
| 1111 | 0xFC, 0x80); |
| 1112 | |
| 1113 | if (err < 0) |
| 1114 | dev_err(ab->dev, "Failed to set PHY_TUNE3 regester err=%d\n", |
| 1115 | err); |
| 1116 | |
| 1117 | /* Switch to normal mode/disable Bank 0x12 access */ |
| 1118 | err = abx500_mask_and_set_register_interruptible(ab->dev, |
| 1119 | AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS, |
| 1120 | 0x00, 0x00); |
| 1121 | if (err < 0) |
| 1122 | dev_err(ab->dev, "Failed to switch bank12 access err=%d\n", |
| 1123 | err); |
| 1124 | } |
| 1125 | |
Fabio Baltieri | 0c380c0 | 2013-05-15 14:03:32 +0200 | [diff] [blame^] | 1126 | static void ab8500_usb_set_ab8540_tuning_values(struct ab8500_usb *ab) |
| 1127 | { |
| 1128 | int err; |
| 1129 | |
| 1130 | err = abx500_set_register_interruptible(ab->dev, |
| 1131 | AB8540_DEBUG, AB8500_USB_PHY_TUNE1, 0xCC); |
| 1132 | if (err < 0) |
| 1133 | dev_err(ab->dev, "Failed to set PHY_TUNE1 register ret=%d\n", |
| 1134 | err); |
| 1135 | |
| 1136 | err = abx500_set_register_interruptible(ab->dev, |
| 1137 | AB8540_DEBUG, AB8500_USB_PHY_TUNE2, 0x60); |
| 1138 | if (err < 0) |
| 1139 | dev_err(ab->dev, "Failed to set PHY_TUNE2 register ret=%d\n", |
| 1140 | err); |
| 1141 | |
| 1142 | err = abx500_set_register_interruptible(ab->dev, |
| 1143 | AB8540_DEBUG, AB8500_USB_PHY_TUNE3, 0x90); |
| 1144 | if (err < 0) |
| 1145 | dev_err(ab->dev, "Failed to set PHY_TUNE3 regester ret=%d\n", |
| 1146 | err); |
| 1147 | } |
| 1148 | |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 1149 | static int ab8500_usb_probe(struct platform_device *pdev) |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 1150 | { |
| 1151 | struct ab8500_usb *ab; |
Fabio Baltieri | 73f226c | 2013-03-08 10:27:08 +0800 | [diff] [blame] | 1152 | struct ab8500 *ab8500; |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 1153 | struct usb_otg *otg; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 1154 | int err; |
| 1155 | int rev; |
| 1156 | |
Fabio Baltieri | 73f226c | 2013-03-08 10:27:08 +0800 | [diff] [blame] | 1157 | ab8500 = dev_get_drvdata(pdev->dev.parent); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 1158 | rev = abx500_get_chip_id(&pdev->dev); |
Fabio Baltieri | 73f226c | 2013-03-08 10:27:08 +0800 | [diff] [blame] | 1159 | |
| 1160 | if (is_ab8500_1p1_or_earlier(ab8500)) { |
| 1161 | dev_err(&pdev->dev, "Unsupported AB8500 chip rev=%d\n", rev); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 1162 | return -ENODEV; |
| 1163 | } |
| 1164 | |
Fabio Baltieri | 81ef672 | 2013-04-03 10:45:03 +0200 | [diff] [blame] | 1165 | ab = devm_kzalloc(&pdev->dev, sizeof(*ab), GFP_KERNEL); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 1166 | if (!ab) |
| 1167 | return -ENOMEM; |
| 1168 | |
Fabio Baltieri | 81ef672 | 2013-04-03 10:45:03 +0200 | [diff] [blame] | 1169 | otg = devm_kzalloc(&pdev->dev, sizeof(*otg), GFP_KERNEL); |
| 1170 | if (!otg) |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 1171 | return -ENOMEM; |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 1172 | |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 1173 | ab->dev = &pdev->dev; |
Fabio Baltieri | 73f226c | 2013-03-08 10:27:08 +0800 | [diff] [blame] | 1174 | ab->ab8500 = ab8500; |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 1175 | ab->phy.dev = ab->dev; |
| 1176 | ab->phy.otg = otg; |
| 1177 | ab->phy.label = "ab8500"; |
| 1178 | ab->phy.set_suspend = ab8500_usb_set_suspend; |
| 1179 | ab->phy.set_power = ab8500_usb_set_power; |
| 1180 | ab->phy.state = OTG_STATE_UNDEFINED; |
| 1181 | |
| 1182 | otg->phy = &ab->phy; |
| 1183 | otg->set_host = ab8500_usb_set_host; |
| 1184 | otg->set_peripheral = ab8500_usb_set_peripheral; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 1185 | |
Fabio Baltieri | bd4c9f0 | 2013-05-15 14:03:31 +0200 | [diff] [blame] | 1186 | if (is_ab8500(ab->ab8500)) { |
| 1187 | ab->flags |= AB8500_USB_FLAG_USE_LINK_STATUS_IRQ | |
| 1188 | AB8500_USB_FLAG_USE_ID_WAKEUP_IRQ | |
| 1189 | AB8500_USB_FLAG_USE_VBUS_DET_IRQ | |
| 1190 | AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE; |
| 1191 | } else if (is_ab8505(ab->ab8500)) { |
| 1192 | ab->flags |= AB8500_USB_FLAG_USE_LINK_STATUS_IRQ | |
| 1193 | AB8500_USB_FLAG_USE_ID_WAKEUP_IRQ | |
| 1194 | AB8500_USB_FLAG_USE_VBUS_DET_IRQ | |
| 1195 | AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE; |
Fabio Baltieri | 0c380c0 | 2013-05-15 14:03:32 +0200 | [diff] [blame^] | 1196 | } else if (is_ab8540(ab->ab8500)) { |
| 1197 | ab->flags |= AB8500_USB_FLAG_USE_LINK_STATUS_IRQ | |
| 1198 | AB8500_USB_FLAG_USE_CHECK_VBUS_STATUS | |
| 1199 | AB8500_USB_FLAG_USE_VBUS_HOST_QUIRK | |
| 1200 | AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE; |
Fabio Baltieri | bd4c9f0 | 2013-05-15 14:03:31 +0200 | [diff] [blame] | 1201 | } |
| 1202 | |
| 1203 | /* Disable regulator voltage setting for AB8500 <= v2.0 */ |
| 1204 | if (is_ab8500_2p0_or_earlier(ab->ab8500)) |
| 1205 | ab->flags &= ~AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE; |
| 1206 | |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 1207 | platform_set_drvdata(pdev, ab); |
| 1208 | |
Heikki Krogerus | 144713f | 2012-02-13 13:24:05 +0200 | [diff] [blame] | 1209 | ATOMIC_INIT_NOTIFIER_HEAD(&ab->phy.notifier); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 1210 | |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 1211 | /* all: Disable phy when called from set_host and set_peripheral */ |
| 1212 | INIT_WORK(&ab->phy_dis_work, ab8500_usb_phy_disable_work); |
| 1213 | |
Fabio Baltieri | 0c380c0 | 2013-05-15 14:03:32 +0200 | [diff] [blame^] | 1214 | INIT_WORK(&ab->vbus_event_work, ab8500_usb_vbus_turn_on_event_work); |
| 1215 | |
Fabio Baltieri | e65b36c | 2013-04-03 10:45:06 +0200 | [diff] [blame] | 1216 | err = ab8500_usb_regulator_get(ab); |
| 1217 | if (err) |
| 1218 | return err; |
| 1219 | |
Mian Yousaf Kaukab | d0ed064 | 2013-05-15 14:03:26 +0200 | [diff] [blame] | 1220 | ab->sysclk = devm_clk_get(ab->dev, "sysclk"); |
| 1221 | if (IS_ERR(ab->sysclk)) { |
| 1222 | dev_err(ab->dev, "Could not get sysclk.\n"); |
| 1223 | return PTR_ERR(ab->sysclk); |
| 1224 | } |
| 1225 | |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 1226 | err = ab8500_usb_irq_setup(pdev, ab); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 1227 | if (err < 0) |
Fabio Baltieri | 81ef672 | 2013-04-03 10:45:03 +0200 | [diff] [blame] | 1228 | return err; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 1229 | |
Kishon Vijay Abraham I | 662dca5 | 2012-06-22 17:02:46 +0530 | [diff] [blame] | 1230 | err = usb_add_phy(&ab->phy, USB_PHY_TYPE_USB2); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 1231 | if (err) { |
| 1232 | dev_err(&pdev->dev, "Can't register transceiver\n"); |
Fabio Baltieri | 81ef672 | 2013-04-03 10:45:03 +0200 | [diff] [blame] | 1233 | return err; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 1234 | } |
| 1235 | |
Fabio Baltieri | 16604a3 | 2013-05-15 14:03:30 +0200 | [diff] [blame] | 1236 | if (is_ab8500(ab->ab8500) && !is_ab8500_2p0_or_earlier(ab->ab8500)) |
| 1237 | /* Phy tuning values for AB8500 > v2.0 */ |
| 1238 | ab8500_usb_set_ab8500_tuning_values(ab); |
| 1239 | else if (is_ab8505(ab->ab8500)) |
| 1240 | /* Phy tuning values for AB8505 */ |
| 1241 | ab8500_usb_set_ab8505_tuning_values(ab); |
Fabio Baltieri | 0c380c0 | 2013-05-15 14:03:32 +0200 | [diff] [blame^] | 1242 | else if (is_ab8540(ab->ab8500)) |
| 1243 | /* Phy tuning values for AB8540 */ |
| 1244 | ab8500_usb_set_ab8540_tuning_values(ab); |
Sakethram Bommisetti | 7124631 | 2013-04-03 10:45:04 +0200 | [diff] [blame] | 1245 | |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 1246 | /* Needed to enable ID detection. */ |
| 1247 | ab8500_usb_wd_workaround(ab); |
| 1248 | |
Sakethram Bommisetti | fb21f37 | 2013-05-15 14:03:27 +0200 | [diff] [blame] | 1249 | /* |
| 1250 | * This is required for usb-link-status to work properly when a |
| 1251 | * cable is connected at boot time. |
| 1252 | */ |
| 1253 | ab8500_usb_restart_phy(ab); |
| 1254 | |
Fabio Baltieri | 0c380c0 | 2013-05-15 14:03:32 +0200 | [diff] [blame^] | 1255 | if (ab->flags & AB8500_USB_FLAG_USE_CHECK_VBUS_STATUS) { |
| 1256 | if (ab8500_usb_check_vbus_status(ab)) |
| 1257 | schedule_work(&ab->vbus_event_work); |
| 1258 | } |
| 1259 | |
Sakethram Bommisetti | 8db1223 | 2013-04-03 10:45:12 +0200 | [diff] [blame] | 1260 | abx500_usb_link_status_update(ab); |
| 1261 | |
Fabio Baltieri | 73f226c | 2013-03-08 10:27:08 +0800 | [diff] [blame] | 1262 | dev_info(&pdev->dev, "revision 0x%2x driver initialized\n", rev); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 1263 | |
| 1264 | return 0; |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 1265 | } |
| 1266 | |
Bill Pemberton | fb4e98a | 2012-11-19 13:26:20 -0500 | [diff] [blame] | 1267 | static int ab8500_usb_remove(struct platform_device *pdev) |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 1268 | { |
| 1269 | struct ab8500_usb *ab = platform_get_drvdata(pdev); |
| 1270 | |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 1271 | cancel_work_sync(&ab->phy_dis_work); |
Fabio Baltieri | 0c380c0 | 2013-05-15 14:03:32 +0200 | [diff] [blame^] | 1272 | cancel_work_sync(&ab->vbus_event_work); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 1273 | |
Kishon Vijay Abraham I | 662dca5 | 2012-06-22 17:02:46 +0530 | [diff] [blame] | 1274 | usb_remove_phy(&ab->phy); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 1275 | |
Mian Yousaf Kaukab | f5ef7b4 | 2013-04-03 10:45:09 +0200 | [diff] [blame] | 1276 | if (ab->mode == USB_HOST) |
| 1277 | ab8500_usb_host_phy_dis(ab); |
| 1278 | else if (ab->mode == USB_PERIPHERAL) |
| 1279 | ab8500_usb_peri_phy_dis(ab); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 1280 | |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 1281 | return 0; |
| 1282 | } |
| 1283 | |
Fabio Baltieri | b3affc3 | 2013-05-15 14:03:29 +0200 | [diff] [blame] | 1284 | static struct platform_device_id ab8500_usb_devtype[] = { |
| 1285 | { .name = "ab8500-usb", }, |
Fabio Baltieri | 0c380c0 | 2013-05-15 14:03:32 +0200 | [diff] [blame^] | 1286 | { .name = "ab8540-usb", }, |
Fabio Baltieri | b3affc3 | 2013-05-15 14:03:29 +0200 | [diff] [blame] | 1287 | { /* sentinel */ } |
| 1288 | }; |
| 1289 | MODULE_DEVICE_TABLE(platform, ab8500_usb_devtype); |
| 1290 | |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 1291 | static struct platform_driver ab8500_usb_driver = { |
| 1292 | .probe = ab8500_usb_probe, |
Bill Pemberton | 7690417 | 2012-11-19 13:21:08 -0500 | [diff] [blame] | 1293 | .remove = ab8500_usb_remove, |
Fabio Baltieri | b3affc3 | 2013-05-15 14:03:29 +0200 | [diff] [blame] | 1294 | .id_table = ab8500_usb_devtype, |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 1295 | .driver = { |
Fabio Baltieri | b3affc3 | 2013-05-15 14:03:29 +0200 | [diff] [blame] | 1296 | .name = "abx5x0-usb", |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 1297 | .owner = THIS_MODULE, |
| 1298 | }, |
| 1299 | }; |
| 1300 | |
| 1301 | static int __init ab8500_usb_init(void) |
| 1302 | { |
| 1303 | return platform_driver_register(&ab8500_usb_driver); |
| 1304 | } |
| 1305 | subsys_initcall(ab8500_usb_init); |
| 1306 | |
| 1307 | static void __exit ab8500_usb_exit(void) |
| 1308 | { |
| 1309 | platform_driver_unregister(&ab8500_usb_driver); |
| 1310 | } |
| 1311 | module_exit(ab8500_usb_exit); |
| 1312 | |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 1313 | MODULE_AUTHOR("ST-Ericsson AB"); |
Fabio Baltieri | 0c380c0 | 2013-05-15 14:03:32 +0200 | [diff] [blame^] | 1314 | MODULE_DESCRIPTION("AB8500 family usb transceiver driver"); |
Mian Yousaf Kaukab | 9691523 | 2010-12-07 15:00:09 +0100 | [diff] [blame] | 1315 | MODULE_LICENSE("GPL"); |