blob: 586e9f82212400555e42dca1b00492bf0c076b16 [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>
Arnaud Patard (Rtp)c6e34a4c2010-10-27 14:40:54 +020025#include <linux/spi/flash.h>
26#include <linux/spi/spi.h>
Arnaud Patard (Rtp)2432cff2011-02-17 15:31:30 +010027#include <linux/mfd/mc13892.h>
28#include <linux/regulator/machine.h>
29#include <linux/regulator/consumer.h>
Amit Kucheria088d01b2010-10-07 03:58:12 +030030
31#include <mach/common.h>
32#include <mach/hardware.h>
33#include <mach/iomux-mx51.h>
Amit Kucheria088d01b2010-10-07 03:58:12 +030034
Amit Kucheria088d01b2010-10-07 03:58:12 +030035#include <asm/setup.h>
David Howells9f97da72012-03-28 18:30:01 +010036#include <asm/system_info.h>
Amit Kucheria088d01b2010-10-07 03:58:12 +030037#include <asm/mach-types.h>
38#include <asm/mach/arch.h>
39#include <asm/mach/time.h>
40
41#include "devices-imx51.h"
Arnaud Patard (Rtp)7ac18a32011-02-17 15:31:28 +010042#include "efika.h"
Amit Kucheria81490fc2010-10-07 03:58:25 +030043
Arnaud Patard (Rtp)96886c42010-11-26 15:20:52 +010044#define EFIKAMX_PCBID0 IMX_GPIO_NR(3, 16)
45#define EFIKAMX_PCBID1 IMX_GPIO_NR(3, 17)
46#define EFIKAMX_PCBID2 IMX_GPIO_NR(3, 11)
Arnaud Patard (Rtp)f1dd3612010-10-27 14:40:46 +020047
Arnaud Patard (Rtp)96886c42010-11-26 15:20:52 +010048#define EFIKAMX_BLUE_LED IMX_GPIO_NR(3, 13)
49#define EFIKAMX_GREEN_LED IMX_GPIO_NR(3, 14)
50#define EFIKAMX_RED_LED IMX_GPIO_NR(3, 15)
Arnaud Patard (Rtp)9d2c0ef2010-10-27 14:40:51 +020051
Arnaud Patard (Rtp)96886c42010-11-26 15:20:52 +010052#define EFIKAMX_POWER_KEY IMX_GPIO_NR(2, 31)
Arnaud Patard (Rtp)fcbd0c52010-10-27 14:40:52 +020053
Arnaud Patard (Rtp)c2932bf2010-10-27 14:40:55 +020054/* board 1.1 doesn't have same reset gpio */
Arnaud Patard (Rtp)96886c42010-11-26 15:20:52 +010055#define EFIKAMX_RESET1_1 IMX_GPIO_NR(3, 2)
56#define EFIKAMX_RESET IMX_GPIO_NR(1, 4)
Arnaud Patard (Rtp)c2932bf2010-10-27 14:40:55 +020057
Arnaud Patard (Rtp)2432cff2011-02-17 15:31:30 +010058#define EFIKAMX_POWEROFF IMX_GPIO_NR(4, 13)
59
60#define EFIKAMX_PMIC IMX_GPIO_NR(1, 6)
61
Arnaud Patard (Rtp)f1dd3612010-10-27 14:40:46 +020062/* the pci ids pin have pull up. they're driven low according to board id */
63#define MX51_PAD_PCBID0 IOMUX_PAD(0x518, 0x130, 3, 0x0, 0, PAD_CTL_PUS_100K_UP)
64#define MX51_PAD_PCBID1 IOMUX_PAD(0x51C, 0x134, 3, 0x0, 0, PAD_CTL_PUS_100K_UP)
65#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 +020066#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 +020067
Lothar Waßmann8f5260c2010-10-26 14:28:31 +020068static iomux_v3_cfg_t mx51efikamx_pads[] = {
Arnaud Patard (Rtp)f1dd3612010-10-27 14:40:46 +020069 /* board id */
70 MX51_PAD_PCBID0,
71 MX51_PAD_PCBID1,
72 MX51_PAD_PCBID2,
Arnaud Patard (Rtp)a96eb142010-10-27 14:40:49 +020073
Arnaud Patard (Rtp)9d2c0ef2010-10-27 14:40:51 +020074 /* leds */
Sascha Haueree1ae4d2010-12-15 09:56:35 +010075 MX51_PAD_CSI1_D9__GPIO3_13,
76 MX51_PAD_CSI1_VSYNC__GPIO3_14,
77 MX51_PAD_CSI1_HSYNC__GPIO3_15,
Arnaud Patard (Rtp)fcbd0c52010-10-27 14:40:52 +020078
79 /* power key */
80 MX51_PAD_PWRKEY,
Arnaud Patard (Rtp)c6e34a4c2010-10-27 14:40:54 +020081
Arnaud Patard (Rtp)c2932bf2010-10-27 14:40:55 +020082 /* reset */
Sascha Haueree1ae4d2010-12-15 09:56:35 +010083 MX51_PAD_DI1_PIN13__GPIO3_2,
84 MX51_PAD_GPIO1_4__GPIO1_4,
Arnaud Patard (Rtp)2432cff2011-02-17 15:31:30 +010085
86 /* power off */
87 MX51_PAD_CSI2_VSYNC__GPIO4_13,
Amit Kucheria088d01b2010-10-07 03:58:12 +030088};
89
Arnaud Patard (Rtp)f1dd3612010-10-27 14:40:46 +020090/* PCBID2 PCBID1 PCBID0 STATE
91 1 1 1 ER1:rev1.1
92 1 1 0 ER2:rev1.2
93 1 0 1 ER3:rev1.3
94 1 0 0 ER4:rev1.4
95*/
96static void __init mx51_efikamx_board_id(void)
97{
98 int id;
99
100 /* things are taking time to settle */
101 msleep(150);
102
103 gpio_request(EFIKAMX_PCBID0, "pcbid0");
104 gpio_direction_input(EFIKAMX_PCBID0);
105 gpio_request(EFIKAMX_PCBID1, "pcbid1");
106 gpio_direction_input(EFIKAMX_PCBID1);
107 gpio_request(EFIKAMX_PCBID2, "pcbid2");
108 gpio_direction_input(EFIKAMX_PCBID2);
109
Arnaud Patard (Rtp)fbd60a72011-06-27 22:41:06 +0200110 id = gpio_get_value(EFIKAMX_PCBID0) ? 1 : 0;
111 id |= (gpio_get_value(EFIKAMX_PCBID1) ? 1 : 0) << 1;
112 id |= (gpio_get_value(EFIKAMX_PCBID2) ? 1 : 0) << 2;
Arnaud Patard (Rtp)f1dd3612010-10-27 14:40:46 +0200113
114 switch (id) {
115 case 7:
116 system_rev = 0x11;
117 break;
118 case 6:
119 system_rev = 0x12;
120 break;
121 case 5:
122 system_rev = 0x13;
123 break;
124 case 4:
125 system_rev = 0x14;
126 break;
127 default:
128 system_rev = 0x10;
129 break;
130 }
131
132 if ((system_rev == 0x10)
133 || (system_rev == 0x12)
134 || (system_rev == 0x14)) {
135 printk(KERN_WARNING
136 "EfikaMX: Unsupported board revision 1.%u!\n",
137 system_rev & 0xf);
138 }
139}
140
Uwe Kleine-König5b8d6282011-05-28 21:05:02 +0200141static struct gpio_led mx51_efikamx_leds[] __initdata = {
Arnaud Patard (Rtp)9d2c0ef2010-10-27 14:40:51 +0200142 {
143 .name = "efikamx:green",
144 .default_trigger = "default-on",
145 .gpio = EFIKAMX_GREEN_LED,
146 },
147 {
148 .name = "efikamx:red",
149 .default_trigger = "ide-disk",
150 .gpio = EFIKAMX_RED_LED,
151 },
152 {
153 .name = "efikamx:blue",
154 .default_trigger = "mmc0",
155 .gpio = EFIKAMX_BLUE_LED,
156 },
157};
158
Uwe Kleine-König5b8d6282011-05-28 21:05:02 +0200159static const struct gpio_led_platform_data
160 mx51_efikamx_leds_data __initconst = {
Arnaud Patard (Rtp)9d2c0ef2010-10-27 14:40:51 +0200161 .leds = mx51_efikamx_leds,
162 .num_leds = ARRAY_SIZE(mx51_efikamx_leds),
163};
164
Arnaud Patard (Rtp)600ea5c2011-08-27 15:15:58 +0200165static struct esdhc_platform_data sd_pdata = {
166 .cd_type = ESDHC_CD_CONTROLLER,
167 .wp_type = ESDHC_WP_CONTROLLER,
168};
169
Arnaud Patard (Rtp)fcbd0c52010-10-27 14:40:52 +0200170static struct gpio_keys_button mx51_efikamx_powerkey[] = {
171 {
172 .code = KEY_POWER,
173 .gpio = EFIKAMX_POWER_KEY,
174 .type = EV_PWR,
175 .desc = "Power Button (CM)",
176 .wakeup = 1,
177 .debounce_interval = 10, /* ms */
178 },
179};
180
181static const struct gpio_keys_platform_data mx51_efikamx_powerkey_data __initconst = {
182 .buttons = mx51_efikamx_powerkey,
183 .nbuttons = ARRAY_SIZE(mx51_efikamx_powerkey),
184};
185
Russell King65ea7882011-11-06 17:12:08 +0000186static void mx51_efikamx_restart(char mode, const char *cmd)
Arnaud Patard (Rtp)c2932bf2010-10-27 14:40:55 +0200187{
188 if (system_rev == 0x11)
189 gpio_direction_output(EFIKAMX_RESET1_1, 0);
190 else
191 gpio_direction_output(EFIKAMX_RESET, 0);
192}
193
Arnaud Patard (Rtp)2432cff2011-02-17 15:31:30 +0100194static struct regulator *pwgt1, *pwgt2, *coincell;
195
196static void mx51_efikamx_power_off(void)
197{
198 if (!IS_ERR(coincell))
199 regulator_disable(coincell);
200
201 if (!IS_ERR(pwgt1) && !IS_ERR(pwgt2)) {
202 regulator_disable(pwgt2);
203 regulator_disable(pwgt1);
204 }
205 gpio_direction_output(EFIKAMX_POWEROFF, 1);
206}
207
208static int __init mx51_efikamx_power_init(void)
209{
210 if (machine_is_mx51_efikamx()) {
211 pwgt1 = regulator_get(NULL, "pwgt1");
212 pwgt2 = regulator_get(NULL, "pwgt2");
213 if (!IS_ERR(pwgt1) && !IS_ERR(pwgt2)) {
214 regulator_enable(pwgt1);
215 regulator_enable(pwgt2);
216 }
217 gpio_request(EFIKAMX_POWEROFF, "poweroff");
218 pm_power_off = mx51_efikamx_power_off;
219
220 /* enable coincell charger. maybe need a small power driver ? */
221 coincell = regulator_get(NULL, "coincell");
222 if (!IS_ERR(coincell)) {
223 regulator_set_voltage(coincell, 3000000, 3000000);
224 regulator_enable(coincell);
225 }
226
227 regulator_has_full_constraints();
228 }
229
230 return 0;
231}
232late_initcall(mx51_efikamx_power_init);
233
Uwe Kleine-Könige134fb22011-02-11 10:23:19 +0100234static void __init mx51_efikamx_init(void)
Amit Kucheria088d01b2010-10-07 03:58:12 +0300235{
Shawn Guob78d8e52011-06-06 00:07:55 +0800236 imx51_soc_init();
237
Amit Kucheria088d01b2010-10-07 03:58:12 +0300238 mxc_iomux_v3_setup_multiple_pads(mx51efikamx_pads,
239 ARRAY_SIZE(mx51efikamx_pads));
Arnaud Patard (Rtp)7ac18a32011-02-17 15:31:28 +0100240 efika_board_common_init();
241
Arnaud Patard (Rtp)f1dd3612010-10-27 14:40:46 +0200242 mx51_efikamx_board_id();
Arnaud Patard (Rtp)a96eb142010-10-27 14:40:49 +0200243
244 /* on < 1.2 boards both SD controllers are used */
Arnaud Patard (Rtp)9d2c0ef2010-10-27 14:40:51 +0200245 if (system_rev < 0x12) {
Arnaud Patard (Rtp)600ea5c2011-08-27 15:15:58 +0200246 imx51_add_sdhci_esdhc_imx(0, NULL);
247 imx51_add_sdhci_esdhc_imx(1, &sd_pdata);
Arnaud Patard (Rtp)9d2c0ef2010-10-27 14:40:51 +0200248 mx51_efikamx_leds[2].default_trigger = "mmc1";
Arnaud Patard (Rtp)600ea5c2011-08-27 15:15:58 +0200249 } else
250 imx51_add_sdhci_esdhc_imx(0, &sd_pdata);
Arnaud Patard (Rtp)9d2c0ef2010-10-27 14:40:51 +0200251
Uwe Kleine-König5b8d6282011-05-28 21:05:02 +0200252 gpio_led_register_device(-1, &mx51_efikamx_leds_data);
Fabio Estevamba8a6c02011-04-06 13:05:26 -0300253 imx_add_gpio_keys(&mx51_efikamx_powerkey_data);
Arnaud Patard (Rtp)c6e34a4c2010-10-27 14:40:54 +0200254
Arnaud Patard (Rtp)c2932bf2010-10-27 14:40:55 +0200255 if (system_rev == 0x11) {
256 gpio_request(EFIKAMX_RESET1_1, "reset");
257 gpio_direction_output(EFIKAMX_RESET1_1, 1);
258 } else {
259 gpio_request(EFIKAMX_RESET, "reset");
260 gpio_direction_output(EFIKAMX_RESET, 1);
261 }
Arnaud Patard (Rtp)9d72af62011-02-17 15:31:29 +0100262
263 /*
264 * enable wifi by default only on mx
265 * sb and mx have same wlan pin but the value to enable it are
266 * different :/
267 */
268 gpio_request(EFIKA_WLAN_EN, "wlan_en");
269 gpio_direction_output(EFIKA_WLAN_EN, 0);
270 msleep(10);
271
272 gpio_request(EFIKA_WLAN_RESET, "wlan_rst");
273 gpio_direction_output(EFIKA_WLAN_RESET, 0);
274 msleep(10);
275 gpio_set_value(EFIKA_WLAN_RESET, 1);
Amit Kucheria088d01b2010-10-07 03:58:12 +0300276}
277
278static void __init mx51_efikamx_timer_init(void)
279{
280 mx51_clocks_init(32768, 24000000, 22579200, 24576000);
281}
282
Uwe Kleine-Könige134fb22011-02-11 10:23:19 +0100283static struct sys_timer mx51_efikamx_timer = {
284 .init = mx51_efikamx_timer_init,
Amit Kucheria088d01b2010-10-07 03:58:12 +0300285};
286
287MACHINE_START(MX51_EFIKAMX, "Genesi EfikaMX nettop")
288 /* Maintainer: Amit Kucheria <amit.kucheria@linaro.org> */
Nicolas Pitre61929352011-07-05 22:38:14 -0400289 .atag_offset = 0x100,
Amit Kucheria088d01b2010-10-07 03:58:12 +0300290 .map_io = mx51_map_io,
Uwe Kleine-Königab1304212011-02-07 16:35:21 +0100291 .init_early = imx51_init_early,
Amit Kucheria088d01b2010-10-07 03:58:12 +0300292 .init_irq = mx51_init_irq,
Sascha Hauerffa2ea32011-09-20 14:31:24 +0200293 .handle_irq = imx51_handle_irq,
Uwe Kleine-Könige134fb22011-02-11 10:23:19 +0100294 .timer = &mx51_efikamx_timer,
295 .init_machine = mx51_efikamx_init,
Russell King65ea7882011-11-06 17:12:08 +0000296 .restart = mx51_efikamx_restart,
Amit Kucheria088d01b2010-10-07 03:58:12 +0300297MACHINE_END