blob: 18e78dba4298ad90aebc7f0a86e44e723d413924 [file] [log] [blame]
Shawn Guo9daaf312011-10-17 08:42:17 +08001/*
2 * Copyright 2011 Freescale Semiconductor, Inc. All Rights Reserved.
3 * Copyright 2011 Linaro Ltd.
4 *
5 * The code contained herein is licensed under the GNU General Public
6 * License. You may obtain a copy of the GNU General Public License
7 * Version 2 or later at the following locations:
8 *
9 * http://www.opensource.org/licenses/gpl-license.html
10 * http://www.gnu.org/copyleft/gpl.html
11 */
12
13#include <linux/irq.h>
14#include <linux/irqdomain.h>
15#include <linux/of_irq.h>
16#include <linux/of_platform.h>
Dong Aishenga2aa65a2012-05-02 19:31:20 +080017#include <linux/pinctrl/machine.h>
Shawn Guo9daaf312011-10-17 08:42:17 +080018#include <asm/mach/arch.h>
19#include <asm/mach/time.h>
20#include <mach/common.h>
21#include <mach/mx51.h>
22
23/*
24 * Lookup table for attaching a specific name and platform_data pointer to
25 * devices as they get created by of_platform_populate(). Ideally this table
26 * would not exist, but the current clock implementation depends on some devices
27 * having a specific name.
28 */
29static const struct of_dev_auxdata imx51_auxdata_lookup[] __initconst = {
30 OF_DEV_AUXDATA("fsl,imx51-uart", MX51_UART1_BASE_ADDR, "imx21-uart.0", NULL),
31 OF_DEV_AUXDATA("fsl,imx51-uart", MX51_UART2_BASE_ADDR, "imx21-uart.1", NULL),
32 OF_DEV_AUXDATA("fsl,imx51-uart", MX51_UART3_BASE_ADDR, "imx21-uart.2", NULL),
33 OF_DEV_AUXDATA("fsl,imx51-fec", MX51_FEC_BASE_ADDR, "imx27-fec.0", NULL),
34 OF_DEV_AUXDATA("fsl,imx51-esdhc", MX51_ESDHC1_BASE_ADDR, "sdhci-esdhc-imx51.0", NULL),
35 OF_DEV_AUXDATA("fsl,imx51-esdhc", MX51_ESDHC2_BASE_ADDR, "sdhci-esdhc-imx51.1", NULL),
36 OF_DEV_AUXDATA("fsl,imx51-esdhc", MX51_ESDHC3_BASE_ADDR, "sdhci-esdhc-imx51.2", NULL),
37 OF_DEV_AUXDATA("fsl,imx51-esdhc", MX51_ESDHC4_BASE_ADDR, "sdhci-esdhc-imx51.3", NULL),
38 OF_DEV_AUXDATA("fsl,imx51-ecspi", MX51_ECSPI1_BASE_ADDR, "imx51-ecspi.0", NULL),
39 OF_DEV_AUXDATA("fsl,imx51-ecspi", MX51_ECSPI2_BASE_ADDR, "imx51-ecspi.1", NULL),
40 OF_DEV_AUXDATA("fsl,imx51-cspi", MX51_CSPI_BASE_ADDR, "imx35-cspi.0", NULL),
41 OF_DEV_AUXDATA("fsl,imx51-i2c", MX51_I2C1_BASE_ADDR, "imx-i2c.0", NULL),
42 OF_DEV_AUXDATA("fsl,imx51-i2c", MX51_I2C2_BASE_ADDR, "imx-i2c.1", NULL),
43 OF_DEV_AUXDATA("fsl,imx51-sdma", MX51_SDMA_BASE_ADDR, "imx35-sdma", NULL),
44 OF_DEV_AUXDATA("fsl,imx51-wdt", MX51_WDOG1_BASE_ADDR, "imx2-wdt.0", NULL),
45 { /* sentinel */ }
46};
47
Shawn Guo2a3267a2011-12-01 14:35:29 +080048static int __init imx51_tzic_add_irq_domain(struct device_node *np,
Shawn Guo9daaf312011-10-17 08:42:17 +080049 struct device_node *interrupt_parent)
50{
Grant Likely6b783f72012-01-10 17:09:30 -070051 irq_domain_add_legacy(np, 128, 0, 0, &irq_domain_simple_ops, NULL);
Shawn Guo2a3267a2011-12-01 14:35:29 +080052 return 0;
Shawn Guo9daaf312011-10-17 08:42:17 +080053}
54
Shawn Guo2a3267a2011-12-01 14:35:29 +080055static int __init imx51_gpio_add_irq_domain(struct device_node *np,
Shawn Guo9daaf312011-10-17 08:42:17 +080056 struct device_node *interrupt_parent)
57{
Shawn Guo04aafd72011-12-01 14:49:29 +080058 static int gpio_irq_base = MXC_GPIO_IRQ_START + ARCH_NR_GPIOS;
Shawn Guo9daaf312011-10-17 08:42:17 +080059
Shawn Guo04aafd72011-12-01 14:49:29 +080060 gpio_irq_base -= 32;
Grant Likely6b783f72012-01-10 17:09:30 -070061 irq_domain_add_legacy(np, 32, gpio_irq_base, 0, &irq_domain_simple_ops, NULL);
Shawn Guo2a3267a2011-12-01 14:35:29 +080062
63 return 0;
Shawn Guo9daaf312011-10-17 08:42:17 +080064}
65
66static const struct of_device_id imx51_irq_match[] __initconst = {
67 { .compatible = "fsl,imx51-tzic", .data = imx51_tzic_add_irq_domain, },
68 { .compatible = "fsl,imx51-gpio", .data = imx51_gpio_add_irq_domain, },
69 { /* sentinel */ }
70};
71
72static const struct of_device_id imx51_iomuxc_of_match[] __initconst = {
73 { .compatible = "fsl,imx51-iomuxc-babbage", .data = imx51_babbage_common_init, },
74 { /* sentinel */ }
75};
76
77static void __init imx51_dt_init(void)
78{
79 struct device_node *node;
80 const struct of_device_id *of_id;
81 void (*func)(void);
82
83 of_irq_init(imx51_irq_match);
84
Dong Aishenga2aa65a2012-05-02 19:31:20 +080085 pinctrl_provide_dummies();
86
Shawn Guo9daaf312011-10-17 08:42:17 +080087 node = of_find_matching_node(NULL, imx51_iomuxc_of_match);
88 if (node) {
89 of_id = of_match_node(imx51_iomuxc_of_match, node);
90 func = of_id->data;
91 func();
92 of_node_put(node);
93 }
94
95 of_platform_populate(NULL, of_default_bus_match_table,
96 imx51_auxdata_lookup, NULL);
97}
98
99static void __init imx51_timer_init(void)
100{
101 mx51_clocks_init_dt();
102}
103
104static struct sys_timer imx51_timer = {
105 .init = imx51_timer_init,
106};
107
108static const char *imx51_dt_board_compat[] __initdata = {
109 "fsl,imx51-babbage",
Sascha Hauer3f8976d2012-02-17 12:07:00 +0100110 "fsl,imx51",
Shawn Guo9daaf312011-10-17 08:42:17 +0800111 NULL
112};
113
114DT_MACHINE_START(IMX51_DT, "Freescale i.MX51 (Device Tree Support)")
115 .map_io = mx51_map_io,
116 .init_early = imx51_init_early,
117 .init_irq = mx51_init_irq,
118 .handle_irq = imx51_handle_irq,
119 .timer = &imx51_timer,
120 .init_machine = imx51_dt_init,
Shawn Guo8321b752012-04-26 11:42:34 +0800121 .init_late = imx51_init_late,
Shawn Guo9daaf312011-10-17 08:42:17 +0800122 .dt_compat = imx51_dt_board_compat,
Russell King65ea7882011-11-06 17:12:08 +0000123 .restart = mxc_restart,
Shawn Guo9daaf312011-10-17 08:42:17 +0800124MACHINE_END