Amit Kucheria | 088d01b | 2010-10-07 03:58:12 +0300 | [diff] [blame] | 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> |
Arnaud Patard (Rtp) | 9d2c0ef | 2010-10-27 14:40:51 +0200 | [diff] [blame] | 21 | #include <linux/leds.h> |
Arnaud Patard (Rtp) | fcbd0c5 | 2010-10-27 14:40:52 +0200 | [diff] [blame] | 22 | #include <linux/input.h> |
Amit Kucheria | 088d01b | 2010-10-07 03:58:12 +0300 | [diff] [blame] | 23 | #include <linux/delay.h> |
| 24 | #include <linux/io.h> |
Arnaud Patard (Rtp) | c6e34a4c | 2010-10-27 14:40:54 +0200 | [diff] [blame] | 25 | #include <linux/spi/flash.h> |
| 26 | #include <linux/spi/spi.h> |
Arnaud Patard (Rtp) | 2432cff | 2011-02-17 15:31:30 +0100 | [diff] [blame] | 27 | #include <linux/mfd/mc13892.h> |
| 28 | #include <linux/regulator/machine.h> |
| 29 | #include <linux/regulator/consumer.h> |
Amit Kucheria | 088d01b | 2010-10-07 03:58:12 +0300 | [diff] [blame] | 30 | |
| 31 | #include <mach/common.h> |
| 32 | #include <mach/hardware.h> |
| 33 | #include <mach/iomux-mx51.h> |
Amit Kucheria | 088d01b | 2010-10-07 03:58:12 +0300 | [diff] [blame] | 34 | |
Amit Kucheria | 088d01b | 2010-10-07 03:58:12 +0300 | [diff] [blame] | 35 | #include <asm/setup.h> |
| 36 | #include <asm/mach-types.h> |
| 37 | #include <asm/mach/arch.h> |
| 38 | #include <asm/mach/time.h> |
| 39 | |
| 40 | #include "devices-imx51.h" |
Arnaud Patard (Rtp) | 7ac18a3 | 2011-02-17 15:31:28 +0100 | [diff] [blame] | 41 | #include "efika.h" |
Amit Kucheria | 81490fc | 2010-10-07 03:58:25 +0300 | [diff] [blame] | 42 | |
Arnaud Patard (Rtp) | 96886c4 | 2010-11-26 15:20:52 +0100 | [diff] [blame] | 43 | #define EFIKAMX_PCBID0 IMX_GPIO_NR(3, 16) |
| 44 | #define EFIKAMX_PCBID1 IMX_GPIO_NR(3, 17) |
| 45 | #define EFIKAMX_PCBID2 IMX_GPIO_NR(3, 11) |
Arnaud Patard (Rtp) | f1dd361 | 2010-10-27 14:40:46 +0200 | [diff] [blame] | 46 | |
Arnaud Patard (Rtp) | 96886c4 | 2010-11-26 15:20:52 +0100 | [diff] [blame] | 47 | #define EFIKAMX_BLUE_LED IMX_GPIO_NR(3, 13) |
| 48 | #define EFIKAMX_GREEN_LED IMX_GPIO_NR(3, 14) |
| 49 | #define EFIKAMX_RED_LED IMX_GPIO_NR(3, 15) |
Arnaud Patard (Rtp) | 9d2c0ef | 2010-10-27 14:40:51 +0200 | [diff] [blame] | 50 | |
Arnaud Patard (Rtp) | 96886c4 | 2010-11-26 15:20:52 +0100 | [diff] [blame] | 51 | #define EFIKAMX_POWER_KEY IMX_GPIO_NR(2, 31) |
Arnaud Patard (Rtp) | fcbd0c5 | 2010-10-27 14:40:52 +0200 | [diff] [blame] | 52 | |
Arnaud Patard (Rtp) | c2932bf | 2010-10-27 14:40:55 +0200 | [diff] [blame] | 53 | /* board 1.1 doesn't have same reset gpio */ |
Arnaud Patard (Rtp) | 96886c4 | 2010-11-26 15:20:52 +0100 | [diff] [blame] | 54 | #define EFIKAMX_RESET1_1 IMX_GPIO_NR(3, 2) |
| 55 | #define EFIKAMX_RESET IMX_GPIO_NR(1, 4) |
Arnaud Patard (Rtp) | c2932bf | 2010-10-27 14:40:55 +0200 | [diff] [blame] | 56 | |
Arnaud Patard (Rtp) | 2432cff | 2011-02-17 15:31:30 +0100 | [diff] [blame] | 57 | #define EFIKAMX_POWEROFF IMX_GPIO_NR(4, 13) |
| 58 | |
| 59 | #define EFIKAMX_PMIC IMX_GPIO_NR(1, 6) |
| 60 | |
Arnaud Patard (Rtp) | f1dd361 | 2010-10-27 14:40:46 +0200 | [diff] [blame] | 61 | /* the pci ids pin have pull up. they're driven low according to board id */ |
| 62 | #define MX51_PAD_PCBID0 IOMUX_PAD(0x518, 0x130, 3, 0x0, 0, PAD_CTL_PUS_100K_UP) |
| 63 | #define MX51_PAD_PCBID1 IOMUX_PAD(0x51C, 0x134, 3, 0x0, 0, PAD_CTL_PUS_100K_UP) |
| 64 | #define MX51_PAD_PCBID2 IOMUX_PAD(0x504, 0x128, 3, 0x0, 0, PAD_CTL_PUS_100K_UP) |
Arnaud Patard (Rtp) | fcbd0c5 | 2010-10-27 14:40:52 +0200 | [diff] [blame] | 65 | #define MX51_PAD_PWRKEY IOMUX_PAD(0x48c, 0x0f8, 1, 0x0, 0, PAD_CTL_PUS_100K_UP | PAD_CTL_PKE) |
Arnaud Patard (Rtp) | f1dd361 | 2010-10-27 14:40:46 +0200 | [diff] [blame] | 66 | |
Lothar Waßmann | 8f5260c | 2010-10-26 14:28:31 +0200 | [diff] [blame] | 67 | static iomux_v3_cfg_t mx51efikamx_pads[] = { |
Arnaud Patard (Rtp) | f1dd361 | 2010-10-27 14:40:46 +0200 | [diff] [blame] | 68 | /* board id */ |
| 69 | MX51_PAD_PCBID0, |
| 70 | MX51_PAD_PCBID1, |
| 71 | MX51_PAD_PCBID2, |
Arnaud Patard (Rtp) | a96eb14 | 2010-10-27 14:40:49 +0200 | [diff] [blame] | 72 | |
Arnaud Patard (Rtp) | 9d2c0ef | 2010-10-27 14:40:51 +0200 | [diff] [blame] | 73 | /* leds */ |
Sascha Hauer | ee1ae4d | 2010-12-15 09:56:35 +0100 | [diff] [blame] | 74 | MX51_PAD_CSI1_D9__GPIO3_13, |
| 75 | MX51_PAD_CSI1_VSYNC__GPIO3_14, |
| 76 | MX51_PAD_CSI1_HSYNC__GPIO3_15, |
Arnaud Patard (Rtp) | fcbd0c5 | 2010-10-27 14:40:52 +0200 | [diff] [blame] | 77 | |
| 78 | /* power key */ |
| 79 | MX51_PAD_PWRKEY, |
Arnaud Patard (Rtp) | c6e34a4c | 2010-10-27 14:40:54 +0200 | [diff] [blame] | 80 | |
Arnaud Patard (Rtp) | c2932bf | 2010-10-27 14:40:55 +0200 | [diff] [blame] | 81 | /* reset */ |
Sascha Hauer | ee1ae4d | 2010-12-15 09:56:35 +0100 | [diff] [blame] | 82 | MX51_PAD_DI1_PIN13__GPIO3_2, |
| 83 | MX51_PAD_GPIO1_4__GPIO1_4, |
Arnaud Patard (Rtp) | 2432cff | 2011-02-17 15:31:30 +0100 | [diff] [blame] | 84 | |
| 85 | /* power off */ |
| 86 | MX51_PAD_CSI2_VSYNC__GPIO4_13, |
Amit Kucheria | 088d01b | 2010-10-07 03:58:12 +0300 | [diff] [blame] | 87 | }; |
| 88 | |
Arnaud Patard (Rtp) | f1dd361 | 2010-10-27 14:40:46 +0200 | [diff] [blame] | 89 | /* PCBID2 PCBID1 PCBID0 STATE |
| 90 | 1 1 1 ER1:rev1.1 |
| 91 | 1 1 0 ER2:rev1.2 |
| 92 | 1 0 1 ER3:rev1.3 |
| 93 | 1 0 0 ER4:rev1.4 |
| 94 | */ |
| 95 | static void __init mx51_efikamx_board_id(void) |
| 96 | { |
| 97 | int id; |
| 98 | |
| 99 | /* things are taking time to settle */ |
| 100 | msleep(150); |
| 101 | |
| 102 | gpio_request(EFIKAMX_PCBID0, "pcbid0"); |
| 103 | gpio_direction_input(EFIKAMX_PCBID0); |
| 104 | gpio_request(EFIKAMX_PCBID1, "pcbid1"); |
| 105 | gpio_direction_input(EFIKAMX_PCBID1); |
| 106 | gpio_request(EFIKAMX_PCBID2, "pcbid2"); |
| 107 | gpio_direction_input(EFIKAMX_PCBID2); |
| 108 | |
Arnaud Patard (Rtp) | fbd60a7 | 2011-06-27 22:41:06 +0200 | [diff] [blame] | 109 | id = gpio_get_value(EFIKAMX_PCBID0) ? 1 : 0; |
| 110 | id |= (gpio_get_value(EFIKAMX_PCBID1) ? 1 : 0) << 1; |
| 111 | id |= (gpio_get_value(EFIKAMX_PCBID2) ? 1 : 0) << 2; |
Arnaud Patard (Rtp) | f1dd361 | 2010-10-27 14:40:46 +0200 | [diff] [blame] | 112 | |
| 113 | switch (id) { |
| 114 | case 7: |
| 115 | system_rev = 0x11; |
| 116 | break; |
| 117 | case 6: |
| 118 | system_rev = 0x12; |
| 119 | break; |
| 120 | case 5: |
| 121 | system_rev = 0x13; |
| 122 | break; |
| 123 | case 4: |
| 124 | system_rev = 0x14; |
| 125 | break; |
| 126 | default: |
| 127 | system_rev = 0x10; |
| 128 | break; |
| 129 | } |
| 130 | |
| 131 | if ((system_rev == 0x10) |
| 132 | || (system_rev == 0x12) |
| 133 | || (system_rev == 0x14)) { |
| 134 | printk(KERN_WARNING |
| 135 | "EfikaMX: Unsupported board revision 1.%u!\n", |
| 136 | system_rev & 0xf); |
| 137 | } |
| 138 | } |
| 139 | |
Uwe Kleine-König | 5b8d628 | 2011-05-28 21:05:02 +0200 | [diff] [blame] | 140 | static struct gpio_led mx51_efikamx_leds[] __initdata = { |
Arnaud Patard (Rtp) | 9d2c0ef | 2010-10-27 14:40:51 +0200 | [diff] [blame] | 141 | { |
| 142 | .name = "efikamx:green", |
| 143 | .default_trigger = "default-on", |
| 144 | .gpio = EFIKAMX_GREEN_LED, |
| 145 | }, |
| 146 | { |
| 147 | .name = "efikamx:red", |
| 148 | .default_trigger = "ide-disk", |
| 149 | .gpio = EFIKAMX_RED_LED, |
| 150 | }, |
| 151 | { |
| 152 | .name = "efikamx:blue", |
| 153 | .default_trigger = "mmc0", |
| 154 | .gpio = EFIKAMX_BLUE_LED, |
| 155 | }, |
| 156 | }; |
| 157 | |
Uwe Kleine-König | 5b8d628 | 2011-05-28 21:05:02 +0200 | [diff] [blame] | 158 | static const struct gpio_led_platform_data |
| 159 | mx51_efikamx_leds_data __initconst = { |
Arnaud Patard (Rtp) | 9d2c0ef | 2010-10-27 14:40:51 +0200 | [diff] [blame] | 160 | .leds = mx51_efikamx_leds, |
| 161 | .num_leds = ARRAY_SIZE(mx51_efikamx_leds), |
| 162 | }; |
| 163 | |
Arnaud Patard (Rtp) | 600ea5c | 2011-08-27 15:15:58 +0200 | [diff] [blame] | 164 | static struct esdhc_platform_data sd_pdata = { |
| 165 | .cd_type = ESDHC_CD_CONTROLLER, |
| 166 | .wp_type = ESDHC_WP_CONTROLLER, |
| 167 | }; |
| 168 | |
Arnaud Patard (Rtp) | fcbd0c5 | 2010-10-27 14:40:52 +0200 | [diff] [blame] | 169 | static struct gpio_keys_button mx51_efikamx_powerkey[] = { |
| 170 | { |
| 171 | .code = KEY_POWER, |
| 172 | .gpio = EFIKAMX_POWER_KEY, |
| 173 | .type = EV_PWR, |
| 174 | .desc = "Power Button (CM)", |
| 175 | .wakeup = 1, |
| 176 | .debounce_interval = 10, /* ms */ |
| 177 | }, |
| 178 | }; |
| 179 | |
| 180 | static const struct gpio_keys_platform_data mx51_efikamx_powerkey_data __initconst = { |
| 181 | .buttons = mx51_efikamx_powerkey, |
| 182 | .nbuttons = ARRAY_SIZE(mx51_efikamx_powerkey), |
| 183 | }; |
| 184 | |
Russell King | 65ea788 | 2011-11-06 17:12:08 +0000 | [diff] [blame] | 185 | static void mx51_efikamx_restart(char mode, const char *cmd) |
Arnaud Patard (Rtp) | c2932bf | 2010-10-27 14:40:55 +0200 | [diff] [blame] | 186 | { |
| 187 | if (system_rev == 0x11) |
| 188 | gpio_direction_output(EFIKAMX_RESET1_1, 0); |
| 189 | else |
| 190 | gpio_direction_output(EFIKAMX_RESET, 0); |
| 191 | } |
| 192 | |
Arnaud Patard (Rtp) | 2432cff | 2011-02-17 15:31:30 +0100 | [diff] [blame] | 193 | static struct regulator *pwgt1, *pwgt2, *coincell; |
| 194 | |
| 195 | static void mx51_efikamx_power_off(void) |
| 196 | { |
| 197 | if (!IS_ERR(coincell)) |
| 198 | regulator_disable(coincell); |
| 199 | |
| 200 | if (!IS_ERR(pwgt1) && !IS_ERR(pwgt2)) { |
| 201 | regulator_disable(pwgt2); |
| 202 | regulator_disable(pwgt1); |
| 203 | } |
| 204 | gpio_direction_output(EFIKAMX_POWEROFF, 1); |
| 205 | } |
| 206 | |
| 207 | static int __init mx51_efikamx_power_init(void) |
| 208 | { |
| 209 | if (machine_is_mx51_efikamx()) { |
| 210 | pwgt1 = regulator_get(NULL, "pwgt1"); |
| 211 | pwgt2 = regulator_get(NULL, "pwgt2"); |
| 212 | if (!IS_ERR(pwgt1) && !IS_ERR(pwgt2)) { |
| 213 | regulator_enable(pwgt1); |
| 214 | regulator_enable(pwgt2); |
| 215 | } |
| 216 | gpio_request(EFIKAMX_POWEROFF, "poweroff"); |
| 217 | pm_power_off = mx51_efikamx_power_off; |
| 218 | |
| 219 | /* enable coincell charger. maybe need a small power driver ? */ |
| 220 | coincell = regulator_get(NULL, "coincell"); |
| 221 | if (!IS_ERR(coincell)) { |
| 222 | regulator_set_voltage(coincell, 3000000, 3000000); |
| 223 | regulator_enable(coincell); |
| 224 | } |
| 225 | |
| 226 | regulator_has_full_constraints(); |
| 227 | } |
| 228 | |
| 229 | return 0; |
| 230 | } |
| 231 | late_initcall(mx51_efikamx_power_init); |
| 232 | |
Uwe Kleine-König | e134fb2 | 2011-02-11 10:23:19 +0100 | [diff] [blame] | 233 | static void __init mx51_efikamx_init(void) |
Amit Kucheria | 088d01b | 2010-10-07 03:58:12 +0300 | [diff] [blame] | 234 | { |
Shawn Guo | b78d8e5 | 2011-06-06 00:07:55 +0800 | [diff] [blame] | 235 | imx51_soc_init(); |
| 236 | |
Amit Kucheria | 088d01b | 2010-10-07 03:58:12 +0300 | [diff] [blame] | 237 | mxc_iomux_v3_setup_multiple_pads(mx51efikamx_pads, |
| 238 | ARRAY_SIZE(mx51efikamx_pads)); |
Arnaud Patard (Rtp) | 7ac18a3 | 2011-02-17 15:31:28 +0100 | [diff] [blame] | 239 | efika_board_common_init(); |
| 240 | |
Arnaud Patard (Rtp) | f1dd361 | 2010-10-27 14:40:46 +0200 | [diff] [blame] | 241 | mx51_efikamx_board_id(); |
Arnaud Patard (Rtp) | a96eb14 | 2010-10-27 14:40:49 +0200 | [diff] [blame] | 242 | |
| 243 | /* on < 1.2 boards both SD controllers are used */ |
Arnaud Patard (Rtp) | 9d2c0ef | 2010-10-27 14:40:51 +0200 | [diff] [blame] | 244 | if (system_rev < 0x12) { |
Arnaud Patard (Rtp) | 600ea5c | 2011-08-27 15:15:58 +0200 | [diff] [blame] | 245 | imx51_add_sdhci_esdhc_imx(0, NULL); |
| 246 | imx51_add_sdhci_esdhc_imx(1, &sd_pdata); |
Arnaud Patard (Rtp) | 9d2c0ef | 2010-10-27 14:40:51 +0200 | [diff] [blame] | 247 | mx51_efikamx_leds[2].default_trigger = "mmc1"; |
Arnaud Patard (Rtp) | 600ea5c | 2011-08-27 15:15:58 +0200 | [diff] [blame] | 248 | } else |
| 249 | imx51_add_sdhci_esdhc_imx(0, &sd_pdata); |
Arnaud Patard (Rtp) | 9d2c0ef | 2010-10-27 14:40:51 +0200 | [diff] [blame] | 250 | |
Uwe Kleine-König | 5b8d628 | 2011-05-28 21:05:02 +0200 | [diff] [blame] | 251 | gpio_led_register_device(-1, &mx51_efikamx_leds_data); |
Fabio Estevam | ba8a6c0 | 2011-04-06 13:05:26 -0300 | [diff] [blame] | 252 | imx_add_gpio_keys(&mx51_efikamx_powerkey_data); |
Arnaud Patard (Rtp) | c6e34a4c | 2010-10-27 14:40:54 +0200 | [diff] [blame] | 253 | |
Arnaud Patard (Rtp) | c2932bf | 2010-10-27 14:40:55 +0200 | [diff] [blame] | 254 | if (system_rev == 0x11) { |
| 255 | gpio_request(EFIKAMX_RESET1_1, "reset"); |
| 256 | gpio_direction_output(EFIKAMX_RESET1_1, 1); |
| 257 | } else { |
| 258 | gpio_request(EFIKAMX_RESET, "reset"); |
| 259 | gpio_direction_output(EFIKAMX_RESET, 1); |
| 260 | } |
Arnaud Patard (Rtp) | 9d72af6 | 2011-02-17 15:31:29 +0100 | [diff] [blame] | 261 | |
| 262 | /* |
| 263 | * enable wifi by default only on mx |
| 264 | * sb and mx have same wlan pin but the value to enable it are |
| 265 | * different :/ |
| 266 | */ |
| 267 | gpio_request(EFIKA_WLAN_EN, "wlan_en"); |
| 268 | gpio_direction_output(EFIKA_WLAN_EN, 0); |
| 269 | msleep(10); |
| 270 | |
| 271 | gpio_request(EFIKA_WLAN_RESET, "wlan_rst"); |
| 272 | gpio_direction_output(EFIKA_WLAN_RESET, 0); |
| 273 | msleep(10); |
| 274 | gpio_set_value(EFIKA_WLAN_RESET, 1); |
Amit Kucheria | 088d01b | 2010-10-07 03:58:12 +0300 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | static void __init mx51_efikamx_timer_init(void) |
| 278 | { |
| 279 | mx51_clocks_init(32768, 24000000, 22579200, 24576000); |
| 280 | } |
| 281 | |
Uwe Kleine-König | e134fb2 | 2011-02-11 10:23:19 +0100 | [diff] [blame] | 282 | static struct sys_timer mx51_efikamx_timer = { |
| 283 | .init = mx51_efikamx_timer_init, |
Amit Kucheria | 088d01b | 2010-10-07 03:58:12 +0300 | [diff] [blame] | 284 | }; |
| 285 | |
| 286 | MACHINE_START(MX51_EFIKAMX, "Genesi EfikaMX nettop") |
| 287 | /* Maintainer: Amit Kucheria <amit.kucheria@linaro.org> */ |
Nicolas Pitre | 6192935 | 2011-07-05 22:38:14 -0400 | [diff] [blame] | 288 | .atag_offset = 0x100, |
Amit Kucheria | 088d01b | 2010-10-07 03:58:12 +0300 | [diff] [blame] | 289 | .map_io = mx51_map_io, |
Uwe Kleine-König | ab130421 | 2011-02-07 16:35:21 +0100 | [diff] [blame] | 290 | .init_early = imx51_init_early, |
Amit Kucheria | 088d01b | 2010-10-07 03:58:12 +0300 | [diff] [blame] | 291 | .init_irq = mx51_init_irq, |
Sascha Hauer | ffa2ea3 | 2011-09-20 14:31:24 +0200 | [diff] [blame] | 292 | .handle_irq = imx51_handle_irq, |
Uwe Kleine-König | e134fb2 | 2011-02-11 10:23:19 +0100 | [diff] [blame] | 293 | .timer = &mx51_efikamx_timer, |
| 294 | .init_machine = mx51_efikamx_init, |
Russell King | 65ea788 | 2011-11-06 17:12:08 +0000 | [diff] [blame] | 295 | .restart = mx51_efikamx_restart, |
Amit Kucheria | 088d01b | 2010-10-07 03:58:12 +0300 | [diff] [blame] | 296 | MACHINE_END |