Arnaud Patard (Rtp) | 102c91d | 2011-02-17 15:31:32 +0100 | [diff] [blame] | 1 | /* |
| 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) | 102c91d | 2011-02-17 15:31:32 +0100 | [diff] [blame] | 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 | #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) | 102c91d | 2011-02-17 15:31:32 +0100 | [diff] [blame] | 37 | |
Arnaud Patard (Rtp) | 102c91d | 2011-02-17 15:31:32 +0100 | [diff] [blame] | 38 | #include <asm/setup.h> |
David Howells | 9f97da7 | 2012-03-28 18:30:01 +0100 | [diff] [blame] | 39 | #include <asm/system_info.h> |
Arnaud Patard (Rtp) | 102c91d | 2011-02-17 15:31:32 +0100 | [diff] [blame] | 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) | 102c91d | 2011-02-17 15:31:32 +0100 | [diff] [blame] | 45 | #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) |
Arnaud Patard (Rtp) | 600ea5c | 2011-08-27 15:15:58 +0200 | [diff] [blame] | 58 | #define MX51_PAD_SD1_CD IOMUX_PAD(0x47c, 0x0e8, 1, __NA_, 0, MX51_ESDHC_PAD_CTRL) |
Arnaud Patard (Rtp) | 102c91d | 2011-02-17 15:31:32 +0100 | [diff] [blame] | 59 | |
| 60 | static iomux_v3_cfg_t mx51efikasb_pads[] = { |
| 61 | /* USB HOST2 */ |
| 62 | MX51_PAD_EIM_D16__USBH2_DATA0, |
| 63 | MX51_PAD_EIM_D17__USBH2_DATA1, |
| 64 | MX51_PAD_EIM_D18__USBH2_DATA2, |
| 65 | MX51_PAD_EIM_D19__USBH2_DATA3, |
| 66 | MX51_PAD_EIM_D20__USBH2_DATA4, |
| 67 | MX51_PAD_EIM_D21__USBH2_DATA5, |
| 68 | MX51_PAD_EIM_D22__USBH2_DATA6, |
| 69 | MX51_PAD_EIM_D23__USBH2_DATA7, |
| 70 | MX51_PAD_EIM_A24__USBH2_CLK, |
| 71 | MX51_PAD_EIM_A25__USBH2_DIR, |
| 72 | MX51_PAD_EIM_A26__USBH2_STP, |
| 73 | MX51_PAD_EIM_A27__USBH2_NXT, |
| 74 | |
| 75 | /* leds */ |
| 76 | MX51_PAD_EIM_CS0__GPIO2_25, |
| 77 | MX51_PAD_GPIO1_3__GPIO1_3, |
| 78 | |
| 79 | /* pcb id */ |
| 80 | MX51_PAD_EIM_CS3__GPIO2_28, |
| 81 | MX51_PAD_EIM_CS4__GPIO2_29, |
| 82 | |
| 83 | /* lid */ |
| 84 | MX51_PAD_CSI1_VSYNC__GPIO3_14, |
| 85 | |
| 86 | /* power key*/ |
| 87 | MX51_PAD_PWRKEY, |
| 88 | |
| 89 | /* wifi/bt button */ |
| 90 | MX51_PAD_DI1_PIN12__GPIO3_1, |
| 91 | |
| 92 | /* power off */ |
| 93 | MX51_PAD_CSI2_VSYNC__GPIO4_13, |
| 94 | |
| 95 | /* wdog reset */ |
| 96 | MX51_PAD_GPIO1_4__WDOG1_WDOG_B, |
| 97 | |
| 98 | /* BT */ |
| 99 | MX51_PAD_EIM_A17__GPIO2_11, |
Arnaud Patard (Rtp) | 600ea5c | 2011-08-27 15:15:58 +0200 | [diff] [blame] | 100 | |
| 101 | MX51_PAD_SD1_CD, |
Arnaud Patard (Rtp) | 102c91d | 2011-02-17 15:31:32 +0100 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | static int initialize_usbh2_port(struct platform_device *pdev) |
| 105 | { |
| 106 | iomux_v3_cfg_t usbh2stp = MX51_PAD_EIM_A26__USBH2_STP; |
| 107 | iomux_v3_cfg_t usbh2gpio = MX51_PAD_EIM_A26__GPIO2_20; |
| 108 | |
| 109 | mxc_iomux_v3_setup_pad(usbh2gpio); |
| 110 | gpio_request(EFIKASB_USBH2_STP, "usbh2_stp"); |
| 111 | gpio_direction_output(EFIKASB_USBH2_STP, 0); |
| 112 | msleep(1); |
| 113 | gpio_set_value(EFIKASB_USBH2_STP, 1); |
| 114 | msleep(1); |
| 115 | |
| 116 | gpio_free(EFIKASB_USBH2_STP); |
| 117 | mxc_iomux_v3_setup_pad(usbh2stp); |
| 118 | |
| 119 | mdelay(10); |
| 120 | |
| 121 | return mx51_initialize_usb_hw(pdev->id, MXC_EHCI_ITC_NO_THRESHOLD); |
| 122 | } |
| 123 | |
Uwe Kleine-König | 7d92e8e | 2011-07-30 23:41:49 +0200 | [diff] [blame] | 124 | static struct mxc_usbh_platform_data usbh2_config __initdata = { |
Arnaud Patard (Rtp) | 102c91d | 2011-02-17 15:31:32 +0100 | [diff] [blame] | 125 | .init = initialize_usbh2_port, |
| 126 | .portsc = MXC_EHCI_MODE_ULPI, |
| 127 | }; |
| 128 | |
| 129 | static void __init mx51_efikasb_usb(void) |
| 130 | { |
Sascha Hauer | 48f6b09 | 2011-03-02 09:27:42 +0100 | [diff] [blame] | 131 | usbh2_config.otg = imx_otg_ulpi_create(ULPI_OTG_DRVVBUS | |
| 132 | ULPI_OTG_DRVVBUS_EXT | ULPI_OTG_EXTVBUSIND); |
| 133 | if (usbh2_config.otg) |
Uwe Kleine-König | 7d92e8e | 2011-07-30 23:41:49 +0200 | [diff] [blame] | 134 | imx51_add_mxc_ehci_hs(2, &usbh2_config); |
Arnaud Patard (Rtp) | 102c91d | 2011-02-17 15:31:32 +0100 | [diff] [blame] | 135 | } |
| 136 | |
Uwe Kleine-König | 5b8d628 | 2011-05-28 21:05:02 +0200 | [diff] [blame] | 137 | static const struct gpio_led mx51_efikasb_leds[] __initconst = { |
Arnaud Patard (Rtp) | 102c91d | 2011-02-17 15:31:32 +0100 | [diff] [blame] | 138 | { |
| 139 | .name = "efikasb:green", |
| 140 | .default_trigger = "default-on", |
| 141 | .gpio = EFIKASB_GREEN_LED, |
| 142 | .active_low = 1, |
| 143 | }, |
| 144 | { |
| 145 | .name = "efikasb:white", |
| 146 | .default_trigger = "caps", |
| 147 | .gpio = EFIKASB_WHITE_LED, |
| 148 | }, |
| 149 | }; |
| 150 | |
Uwe Kleine-König | 5b8d628 | 2011-05-28 21:05:02 +0200 | [diff] [blame] | 151 | static const struct gpio_led_platform_data |
| 152 | mx51_efikasb_leds_data __initconst = { |
Arnaud Patard (Rtp) | 102c91d | 2011-02-17 15:31:32 +0100 | [diff] [blame] | 153 | .leds = mx51_efikasb_leds, |
| 154 | .num_leds = ARRAY_SIZE(mx51_efikasb_leds), |
| 155 | }; |
| 156 | |
Arnaud Patard (Rtp) | 102c91d | 2011-02-17 15:31:32 +0100 | [diff] [blame] | 157 | static struct gpio_keys_button mx51_efikasb_keys[] = { |
| 158 | { |
| 159 | .code = KEY_POWER, |
| 160 | .gpio = EFIKASB_PWRKEY, |
Arnaud Patard (Rtp) | f7db3d5f | 2011-06-27 22:41:05 +0200 | [diff] [blame] | 161 | .type = EV_KEY, |
Arnaud Patard (Rtp) | 102c91d | 2011-02-17 15:31:32 +0100 | [diff] [blame] | 162 | .desc = "Power Button", |
| 163 | .wakeup = 1, |
Arnaud Patard (Rtp) | f7db3d5f | 2011-06-27 22:41:05 +0200 | [diff] [blame] | 164 | .active_low = 1, |
Arnaud Patard (Rtp) | 102c91d | 2011-02-17 15:31:32 +0100 | [diff] [blame] | 165 | }, |
| 166 | { |
| 167 | .code = SW_LID, |
| 168 | .gpio = EFIKASB_LID, |
| 169 | .type = EV_SW, |
| 170 | .desc = "Lid Switch", |
Arnaud Patard (Rtp) | f7db3d5f | 2011-06-27 22:41:05 +0200 | [diff] [blame] | 171 | .active_low = 1, |
Arnaud Patard (Rtp) | 102c91d | 2011-02-17 15:31:32 +0100 | [diff] [blame] | 172 | }, |
| 173 | { |
Arnaud Patard (Rtp) | f7db3d5f | 2011-06-27 22:41:05 +0200 | [diff] [blame] | 174 | .code = KEY_RFKILL, |
Arnaud Patard (Rtp) | 102c91d | 2011-02-17 15:31:32 +0100 | [diff] [blame] | 175 | .gpio = EFIKASB_RFKILL, |
Arnaud Patard (Rtp) | f7db3d5f | 2011-06-27 22:41:05 +0200 | [diff] [blame] | 176 | .type = EV_KEY, |
Arnaud Patard (Rtp) | 102c91d | 2011-02-17 15:31:32 +0100 | [diff] [blame] | 177 | .desc = "rfkill", |
Arnaud Patard (Rtp) | f7db3d5f | 2011-06-27 22:41:05 +0200 | [diff] [blame] | 178 | .active_low = 1, |
Arnaud Patard (Rtp) | 102c91d | 2011-02-17 15:31:32 +0100 | [diff] [blame] | 179 | }, |
| 180 | }; |
| 181 | |
| 182 | static const struct gpio_keys_platform_data mx51_efikasb_keys_data __initconst = { |
| 183 | .buttons = mx51_efikasb_keys, |
| 184 | .nbuttons = ARRAY_SIZE(mx51_efikasb_keys), |
| 185 | }; |
| 186 | |
Arnaud Patard (Rtp) | 600ea5c | 2011-08-27 15:15:58 +0200 | [diff] [blame] | 187 | static struct esdhc_platform_data sd0_pdata = { |
| 188 | #define EFIKASB_SD1_CD IMX_GPIO_NR(2, 27) |
| 189 | .cd_gpio = EFIKASB_SD1_CD, |
| 190 | .cd_type = ESDHC_CD_GPIO, |
| 191 | .wp_type = ESDHC_WP_CONTROLLER, |
| 192 | }; |
| 193 | |
| 194 | static struct esdhc_platform_data sd1_pdata = { |
| 195 | .cd_type = ESDHC_CD_CONTROLLER, |
| 196 | .wp_type = ESDHC_WP_CONTROLLER, |
| 197 | }; |
| 198 | |
Arnaud Patard (Rtp) | 102c91d | 2011-02-17 15:31:32 +0100 | [diff] [blame] | 199 | static struct regulator *pwgt1, *pwgt2; |
| 200 | |
| 201 | static void mx51_efikasb_power_off(void) |
| 202 | { |
| 203 | gpio_set_value(EFIKA_USB_PHY_RESET, 0); |
| 204 | |
| 205 | if (!IS_ERR(pwgt1) && !IS_ERR(pwgt2)) { |
| 206 | regulator_disable(pwgt2); |
| 207 | regulator_disable(pwgt1); |
| 208 | } |
| 209 | gpio_direction_output(EFIKASB_POWEROFF, 1); |
| 210 | } |
| 211 | |
| 212 | static int __init mx51_efikasb_power_init(void) |
| 213 | { |
Shawn Guo | 8321b75 | 2012-04-26 11:42:34 +0800 | [diff] [blame] | 214 | pwgt1 = regulator_get(NULL, "pwgt1"); |
| 215 | pwgt2 = regulator_get(NULL, "pwgt2"); |
| 216 | if (!IS_ERR(pwgt1) && !IS_ERR(pwgt2)) { |
| 217 | regulator_enable(pwgt1); |
| 218 | regulator_enable(pwgt2); |
Arnaud Patard (Rtp) | 102c91d | 2011-02-17 15:31:32 +0100 | [diff] [blame] | 219 | } |
Shawn Guo | 8321b75 | 2012-04-26 11:42:34 +0800 | [diff] [blame] | 220 | gpio_request(EFIKASB_POWEROFF, "poweroff"); |
| 221 | pm_power_off = mx51_efikasb_power_off; |
| 222 | |
| 223 | regulator_has_full_constraints(); |
Arnaud Patard (Rtp) | 102c91d | 2011-02-17 15:31:32 +0100 | [diff] [blame] | 224 | |
| 225 | return 0; |
| 226 | } |
Shawn Guo | 8321b75 | 2012-04-26 11:42:34 +0800 | [diff] [blame] | 227 | |
| 228 | static void __init mx51_efikasb_init_late(void) |
| 229 | { |
| 230 | imx51_init_late(); |
| 231 | mx51_efikasb_power_init(); |
| 232 | } |
Arnaud Patard (Rtp) | 102c91d | 2011-02-17 15:31:32 +0100 | [diff] [blame] | 233 | |
| 234 | /* 01 R1.3 board |
| 235 | 10 R2.0 board */ |
| 236 | static void __init mx51_efikasb_board_id(void) |
| 237 | { |
| 238 | int id; |
| 239 | |
| 240 | gpio_request(EFIKASB_PCBID0, "pcb id0"); |
| 241 | gpio_direction_input(EFIKASB_PCBID0); |
| 242 | gpio_request(EFIKASB_PCBID1, "pcb id1"); |
| 243 | gpio_direction_input(EFIKASB_PCBID1); |
| 244 | |
Arnaud Patard (Rtp) | fbd60a7 | 2011-06-27 22:41:06 +0200 | [diff] [blame] | 245 | id = gpio_get_value(EFIKASB_PCBID0) ? 1 : 0; |
| 246 | id |= (gpio_get_value(EFIKASB_PCBID1) ? 1 : 0) << 1; |
Arnaud Patard (Rtp) | 102c91d | 2011-02-17 15:31:32 +0100 | [diff] [blame] | 247 | |
| 248 | switch (id) { |
| 249 | default: |
| 250 | break; |
| 251 | case 1: |
| 252 | system_rev = 0x13; |
| 253 | break; |
| 254 | case 2: |
| 255 | system_rev = 0x20; |
| 256 | break; |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | static void __init efikasb_board_init(void) |
| 261 | { |
Shawn Guo | b78d8e5 | 2011-06-06 00:07:55 +0800 | [diff] [blame] | 262 | imx51_soc_init(); |
| 263 | |
Arnaud Patard (Rtp) | 102c91d | 2011-02-17 15:31:32 +0100 | [diff] [blame] | 264 | mxc_iomux_v3_setup_multiple_pads(mx51efikasb_pads, |
| 265 | ARRAY_SIZE(mx51efikasb_pads)); |
| 266 | efika_board_common_init(); |
| 267 | |
| 268 | mx51_efikasb_board_id(); |
| 269 | mx51_efikasb_usb(); |
Arnaud Patard (Rtp) | 600ea5c | 2011-08-27 15:15:58 +0200 | [diff] [blame] | 270 | imx51_add_sdhci_esdhc_imx(0, &sd0_pdata); |
| 271 | imx51_add_sdhci_esdhc_imx(1, &sd1_pdata); |
Arnaud Patard (Rtp) | 102c91d | 2011-02-17 15:31:32 +0100 | [diff] [blame] | 272 | |
Uwe Kleine-König | 5b8d628 | 2011-05-28 21:05:02 +0200 | [diff] [blame] | 273 | gpio_led_register_device(-1, &mx51_efikasb_leds_data); |
Fabio Estevam | ba8a6c04 | 2011-04-06 13:05:26 -0300 | [diff] [blame] | 274 | imx_add_gpio_keys(&mx51_efikasb_keys_data); |
Arnaud Patard (Rtp) | 102c91d | 2011-02-17 15:31:32 +0100 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | static void __init mx51_efikasb_timer_init(void) |
| 278 | { |
| 279 | mx51_clocks_init(32768, 24000000, 22579200, 24576000); |
| 280 | } |
| 281 | |
| 282 | static struct sys_timer mx51_efikasb_timer = { |
| 283 | .init = mx51_efikasb_timer_init, |
| 284 | }; |
| 285 | |
Hector Oron | 3307688 | 2012-02-21 00:09:28 +0100 | [diff] [blame] | 286 | MACHINE_START(MX51_EFIKASB, "Genesi Efika MX (Smartbook)") |
Nicolas Pitre | 6192935 | 2011-07-05 22:38:14 -0400 | [diff] [blame] | 287 | .atag_offset = 0x100, |
Arnaud Patard (Rtp) | 102c91d | 2011-02-17 15:31:32 +0100 | [diff] [blame] | 288 | .map_io = mx51_map_io, |
| 289 | .init_early = imx51_init_early, |
| 290 | .init_irq = mx51_init_irq, |
Sascha Hauer | ffa2ea3 | 2011-09-20 14:31:24 +0200 | [diff] [blame] | 291 | .handle_irq = imx51_handle_irq, |
Arnaud Patard (Rtp) | 102c91d | 2011-02-17 15:31:32 +0100 | [diff] [blame] | 292 | .init_machine = efikasb_board_init, |
Shawn Guo | 8321b75 | 2012-04-26 11:42:34 +0800 | [diff] [blame] | 293 | .init_late = mx51_efikasb_init_late, |
Arnaud Patard (Rtp) | 102c91d | 2011-02-17 15:31:32 +0100 | [diff] [blame] | 294 | .timer = &mx51_efikasb_timer, |
Russell King | 65ea788 | 2011-11-06 17:12:08 +0000 | [diff] [blame] | 295 | .restart = mxc_restart, |
Arnaud Patard (Rtp) | 102c91d | 2011-02-17 15:31:32 +0100 | [diff] [blame] | 296 | MACHINE_END |