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