mach-mx28evk.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. /*
  2. * Copyright 2010 Freescale Semiconductor, Inc. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #include <linux/delay.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/gpio.h>
  17. #include <linux/irq.h>
  18. #include <linux/clk.h>
  19. #include <asm/mach-types.h>
  20. #include <asm/mach/arch.h>
  21. #include <asm/mach/time.h>
  22. #include <mach/common.h>
  23. #include <mach/iomux-mx28.h>
  24. #include "devices-mx28.h"
  25. #include "gpio.h"
  26. #define MX28EVK_FLEXCAN_SWITCH MXS_GPIO_NR(2, 13)
  27. #define MX28EVK_FEC_PHY_POWER MXS_GPIO_NR(2, 15)
  28. #define MX28EVK_BL_ENABLE MXS_GPIO_NR(3, 18)
  29. #define MX28EVK_LCD_ENABLE MXS_GPIO_NR(3, 30)
  30. #define MX28EVK_FEC_PHY_RESET MXS_GPIO_NR(4, 13)
  31. #define MX28EVK_MMC0_WRITE_PROTECT MXS_GPIO_NR(2, 12)
  32. #define MX28EVK_MMC1_WRITE_PROTECT MXS_GPIO_NR(0, 28)
  33. #define MX28EVK_MMC0_SLOT_POWER MXS_GPIO_NR(3, 28)
  34. #define MX28EVK_MMC1_SLOT_POWER MXS_GPIO_NR(3, 29)
  35. static const iomux_cfg_t mx28evk_pads[] __initconst = {
  36. /* duart */
  37. MX28_PAD_PWM0__DUART_RX | MXS_PAD_CTRL,
  38. MX28_PAD_PWM1__DUART_TX | MXS_PAD_CTRL,
  39. /* auart0 */
  40. MX28_PAD_AUART0_RX__AUART0_RX | MXS_PAD_CTRL,
  41. MX28_PAD_AUART0_TX__AUART0_TX | MXS_PAD_CTRL,
  42. MX28_PAD_AUART0_CTS__AUART0_CTS | MXS_PAD_CTRL,
  43. MX28_PAD_AUART0_RTS__AUART0_RTS | MXS_PAD_CTRL,
  44. /* auart3 */
  45. MX28_PAD_AUART3_RX__AUART3_RX | MXS_PAD_CTRL,
  46. MX28_PAD_AUART3_TX__AUART3_TX | MXS_PAD_CTRL,
  47. MX28_PAD_AUART3_CTS__AUART3_CTS | MXS_PAD_CTRL,
  48. MX28_PAD_AUART3_RTS__AUART3_RTS | MXS_PAD_CTRL,
  49. #define MXS_PAD_FEC (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP)
  50. /* fec0 */
  51. MX28_PAD_ENET0_MDC__ENET0_MDC | MXS_PAD_FEC,
  52. MX28_PAD_ENET0_MDIO__ENET0_MDIO | MXS_PAD_FEC,
  53. MX28_PAD_ENET0_RX_EN__ENET0_RX_EN | MXS_PAD_FEC,
  54. MX28_PAD_ENET0_RXD0__ENET0_RXD0 | MXS_PAD_FEC,
  55. MX28_PAD_ENET0_RXD1__ENET0_RXD1 | MXS_PAD_FEC,
  56. MX28_PAD_ENET0_TX_EN__ENET0_TX_EN | MXS_PAD_FEC,
  57. MX28_PAD_ENET0_TXD0__ENET0_TXD0 | MXS_PAD_FEC,
  58. MX28_PAD_ENET0_TXD1__ENET0_TXD1 | MXS_PAD_FEC,
  59. MX28_PAD_ENET_CLK__CLKCTRL_ENET | MXS_PAD_FEC,
  60. /* fec1 */
  61. MX28_PAD_ENET0_CRS__ENET1_RX_EN | MXS_PAD_FEC,
  62. MX28_PAD_ENET0_RXD2__ENET1_RXD0 | MXS_PAD_FEC,
  63. MX28_PAD_ENET0_RXD3__ENET1_RXD1 | MXS_PAD_FEC,
  64. MX28_PAD_ENET0_COL__ENET1_TX_EN | MXS_PAD_FEC,
  65. MX28_PAD_ENET0_TXD2__ENET1_TXD0 | MXS_PAD_FEC,
  66. MX28_PAD_ENET0_TXD3__ENET1_TXD1 | MXS_PAD_FEC,
  67. /* phy power line */
  68. MX28_PAD_SSP1_DATA3__GPIO_2_15 | MXS_PAD_CTRL,
  69. /* phy reset line */
  70. MX28_PAD_ENET0_RX_CLK__GPIO_4_13 | MXS_PAD_CTRL,
  71. /* flexcan0 */
  72. MX28_PAD_GPMI_RDY2__CAN0_TX,
  73. MX28_PAD_GPMI_RDY3__CAN0_RX,
  74. /* flexcan1 */
  75. MX28_PAD_GPMI_CE2N__CAN1_TX,
  76. MX28_PAD_GPMI_CE3N__CAN1_RX,
  77. /* transceiver power control */
  78. MX28_PAD_SSP1_CMD__GPIO_2_13,
  79. /* mxsfb (lcdif) */
  80. MX28_PAD_LCD_D00__LCD_D0 | MXS_PAD_CTRL,
  81. MX28_PAD_LCD_D01__LCD_D1 | MXS_PAD_CTRL,
  82. MX28_PAD_LCD_D02__LCD_D2 | MXS_PAD_CTRL,
  83. MX28_PAD_LCD_D03__LCD_D3 | MXS_PAD_CTRL,
  84. MX28_PAD_LCD_D04__LCD_D4 | MXS_PAD_CTRL,
  85. MX28_PAD_LCD_D05__LCD_D5 | MXS_PAD_CTRL,
  86. MX28_PAD_LCD_D06__LCD_D6 | MXS_PAD_CTRL,
  87. MX28_PAD_LCD_D07__LCD_D7 | MXS_PAD_CTRL,
  88. MX28_PAD_LCD_D08__LCD_D8 | MXS_PAD_CTRL,
  89. MX28_PAD_LCD_D09__LCD_D9 | MXS_PAD_CTRL,
  90. MX28_PAD_LCD_D10__LCD_D10 | MXS_PAD_CTRL,
  91. MX28_PAD_LCD_D11__LCD_D11 | MXS_PAD_CTRL,
  92. MX28_PAD_LCD_D12__LCD_D12 | MXS_PAD_CTRL,
  93. MX28_PAD_LCD_D13__LCD_D13 | MXS_PAD_CTRL,
  94. MX28_PAD_LCD_D14__LCD_D14 | MXS_PAD_CTRL,
  95. MX28_PAD_LCD_D15__LCD_D15 | MXS_PAD_CTRL,
  96. MX28_PAD_LCD_D16__LCD_D16 | MXS_PAD_CTRL,
  97. MX28_PAD_LCD_D17__LCD_D17 | MXS_PAD_CTRL,
  98. MX28_PAD_LCD_D18__LCD_D18 | MXS_PAD_CTRL,
  99. MX28_PAD_LCD_D19__LCD_D19 | MXS_PAD_CTRL,
  100. MX28_PAD_LCD_D20__LCD_D20 | MXS_PAD_CTRL,
  101. MX28_PAD_LCD_D21__LCD_D21 | MXS_PAD_CTRL,
  102. MX28_PAD_LCD_D22__LCD_D22 | MXS_PAD_CTRL,
  103. MX28_PAD_LCD_D23__LCD_D23 | MXS_PAD_CTRL,
  104. MX28_PAD_LCD_RD_E__LCD_VSYNC | MXS_PAD_CTRL,
  105. MX28_PAD_LCD_WR_RWN__LCD_HSYNC | MXS_PAD_CTRL,
  106. MX28_PAD_LCD_RS__LCD_DOTCLK | MXS_PAD_CTRL,
  107. MX28_PAD_LCD_CS__LCD_ENABLE | MXS_PAD_CTRL,
  108. /* LCD panel enable */
  109. MX28_PAD_LCD_RESET__GPIO_3_30 | MXS_PAD_CTRL,
  110. /* backlight control */
  111. MX28_PAD_PWM2__GPIO_3_18 | MXS_PAD_CTRL,
  112. /* mmc0 */
  113. MX28_PAD_SSP0_DATA0__SSP0_D0 |
  114. (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
  115. MX28_PAD_SSP0_DATA1__SSP0_D1 |
  116. (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
  117. MX28_PAD_SSP0_DATA2__SSP0_D2 |
  118. (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
  119. MX28_PAD_SSP0_DATA3__SSP0_D3 |
  120. (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
  121. MX28_PAD_SSP0_DATA4__SSP0_D4 |
  122. (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
  123. MX28_PAD_SSP0_DATA5__SSP0_D5 |
  124. (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
  125. MX28_PAD_SSP0_DATA6__SSP0_D6 |
  126. (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
  127. MX28_PAD_SSP0_DATA7__SSP0_D7 |
  128. (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
  129. MX28_PAD_SSP0_CMD__SSP0_CMD |
  130. (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
  131. MX28_PAD_SSP0_DETECT__SSP0_CARD_DETECT |
  132. (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
  133. MX28_PAD_SSP0_SCK__SSP0_SCK |
  134. (MXS_PAD_12MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
  135. /* write protect */
  136. MX28_PAD_SSP1_SCK__GPIO_2_12 |
  137. (MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
  138. /* slot power enable */
  139. MX28_PAD_PWM3__GPIO_3_28 |
  140. (MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
  141. /* mmc1 */
  142. MX28_PAD_GPMI_D00__SSP1_D0 |
  143. (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
  144. MX28_PAD_GPMI_D01__SSP1_D1 |
  145. (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
  146. MX28_PAD_GPMI_D02__SSP1_D2 |
  147. (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
  148. MX28_PAD_GPMI_D03__SSP1_D3 |
  149. (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
  150. MX28_PAD_GPMI_D04__SSP1_D4 |
  151. (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
  152. MX28_PAD_GPMI_D05__SSP1_D5 |
  153. (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
  154. MX28_PAD_GPMI_D06__SSP1_D6 |
  155. (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
  156. MX28_PAD_GPMI_D07__SSP1_D7 |
  157. (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
  158. MX28_PAD_GPMI_RDY1__SSP1_CMD |
  159. (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
  160. MX28_PAD_GPMI_RDY0__SSP1_CARD_DETECT |
  161. (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
  162. MX28_PAD_GPMI_WRN__SSP1_SCK |
  163. (MXS_PAD_12MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
  164. /* write protect */
  165. MX28_PAD_GPMI_RESETN__GPIO_0_28 |
  166. (MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
  167. /* slot power enable */
  168. MX28_PAD_PWM4__GPIO_3_29 |
  169. (MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
  170. };
  171. /* fec */
  172. static void __init mx28evk_fec_reset(void)
  173. {
  174. int ret;
  175. struct clk *clk;
  176. /* Enable fec phy clock */
  177. clk = clk_get_sys("pll2", NULL);
  178. if (!IS_ERR(clk))
  179. clk_enable(clk);
  180. /* Power up fec phy */
  181. ret = gpio_request(MX28EVK_FEC_PHY_POWER, "fec-phy-power");
  182. if (ret) {
  183. pr_err("Failed to request gpio fec-phy-%s: %d\n", "power", ret);
  184. return;
  185. }
  186. ret = gpio_direction_output(MX28EVK_FEC_PHY_POWER, 0);
  187. if (ret) {
  188. pr_err("Failed to drive gpio fec-phy-%s: %d\n", "power", ret);
  189. return;
  190. }
  191. /* Reset fec phy */
  192. ret = gpio_request(MX28EVK_FEC_PHY_RESET, "fec-phy-reset");
  193. if (ret) {
  194. pr_err("Failed to request gpio fec-phy-%s: %d\n", "reset", ret);
  195. return;
  196. }
  197. gpio_direction_output(MX28EVK_FEC_PHY_RESET, 0);
  198. if (ret) {
  199. pr_err("Failed to drive gpio fec-phy-%s: %d\n", "reset", ret);
  200. return;
  201. }
  202. mdelay(1);
  203. gpio_set_value(MX28EVK_FEC_PHY_RESET, 1);
  204. }
  205. static struct fec_platform_data mx28_fec_pdata[] __initdata = {
  206. {
  207. /* fec0 */
  208. .phy = PHY_INTERFACE_MODE_RMII,
  209. }, {
  210. /* fec1 */
  211. .phy = PHY_INTERFACE_MODE_RMII,
  212. },
  213. };
  214. static int __init mx28evk_fec_get_mac(void)
  215. {
  216. int i;
  217. u32 val;
  218. const u32 *ocotp = mxs_get_ocotp();
  219. if (!ocotp)
  220. goto error;
  221. /*
  222. * OCOTP only stores the last 4 octets for each mac address,
  223. * so hard-code Freescale OUI (00:04:9f) here.
  224. */
  225. for (i = 0; i < 2; i++) {
  226. val = ocotp[i * 4];
  227. mx28_fec_pdata[i].mac[0] = 0x00;
  228. mx28_fec_pdata[i].mac[1] = 0x04;
  229. mx28_fec_pdata[i].mac[2] = 0x9f;
  230. mx28_fec_pdata[i].mac[3] = (val >> 16) & 0xff;
  231. mx28_fec_pdata[i].mac[4] = (val >> 8) & 0xff;
  232. mx28_fec_pdata[i].mac[5] = (val >> 0) & 0xff;
  233. }
  234. return 0;
  235. error:
  236. pr_err("%s: timeout when reading fec mac from OCOTP\n", __func__);
  237. return -ETIMEDOUT;
  238. }
  239. /*
  240. * MX28EVK_FLEXCAN_SWITCH is shared between both flexcan controllers
  241. */
  242. static int flexcan0_en, flexcan1_en;
  243. static void mx28evk_flexcan_switch(void)
  244. {
  245. if (flexcan0_en || flexcan1_en)
  246. gpio_set_value(MX28EVK_FLEXCAN_SWITCH, 1);
  247. else
  248. gpio_set_value(MX28EVK_FLEXCAN_SWITCH, 0);
  249. }
  250. static void mx28evk_flexcan0_switch(int enable)
  251. {
  252. flexcan0_en = enable;
  253. mx28evk_flexcan_switch();
  254. }
  255. static void mx28evk_flexcan1_switch(int enable)
  256. {
  257. flexcan1_en = enable;
  258. mx28evk_flexcan_switch();
  259. }
  260. static const struct flexcan_platform_data
  261. mx28evk_flexcan_pdata[] __initconst = {
  262. {
  263. .transceiver_switch = mx28evk_flexcan0_switch,
  264. }, {
  265. .transceiver_switch = mx28evk_flexcan1_switch,
  266. }
  267. };
  268. /* mxsfb (lcdif) */
  269. static struct fb_videomode mx28evk_video_modes[] = {
  270. {
  271. .name = "Seiko-43WVF1G",
  272. .refresh = 60,
  273. .xres = 800,
  274. .yres = 480,
  275. .pixclock = 29851, /* picosecond (33.5 MHz) */
  276. .left_margin = 89,
  277. .right_margin = 164,
  278. .upper_margin = 23,
  279. .lower_margin = 10,
  280. .hsync_len = 10,
  281. .vsync_len = 10,
  282. .sync = FB_SYNC_DATA_ENABLE_HIGH_ACT |
  283. FB_SYNC_DOTCLK_FAILING_ACT,
  284. },
  285. };
  286. static const struct mxsfb_platform_data mx28evk_mxsfb_pdata __initconst = {
  287. .mode_list = mx28evk_video_modes,
  288. .mode_count = ARRAY_SIZE(mx28evk_video_modes),
  289. .default_bpp = 32,
  290. .ld_intf_width = STMLCDIF_24BIT,
  291. };
  292. static struct mxs_mmc_platform_data mx28evk_mmc_pdata[] __initdata = {
  293. {
  294. /* mmc0 */
  295. .wp_gpio = MX28EVK_MMC0_WRITE_PROTECT,
  296. .flags = SLOTF_8_BIT_CAPABLE,
  297. }, {
  298. /* mmc1 */
  299. .wp_gpio = MX28EVK_MMC1_WRITE_PROTECT,
  300. .flags = SLOTF_8_BIT_CAPABLE,
  301. },
  302. };
  303. static void __init mx28evk_init(void)
  304. {
  305. int ret;
  306. mxs_iomux_setup_multiple_pads(mx28evk_pads, ARRAY_SIZE(mx28evk_pads));
  307. mx28_add_duart();
  308. mx28_add_auart0();
  309. mx28_add_auart3();
  310. if (mx28evk_fec_get_mac())
  311. pr_warn("%s: failed on fec mac setup\n", __func__);
  312. mx28evk_fec_reset();
  313. mx28_add_fec(0, &mx28_fec_pdata[0]);
  314. mx28_add_fec(1, &mx28_fec_pdata[1]);
  315. ret = gpio_request_one(MX28EVK_FLEXCAN_SWITCH, GPIOF_DIR_OUT,
  316. "flexcan-switch");
  317. if (ret) {
  318. pr_err("failed to request gpio flexcan-switch: %d\n", ret);
  319. } else {
  320. mx28_add_flexcan(0, &mx28evk_flexcan_pdata[0]);
  321. mx28_add_flexcan(1, &mx28evk_flexcan_pdata[1]);
  322. }
  323. ret = gpio_request_one(MX28EVK_LCD_ENABLE, GPIOF_DIR_OUT, "lcd-enable");
  324. if (ret)
  325. pr_warn("failed to request gpio lcd-enable: %d\n", ret);
  326. else
  327. gpio_set_value(MX28EVK_LCD_ENABLE, 1);
  328. ret = gpio_request_one(MX28EVK_BL_ENABLE, GPIOF_DIR_OUT, "bl-enable");
  329. if (ret)
  330. pr_warn("failed to request gpio bl-enable: %d\n", ret);
  331. else
  332. gpio_set_value(MX28EVK_BL_ENABLE, 1);
  333. mx28_add_mxsfb(&mx28evk_mxsfb_pdata);
  334. /* power on mmc slot by writing 0 to the gpio */
  335. ret = gpio_request_one(MX28EVK_MMC0_SLOT_POWER, GPIOF_OUT_INIT_LOW,
  336. "mmc0-slot-power");
  337. if (ret)
  338. pr_warn("failed to request gpio mmc0-slot-power: %d\n", ret);
  339. mx28_add_mxs_mmc(0, &mx28evk_mmc_pdata[0]);
  340. ret = gpio_request_one(MX28EVK_MMC1_SLOT_POWER, GPIOF_OUT_INIT_LOW,
  341. "mmc1-slot-power");
  342. if (ret)
  343. pr_warn("failed to request gpio mmc1-slot-power: %d\n", ret);
  344. mx28_add_mxs_mmc(1, &mx28evk_mmc_pdata[1]);
  345. }
  346. static void __init mx28evk_timer_init(void)
  347. {
  348. mx28_clocks_init();
  349. }
  350. static struct sys_timer mx28evk_timer = {
  351. .init = mx28evk_timer_init,
  352. };
  353. MACHINE_START(MX28EVK, "Freescale MX28 EVK")
  354. /* Maintainer: Freescale Semiconductor, Inc. */
  355. .map_io = mx28_map_io,
  356. .init_irq = mx28_init_irq,
  357. .init_machine = mx28evk_init,
  358. .timer = &mx28evk_timer,
  359. MACHINE_END