| 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 |  | 
| Vineet Gupta | 7fadc1e | 2013-01-18 15:12:24 +0530 | [diff] [blame] | 25 | /*-----------------------BVCI Latency Unit -----------------------------*/ | 
|  | 26 |  | 
|  | 27 | #ifdef CONFIG_ARC_HAS_BVCI_LAT_UNIT | 
|  | 28 |  | 
|  | 29 | int lat_cycles = CONFIG_BVCI_LAT_CYCLES; | 
|  | 30 |  | 
|  | 31 | /* BVCI Bus Profiler: Latency Unit */ | 
|  | 32 | static void __init setup_bvci_lat_unit(void) | 
|  | 33 | { | 
|  | 34 | #define MAX_BVCI_UNITS 12 | 
|  | 35 |  | 
|  | 36 | unsigned int i; | 
|  | 37 | unsigned int *base = (unsigned int *)BVCI_LAT_UNIT_BASE; | 
|  | 38 | const unsigned long units_req = CONFIG_BVCI_LAT_UNITS; | 
|  | 39 | const unsigned int REG_UNIT = 21; | 
|  | 40 | const unsigned int REG_VAL = 22; | 
|  | 41 |  | 
|  | 42 | /* | 
|  | 43 | * There are multiple Latency Units corresponding to the many | 
|  | 44 | * interfaces of the system bus arbiter (both CPU side as well as | 
|  | 45 | * the peripheral side). | 
|  | 46 | * | 
|  | 47 | * Unit  0 - System Arb and Mem Controller - adds latency to all | 
|  | 48 | *	    memory trasactions | 
|  | 49 | * Unit  1 - I$ and System Bus | 
|  | 50 | * Unit  2 - D$ and System Bus | 
|  | 51 | * .. | 
|  | 52 | * Unit 12 - IDE Disk controller and System Bus | 
|  | 53 | * | 
|  | 54 | * The programmers model requires writing to lat_unit reg first | 
|  | 55 | * and then the latency value (cycles) to lat_value reg | 
|  | 56 | */ | 
|  | 57 |  | 
|  | 58 | if (CONFIG_BVCI_LAT_UNITS == 0) { | 
|  | 59 | writel(0, base + REG_UNIT); | 
|  | 60 | writel(lat_cycles, base + REG_VAL); | 
|  | 61 | pr_info("BVCI Latency for all Memory Transactions %d cycles\n", | 
|  | 62 | lat_cycles); | 
|  | 63 | } else { | 
|  | 64 | for_each_set_bit(i, &units_req, MAX_BVCI_UNITS) { | 
|  | 65 | writel(i + 1, base + REG_UNIT); /* loop is 0 based */ | 
|  | 66 | writel(lat_cycles, base + REG_VAL); | 
|  | 67 | pr_info("BVCI Latency for Unit[%d] = %d cycles\n", | 
|  | 68 | (i + 1), lat_cycles); | 
|  | 69 | } | 
|  | 70 | } | 
|  | 71 | } | 
|  | 72 | #else | 
|  | 73 | static void __init setup_bvci_lat_unit(void) | 
|  | 74 | { | 
|  | 75 | } | 
|  | 76 | #endif | 
|  | 77 |  | 
| Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 78 | /*----------------------- Platform Devices -----------------------------*/ | 
|  | 79 |  | 
| Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 80 | static unsigned long arc_uart_info[] = { | 
| Vineet Gupta | abe11dd | 2013-01-18 15:12:21 +0530 | [diff] [blame] | 81 | 0,	/* uart->is_emulated (runtime @running_on_hw) */ | 
|  | 82 | 0,	/* uart->port.uartclk */ | 
|  | 83 | 0,	/* uart->baud */ | 
| Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 84 | 0 | 
|  | 85 | }; | 
|  | 86 |  | 
| Vineet Gupta | abe11dd | 2013-01-18 15:12:21 +0530 | [diff] [blame] | 87 | #if defined(CONFIG_SERIAL_ARC_CONSOLE) | 
|  | 88 | /* | 
|  | 89 | * static platform data - but only for early serial | 
|  | 90 | * TBD: derive this from a special DT node | 
|  | 91 | */ | 
|  | 92 | static struct resource arc_uart0_res[] = { | 
|  | 93 | { | 
|  | 94 | .start = UART0_BASE, | 
|  | 95 | .end   = UART0_BASE + 0xFF, | 
|  | 96 | .flags = IORESOURCE_MEM, | 
|  | 97 | }, | 
|  | 98 | { | 
|  | 99 | .start = UART0_IRQ, | 
|  | 100 | .end   = UART0_IRQ, | 
|  | 101 | .flags = IORESOURCE_IRQ, | 
|  | 102 | }, | 
|  | 103 | }; | 
| Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 104 |  | 
| Vineet Gupta | abe11dd | 2013-01-18 15:12:21 +0530 | [diff] [blame] | 105 | static struct platform_device arc_uart0_dev = { | 
|  | 106 | .name = "arc-uart", | 
|  | 107 | .id = 0, | 
|  | 108 | .num_resources = ARRAY_SIZE(arc_uart0_res), | 
|  | 109 | .resource = arc_uart0_res, | 
|  | 110 | .dev = { | 
|  | 111 | .platform_data = &arc_uart_info, | 
|  | 112 | }, | 
|  | 113 | }; | 
| Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 114 |  | 
|  | 115 | static struct platform_device *fpga_early_devs[] __initdata = { | 
| Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 116 | &arc_uart0_dev, | 
| Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 117 | }; | 
| Vineet Gupta | abe11dd | 2013-01-18 15:12:21 +0530 | [diff] [blame] | 118 | #endif | 
| Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 119 |  | 
|  | 120 | static void arc_fpga_serial_init(void) | 
|  | 121 | { | 
| Vineet Gupta | abe11dd | 2013-01-18 15:12:21 +0530 | [diff] [blame] | 122 | /* To let driver workaround ISS bug: baudh Reg can't be set to 0 */ | 
|  | 123 | arc_uart_info[0] = !running_on_hw; | 
|  | 124 |  | 
| Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 125 | arc_uart_info[1] = arc_get_core_freq(); | 
|  | 126 |  | 
| Vineet Gupta | abe11dd | 2013-01-18 15:12:21 +0530 | [diff] [blame] | 127 | arc_uart_info[2] = CONFIG_ARC_SERIAL_BAUD; | 
| Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 128 |  | 
| Vineet Gupta | abe11dd | 2013-01-18 15:12:21 +0530 | [diff] [blame] | 129 | #if defined(CONFIG_SERIAL_ARC_CONSOLE) | 
| Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 130 | early_platform_add_devices(fpga_early_devs, | 
|  | 131 | ARRAY_SIZE(fpga_early_devs)); | 
|  | 132 |  | 
|  | 133 | /* | 
|  | 134 | * ARC console driver registers itself as an early platform driver | 
|  | 135 | * of class "earlyprintk". | 
|  | 136 | * Install it here, followed by probe of devices. | 
|  | 137 | * The installation here doesn't require earlyprintk in command line | 
|  | 138 | * To do so however, replace the lines below with | 
|  | 139 | *	parse_early_param(); | 
|  | 140 | *	early_platform_driver_probe("earlyprintk", 1, 1); | 
|  | 141 | *						      ^^ | 
|  | 142 | */ | 
|  | 143 | early_platform_driver_register_all("earlyprintk"); | 
|  | 144 | early_platform_driver_probe("earlyprintk", 1, 0); | 
|  | 145 |  | 
|  | 146 | /* | 
|  | 147 | * This is to make sure that arc uart would be preferred console | 
|  | 148 | * despite one/more of following: | 
|  | 149 | *   -command line lacked "console=ttyARC0" or | 
|  | 150 | *   -CONFIG_VT_CONSOLE was enabled (for no reason whatsoever) | 
|  | 151 | * Note that this needs to be done after above early console is reg, | 
|  | 152 | * otherwise the early console never gets a chance to run. | 
|  | 153 | */ | 
|  | 154 | add_preferred_console("ttyARC", 0, "115200"); | 
| Vineet Gupta | abe11dd | 2013-01-18 15:12:21 +0530 | [diff] [blame] | 155 | #endif | 
| Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 156 | } | 
|  | 157 |  | 
| Vineet Gupta | 877768c | 2013-01-23 16:32:48 +0530 | [diff] [blame] | 158 | static void __init plat_fpga_early_init(void) | 
| Vineet Gupta | c121c50 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 159 | { | 
|  | 160 | pr_info("[plat-arcfpga]: registering early dev resources\n"); | 
| Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 161 |  | 
| Vineet Gupta | 7fadc1e | 2013-01-18 15:12:24 +0530 | [diff] [blame] | 162 | setup_bvci_lat_unit(); | 
|  | 163 |  | 
| Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 164 | arc_fpga_serial_init(); | 
| Vineet Gupta | b830cde | 2013-01-18 15:12:26 +0530 | [diff] [blame] | 165 |  | 
|  | 166 | #ifdef CONFIG_SMP | 
|  | 167 | iss_model_init_early_smp(); | 
|  | 168 | #endif | 
| Vineet Gupta | c121c50 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 169 | } | 
|  | 170 |  | 
| Vineet Gupta | abe11dd | 2013-01-18 15:12:21 +0530 | [diff] [blame] | 171 | static struct of_dev_auxdata plat_auxdata_lookup[] __initdata = { | 
| Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 172 | #if defined(CONFIG_SERIAL_ARC) || defined(CONFIG_SERIAL_ARC_MODULE) | 
| Vineet Gupta | abe11dd | 2013-01-18 15:12:21 +0530 | [diff] [blame] | 173 | 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] | 174 | #endif | 
| Vineet Gupta | abe11dd | 2013-01-18 15:12:21 +0530 | [diff] [blame] | 175 | {} | 
| Vineet Gupta | ee36d17 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 176 | }; | 
|  | 177 |  | 
| Vineet Gupta | 877768c | 2013-01-23 16:32:48 +0530 | [diff] [blame] | 178 | static void __init plat_fpga_populate_dev(void) | 
| Vineet Gupta | c121c50 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 179 | { | 
|  | 180 | pr_info("[plat-arcfpga]: registering device resources\n"); | 
|  | 181 |  | 
| Vineet Gupta | abe11dd | 2013-01-18 15:12:21 +0530 | [diff] [blame] | 182 | /* | 
|  | 183 | * Traverses flattened DeviceTree - registering platform devices | 
|  | 184 | * complete with their resources | 
|  | 185 | */ | 
|  | 186 | of_platform_populate(NULL, of_default_bus_match_table, | 
|  | 187 | plat_auxdata_lookup, NULL); | 
| Vineet Gupta | c121c50 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 188 | } | 
| Vineet Gupta | 877768c | 2013-01-23 16:32:48 +0530 | [diff] [blame] | 189 |  | 
|  | 190 | /*----------------------- Machine Descriptions ------------------------------ | 
|  | 191 | * | 
|  | 192 | * Machine description is simply a set of platform/board specific callbacks | 
|  | 193 | * This is not directly related to DeviceTree based dynamic device creation, | 
|  | 194 | * however as part of early device tree scan, we also select the right | 
|  | 195 | * callback set, by matching the DT compatible name. | 
|  | 196 | */ | 
|  | 197 |  | 
|  | 198 | static const char *aa4_compat[] __initdata = { | 
|  | 199 | "snps,arc-angel4", | 
|  | 200 | NULL, | 
|  | 201 | }; | 
|  | 202 |  | 
|  | 203 | MACHINE_START(ANGEL4, "angel4") | 
|  | 204 | .dt_compat	= aa4_compat, | 
|  | 205 | .init_early	= plat_fpga_early_init, | 
|  | 206 | .init_machine	= plat_fpga_populate_dev, | 
|  | 207 | .init_irq	= plat_fpga_init_IRQ, | 
|  | 208 | #ifdef CONFIG_SMP | 
|  | 209 | .init_smp	= iss_model_init_smp, | 
|  | 210 | #endif | 
|  | 211 | MACHINE_END | 
|  | 212 |  | 
|  | 213 | static const char *ml509_compat[] __initdata = { | 
|  | 214 | "snps,arc-ml509", | 
|  | 215 | NULL, | 
|  | 216 | }; | 
|  | 217 |  | 
|  | 218 | MACHINE_START(ML509, "ml509") | 
|  | 219 | .dt_compat	= ml509_compat, | 
|  | 220 | .init_early	= plat_fpga_early_init, | 
|  | 221 | .init_machine	= plat_fpga_populate_dev, | 
|  | 222 | .init_irq	= plat_fpga_init_IRQ, | 
|  | 223 | #ifdef CONFIG_SMP | 
|  | 224 | .init_smp	= iss_model_init_smp, | 
|  | 225 | #endif | 
|  | 226 | MACHINE_END |