Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 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: |
David Brownell | cc835e3 | 2009-03-31 12:28:31 -0700 | [diff] [blame] | 25 | * This provides a "nop" transceiver for PHYs which are |
| 26 | * autonomous such as isp1504, isp1707, etc. |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 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> |
Felipe Balbi | 78c289f | 2012-07-19 13:32:15 +0300 | [diff] [blame] | 33 | #include <linux/usb/nop-usb-xceiv.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 34 | #include <linux/slab.h> |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 35 | |
| 36 | struct nop_usb_xceiv { |
Heikki Krogerus | 41adf10 | 2012-02-13 13:24:10 +0200 | [diff] [blame] | 37 | struct usb_phy phy; |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 38 | struct device *dev; |
| 39 | }; |
| 40 | |
David Brownell | cc835e3 | 2009-03-31 12:28:31 -0700 | [diff] [blame] | 41 | static struct platform_device *pd; |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 42 | |
| 43 | void usb_nop_xceiv_register(void) |
| 44 | { |
David Brownell | cc835e3 | 2009-03-31 12:28:31 -0700 | [diff] [blame] | 45 | if (pd) |
| 46 | return; |
| 47 | pd = platform_device_register_simple("nop_usb_xceiv", -1, NULL, 0); |
| 48 | if (!pd) { |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 49 | printk(KERN_ERR "Unable to register usb nop transceiver\n"); |
| 50 | return; |
| 51 | } |
| 52 | } |
David Brownell | cc835e3 | 2009-03-31 12:28:31 -0700 | [diff] [blame] | 53 | EXPORT_SYMBOL(usb_nop_xceiv_register); |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 54 | |
| 55 | void usb_nop_xceiv_unregister(void) |
| 56 | { |
David Brownell | cc835e3 | 2009-03-31 12:28:31 -0700 | [diff] [blame] | 57 | platform_device_unregister(pd); |
Ajay Kumar Gupta | dc7520c | 2009-07-03 13:18:45 +0530 | [diff] [blame] | 58 | pd = NULL; |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 59 | } |
David Brownell | cc835e3 | 2009-03-31 12:28:31 -0700 | [diff] [blame] | 60 | EXPORT_SYMBOL(usb_nop_xceiv_unregister); |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 61 | |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame] | 62 | static int nop_set_suspend(struct usb_phy *x, int suspend) |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 63 | { |
| 64 | return 0; |
| 65 | } |
| 66 | |
Heikki Krogerus | 41adf10 | 2012-02-13 13:24:10 +0200 | [diff] [blame] | 67 | static int nop_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget) |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 68 | { |
Heikki Krogerus | 41adf10 | 2012-02-13 13:24:10 +0200 | [diff] [blame] | 69 | if (!otg) |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 70 | return -ENODEV; |
| 71 | |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 72 | if (!gadget) { |
Heikki Krogerus | 41adf10 | 2012-02-13 13:24:10 +0200 | [diff] [blame] | 73 | otg->gadget = NULL; |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 74 | return -ENODEV; |
| 75 | } |
| 76 | |
Heikki Krogerus | 41adf10 | 2012-02-13 13:24:10 +0200 | [diff] [blame] | 77 | otg->gadget = gadget; |
| 78 | otg->phy->state = OTG_STATE_B_IDLE; |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 79 | return 0; |
| 80 | } |
| 81 | |
Heikki Krogerus | 41adf10 | 2012-02-13 13:24:10 +0200 | [diff] [blame] | 82 | static int nop_set_host(struct usb_otg *otg, struct usb_bus *host) |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 83 | { |
Heikki Krogerus | 41adf10 | 2012-02-13 13:24:10 +0200 | [diff] [blame] | 84 | if (!otg) |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 85 | return -ENODEV; |
| 86 | |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 87 | if (!host) { |
Heikki Krogerus | 41adf10 | 2012-02-13 13:24:10 +0200 | [diff] [blame] | 88 | otg->host = NULL; |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 89 | return -ENODEV; |
| 90 | } |
| 91 | |
Heikki Krogerus | 41adf10 | 2012-02-13 13:24:10 +0200 | [diff] [blame] | 92 | otg->host = host; |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 93 | return 0; |
| 94 | } |
| 95 | |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame^] | 96 | static int nop_usb_xceiv_probe(struct platform_device *pdev) |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 97 | { |
Felipe Balbi | c84d364 | 2012-07-19 13:38:06 +0300 | [diff] [blame] | 98 | struct nop_usb_xceiv_platform_data *pdata = pdev->dev.platform_data; |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 99 | struct nop_usb_xceiv *nop; |
Felipe Balbi | c84d364 | 2012-07-19 13:38:06 +0300 | [diff] [blame] | 100 | enum usb_phy_type type = USB_PHY_TYPE_USB2; |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 101 | int err; |
| 102 | |
| 103 | nop = kzalloc(sizeof *nop, GFP_KERNEL); |
| 104 | if (!nop) |
| 105 | return -ENOMEM; |
| 106 | |
Heikki Krogerus | 41adf10 | 2012-02-13 13:24:10 +0200 | [diff] [blame] | 107 | nop->phy.otg = kzalloc(sizeof *nop->phy.otg, GFP_KERNEL); |
| 108 | if (!nop->phy.otg) { |
| 109 | kfree(nop); |
| 110 | return -ENOMEM; |
| 111 | } |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 112 | |
Felipe Balbi | c84d364 | 2012-07-19 13:38:06 +0300 | [diff] [blame] | 113 | if (pdata) |
| 114 | type = pdata->type; |
| 115 | |
Heikki Krogerus | 41adf10 | 2012-02-13 13:24:10 +0200 | [diff] [blame] | 116 | nop->dev = &pdev->dev; |
| 117 | nop->phy.dev = nop->dev; |
| 118 | nop->phy.label = "nop-xceiv"; |
| 119 | nop->phy.set_suspend = nop_set_suspend; |
| 120 | nop->phy.state = OTG_STATE_UNDEFINED; |
| 121 | |
| 122 | nop->phy.otg->phy = &nop->phy; |
| 123 | nop->phy.otg->set_host = nop_set_host; |
| 124 | nop->phy.otg->set_peripheral = nop_set_peripheral; |
| 125 | |
Felipe Balbi | c84d364 | 2012-07-19 13:38:06 +0300 | [diff] [blame] | 126 | err = usb_add_phy(&nop->phy, type); |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 127 | if (err) { |
| 128 | dev_err(&pdev->dev, "can't register transceiver, err: %d\n", |
| 129 | err); |
| 130 | goto exit; |
| 131 | } |
| 132 | |
| 133 | platform_set_drvdata(pdev, nop); |
| 134 | |
Heikki Krogerus | 41adf10 | 2012-02-13 13:24:10 +0200 | [diff] [blame] | 135 | ATOMIC_INIT_NOTIFIER_HEAD(&nop->phy.notifier); |
Ming Lei | 20831ad | 2011-01-04 20:21:32 +0800 | [diff] [blame] | 136 | |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 137 | return 0; |
| 138 | exit: |
Heikki Krogerus | 41adf10 | 2012-02-13 13:24:10 +0200 | [diff] [blame] | 139 | kfree(nop->phy.otg); |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 140 | kfree(nop); |
| 141 | return err; |
| 142 | } |
| 143 | |
| 144 | static int __devexit nop_usb_xceiv_remove(struct platform_device *pdev) |
| 145 | { |
| 146 | struct nop_usb_xceiv *nop = platform_get_drvdata(pdev); |
| 147 | |
Kishon Vijay Abraham I | 662dca5 | 2012-06-22 17:02:46 +0530 | [diff] [blame] | 148 | usb_remove_phy(&nop->phy); |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 149 | |
| 150 | platform_set_drvdata(pdev, NULL); |
Heikki Krogerus | 41adf10 | 2012-02-13 13:24:10 +0200 | [diff] [blame] | 151 | kfree(nop->phy.otg); |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 152 | kfree(nop); |
| 153 | |
| 154 | return 0; |
| 155 | } |
| 156 | |
| 157 | static struct platform_driver nop_usb_xceiv_driver = { |
| 158 | .probe = nop_usb_xceiv_probe, |
Bill Pemberton | 7690417 | 2012-11-19 13:21:08 -0500 | [diff] [blame] | 159 | .remove = nop_usb_xceiv_remove, |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 160 | .driver = { |
| 161 | .name = "nop_usb_xceiv", |
| 162 | .owner = THIS_MODULE, |
| 163 | }, |
| 164 | }; |
| 165 | |
| 166 | static int __init nop_usb_xceiv_init(void) |
| 167 | { |
| 168 | return platform_driver_register(&nop_usb_xceiv_driver); |
| 169 | } |
| 170 | subsys_initcall(nop_usb_xceiv_init); |
| 171 | |
| 172 | static void __exit nop_usb_xceiv_exit(void) |
| 173 | { |
| 174 | platform_driver_unregister(&nop_usb_xceiv_driver); |
| 175 | } |
| 176 | module_exit(nop_usb_xceiv_exit); |
| 177 | |
| 178 | MODULE_ALIAS("platform:nop_usb_xceiv"); |
| 179 | MODULE_AUTHOR("Texas Instruments Inc"); |
| 180 | MODULE_DESCRIPTION("NOP USB Transceiver driver"); |
| 181 | MODULE_LICENSE("GPL"); |