atmel_hlcdfb.c 6.5 KB

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