blob: 5388b31e2eadc7508445bfe8416759a2eab43fdd [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>
16#include <asm/setup.h>
17#include <asm/irq.h>
18#include <asm/clk.h>
19#include <plat/memmap.h>
20
21/*----------------------- Platform Devices -----------------------------*/
22
23#if defined(CONFIG_SERIAL_ARC) || defined(CONFIG_SERIAL_ARC_MODULE)
24
25static unsigned long arc_uart_info[] = {
26 CONFIG_ARC_SERIAL_BAUD, /* uart->baud */
27 -1, /* uart->port.uartclk */
28 -1, /* uart->is_emulated (runtime @running_on_hw) */
29 0
30};
31
32#define ARC_UART_DEV(n) \
33 \
34static struct resource arc_uart##n##_res[] = { \
35 { \
36 .start = UART##n##_BASE, \
37 .end = UART##n##_BASE + 0xFF, \
38 .flags = IORESOURCE_MEM, \
39 }, \
40 { \
41 .start = UART##n##_IRQ, \
42 .end = UART##n##_IRQ, \
43 .flags = IORESOURCE_IRQ, \
44 }, \
45}; \
46 \
47static struct platform_device arc_uart##n##_dev = { \
48 .name = "arc-uart", \
49 .id = n, \
50 .num_resources = ARRAY_SIZE(arc_uart##n##_res), \
51 .resource = arc_uart##n##_res, \
52 .dev = { \
53 .platform_data = &arc_uart_info, \
54 }, \
55}
56
57ARC_UART_DEV(0);
58#if CONFIG_SERIAL_ARC_NR_PORTS > 1
59ARC_UART_DEV(1);
60#endif
61
62static struct platform_device *fpga_early_devs[] __initdata = {
63#if defined(CONFIG_SERIAL_ARC_CONSOLE)
64 &arc_uart0_dev,
65#endif
66};
67
68static void arc_fpga_serial_init(void)
69{
70 arc_uart_info[1] = arc_get_core_freq();
71
72 /* To let driver workaround ISS bug: baudh Reg can't be set to 0 */
73 arc_uart_info[2] = !running_on_hw;
74
75 early_platform_add_devices(fpga_early_devs,
76 ARRAY_SIZE(fpga_early_devs));
77
78 /*
79 * ARC console driver registers itself as an early platform driver
80 * of class "earlyprintk".
81 * Install it here, followed by probe of devices.
82 * The installation here doesn't require earlyprintk in command line
83 * To do so however, replace the lines below with
84 * parse_early_param();
85 * early_platform_driver_probe("earlyprintk", 1, 1);
86 * ^^
87 */
88 early_platform_driver_register_all("earlyprintk");
89 early_platform_driver_probe("earlyprintk", 1, 0);
90
91 /*
92 * This is to make sure that arc uart would be preferred console
93 * despite one/more of following:
94 * -command line lacked "console=ttyARC0" or
95 * -CONFIG_VT_CONSOLE was enabled (for no reason whatsoever)
96 * Note that this needs to be done after above early console is reg,
97 * otherwise the early console never gets a chance to run.
98 */
99 add_preferred_console("ttyARC", 0, "115200");
100}
101
102#else
103
104static void arc_fpga_serial_init(void)
105{
106}
107
108#endif /* CONFIG_SERIAL_ARC */
Vineet Guptac121c502013-01-18 15:12:20 +0530109
110/*
111 * Early Platform Initialization called from setup_arch()
112 */
113void __init arc_platform_early_init(void)
114{
115 pr_info("[plat-arcfpga]: registering early dev resources\n");
Vineet Guptaee36d172013-01-18 15:12:20 +0530116
117 arc_fpga_serial_init();
Vineet Guptac121c502013-01-18 15:12:20 +0530118}
119
Vineet Guptaee36d172013-01-18 15:12:20 +0530120static struct platform_device *fpga_devs[] __initdata = {
121#if defined(CONFIG_SERIAL_ARC) || defined(CONFIG_SERIAL_ARC_MODULE)
122 &arc_uart0_dev,
123#if CONFIG_SERIAL_ARC_NR_PORTS > 1
124 &arc_uart1_dev,
125#endif
126#endif
127};
128
Vineet Guptac121c502013-01-18 15:12:20 +0530129int __init fpga_plat_init(void)
130{
131 pr_info("[plat-arcfpga]: registering device resources\n");
132
Vineet Guptaee36d172013-01-18 15:12:20 +0530133 platform_add_devices(fpga_devs, ARRAY_SIZE(fpga_devs));
134
Vineet Guptac121c502013-01-18 15:12:20 +0530135 return 0;
136}
137arch_initcall(fpga_plat_init);