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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 33 | #include <linux/slab.h> |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 34 | |
| 35 | struct nop_usb_xceiv { |
Heikki Krogerus | 41adf10 | 2012-02-13 13:24:10 +0200 | [diff] [blame] | 36 | struct usb_phy phy; |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 37 | struct device *dev; |
| 38 | }; |
| 39 | |
David Brownell | cc835e3 | 2009-03-31 12:28:31 -0700 | [diff] [blame] | 40 | static struct platform_device *pd; |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 41 | |
| 42 | void usb_nop_xceiv_register(void) |
| 43 | { |
David Brownell | cc835e3 | 2009-03-31 12:28:31 -0700 | [diff] [blame] | 44 | if (pd) |
| 45 | return; |
| 46 | pd = platform_device_register_simple("nop_usb_xceiv", -1, NULL, 0); |
| 47 | if (!pd) { |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 48 | printk(KERN_ERR "Unable to register usb nop transceiver\n"); |
| 49 | return; |
| 50 | } |
| 51 | } |
David Brownell | cc835e3 | 2009-03-31 12:28:31 -0700 | [diff] [blame] | 52 | EXPORT_SYMBOL(usb_nop_xceiv_register); |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 53 | |
| 54 | void usb_nop_xceiv_unregister(void) |
| 55 | { |
David Brownell | cc835e3 | 2009-03-31 12:28:31 -0700 | [diff] [blame] | 56 | platform_device_unregister(pd); |
Ajay Kumar Gupta | dc7520c | 2009-07-03 13:18:45 +0530 | [diff] [blame] | 57 | pd = NULL; |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 58 | } |
David Brownell | cc835e3 | 2009-03-31 12:28:31 -0700 | [diff] [blame] | 59 | EXPORT_SYMBOL(usb_nop_xceiv_unregister); |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 60 | |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame] | 61 | static int nop_set_suspend(struct usb_phy *x, int suspend) |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 62 | { |
| 63 | return 0; |
| 64 | } |
| 65 | |
Heikki Krogerus | 41adf10 | 2012-02-13 13:24:10 +0200 | [diff] [blame] | 66 | 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] | 67 | { |
Heikki Krogerus | 41adf10 | 2012-02-13 13:24:10 +0200 | [diff] [blame] | 68 | if (!otg) |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 69 | return -ENODEV; |
| 70 | |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 71 | if (!gadget) { |
Heikki Krogerus | 41adf10 | 2012-02-13 13:24:10 +0200 | [diff] [blame] | 72 | otg->gadget = NULL; |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 73 | return -ENODEV; |
| 74 | } |
| 75 | |
Heikki Krogerus | 41adf10 | 2012-02-13 13:24:10 +0200 | [diff] [blame] | 76 | otg->gadget = gadget; |
| 77 | otg->phy->state = OTG_STATE_B_IDLE; |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 78 | return 0; |
| 79 | } |
| 80 | |
Heikki Krogerus | 41adf10 | 2012-02-13 13:24:10 +0200 | [diff] [blame] | 81 | 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] | 82 | { |
Heikki Krogerus | 41adf10 | 2012-02-13 13:24:10 +0200 | [diff] [blame] | 83 | if (!otg) |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 84 | return -ENODEV; |
| 85 | |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 86 | if (!host) { |
Heikki Krogerus | 41adf10 | 2012-02-13 13:24:10 +0200 | [diff] [blame] | 87 | otg->host = NULL; |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 88 | return -ENODEV; |
| 89 | } |
| 90 | |
Heikki Krogerus | 41adf10 | 2012-02-13 13:24:10 +0200 | [diff] [blame] | 91 | otg->host = host; |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 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 | |
Heikki Krogerus | 41adf10 | 2012-02-13 13:24:10 +0200 | [diff] [blame] | 104 | nop->phy.otg = kzalloc(sizeof *nop->phy.otg, GFP_KERNEL); |
| 105 | if (!nop->phy.otg) { |
| 106 | kfree(nop); |
| 107 | return -ENOMEM; |
| 108 | } |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 109 | |
Heikki Krogerus | 41adf10 | 2012-02-13 13:24:10 +0200 | [diff] [blame] | 110 | 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 | |
Kishon Vijay Abraham I | 662dca5 | 2012-06-22 17:02:46 +0530 | [diff] [blame] | 120 | err = usb_add_phy(&nop->phy, USB_PHY_TYPE_USB2); |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 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 | |
Heikki Krogerus | 41adf10 | 2012-02-13 13:24:10 +0200 | [diff] [blame] | 129 | ATOMIC_INIT_NOTIFIER_HEAD(&nop->phy.notifier); |
Ming Lei | 20831ad | 2011-01-04 20:21:32 +0800 | [diff] [blame] | 130 | |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 131 | return 0; |
| 132 | exit: |
Heikki Krogerus | 41adf10 | 2012-02-13 13:24:10 +0200 | [diff] [blame] | 133 | kfree(nop->phy.otg); |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 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 | |
Kishon Vijay Abraham I | 662dca5 | 2012-06-22 17:02:46 +0530 | [diff] [blame] | 142 | usb_remove_phy(&nop->phy); |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 143 | |
| 144 | platform_set_drvdata(pdev, NULL); |
Heikki Krogerus | 41adf10 | 2012-02-13 13:24:10 +0200 | [diff] [blame] | 145 | kfree(nop->phy.otg); |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 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"); |