• 芯片制造中的阻挡层沉积技术介绍
  • 接地搭接电缆布局屏蔽!!!
  • 北美液冷生态解码:超微spuermicro,24年营
  • SK海力士全球首发HBM4-16层堆叠、2.0TB/s
  • 2纳米Nanosheet技术及其以后的选择性层减薄

S3C2440 LCD驱动源码

[复制链接]
查看740 | 回复13 | 2020-11-23 08:31:34 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区

您需要 登录 才可以下载或查看,没有账号?立即注册

×
#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 <asm/arch/regs-lcd.h>
#include <asm/arch/regs-gpio.h>
#include <asm/arch/fb.h>

#include "./S3C2440.h"


#define DEVICE_NAME "LCD"

static struct lcd_sturt* LCD;
static struct gpio_sturt* GPIO;
static unsigned char* frambuffer;
static int major;
static struct class *lcd_class;
static struct class_device lcd_class_devs;


static struct file_operations lcd_fops = {
        .owner  =   THIS_MODULE,    /* 这是一个宏,推向编译模块时自动创建的__this_module变量 */
    .open   =   s3c24xx_leds_open,     
        .read       =       s3c24xx_leds_read,     
        .write  =       s3c24xx_leds_write,   
};

static int lcd_init(void)
{
        major = register_chrdev(0, DEVICE_NAME, &lcd_fops);                                                                                 //注册
   
        lcd_class = class_create(THIS_MODULE, DEVICE_NAME );                                                                                //设备对象
        lcd_class_devs = class_device_create(lcd_class, NULL, MKDEV(major, 0), NULL, DEVICE_NAME ); //创建设备文件
   
        GPIO = (struct gpio_sturt*)ioremap( GPIO_BASE, sizeof(struct gpio_sturt) );                                 //寄存器重映射
        LCD = (struct lcd_sturt*)ioremap( LCD_BASE, sizeof(struct lcd_sturt) );                                         //寄存器重映射
        
   
        /* 3. 硬件相关的操作 */
        /* 3.1 配置GPIO用于LCD */
        GPIO->GPCCON = 0xaaaaaaaa;   /* GPIO管脚用于VD[7:0],LCDVF[2:0],VM,VFRAME,VLINE,VCLK,LEND */
        GPIO->GPDCON = 0xaaaaaaaa;   /* GPIO管脚用于VD[23:8] */
   
        GPIO->GPBCON &= ~(3);           /* GPB0设置为输出引脚 */
        GPIO->GPBCON |= 1;
        GPIO->GPBDAT |= 1;              /* 输出高电平, 使能背光 */

        GPIO->GPGCON |= (3<<8);         /* GPG4用作LCD_PWREN */
   
        /* 3.2 根据LCD手册设置LCD控制器, 比如VCLK的频率等 */
   
    /* bit[17:8]: VCLK = HCLK / [(CLKVAL+1) x 2], LCD手册P14
     *            10MHz(100ns) = 100MHz / [(CLKVAL+1) x 2]
     *            CLKVAL = 4
     * bit[6:5]: 0b11, TFT LCD
     * bit[4:1]: 0b1100, 16 bpp for TFT
     * bit[0]  : 0 = Disable the video output and the LCD control signal.
     */
    LCD->LCDCON1  = (4<<8) | (3<<5) | (0x0c<<1);

#if 1
    /* 垂直方向的时间参数
     * bit[31:24]: VBPD, VSYNC之后再过多长时间才能发出第1行数据
     *             LCD手册 T0-T2-T1=4
     *             VBPD=3
     * bit[23:14]: 多少行, 320, 所以LINEVAL=320-1=319
     * bit[13:6] : VFPD, 发出最后一行数据之后,再过多长时间才发出VSYNC
     *             LCD手册T2-T5=322-320=2, 所以VFPD=2-1=1
     * bit[5:0]  : VSPW, VSYNC信号的脉冲宽度, LCD手册T1=1, 所以VSPW=1-1=0
     */
    LCD->LCDCON2  = (1<<24) | (271<<14) | (1<<6) | (9);


    /* 水平方向的时间参数
     * bit[25:19]: HBPD, VSYNC之后再过多长时间才能发出第1行数据
     *             LCD手册 T6-T7-T8=17
     *             HBPD=16
     * bit[18:8]: 多少列, 240, 所以HOZVAL=240-1=239
     * bit[7:0] : HFPD, 发出最后一行里最后一个象素数据之后,再过多长时间才发出HSYNC
     *             LCD手册T8-T11=251-240=11, 所以HFPD=11-1=10
     */
    LCD->LCDCON3 = (1<<19) | (479<<8) | (1);

    /* 水平方向的同步信号
     * bit[7:0] : HSPW, HSYNC信号的脉冲宽度, LCD手册T7=5, 所以HSPW=5-1=4
     */
    LCD->LCDCON4 = 40;

#else
        LCD->LCDCON2 =  S3C2410_LCDCON2_VBPD(5) | \
        S3C2410_LCDCON2_LINEVAL(319) | \
        S3C2410_LCDCON2_VFPD(3) | \
        S3C2410_LCDCON2_VSPW(1);

        LCD->LCDCON3 =  S3C2410_LCDCON3_HBPD(10) | \
        S3C2410_LCDCON3_HOZVAL(239) | \
        S3C2410_LCDCON3_HFPD(1);

        LCD->LCDCON4 =  S3C2410_LCDCON4_MVAL(13) | \
        S3C2410_LCDCON4_HSPW(0);

#endif
    /* 信号的极性
     * bit[11]: 1=565 format
     * bit[10]: 0 = The video data is fetched at VCLK falling edge
     * bit[9] : 1 = HSYNC信号要反转,即低电平有效
     * bit[8] : 1 = VSYNC信号要反转,即低电平有效
     * bit[6] : 0 = VDEN不用反转
     * bit[3] : 0 = PWREN输出0
     * bit[1] : 0 = BSWP
     * bit[0] : 1 = HWSWP 2440手册P413
     */
    LCD->LCDCON5 = (1<<11) | (0<<10) | (1<<9) | (1<<8) | (1<<0);
   
    /* 3.3 分配显存(framebuffer), 并把地址告诉LCD控制器 */
    frambuffer = kmalloc( 1024*1024*4,)
   
    LCD->LCDSADDR1  = (s3c_lcd->fix.smem_start >> 1) & ~(3<<30);
    LCD->LCDSADDR2  = ((s3c_lcd->fix.smem_start + s3c_lcd->fix.smem_len) >> 1) & 0x1fffff;
    LCD->LCDSADDR3  = (480*16/16);  /* 一行的长度(单位: 2字节) */   
   
    //s3c_lcd->fix.smem_start = xxx;  /* 显存的物理地址 */
    /* 启动LCD */
    LCD->LCDCON1 |= (1<<0); /* 使能LCD控制器 */
    LCD->LCDCON5 |= (1<<3); /* 使能LCD本身 */
   
            
   
    return 0;
}

static void lcd_exit(void)
{
        unregister_chrdev(major, DEVICE_NAME);
        
        class_device_unregister(lcd_class_devs);   
        class_destroy(lcd_class);

        iounmap(LCD);
        iounmap(GPIO);

}

module_init(lcd_init);
module_exit(lcd_exit);

/* 描述驱动程序的一些信息,不是必须的 */
MODULE_AUTHOR("db-Mark");
MODULE_VERSION("0.1.0");
MODULE_DESCRIPTION("LCD Driver");
MODULE_LICENSE("GPL");
回复

使用道具 举报

wangyitu | 2020-11-23 08:49:41 | 显示全部楼层
回复

使用道具 举报

arthurbruin | 2020-11-23 08:50:16 | 显示全部楼层
回复

使用道具 举报

清心如水 | 2020-11-23 08:52:38 | 显示全部楼层
回复

使用道具 举报

1123581321 | 2020-11-23 09:00:28 | 显示全部楼层
回复

使用道具 举报

tian_000 | 2020-11-23 10:16:00 | 显示全部楼层
回复

使用道具 举报

bidezhi7777 | 2020-11-23 12:39:34 | 显示全部楼层
回复

使用道具 举报

luchonghui74 | 2020-11-23 15:38:24 | 显示全部楼层
回复

使用道具 举报

yangxf0120 | 2020-11-23 18:18:41 | 显示全部楼层
谢谢分享S3C2440 LCD驱动源码
回复

使用道具 举报

zhang00963 | 2020-11-23 21:48:06 | 显示全部楼层
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则