mmc: rtsx_pci: Enable MMC_CAP_ERASE to allow erase/discard/trim requests
[linux/fpc-iii.git] / drivers / usb / dwc3 / dwc3-keystone.c
blob72664700b8a25c7d9bcee89c16c68fa6b5792565
1 /**
2 * dwc3-keystone.c - Keystone Specific Glue layer
4 * Copyright (C) 2010-2013 Texas Instruments Incorporated - http://www.ti.com
6 * Author: WingMan Kwok <w-kwok2@ti.com>
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 of
10 * the License as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
18 #include <linux/clk.h>
19 #include <linux/module.h>
20 #include <linux/kernel.h>
21 #include <linux/interrupt.h>
22 #include <linux/platform_device.h>
23 #include <linux/dma-mapping.h>
24 #include <linux/io.h>
25 #include <linux/of_platform.h>
27 /* USBSS register offsets */
28 #define USBSS_REVISION 0x0000
29 #define USBSS_SYSCONFIG 0x0010
30 #define USBSS_IRQ_EOI 0x0018
31 #define USBSS_IRQSTATUS_RAW_0 0x0020
32 #define USBSS_IRQSTATUS_0 0x0024
33 #define USBSS_IRQENABLE_SET_0 0x0028
34 #define USBSS_IRQENABLE_CLR_0 0x002c
36 /* IRQ register bits */
37 #define USBSS_IRQ_EOI_LINE(n) BIT(n)
38 #define USBSS_IRQ_EVENT_ST BIT(0)
39 #define USBSS_IRQ_COREIRQ_EN BIT(0)
40 #define USBSS_IRQ_COREIRQ_CLR BIT(0)
42 struct dwc3_keystone {
43 struct device *dev;
44 struct clk *clk;
45 void __iomem *usbss;
48 static inline u32 kdwc3_readl(void __iomem *base, u32 offset)
50 return readl(base + offset);
53 static inline void kdwc3_writel(void __iomem *base, u32 offset, u32 value)
55 writel(value, base + offset);
58 static void kdwc3_enable_irqs(struct dwc3_keystone *kdwc)
60 u32 val;
62 val = kdwc3_readl(kdwc->usbss, USBSS_IRQENABLE_SET_0);
63 val |= USBSS_IRQ_COREIRQ_EN;
64 kdwc3_writel(kdwc->usbss, USBSS_IRQENABLE_SET_0, val);
67 static void kdwc3_disable_irqs(struct dwc3_keystone *kdwc)
69 u32 val;
71 val = kdwc3_readl(kdwc->usbss, USBSS_IRQENABLE_SET_0);
72 val &= ~USBSS_IRQ_COREIRQ_EN;
73 kdwc3_writel(kdwc->usbss, USBSS_IRQENABLE_SET_0, val);
76 static irqreturn_t dwc3_keystone_interrupt(int irq, void *_kdwc)
78 struct dwc3_keystone *kdwc = _kdwc;
80 kdwc3_writel(kdwc->usbss, USBSS_IRQENABLE_CLR_0, USBSS_IRQ_COREIRQ_CLR);
81 kdwc3_writel(kdwc->usbss, USBSS_IRQSTATUS_0, USBSS_IRQ_EVENT_ST);
82 kdwc3_writel(kdwc->usbss, USBSS_IRQENABLE_SET_0, USBSS_IRQ_COREIRQ_EN);
83 kdwc3_writel(kdwc->usbss, USBSS_IRQ_EOI, USBSS_IRQ_EOI_LINE(0));
85 return IRQ_HANDLED;
88 static int kdwc3_probe(struct platform_device *pdev)
90 struct device *dev = &pdev->dev;
91 struct device_node *node = pdev->dev.of_node;
92 struct dwc3_keystone *kdwc;
93 struct resource *res;
94 int error, irq;
96 kdwc = devm_kzalloc(dev, sizeof(*kdwc), GFP_KERNEL);
97 if (!kdwc)
98 return -ENOMEM;
100 platform_set_drvdata(pdev, kdwc);
102 kdwc->dev = dev;
104 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
105 kdwc->usbss = devm_ioremap_resource(dev, res);
106 if (IS_ERR(kdwc->usbss))
107 return PTR_ERR(kdwc->usbss);
109 kdwc->clk = devm_clk_get(kdwc->dev, "usb");
111 error = clk_prepare_enable(kdwc->clk);
112 if (error < 0) {
113 dev_err(kdwc->dev, "unable to enable usb clock, error %d\n",
114 error);
115 return error;
118 irq = platform_get_irq(pdev, 0);
119 if (irq < 0) {
120 dev_err(&pdev->dev, "missing irq\n");
121 error = irq;
122 goto err_irq;
125 error = devm_request_irq(dev, irq, dwc3_keystone_interrupt, IRQF_SHARED,
126 dev_name(dev), kdwc);
127 if (error) {
128 dev_err(dev, "failed to request IRQ #%d --> %d\n",
129 irq, error);
130 goto err_irq;
133 kdwc3_enable_irqs(kdwc);
135 error = of_platform_populate(node, NULL, NULL, dev);
136 if (error) {
137 dev_err(&pdev->dev, "failed to create dwc3 core\n");
138 goto err_core;
141 return 0;
143 err_core:
144 kdwc3_disable_irqs(kdwc);
145 err_irq:
146 clk_disable_unprepare(kdwc->clk);
148 return error;
151 static int kdwc3_remove_core(struct device *dev, void *c)
153 struct platform_device *pdev = to_platform_device(dev);
155 platform_device_unregister(pdev);
157 return 0;
160 static int kdwc3_remove(struct platform_device *pdev)
162 struct dwc3_keystone *kdwc = platform_get_drvdata(pdev);
164 kdwc3_disable_irqs(kdwc);
165 device_for_each_child(&pdev->dev, NULL, kdwc3_remove_core);
166 clk_disable_unprepare(kdwc->clk);
167 platform_set_drvdata(pdev, NULL);
169 return 0;
172 static const struct of_device_id kdwc3_of_match[] = {
173 { .compatible = "ti,keystone-dwc3", },
176 MODULE_DEVICE_TABLE(of, kdwc3_of_match);
178 static struct platform_driver kdwc3_driver = {
179 .probe = kdwc3_probe,
180 .remove = kdwc3_remove,
181 .driver = {
182 .name = "keystone-dwc3",
183 .of_match_table = kdwc3_of_match,
187 module_platform_driver(kdwc3_driver);
189 MODULE_ALIAS("platform:keystone-dwc3");
190 MODULE_AUTHOR("WingMan Kwok <w-kwok2@ti.com>");
191 MODULE_LICENSE("GPL v2");
192 MODULE_DESCRIPTION("DesignWare USB3 KEYSTONE Glue Layer");