1 /*
2 * drivers/usb/otg/nop-usb-xceiv.c
3 *
4 * NOP USB transceiver for all USB transceiver which are either built-in
5 * into USB IP or which are mostly autonomous.
6 *
7 * Copyright (C) 2009 Texas Instruments Inc
8 * Author: Ajay Kumar Gupta <ajay.gupta@ti.com>
9 *
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.
14 *
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.
19 *
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.
23 *
24 * Current status:
25 * This provides a "nop" transceiver for PHYs which are
26 * autonomous such as isp1504, isp1707, etc.
27 */
28
29 #include <linux/module.h>
30 #include <linux/platform_device.h>
31 #include <linux/dma-mapping.h>
32 #include <linux/usb/otg.h>
33 #include <linux/slab.h>
34
35 struct nop_usb_xceiv {
36 struct usb_phy phy;
37 struct device *dev;
38 };
39
40 static struct platform_device *pd;
41
usb_nop_xceiv_register(void)42 void usb_nop_xceiv_register(void)
43 {
44 if (pd)
45 return;
46 pd = platform_device_register_simple("nop_usb_xceiv", -1, NULL, 0);
47 if (!pd) {
48 printk(KERN_ERR "Unable to register usb nop transceiver\n");
49 return;
50 }
51 }
52 EXPORT_SYMBOL(usb_nop_xceiv_register);
53
usb_nop_xceiv_unregister(void)54 void usb_nop_xceiv_unregister(void)
55 {
56 platform_device_unregister(pd);
57 pd = NULL;
58 }
59 EXPORT_SYMBOL(usb_nop_xceiv_unregister);
60
nop_set_suspend(struct usb_phy * x,int suspend)61 static int nop_set_suspend(struct usb_phy *x, int suspend)
62 {
63 return 0;
64 }
65
nop_set_peripheral(struct usb_otg * otg,struct usb_gadget * gadget)66 static int nop_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget)
67 {
68 if (!otg)
69 return -ENODEV;
70
71 if (!gadget) {
72 otg->gadget = NULL;
73 return -ENODEV;
74 }
75
76 otg->gadget = gadget;
77 otg->phy->state = OTG_STATE_B_IDLE;
78 return 0;
79 }
80
nop_set_host(struct usb_otg * otg,struct usb_bus * host)81 static int nop_set_host(struct usb_otg *otg, struct usb_bus *host)
82 {
83 if (!otg)
84 return -ENODEV;
85
86 if (!host) {
87 otg->host = NULL;
88 return -ENODEV;
89 }
90
91 otg->host = host;
92 return 0;
93 }
94
nop_usb_xceiv_probe(struct platform_device * pdev)95 static int __devinit nop_usb_xceiv_probe(struct platform_device *pdev)
96 {
97 struct nop_usb_xceiv *nop;
98 int err;
99
100 nop = kzalloc(sizeof *nop, GFP_KERNEL);
101 if (!nop)
102 return -ENOMEM;
103
104 nop->phy.otg = kzalloc(sizeof *nop->phy.otg, GFP_KERNEL);
105 if (!nop->phy.otg) {
106 kfree(nop);
107 return -ENOMEM;
108 }
109
110 nop->dev = &pdev->dev;
111 nop->phy.dev = nop->dev;
112 nop->phy.label = "nop-xceiv";
113 nop->phy.set_suspend = nop_set_suspend;
114 nop->phy.state = OTG_STATE_UNDEFINED;
115
116 nop->phy.otg->phy = &nop->phy;
117 nop->phy.otg->set_host = nop_set_host;
118 nop->phy.otg->set_peripheral = nop_set_peripheral;
119
120 err = usb_set_transceiver(&nop->phy);
121 if (err) {
122 dev_err(&pdev->dev, "can't register transceiver, err: %d\n",
123 err);
124 goto exit;
125 }
126
127 platform_set_drvdata(pdev, nop);
128
129 ATOMIC_INIT_NOTIFIER_HEAD(&nop->phy.notifier);
130
131 return 0;
132 exit:
133 kfree(nop->phy.otg);
134 kfree(nop);
135 return err;
136 }
137
nop_usb_xceiv_remove(struct platform_device * pdev)138 static int __devexit nop_usb_xceiv_remove(struct platform_device *pdev)
139 {
140 struct nop_usb_xceiv *nop = platform_get_drvdata(pdev);
141
142 usb_set_transceiver(NULL);
143
144 platform_set_drvdata(pdev, NULL);
145 kfree(nop->phy.otg);
146 kfree(nop);
147
148 return 0;
149 }
150
151 static struct platform_driver nop_usb_xceiv_driver = {
152 .probe = nop_usb_xceiv_probe,
153 .remove = __devexit_p(nop_usb_xceiv_remove),
154 .driver = {
155 .name = "nop_usb_xceiv",
156 .owner = THIS_MODULE,
157 },
158 };
159
nop_usb_xceiv_init(void)160 static int __init nop_usb_xceiv_init(void)
161 {
162 return platform_driver_register(&nop_usb_xceiv_driver);
163 }
164 subsys_initcall(nop_usb_xceiv_init);
165
nop_usb_xceiv_exit(void)166 static void __exit nop_usb_xceiv_exit(void)
167 {
168 platform_driver_unregister(&nop_usb_xceiv_driver);
169 }
170 module_exit(nop_usb_xceiv_exit);
171
172 MODULE_ALIAS("platform:nop_usb_xceiv");
173 MODULE_AUTHOR("Texas Instruments Inc");
174 MODULE_DESCRIPTION("NOP USB Transceiver driver");
175 MODULE_LICENSE("GPL");
176