ramips: rt305x: introduce rt305x_register_spi helper
[openwrt/openwrt.git] / target / linux / ramips / files / arch / mips / ralink / rt305x / devices.c
1 /*
2 * Ralink RT305x SoC platform device registration
3 *
4 * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
9 */
10
11 #include <linux/kernel.h>
12 #include <linux/platform_device.h>
13 #include <linux/err.h>
14 #include <linux/clk.h>
15 #include <linux/mtd/mtd.h>
16 #include <linux/mtd/physmap.h>
17 #include <linux/spi/spi.h>
18 #include <linux/rt2x00_platform.h>
19
20 #include <asm/addrspace.h>
21
22 #include <asm/mach-ralink/rt305x.h>
23 #include <asm/mach-ralink/rt305x_regs.h>
24 #include "devices.h"
25
26 #include <ramips_eth_platform.h>
27
28 static struct resource rt305x_flash0_resources[] = {
29 {
30 .flags = IORESOURCE_MEM,
31 .start = KSEG1ADDR(RT305X_FLASH0_BASE),
32 .end = KSEG1ADDR(RT305X_FLASH0_BASE) +
33 RT305X_FLASH0_SIZE - 1,
34 },
35 };
36
37 static struct platform_device rt305x_flash0_device = {
38 .name = "physmap-flash",
39 .resource = rt305x_flash0_resources,
40 .num_resources = ARRAY_SIZE(rt305x_flash0_resources),
41 };
42
43 static struct resource rt305x_flash1_resources[] = {
44 {
45 .flags = IORESOURCE_MEM,
46 .start = KSEG1ADDR(RT305X_FLASH1_BASE),
47 .end = KSEG1ADDR(RT305X_FLASH1_BASE) +
48 RT305X_FLASH1_SIZE - 1,
49 },
50 };
51
52 static struct platform_device rt305x_flash1_device = {
53 .name = "physmap-flash",
54 .resource = rt305x_flash1_resources,
55 .num_resources = ARRAY_SIZE(rt305x_flash1_resources),
56 };
57
58 static int rt305x_flash_instance __initdata;
59 void __init rt305x_register_flash(unsigned int id,
60 struct physmap_flash_data *pdata)
61 {
62 struct platform_device *pdev;
63 u32 t;
64 int reg;
65
66 switch (id) {
67 case 0:
68 pdev = &rt305x_flash0_device;
69 reg = MEMC_REG_FLASH_CFG0;
70 break;
71 case 1:
72 pdev = &rt305x_flash1_device;
73 reg = MEMC_REG_FLASH_CFG1;
74 break;
75 default:
76 return;
77 }
78
79 t = rt305x_memc_rr(reg);
80 t = (t >> FLASH_CFG_WIDTH_SHIFT) & FLASH_CFG_WIDTH_MASK;
81
82 switch (t) {
83 case FLASH_CFG_WIDTH_8BIT:
84 pdata->width = 1;
85 break;
86 case FLASH_CFG_WIDTH_16BIT:
87 pdata->width = 2;
88 break;
89 case FLASH_CFG_WIDTH_32BIT:
90 pdata->width = 4;
91 break;
92 default:
93 printk(KERN_ERR "RT305x: flash bank%u witdh is invalid\n", id);
94 return;
95 }
96
97 pdev->dev.platform_data = pdata;
98 pdev->id = rt305x_flash_instance;
99
100 platform_device_register(pdev);
101 rt305x_flash_instance++;
102 }
103
104 static void rt305x_fe_reset(void)
105 {
106 rt305x_sysc_wr(RT305X_RESET_FE, SYSC_REG_RESET_CTRL);
107 rt305x_sysc_wr(0, SYSC_REG_RESET_CTRL);
108 }
109
110 static struct resource rt305x_eth_resources[] = {
111 {
112 .start = RT305X_FE_BASE,
113 .end = RT305X_FE_BASE + PAGE_SIZE - 1,
114 .flags = IORESOURCE_MEM,
115 }, {
116 .start = RT305X_CPU_IRQ_FE,
117 .end = RT305X_CPU_IRQ_FE,
118 .flags = IORESOURCE_IRQ,
119 },
120 };
121
122 static struct ramips_eth_platform_data ramips_eth_data = {
123 .mac = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 },
124 .reset_fe = rt305x_fe_reset,
125 .min_pkt_len = 64,
126 };
127
128 static struct platform_device rt305x_eth_device = {
129 .name = "ramips_eth",
130 .resource = rt305x_eth_resources,
131 .num_resources = ARRAY_SIZE(rt305x_eth_resources),
132 .dev = {
133 .platform_data = &ramips_eth_data,
134 }
135 };
136
137 static struct resource rt305x_esw_resources[] = {
138 {
139 .start = RT305X_SWITCH_BASE,
140 .end = RT305X_SWITCH_BASE + PAGE_SIZE - 1,
141 .flags = IORESOURCE_MEM,
142 },
143 };
144
145 struct rt305x_esw_platform_data rt305x_esw_data;
146 static struct platform_device rt305x_esw_device = {
147 .name = "rt305x-esw",
148 .resource = rt305x_esw_resources,
149 .num_resources = ARRAY_SIZE(rt305x_esw_resources),
150 .dev = {
151 .platform_data = &rt305x_esw_data,
152 }
153 };
154
155 void __init rt305x_register_ethernet(void)
156 {
157 struct clk *clk;
158
159 clk = clk_get(NULL, "sys");
160 if (IS_ERR(clk))
161 panic("unable to get SYS clock, err=%ld", PTR_ERR(clk));
162
163 ramips_eth_data.sys_freq = clk_get_rate(clk);
164
165 platform_device_register(&rt305x_esw_device);
166 platform_device_register(&rt305x_eth_device);
167 }
168
169 static struct resource rt305x_wifi_resources[] = {
170 {
171 .start = RT305X_WMAC_BASE,
172 .end = RT305X_WMAC_BASE + 0x3FFFF,
173 .flags = IORESOURCE_MEM,
174 }, {
175 .start = RT305X_CPU_IRQ_WNIC,
176 .end = RT305X_CPU_IRQ_WNIC,
177 .flags = IORESOURCE_IRQ,
178 },
179 };
180
181 static struct rt2x00_platform_data rt305x_wifi_data;
182 static struct platform_device rt305x_wifi_device = {
183 .name = "rt2800_wmac",
184 .resource = rt305x_wifi_resources,
185 .num_resources = ARRAY_SIZE(rt305x_wifi_resources),
186 .dev = {
187 .platform_data = &rt305x_wifi_data,
188 }
189 };
190
191 void __init rt305x_register_wifi(void)
192 {
193 rt305x_wifi_data.eeprom_file_name = "RT305X.eeprom";
194 platform_device_register(&rt305x_wifi_device);
195 }
196
197 static struct resource rt305x_wdt_resources[] = {
198 {
199 .start = RT305X_TIMER_BASE,
200 .end = RT305X_TIMER_BASE + RT305X_TIMER_SIZE - 1,
201 .flags = IORESOURCE_MEM,
202 },
203 };
204
205 static struct platform_device rt305x_wdt_device = {
206 .name = "ramips-wdt",
207 .id = -1,
208 .resource = rt305x_wdt_resources,
209 .num_resources = ARRAY_SIZE(rt305x_wdt_resources),
210 };
211
212 void __init rt305x_register_wdt(void)
213 {
214 u32 t;
215
216 /* enable WDT reset output on pin SRAM_CS_N */
217 t = rt305x_sysc_rr(SYSC_REG_SYSTEM_CONFIG);
218 t |= SYSTEM_CONFIG_SRAM_CS0_MODE_WDT <<
219 SYSTEM_CONFIG_SRAM_CS0_MODE_SHIFT;
220 rt305x_sysc_wr(t, SYSC_REG_SYSTEM_CONFIG);
221
222 platform_device_register(&rt305x_wdt_device);
223 }
224
225 static struct resource rt305x_spi_resources[] = {
226 {
227 .flags = IORESOURCE_MEM,
228 .start = RT305X_SPI_BASE,
229 .end = RT305X_SPI_BASE + RT305X_SPI_SIZE - 1,
230 },
231 };
232
233 static struct platform_device rt305x_spi_device = {
234 .name = "ramips-spi",
235 .id = 0,
236 .resource = rt305x_spi_resources,
237 .num_resources = ARRAY_SIZE(rt305x_spi_resources),
238 };
239
240 void __init rt305x_register_spi(struct spi_board_info *info, int n)
241 {
242 spi_register_board_info(info, n);
243 platform_device_register(&rt305x_spi_device);
244 }