Root/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#include <linux/rt2x00_platform.h>
20
21#include <asm/addrspace.h>
22
23#include <asm/mach-ralink/rt288x.h>
24#include <asm/mach-ralink/rt288x_regs.h>
25#include <asm/mach-ralink/ramips_eth_platform.h>
26
27#include "devices.h"
28
29static struct resource rt288x_flash0_resources[] = {
30    {
31        .flags = IORESOURCE_MEM,
32        .start = KSEG1ADDR(RT2880_FLASH0_BASE),
33        .end = KSEG1ADDR(RT2880_FLASH0_BASE) +
34              RT2880_FLASH0_SIZE - 1,
35    },
36};
37
38static struct platform_device rt288x_flash0_device = {
39    .name = "physmap-flash",
40    .resource = rt288x_flash0_resources,
41    .num_resources = ARRAY_SIZE(rt288x_flash0_resources),
42};
43
44static struct resource rt288x_flash1_resources[] = {
45    {
46        .flags = IORESOURCE_MEM,
47        .start = KSEG1ADDR(RT2880_FLASH1_BASE),
48        .end = KSEG1ADDR(RT2880_FLASH1_BASE) +
49              RT2880_FLASH1_SIZE - 1,
50    },
51};
52
53static struct platform_device rt288x_flash1_device = {
54    .name = "physmap-flash",
55    .resource = rt288x_flash1_resources,
56    .num_resources = ARRAY_SIZE(rt288x_flash1_resources),
57};
58
59static int rt288x_flash_instance __initdata;
60void __init rt288x_register_flash(unsigned int id,
61                  struct physmap_flash_data *pdata)
62{
63    struct platform_device *pdev;
64    u32 t;
65    int reg;
66
67    switch (id) {
68    case 0:
69        pdev = &rt288x_flash0_device;
70        reg = MEMC_REG_FLASH_CFG0;
71        break;
72    case 1:
73        pdev = &rt288x_flash1_device;
74        reg = MEMC_REG_FLASH_CFG1;
75        break;
76    default:
77        return;
78    }
79
80    t = rt288x_memc_rr(reg);
81    t = (t >> FLASH_CFG_WIDTH_SHIFT) & FLASH_CFG_WIDTH_MASK;
82
83    switch (t) {
84    case FLASH_CFG_WIDTH_8BIT:
85        pdata->width = 1;
86        break;
87    case FLASH_CFG_WIDTH_16BIT:
88        pdata->width = 2;
89        break;
90    case FLASH_CFG_WIDTH_32BIT:
91        pdata->width = 4;
92        break;
93    default:
94        printk(KERN_ERR "RT288x: flash bank%u witdh is invalid\n", id);
95        return;
96    }
97
98    pdev->dev.platform_data = pdata;
99    pdev->id = rt288x_flash_instance;
100
101    platform_device_register(pdev);
102    rt288x_flash_instance++;
103}
104
105static struct resource rt288x_wifi_resources[] = {
106    {
107        .start = RT2880_WMAC_BASE,
108        .end = RT2880_WMAC_BASE + 0x3FFFF,
109        .flags = IORESOURCE_MEM,
110    }, {
111        .start = RT288X_CPU_IRQ_WNIC,
112        .end = RT288X_CPU_IRQ_WNIC,
113        .flags = IORESOURCE_IRQ,
114    },
115};
116
117static struct rt2x00_platform_data rt288x_wifi_data;
118static struct platform_device rt288x_wifi_device = {
119    .name = "rt2800_wmac",
120    .resource = rt288x_wifi_resources,
121    .num_resources = ARRAY_SIZE(rt288x_wifi_resources),
122    .dev = {
123        .platform_data = &rt288x_wifi_data,
124    }
125};
126
127void __init rt288x_register_wifi(void)
128{
129    rt288x_wifi_data.eeprom_file_name = "RT288X.eeprom";
130    platform_device_register(&rt288x_wifi_device);
131}
132
133static void rt288x_fe_reset(void)
134{
135    rt288x_sysc_wr(RT2880_RESET_FE, SYSC_REG_RESET_CTRL);
136}
137
138static struct resource rt288x_eth_resources[] = {
139    {
140        .start = RT2880_FE_BASE,
141        .end = RT2880_FE_BASE + PAGE_SIZE - 1,
142        .flags = IORESOURCE_MEM,
143    }, {
144        .start = RT288X_CPU_IRQ_FE,
145        .end = RT288X_CPU_IRQ_FE,
146        .flags = IORESOURCE_IRQ,
147    },
148};
149
150struct ramips_eth_platform_data rt288x_eth_data;
151static struct platform_device rt288x_eth_device = {
152    .name = "ramips_eth",
153    .resource = rt288x_eth_resources,
154    .num_resources = ARRAY_SIZE(rt288x_eth_resources),
155    .dev = {
156        .platform_data = &rt288x_eth_data,
157    }
158};
159
160void __init rt288x_register_ethernet(void)
161{
162    struct clk *clk;
163
164    clk = clk_get(NULL, "sys");
165    if (IS_ERR(clk))
166        panic("unable to get SYS clock, err=%ld", PTR_ERR(clk));
167
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;
171
172    if (!is_valid_ether_addr(rt288x_eth_data.mac))
173        random_ether_addr(rt288x_eth_data.mac);
174
175    platform_device_register(&rt288x_eth_device);
176}
177
178static struct resource rt288x_wdt_resources[] = {
179    {
180        .start = RT2880_TIMER_BASE,
181        .end = RT2880_TIMER_BASE + RT2880_TIMER_SIZE - 1,
182        .flags = IORESOURCE_MEM,
183    },
184};
185
186static struct platform_device rt288x_wdt_device = {
187    .name = "ramips-wdt",
188    .id = -1,
189    .resource = rt288x_wdt_resources,
190    .num_resources = ARRAY_SIZE(rt288x_wdt_resources),
191};
192
193void __init rt288x_register_wdt(void)
194{
195    u32 t;
196
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);
201
202    platform_device_register(&rt288x_wdt_device);
203}
204

Archive Download this file



interactive