usb: chipidea: split the driver code into units
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / usb / chipidea / ci13xxx_msm.c
CommitLineData
33f82f38
PK
1/* Copyright (c) 2010, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
33f82f38
PK
6 */
7
8#include <linux/module.h>
9#include <linux/platform_device.h>
2d0cdcc5 10#include <linux/pm_runtime.h>
33f82f38
PK
11#include <linux/usb/msm_hsusb_hw.h>
12#include <linux/usb/ulpi.h>
62bb84ed 13#include <linux/usb/gadget.h>
e443b333 14#include <linux/usb/chipidea.h>
33f82f38 15
e443b333 16#include "ci.h"
33f82f38
PK
17
18#define MSM_USB_BASE (udc->regs)
19
33f82f38
PK
20static void ci13xxx_msm_notify_event(struct ci13xxx *udc, unsigned event)
21{
22 struct device *dev = udc->gadget.dev.parent;
23 int val;
24
25 switch (event) {
26 case CI13XXX_CONTROLLER_RESET_EVENT:
27 dev_dbg(dev, "CI13XXX_CONTROLLER_RESET_EVENT received\n");
28 writel(0, USB_AHBBURST);
29 writel(0, USB_AHBMODE);
30 break;
31 case CI13XXX_CONTROLLER_STOPPED_EVENT:
32 dev_dbg(dev, "CI13XXX_CONTROLLER_STOPPED_EVENT received\n");
33 /*
34 * Put the transceiver in non-driving mode. Otherwise host
35 * may not detect soft-disconnection.
36 */
b96d3b08 37 val = usb_phy_io_read(udc->transceiver, ULPI_FUNC_CTRL);
33f82f38
PK
38 val &= ~ULPI_FUNC_CTRL_OPMODE_MASK;
39 val |= ULPI_FUNC_CTRL_OPMODE_NONDRIVING;
b96d3b08 40 usb_phy_io_write(udc->transceiver, val, ULPI_FUNC_CTRL);
33f82f38
PK
41 break;
42 default:
43 dev_dbg(dev, "unknown ci13xxx_udc event\n");
44 break;
45 }
46}
47
48static struct ci13xxx_udc_driver ci13xxx_msm_udc_driver = {
49 .name = "ci13xxx_msm",
50 .flags = CI13XXX_REGS_SHARED |
51 CI13XXX_REQUIRE_TRANSCEIVER |
52 CI13XXX_PULLUP_ON_VBUS |
53 CI13XXX_DISABLE_STREAMING,
54
55 .notify_event = ci13xxx_msm_notify_event,
56};
57
58static int ci13xxx_msm_probe(struct platform_device *pdev)
59{
62bb84ed 60 struct platform_device *plat_ci;
33f82f38
PK
61 int ret;
62
63 dev_dbg(&pdev->dev, "ci13xxx_msm_probe\n");
64
62bb84ed
AS
65 plat_ci = platform_device_alloc("ci_udc", -1);
66 if (!plat_ci) {
67 dev_err(&pdev->dev, "can't allocate ci_udc platform device\n");
33f82f38
PK
68 return -ENOMEM;
69 }
70
62bb84ed
AS
71 ret = platform_device_add_resources(plat_ci, pdev->resource,
72 pdev->num_resources);
73 if (ret) {
74 dev_err(&pdev->dev, "can't add resources to platform device\n");
75 goto put_platform;
33f82f38
PK
76 }
77
62bb84ed
AS
78 ret = platform_device_add_data(plat_ci, &ci13xxx_msm_udc_driver,
79 sizeof(ci13xxx_msm_udc_driver));
80 if (ret)
81 goto put_platform;
33f82f38 82
62bb84ed
AS
83 ret = platform_device_add(plat_ci);
84 if (ret)
85 goto put_platform;
33f82f38 86
2d0cdcc5
PK
87 pm_runtime_no_callbacks(&pdev->dev);
88 pm_runtime_enable(&pdev->dev);
89
33f82f38
PK
90 return 0;
91
62bb84ed
AS
92put_platform:
93 platform_device_put(plat_ci);
33f82f38
PK
94
95 return ret;
96}
97
98static struct platform_driver ci13xxx_msm_driver = {
99 .probe = ci13xxx_msm_probe,
100 .driver = { .name = "msm_hsusb", },
101};
86081d7b 102MODULE_ALIAS("platform:msm_hsusb");
33f82f38
PK
103
104static int __init ci13xxx_msm_init(void)
105{
106 return platform_driver_register(&ci13xxx_msm_driver);
107}
108module_init(ci13xxx_msm_init);
4703d2e9
MKB
109
110MODULE_LICENSE("GPL v2");