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>
11 #include <linux/module.h>
12 #include <linux/platform_device.h>
13 #include <linux/usb/otg.h>
14 #include <linux/slab.h>
15 #include <linux/notifier.h>
16 #include <linux/interrupt.h>
17 #include <linux/delay.h>
18 #include <linux/clk.h>
19 #include <linux/err.h>
20 #include <linux/mfd/abx500.h>
21 #include <linux/mfd/abx500/ab8500.h>
22 #include <linux/usb/musb-ux500.h>
23 #include <linux/regulator/consumer.h>
24 #include <linux/pinctrl/consumer.h>
26 /* Bank AB8500_SYS_CTRL2_BLOCK */
27 #define AB8500_MAIN_WD_CTRL_REG 0x01
30 #define AB8500_USB_LINE_STAT_REG 0x80
31 #define AB8505_USB_LINE_STAT_REG 0x94
32 #define AB8540_USB_LINK_STAT_REG 0x94
33 #define AB9540_USB_LINK_STAT_REG 0x94
34 #define AB8540_USB_OTG_CTL_REG 0x87
35 #define AB8500_USB_PHY_CTRL_REG 0x8A
36 #define AB8540_VBUS_CTRL_REG 0x82
38 /* Bank AB8500_DEVELOPMENT */
39 #define AB8500_BANK12_ACCESS 0x00
41 /* Bank AB8500_DEBUG */
42 #define AB8540_DEBUG 0x32
43 #define AB8500_USB_PHY_TUNE1 0x05
44 #define AB8500_USB_PHY_TUNE2 0x06
45 #define AB8500_USB_PHY_TUNE3 0x07
47 /* Bank AB8500_INTERRUPT */
48 #define AB8500_IT_SOURCE2_REG 0x01
50 #define AB8500_BIT_OTG_STAT_ID (1 << 0)
51 #define AB8500_BIT_PHY_CTRL_HOST_EN (1 << 0)
52 #define AB8500_BIT_PHY_CTRL_DEVICE_EN (1 << 1)
53 #define AB8500_BIT_WD_CTRL_ENABLE (1 << 0)
54 #define AB8500_BIT_WD_CTRL_KICK (1 << 1)
55 #define AB8500_BIT_SOURCE2_VBUSDET (1 << 7)
56 #define AB8540_BIT_OTG_CTL_VBUS_VALID_ENA (1 << 0)
57 #define AB8540_BIT_OTG_CTL_ID_HOST_ENA (1 << 1)
58 #define AB8540_BIT_OTG_CTL_ID_DEV_ENA (1 << 5)
59 #define AB8540_BIT_VBUS_CTRL_CHARG_DET_ENA (1 << 0)
61 #define AB8500_WD_KICK_DELAY_US 100 /* usec */
62 #define AB8500_WD_V11_DISABLE_DELAY_US 100 /* usec */
63 #define AB8500_V20_31952_DISABLE_DELAY_US 100 /* usec */
65 /* Usb line status register */
66 enum ab8500_usb_link_status
{
67 USB_LINK_NOT_CONFIGURED_8500
= 0,
68 USB_LINK_STD_HOST_NC_8500
,
69 USB_LINK_STD_HOST_C_NS_8500
,
70 USB_LINK_STD_HOST_C_S_8500
,
71 USB_LINK_HOST_CHG_NM_8500
,
72 USB_LINK_HOST_CHG_HS_8500
,
73 USB_LINK_HOST_CHG_HS_CHIRP_8500
,
74 USB_LINK_DEDICATED_CHG_8500
,
75 USB_LINK_ACA_RID_A_8500
,
76 USB_LINK_ACA_RID_B_8500
,
77 USB_LINK_ACA_RID_C_NM_8500
,
78 USB_LINK_ACA_RID_C_HS_8500
,
79 USB_LINK_ACA_RID_C_HS_CHIRP_8500
,
80 USB_LINK_HM_IDGND_8500
,
81 USB_LINK_RESERVED_8500
,
82 USB_LINK_NOT_VALID_LINK_8500
,
85 enum ab8505_usb_link_status
{
86 USB_LINK_NOT_CONFIGURED_8505
= 0,
87 USB_LINK_STD_HOST_NC_8505
,
88 USB_LINK_STD_HOST_C_NS_8505
,
89 USB_LINK_STD_HOST_C_S_8505
,
91 USB_LINK_RESERVED0_8505
,
92 USB_LINK_RESERVED1_8505
,
93 USB_LINK_DEDICATED_CHG_8505
,
94 USB_LINK_ACA_RID_A_8505
,
95 USB_LINK_ACA_RID_B_8505
,
96 USB_LINK_ACA_RID_C_NM_8505
,
97 USB_LINK_RESERVED2_8505
,
98 USB_LINK_RESERVED3_8505
,
99 USB_LINK_HM_IDGND_8505
,
100 USB_LINK_CHARGERPORT_NOT_OK_8505
,
101 USB_LINK_CHARGER_DM_HIGH_8505
,
102 USB_LINK_PHYEN_NO_VBUS_NO_IDGND_8505
,
103 USB_LINK_STD_UPSTREAM_NO_IDGNG_NO_VBUS_8505
,
104 USB_LINK_STD_UPSTREAM_8505
,
105 USB_LINK_CHARGER_SE1_8505
,
106 USB_LINK_CARKIT_CHGR_1_8505
,
107 USB_LINK_CARKIT_CHGR_2_8505
,
108 USB_LINK_ACA_DOCK_CHGR_8505
,
109 USB_LINK_SAMSUNG_BOOT_CBL_PHY_EN_8505
,
110 USB_LINK_SAMSUNG_BOOT_CBL_PHY_DISB_8505
,
111 USB_LINK_SAMSUNG_UART_CBL_PHY_EN_8505
,
112 USB_LINK_SAMSUNG_UART_CBL_PHY_DISB_8505
,
113 USB_LINK_MOTOROLA_FACTORY_CBL_PHY_EN_8505
,
116 enum ab8540_usb_link_status
{
117 USB_LINK_NOT_CONFIGURED_8540
= 0,
118 USB_LINK_STD_HOST_NC_8540
,
119 USB_LINK_STD_HOST_C_NS_8540
,
120 USB_LINK_STD_HOST_C_S_8540
,
122 USB_LINK_RESERVED0_8540
,
123 USB_LINK_RESERVED1_8540
,
124 USB_LINK_DEDICATED_CHG_8540
,
125 USB_LINK_ACA_RID_A_8540
,
126 USB_LINK_ACA_RID_B_8540
,
127 USB_LINK_ACA_RID_C_NM_8540
,
128 USB_LINK_RESERVED2_8540
,
129 USB_LINK_RESERVED3_8540
,
130 USB_LINK_HM_IDGND_8540
,
131 USB_LINK_CHARGERPORT_NOT_OK_8540
,
132 USB_LINK_CHARGER_DM_HIGH_8540
,
133 USB_LINK_PHYEN_NO_VBUS_NO_IDGND_8540
,
134 USB_LINK_STD_UPSTREAM_NO_IDGNG_VBUS_8540
,
135 USB_LINK_STD_UPSTREAM_8540
,
136 USB_LINK_CHARGER_SE1_8540
,
137 USB_LINK_CARKIT_CHGR_1_8540
,
138 USB_LINK_CARKIT_CHGR_2_8540
,
139 USB_LINK_ACA_DOCK_CHGR_8540
,
140 USB_LINK_SAMSUNG_BOOT_CBL_PHY_EN_8540
,
141 USB_LINK_SAMSUNG_BOOT_CBL_PHY_DISB_8540
,
142 USB_LINK_SAMSUNG_UART_CBL_PHY_EN_8540
,
143 USB_LINK_SAMSUNG_UART_CBL_PHY_DISB_8540
,
144 USB_LINK_MOTOROLA_FACTORY_CBL_PHY_EN_8540
147 enum ab9540_usb_link_status
{
148 USB_LINK_NOT_CONFIGURED_9540
= 0,
149 USB_LINK_STD_HOST_NC_9540
,
150 USB_LINK_STD_HOST_C_NS_9540
,
151 USB_LINK_STD_HOST_C_S_9540
,
153 USB_LINK_RESERVED0_9540
,
154 USB_LINK_RESERVED1_9540
,
155 USB_LINK_DEDICATED_CHG_9540
,
156 USB_LINK_ACA_RID_A_9540
,
157 USB_LINK_ACA_RID_B_9540
,
158 USB_LINK_ACA_RID_C_NM_9540
,
159 USB_LINK_RESERVED2_9540
,
160 USB_LINK_RESERVED3_9540
,
161 USB_LINK_HM_IDGND_9540
,
162 USB_LINK_CHARGERPORT_NOT_OK_9540
,
163 USB_LINK_CHARGER_DM_HIGH_9540
,
164 USB_LINK_PHYEN_NO_VBUS_NO_IDGND_9540
,
165 USB_LINK_STD_UPSTREAM_NO_IDGNG_VBUS_9540
,
166 USB_LINK_STD_UPSTREAM_9540
,
167 USB_LINK_CHARGER_SE1_9540
,
168 USB_LINK_CARKIT_CHGR_1_9540
,
169 USB_LINK_CARKIT_CHGR_2_9540
,
170 USB_LINK_ACA_DOCK_CHGR_9540
,
171 USB_LINK_SAMSUNG_BOOT_CBL_PHY_EN_9540
,
172 USB_LINK_SAMSUNG_BOOT_CBL_PHY_DISB_9540
,
173 USB_LINK_SAMSUNG_UART_CBL_PHY_EN_9540
,
174 USB_LINK_SAMSUNG_UART_CBL_PHY_DISB_9540
,
175 USB_LINK_MOTOROLA_FACTORY_CBL_PHY_EN_9540
178 enum ab8500_usb_mode
{
185 /* Register USB_LINK_STATUS interrupt */
186 #define AB8500_USB_FLAG_USE_LINK_STATUS_IRQ (1 << 0)
187 /* Register ID_WAKEUP_F interrupt */
188 #define AB8500_USB_FLAG_USE_ID_WAKEUP_IRQ (1 << 1)
189 /* Register VBUS_DET_F interrupt */
190 #define AB8500_USB_FLAG_USE_VBUS_DET_IRQ (1 << 2)
191 /* Driver is using the ab-iddet driver*/
192 #define AB8500_USB_FLAG_USE_AB_IDDET (1 << 3)
193 /* Enable setting regulators voltage */
194 #define AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE (1 << 4)
195 /* Enable the check_vbus_status workaround */
196 #define AB8500_USB_FLAG_USE_CHECK_VBUS_STATUS (1 << 5)
197 /* Enable the vbus host workaround */
198 #define AB8500_USB_FLAG_USE_VBUS_HOST_QUIRK (1 << 6)
203 struct ab8500
*ab8500
;
205 struct work_struct phy_dis_work
;
206 struct work_struct vbus_event_work
;
207 enum ab8500_usb_mode mode
;
209 struct regulator
*v_ape
;
210 struct regulator
*v_musb
;
211 struct regulator
*v_ulpi
;
213 int previous_link_status_state
;
214 struct pinctrl
*pinctrl
;
215 struct pinctrl_state
*pins_sleep
;
216 bool enabled_charging_detection
;
220 static inline struct ab8500_usb
*phy_to_ab(struct usb_phy
*x
)
222 return container_of(x
, struct ab8500_usb
, phy
);
225 static void ab8500_usb_wd_workaround(struct ab8500_usb
*ab
)
227 abx500_set_register_interruptible(ab
->dev
,
228 AB8500_SYS_CTRL2_BLOCK
,
229 AB8500_MAIN_WD_CTRL_REG
,
230 AB8500_BIT_WD_CTRL_ENABLE
);
232 udelay(AB8500_WD_KICK_DELAY_US
);
234 abx500_set_register_interruptible(ab
->dev
,
235 AB8500_SYS_CTRL2_BLOCK
,
236 AB8500_MAIN_WD_CTRL_REG
,
237 (AB8500_BIT_WD_CTRL_ENABLE
238 | AB8500_BIT_WD_CTRL_KICK
));
240 udelay(AB8500_WD_V11_DISABLE_DELAY_US
);
242 abx500_set_register_interruptible(ab
->dev
,
243 AB8500_SYS_CTRL2_BLOCK
,
244 AB8500_MAIN_WD_CTRL_REG
,
248 static void ab8500_usb_regulator_enable(struct ab8500_usb
*ab
)
252 ret
= regulator_enable(ab
->v_ape
);
254 dev_err(ab
->dev
, "Failed to enable v-ape\n");
256 if (ab
->flags
& AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE
) {
257 ab
->saved_v_ulpi
= regulator_get_voltage(ab
->v_ulpi
);
258 if (ab
->saved_v_ulpi
< 0)
259 dev_err(ab
->dev
, "Failed to get v_ulpi voltage\n");
261 ret
= regulator_set_voltage(ab
->v_ulpi
, 1300000, 1350000);
263 dev_err(ab
->dev
, "Failed to set the Vintcore to 1.3V, ret=%d\n",
266 ret
= regulator_set_load(ab
->v_ulpi
, 28000);
268 dev_err(ab
->dev
, "Failed to set optimum mode (ret=%d)\n",
272 ret
= regulator_enable(ab
->v_ulpi
);
274 dev_err(ab
->dev
, "Failed to enable vddulpivio18\n");
276 if (ab
->flags
& AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE
) {
277 volt
= regulator_get_voltage(ab
->v_ulpi
);
278 if ((volt
!= 1300000) && (volt
!= 1350000))
279 dev_err(ab
->dev
, "Vintcore is not set to 1.3V volt=%d\n",
283 ret
= regulator_enable(ab
->v_musb
);
285 dev_err(ab
->dev
, "Failed to enable musb_1v8\n");
288 static void ab8500_usb_regulator_disable(struct ab8500_usb
*ab
)
292 regulator_disable(ab
->v_musb
);
294 regulator_disable(ab
->v_ulpi
);
296 /* USB is not the only consumer of Vintcore, restore old settings */
297 if (ab
->flags
& AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE
) {
298 if (ab
->saved_v_ulpi
> 0) {
299 ret
= regulator_set_voltage(ab
->v_ulpi
,
300 ab
->saved_v_ulpi
, ab
->saved_v_ulpi
);
302 dev_err(ab
->dev
, "Failed to set the Vintcore to %duV, ret=%d\n",
303 ab
->saved_v_ulpi
, ret
);
306 ret
= regulator_set_load(ab
->v_ulpi
, 0);
308 dev_err(ab
->dev
, "Failed to set optimum mode (ret=%d)\n",
312 regulator_disable(ab
->v_ape
);
315 static void ab8500_usb_wd_linkstatus(struct ab8500_usb
*ab
, u8 bit
)
317 /* Workaround for v2.0 bug # 31952 */
318 if (is_ab8500_2p0(ab
->ab8500
)) {
319 abx500_mask_and_set_register_interruptible(ab
->dev
,
320 AB8500_USB
, AB8500_USB_PHY_CTRL_REG
,
322 udelay(AB8500_V20_31952_DISABLE_DELAY_US
);
326 static void ab8500_usb_phy_enable(struct ab8500_usb
*ab
, bool sel_host
)
329 bit
= sel_host
? AB8500_BIT_PHY_CTRL_HOST_EN
:
330 AB8500_BIT_PHY_CTRL_DEVICE_EN
;
332 /* mux and configure USB pins to DEFAULT state */
333 ab
->pinctrl
= pinctrl_get_select(ab
->dev
, PINCTRL_STATE_DEFAULT
);
334 if (IS_ERR(ab
->pinctrl
))
335 dev_err(ab
->dev
, "could not get/set default pinstate\n");
337 if (clk_prepare_enable(ab
->sysclk
))
338 dev_err(ab
->dev
, "can't prepare/enable clock\n");
340 ab8500_usb_regulator_enable(ab
);
342 abx500_mask_and_set_register_interruptible(ab
->dev
,
343 AB8500_USB
, AB8500_USB_PHY_CTRL_REG
,
346 if (ab
->flags
& AB8500_USB_FLAG_USE_VBUS_HOST_QUIRK
) {
348 abx500_set_register_interruptible(ab
->dev
,
349 AB8500_USB
, AB8540_USB_OTG_CTL_REG
,
350 AB8540_BIT_OTG_CTL_VBUS_VALID_ENA
|
351 AB8540_BIT_OTG_CTL_ID_HOST_ENA
|
352 AB8540_BIT_OTG_CTL_ID_DEV_ENA
);
356 static void ab8500_usb_phy_disable(struct ab8500_usb
*ab
, bool sel_host
)
359 bit
= sel_host
? AB8500_BIT_PHY_CTRL_HOST_EN
:
360 AB8500_BIT_PHY_CTRL_DEVICE_EN
;
362 ab8500_usb_wd_linkstatus(ab
, bit
);
364 abx500_mask_and_set_register_interruptible(ab
->dev
,
365 AB8500_USB
, AB8500_USB_PHY_CTRL_REG
,
368 /* Needed to disable the phy.*/
369 ab8500_usb_wd_workaround(ab
);
371 clk_disable_unprepare(ab
->sysclk
);
373 ab8500_usb_regulator_disable(ab
);
375 if (!IS_ERR(ab
->pinctrl
)) {
376 /* configure USB pins to SLEEP state */
377 ab
->pins_sleep
= pinctrl_lookup_state(ab
->pinctrl
,
378 PINCTRL_STATE_SLEEP
);
380 if (IS_ERR(ab
->pins_sleep
))
381 dev_dbg(ab
->dev
, "could not get sleep pinstate\n");
382 else if (pinctrl_select_state(ab
->pinctrl
, ab
->pins_sleep
))
383 dev_err(ab
->dev
, "could not set pins to sleep state\n");
386 * as USB pins are shared with iddet, release them to allow
387 * iddet to request them
389 pinctrl_put(ab
->pinctrl
);
393 #define ab8500_usb_host_phy_en(ab) ab8500_usb_phy_enable(ab, true)
394 #define ab8500_usb_host_phy_dis(ab) ab8500_usb_phy_disable(ab, true)
395 #define ab8500_usb_peri_phy_en(ab) ab8500_usb_phy_enable(ab, false)
396 #define ab8500_usb_peri_phy_dis(ab) ab8500_usb_phy_disable(ab, false)
398 static int ab9540_usb_link_status_update(struct ab8500_usb
*ab
,
399 enum ab9540_usb_link_status lsts
)
401 enum ux500_musb_vbus_id_status event
= 0;
403 dev_dbg(ab
->dev
, "ab9540_usb_link_status_update %d\n", lsts
);
405 if (ab
->previous_link_status_state
== USB_LINK_HM_IDGND_9540
&&
406 (lsts
== USB_LINK_STD_HOST_C_NS_9540
||
407 lsts
== USB_LINK_STD_HOST_NC_9540
))
410 if (ab
->previous_link_status_state
== USB_LINK_ACA_RID_A_9540
&&
411 (lsts
== USB_LINK_STD_HOST_NC_9540
))
414 ab
->previous_link_status_state
= lsts
;
417 case USB_LINK_ACA_RID_B_9540
:
418 event
= UX500_MUSB_RIDB
;
419 case USB_LINK_NOT_CONFIGURED_9540
:
420 case USB_LINK_RESERVED0_9540
:
421 case USB_LINK_RESERVED1_9540
:
422 case USB_LINK_RESERVED2_9540
:
423 case USB_LINK_RESERVED3_9540
:
424 if (ab
->mode
== USB_PERIPHERAL
)
425 atomic_notifier_call_chain(&ab
->phy
.notifier
,
426 UX500_MUSB_CLEAN
, &ab
->vbus_draw
);
428 ab
->phy
.otg
->default_a
= false;
430 if (event
!= UX500_MUSB_RIDB
)
431 event
= UX500_MUSB_NONE
;
432 /* Fallback to default B_IDLE as nothing is connected. */
433 ab
->phy
.otg
->state
= OTG_STATE_B_IDLE
;
434 usb_phy_set_event(&ab
->phy
, USB_EVENT_NONE
);
437 case USB_LINK_ACA_RID_C_NM_9540
:
438 event
= UX500_MUSB_RIDC
;
439 case USB_LINK_STD_HOST_NC_9540
:
440 case USB_LINK_STD_HOST_C_NS_9540
:
441 case USB_LINK_STD_HOST_C_S_9540
:
442 case USB_LINK_CDP_9540
:
443 if (ab
->mode
== USB_HOST
) {
444 ab
->mode
= USB_PERIPHERAL
;
445 ab8500_usb_host_phy_dis(ab
);
446 ab8500_usb_peri_phy_en(ab
);
447 atomic_notifier_call_chain(&ab
->phy
.notifier
,
448 UX500_MUSB_PREPARE
, &ab
->vbus_draw
);
449 usb_phy_set_event(&ab
->phy
, USB_EVENT_ENUMERATED
);
451 if (ab
->mode
== USB_IDLE
) {
452 ab
->mode
= USB_PERIPHERAL
;
453 ab8500_usb_peri_phy_en(ab
);
454 atomic_notifier_call_chain(&ab
->phy
.notifier
,
455 UX500_MUSB_PREPARE
, &ab
->vbus_draw
);
456 usb_phy_set_event(&ab
->phy
, USB_EVENT_ENUMERATED
);
458 if (event
!= UX500_MUSB_RIDC
)
459 event
= UX500_MUSB_VBUS
;
462 case USB_LINK_ACA_RID_A_9540
:
463 event
= UX500_MUSB_RIDA
;
464 case USB_LINK_HM_IDGND_9540
:
465 case USB_LINK_STD_UPSTREAM_9540
:
466 if (ab
->mode
== USB_PERIPHERAL
) {
468 ab8500_usb_peri_phy_dis(ab
);
469 ab8500_usb_host_phy_en(ab
);
470 atomic_notifier_call_chain(&ab
->phy
.notifier
,
471 UX500_MUSB_PREPARE
, &ab
->vbus_draw
);
473 if (ab
->mode
== USB_IDLE
) {
475 ab8500_usb_host_phy_en(ab
);
476 atomic_notifier_call_chain(&ab
->phy
.notifier
,
477 UX500_MUSB_PREPARE
, &ab
->vbus_draw
);
479 ab
->phy
.otg
->default_a
= true;
480 if (event
!= UX500_MUSB_RIDA
)
481 event
= UX500_MUSB_ID
;
483 atomic_notifier_call_chain(&ab
->phy
.notifier
,
484 event
, &ab
->vbus_draw
);
487 case USB_LINK_DEDICATED_CHG_9540
:
488 ab
->mode
= USB_DEDICATED_CHG
;
489 event
= UX500_MUSB_CHARGER
;
490 atomic_notifier_call_chain(&ab
->phy
.notifier
,
491 event
, &ab
->vbus_draw
);
492 usb_phy_set_event(&ab
->phy
, USB_EVENT_CHARGER
);
495 case USB_LINK_PHYEN_NO_VBUS_NO_IDGND_9540
:
496 case USB_LINK_STD_UPSTREAM_NO_IDGNG_VBUS_9540
:
497 if (!(is_ab9540_2p0_or_earlier(ab
->ab8500
))) {
498 event
= UX500_MUSB_NONE
;
499 if (ab
->mode
== USB_HOST
) {
500 ab
->phy
.otg
->default_a
= false;
502 atomic_notifier_call_chain(&ab
->phy
.notifier
,
503 event
, &ab
->vbus_draw
);
504 ab8500_usb_host_phy_dis(ab
);
507 if (ab
->mode
== USB_PERIPHERAL
) {
508 atomic_notifier_call_chain(&ab
->phy
.notifier
,
509 event
, &ab
->vbus_draw
);
510 ab8500_usb_peri_phy_dis(ab
);
511 atomic_notifier_call_chain(&ab
->phy
.notifier
,
515 ab
->phy
.otg
->default_a
= false;
517 usb_phy_set_event(&ab
->phy
, USB_EVENT_NONE
);
529 static int ab8540_usb_link_status_update(struct ab8500_usb
*ab
,
530 enum ab8540_usb_link_status lsts
)
532 enum ux500_musb_vbus_id_status event
= 0;
534 dev_dbg(ab
->dev
, "ab8540_usb_link_status_update %d\n", lsts
);
536 if (ab
->enabled_charging_detection
) {
537 /* Disable USB Charger detection */
538 abx500_mask_and_set_register_interruptible(ab
->dev
,
539 AB8500_USB
, AB8540_VBUS_CTRL_REG
,
540 AB8540_BIT_VBUS_CTRL_CHARG_DET_ENA
, 0x00);
541 ab
->enabled_charging_detection
= false;
545 * Spurious link_status interrupts are seen in case of a
546 * disconnection of a device in IDGND and RIDA stage
548 if (ab
->previous_link_status_state
== USB_LINK_HM_IDGND_8540
&&
549 (lsts
== USB_LINK_STD_HOST_C_NS_8540
||
550 lsts
== USB_LINK_STD_HOST_NC_8540
))
553 if (ab
->previous_link_status_state
== USB_LINK_ACA_RID_A_8540
&&
554 (lsts
== USB_LINK_STD_HOST_NC_8540
))
557 ab
->previous_link_status_state
= lsts
;
560 case USB_LINK_ACA_RID_B_8540
:
561 event
= UX500_MUSB_RIDB
;
562 case USB_LINK_NOT_CONFIGURED_8540
:
563 case USB_LINK_RESERVED0_8540
:
564 case USB_LINK_RESERVED1_8540
:
565 case USB_LINK_RESERVED2_8540
:
566 case USB_LINK_RESERVED3_8540
:
568 ab
->phy
.otg
->default_a
= false;
570 if (event
!= UX500_MUSB_RIDB
)
571 event
= UX500_MUSB_NONE
;
573 * Fallback to default B_IDLE as nothing
576 ab
->phy
.otg
->state
= OTG_STATE_B_IDLE
;
577 usb_phy_set_event(&ab
->phy
, USB_EVENT_NONE
);
580 case USB_LINK_ACA_RID_C_NM_8540
:
581 event
= UX500_MUSB_RIDC
;
582 case USB_LINK_STD_HOST_NC_8540
:
583 case USB_LINK_STD_HOST_C_NS_8540
:
584 case USB_LINK_STD_HOST_C_S_8540
:
585 case USB_LINK_CDP_8540
:
586 if (ab
->mode
== USB_IDLE
) {
587 ab
->mode
= USB_PERIPHERAL
;
588 ab8500_usb_peri_phy_en(ab
);
589 atomic_notifier_call_chain(&ab
->phy
.notifier
,
590 UX500_MUSB_PREPARE
, &ab
->vbus_draw
);
591 usb_phy_set_event(&ab
->phy
, USB_EVENT_ENUMERATED
);
593 if (event
!= UX500_MUSB_RIDC
)
594 event
= UX500_MUSB_VBUS
;
597 case USB_LINK_ACA_RID_A_8540
:
598 case USB_LINK_ACA_DOCK_CHGR_8540
:
599 event
= UX500_MUSB_RIDA
;
600 case USB_LINK_HM_IDGND_8540
:
601 case USB_LINK_STD_UPSTREAM_8540
:
602 if (ab
->mode
== USB_IDLE
) {
604 ab8500_usb_host_phy_en(ab
);
605 atomic_notifier_call_chain(&ab
->phy
.notifier
,
606 UX500_MUSB_PREPARE
, &ab
->vbus_draw
);
608 ab
->phy
.otg
->default_a
= true;
609 if (event
!= UX500_MUSB_RIDA
)
610 event
= UX500_MUSB_ID
;
611 atomic_notifier_call_chain(&ab
->phy
.notifier
,
612 event
, &ab
->vbus_draw
);
615 case USB_LINK_DEDICATED_CHG_8540
:
616 ab
->mode
= USB_DEDICATED_CHG
;
617 event
= UX500_MUSB_CHARGER
;
618 atomic_notifier_call_chain(&ab
->phy
.notifier
,
619 event
, &ab
->vbus_draw
);
620 usb_phy_set_event(&ab
->phy
, USB_EVENT_CHARGER
);
623 case USB_LINK_PHYEN_NO_VBUS_NO_IDGND_8540
:
624 case USB_LINK_STD_UPSTREAM_NO_IDGNG_VBUS_8540
:
625 event
= UX500_MUSB_NONE
;
626 if (ab
->mode
== USB_HOST
) {
627 ab
->phy
.otg
->default_a
= false;
629 atomic_notifier_call_chain(&ab
->phy
.notifier
,
630 event
, &ab
->vbus_draw
);
631 ab8500_usb_host_phy_dis(ab
);
634 if (ab
->mode
== USB_PERIPHERAL
) {
635 atomic_notifier_call_chain(&ab
->phy
.notifier
,
636 event
, &ab
->vbus_draw
);
637 ab8500_usb_peri_phy_dis(ab
);
638 atomic_notifier_call_chain(&ab
->phy
.notifier
,
639 UX500_MUSB_CLEAN
, &ab
->vbus_draw
);
641 ab
->phy
.otg
->default_a
= false;
643 usb_phy_set_event(&ab
->phy
, USB_EVENT_NONE
);
648 event
= UX500_MUSB_NONE
;
655 static int ab8505_usb_link_status_update(struct ab8500_usb
*ab
,
656 enum ab8505_usb_link_status lsts
)
658 enum ux500_musb_vbus_id_status event
= 0;
660 dev_dbg(ab
->dev
, "ab8505_usb_link_status_update %d\n", lsts
);
663 * Spurious link_status interrupts are seen at the time of
664 * disconnection of a device in RIDA state
666 if (ab
->previous_link_status_state
== USB_LINK_ACA_RID_A_8505
&&
667 (lsts
== USB_LINK_STD_HOST_NC_8505
))
670 ab
->previous_link_status_state
= lsts
;
673 case USB_LINK_ACA_RID_B_8505
:
674 event
= UX500_MUSB_RIDB
;
675 case USB_LINK_NOT_CONFIGURED_8505
:
676 case USB_LINK_RESERVED0_8505
:
677 case USB_LINK_RESERVED1_8505
:
678 case USB_LINK_RESERVED2_8505
:
679 case USB_LINK_RESERVED3_8505
:
681 ab
->phy
.otg
->default_a
= false;
683 if (event
!= UX500_MUSB_RIDB
)
684 event
= UX500_MUSB_NONE
;
686 * Fallback to default B_IDLE as nothing
689 ab
->phy
.otg
->state
= OTG_STATE_B_IDLE
;
690 usb_phy_set_event(&ab
->phy
, USB_EVENT_NONE
);
693 case USB_LINK_ACA_RID_C_NM_8505
:
694 event
= UX500_MUSB_RIDC
;
695 case USB_LINK_STD_HOST_NC_8505
:
696 case USB_LINK_STD_HOST_C_NS_8505
:
697 case USB_LINK_STD_HOST_C_S_8505
:
698 case USB_LINK_CDP_8505
:
699 if (ab
->mode
== USB_IDLE
) {
700 ab
->mode
= USB_PERIPHERAL
;
701 ab8500_usb_peri_phy_en(ab
);
702 atomic_notifier_call_chain(&ab
->phy
.notifier
,
703 UX500_MUSB_PREPARE
, &ab
->vbus_draw
);
704 usb_phy_set_event(&ab
->phy
, USB_EVENT_ENUMERATED
);
706 if (event
!= UX500_MUSB_RIDC
)
707 event
= UX500_MUSB_VBUS
;
710 case USB_LINK_ACA_RID_A_8505
:
711 case USB_LINK_ACA_DOCK_CHGR_8505
:
712 event
= UX500_MUSB_RIDA
;
713 case USB_LINK_HM_IDGND_8505
:
714 if (ab
->mode
== USB_IDLE
) {
716 ab8500_usb_host_phy_en(ab
);
717 atomic_notifier_call_chain(&ab
->phy
.notifier
,
718 UX500_MUSB_PREPARE
, &ab
->vbus_draw
);
720 ab
->phy
.otg
->default_a
= true;
721 if (event
!= UX500_MUSB_RIDA
)
722 event
= UX500_MUSB_ID
;
723 atomic_notifier_call_chain(&ab
->phy
.notifier
,
724 event
, &ab
->vbus_draw
);
727 case USB_LINK_DEDICATED_CHG_8505
:
728 ab
->mode
= USB_DEDICATED_CHG
;
729 event
= UX500_MUSB_CHARGER
;
730 atomic_notifier_call_chain(&ab
->phy
.notifier
,
731 event
, &ab
->vbus_draw
);
732 usb_phy_set_event(&ab
->phy
, USB_EVENT_CHARGER
);
742 static int ab8500_usb_link_status_update(struct ab8500_usb
*ab
,
743 enum ab8500_usb_link_status lsts
)
745 enum ux500_musb_vbus_id_status event
= 0;
747 dev_dbg(ab
->dev
, "ab8500_usb_link_status_update %d\n", lsts
);
750 * Spurious link_status interrupts are seen in case of a
751 * disconnection of a device in IDGND and RIDA stage
753 if (ab
->previous_link_status_state
== USB_LINK_HM_IDGND_8500
&&
754 (lsts
== USB_LINK_STD_HOST_C_NS_8500
||
755 lsts
== USB_LINK_STD_HOST_NC_8500
))
758 if (ab
->previous_link_status_state
== USB_LINK_ACA_RID_A_8500
&&
759 lsts
== USB_LINK_STD_HOST_NC_8500
)
762 ab
->previous_link_status_state
= lsts
;
765 case USB_LINK_ACA_RID_B_8500
:
766 event
= UX500_MUSB_RIDB
;
767 case USB_LINK_NOT_CONFIGURED_8500
:
768 case USB_LINK_NOT_VALID_LINK_8500
:
770 ab
->phy
.otg
->default_a
= false;
772 if (event
!= UX500_MUSB_RIDB
)
773 event
= UX500_MUSB_NONE
;
774 /* Fallback to default B_IDLE as nothing is connected */
775 ab
->phy
.otg
->state
= OTG_STATE_B_IDLE
;
776 usb_phy_set_event(&ab
->phy
, USB_EVENT_NONE
);
779 case USB_LINK_ACA_RID_C_NM_8500
:
780 case USB_LINK_ACA_RID_C_HS_8500
:
781 case USB_LINK_ACA_RID_C_HS_CHIRP_8500
:
782 event
= UX500_MUSB_RIDC
;
783 case USB_LINK_STD_HOST_NC_8500
:
784 case USB_LINK_STD_HOST_C_NS_8500
:
785 case USB_LINK_STD_HOST_C_S_8500
:
786 case USB_LINK_HOST_CHG_NM_8500
:
787 case USB_LINK_HOST_CHG_HS_8500
:
788 case USB_LINK_HOST_CHG_HS_CHIRP_8500
:
789 if (ab
->mode
== USB_IDLE
) {
790 ab
->mode
= USB_PERIPHERAL
;
791 ab8500_usb_peri_phy_en(ab
);
792 atomic_notifier_call_chain(&ab
->phy
.notifier
,
793 UX500_MUSB_PREPARE
, &ab
->vbus_draw
);
794 usb_phy_set_event(&ab
->phy
, USB_EVENT_ENUMERATED
);
796 if (event
!= UX500_MUSB_RIDC
)
797 event
= UX500_MUSB_VBUS
;
800 case USB_LINK_ACA_RID_A_8500
:
801 event
= UX500_MUSB_RIDA
;
802 case USB_LINK_HM_IDGND_8500
:
803 if (ab
->mode
== USB_IDLE
) {
805 ab8500_usb_host_phy_en(ab
);
806 atomic_notifier_call_chain(&ab
->phy
.notifier
,
807 UX500_MUSB_PREPARE
, &ab
->vbus_draw
);
809 ab
->phy
.otg
->default_a
= true;
810 if (event
!= UX500_MUSB_RIDA
)
811 event
= UX500_MUSB_ID
;
812 atomic_notifier_call_chain(&ab
->phy
.notifier
,
813 event
, &ab
->vbus_draw
);
816 case USB_LINK_DEDICATED_CHG_8500
:
817 ab
->mode
= USB_DEDICATED_CHG
;
818 event
= UX500_MUSB_CHARGER
;
819 atomic_notifier_call_chain(&ab
->phy
.notifier
,
820 event
, &ab
->vbus_draw
);
821 usb_phy_set_event(&ab
->phy
, USB_EVENT_CHARGER
);
824 case USB_LINK_RESERVED_8500
:
832 * Connection Sequence:
833 * 1. Link Status Interrupt
835 * 3. Enable AB regulators
837 * 5. Reset the musb controller
838 * 6. Switch the ULPI GPIO pins to fucntion mode
839 * 7. Enable the musb Peripheral5 clock
840 * 8. Restore MUSB context
842 static int abx500_usb_link_status_update(struct ab8500_usb
*ab
)
847 if (is_ab8500(ab
->ab8500
)) {
848 enum ab8500_usb_link_status lsts
;
850 abx500_get_register_interruptible(ab
->dev
,
851 AB8500_USB
, AB8500_USB_LINE_STAT_REG
, ®
);
852 lsts
= (reg
>> 3) & 0x0F;
853 ret
= ab8500_usb_link_status_update(ab
, lsts
);
854 } else if (is_ab8505(ab
->ab8500
)) {
855 enum ab8505_usb_link_status lsts
;
857 abx500_get_register_interruptible(ab
->dev
,
858 AB8500_USB
, AB8505_USB_LINE_STAT_REG
, ®
);
859 lsts
= (reg
>> 3) & 0x1F;
860 ret
= ab8505_usb_link_status_update(ab
, lsts
);
861 } else if (is_ab8540(ab
->ab8500
)) {
862 enum ab8540_usb_link_status lsts
;
864 abx500_get_register_interruptible(ab
->dev
,
865 AB8500_USB
, AB8540_USB_LINK_STAT_REG
, ®
);
866 lsts
= (reg
>> 3) & 0xFF;
867 ret
= ab8540_usb_link_status_update(ab
, lsts
);
868 } else if (is_ab9540(ab
->ab8500
)) {
869 enum ab9540_usb_link_status lsts
;
871 abx500_get_register_interruptible(ab
->dev
,
872 AB8500_USB
, AB9540_USB_LINK_STAT_REG
, ®
);
873 lsts
= (reg
>> 3) & 0xFF;
874 ret
= ab9540_usb_link_status_update(ab
, lsts
);
881 * Disconnection Sequence:
882 * 1. Disconnect Interrupt
883 * 2. Disable regulators
884 * 3. Disable AB clock
886 * 5. Link Status Interrupt
887 * 6. Disable Musb Clock
889 static irqreturn_t
ab8500_usb_disconnect_irq(int irq
, void *data
)
891 struct ab8500_usb
*ab
= (struct ab8500_usb
*) data
;
892 enum usb_phy_events event
= UX500_MUSB_NONE
;
894 /* Link status will not be updated till phy is disabled. */
895 if (ab
->mode
== USB_HOST
) {
896 ab
->phy
.otg
->default_a
= false;
898 atomic_notifier_call_chain(&ab
->phy
.notifier
,
899 event
, &ab
->vbus_draw
);
900 ab8500_usb_host_phy_dis(ab
);
904 if (ab
->mode
== USB_PERIPHERAL
) {
905 atomic_notifier_call_chain(&ab
->phy
.notifier
,
906 event
, &ab
->vbus_draw
);
907 ab8500_usb_peri_phy_dis(ab
);
908 atomic_notifier_call_chain(&ab
->phy
.notifier
,
909 UX500_MUSB_CLEAN
, &ab
->vbus_draw
);
911 ab
->phy
.otg
->default_a
= false;
915 if (is_ab8500_2p0(ab
->ab8500
)) {
916 if (ab
->mode
== USB_DEDICATED_CHG
) {
917 ab8500_usb_wd_linkstatus(ab
,
918 AB8500_BIT_PHY_CTRL_DEVICE_EN
);
919 abx500_mask_and_set_register_interruptible(ab
->dev
,
920 AB8500_USB
, AB8500_USB_PHY_CTRL_REG
,
921 AB8500_BIT_PHY_CTRL_DEVICE_EN
, 0);
928 static irqreturn_t
ab8500_usb_link_status_irq(int irq
, void *data
)
930 struct ab8500_usb
*ab
= (struct ab8500_usb
*)data
;
932 abx500_usb_link_status_update(ab
);
937 static void ab8500_usb_phy_disable_work(struct work_struct
*work
)
939 struct ab8500_usb
*ab
= container_of(work
, struct ab8500_usb
,
942 if (!ab
->phy
.otg
->host
)
943 ab8500_usb_host_phy_dis(ab
);
945 if (!ab
->phy
.otg
->gadget
)
946 ab8500_usb_peri_phy_dis(ab
);
949 /* Check if VBUS is set and linkstatus has not detected a cable. */
950 static bool ab8500_usb_check_vbus_status(struct ab8500_usb
*ab
)
954 enum ab8540_usb_link_status lsts
;
956 abx500_get_register_interruptible(ab
->dev
,
957 AB8500_INTERRUPT
, AB8500_IT_SOURCE2_REG
,
960 /* If Vbus is below 3.6V abort */
961 if (!(isource2
& AB8500_BIT_SOURCE2_VBUSDET
))
964 abx500_get_register_interruptible(ab
->dev
,
965 AB8500_USB
, AB8540_USB_LINK_STAT_REG
,
968 lsts
= (reg
>> 3) & 0xFF;
970 /* Check if linkstatus has detected a cable */
977 /* re-trigger charger detection again with watchdog re-kick. */
978 static void ab8500_usb_vbus_turn_on_event_work(struct work_struct
*work
)
980 struct ab8500_usb
*ab
= container_of(work
, struct ab8500_usb
,
983 if (ab
->mode
!= USB_IDLE
)
986 abx500_set_register_interruptible(ab
->dev
,
987 AB8500_SYS_CTRL2_BLOCK
, AB8500_MAIN_WD_CTRL_REG
,
988 AB8500_BIT_WD_CTRL_ENABLE
);
992 abx500_set_register_interruptible(ab
->dev
,
993 AB8500_SYS_CTRL2_BLOCK
, AB8500_MAIN_WD_CTRL_REG
,
994 AB8500_BIT_WD_CTRL_ENABLE
| AB8500_BIT_WD_CTRL_KICK
);
998 /* Disable Main watchdog */
999 abx500_set_register_interruptible(ab
->dev
,
1000 AB8500_SYS_CTRL2_BLOCK
, AB8500_MAIN_WD_CTRL_REG
,
1003 /* Enable USB Charger detection */
1004 abx500_mask_and_set_register_interruptible(ab
->dev
,
1005 AB8500_USB
, AB8540_VBUS_CTRL_REG
,
1006 AB8540_BIT_VBUS_CTRL_CHARG_DET_ENA
,
1007 AB8540_BIT_VBUS_CTRL_CHARG_DET_ENA
);
1009 ab
->enabled_charging_detection
= true;
1012 static int ab8500_usb_set_suspend(struct usb_phy
*x
, int suspend
)
1018 static int ab8500_usb_set_peripheral(struct usb_otg
*otg
,
1019 struct usb_gadget
*gadget
)
1021 struct ab8500_usb
*ab
;
1026 ab
= phy_to_ab(otg
->usb_phy
);
1028 ab
->phy
.otg
->gadget
= gadget
;
1030 /* Some drivers call this function in atomic context.
1031 * Do not update ab8500 registers directly till this
1035 if ((ab
->mode
!= USB_IDLE
) && !gadget
) {
1036 ab
->mode
= USB_IDLE
;
1037 schedule_work(&ab
->phy_dis_work
);
1043 static int ab8500_usb_set_host(struct usb_otg
*otg
, struct usb_bus
*host
)
1045 struct ab8500_usb
*ab
;
1050 ab
= phy_to_ab(otg
->usb_phy
);
1052 ab
->phy
.otg
->host
= host
;
1054 /* Some drivers call this function in atomic context.
1055 * Do not update ab8500 registers directly till this
1059 if ((ab
->mode
!= USB_IDLE
) && !host
) {
1060 ab
->mode
= USB_IDLE
;
1061 schedule_work(&ab
->phy_dis_work
);
1067 static void ab8500_usb_restart_phy(struct ab8500_usb
*ab
)
1069 abx500_mask_and_set_register_interruptible(ab
->dev
,
1070 AB8500_USB
, AB8500_USB_PHY_CTRL_REG
,
1071 AB8500_BIT_PHY_CTRL_DEVICE_EN
,
1072 AB8500_BIT_PHY_CTRL_DEVICE_EN
);
1076 abx500_mask_and_set_register_interruptible(ab
->dev
,
1077 AB8500_USB
, AB8500_USB_PHY_CTRL_REG
,
1078 AB8500_BIT_PHY_CTRL_DEVICE_EN
,
1081 abx500_mask_and_set_register_interruptible(ab
->dev
,
1082 AB8500_USB
, AB8500_USB_PHY_CTRL_REG
,
1083 AB8500_BIT_PHY_CTRL_HOST_EN
,
1084 AB8500_BIT_PHY_CTRL_HOST_EN
);
1088 abx500_mask_and_set_register_interruptible(ab
->dev
,
1089 AB8500_USB
, AB8500_USB_PHY_CTRL_REG
,
1090 AB8500_BIT_PHY_CTRL_HOST_EN
,
1094 static int ab8500_usb_regulator_get(struct ab8500_usb
*ab
)
1098 ab
->v_ape
= devm_regulator_get(ab
->dev
, "v-ape");
1099 if (IS_ERR(ab
->v_ape
)) {
1100 dev_err(ab
->dev
, "Could not get v-ape supply\n");
1101 err
= PTR_ERR(ab
->v_ape
);
1105 ab
->v_ulpi
= devm_regulator_get(ab
->dev
, "vddulpivio18");
1106 if (IS_ERR(ab
->v_ulpi
)) {
1107 dev_err(ab
->dev
, "Could not get vddulpivio18 supply\n");
1108 err
= PTR_ERR(ab
->v_ulpi
);
1112 ab
->v_musb
= devm_regulator_get(ab
->dev
, "musb_1v8");
1113 if (IS_ERR(ab
->v_musb
)) {
1114 dev_err(ab
->dev
, "Could not get musb_1v8 supply\n");
1115 err
= PTR_ERR(ab
->v_musb
);
1122 static int ab8500_usb_irq_setup(struct platform_device
*pdev
,
1123 struct ab8500_usb
*ab
)
1128 if (ab
->flags
& AB8500_USB_FLAG_USE_LINK_STATUS_IRQ
) {
1129 irq
= platform_get_irq_byname(pdev
, "USB_LINK_STATUS");
1131 dev_err(&pdev
->dev
, "Link status irq not found\n");
1134 err
= devm_request_threaded_irq(&pdev
->dev
, irq
, NULL
,
1135 ab8500_usb_link_status_irq
,
1136 IRQF_NO_SUSPEND
| IRQF_SHARED
| IRQF_ONESHOT
,
1137 "usb-link-status", ab
);
1139 dev_err(ab
->dev
, "request_irq failed for link status irq\n");
1144 if (ab
->flags
& AB8500_USB_FLAG_USE_ID_WAKEUP_IRQ
) {
1145 irq
= platform_get_irq_byname(pdev
, "ID_WAKEUP_F");
1147 dev_err(&pdev
->dev
, "ID fall irq not found\n");
1150 err
= devm_request_threaded_irq(&pdev
->dev
, irq
, NULL
,
1151 ab8500_usb_disconnect_irq
,
1152 IRQF_NO_SUSPEND
| IRQF_SHARED
| IRQF_ONESHOT
,
1155 dev_err(ab
->dev
, "request_irq failed for ID fall irq\n");
1160 if (ab
->flags
& AB8500_USB_FLAG_USE_VBUS_DET_IRQ
) {
1161 irq
= platform_get_irq_byname(pdev
, "VBUS_DET_F");
1163 dev_err(&pdev
->dev
, "VBUS fall irq not found\n");
1166 err
= devm_request_threaded_irq(&pdev
->dev
, irq
, NULL
,
1167 ab8500_usb_disconnect_irq
,
1168 IRQF_NO_SUSPEND
| IRQF_SHARED
| IRQF_ONESHOT
,
1169 "usb-vbus-fall", ab
);
1171 dev_err(ab
->dev
, "request_irq failed for Vbus fall irq\n");
1179 static void ab8500_usb_set_ab8500_tuning_values(struct ab8500_usb
*ab
)
1183 /* Enable the PBT/Bank 0x12 access */
1184 err
= abx500_set_register_interruptible(ab
->dev
,
1185 AB8500_DEVELOPMENT
, AB8500_BANK12_ACCESS
, 0x01);
1187 dev_err(ab
->dev
, "Failed to enable bank12 access err=%d\n",
1190 err
= abx500_set_register_interruptible(ab
->dev
,
1191 AB8500_DEBUG
, AB8500_USB_PHY_TUNE1
, 0xC8);
1193 dev_err(ab
->dev
, "Failed to set PHY_TUNE1 register err=%d\n",
1196 err
= abx500_set_register_interruptible(ab
->dev
,
1197 AB8500_DEBUG
, AB8500_USB_PHY_TUNE2
, 0x00);
1199 dev_err(ab
->dev
, "Failed to set PHY_TUNE2 register err=%d\n",
1202 err
= abx500_set_register_interruptible(ab
->dev
,
1203 AB8500_DEBUG
, AB8500_USB_PHY_TUNE3
, 0x78);
1205 dev_err(ab
->dev
, "Failed to set PHY_TUNE3 register err=%d\n",
1208 /* Switch to normal mode/disable Bank 0x12 access */
1209 err
= abx500_set_register_interruptible(ab
->dev
,
1210 AB8500_DEVELOPMENT
, AB8500_BANK12_ACCESS
, 0x00);
1212 dev_err(ab
->dev
, "Failed to switch bank12 access err=%d\n",
1216 static void ab8500_usb_set_ab8505_tuning_values(struct ab8500_usb
*ab
)
1220 /* Enable the PBT/Bank 0x12 access */
1221 err
= abx500_mask_and_set_register_interruptible(ab
->dev
,
1222 AB8500_DEVELOPMENT
, AB8500_BANK12_ACCESS
,
1225 dev_err(ab
->dev
, "Failed to enable bank12 access err=%d\n",
1228 err
= abx500_mask_and_set_register_interruptible(ab
->dev
,
1229 AB8500_DEBUG
, AB8500_USB_PHY_TUNE1
,
1232 dev_err(ab
->dev
, "Failed to set PHY_TUNE1 register err=%d\n",
1235 err
= abx500_mask_and_set_register_interruptible(ab
->dev
,
1236 AB8500_DEBUG
, AB8500_USB_PHY_TUNE2
,
1239 dev_err(ab
->dev
, "Failed to set PHY_TUNE2 register err=%d\n",
1242 err
= abx500_mask_and_set_register_interruptible(ab
->dev
,
1243 AB8500_DEBUG
, AB8500_USB_PHY_TUNE3
,
1247 dev_err(ab
->dev
, "Failed to set PHY_TUNE3 register err=%d\n",
1250 /* Switch to normal mode/disable Bank 0x12 access */
1251 err
= abx500_mask_and_set_register_interruptible(ab
->dev
,
1252 AB8500_DEVELOPMENT
, AB8500_BANK12_ACCESS
,
1255 dev_err(ab
->dev
, "Failed to switch bank12 access err=%d\n",
1259 static void ab8500_usb_set_ab8540_tuning_values(struct ab8500_usb
*ab
)
1263 err
= abx500_set_register_interruptible(ab
->dev
,
1264 AB8540_DEBUG
, AB8500_USB_PHY_TUNE1
, 0xCC);
1266 dev_err(ab
->dev
, "Failed to set PHY_TUNE1 register ret=%d\n",
1269 err
= abx500_set_register_interruptible(ab
->dev
,
1270 AB8540_DEBUG
, AB8500_USB_PHY_TUNE2
, 0x60);
1272 dev_err(ab
->dev
, "Failed to set PHY_TUNE2 register ret=%d\n",
1275 err
= abx500_set_register_interruptible(ab
->dev
,
1276 AB8540_DEBUG
, AB8500_USB_PHY_TUNE3
, 0x90);
1278 dev_err(ab
->dev
, "Failed to set PHY_TUNE3 register ret=%d\n",
1282 static void ab8500_usb_set_ab9540_tuning_values(struct ab8500_usb
*ab
)
1286 /* Enable the PBT/Bank 0x12 access */
1287 err
= abx500_set_register_interruptible(ab
->dev
,
1288 AB8500_DEVELOPMENT
, AB8500_BANK12_ACCESS
, 0x01);
1290 dev_err(ab
->dev
, "Failed to enable bank12 access err=%d\n",
1293 err
= abx500_set_register_interruptible(ab
->dev
,
1294 AB8500_DEBUG
, AB8500_USB_PHY_TUNE1
, 0xC8);
1296 dev_err(ab
->dev
, "Failed to set PHY_TUNE1 register err=%d\n",
1299 err
= abx500_set_register_interruptible(ab
->dev
,
1300 AB8500_DEBUG
, AB8500_USB_PHY_TUNE2
, 0x60);
1302 dev_err(ab
->dev
, "Failed to set PHY_TUNE2 register err=%d\n",
1305 err
= abx500_set_register_interruptible(ab
->dev
,
1306 AB8500_DEBUG
, AB8500_USB_PHY_TUNE3
, 0x80);
1308 dev_err(ab
->dev
, "Failed to set PHY_TUNE3 register err=%d\n",
1311 /* Switch to normal mode/disable Bank 0x12 access */
1312 err
= abx500_set_register_interruptible(ab
->dev
,
1313 AB8500_DEVELOPMENT
, AB8500_BANK12_ACCESS
, 0x00);
1315 dev_err(ab
->dev
, "Failed to switch bank12 access err=%d\n",
1319 static int ab8500_usb_probe(struct platform_device
*pdev
)
1321 struct ab8500_usb
*ab
;
1322 struct ab8500
*ab8500
;
1323 struct usb_otg
*otg
;
1327 ab8500
= dev_get_drvdata(pdev
->dev
.parent
);
1328 rev
= abx500_get_chip_id(&pdev
->dev
);
1330 if (is_ab8500_1p1_or_earlier(ab8500
)) {
1331 dev_err(&pdev
->dev
, "Unsupported AB8500 chip rev=%d\n", rev
);
1335 ab
= devm_kzalloc(&pdev
->dev
, sizeof(*ab
), GFP_KERNEL
);
1339 otg
= devm_kzalloc(&pdev
->dev
, sizeof(*otg
), GFP_KERNEL
);
1343 ab
->dev
= &pdev
->dev
;
1344 ab
->ab8500
= ab8500
;
1345 ab
->phy
.dev
= ab
->dev
;
1347 ab
->phy
.label
= "ab8500";
1348 ab
->phy
.set_suspend
= ab8500_usb_set_suspend
;
1349 ab
->phy
.otg
->state
= OTG_STATE_UNDEFINED
;
1351 otg
->usb_phy
= &ab
->phy
;
1352 otg
->set_host
= ab8500_usb_set_host
;
1353 otg
->set_peripheral
= ab8500_usb_set_peripheral
;
1355 if (is_ab8500(ab
->ab8500
)) {
1356 ab
->flags
|= AB8500_USB_FLAG_USE_LINK_STATUS_IRQ
|
1357 AB8500_USB_FLAG_USE_ID_WAKEUP_IRQ
|
1358 AB8500_USB_FLAG_USE_VBUS_DET_IRQ
|
1359 AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE
;
1360 } else if (is_ab8505(ab
->ab8500
)) {
1361 ab
->flags
|= AB8500_USB_FLAG_USE_LINK_STATUS_IRQ
|
1362 AB8500_USB_FLAG_USE_ID_WAKEUP_IRQ
|
1363 AB8500_USB_FLAG_USE_VBUS_DET_IRQ
|
1364 AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE
;
1365 } else if (is_ab8540(ab
->ab8500
)) {
1366 ab
->flags
|= AB8500_USB_FLAG_USE_LINK_STATUS_IRQ
|
1367 AB8500_USB_FLAG_USE_CHECK_VBUS_STATUS
|
1368 AB8500_USB_FLAG_USE_VBUS_HOST_QUIRK
|
1369 AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE
;
1370 } else if (is_ab9540(ab
->ab8500
)) {
1371 ab
->flags
|= AB8500_USB_FLAG_USE_LINK_STATUS_IRQ
|
1372 AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE
;
1373 if (is_ab9540_2p0_or_earlier(ab
->ab8500
))
1374 ab
->flags
|= AB8500_USB_FLAG_USE_ID_WAKEUP_IRQ
|
1375 AB8500_USB_FLAG_USE_VBUS_DET_IRQ
;
1378 /* Disable regulator voltage setting for AB8500 <= v2.0 */
1379 if (is_ab8500_2p0_or_earlier(ab
->ab8500
))
1380 ab
->flags
&= ~AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE
;
1382 platform_set_drvdata(pdev
, ab
);
1384 /* all: Disable phy when called from set_host and set_peripheral */
1385 INIT_WORK(&ab
->phy_dis_work
, ab8500_usb_phy_disable_work
);
1387 INIT_WORK(&ab
->vbus_event_work
, ab8500_usb_vbus_turn_on_event_work
);
1389 err
= ab8500_usb_regulator_get(ab
);
1393 ab
->sysclk
= devm_clk_get(ab
->dev
, "sysclk");
1394 if (IS_ERR(ab
->sysclk
)) {
1395 dev_err(ab
->dev
, "Could not get sysclk.\n");
1396 return PTR_ERR(ab
->sysclk
);
1399 err
= ab8500_usb_irq_setup(pdev
, ab
);
1403 err
= usb_add_phy(&ab
->phy
, USB_PHY_TYPE_USB2
);
1405 dev_err(&pdev
->dev
, "Can't register transceiver\n");
1409 if (is_ab8500(ab
->ab8500
) && !is_ab8500_2p0_or_earlier(ab
->ab8500
))
1410 /* Phy tuning values for AB8500 > v2.0 */
1411 ab8500_usb_set_ab8500_tuning_values(ab
);
1412 else if (is_ab8505(ab
->ab8500
))
1413 /* Phy tuning values for AB8505 */
1414 ab8500_usb_set_ab8505_tuning_values(ab
);
1415 else if (is_ab8540(ab
->ab8500
))
1416 /* Phy tuning values for AB8540 */
1417 ab8500_usb_set_ab8540_tuning_values(ab
);
1418 else if (is_ab9540(ab
->ab8500
))
1419 /* Phy tuning values for AB9540 */
1420 ab8500_usb_set_ab9540_tuning_values(ab
);
1422 /* Needed to enable ID detection. */
1423 ab8500_usb_wd_workaround(ab
);
1426 * This is required for usb-link-status to work properly when a
1427 * cable is connected at boot time.
1429 ab8500_usb_restart_phy(ab
);
1431 if (ab
->flags
& AB8500_USB_FLAG_USE_CHECK_VBUS_STATUS
) {
1432 if (ab8500_usb_check_vbus_status(ab
))
1433 schedule_work(&ab
->vbus_event_work
);
1436 abx500_usb_link_status_update(ab
);
1438 dev_info(&pdev
->dev
, "revision 0x%2x driver initialized\n", rev
);
1443 static int ab8500_usb_remove(struct platform_device
*pdev
)
1445 struct ab8500_usb
*ab
= platform_get_drvdata(pdev
);
1447 cancel_work_sync(&ab
->phy_dis_work
);
1448 cancel_work_sync(&ab
->vbus_event_work
);
1450 usb_remove_phy(&ab
->phy
);
1452 if (ab
->mode
== USB_HOST
)
1453 ab8500_usb_host_phy_dis(ab
);
1454 else if (ab
->mode
== USB_PERIPHERAL
)
1455 ab8500_usb_peri_phy_dis(ab
);
1460 static const struct platform_device_id ab8500_usb_devtype
[] = {
1461 { .name
= "ab8500-usb", },
1462 { .name
= "ab8540-usb", },
1463 { .name
= "ab9540-usb", },
1466 MODULE_DEVICE_TABLE(platform
, ab8500_usb_devtype
);
1468 static struct platform_driver ab8500_usb_driver
= {
1469 .probe
= ab8500_usb_probe
,
1470 .remove
= ab8500_usb_remove
,
1471 .id_table
= ab8500_usb_devtype
,
1473 .name
= "abx5x0-usb",
1477 static int __init
ab8500_usb_init(void)
1479 return platform_driver_register(&ab8500_usb_driver
);
1481 subsys_initcall(ab8500_usb_init
);
1483 static void __exit
ab8500_usb_exit(void)
1485 platform_driver_unregister(&ab8500_usb_driver
);
1487 module_exit(ab8500_usb_exit
);
1489 MODULE_AUTHOR("ST-Ericsson AB");
1490 MODULE_DESCRIPTION("AB8500 family usb transceiver driver");
1491 MODULE_LICENSE("GPL");