blob: fa6a82cfaf6f37b4e655080675e4abf7809184c3 [file] [log] [blame]
Stelian Pop39cf4802008-05-09 21:57:18 +02001/*
2 * Driver for AT91/AT32 LCD Controller
3 *
4 * Copyright (C) 2007 Atmel Corporation
5 *
Wolfgang Denk3765b3e2013-10-07 13:07:26 +02006 * SPDX-License-Identifier: GPL-2.0+
Stelian Pop39cf4802008-05-09 21:57:18 +02007 */
8
9#include <common.h>
10#include <asm/io.h>
Stelian Pop39cf4802008-05-09 21:57:18 +020011#include <asm/arch/gpio.h>
12#include <asm/arch/clk.h>
13#include <lcd.h>
14#include <atmel_lcdc.h>
15
Stelian Pop39cf4802008-05-09 21:57:18 +020016/* configurable parameters */
17#define ATMEL_LCDC_CVAL_DEFAULT 0xc8
18#define ATMEL_LCDC_DMA_BURST_LEN 8
Mark Jackson6bbced62009-06-29 15:59:10 +010019#ifndef ATMEL_LCDC_GUARD_TIME
20#define ATMEL_LCDC_GUARD_TIME 1
21#endif
Stelian Pop39cf4802008-05-09 21:57:18 +020022
23#if defined(CONFIG_AT91SAM9263) || defined(CONFIG_AT91CAP9)
24#define ATMEL_LCDC_FIFO_SIZE 2048
25#else
26#define ATMEL_LCDC_FIFO_SIZE 512
27#endif
28
29#define lcdc_readl(mmio, reg) __raw_readl((mmio)+(reg))
30#define lcdc_writel(mmio, reg, val) __raw_writel((val), (mmio)+(reg))
31
Nikita Kiryanov38b55082015-02-03 13:32:21 +020032ushort *configuration_get_cmap(void)
33{
34 return (ushort *)(panel_info.mmio + ATMEL_LCDC_LUT(0));
35}
36
Stelian Pop39cf4802008-05-09 21:57:18 +020037void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blue)
38{
39#if defined(CONFIG_ATMEL_LCD_BGR555)
40 lcdc_writel(panel_info.mmio, ATMEL_LCDC_LUT(regno),
41 (red >> 3) | ((green & 0xf8) << 2) | ((blue & 0xf8) << 7));
42#else
43 lcdc_writel(panel_info.mmio, ATMEL_LCDC_LUT(regno),
44 (blue >> 3) | ((green & 0xfc) << 3) | ((red & 0xf8) << 8));
45#endif
46}
47
48void lcd_ctrl_init(void *lcdbase)
49{
50 unsigned long value;
51
52 /* Turn off the LCD controller and the DMA controller */
53 lcdc_writel(panel_info.mmio, ATMEL_LCDC_PWRCON,
Mark Jackson6bbced62009-06-29 15:59:10 +010054 ATMEL_LCDC_GUARD_TIME << ATMEL_LCDC_GUARDT_OFFSET);
Stelian Pop39cf4802008-05-09 21:57:18 +020055
56 /* Wait for the LCDC core to become idle */
57 while (lcdc_readl(panel_info.mmio, ATMEL_LCDC_PWRCON) & ATMEL_LCDC_BUSY)
58 udelay(10);
59
60 lcdc_writel(panel_info.mmio, ATMEL_LCDC_DMACON, 0);
61
62 /* Reset LCDC DMA */
63 lcdc_writel(panel_info.mmio, ATMEL_LCDC_DMACON, ATMEL_LCDC_DMARST);
64
65 /* ...set frame size and burst length = 8 words (?) */
66 value = (panel_info.vl_col * panel_info.vl_row *
67 NBITS(panel_info.vl_bpix)) / 32;
68 value |= ((ATMEL_LCDC_DMA_BURST_LEN - 1) << ATMEL_LCDC_BLENGTH_OFFSET);
69 lcdc_writel(panel_info.mmio, ATMEL_LCDC_DMAFRMCFG, value);
70
71 /* Set pixel clock */
72 value = get_lcdc_clk_rate(0) / panel_info.vl_clk;
73 if (get_lcdc_clk_rate(0) % panel_info.vl_clk)
74 value++;
75 value = (value / 2) - 1;
76
77 if (!value) {
78 lcdc_writel(panel_info.mmio, ATMEL_LCDC_LCDCON1, ATMEL_LCDC_BYPASS);
79 } else
80 lcdc_writel(panel_info.mmio, ATMEL_LCDC_LCDCON1,
81 value << ATMEL_LCDC_CLKVAL_OFFSET);
82
83 /* Initialize control register 2 */
Stefan Roesef2302d42008-08-06 14:05:38 +020084#ifdef CONFIG_AVR32
85 value = ATMEL_LCDC_MEMOR_BIG | ATMEL_LCDC_CLKMOD_ALWAYSACTIVE;
86#else
Stelian Pop39cf4802008-05-09 21:57:18 +020087 value = ATMEL_LCDC_MEMOR_LITTLE | ATMEL_LCDC_CLKMOD_ALWAYSACTIVE;
Stefan Roesef2302d42008-08-06 14:05:38 +020088#endif
Stelian Pop39cf4802008-05-09 21:57:18 +020089 if (panel_info.vl_tft)
90 value |= ATMEL_LCDC_DISTYPE_TFT;
91
Haavard Skinnemoen70dbc542008-09-01 16:21:19 +020092 value |= panel_info.vl_sync;
Stelian Pop39cf4802008-05-09 21:57:18 +020093 value |= (panel_info.vl_bpix << 5);
94 lcdc_writel(panel_info.mmio, ATMEL_LCDC_LCDCON2, value);
95
96 /* Vertical timing */
97 value = (panel_info.vl_vsync_len - 1) << ATMEL_LCDC_VPW_OFFSET;
98 value |= panel_info.vl_upper_margin << ATMEL_LCDC_VBP_OFFSET;
99 value |= panel_info.vl_lower_margin;
100 lcdc_writel(panel_info.mmio, ATMEL_LCDC_TIM1, value);
101
102 /* Horizontal timing */
103 value = (panel_info.vl_right_margin - 1) << ATMEL_LCDC_HFP_OFFSET;
104 value |= (panel_info.vl_hsync_len - 1) << ATMEL_LCDC_HPW_OFFSET;
105 value |= (panel_info.vl_left_margin - 1);
106 lcdc_writel(panel_info.mmio, ATMEL_LCDC_TIM2, value);
107
108 /* Display size */
109 value = (panel_info.vl_col - 1) << ATMEL_LCDC_HOZVAL_OFFSET;
110 value |= panel_info.vl_row - 1;
111 lcdc_writel(panel_info.mmio, ATMEL_LCDC_LCDFRMCFG, value);
112
113 /* FIFO Threshold: Use formula from data sheet */
114 value = ATMEL_LCDC_FIFO_SIZE - (2 * ATMEL_LCDC_DMA_BURST_LEN + 3);
115 lcdc_writel(panel_info.mmio, ATMEL_LCDC_FIFO, value);
116
117 /* Toggle LCD_MODE every frame */
118 lcdc_writel(panel_info.mmio, ATMEL_LCDC_MVAL, 0);
119
120 /* Disable all interrupts */
121 lcdc_writel(panel_info.mmio, ATMEL_LCDC_IDR, ~0UL);
122
123 /* Set contrast */
124 value = ATMEL_LCDC_PS_DIV8 |
Stelian Pop39cf4802008-05-09 21:57:18 +0200125 ATMEL_LCDC_ENA_PWMENABLE;
Alexander Steincdfcedb2010-07-20 08:55:40 +0200126 if (!panel_info.vl_cont_pol_low)
127 value |= ATMEL_LCDC_POL_POSITIVE;
Stelian Pop39cf4802008-05-09 21:57:18 +0200128 lcdc_writel(panel_info.mmio, ATMEL_LCDC_CONTRAST_CTR, value);
129 lcdc_writel(panel_info.mmio, ATMEL_LCDC_CONTRAST_VAL, ATMEL_LCDC_CVAL_DEFAULT);
130
131 /* Set framebuffer DMA base address and pixel offset */
132 lcdc_writel(panel_info.mmio, ATMEL_LCDC_DMABADDR1, (u_long)lcdbase);
133
134 lcdc_writel(panel_info.mmio, ATMEL_LCDC_DMACON, ATMEL_LCDC_DMAEN);
135 lcdc_writel(panel_info.mmio, ATMEL_LCDC_PWRCON,
Mark Jackson6bbced62009-06-29 15:59:10 +0100136 (ATMEL_LCDC_GUARD_TIME << ATMEL_LCDC_GUARDT_OFFSET) | ATMEL_LCDC_PWR);
Stelian Pop39cf4802008-05-09 21:57:18 +0200137}
138
139ulong calc_fbsize(void)
140{
141 return ((panel_info.vl_col * panel_info.vl_row *
142 NBITS(panel_info.vl_bpix)) / 8) + PAGE_SIZE;
143}