25 #include <linux/module.h>
28 #include <linux/slab.h>
35 #define AB8500_MAIN_WD_CTRL_REG 0x01
36 #define AB8500_USB_LINE_STAT_REG 0x80
37 #define AB8500_USB_PHY_CTRL_REG 0x8A
39 #define AB8500_BIT_OTG_STAT_ID (1 << 0)
40 #define AB8500_BIT_PHY_CTRL_HOST_EN (1 << 0)
41 #define AB8500_BIT_PHY_CTRL_DEVICE_EN (1 << 1)
42 #define AB8500_BIT_WD_CTRL_ENABLE (1 << 0)
43 #define AB8500_BIT_WD_CTRL_KICK (1 << 1)
45 #define AB8500_V1x_LINK_STAT_WAIT (HZ/10)
46 #define AB8500_WD_KICK_DELAY_US 100
47 #define AB8500_WD_V11_DISABLE_DELAY_US 100
48 #define AB8500_WD_V10_DISABLE_DELAY_MS 100
90 static void ab8500_usb_wd_workaround(
struct ab8500_usb *ab)
116 static void ab8500_usb_phy_ctrl(
struct ab8500_usb *ab,
bool sel_host,
143 ab8500_usb_wd_workaround(ab);
146 #define ab8500_usb_host_phy_en(ab) ab8500_usb_phy_ctrl(ab, true, true)
147 #define ab8500_usb_host_phy_dis(ab) ab8500_usb_phy_ctrl(ab, true, false)
148 #define ab8500_usb_peri_phy_en(ab) ab8500_usb_phy_ctrl(ab, false, true)
149 #define ab8500_usb_peri_phy_dis(ab) ab8500_usb_phy_ctrl(ab, false, false)
151 static int ab8500_usb_link_status_update(
struct ab8500_usb *ab)
163 lsts = (reg >> 3) & 0x0F;
173 ab->
phy.otg->default_a =
false;
184 if (ab->
phy.otg->gadget) {
187 v = ab->
phy.otg->gadget;
193 if (ab->
phy.otg->host) {
196 v = ab->
phy.otg->host;
199 ab->
phy.otg->default_a =
true;
225 ab8500_usb_link_status_update(ab);
255 ab8500_usb_link_status_update(ab);
265 if (!ab->
phy.otg->host)
268 if (!ab->
phy.otg->gadget)
272 static int ab8500_usb_set_power(
struct usb_phy *
phy,
unsigned mA)
299 static int ab8500_usb_set_peripheral(
struct usb_otg *otg,
307 ab = phy_to_ab(otg->
phy);
332 static int ab8500_usb_set_host(
struct usb_otg *otg,
struct usb_bus *
host)
339 ab = phy_to_ab(otg->
phy);
362 static void ab8500_usb_irq_free(
struct ab8500_usb *ab)
364 if (ab->
rev < 0x20) {
381 dev_err(&pdev->
dev,
"ID rise irq not found\n");
385 ab8500_usb_v1x_common_irq,
389 dev_err(ab->
dev,
"request_irq failed for ID rise irq\n");
395 dev_err(&pdev->
dev,
"ID fall irq not found\n");
399 ab8500_usb_v1x_common_irq,
403 dev_err(ab->
dev,
"request_irq failed for ID fall irq\n");
409 dev_err(&pdev->
dev,
"VBUS rise irq not found\n");
413 ab8500_usb_v1x_common_irq,
415 "usb-vbus-rise", ab);
417 dev_err(ab->
dev,
"request_irq failed for Vbus rise irq\n");
423 dev_err(&pdev->
dev,
"VBUS fall irq not found\n");
427 ab8500_usb_v1x_vbus_fall_irq,
429 "usb-vbus-fall", ab);
431 dev_err(ab->
dev,
"request_irq failed for Vbus fall irq\n");
454 dev_err(&pdev->
dev,
"Link status irq not found\n");
461 "usb-link-status", ab);
464 "request_irq failed for link status irq\n");
482 }
else if (rev < 0x10) {
483 dev_err(&pdev->
dev,
"Unsupported AB8500 chip\n");
501 ab->
phy.label =
"ab8500";
502 ab->
phy.set_suspend = ab8500_usb_set_suspend;
503 ab->
phy.set_power = ab8500_usb_set_power;
507 otg->
set_host = ab8500_usb_set_host;
510 platform_set_drvdata(pdev, ab);
522 if (ab->
rev < 0x20) {
523 err = ab8500_usb_v1x_res_setup(pdev, ab);
526 err = ab8500_usb_v2_res_setup(pdev, ab);
534 dev_err(&pdev->
dev,
"Can't register transceiver\n");
538 dev_info(&pdev->
dev,
"AB8500 usb driver initialized\n");
542 ab8500_usb_irq_free(ab);
551 struct ab8500_usb *ab = platform_get_drvdata(pdev);
553 ab8500_usb_irq_free(ab);
564 platform_set_drvdata(pdev,
NULL);
573 .probe = ab8500_usb_probe,
576 .name =
"ab8500-usb",
581 static int __init ab8500_usb_init(
void)
587 static void __exit ab8500_usb_exit(
void)