Path: blob/master/arch/arm/mach-mx5/board-mx51_efikamx.c
10817 views
/*1* Copyright (C) 2010 Linaro Limited2*3* based on code from the following4* Copyright 2009-2010 Freescale Semiconductor, Inc. All Rights Reserved.5* Copyright 2009-2010 Pegatron Corporation. All Rights Reserved.6* Copyright 2009-2010 Genesi USA, Inc. All Rights Reserved.7*8* The code contained herein is licensed under the GNU General Public9* License. You may obtain a copy of the GNU General Public License10* Version 2 or later at the following locations:11*12* http://www.opensource.org/licenses/gpl-license.html13* http://www.gnu.org/copyleft/gpl.html14*/1516#include <linux/init.h>17#include <linux/platform_device.h>18#include <linux/i2c.h>19#include <linux/gpio.h>20#include <linux/leds.h>21#include <linux/input.h>22#include <linux/delay.h>23#include <linux/io.h>24#include <linux/spi/flash.h>25#include <linux/spi/spi.h>26#include <linux/mfd/mc13892.h>27#include <linux/regulator/machine.h>28#include <linux/regulator/consumer.h>2930#include <mach/common.h>31#include <mach/hardware.h>32#include <mach/iomux-mx51.h>3334#include <asm/irq.h>35#include <asm/setup.h>36#include <asm/mach-types.h>37#include <asm/mach/arch.h>38#include <asm/mach/time.h>3940#include "devices-imx51.h"41#include "devices.h"42#include "efika.h"4344#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)4748#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)5152#define EFIKAMX_POWER_KEY IMX_GPIO_NR(2, 31)5354/* board 1.1 doesn't have same reset gpio */55#define EFIKAMX_RESET1_1 IMX_GPIO_NR(3, 2)56#define EFIKAMX_RESET IMX_GPIO_NR(1, 4)5758#define EFIKAMX_POWEROFF IMX_GPIO_NR(4, 13)5960#define EFIKAMX_PMIC IMX_GPIO_NR(1, 6)6162/* 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)66#define MX51_PAD_PWRKEY IOMUX_PAD(0x48c, 0x0f8, 1, 0x0, 0, PAD_CTL_PUS_100K_UP | PAD_CTL_PKE)6768static iomux_v3_cfg_t mx51efikamx_pads[] = {69/* board id */70MX51_PAD_PCBID0,71MX51_PAD_PCBID1,72MX51_PAD_PCBID2,7374/* leds */75MX51_PAD_CSI1_D9__GPIO3_13,76MX51_PAD_CSI1_VSYNC__GPIO3_14,77MX51_PAD_CSI1_HSYNC__GPIO3_15,7879/* power key */80MX51_PAD_PWRKEY,8182/* reset */83MX51_PAD_DI1_PIN13__GPIO3_2,84MX51_PAD_GPIO1_4__GPIO1_4,8586/* power off */87MX51_PAD_CSI2_VSYNC__GPIO4_13,88};8990/* PCBID2 PCBID1 PCBID0 STATE911 1 1 ER1:rev1.1921 1 0 ER2:rev1.2931 0 1 ER3:rev1.3941 0 0 ER4:rev1.495*/96static void __init mx51_efikamx_board_id(void)97{98int id;99100/* things are taking time to settle */101msleep(150);102103gpio_request(EFIKAMX_PCBID0, "pcbid0");104gpio_direction_input(EFIKAMX_PCBID0);105gpio_request(EFIKAMX_PCBID1, "pcbid1");106gpio_direction_input(EFIKAMX_PCBID1);107gpio_request(EFIKAMX_PCBID2, "pcbid2");108gpio_direction_input(EFIKAMX_PCBID2);109110id = gpio_get_value(EFIKAMX_PCBID0);111id |= gpio_get_value(EFIKAMX_PCBID1) << 1;112id |= gpio_get_value(EFIKAMX_PCBID2) << 2;113114switch (id) {115case 7:116system_rev = 0x11;117break;118case 6:119system_rev = 0x12;120break;121case 5:122system_rev = 0x13;123break;124case 4:125system_rev = 0x14;126break;127default:128system_rev = 0x10;129break;130}131132if ((system_rev == 0x10)133|| (system_rev == 0x12)134|| (system_rev == 0x14)) {135printk(KERN_WARNING136"EfikaMX: Unsupported board revision 1.%u!\n",137system_rev & 0xf);138}139}140141static struct gpio_led mx51_efikamx_leds[] = {142{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};158159static struct gpio_led_platform_data mx51_efikamx_leds_data = {160.leds = mx51_efikamx_leds,161.num_leds = ARRAY_SIZE(mx51_efikamx_leds),162};163164static struct platform_device mx51_efikamx_leds_device = {165.name = "leds-gpio",166.id = -1,167.dev = {168.platform_data = &mx51_efikamx_leds_data,169},170};171172static struct gpio_keys_button mx51_efikamx_powerkey[] = {173{174.code = KEY_POWER,175.gpio = EFIKAMX_POWER_KEY,176.type = EV_PWR,177.desc = "Power Button (CM)",178.wakeup = 1,179.debounce_interval = 10, /* ms */180},181};182183static const struct gpio_keys_platform_data mx51_efikamx_powerkey_data __initconst = {184.buttons = mx51_efikamx_powerkey,185.nbuttons = ARRAY_SIZE(mx51_efikamx_powerkey),186};187188void mx51_efikamx_reset(void)189{190if (system_rev == 0x11)191gpio_direction_output(EFIKAMX_RESET1_1, 0);192else193gpio_direction_output(EFIKAMX_RESET, 0);194}195196static struct regulator *pwgt1, *pwgt2, *coincell;197198static void mx51_efikamx_power_off(void)199{200if (!IS_ERR(coincell))201regulator_disable(coincell);202203if (!IS_ERR(pwgt1) && !IS_ERR(pwgt2)) {204regulator_disable(pwgt2);205regulator_disable(pwgt1);206}207gpio_direction_output(EFIKAMX_POWEROFF, 1);208}209210static int __init mx51_efikamx_power_init(void)211{212if (machine_is_mx51_efikamx()) {213pwgt1 = regulator_get(NULL, "pwgt1");214pwgt2 = regulator_get(NULL, "pwgt2");215if (!IS_ERR(pwgt1) && !IS_ERR(pwgt2)) {216regulator_enable(pwgt1);217regulator_enable(pwgt2);218}219gpio_request(EFIKAMX_POWEROFF, "poweroff");220pm_power_off = mx51_efikamx_power_off;221222/* enable coincell charger. maybe need a small power driver ? */223coincell = regulator_get(NULL, "coincell");224if (!IS_ERR(coincell)) {225regulator_set_voltage(coincell, 3000000, 3000000);226regulator_enable(coincell);227}228229regulator_has_full_constraints();230}231232return 0;233}234late_initcall(mx51_efikamx_power_init);235236static void __init mx51_efikamx_init(void)237{238mxc_iomux_v3_setup_multiple_pads(mx51efikamx_pads,239ARRAY_SIZE(mx51efikamx_pads));240efika_board_common_init();241242mx51_efikamx_board_id();243244/* on < 1.2 boards both SD controllers are used */245if (system_rev < 0x12) {246imx51_add_sdhci_esdhc_imx(1, NULL);247mx51_efikamx_leds[2].default_trigger = "mmc1";248}249250platform_device_register(&mx51_efikamx_leds_device);251imx_add_gpio_keys(&mx51_efikamx_powerkey_data);252253if (system_rev == 0x11) {254gpio_request(EFIKAMX_RESET1_1, "reset");255gpio_direction_output(EFIKAMX_RESET1_1, 1);256} else {257gpio_request(EFIKAMX_RESET, "reset");258gpio_direction_output(EFIKAMX_RESET, 1);259}260261/*262* enable wifi by default only on mx263* sb and mx have same wlan pin but the value to enable it are264* different :/265*/266gpio_request(EFIKA_WLAN_EN, "wlan_en");267gpio_direction_output(EFIKA_WLAN_EN, 0);268msleep(10);269270gpio_request(EFIKA_WLAN_RESET, "wlan_rst");271gpio_direction_output(EFIKA_WLAN_RESET, 0);272msleep(10);273gpio_set_value(EFIKA_WLAN_RESET, 1);274}275276static void __init mx51_efikamx_timer_init(void)277{278mx51_clocks_init(32768, 24000000, 22579200, 24576000);279}280281static struct sys_timer mx51_efikamx_timer = {282.init = mx51_efikamx_timer_init,283};284285MACHINE_START(MX51_EFIKAMX, "Genesi EfikaMX nettop")286/* Maintainer: Amit Kucheria <[email protected]> */287.boot_params = MX51_PHYS_OFFSET + 0x100,288.map_io = mx51_map_io,289.init_early = imx51_init_early,290.init_irq = mx51_init_irq,291.timer = &mx51_efikamx_timer,292.init_machine = mx51_efikamx_init,293MACHINE_END294295296