source: src/linux/universal/linux-3.2/arch/mips/ar7240/platform.c @ 18404

Last change on this file since 18404 was 18404, checked in by BrainSlayer, 16 months ago

WNR2000 uboot detection and platform mac

File size: 7.8 KB
Line 
1#include <linux/device.h>
2#include <linux/platform_device.h>
3#include <linux/kernel.h>
4#include <linux/init.h>
5#include <linux/resource.h>
6
7#include <linux/console.h>
8#include <asm/serial.h>
9
10#include <linux/tty.h>
11#include <linux/serial_core.h>
12#include <linux/serial.h>
13#include <linux/serial_8250.h>
14
15#include <asm/mach-ar7240/ar7240.h>
16#include <asm/mach-ar71xx/ar71xx.h>
17#include "nvram.h"
18#include "devices.h"
19#include <asm/mach-ar71xx/ar933x_uart_platform.h>
20
21void serial_print(char *fmt, ...);
22
23#ifdef CONFIG_WASP_SUPPORT
24extern uint32_t ath_ref_clk_freq;
25#else
26extern uint32_t ar7240_ahb_freq;
27#endif
28
29/*
30 * OHCI (USB full speed host controller)
31 */
32static struct resource ar7240_usb_ohci_resources[] = {
33        [0] = {
34                .start          = AR7240_USB_OHCI_BASE,
35                .end            = AR7240_USB_OHCI_BASE + AR7240_USB_WINDOW - 1,
36                .flags          = IORESOURCE_MEM,
37        },
38        [1] = {
39                .start          = AR7240_CPU_IRQ_USB,
40        .end        = AR7240_CPU_IRQ_USB,
41                .flags          = IORESOURCE_IRQ,
42        },
43};
44
45/*
46 * The dmamask must be set for OHCI to work
47 */
48static u64 ohci_dmamask = ~(u32)0;
49static struct platform_device ar7240_usb_ohci_device = {
50        .name           = "ar7240-ohci",
51        .id                 = 0,
52        .dev = {
53                .dma_mask               = &ohci_dmamask,
54                .coherent_dma_mask      = 0xffffffff,
55        },
56        .num_resources  = ARRAY_SIZE(ar7240_usb_ohci_resources),
57        .resource       = ar7240_usb_ohci_resources,
58};
59
60/*
61 * EHCI (USB full speed host controller)
62 */
63static struct resource ar7240_usb_ehci_resources[] = {
64        [0] = {
65                .start          = AR7240_USB_EHCI_BASE,
66                .end            = AR7240_USB_EHCI_BASE + AR7240_USB_WINDOW - 1,
67                .flags          = IORESOURCE_MEM,
68        },
69        [1] = {
70                .start          = AR7240_CPU_IRQ_USB,
71                .end            = AR7240_CPU_IRQ_USB,
72                .flags          = IORESOURCE_IRQ,
73        },
74};
75
76/*
77 * The dmamask must be set for EHCI to work
78 */
79static u64 ehci_dmamask = ~(u32)0;
80
81static struct platform_device ar7240_usb_ehci_device = {
82        .name           = "ar71xx-ehci",
83        .id                 = 0,
84        .dev = {
85                .dma_mask               = &ehci_dmamask,
86                .coherent_dma_mask      = 0xffffffff,
87        },
88        .num_resources  = ARRAY_SIZE(ar7240_usb_ehci_resources),
89        .resource       = ar7240_usb_ehci_resources,
90};
91
92
93
94static struct resource ar7240_uart_resources[] = {
95        {
96                .start = AR7240_UART_BASE,
97                .end = AR7240_UART_BASE+0x0fff,
98                .flags = IORESOURCE_MEM,
99        },
100};
101
102#define AR71XX_UART_FLAGS (UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_IOREMAP)
103
104static struct plat_serial8250_port ar7240_uart_data[] = {
105        {
106                .mapbase        = AR7240_UART_BASE,
107                .irq            = AR7240_MISC_IRQ_UART,
108                .flags          = AR71XX_UART_FLAGS,
109                .iotype         = UPIO_MEM32,
110                .regshift       = 2,
111                .uartclk        = 0, /* ar7240_ahb_freq, */
112        },
113        { },
114};
115
116static struct platform_device ar7240_uart = {
117         .name               = "serial8250",
118        .id                 = 0,
119        .dev.platform_data  = ar7240_uart_data,
120        .num_resources      = 1,
121        .resource           = ar7240_uart_resources
122
123};
124
125
126static struct resource ar933x_uart_resources[] = {
127        {
128                .start  = AR933X_UART_BASE,
129                .end    = AR933X_UART_BASE + AR71XX_UART_SIZE - 1,
130                .flags  = IORESOURCE_MEM,
131        },
132        {
133                .start  = AR7240_MISC_IRQ_UART,
134                .end    = AR7240_MISC_IRQ_UART,
135                .flags  = IORESOURCE_IRQ,
136        },
137};
138
139static struct ar933x_uart_platform_data ar933x_uart_data;
140static struct platform_device ar933x_uart_device = {
141        .name           = "ar933x-uart",
142        .id             = -1,
143        .resource       = ar933x_uart_resources,
144        .num_resources  = ARRAY_SIZE(ar933x_uart_resources),
145        .dev = {
146                .platform_data  = &ar933x_uart_data,
147        },
148};
149
150static struct resource ath_uart_resources[] = {
151        {
152         .start = AR933X_UART_BASE,
153         .end = AR933X_UART_BASE + 0x0fff,
154         .flags = IORESOURCE_MEM,
155         },
156};
157
158static struct plat_serial8250_port ath_uart_data[] = {
159        {
160         .mapbase = (u32) KSEG1ADDR(AR933X_UART_BASE),
161         .membase = (void __iomem *)((u32) (KSEG1ADDR(AR933X_UART_BASE))),
162         .irq = AR7240_MISC_IRQ_UART,
163         .flags = (UPF_BOOT_AUTOCONF | UPF_SKIP_TEST),
164         .iotype = UPIO_MEM32,
165         .regshift = 2,
166         .uartclk = 0,          /* ath_ahb_freq, */
167         },
168        {},
169};
170
171static struct platform_device ath_uart = {
172        .name = "serial8250",
173        .id = 0,
174        .dev.platform_data = ath_uart_data,
175        .num_resources = 1,
176        .resource = ath_uart_resources
177};
178
179
180
181static struct platform_device *ar7241_platform_devices[] __initdata = {
182        &ar7240_usb_ehci_device
183};
184
185static struct platform_device *ar7240_platform_devices[] __initdata = {
186        &ar7240_usb_ohci_device
187};
188
189static struct platform_device *ar724x_platform_devices[] __initdata = {
190#ifdef CONFIG_MACH_HORNET
191        &ar933x_uart_device,
192        &ath_uart
193#else
194        &ar7240_uart
195#endif
196};
197
198extern __init ap91_pci_init(u8 *cal_data, u8 *mac_addr);
199void ar9xxx_add_device_wmac(u8 *cal_data, u8 *mac_addr) __init;
200
201static void *getCalData(int slot)
202{
203u8 *base;
204for (base=(u8 *) KSEG1ADDR(0x1f000000);base<KSEG1ADDR (0x1ffff000);base+=0x1000) {
205        u32 *cal = (u32 *)base;
206        if (*cal==0xa55a0000 || *cal==0x5aa50000) { //protection bit is always zero on inflash devices, so we can use for match it
207                if (slot) {
208                        base+=0x4000;
209                }
210                printk(KERN_INFO "found calibration data for slot %d on 0x%08X\n",slot,base);
211                return base;
212        }
213    }
214return NULL;
215}
216
217enum ar71xx_soc_type ar71xx_soc;
218EXPORT_SYMBOL_GPL(ar71xx_soc);
219
220int __init ar7240_platform_init(void)
221{
222        int ret;
223        void *ee;
224#ifdef CONFIG_WR741
225        u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
226#else
227        u8 *mac = NULL;//(u8 *) KSEG1ADDR(0x1fff0000);
228#endif
229
230#if defined(CONFIG_AR7242_RTL8309G_PHY) || defined(CONFIG_DIR615E)
231#ifdef CONFIG_DIR615E
232        const char *config = (char *) KSEG1ADDR(0x1f030000);
233#else
234        const char *config = (char *) KSEG1ADDR(0x1f040000);
235#endif
236        u8 wlan_mac[6];
237        if (nvram_parse_mac_addr(config, 0x10000,"lan_mac=", wlan_mac) == 0) {
238                mac = wlan_mac;
239        }
240#endif
241
242
243
244        /* need to set clock appropriately */
245#ifdef CONFIG_MACH_HORNET
246
247        ath_uart_data[0].uartclk = ar71xx_ref_freq;
248        ar933x_uart_data.uartclk = ar71xx_ref_freq;
249#endif
250
251#ifdef CONFIG_WASP_SUPPORT
252        ar7240_uart_data[0].uartclk = ath_ref_clk_freq;
253#else
254        ar7240_uart_data[0].uartclk = ar7240_ahb_freq;
255#endif
256#ifdef CONFIG_WASP_SUPPORT
257
258#define DB120_MAC0_OFFSET       0
259#define DB120_MAC1_OFFSET       6
260        u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
261
262        void __iomem *base;
263        u32 t;
264
265/*      base = ioremap(AR934X_GMAC_BASE, AR934X_GMAC_SIZE);
266
267        t = __raw_readl(base + AR934X_GMAC_REG_ETH_CFG);
268        t &= ~(AR934X_ETH_CFG_GMII_GMAC0 | AR934X_ETH_CFG_MII_GMAC0 |
269               AR934X_ETH_CFG_MII_GMAC0 | AR934X_ETH_CFG_SW_ONLY_MODE);
270        __raw_writel(t, base + AR934X_GMAC_REG_ETH_CFG);
271
272        iounmap(base);
273*/
274
275        ar71xx_add_device_mdio(0, 0x0);
276        ar71xx_add_device_mdio(1, 0x0);
277
278        ar71xx_init_mac(ar71xx_eth0_data.mac_addr, art + DB120_MAC0_OFFSET, 0);
279        ar71xx_switch_data.phy4_mii_en = 1;
280
281
282        ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
283        ar71xx_eth0_data.speed = SPEED_1000;
284        ar71xx_eth0_data.duplex = DUPLEX_FULL;
285
286        ar71xx_add_device_eth(0);
287
288        /* GMAC1 is connected to the internal switch */
289/*      ar71xx_init_mac(ar71xx_eth1_data.mac_addr, art + DB120_MAC1_OFFSET, 0);
290        ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
291        ar71xx_eth1_data.speed = SPEED_1000;
292        ar71xx_eth1_data.duplex = DUPLEX_FULL;
293
294        ar71xx_add_device_eth(1);
295*/
296
297#endif
298
299
300        ret = platform_add_devices(ar724x_platform_devices,
301                                ARRAY_SIZE(ar724x_platform_devices));
302
303        if (ret < 0)
304                return ret;
305
306        if (is_ar7241() || is_ar7242()  || is_ar933x() || is_ar934x()) {
307            ret = platform_add_devices(ar7241_platform_devices,
308                                ARRAY_SIZE(ar7241_platform_devices));
309        }
310        if (is_ar7240()) {
311            ret = platform_add_devices(ar7240_platform_devices,
312                                ARRAY_SIZE(ar7240_platform_devices));
313        }
314       
315#ifdef CONFIG_MACH_HORNET
316        ee = (u8 *) KSEG1ADDR(0x1fff1000);
317        ar9xxx_add_device_wmac(ee, NULL);
318#elif CONFIG_WASP_SUPPORT
319        ee = (u8 *) KSEG1ADDR(0x1fff1000);
320        ar9xxx_add_device_wmac(ee, NULL);
321        ap91_pci_init(NULL, NULL);
322#else
323        ee = getCalData(0);
324        if (ee)
325            mac = ((u8 *)ee)-0x1000;
326        ap91_pci_init(ee, mac);
327#endif
328return ret;
329}
330
331arch_initcall(ar7240_platform_init);
332   
Note: See TracBrowser for help on using the repository browser.