46bf460d9c35a2912d6301e30792184886fc8f9a
[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/mtd/mtd.h>
14 #include <linux/mtd/physmap.h>
15
16 #include <asm/addrspace.h>
17
18 #include <asm/mach-ralink/rt305x.h>
19 #include <asm/mach-ralink/rt305x_regs.h>
20 #include "devices.h"
21
22 #include <ramips_eth_platform.h>
23
24 static struct resource rt305x_flash0_resources[] = {
25 {
26 .flags = IORESOURCE_MEM,
27 .start = KSEG1ADDR(RT305X_FLASH0_BASE),
28 .end = KSEG1ADDR(RT305X_FLASH0_BASE) +
29 RT305X_FLASH0_SIZE - 1,
30 },
31 };
32
33 static struct platform_device rt305x_flash0_device = {
34 .name = "physmap-flash",
35 .resource = rt305x_flash0_resources,
36 .num_resources = ARRAY_SIZE(rt305x_flash0_resources),
37 };
38
39 static struct resource rt305x_flash1_resources[] = {
40 {
41 .flags = IORESOURCE_MEM,
42 .start = KSEG1ADDR(RT305X_FLASH1_BASE),
43 .end = KSEG1ADDR(RT305X_FLASH1_BASE) +
44 RT305X_FLASH1_SIZE - 1,
45 },
46 };
47
48 static struct platform_device rt305x_flash1_device = {
49 .name = "physmap-flash",
50 .resource = rt305x_flash1_resources,
51 .num_resources = ARRAY_SIZE(rt305x_flash1_resources),
52 };
53
54 static int rt305x_flash_instance __initdata;
55 void __init rt305x_register_flash(unsigned int id,
56 struct physmap_flash_data *pdata)
57 {
58 struct platform_device *pdev;
59 u32 t;
60 int reg;
61
62 switch (id) {
63 case 0:
64 pdev = &rt305x_flash0_device;
65 reg = MEMC_REG_FLASH_CFG0;
66 break;
67 case 1:
68 pdev = &rt305x_flash1_device;
69 reg = MEMC_REG_FLASH_CFG1;
70 break;
71 default:
72 return;
73 }
74
75 t = rt305x_memc_rr(reg);
76 t = (t >> FLASH_CFG_WIDTH_SHIFT) & FLASH_CFG_WIDTH_MASK;
77
78 switch (t) {
79 case FLASH_CFG_WIDTH_8BIT:
80 pdata->width = 1;
81 break;
82 case FLASH_CFG_WIDTH_16BIT:
83 pdata->width = 2;
84 break;
85 case FLASH_CFG_WIDTH_32BIT:
86 pdata->width = 4;
87 break;
88 default:
89 printk(KERN_ERR "RT305x: flash bank%u witdh is invalid\n", id);
90 return;
91 }
92
93 pdev->dev.platform_data = pdata;
94 pdev->id = rt305x_flash_instance;
95
96 platform_device_register(pdev);
97 rt305x_flash_instance++;
98 }
99
100 static void rt305x_fe_reset(void)
101 {
102 rt305x_sysc_wr(RT305X_RESET_FE, SYSC_REG_RESET_CTRL);
103 rt305x_sysc_wr(0, SYSC_REG_RESET_CTRL);
104 }
105
106 static struct resource rt305x_eth_resources[] = {
107 {
108 .start = RT305X_FE_BASE,
109 .end = RT305X_FE_BASE + PAGE_SIZE - 1,
110 .flags = IORESOURCE_MEM,
111 }, {
112 .start = RT305X_CPU_IRQ_FE,
113 .end = RT305X_CPU_IRQ_FE,
114 .flags = IORESOURCE_IRQ,
115 },
116 };
117
118 static struct ramips_eth_platform_data ramips_eth_data = {
119 .mac = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 },
120 .reset_fe = rt305x_fe_reset,
121 .min_pkt_len = 64,
122 };
123
124 static struct platform_device rt305x_eth_device = {
125 .name = "ramips_eth",
126 .resource = rt305x_eth_resources,
127 .num_resources = ARRAY_SIZE(rt305x_eth_resources),
128 .dev = {
129 .platform_data = &ramips_eth_data,
130 }
131 };
132
133 static struct resource rt305x_esw_resources[] = {
134 {
135 .start = RT305X_SWITCH_BASE,
136 .end = RT305X_SWITCH_BASE + PAGE_SIZE - 1,
137 .flags = IORESOURCE_MEM,
138 },
139 };
140
141 struct rt305x_esw_platform_data rt305x_esw_data;
142 static struct platform_device rt305x_esw_device = {
143 .name = "rt305x-esw",
144 .resource = rt305x_esw_resources,
145 .num_resources = ARRAY_SIZE(rt305x_esw_resources),
146 .dev = {
147 .platform_data = &rt305x_esw_data,
148 }
149 };
150
151 void __init rt305x_register_ethernet(void)
152 {
153 ramips_eth_data.sys_freq = rt305x_sys_freq;
154
155 platform_device_register(&rt305x_esw_device);
156 platform_device_register(&rt305x_eth_device);
157 }
158
159 static struct resource rt305x_wifi_resources[] = {
160 {
161 .start = RT305X_WMAC_BASE,
162 .end = RT305X_WMAC_BASE + 0x3FFFF,
163 .flags = IORESOURCE_MEM,
164 }, {
165 .start = RT305X_CPU_IRQ_WNIC,
166 .end = RT305X_CPU_IRQ_WNIC,
167 .flags = IORESOURCE_IRQ,
168 },
169 };
170
171 static struct platform_device rt305x_wifi_device = {
172 .name = "rt2800_wmac",
173 .resource = rt305x_wifi_resources,
174 .num_resources = ARRAY_SIZE(rt305x_wifi_resources),
175 .dev = {
176 .platform_data = NULL,
177 }
178 };
179
180 void __init rt305x_register_wifi(void)
181 {
182 platform_device_register(&rt305x_wifi_device);
183 }