board-mx51_efikasb.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. #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>
  29. #include <linux/usb/otg.h>
  30. #include <linux/usb/ulpi.h>
  31. #include <mach/ulpi.h>
  32. #include <mach/common.h>
  33. #include <mach/hardware.h>
  34. #include <mach/iomux-mx51.h>
  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. #include "devices-imx51.h"
  41. #include "devices.h"
  42. #include "efika.h"
  43. #define EFIKASB_USBH2_STP IMX_GPIO_NR(2, 20)
  44. #define EFIKASB_GREEN_LED IMX_GPIO_NR(1, 3)
  45. #define EFIKASB_WHITE_LED IMX_GPIO_NR(2, 25)
  46. #define EFIKASB_PCBID0 IMX_GPIO_NR(2, 28)
  47. #define EFIKASB_PCBID1 IMX_GPIO_NR(2, 29)
  48. #define EFIKASB_PWRKEY IMX_GPIO_NR(2, 31)
  49. #define EFIKASB_LID IMX_GPIO_NR(3, 14)
  50. #define EFIKASB_POWEROFF IMX_GPIO_NR(4, 13)
  51. #define EFIKASB_RFKILL IMX_GPIO_NR(3, 1)
  52. #define MX51_PAD_PWRKEY IOMUX_PAD(0x48c, 0x0f8, 1, 0x0, 0, PAD_CTL_PUS_100K_UP | PAD_CTL_PKE)
  53. #define MX51_PAD_SD1_CD IOMUX_PAD(0x47c, 0x0e8, 1, __NA_, 0, MX51_ESDHC_PAD_CTRL)
  54. static iomux_v3_cfg_t mx51efikasb_pads[] = {
  55. /* USB HOST2 */
  56. MX51_PAD_EIM_D16__USBH2_DATA0,
  57. MX51_PAD_EIM_D17__USBH2_DATA1,
  58. MX51_PAD_EIM_D18__USBH2_DATA2,
  59. MX51_PAD_EIM_D19__USBH2_DATA3,
  60. MX51_PAD_EIM_D20__USBH2_DATA4,
  61. MX51_PAD_EIM_D21__USBH2_DATA5,
  62. MX51_PAD_EIM_D22__USBH2_DATA6,
  63. MX51_PAD_EIM_D23__USBH2_DATA7,
  64. MX51_PAD_EIM_A24__USBH2_CLK,
  65. MX51_PAD_EIM_A25__USBH2_DIR,
  66. MX51_PAD_EIM_A26__USBH2_STP,
  67. MX51_PAD_EIM_A27__USBH2_NXT,
  68. /* leds */
  69. MX51_PAD_EIM_CS0__GPIO2_25,
  70. MX51_PAD_GPIO1_3__GPIO1_3,
  71. /* pcb id */
  72. MX51_PAD_EIM_CS3__GPIO2_28,
  73. MX51_PAD_EIM_CS4__GPIO2_29,
  74. /* lid */
  75. MX51_PAD_CSI1_VSYNC__GPIO3_14,
  76. /* power key*/
  77. MX51_PAD_PWRKEY,
  78. /* wifi/bt button */
  79. MX51_PAD_DI1_PIN12__GPIO3_1,
  80. /* power off */
  81. MX51_PAD_CSI2_VSYNC__GPIO4_13,
  82. /* wdog reset */
  83. MX51_PAD_GPIO1_4__WDOG1_WDOG_B,
  84. /* BT */
  85. MX51_PAD_EIM_A17__GPIO2_11,
  86. MX51_PAD_SD1_CD,
  87. };
  88. static int initialize_usbh2_port(struct platform_device *pdev)
  89. {
  90. iomux_v3_cfg_t usbh2stp = MX51_PAD_EIM_A26__USBH2_STP;
  91. iomux_v3_cfg_t usbh2gpio = MX51_PAD_EIM_A26__GPIO2_20;
  92. mxc_iomux_v3_setup_pad(usbh2gpio);
  93. gpio_request(EFIKASB_USBH2_STP, "usbh2_stp");
  94. gpio_direction_output(EFIKASB_USBH2_STP, 0);
  95. msleep(1);
  96. gpio_set_value(EFIKASB_USBH2_STP, 1);
  97. msleep(1);
  98. gpio_free(EFIKASB_USBH2_STP);
  99. mxc_iomux_v3_setup_pad(usbh2stp);
  100. mdelay(10);
  101. return mx51_initialize_usb_hw(pdev->id, MXC_EHCI_ITC_NO_THRESHOLD);
  102. }
  103. static struct mxc_usbh_platform_data usbh2_config = {
  104. .init = initialize_usbh2_port,
  105. .portsc = MXC_EHCI_MODE_ULPI,
  106. };
  107. static void __init mx51_efikasb_usb(void)
  108. {
  109. usbh2_config.otg = imx_otg_ulpi_create(ULPI_OTG_DRVVBUS |
  110. ULPI_OTG_DRVVBUS_EXT | ULPI_OTG_EXTVBUSIND);
  111. if (usbh2_config.otg)
  112. mxc_register_device(&mxc_usbh2_device, &usbh2_config);
  113. }
  114. static const struct gpio_led mx51_efikasb_leds[] __initconst = {
  115. {
  116. .name = "efikasb:green",
  117. .default_trigger = "default-on",
  118. .gpio = EFIKASB_GREEN_LED,
  119. .active_low = 1,
  120. },
  121. {
  122. .name = "efikasb:white",
  123. .default_trigger = "caps",
  124. .gpio = EFIKASB_WHITE_LED,
  125. },
  126. };
  127. static const struct gpio_led_platform_data
  128. mx51_efikasb_leds_data __initconst = {
  129. .leds = mx51_efikasb_leds,
  130. .num_leds = ARRAY_SIZE(mx51_efikasb_leds),
  131. };
  132. static struct gpio_keys_button mx51_efikasb_keys[] = {
  133. {
  134. .code = KEY_POWER,
  135. .gpio = EFIKASB_PWRKEY,
  136. .type = EV_KEY,
  137. .desc = "Power Button",
  138. .wakeup = 1,
  139. .active_low = 1,
  140. },
  141. {
  142. .code = SW_LID,
  143. .gpio = EFIKASB_LID,
  144. .type = EV_SW,
  145. .desc = "Lid Switch",
  146. .active_low = 1,
  147. },
  148. {
  149. .code = KEY_RFKILL,
  150. .gpio = EFIKASB_RFKILL,
  151. .type = EV_KEY,
  152. .desc = "rfkill",
  153. .active_low = 1,
  154. },
  155. };
  156. static const struct gpio_keys_platform_data mx51_efikasb_keys_data __initconst = {
  157. .buttons = mx51_efikasb_keys,
  158. .nbuttons = ARRAY_SIZE(mx51_efikasb_keys),
  159. };
  160. static struct esdhc_platform_data sd0_pdata = {
  161. #define EFIKASB_SD1_CD IMX_GPIO_NR(2, 27)
  162. .cd_gpio = EFIKASB_SD1_CD,
  163. .cd_type = ESDHC_CD_GPIO,
  164. .wp_type = ESDHC_WP_CONTROLLER,
  165. };
  166. static struct esdhc_platform_data sd1_pdata = {
  167. .cd_type = ESDHC_CD_CONTROLLER,
  168. .wp_type = ESDHC_WP_CONTROLLER,
  169. };
  170. static struct regulator *pwgt1, *pwgt2;
  171. static void mx51_efikasb_power_off(void)
  172. {
  173. gpio_set_value(EFIKA_USB_PHY_RESET, 0);
  174. if (!IS_ERR(pwgt1) && !IS_ERR(pwgt2)) {
  175. regulator_disable(pwgt2);
  176. regulator_disable(pwgt1);
  177. }
  178. gpio_direction_output(EFIKASB_POWEROFF, 1);
  179. }
  180. static int __init mx51_efikasb_power_init(void)
  181. {
  182. if (machine_is_mx51_efikasb()) {
  183. pwgt1 = regulator_get(NULL, "pwgt1");
  184. pwgt2 = regulator_get(NULL, "pwgt2");
  185. if (!IS_ERR(pwgt1) && !IS_ERR(pwgt2)) {
  186. regulator_enable(pwgt1);
  187. regulator_enable(pwgt2);
  188. }
  189. gpio_request(EFIKASB_POWEROFF, "poweroff");
  190. pm_power_off = mx51_efikasb_power_off;
  191. regulator_has_full_constraints();
  192. }
  193. return 0;
  194. }
  195. late_initcall(mx51_efikasb_power_init);
  196. /* 01 R1.3 board
  197. 10 R2.0 board */
  198. static void __init mx51_efikasb_board_id(void)
  199. {
  200. int id;
  201. gpio_request(EFIKASB_PCBID0, "pcb id0");
  202. gpio_direction_input(EFIKASB_PCBID0);
  203. gpio_request(EFIKASB_PCBID1, "pcb id1");
  204. gpio_direction_input(EFIKASB_PCBID1);
  205. id = gpio_get_value(EFIKASB_PCBID0) ? 1 : 0;
  206. id |= (gpio_get_value(EFIKASB_PCBID1) ? 1 : 0) << 1;
  207. switch (id) {
  208. default:
  209. break;
  210. case 1:
  211. system_rev = 0x13;
  212. break;
  213. case 2:
  214. system_rev = 0x20;
  215. break;
  216. }
  217. }
  218. static void __init efikasb_board_init(void)
  219. {
  220. imx51_soc_init();
  221. mxc_iomux_v3_setup_multiple_pads(mx51efikasb_pads,
  222. ARRAY_SIZE(mx51efikasb_pads));
  223. efika_board_common_init();
  224. mx51_efikasb_board_id();
  225. mx51_efikasb_usb();
  226. imx51_add_sdhci_esdhc_imx(0, &sd0_pdata);
  227. imx51_add_sdhci_esdhc_imx(1, &sd1_pdata);
  228. gpio_led_register_device(-1, &mx51_efikasb_leds_data);
  229. imx_add_gpio_keys(&mx51_efikasb_keys_data);
  230. }
  231. static void __init mx51_efikasb_timer_init(void)
  232. {
  233. mx51_clocks_init(32768, 24000000, 22579200, 24576000);
  234. }
  235. static struct sys_timer mx51_efikasb_timer = {
  236. .init = mx51_efikasb_timer_init,
  237. };
  238. MACHINE_START(MX51_EFIKASB, "Genesi Efika Smartbook")
  239. .boot_params = MX51_PHYS_OFFSET + 0x100,
  240. .map_io = mx51_map_io,
  241. .init_early = imx51_init_early,
  242. .init_irq = mx51_init_irq,
  243. .handle_irq = imx51_handle_irq,
  244. .init_machine = efikasb_board_init,
  245. .timer = &mx51_efikasb_timer,
  246. MACHINE_END