blob: af456b48985f06f3ebe09ae43363f47f7d0bfec7 [file] [log] [blame]
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +05301/*
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:
David Brownellcc835e32009-03-31 12:28:31 -070025 * This provides a "nop" transceiver for PHYs which are
26 * autonomous such as isp1504, isp1707, etc.
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053027 */
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
34struct nop_usb_xceiv {
35 struct otg_transceiver otg;
36 struct device *dev;
37};
38
David Brownellcc835e32009-03-31 12:28:31 -070039static struct platform_device *pd;
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053040
41void usb_nop_xceiv_register(void)
42{
David Brownellcc835e32009-03-31 12:28:31 -070043 if (pd)
44 return;
45 pd = platform_device_register_simple("nop_usb_xceiv", -1, NULL, 0);
46 if (!pd) {
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053047 printk(KERN_ERR "Unable to register usb nop transceiver\n");
48 return;
49 }
50}
David Brownellcc835e32009-03-31 12:28:31 -070051EXPORT_SYMBOL(usb_nop_xceiv_register);
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053052
53void usb_nop_xceiv_unregister(void)
54{
David Brownellcc835e32009-03-31 12:28:31 -070055 platform_device_unregister(pd);
Ajay Kumar Guptadc7520c2009-07-03 13:18:45 +053056 pd = NULL;
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053057}
David Brownellcc835e32009-03-31 12:28:31 -070058EXPORT_SYMBOL(usb_nop_xceiv_unregister);
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053059
60static inline struct nop_usb_xceiv *xceiv_to_nop(struct otg_transceiver *x)
61{
62 return container_of(x, struct nop_usb_xceiv, otg);
63}
64
65static int nop_set_suspend(struct otg_transceiver *x, int suspend)
66{
67 return 0;
68}
69
70static int nop_set_peripheral(struct otg_transceiver *x,
71 struct usb_gadget *gadget)
72{
73 struct nop_usb_xceiv *nop;
74
75 if (!x)
76 return -ENODEV;
77
78 nop = xceiv_to_nop(x);
79
80 if (!gadget) {
81 nop->otg.gadget = NULL;
82 return -ENODEV;
83 }
84
85 nop->otg.gadget = gadget;
86 nop->otg.state = OTG_STATE_B_IDLE;
87 return 0;
88}
89
90static int nop_set_host(struct otg_transceiver *x, struct usb_bus *host)
91{
92 struct nop_usb_xceiv *nop;
93
94 if (!x)
95 return -ENODEV;
96
97 nop = xceiv_to_nop(x);
98
99 if (!host) {
100 nop->otg.host = NULL;
101 return -ENODEV;
102 }
103
104 nop->otg.host = host;
105 return 0;
106}
107
108static int __devinit nop_usb_xceiv_probe(struct platform_device *pdev)
109{
110 struct nop_usb_xceiv *nop;
111 int err;
112
113 nop = kzalloc(sizeof *nop, GFP_KERNEL);
114 if (!nop)
115 return -ENOMEM;
116
117 nop->dev = &pdev->dev;
118 nop->otg.dev = nop->dev;
119 nop->otg.label = "nop-xceiv";
120 nop->otg.state = OTG_STATE_UNDEFINED;
121 nop->otg.set_host = nop_set_host;
122 nop->otg.set_peripheral = nop_set_peripheral;
123 nop->otg.set_suspend = nop_set_suspend;
124
125 err = otg_set_transceiver(&nop->otg);
126 if (err) {
127 dev_err(&pdev->dev, "can't register transceiver, err: %d\n",
128 err);
129 goto exit;
130 }
131
132 platform_set_drvdata(pdev, nop);
133
134 return 0;
135exit:
136 kfree(nop);
137 return err;
138}
139
140static int __devexit nop_usb_xceiv_remove(struct platform_device *pdev)
141{
142 struct nop_usb_xceiv *nop = platform_get_drvdata(pdev);
143
144 otg_set_transceiver(NULL);
145
146 platform_set_drvdata(pdev, NULL);
147 kfree(nop);
148
149 return 0;
150}
151
152static struct platform_driver nop_usb_xceiv_driver = {
153 .probe = nop_usb_xceiv_probe,
154 .remove = __devexit_p(nop_usb_xceiv_remove),
155 .driver = {
156 .name = "nop_usb_xceiv",
157 .owner = THIS_MODULE,
158 },
159};
160
161static int __init nop_usb_xceiv_init(void)
162{
163 return platform_driver_register(&nop_usb_xceiv_driver);
164}
165subsys_initcall(nop_usb_xceiv_init);
166
167static void __exit nop_usb_xceiv_exit(void)
168{
169 platform_driver_unregister(&nop_usb_xceiv_driver);
170}
171module_exit(nop_usb_xceiv_exit);
172
173MODULE_ALIAS("platform:nop_usb_xceiv");
174MODULE_AUTHOR("Texas Instruments Inc");
175MODULE_DESCRIPTION("NOP USB Transceiver driver");
176MODULE_LICENSE("GPL");