3b575f6208f7cc74a55874cc1de6f70aef9a025c
[openwrt/svn-archive/archive.git] / target / linux / ramips / files / arch / mips / ralink / rt288x / devices.c
1 /*
2 * Ralink RT288x SoC platform device registration
3 *
4 * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
6 *
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.
10 */
11
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
18 #include <asm/addrspace.h>
19
20 #include <asm/mach-ralink/rt288x.h>
21 #include <asm/mach-ralink/rt288x_regs.h>
22 #include <asm/mach-ralink/ramips_eth_platform.h>
23
24 #include "devices.h"
25
26 static struct resource rt288x_flash0_resources[] = {
27 {
28 .flags = IORESOURCE_MEM,
29 .start = KSEG1ADDR(RT2880_FLASH0_BASE),
30 .end = KSEG1ADDR(RT2880_FLASH0_BASE) +
31 RT2880_FLASH0_SIZE - 1,
32 },
33 };
34
35 static struct platform_device rt288x_flash0_device = {
36 .name = "physmap-flash",
37 .resource = rt288x_flash0_resources,
38 .num_resources = ARRAY_SIZE(rt288x_flash0_resources),
39 };
40
41 static struct resource rt288x_flash1_resources[] = {
42 {
43 .flags = IORESOURCE_MEM,
44 .start = KSEG1ADDR(RT2880_FLASH1_BASE),
45 .end = KSEG1ADDR(RT2880_FLASH1_BASE) +
46 RT2880_FLASH1_SIZE - 1,
47 },
48 };
49
50 static struct platform_device rt288x_flash1_device = {
51 .name = "physmap-flash",
52 .resource = rt288x_flash1_resources,
53 .num_resources = ARRAY_SIZE(rt288x_flash1_resources),
54 };
55
56 static int rt288x_flash_instance __initdata;
57 void __init rt288x_register_flash(unsigned int id,
58 struct physmap_flash_data *pdata)
59 {
60 struct platform_device *pdev;
61 u32 t;
62 int reg;
63
64 switch (id) {
65 case 0:
66 pdev = &rt288x_flash0_device;
67 reg = MEMC_REG_FLASH_CFG0;
68 break;
69 case 1:
70 pdev = &rt288x_flash1_device;
71 reg = MEMC_REG_FLASH_CFG1;
72 break;
73 default:
74 return;
75 }
76
77 t = rt288x_memc_rr(reg);
78 t = (t >> FLASH_CFG_WIDTH_SHIFT) & FLASH_CFG_WIDTH_MASK;
79
80 switch (t) {
81 case FLASH_CFG_WIDTH_8BIT:
82 pdata->width = 1;
83 break;
84 case FLASH_CFG_WIDTH_16BIT:
85 pdata->width = 2;
86 break;
87 case FLASH_CFG_WIDTH_32BIT:
88 pdata->width = 4;
89 break;
90 default:
91 printk(KERN_ERR "RT288x: flash bank%u witdh is invalid\n", id);
92 return;
93 }
94
95 pdev->dev.platform_data = pdata;
96 pdev->id = rt288x_flash_instance;
97
98 platform_device_register(pdev);
99 rt288x_flash_instance++;
100 }
101
102 static struct resource rt288x_wifi_resources[] = {
103 {
104 .start = RT2880_WMAC_BASE,
105 .end = RT2880_WMAC_BASE + 0x3FFFF,
106 .flags = IORESOURCE_MEM,
107 }, {
108 .start = RT288X_CPU_IRQ_WNIC,
109 .end = RT288X_CPU_IRQ_WNIC,
110 .flags = IORESOURCE_IRQ,
111 },
112 };
113
114 static struct platform_device rt288x_wifi_device = {
115 .name = "rt2800_wmac",
116 .resource = rt288x_wifi_resources,
117 .num_resources = ARRAY_SIZE(rt288x_wifi_resources),
118 .dev = {
119 .platform_data = NULL,
120 }
121 };
122
123 void __init rt288x_register_wifi(void)
124 {
125 platform_device_register(&rt288x_wifi_device);
126 }
127
128 static void rt288x_fe_reset(void)
129 {
130 rt288x_sysc_wr(RT2880_RESET_FE, SYSC_REG_RESET_CTRL);
131 }
132
133 static struct resource rt288x_eth_resources[] = {
134 {
135 .start = RT2880_FE_BASE,
136 .end = RT2880_FE_BASE + PAGE_SIZE - 1,
137 .flags = IORESOURCE_MEM,
138 }, {
139 .start = RT288X_CPU_IRQ_FE,
140 .end = RT288X_CPU_IRQ_FE,
141 .flags = IORESOURCE_IRQ,
142 },
143 };
144
145 struct ramips_eth_platform_data rt288x_eth_data;
146 static struct platform_device rt288x_eth_device = {
147 .name = "ramips_eth",
148 .resource = rt288x_eth_resources,
149 .num_resources = ARRAY_SIZE(rt288x_eth_resources),
150 .dev = {
151 .platform_data = &rt288x_eth_data,
152 }
153 };
154
155 void __init rt288x_register_ethernet(void)
156 {
157 rt288x_eth_data.sys_freq = rt288x_sys_freq;
158 rt288x_eth_data.reset_fe = rt288x_fe_reset;
159 rt288x_eth_data.min_pkt_len = 64;
160
161 if (!is_valid_ether_addr(rt288x_eth_data.mac))
162 random_ether_addr(rt288x_eth_data.mac);
163
164 platform_device_register(&rt288x_eth_device);
165 }