Root/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#include <linux/delay.h>
20#include <linux/dma-mapping.h>
21
22#include <asm/addrspace.h>
23
24#include <asm/mach-ralink/rt305x.h>
25#include <asm/mach-ralink/rt305x_regs.h>
26#include "devices.h"
27
28#include <ramips_eth_platform.h>
29#include <rt305x_esw_platform.h>
30#include <rt3883_ehci_platform.h>
31#include <rt3883_ohci_platform.h>
32
33static struct resource rt305x_flash0_resources[] = {
34    {
35        .flags = IORESOURCE_MEM,
36        .start = KSEG1ADDR(RT305X_FLASH0_BASE),
37        .end = KSEG1ADDR(RT305X_FLASH0_BASE) +
38              RT305X_FLASH0_SIZE - 1,
39    },
40};
41
42struct physmap_flash_data rt305x_flash0_data;
43static struct platform_device rt305x_flash0_device = {
44    .name = "physmap-flash",
45    .resource = rt305x_flash0_resources,
46    .num_resources = ARRAY_SIZE(rt305x_flash0_resources),
47    .dev = {
48        .platform_data = &rt305x_flash0_data,
49    },
50};
51
52static struct resource rt305x_flash1_resources[] = {
53    {
54        .flags = IORESOURCE_MEM,
55        .start = KSEG1ADDR(RT305X_FLASH1_BASE),
56        .end = KSEG1ADDR(RT305X_FLASH1_BASE) +
57              RT305X_FLASH1_SIZE - 1,
58    },
59};
60
61struct physmap_flash_data rt305x_flash1_data;
62static struct platform_device rt305x_flash1_device = {
63    .name = "physmap-flash",
64    .resource = rt305x_flash1_resources,
65    .num_resources = ARRAY_SIZE(rt305x_flash1_resources),
66    .dev = {
67        .platform_data = &rt305x_flash1_data,
68    },
69};
70
71static int rt305x_flash_instance __initdata;
72void __init rt305x_register_flash(unsigned int id)
73{
74    struct platform_device *pdev;
75    struct physmap_flash_data *pdata;
76    u32 t;
77    int reg;
78
79    switch (id) {
80    case 0:
81        pdev = &rt305x_flash0_device;
82        reg = MEMC_REG_FLASH_CFG0;
83        break;
84    case 1:
85        pdev = &rt305x_flash1_device;
86        reg = MEMC_REG_FLASH_CFG1;
87        break;
88    default:
89        return;
90    }
91
92    t = rt305x_memc_rr(reg);
93    t = (t >> FLASH_CFG_WIDTH_SHIFT) & FLASH_CFG_WIDTH_MASK;
94
95    pdata = pdev->dev.platform_data;
96    switch (t) {
97    case FLASH_CFG_WIDTH_8BIT:
98        pdata->width = 1;
99        break;
100    case FLASH_CFG_WIDTH_16BIT:
101        pdata->width = 2;
102        break;
103    case FLASH_CFG_WIDTH_32BIT:
104        pdata->width = 4;
105        break;
106    default:
107        printk(KERN_ERR "RT305x: flash bank%u witdh is invalid\n", id);
108        return;
109    }
110
111    pdev->id = rt305x_flash_instance;
112
113    platform_device_register(pdev);
114    rt305x_flash_instance++;
115}
116
117static void rt305x_fe_reset(void)
118{
119    rt305x_sysc_wr(RT305X_RESET_FE, SYSC_REG_RESET_CTRL);
120    rt305x_sysc_wr(0, SYSC_REG_RESET_CTRL);
121}
122
123static struct resource rt305x_eth_resources[] = {
124    {
125        .start = RT305X_FE_BASE,
126        .end = RT305X_FE_BASE + PAGE_SIZE - 1,
127        .flags = IORESOURCE_MEM,
128    }, {
129        .start = RT305X_CPU_IRQ_FE,
130        .end = RT305X_CPU_IRQ_FE,
131        .flags = IORESOURCE_IRQ,
132    },
133};
134
135static struct ramips_eth_platform_data ramips_eth_data = {
136    .mac = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 },
137    .reset_fe = rt305x_fe_reset,
138    .min_pkt_len = 64,
139};
140
141static struct platform_device rt305x_eth_device = {
142    .name = "ramips_eth",
143    .resource = rt305x_eth_resources,
144    .num_resources = ARRAY_SIZE(rt305x_eth_resources),
145    .dev = {
146        .platform_data = &ramips_eth_data,
147    }
148};
149
150static struct resource rt305x_esw_resources[] = {
151    {
152        .start = RT305X_SWITCH_BASE,
153        .end = RT305X_SWITCH_BASE + PAGE_SIZE - 1,
154        .flags = IORESOURCE_MEM,
155    },
156};
157
158struct rt305x_esw_platform_data rt305x_esw_data = {
159    /* All ports are LAN ports. */
160    .vlan_config = RT305X_ESW_VLAN_CONFIG_NONE,
161    .reg_initval_fct2 = 0x00d6500c,
162    /*
163     * ext phy base addr 31, enable port 5 polling, rx/tx clock skew 1,
164     * turbo mii off, rgmi 3.3v off
165     * port5: disabled
166     * port6: enabled, gige, full-duplex, rx/tx-flow-control
167     */
168    .reg_initval_fpa2 = 0x3f502b28,
169};
170
171static struct platform_device rt305x_esw_device = {
172    .name = "rt305x-esw",
173    .resource = rt305x_esw_resources,
174    .num_resources = ARRAY_SIZE(rt305x_esw_resources),
175    .dev = {
176        .platform_data = &rt305x_esw_data,
177    }
178};
179
180void __init rt305x_register_ethernet(void)
181{
182    struct clk *clk;
183
184    clk = clk_get(NULL, "sys");
185    if (IS_ERR(clk))
186        panic("unable to get SYS clock, err=%ld", PTR_ERR(clk));
187
188    ramips_eth_data.sys_freq = clk_get_rate(clk);
189
190    platform_device_register(&rt305x_esw_device);
191    platform_device_register(&rt305x_eth_device);
192}
193
194static struct resource rt305x_wifi_resources[] = {
195    {
196        .start = RT305X_WMAC_BASE,
197        .end = RT305X_WMAC_BASE + 0x3FFFF,
198        .flags = IORESOURCE_MEM,
199    }, {
200        .start = RT305X_CPU_IRQ_WNIC,
201        .end = RT305X_CPU_IRQ_WNIC,
202        .flags = IORESOURCE_IRQ,
203    },
204};
205
206static struct rt2x00_platform_data rt305x_wifi_data;
207static struct platform_device rt305x_wifi_device = {
208    .name = "rt2800_wmac",
209    .resource = rt305x_wifi_resources,
210    .num_resources = ARRAY_SIZE(rt305x_wifi_resources),
211    .dev = {
212        .platform_data = &rt305x_wifi_data,
213    }
214};
215
216void __init rt305x_register_wifi(void)
217{
218    rt305x_wifi_data.eeprom_file_name = "RT305X.eeprom";
219    platform_device_register(&rt305x_wifi_device);
220}
221
222static struct resource rt305x_wdt_resources[] = {
223    {
224        .start = RT305X_TIMER_BASE,
225        .end = RT305X_TIMER_BASE + RT305X_TIMER_SIZE - 1,
226        .flags = IORESOURCE_MEM,
227    },
228};
229
230static struct platform_device rt305x_wdt_device = {
231    .name = "ramips-wdt",
232    .id = -1,
233    .resource = rt305x_wdt_resources,
234    .num_resources = ARRAY_SIZE(rt305x_wdt_resources),
235};
236
237void __init rt305x_register_wdt(void)
238{
239    u32 t;
240
241    /* enable WDT reset output on pin SRAM_CS_N */
242    t = rt305x_sysc_rr(SYSC_REG_SYSTEM_CONFIG);
243    t |= RT305X_SYSCFG_SRAM_CS0_MODE_WDT <<
244         RT305X_SYSCFG_SRAM_CS0_MODE_SHIFT;
245    rt305x_sysc_wr(t, SYSC_REG_SYSTEM_CONFIG);
246
247    platform_device_register(&rt305x_wdt_device);
248}
249
250static struct resource rt305x_spi_resources[] = {
251    {
252        .flags = IORESOURCE_MEM,
253        .start = RT305X_SPI_BASE,
254        .end = RT305X_SPI_BASE + RT305X_SPI_SIZE - 1,
255    },
256};
257
258static struct platform_device rt305x_spi_device = {
259    .name = "ramips-spi",
260    .id = 0,
261    .resource = rt305x_spi_resources,
262    .num_resources = ARRAY_SIZE(rt305x_spi_resources),
263};
264
265void __init rt305x_register_spi(struct spi_board_info *info, int n)
266{
267    spi_register_board_info(info, n);
268    platform_device_register(&rt305x_spi_device);
269}
270
271static struct resource rt305x_dwc_otg_resources[] = {
272    {
273        .start = RT305X_OTG_BASE,
274        .end = RT305X_OTG_BASE + 0x3FFFF,
275        .flags = IORESOURCE_MEM,
276    }, {
277        .start = RT305X_INTC_IRQ_OTG,
278        .end = RT305X_INTC_IRQ_OTG,
279        .flags = IORESOURCE_IRQ,
280    },
281};
282
283static struct platform_device rt305x_dwc_otg_device = {
284    .name = "dwc_otg",
285    .resource = rt305x_dwc_otg_resources,
286    .num_resources = ARRAY_SIZE(rt305x_dwc_otg_resources),
287    .dev = {
288        .platform_data = NULL,
289    }
290};
291
292static atomic_t rt3352_usb_use_count = ATOMIC_INIT(0);
293
294static void rt3352_usb_host_start(void)
295{
296    u32 t;
297
298    if (atomic_inc_return(&rt3352_usb_use_count) != 1)
299        return;
300
301    t = rt305x_sysc_rr(RT3352_SYSC_REG_USB_PS);
302
303    /* enable clock for port0's and port1's phys */
304    t = rt305x_sysc_rr(RT3352_SYSC_REG_CLKCFG1);
305    t = t | RT3352_CLKCFG1_UPHY0_CLK_EN | RT3352_CLKCFG1_UPHY1_CLK_EN;
306    rt305x_sysc_wr(t, RT3352_SYSC_REG_CLKCFG1);
307    mdelay(500);
308
309    /* pull USBHOST and USBDEV out from reset */
310    t = rt305x_sysc_rr(RT3352_SYSC_REG_RSTCTRL);
311    t &= ~(RT3352_RSTCTRL_UHST | RT3352_RSTCTRL_UDEV);
312    rt305x_sysc_wr(t, RT3352_SYSC_REG_RSTCTRL);
313    mdelay(500);
314
315    /* enable host mode */
316    t = rt305x_sysc_rr(RT3352_SYSC_REG_SYSCFG1);
317    t |= RT3352_SYSCFG1_USB0_HOST_MODE;
318    rt305x_sysc_wr(t, RT3352_SYSC_REG_SYSCFG1);
319
320    t = rt305x_sysc_rr(RT3352_SYSC_REG_USB_PS);
321}
322
323static void rt3352_usb_host_stop(void)
324{
325    u32 t;
326
327    if (atomic_dec_return(&rt3352_usb_use_count) != 0)
328        return;
329
330    /* put USBHOST and USBDEV into reset */
331    t = rt305x_sysc_rr(RT3352_SYSC_REG_RSTCTRL);
332    t |= RT3352_RSTCTRL_UHST | RT3352_RSTCTRL_UDEV;
333    rt305x_sysc_wr(t, RT3352_SYSC_REG_RSTCTRL);
334    udelay(10000);
335
336    /* disable clock for port0's and port1's phys*/
337    t = rt305x_sysc_rr(RT3352_SYSC_REG_CLKCFG1);
338    t &= ~(RT3352_CLKCFG1_UPHY0_CLK_EN | RT3352_CLKCFG1_UPHY1_CLK_EN);
339    rt305x_sysc_wr(t, RT3352_SYSC_REG_CLKCFG1);
340    udelay(10000);
341}
342
343static struct rt3883_ehci_platform_data rt3352_ehci_data = {
344    .start_hw = rt3352_usb_host_start,
345    .stop_hw = rt3352_usb_host_stop,
346};
347
348static struct resource rt3352_ehci_resources[] = {
349    {
350        .start = RT3352_EHCI_BASE,
351        .end = RT3352_EHCI_BASE + RT3352_EHCI_SIZE - 1,
352        .flags = IORESOURCE_MEM,
353    }, {
354        .start = RT305X_INTC_IRQ_OTG,
355        .end = RT305X_INTC_IRQ_OTG,
356        .flags = IORESOURCE_IRQ,
357    },
358};
359
360static u64 rt3352_ehci_dmamask = DMA_BIT_MASK(32);
361static struct platform_device rt3352_ehci_device = {
362    .name = "rt3883-ehci",
363    .id = -1,
364    .resource = rt3352_ehci_resources,
365    .num_resources = ARRAY_SIZE(rt3352_ehci_resources),
366    .dev = {
367        .dma_mask = &rt3352_ehci_dmamask,
368        .coherent_dma_mask = DMA_BIT_MASK(32),
369        .platform_data = &rt3352_ehci_data,
370    },
371};
372
373static struct resource rt3352_ohci_resources[] = {
374    {
375        .start = RT3352_OHCI_BASE,
376        .end = RT3352_OHCI_BASE + RT3352_OHCI_SIZE - 1,
377        .flags = IORESOURCE_MEM,
378    }, {
379        .start = RT305X_INTC_IRQ_OTG,
380        .end = RT305X_INTC_IRQ_OTG,
381        .flags = IORESOURCE_IRQ,
382    },
383};
384
385static struct rt3883_ohci_platform_data rt3352_ohci_data = {
386    .start_hw = rt3352_usb_host_start,
387    .stop_hw = rt3352_usb_host_stop,
388};
389
390static u64 rt3352_ohci_dmamask = DMA_BIT_MASK(32);
391static struct platform_device rt3352_ohci_device = {
392    .name = "rt3883-ohci",
393    .id = -1,
394    .resource = rt3352_ohci_resources,
395    .num_resources = ARRAY_SIZE(rt3352_ohci_resources),
396    .dev = {
397        .dma_mask = &rt3352_ohci_dmamask,
398        .coherent_dma_mask = DMA_BIT_MASK(32),
399        .platform_data = &rt3352_ohci_data,
400    },
401};
402
403void __init rt305x_register_usb(void)
404{
405    if (soc_is_rt305x() || soc_is_rt3350()) {
406        platform_device_register(&rt305x_dwc_otg_device);
407    } else if (soc_is_rt3352() || soc_is_rt5350()) {
408        platform_device_register(&rt3352_ehci_device);
409        platform_device_register(&rt3352_ohci_device);
410    } else {
411        BUG();
412    }
413}
414

Archive Download this file



interactive