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>
19 #include <linux/rt2x00_platform.h>
21 #include <asm/addrspace.h>
23 #include <asm/mach-ralink/rt288x.h>
24 #include <asm/mach-ralink/rt288x_regs.h>
25 #include <asm/mach-ralink/ramips_eth_platform.h>
29 static struct resource rt288x_flash0_resources[] = {
31 .flags = IORESOURCE_MEM,
32 .start = KSEG1ADDR(RT2880_FLASH0_BASE),
33 .end = KSEG1ADDR(RT2880_FLASH0_BASE) +
34 RT2880_FLASH0_SIZE - 1,
38 struct physmap_flash_data rt288x_flash0_data;
39 static struct platform_device rt288x_flash0_device = {
40 .name = "physmap-flash",
41 .resource = rt288x_flash0_resources,
42 .num_resources = ARRAY_SIZE(rt288x_flash0_resources),
44 .platform_data = &rt288x_flash0_data,
48 static struct resource rt288x_flash1_resources[] = {
50 .flags = IORESOURCE_MEM,
51 .start = KSEG1ADDR(RT2880_FLASH1_BASE),
52 .end = KSEG1ADDR(RT2880_FLASH1_BASE) +
53 RT2880_FLASH1_SIZE - 1,
57 struct physmap_flash_data rt288x_flash1_data;
58 static struct platform_device rt288x_flash1_device = {
59 .name = "physmap-flash",
60 .resource = rt288x_flash1_resources,
61 .num_resources = ARRAY_SIZE(rt288x_flash1_resources),
63 .platform_data = &rt288x_flash1_data,
67 static int rt288x_flash_instance __initdata;
68 void __init rt288x_register_flash(unsigned int id)
70 struct platform_device *pdev;
71 struct physmap_flash_data *pdata;
77 pdev = &rt288x_flash0_device;
78 reg = MEMC_REG_FLASH_CFG0;
81 pdev = &rt288x_flash1_device;
82 reg = MEMC_REG_FLASH_CFG1;
88 t = rt288x_memc_rr(reg);
89 t = (t >> FLASH_CFG_WIDTH_SHIFT) & FLASH_CFG_WIDTH_MASK;
91 pdata = pdev->dev.platform_data;
93 case FLASH_CFG_WIDTH_8BIT:
96 case FLASH_CFG_WIDTH_16BIT:
99 case FLASH_CFG_WIDTH_32BIT:
103 printk(KERN_ERR "RT288x: flash bank%u witdh is invalid\n", id);
107 pdev->id = rt288x_flash_instance;
109 platform_device_register(pdev);
110 rt288x_flash_instance++;
113 static struct resource rt288x_wifi_resources[] = {
115 .start = RT2880_WMAC_BASE,
116 .end = RT2880_WMAC_BASE + 0x3FFFF,
117 .flags = IORESOURCE_MEM,
119 .start = RT288X_CPU_IRQ_WNIC,
120 .end = RT288X_CPU_IRQ_WNIC,
121 .flags = IORESOURCE_IRQ,
125 static struct rt2x00_platform_data rt288x_wifi_data;
126 static struct platform_device rt288x_wifi_device = {
127 .name = "rt2800_wmac",
128 .resource = rt288x_wifi_resources,
129 .num_resources = ARRAY_SIZE(rt288x_wifi_resources),
131 .platform_data = &rt288x_wifi_data,
135 void __init rt288x_register_wifi(void)
137 rt288x_wifi_data.eeprom_file_name = "RT288X.eeprom";
138 platform_device_register(&rt288x_wifi_device);
141 static void rt288x_fe_reset(void)
143 rt288x_sysc_wr(RT2880_RESET_FE, SYSC_REG_RESET_CTRL);
146 static struct resource rt288x_eth_resources[] = {
148 .start = RT2880_FE_BASE,
149 .end = RT2880_FE_BASE + PAGE_SIZE - 1,
150 .flags = IORESOURCE_MEM,
152 .start = RT288X_CPU_IRQ_FE,
153 .end = RT288X_CPU_IRQ_FE,
154 .flags = IORESOURCE_IRQ,
158 struct ramips_eth_platform_data rt288x_eth_data;
159 static struct platform_device rt288x_eth_device = {
160 .name = "ramips_eth",
161 .resource = rt288x_eth_resources,
162 .num_resources = ARRAY_SIZE(rt288x_eth_resources),
164 .platform_data = &rt288x_eth_data,
168 void __init rt288x_register_ethernet(void)
172 clk = clk_get(NULL, "sys");
174 panic("unable to get SYS clock, err=%ld", PTR_ERR(clk));
176 rt288x_eth_data.sys_freq = clk_get_rate(clk);
177 rt288x_eth_data.reset_fe = rt288x_fe_reset;
178 rt288x_eth_data.min_pkt_len = 64;
180 if (!is_valid_ether_addr(rt288x_eth_data.mac))
181 random_ether_addr(rt288x_eth_data.mac);
183 platform_device_register(&rt288x_eth_device);
186 static struct resource rt288x_wdt_resources[] = {
188 .start = RT2880_TIMER_BASE,
189 .end = RT2880_TIMER_BASE + RT2880_TIMER_SIZE - 1,
190 .flags = IORESOURCE_MEM,
194 static struct platform_device rt288x_wdt_device = {
195 .name = "ramips-wdt",
197 .resource = rt288x_wdt_resources,
198 .num_resources = ARRAY_SIZE(rt288x_wdt_resources),
201 void __init rt288x_register_wdt(void)
205 /* enable WDT reset output on pin SRAM_CS_N */
206 t = rt288x_sysc_rr(SYSC_REG_CLKCFG);
207 t |= CLKCFG_SRAM_CS_N_WDT;
208 rt288x_sysc_wr(t, SYSC_REG_CLKCFG);
210 platform_device_register(&rt288x_wdt_device);