ramips: add watchdog device for RT288x
[openwrt.git] / target / linux / ramips / files / arch / mips / ralink / rt288x / devices.c
1 /*
2  *  Ralink RT288x SoC platform device registration
3  *
4  *  Copyright (C) 2008-2011 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 #include <linux/err.h>
18 #include <linux/clk.h>
19
20 #include <asm/addrspace.h>
21
22 #include <asm/mach-ralink/rt288x.h>
23 #include <asm/mach-ralink/rt288x_regs.h>
24 #include <asm/mach-ralink/ramips_eth_platform.h>
25
26 #include "devices.h"
27
28 static struct resource rt288x_flash0_resources[] = {
29         {
30                 .flags  = IORESOURCE_MEM,
31                 .start  = KSEG1ADDR(RT2880_FLASH0_BASE),
32                 .end    = KSEG1ADDR(RT2880_FLASH0_BASE) +
33                           RT2880_FLASH0_SIZE - 1,
34         },
35 };
36
37 static struct platform_device rt288x_flash0_device = {
38         .name           = "physmap-flash",
39         .resource       = rt288x_flash0_resources,
40         .num_resources  = ARRAY_SIZE(rt288x_flash0_resources),
41 };
42
43 static struct resource rt288x_flash1_resources[] = {
44         {
45                 .flags  = IORESOURCE_MEM,
46                 .start  = KSEG1ADDR(RT2880_FLASH1_BASE),
47                 .end    = KSEG1ADDR(RT2880_FLASH1_BASE) +
48                           RT2880_FLASH1_SIZE - 1,
49         },
50 };
51
52 static struct platform_device rt288x_flash1_device = {
53         .name           = "physmap-flash",
54         .resource       = rt288x_flash1_resources,
55         .num_resources  = ARRAY_SIZE(rt288x_flash1_resources),
56 };
57
58 static int rt288x_flash_instance __initdata;
59 void __init rt288x_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 = &rt288x_flash0_device;
69                 reg = MEMC_REG_FLASH_CFG0;
70                 break;
71         case 1:
72                 pdev = &rt288x_flash1_device;
73                 reg = MEMC_REG_FLASH_CFG1;
74                 break;
75         default:
76                 return;
77         }
78
79         t = rt288x_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 "RT288x: flash bank%u witdh is invalid\n", id);
94                 return;
95         }
96
97         pdev->dev.platform_data = pdata;
98         pdev->id = rt288x_flash_instance;
99
100         platform_device_register(pdev);
101         rt288x_flash_instance++;
102 }
103
104 static struct resource rt288x_wifi_resources[] = {
105         {
106                 .start  = RT2880_WMAC_BASE,
107                 .end    = RT2880_WMAC_BASE + 0x3FFFF,
108                 .flags  = IORESOURCE_MEM,
109         }, {
110                 .start  = RT288X_CPU_IRQ_WNIC,
111                 .end    = RT288X_CPU_IRQ_WNIC,
112                 .flags  = IORESOURCE_IRQ,
113         },
114 };
115
116 static struct platform_device rt288x_wifi_device = {
117         .name                   = "rt2800_wmac",
118         .resource               = rt288x_wifi_resources,
119         .num_resources  = ARRAY_SIZE(rt288x_wifi_resources),
120         .dev = {
121                 .platform_data = NULL,
122         }
123 };
124
125 void __init rt288x_register_wifi(void)
126 {
127         platform_device_register(&rt288x_wifi_device);
128 }
129
130 static void rt288x_fe_reset(void)
131 {
132         rt288x_sysc_wr(RT2880_RESET_FE, SYSC_REG_RESET_CTRL);
133 }
134
135 static struct resource rt288x_eth_resources[] = {
136         {
137                 .start  = RT2880_FE_BASE,
138                 .end    = RT2880_FE_BASE + PAGE_SIZE - 1,
139                 .flags  = IORESOURCE_MEM,
140         }, {
141                 .start  = RT288X_CPU_IRQ_FE,
142                 .end    = RT288X_CPU_IRQ_FE,
143                 .flags  = IORESOURCE_IRQ,
144         },
145 };
146
147 struct ramips_eth_platform_data rt288x_eth_data;
148 static struct platform_device rt288x_eth_device = {
149         .name           = "ramips_eth",
150         .resource       = rt288x_eth_resources,
151         .num_resources  = ARRAY_SIZE(rt288x_eth_resources),
152         .dev = {
153                 .platform_data = &rt288x_eth_data,
154         }
155 };
156
157 void __init rt288x_register_ethernet(void)
158 {
159         struct clk *clk;
160
161         clk = clk_get(NULL, "sys");
162         if (IS_ERR(clk))
163                 panic("unable to get SYS clock, err=%ld", PTR_ERR(clk));
164
165         rt288x_eth_data.sys_freq = clk_get_rate(clk);
166         rt288x_eth_data.reset_fe = rt288x_fe_reset;
167         rt288x_eth_data.min_pkt_len = 64;
168
169         if (!is_valid_ether_addr(rt288x_eth_data.mac))
170                 random_ether_addr(rt288x_eth_data.mac);
171
172         platform_device_register(&rt288x_eth_device);
173 }
174
175 static struct resource rt288x_wdt_resources[] = {
176         {
177                 .start  = RT2880_TIMER_BASE,
178                 .end    = RT2880_TIMER_BASE + RT2880_TIMER_SIZE - 1,
179                 .flags  = IORESOURCE_MEM,
180         },
181 };
182
183 static struct platform_device rt288x_wdt_device = {
184         .name           = "ramips-wdt",
185         .id             = -1,
186         .resource       = rt288x_wdt_resources,
187         .num_resources  = ARRAY_SIZE(rt288x_wdt_resources),
188 };
189
190 void __init rt288x_register_wdt(void)
191 {
192         u32 t;
193
194         /* enable WDT reset output on pin SRAM_CS_N */
195         t = rt288x_sysc_rr(SYSC_REG_CLKCFG);
196         t |= CLKCFG_SRAM_CS_N_WDT;
197         rt288x_sysc_wr(t, SYSC_REG_CLKCFG);
198
199         platform_device_register(&rt288x_wdt_device);
200 }