2 * drivers/usb/otg/nop-usb-xceiv.c
4 * NOP USB transceiver for all USB transceiver which are either built-in
5 * into USB IP or which are mostly autonomous.
7 * Copyright (C) 2009 Texas Instruments Inc
8 * Author: Ajay Kumar Gupta <ajay.gupta@ti.com>
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.
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.
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.
25 * This provides a "nop" transceiver for PHYs which are
26 * autonomous such as isp1504, isp1707, etc.
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/usb/nop-usb-xceiv.h>
34 #include <linux/slab.h>
35 #include <linux/clk.h>
37 struct nop_usb_xceiv {
43 static struct platform_device *pd;
45 void usb_nop_xceiv_register(void)
49 pd = platform_device_register_simple("nop_usb_xceiv", -1, NULL, 0);
51 printk(KERN_ERR "Unable to register usb nop transceiver\n");
55 EXPORT_SYMBOL(usb_nop_xceiv_register);
57 void usb_nop_xceiv_unregister(void)
59 platform_device_unregister(pd);
62 EXPORT_SYMBOL(usb_nop_xceiv_unregister);
64 static int nop_set_suspend(struct usb_phy *x, int suspend)
69 static int nop_init(struct usb_phy *phy)
71 struct nop_usb_xceiv *nop = dev_get_drvdata(phy->dev);
73 if (!IS_ERR(nop->clk))
79 static void nop_shutdown(struct usb_phy *phy)
81 struct nop_usb_xceiv *nop = dev_get_drvdata(phy->dev);
83 if (!IS_ERR(nop->clk))
84 clk_disable(nop->clk);
87 static int nop_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget)
98 otg->phy->state = OTG_STATE_B_IDLE;
102 static int nop_set_host(struct usb_otg *otg, struct usb_bus *host)
116 static int nop_usb_xceiv_probe(struct platform_device *pdev)
118 struct nop_usb_xceiv_platform_data *pdata = pdev->dev.platform_data;
119 struct nop_usb_xceiv *nop;
120 enum usb_phy_type type = USB_PHY_TYPE_USB2;
123 nop = devm_kzalloc(&pdev->dev, sizeof(*nop), GFP_KERNEL);
127 nop->phy.otg = devm_kzalloc(&pdev->dev, sizeof(*nop->phy.otg),
135 nop->clk = devm_clk_get(&pdev->dev, "main_clk");
136 if (IS_ERR(nop->clk)) {
137 dev_dbg(&pdev->dev, "Can't get phy clock: %ld\n",
141 if (!IS_ERR(nop->clk) && pdata && pdata->clk_rate) {
142 err = clk_set_rate(nop->clk, pdata->clk_rate);
144 dev_err(&pdev->dev, "Error setting clock rate\n");
149 if (!IS_ERR(nop->clk)) {
150 err = clk_prepare(nop->clk);
152 dev_err(&pdev->dev, "Error preparing clock\n");
157 nop->dev = &pdev->dev;
158 nop->phy.dev = nop->dev;
159 nop->phy.label = "nop-xceiv";
160 nop->phy.set_suspend = nop_set_suspend;
161 nop->phy.init = nop_init;
162 nop->phy.shutdown = nop_shutdown;
163 nop->phy.state = OTG_STATE_UNDEFINED;
165 nop->phy.otg->phy = &nop->phy;
166 nop->phy.otg->set_host = nop_set_host;
167 nop->phy.otg->set_peripheral = nop_set_peripheral;
169 err = usb_add_phy(&nop->phy, type);
171 dev_err(&pdev->dev, "can't register transceiver, err: %d\n",
176 platform_set_drvdata(pdev, nop);
178 ATOMIC_INIT_NOTIFIER_HEAD(&nop->phy.notifier);
183 if (!IS_ERR(nop->clk))
184 clk_unprepare(nop->clk);
188 static int nop_usb_xceiv_remove(struct platform_device *pdev)
190 struct nop_usb_xceiv *nop = platform_get_drvdata(pdev);
192 if (!IS_ERR(nop->clk))
193 clk_unprepare(nop->clk);
195 usb_remove_phy(&nop->phy);
197 platform_set_drvdata(pdev, NULL);
202 static struct platform_driver nop_usb_xceiv_driver = {
203 .probe = nop_usb_xceiv_probe,
204 .remove = nop_usb_xceiv_remove,
206 .name = "nop_usb_xceiv",
207 .owner = THIS_MODULE,
211 static int __init nop_usb_xceiv_init(void)
213 return platform_driver_register(&nop_usb_xceiv_driver);
215 subsys_initcall(nop_usb_xceiv_init);
217 static void __exit nop_usb_xceiv_exit(void)
219 platform_driver_unregister(&nop_usb_xceiv_driver);
221 module_exit(nop_usb_xceiv_exit);
223 MODULE_ALIAS("platform:nop_usb_xceiv");
224 MODULE_AUTHOR("Texas Instruments Inc");
225 MODULE_DESCRIPTION("NOP USB Transceiver driver");
226 MODULE_LICENSE("GPL");