atmel_hlcdfb.c 6.4 KB

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