blob: acab1911cb3c6f7eac1720515ac6d3634b3e84f3 [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>
Arnaud Patard (Rtp)2432cff2011-02-17 15:31:30 +010028#include <linux/mfd/mc13892.h>
29#include <linux/regulator/machine.h>
30#include <linux/regulator/consumer.h>
Amit Kucheria088d01b2010-10-07 03:58:12 +030031
32#include <mach/common.h>
33#include <mach/hardware.h>
34#include <mach/iomux-mx51.h>
35#include <mach/i2c.h>
36#include <mach/mxc_ehci.h>
37
38#include <asm/irq.h>
39#include <asm/setup.h>
40#include <asm/mach-types.h>
41#include <asm/mach/arch.h>
42#include <asm/mach/time.h>
43
44#include "devices-imx51.h"
45#include "devices.h"
Arnaud Patard (Rtp)7ac18a32011-02-17 15:31:28 +010046#include "efika.h"
Amit Kucheria81490fc2010-10-07 03:58:25 +030047
Arnaud Patard (Rtp)96886c42010-11-26 15:20:52 +010048#define EFIKAMX_PCBID0 IMX_GPIO_NR(3, 16)
49#define EFIKAMX_PCBID1 IMX_GPIO_NR(3, 17)
50#define EFIKAMX_PCBID2 IMX_GPIO_NR(3, 11)
Arnaud Patard (Rtp)f1dd3612010-10-27 14:40:46 +020051
Arnaud Patard (Rtp)96886c42010-11-26 15:20:52 +010052#define EFIKAMX_BLUE_LED IMX_GPIO_NR(3, 13)
53#define EFIKAMX_GREEN_LED IMX_GPIO_NR(3, 14)
54#define EFIKAMX_RED_LED IMX_GPIO_NR(3, 15)
Arnaud Patard (Rtp)9d2c0ef2010-10-27 14:40:51 +020055
Arnaud Patard (Rtp)96886c42010-11-26 15:20:52 +010056#define EFIKAMX_POWER_KEY IMX_GPIO_NR(2, 31)
Arnaud Patard (Rtp)fcbd0c52010-10-27 14:40:52 +020057
Arnaud Patard (Rtp)c2932bf2010-10-27 14:40:55 +020058/* board 1.1 doesn't have same reset gpio */
Arnaud Patard (Rtp)96886c42010-11-26 15:20:52 +010059#define EFIKAMX_RESET1_1 IMX_GPIO_NR(3, 2)
60#define EFIKAMX_RESET IMX_GPIO_NR(1, 4)
Arnaud Patard (Rtp)c2932bf2010-10-27 14:40:55 +020061
Arnaud Patard (Rtp)2432cff2011-02-17 15:31:30 +010062#define EFIKAMX_POWEROFF IMX_GPIO_NR(4, 13)
63
64#define EFIKAMX_PMIC IMX_GPIO_NR(1, 6)
65
Arnaud Patard (Rtp)f1dd3612010-10-27 14:40:46 +020066/* the pci ids pin have pull up. they're driven low according to board id */
67#define MX51_PAD_PCBID0 IOMUX_PAD(0x518, 0x130, 3, 0x0, 0, PAD_CTL_PUS_100K_UP)
68#define MX51_PAD_PCBID1 IOMUX_PAD(0x51C, 0x134, 3, 0x0, 0, PAD_CTL_PUS_100K_UP)
69#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 +020070#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 +020071
Lothar Waßmann8f5260c2010-10-26 14:28:31 +020072static iomux_v3_cfg_t mx51efikamx_pads[] = {
Arnaud Patard (Rtp)f1dd3612010-10-27 14:40:46 +020073 /* board id */
74 MX51_PAD_PCBID0,
75 MX51_PAD_PCBID1,
76 MX51_PAD_PCBID2,
Arnaud Patard (Rtp)a96eb142010-10-27 14:40:49 +020077
Arnaud Patard (Rtp)9d2c0ef2010-10-27 14:40:51 +020078 /* leds */
Sascha Haueree1ae4d2010-12-15 09:56:35 +010079 MX51_PAD_CSI1_D9__GPIO3_13,
80 MX51_PAD_CSI1_VSYNC__GPIO3_14,
81 MX51_PAD_CSI1_HSYNC__GPIO3_15,
Arnaud Patard (Rtp)fcbd0c52010-10-27 14:40:52 +020082
83 /* power key */
84 MX51_PAD_PWRKEY,
Arnaud Patard (Rtp)c6e34a42010-10-27 14:40:54 +020085
Arnaud Patard (Rtp)c2932bf2010-10-27 14:40:55 +020086 /* reset */
Sascha Haueree1ae4d2010-12-15 09:56:35 +010087 MX51_PAD_DI1_PIN13__GPIO3_2,
88 MX51_PAD_GPIO1_4__GPIO1_4,
Arnaud Patard (Rtp)2432cff2011-02-17 15:31:30 +010089
90 /* power off */
91 MX51_PAD_CSI2_VSYNC__GPIO4_13,
Amit Kucheria088d01b2010-10-07 03:58:12 +030092};
93
Arnaud Patard (Rtp)f1dd3612010-10-27 14:40:46 +020094/* PCBID2 PCBID1 PCBID0 STATE
95 1 1 1 ER1:rev1.1
96 1 1 0 ER2:rev1.2
97 1 0 1 ER3:rev1.3
98 1 0 0 ER4:rev1.4
99*/
100static void __init mx51_efikamx_board_id(void)
101{
102 int id;
103
104 /* things are taking time to settle */
105 msleep(150);
106
107 gpio_request(EFIKAMX_PCBID0, "pcbid0");
108 gpio_direction_input(EFIKAMX_PCBID0);
109 gpio_request(EFIKAMX_PCBID1, "pcbid1");
110 gpio_direction_input(EFIKAMX_PCBID1);
111 gpio_request(EFIKAMX_PCBID2, "pcbid2");
112 gpio_direction_input(EFIKAMX_PCBID2);
113
114 id = gpio_get_value(EFIKAMX_PCBID0);
115 id |= gpio_get_value(EFIKAMX_PCBID1) << 1;
116 id |= gpio_get_value(EFIKAMX_PCBID2) << 2;
117
118 switch (id) {
119 case 7:
120 system_rev = 0x11;
121 break;
122 case 6:
123 system_rev = 0x12;
124 break;
125 case 5:
126 system_rev = 0x13;
127 break;
128 case 4:
129 system_rev = 0x14;
130 break;
131 default:
132 system_rev = 0x10;
133 break;
134 }
135
136 if ((system_rev == 0x10)
137 || (system_rev == 0x12)
138 || (system_rev == 0x14)) {
139 printk(KERN_WARNING
140 "EfikaMX: Unsupported board revision 1.%u!\n",
141 system_rev & 0xf);
142 }
143}
144
Arnaud Patard (Rtp)9d2c0ef2010-10-27 14:40:51 +0200145static struct gpio_led mx51_efikamx_leds[] = {
146 {
147 .name = "efikamx:green",
148 .default_trigger = "default-on",
149 .gpio = EFIKAMX_GREEN_LED,
150 },
151 {
152 .name = "efikamx:red",
153 .default_trigger = "ide-disk",
154 .gpio = EFIKAMX_RED_LED,
155 },
156 {
157 .name = "efikamx:blue",
158 .default_trigger = "mmc0",
159 .gpio = EFIKAMX_BLUE_LED,
160 },
161};
162
163static struct gpio_led_platform_data mx51_efikamx_leds_data = {
164 .leds = mx51_efikamx_leds,
165 .num_leds = ARRAY_SIZE(mx51_efikamx_leds),
166};
167
168static struct platform_device mx51_efikamx_leds_device = {
169 .name = "leds-gpio",
170 .id = -1,
171 .dev = {
172 .platform_data = &mx51_efikamx_leds_data,
173 },
174};
175
Arnaud Patard (Rtp)fcbd0c52010-10-27 14:40:52 +0200176static struct gpio_keys_button mx51_efikamx_powerkey[] = {
177 {
178 .code = KEY_POWER,
179 .gpio = EFIKAMX_POWER_KEY,
180 .type = EV_PWR,
181 .desc = "Power Button (CM)",
182 .wakeup = 1,
183 .debounce_interval = 10, /* ms */
184 },
185};
186
187static const struct gpio_keys_platform_data mx51_efikamx_powerkey_data __initconst = {
188 .buttons = mx51_efikamx_powerkey,
189 .nbuttons = ARRAY_SIZE(mx51_efikamx_powerkey),
190};
191
Arnaud Patard (Rtp)c2932bf2010-10-27 14:40:55 +0200192void mx51_efikamx_reset(void)
193{
194 if (system_rev == 0x11)
195 gpio_direction_output(EFIKAMX_RESET1_1, 0);
196 else
197 gpio_direction_output(EFIKAMX_RESET, 0);
198}
199
Arnaud Patard (Rtp)2432cff2011-02-17 15:31:30 +0100200static struct regulator *pwgt1, *pwgt2, *coincell;
201
202static void mx51_efikamx_power_off(void)
203{
204 if (!IS_ERR(coincell))
205 regulator_disable(coincell);
206
207 if (!IS_ERR(pwgt1) && !IS_ERR(pwgt2)) {
208 regulator_disable(pwgt2);
209 regulator_disable(pwgt1);
210 }
211 gpio_direction_output(EFIKAMX_POWEROFF, 1);
212}
213
214static int __init mx51_efikamx_power_init(void)
215{
216 if (machine_is_mx51_efikamx()) {
217 pwgt1 = regulator_get(NULL, "pwgt1");
218 pwgt2 = regulator_get(NULL, "pwgt2");
219 if (!IS_ERR(pwgt1) && !IS_ERR(pwgt2)) {
220 regulator_enable(pwgt1);
221 regulator_enable(pwgt2);
222 }
223 gpio_request(EFIKAMX_POWEROFF, "poweroff");
224 pm_power_off = mx51_efikamx_power_off;
225
226 /* enable coincell charger. maybe need a small power driver ? */
227 coincell = regulator_get(NULL, "coincell");
228 if (!IS_ERR(coincell)) {
229 regulator_set_voltage(coincell, 3000000, 3000000);
230 regulator_enable(coincell);
231 }
232
233 regulator_has_full_constraints();
234 }
235
236 return 0;
237}
238late_initcall(mx51_efikamx_power_init);
239
Uwe Kleine-Könige134fb22011-02-11 10:23:19 +0100240static void __init mx51_efikamx_init(void)
Amit Kucheria088d01b2010-10-07 03:58:12 +0300241{
242 mxc_iomux_v3_setup_multiple_pads(mx51efikamx_pads,
243 ARRAY_SIZE(mx51efikamx_pads));
Arnaud Patard (Rtp)7ac18a32011-02-17 15:31:28 +0100244 efika_board_common_init();
245
Arnaud Patard (Rtp)f1dd3612010-10-27 14:40:46 +0200246 mx51_efikamx_board_id();
Arnaud Patard (Rtp)a96eb142010-10-27 14:40:49 +0200247
248 /* on < 1.2 boards both SD controllers are used */
Arnaud Patard (Rtp)9d2c0ef2010-10-27 14:40:51 +0200249 if (system_rev < 0x12) {
Arnaud Patard (Rtp)0ef51952010-11-26 15:27:53 +0100250 imx51_add_sdhci_esdhc_imx(1, NULL);
Arnaud Patard (Rtp)9d2c0ef2010-10-27 14:40:51 +0200251 mx51_efikamx_leds[2].default_trigger = "mmc1";
252 }
253
254 platform_device_register(&mx51_efikamx_leds_device);
Arnaud Patard (Rtp)fcbd0c52010-10-27 14:40:52 +0200255 imx51_add_gpio_keys(&mx51_efikamx_powerkey_data);
Arnaud Patard (Rtp)c6e34a42010-10-27 14:40:54 +0200256
Arnaud Patard (Rtp)c2932bf2010-10-27 14:40:55 +0200257 if (system_rev == 0x11) {
258 gpio_request(EFIKAMX_RESET1_1, "reset");
259 gpio_direction_output(EFIKAMX_RESET1_1, 1);
260 } else {
261 gpio_request(EFIKAMX_RESET, "reset");
262 gpio_direction_output(EFIKAMX_RESET, 1);
263 }
Arnaud Patard (Rtp)9d72af62011-02-17 15:31:29 +0100264
265 /*
266 * enable wifi by default only on mx
267 * sb and mx have same wlan pin but the value to enable it are
268 * different :/
269 */
270 gpio_request(EFIKA_WLAN_EN, "wlan_en");
271 gpio_direction_output(EFIKA_WLAN_EN, 0);
272 msleep(10);
273
274 gpio_request(EFIKA_WLAN_RESET, "wlan_rst");
275 gpio_direction_output(EFIKA_WLAN_RESET, 0);
276 msleep(10);
277 gpio_set_value(EFIKA_WLAN_RESET, 1);
Amit Kucheria088d01b2010-10-07 03:58:12 +0300278}
279
280static void __init mx51_efikamx_timer_init(void)
281{
282 mx51_clocks_init(32768, 24000000, 22579200, 24576000);
283}
284
Uwe Kleine-Könige134fb22011-02-11 10:23:19 +0100285static struct sys_timer mx51_efikamx_timer = {
286 .init = mx51_efikamx_timer_init,
Amit Kucheria088d01b2010-10-07 03:58:12 +0300287};
288
289MACHINE_START(MX51_EFIKAMX, "Genesi EfikaMX nettop")
290 /* Maintainer: Amit Kucheria <amit.kucheria@linaro.org> */
Amit Kucheria088d01b2010-10-07 03:58:12 +0300291 .boot_params = MX51_PHYS_OFFSET + 0x100,
292 .map_io = mx51_map_io,
Uwe Kleine-Königab130422011-02-07 16:35:21 +0100293 .init_early = imx51_init_early,
Amit Kucheria088d01b2010-10-07 03:58:12 +0300294 .init_irq = mx51_init_irq,
Uwe Kleine-Könige134fb22011-02-11 10:23:19 +0100295 .timer = &mx51_efikamx_timer,
296 .init_machine = mx51_efikamx_init,
Amit Kucheria088d01b2010-10-07 03:58:12 +0300297MACHINE_END