Commit | Line | Data |
---|---|---|
f6d92a05 AKG |
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: | |
cc835e32 DB |
25 | * This provides a "nop" transceiver for PHYs which are |
26 | * autonomous such as isp1504, isp1707, etc. | |
f6d92a05 AKG |
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> | |
5a0e3ad6 | 33 | #include <linux/slab.h> |
f6d92a05 AKG |
34 | |
35 | struct nop_usb_xceiv { | |
41adf109 | 36 | struct usb_phy phy; |
f6d92a05 AKG |
37 | struct device *dev; |
38 | }; | |
39 | ||
cc835e32 | 40 | static struct platform_device *pd; |
f6d92a05 AKG |
41 | |
42 | void usb_nop_xceiv_register(void) | |
43 | { | |
cc835e32 DB |
44 | if (pd) |
45 | return; | |
46 | pd = platform_device_register_simple("nop_usb_xceiv", -1, NULL, 0); | |
47 | if (!pd) { | |
f6d92a05 AKG |
48 | printk(KERN_ERR "Unable to register usb nop transceiver\n"); |
49 | return; | |
50 | } | |
51 | } | |
cc835e32 | 52 | EXPORT_SYMBOL(usb_nop_xceiv_register); |
f6d92a05 AKG |
53 | |
54 | void usb_nop_xceiv_unregister(void) | |
55 | { | |
cc835e32 | 56 | platform_device_unregister(pd); |
dc7520c1 | 57 | pd = NULL; |
f6d92a05 | 58 | } |
cc835e32 | 59 | EXPORT_SYMBOL(usb_nop_xceiv_unregister); |
f6d92a05 | 60 | |
86753811 | 61 | static int nop_set_suspend(struct usb_phy *x, int suspend) |
f6d92a05 AKG |
62 | { |
63 | return 0; | |
64 | } | |
65 | ||
41adf109 | 66 | static int nop_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget) |
f6d92a05 | 67 | { |
41adf109 | 68 | if (!otg) |
f6d92a05 AKG |
69 | return -ENODEV; |
70 | ||
f6d92a05 | 71 | if (!gadget) { |
41adf109 | 72 | otg->gadget = NULL; |
f6d92a05 AKG |
73 | return -ENODEV; |
74 | } | |
75 | ||
41adf109 HK |
76 | otg->gadget = gadget; |
77 | otg->phy->state = OTG_STATE_B_IDLE; | |
f6d92a05 AKG |
78 | return 0; |
79 | } | |
80 | ||
41adf109 | 81 | static int nop_set_host(struct usb_otg *otg, struct usb_bus *host) |
f6d92a05 | 82 | { |
41adf109 | 83 | if (!otg) |
f6d92a05 AKG |
84 | return -ENODEV; |
85 | ||
f6d92a05 | 86 | if (!host) { |
41adf109 | 87 | otg->host = NULL; |
f6d92a05 AKG |
88 | return -ENODEV; |
89 | } | |
90 | ||
41adf109 | 91 | otg->host = host; |
f6d92a05 AKG |
92 | return 0; |
93 | } | |
94 | ||
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 | ||
41adf109 HK |
104 | nop->phy.otg = kzalloc(sizeof *nop->phy.otg, GFP_KERNEL); |
105 | if (!nop->phy.otg) { | |
106 | kfree(nop); | |
107 | return -ENOMEM; | |
108 | } | |
109 | ||
f6d92a05 | 110 | nop->dev = &pdev->dev; |
41adf109 HK |
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 | ||
721002ec | 120 | err = usb_add_phy(&nop->phy); |
f6d92a05 AKG |
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 | ||
41adf109 | 129 | ATOMIC_INIT_NOTIFIER_HEAD(&nop->phy.notifier); |
20831ad2 | 130 | |
f6d92a05 AKG |
131 | return 0; |
132 | exit: | |
41adf109 | 133 | kfree(nop->phy.otg); |
f6d92a05 AKG |
134 | kfree(nop); |
135 | return err; | |
136 | } | |
137 | ||
138 | static int __devexit nop_usb_xceiv_remove(struct platform_device *pdev) | |
139 | { | |
140 | struct nop_usb_xceiv *nop = platform_get_drvdata(pdev); | |
141 | ||
721002ec | 142 | usb_add_phy(NULL); |
f6d92a05 AKG |
143 | |
144 | platform_set_drvdata(pdev, NULL); | |
41adf109 | 145 | kfree(nop->phy.otg); |
f6d92a05 AKG |
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 | ||
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 | ||
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"); |