mach-mx51_efikamx.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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. #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 <mach/common.h>
  30. #include <mach/hardware.h>
  31. #include <mach/iomux-mx51.h>
  32. #include <asm/setup.h>
  33. #include <asm/system_info.h>
  34. #include <asm/mach-types.h>
  35. #include <asm/mach/arch.h>
  36. #include <asm/mach/time.h>
  37. #include "devices-imx51.h"
  38. #include "efika.h"
  39. #define EFIKAMX_PCBID0 IMX_GPIO_NR(3, 16)
  40. #define EFIKAMX_PCBID1 IMX_GPIO_NR(3, 17)
  41. #define EFIKAMX_PCBID2 IMX_GPIO_NR(3, 11)
  42. #define EFIKAMX_BLUE_LED IMX_GPIO_NR(3, 13)
  43. #define EFIKAMX_GREEN_LED IMX_GPIO_NR(3, 14)
  44. #define EFIKAMX_RED_LED IMX_GPIO_NR(3, 15)
  45. #define EFIKAMX_POWER_KEY IMX_GPIO_NR(2, 31)
  46. /* board 1.1 doesn't have same reset gpio */
  47. #define EFIKAMX_RESET1_1 IMX_GPIO_NR(3, 2)
  48. #define EFIKAMX_RESET IMX_GPIO_NR(1, 4)
  49. #define EFIKAMX_POWEROFF IMX_GPIO_NR(4, 13)
  50. #define EFIKAMX_PMIC IMX_GPIO_NR(1, 6)
  51. /* the pci ids pin have pull up. they're driven low according to board id */
  52. #define MX51_PAD_PCBID0 IOMUX_PAD(0x518, 0x130, 3, 0x0, 0, PAD_CTL_PUS_100K_UP)
  53. #define MX51_PAD_PCBID1 IOMUX_PAD(0x51C, 0x134, 3, 0x0, 0, PAD_CTL_PUS_100K_UP)
  54. #define MX51_PAD_PCBID2 IOMUX_PAD(0x504, 0x128, 3, 0x0, 0, PAD_CTL_PUS_100K_UP)
  55. #define MX51_PAD_PWRKEY IOMUX_PAD(0x48c, 0x0f8, 1, 0x0, 0, PAD_CTL_PUS_100K_UP | PAD_CTL_PKE)
  56. static iomux_v3_cfg_t mx51efikamx_pads[] = {
  57. /* board id */
  58. MX51_PAD_PCBID0,
  59. MX51_PAD_PCBID1,
  60. MX51_PAD_PCBID2,
  61. /* leds */
  62. MX51_PAD_CSI1_D9__GPIO3_13,
  63. MX51_PAD_CSI1_VSYNC__GPIO3_14,
  64. MX51_PAD_CSI1_HSYNC__GPIO3_15,
  65. /* power key */
  66. MX51_PAD_PWRKEY,
  67. /* reset */
  68. MX51_PAD_DI1_PIN13__GPIO3_2,
  69. MX51_PAD_GPIO1_4__GPIO1_4,
  70. /* power off */
  71. MX51_PAD_CSI2_VSYNC__GPIO4_13,
  72. };
  73. /* PCBID2 PCBID1 PCBID0 STATE
  74. 1 1 1 ER1:rev1.1
  75. 1 1 0 ER2:rev1.2
  76. 1 0 1 ER3:rev1.3
  77. 1 0 0 ER4:rev1.4
  78. */
  79. static void __init mx51_efikamx_board_id(void)
  80. {
  81. int id;
  82. /* things are taking time to settle */
  83. msleep(150);
  84. gpio_request(EFIKAMX_PCBID0, "pcbid0");
  85. gpio_direction_input(EFIKAMX_PCBID0);
  86. gpio_request(EFIKAMX_PCBID1, "pcbid1");
  87. gpio_direction_input(EFIKAMX_PCBID1);
  88. gpio_request(EFIKAMX_PCBID2, "pcbid2");
  89. gpio_direction_input(EFIKAMX_PCBID2);
  90. id = gpio_get_value(EFIKAMX_PCBID0) ? 1 : 0;
  91. id |= (gpio_get_value(EFIKAMX_PCBID1) ? 1 : 0) << 1;
  92. id |= (gpio_get_value(EFIKAMX_PCBID2) ? 1 : 0) << 2;
  93. switch (id) {
  94. case 7:
  95. system_rev = 0x11;
  96. break;
  97. case 6:
  98. system_rev = 0x12;
  99. break;
  100. case 5:
  101. system_rev = 0x13;
  102. break;
  103. case 4:
  104. system_rev = 0x14;
  105. break;
  106. default:
  107. system_rev = 0x10;
  108. break;
  109. }
  110. if ((system_rev == 0x10)
  111. || (system_rev == 0x12)
  112. || (system_rev == 0x14)) {
  113. printk(KERN_WARNING
  114. "EfikaMX: Unsupported board revision 1.%u!\n",
  115. system_rev & 0xf);
  116. }
  117. }
  118. static struct gpio_led mx51_efikamx_leds[] __initdata = {
  119. {
  120. .name = "efikamx:green",
  121. .default_trigger = "default-on",
  122. .gpio = EFIKAMX_GREEN_LED,
  123. },
  124. {
  125. .name = "efikamx:red",
  126. .default_trigger = "ide-disk",
  127. .gpio = EFIKAMX_RED_LED,
  128. },
  129. {
  130. .name = "efikamx:blue",
  131. .default_trigger = "mmc0",
  132. .gpio = EFIKAMX_BLUE_LED,
  133. },
  134. };
  135. static const struct gpio_led_platform_data
  136. mx51_efikamx_leds_data __initconst = {
  137. .leds = mx51_efikamx_leds,
  138. .num_leds = ARRAY_SIZE(mx51_efikamx_leds),
  139. };
  140. static struct esdhc_platform_data sd_pdata = {
  141. .cd_type = ESDHC_CD_CONTROLLER,
  142. .wp_type = ESDHC_WP_CONTROLLER,
  143. };
  144. static struct gpio_keys_button mx51_efikamx_powerkey[] = {
  145. {
  146. .code = KEY_POWER,
  147. .gpio = EFIKAMX_POWER_KEY,
  148. .type = EV_PWR,
  149. .desc = "Power Button (CM)",
  150. .wakeup = 1,
  151. .debounce_interval = 10, /* ms */
  152. },
  153. };
  154. static const struct gpio_keys_platform_data mx51_efikamx_powerkey_data __initconst = {
  155. .buttons = mx51_efikamx_powerkey,
  156. .nbuttons = ARRAY_SIZE(mx51_efikamx_powerkey),
  157. };
  158. static void mx51_efikamx_restart(char mode, const char *cmd)
  159. {
  160. if (system_rev == 0x11)
  161. gpio_direction_output(EFIKAMX_RESET1_1, 0);
  162. else
  163. gpio_direction_output(EFIKAMX_RESET, 0);
  164. }
  165. static struct regulator *pwgt1, *pwgt2, *coincell;
  166. static void mx51_efikamx_power_off(void)
  167. {
  168. if (!IS_ERR(coincell))
  169. regulator_disable(coincell);
  170. if (!IS_ERR(pwgt1) && !IS_ERR(pwgt2)) {
  171. regulator_disable(pwgt2);
  172. regulator_disable(pwgt1);
  173. }
  174. gpio_direction_output(EFIKAMX_POWEROFF, 1);
  175. }
  176. static int __init mx51_efikamx_power_init(void)
  177. {
  178. if (machine_is_mx51_efikamx()) {
  179. pwgt1 = regulator_get(NULL, "pwgt1");
  180. pwgt2 = regulator_get(NULL, "pwgt2");
  181. if (!IS_ERR(pwgt1) && !IS_ERR(pwgt2)) {
  182. regulator_enable(pwgt1);
  183. regulator_enable(pwgt2);
  184. }
  185. gpio_request(EFIKAMX_POWEROFF, "poweroff");
  186. pm_power_off = mx51_efikamx_power_off;
  187. /* enable coincell charger. maybe need a small power driver ? */
  188. coincell = regulator_get(NULL, "coincell");
  189. if (!IS_ERR(coincell)) {
  190. regulator_set_voltage(coincell, 3000000, 3000000);
  191. regulator_enable(coincell);
  192. }
  193. regulator_has_full_constraints();
  194. }
  195. return 0;
  196. }
  197. late_initcall(mx51_efikamx_power_init);
  198. static void __init mx51_efikamx_init(void)
  199. {
  200. imx51_soc_init();
  201. mxc_iomux_v3_setup_multiple_pads(mx51efikamx_pads,
  202. ARRAY_SIZE(mx51efikamx_pads));
  203. efika_board_common_init();
  204. mx51_efikamx_board_id();
  205. /* on < 1.2 boards both SD controllers are used */
  206. if (system_rev < 0x12) {
  207. imx51_add_sdhci_esdhc_imx(0, NULL);
  208. imx51_add_sdhci_esdhc_imx(1, &sd_pdata);
  209. mx51_efikamx_leds[2].default_trigger = "mmc1";
  210. } else
  211. imx51_add_sdhci_esdhc_imx(0, &sd_pdata);
  212. gpio_led_register_device(-1, &mx51_efikamx_leds_data);
  213. imx_add_gpio_keys(&mx51_efikamx_powerkey_data);
  214. if (system_rev == 0x11) {
  215. gpio_request(EFIKAMX_RESET1_1, "reset");
  216. gpio_direction_output(EFIKAMX_RESET1_1, 1);
  217. } else {
  218. gpio_request(EFIKAMX_RESET, "reset");
  219. gpio_direction_output(EFIKAMX_RESET, 1);
  220. }
  221. /*
  222. * enable wifi by default only on mx
  223. * sb and mx have same wlan pin but the value to enable it are
  224. * different :/
  225. */
  226. gpio_request(EFIKA_WLAN_EN, "wlan_en");
  227. gpio_direction_output(EFIKA_WLAN_EN, 0);
  228. msleep(10);
  229. gpio_request(EFIKA_WLAN_RESET, "wlan_rst");
  230. gpio_direction_output(EFIKA_WLAN_RESET, 0);
  231. msleep(10);
  232. gpio_set_value(EFIKA_WLAN_RESET, 1);
  233. }
  234. static void __init mx51_efikamx_timer_init(void)
  235. {
  236. mx51_clocks_init(32768, 24000000, 22579200, 24576000);
  237. }
  238. static struct sys_timer mx51_efikamx_timer = {
  239. .init = mx51_efikamx_timer_init,
  240. };
  241. MACHINE_START(MX51_EFIKAMX, "Genesi EfikaMX nettop")
  242. /* Maintainer: Amit Kucheria <amit.kucheria@linaro.org> */
  243. .atag_offset = 0x100,
  244. .map_io = mx51_map_io,
  245. .init_early = imx51_init_early,
  246. .init_irq = mx51_init_irq,
  247. .handle_irq = imx51_handle_irq,
  248. .timer = &mx51_efikamx_timer,
  249. .init_machine = mx51_efikamx_init,
  250. .restart = mx51_efikamx_restart,
  251. MACHINE_END