blob: 58b26df6afd1b3a457f2f1897b3c43d176a6e42c [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090033#include <linux/slab.h>
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053034
35struct nop_usb_xceiv {
Heikki Krogerus41adf102012-02-13 13:24:10 +020036 struct usb_phy phy;
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053037 struct device *dev;
38};
39
David Brownellcc835e32009-03-31 12:28:31 -070040static struct platform_device *pd;
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053041
42void usb_nop_xceiv_register(void)
43{
David Brownellcc835e32009-03-31 12:28:31 -070044 if (pd)
45 return;
46 pd = platform_device_register_simple("nop_usb_xceiv", -1, NULL, 0);
47 if (!pd) {
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053048 printk(KERN_ERR "Unable to register usb nop transceiver\n");
49 return;
50 }
51}
David Brownellcc835e32009-03-31 12:28:31 -070052EXPORT_SYMBOL(usb_nop_xceiv_register);
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053053
54void usb_nop_xceiv_unregister(void)
55{
David Brownellcc835e32009-03-31 12:28:31 -070056 platform_device_unregister(pd);
Ajay Kumar Guptadc7520c2009-07-03 13:18:45 +053057 pd = NULL;
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053058}
David Brownellcc835e32009-03-31 12:28:31 -070059EXPORT_SYMBOL(usb_nop_xceiv_unregister);
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053060
Heikki Krogerus86753812012-02-13 13:24:02 +020061static int nop_set_suspend(struct usb_phy *x, int suspend)
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053062{
63 return 0;
64}
65
Heikki Krogerus41adf102012-02-13 13:24:10 +020066static int nop_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget)
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053067{
Heikki Krogerus41adf102012-02-13 13:24:10 +020068 if (!otg)
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053069 return -ENODEV;
70
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053071 if (!gadget) {
Heikki Krogerus41adf102012-02-13 13:24:10 +020072 otg->gadget = NULL;
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053073 return -ENODEV;
74 }
75
Heikki Krogerus41adf102012-02-13 13:24:10 +020076 otg->gadget = gadget;
77 otg->phy->state = OTG_STATE_B_IDLE;
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053078 return 0;
79}
80
Heikki Krogerus41adf102012-02-13 13:24:10 +020081static int nop_set_host(struct usb_otg *otg, struct usb_bus *host)
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053082{
Heikki Krogerus41adf102012-02-13 13:24:10 +020083 if (!otg)
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053084 return -ENODEV;
85
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053086 if (!host) {
Heikki Krogerus41adf102012-02-13 13:24:10 +020087 otg->host = NULL;
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053088 return -ENODEV;
89 }
90
Heikki Krogerus41adf102012-02-13 13:24:10 +020091 otg->host = host;
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053092 return 0;
93}
94
95static 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
Heikki Krogerus41adf102012-02-13 13:24:10 +0200104 nop->phy.otg = kzalloc(sizeof *nop->phy.otg, GFP_KERNEL);
105 if (!nop->phy.otg) {
106 kfree(nop);
107 return -ENOMEM;
108 }
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +0530109
Heikki Krogerus41adf102012-02-13 13:24:10 +0200110 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);
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +0530121 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
Heikki Krogerus41adf102012-02-13 13:24:10 +0200129 ATOMIC_INIT_NOTIFIER_HEAD(&nop->phy.notifier);
Ming Lei20831ad2011-01-04 20:21:32 +0800130
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +0530131 return 0;
132exit:
Heikki Krogerus41adf102012-02-13 13:24:10 +0200133 kfree(nop->phy.otg);
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +0530134 kfree(nop);
135 return err;
136}
137
138static int __devexit nop_usb_xceiv_remove(struct platform_device *pdev)
139{
140 struct nop_usb_xceiv *nop = platform_get_drvdata(pdev);
141
Heikki Krogerus41adf102012-02-13 13:24:10 +0200142 usb_set_transceiver(NULL);
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +0530143
144 platform_set_drvdata(pdev, NULL);
Heikki Krogerus41adf102012-02-13 13:24:10 +0200145 kfree(nop->phy.otg);
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +0530146 kfree(nop);
147
148 return 0;
149}
150
151static 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
160static int __init nop_usb_xceiv_init(void)
161{
162 return platform_driver_register(&nop_usb_xceiv_driver);
163}
164subsys_initcall(nop_usb_xceiv_init);
165
166static void __exit nop_usb_xceiv_exit(void)
167{
168 platform_driver_unregister(&nop_usb_xceiv_driver);
169}
170module_exit(nop_usb_xceiv_exit);
171
172MODULE_ALIAS("platform:nop_usb_xceiv");
173MODULE_AUTHOR("Texas Instruments Inc");
174MODULE_DESCRIPTION("NOP USB Transceiver driver");
175MODULE_LICENSE("GPL");