blob: 33bcac8bd6b81333eb55eea394ab52f7a66762bb [file] [log] [blame]
Vineet Guptac121c502013-01-18 15:12:20 +05301/*
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 Guptaee36d172013-01-18 15:12:20 +053013#include <linux/device.h>
Vineet Guptac121c502013-01-18 15:12:20 +053014#include <linux/platform_device.h>
Vineet Guptaee36d172013-01-18 15:12:20 +053015#include <linux/console.h>
Vineet Guptaabe11dd2013-01-18 15:12:21 +053016#include <linux/of_platform.h>
Vineet Guptaee36d172013-01-18 15:12:20 +053017#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 Guptaee36d172013-01-18 15:12:20 +053024static unsigned long arc_uart_info[] = {
Vineet Guptaabe11dd2013-01-18 15:12:21 +053025 0, /* uart->is_emulated (runtime @running_on_hw) */
26 0, /* uart->port.uartclk */
27 0, /* uart->baud */
Vineet Guptaee36d172013-01-18 15:12:20 +053028 0
29};
30
Vineet Guptaabe11dd2013-01-18 15:12:21 +053031#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 */
36static 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 Guptaee36d172013-01-18 15:12:20 +053048
Vineet Guptaabe11dd2013-01-18 15:12:21 +053049static 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 Guptaee36d172013-01-18 15:12:20 +053058
59static struct platform_device *fpga_early_devs[] __initdata = {
Vineet Guptaee36d172013-01-18 15:12:20 +053060 &arc_uart0_dev,
Vineet Guptaee36d172013-01-18 15:12:20 +053061};
Vineet Guptaabe11dd2013-01-18 15:12:21 +053062#endif
Vineet Guptaee36d172013-01-18 15:12:20 +053063
64static void arc_fpga_serial_init(void)
65{
Vineet Guptaabe11dd2013-01-18 15:12:21 +053066 /* To let driver workaround ISS bug: baudh Reg can't be set to 0 */
67 arc_uart_info[0] = !running_on_hw;
68
Vineet Guptaee36d172013-01-18 15:12:20 +053069 arc_uart_info[1] = arc_get_core_freq();
70
Vineet Guptaabe11dd2013-01-18 15:12:21 +053071 arc_uart_info[2] = CONFIG_ARC_SERIAL_BAUD;
Vineet Guptaee36d172013-01-18 15:12:20 +053072
Vineet Guptaabe11dd2013-01-18 15:12:21 +053073#if defined(CONFIG_SERIAL_ARC_CONSOLE)
Vineet Guptaee36d172013-01-18 15:12:20 +053074 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 Guptaabe11dd2013-01-18 15:12:21 +053099#endif
Vineet Guptaee36d172013-01-18 15:12:20 +0530100}
101
Vineet Guptac121c502013-01-18 15:12:20 +0530102/*
103 * Early Platform Initialization called from setup_arch()
104 */
105void __init arc_platform_early_init(void)
106{
107 pr_info("[plat-arcfpga]: registering early dev resources\n");
Vineet Guptaee36d172013-01-18 15:12:20 +0530108
109 arc_fpga_serial_init();
Vineet Guptac121c502013-01-18 15:12:20 +0530110}
111
Vineet Guptaabe11dd2013-01-18 15:12:21 +0530112static struct of_dev_auxdata plat_auxdata_lookup[] __initdata = {
Vineet Guptaee36d172013-01-18 15:12:20 +0530113#if defined(CONFIG_SERIAL_ARC) || defined(CONFIG_SERIAL_ARC_MODULE)
Vineet Guptaabe11dd2013-01-18 15:12:21 +0530114 OF_DEV_AUXDATA("snps,arc-uart", UART0_BASE, "arc-uart", arc_uart_info),
Vineet Guptaee36d172013-01-18 15:12:20 +0530115#endif
Vineet Guptaabe11dd2013-01-18 15:12:21 +0530116 {}
Vineet Guptaee36d172013-01-18 15:12:20 +0530117};
118
Vineet Guptac121c502013-01-18 15:12:20 +0530119int __init fpga_plat_init(void)
120{
121 pr_info("[plat-arcfpga]: registering device resources\n");
122
Vineet Guptaabe11dd2013-01-18 15:12:21 +0530123 /*
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 Guptaee36d172013-01-18 15:12:20 +0530129
Vineet Guptac121c502013-01-18 15:12:20 +0530130 return 0;
131}
132arch_initcall(fpga_plat_init);