| 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 | |
| 18 | #include <asm/addrspace.h> |
| 19 | |
| 20 | #include <asm/mach-ralink/rt305x.h> |
| 21 | #include <asm/mach-ralink/rt305x_regs.h> |
| 22 | #include "devices.h" |
| 23 | |
| 24 | #include <ramips_eth_platform.h> |
| 25 | |
| 26 | static struct resource rt305x_flash0_resources[] = { |
| 27 | { |
| 28 | .flags = IORESOURCE_MEM, |
| 29 | .start = KSEG1ADDR(RT305X_FLASH0_BASE), |
| 30 | .end = KSEG1ADDR(RT305X_FLASH0_BASE) + |
| 31 | RT305X_FLASH0_SIZE - 1, |
| 32 | }, |
| 33 | }; |
| 34 | |
| 35 | static struct platform_device rt305x_flash0_device = { |
| 36 | .name = "physmap-flash", |
| 37 | .resource = rt305x_flash0_resources, |
| 38 | .num_resources = ARRAY_SIZE(rt305x_flash0_resources), |
| 39 | }; |
| 40 | |
| 41 | static struct resource rt305x_flash1_resources[] = { |
| 42 | { |
| 43 | .flags = IORESOURCE_MEM, |
| 44 | .start = KSEG1ADDR(RT305X_FLASH1_BASE), |
| 45 | .end = KSEG1ADDR(RT305X_FLASH1_BASE) + |
| 46 | RT305X_FLASH1_SIZE - 1, |
| 47 | }, |
| 48 | }; |
| 49 | |
| 50 | static struct platform_device rt305x_flash1_device = { |
| 51 | .name = "physmap-flash", |
| 52 | .resource = rt305x_flash1_resources, |
| 53 | .num_resources = ARRAY_SIZE(rt305x_flash1_resources), |
| 54 | }; |
| 55 | |
| 56 | static int rt305x_flash_instance __initdata; |
| 57 | void __init rt305x_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 = &rt305x_flash0_device; |
| 67 | reg = MEMC_REG_FLASH_CFG0; |
| 68 | break; |
| 69 | case 1: |
| 70 | pdev = &rt305x_flash1_device; |
| 71 | reg = MEMC_REG_FLASH_CFG1; |
| 72 | break; |
| 73 | default: |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | t = rt305x_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 "RT305x: flash bank%u witdh is invalid\n", id); |
| 92 | return; |
| 93 | } |
| 94 | |
| 95 | pdev->dev.platform_data = pdata; |
| 96 | pdev->id = rt305x_flash_instance; |
| 97 | |
| 98 | platform_device_register(pdev); |
| 99 | rt305x_flash_instance++; |
| 100 | } |
| 101 | |
| 102 | static void rt305x_fe_reset(void) |
| 103 | { |
| 104 | rt305x_sysc_wr(RT305X_RESET_FE, SYSC_REG_RESET_CTRL); |
| 105 | rt305x_sysc_wr(0, SYSC_REG_RESET_CTRL); |
| 106 | } |
| 107 | |
| 108 | static struct resource rt305x_eth_resources[] = { |
| 109 | { |
| 110 | .start = RT305X_FE_BASE, |
| 111 | .end = RT305X_FE_BASE + PAGE_SIZE - 1, |
| 112 | .flags = IORESOURCE_MEM, |
| 113 | }, { |
| 114 | .start = RT305X_CPU_IRQ_FE, |
| 115 | .end = RT305X_CPU_IRQ_FE, |
| 116 | .flags = IORESOURCE_IRQ, |
| 117 | }, |
| 118 | }; |
| 119 | |
| 120 | static struct ramips_eth_platform_data ramips_eth_data = { |
| 121 | .mac = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 }, |
| 122 | .reset_fe = rt305x_fe_reset, |
| 123 | .min_pkt_len = 64, |
| 124 | }; |
| 125 | |
| 126 | static struct platform_device rt305x_eth_device = { |
| 127 | .name = "ramips_eth", |
| 128 | .resource = rt305x_eth_resources, |
| 129 | .num_resources = ARRAY_SIZE(rt305x_eth_resources), |
| 130 | .dev = { |
| 131 | .platform_data = &ramips_eth_data, |
| 132 | } |
| 133 | }; |
| 134 | |
| 135 | static struct resource rt305x_esw_resources[] = { |
| 136 | { |
| 137 | .start = RT305X_SWITCH_BASE, |
| 138 | .end = RT305X_SWITCH_BASE + PAGE_SIZE - 1, |
| 139 | .flags = IORESOURCE_MEM, |
| 140 | }, |
| 141 | }; |
| 142 | |
| 143 | struct rt305x_esw_platform_data rt305x_esw_data; |
| 144 | static struct platform_device rt305x_esw_device = { |
| 145 | .name = "rt305x-esw", |
| 146 | .resource = rt305x_esw_resources, |
| 147 | .num_resources = ARRAY_SIZE(rt305x_esw_resources), |
| 148 | .dev = { |
| 149 | .platform_data = &rt305x_esw_data, |
| 150 | } |
| 151 | }; |
| 152 | |
| 153 | void __init rt305x_register_ethernet(void) |
| 154 | { |
| 155 | struct clk *clk; |
| 156 | |
| 157 | clk = clk_get(NULL, "sys"); |
| 158 | if (IS_ERR(clk)) |
| 159 | panic("unable to get SYS clock, err=%ld", PTR_ERR(clk)); |
| 160 | |
| 161 | ramips_eth_data.sys_freq = clk_get_rate(clk); |
| 162 | |
| 163 | platform_device_register(&rt305x_esw_device); |
| 164 | platform_device_register(&rt305x_eth_device); |
| 165 | } |
| 166 | |
| 167 | static struct resource rt305x_wifi_resources[] = { |
| 168 | { |
| 169 | .start = RT305X_WMAC_BASE, |
| 170 | .end = RT305X_WMAC_BASE + 0x3FFFF, |
| 171 | .flags = IORESOURCE_MEM, |
| 172 | }, { |
| 173 | .start = RT305X_CPU_IRQ_WNIC, |
| 174 | .end = RT305X_CPU_IRQ_WNIC, |
| 175 | .flags = IORESOURCE_IRQ, |
| 176 | }, |
| 177 | }; |
| 178 | |
| 179 | static struct platform_device rt305x_wifi_device = { |
| 180 | .name = "rt2800_wmac", |
| 181 | .resource = rt305x_wifi_resources, |
| 182 | .num_resources = ARRAY_SIZE(rt305x_wifi_resources), |
| 183 | .dev = { |
| 184 | .platform_data = NULL, |
| 185 | } |
| 186 | }; |
| 187 | |
| 188 | void __init rt305x_register_wifi(void) |
| 189 | { |
| 190 | platform_device_register(&rt305x_wifi_device); |
| 191 | } |
| 192 | |
| 193 | static struct resource rt305x_wdt_resources[] = { |
| 194 | { |
| 195 | .start = RT305X_TIMER_BASE, |
| 196 | .end = RT305X_TIMER_BASE + RT305X_TIMER_SIZE - 1, |
| 197 | .flags = IORESOURCE_MEM, |
| 198 | }, |
| 199 | }; |
| 200 | |
| 201 | static struct platform_device rt305x_wdt_device = { |
| 202 | .name = "ramips-wdt", |
| 203 | .id = -1, |
| 204 | .resource = rt305x_wdt_resources, |
| 205 | .num_resources = ARRAY_SIZE(rt305x_wdt_resources), |
| 206 | }; |
| 207 | |
| 208 | void __init rt305x_register_wdt(void) |
| 209 | { |
| 210 | u32 t; |
| 211 | |
| 212 | /* enable WDT reset output on pin SRAM_CS_N */ |
| 213 | t = rt305x_sysc_rr(SYSC_REG_SYSTEM_CONFIG); |
| 214 | t |= SYSTEM_CONFIG_SRAM_CS0_MODE_WDT << |
| 215 | SYSTEM_CONFIG_SRAM_CS0_MODE_SHIFT; |
| 216 | rt305x_sysc_wr(t, SYSC_REG_SYSTEM_CONFIG); |
| 217 | |
| 218 | platform_device_register(&rt305x_wdt_device); |
| 219 | } |
| 220 | |