裝置樹學習之(十二)LCD驅動
開發板:tiny4412SDK + S702 + 4GB Flash
要移植的核心版本:Linux-4.4.0 (支援device tree)
u-boot版本:友善之臂自帶的 U-Boot 2010.12
busybox版本:busybox 1.25
1、背光
友善之臂的該款LCD採用了一線觸控技術,包括背光控制也整合在一線觸控之中,關於背光的控制,在前一篇文章中已經提及,本文重點在於LCD驅動。
2、LCD介面
- 1)Tiny 4412 使用的lcd介面為LCD1
- 2)圖片資料訊號介面
- B[0:7] : 藍色資料訊號線
- G[0:7] : 綠色資料訊號線
- R[0:7] : 紅色資料訊號線
- 3)時序訊號介面
- DEN 資料允許訊號
- VSYNC 垂直同步訊號
- HSYNC 水平同步訊號
- VLCK LCD時鐘訊號
- 4)一線觸控
- XEINT10_OUT
3、影象的構成
- 幀:一幅影象被稱為一幀,每幀有多行組成,每行有多個畫素點組成
- 畫素:
- 1)顯示的最小單位
- 2)由若干位的顏色資料來構成,畫素越高,則一個畫素點所需要的顏色資料越多,能夠顯示的顏色更廣
- 3)一個畫素點構成的顏色位數稱為畫素深度,單位為1BPP 常見的有16BPP/24BPP
4、顏色的量化(顏色<—–>數字)
顏色一般採用RGB標準,通過對紅(R)、綠(GREEN),藍(B)三個顏色以及相互疊加獲取各種不同的顏色
- 1)通過對顏色的編碼來對顏色進行量化(即轉換成數字量,RGB是一種編碼方式)
- 2)每種顏色根據RGB格式不同,每種顏色的量化位不相同
- 3) 常見的RGB格式有RGB565/RGB888
- RGB565: red :5 green : 6 blue:5
- RGB888: red :8 green : 8 blue:8
5、顯示影象與LCD時序
- 1)使用HSYNC訊號來控制一行的顯示
- 2)使用VSYNC訊號來控制一幀的顯示
- 3)使用VCLK訊號來控制一個畫素的顯示
- 4)使用VDEN訊號來控制資料的輸出
6、Exyons 4412 display 控制器
- 1)alpha,alpha操作用於實現圖形漸變效果,以及半透明效果
- 0xfff == 全透明
- 0x0 == 不透明
- 2)colorkey,colorkey操作在融合兩個視窗時過慮掉其中一個視窗的某一種特定顏色
- 3)HOZVAL與LINEVAL
- HOZVAL = (Horizontal display size) - 1
- LINEVAL = (Vertical display size) - 1
- 4)LCD時序圖
notes:
.Using the display controller data, you can select one of the above data paths by setting LCDBLK_CFG Register(0x1001_0210). For more information, refer to the “System Others” manual
7、Exyons 4412 display 控制器配置
- 1)gpio配置,檢視原理圖 ,獲取LCD介面的對應的gpio
- LCD_HSYNC:GPF0_0
- LCD_VSYNC:GPF0_1
- LCD_VDEV: GPF0_2
- LCD_VCLK: GPF0_3
- VD[23:0]:GPF1_0 - GPF1_5 / GPF2_0 - GPF2_7 / GPF3_0 - GPF3_3
- 2)時鐘配置
- (1)檢視Exyons 4412 手冊 獲取LCD時鐘源
LCD 時鐘源為SCLKmpll_user_t:800Mhz - (2)配置相關的暫存器得到LCD所需要的時鐘 (見07lcd_clock)
- (1)檢視Exyons 4412 手冊 獲取LCD時鐘源
- 3)系統配置
LCDBLK_CFG : 配置成FIMD介面
一、裝置樹
&pinctrl_0 {
lcd_demo: lcd{
samsung,pins = "gpf0-0", "gpf0-1", "gpf0-2", "gpf0-3", "gpf0-4", "gpf0-5", "gpf0-6","gpf0-7", "gpf1-0", "gpf1-1", "gpf1-2", "gpf1-3", "gpf1-4", "gpf1-5", "gpf1-6","gpf1-7", "gpf2-0", "gpf2-1", "gpf2-2", "gpf2-3", "gpf2-4", "gpf2-5", "gpf2-6","gpf2-7", "gpf3-0", "gpf3-1", "gpf3-2", "gpf3-3";
samsung,pin-function = <2>;
samsung,pin-pud = <0>;
samsung,pin-drv = <0>;
};
};
[email protected]11C00000{
compatible = "tiny4412,lcd_demo";
reg = <0x11C00000 0x20c0 0x10010210 0x08 0x10023c80 0x04 0x1003c000 0x1000>;
pinctrl-names = "default";
pinctrl-0 = <&lcd_demo>;
clocks = <&clock CLK_FIMD0 &clock CLK_ACLK160>;
clock-names = "fimd0","aclk160";
};
二、驅動程式碼
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/string.h>
#include <linux/mm.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/fb.h>
#include <linux/init.h>
#include <linux/dma-mapping.h>
#include <linux/interrupt.h>
#include <linux/workqueue.h>
#include <linux/wait.h>
#include <linux/platform_device.h>
#include <linux/clk.h>
#include <asm/io.h>
#include <asm/uaccess.h>
#include <asm/div64.h>
#include <asm/mach/map.h>
#include <linux/fb.h>
#include <asm/types.h>
#define VIDCON0 0x00
#define VIDCON1 0x04
#define VIDTCON0 0x10
#define VIDTCON1 0x14
#define VIDTCON2 0x18
#define WINCON0 0x20
#define VIDOSD0C 0x48
#define SHADOWCON 0x34
#define WINCHMAP2 0x3c
#define VIDOSD0A 0x40
#define VIDOSD0B 0x44
#define VIDW00ADD0B0 0xA0
#define VIDW00ADD1B0 0xD0
#define CLK_SRC_LCD0 0x234
#define CLK_SRC_MASK_LCD 0x334
#define CLK_DIV_LCD 0x534
#define CLK_GATE_IP_LCD 0x934
#define LCDBLK_CFG 0x00
#define LCDBLK_CFG2 0x04
static int s3c_lcdfb_setcolreg(unsigned int regno, unsigned int red,
unsigned int green, unsigned int blue,
unsigned int transp, struct fb_info *info);
static struct fb_ops s3c_lcdfb_ops =
{
.owner = THIS_MODULE,
.fb_setcolreg = s3c_lcdfb_setcolreg,
.fb_fillrect = cfb_fillrect,
.fb_copyarea = cfb_copyarea,
.fb_imageblit = cfb_imageblit,
};
static struct fb_info *s3c_lcd;
static volatile void __iomem *lcd_regs_base;
static volatile void __iomem *clk_regs_base;
static volatile void __iomem *lcdblk_regs_base;
static volatile void __iomem *lcd0_configuration;
static u32 pseudo_palette[16];
static struct resource *res1, *res2, *res3, *res4;
/* from pxafb.c */
static inline unsigned int chan_to_field(unsigned int chan, struct fb_bitfield *bf)
{
chan &= 0xffff;
chan >>= 16 - bf->length;
return chan << bf->offset;
}
static int s3c_lcdfb_setcolreg(unsigned int regno, unsigned int red,
unsigned int green, unsigned int blue,
unsigned int transp, struct fb_info *info)
{
unsigned int val;
if (regno > 16)
{ return 1; }
/* 用red,green,blue三原色構造出val */
val = chan_to_field(red, &info->var.red);
val |= chan_to_field(green, &info->var.green);
val |= chan_to_field(blue, &info->var.blue);
//((u32 *)(info->pseudo_palette))[regno] = val;
pseudo_palette[regno] = val;
return 0;
}
static int lcd_probe(struct platform_device *pdev)
{
int ret;
unsigned int temp;
/* 1. 分配一個fb_info */
s3c_lcd = framebuffer_alloc(0, NULL);
/* 2. 設定 */
/* 2.1 設定 fix 固定的引數 */
strcpy(s3c_lcd->fix.id, "mylcd");
s3c_lcd->fix.smem_len = 480 * 800 * 16 / 8; //視訊記憶體的長度
s3c_lcd->fix.type = FB_TYPE_PACKED_PIXELS; //型別
s3c_lcd->fix.visual = FB_VISUAL_TRUECOLOR; //TFT 真彩色
s3c_lcd->fix.line_length = 800 * 2; //一行的長度
/* 2.2 設定 var 可變的引數 */
s3c_lcd->var.xres = 800; //x方向解析度
s3c_lcd->var.yres = 480; //y方向解析度
s3c_lcd->var.xres_virtual = 800; //x方向虛擬解析度
s3c_lcd->var.yres_virtual = 480; //y方向虛擬解析度
s3c_lcd->var.bits_per_pixel = 16; //每個畫素佔的bit
/* RGB:565 */
s3c_lcd->var.red.offset = 11; //紅
s3c_lcd->var.red.length = 5;
s3c_lcd->var.green.offset = 5; //綠
s3c_lcd->var.green.length = 6;
s3c_lcd->var.blue.offset = 0; //藍
s3c_lcd->var.blue.length = 5;
s3c_lcd->var.activate = FB_ACTIVATE_NOW;
/* 2.3 設定操作函式 */
s3c_lcd->fbops = &s3c_lcdfb_ops;
/* 2.4 其他的設定 */
s3c_lcd->pseudo_palette = pseudo_palette; //調色盤
//s3c_lcd->screen_base = ; //視訊記憶體的虛擬地址,分配視訊記憶體時填充
s3c_lcd->screen_size = 480 * 800 * 16 / 8; //視訊記憶體大小
/* 3. 硬體相關的操作 */
/* 3.1 配置GPIO用於LCD */
//裝置樹中使用"default"
/* 3.2 根據LCD手冊設定LCD控制器, 比如VCLK的頻率等 */
//暫存器對映
res1 = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (res1 == NULL)
{
printk("platform_get_resource error\n");
return -EINVAL;
}
lcd_regs_base = devm_ioremap_resource(&pdev->dev, res1);
if (lcd_regs_base == NULL)
{
printk("devm_ioremap_resource error\n");
return -EINVAL;
}
res2 = platform_get_resource(pdev, IORESOURCE_MEM, 1);
if (res2 == NULL)
{
printk("platform_get_resource error\n");
return -EINVAL;
}
lcdblk_regs_base = devm_ioremap_resource(&pdev->dev, res2);
if (lcdblk_regs_base == NULL)
{
printk("devm_ioremap_resource error\n");
return -EINVAL;
}
res3 = platform_get_resource(pdev, IORESOURCE_MEM, 2);
if (res3 == NULL)
{
printk("platform_get_resource error\n");
return -EINVAL;
}
lcd0_configuration = ioremap(res3->start, 0x04);
*lcd0_configuration = 0x07;
res4 = platform_get_resource(pdev, IORESOURCE_MEM, 3);
if (res4 == NULL)
{
printk("platform_get_resource error\n");
return -EINVAL;
}
clk_regs_base = ioremap(res4->start, 0x1000);
if (clk_regs_base == NULL)
{
printk("devm_ioremap_resource error\n");
return -EINVAL;
}
//使能時鐘
//時鐘源選擇 0110 SCLKMPLL_USER_T 800M
temp = readl(clk_regs_base + CLK_SRC_LCD0);
temp &= ~0x0f;
temp |= 0x06;
writel(temp, clk_regs_base + CLK_SRC_LCD0);
//FIMD0_MASK
temp = readl(clk_regs_base + CLK_SRC_MASK_LCD);
temp |= 0x01;
writel(temp, clk_regs_base + CLK_SRC_MASK_LCD);
//SCLK_FIMD0 = MOUTFIMD0/(FIMD0_RATIO + 1),分頻 1/1
temp = readl(clk_regs_base + CLK_DIV_LCD);
temp &= ~0x0f;
writel(temp, clk_regs_base + CLK_DIV_LCD);
//CLK_FIMD0 Pass
temp = readl(clk_regs_base + CLK_GATE_IP_LCD);
temp |= 0x01;
writel(temp, clk_regs_base + CLK_GATE_IP_LCD);
//FIMDBYPASS_LBLK0 FIMD Bypass
temp = readl(lcdblk_regs_base + LCDBLK_CFG);
temp |= 1 << 1;
writel(temp, lcdblk_regs_base + LCDBLK_CFG);
temp = readl(lcdblk_regs_base + LCDBLK_CFG2);
temp |= 1 << 0;
writel(temp, lcdblk_regs_base + LCDBLK_CFG2);
mdelay(1000);
//分頻 800/(23 +1 ) == 33M
temp = readl(lcd_regs_base + VIDCON0);
temp |= (23 << 6);
writel(temp, lcd_regs_base + VIDCON0);
/*
* VIDTCON1:
* [5]:IVSYNC ===> 1 : Inverted(反轉)
* [6]:IHSYNC ===> 1 : Inverted(反轉)
* [7]:IVCLK ===> 1 : Fetches video data at VCLK rising edge (下降沿觸發)
* [10:9]:FIXVCLK ====> 01 : VCLK running
*/
temp = readl(lcd_regs_base + VIDCON1);
temp |= (1 << 9) | (1 << 7) | (1 << 5) | (1 << 6);
writel(temp, lcd_regs_base + VIDCON1);
/*
* VIDTCON0:
* [23:16]: VBPD + 1 <------> tvpw (1 - 20) 13
* [15:8] : VFPD + 1 <------> tvfp 22
* [7:0] : VSPW + 1 <------> tvb - tvpw = 23 - 13 = 10
*/
temp = readl(lcd_regs_base + VIDTCON0);
temp |= (12 << 16) | (21 << 8) | (9);
writel(temp, lcd_regs_base + VIDTCON0);
/*
* VIDTCON1:
* [23:16]: HBPD + 1 <------> thpw (1 - 40) 36
* [15:8] : HFPD + 1 <------> thfp 210
* [7:0] : HSPW + 1 <------> thb - thpw = 46 - 36 = 10
*/
temp = readl(lcd_regs_base + VIDTCON1);
temp |= (35 << 16) | (209 << 8) | (9);
writel(temp, lcd_regs_base + VIDTCON1);
/*
* HOZVAL = (Horizontal display size) - 1 and LINEVAL = (Vertical display size) - 1.
* Horizontal(水平) display size : 800
* Vertical(垂直) display size : 480
*/
temp = (479 << 11) | 799;
writel(temp, lcd_regs_base + VIDTCON2);
/*
* WINCON0:
* [16]:Specifies Half-Word swap control bit. 1 = Enables swap P1779 低位畫素存放在低位元組
* [5:2]: Selects Bits Per Pixel (BPP) mode for Window image : 0101 ===> 16BPP RGB565
* [1]:Enables/disables video output 1 = Enables
*/
temp = readl(lcd_regs_base + WINCON0);
temp |= (1 << 16) | (5 << 2) | 1;
writel(temp, lcd_regs_base + WINCON0);
temp = readl(lcd_regs_base + SHADOWCON);
writel(temp | 0x01, lcd_regs_base + SHADOWCON);
//p1769
temp = readl(lcd_regs_base + WINCHMAP2);
temp &= ~(7 << 16);
temp |= 1 << 16;
temp &= ~7;
temp |= 1;
writel(temp, lcd_regs_base + WINCHMAP2);
/*
* bit0-10 : 指定OSD影象左上畫素的垂直螢幕座標
* bit11-21: 指定OSD影象左上畫素的水平螢幕座標
*/
writel(0, lcd_regs_base + VIDOSD0A);
/*
* bit0-10 : 指定OSD影象右下畫素的垂直螢幕座標
* bit11-21: 指定OSD影象右下畫素的水平螢幕座標
*/
writel((799 << 11) | 479, lcd_regs_base + VIDOSD0B);
//Window Size For example, Height ? Width (number of word)
temp = 480 * 800 >> 1;
writel(temp, lcd_regs_base + VIDOSD0C);
/* 3.3 分配視訊記憶體(framebuffer), 並把地址告訴LCD控制器 */
// s3c_lcd->screen_base 視訊記憶體虛擬地址
// s3c_lcd->fix.smem_len 視訊記憶體大小,前面計算的
// s3c_lcd->fix.smem_start 視訊記憶體實體地址
s3c_lcd->screen_base = dma_alloc_writecombine(NULL, s3c_lcd->fix.smem_len, (dma_addr_t *)&s3c_lcd->fix.smem_start, GFP_KERNEL);
//視訊記憶體起始地址
writel(s3c_lcd->fix.smem_start, lcd_regs_base + VIDW00ADD0B0);
//視訊記憶體結束地址
writel(s3c_lcd->fix.smem_start + s3c_lcd->fix.smem_len, lcd_regs_base + VIDW00ADD1B0);
//Enables video output and logic immediately
temp = readl(lcd_regs_base + VIDCON0);
writel(temp | 0x03, lcd_regs_base + VIDCON0);
/* 4. 註冊 */
ret = register_framebuffer(s3c_lcd);
return ret;
}
static int lcd_remove(struct platform_device *pdev)
{
printk("%s enter.\n", __func__);
unregister_framebuffer(s3c_lcd);
dma_free_writecombine(NULL, s3c_lcd->fix.smem_len, s3c_lcd->screen_base, s3c_lcd->fix.smem_start);
framebuffer_release(s3c_lcd);
iounmap(lcd0_configuration);
iounmap(clk_regs_base);
return 0;
}
static const struct of_device_id lcd_dt_ids[] =
{
{ .compatible = "tiny4412,lcd_demo", },
{},
};
MODULE_DEVICE_TABLE(of, lcd_dt_ids);
static struct platform_driver lcd_driver =
{
.driver = {
.name = "lcd_demo",
.of_match_table = of_match_ptr(lcd_dt_ids),
},
.probe = lcd_probe,
.remove = lcd_remove,
};
static int lcd_init(void)
{
int ret;
printk("enter %s\n", __func__);
ret = platform_driver_register(&lcd_driver);
if (ret)
{
printk(KERN_ERR "pwm demo: probe faipwm: %d\n", ret);
}
return ret;
}
static void lcd_exit(void)
{
printk("enter %s\n", __func__);
platform_driver_unregister(&lcd_driver);
}
module_init(lcd_init);
module_exit(lcd_exit);
MODULE_LICENSE("GPL");
相關推薦
裝置樹學習之(十二)LCD驅動
開發板:tiny4412SDK + S702 + 4GB Flash 要移植的核心版本:Linux-4.4.0 (支援device tree) u-boot版本:友善之臂自帶的 U-Boot 2010.12 busybox版本:busy
裝置樹學習之(十)spi flash
開發板:tiny4412SDK + S702 + 4GB Flash 要移植的核心版本:Linux-4.4.0 (支援device tree) u-boot版本:友善之臂自帶的 U-Boot 2010.12 busybox版本:busy
裝置樹學習之(二)點燈
開發板:tiny4412SDK + S702 + 4GB Flash 要移植的核心版本:Linux-4.4.0 (支援device tree) u-boot版本:友善之臂自帶的 U-Boot 2010.12 busybox版本:busy
Android開發學習筆記(十二)基礎UI控制元件之ImageView、CheckBox、RadioButton
一、ImageView:直接繼承自View,它的作用是在介面上顯示Drawable物件。 ImageView在佈局檔案(如main_activity.xml)中常用的屬性 有 scaleType ,s
Python3《機器學習實戰》學習筆記(十二):線性迴歸提高篇之樂高玩具套件二手價預測
一、前言 本篇文章講解線性迴歸的縮減方法,嶺迴歸以及逐步線性迴歸,同時熟悉sklearn的嶺迴歸使用方法,對樂高玩具套件的二手價格做出預測。 二、嶺迴歸 如果資料的特徵比樣本點還多應該怎麼辦?很顯然,此時我們不能再使用上文的方法進行計算了,因為矩陣X不是滿秩矩
各種音視訊編解碼學習詳解之 編解碼學習筆記(十二):其他編解碼(M-JPEG,Motion JPEG 2000,DivX)
最近在研究音視訊編解碼這一塊兒,看到@bitbit大神寫的【各種音視訊編解碼學習詳解】這篇文章,非常感謝,佩服的五體投地。奈何大神這邊文章太長,在這裡我把它分解成很多小的篇幅,方便閱讀。大神部落格傳送門:https://www.cnblogs.com/skyofbitbi
裝置樹學習之(七)I2C裝置的註冊過程分析
開發板:tiny4412SDK + S702 + 4GB Flash 要移植的核心版本:Linux-4.4.0 (支援device tree) u-boot版本:友善之臂自帶的 U-Boot 2010.12 busybox版本:busy
裝置樹學習之(九)SPI設備註冊過程
開發板:tiny4412SDK + S702 + 4GB Flash 要移植的核心版本:Linux-4.4.0 (支援device tree) u-boot版本:友善之臂自帶的 U-Boot 2010.12 busybox版本:busy
裝置樹學習之(一)GPIO中斷
開發板:tiny4412SDK + S702 + 4GB Flash 要移植的核心版本:Linux-4.4.0 (支援device tree) u-boot版本:友善之臂自帶的 U-Boot 2010.12 busybox版本:busybox 1.25目標: 學習裝置樹中GP
裝置樹學習之(十三)電容觸控式螢幕驅動
開發板:tiny4412SDK + S702 + 4GB Flash 要移植的核心版本:Linux-4.4.0 (支援device tree) u-boot版本:友善之臂自帶的 U-Boot 2010.12 busybox版本:bu
裝置樹學習之(五)watchdog
開發板:tiny4412SDK + S702 + 4GB Flash 要移植的核心版本:Linux-4.4.0 (支援device tree) u-boot版本:友善之臂自帶的 U-Boot 2010.12 busybox版本:busybox 1.25 目標: 學習裝置樹中普通
《機器學習實戰》學習筆記(十二)之利用PCA來簡化資料
轉載請註明作者和出處:http://blog.csdn.net/john_bh/ 執行平臺: Windows Python版本: Python3.6 IDE: Sublime text3 一、降維技術 1.1 什麼是降維 降維就是
裝置樹學習之(三)Clock
開發板:tiny4412SDK + S702 + 4GB Flash 要移植的核心版本:Linux-4.4.0 (支援device tree) u-boot版本:友善之臂自帶的 U-Boot 2010.12 busybox版本:busybox 1.25 目標:
從零開始學習html(十二)CSS布局模型——下
位操作 女生 margin 沒有 定位元素 top 並且 變化 開始 五、什麽是層模型? 什麽是層布局模型?層布局模型就像是圖像軟件PhotoShop中非常流行的圖層編輯功能一樣, 每個圖層能夠精確定位操作,但在網頁設計領域,由於網頁大小的活動性,層布局沒能受到熱捧。 但是
Android學習路線(十二)Activity生命周期——啟動一個Activity
-c out 方式 下載地址 生命 後臺線程 ring lan debug DEMO下載地址:http://download.csdn.net/detail/sweetvvck/7728735 不像其他的編程模式那樣應用是通過main()函數啟動的。Android系
Python學習筆記(十二) 使用模塊
常見 永遠 命令行 效果 學習筆記 例如 style name hello 摘抄:https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/001431845183
cocos2d-x學習筆記(十二)cocos2dx 3.10添加lua LuaFileSystem庫遍歷文件
luafilesystem庫;lfs;遍歷文件在lua中遍歷目錄文件需要用到lfs庫,而所用的cocos2dx 3.10沒用lfs,需要自己添加1、下載lfs.c和lfs.hhttps://github.com/keplerproject/luafilesystem 從github獲取源碼,在src目錄拷貝l
《Qt5 開發與實例(第三版)》學習筆記(十二)
action spa 添加 png esb geb itl msgbox setw 1 // 4.2 Qt5 自定義對話框 2 #include <QMessageBox> 3 4 void Dialog::showCustomMsgBox() 5
Linux學習筆記(十二)usermod、passwd、mkpasswd
屬於 pass bsp exp -- 改密碼 use uid gid 一、usermod修改用戶信息usermod -u 111 username #修改用戶 usermod -g grp2 username #修改用戶組 usermod -d
PHP7 學習筆記(十二)PHPExcel vs PhpSpreadsheet and PHP_XLSXWriter
sheet class clas 參考 項目 open shee 現在 nbsp 前言 PhpSpreadsheet是PHPExcel的下一個版本。 它打破了兼容性,極大地提高了代碼庫的質量(命名空間,PSR合規性,使用最新的PHP語言功能等)。由於所有努力都轉移到了P