Max Filippov | 0d456ba | 2012-11-05 07:37:14 +0400 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * arch/xtensa/platform/xtavnet/setup.c |
| 4 | * |
| 5 | * ... |
| 6 | * |
| 7 | * Authors: Chris Zankel <chris@zankel.net> |
| 8 | * Joe Taylor <joe@tensilica.com> |
| 9 | * |
| 10 | * Copyright 2001 - 2006 Tensilica Inc. |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify it |
| 13 | * under the terms of the GNU General Public License as published by the |
| 14 | * Free Software Foundation; either version 2 of the License, or (at your |
| 15 | * option) any later version. |
| 16 | * |
| 17 | */ |
| 18 | #include <linux/stddef.h> |
| 19 | #include <linux/kernel.h> |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/errno.h> |
| 22 | #include <linux/reboot.h> |
| 23 | #include <linux/kdev_t.h> |
| 24 | #include <linux/types.h> |
| 25 | #include <linux/major.h> |
| 26 | #include <linux/console.h> |
| 27 | #include <linux/delay.h> |
| 28 | #include <linux/of.h> |
| 29 | |
| 30 | #include <asm/timex.h> |
| 31 | #include <asm/processor.h> |
| 32 | #include <asm/platform.h> |
| 33 | #include <asm/bootparam.h> |
| 34 | #include <platform/lcd.h> |
Chris Zankel | 33c760f | 2012-11-28 16:52:09 -0800 | [diff] [blame] | 35 | #include <platform/hardware.h> |
Max Filippov | 0d456ba | 2012-11-05 07:37:14 +0400 | [diff] [blame] | 36 | |
| 37 | void platform_halt(void) |
| 38 | { |
| 39 | lcd_disp_at_pos(" HALT ", 0); |
| 40 | local_irq_disable(); |
| 41 | while (1) |
| 42 | cpu_relax(); |
| 43 | } |
| 44 | |
| 45 | void platform_power_off(void) |
| 46 | { |
| 47 | lcd_disp_at_pos("POWEROFF", 0); |
| 48 | local_irq_disable(); |
| 49 | while (1) |
| 50 | cpu_relax(); |
| 51 | } |
| 52 | |
| 53 | void platform_restart(void) |
| 54 | { |
| 55 | /* Flush and reset the mmu, simulate a processor reset, and |
| 56 | * jump to the reset vector. */ |
| 57 | |
| 58 | |
| 59 | __asm__ __volatile__ ("movi a2, 15\n\t" |
| 60 | "wsr a2, icountlevel\n\t" |
| 61 | "movi a2, 0\n\t" |
| 62 | "wsr a2, icount\n\t" |
Max Filippov | d83ff0b | 2013-03-04 03:40:42 +0400 | [diff] [blame] | 63 | #if XCHAL_NUM_IBREAK > 0 |
Max Filippov | 0d456ba | 2012-11-05 07:37:14 +0400 | [diff] [blame] | 64 | "wsr a2, ibreakenable\n\t" |
Max Filippov | d83ff0b | 2013-03-04 03:40:42 +0400 | [diff] [blame] | 65 | #endif |
Max Filippov | 0d456ba | 2012-11-05 07:37:14 +0400 | [diff] [blame] | 66 | "wsr a2, lcount\n\t" |
| 67 | "movi a2, 0x1f\n\t" |
| 68 | "wsr a2, ps\n\t" |
| 69 | "isync\n\t" |
| 70 | "jx %0\n\t" |
| 71 | : |
| 72 | : "a" (XCHAL_RESET_VECTOR_VADDR) |
| 73 | : "a2" |
| 74 | ); |
| 75 | |
| 76 | /* control never gets here */ |
| 77 | } |
| 78 | |
| 79 | void __init platform_setup(char **cmdline) |
| 80 | { |
| 81 | } |
| 82 | |
| 83 | #ifdef CONFIG_OF |
| 84 | |
| 85 | static void __init update_clock_frequency(struct device_node *node) |
| 86 | { |
| 87 | struct property *newfreq; |
| 88 | u32 freq; |
| 89 | |
Chris Zankel | 33c760f | 2012-11-28 16:52:09 -0800 | [diff] [blame] | 90 | if (!of_property_read_u32(node, "clock-frequency", &freq) && freq != 0) |
Max Filippov | 0d456ba | 2012-11-05 07:37:14 +0400 | [diff] [blame] | 91 | return; |
| 92 | |
| 93 | newfreq = kzalloc(sizeof(*newfreq) + sizeof(u32), GFP_KERNEL); |
| 94 | if (!newfreq) |
| 95 | return; |
| 96 | newfreq->value = newfreq + 1; |
| 97 | newfreq->length = sizeof(freq); |
| 98 | newfreq->name = kstrdup("clock-frequency", GFP_KERNEL); |
| 99 | if (!newfreq->name) { |
| 100 | kfree(newfreq); |
| 101 | return; |
| 102 | } |
| 103 | |
| 104 | *(u32 *)newfreq->value = cpu_to_be32(*(u32 *)XTFPGA_CLKFRQ_VADDR); |
Max Filippov | 127bc79 | 2012-12-22 07:10:11 +0400 | [diff] [blame] | 105 | of_update_property(node, newfreq); |
Max Filippov | 0d456ba | 2012-11-05 07:37:14 +0400 | [diff] [blame] | 106 | } |
| 107 | |
Chris Zankel | 33c760f | 2012-11-28 16:52:09 -0800 | [diff] [blame] | 108 | #define MAC_LEN 6 |
| 109 | static void __init update_local_mac(struct device_node *node) |
| 110 | { |
| 111 | struct property *newmac; |
| 112 | const u8* macaddr; |
| 113 | int prop_len; |
| 114 | |
| 115 | macaddr = of_get_property(node, "local-mac-address", &prop_len); |
| 116 | if (macaddr == NULL || prop_len != MAC_LEN) |
| 117 | return; |
| 118 | |
| 119 | newmac = kzalloc(sizeof(*newmac) + MAC_LEN, GFP_KERNEL); |
| 120 | if (newmac == NULL) |
| 121 | return; |
| 122 | |
| 123 | newmac->value = newmac + 1; |
| 124 | newmac->length = MAC_LEN; |
| 125 | newmac->name = kstrdup("local-mac-address", GFP_KERNEL); |
| 126 | if (newmac->name == NULL) { |
| 127 | kfree(newmac); |
| 128 | return; |
| 129 | } |
| 130 | |
| 131 | memcpy(newmac->value, macaddr, MAC_LEN); |
| 132 | ((u8*)newmac->value)[5] = (*(u32*)DIP_SWITCHES_VADDR) & 0x3f; |
Max Filippov | 127bc79 | 2012-12-22 07:10:11 +0400 | [diff] [blame] | 133 | of_update_property(node, newmac); |
Chris Zankel | 33c760f | 2012-11-28 16:52:09 -0800 | [diff] [blame] | 134 | } |
| 135 | |
Max Filippov | 0d456ba | 2012-11-05 07:37:14 +0400 | [diff] [blame] | 136 | static int __init machine_setup(void) |
| 137 | { |
Wei Yongjun | 90e3bc7 | 2012-12-03 00:35:11 -0800 | [diff] [blame] | 138 | struct device_node *serial; |
Chris Zankel | 33c760f | 2012-11-28 16:52:09 -0800 | [diff] [blame] | 139 | struct device_node *eth = NULL; |
Max Filippov | 0d456ba | 2012-11-05 07:37:14 +0400 | [diff] [blame] | 140 | |
Wei Yongjun | 90e3bc7 | 2012-12-03 00:35:11 -0800 | [diff] [blame] | 141 | for_each_compatible_node(serial, NULL, "ns16550a") |
Max Filippov | 0d456ba | 2012-11-05 07:37:14 +0400 | [diff] [blame] | 142 | update_clock_frequency(serial); |
Chris Zankel | 33c760f | 2012-11-28 16:52:09 -0800 | [diff] [blame] | 143 | |
| 144 | if ((eth = of_find_compatible_node(eth, NULL, "opencores,ethoc"))) |
| 145 | update_local_mac(eth); |
Max Filippov | 0d456ba | 2012-11-05 07:37:14 +0400 | [diff] [blame] | 146 | return 0; |
| 147 | } |
| 148 | arch_initcall(machine_setup); |
| 149 | |
| 150 | #endif |
| 151 | |
| 152 | /* early initialization */ |
| 153 | |
| 154 | void __init platform_init(bp_tag_t *first) |
| 155 | { |
| 156 | } |
| 157 | |
| 158 | /* Heartbeat. */ |
| 159 | |
| 160 | void platform_heartbeat(void) |
| 161 | { |
| 162 | } |
| 163 | |
| 164 | #ifdef CONFIG_XTENSA_CALIBRATE_CCOUNT |
| 165 | |
Baruch Siach | 54c0af9 | 2013-05-27 09:11:59 +0300 | [diff] [blame^] | 166 | void __init platform_calibrate_ccount(void) |
Max Filippov | 0d456ba | 2012-11-05 07:37:14 +0400 | [diff] [blame] | 167 | { |
| 168 | long clk_freq = 0; |
| 169 | #ifdef CONFIG_OF |
| 170 | struct device_node *cpu = |
| 171 | of_find_compatible_node(NULL, NULL, "xtensa,cpu"); |
| 172 | if (cpu) { |
| 173 | u32 freq; |
| 174 | update_clock_frequency(cpu); |
| 175 | if (!of_property_read_u32(cpu, "clock-frequency", &freq)) |
| 176 | clk_freq = freq; |
| 177 | } |
| 178 | #endif |
| 179 | if (!clk_freq) |
| 180 | clk_freq = *(long *)XTFPGA_CLKFRQ_VADDR; |
| 181 | |
| 182 | ccount_per_jiffy = clk_freq / HZ; |
| 183 | nsec_per_ccount = 1000000000UL / clk_freq; |
| 184 | } |
| 185 | |
| 186 | #endif |
| 187 | |
| 188 | #ifndef CONFIG_OF |
| 189 | |
| 190 | #include <linux/serial_8250.h> |
| 191 | #include <linux/if.h> |
| 192 | #include <net/ethoc.h> |
| 193 | |
| 194 | /*---------------------------------------------------------------------------- |
| 195 | * Ethernet -- OpenCores Ethernet MAC (ethoc driver) |
| 196 | */ |
| 197 | |
| 198 | static struct resource ethoc_res[] __initdata = { |
| 199 | [0] = { /* register space */ |
| 200 | .start = OETH_REGS_PADDR, |
| 201 | .end = OETH_REGS_PADDR + OETH_REGS_SIZE - 1, |
| 202 | .flags = IORESOURCE_MEM, |
| 203 | }, |
| 204 | [1] = { /* buffer space */ |
| 205 | .start = OETH_SRAMBUFF_PADDR, |
| 206 | .end = OETH_SRAMBUFF_PADDR + OETH_SRAMBUFF_SIZE - 1, |
| 207 | .flags = IORESOURCE_MEM, |
| 208 | }, |
| 209 | [2] = { /* IRQ number */ |
| 210 | .start = OETH_IRQ, |
| 211 | .end = OETH_IRQ, |
| 212 | .flags = IORESOURCE_IRQ, |
| 213 | }, |
| 214 | }; |
| 215 | |
| 216 | static struct ethoc_platform_data ethoc_pdata __initdata = { |
| 217 | /* |
| 218 | * The MAC address for these boards is 00:50:c2:13:6f:xx. |
| 219 | * The last byte (here as zero) is read from the DIP switches on the |
| 220 | * board. |
| 221 | */ |
| 222 | .hwaddr = { 0x00, 0x50, 0xc2, 0x13, 0x6f, 0 }, |
| 223 | .phy_id = -1, |
| 224 | }; |
| 225 | |
| 226 | static struct platform_device ethoc_device __initdata = { |
| 227 | .name = "ethoc", |
| 228 | .id = -1, |
| 229 | .num_resources = ARRAY_SIZE(ethoc_res), |
| 230 | .resource = ethoc_res, |
| 231 | .dev = { |
| 232 | .platform_data = ðoc_pdata, |
| 233 | }, |
| 234 | }; |
| 235 | |
| 236 | /*---------------------------------------------------------------------------- |
| 237 | * UART |
| 238 | */ |
| 239 | |
| 240 | static struct resource serial_resource __initdata = { |
| 241 | .start = DUART16552_PADDR, |
| 242 | .end = DUART16552_PADDR + 0x1f, |
| 243 | .flags = IORESOURCE_MEM, |
| 244 | }; |
| 245 | |
| 246 | static struct plat_serial8250_port serial_platform_data[] __initdata = { |
| 247 | [0] = { |
| 248 | .mapbase = DUART16552_PADDR, |
| 249 | .irq = DUART16552_INTNUM, |
| 250 | .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | |
| 251 | UPF_IOREMAP, |
| 252 | .iotype = UPIO_MEM32, |
| 253 | .regshift = 2, |
| 254 | .uartclk = 0, /* set in xtavnet_init() */ |
| 255 | }, |
| 256 | { }, |
| 257 | }; |
| 258 | |
| 259 | static struct platform_device xtavnet_uart __initdata = { |
| 260 | .name = "serial8250", |
| 261 | .id = PLAT8250_DEV_PLATFORM, |
| 262 | .dev = { |
| 263 | .platform_data = serial_platform_data, |
| 264 | }, |
| 265 | .num_resources = 1, |
| 266 | .resource = &serial_resource, |
| 267 | }; |
| 268 | |
| 269 | /* platform devices */ |
| 270 | static struct platform_device *platform_devices[] __initdata = { |
| 271 | ðoc_device, |
| 272 | &xtavnet_uart, |
| 273 | }; |
| 274 | |
| 275 | |
| 276 | static int __init xtavnet_init(void) |
| 277 | { |
| 278 | /* Ethernet MAC address. */ |
| 279 | ethoc_pdata.hwaddr[5] = *(u32 *)DIP_SWITCHES_VADDR; |
| 280 | |
| 281 | /* Clock rate varies among FPGA bitstreams; board specific FPGA register |
| 282 | * reports the actual clock rate. |
| 283 | */ |
| 284 | serial_platform_data[0].uartclk = *(long *)XTFPGA_CLKFRQ_VADDR; |
| 285 | |
| 286 | |
| 287 | /* register platform devices */ |
| 288 | platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices)); |
| 289 | |
| 290 | /* ETHOC driver is a bit quiet; at least display Ethernet MAC, so user |
| 291 | * knows whether they set it correctly on the DIP switches. |
| 292 | */ |
| 293 | pr_info("XTFPGA: Ethernet MAC %pM\n", ethoc_pdata.hwaddr); |
| 294 | |
| 295 | return 0; |
| 296 | } |
| 297 | |
| 298 | /* |
| 299 | * Register to be done during do_initcalls(). |
| 300 | */ |
| 301 | arch_initcall(xtavnet_init); |
| 302 | |
| 303 | #endif /* CONFIG_OF */ |