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 static struct platform_device rt288x_flash0_device
= {
39 .name
= "physmap-flash",
40 .resource
= rt288x_flash0_resources
,
41 .num_resources
= ARRAY_SIZE(rt288x_flash0_resources
),
44 static struct resource rt288x_flash1_resources
[] = {
46 .flags
= IORESOURCE_MEM
,
47 .start
= KSEG1ADDR(RT2880_FLASH1_BASE
),
48 .end
= KSEG1ADDR(RT2880_FLASH1_BASE
) +
49 RT2880_FLASH1_SIZE
- 1,
53 static struct platform_device rt288x_flash1_device
= {
54 .name
= "physmap-flash",
55 .resource
= rt288x_flash1_resources
,
56 .num_resources
= ARRAY_SIZE(rt288x_flash1_resources
),
59 static int rt288x_flash_instance __initdata
;
60 void __init
rt288x_register_flash(unsigned int id
,
61 struct physmap_flash_data
*pdata
)
63 struct platform_device
*pdev
;
69 pdev
= &rt288x_flash0_device
;
70 reg
= MEMC_REG_FLASH_CFG0
;
73 pdev
= &rt288x_flash1_device
;
74 reg
= MEMC_REG_FLASH_CFG1
;
80 t
= rt288x_memc_rr(reg
);
81 t
= (t
>> FLASH_CFG_WIDTH_SHIFT
) & FLASH_CFG_WIDTH_MASK
;
84 case FLASH_CFG_WIDTH_8BIT
:
87 case FLASH_CFG_WIDTH_16BIT
:
90 case FLASH_CFG_WIDTH_32BIT
:
94 printk(KERN_ERR
"RT288x: flash bank%u witdh is invalid\n", id
);
98 pdev
->dev
.platform_data
= pdata
;
99 pdev
->id
= rt288x_flash_instance
;
101 platform_device_register(pdev
);
102 rt288x_flash_instance
++;
105 static struct resource rt288x_wifi_resources
[] = {
107 .start
= RT2880_WMAC_BASE
,
108 .end
= RT2880_WMAC_BASE
+ 0x3FFFF,
109 .flags
= IORESOURCE_MEM
,
111 .start
= RT288X_CPU_IRQ_WNIC
,
112 .end
= RT288X_CPU_IRQ_WNIC
,
113 .flags
= IORESOURCE_IRQ
,
117 static struct rt2x00_platform_data rt288x_wifi_data
;
118 static struct platform_device rt288x_wifi_device
= {
119 .name
= "rt2800_wmac",
120 .resource
= rt288x_wifi_resources
,
121 .num_resources
= ARRAY_SIZE(rt288x_wifi_resources
),
123 .platform_data
= &rt288x_wifi_data
,
127 void __init
rt288x_register_wifi(void)
129 rt288x_wifi_data
.eeprom_file_name
= "RT288X.eeprom";
130 platform_device_register(&rt288x_wifi_device
);
133 static void rt288x_fe_reset(void)
135 rt288x_sysc_wr(RT2880_RESET_FE
, SYSC_REG_RESET_CTRL
);
138 static struct resource rt288x_eth_resources
[] = {
140 .start
= RT2880_FE_BASE
,
141 .end
= RT2880_FE_BASE
+ PAGE_SIZE
- 1,
142 .flags
= IORESOURCE_MEM
,
144 .start
= RT288X_CPU_IRQ_FE
,
145 .end
= RT288X_CPU_IRQ_FE
,
146 .flags
= IORESOURCE_IRQ
,
150 struct ramips_eth_platform_data rt288x_eth_data
;
151 static struct platform_device rt288x_eth_device
= {
152 .name
= "ramips_eth",
153 .resource
= rt288x_eth_resources
,
154 .num_resources
= ARRAY_SIZE(rt288x_eth_resources
),
156 .platform_data
= &rt288x_eth_data
,
160 void __init
rt288x_register_ethernet(void)
164 clk
= clk_get(NULL
, "sys");
166 panic("unable to get SYS clock, err=%ld", PTR_ERR(clk
));
168 rt288x_eth_data
.sys_freq
= clk_get_rate(clk
);
169 rt288x_eth_data
.reset_fe
= rt288x_fe_reset
;
170 rt288x_eth_data
.min_pkt_len
= 64;
172 if (!is_valid_ether_addr(rt288x_eth_data
.mac
))
173 random_ether_addr(rt288x_eth_data
.mac
);
175 platform_device_register(&rt288x_eth_device
);
178 static struct resource rt288x_wdt_resources
[] = {
180 .start
= RT2880_TIMER_BASE
,
181 .end
= RT2880_TIMER_BASE
+ RT2880_TIMER_SIZE
- 1,
182 .flags
= IORESOURCE_MEM
,
186 static struct platform_device rt288x_wdt_device
= {
187 .name
= "ramips-wdt",
189 .resource
= rt288x_wdt_resources
,
190 .num_resources
= ARRAY_SIZE(rt288x_wdt_resources
),
193 void __init
rt288x_register_wdt(void)
197 /* enable WDT reset output on pin SRAM_CS_N */
198 t
= rt288x_sysc_rr(SYSC_REG_CLKCFG
);
199 t
|= CLKCFG_SRAM_CS_N_WDT
;
200 rt288x_sysc_wr(t
, SYSC_REG_CLKCFG
);
202 platform_device_register(&rt288x_wdt_device
);