atmel_hlcdfb.c 6.1 KB

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