atmel_hlcdfb.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. * Driver for AT91/AT32 MULTI LAYER LCD Controller
  3. *
  4. * Copyright (C) 2012 Atmel Corporation
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <common.h>
  25. #include <asm/io.h>
  26. #include <asm/arch/gpio.h>
  27. #include <asm/arch/clk.h>
  28. #include <lcd.h>
  29. #include <atmel_hlcdc.h>
  30. /* configurable parameters */
  31. #define ATMEL_LCDC_CVAL_DEFAULT 0xc8
  32. #define ATMEL_LCDC_DMA_BURST_LEN 8
  33. #ifndef ATMEL_LCDC_GUARD_TIME
  34. #define ATMEL_LCDC_GUARD_TIME 1
  35. #endif
  36. #define ATMEL_LCDC_FIFO_SIZE 512
  37. #define lcdc_readl(reg) __raw_readl((reg))
  38. #define lcdc_writel(reg, val) __raw_writel((val), (reg))
  39. /*
  40. * the CLUT register map as following
  41. * RCLUT(24 ~ 16), GCLUT(15 ~ 8), BCLUT(7 ~ 0)
  42. */
  43. void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blue)
  44. {
  45. lcdc_writel(((red << LCDC_BASECLUT_RCLUT_Pos) & LCDC_BASECLUT_RCLUT_Msk)
  46. | ((green << LCDC_BASECLUT_GCLUT_Pos) & LCDC_BASECLUT_GCLUT_Msk)
  47. | ((blue << LCDC_BASECLUT_BCLUT_Pos) & LCDC_BASECLUT_BCLUT_Msk),
  48. panel_info.mmio + ATMEL_LCDC_LUT(regno));
  49. }
  50. void lcd_ctrl_init(void *lcdbase)
  51. {
  52. unsigned long value;
  53. struct lcd_dma_desc *desc;
  54. struct atmel_hlcd_regs *regs;
  55. if (!has_lcdc())
  56. return; /* No lcdc */
  57. regs = (struct atmel_hlcd_regs *)panel_info.mmio;
  58. /* Disable DISP signal */
  59. lcdc_writel(&regs->lcdc_lcddis, LCDC_LCDDIS_DISPDIS);
  60. while ((lcdc_readl(&regs->lcdc_lcdsr) & LCDC_LCDSR_DISPSTS))
  61. udelay(1);
  62. /* Disable synchronization */
  63. lcdc_writel(&regs->lcdc_lcddis, LCDC_LCDDIS_SYNCDIS);
  64. while ((lcdc_readl(&regs->lcdc_lcdsr) & LCDC_LCDSR_LCDSTS))
  65. udelay(1);
  66. /* Disable pixel clock */
  67. lcdc_writel(&regs->lcdc_lcddis, LCDC_LCDDIS_CLKDIS);
  68. while ((lcdc_readl(&regs->lcdc_lcdsr) & LCDC_LCDSR_CLKSTS))
  69. udelay(1);
  70. /* Disable PWM */
  71. lcdc_writel(&regs->lcdc_lcddis, LCDC_LCDDIS_PWMDIS);
  72. while ((lcdc_readl(&regs->lcdc_lcdsr) & LCDC_LCDSR_PWMSTS))
  73. udelay(1);
  74. /* Set pixel clock */
  75. value = get_lcdc_clk_rate(0) / panel_info.vl_clk;
  76. if (get_lcdc_clk_rate(0) % panel_info.vl_clk)
  77. value++;
  78. if (value < 1) {
  79. /* Using system clock as pixel clock */
  80. lcdc_writel(&regs->lcdc_lcdcfg0,
  81. LCDC_LCDCFG0_CLKDIV(0)
  82. | LCDC_LCDCFG0_CGDISHCR
  83. | LCDC_LCDCFG0_CGDISHEO
  84. | LCDC_LCDCFG0_CGDISOVR1
  85. | LCDC_LCDCFG0_CGDISBASE
  86. | panel_info.vl_clk_pol
  87. | LCDC_LCDCFG0_CLKSEL);
  88. } else {
  89. lcdc_writel(&regs->lcdc_lcdcfg0,
  90. LCDC_LCDCFG0_CLKDIV(value - 2)
  91. | LCDC_LCDCFG0_CGDISHCR
  92. | LCDC_LCDCFG0_CGDISHEO
  93. | LCDC_LCDCFG0_CGDISOVR1
  94. | LCDC_LCDCFG0_CGDISBASE
  95. | panel_info.vl_clk_pol);
  96. }
  97. /* Initialize control register 5 */
  98. value = 0;
  99. value |= panel_info.vl_sync;
  100. #ifndef LCD_OUTPUT_BPP
  101. /* Output is 24bpp */
  102. value |= LCDC_LCDCFG5_MODE_OUTPUT_24BPP;
  103. #else
  104. switch (LCD_OUTPUT_BPP) {
  105. case 12:
  106. value |= LCDC_LCDCFG5_MODE_OUTPUT_12BPP;
  107. break;
  108. case 16:
  109. value |= LCDC_LCDCFG5_MODE_OUTPUT_16BPP;
  110. break;
  111. case 18:
  112. value |= LCDC_LCDCFG5_MODE_OUTPUT_18BPP;
  113. break;
  114. case 24:
  115. value |= LCDC_LCDCFG5_MODE_OUTPUT_24BPP;
  116. break;
  117. default:
  118. BUG();
  119. break;
  120. }
  121. #endif
  122. value |= LCDC_LCDCFG5_GUARDTIME(ATMEL_LCDC_GUARD_TIME);
  123. value |= (LCDC_LCDCFG5_DISPDLY | LCDC_LCDCFG5_VSPDLYS);
  124. lcdc_writel(&regs->lcdc_lcdcfg5, value);
  125. /* Vertical & Horizontal Timing */
  126. value = LCDC_LCDCFG1_VSPW(panel_info.vl_vsync_len - 1);
  127. value |= LCDC_LCDCFG1_HSPW(panel_info.vl_hsync_len - 1);
  128. lcdc_writel(&regs->lcdc_lcdcfg1, value);
  129. value = LCDC_LCDCFG2_VBPW(panel_info.vl_lower_margin);
  130. value |= LCDC_LCDCFG2_VFPW(panel_info.vl_upper_margin - 1);
  131. lcdc_writel(&regs->lcdc_lcdcfg2, value);
  132. value = LCDC_LCDCFG3_HBPW(panel_info.vl_right_margin - 1);
  133. value |= LCDC_LCDCFG3_HFPW(panel_info.vl_left_margin - 1);
  134. lcdc_writel(&regs->lcdc_lcdcfg3, value);
  135. /* Display size */
  136. value = LCDC_LCDCFG4_RPF(panel_info.vl_row - 1);
  137. value |= LCDC_LCDCFG4_PPL(panel_info.vl_col - 1);
  138. lcdc_writel(&regs->lcdc_lcdcfg4, value);
  139. lcdc_writel(&regs->lcdc_basecfg0,
  140. LCDC_BASECFG0_BLEN_AHB_INCR4 | LCDC_BASECFG0_DLBO);
  141. switch (NBITS(panel_info.vl_bpix)) {
  142. case 16:
  143. lcdc_writel(&regs->lcdc_basecfg1,
  144. LCDC_BASECFG1_RGBMODE_16BPP_RGB_565);
  145. break;
  146. default:
  147. BUG();
  148. break;
  149. }
  150. lcdc_writel(&regs->lcdc_basecfg2, LCDC_BASECFG2_XSTRIDE(0));
  151. lcdc_writel(&regs->lcdc_basecfg3, 0);
  152. lcdc_writel(&regs->lcdc_basecfg4, LCDC_BASECFG4_DMA);
  153. /* Disable all interrupts */
  154. lcdc_writel(&regs->lcdc_lcdidr, ~0UL);
  155. lcdc_writel(&regs->lcdc_baseidr, ~0UL);
  156. /* Setup the DMA descriptor, this descriptor will loop to itself */
  157. desc = (struct lcd_dma_desc *)(lcdbase - 16);
  158. desc->address = (u32)lcdbase;
  159. /* Disable DMA transfer interrupt & descriptor loaded interrupt. */
  160. desc->control = LCDC_BASECTRL_ADDIEN | LCDC_BASECTRL_DSCRIEN
  161. | LCDC_BASECTRL_DMAIEN | LCDC_BASECTRL_DFETCH;
  162. desc->next = (u32)desc;
  163. lcdc_writel(&regs->lcdc_baseaddr, desc->address);
  164. lcdc_writel(&regs->lcdc_basectrl, desc->control);
  165. lcdc_writel(&regs->lcdc_basenext, desc->next);
  166. lcdc_writel(&regs->lcdc_basecher, LCDC_BASECHER_CHEN |
  167. LCDC_BASECHER_UPDATEEN);
  168. /* Enable LCD */
  169. value = lcdc_readl(&regs->lcdc_lcden);
  170. lcdc_writel(&regs->lcdc_lcden, value | LCDC_LCDEN_CLKEN);
  171. while (!(lcdc_readl(&regs->lcdc_lcdsr) & LCDC_LCDSR_CLKSTS))
  172. udelay(1);
  173. value = lcdc_readl(&regs->lcdc_lcden);
  174. lcdc_writel(&regs->lcdc_lcden, value | LCDC_LCDEN_SYNCEN);
  175. while (!(lcdc_readl(&regs->lcdc_lcdsr) & LCDC_LCDSR_LCDSTS))
  176. udelay(1);
  177. value = lcdc_readl(&regs->lcdc_lcden);
  178. lcdc_writel(&regs->lcdc_lcden, value | LCDC_LCDEN_DISPEN);
  179. while (!(lcdc_readl(&regs->lcdc_lcdsr) & LCDC_LCDSR_DISPSTS))
  180. udelay(1);
  181. value = lcdc_readl(&regs->lcdc_lcden);
  182. lcdc_writel(&regs->lcdc_lcden, value | LCDC_LCDEN_PWMEN);
  183. while (!(lcdc_readl(&regs->lcdc_lcdsr) & LCDC_LCDSR_PWMSTS))
  184. udelay(1);
  185. }