ar71xx: build image for the TL-MR3220 v2
[openwrt.git] / target / linux / ar71xx / patches-3.6 / 001-MIPS-ath79-use-a-helper-function-for-USB-resource-in.patch
1 From 58a4dbd4160ee4a1428da23b81ff6d94c9a067a8 Mon Sep 17 00:00:00 2001
2 From: Gabor Juhos <juhosg@openwrt.org>
3 Date: Sat, 4 Aug 2012 15:03:55 +0000
4 Subject: [PATCH] MIPS: ath79: use a helper function for USB resource
5  initialization
6
7 commit 8d3e03e186cb94a333d0176fe8b22a6df200fcc7 upstream.
8
9 This improves code readability, and ensures that
10 all resource fields will be initialized correctly.
11 Additionally, it helps to reduce the size of the
12 kernel image by using uninitialized resource
13 variables.
14
15 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
16 Patchwork: http://patchwork.linux-mips.org/patch/4171/
17 Signed-off-by: John Crispin <blogic@openwrt.org>
18 ---
19  arch/mips/ath79/dev-usb.c |   64 ++++++++++++++++++++-------------------------
20  1 file changed, 28 insertions(+), 36 deletions(-)
21
22 --- a/arch/mips/ath79/dev-usb.c
23 +++ b/arch/mips/ath79/dev-usb.c
24 @@ -25,17 +25,7 @@
25  #include "common.h"
26  #include "dev-usb.h"
27  
28 -static struct resource ath79_ohci_resources[] = {
29 -       [0] = {
30 -               /* .start and .end fields are filled dynamically */
31 -               .flags  = IORESOURCE_MEM,
32 -       },
33 -       [1] = {
34 -               .start  = ATH79_MISC_IRQ_OHCI,
35 -               .end    = ATH79_MISC_IRQ_OHCI,
36 -               .flags  = IORESOURCE_IRQ,
37 -       },
38 -};
39 +static struct resource ath79_ohci_resources[2];
40  
41  static u64 ath79_ohci_dmamask = DMA_BIT_MASK(32);
42  
43 @@ -54,17 +44,7 @@ static struct platform_device ath79_ohci
44         },
45  };
46  
47 -static struct resource ath79_ehci_resources[] = {
48 -       [0] = {
49 -               /* .start and .end fields are filled dynamically */
50 -               .flags  = IORESOURCE_MEM,
51 -       },
52 -       [1] = {
53 -               .start  = ATH79_CPU_IRQ_USB,
54 -               .end    = ATH79_CPU_IRQ_USB,
55 -               .flags  = IORESOURCE_IRQ,
56 -       },
57 -};
58 +static struct resource ath79_ehci_resources[2];
59  
60  static u64 ath79_ehci_dmamask = DMA_BIT_MASK(32);
61  
62 @@ -90,6 +70,20 @@ static struct platform_device ath79_ehci
63         },
64  };
65  
66 +static void __init ath79_usb_init_resource(struct resource res[2],
67 +                                          unsigned long base,
68 +                                          unsigned long size,
69 +                                          int irq)
70 +{
71 +       res[0].flags = IORESOURCE_MEM;
72 +       res[0].start = base;
73 +       res[0].end = base + size - 1;
74 +
75 +       res[1].flags = IORESOURCE_IRQ;
76 +       res[1].start = irq;
77 +       res[1].end = irq;
78 +}
79 +
80  #define AR71XX_USB_RESET_MASK  (AR71XX_RESET_USB_HOST | \
81                                  AR71XX_RESET_USB_PHY | \
82                                  AR71XX_RESET_USB_OHCI_DLL)
83 @@ -114,12 +108,12 @@ static void __init ath79_usb_setup(void)
84  
85         mdelay(900);
86  
87 -       ath79_ohci_resources[0].start = AR71XX_OHCI_BASE;
88 -       ath79_ohci_resources[0].end = AR71XX_OHCI_BASE + AR71XX_OHCI_SIZE - 1;
89 +       ath79_usb_init_resource(ath79_ohci_resources, AR71XX_OHCI_BASE,
90 +                               AR71XX_OHCI_SIZE, ATH79_MISC_IRQ_OHCI);
91         platform_device_register(&ath79_ohci_device);
92  
93 -       ath79_ehci_resources[0].start = AR71XX_EHCI_BASE;
94 -       ath79_ehci_resources[0].end = AR71XX_EHCI_BASE + AR71XX_EHCI_SIZE - 1;
95 +       ath79_usb_init_resource(ath79_ehci_resources, AR71XX_EHCI_BASE,
96 +                               AR71XX_EHCI_SIZE, ATH79_CPU_IRQ_USB);
97         ath79_ehci_device.dev.platform_data = &ath79_ehci_pdata_v1;
98         platform_device_register(&ath79_ehci_device);
99  }
100 @@ -143,10 +137,8 @@ static void __init ar7240_usb_setup(void
101  
102         iounmap(usb_ctrl_base);
103  
104 -       ath79_ohci_resources[0].start = AR7240_OHCI_BASE;
105 -       ath79_ohci_resources[0].end = AR7240_OHCI_BASE + AR7240_OHCI_SIZE - 1;
106 -       ath79_ohci_resources[1].start = ATH79_CPU_IRQ_USB;
107 -       ath79_ohci_resources[1].end = ATH79_CPU_IRQ_USB;
108 +       ath79_usb_init_resource(ath79_ohci_resources, AR7240_OHCI_BASE,
109 +                               AR7240_OHCI_SIZE, ATH79_CPU_IRQ_USB);
110         platform_device_register(&ath79_ohci_device);
111  }
112  
113 @@ -161,8 +153,8 @@ static void __init ar724x_usb_setup(void
114         ath79_device_reset_clear(AR724X_RESET_USB_PHY);
115         mdelay(10);
116  
117 -       ath79_ehci_resources[0].start = AR724X_EHCI_BASE;
118 -       ath79_ehci_resources[0].end = AR724X_EHCI_BASE + AR724X_EHCI_SIZE - 1;
119 +       ath79_usb_init_resource(ath79_ehci_resources, AR724X_EHCI_BASE,
120 +                               AR724X_EHCI_SIZE, ATH79_CPU_IRQ_USB);
121         ath79_ehci_device.dev.platform_data = &ath79_ehci_pdata_v2;
122         platform_device_register(&ath79_ehci_device);
123  }
124 @@ -178,8 +170,8 @@ static void __init ar913x_usb_setup(void
125         ath79_device_reset_clear(AR913X_RESET_USB_PHY);
126         mdelay(10);
127  
128 -       ath79_ehci_resources[0].start = AR913X_EHCI_BASE;
129 -       ath79_ehci_resources[0].end = AR913X_EHCI_BASE + AR913X_EHCI_SIZE - 1;
130 +       ath79_usb_init_resource(ath79_ehci_resources, AR913X_EHCI_BASE,
131 +                               AR913X_EHCI_SIZE, ATH79_CPU_IRQ_USB);
132         ath79_ehci_device.dev.platform_data = &ath79_ehci_pdata_v2;
133         platform_device_register(&ath79_ehci_device);
134  }
135 @@ -195,8 +187,8 @@ static void __init ar933x_usb_setup(void
136         ath79_device_reset_clear(AR933X_RESET_USB_PHY);
137         mdelay(10);
138  
139 -       ath79_ehci_resources[0].start = AR933X_EHCI_BASE;
140 -       ath79_ehci_resources[0].end = AR933X_EHCI_BASE + AR933X_EHCI_SIZE - 1;
141 +       ath79_usb_init_resource(ath79_ehci_resources, AR933X_EHCI_BASE,
142 +                               AR933X_EHCI_SIZE, ATH79_CPU_IRQ_USB);
143         ath79_ehci_device.dev.platform_data = &ath79_ehci_pdata_v2;
144         platform_device_register(&ath79_ehci_device);
145  }