xfi3.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*
  2. * Creative ZEN X-Fi3 board
  3. *
  4. * Copyright (C) 2013 Marek Vasut <marex@denx.de>
  5. *
  6. * Hardware investigation done by:
  7. *
  8. * Amaury Pouly <amaury.pouly@gmail.com>
  9. *
  10. * SPDX-License-Identifier: GPL-2.0+
  11. */
  12. #include <common.h>
  13. #include <errno.h>
  14. #include <asm/gpio.h>
  15. #include <asm/io.h>
  16. #include <asm/arch/iomux-mx23.h>
  17. #include <asm/arch/imx-regs.h>
  18. #include <asm/arch/clock.h>
  19. #include <asm/arch/sys_proto.h>
  20. DECLARE_GLOBAL_DATA_PTR;
  21. /*
  22. * Functions
  23. */
  24. int board_early_init_f(void)
  25. {
  26. /* IO0 clock at 480MHz */
  27. mxs_set_ioclk(MXC_IOCLK0, 480000);
  28. /* SSP0 clock at 96MHz */
  29. mxs_set_sspclk(MXC_SSPCLK0, 96000, 0);
  30. return 0;
  31. }
  32. int dram_init(void)
  33. {
  34. return mxs_dram_init();
  35. }
  36. #ifdef CONFIG_CMD_MMC
  37. static int xfi3_mmc_cd(int id)
  38. {
  39. switch (id) {
  40. case 0:
  41. /* The SSP_DETECT is inverted on this board. */
  42. return gpio_get_value(MX23_PAD_SSP1_DETECT__GPIO_2_1);
  43. case 1:
  44. /* Phison bridge always present */
  45. return 1;
  46. default:
  47. return 0;
  48. }
  49. }
  50. int board_mmc_init(bd_t *bis)
  51. {
  52. int ret;
  53. /* MicroSD slot */
  54. gpio_direction_input(MX23_PAD_SSP1_DETECT__GPIO_2_1);
  55. gpio_direction_output(MX23_PAD_GPMI_D07__GPIO_0_7, 0);
  56. ret = mxsmmc_initialize(bis, 0, NULL, xfi3_mmc_cd);
  57. if (ret)
  58. return ret;
  59. /* Phison SD-NAND bridge */
  60. ret = mxsmmc_initialize(bis, 1, NULL, xfi3_mmc_cd);
  61. return ret;
  62. }
  63. #endif
  64. #ifdef CONFIG_VIDEO_MXS
  65. static int mxsfb_write_byte(uint32_t payload, const unsigned int data)
  66. {
  67. struct mxs_lcdif_regs *regs = (struct mxs_lcdif_regs *)MXS_LCDIF_BASE;
  68. const unsigned int timeout = 0x10000;
  69. if (mxs_wait_mask_clr(&regs->hw_lcdif_ctrl_reg, LCDIF_CTRL_RUN,
  70. timeout))
  71. return -ETIMEDOUT;
  72. writel((1 << LCDIF_TRANSFER_COUNT_V_COUNT_OFFSET) |
  73. (1 << LCDIF_TRANSFER_COUNT_H_COUNT_OFFSET),
  74. &regs->hw_lcdif_transfer_count);
  75. writel(LCDIF_CTRL_DATA_SELECT | LCDIF_CTRL_RUN,
  76. &regs->hw_lcdif_ctrl_clr);
  77. if (data)
  78. writel(LCDIF_CTRL_DATA_SELECT, &regs->hw_lcdif_ctrl_set);
  79. writel(LCDIF_CTRL_RUN, &regs->hw_lcdif_ctrl_set);
  80. if (mxs_wait_mask_clr(&regs->hw_lcdif_lcdif_stat_reg, 1 << 29,
  81. timeout))
  82. return -ETIMEDOUT;
  83. writel(payload, &regs->hw_lcdif_data);
  84. return mxs_wait_mask_clr(&regs->hw_lcdif_ctrl_reg, LCDIF_CTRL_RUN,
  85. timeout);
  86. }
  87. static void mxsfb_write_register(uint32_t reg, uint32_t data)
  88. {
  89. mxsfb_write_byte(reg, 0);
  90. mxsfb_write_byte(data, 1);
  91. }
  92. static const struct {
  93. uint8_t reg;
  94. uint8_t delay;
  95. uint16_t val;
  96. } lcd_regs[] = {
  97. { 0x01, 0, 0x001c },
  98. { 0x02, 0, 0x0100 },
  99. /* Writing 0x30 to reg. 0x03 flips the LCD */
  100. { 0x03, 0, 0x1038 },
  101. { 0x08, 0, 0x0808 },
  102. /* This can contain 0x111 to rotate the LCD. */
  103. { 0x0c, 0, 0x0000 },
  104. { 0x0f, 0, 0x0c01 },
  105. { 0x20, 0, 0x0000 },
  106. { 0x21, 30, 0x0000 },
  107. /* Wait 30 mS here */
  108. { 0x10, 0, 0x0a00 },
  109. { 0x11, 30, 0x1038 },
  110. /* Wait 30 mS here */
  111. { 0x12, 0, 0x1010 },
  112. { 0x13, 0, 0x0050 },
  113. { 0x14, 0, 0x4f58 },
  114. { 0x30, 0, 0x0000 },
  115. { 0x31, 0, 0x00db },
  116. { 0x32, 0, 0x0000 },
  117. { 0x33, 0, 0x0000 },
  118. { 0x34, 0, 0x00db },
  119. { 0x35, 0, 0x0000 },
  120. { 0x36, 0, 0x00af },
  121. { 0x37, 0, 0x0000 },
  122. { 0x38, 0, 0x00db },
  123. { 0x39, 0, 0x0000 },
  124. { 0x50, 0, 0x0000 },
  125. { 0x51, 0, 0x0705 },
  126. { 0x52, 0, 0x0e0a },
  127. { 0x53, 0, 0x0300 },
  128. { 0x54, 0, 0x0a0e },
  129. { 0x55, 0, 0x0507 },
  130. { 0x56, 0, 0x0000 },
  131. { 0x57, 0, 0x0003 },
  132. { 0x58, 0, 0x090a },
  133. { 0x59, 30, 0x0a09 },
  134. /* Wait 30 mS here */
  135. { 0x07, 30, 0x1017 },
  136. /* Wait 40 mS here */
  137. { 0x36, 0, 0x00af },
  138. { 0x37, 0, 0x0000 },
  139. { 0x38, 0, 0x00db },
  140. { 0x39, 0, 0x0000 },
  141. { 0x20, 0, 0x0000 },
  142. { 0x21, 0, 0x0000 },
  143. };
  144. void mxsfb_system_setup(void)
  145. {
  146. struct mxs_lcdif_regs *regs = (struct mxs_lcdif_regs *)MXS_LCDIF_BASE;
  147. int i;
  148. /* Switch the LCDIF into System-Mode */
  149. writel(LCDIF_CTRL_LCDIF_MASTER | LCDIF_CTRL_DOTCLK_MODE |
  150. LCDIF_CTRL_BYPASS_COUNT, &regs->hw_lcdif_ctrl_clr);
  151. /* Restart the SmartLCD controller */
  152. mdelay(50);
  153. writel(1, &regs->hw_lcdif_ctrl1_set);
  154. mdelay(50);
  155. writel(1, &regs->hw_lcdif_ctrl1_clr);
  156. mdelay(50);
  157. writel(1, &regs->hw_lcdif_ctrl1_set);
  158. mdelay(50);
  159. /* Program the SmartLCD controller */
  160. writel(LCDIF_CTRL1_RECOVER_ON_UNDERFLOW, &regs->hw_lcdif_ctrl1_set);
  161. writel((0x03 << LCDIF_TIMING_CMD_HOLD_OFFSET) |
  162. (0x03 << LCDIF_TIMING_CMD_SETUP_OFFSET) |
  163. (0x03 << LCDIF_TIMING_DATA_HOLD_OFFSET) |
  164. (0x02 << LCDIF_TIMING_DATA_SETUP_OFFSET),
  165. &regs->hw_lcdif_timing);
  166. /*
  167. * OTM2201A init and configuration sequence.
  168. */
  169. for (i = 0; i < ARRAY_SIZE(lcd_regs); i++) {
  170. mxsfb_write_register(lcd_regs[i].reg, lcd_regs[i].val);
  171. if (lcd_regs[i].delay)
  172. mdelay(lcd_regs[i].delay);
  173. }
  174. /* Turn on Framebuffer Upload Mode */
  175. mxsfb_write_byte(0x22, 0);
  176. writel(LCDIF_CTRL_LCDIF_MASTER | LCDIF_CTRL_DATA_SELECT,
  177. &regs->hw_lcdif_ctrl_set);
  178. }
  179. #endif
  180. int board_init(void)
  181. {
  182. /* Adress of boot parameters */
  183. gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
  184. /* Turn on PWM backlight */
  185. gpio_direction_output(MX23_PAD_PWM2__GPIO_1_28, 1);
  186. return 0;
  187. }
  188. int board_eth_init(bd_t *bis)
  189. {
  190. usb_eth_initialize(bis);
  191. return 0;
  192. }