Date: | 2013-05-21 22:56:12 (10 years 11 days ago) |
---|---|
Author: | Apelete Seketeli |
Commit: | 708f4c01e4b5fdc7b44e0eeb6c342e770b9a8fcb |
Message: | usb: musb: add support for JZ4740 usb device controller Add support for Ingenic JZ4740 USB Device Controller through a specific musb glue layer. The platform data already available in tree for that USB Device Controller was previously used by an out-of-tree USB gadget driver which was not relying on the musb driver and was written by Ingenic and the Qi-Hardware community. 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> |
Files: |
arch/mips/include/asm/mach-jz4740/platform.h (1 diff) arch/mips/jz4740/board-qi_lb60.c (1 diff) arch/mips/jz4740/platform.c (2 diffs) drivers/usb/musb/Kconfig (2 diffs) drivers/usb/musb/Makefile (1 diff) drivers/usb/musb/jz4740.c (1 diff) |
Change Details
arch/mips/include/asm/mach-jz4740/platform.h | ||
---|---|---|
21 | 21 | |
22 | 22 | extern struct platform_device jz4740_usb_ohci_device; |
23 | 23 | extern struct platform_device jz4740_udc_device; |
24 | extern struct platform_device jz4740_udc_xceiv_device; | |
24 | 25 | extern struct platform_device jz4740_mmc_device; |
25 | 26 | extern struct platform_device jz4740_rtc_device; |
26 | 27 | extern struct platform_device jz4740_i2c_device; |
arch/mips/jz4740/board-qi_lb60.c | ||
---|---|---|
454 | 454 | |
455 | 455 | static struct platform_device *jz_platform_devices[] __initdata = { |
456 | 456 | &jz4740_udc_device, |
457 | &jz4740_udc_xceiv_device, | |
457 | 458 | &jz4740_mmc_device, |
458 | 459 | &jz4740_nand_device, |
459 | 460 | &qi_lb60_keypad, |
arch/mips/jz4740/platform.c | ||
---|---|---|
21 | 21 | |
22 | 22 | #include <linux/dma-mapping.h> |
23 | 23 | |
24 | #include <linux/usb/musb.h> | |
25 | ||
24 | 26 | #include <asm/mach-jz4740/platform.h> |
25 | 27 | #include <asm/mach-jz4740/base.h> |
26 | 28 | #include <asm/mach-jz4740/irq.h> |
... | ... | |
56 | 58 | .resource = jz4740_usb_ohci_resources, |
57 | 59 | }; |
58 | 60 | |
59 | /* UDC (USB gadget controller) */ | |
60 | static struct resource jz4740_usb_gdt_resources[] = { | |
61 | { | |
62 | .start = JZ4740_UDC_BASE_ADDR, | |
63 | .end = JZ4740_UDC_BASE_ADDR + 0x1000 - 1, | |
64 | .flags = IORESOURCE_MEM, | |
61 | /* USB Device Controller */ | |
62 | struct platform_device jz4740_udc_xceiv_device = { | |
63 | .name = "usb_phy_gen_xceiv", | |
64 | .id = 0, | |
65 | }; | |
66 | ||
67 | static struct resource jz4740_udc_resources[] = { | |
68 | [0] = { | |
69 | .start = JZ4740_UDC_BASE_ADDR, | |
70 | .end = JZ4740_UDC_BASE_ADDR + 0x10000 - 1, | |
71 | .flags = IORESOURCE_MEM, | |
65 | 72 | }, |
66 | { | |
67 | .start = JZ4740_IRQ_UDC, | |
68 | .end = JZ4740_IRQ_UDC, | |
69 | .flags = IORESOURCE_IRQ, | |
73 | [1] = { | |
74 | .start = JZ4740_IRQ_UDC, | |
75 | .end = JZ4740_IRQ_UDC, | |
76 | .flags = IORESOURCE_IRQ, | |
77 | .name = "mc", | |
70 | 78 | }, |
71 | 79 | }; |
72 | 80 | |
73 | 81 | struct platform_device jz4740_udc_device = { |
74 | .name = "jz-udc", | |
75 | .id = -1, | |
76 | .dev = { | |
77 | .dma_mask = &jz4740_udc_device.dev.coherent_dma_mask, | |
82 | .name = "musb-jz4740", | |
83 | .id = -1, | |
84 | .dev = { | |
85 | .dma_mask = &jz4740_udc_device.dev.coherent_dma_mask, | |
78 | 86 | .coherent_dma_mask = DMA_BIT_MASK(32), |
79 | 87 | }, |
80 | .num_resources = ARRAY_SIZE(jz4740_usb_gdt_resources), | |
81 | .resource = jz4740_usb_gdt_resources, | |
88 | .num_resources = ARRAY_SIZE(jz4740_udc_resources), | |
89 | .resource = jz4740_udc_resources, | |
82 | 90 | }; |
83 | 91 | |
84 | 92 | /* MMC/SD controller */ |
drivers/usb/musb/Kconfig | ||
---|---|---|
93 | 93 | config USB_MUSB_UX500 |
94 | 94 | tristate "Ux500 platforms" |
95 | 95 | |
96 | config USB_MUSB_JZ4740 | |
97 | tristate "JZ4740" | |
98 | depends on MACH_JZ4740 | |
99 | depends on USB_MUSB_GADGET | |
100 | depends on USB_OTG_BLACKLIST_HUB | |
101 | ||
96 | 102 | endchoice |
97 | 103 | |
98 | 104 | config USB_MUSB_AM335X_CHILD |
... | ... | |
100 | 106 | |
101 | 107 | choice |
102 | 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 | 110 | default USB_UX500_DMA if USB_MUSB_UX500 |
105 | 111 | default USB_INVENTRA_DMA if USB_MUSB_OMAP2PLUS || USB_MUSB_BLACKFIN |
106 | 112 | default USB_TI_CPPI_DMA if USB_MUSB_DAVINCI |
drivers/usb/musb/Makefile | ||
---|---|---|
19 | 19 | obj-$(CONFIG_USB_MUSB_DA8XX) += da8xx.o |
20 | 20 | obj-$(CONFIG_USB_MUSB_BLACKFIN) += blackfin.o |
21 | 21 | obj-$(CONFIG_USB_MUSB_UX500) += ux500.o |
22 | obj-$(CONFIG_USB_MUSB_JZ4740) += jz4740.o | |
22 | 23 | |
23 | 24 | |
24 | 25 | obj-$(CONFIG_USB_MUSB_AM335X_CHILD) += musb_am335x.o |
drivers/usb/musb/jz4740.c | ||
---|---|---|
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 | ||
25 | struct jz4740_glue { | |
26 | struct device *dev; | |
27 | struct platform_device *musb; | |
28 | struct clk *clk; | |
29 | }; | |
30 | ||
31 | static 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 | ||
59 | static 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 | static struct musb_hdrc_config jz4740_musb_config = { | |
65 | /* Silicon does not implement USB OTG. */ | |
66 | .multipoint = 0, | |
67 | /* Max EPs scanned, driver will decide which EP can be used. */ | |
68 | .num_eps = 4, | |
69 | /* RAMbits needed to configure EPs from table */ | |
70 | .ram_bits = 9, | |
71 | .fifo_cfg = jz4740_musb_fifo_cfg, | |
72 | .fifo_cfg_size = ARRAY_SIZE(jz4740_musb_fifo_cfg), | |
73 | }; | |
74 | ||
75 | static struct musb_hdrc_platform_data jz4740_musb_platform_data = { | |
76 | .mode = MUSB_PERIPHERAL, | |
77 | .config = &jz4740_musb_config, | |
78 | }; | |
79 | ||
80 | static int jz4740_musb_init(struct musb *musb) | |
81 | { | |
82 | musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); | |
83 | if (!musb->xceiv) { | |
84 | pr_err("HS UDC: no transceiver configured\n"); | |
85 | return -ENODEV; | |
86 | } | |
87 | ||
88 | /* Silicon does not implement ConfigData register. | |
89 | * Set dyn_fifo to avoid reading EP config from hardware. | |
90 | */ | |
91 | musb->dyn_fifo = true; | |
92 | ||
93 | musb->isr = jz4740_musb_interrupt; | |
94 | ||
95 | return 0; | |
96 | } | |
97 | ||
98 | static int jz4740_musb_exit(struct musb *musb) | |
99 | { | |
100 | usb_put_phy(musb->xceiv); | |
101 | ||
102 | return 0; | |
103 | } | |
104 | ||
105 | static const struct musb_platform_ops jz4740_musb_ops = { | |
106 | .init = jz4740_musb_init, | |
107 | .exit = jz4740_musb_exit, | |
108 | }; | |
109 | ||
110 | static int jz4740_probe(struct platform_device *pdev) | |
111 | { | |
112 | struct musb_hdrc_platform_data *pdata = &jz4740_musb_platform_data; | |
113 | struct platform_device *musb; | |
114 | struct jz4740_glue *glue; | |
115 | struct clk *clk; | |
116 | int ret; | |
117 | ||
118 | glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); | |
119 | if (!glue) | |
120 | return -ENOMEM; | |
121 | ||
122 | musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO); | |
123 | if (!musb) { | |
124 | dev_err(&pdev->dev, "failed to allocate musb device\n"); | |
125 | return -ENOMEM; | |
126 | } | |
127 | ||
128 | clk = devm_clk_get(&pdev->dev, "udc"); | |
129 | if (IS_ERR(clk)) { | |
130 | dev_err(&pdev->dev, "failed to get clock\n"); | |
131 | ret = PTR_ERR(clk); | |
132 | goto err_platform_device_put; | |
133 | } | |
134 | ||
135 | ret = clk_prepare_enable(clk); | |
136 | if (ret) { | |
137 | dev_err(&pdev->dev, "failed to enable clock\n"); | |
138 | goto err_platform_device_put; | |
139 | } | |
140 | ||
141 | musb->dev.parent = &pdev->dev; | |
142 | ||
143 | glue->dev = &pdev->dev; | |
144 | glue->musb = musb; | |
145 | glue->clk = clk; | |
146 | ||
147 | pdata->platform_ops = &jz4740_musb_ops; | |
148 | ||
149 | platform_set_drvdata(pdev, glue); | |
150 | ||
151 | ret = platform_device_add_resources(musb, pdev->resource, | |
152 | pdev->num_resources); | |
153 | if (ret) { | |
154 | dev_err(&pdev->dev, "failed to add resources\n"); | |
155 | goto err_clk_disable; | |
156 | } | |
157 | ||
158 | ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); | |
159 | if (ret) { | |
160 | dev_err(&pdev->dev, "failed to add platform_data\n"); | |
161 | goto err_clk_disable; | |
162 | } | |
163 | ||
164 | ret = platform_device_add(musb); | |
165 | if (ret) { | |
166 | dev_err(&pdev->dev, "failed to register musb device\n"); | |
167 | goto err_clk_disable; | |
168 | } | |
169 | ||
170 | return 0; | |
171 | ||
172 | err_clk_disable: | |
173 | clk_disable_unprepare(clk); | |
174 | err_platform_device_put: | |
175 | platform_device_put(musb); | |
176 | return ret; | |
177 | } | |
178 | ||
179 | static int jz4740_remove(struct platform_device *pdev) | |
180 | { | |
181 | struct jz4740_glue *glue = platform_get_drvdata(pdev); | |
182 | ||
183 | platform_device_unregister(glue->musb); | |
184 | clk_disable_unprepare(glue->clk); | |
185 | ||
186 | return 0; | |
187 | } | |
188 | ||
189 | static struct platform_driver jz4740_driver = { | |
190 | .probe = jz4740_probe, | |
191 | .remove = jz4740_remove, | |
192 | .driver = { | |
193 | .name = "musb-jz4740", | |
194 | }, | |
195 | }; | |
196 | ||
197 | MODULE_DESCRIPTION("JZ4740 MUSB Glue Layer"); | |
198 | MODULE_AUTHOR("Apelete Seketeli <apelete@seketeli.net>"); | |
199 | MODULE_LICENSE("GPL v2"); | |
200 | module_platform_driver(jz4740_driver); |
Branches:
ben-wpan
ben-wpan-stefan
5396a9238205f20f811ea57898980d3ca82df0b6
jz-2.6.34
jz-2.6.34-rc5
jz-2.6.34-rc6
jz-2.6.34-rc7
jz-2.6.35
jz-2.6.36
jz-2.6.37
jz-2.6.38
jz-2.6.39
jz-3.0
jz-3.1
jz-3.11
jz-3.12
jz-3.13
jz-3.15
jz-3.16
jz-3.18-dt
jz-3.2
jz-3.3
jz-3.4
jz-3.5
jz-3.6
jz-3.6-rc2-pwm
jz-3.9
jz-3.9-clk
jz-3.9-rc8
jz47xx
jz47xx-2.6.38
master
Tags:
od-2011-09-04
od-2011-09-18
v2.6.34-rc5
v2.6.34-rc6
v2.6.34-rc7
v3.9