1 // SPDX-License-Identifier: GPL-2.0+
3 * USB transceiver driver for AB8500 family chips
5 * Copyright (C) 2010-2013 ST-Ericsson AB
6 * Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>
7 * Avinash Kumar <avinash.kumar@stericsson.com>
8 * Thirupathi Chippakurthy <thirupathi.chippakurthy@stericsson.com>
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.
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.
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.
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>
33 #include <linux/clk.h>
34 #include <linux/err.h>
35 #include <linux/mfd/abx500.h>
36 #include <linux/mfd/abx500/ab8500.h>
37 #include <linux/usb/musb-ux500.h>
38 #include <linux/regulator/consumer.h>
39 #include <linux/pinctrl/consumer.h>
41 /* Bank AB8500_SYS_CTRL2_BLOCK */
42 #define AB8500_MAIN_WD_CTRL_REG 0x01
45 #define AB8500_USB_LINE_STAT_REG 0x80
46 #define AB8505_USB_LINE_STAT_REG 0x94
47 #define AB8540_USB_LINK_STAT_REG 0x94
48 #define AB9540_USB_LINK_STAT_REG 0x94
49 #define AB8540_USB_OTG_CTL_REG 0x87
50 #define AB8500_USB_PHY_CTRL_REG 0x8A
51 #define AB8540_VBUS_CTRL_REG 0x82
53 /* Bank AB8500_DEVELOPMENT */
54 #define AB8500_BANK12_ACCESS 0x00
56 /* Bank AB8500_DEBUG */
57 #define AB8540_DEBUG 0x32
58 #define AB8500_USB_PHY_TUNE1 0x05
59 #define AB8500_USB_PHY_TUNE2 0x06
60 #define AB8500_USB_PHY_TUNE3 0x07
62 /* Bank AB8500_INTERRUPT */
63 #define AB8500_IT_SOURCE2_REG 0x01
65 #define AB8500_BIT_OTG_STAT_ID (1 << 0)
66 #define AB8500_BIT_PHY_CTRL_HOST_EN (1 << 0)
67 #define AB8500_BIT_PHY_CTRL_DEVICE_EN (1 << 1)
68 #define AB8500_BIT_WD_CTRL_ENABLE (1 << 0)
69 #define AB8500_BIT_WD_CTRL_KICK (1 << 1)
70 #define AB8500_BIT_SOURCE2_VBUSDET (1 << 7)
71 #define AB8540_BIT_OTG_CTL_VBUS_VALID_ENA (1 << 0)
72 #define AB8540_BIT_OTG_CTL_ID_HOST_ENA (1 << 1)
73 #define AB8540_BIT_OTG_CTL_ID_DEV_ENA (1 << 5)
74 #define AB8540_BIT_VBUS_CTRL_CHARG_DET_ENA (1 << 0)
76 #define AB8500_WD_KICK_DELAY_US 100 /* usec */
77 #define AB8500_WD_V11_DISABLE_DELAY_US 100 /* usec */
78 #define AB8500_V20_31952_DISABLE_DELAY_US 100 /* usec */
80 /* Usb line status register */
81 enum ab8500_usb_link_status {
82 USB_LINK_NOT_CONFIGURED_8500 = 0,
83 USB_LINK_STD_HOST_NC_8500,
84 USB_LINK_STD_HOST_C_NS_8500,
85 USB_LINK_STD_HOST_C_S_8500,
86 USB_LINK_HOST_CHG_NM_8500,
87 USB_LINK_HOST_CHG_HS_8500,
88 USB_LINK_HOST_CHG_HS_CHIRP_8500,
89 USB_LINK_DEDICATED_CHG_8500,
90 USB_LINK_ACA_RID_A_8500,
91 USB_LINK_ACA_RID_B_8500,
92 USB_LINK_ACA_RID_C_NM_8500,
93 USB_LINK_ACA_RID_C_HS_8500,
94 USB_LINK_ACA_RID_C_HS_CHIRP_8500,
95 USB_LINK_HM_IDGND_8500,
96 USB_LINK_RESERVED_8500,
97 USB_LINK_NOT_VALID_LINK_8500,
100 enum ab8505_usb_link_status {
101 USB_LINK_NOT_CONFIGURED_8505 = 0,
102 USB_LINK_STD_HOST_NC_8505,
103 USB_LINK_STD_HOST_C_NS_8505,
104 USB_LINK_STD_HOST_C_S_8505,
106 USB_LINK_RESERVED0_8505,
107 USB_LINK_RESERVED1_8505,
108 USB_LINK_DEDICATED_CHG_8505,
109 USB_LINK_ACA_RID_A_8505,
110 USB_LINK_ACA_RID_B_8505,
111 USB_LINK_ACA_RID_C_NM_8505,
112 USB_LINK_RESERVED2_8505,
113 USB_LINK_RESERVED3_8505,
114 USB_LINK_HM_IDGND_8505,
115 USB_LINK_CHARGERPORT_NOT_OK_8505,
116 USB_LINK_CHARGER_DM_HIGH_8505,
117 USB_LINK_PHYEN_NO_VBUS_NO_IDGND_8505,
118 USB_LINK_STD_UPSTREAM_NO_IDGNG_NO_VBUS_8505,
119 USB_LINK_STD_UPSTREAM_8505,
120 USB_LINK_CHARGER_SE1_8505,
121 USB_LINK_CARKIT_CHGR_1_8505,
122 USB_LINK_CARKIT_CHGR_2_8505,
123 USB_LINK_ACA_DOCK_CHGR_8505,
124 USB_LINK_SAMSUNG_BOOT_CBL_PHY_EN_8505,
125 USB_LINK_SAMSUNG_BOOT_CBL_PHY_DISB_8505,
126 USB_LINK_SAMSUNG_UART_CBL_PHY_EN_8505,
127 USB_LINK_SAMSUNG_UART_CBL_PHY_DISB_8505,
128 USB_LINK_MOTOROLA_FACTORY_CBL_PHY_EN_8505,
131 enum ab8540_usb_link_status {
132 USB_LINK_NOT_CONFIGURED_8540 = 0,
133 USB_LINK_STD_HOST_NC_8540,
134 USB_LINK_STD_HOST_C_NS_8540,
135 USB_LINK_STD_HOST_C_S_8540,
137 USB_LINK_RESERVED0_8540,
138 USB_LINK_RESERVED1_8540,
139 USB_LINK_DEDICATED_CHG_8540,
140 USB_LINK_ACA_RID_A_8540,
141 USB_LINK_ACA_RID_B_8540,
142 USB_LINK_ACA_RID_C_NM_8540,
143 USB_LINK_RESERVED2_8540,
144 USB_LINK_RESERVED3_8540,
145 USB_LINK_HM_IDGND_8540,
146 USB_LINK_CHARGERPORT_NOT_OK_8540,
147 USB_LINK_CHARGER_DM_HIGH_8540,
148 USB_LINK_PHYEN_NO_VBUS_NO_IDGND_8540,
149 USB_LINK_STD_UPSTREAM_NO_IDGNG_VBUS_8540,
150 USB_LINK_STD_UPSTREAM_8540,
151 USB_LINK_CHARGER_SE1_8540,
152 USB_LINK_CARKIT_CHGR_1_8540,
153 USB_LINK_CARKIT_CHGR_2_8540,
154 USB_LINK_ACA_DOCK_CHGR_8540,
155 USB_LINK_SAMSUNG_BOOT_CBL_PHY_EN_8540,
156 USB_LINK_SAMSUNG_BOOT_CBL_PHY_DISB_8540,
157 USB_LINK_SAMSUNG_UART_CBL_PHY_EN_8540,
158 USB_LINK_SAMSUNG_UART_CBL_PHY_DISB_8540,
159 USB_LINK_MOTOROLA_FACTORY_CBL_PHY_EN_8540
162 enum ab9540_usb_link_status {
163 USB_LINK_NOT_CONFIGURED_9540 = 0,
164 USB_LINK_STD_HOST_NC_9540,
165 USB_LINK_STD_HOST_C_NS_9540,
166 USB_LINK_STD_HOST_C_S_9540,
168 USB_LINK_RESERVED0_9540,
169 USB_LINK_RESERVED1_9540,
170 USB_LINK_DEDICATED_CHG_9540,
171 USB_LINK_ACA_RID_A_9540,
172 USB_LINK_ACA_RID_B_9540,
173 USB_LINK_ACA_RID_C_NM_9540,
174 USB_LINK_RESERVED2_9540,
175 USB_LINK_RESERVED3_9540,
176 USB_LINK_HM_IDGND_9540,
177 USB_LINK_CHARGERPORT_NOT_OK_9540,
178 USB_LINK_CHARGER_DM_HIGH_9540,
179 USB_LINK_PHYEN_NO_VBUS_NO_IDGND_9540,
180 USB_LINK_STD_UPSTREAM_NO_IDGNG_VBUS_9540,
181 USB_LINK_STD_UPSTREAM_9540,
182 USB_LINK_CHARGER_SE1_9540,
183 USB_LINK_CARKIT_CHGR_1_9540,
184 USB_LINK_CARKIT_CHGR_2_9540,
185 USB_LINK_ACA_DOCK_CHGR_9540,
186 USB_LINK_SAMSUNG_BOOT_CBL_PHY_EN_9540,
187 USB_LINK_SAMSUNG_BOOT_CBL_PHY_DISB_9540,
188 USB_LINK_SAMSUNG_UART_CBL_PHY_EN_9540,
189 USB_LINK_SAMSUNG_UART_CBL_PHY_DISB_9540,
190 USB_LINK_MOTOROLA_FACTORY_CBL_PHY_EN_9540
193 enum ab8500_usb_mode {
200 /* Register USB_LINK_STATUS interrupt */
201 #define AB8500_USB_FLAG_USE_LINK_STATUS_IRQ (1 << 0)
202 /* Register ID_WAKEUP_F interrupt */
203 #define AB8500_USB_FLAG_USE_ID_WAKEUP_IRQ (1 << 1)
204 /* Register VBUS_DET_F interrupt */
205 #define AB8500_USB_FLAG_USE_VBUS_DET_IRQ (1 << 2)
206 /* Driver is using the ab-iddet driver*/
207 #define AB8500_USB_FLAG_USE_AB_IDDET (1 << 3)
208 /* Enable setting regulators voltage */
209 #define AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE (1 << 4)
210 /* Enable the check_vbus_status workaround */
211 #define AB8500_USB_FLAG_USE_CHECK_VBUS_STATUS (1 << 5)
212 /* Enable the vbus host workaround */
213 #define AB8500_USB_FLAG_USE_VBUS_HOST_QUIRK (1 << 6)
218 struct ab8500 *ab8500;
220 struct work_struct phy_dis_work;
221 struct work_struct vbus_event_work;
222 enum ab8500_usb_mode mode;
224 struct regulator *v_ape;
225 struct regulator *v_musb;
226 struct regulator *v_ulpi;
228 int previous_link_status_state;
229 struct pinctrl *pinctrl;
230 struct pinctrl_state *pins_sleep;
231 bool enabled_charging_detection;
235 static inline struct ab8500_usb *phy_to_ab(struct usb_phy *x)
237 return container_of(x, struct ab8500_usb, phy);
240 static void ab8500_usb_wd_workaround(struct ab8500_usb *ab)
242 abx500_set_register_interruptible(ab->dev,
243 AB8500_SYS_CTRL2_BLOCK,
244 AB8500_MAIN_WD_CTRL_REG,
245 AB8500_BIT_WD_CTRL_ENABLE);
247 udelay(AB8500_WD_KICK_DELAY_US);
249 abx500_set_register_interruptible(ab->dev,
250 AB8500_SYS_CTRL2_BLOCK,
251 AB8500_MAIN_WD_CTRL_REG,
252 (AB8500_BIT_WD_CTRL_ENABLE
253 | AB8500_BIT_WD_CTRL_KICK));
255 udelay(AB8500_WD_V11_DISABLE_DELAY_US);
257 abx500_set_register_interruptible(ab->dev,
258 AB8500_SYS_CTRL2_BLOCK,
259 AB8500_MAIN_WD_CTRL_REG,
263 static void ab8500_usb_regulator_enable(struct ab8500_usb *ab)
267 ret = regulator_enable(ab->v_ape);
269 dev_err(ab->dev, "Failed to enable v-ape\n");
271 if (ab->flags & AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE) {
272 ab->saved_v_ulpi = regulator_get_voltage(ab->v_ulpi);
273 if (ab->saved_v_ulpi < 0)
274 dev_err(ab->dev, "Failed to get v_ulpi voltage\n");
276 ret = regulator_set_voltage(ab->v_ulpi, 1300000, 1350000);
278 dev_err(ab->dev, "Failed to set the Vintcore to 1.3V, ret=%d\n",
281 ret = regulator_set_load(ab->v_ulpi, 28000);
283 dev_err(ab->dev, "Failed to set optimum mode (ret=%d)\n",
287 ret = regulator_enable(ab->v_ulpi);
289 dev_err(ab->dev, "Failed to enable vddulpivio18\n");
291 if (ab->flags & AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE) {
292 volt = regulator_get_voltage(ab->v_ulpi);
293 if ((volt != 1300000) && (volt != 1350000))
294 dev_err(ab->dev, "Vintcore is not set to 1.3V volt=%d\n",
298 ret = regulator_enable(ab->v_musb);
300 dev_err(ab->dev, "Failed to enable musb_1v8\n");
303 static void ab8500_usb_regulator_disable(struct ab8500_usb *ab)
307 regulator_disable(ab->v_musb);
309 regulator_disable(ab->v_ulpi);
311 /* USB is not the only consumer of Vintcore, restore old settings */
312 if (ab->flags & AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE) {
313 if (ab->saved_v_ulpi > 0) {
314 ret = regulator_set_voltage(ab->v_ulpi,
315 ab->saved_v_ulpi, ab->saved_v_ulpi);
317 dev_err(ab->dev, "Failed to set the Vintcore to %duV, ret=%d\n",
318 ab->saved_v_ulpi, ret);
321 ret = regulator_set_load(ab->v_ulpi, 0);
323 dev_err(ab->dev, "Failed to set optimum mode (ret=%d)\n",
327 regulator_disable(ab->v_ape);
330 static void ab8500_usb_wd_linkstatus(struct ab8500_usb *ab, u8 bit)
332 /* Workaround for v2.0 bug # 31952 */
333 if (is_ab8500_2p0(ab->ab8500)) {
334 abx500_mask_and_set_register_interruptible(ab->dev,
335 AB8500_USB, AB8500_USB_PHY_CTRL_REG,
337 udelay(AB8500_V20_31952_DISABLE_DELAY_US);
341 static void ab8500_usb_phy_enable(struct ab8500_usb *ab, bool sel_host)
344 bit = sel_host ? AB8500_BIT_PHY_CTRL_HOST_EN :
345 AB8500_BIT_PHY_CTRL_DEVICE_EN;
347 /* mux and configure USB pins to DEFAULT state */
348 ab->pinctrl = pinctrl_get_select(ab->dev, PINCTRL_STATE_DEFAULT);
349 if (IS_ERR(ab->pinctrl))
350 dev_err(ab->dev, "could not get/set default pinstate\n");
352 if (clk_prepare_enable(ab->sysclk))
353 dev_err(ab->dev, "can't prepare/enable clock\n");
355 ab8500_usb_regulator_enable(ab);
357 abx500_mask_and_set_register_interruptible(ab->dev,
358 AB8500_USB, AB8500_USB_PHY_CTRL_REG,
361 if (ab->flags & AB8500_USB_FLAG_USE_VBUS_HOST_QUIRK) {
363 abx500_set_register_interruptible(ab->dev,
364 AB8500_USB, AB8540_USB_OTG_CTL_REG,
365 AB8540_BIT_OTG_CTL_VBUS_VALID_ENA |
366 AB8540_BIT_OTG_CTL_ID_HOST_ENA |
367 AB8540_BIT_OTG_CTL_ID_DEV_ENA);
371 static void ab8500_usb_phy_disable(struct ab8500_usb *ab, bool sel_host)
374 bit = sel_host ? AB8500_BIT_PHY_CTRL_HOST_EN :
375 AB8500_BIT_PHY_CTRL_DEVICE_EN;
377 ab8500_usb_wd_linkstatus(ab, bit);
379 abx500_mask_and_set_register_interruptible(ab->dev,
380 AB8500_USB, AB8500_USB_PHY_CTRL_REG,
383 /* Needed to disable the phy.*/
384 ab8500_usb_wd_workaround(ab);
386 clk_disable_unprepare(ab->sysclk);
388 ab8500_usb_regulator_disable(ab);
390 if (!IS_ERR(ab->pinctrl)) {
391 /* configure USB pins to SLEEP state */
392 ab->pins_sleep = pinctrl_lookup_state(ab->pinctrl,
393 PINCTRL_STATE_SLEEP);
395 if (IS_ERR(ab->pins_sleep))
396 dev_dbg(ab->dev, "could not get sleep pinstate\n");
397 else if (pinctrl_select_state(ab->pinctrl, ab->pins_sleep))
398 dev_err(ab->dev, "could not set pins to sleep state\n");
401 * as USB pins are shared with iddet, release them to allow
402 * iddet to request them
404 pinctrl_put(ab->pinctrl);
408 #define ab8500_usb_host_phy_en(ab) ab8500_usb_phy_enable(ab, true)
409 #define ab8500_usb_host_phy_dis(ab) ab8500_usb_phy_disable(ab, true)
410 #define ab8500_usb_peri_phy_en(ab) ab8500_usb_phy_enable(ab, false)
411 #define ab8500_usb_peri_phy_dis(ab) ab8500_usb_phy_disable(ab, false)
413 static int ab9540_usb_link_status_update(struct ab8500_usb *ab,
414 enum ab9540_usb_link_status lsts)
416 enum ux500_musb_vbus_id_status event = 0;
418 dev_dbg(ab->dev, "ab9540_usb_link_status_update %d\n", lsts);
420 if (ab->previous_link_status_state == USB_LINK_HM_IDGND_9540 &&
421 (lsts == USB_LINK_STD_HOST_C_NS_9540 ||
422 lsts == USB_LINK_STD_HOST_NC_9540))
425 if (ab->previous_link_status_state == USB_LINK_ACA_RID_A_9540 &&
426 (lsts == USB_LINK_STD_HOST_NC_9540))
429 ab->previous_link_status_state = lsts;
432 case USB_LINK_ACA_RID_B_9540:
433 event = UX500_MUSB_RIDB;
434 case USB_LINK_NOT_CONFIGURED_9540:
435 case USB_LINK_RESERVED0_9540:
436 case USB_LINK_RESERVED1_9540:
437 case USB_LINK_RESERVED2_9540:
438 case USB_LINK_RESERVED3_9540:
439 if (ab->mode == USB_PERIPHERAL)
440 atomic_notifier_call_chain(&ab->phy.notifier,
441 UX500_MUSB_CLEAN, &ab->vbus_draw);
443 ab->phy.otg->default_a = false;
445 if (event != UX500_MUSB_RIDB)
446 event = UX500_MUSB_NONE;
447 /* Fallback to default B_IDLE as nothing is connected. */
448 ab->phy.otg->state = OTG_STATE_B_IDLE;
449 usb_phy_set_event(&ab->phy, USB_EVENT_NONE);
452 case USB_LINK_ACA_RID_C_NM_9540:
453 event = UX500_MUSB_RIDC;
454 case USB_LINK_STD_HOST_NC_9540:
455 case USB_LINK_STD_HOST_C_NS_9540:
456 case USB_LINK_STD_HOST_C_S_9540:
457 case USB_LINK_CDP_9540:
458 if (ab->mode == USB_HOST) {
459 ab->mode = USB_PERIPHERAL;
460 ab8500_usb_host_phy_dis(ab);
461 ab8500_usb_peri_phy_en(ab);
462 atomic_notifier_call_chain(&ab->phy.notifier,
463 UX500_MUSB_PREPARE, &ab->vbus_draw);
464 usb_phy_set_event(&ab->phy, USB_EVENT_ENUMERATED);
466 if (ab->mode == USB_IDLE) {
467 ab->mode = USB_PERIPHERAL;
468 ab8500_usb_peri_phy_en(ab);
469 atomic_notifier_call_chain(&ab->phy.notifier,
470 UX500_MUSB_PREPARE, &ab->vbus_draw);
471 usb_phy_set_event(&ab->phy, USB_EVENT_ENUMERATED);
473 if (event != UX500_MUSB_RIDC)
474 event = UX500_MUSB_VBUS;
477 case USB_LINK_ACA_RID_A_9540:
478 event = UX500_MUSB_RIDA;
479 case USB_LINK_HM_IDGND_9540:
480 case USB_LINK_STD_UPSTREAM_9540:
481 if (ab->mode == USB_PERIPHERAL) {
483 ab8500_usb_peri_phy_dis(ab);
484 ab8500_usb_host_phy_en(ab);
485 atomic_notifier_call_chain(&ab->phy.notifier,
486 UX500_MUSB_PREPARE, &ab->vbus_draw);
488 if (ab->mode == USB_IDLE) {
490 ab8500_usb_host_phy_en(ab);
491 atomic_notifier_call_chain(&ab->phy.notifier,
492 UX500_MUSB_PREPARE, &ab->vbus_draw);
494 ab->phy.otg->default_a = true;
495 if (event != UX500_MUSB_RIDA)
496 event = UX500_MUSB_ID;
498 atomic_notifier_call_chain(&ab->phy.notifier,
499 event, &ab->vbus_draw);
502 case USB_LINK_DEDICATED_CHG_9540:
503 ab->mode = USB_DEDICATED_CHG;
504 event = UX500_MUSB_CHARGER;
505 atomic_notifier_call_chain(&ab->phy.notifier,
506 event, &ab->vbus_draw);
507 usb_phy_set_event(&ab->phy, USB_EVENT_CHARGER);
510 case USB_LINK_PHYEN_NO_VBUS_NO_IDGND_9540:
511 case USB_LINK_STD_UPSTREAM_NO_IDGNG_VBUS_9540:
512 if (!(is_ab9540_2p0_or_earlier(ab->ab8500))) {
513 event = UX500_MUSB_NONE;
514 if (ab->mode == USB_HOST) {
515 ab->phy.otg->default_a = false;
517 atomic_notifier_call_chain(&ab->phy.notifier,
518 event, &ab->vbus_draw);
519 ab8500_usb_host_phy_dis(ab);
522 if (ab->mode == USB_PERIPHERAL) {
523 atomic_notifier_call_chain(&ab->phy.notifier,
524 event, &ab->vbus_draw);
525 ab8500_usb_peri_phy_dis(ab);
526 atomic_notifier_call_chain(&ab->phy.notifier,
530 ab->phy.otg->default_a = false;
532 usb_phy_set_event(&ab->phy, USB_EVENT_NONE);
544 static int ab8540_usb_link_status_update(struct ab8500_usb *ab,
545 enum ab8540_usb_link_status lsts)
547 enum ux500_musb_vbus_id_status event = 0;
549 dev_dbg(ab->dev, "ab8540_usb_link_status_update %d\n", lsts);
551 if (ab->enabled_charging_detection) {
552 /* Disable USB Charger detection */
553 abx500_mask_and_set_register_interruptible(ab->dev,
554 AB8500_USB, AB8540_VBUS_CTRL_REG,
555 AB8540_BIT_VBUS_CTRL_CHARG_DET_ENA, 0x00);
556 ab->enabled_charging_detection = false;
560 * Spurious link_status interrupts are seen in case of a
561 * disconnection of a device in IDGND and RIDA stage
563 if (ab->previous_link_status_state == USB_LINK_HM_IDGND_8540 &&
564 (lsts == USB_LINK_STD_HOST_C_NS_8540 ||
565 lsts == USB_LINK_STD_HOST_NC_8540))
568 if (ab->previous_link_status_state == USB_LINK_ACA_RID_A_8540 &&
569 (lsts == USB_LINK_STD_HOST_NC_8540))
572 ab->previous_link_status_state = lsts;
575 case USB_LINK_ACA_RID_B_8540:
576 event = UX500_MUSB_RIDB;
577 case USB_LINK_NOT_CONFIGURED_8540:
578 case USB_LINK_RESERVED0_8540:
579 case USB_LINK_RESERVED1_8540:
580 case USB_LINK_RESERVED2_8540:
581 case USB_LINK_RESERVED3_8540:
583 ab->phy.otg->default_a = false;
585 if (event != UX500_MUSB_RIDB)
586 event = UX500_MUSB_NONE;
588 * Fallback to default B_IDLE as nothing
591 ab->phy.otg->state = OTG_STATE_B_IDLE;
592 usb_phy_set_event(&ab->phy, USB_EVENT_NONE);
595 case USB_LINK_ACA_RID_C_NM_8540:
596 event = UX500_MUSB_RIDC;
597 case USB_LINK_STD_HOST_NC_8540:
598 case USB_LINK_STD_HOST_C_NS_8540:
599 case USB_LINK_STD_HOST_C_S_8540:
600 case USB_LINK_CDP_8540:
601 if (ab->mode == USB_IDLE) {
602 ab->mode = USB_PERIPHERAL;
603 ab8500_usb_peri_phy_en(ab);
604 atomic_notifier_call_chain(&ab->phy.notifier,
605 UX500_MUSB_PREPARE, &ab->vbus_draw);
606 usb_phy_set_event(&ab->phy, USB_EVENT_ENUMERATED);
608 if (event != UX500_MUSB_RIDC)
609 event = UX500_MUSB_VBUS;
612 case USB_LINK_ACA_RID_A_8540:
613 case USB_LINK_ACA_DOCK_CHGR_8540:
614 event = UX500_MUSB_RIDA;
615 case USB_LINK_HM_IDGND_8540:
616 case USB_LINK_STD_UPSTREAM_8540:
617 if (ab->mode == USB_IDLE) {
619 ab8500_usb_host_phy_en(ab);
620 atomic_notifier_call_chain(&ab->phy.notifier,
621 UX500_MUSB_PREPARE, &ab->vbus_draw);
623 ab->phy.otg->default_a = true;
624 if (event != UX500_MUSB_RIDA)
625 event = UX500_MUSB_ID;
626 atomic_notifier_call_chain(&ab->phy.notifier,
627 event, &ab->vbus_draw);
630 case USB_LINK_DEDICATED_CHG_8540:
631 ab->mode = USB_DEDICATED_CHG;
632 event = UX500_MUSB_CHARGER;
633 atomic_notifier_call_chain(&ab->phy.notifier,
634 event, &ab->vbus_draw);
635 usb_phy_set_event(&ab->phy, USB_EVENT_CHARGER);
638 case USB_LINK_PHYEN_NO_VBUS_NO_IDGND_8540:
639 case USB_LINK_STD_UPSTREAM_NO_IDGNG_VBUS_8540:
640 event = UX500_MUSB_NONE;
641 if (ab->mode == USB_HOST) {
642 ab->phy.otg->default_a = false;
644 atomic_notifier_call_chain(&ab->phy.notifier,
645 event, &ab->vbus_draw);
646 ab8500_usb_host_phy_dis(ab);
649 if (ab->mode == USB_PERIPHERAL) {
650 atomic_notifier_call_chain(&ab->phy.notifier,
651 event, &ab->vbus_draw);
652 ab8500_usb_peri_phy_dis(ab);
653 atomic_notifier_call_chain(&ab->phy.notifier,
654 UX500_MUSB_CLEAN, &ab->vbus_draw);
656 ab->phy.otg->default_a = false;
658 usb_phy_set_event(&ab->phy, USB_EVENT_NONE);
663 event = UX500_MUSB_NONE;
670 static int ab8505_usb_link_status_update(struct ab8500_usb *ab,
671 enum ab8505_usb_link_status lsts)
673 enum ux500_musb_vbus_id_status event = 0;
675 dev_dbg(ab->dev, "ab8505_usb_link_status_update %d\n", lsts);
678 * Spurious link_status interrupts are seen at the time of
679 * disconnection of a device in RIDA state
681 if (ab->previous_link_status_state == USB_LINK_ACA_RID_A_8505 &&
682 (lsts == USB_LINK_STD_HOST_NC_8505))
685 ab->previous_link_status_state = lsts;
688 case USB_LINK_ACA_RID_B_8505:
689 event = UX500_MUSB_RIDB;
690 case USB_LINK_NOT_CONFIGURED_8505:
691 case USB_LINK_RESERVED0_8505:
692 case USB_LINK_RESERVED1_8505:
693 case USB_LINK_RESERVED2_8505:
694 case USB_LINK_RESERVED3_8505:
696 ab->phy.otg->default_a = false;
698 if (event != UX500_MUSB_RIDB)
699 event = UX500_MUSB_NONE;
701 * Fallback to default B_IDLE as nothing
704 ab->phy.otg->state = OTG_STATE_B_IDLE;
705 usb_phy_set_event(&ab->phy, USB_EVENT_NONE);
708 case USB_LINK_ACA_RID_C_NM_8505:
709 event = UX500_MUSB_RIDC;
710 case USB_LINK_STD_HOST_NC_8505:
711 case USB_LINK_STD_HOST_C_NS_8505:
712 case USB_LINK_STD_HOST_C_S_8505:
713 case USB_LINK_CDP_8505:
714 if (ab->mode == USB_IDLE) {
715 ab->mode = USB_PERIPHERAL;
716 ab8500_usb_peri_phy_en(ab);
717 atomic_notifier_call_chain(&ab->phy.notifier,
718 UX500_MUSB_PREPARE, &ab->vbus_draw);
719 usb_phy_set_event(&ab->phy, USB_EVENT_ENUMERATED);
721 if (event != UX500_MUSB_RIDC)
722 event = UX500_MUSB_VBUS;
725 case USB_LINK_ACA_RID_A_8505:
726 case USB_LINK_ACA_DOCK_CHGR_8505:
727 event = UX500_MUSB_RIDA;
728 case USB_LINK_HM_IDGND_8505:
729 if (ab->mode == USB_IDLE) {
731 ab8500_usb_host_phy_en(ab);
732 atomic_notifier_call_chain(&ab->phy.notifier,
733 UX500_MUSB_PREPARE, &ab->vbus_draw);
735 ab->phy.otg->default_a = true;
736 if (event != UX500_MUSB_RIDA)
737 event = UX500_MUSB_ID;
738 atomic_notifier_call_chain(&ab->phy.notifier,
739 event, &ab->vbus_draw);
742 case USB_LINK_DEDICATED_CHG_8505:
743 ab->mode = USB_DEDICATED_CHG;
744 event = UX500_MUSB_CHARGER;
745 atomic_notifier_call_chain(&ab->phy.notifier,
746 event, &ab->vbus_draw);
747 usb_phy_set_event(&ab->phy, USB_EVENT_CHARGER);
757 static int ab8500_usb_link_status_update(struct ab8500_usb *ab,
758 enum ab8500_usb_link_status lsts)
760 enum ux500_musb_vbus_id_status event = 0;
762 dev_dbg(ab->dev, "ab8500_usb_link_status_update %d\n", lsts);
765 * Spurious link_status interrupts are seen in case of a
766 * disconnection of a device in IDGND and RIDA stage
768 if (ab->previous_link_status_state == USB_LINK_HM_IDGND_8500 &&
769 (lsts == USB_LINK_STD_HOST_C_NS_8500 ||
770 lsts == USB_LINK_STD_HOST_NC_8500))
773 if (ab->previous_link_status_state == USB_LINK_ACA_RID_A_8500 &&
774 lsts == USB_LINK_STD_HOST_NC_8500)
777 ab->previous_link_status_state = lsts;
780 case USB_LINK_ACA_RID_B_8500:
781 event = UX500_MUSB_RIDB;
782 case USB_LINK_NOT_CONFIGURED_8500:
783 case USB_LINK_NOT_VALID_LINK_8500:
785 ab->phy.otg->default_a = false;
787 if (event != UX500_MUSB_RIDB)
788 event = UX500_MUSB_NONE;
789 /* Fallback to default B_IDLE as nothing is connected */
790 ab->phy.otg->state = OTG_STATE_B_IDLE;
791 usb_phy_set_event(&ab->phy, USB_EVENT_NONE);
794 case USB_LINK_ACA_RID_C_NM_8500:
795 case USB_LINK_ACA_RID_C_HS_8500:
796 case USB_LINK_ACA_RID_C_HS_CHIRP_8500:
797 event = UX500_MUSB_RIDC;
798 case USB_LINK_STD_HOST_NC_8500:
799 case USB_LINK_STD_HOST_C_NS_8500:
800 case USB_LINK_STD_HOST_C_S_8500:
801 case USB_LINK_HOST_CHG_NM_8500:
802 case USB_LINK_HOST_CHG_HS_8500:
803 case USB_LINK_HOST_CHG_HS_CHIRP_8500:
804 if (ab->mode == USB_IDLE) {
805 ab->mode = USB_PERIPHERAL;
806 ab8500_usb_peri_phy_en(ab);
807 atomic_notifier_call_chain(&ab->phy.notifier,
808 UX500_MUSB_PREPARE, &ab->vbus_draw);
809 usb_phy_set_event(&ab->phy, USB_EVENT_ENUMERATED);
811 if (event != UX500_MUSB_RIDC)
812 event = UX500_MUSB_VBUS;
815 case USB_LINK_ACA_RID_A_8500:
816 event = UX500_MUSB_RIDA;
817 case USB_LINK_HM_IDGND_8500:
818 if (ab->mode == USB_IDLE) {
820 ab8500_usb_host_phy_en(ab);
821 atomic_notifier_call_chain(&ab->phy.notifier,
822 UX500_MUSB_PREPARE, &ab->vbus_draw);
824 ab->phy.otg->default_a = true;
825 if (event != UX500_MUSB_RIDA)
826 event = UX500_MUSB_ID;
827 atomic_notifier_call_chain(&ab->phy.notifier,
828 event, &ab->vbus_draw);
831 case USB_LINK_DEDICATED_CHG_8500:
832 ab->mode = USB_DEDICATED_CHG;
833 event = UX500_MUSB_CHARGER;
834 atomic_notifier_call_chain(&ab->phy.notifier,
835 event, &ab->vbus_draw);
836 usb_phy_set_event(&ab->phy, USB_EVENT_CHARGER);
839 case USB_LINK_RESERVED_8500:
847 * Connection Sequence:
848 * 1. Link Status Interrupt
850 * 3. Enable AB regulators
852 * 5. Reset the musb controller
853 * 6. Switch the ULPI GPIO pins to fucntion mode
854 * 7. Enable the musb Peripheral5 clock
855 * 8. Restore MUSB context
857 static int abx500_usb_link_status_update(struct ab8500_usb *ab)
862 if (is_ab8500(ab->ab8500)) {
863 enum ab8500_usb_link_status lsts;
865 abx500_get_register_interruptible(ab->dev,
866 AB8500_USB, AB8500_USB_LINE_STAT_REG, ®);
867 lsts = (reg >> 3) & 0x0F;
868 ret = ab8500_usb_link_status_update(ab, lsts);
869 } else if (is_ab8505(ab->ab8500)) {
870 enum ab8505_usb_link_status lsts;
872 abx500_get_register_interruptible(ab->dev,
873 AB8500_USB, AB8505_USB_LINE_STAT_REG, ®);
874 lsts = (reg >> 3) & 0x1F;
875 ret = ab8505_usb_link_status_update(ab, lsts);
876 } else if (is_ab8540(ab->ab8500)) {
877 enum ab8540_usb_link_status lsts;
879 abx500_get_register_interruptible(ab->dev,
880 AB8500_USB, AB8540_USB_LINK_STAT_REG, ®);
881 lsts = (reg >> 3) & 0xFF;
882 ret = ab8540_usb_link_status_update(ab, lsts);
883 } else if (is_ab9540(ab->ab8500)) {
884 enum ab9540_usb_link_status lsts;
886 abx500_get_register_interruptible(ab->dev,
887 AB8500_USB, AB9540_USB_LINK_STAT_REG, ®);
888 lsts = (reg >> 3) & 0xFF;
889 ret = ab9540_usb_link_status_update(ab, lsts);
896 * Disconnection Sequence:
897 * 1. Disconnect Interrupt
898 * 2. Disable regulators
899 * 3. Disable AB clock
901 * 5. Link Status Interrupt
902 * 6. Disable Musb Clock
904 static irqreturn_t ab8500_usb_disconnect_irq(int irq, void *data)
906 struct ab8500_usb *ab = (struct ab8500_usb *) data;
907 enum usb_phy_events event = UX500_MUSB_NONE;
909 /* Link status will not be updated till phy is disabled. */
910 if (ab->mode == USB_HOST) {
911 ab->phy.otg->default_a = false;
913 atomic_notifier_call_chain(&ab->phy.notifier,
914 event, &ab->vbus_draw);
915 ab8500_usb_host_phy_dis(ab);
919 if (ab->mode == USB_PERIPHERAL) {
920 atomic_notifier_call_chain(&ab->phy.notifier,
921 event, &ab->vbus_draw);
922 ab8500_usb_peri_phy_dis(ab);
923 atomic_notifier_call_chain(&ab->phy.notifier,
924 UX500_MUSB_CLEAN, &ab->vbus_draw);
926 ab->phy.otg->default_a = false;
930 if (is_ab8500_2p0(ab->ab8500)) {
931 if (ab->mode == USB_DEDICATED_CHG) {
932 ab8500_usb_wd_linkstatus(ab,
933 AB8500_BIT_PHY_CTRL_DEVICE_EN);
934 abx500_mask_and_set_register_interruptible(ab->dev,
935 AB8500_USB, AB8500_USB_PHY_CTRL_REG,
936 AB8500_BIT_PHY_CTRL_DEVICE_EN, 0);
943 static irqreturn_t ab8500_usb_link_status_irq(int irq, void *data)
945 struct ab8500_usb *ab = (struct ab8500_usb *)data;
947 abx500_usb_link_status_update(ab);
952 static void ab8500_usb_phy_disable_work(struct work_struct *work)
954 struct ab8500_usb *ab = container_of(work, struct ab8500_usb,
957 if (!ab->phy.otg->host)
958 ab8500_usb_host_phy_dis(ab);
960 if (!ab->phy.otg->gadget)
961 ab8500_usb_peri_phy_dis(ab);
964 /* Check if VBUS is set and linkstatus has not detected a cable. */
965 static bool ab8500_usb_check_vbus_status(struct ab8500_usb *ab)
969 enum ab8540_usb_link_status lsts;
971 abx500_get_register_interruptible(ab->dev,
972 AB8500_INTERRUPT, AB8500_IT_SOURCE2_REG,
975 /* If Vbus is below 3.6V abort */
976 if (!(isource2 & AB8500_BIT_SOURCE2_VBUSDET))
979 abx500_get_register_interruptible(ab->dev,
980 AB8500_USB, AB8540_USB_LINK_STAT_REG,
983 lsts = (reg >> 3) & 0xFF;
985 /* Check if linkstatus has detected a cable */
992 /* re-trigger charger detection again with watchdog re-kick. */
993 static void ab8500_usb_vbus_turn_on_event_work(struct work_struct *work)
995 struct ab8500_usb *ab = container_of(work, struct ab8500_usb,
998 if (ab->mode != USB_IDLE)
1001 abx500_set_register_interruptible(ab->dev,
1002 AB8500_SYS_CTRL2_BLOCK, AB8500_MAIN_WD_CTRL_REG,
1003 AB8500_BIT_WD_CTRL_ENABLE);
1007 abx500_set_register_interruptible(ab->dev,
1008 AB8500_SYS_CTRL2_BLOCK, AB8500_MAIN_WD_CTRL_REG,
1009 AB8500_BIT_WD_CTRL_ENABLE | AB8500_BIT_WD_CTRL_KICK);
1013 /* Disable Main watchdog */
1014 abx500_set_register_interruptible(ab->dev,
1015 AB8500_SYS_CTRL2_BLOCK, AB8500_MAIN_WD_CTRL_REG,
1018 /* Enable USB Charger detection */
1019 abx500_mask_and_set_register_interruptible(ab->dev,
1020 AB8500_USB, AB8540_VBUS_CTRL_REG,
1021 AB8540_BIT_VBUS_CTRL_CHARG_DET_ENA,
1022 AB8540_BIT_VBUS_CTRL_CHARG_DET_ENA);
1024 ab->enabled_charging_detection = true;
1027 static int ab8500_usb_set_suspend(struct usb_phy *x, int suspend)
1033 static int ab8500_usb_set_peripheral(struct usb_otg *otg,
1034 struct usb_gadget *gadget)
1036 struct ab8500_usb *ab;
1041 ab = phy_to_ab(otg->usb_phy);
1043 ab->phy.otg->gadget = gadget;
1045 /* Some drivers call this function in atomic context.
1046 * Do not update ab8500 registers directly till this
1050 if ((ab->mode != USB_IDLE) && !gadget) {
1051 ab->mode = USB_IDLE;
1052 schedule_work(&ab->phy_dis_work);
1058 static int ab8500_usb_set_host(struct usb_otg *otg, struct usb_bus *host)
1060 struct ab8500_usb *ab;
1065 ab = phy_to_ab(otg->usb_phy);
1067 ab->phy.otg->host = host;
1069 /* Some drivers call this function in atomic context.
1070 * Do not update ab8500 registers directly till this
1074 if ((ab->mode != USB_IDLE) && !host) {
1075 ab->mode = USB_IDLE;
1076 schedule_work(&ab->phy_dis_work);
1082 static void ab8500_usb_restart_phy(struct ab8500_usb *ab)
1084 abx500_mask_and_set_register_interruptible(ab->dev,
1085 AB8500_USB, AB8500_USB_PHY_CTRL_REG,
1086 AB8500_BIT_PHY_CTRL_DEVICE_EN,
1087 AB8500_BIT_PHY_CTRL_DEVICE_EN);
1091 abx500_mask_and_set_register_interruptible(ab->dev,
1092 AB8500_USB, AB8500_USB_PHY_CTRL_REG,
1093 AB8500_BIT_PHY_CTRL_DEVICE_EN,
1096 abx500_mask_and_set_register_interruptible(ab->dev,
1097 AB8500_USB, AB8500_USB_PHY_CTRL_REG,
1098 AB8500_BIT_PHY_CTRL_HOST_EN,
1099 AB8500_BIT_PHY_CTRL_HOST_EN);
1103 abx500_mask_and_set_register_interruptible(ab->dev,
1104 AB8500_USB, AB8500_USB_PHY_CTRL_REG,
1105 AB8500_BIT_PHY_CTRL_HOST_EN,
1109 static int ab8500_usb_regulator_get(struct ab8500_usb *ab)
1113 ab->v_ape = devm_regulator_get(ab->dev, "v-ape");
1114 if (IS_ERR(ab->v_ape)) {
1115 dev_err(ab->dev, "Could not get v-ape supply\n");
1116 err = PTR_ERR(ab->v_ape);
1120 ab->v_ulpi = devm_regulator_get(ab->dev, "vddulpivio18");
1121 if (IS_ERR(ab->v_ulpi)) {
1122 dev_err(ab->dev, "Could not get vddulpivio18 supply\n");
1123 err = PTR_ERR(ab->v_ulpi);
1127 ab->v_musb = devm_regulator_get(ab->dev, "musb_1v8");
1128 if (IS_ERR(ab->v_musb)) {
1129 dev_err(ab->dev, "Could not get musb_1v8 supply\n");
1130 err = PTR_ERR(ab->v_musb);
1137 static int ab8500_usb_irq_setup(struct platform_device *pdev,
1138 struct ab8500_usb *ab)
1143 if (ab->flags & AB8500_USB_FLAG_USE_LINK_STATUS_IRQ) {
1144 irq = platform_get_irq_byname(pdev, "USB_LINK_STATUS");
1146 dev_err(&pdev->dev, "Link status irq not found\n");
1149 err = devm_request_threaded_irq(&pdev->dev, irq, NULL,
1150 ab8500_usb_link_status_irq,
1151 IRQF_NO_SUSPEND | IRQF_SHARED | IRQF_ONESHOT,
1152 "usb-link-status", ab);
1154 dev_err(ab->dev, "request_irq failed for link status irq\n");
1159 if (ab->flags & AB8500_USB_FLAG_USE_ID_WAKEUP_IRQ) {
1160 irq = platform_get_irq_byname(pdev, "ID_WAKEUP_F");
1162 dev_err(&pdev->dev, "ID fall irq not found\n");
1165 err = devm_request_threaded_irq(&pdev->dev, irq, NULL,
1166 ab8500_usb_disconnect_irq,
1167 IRQF_NO_SUSPEND | IRQF_SHARED | IRQF_ONESHOT,
1170 dev_err(ab->dev, "request_irq failed for ID fall irq\n");
1175 if (ab->flags & AB8500_USB_FLAG_USE_VBUS_DET_IRQ) {
1176 irq = platform_get_irq_byname(pdev, "VBUS_DET_F");
1178 dev_err(&pdev->dev, "VBUS fall irq not found\n");
1181 err = devm_request_threaded_irq(&pdev->dev, irq, NULL,
1182 ab8500_usb_disconnect_irq,
1183 IRQF_NO_SUSPEND | IRQF_SHARED | IRQF_ONESHOT,
1184 "usb-vbus-fall", ab);
1186 dev_err(ab->dev, "request_irq failed for Vbus fall irq\n");
1194 static void ab8500_usb_set_ab8500_tuning_values(struct ab8500_usb *ab)
1198 /* Enable the PBT/Bank 0x12 access */
1199 err = abx500_set_register_interruptible(ab->dev,
1200 AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS, 0x01);
1202 dev_err(ab->dev, "Failed to enable bank12 access err=%d\n",
1205 err = abx500_set_register_interruptible(ab->dev,
1206 AB8500_DEBUG, AB8500_USB_PHY_TUNE1, 0xC8);
1208 dev_err(ab->dev, "Failed to set PHY_TUNE1 register err=%d\n",
1211 err = abx500_set_register_interruptible(ab->dev,
1212 AB8500_DEBUG, AB8500_USB_PHY_TUNE2, 0x00);
1214 dev_err(ab->dev, "Failed to set PHY_TUNE2 register err=%d\n",
1217 err = abx500_set_register_interruptible(ab->dev,
1218 AB8500_DEBUG, AB8500_USB_PHY_TUNE3, 0x78);
1220 dev_err(ab->dev, "Failed to set PHY_TUNE3 register err=%d\n",
1223 /* Switch to normal mode/disable Bank 0x12 access */
1224 err = abx500_set_register_interruptible(ab->dev,
1225 AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS, 0x00);
1227 dev_err(ab->dev, "Failed to switch bank12 access err=%d\n",
1231 static void ab8500_usb_set_ab8505_tuning_values(struct ab8500_usb *ab)
1235 /* Enable the PBT/Bank 0x12 access */
1236 err = abx500_mask_and_set_register_interruptible(ab->dev,
1237 AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS,
1240 dev_err(ab->dev, "Failed to enable bank12 access err=%d\n",
1243 err = abx500_mask_and_set_register_interruptible(ab->dev,
1244 AB8500_DEBUG, AB8500_USB_PHY_TUNE1,
1247 dev_err(ab->dev, "Failed to set PHY_TUNE1 register err=%d\n",
1250 err = abx500_mask_and_set_register_interruptible(ab->dev,
1251 AB8500_DEBUG, AB8500_USB_PHY_TUNE2,
1254 dev_err(ab->dev, "Failed to set PHY_TUNE2 register err=%d\n",
1257 err = abx500_mask_and_set_register_interruptible(ab->dev,
1258 AB8500_DEBUG, AB8500_USB_PHY_TUNE3,
1262 dev_err(ab->dev, "Failed to set PHY_TUNE3 register err=%d\n",
1265 /* Switch to normal mode/disable Bank 0x12 access */
1266 err = abx500_mask_and_set_register_interruptible(ab->dev,
1267 AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS,
1270 dev_err(ab->dev, "Failed to switch bank12 access err=%d\n",
1274 static void ab8500_usb_set_ab8540_tuning_values(struct ab8500_usb *ab)
1278 err = abx500_set_register_interruptible(ab->dev,
1279 AB8540_DEBUG, AB8500_USB_PHY_TUNE1, 0xCC);
1281 dev_err(ab->dev, "Failed to set PHY_TUNE1 register ret=%d\n",
1284 err = abx500_set_register_interruptible(ab->dev,
1285 AB8540_DEBUG, AB8500_USB_PHY_TUNE2, 0x60);
1287 dev_err(ab->dev, "Failed to set PHY_TUNE2 register ret=%d\n",
1290 err = abx500_set_register_interruptible(ab->dev,
1291 AB8540_DEBUG, AB8500_USB_PHY_TUNE3, 0x90);
1293 dev_err(ab->dev, "Failed to set PHY_TUNE3 register ret=%d\n",
1297 static void ab8500_usb_set_ab9540_tuning_values(struct ab8500_usb *ab)
1301 /* Enable the PBT/Bank 0x12 access */
1302 err = abx500_set_register_interruptible(ab->dev,
1303 AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS, 0x01);
1305 dev_err(ab->dev, "Failed to enable bank12 access err=%d\n",
1308 err = abx500_set_register_interruptible(ab->dev,
1309 AB8500_DEBUG, AB8500_USB_PHY_TUNE1, 0xC8);
1311 dev_err(ab->dev, "Failed to set PHY_TUNE1 register err=%d\n",
1314 err = abx500_set_register_interruptible(ab->dev,
1315 AB8500_DEBUG, AB8500_USB_PHY_TUNE2, 0x60);
1317 dev_err(ab->dev, "Failed to set PHY_TUNE2 register err=%d\n",
1320 err = abx500_set_register_interruptible(ab->dev,
1321 AB8500_DEBUG, AB8500_USB_PHY_TUNE3, 0x80);
1323 dev_err(ab->dev, "Failed to set PHY_TUNE3 register err=%d\n",
1326 /* Switch to normal mode/disable Bank 0x12 access */
1327 err = abx500_set_register_interruptible(ab->dev,
1328 AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS, 0x00);
1330 dev_err(ab->dev, "Failed to switch bank12 access err=%d\n",
1334 static int ab8500_usb_probe(struct platform_device *pdev)
1336 struct ab8500_usb *ab;
1337 struct ab8500 *ab8500;
1338 struct usb_otg *otg;
1342 ab8500 = dev_get_drvdata(pdev->dev.parent);
1343 rev = abx500_get_chip_id(&pdev->dev);
1345 if (is_ab8500_1p1_or_earlier(ab8500)) {
1346 dev_err(&pdev->dev, "Unsupported AB8500 chip rev=%d\n", rev);
1350 ab = devm_kzalloc(&pdev->dev, sizeof(*ab), GFP_KERNEL);
1354 otg = devm_kzalloc(&pdev->dev, sizeof(*otg), GFP_KERNEL);
1358 ab->dev = &pdev->dev;
1359 ab->ab8500 = ab8500;
1360 ab->phy.dev = ab->dev;
1362 ab->phy.label = "ab8500";
1363 ab->phy.set_suspend = ab8500_usb_set_suspend;
1364 ab->phy.otg->state = OTG_STATE_UNDEFINED;
1366 otg->usb_phy = &ab->phy;
1367 otg->set_host = ab8500_usb_set_host;
1368 otg->set_peripheral = ab8500_usb_set_peripheral;
1370 if (is_ab8500(ab->ab8500)) {
1371 ab->flags |= AB8500_USB_FLAG_USE_LINK_STATUS_IRQ |
1372 AB8500_USB_FLAG_USE_ID_WAKEUP_IRQ |
1373 AB8500_USB_FLAG_USE_VBUS_DET_IRQ |
1374 AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE;
1375 } else if (is_ab8505(ab->ab8500)) {
1376 ab->flags |= AB8500_USB_FLAG_USE_LINK_STATUS_IRQ |
1377 AB8500_USB_FLAG_USE_ID_WAKEUP_IRQ |
1378 AB8500_USB_FLAG_USE_VBUS_DET_IRQ |
1379 AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE;
1380 } else if (is_ab8540(ab->ab8500)) {
1381 ab->flags |= AB8500_USB_FLAG_USE_LINK_STATUS_IRQ |
1382 AB8500_USB_FLAG_USE_CHECK_VBUS_STATUS |
1383 AB8500_USB_FLAG_USE_VBUS_HOST_QUIRK |
1384 AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE;
1385 } else if (is_ab9540(ab->ab8500)) {
1386 ab->flags |= AB8500_USB_FLAG_USE_LINK_STATUS_IRQ |
1387 AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE;
1388 if (is_ab9540_2p0_or_earlier(ab->ab8500))
1389 ab->flags |= AB8500_USB_FLAG_USE_ID_WAKEUP_IRQ |
1390 AB8500_USB_FLAG_USE_VBUS_DET_IRQ;
1393 /* Disable regulator voltage setting for AB8500 <= v2.0 */
1394 if (is_ab8500_2p0_or_earlier(ab->ab8500))
1395 ab->flags &= ~AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE;
1397 platform_set_drvdata(pdev, ab);
1399 /* all: Disable phy when called from set_host and set_peripheral */
1400 INIT_WORK(&ab->phy_dis_work, ab8500_usb_phy_disable_work);
1402 INIT_WORK(&ab->vbus_event_work, ab8500_usb_vbus_turn_on_event_work);
1404 err = ab8500_usb_regulator_get(ab);
1408 ab->sysclk = devm_clk_get(ab->dev, "sysclk");
1409 if (IS_ERR(ab->sysclk)) {
1410 dev_err(ab->dev, "Could not get sysclk.\n");
1411 return PTR_ERR(ab->sysclk);
1414 err = ab8500_usb_irq_setup(pdev, ab);
1418 err = usb_add_phy(&ab->phy, USB_PHY_TYPE_USB2);
1420 dev_err(&pdev->dev, "Can't register transceiver\n");
1424 if (is_ab8500(ab->ab8500) && !is_ab8500_2p0_or_earlier(ab->ab8500))
1425 /* Phy tuning values for AB8500 > v2.0 */
1426 ab8500_usb_set_ab8500_tuning_values(ab);
1427 else if (is_ab8505(ab->ab8500))
1428 /* Phy tuning values for AB8505 */
1429 ab8500_usb_set_ab8505_tuning_values(ab);
1430 else if (is_ab8540(ab->ab8500))
1431 /* Phy tuning values for AB8540 */
1432 ab8500_usb_set_ab8540_tuning_values(ab);
1433 else if (is_ab9540(ab->ab8500))
1434 /* Phy tuning values for AB9540 */
1435 ab8500_usb_set_ab9540_tuning_values(ab);
1437 /* Needed to enable ID detection. */
1438 ab8500_usb_wd_workaround(ab);
1441 * This is required for usb-link-status to work properly when a
1442 * cable is connected at boot time.
1444 ab8500_usb_restart_phy(ab);
1446 if (ab->flags & AB8500_USB_FLAG_USE_CHECK_VBUS_STATUS) {
1447 if (ab8500_usb_check_vbus_status(ab))
1448 schedule_work(&ab->vbus_event_work);
1451 abx500_usb_link_status_update(ab);
1453 dev_info(&pdev->dev, "revision 0x%2x driver initialized\n", rev);
1458 static int ab8500_usb_remove(struct platform_device *pdev)
1460 struct ab8500_usb *ab = platform_get_drvdata(pdev);
1462 cancel_work_sync(&ab->phy_dis_work);
1463 cancel_work_sync(&ab->vbus_event_work);
1465 usb_remove_phy(&ab->phy);
1467 if (ab->mode == USB_HOST)
1468 ab8500_usb_host_phy_dis(ab);
1469 else if (ab->mode == USB_PERIPHERAL)
1470 ab8500_usb_peri_phy_dis(ab);
1475 static const struct platform_device_id ab8500_usb_devtype[] = {
1476 { .name = "ab8500-usb", },
1477 { .name = "ab8540-usb", },
1478 { .name = "ab9540-usb", },
1481 MODULE_DEVICE_TABLE(platform, ab8500_usb_devtype);
1483 static struct platform_driver ab8500_usb_driver = {
1484 .probe = ab8500_usb_probe,
1485 .remove = ab8500_usb_remove,
1486 .id_table = ab8500_usb_devtype,
1488 .name = "abx5x0-usb",
1492 static int __init ab8500_usb_init(void)
1494 return platform_driver_register(&ab8500_usb_driver);
1496 subsys_initcall(ab8500_usb_init);
1498 static void __exit ab8500_usb_exit(void)
1500 platform_driver_unregister(&ab8500_usb_driver);
1502 module_exit(ab8500_usb_exit);
1504 MODULE_AUTHOR("ST-Ericsson AB");
1505 MODULE_DESCRIPTION("AB8500 family usb transceiver driver");
1506 MODULE_LICENSE("GPL");