blob: 10f0562c3c48ced4d44185925df14140314c7179 [file] [log] [blame]
Arnaud Patard (Rtp)102c91d2011-02-17 15:31:32 +01001/*
2 * Copyright (C) Arnaud Patard <arnaud.patard@rtp-net.org>
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>
21#include <linux/leds.h>
22#include <linux/input.h>
23#include <linux/delay.h>
24#include <linux/io.h>
Arnaud Patard (Rtp)102c91d2011-02-17 15:31:32 +010025#include <linux/spi/flash.h>
26#include <linux/spi/spi.h>
27#include <linux/mfd/mc13892.h>
28#include <linux/regulator/machine.h>
29#include <linux/regulator/consumer.h>
30#include <linux/usb/otg.h>
31#include <linux/usb/ulpi.h>
32#include <mach/ulpi.h>
33
34#include <mach/common.h>
35#include <mach/hardware.h>
36#include <mach/iomux-mx51.h>
Arnaud Patard (Rtp)102c91d2011-02-17 15:31:32 +010037
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"
Arnaud Patard (Rtp)102c91d2011-02-17 15:31:32 +010045#include "efika.h"
46
47#define EFIKASB_USBH2_STP IMX_GPIO_NR(2, 20)
48#define EFIKASB_GREEN_LED IMX_GPIO_NR(1, 3)
49#define EFIKASB_WHITE_LED IMX_GPIO_NR(2, 25)
50#define EFIKASB_PCBID0 IMX_GPIO_NR(2, 28)
51#define EFIKASB_PCBID1 IMX_GPIO_NR(2, 29)
52#define EFIKASB_PWRKEY IMX_GPIO_NR(2, 31)
53#define EFIKASB_LID IMX_GPIO_NR(3, 14)
54#define EFIKASB_POWEROFF IMX_GPIO_NR(4, 13)
55#define EFIKASB_RFKILL IMX_GPIO_NR(3, 1)
56
57#define MX51_PAD_PWRKEY IOMUX_PAD(0x48c, 0x0f8, 1, 0x0, 0, PAD_CTL_PUS_100K_UP | PAD_CTL_PKE)
58
59static iomux_v3_cfg_t mx51efikasb_pads[] = {
60 /* USB HOST2 */
61 MX51_PAD_EIM_D16__USBH2_DATA0,
62 MX51_PAD_EIM_D17__USBH2_DATA1,
63 MX51_PAD_EIM_D18__USBH2_DATA2,
64 MX51_PAD_EIM_D19__USBH2_DATA3,
65 MX51_PAD_EIM_D20__USBH2_DATA4,
66 MX51_PAD_EIM_D21__USBH2_DATA5,
67 MX51_PAD_EIM_D22__USBH2_DATA6,
68 MX51_PAD_EIM_D23__USBH2_DATA7,
69 MX51_PAD_EIM_A24__USBH2_CLK,
70 MX51_PAD_EIM_A25__USBH2_DIR,
71 MX51_PAD_EIM_A26__USBH2_STP,
72 MX51_PAD_EIM_A27__USBH2_NXT,
73
74 /* leds */
75 MX51_PAD_EIM_CS0__GPIO2_25,
76 MX51_PAD_GPIO1_3__GPIO1_3,
77
78 /* pcb id */
79 MX51_PAD_EIM_CS3__GPIO2_28,
80 MX51_PAD_EIM_CS4__GPIO2_29,
81
82 /* lid */
83 MX51_PAD_CSI1_VSYNC__GPIO3_14,
84
85 /* power key*/
86 MX51_PAD_PWRKEY,
87
88 /* wifi/bt button */
89 MX51_PAD_DI1_PIN12__GPIO3_1,
90
91 /* power off */
92 MX51_PAD_CSI2_VSYNC__GPIO4_13,
93
94 /* wdog reset */
95 MX51_PAD_GPIO1_4__WDOG1_WDOG_B,
96
97 /* BT */
98 MX51_PAD_EIM_A17__GPIO2_11,
99};
100
101static int initialize_usbh2_port(struct platform_device *pdev)
102{
103 iomux_v3_cfg_t usbh2stp = MX51_PAD_EIM_A26__USBH2_STP;
104 iomux_v3_cfg_t usbh2gpio = MX51_PAD_EIM_A26__GPIO2_20;
105
106 mxc_iomux_v3_setup_pad(usbh2gpio);
107 gpio_request(EFIKASB_USBH2_STP, "usbh2_stp");
108 gpio_direction_output(EFIKASB_USBH2_STP, 0);
109 msleep(1);
110 gpio_set_value(EFIKASB_USBH2_STP, 1);
111 msleep(1);
112
113 gpio_free(EFIKASB_USBH2_STP);
114 mxc_iomux_v3_setup_pad(usbh2stp);
115
116 mdelay(10);
117
118 return mx51_initialize_usb_hw(pdev->id, MXC_EHCI_ITC_NO_THRESHOLD);
119}
120
Uwe Kleine-König7d92e8e2011-07-30 23:41:49 +0200121static struct mxc_usbh_platform_data usbh2_config __initdata = {
Arnaud Patard (Rtp)102c91d2011-02-17 15:31:32 +0100122 .init = initialize_usbh2_port,
123 .portsc = MXC_EHCI_MODE_ULPI,
124};
125
126static void __init mx51_efikasb_usb(void)
127{
Sascha Hauer48f6b092011-03-02 09:27:42 +0100128 usbh2_config.otg = imx_otg_ulpi_create(ULPI_OTG_DRVVBUS |
129 ULPI_OTG_DRVVBUS_EXT | ULPI_OTG_EXTVBUSIND);
130 if (usbh2_config.otg)
Uwe Kleine-König7d92e8e2011-07-30 23:41:49 +0200131 imx51_add_mxc_ehci_hs(2, &usbh2_config);
Arnaud Patard (Rtp)102c91d2011-02-17 15:31:32 +0100132}
133
Uwe Kleine-König5b8d6282011-05-28 21:05:02 +0200134static const struct gpio_led mx51_efikasb_leds[] __initconst = {
Arnaud Patard (Rtp)102c91d2011-02-17 15:31:32 +0100135 {
136 .name = "efikasb:green",
137 .default_trigger = "default-on",
138 .gpio = EFIKASB_GREEN_LED,
139 .active_low = 1,
140 },
141 {
142 .name = "efikasb:white",
143 .default_trigger = "caps",
144 .gpio = EFIKASB_WHITE_LED,
145 },
146};
147
Uwe Kleine-König5b8d6282011-05-28 21:05:02 +0200148static const struct gpio_led_platform_data
149 mx51_efikasb_leds_data __initconst = {
Arnaud Patard (Rtp)102c91d2011-02-17 15:31:32 +0100150 .leds = mx51_efikasb_leds,
151 .num_leds = ARRAY_SIZE(mx51_efikasb_leds),
152};
153
Arnaud Patard (Rtp)102c91d2011-02-17 15:31:32 +0100154static struct gpio_keys_button mx51_efikasb_keys[] = {
155 {
156 .code = KEY_POWER,
157 .gpio = EFIKASB_PWRKEY,
158 .type = EV_PWR,
159 .desc = "Power Button",
160 .wakeup = 1,
161 .debounce_interval = 10, /* ms */
162 },
163 {
164 .code = SW_LID,
165 .gpio = EFIKASB_LID,
166 .type = EV_SW,
167 .desc = "Lid Switch",
168 },
169 {
170 /* SW_RFKILLALL vs KEY_RFKILL ? */
171 .code = SW_RFKILL_ALL,
172 .gpio = EFIKASB_RFKILL,
173 .type = EV_SW,
174 .desc = "rfkill",
175 },
176};
177
178static const struct gpio_keys_platform_data mx51_efikasb_keys_data __initconst = {
179 .buttons = mx51_efikasb_keys,
180 .nbuttons = ARRAY_SIZE(mx51_efikasb_keys),
181};
182
183static struct regulator *pwgt1, *pwgt2;
184
185static void mx51_efikasb_power_off(void)
186{
187 gpio_set_value(EFIKA_USB_PHY_RESET, 0);
188
189 if (!IS_ERR(pwgt1) && !IS_ERR(pwgt2)) {
190 regulator_disable(pwgt2);
191 regulator_disable(pwgt1);
192 }
193 gpio_direction_output(EFIKASB_POWEROFF, 1);
194}
195
196static int __init mx51_efikasb_power_init(void)
197{
198 if (machine_is_mx51_efikasb()) {
199 pwgt1 = regulator_get(NULL, "pwgt1");
200 pwgt2 = regulator_get(NULL, "pwgt2");
201 if (!IS_ERR(pwgt1) && !IS_ERR(pwgt2)) {
202 regulator_enable(pwgt1);
203 regulator_enable(pwgt2);
204 }
205 gpio_request(EFIKASB_POWEROFF, "poweroff");
206 pm_power_off = mx51_efikasb_power_off;
207
208 regulator_has_full_constraints();
209 }
210
211 return 0;
212}
213late_initcall(mx51_efikasb_power_init);
214
215/* 01 R1.3 board
216 10 R2.0 board */
217static void __init mx51_efikasb_board_id(void)
218{
219 int id;
220
221 gpio_request(EFIKASB_PCBID0, "pcb id0");
222 gpio_direction_input(EFIKASB_PCBID0);
223 gpio_request(EFIKASB_PCBID1, "pcb id1");
224 gpio_direction_input(EFIKASB_PCBID1);
225
226 id = gpio_get_value(EFIKASB_PCBID0);
227 id |= gpio_get_value(EFIKASB_PCBID1) << 1;
228
229 switch (id) {
230 default:
231 break;
232 case 1:
233 system_rev = 0x13;
234 break;
235 case 2:
236 system_rev = 0x20;
237 break;
238 }
239}
240
241static void __init efikasb_board_init(void)
242{
Shawn Guob78d8e52011-06-06 00:07:55 +0800243 imx51_soc_init();
244
Arnaud Patard (Rtp)102c91d2011-02-17 15:31:32 +0100245 mxc_iomux_v3_setup_multiple_pads(mx51efikasb_pads,
246 ARRAY_SIZE(mx51efikasb_pads));
247 efika_board_common_init();
248
249 mx51_efikasb_board_id();
250 mx51_efikasb_usb();
251 imx51_add_sdhci_esdhc_imx(1, NULL);
252
Uwe Kleine-König5b8d6282011-05-28 21:05:02 +0200253 gpio_led_register_device(-1, &mx51_efikasb_leds_data);
Fabio Estevamba8a6c02011-04-06 13:05:26 -0300254 imx_add_gpio_keys(&mx51_efikasb_keys_data);
Arnaud Patard (Rtp)102c91d2011-02-17 15:31:32 +0100255}
256
257static void __init mx51_efikasb_timer_init(void)
258{
259 mx51_clocks_init(32768, 24000000, 22579200, 24576000);
260}
261
262static struct sys_timer mx51_efikasb_timer = {
263 .init = mx51_efikasb_timer_init,
264};
265
266MACHINE_START(MX51_EFIKASB, "Genesi Efika Smartbook")
267 .boot_params = MX51_PHYS_OFFSET + 0x100,
268 .map_io = mx51_map_io,
269 .init_early = imx51_init_early,
270 .init_irq = mx51_init_irq,
271 .init_machine = efikasb_board_init,
272 .timer = &mx51_efikasb_timer,
273MACHINE_END