2 * Ralink RT288x SoC platform device registration
4 * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published
9 * by the Free Software Foundation.
12 #include <linux/kernel.h>
13 #include <linux/platform_device.h>
14 #include <linux/mtd/mtd.h>
15 #include <linux/mtd/physmap.h>
16 #include <linux/etherdevice.h>
17 #include <linux/err.h>
18 #include <linux/clk.h>
20 #include <asm/addrspace.h>
22 #include <asm/mach-ralink/rt288x.h>
23 #include <asm/mach-ralink/rt288x_regs.h>
24 #include <asm/mach-ralink/ramips_eth_platform.h>
28 static struct resource rt288x_flash0_resources[] = {
30 .flags = IORESOURCE_MEM,
31 .start = KSEG1ADDR(RT2880_FLASH0_BASE),
32 .end = KSEG1ADDR(RT2880_FLASH0_BASE) +
33 RT2880_FLASH0_SIZE - 1,
37 static struct platform_device rt288x_flash0_device = {
38 .name = "physmap-flash",
39 .resource = rt288x_flash0_resources,
40 .num_resources = ARRAY_SIZE(rt288x_flash0_resources),
43 static struct resource rt288x_flash1_resources[] = {
45 .flags = IORESOURCE_MEM,
46 .start = KSEG1ADDR(RT2880_FLASH1_BASE),
47 .end = KSEG1ADDR(RT2880_FLASH1_BASE) +
48 RT2880_FLASH1_SIZE - 1,
52 static struct platform_device rt288x_flash1_device = {
53 .name = "physmap-flash",
54 .resource = rt288x_flash1_resources,
55 .num_resources = ARRAY_SIZE(rt288x_flash1_resources),
58 static int rt288x_flash_instance __initdata;
59 void __init rt288x_register_flash(unsigned int id,
60 struct physmap_flash_data *pdata)
62 struct platform_device *pdev;
68 pdev = &rt288x_flash0_device;
69 reg = MEMC_REG_FLASH_CFG0;
72 pdev = &rt288x_flash1_device;
73 reg = MEMC_REG_FLASH_CFG1;
79 t = rt288x_memc_rr(reg);
80 t = (t >> FLASH_CFG_WIDTH_SHIFT) & FLASH_CFG_WIDTH_MASK;
83 case FLASH_CFG_WIDTH_8BIT:
86 case FLASH_CFG_WIDTH_16BIT:
89 case FLASH_CFG_WIDTH_32BIT:
93 printk(KERN_ERR "RT288x: flash bank%u witdh is invalid\n", id);
97 pdev->dev.platform_data = pdata;
98 pdev->id = rt288x_flash_instance;
100 platform_device_register(pdev);
101 rt288x_flash_instance++;
104 static struct resource rt288x_wifi_resources[] = {
106 .start = RT2880_WMAC_BASE,
107 .end = RT2880_WMAC_BASE + 0x3FFFF,
108 .flags = IORESOURCE_MEM,
110 .start = RT288X_CPU_IRQ_WNIC,
111 .end = RT288X_CPU_IRQ_WNIC,
112 .flags = IORESOURCE_IRQ,
116 static struct platform_device rt288x_wifi_device = {
117 .name = "rt2800_wmac",
118 .resource = rt288x_wifi_resources,
119 .num_resources = ARRAY_SIZE(rt288x_wifi_resources),
121 .platform_data = NULL,
125 void __init rt288x_register_wifi(void)
127 platform_device_register(&rt288x_wifi_device);
130 static void rt288x_fe_reset(void)
132 rt288x_sysc_wr(RT2880_RESET_FE, SYSC_REG_RESET_CTRL);
135 static struct resource rt288x_eth_resources[] = {
137 .start = RT2880_FE_BASE,
138 .end = RT2880_FE_BASE + PAGE_SIZE - 1,
139 .flags = IORESOURCE_MEM,
141 .start = RT288X_CPU_IRQ_FE,
142 .end = RT288X_CPU_IRQ_FE,
143 .flags = IORESOURCE_IRQ,
147 struct ramips_eth_platform_data rt288x_eth_data;
148 static struct platform_device rt288x_eth_device = {
149 .name = "ramips_eth",
150 .resource = rt288x_eth_resources,
151 .num_resources = ARRAY_SIZE(rt288x_eth_resources),
153 .platform_data = &rt288x_eth_data,
157 void __init rt288x_register_ethernet(void)
161 clk = clk_get(NULL, "sys");
163 panic("unable to get SYS clock, err=%ld", PTR_ERR(clk));
165 rt288x_eth_data.sys_freq = clk_get_rate(clk);
166 rt288x_eth_data.reset_fe = rt288x_fe_reset;
167 rt288x_eth_data.min_pkt_len = 64;
169 if (!is_valid_ether_addr(rt288x_eth_data.mac))
170 random_ether_addr(rt288x_eth_data.mac);
172 platform_device_register(&rt288x_eth_device);
175 static struct resource rt288x_wdt_resources[] = {
177 .start = RT2880_TIMER_BASE,
178 .end = RT2880_TIMER_BASE + RT2880_TIMER_SIZE - 1,
179 .flags = IORESOURCE_MEM,
183 static struct platform_device rt288x_wdt_device = {
184 .name = "ramips-wdt",
186 .resource = rt288x_wdt_resources,
187 .num_resources = ARRAY_SIZE(rt288x_wdt_resources),
190 void __init rt288x_register_wdt(void)
194 /* enable WDT reset output on pin SRAM_CS_N */
195 t = rt288x_sysc_rr(SYSC_REG_CLKCFG);
196 t |= CLKCFG_SRAM_CS_N_WDT;
197 rt288x_sysc_wr(t, SYSC_REG_CLKCFG);
199 platform_device_register(&rt288x_wdt_device);