aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/musb
diff options
context:
space:
mode:
authorApelete Seketeli <apelete@seketeli.net>2013-12-19 15:42:26 -0500
committerFelipe Balbi <balbi@ti.com>2013-12-20 10:53:24 -0500
commit10434d273ccdcee8eab4f5e08497d65841bbf354 (patch)
tree754d7bd7ec4e195584c45546f2c600eca3fa886a /drivers/usb/musb
parent5b022849c84d426a2a365d916b5015b3bf6ad9db (diff)
usb: musb: add support for JZ4740 usb device controller
Add support for Ingenic JZ4740 USB Device Controller through a specific musb glue layer. JZ4740 UDC not being OTG compatible and missing some hardware registers, this musb glue layer is written from scratch to be used in gadget mode only and take silicon design specifics into account. Signed-off-by: Apelete Seketeli <apelete@seketeli.net> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb/musb')
-rw-r--r--drivers/usb/musb/Kconfig8
-rw-r--r--drivers/usb/musb/Makefile1
-rw-r--r--drivers/usb/musb/jz4740.c201
3 files changed, 209 insertions, 1 deletions
diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
index 57dfc0cedb00..14d7e725c2ff 100644
--- a/drivers/usb/musb/Kconfig
+++ b/drivers/usb/musb/Kconfig
@@ -93,6 +93,12 @@ config USB_MUSB_BLACKFIN
93config USB_MUSB_UX500 93config USB_MUSB_UX500
94 tristate "Ux500 platforms" 94 tristate "Ux500 platforms"
95 95
96config USB_MUSB_JZ4740
97 tristate "JZ4740"
98 depends on MACH_JZ4740 || COMPILE_TEST
99 depends on USB_MUSB_GADGET
100 depends on USB_OTG_BLACKLIST_HUB
101
96endchoice 102endchoice
97 103
98config USB_MUSB_AM335X_CHILD 104config USB_MUSB_AM335X_CHILD
@@ -100,7 +106,7 @@ config USB_MUSB_AM335X_CHILD
100 106
101choice 107choice
102 prompt 'MUSB DMA mode' 108 prompt 'MUSB DMA mode'
103 default MUSB_PIO_ONLY if ARCH_MULTIPLATFORM 109 default MUSB_PIO_ONLY if ARCH_MULTIPLATFORM || USB_MUSB_JZ4740
104 default USB_UX500_DMA if USB_MUSB_UX500 110 default USB_UX500_DMA if USB_MUSB_UX500
105 default USB_INVENTRA_DMA if USB_MUSB_OMAP2PLUS || USB_MUSB_BLACKFIN 111 default USB_INVENTRA_DMA if USB_MUSB_OMAP2PLUS || USB_MUSB_BLACKFIN
106 default USB_TI_CPPI_DMA if USB_MUSB_DAVINCI 112 default USB_TI_CPPI_DMA if USB_MUSB_DAVINCI
diff --git a/drivers/usb/musb/Makefile b/drivers/usb/musb/Makefile
index c5ea5c6dc169..ba495018b416 100644
--- a/drivers/usb/musb/Makefile
+++ b/drivers/usb/musb/Makefile
@@ -19,6 +19,7 @@ obj-$(CONFIG_USB_MUSB_DAVINCI) += davinci.o
19obj-$(CONFIG_USB_MUSB_DA8XX) += da8xx.o 19obj-$(CONFIG_USB_MUSB_DA8XX) += da8xx.o
20obj-$(CONFIG_USB_MUSB_BLACKFIN) += blackfin.o 20obj-$(CONFIG_USB_MUSB_BLACKFIN) += blackfin.o
21obj-$(CONFIG_USB_MUSB_UX500) += ux500.o 21obj-$(CONFIG_USB_MUSB_UX500) += ux500.o
22obj-$(CONFIG_USB_MUSB_JZ4740) += jz4740.o
22 23
23 24
24obj-$(CONFIG_USB_MUSB_AM335X_CHILD) += musb_am335x.o 25obj-$(CONFIG_USB_MUSB_AM335X_CHILD) += musb_am335x.o
diff --git a/drivers/usb/musb/jz4740.c b/drivers/usb/musb/jz4740.c
new file mode 100644
index 000000000000..5f30537f1927
--- /dev/null
+++ b/drivers/usb/musb/jz4740.c
@@ -0,0 +1,201 @@
1/*
2 * Ingenic JZ4740 "glue layer"
3 *
4 * Copyright (C) 2013, Apelete Seketeli <apelete@seketeli.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * You should have received a copy of the GNU General Public License along
12 * with this program; if not, write to the Free Software Foundation, Inc.,
13 * 675 Mass Ave, Cambridge, MA 02139, USA.
14 */
15
16#include <linux/clk.h>
17#include <linux/dma-mapping.h>
18#include <linux/errno.h>
19#include <linux/kernel.h>
20#include <linux/module.h>
21#include <linux/platform_device.h>
22
23#include "musb_core.h"
24
25struct jz4740_glue {
26 struct device *dev;
27 struct platform_device *musb;
28 struct clk *clk;
29};
30
31static irqreturn_t jz4740_musb_interrupt(int irq, void *__hci)
32{
33 unsigned long flags;
34 irqreturn_t retval = IRQ_NONE;
35 struct musb *musb = __hci;
36
37 spin_lock_irqsave(&musb->lock, flags);
38
39 musb->int_usb = musb_readb(musb->mregs, MUSB_INTRUSB);
40 musb->int_tx = musb_readw(musb->mregs, MUSB_INTRTX);
41 musb->int_rx = musb_readw(musb->mregs, MUSB_INTRRX);
42
43 /*
44 * The controller is gadget only, the state of the host mode IRQ bits is
45 * undefined. Mask them to make sure that the musb driver core will
46 * never see them set
47 */
48 musb->int_usb &= MUSB_INTR_SUSPEND | MUSB_INTR_RESUME |
49 MUSB_INTR_RESET | MUSB_INTR_SOF;
50
51 if (musb->int_usb || musb->int_tx || musb->int_rx)
52 retval = musb_interrupt(musb);
53
54 spin_unlock_irqrestore(&musb->lock, flags);
55
56 return retval;
57}
58
59static struct musb_fifo_cfg jz4740_musb_fifo_cfg[] = {
60{ .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, },
61{ .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, },
62{ .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 64, },
63};
64
65static struct musb_hdrc_config jz4740_musb_config = {
66 /* Silicon does not implement USB OTG. */
67 .multipoint = 0,
68 /* Max EPs scanned, driver will decide which EP can be used. */
69 .num_eps = 4,
70 /* RAMbits needed to configure EPs from table */
71 .ram_bits = 9,
72 .fifo_cfg = jz4740_musb_fifo_cfg,
73 .fifo_cfg_size = ARRAY_SIZE(jz4740_musb_fifo_cfg),
74};
75
76static struct musb_hdrc_platform_data jz4740_musb_platform_data = {
77 .mode = MUSB_PERIPHERAL,
78 .config = &jz4740_musb_config,
79};
80
81static int jz4740_musb_init(struct musb *musb)
82{
83 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
84 if (!musb->xceiv) {
85 pr_err("HS UDC: no transceiver configured\n");
86 return -ENODEV;
87 }
88
89 /* Silicon does not implement ConfigData register.
90 * Set dyn_fifo to avoid reading EP config from hardware.
91 */
92 musb->dyn_fifo = true;
93
94 musb->isr = jz4740_musb_interrupt;
95
96 return 0;
97}
98
99static int jz4740_musb_exit(struct musb *musb)
100{
101 usb_put_phy(musb->xceiv);
102
103 return 0;
104}
105
106static const struct musb_platform_ops jz4740_musb_ops = {
107 .init = jz4740_musb_init,
108 .exit = jz4740_musb_exit,
109};
110
111static int jz4740_probe(struct platform_device *pdev)
112{
113 struct musb_hdrc_platform_data *pdata = &jz4740_musb_platform_data;
114 struct platform_device *musb;
115 struct jz4740_glue *glue;
116 struct clk *clk;
117 int ret;
118
119 glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL);
120 if (!glue)
121 return -ENOMEM;
122
123 musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO);
124 if (!musb) {
125 dev_err(&pdev->dev, "failed to allocate musb device\n");
126 return -ENOMEM;
127 }
128
129 clk = devm_clk_get(&pdev->dev, "udc");
130 if (IS_ERR(clk)) {
131 dev_err(&pdev->dev, "failed to get clock\n");
132 ret = PTR_ERR(clk);
133 goto err_platform_device_put;
134 }
135
136 ret = clk_prepare_enable(clk);
137 if (ret) {
138 dev_err(&pdev->dev, "failed to enable clock\n");
139 goto err_platform_device_put;
140 }
141
142 musb->dev.parent = &pdev->dev;
143
144 glue->dev = &pdev->dev;
145 glue->musb = musb;
146 glue->clk = clk;
147
148 pdata->platform_ops = &jz4740_musb_ops;
149
150 platform_set_drvdata(pdev, glue);
151
152 ret = platform_device_add_resources(musb, pdev->resource,
153 pdev->num_resources);
154 if (ret) {
155 dev_err(&pdev->dev, "failed to add resources\n");
156 goto err_clk_disable;
157 }
158
159 ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
160 if (ret) {
161 dev_err(&pdev->dev, "failed to add platform_data\n");
162 goto err_clk_disable;
163 }
164
165 ret = platform_device_add(musb);
166 if (ret) {
167 dev_err(&pdev->dev, "failed to register musb device\n");
168 goto err_clk_disable;
169 }
170
171 return 0;
172
173err_clk_disable:
174 clk_disable_unprepare(clk);
175err_platform_device_put:
176 platform_device_put(musb);
177 return ret;
178}
179
180static int jz4740_remove(struct platform_device *pdev)
181{
182 struct jz4740_glue *glue = platform_get_drvdata(pdev);
183
184 platform_device_unregister(glue->musb);
185 clk_disable_unprepare(glue->clk);
186
187 return 0;
188}
189
190static struct platform_driver jz4740_driver = {
191 .probe = jz4740_probe,
192 .remove = jz4740_remove,
193 .driver = {
194 .name = "musb-jz4740",
195 },
196};
197
198MODULE_DESCRIPTION("JZ4740 MUSB Glue Layer");
199MODULE_AUTHOR("Apelete Seketeli <apelete@seketeli.net>");
200MODULE_LICENSE("GPL v2");
201module_platform_driver(jz4740_driver);