2 * drivers/usb/otg/ab8500_usb.c
4 * USB transceiver driver for AB8500 chip
6 * Copyright (C) 2010 ST-Ericsson AB
7 * Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include <linux/module.h>
26 #include <linux/platform_device.h>
27 #include <linux/usb/otg.h>
28 #include <linux/slab.h>
29 #include <linux/notifier.h>
30 #include <linux/interrupt.h>
31 #include <linux/delay.h>
32 #include <linux/mfd/abx500.h>
33 #include <linux/mfd/abx500/ab8500.h>
34 #include <linux/usb/musb-ux500.h>
35 #include <linux/regulator/consumer.h>
37 /* Bank AB8500_SYS_CTRL2_BLOCK */
38 #define AB8500_MAIN_WD_CTRL_REG 0x01
41 #define AB8500_USB_LINE_STAT_REG 0x80
42 #define AB8505_USB_LINE_STAT_REG 0x94
43 #define AB8500_USB_PHY_CTRL_REG 0x8A
45 /* Bank AB8500_DEVELOPMENT */
46 #define AB8500_BANK12_ACCESS 0x00
48 /* Bank AB8500_DEBUG */
49 #define AB8500_USB_PHY_TUNE1 0x05
50 #define AB8500_USB_PHY_TUNE2 0x06
51 #define AB8500_USB_PHY_TUNE3 0x07
53 #define AB8500_BIT_OTG_STAT_ID (1 << 0)
54 #define AB8500_BIT_PHY_CTRL_HOST_EN (1 << 0)
55 #define AB8500_BIT_PHY_CTRL_DEVICE_EN (1 << 1)
56 #define AB8500_BIT_WD_CTRL_ENABLE (1 << 0)
57 #define AB8500_BIT_WD_CTRL_KICK (1 << 1)
59 #define AB8500_WD_KICK_DELAY_US 100 /* usec */
60 #define AB8500_WD_V11_DISABLE_DELAY_US 100 /* usec */
61 #define AB8500_V20_31952_DISABLE_DELAY_US 100 /* usec */
63 /* Usb line status register */
64 enum ab8500_usb_link_status
{
65 USB_LINK_NOT_CONFIGURED_8500
= 0,
66 USB_LINK_STD_HOST_NC_8500
,
67 USB_LINK_STD_HOST_C_NS_8500
,
68 USB_LINK_STD_HOST_C_S_8500
,
69 USB_LINK_HOST_CHG_NM_8500
,
70 USB_LINK_HOST_CHG_HS_8500
,
71 USB_LINK_HOST_CHG_HS_CHIRP_8500
,
72 USB_LINK_DEDICATED_CHG_8500
,
73 USB_LINK_ACA_RID_A_8500
,
74 USB_LINK_ACA_RID_B_8500
,
75 USB_LINK_ACA_RID_C_NM_8500
,
76 USB_LINK_ACA_RID_C_HS_8500
,
77 USB_LINK_ACA_RID_C_HS_CHIRP_8500
,
78 USB_LINK_HM_IDGND_8500
,
79 USB_LINK_RESERVED_8500
,
80 USB_LINK_NOT_VALID_LINK_8500
,
83 enum ab8505_usb_link_status
{
84 USB_LINK_NOT_CONFIGURED_8505
= 0,
85 USB_LINK_STD_HOST_NC_8505
,
86 USB_LINK_STD_HOST_C_NS_8505
,
87 USB_LINK_STD_HOST_C_S_8505
,
89 USB_LINK_RESERVED0_8505
,
90 USB_LINK_RESERVED1_8505
,
91 USB_LINK_DEDICATED_CHG_8505
,
92 USB_LINK_ACA_RID_A_8505
,
93 USB_LINK_ACA_RID_B_8505
,
94 USB_LINK_ACA_RID_C_NM_8505
,
95 USB_LINK_RESERVED2_8505
,
96 USB_LINK_RESERVED3_8505
,
97 USB_LINK_HM_IDGND_8505
,
98 USB_LINK_CHARGERPORT_NOT_OK_8505
,
99 USB_LINK_CHARGER_DM_HIGH_8505
,
100 USB_LINK_PHYEN_NO_VBUS_NO_IDGND_8505
,
101 USB_LINK_STD_UPSTREAM_NO_IDGNG_NO_VBUS_8505
,
102 USB_LINK_STD_UPSTREAM_8505
,
103 USB_LINK_CHARGER_SE1_8505
,
104 USB_LINK_CARKIT_CHGR_1_8505
,
105 USB_LINK_CARKIT_CHGR_2_8505
,
106 USB_LINK_ACA_DOCK_CHGR_8505
,
107 USB_LINK_SAMSUNG_BOOT_CBL_PHY_EN_8505
,
108 USB_LINK_SAMSUNG_BOOT_CBL_PHY_DISB_8505
,
109 USB_LINK_SAMSUNG_UART_CBL_PHY_EN_8505
,
110 USB_LINK_SAMSUNG_UART_CBL_PHY_DISB_8505
,
111 USB_LINK_MOTOROLA_FACTORY_CBL_PHY_EN_8505
,
114 enum ab8500_usb_mode
{
124 struct ab8500
*ab8500
;
126 struct delayed_work dwork
;
127 struct work_struct phy_dis_work
;
128 unsigned long link_status_wait
;
129 enum ab8500_usb_mode mode
;
130 struct regulator
*v_ape
;
131 struct regulator
*v_musb
;
132 struct regulator
*v_ulpi
;
134 int previous_link_status_state
;
137 static inline struct ab8500_usb
*phy_to_ab(struct usb_phy
*x
)
139 return container_of(x
, struct ab8500_usb
, phy
);
142 static void ab8500_usb_wd_workaround(struct ab8500_usb
*ab
)
144 abx500_set_register_interruptible(ab
->dev
,
145 AB8500_SYS_CTRL2_BLOCK
,
146 AB8500_MAIN_WD_CTRL_REG
,
147 AB8500_BIT_WD_CTRL_ENABLE
);
149 udelay(AB8500_WD_KICK_DELAY_US
);
151 abx500_set_register_interruptible(ab
->dev
,
152 AB8500_SYS_CTRL2_BLOCK
,
153 AB8500_MAIN_WD_CTRL_REG
,
154 (AB8500_BIT_WD_CTRL_ENABLE
155 | AB8500_BIT_WD_CTRL_KICK
));
157 udelay(AB8500_WD_V11_DISABLE_DELAY_US
);
159 abx500_set_register_interruptible(ab
->dev
,
160 AB8500_SYS_CTRL2_BLOCK
,
161 AB8500_MAIN_WD_CTRL_REG
,
165 static void ab8500_usb_regulator_enable(struct ab8500_usb
*ab
)
169 regulator_enable(ab
->v_ape
);
171 if (!is_ab8500_2p0_or_earlier(ab
->ab8500
)) {
172 ab
->saved_v_ulpi
= regulator_get_voltage(ab
->v_ulpi
);
173 if (ab
->saved_v_ulpi
< 0)
174 dev_err(ab
->dev
, "Failed to get v_ulpi voltage\n");
176 ret
= regulator_set_voltage(ab
->v_ulpi
, 1300000, 1350000);
178 dev_err(ab
->dev
, "Failed to set the Vintcore to 1.3V, ret=%d\n",
181 ret
= regulator_set_optimum_mode(ab
->v_ulpi
, 28000);
183 dev_err(ab
->dev
, "Failed to set optimum mode (ret=%d)\n",
187 regulator_enable(ab
->v_ulpi
);
189 if (!is_ab8500_2p0_or_earlier(ab
->ab8500
)) {
190 volt
= regulator_get_voltage(ab
->v_ulpi
);
191 if ((volt
!= 1300000) && (volt
!= 1350000))
192 dev_err(ab
->dev
, "Vintcore is not set to 1.3V volt=%d\n",
196 regulator_enable(ab
->v_musb
);
199 static void ab8500_usb_regulator_disable(struct ab8500_usb
*ab
)
203 regulator_disable(ab
->v_musb
);
205 regulator_disable(ab
->v_ulpi
);
207 /* USB is not the only consumer of Vintcore, restore old settings */
208 if (!is_ab8500_2p0_or_earlier(ab
->ab8500
)) {
209 if (ab
->saved_v_ulpi
> 0) {
210 ret
= regulator_set_voltage(ab
->v_ulpi
,
211 ab
->saved_v_ulpi
, ab
->saved_v_ulpi
);
213 dev_err(ab
->dev
, "Failed to set the Vintcore to %duV, ret=%d\n",
214 ab
->saved_v_ulpi
, ret
);
217 ret
= regulator_set_optimum_mode(ab
->v_ulpi
, 0);
219 dev_err(ab
->dev
, "Failed to set optimum mode (ret=%d)\n",
223 regulator_disable(ab
->v_ape
);
226 static void ab8500_usb_wd_linkstatus(struct ab8500_usb
*ab
, u8 bit
)
228 /* Workaround for v2.0 bug # 31952 */
229 if (is_ab8500_2p0(ab
->ab8500
)) {
230 abx500_mask_and_set_register_interruptible(ab
->dev
,
231 AB8500_USB
, AB8500_USB_PHY_CTRL_REG
,
233 udelay(AB8500_V20_31952_DISABLE_DELAY_US
);
237 static void ab8500_usb_phy_enable(struct ab8500_usb
*ab
, bool sel_host
)
240 bit
= sel_host
? AB8500_BIT_PHY_CTRL_HOST_EN
:
241 AB8500_BIT_PHY_CTRL_DEVICE_EN
;
243 ab8500_usb_regulator_enable(ab
);
245 abx500_mask_and_set_register_interruptible(ab
->dev
,
246 AB8500_USB
, AB8500_USB_PHY_CTRL_REG
,
250 static void ab8500_usb_phy_disable(struct ab8500_usb
*ab
, bool sel_host
)
253 bit
= sel_host
? AB8500_BIT_PHY_CTRL_HOST_EN
:
254 AB8500_BIT_PHY_CTRL_DEVICE_EN
;
256 ab8500_usb_wd_linkstatus(ab
, bit
);
258 abx500_mask_and_set_register_interruptible(ab
->dev
,
259 AB8500_USB
, AB8500_USB_PHY_CTRL_REG
,
262 /* Needed to disable the phy.*/
263 ab8500_usb_wd_workaround(ab
);
265 ab8500_usb_regulator_disable(ab
);
268 #define ab8500_usb_host_phy_en(ab) ab8500_usb_phy_enable(ab, true)
269 #define ab8500_usb_host_phy_dis(ab) ab8500_usb_phy_disable(ab, true)
270 #define ab8500_usb_peri_phy_en(ab) ab8500_usb_phy_enable(ab, false)
271 #define ab8500_usb_peri_phy_dis(ab) ab8500_usb_phy_disable(ab, false)
273 static int ab8505_usb_link_status_update(struct ab8500_usb
*ab
,
274 enum ab8505_usb_link_status lsts
)
276 enum ux500_musb_vbus_id_status event
= 0;
278 dev_dbg(ab
->dev
, "ab8505_usb_link_status_update %d\n", lsts
);
281 * Spurious link_status interrupts are seen at the time of
282 * disconnection of a device in RIDA state
284 if (ab
->previous_link_status_state
== USB_LINK_ACA_RID_A_8505
&&
285 (lsts
== USB_LINK_STD_HOST_NC_8505
))
288 ab
->previous_link_status_state
= lsts
;
291 case USB_LINK_ACA_RID_B_8505
:
292 event
= UX500_MUSB_RIDB
;
293 case USB_LINK_NOT_CONFIGURED_8505
:
294 case USB_LINK_RESERVED0_8505
:
295 case USB_LINK_RESERVED1_8505
:
296 case USB_LINK_RESERVED2_8505
:
297 case USB_LINK_RESERVED3_8505
:
299 ab
->phy
.otg
->default_a
= false;
301 if (event
!= UX500_MUSB_RIDB
)
302 event
= UX500_MUSB_NONE
;
304 * Fallback to default B_IDLE as nothing
307 ab
->phy
.state
= OTG_STATE_B_IDLE
;
310 case USB_LINK_ACA_RID_C_NM_8505
:
311 event
= UX500_MUSB_RIDC
;
312 case USB_LINK_STD_HOST_NC_8505
:
313 case USB_LINK_STD_HOST_C_NS_8505
:
314 case USB_LINK_STD_HOST_C_S_8505
:
315 case USB_LINK_CDP_8505
:
316 if (ab
->mode
== USB_IDLE
) {
317 ab
->mode
= USB_PERIPHERAL
;
318 ab8500_usb_peri_phy_en(ab
);
319 atomic_notifier_call_chain(&ab
->phy
.notifier
,
320 UX500_MUSB_PREPARE
, &ab
->vbus_draw
);
322 if (event
!= UX500_MUSB_RIDC
)
323 event
= UX500_MUSB_VBUS
;
326 case USB_LINK_ACA_RID_A_8505
:
327 case USB_LINK_ACA_DOCK_CHGR_8505
:
328 event
= UX500_MUSB_RIDA
;
329 case USB_LINK_HM_IDGND_8505
:
330 if (ab
->mode
== USB_IDLE
) {
332 ab8500_usb_host_phy_en(ab
);
333 atomic_notifier_call_chain(&ab
->phy
.notifier
,
334 UX500_MUSB_PREPARE
, &ab
->vbus_draw
);
336 ab
->phy
.otg
->default_a
= true;
337 if (event
!= UX500_MUSB_RIDA
)
338 event
= UX500_MUSB_ID
;
339 atomic_notifier_call_chain(&ab
->phy
.notifier
,
340 event
, &ab
->vbus_draw
);
343 case USB_LINK_DEDICATED_CHG_8505
:
344 ab
->mode
= USB_DEDICATED_CHG
;
345 event
= UX500_MUSB_CHARGER
;
346 atomic_notifier_call_chain(&ab
->phy
.notifier
,
347 event
, &ab
->vbus_draw
);
357 static int ab8500_usb_link_status_update(struct ab8500_usb
*ab
,
358 enum ab8500_usb_link_status lsts
)
360 enum ux500_musb_vbus_id_status event
= 0;
362 dev_dbg(ab
->dev
, "ab8500_usb_link_status_update %d\n", lsts
);
365 * Spurious link_status interrupts are seen in case of a
366 * disconnection of a device in IDGND and RIDA stage
368 if (ab
->previous_link_status_state
== USB_LINK_HM_IDGND_8500
&&
369 (lsts
== USB_LINK_STD_HOST_C_NS_8500
||
370 lsts
== USB_LINK_STD_HOST_NC_8500
))
373 if (ab
->previous_link_status_state
== USB_LINK_ACA_RID_A_8500
&&
374 lsts
== USB_LINK_STD_HOST_NC_8500
)
377 ab
->previous_link_status_state
= lsts
;
380 case USB_LINK_ACA_RID_B_8500
:
381 event
= UX500_MUSB_RIDB
;
382 case USB_LINK_NOT_CONFIGURED_8500
:
383 case USB_LINK_NOT_VALID_LINK_8500
:
385 ab
->phy
.otg
->default_a
= false;
387 if (event
!= UX500_MUSB_RIDB
)
388 event
= UX500_MUSB_NONE
;
389 /* Fallback to default B_IDLE as nothing is connected */
390 ab
->phy
.state
= OTG_STATE_B_IDLE
;
393 case USB_LINK_ACA_RID_C_NM_8500
:
394 case USB_LINK_ACA_RID_C_HS_8500
:
395 case USB_LINK_ACA_RID_C_HS_CHIRP_8500
:
396 event
= UX500_MUSB_RIDC
;
397 case USB_LINK_STD_HOST_NC_8500
:
398 case USB_LINK_STD_HOST_C_NS_8500
:
399 case USB_LINK_STD_HOST_C_S_8500
:
400 case USB_LINK_HOST_CHG_NM_8500
:
401 case USB_LINK_HOST_CHG_HS_8500
:
402 case USB_LINK_HOST_CHG_HS_CHIRP_8500
:
403 if (ab
->mode
== USB_IDLE
) {
404 ab
->mode
= USB_PERIPHERAL
;
405 ab8500_usb_peri_phy_en(ab
);
406 atomic_notifier_call_chain(&ab
->phy
.notifier
,
407 UX500_MUSB_PREPARE
, &ab
->vbus_draw
);
409 if (event
!= UX500_MUSB_RIDC
)
410 event
= UX500_MUSB_VBUS
;
413 case USB_LINK_ACA_RID_A_8500
:
414 event
= UX500_MUSB_RIDA
;
415 case USB_LINK_HM_IDGND_8500
:
416 if (ab
->mode
== USB_IDLE
) {
418 ab8500_usb_host_phy_en(ab
);
419 atomic_notifier_call_chain(&ab
->phy
.notifier
,
420 UX500_MUSB_PREPARE
, &ab
->vbus_draw
);
422 ab
->phy
.otg
->default_a
= true;
423 if (event
!= UX500_MUSB_RIDA
)
424 event
= UX500_MUSB_ID
;
425 atomic_notifier_call_chain(&ab
->phy
.notifier
,
426 event
, &ab
->vbus_draw
);
429 case USB_LINK_DEDICATED_CHG_8500
:
430 ab
->mode
= USB_DEDICATED_CHG
;
431 event
= UX500_MUSB_CHARGER
;
432 atomic_notifier_call_chain(&ab
->phy
.notifier
,
433 event
, &ab
->vbus_draw
);
436 case USB_LINK_RESERVED_8500
:
444 * Connection Sequence:
445 * 1. Link Status Interrupt
447 * 3. Enable AB regulators
449 * 5. Reset the musb controller
450 * 6. Switch the ULPI GPIO pins to fucntion mode
451 * 7. Enable the musb Peripheral5 clock
452 * 8. Restore MUSB context
454 static int abx500_usb_link_status_update(struct ab8500_usb
*ab
)
459 if (is_ab8500(ab
->ab8500
)) {
460 enum ab8500_usb_link_status lsts
;
462 abx500_get_register_interruptible(ab
->dev
,
463 AB8500_USB
, AB8500_USB_LINE_STAT_REG
, ®
);
464 lsts
= (reg
>> 3) & 0x0F;
465 ret
= ab8500_usb_link_status_update(ab
, lsts
);
466 } else if (is_ab8505(ab
->ab8500
)) {
467 enum ab8505_usb_link_status lsts
;
469 abx500_get_register_interruptible(ab
->dev
,
470 AB8500_USB
, AB8505_USB_LINE_STAT_REG
, ®
);
471 lsts
= (reg
>> 3) & 0x1F;
472 ret
= ab8505_usb_link_status_update(ab
, lsts
);
479 * Disconnection Sequence:
480 * 1. Disconect Interrupt
481 * 2. Disable regulators
482 * 3. Disable AB clock
484 * 5. Link Status Interrupt
485 * 6. Disable Musb Clock
487 static irqreturn_t
ab8500_usb_disconnect_irq(int irq
, void *data
)
489 struct ab8500_usb
*ab
= (struct ab8500_usb
*) data
;
490 enum usb_phy_events event
= UX500_MUSB_NONE
;
492 /* Link status will not be updated till phy is disabled. */
493 if (ab
->mode
== USB_HOST
) {
494 ab
->phy
.otg
->default_a
= false;
496 atomic_notifier_call_chain(&ab
->phy
.notifier
,
497 event
, &ab
->vbus_draw
);
498 ab8500_usb_host_phy_dis(ab
);
502 if (ab
->mode
== USB_PERIPHERAL
) {
503 atomic_notifier_call_chain(&ab
->phy
.notifier
,
504 event
, &ab
->vbus_draw
);
505 ab8500_usb_peri_phy_dis(ab
);
506 atomic_notifier_call_chain(&ab
->phy
.notifier
,
507 UX500_MUSB_CLEAN
, &ab
->vbus_draw
);
509 ab
->phy
.otg
->default_a
= false;
513 if (is_ab8500_2p0(ab
->ab8500
)) {
514 if (ab
->mode
== USB_DEDICATED_CHG
) {
515 ab8500_usb_wd_linkstatus(ab
,
516 AB8500_BIT_PHY_CTRL_DEVICE_EN
);
517 abx500_mask_and_set_register_interruptible(ab
->dev
,
518 AB8500_USB
, AB8500_USB_PHY_CTRL_REG
,
519 AB8500_BIT_PHY_CTRL_DEVICE_EN
, 0);
526 static irqreturn_t
ab8500_usb_link_status_irq(int irq
, void *data
)
528 struct ab8500_usb
*ab
= (struct ab8500_usb
*) data
;
530 abx500_usb_link_status_update(ab
);
535 static void ab8500_usb_delayed_work(struct work_struct
*work
)
537 struct ab8500_usb
*ab
= container_of(work
, struct ab8500_usb
,
540 abx500_usb_link_status_update(ab
);
543 static void ab8500_usb_phy_disable_work(struct work_struct
*work
)
545 struct ab8500_usb
*ab
= container_of(work
, struct ab8500_usb
,
548 if (!ab
->phy
.otg
->host
)
549 ab8500_usb_host_phy_dis(ab
);
551 if (!ab
->phy
.otg
->gadget
)
552 ab8500_usb_peri_phy_dis(ab
);
555 static unsigned ab8500_eyediagram_workaroud(struct ab8500_usb
*ab
, unsigned mA
)
558 * AB8500 V2 has eye diagram issues when drawing more than 100mA from
559 * VBUS. Set charging current to 100mA in case of standard host
561 if (is_ab8500_2p0_or_earlier(ab
->ab8500
))
568 static int ab8500_usb_set_power(struct usb_phy
*phy
, unsigned mA
)
570 struct ab8500_usb
*ab
;
577 mA
= ab8500_eyediagram_workaroud(ab
, mA
);
581 atomic_notifier_call_chain(&ab
->phy
.notifier
,
582 UX500_MUSB_VBUS
, &ab
->vbus_draw
);
587 static int ab8500_usb_set_suspend(struct usb_phy
*x
, int suspend
)
593 static int ab8500_usb_set_peripheral(struct usb_otg
*otg
,
594 struct usb_gadget
*gadget
)
596 struct ab8500_usb
*ab
;
601 ab
= phy_to_ab(otg
->phy
);
603 /* Some drivers call this function in atomic context.
604 * Do not update ab8500 registers directly till this
610 schedule_work(&ab
->phy_dis_work
);
612 otg
->gadget
= gadget
;
613 otg
->phy
->state
= OTG_STATE_B_IDLE
;
615 /* Phy will not be enabled if cable is already
616 * plugged-in. Schedule to enable phy.
617 * Use same delay to avoid any race condition.
619 schedule_delayed_work(&ab
->dwork
, ab
->link_status_wait
);
625 static int ab8500_usb_set_host(struct usb_otg
*otg
, struct usb_bus
*host
)
627 struct ab8500_usb
*ab
;
632 ab
= phy_to_ab(otg
->phy
);
634 /* Some drivers call this function in atomic context.
635 * Do not update ab8500 registers directly till this
641 schedule_work(&ab
->phy_dis_work
);
644 /* Phy will not be enabled if cable is already
645 * plugged-in. Schedule to enable phy.
646 * Use same delay to avoid any race condition.
648 schedule_delayed_work(&ab
->dwork
, ab
->link_status_wait
);
654 static int ab8500_usb_regulator_get(struct ab8500_usb
*ab
)
658 ab
->v_ape
= devm_regulator_get(ab
->dev
, "v-ape");
659 if (IS_ERR(ab
->v_ape
)) {
660 dev_err(ab
->dev
, "Could not get v-ape supply\n");
661 err
= PTR_ERR(ab
->v_ape
);
665 ab
->v_ulpi
= devm_regulator_get(ab
->dev
, "vddulpivio18");
666 if (IS_ERR(ab
->v_ulpi
)) {
667 dev_err(ab
->dev
, "Could not get vddulpivio18 supply\n");
668 err
= PTR_ERR(ab
->v_ulpi
);
672 ab
->v_musb
= devm_regulator_get(ab
->dev
, "musb_1v8");
673 if (IS_ERR(ab
->v_musb
)) {
674 dev_err(ab
->dev
, "Could not get musb_1v8 supply\n");
675 err
= PTR_ERR(ab
->v_musb
);
682 static int ab8500_usb_irq_setup(struct platform_device
*pdev
,
683 struct ab8500_usb
*ab
)
688 irq
= platform_get_irq_byname(pdev
, "USB_LINK_STATUS");
690 dev_err(&pdev
->dev
, "Link status irq not found\n");
693 err
= devm_request_threaded_irq(&pdev
->dev
, irq
, NULL
,
694 ab8500_usb_link_status_irq
,
695 IRQF_NO_SUSPEND
| IRQF_SHARED
, "usb-link-status", ab
);
697 dev_err(ab
->dev
, "request_irq failed for link status irq\n");
701 irq
= platform_get_irq_byname(pdev
, "ID_WAKEUP_F");
703 dev_err(&pdev
->dev
, "ID fall irq not found\n");
706 err
= devm_request_threaded_irq(&pdev
->dev
, irq
, NULL
,
707 ab8500_usb_disconnect_irq
,
708 IRQF_NO_SUSPEND
| IRQF_SHARED
, "usb-id-fall", ab
);
710 dev_err(ab
->dev
, "request_irq failed for ID fall irq\n");
714 irq
= platform_get_irq_byname(pdev
, "VBUS_DET_F");
716 dev_err(&pdev
->dev
, "VBUS fall irq not found\n");
719 err
= devm_request_threaded_irq(&pdev
->dev
, irq
, NULL
,
720 ab8500_usb_disconnect_irq
,
721 IRQF_NO_SUSPEND
| IRQF_SHARED
, "usb-vbus-fall", ab
);
723 dev_err(ab
->dev
, "request_irq failed for Vbus fall irq\n");
730 static int ab8500_usb_probe(struct platform_device
*pdev
)
732 struct ab8500_usb
*ab
;
733 struct ab8500
*ab8500
;
738 ab8500
= dev_get_drvdata(pdev
->dev
.parent
);
739 rev
= abx500_get_chip_id(&pdev
->dev
);
741 if (is_ab8500_1p1_or_earlier(ab8500
)) {
742 dev_err(&pdev
->dev
, "Unsupported AB8500 chip rev=%d\n", rev
);
746 ab
= devm_kzalloc(&pdev
->dev
, sizeof(*ab
), GFP_KERNEL
);
750 otg
= devm_kzalloc(&pdev
->dev
, sizeof(*otg
), GFP_KERNEL
);
754 ab
->dev
= &pdev
->dev
;
756 ab
->phy
.dev
= ab
->dev
;
758 ab
->phy
.label
= "ab8500";
759 ab
->phy
.set_suspend
= ab8500_usb_set_suspend
;
760 ab
->phy
.set_power
= ab8500_usb_set_power
;
761 ab
->phy
.state
= OTG_STATE_UNDEFINED
;
764 otg
->set_host
= ab8500_usb_set_host
;
765 otg
->set_peripheral
= ab8500_usb_set_peripheral
;
767 platform_set_drvdata(pdev
, ab
);
769 ATOMIC_INIT_NOTIFIER_HEAD(&ab
->phy
.notifier
);
771 /* v1: Wait for link status to become stable.
772 * all: Updates form set_host and set_peripheral as they are atomic.
774 INIT_DELAYED_WORK(&ab
->dwork
, ab8500_usb_delayed_work
);
776 /* all: Disable phy when called from set_host and set_peripheral */
777 INIT_WORK(&ab
->phy_dis_work
, ab8500_usb_phy_disable_work
);
779 err
= ab8500_usb_regulator_get(ab
);
783 err
= ab8500_usb_irq_setup(pdev
, ab
);
787 err
= usb_add_phy(&ab
->phy
, USB_PHY_TYPE_USB2
);
789 dev_err(&pdev
->dev
, "Can't register transceiver\n");
793 /* Phy tuning values for AB8500 */
794 if (!is_ab8500_2p0_or_earlier(ab
->ab8500
)) {
795 /* Enable the PBT/Bank 0x12 access */
796 err
= abx500_set_register_interruptible(ab
->dev
,
797 AB8500_DEVELOPMENT
, AB8500_BANK12_ACCESS
, 0x01);
799 dev_err(ab
->dev
, "Failed to enable bank12 access err=%d\n",
802 err
= abx500_set_register_interruptible(ab
->dev
,
803 AB8500_DEBUG
, AB8500_USB_PHY_TUNE1
, 0xC8);
805 dev_err(ab
->dev
, "Failed to set PHY_TUNE1 register err=%d\n",
808 err
= abx500_set_register_interruptible(ab
->dev
,
809 AB8500_DEBUG
, AB8500_USB_PHY_TUNE2
, 0x00);
811 dev_err(ab
->dev
, "Failed to set PHY_TUNE2 register err=%d\n",
814 err
= abx500_set_register_interruptible(ab
->dev
,
815 AB8500_DEBUG
, AB8500_USB_PHY_TUNE3
, 0x78);
817 dev_err(ab
->dev
, "Failed to set PHY_TUNE3 regester err=%d\n",
820 /* Switch to normal mode/disable Bank 0x12 access */
821 err
= abx500_set_register_interruptible(ab
->dev
,
822 AB8500_DEVELOPMENT
, AB8500_BANK12_ACCESS
, 0x00);
824 dev_err(ab
->dev
, "Failed to switch bank12 access err=%d\n",
828 /* Phy tuning values for AB8505 */
829 if (is_ab8505(ab
->ab8500
)) {
830 /* Enable the PBT/Bank 0x12 access */
831 err
= abx500_mask_and_set_register_interruptible(ab
->dev
,
832 AB8500_DEVELOPMENT
, AB8500_BANK12_ACCESS
,
835 dev_err(ab
->dev
, "Failed to enable bank12 access err=%d\n",
838 err
= abx500_mask_and_set_register_interruptible(ab
->dev
,
839 AB8500_DEBUG
, AB8500_USB_PHY_TUNE1
,
842 dev_err(ab
->dev
, "Failed to set PHY_TUNE1 register err=%d\n",
845 err
= abx500_mask_and_set_register_interruptible(ab
->dev
,
846 AB8500_DEBUG
, AB8500_USB_PHY_TUNE2
,
849 dev_err(ab
->dev
, "Failed to set PHY_TUNE2 register err=%d\n",
852 err
= abx500_mask_and_set_register_interruptible(ab
->dev
,
853 AB8500_DEBUG
, AB8500_USB_PHY_TUNE3
,
857 dev_err(ab
->dev
, "Failed to set PHY_TUNE3 regester err=%d\n",
860 /* Switch to normal mode/disable Bank 0x12 access */
861 err
= abx500_mask_and_set_register_interruptible(ab
->dev
,
862 AB8500_DEVELOPMENT
, AB8500_BANK12_ACCESS
,
865 dev_err(ab
->dev
, "Failed to switch bank12 access err=%d\n",
869 /* Needed to enable ID detection. */
870 ab8500_usb_wd_workaround(ab
);
872 dev_info(&pdev
->dev
, "revision 0x%2x driver initialized\n", rev
);
877 static int ab8500_usb_remove(struct platform_device
*pdev
)
879 struct ab8500_usb
*ab
= platform_get_drvdata(pdev
);
881 cancel_delayed_work_sync(&ab
->dwork
);
883 cancel_work_sync(&ab
->phy_dis_work
);
885 usb_remove_phy(&ab
->phy
);
887 if (ab
->mode
== USB_HOST
)
888 ab8500_usb_host_phy_dis(ab
);
889 else if (ab
->mode
== USB_PERIPHERAL
)
890 ab8500_usb_peri_phy_dis(ab
);
892 platform_set_drvdata(pdev
, NULL
);
897 static struct platform_driver ab8500_usb_driver
= {
898 .probe
= ab8500_usb_probe
,
899 .remove
= ab8500_usb_remove
,
901 .name
= "ab8500-usb",
902 .owner
= THIS_MODULE
,
906 static int __init
ab8500_usb_init(void)
908 return platform_driver_register(&ab8500_usb_driver
);
910 subsys_initcall(ab8500_usb_init
);
912 static void __exit
ab8500_usb_exit(void)
914 platform_driver_unregister(&ab8500_usb_driver
);
916 module_exit(ab8500_usb_exit
);
918 MODULE_ALIAS("platform:ab8500_usb");
919 MODULE_AUTHOR("ST-Ericsson AB");
920 MODULE_DESCRIPTION("AB8500 usb transceiver driver");
921 MODULE_LICENSE("GPL");