2008-05-09 19:57:18 +00:00
|
|
|
/*
|
|
|
|
* Driver for AT91/AT32 LCD Controller
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Atmel Corporation
|
|
|
|
*
|
2013-10-07 11:07:26 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2008-05-09 19:57:18 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2016-05-05 13:28:20 +00:00
|
|
|
#include <atmel_lcd.h>
|
|
|
|
#include <dm.h>
|
2016-05-05 13:28:19 +00:00
|
|
|
#include <fdtdec.h>
|
2016-05-05 13:28:20 +00:00
|
|
|
#include <video.h>
|
2008-05-09 19:57:18 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/arch/gpio.h>
|
|
|
|
#include <asm/arch/clk.h>
|
|
|
|
#include <lcd.h>
|
2015-02-03 11:32:27 +00:00
|
|
|
#include <bmp_layout.h>
|
2008-05-09 19:57:18 +00:00
|
|
|
#include <atmel_lcdc.h>
|
|
|
|
|
2016-05-05 13:28:20 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
#ifdef CONFIG_DM_VIDEO
|
|
|
|
enum {
|
|
|
|
/* Maximum LCD size we support */
|
|
|
|
LCD_MAX_WIDTH = 1366,
|
|
|
|
LCD_MAX_HEIGHT = 768,
|
|
|
|
LCD_MAX_LOG2_BPP = VIDEO_BPP16,
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct atmel_fb_priv {
|
|
|
|
struct display_timing timing;
|
|
|
|
};
|
|
|
|
|
2008-05-09 19:57:18 +00:00
|
|
|
/* configurable parameters */
|
|
|
|
#define ATMEL_LCDC_CVAL_DEFAULT 0xc8
|
|
|
|
#define ATMEL_LCDC_DMA_BURST_LEN 8
|
2009-06-29 14:59:10 +00:00
|
|
|
#ifndef ATMEL_LCDC_GUARD_TIME
|
|
|
|
#define ATMEL_LCDC_GUARD_TIME 1
|
|
|
|
#endif
|
2008-05-09 19:57:18 +00:00
|
|
|
|
2015-01-16 02:55:46 +00:00
|
|
|
#if defined(CONFIG_AT91SAM9263)
|
2008-05-09 19:57:18 +00:00
|
|
|
#define ATMEL_LCDC_FIFO_SIZE 2048
|
|
|
|
#else
|
|
|
|
#define ATMEL_LCDC_FIFO_SIZE 512
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define lcdc_readl(mmio, reg) __raw_readl((mmio)+(reg))
|
|
|
|
#define lcdc_writel(mmio, reg, val) __raw_writel((val), (mmio)+(reg))
|
|
|
|
|
2016-05-05 13:28:20 +00:00
|
|
|
#ifndef CONFIG_DM_VIDEO
|
2015-02-03 11:32:21 +00:00
|
|
|
ushort *configuration_get_cmap(void)
|
|
|
|
{
|
|
|
|
return (ushort *)(panel_info.mmio + ATMEL_LCDC_LUT(0));
|
|
|
|
}
|
|
|
|
|
2015-02-03 11:32:22 +00:00
|
|
|
#if defined(CONFIG_BMP_16BPP) && defined(CONFIG_ATMEL_LCD_BGR555)
|
|
|
|
void fb_put_word(uchar **fb, uchar **from)
|
|
|
|
{
|
|
|
|
*(*fb)++ = (((*from)[0] & 0x1f) << 2) | ((*from)[1] & 0x03);
|
|
|
|
*(*fb)++ = ((*from)[0] & 0xe0) | (((*from)[1] & 0x7c) >> 2);
|
|
|
|
*from += 2;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-02-03 11:32:24 +00:00
|
|
|
#ifdef CONFIG_LCD_LOGO
|
|
|
|
#include <bmp_logo.h>
|
|
|
|
void lcd_logo_set_cmap(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
uint lut_entry;
|
|
|
|
ushort colreg;
|
|
|
|
uint *cmap = (uint *)configuration_get_cmap();
|
|
|
|
|
|
|
|
for (i = 0; i < BMP_LOGO_COLORS; ++i) {
|
|
|
|
colreg = bmp_logo_palette[i];
|
|
|
|
#ifdef CONFIG_ATMEL_LCD_BGR555
|
|
|
|
lut_entry = ((colreg & 0x000F) << 11) |
|
|
|
|
((colreg & 0x00F0) << 2) |
|
|
|
|
((colreg & 0x0F00) >> 7);
|
|
|
|
#else
|
|
|
|
lut_entry = ((colreg & 0x000F) << 1) |
|
|
|
|
((colreg & 0x00F0) << 3) |
|
|
|
|
((colreg & 0x0F00) << 4);
|
|
|
|
#endif
|
|
|
|
*(cmap + BMP_LOGO_OFFSET) = lut_entry;
|
|
|
|
cmap++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-05-09 19:57:18 +00:00
|
|
|
void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blue)
|
|
|
|
{
|
|
|
|
#if defined(CONFIG_ATMEL_LCD_BGR555)
|
|
|
|
lcdc_writel(panel_info.mmio, ATMEL_LCDC_LUT(regno),
|
|
|
|
(red >> 3) | ((green & 0xf8) << 2) | ((blue & 0xf8) << 7));
|
|
|
|
#else
|
|
|
|
lcdc_writel(panel_info.mmio, ATMEL_LCDC_LUT(regno),
|
|
|
|
(blue >> 3) | ((green & 0xfc) << 3) | ((red & 0xf8) << 8));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-05-13 13:02:27 +00:00
|
|
|
void lcd_set_cmap(struct bmp_image *bmp, unsigned colors)
|
2015-02-03 11:32:27 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < colors; ++i) {
|
2015-05-13 13:02:27 +00:00
|
|
|
struct bmp_color_table_entry cte = bmp->color_table[i];
|
2015-02-03 11:32:27 +00:00
|
|
|
lcd_setcolreg(i, cte.red, cte.green, cte.blue);
|
|
|
|
}
|
|
|
|
}
|
2016-05-05 13:28:20 +00:00
|
|
|
#endif
|
2015-02-03 11:32:27 +00:00
|
|
|
|
2016-05-05 13:28:19 +00:00
|
|
|
static void atmel_fb_init(ulong addr, struct display_timing *timing, int bpix,
|
|
|
|
bool tft, bool cont_pol_low, ulong lcdbase)
|
2008-05-09 19:57:18 +00:00
|
|
|
{
|
|
|
|
unsigned long value;
|
2016-05-05 13:28:19 +00:00
|
|
|
void *reg = (void *)addr;
|
2008-05-09 19:57:18 +00:00
|
|
|
|
|
|
|
/* Turn off the LCD controller and the DMA controller */
|
2016-05-05 13:28:19 +00:00
|
|
|
lcdc_writel(reg, ATMEL_LCDC_PWRCON,
|
2009-06-29 14:59:10 +00:00
|
|
|
ATMEL_LCDC_GUARD_TIME << ATMEL_LCDC_GUARDT_OFFSET);
|
2008-05-09 19:57:18 +00:00
|
|
|
|
|
|
|
/* Wait for the LCDC core to become idle */
|
2016-05-05 13:28:19 +00:00
|
|
|
while (lcdc_readl(reg, ATMEL_LCDC_PWRCON) & ATMEL_LCDC_BUSY)
|
2008-05-09 19:57:18 +00:00
|
|
|
udelay(10);
|
|
|
|
|
2016-05-05 13:28:19 +00:00
|
|
|
lcdc_writel(reg, ATMEL_LCDC_DMACON, 0);
|
2008-05-09 19:57:18 +00:00
|
|
|
|
|
|
|
/* Reset LCDC DMA */
|
2016-05-05 13:28:19 +00:00
|
|
|
lcdc_writel(reg, ATMEL_LCDC_DMACON, ATMEL_LCDC_DMARST);
|
2008-05-09 19:57:18 +00:00
|
|
|
|
|
|
|
/* ...set frame size and burst length = 8 words (?) */
|
2016-05-05 13:28:19 +00:00
|
|
|
value = (timing->hactive.typ * timing->vactive.typ *
|
|
|
|
(1 << bpix)) / 32;
|
2008-05-09 19:57:18 +00:00
|
|
|
value |= ((ATMEL_LCDC_DMA_BURST_LEN - 1) << ATMEL_LCDC_BLENGTH_OFFSET);
|
2016-05-05 13:28:19 +00:00
|
|
|
lcdc_writel(reg, ATMEL_LCDC_DMAFRMCFG, value);
|
2008-05-09 19:57:18 +00:00
|
|
|
|
|
|
|
/* Set pixel clock */
|
2016-05-05 13:28:19 +00:00
|
|
|
value = get_lcdc_clk_rate(0) / timing->pixelclock.typ;
|
|
|
|
if (get_lcdc_clk_rate(0) % timing->pixelclock.typ)
|
2008-05-09 19:57:18 +00:00
|
|
|
value++;
|
|
|
|
value = (value / 2) - 1;
|
|
|
|
|
|
|
|
if (!value) {
|
2016-05-05 13:28:19 +00:00
|
|
|
lcdc_writel(reg, ATMEL_LCDC_LCDCON1, ATMEL_LCDC_BYPASS);
|
2008-05-09 19:57:18 +00:00
|
|
|
} else
|
2016-05-05 13:28:19 +00:00
|
|
|
lcdc_writel(reg, ATMEL_LCDC_LCDCON1,
|
2008-05-09 19:57:18 +00:00
|
|
|
value << ATMEL_LCDC_CLKVAL_OFFSET);
|
|
|
|
|
|
|
|
/* Initialize control register 2 */
|
2008-08-06 12:05:38 +00:00
|
|
|
#ifdef CONFIG_AVR32
|
|
|
|
value = ATMEL_LCDC_MEMOR_BIG | ATMEL_LCDC_CLKMOD_ALWAYSACTIVE;
|
|
|
|
#else
|
2008-05-09 19:57:18 +00:00
|
|
|
value = ATMEL_LCDC_MEMOR_LITTLE | ATMEL_LCDC_CLKMOD_ALWAYSACTIVE;
|
2008-08-06 12:05:38 +00:00
|
|
|
#endif
|
2016-05-05 13:28:19 +00:00
|
|
|
if (tft)
|
2008-05-09 19:57:18 +00:00
|
|
|
value |= ATMEL_LCDC_DISTYPE_TFT;
|
|
|
|
|
2016-05-05 13:28:19 +00:00
|
|
|
if (!(timing->flags & DISPLAY_FLAGS_HSYNC_HIGH))
|
|
|
|
value |= ATMEL_LCDC_INVLINE_INVERTED;
|
|
|
|
if (!(timing->flags & DISPLAY_FLAGS_VSYNC_HIGH))
|
|
|
|
value |= ATMEL_LCDC_INVFRAME_INVERTED;
|
|
|
|
value |= bpix << 5;
|
|
|
|
lcdc_writel(reg, ATMEL_LCDC_LCDCON2, value);
|
2008-05-09 19:57:18 +00:00
|
|
|
|
|
|
|
/* Vertical timing */
|
2016-05-05 13:28:19 +00:00
|
|
|
value = (timing->vsync_len.typ - 1) << ATMEL_LCDC_VPW_OFFSET;
|
|
|
|
value |= timing->vback_porch.typ << ATMEL_LCDC_VBP_OFFSET;
|
|
|
|
value |= timing->vfront_porch.typ;
|
|
|
|
/* Magic! (Datasheet says "Bit 31 must be written to 1") */
|
|
|
|
value |= 1U << 31;
|
|
|
|
lcdc_writel(reg, ATMEL_LCDC_TIM1, value);
|
2008-05-09 19:57:18 +00:00
|
|
|
|
|
|
|
/* Horizontal timing */
|
2016-05-05 13:28:19 +00:00
|
|
|
value = (timing->hfront_porch.typ - 1) << ATMEL_LCDC_HFP_OFFSET;
|
|
|
|
value |= (timing->hsync_len.typ - 1) << ATMEL_LCDC_HPW_OFFSET;
|
|
|
|
value |= (timing->hback_porch.typ - 1);
|
|
|
|
lcdc_writel(reg, ATMEL_LCDC_TIM2, value);
|
2008-05-09 19:57:18 +00:00
|
|
|
|
|
|
|
/* Display size */
|
2016-05-05 13:28:19 +00:00
|
|
|
value = (timing->hactive.typ - 1) << ATMEL_LCDC_HOZVAL_OFFSET;
|
|
|
|
value |= timing->vactive.typ - 1;
|
|
|
|
lcdc_writel(reg, ATMEL_LCDC_LCDFRMCFG, value);
|
2008-05-09 19:57:18 +00:00
|
|
|
|
|
|
|
/* FIFO Threshold: Use formula from data sheet */
|
|
|
|
value = ATMEL_LCDC_FIFO_SIZE - (2 * ATMEL_LCDC_DMA_BURST_LEN + 3);
|
2016-05-05 13:28:19 +00:00
|
|
|
lcdc_writel(reg, ATMEL_LCDC_FIFO, value);
|
2008-05-09 19:57:18 +00:00
|
|
|
|
|
|
|
/* Toggle LCD_MODE every frame */
|
2016-05-05 13:28:19 +00:00
|
|
|
lcdc_writel(reg, ATMEL_LCDC_MVAL, 0);
|
2008-05-09 19:57:18 +00:00
|
|
|
|
|
|
|
/* Disable all interrupts */
|
2016-05-05 13:28:19 +00:00
|
|
|
lcdc_writel(reg, ATMEL_LCDC_IDR, ~0UL);
|
2008-05-09 19:57:18 +00:00
|
|
|
|
|
|
|
/* Set contrast */
|
|
|
|
value = ATMEL_LCDC_PS_DIV8 |
|
|
|
|
ATMEL_LCDC_ENA_PWMENABLE;
|
2016-05-05 13:28:19 +00:00
|
|
|
if (!cont_pol_low)
|
2010-07-20 06:55:40 +00:00
|
|
|
value |= ATMEL_LCDC_POL_POSITIVE;
|
2016-05-05 13:28:19 +00:00
|
|
|
lcdc_writel(reg, ATMEL_LCDC_CONTRAST_CTR, value);
|
|
|
|
lcdc_writel(reg, ATMEL_LCDC_CONTRAST_VAL, ATMEL_LCDC_CVAL_DEFAULT);
|
2008-05-09 19:57:18 +00:00
|
|
|
|
|
|
|
/* Set framebuffer DMA base address and pixel offset */
|
2016-05-05 13:28:19 +00:00
|
|
|
lcdc_writel(reg, ATMEL_LCDC_DMABADDR1, lcdbase);
|
2008-05-09 19:57:18 +00:00
|
|
|
|
2016-05-05 13:28:19 +00:00
|
|
|
lcdc_writel(reg, ATMEL_LCDC_DMACON, ATMEL_LCDC_DMAEN);
|
|
|
|
lcdc_writel(reg, ATMEL_LCDC_PWRCON,
|
2009-06-29 14:59:10 +00:00
|
|
|
(ATMEL_LCDC_GUARD_TIME << ATMEL_LCDC_GUARDT_OFFSET) | ATMEL_LCDC_PWR);
|
2008-05-09 19:57:18 +00:00
|
|
|
}
|
|
|
|
|
2016-05-05 13:28:20 +00:00
|
|
|
#ifndef CONFIG_DM_VIDEO
|
2016-05-05 13:28:19 +00:00
|
|
|
void lcd_ctrl_init(void *lcdbase)
|
|
|
|
{
|
|
|
|
struct display_timing timing;
|
|
|
|
|
|
|
|
timing.flags = 0;
|
|
|
|
if (!(panel_info.vl_sync & ATMEL_LCDC_INVLINE_INVERTED))
|
|
|
|
timing.flags |= DISPLAY_FLAGS_HSYNC_HIGH;
|
|
|
|
if (!(panel_info.vl_sync & ATMEL_LCDC_INVFRAME_INVERTED))
|
|
|
|
timing.flags |= DISPLAY_FLAGS_VSYNC_LOW;
|
|
|
|
timing.pixelclock.typ = panel_info.vl_clk;
|
|
|
|
|
|
|
|
timing.hactive.typ = panel_info.vl_col;
|
|
|
|
timing.hfront_porch.typ = panel_info.vl_right_margin;
|
|
|
|
timing.hback_porch.typ = panel_info.vl_left_margin;
|
|
|
|
timing.hsync_len.typ = panel_info.vl_hsync_len;
|
|
|
|
|
|
|
|
timing.vactive.typ = panel_info.vl_row;
|
|
|
|
timing.vfront_porch.typ = panel_info.vl_clk;
|
|
|
|
timing.vback_porch.typ = panel_info.vl_clk;
|
|
|
|
timing.vsync_len.typ = panel_info.vl_clk;
|
|
|
|
|
|
|
|
atmel_fb_init(panel_info.mmio, &timing, panel_info.vl_bpix,
|
|
|
|
panel_info.vl_tft, panel_info.vl_cont_pol_low,
|
|
|
|
(ulong)lcdbase);
|
|
|
|
}
|
|
|
|
|
2008-05-09 19:57:18 +00:00
|
|
|
ulong calc_fbsize(void)
|
|
|
|
{
|
|
|
|
return ((panel_info.vl_col * panel_info.vl_row *
|
|
|
|
NBITS(panel_info.vl_bpix)) / 8) + PAGE_SIZE;
|
|
|
|
}
|
2016-05-05 13:28:20 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_DM_VIDEO
|
|
|
|
static int atmel_fb_lcd_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct video_uc_platdata *uc_plat = dev_get_uclass_platdata(dev);
|
|
|
|
struct video_priv *uc_priv = dev_get_uclass_priv(dev);
|
|
|
|
struct atmel_fb_priv *priv = dev_get_priv(dev);
|
|
|
|
struct display_timing *timing = &priv->timing;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For now some values are hard-coded. We could use the device tree
|
|
|
|
* bindings in simple-framebuffer.txt to specify the format/bpp and
|
|
|
|
* some Atmel-specific binding for tft and cont_pol_low.
|
|
|
|
*/
|
|
|
|
atmel_fb_init(ATMEL_BASE_LCDC, timing, VIDEO_BPP16, true, false,
|
|
|
|
uc_plat->base);
|
|
|
|
uc_priv->xsize = timing->hactive.typ;
|
|
|
|
uc_priv->ysize = timing->vactive.typ;
|
|
|
|
uc_priv->bpix = VIDEO_BPP16;
|
|
|
|
video_set_flush_dcache(dev, true);
|
|
|
|
debug("LCD frame buffer at %lx, size %x, %dx%d pixels\n", uc_plat->base,
|
|
|
|
uc_plat->size, uc_priv->xsize, uc_priv->ysize);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int atmel_fb_ofdata_to_platdata(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct atmel_lcd_platdata *plat = dev_get_platdata(dev);
|
|
|
|
struct atmel_fb_priv *priv = dev_get_priv(dev);
|
|
|
|
struct display_timing *timing = &priv->timing;
|
|
|
|
const void *blob = gd->fdt_blob;
|
|
|
|
|
|
|
|
if (fdtdec_decode_display_timing(blob, dev->of_offset,
|
|
|
|
plat->timing_index, timing)) {
|
|
|
|
debug("%s: Failed to decode display timing\n", __func__);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int atmel_fb_lcd_bind(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct video_uc_platdata *uc_plat = dev_get_uclass_platdata(dev);
|
|
|
|
|
|
|
|
uc_plat->size = LCD_MAX_WIDTH * LCD_MAX_HEIGHT *
|
|
|
|
(1 << VIDEO_BPP16) / 8;
|
|
|
|
debug("%s: Frame buffer size %x\n", __func__, uc_plat->size);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct udevice_id atmel_fb_lcd_ids[] = {
|
|
|
|
{ .compatible = "atmel,at91sam9g45-lcdc" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(atmel_fb) = {
|
|
|
|
.name = "atmel_fb",
|
|
|
|
.id = UCLASS_VIDEO,
|
|
|
|
.of_match = atmel_fb_lcd_ids,
|
|
|
|
.bind = atmel_fb_lcd_bind,
|
|
|
|
.ofdata_to_platdata = atmel_fb_ofdata_to_platdata,
|
|
|
|
.probe = atmel_fb_lcd_probe,
|
|
|
|
.platdata_auto_alloc_size = sizeof(struct atmel_lcd_platdata),
|
|
|
|
.priv_auto_alloc_size = sizeof(struct atmel_fb_priv),
|
|
|
|
};
|
|
|
|
#endif
|