Daniel Mack | 7e8d5cd | 2009-10-28 01:14:59 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2008 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix |
| 3 | * Copyright (c) 2009 Daniel Mack <daniel@caiaq.de> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License as published by the |
| 7 | * Free Software Foundation; either version 2 of the License, or (at your |
| 8 | * option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 12 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 13 | * for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software Foundation, |
| 17 | * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 18 | */ |
| 19 | |
Alan Stern | dba63b2 | 2013-01-23 13:26:15 -0500 | [diff] [blame] | 20 | #include <linux/kernel.h> |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/io.h> |
Daniel Mack | 7e8d5cd | 2009-10-28 01:14:59 +0100 | [diff] [blame] | 23 | #include <linux/platform_device.h> |
| 24 | #include <linux/clk.h> |
| 25 | #include <linux/delay.h> |
| 26 | #include <linux/usb/otg.h> |
Arnaud Patard (Rtp) | a464dc4 | 2011-01-18 00:04:12 +0100 | [diff] [blame] | 27 | #include <linux/usb/ulpi.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 28 | #include <linux/slab.h> |
Alan Stern | dba63b2 | 2013-01-23 13:26:15 -0500 | [diff] [blame] | 29 | #include <linux/usb.h> |
| 30 | #include <linux/usb/hcd.h> |
Arnd Bergmann | 82906b1 | 2012-08-24 15:14:29 +0200 | [diff] [blame] | 31 | #include <linux/platform_data/usb-ehci-mxc.h> |
Alan Stern | dba63b2 | 2013-01-23 13:26:15 -0500 | [diff] [blame] | 32 | #include "ehci.h" |
| 33 | |
| 34 | #define DRIVER_DESC "Freescale On-Chip EHCI Host driver" |
| 35 | |
| 36 | static const char hcd_name[] = "ehci-mxc"; |
| 37 | |
Daniel Mack | 7e8d5cd | 2009-10-28 01:14:59 +0100 | [diff] [blame] | 38 | #define ULPI_VIEWPORT_OFFSET 0x170 |
Daniel Mack | 7e8d5cd | 2009-10-28 01:14:59 +0100 | [diff] [blame] | 39 | |
| 40 | struct ehci_mxc_priv { |
Sascha Hauer | c943740 | 2012-04-25 16:39:06 +0200 | [diff] [blame] | 41 | struct clk *usbclk, *ahbclk, *phyclk; |
Daniel Mack | 7e8d5cd | 2009-10-28 01:14:59 +0100 | [diff] [blame] | 42 | }; |
| 43 | |
Alan Stern | dba63b2 | 2013-01-23 13:26:15 -0500 | [diff] [blame] | 44 | static struct hc_driver __read_mostly ehci_mxc_hc_driver; |
Matthieu CASTET | 65fd427 | 2010-09-06 18:26:56 +0200 | [diff] [blame] | 45 | |
Andi Kleen | 62d08a1 | 2013-04-22 09:44:56 -0700 | [diff] [blame] | 46 | static const struct ehci_driver_overrides ehci_mxc_overrides __initconst = { |
Alan Stern | dba63b2 | 2013-01-23 13:26:15 -0500 | [diff] [blame] | 47 | .extra_priv_size = sizeof(struct ehci_mxc_priv), |
Daniel Mack | 7e8d5cd | 2009-10-28 01:14:59 +0100 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | static int ehci_mxc_drv_probe(struct platform_device *pdev) |
| 51 | { |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 52 | struct mxc_usbh_platform_data *pdata = dev_get_platdata(&pdev->dev); |
Daniel Mack | 7e8d5cd | 2009-10-28 01:14:59 +0100 | [diff] [blame] | 53 | struct usb_hcd *hcd; |
| 54 | struct resource *res; |
Uwe Kleine-König | 724c852 | 2010-11-02 10:30:57 +0100 | [diff] [blame] | 55 | int irq, ret; |
Daniel Mack | 7e8d5cd | 2009-10-28 01:14:59 +0100 | [diff] [blame] | 56 | struct ehci_mxc_priv *priv; |
| 57 | struct device *dev = &pdev->dev; |
Fabio Estevam | 0247a7b | 2010-12-15 22:31:28 -0200 | [diff] [blame] | 58 | struct ehci_hcd *ehci; |
Daniel Mack | 7e8d5cd | 2009-10-28 01:14:59 +0100 | [diff] [blame] | 59 | |
Daniel Mack | 7e8d5cd | 2009-10-28 01:14:59 +0100 | [diff] [blame] | 60 | if (!pdata) { |
| 61 | dev_err(dev, "No platform data given, bailing out.\n"); |
| 62 | return -EINVAL; |
| 63 | } |
| 64 | |
| 65 | irq = platform_get_irq(pdev, 0); |
| 66 | |
| 67 | hcd = usb_create_hcd(&ehci_mxc_hc_driver, dev, dev_name(dev)); |
| 68 | if (!hcd) |
| 69 | return -ENOMEM; |
| 70 | |
Daniel Mack | 7e8d5cd | 2009-10-28 01:14:59 +0100 | [diff] [blame] | 71 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Thierry Reding | 148e113 | 2013-01-21 11:09:22 +0100 | [diff] [blame] | 72 | hcd->regs = devm_ioremap_resource(&pdev->dev, res); |
| 73 | if (IS_ERR(hcd->regs)) { |
| 74 | ret = PTR_ERR(hcd->regs); |
Julia Lawall | af09c06 | 2012-07-29 21:46:13 +0200 | [diff] [blame] | 75 | goto err_alloc; |
Daniel Mack | 7e8d5cd | 2009-10-28 01:14:59 +0100 | [diff] [blame] | 76 | } |
Varka Bhadram | d6e269a | 2014-11-04 07:51:22 +0530 | [diff] [blame] | 77 | hcd->rsrc_start = res->start; |
| 78 | hcd->rsrc_len = resource_size(res); |
Daniel Mack | 7e8d5cd | 2009-10-28 01:14:59 +0100 | [diff] [blame] | 79 | |
Alan Stern | dba63b2 | 2013-01-23 13:26:15 -0500 | [diff] [blame] | 80 | hcd->has_tt = 1; |
| 81 | ehci = hcd_to_ehci(hcd); |
| 82 | priv = (struct ehci_mxc_priv *) ehci->priv; |
| 83 | |
Daniel Mack | 7e8d5cd | 2009-10-28 01:14:59 +0100 | [diff] [blame] | 84 | /* enable clocks */ |
Julia Lawall | af09c06 | 2012-07-29 21:46:13 +0200 | [diff] [blame] | 85 | priv->usbclk = devm_clk_get(&pdev->dev, "ipg"); |
Daniel Mack | 7e8d5cd | 2009-10-28 01:14:59 +0100 | [diff] [blame] | 86 | if (IS_ERR(priv->usbclk)) { |
| 87 | ret = PTR_ERR(priv->usbclk); |
Julia Lawall | af09c06 | 2012-07-29 21:46:13 +0200 | [diff] [blame] | 88 | goto err_alloc; |
Daniel Mack | 7e8d5cd | 2009-10-28 01:14:59 +0100 | [diff] [blame] | 89 | } |
Sascha Hauer | 198ad2c | 2012-03-07 20:58:21 +0100 | [diff] [blame] | 90 | clk_prepare_enable(priv->usbclk); |
Daniel Mack | 7e8d5cd | 2009-10-28 01:14:59 +0100 | [diff] [blame] | 91 | |
Julia Lawall | af09c06 | 2012-07-29 21:46:13 +0200 | [diff] [blame] | 92 | priv->ahbclk = devm_clk_get(&pdev->dev, "ahb"); |
Sascha Hauer | c943740 | 2012-04-25 16:39:06 +0200 | [diff] [blame] | 93 | if (IS_ERR(priv->ahbclk)) { |
| 94 | ret = PTR_ERR(priv->ahbclk); |
| 95 | goto err_clk_ahb; |
Daniel Mack | 7e8d5cd | 2009-10-28 01:14:59 +0100 | [diff] [blame] | 96 | } |
Sascha Hauer | c943740 | 2012-04-25 16:39:06 +0200 | [diff] [blame] | 97 | clk_prepare_enable(priv->ahbclk); |
Daniel Mack | 7e8d5cd | 2009-10-28 01:14:59 +0100 | [diff] [blame] | 98 | |
Eric Bénard | 3bb8029 | 2011-01-13 14:53:17 +0100 | [diff] [blame] | 99 | /* "dr" device has its own clock on i.MX51 */ |
Julia Lawall | af09c06 | 2012-07-29 21:46:13 +0200 | [diff] [blame] | 100 | priv->phyclk = devm_clk_get(&pdev->dev, "phy"); |
Sascha Hauer | c943740 | 2012-04-25 16:39:06 +0200 | [diff] [blame] | 101 | if (IS_ERR(priv->phyclk)) |
| 102 | priv->phyclk = NULL; |
| 103 | if (priv->phyclk) |
| 104 | clk_prepare_enable(priv->phyclk); |
Arnaud Patard (Rtp) | 711669e | 2010-12-20 16:48:58 +0100 | [diff] [blame] | 105 | |
| 106 | |
| 107 | /* call platform specific init function */ |
| 108 | if (pdata->init) { |
| 109 | ret = pdata->init(pdev); |
| 110 | if (ret) { |
| 111 | dev_err(dev, "platform init failed\n"); |
| 112 | goto err_init; |
| 113 | } |
| 114 | /* platforms need some time to settle changed IO settings */ |
| 115 | mdelay(10); |
| 116 | } |
| 117 | |
Fabio Estevam | 0247a7b | 2010-12-15 22:31:28 -0200 | [diff] [blame] | 118 | /* EHCI registers start at offset 0x100 */ |
| 119 | ehci->caps = hcd->regs + 0x100; |
| 120 | ehci->regs = hcd->regs + 0x100 + |
Jan Andersson | c430131 | 2011-05-03 20:11:57 +0200 | [diff] [blame] | 121 | HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase)); |
Fabio Estevam | 0247a7b | 2010-12-15 22:31:28 -0200 | [diff] [blame] | 122 | |
| 123 | /* set up the PORTSCx register */ |
| 124 | ehci_writel(ehci, pdata->portsc, &ehci->regs->port_status[0]); |
| 125 | |
| 126 | /* is this really needed? */ |
| 127 | msleep(10); |
| 128 | |
Daniel Mack | 7e8d5cd | 2009-10-28 01:14:59 +0100 | [diff] [blame] | 129 | /* Initialize the transceiver */ |
| 130 | if (pdata->otg) { |
| 131 | pdata->otg->io_priv = hcd->regs + ULPI_VIEWPORT_OFFSET; |
Heikki Krogerus | b96d3b0 | 2012-02-13 13:24:18 +0200 | [diff] [blame] | 132 | ret = usb_phy_init(pdata->otg); |
Wolfram Sang | 4c9715d | 2010-06-15 12:34:23 +0200 | [diff] [blame] | 133 | if (ret) { |
| 134 | dev_err(dev, "unable to init transceiver, probably missing\n"); |
| 135 | ret = -ENODEV; |
| 136 | goto err_add; |
| 137 | } |
Heikki Krogerus | 6e13c65 | 2012-02-13 13:24:20 +0200 | [diff] [blame] | 138 | ret = otg_set_vbus(pdata->otg->otg, 1); |
Wolfram Sang | 4c9715d | 2010-06-15 12:34:23 +0200 | [diff] [blame] | 139 | if (ret) { |
Daniel Mack | 7e8d5cd | 2009-10-28 01:14:59 +0100 | [diff] [blame] | 140 | dev_err(dev, "unable to enable vbus on transceiver\n"); |
Wolfram Sang | 4c9715d | 2010-06-15 12:34:23 +0200 | [diff] [blame] | 141 | goto err_add; |
| 142 | } |
Daniel Mack | 7e8d5cd | 2009-10-28 01:14:59 +0100 | [diff] [blame] | 143 | } |
| 144 | |
Alan Stern | dba63b2 | 2013-01-23 13:26:15 -0500 | [diff] [blame] | 145 | platform_set_drvdata(pdev, hcd); |
Daniel Mack | 7e8d5cd | 2009-10-28 01:14:59 +0100 | [diff] [blame] | 146 | |
Yong Zhang | b5dd18d | 2011-09-07 16:10:52 +0800 | [diff] [blame] | 147 | ret = usb_add_hcd(hcd, irq, IRQF_SHARED); |
Daniel Mack | 7e8d5cd | 2009-10-28 01:14:59 +0100 | [diff] [blame] | 148 | if (ret) |
| 149 | goto err_add; |
| 150 | |
Peter Chen | 3c9740a | 2013-11-05 10:46:02 +0800 | [diff] [blame] | 151 | device_wakeup_enable(hcd->self.controller); |
Daniel Mack | 7e8d5cd | 2009-10-28 01:14:59 +0100 | [diff] [blame] | 152 | return 0; |
| 153 | |
| 154 | err_add: |
| 155 | if (pdata && pdata->exit) |
| 156 | pdata->exit(pdev); |
| 157 | err_init: |
Julia Lawall | af09c06 | 2012-07-29 21:46:13 +0200 | [diff] [blame] | 158 | if (priv->phyclk) |
Sascha Hauer | c943740 | 2012-04-25 16:39:06 +0200 | [diff] [blame] | 159 | clk_disable_unprepare(priv->phyclk); |
Sascha Hauer | c943740 | 2012-04-25 16:39:06 +0200 | [diff] [blame] | 160 | |
| 161 | clk_disable_unprepare(priv->ahbclk); |
Daniel Mack | 7e8d5cd | 2009-10-28 01:14:59 +0100 | [diff] [blame] | 162 | err_clk_ahb: |
Sascha Hauer | 198ad2c | 2012-03-07 20:58:21 +0100 | [diff] [blame] | 163 | clk_disable_unprepare(priv->usbclk); |
Daniel Mack | 7e8d5cd | 2009-10-28 01:14:59 +0100 | [diff] [blame] | 164 | err_alloc: |
| 165 | usb_put_hcd(hcd); |
| 166 | return ret; |
| 167 | } |
| 168 | |
Dmitry Torokhov | 39d3568 | 2013-02-24 00:55:07 -0800 | [diff] [blame] | 169 | static int ehci_mxc_drv_remove(struct platform_device *pdev) |
Daniel Mack | 7e8d5cd | 2009-10-28 01:14:59 +0100 | [diff] [blame] | 170 | { |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 171 | struct mxc_usbh_platform_data *pdata = dev_get_platdata(&pdev->dev); |
Alan Stern | dba63b2 | 2013-01-23 13:26:15 -0500 | [diff] [blame] | 172 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 173 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
| 174 | struct ehci_mxc_priv *priv = (struct ehci_mxc_priv *) ehci->priv; |
| 175 | |
| 176 | usb_remove_hcd(hcd); |
Daniel Mack | 7e8d5cd | 2009-10-28 01:14:59 +0100 | [diff] [blame] | 177 | |
| 178 | if (pdata && pdata->exit) |
| 179 | pdata->exit(pdev); |
| 180 | |
Daniel Mack | f375fc5 | 2013-08-21 11:17:21 +0200 | [diff] [blame] | 181 | if (pdata && pdata->otg) |
Heikki Krogerus | b96d3b0 | 2012-02-13 13:24:18 +0200 | [diff] [blame] | 182 | usb_phy_shutdown(pdata->otg); |
Daniel Mack | 7e8d5cd | 2009-10-28 01:14:59 +0100 | [diff] [blame] | 183 | |
Sascha Hauer | 198ad2c | 2012-03-07 20:58:21 +0100 | [diff] [blame] | 184 | clk_disable_unprepare(priv->usbclk); |
Sascha Hauer | c943740 | 2012-04-25 16:39:06 +0200 | [diff] [blame] | 185 | clk_disable_unprepare(priv->ahbclk); |
Sascha Hauer | c943740 | 2012-04-25 16:39:06 +0200 | [diff] [blame] | 186 | |
Julia Lawall | af09c06 | 2012-07-29 21:46:13 +0200 | [diff] [blame] | 187 | if (priv->phyclk) |
Sascha Hauer | c943740 | 2012-04-25 16:39:06 +0200 | [diff] [blame] | 188 | clk_disable_unprepare(priv->phyclk); |
Daniel Mack | 7e8d5cd | 2009-10-28 01:14:59 +0100 | [diff] [blame] | 189 | |
Alan Stern | dba63b2 | 2013-01-23 13:26:15 -0500 | [diff] [blame] | 190 | usb_put_hcd(hcd); |
Daniel Mack | 7e8d5cd | 2009-10-28 01:14:59 +0100 | [diff] [blame] | 191 | return 0; |
| 192 | } |
| 193 | |
Daniel Mack | 7e8d5cd | 2009-10-28 01:14:59 +0100 | [diff] [blame] | 194 | MODULE_ALIAS("platform:mxc-ehci"); |
| 195 | |
| 196 | static struct platform_driver ehci_mxc_driver = { |
| 197 | .probe = ehci_mxc_drv_probe, |
Alan Stern | dba63b2 | 2013-01-23 13:26:15 -0500 | [diff] [blame] | 198 | .remove = ehci_mxc_drv_remove, |
Roger Quadros | aaf6b52 | 2013-07-22 15:04:50 +0300 | [diff] [blame] | 199 | .shutdown = usb_hcd_platform_shutdown, |
Daniel Mack | 7e8d5cd | 2009-10-28 01:14:59 +0100 | [diff] [blame] | 200 | .driver = { |
| 201 | .name = "mxc-ehci", |
| 202 | }, |
| 203 | }; |
Alan Stern | dba63b2 | 2013-01-23 13:26:15 -0500 | [diff] [blame] | 204 | |
| 205 | static int __init ehci_mxc_init(void) |
| 206 | { |
| 207 | if (usb_disabled()) |
| 208 | return -ENODEV; |
| 209 | |
| 210 | pr_info("%s: " DRIVER_DESC "\n", hcd_name); |
| 211 | |
| 212 | ehci_init_driver(&ehci_mxc_hc_driver, &ehci_mxc_overrides); |
| 213 | return platform_driver_register(&ehci_mxc_driver); |
| 214 | } |
| 215 | module_init(ehci_mxc_init); |
| 216 | |
| 217 | static void __exit ehci_mxc_cleanup(void) |
| 218 | { |
| 219 | platform_driver_unregister(&ehci_mxc_driver); |
| 220 | } |
| 221 | module_exit(ehci_mxc_cleanup); |
| 222 | |
| 223 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 224 | MODULE_AUTHOR("Sascha Hauer"); |
| 225 | MODULE_LICENSE("GPL"); |