blob: 272de6e883e75391cf2f4be8aedf94ab8ddaaecc [file] [log] [blame]
Amit Kucheria088d01b2010-10-07 03:58:12 +03001/*
2 * Copyright (C) 2010 Linaro Limited
3 *
4 * based on code from the following
5 * Copyright 2009-2010 Freescale Semiconductor, Inc. All Rights Reserved.
6 * Copyright 2009-2010 Pegatron Corporation. All Rights Reserved.
7 * Copyright 2009-2010 Genesi USA, Inc. All Rights Reserved.
8 *
9 * The code contained herein is licensed under the GNU General Public
10 * License. You may obtain a copy of the GNU General Public License
11 * Version 2 or later at the following locations:
12 *
13 * http://www.opensource.org/licenses/gpl-license.html
14 * http://www.gnu.org/copyleft/gpl.html
15 */
16
17#include <linux/init.h>
18#include <linux/platform_device.h>
19#include <linux/i2c.h>
20#include <linux/gpio.h>
Arnaud Patard (Rtp)9d2c0ef2010-10-27 14:40:51 +020021#include <linux/leds.h>
Arnaud Patard (Rtp)fcbd0c52010-10-27 14:40:52 +020022#include <linux/input.h>
Amit Kucheria088d01b2010-10-07 03:58:12 +030023#include <linux/delay.h>
24#include <linux/io.h>
25#include <linux/fsl_devices.h>
Arnaud Patard (Rtp)c6e34a42010-10-27 14:40:54 +020026#include <linux/spi/flash.h>
27#include <linux/spi/spi.h>
Amit Kucheria088d01b2010-10-07 03:58:12 +030028
29#include <mach/common.h>
30#include <mach/hardware.h>
31#include <mach/iomux-mx51.h>
32#include <mach/i2c.h>
33#include <mach/mxc_ehci.h>
34
35#include <asm/irq.h>
36#include <asm/setup.h>
37#include <asm/mach-types.h>
38#include <asm/mach/arch.h>
39#include <asm/mach/time.h>
40
41#include "devices-imx51.h"
42#include "devices.h"
Arnaud Patard (Rtp)7ac18a32011-02-17 15:31:28 +010043#include "efika.h"
Amit Kucheria81490fc2010-10-07 03:58:25 +030044
Arnaud Patard (Rtp)96886c42010-11-26 15:20:52 +010045#define EFIKAMX_PCBID0 IMX_GPIO_NR(3, 16)
46#define EFIKAMX_PCBID1 IMX_GPIO_NR(3, 17)
47#define EFIKAMX_PCBID2 IMX_GPIO_NR(3, 11)
Arnaud Patard (Rtp)f1dd3612010-10-27 14:40:46 +020048
Arnaud Patard (Rtp)96886c42010-11-26 15:20:52 +010049#define EFIKAMX_BLUE_LED IMX_GPIO_NR(3, 13)
50#define EFIKAMX_GREEN_LED IMX_GPIO_NR(3, 14)
51#define EFIKAMX_RED_LED IMX_GPIO_NR(3, 15)
Arnaud Patard (Rtp)9d2c0ef2010-10-27 14:40:51 +020052
Arnaud Patard (Rtp)96886c42010-11-26 15:20:52 +010053#define EFIKAMX_POWER_KEY IMX_GPIO_NR(2, 31)
Arnaud Patard (Rtp)fcbd0c52010-10-27 14:40:52 +020054
Arnaud Patard (Rtp)c2932bf2010-10-27 14:40:55 +020055/* board 1.1 doesn't have same reset gpio */
Arnaud Patard (Rtp)96886c42010-11-26 15:20:52 +010056#define EFIKAMX_RESET1_1 IMX_GPIO_NR(3, 2)
57#define EFIKAMX_RESET IMX_GPIO_NR(1, 4)
Arnaud Patard (Rtp)c2932bf2010-10-27 14:40:55 +020058
Arnaud Patard (Rtp)f1dd3612010-10-27 14:40:46 +020059/* the pci ids pin have pull up. they're driven low according to board id */
60#define MX51_PAD_PCBID0 IOMUX_PAD(0x518, 0x130, 3, 0x0, 0, PAD_CTL_PUS_100K_UP)
61#define MX51_PAD_PCBID1 IOMUX_PAD(0x51C, 0x134, 3, 0x0, 0, PAD_CTL_PUS_100K_UP)
62#define MX51_PAD_PCBID2 IOMUX_PAD(0x504, 0x128, 3, 0x0, 0, PAD_CTL_PUS_100K_UP)
Arnaud Patard (Rtp)fcbd0c52010-10-27 14:40:52 +020063#define MX51_PAD_PWRKEY IOMUX_PAD(0x48c, 0x0f8, 1, 0x0, 0, PAD_CTL_PUS_100K_UP | PAD_CTL_PKE)
Arnaud Patard (Rtp)f1dd3612010-10-27 14:40:46 +020064
Lothar Waßmann8f5260c2010-10-26 14:28:31 +020065static iomux_v3_cfg_t mx51efikamx_pads[] = {
Arnaud Patard (Rtp)f1dd3612010-10-27 14:40:46 +020066 /* board id */
67 MX51_PAD_PCBID0,
68 MX51_PAD_PCBID1,
69 MX51_PAD_PCBID2,
Arnaud Patard (Rtp)a96eb142010-10-27 14:40:49 +020070
Arnaud Patard (Rtp)9d2c0ef2010-10-27 14:40:51 +020071 /* leds */
Sascha Haueree1ae4d2010-12-15 09:56:35 +010072 MX51_PAD_CSI1_D9__GPIO3_13,
73 MX51_PAD_CSI1_VSYNC__GPIO3_14,
74 MX51_PAD_CSI1_HSYNC__GPIO3_15,
Arnaud Patard (Rtp)fcbd0c52010-10-27 14:40:52 +020075
76 /* power key */
77 MX51_PAD_PWRKEY,
Arnaud Patard (Rtp)c6e34a42010-10-27 14:40:54 +020078
Arnaud Patard (Rtp)c2932bf2010-10-27 14:40:55 +020079 /* reset */
Sascha Haueree1ae4d2010-12-15 09:56:35 +010080 MX51_PAD_DI1_PIN13__GPIO3_2,
81 MX51_PAD_GPIO1_4__GPIO1_4,
Amit Kucheria088d01b2010-10-07 03:58:12 +030082};
83
Arnaud Patard (Rtp)f1dd3612010-10-27 14:40:46 +020084/* PCBID2 PCBID1 PCBID0 STATE
85 1 1 1 ER1:rev1.1
86 1 1 0 ER2:rev1.2
87 1 0 1 ER3:rev1.3
88 1 0 0 ER4:rev1.4
89*/
90static void __init mx51_efikamx_board_id(void)
91{
92 int id;
93
94 /* things are taking time to settle */
95 msleep(150);
96
97 gpio_request(EFIKAMX_PCBID0, "pcbid0");
98 gpio_direction_input(EFIKAMX_PCBID0);
99 gpio_request(EFIKAMX_PCBID1, "pcbid1");
100 gpio_direction_input(EFIKAMX_PCBID1);
101 gpio_request(EFIKAMX_PCBID2, "pcbid2");
102 gpio_direction_input(EFIKAMX_PCBID2);
103
104 id = gpio_get_value(EFIKAMX_PCBID0);
105 id |= gpio_get_value(EFIKAMX_PCBID1) << 1;
106 id |= gpio_get_value(EFIKAMX_PCBID2) << 2;
107
108 switch (id) {
109 case 7:
110 system_rev = 0x11;
111 break;
112 case 6:
113 system_rev = 0x12;
114 break;
115 case 5:
116 system_rev = 0x13;
117 break;
118 case 4:
119 system_rev = 0x14;
120 break;
121 default:
122 system_rev = 0x10;
123 break;
124 }
125
126 if ((system_rev == 0x10)
127 || (system_rev == 0x12)
128 || (system_rev == 0x14)) {
129 printk(KERN_WARNING
130 "EfikaMX: Unsupported board revision 1.%u!\n",
131 system_rev & 0xf);
132 }
133}
134
Arnaud Patard (Rtp)9d2c0ef2010-10-27 14:40:51 +0200135static struct gpio_led mx51_efikamx_leds[] = {
136 {
137 .name = "efikamx:green",
138 .default_trigger = "default-on",
139 .gpio = EFIKAMX_GREEN_LED,
140 },
141 {
142 .name = "efikamx:red",
143 .default_trigger = "ide-disk",
144 .gpio = EFIKAMX_RED_LED,
145 },
146 {
147 .name = "efikamx:blue",
148 .default_trigger = "mmc0",
149 .gpio = EFIKAMX_BLUE_LED,
150 },
151};
152
153static struct gpio_led_platform_data mx51_efikamx_leds_data = {
154 .leds = mx51_efikamx_leds,
155 .num_leds = ARRAY_SIZE(mx51_efikamx_leds),
156};
157
158static struct platform_device mx51_efikamx_leds_device = {
159 .name = "leds-gpio",
160 .id = -1,
161 .dev = {
162 .platform_data = &mx51_efikamx_leds_data,
163 },
164};
165
Arnaud Patard (Rtp)fcbd0c52010-10-27 14:40:52 +0200166static struct gpio_keys_button mx51_efikamx_powerkey[] = {
167 {
168 .code = KEY_POWER,
169 .gpio = EFIKAMX_POWER_KEY,
170 .type = EV_PWR,
171 .desc = "Power Button (CM)",
172 .wakeup = 1,
173 .debounce_interval = 10, /* ms */
174 },
175};
176
177static const struct gpio_keys_platform_data mx51_efikamx_powerkey_data __initconst = {
178 .buttons = mx51_efikamx_powerkey,
179 .nbuttons = ARRAY_SIZE(mx51_efikamx_powerkey),
180};
181
Arnaud Patard (Rtp)c2932bf2010-10-27 14:40:55 +0200182void mx51_efikamx_reset(void)
183{
184 if (system_rev == 0x11)
185 gpio_direction_output(EFIKAMX_RESET1_1, 0);
186 else
187 gpio_direction_output(EFIKAMX_RESET, 0);
188}
189
Uwe Kleine-Könige134fb22011-02-11 10:23:19 +0100190static void __init mx51_efikamx_init(void)
Amit Kucheria088d01b2010-10-07 03:58:12 +0300191{
192 mxc_iomux_v3_setup_multiple_pads(mx51efikamx_pads,
193 ARRAY_SIZE(mx51efikamx_pads));
Arnaud Patard (Rtp)7ac18a32011-02-17 15:31:28 +0100194 efika_board_common_init();
195
Arnaud Patard (Rtp)f1dd3612010-10-27 14:40:46 +0200196 mx51_efikamx_board_id();
Arnaud Patard (Rtp)a96eb142010-10-27 14:40:49 +0200197
198 /* on < 1.2 boards both SD controllers are used */
Arnaud Patard (Rtp)9d2c0ef2010-10-27 14:40:51 +0200199 if (system_rev < 0x12) {
Arnaud Patard (Rtp)0ef51952010-11-26 15:27:53 +0100200 imx51_add_sdhci_esdhc_imx(1, NULL);
Arnaud Patard (Rtp)9d2c0ef2010-10-27 14:40:51 +0200201 mx51_efikamx_leds[2].default_trigger = "mmc1";
202 }
203
204 platform_device_register(&mx51_efikamx_leds_device);
Arnaud Patard (Rtp)fcbd0c52010-10-27 14:40:52 +0200205 imx51_add_gpio_keys(&mx51_efikamx_powerkey_data);
Arnaud Patard (Rtp)c6e34a42010-10-27 14:40:54 +0200206
Arnaud Patard (Rtp)c2932bf2010-10-27 14:40:55 +0200207 if (system_rev == 0x11) {
208 gpio_request(EFIKAMX_RESET1_1, "reset");
209 gpio_direction_output(EFIKAMX_RESET1_1, 1);
210 } else {
211 gpio_request(EFIKAMX_RESET, "reset");
212 gpio_direction_output(EFIKAMX_RESET, 1);
213 }
Amit Kucheria088d01b2010-10-07 03:58:12 +0300214}
215
216static void __init mx51_efikamx_timer_init(void)
217{
218 mx51_clocks_init(32768, 24000000, 22579200, 24576000);
219}
220
Uwe Kleine-Könige134fb22011-02-11 10:23:19 +0100221static struct sys_timer mx51_efikamx_timer = {
222 .init = mx51_efikamx_timer_init,
Amit Kucheria088d01b2010-10-07 03:58:12 +0300223};
224
225MACHINE_START(MX51_EFIKAMX, "Genesi EfikaMX nettop")
226 /* Maintainer: Amit Kucheria <amit.kucheria@linaro.org> */
Amit Kucheria088d01b2010-10-07 03:58:12 +0300227 .boot_params = MX51_PHYS_OFFSET + 0x100,
228 .map_io = mx51_map_io,
Uwe Kleine-Königab130422011-02-07 16:35:21 +0100229 .init_early = imx51_init_early,
Amit Kucheria088d01b2010-10-07 03:58:12 +0300230 .init_irq = mx51_init_irq,
Uwe Kleine-Könige134fb22011-02-11 10:23:19 +0100231 .timer = &mx51_efikamx_timer,
232 .init_machine = mx51_efikamx_init,
Amit Kucheria088d01b2010-10-07 03:58:12 +0300233MACHINE_END