Vineet Gupta | c121c50 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 1 | /* |
| 2 | * ARC FPGA Platform support code |
| 3 | * |
| 4 | * Copyright (C) 2012 Synopsys, Inc. (www.synopsys.com) |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | */ |
| 10 | |
| 11 | #include <linux/types.h> |
| 12 | #include <linux/init.h> |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 13 | #include <linux/device.h> |
Vineet Gupta | c121c50 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 14 | #include <linux/platform_device.h> |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 15 | #include <linux/console.h> |
Vineet Gupta | abe11dd | 2013-01-18 15:12:21 +0530 | [diff] [blame] | 16 | #include <linux/of_platform.h> |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 17 | #include <asm/setup.h> |
| 18 | #include <asm/irq.h> |
| 19 | #include <asm/clk.h> |
| 20 | #include <plat/memmap.h> |
| 21 | |
| 22 | /*----------------------- Platform Devices -----------------------------*/ |
| 23 | |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 24 | static unsigned long arc_uart_info[] = { |
Vineet Gupta | abe11dd | 2013-01-18 15:12:21 +0530 | [diff] [blame] | 25 | 0, /* uart->is_emulated (runtime @running_on_hw) */ |
| 26 | 0, /* uart->port.uartclk */ |
| 27 | 0, /* uart->baud */ |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 28 | 0 |
| 29 | }; |
| 30 | |
Vineet Gupta | abe11dd | 2013-01-18 15:12:21 +0530 | [diff] [blame] | 31 | #if defined(CONFIG_SERIAL_ARC_CONSOLE) |
| 32 | /* |
| 33 | * static platform data - but only for early serial |
| 34 | * TBD: derive this from a special DT node |
| 35 | */ |
| 36 | static struct resource arc_uart0_res[] = { |
| 37 | { |
| 38 | .start = UART0_BASE, |
| 39 | .end = UART0_BASE + 0xFF, |
| 40 | .flags = IORESOURCE_MEM, |
| 41 | }, |
| 42 | { |
| 43 | .start = UART0_IRQ, |
| 44 | .end = UART0_IRQ, |
| 45 | .flags = IORESOURCE_IRQ, |
| 46 | }, |
| 47 | }; |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 48 | |
Vineet Gupta | abe11dd | 2013-01-18 15:12:21 +0530 | [diff] [blame] | 49 | static struct platform_device arc_uart0_dev = { |
| 50 | .name = "arc-uart", |
| 51 | .id = 0, |
| 52 | .num_resources = ARRAY_SIZE(arc_uart0_res), |
| 53 | .resource = arc_uart0_res, |
| 54 | .dev = { |
| 55 | .platform_data = &arc_uart_info, |
| 56 | }, |
| 57 | }; |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 58 | |
| 59 | static struct platform_device *fpga_early_devs[] __initdata = { |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 60 | &arc_uart0_dev, |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 61 | }; |
Vineet Gupta | abe11dd | 2013-01-18 15:12:21 +0530 | [diff] [blame] | 62 | #endif |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 63 | |
| 64 | static void arc_fpga_serial_init(void) |
| 65 | { |
Vineet Gupta | abe11dd | 2013-01-18 15:12:21 +0530 | [diff] [blame] | 66 | /* To let driver workaround ISS bug: baudh Reg can't be set to 0 */ |
| 67 | arc_uart_info[0] = !running_on_hw; |
| 68 | |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 69 | arc_uart_info[1] = arc_get_core_freq(); |
| 70 | |
Vineet Gupta | abe11dd | 2013-01-18 15:12:21 +0530 | [diff] [blame] | 71 | arc_uart_info[2] = CONFIG_ARC_SERIAL_BAUD; |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 72 | |
Vineet Gupta | abe11dd | 2013-01-18 15:12:21 +0530 | [diff] [blame] | 73 | #if defined(CONFIG_SERIAL_ARC_CONSOLE) |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 74 | early_platform_add_devices(fpga_early_devs, |
| 75 | ARRAY_SIZE(fpga_early_devs)); |
| 76 | |
| 77 | /* |
| 78 | * ARC console driver registers itself as an early platform driver |
| 79 | * of class "earlyprintk". |
| 80 | * Install it here, followed by probe of devices. |
| 81 | * The installation here doesn't require earlyprintk in command line |
| 82 | * To do so however, replace the lines below with |
| 83 | * parse_early_param(); |
| 84 | * early_platform_driver_probe("earlyprintk", 1, 1); |
| 85 | * ^^ |
| 86 | */ |
| 87 | early_platform_driver_register_all("earlyprintk"); |
| 88 | early_platform_driver_probe("earlyprintk", 1, 0); |
| 89 | |
| 90 | /* |
| 91 | * This is to make sure that arc uart would be preferred console |
| 92 | * despite one/more of following: |
| 93 | * -command line lacked "console=ttyARC0" or |
| 94 | * -CONFIG_VT_CONSOLE was enabled (for no reason whatsoever) |
| 95 | * Note that this needs to be done after above early console is reg, |
| 96 | * otherwise the early console never gets a chance to run. |
| 97 | */ |
| 98 | add_preferred_console("ttyARC", 0, "115200"); |
Vineet Gupta | abe11dd | 2013-01-18 15:12:21 +0530 | [diff] [blame] | 99 | #endif |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 100 | } |
| 101 | |
Vineet Gupta | c121c50 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 102 | /* |
| 103 | * Early Platform Initialization called from setup_arch() |
| 104 | */ |
| 105 | void __init arc_platform_early_init(void) |
| 106 | { |
| 107 | pr_info("[plat-arcfpga]: registering early dev resources\n"); |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 108 | |
| 109 | arc_fpga_serial_init(); |
Vineet Gupta | c121c50 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 110 | } |
| 111 | |
Vineet Gupta | abe11dd | 2013-01-18 15:12:21 +0530 | [diff] [blame] | 112 | static struct of_dev_auxdata plat_auxdata_lookup[] __initdata = { |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 113 | #if defined(CONFIG_SERIAL_ARC) || defined(CONFIG_SERIAL_ARC_MODULE) |
Vineet Gupta | abe11dd | 2013-01-18 15:12:21 +0530 | [diff] [blame] | 114 | OF_DEV_AUXDATA("snps,arc-uart", UART0_BASE, "arc-uart", arc_uart_info), |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 115 | #endif |
Vineet Gupta | abe11dd | 2013-01-18 15:12:21 +0530 | [diff] [blame] | 116 | {} |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 117 | }; |
| 118 | |
Vineet Gupta | c121c50 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 119 | int __init fpga_plat_init(void) |
| 120 | { |
| 121 | pr_info("[plat-arcfpga]: registering device resources\n"); |
| 122 | |
Vineet Gupta | abe11dd | 2013-01-18 15:12:21 +0530 | [diff] [blame] | 123 | /* |
| 124 | * Traverses flattened DeviceTree - registering platform devices |
| 125 | * complete with their resources |
| 126 | */ |
| 127 | of_platform_populate(NULL, of_default_bus_match_table, |
| 128 | plat_auxdata_lookup, NULL); |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 129 | |
Vineet Gupta | c121c50 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 130 | return 0; |
| 131 | } |
| 132 | arch_initcall(fpga_plat_init); |