PageRenderTime 26ms CodeModel.GetById 7ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 0ms

/arch/arm/mach-mx5/board-mx51_efikamx.c

https://github.com/AICP/kernel_asus_grouper
C | 289 lines | 207 code | 45 blank | 37 comment | 20 complexity | 79162bd6490134f1e4ba33a87ea5e96e MD5 | raw file
  1/*
  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>
 21#include <linux/leds.h>
 22#include <linux/input.h>
 23#include <linux/delay.h>
 24#include <linux/io.h>
 25#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
 31#include <mach/common.h>
 32#include <mach/hardware.h>
 33#include <mach/iomux-mx51.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"
 43#include "efika.h"
 44
 45#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)
 48
 49#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)
 52
 53#define EFIKAMX_POWER_KEY	IMX_GPIO_NR(2, 31)
 54
 55/* board 1.1 doesn't have same reset gpio */
 56#define EFIKAMX_RESET1_1	IMX_GPIO_NR(3, 2)
 57#define EFIKAMX_RESET		IMX_GPIO_NR(1, 4)
 58
 59#define EFIKAMX_POWEROFF	IMX_GPIO_NR(4, 13)
 60
 61#define EFIKAMX_PMIC		IMX_GPIO_NR(1, 6)
 62
 63/* the pci ids pin have pull up. they're driven low according to board id */
 64#define MX51_PAD_PCBID0	IOMUX_PAD(0x518, 0x130, 3, 0x0,   0, PAD_CTL_PUS_100K_UP)
 65#define MX51_PAD_PCBID1	IOMUX_PAD(0x51C, 0x134, 3, 0x0,   0, PAD_CTL_PUS_100K_UP)
 66#define MX51_PAD_PCBID2	IOMUX_PAD(0x504, 0x128, 3, 0x0,   0, PAD_CTL_PUS_100K_UP)
 67#define MX51_PAD_PWRKEY	IOMUX_PAD(0x48c, 0x0f8, 1, 0x0,   0, PAD_CTL_PUS_100K_UP | PAD_CTL_PKE)
 68
 69static iomux_v3_cfg_t mx51efikamx_pads[] = {
 70	/* board id */
 71	MX51_PAD_PCBID0,
 72	MX51_PAD_PCBID1,
 73	MX51_PAD_PCBID2,
 74
 75	/* leds */
 76	MX51_PAD_CSI1_D9__GPIO3_13,
 77	MX51_PAD_CSI1_VSYNC__GPIO3_14,
 78	MX51_PAD_CSI1_HSYNC__GPIO3_15,
 79
 80	/* power key */
 81	MX51_PAD_PWRKEY,
 82
 83	/* reset */
 84	MX51_PAD_DI1_PIN13__GPIO3_2,
 85	MX51_PAD_GPIO1_4__GPIO1_4,
 86
 87	/* power off */
 88	MX51_PAD_CSI2_VSYNC__GPIO4_13,
 89};
 90
 91/*   PCBID2  PCBID1 PCBID0  STATE
 92	1       1      1    ER1:rev1.1
 93	1       1      0    ER2:rev1.2
 94	1       0      1    ER3:rev1.3
 95	1       0      0    ER4:rev1.4
 96*/
 97static void __init mx51_efikamx_board_id(void)
 98{
 99	int id;
100
101	/* things are taking time to settle */
102	msleep(150);
103
104	gpio_request(EFIKAMX_PCBID0, "pcbid0");
105	gpio_direction_input(EFIKAMX_PCBID0);
106	gpio_request(EFIKAMX_PCBID1, "pcbid1");
107	gpio_direction_input(EFIKAMX_PCBID1);
108	gpio_request(EFIKAMX_PCBID2, "pcbid2");
109	gpio_direction_input(EFIKAMX_PCBID2);
110
111	id = gpio_get_value(EFIKAMX_PCBID0) ? 1 : 0;
112	id |= (gpio_get_value(EFIKAMX_PCBID1) ? 1 : 0) << 1;
113	id |= (gpio_get_value(EFIKAMX_PCBID2) ? 1 : 0) << 2;
114
115	switch (id) {
116	case 7:
117		system_rev = 0x11;
118		break;
119	case 6:
120		system_rev = 0x12;
121		break;
122	case 5:
123		system_rev = 0x13;
124		break;
125	case 4:
126		system_rev = 0x14;
127		break;
128	default:
129		system_rev = 0x10;
130		break;
131	}
132
133	if ((system_rev == 0x10)
134		|| (system_rev == 0x12)
135		|| (system_rev == 0x14)) {
136		printk(KERN_WARNING
137			"EfikaMX: Unsupported board revision 1.%u!\n",
138			system_rev & 0xf);
139	}
140}
141
142static struct gpio_led mx51_efikamx_leds[] __initdata = {
143	{
144		.name = "efikamx:green",
145		.default_trigger = "default-on",
146		.gpio = EFIKAMX_GREEN_LED,
147	},
148	{
149		.name = "efikamx:red",
150		.default_trigger = "ide-disk",
151		.gpio = EFIKAMX_RED_LED,
152	},
153	{
154		.name = "efikamx:blue",
155		.default_trigger = "mmc0",
156		.gpio = EFIKAMX_BLUE_LED,
157	},
158};
159
160static const struct gpio_led_platform_data
161		mx51_efikamx_leds_data __initconst = {
162	.leds = mx51_efikamx_leds,
163	.num_leds = ARRAY_SIZE(mx51_efikamx_leds),
164};
165
166static 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
182void 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
190static struct regulator *pwgt1, *pwgt2, *coincell;
191
192static void mx51_efikamx_power_off(void)
193{
194	if (!IS_ERR(coincell))
195		regulator_disable(coincell);
196
197	if (!IS_ERR(pwgt1) && !IS_ERR(pwgt2)) {
198		regulator_disable(pwgt2);
199		regulator_disable(pwgt1);
200	}
201	gpio_direction_output(EFIKAMX_POWEROFF, 1);
202}
203
204static int __init mx51_efikamx_power_init(void)
205{
206	if (machine_is_mx51_efikamx()) {
207		pwgt1 = regulator_get(NULL, "pwgt1");
208		pwgt2 = regulator_get(NULL, "pwgt2");
209		if (!IS_ERR(pwgt1) && !IS_ERR(pwgt2)) {
210			regulator_enable(pwgt1);
211			regulator_enable(pwgt2);
212		}
213		gpio_request(EFIKAMX_POWEROFF, "poweroff");
214		pm_power_off = mx51_efikamx_power_off;
215
216		/* enable coincell charger. maybe need a small power driver ? */
217		coincell = regulator_get(NULL, "coincell");
218		if (!IS_ERR(coincell)) {
219			regulator_set_voltage(coincell, 3000000, 3000000);
220			regulator_enable(coincell);
221		}
222
223		regulator_has_full_constraints();
224	}
225
226	return 0;
227}
228late_initcall(mx51_efikamx_power_init);
229
230static void __init mx51_efikamx_init(void)
231{
232	imx51_soc_init();
233
234	mxc_iomux_v3_setup_multiple_pads(mx51efikamx_pads,
235					ARRAY_SIZE(mx51efikamx_pads));
236	efika_board_common_init();
237
238	mx51_efikamx_board_id();
239
240	/* on < 1.2 boards both SD controllers are used */
241	if (system_rev < 0x12) {
242		imx51_add_sdhci_esdhc_imx(1, NULL);
243		mx51_efikamx_leds[2].default_trigger = "mmc1";
244	}
245
246	gpio_led_register_device(-1, &mx51_efikamx_leds_data);
247	imx_add_gpio_keys(&mx51_efikamx_powerkey_data);
248
249	if (system_rev == 0x11) {
250		gpio_request(EFIKAMX_RESET1_1, "reset");
251		gpio_direction_output(EFIKAMX_RESET1_1, 1);
252	} else {
253		gpio_request(EFIKAMX_RESET, "reset");
254		gpio_direction_output(EFIKAMX_RESET, 1);
255	}
256
257	/*
258	 * enable wifi by default only on mx
259	 * sb and mx have same wlan pin but the value to enable it are
260	 * different :/
261	 */
262	gpio_request(EFIKA_WLAN_EN, "wlan_en");
263	gpio_direction_output(EFIKA_WLAN_EN, 0);
264	msleep(10);
265
266	gpio_request(EFIKA_WLAN_RESET, "wlan_rst");
267	gpio_direction_output(EFIKA_WLAN_RESET, 0);
268	msleep(10);
269	gpio_set_value(EFIKA_WLAN_RESET, 1);
270}
271
272static void __init mx51_efikamx_timer_init(void)
273{
274	mx51_clocks_init(32768, 24000000, 22579200, 24576000);
275}
276
277static struct sys_timer mx51_efikamx_timer = {
278	.init = mx51_efikamx_timer_init,
279};
280
281MACHINE_START(MX51_EFIKAMX, "Genesi EfikaMX nettop")
282	/* Maintainer: Amit Kucheria <amit.kucheria@linaro.org> */
283	.boot_params = MX51_PHYS_OFFSET + 0x100,
284	.map_io = mx51_map_io,
285	.init_early = imx51_init_early,
286	.init_irq = mx51_init_irq,
287	.timer = &mx51_efikamx_timer,
288	.init_machine = mx51_efikamx_init,
289MACHINE_END