blob: af52870788ec04b447beb5faf39aae2b25035771 [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>
Felipe Balbi78c289f2012-07-19 13:32:15 +030033#include <linux/usb/nop-usb-xceiv.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090034#include <linux/slab.h>
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053035
36struct nop_usb_xceiv {
Heikki Krogerus41adf102012-02-13 13:24:10 +020037 struct usb_phy phy;
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053038 struct device *dev;
39};
40
David Brownellcc835e32009-03-31 12:28:31 -070041static struct platform_device *pd;
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053042
43void usb_nop_xceiv_register(void)
44{
David Brownellcc835e32009-03-31 12:28:31 -070045 if (pd)
46 return;
47 pd = platform_device_register_simple("nop_usb_xceiv", -1, NULL, 0);
48 if (!pd) {
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053049 printk(KERN_ERR "Unable to register usb nop transceiver\n");
50 return;
51 }
52}
David Brownellcc835e32009-03-31 12:28:31 -070053EXPORT_SYMBOL(usb_nop_xceiv_register);
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053054
55void usb_nop_xceiv_unregister(void)
56{
David Brownellcc835e32009-03-31 12:28:31 -070057 platform_device_unregister(pd);
Ajay Kumar Guptadc7520c2009-07-03 13:18:45 +053058 pd = NULL;
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053059}
David Brownellcc835e32009-03-31 12:28:31 -070060EXPORT_SYMBOL(usb_nop_xceiv_unregister);
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053061
Heikki Krogerus86753812012-02-13 13:24:02 +020062static int nop_set_suspend(struct usb_phy *x, int suspend)
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053063{
64 return 0;
65}
66
Heikki Krogerus41adf102012-02-13 13:24:10 +020067static int nop_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget)
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053068{
Heikki Krogerus41adf102012-02-13 13:24:10 +020069 if (!otg)
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053070 return -ENODEV;
71
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053072 if (!gadget) {
Heikki Krogerus41adf102012-02-13 13:24:10 +020073 otg->gadget = NULL;
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053074 return -ENODEV;
75 }
76
Heikki Krogerus41adf102012-02-13 13:24:10 +020077 otg->gadget = gadget;
78 otg->phy->state = OTG_STATE_B_IDLE;
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053079 return 0;
80}
81
Heikki Krogerus41adf102012-02-13 13:24:10 +020082static int nop_set_host(struct usb_otg *otg, struct usb_bus *host)
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053083{
Heikki Krogerus41adf102012-02-13 13:24:10 +020084 if (!otg)
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053085 return -ENODEV;
86
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053087 if (!host) {
Heikki Krogerus41adf102012-02-13 13:24:10 +020088 otg->host = NULL;
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053089 return -ENODEV;
90 }
91
Heikki Krogerus41adf102012-02-13 13:24:10 +020092 otg->host = host;
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053093 return 0;
94}
95
Bill Pemberton41ac7b32012-11-19 13:21:48 -050096static int nop_usb_xceiv_probe(struct platform_device *pdev)
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053097{
Felipe Balbic84d3642012-07-19 13:38:06 +030098 struct nop_usb_xceiv_platform_data *pdata = pdev->dev.platform_data;
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +053099 struct nop_usb_xceiv *nop;
Felipe Balbic84d3642012-07-19 13:38:06 +0300100 enum usb_phy_type type = USB_PHY_TYPE_USB2;
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +0530101 int err;
102
Roger Quadrose4d7dc62013-03-12 13:24:20 +0200103 nop = devm_kzalloc(&pdev->dev, sizeof(*nop), GFP_KERNEL);
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +0530104 if (!nop)
105 return -ENOMEM;
106
Roger Quadrose4d7dc62013-03-12 13:24:20 +0200107 nop->phy.otg = devm_kzalloc(&pdev->dev, sizeof(*nop->phy.otg),
108 GFP_KERNEL);
109 if (!nop->phy.otg)
Heikki Krogerus41adf102012-02-13 13:24:10 +0200110 return -ENOMEM;
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +0530111
Felipe Balbic84d3642012-07-19 13:38:06 +0300112 if (pdata)
113 type = pdata->type;
114
Heikki Krogerus41adf102012-02-13 13:24:10 +0200115 nop->dev = &pdev->dev;
116 nop->phy.dev = nop->dev;
117 nop->phy.label = "nop-xceiv";
118 nop->phy.set_suspend = nop_set_suspend;
119 nop->phy.state = OTG_STATE_UNDEFINED;
120
121 nop->phy.otg->phy = &nop->phy;
122 nop->phy.otg->set_host = nop_set_host;
123 nop->phy.otg->set_peripheral = nop_set_peripheral;
124
Felipe Balbic84d3642012-07-19 13:38:06 +0300125 err = usb_add_phy(&nop->phy, type);
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +0530126 if (err) {
127 dev_err(&pdev->dev, "can't register transceiver, err: %d\n",
128 err);
Roger Quadrose4d7dc62013-03-12 13:24:20 +0200129 return err;
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +0530130 }
131
132 platform_set_drvdata(pdev, nop);
133
Heikki Krogerus41adf102012-02-13 13:24:10 +0200134 ATOMIC_INIT_NOTIFIER_HEAD(&nop->phy.notifier);
Ming Lei20831ad2011-01-04 20:21:32 +0800135
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +0530136 return 0;
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +0530137}
138
Bill Pembertonfb4e98a2012-11-19 13:26:20 -0500139static int nop_usb_xceiv_remove(struct platform_device *pdev)
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +0530140{
141 struct nop_usb_xceiv *nop = platform_get_drvdata(pdev);
142
Kishon Vijay Abraham I662dca52012-06-22 17:02:46 +0530143 usb_remove_phy(&nop->phy);
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +0530144
145 platform_set_drvdata(pdev, NULL);
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +0530146
147 return 0;
148}
149
150static struct platform_driver nop_usb_xceiv_driver = {
151 .probe = nop_usb_xceiv_probe,
Bill Pemberton76904172012-11-19 13:21:08 -0500152 .remove = nop_usb_xceiv_remove,
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +0530153 .driver = {
154 .name = "nop_usb_xceiv",
155 .owner = THIS_MODULE,
156 },
157};
158
159static int __init nop_usb_xceiv_init(void)
160{
161 return platform_driver_register(&nop_usb_xceiv_driver);
162}
163subsys_initcall(nop_usb_xceiv_init);
164
165static void __exit nop_usb_xceiv_exit(void)
166{
167 platform_driver_unregister(&nop_usb_xceiv_driver);
168}
169module_exit(nop_usb_xceiv_exit);
170
171MODULE_ALIAS("platform:nop_usb_xceiv");
172MODULE_AUTHOR("Texas Instruments Inc");
173MODULE_DESCRIPTION("NOP USB Transceiver driver");
174MODULE_LICENSE("GPL");