atmel_hlcdfb.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. void *lcd_base; /* Start of framebuffer memory */
  31. /* configurable parameters */
  32. #define ATMEL_LCDC_CVAL_DEFAULT 0xc8
  33. #define ATMEL_LCDC_DMA_BURST_LEN 8
  34. #ifndef ATMEL_LCDC_GUARD_TIME
  35. #define ATMEL_LCDC_GUARD_TIME 1
  36. #endif
  37. #define ATMEL_LCDC_FIFO_SIZE 512
  38. #define lcdc_readl(reg) __raw_readl((reg))
  39. #define lcdc_writel(reg, val) __raw_writel((val), (reg))
  40. /*
  41. * the CLUT register map as following
  42. * RCLUT(24 ~ 16), GCLUT(15 ~ 8), BCLUT(7 ~ 0)
  43. */
  44. void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blue)
  45. {
  46. lcdc_writel(((red << LCDC_BASECLUT_RCLUT_Pos) & LCDC_BASECLUT_RCLUT_Msk)
  47. | ((green << LCDC_BASECLUT_GCLUT_Pos) & LCDC_BASECLUT_GCLUT_Msk)
  48. | ((blue << LCDC_BASECLUT_BCLUT_Pos) & LCDC_BASECLUT_BCLUT_Msk),
  49. panel_info.mmio + ATMEL_LCDC_LUT(regno));
  50. }
  51. void lcd_ctrl_init(void *lcdbase)
  52. {
  53. unsigned long value;
  54. struct lcd_dma_desc *desc;
  55. struct atmel_hlcd_regs *regs;
  56. if (!has_lcdc())
  57. return; /* No lcdc */
  58. regs = (struct atmel_hlcd_regs *)panel_info.mmio;
  59. /* Disable DISP signal */
  60. lcdc_writel(&regs->lcdc_lcddis, LCDC_LCDDIS_DISPDIS);
  61. while ((lcdc_readl(&regs->lcdc_lcdsr) & LCDC_LCDSR_DISPSTS))
  62. udelay(1);
  63. /* Disable synchronization */
  64. lcdc_writel(&regs->lcdc_lcddis, LCDC_LCDDIS_SYNCDIS);
  65. while ((lcdc_readl(&regs->lcdc_lcdsr) & LCDC_LCDSR_LCDSTS))
  66. udelay(1);
  67. /* Disable pixel clock */
  68. lcdc_writel(&regs->lcdc_lcddis, LCDC_LCDDIS_CLKDIS);
  69. while ((lcdc_readl(&regs->lcdc_lcdsr) & LCDC_LCDSR_CLKSTS))
  70. udelay(1);
  71. /* Disable PWM */
  72. lcdc_writel(&regs->lcdc_lcddis, LCDC_LCDDIS_PWMDIS);
  73. while ((lcdc_readl(&regs->lcdc_lcdsr) & LCDC_LCDSR_PWMSTS))
  74. udelay(1);
  75. /* Set pixel clock */
  76. value = get_lcdc_clk_rate(0) / panel_info.vl_clk;
  77. if (get_lcdc_clk_rate(0) % panel_info.vl_clk)
  78. value++;
  79. if (value < 1) {
  80. /* Using system clock as pixel clock */
  81. lcdc_writel(&regs->lcdc_lcdcfg0,
  82. LCDC_LCDCFG0_CLKDIV(0)
  83. | LCDC_LCDCFG0_CGDISHCR
  84. | LCDC_LCDCFG0_CGDISHEO
  85. | LCDC_LCDCFG0_CGDISOVR1
  86. | LCDC_LCDCFG0_CGDISBASE
  87. | panel_info.vl_clk_pol
  88. | LCDC_LCDCFG0_CLKSEL);
  89. } else {
  90. lcdc_writel(&regs->lcdc_lcdcfg0,
  91. LCDC_LCDCFG0_CLKDIV(value - 2)
  92. | LCDC_LCDCFG0_CGDISHCR
  93. | LCDC_LCDCFG0_CGDISHEO
  94. | LCDC_LCDCFG0_CGDISOVR1
  95. | LCDC_LCDCFG0_CGDISBASE
  96. | panel_info.vl_clk_pol);
  97. }
  98. /* Initialize control register 5 */
  99. value = 0;
  100. value |= panel_info.vl_sync;
  101. #ifndef LCD_OUTPUT_BPP
  102. /* Output is 24bpp */
  103. value |= LCDC_LCDCFG5_MODE_OUTPUT_24BPP;
  104. #else
  105. switch (LCD_OUTPUT_BPP) {
  106. case 12:
  107. value |= LCDC_LCDCFG5_MODE_OUTPUT_12BPP;
  108. break;
  109. case 16:
  110. value |= LCDC_LCDCFG5_MODE_OUTPUT_16BPP;
  111. break;
  112. case 18:
  113. value |= LCDC_LCDCFG5_MODE_OUTPUT_18BPP;
  114. break;
  115. case 24:
  116. value |= LCDC_LCDCFG5_MODE_OUTPUT_24BPP;
  117. break;
  118. default:
  119. BUG();
  120. break;
  121. }
  122. #endif
  123. value |= LCDC_LCDCFG5_GUARDTIME(ATMEL_LCDC_GUARD_TIME);
  124. value |= (LCDC_LCDCFG5_DISPDLY | LCDC_LCDCFG5_VSPDLYS);
  125. lcdc_writel(&regs->lcdc_lcdcfg5, value);
  126. /* Vertical & Horizontal Timing */
  127. value = LCDC_LCDCFG1_VSPW(panel_info.vl_vsync_len - 1);
  128. value |= LCDC_LCDCFG1_HSPW(panel_info.vl_hsync_len - 1);
  129. lcdc_writel(&regs->lcdc_lcdcfg1, value);
  130. value = LCDC_LCDCFG2_VBPW(panel_info.vl_lower_margin);
  131. value |= LCDC_LCDCFG2_VFPW(panel_info.vl_upper_margin - 1);
  132. lcdc_writel(&regs->lcdc_lcdcfg2, value);
  133. value = LCDC_LCDCFG3_HBPW(panel_info.vl_right_margin - 1);
  134. value |= LCDC_LCDCFG3_HFPW(panel_info.vl_left_margin - 1);
  135. lcdc_writel(&regs->lcdc_lcdcfg3, value);
  136. /* Display size */
  137. value = LCDC_LCDCFG4_RPF(panel_info.vl_row - 1);
  138. value |= LCDC_LCDCFG4_PPL(panel_info.vl_col - 1);
  139. lcdc_writel(&regs->lcdc_lcdcfg4, value);
  140. lcdc_writel(&regs->lcdc_basecfg0,
  141. LCDC_BASECFG0_BLEN_AHB_INCR4 | LCDC_BASECFG0_DLBO);
  142. switch (NBITS(panel_info.vl_bpix)) {
  143. case 16:
  144. lcdc_writel(&regs->lcdc_basecfg1,
  145. LCDC_BASECFG1_RGBMODE_16BPP_RGB_565);
  146. break;
  147. default:
  148. BUG();
  149. break;
  150. }
  151. lcdc_writel(&regs->lcdc_basecfg2, LCDC_BASECFG2_XSTRIDE(0));
  152. lcdc_writel(&regs->lcdc_basecfg3, 0);
  153. lcdc_writel(&regs->lcdc_basecfg4, LCDC_BASECFG4_DMA);
  154. /* Disable all interrupts */
  155. lcdc_writel(&regs->lcdc_lcdidr, ~0UL);
  156. lcdc_writel(&regs->lcdc_baseidr, ~0UL);
  157. /* Setup the DMA descriptor, this descriptor will loop to itself */
  158. desc = (struct lcd_dma_desc *)(lcdbase - 16);
  159. desc->address = (u32)lcdbase;
  160. /* Disable DMA transfer interrupt & descriptor loaded interrupt. */
  161. desc->control = LCDC_BASECTRL_ADDIEN | LCDC_BASECTRL_DSCRIEN
  162. | LCDC_BASECTRL_DMAIEN | LCDC_BASECTRL_DFETCH;
  163. desc->next = (u32)desc;
  164. lcdc_writel(&regs->lcdc_baseaddr, desc->address);
  165. lcdc_writel(&regs->lcdc_basectrl, desc->control);
  166. lcdc_writel(&regs->lcdc_basenext, desc->next);
  167. lcdc_writel(&regs->lcdc_basecher, LCDC_BASECHER_CHEN |
  168. LCDC_BASECHER_UPDATEEN);
  169. /* Enable LCD */
  170. value = lcdc_readl(&regs->lcdc_lcden);
  171. lcdc_writel(&regs->lcdc_lcden, value | LCDC_LCDEN_CLKEN);
  172. while (!(lcdc_readl(&regs->lcdc_lcdsr) & LCDC_LCDSR_CLKSTS))
  173. udelay(1);
  174. value = lcdc_readl(&regs->lcdc_lcden);
  175. lcdc_writel(&regs->lcdc_lcden, value | LCDC_LCDEN_SYNCEN);
  176. while (!(lcdc_readl(&regs->lcdc_lcdsr) & LCDC_LCDSR_LCDSTS))
  177. udelay(1);
  178. value = lcdc_readl(&regs->lcdc_lcden);
  179. lcdc_writel(&regs->lcdc_lcden, value | LCDC_LCDEN_DISPEN);
  180. while (!(lcdc_readl(&regs->lcdc_lcdsr) & LCDC_LCDSR_DISPSTS))
  181. udelay(1);
  182. value = lcdc_readl(&regs->lcdc_lcden);
  183. lcdc_writel(&regs->lcdc_lcden, value | LCDC_LCDEN_PWMEN);
  184. while (!(lcdc_readl(&regs->lcdc_lcdsr) & LCDC_LCDSR_PWMSTS))
  185. udelay(1);
  186. }