blob: 3694e450a11a1be32ba3389219fd4c6c0b4d3ec6 [file] [log] [blame]
Greg Kroah-Hartman5fd54ac2017-11-03 11:28:30 +01001// SPDX-License-Identifier: GPL-2.0
Deepak Sikric8c38de2010-11-10 14:33:18 +05302/*
Manjunath Goudar7675d6b2013-04-02 18:24:00 +02003* Driver for EHCI HCD on SPEAr SOC
Deepak Sikric8c38de2010-11-10 14:33:18 +05304*
5* Copyright (C) 2010 ST Micro Electronics,
6* Deepak Sikri <deepak.sikri@st.com>
7*
8* Based on various ehci-*.c drivers
Deepak Sikric8c38de2010-11-10 14:33:18 +05309*/
10
Deepak Sikric8c38de2010-11-10 14:33:18 +053011#include <linux/clk.h>
Manjunath Goudar7675d6b2013-04-02 18:24:00 +020012#include <linux/dma-mapping.h>
13#include <linux/io.h>
Deepak Sikri8c1b3692012-02-24 14:49:31 +053014#include <linux/jiffies.h>
Manjunath Goudar7675d6b2013-04-02 18:24:00 +020015#include <linux/kernel.h>
16#include <linux/module.h>
Stefan Roese56fafb92012-04-16 09:08:08 +053017#include <linux/of.h>
Deepak Sikri8c1b3692012-02-24 14:49:31 +053018#include <linux/platform_device.h>
19#include <linux/pm.h>
Manjunath Goudar7675d6b2013-04-02 18:24:00 +020020#include <linux/usb.h>
21#include <linux/usb/hcd.h>
22
23#include "ehci.h"
24
25#define DRIVER_DESC "EHCI SPEAr driver"
26
27static const char hcd_name[] = "SPEAr-ehci";
Deepak Sikric8c38de2010-11-10 14:33:18 +053028
29struct spear_ehci {
Deepak Sikric8c38de2010-11-10 14:33:18 +053030 struct clk *clk;
31};
32
Manjunath Goudar7675d6b2013-04-02 18:24:00 +020033#define to_spear_ehci(hcd) (struct spear_ehci *)(hcd_to_ehci(hcd)->priv)
Deepak Sikric8c38de2010-11-10 14:33:18 +053034
Manjunath Goudar7675d6b2013-04-02 18:24:00 +020035static struct hc_driver __read_mostly ehci_spear_hc_driver;
Deepak Sikric8c38de2010-11-10 14:33:18 +053036
Paul Cercueil1874b632020-09-03 13:25:36 +020037static int __maybe_unused ehci_spear_drv_suspend(struct device *dev)
Deepak Sikri8c1b3692012-02-24 14:49:31 +053038{
39 struct usb_hcd *hcd = dev_get_drvdata(dev);
Alan Sternc5cf9212012-06-28 11:19:02 -040040 bool do_wakeup = device_may_wakeup(dev);
Deepak Sikri8c1b3692012-02-24 14:49:31 +053041
Alan Sternc5cf9212012-06-28 11:19:02 -040042 return ehci_suspend(hcd, do_wakeup);
Deepak Sikri8c1b3692012-02-24 14:49:31 +053043}
44
Paul Cercueil1874b632020-09-03 13:25:36 +020045static int __maybe_unused ehci_spear_drv_resume(struct device *dev)
Deepak Sikri8c1b3692012-02-24 14:49:31 +053046{
47 struct usb_hcd *hcd = dev_get_drvdata(dev);
Deepak Sikri8c1b3692012-02-24 14:49:31 +053048
Alan Sternc5cf9212012-06-28 11:19:02 -040049 ehci_resume(hcd, false);
Deepak Sikri8c1b3692012-02-24 14:49:31 +053050 return 0;
51}
Deepak Sikri8c1b3692012-02-24 14:49:31 +053052
53static SIMPLE_DEV_PM_OPS(ehci_spear_pm_ops, ehci_spear_drv_suspend,
54 ehci_spear_drv_resume);
55
Deepak Sikric8c38de2010-11-10 14:33:18 +053056static int spear_ehci_hcd_drv_probe(struct platform_device *pdev)
57{
58 struct usb_hcd *hcd ;
Manjunath Goudar7675d6b2013-04-02 18:24:00 +020059 struct spear_ehci *sehci;
Deepak Sikric8c38de2010-11-10 14:33:18 +053060 struct resource *res;
61 struct clk *usbh_clk;
62 const struct hc_driver *driver = &ehci_spear_hc_driver;
Deepak Sikric8c38de2010-11-10 14:33:18 +053063 int irq, retval;
Deepak Sikric8c38de2010-11-10 14:33:18 +053064
65 if (usb_disabled())
66 return -ENODEV;
67
68 irq = platform_get_irq(pdev, 0);
69 if (irq < 0) {
70 retval = irq;
Viresh Kumar98515e52012-11-08 20:37:59 +053071 goto fail;
Deepak Sikric8c38de2010-11-10 14:33:18 +053072 }
73
Stefan Roese56fafb92012-04-16 09:08:08 +053074 /*
75 * Right now device-tree probed devices don't get dma_mask set.
76 * Since shared usb code relies on it, set it here for now.
77 * Once we have dma capability bindings this can go away.
78 */
Russell Kinge1fd7342013-06-27 12:36:37 +010079 retval = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
Russell King22d9d8e2013-06-10 16:28:49 +010080 if (retval)
81 goto fail;
Stefan Roese56fafb92012-04-16 09:08:08 +053082
Viresh Kumar98515e52012-11-08 20:37:59 +053083 usbh_clk = devm_clk_get(&pdev->dev, NULL);
Deepak Sikric8c38de2010-11-10 14:33:18 +053084 if (IS_ERR(usbh_clk)) {
85 dev_err(&pdev->dev, "Error getting interface clock\n");
86 retval = PTR_ERR(usbh_clk);
Viresh Kumar98515e52012-11-08 20:37:59 +053087 goto fail;
Deepak Sikric8c38de2010-11-10 14:33:18 +053088 }
89
90 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
91 if (!hcd) {
92 retval = -ENOMEM;
Viresh Kumar98515e52012-11-08 20:37:59 +053093 goto fail;
Deepak Sikric8c38de2010-11-10 14:33:18 +053094 }
95
96 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Vivek Gautame0f77a92014-05-10 17:30:08 +053097 hcd->regs = devm_ioremap_resource(&pdev->dev, res);
98 if (IS_ERR(hcd->regs)) {
99 retval = PTR_ERR(hcd->regs);
Viresh Kumar98515e52012-11-08 20:37:59 +0530100 goto err_put_hcd;
Deepak Sikric8c38de2010-11-10 14:33:18 +0530101 }
Varka Bhadram3b59d312014-11-04 07:51:26 +0530102 hcd->rsrc_start = res->start;
103 hcd->rsrc_len = resource_size(res);
Deepak Sikric8c38de2010-11-10 14:33:18 +0530104
Manjunath Goudar7675d6b2013-04-02 18:24:00 +0200105 sehci = to_spear_ehci(hcd);
106 sehci->clk = usbh_clk;
Deepak Sikric8c38de2010-11-10 14:33:18 +0530107
Manjunath Goudar7675d6b2013-04-02 18:24:00 +0200108 /* registers start at offset 0x0 */
109 hcd_to_ehci(hcd)->caps = hcd->regs;
110
111 clk_prepare_enable(sehci->clk);
Yong Zhangb5dd18d2011-09-07 16:10:52 +0800112 retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
Deepak Sikric8c38de2010-11-10 14:33:18 +0530113 if (retval)
Viresh Kumar98515e52012-11-08 20:37:59 +0530114 goto err_stop_ehci;
Deepak Sikric8c38de2010-11-10 14:33:18 +0530115
Peter Chen3c9740a2013-11-05 10:46:02 +0800116 device_wakeup_enable(hcd->self.controller);
Deepak Sikric8c38de2010-11-10 14:33:18 +0530117 return retval;
118
Viresh Kumar98515e52012-11-08 20:37:59 +0530119err_stop_ehci:
Manjunath Goudar7675d6b2013-04-02 18:24:00 +0200120 clk_disable_unprepare(sehci->clk);
Viresh Kumar98515e52012-11-08 20:37:59 +0530121err_put_hcd:
Deepak Sikric8c38de2010-11-10 14:33:18 +0530122 usb_put_hcd(hcd);
Viresh Kumar98515e52012-11-08 20:37:59 +0530123fail:
Deepak Sikric8c38de2010-11-10 14:33:18 +0530124 dev_err(&pdev->dev, "init fail, %d\n", retval);
125
126 return retval ;
127}
128
129static int spear_ehci_hcd_drv_remove(struct platform_device *pdev)
130{
131 struct usb_hcd *hcd = platform_get_drvdata(pdev);
Manjunath Goudar7675d6b2013-04-02 18:24:00 +0200132 struct spear_ehci *sehci = to_spear_ehci(hcd);
Deepak Sikric8c38de2010-11-10 14:33:18 +0530133
Deepak Sikric8c38de2010-11-10 14:33:18 +0530134 usb_remove_hcd(hcd);
135
Manjunath Goudar7675d6b2013-04-02 18:24:00 +0200136 if (sehci->clk)
137 clk_disable_unprepare(sehci->clk);
Deepak Sikric8c38de2010-11-10 14:33:18 +0530138 usb_put_hcd(hcd);
139
Deepak Sikric8c38de2010-11-10 14:33:18 +0530140 return 0;
141}
142
Jingoo Han3632eba2014-06-18 13:35:41 +0900143static const struct of_device_id spear_ehci_id_table[] = {
Stefan Roese56fafb92012-04-16 09:08:08 +0530144 { .compatible = "st,spear600-ehci", },
145 { },
146};
Luis de Bethencourte76eaef2015-09-19 14:10:56 +0100147MODULE_DEVICE_TABLE(of, spear_ehci_id_table);
Stefan Roese56fafb92012-04-16 09:08:08 +0530148
Deepak Sikric8c38de2010-11-10 14:33:18 +0530149static struct platform_driver spear_ehci_hcd_driver = {
150 .probe = spear_ehci_hcd_drv_probe,
151 .remove = spear_ehci_hcd_drv_remove,
152 .shutdown = usb_hcd_platform_shutdown,
153 .driver = {
154 .name = "spear-ehci",
Deepak Sikri8c1b3692012-02-24 14:49:31 +0530155 .bus = &platform_bus_type,
Paul Cercueil1874b632020-09-03 13:25:36 +0200156 .pm = pm_ptr(&ehci_spear_pm_ops),
Sachin Kamat2c398f32013-05-21 17:17:17 +0530157 .of_match_table = spear_ehci_id_table,
Deepak Sikric8c38de2010-11-10 14:33:18 +0530158 }
159};
160
Nicolas Pitreedc8c542016-04-27 13:28:32 -0400161static const struct ehci_driver_overrides spear_overrides __initconst = {
Manjunath Goudar7675d6b2013-04-02 18:24:00 +0200162 .extra_priv_size = sizeof(struct spear_ehci),
163};
164
165static int __init ehci_spear_init(void)
166{
167 if (usb_disabled())
168 return -ENODEV;
169
170 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
171
172 ehci_init_driver(&ehci_spear_hc_driver, &spear_overrides);
173 return platform_driver_register(&spear_ehci_hcd_driver);
174}
175module_init(ehci_spear_init);
176
177static void __exit ehci_spear_cleanup(void)
178{
179 platform_driver_unregister(&spear_ehci_hcd_driver);
180}
181module_exit(ehci_spear_cleanup);
182
183MODULE_DESCRIPTION(DRIVER_DESC);
Deepak Sikric8c38de2010-11-10 14:33:18 +0530184MODULE_ALIAS("platform:spear-ehci");
Manjunath Goudar7675d6b2013-04-02 18:24:00 +0200185MODULE_AUTHOR("Deepak Sikri");
186MODULE_LICENSE("GPL");