kernel: update linux 3.8 to 3.8.10
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / patches-3.8 / 026-MIPS-ath79-use-dynamically-allocated-USB-platform-de.patch
1 From 9c3c3f7be27c88b59359e743be0437eb6f9af41f Mon Sep 17 00:00:00 2001
2 From: Gabor Juhos <juhosg@openwrt.org>
3 Date: Sat, 9 Feb 2013 17:57:52 +0000
4 Subject: [PATCH] MIPS: ath79: use dynamically allocated USB platform devices
5
6 commit 90a938d1add4859ad3e43c3dd5ee54bd0627e42d upstream.
7
8 The current code uses static resources and static platform
9 device instances for the possible USB controllers in the
10 system. These static variables contains initial values which
11 leads to data segment pollution.
12
13 Remove the static variables and use dynamically allocated
14 structures instead.
15
16 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
17 Patchwork: http://patchwork.linux-mips.org/patch/4933/
18 Signed-off-by: John Crispin <blogic@openwrt.org>
19 ---
20 arch/mips/ath79/dev-usb.c | 111 +++++++++++++++++++++------------------------
21 1 file changed, 51 insertions(+), 60 deletions(-)
22
23 --- a/arch/mips/ath79/dev-usb.c
24 +++ b/arch/mips/ath79/dev-usb.c
25 @@ -25,29 +25,11 @@
26 #include "common.h"
27 #include "dev-usb.h"
28
29 -static struct resource ath79_ohci_resources[2];
30 -
31 -static u64 ath79_ohci_dmamask = DMA_BIT_MASK(32);
32 +static u64 ath79_usb_dmamask = DMA_BIT_MASK(32);
33
34 static struct usb_ohci_pdata ath79_ohci_pdata = {
35 };
36
37 -static struct platform_device ath79_ohci_device = {
38 - .name = "ohci-platform",
39 - .id = -1,
40 - .resource = ath79_ohci_resources,
41 - .num_resources = ARRAY_SIZE(ath79_ohci_resources),
42 - .dev = {
43 - .dma_mask = &ath79_ohci_dmamask,
44 - .coherent_dma_mask = DMA_BIT_MASK(32),
45 - .platform_data = &ath79_ohci_pdata,
46 - },
47 -};
48 -
49 -static struct resource ath79_ehci_resources[2];
50 -
51 -static u64 ath79_ehci_dmamask = DMA_BIT_MASK(32);
52 -
53 static struct usb_ehci_pdata ath79_ehci_pdata_v1 = {
54 .has_synopsys_hc_bug = 1,
55 };
56 @@ -57,22 +39,16 @@ static struct usb_ehci_pdata ath79_ehci_
57 .has_tt = 1,
58 };
59
60 -static struct platform_device ath79_ehci_device = {
61 - .name = "ehci-platform",
62 - .id = -1,
63 - .resource = ath79_ehci_resources,
64 - .num_resources = ARRAY_SIZE(ath79_ehci_resources),
65 - .dev = {
66 - .dma_mask = &ath79_ehci_dmamask,
67 - .coherent_dma_mask = DMA_BIT_MASK(32),
68 - },
69 -};
70 -
71 -static void __init ath79_usb_init_resource(struct resource res[2],
72 - unsigned long base,
73 - unsigned long size,
74 - int irq)
75 +static void __init ath79_usb_register(const char *name, int id,
76 + unsigned long base, unsigned long size,
77 + int irq, const void *data,
78 + size_t data_size)
79 {
80 + struct resource res[2];
81 + struct platform_device *pdev;
82 +
83 + memset(res, 0, sizeof(res));
84 +
85 res[0].flags = IORESOURCE_MEM;
86 res[0].start = base;
87 res[0].end = base + size - 1;
88 @@ -80,6 +56,19 @@ static void __init ath79_usb_init_resour
89 res[1].flags = IORESOURCE_IRQ;
90 res[1].start = irq;
91 res[1].end = irq;
92 +
93 + pdev = platform_device_register_resndata(NULL, name, id,
94 + res, ARRAY_SIZE(res),
95 + data, data_size);
96 +
97 + if (IS_ERR(pdev)) {
98 + pr_err("ath79: unable to register USB at %08lx, err=%d\n",
99 + base, (int) PTR_ERR(pdev));
100 + return;
101 + }
102 +
103 + pdev->dev.dma_mask = &ath79_usb_dmamask;
104 + pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
105 }
106
107 #define AR71XX_USB_RESET_MASK (AR71XX_RESET_USB_HOST | \
108 @@ -106,14 +95,15 @@ static void __init ath79_usb_setup(void)
109
110 mdelay(900);
111
112 - ath79_usb_init_resource(ath79_ohci_resources, AR71XX_OHCI_BASE,
113 - AR71XX_OHCI_SIZE, ATH79_MISC_IRQ(6));
114 - platform_device_register(&ath79_ohci_device);
115 -
116 - ath79_usb_init_resource(ath79_ehci_resources, AR71XX_EHCI_BASE,
117 - AR71XX_EHCI_SIZE, ATH79_CPU_IRQ(3));
118 - ath79_ehci_device.dev.platform_data = &ath79_ehci_pdata_v1;
119 - platform_device_register(&ath79_ehci_device);
120 + ath79_usb_register("ohci-platform", -1,
121 + AR71XX_OHCI_BASE, AR71XX_OHCI_SIZE,
122 + ATH79_MISC_IRQ(6),
123 + &ath79_ohci_pdata, sizeof(ath79_ohci_pdata));
124 +
125 + ath79_usb_register("ehci-platform", -1,
126 + AR71XX_EHCI_BASE, AR71XX_EHCI_SIZE,
127 + ATH79_CPU_IRQ(3),
128 + &ath79_ehci_pdata_v1, sizeof(ath79_ehci_pdata_v1));
129 }
130
131 static void __init ar7240_usb_setup(void)
132 @@ -135,9 +125,10 @@ static void __init ar7240_usb_setup(void
133
134 iounmap(usb_ctrl_base);
135
136 - ath79_usb_init_resource(ath79_ohci_resources, AR7240_OHCI_BASE,
137 - AR7240_OHCI_SIZE, ATH79_CPU_IRQ(3));
138 - platform_device_register(&ath79_ohci_device);
139 + ath79_usb_register("ohci-platform", -1,
140 + AR7240_OHCI_BASE, AR7240_OHCI_SIZE,
141 + ATH79_CPU_IRQ(3),
142 + &ath79_ohci_pdata, sizeof(ath79_ohci_pdata));
143 }
144
145 static void __init ar724x_usb_setup(void)
146 @@ -151,10 +142,10 @@ static void __init ar724x_usb_setup(void
147 ath79_device_reset_clear(AR724X_RESET_USB_PHY);
148 mdelay(10);
149
150 - ath79_usb_init_resource(ath79_ehci_resources, AR724X_EHCI_BASE,
151 - AR724X_EHCI_SIZE, ATH79_CPU_IRQ(3));
152 - ath79_ehci_device.dev.platform_data = &ath79_ehci_pdata_v2;
153 - platform_device_register(&ath79_ehci_device);
154 + ath79_usb_register("ehci-platform", -1,
155 + AR724X_EHCI_BASE, AR724X_EHCI_SIZE,
156 + ATH79_CPU_IRQ(3),
157 + &ath79_ehci_pdata_v2, sizeof(ath79_ehci_pdata_v2));
158 }
159
160 static void __init ar913x_usb_setup(void)
161 @@ -168,10 +159,10 @@ static void __init ar913x_usb_setup(void
162 ath79_device_reset_clear(AR913X_RESET_USB_PHY);
163 mdelay(10);
164
165 - ath79_usb_init_resource(ath79_ehci_resources, AR913X_EHCI_BASE,
166 - AR913X_EHCI_SIZE, ATH79_CPU_IRQ(3));
167 - ath79_ehci_device.dev.platform_data = &ath79_ehci_pdata_v2;
168 - platform_device_register(&ath79_ehci_device);
169 + ath79_usb_register("ehci-platform", -1,
170 + AR913X_EHCI_BASE, AR913X_EHCI_SIZE,
171 + ATH79_CPU_IRQ(3),
172 + &ath79_ehci_pdata_v2, sizeof(ath79_ehci_pdata_v2));
173 }
174
175 static void __init ar933x_usb_setup(void)
176 @@ -185,10 +176,10 @@ static void __init ar933x_usb_setup(void
177 ath79_device_reset_clear(AR933X_RESET_USB_PHY);
178 mdelay(10);
179
180 - ath79_usb_init_resource(ath79_ehci_resources, AR933X_EHCI_BASE,
181 - AR933X_EHCI_SIZE, ATH79_CPU_IRQ(3));
182 - ath79_ehci_device.dev.platform_data = &ath79_ehci_pdata_v2;
183 - platform_device_register(&ath79_ehci_device);
184 + ath79_usb_register("ehci-platform", -1,
185 + AR933X_EHCI_BASE, AR933X_EHCI_SIZE,
186 + ATH79_CPU_IRQ(3),
187 + &ath79_ehci_pdata_v2, sizeof(ath79_ehci_pdata_v2));
188 }
189
190 static void __init ar934x_usb_setup(void)
191 @@ -211,10 +202,10 @@ static void __init ar934x_usb_setup(void
192 ath79_device_reset_clear(AR934X_RESET_USB_HOST);
193 udelay(1000);
194
195 - ath79_usb_init_resource(ath79_ehci_resources, AR934X_EHCI_BASE,
196 - AR934X_EHCI_SIZE, ATH79_CPU_IRQ(3));
197 - ath79_ehci_device.dev.platform_data = &ath79_ehci_pdata_v2;
198 - platform_device_register(&ath79_ehci_device);
199 + ath79_usb_register("ehci-platform", -1,
200 + AR934X_EHCI_BASE, AR934X_EHCI_SIZE,
201 + ATH79_CPU_IRQ(3),
202 + &ath79_ehci_pdata_v2, sizeof(ath79_ehci_pdata_v2));
203 }
204
205 void __init ath79_register_usb(void)