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 | 7fadc1e | 2013-01-18 15:12:24 +0530 | [diff] [blame] | 15 | #include <linux/io.h> |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 16 | #include <linux/console.h> |
Vineet Gupta | abe11dd | 2013-01-18 15:12:21 +0530 | [diff] [blame] | 17 | #include <linux/of_platform.h> |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 18 | #include <asm/setup.h> |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 19 | #include <asm/clk.h> |
Vineet Gupta | 877768c | 2013-01-23 16:32:48 +0530 | [diff] [blame] | 20 | #include <asm/mach_desc.h> |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 21 | #include <plat/memmap.h> |
Vineet Gupta | 877768c | 2013-01-23 16:32:48 +0530 | [diff] [blame] | 22 | #include <plat/smp.h> |
Vineet Gupta | e97ff12 | 2013-01-18 15:12:26 +0530 | [diff] [blame] | 23 | #include <plat/irq.h> |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 24 | |
| 25 | /*----------------------- Platform Devices -----------------------------*/ |
| 26 | |
Mischa Jonker | ba5afad | 2013-06-04 11:00:49 +0200 | [diff] [blame] | 27 | #if IS_ENABLED(CONFIG_SERIAL_ARC) |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 28 | static unsigned long arc_uart_info[] = { |
Vineet Gupta | abe11dd | 2013-01-18 15:12:21 +0530 | [diff] [blame] | 29 | 0, /* uart->is_emulated (runtime @running_on_hw) */ |
| 30 | 0, /* uart->port.uartclk */ |
| 31 | 0, /* uart->baud */ |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 32 | 0 |
| 33 | }; |
| 34 | |
Vineet Gupta | abe11dd | 2013-01-18 15:12:21 +0530 | [diff] [blame] | 35 | #if defined(CONFIG_SERIAL_ARC_CONSOLE) |
| 36 | /* |
| 37 | * static platform data - but only for early serial |
| 38 | * TBD: derive this from a special DT node |
| 39 | */ |
| 40 | static struct resource arc_uart0_res[] = { |
| 41 | { |
| 42 | .start = UART0_BASE, |
| 43 | .end = UART0_BASE + 0xFF, |
| 44 | .flags = IORESOURCE_MEM, |
| 45 | }, |
| 46 | { |
| 47 | .start = UART0_IRQ, |
| 48 | .end = UART0_IRQ, |
| 49 | .flags = IORESOURCE_IRQ, |
| 50 | }, |
| 51 | }; |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 52 | |
Vineet Gupta | abe11dd | 2013-01-18 15:12:21 +0530 | [diff] [blame] | 53 | static struct platform_device arc_uart0_dev = { |
| 54 | .name = "arc-uart", |
| 55 | .id = 0, |
| 56 | .num_resources = ARRAY_SIZE(arc_uart0_res), |
| 57 | .resource = arc_uart0_res, |
| 58 | .dev = { |
| 59 | .platform_data = &arc_uart_info, |
| 60 | }, |
| 61 | }; |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 62 | |
| 63 | static struct platform_device *fpga_early_devs[] __initdata = { |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 64 | &arc_uart0_dev, |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 65 | }; |
Mischa Jonker | ba5afad | 2013-06-04 11:00:49 +0200 | [diff] [blame] | 66 | #endif /* CONFIG_SERIAL_ARC_CONSOLE */ |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 67 | |
| 68 | static void arc_fpga_serial_init(void) |
| 69 | { |
Vineet Gupta | abe11dd | 2013-01-18 15:12:21 +0530 | [diff] [blame] | 70 | /* To let driver workaround ISS bug: baudh Reg can't be set to 0 */ |
| 71 | arc_uart_info[0] = !running_on_hw; |
| 72 | |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 73 | arc_uart_info[1] = arc_get_core_freq(); |
| 74 | |
Vineet Gupta | abe11dd | 2013-01-18 15:12:21 +0530 | [diff] [blame] | 75 | arc_uart_info[2] = CONFIG_ARC_SERIAL_BAUD; |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 76 | |
Vineet Gupta | abe11dd | 2013-01-18 15:12:21 +0530 | [diff] [blame] | 77 | #if defined(CONFIG_SERIAL_ARC_CONSOLE) |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 78 | early_platform_add_devices(fpga_early_devs, |
| 79 | ARRAY_SIZE(fpga_early_devs)); |
| 80 | |
| 81 | /* |
Vineet Gupta | e87a850 | 2014-03-31 16:22:09 +0530 | [diff] [blame] | 82 | * ARC console driver registers (build time) as an early platform driver |
| 83 | * of class "earlyprintk". However it needs explicit cmdline toggle |
| 84 | * "earlyprintk=ttyARC0" to be successfuly runtime registered. |
| 85 | * Otherwise the early probe below fails to find the driver |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 86 | */ |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 87 | early_platform_driver_probe("earlyprintk", 1, 0); |
| 88 | |
| 89 | /* |
| 90 | * This is to make sure that arc uart would be preferred console |
| 91 | * despite one/more of following: |
| 92 | * -command line lacked "console=ttyARC0" or |
| 93 | * -CONFIG_VT_CONSOLE was enabled (for no reason whatsoever) |
| 94 | * Note that this needs to be done after above early console is reg, |
| 95 | * otherwise the early console never gets a chance to run. |
| 96 | */ |
| 97 | add_preferred_console("ttyARC", 0, "115200"); |
Mischa Jonker | ba5afad | 2013-06-04 11:00:49 +0200 | [diff] [blame] | 98 | #endif /* CONFIG_SERIAL_ARC_CONSOLE */ |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 99 | } |
Mischa Jonker | ba5afad | 2013-06-04 11:00:49 +0200 | [diff] [blame] | 100 | #else /* !IS_ENABLED(CONFIG_SERIAL_ARC) */ |
| 101 | static void arc_fpga_serial_init(void) |
| 102 | { |
| 103 | } |
| 104 | #endif |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 105 | |
Vineet Gupta | 877768c | 2013-01-23 16:32:48 +0530 | [diff] [blame] | 106 | static void __init plat_fpga_early_init(void) |
Vineet Gupta | c121c50 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 107 | { |
| 108 | pr_info("[plat-arcfpga]: registering early dev resources\n"); |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 109 | |
| 110 | arc_fpga_serial_init(); |
Vineet Gupta | b830cde | 2013-01-18 15:12:26 +0530 | [diff] [blame] | 111 | |
Vineet Gupta | 9a091d9 | 2014-02-28 16:13:44 +0800 | [diff] [blame] | 112 | #ifdef CONFIG_ISS_SMP_EXTN |
Vineet Gupta | b830cde | 2013-01-18 15:12:26 +0530 | [diff] [blame] | 113 | iss_model_init_early_smp(); |
| 114 | #endif |
Vineet Gupta | c121c50 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 115 | } |
| 116 | |
Vineet Gupta | abe11dd | 2013-01-18 15:12:21 +0530 | [diff] [blame] | 117 | static struct of_dev_auxdata plat_auxdata_lookup[] __initdata = { |
Mischa Jonker | ba5afad | 2013-06-04 11:00:49 +0200 | [diff] [blame] | 118 | #if IS_ENABLED(CONFIG_SERIAL_ARC) |
Vineet Gupta | abe11dd | 2013-01-18 15:12:21 +0530 | [diff] [blame] | 119 | 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] | 120 | #endif |
Vineet Gupta | abe11dd | 2013-01-18 15:12:21 +0530 | [diff] [blame] | 121 | {} |
Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 122 | }; |
| 123 | |
Vineet Gupta | 877768c | 2013-01-23 16:32:48 +0530 | [diff] [blame] | 124 | static void __init plat_fpga_populate_dev(void) |
Vineet Gupta | c121c50 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 125 | { |
| 126 | pr_info("[plat-arcfpga]: registering device resources\n"); |
| 127 | |
Vineet Gupta | abe11dd | 2013-01-18 15:12:21 +0530 | [diff] [blame] | 128 | /* |
| 129 | * Traverses flattened DeviceTree - registering platform devices |
| 130 | * complete with their resources |
| 131 | */ |
| 132 | of_platform_populate(NULL, of_default_bus_match_table, |
| 133 | plat_auxdata_lookup, NULL); |
Vineet Gupta | c121c50 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 134 | } |
Vineet Gupta | 877768c | 2013-01-23 16:32:48 +0530 | [diff] [blame] | 135 | |
| 136 | /*----------------------- Machine Descriptions ------------------------------ |
| 137 | * |
| 138 | * Machine description is simply a set of platform/board specific callbacks |
| 139 | * This is not directly related to DeviceTree based dynamic device creation, |
| 140 | * however as part of early device tree scan, we also select the right |
| 141 | * callback set, by matching the DT compatible name. |
| 142 | */ |
| 143 | |
Mischa Jonker | 18bff65 | 2014-01-27 15:34:17 +0100 | [diff] [blame] | 144 | static const char *aa4_compat[] __initconst = { |
Vineet Gupta | 877768c | 2013-01-23 16:32:48 +0530 | [diff] [blame] | 145 | "snps,arc-angel4", |
| 146 | NULL, |
| 147 | }; |
| 148 | |
| 149 | MACHINE_START(ANGEL4, "angel4") |
| 150 | .dt_compat = aa4_compat, |
| 151 | .init_early = plat_fpga_early_init, |
| 152 | .init_machine = plat_fpga_populate_dev, |
| 153 | .init_irq = plat_fpga_init_IRQ, |
Vineet Gupta | 9a091d9 | 2014-02-28 16:13:44 +0800 | [diff] [blame] | 154 | #ifdef CONFIG_ISS_SMP_EXTN |
Vineet Gupta | 877768c | 2013-01-23 16:32:48 +0530 | [diff] [blame] | 155 | .init_smp = iss_model_init_smp, |
| 156 | #endif |
| 157 | MACHINE_END |
| 158 | |
Mischa Jonker | 18bff65 | 2014-01-27 15:34:17 +0100 | [diff] [blame] | 159 | static const char *ml509_compat[] __initconst = { |
Vineet Gupta | 877768c | 2013-01-23 16:32:48 +0530 | [diff] [blame] | 160 | "snps,arc-ml509", |
| 161 | NULL, |
| 162 | }; |
| 163 | |
| 164 | MACHINE_START(ML509, "ml509") |
| 165 | .dt_compat = ml509_compat, |
| 166 | .init_early = plat_fpga_early_init, |
| 167 | .init_machine = plat_fpga_populate_dev, |
| 168 | .init_irq = plat_fpga_init_IRQ, |
| 169 | #ifdef CONFIG_SMP |
| 170 | .init_smp = iss_model_init_smp, |
| 171 | #endif |
| 172 | MACHINE_END |
Mischa Jonker | a92a5d0 | 2013-04-18 11:40:39 +0200 | [diff] [blame] | 173 | |
Mischa Jonker | 18bff65 | 2014-01-27 15:34:17 +0100 | [diff] [blame] | 174 | static const char *nsimosci_compat[] __initconst = { |
Mischa Jonker | a92a5d0 | 2013-04-18 11:40:39 +0200 | [diff] [blame] | 175 | "snps,nsimosci", |
| 176 | NULL, |
| 177 | }; |
| 178 | |
| 179 | MACHINE_START(NSIMOSCI, "nsimosci") |
| 180 | .dt_compat = nsimosci_compat, |
| 181 | .init_early = NULL, |
| 182 | .init_machine = plat_fpga_populate_dev, |
| 183 | .init_irq = NULL, |
| 184 | MACHINE_END |