这个型号的屏原来在6410上调过,昨天在2416上重新调了一次,把驱动贴上来给大家参考一上.这个是IO模拟SPI的屏,用到了LCD的信号线VD0,VD1,VD8,VD9,请在LCD初始化的时候不要把这几个初始化成LCD数据线。
文件名:gzsd_ili9486.c
内容如下:
/* * drivers/video/samsung/gzsd_ili9486.c * * $Id: gzsd_ili9486.c,v 1.0 2012/11/24 14:22:24 * * Copyright (C) 2012 Hcly Dao <[email protected]> * * This file is subject to the terms and conditions of the GNU General Public * License. See the file COPYING in the main directory of this archive for * more details. * * S3C Frame Buffer Driver * based on skeletonfb.c, sa1100fb.h, s3c2410fb.c */ #include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/string.h> #include <linux/init.h> #include <linux/delay.h> #include <mach/regs-gpio.h> #include <linux/gpio.h> #include <plat/gpio-cfg.h> #define SPI_CS S3C2410_GPC(8) #define SPI_CLK S3C2410_GPD(0) #define SPI_SDI S3C2410_GPC(9) #define RESET S3C2410_GPD(1) static void set_cs(int cs) { gpio_set_value(SPI_CS,cs); } static void set_clk(int clk) { gpio_set_value(SPI_CLK,clk); } static void set_outdata(int outdata) { gpio_set_value(SPI_SDI,outdata); } static void send_data(unsigned int data) { unsigned int i; int clk_num; int clk_mask; set_cs(0); udelay(10); set_clk(1); set_outdata(1); udelay(10); clk_num = 9; clk_mask = 0x100; udelay(50); for(i = 0; i < clk_num; ++i){ set_clk(0); if(data & clk_mask){ set_outdata(1); } else{ set_outdata(0); } udelay(100); set_clk(1); udelay(100); data <<= 1; } set_outdata(1); set_cs(1); } static void ili9486_write_cmd(unsigned char cmd) { unsigned int out; out = (cmd & 0xFF); send_data(out); } static void ili9486_write_data(unsigned char data) { unsigned int out = (data & 0xFF) | 0x100; send_data(out); } static void set_ili9486(void) { ili9486_write_cmd(0XF1); ili9486_write_data(0x36); ili9486_write_data(0x04); ili9486_write_data(0x00); ili9486_write_data(0x3c); ili9486_write_data(0x0f); ili9486_write_data(0x8f); ili9486_write_cmd(0XF2); ili9486_write_data(0x18); ili9486_write_data(0xa3); ili9486_write_data(0x12); ili9486_write_data(0x02); ili9486_write_data(0xb2); ili9486_write_data(0x12); ili9486_write_data(0xff); ili9486_write_data(0x10); ili9486_write_data(0x00); ili9486_write_cmd(0XF8); ili9486_write_data(0x21); ili9486_write_data(0x04); ili9486_write_cmd(0XF9); ili9486_write_data(0x00); ili9486_write_data(0x08); ili9486_write_cmd(0XB1); ili9486_write_data(0xB0); ili9486_write_data(0x11); ili9486_write_cmd(0XB4); ili9486_write_data(0x02); ili9486_write_cmd(0XB6); ili9486_write_data(0x32); //0x22 internal syytem clock ili9486_write_data(0x62); ili9486_write_data(0x3B); ili9486_write_cmd(0XC0); ili9486_write_data(0x09); ili9486_write_data(0x09); ili9486_write_cmd(0XC1); ili9486_write_data(0x41); ili9486_write_cmd(0XC2); ili9486_write_data(0x22); ili9486_write_cmd(0XC5); ili9486_write_data(0x00); ili9486_write_data(0x36); ili9486_write_cmd(0x36); ili9486_write_data(0x88); ili9486_write_cmd(0x3A); ili9486_write_data(0x66); // 8bit,16bit=0x55 18bit=0x66 ili9486_write_cmd(0xE0); ili9486_write_data(0x00); ili9486_write_data(0x2C); ili9486_write_data(0x2C); ili9486_write_data(0x0B); ili9486_write_data(0x0C); ili9486_write_data(0x04); ili9486_write_data(0x4C); ili9486_write_data(0x64); ili9486_write_data(0x36); ili9486_write_data(0x03); ili9486_write_data(0x0E); ili9486_write_data(0x01); ili9486_write_data(0x10); ili9486_write_data(0x01); ili9486_write_data(0x00); ili9486_write_cmd(0XE1); ili9486_write_data(0x0f); ili9486_write_data(0x37); ili9486_write_data(0x37); ili9486_write_data(0x0C); ili9486_write_data(0x0F); ili9486_write_data(0x05); ili9486_write_data(0x50); ili9486_write_data(0x32); ili9486_write_data(0x36); ili9486_write_data(0x04); ili9486_write_data(0x0B); ili9486_write_data(0x00); ili9486_write_data(0x19); ili9486_write_data(0x14); ili9486_write_data(0x0F); ili9486_write_cmd(0x21); ili9486_write_cmd(0x11); mdelay(200); ili9486_write_cmd(0x29); } static void ili9486_reset(void) { gpio_set_value(RESET,1); mdelay(1); gpio_set_value(RESET,0); mdelay(100); gpio_set_value(RESET,1); mdelay(20); } static int cfg_gpio() { int err; err = gpio_request(SPI_CS, "GPI0"); //cs if (err) { printk(KERN_ERR "failed to request GPI0 for " "ili9486 cs control\n"); return err; } err = gpio_request(SPI_SDI, "GPI1"); //data if (err) { printk(KERN_ERR "failed to request GPI1 for " "ili9486 outdata control\n"); return err; } err = gpio_request(SPI_CLK, "GPI8"); //clk if (err) { printk(KERN_ERR "failed to request GPI8 for " "ili9486 clk control\n"); return err; } err = gpio_request(RESET, "GPI9"); //reset if (err) { printk(KERN_ERR "failed to request GPI9 for " "ili9486 reset control\n"); return err; } s3c_gpio_cfgpin(SPI_CS, S3C_GPIO_OUTPUT); //cs s3c_gpio_setpull(SPI_CS, S3C_GPIO_PULL_UP); s3c_gpio_cfgpin(SPI_SDI, S3C_GPIO_OUTPUT); //outdata s3c_gpio_setpull(SPI_SDI, S3C_GPIO_PULL_UP); s3c_gpio_cfgpin(SPI_CLK,S3C_GPIO_OUTPUT); //clk s3c_gpio_setpull(SPI_CLK, S3C_GPIO_PULL_UP); s3c_gpio_cfgpin(RESET, S3C_GPIO_OUTPUT); //reset s3c_gpio_setpull(RESET, S3C_GPIO_PULL_UP); return 0; } static void ili9486_release(void) { set_cs(1); set_clk(1); set_outdata(1); gpio_free(SPI_CS); gpio_free(SPI_SDI); gpio_free(SPI_CLK); gpio_free(RESET); } static void __init ili9486_init(void) { int err; err = cfg_gpio(); if(err < 0) return; ili9486_reset(); set_ili9486(); printk(KERN_INFO "Gzsd LCD ili9486 init successfully!\n"); } static void __exit ili9486_exit(void) { ili9486_release(); } module_init(ili9486_init); module_exit(ili9486_exit); MODULE_AUTHOR("Hcly Dao <[email protected]>"); MODULE_DESCRIPTION("Gzsd210 ili9486 driver"); MODULE_LICENSE("GPL");
屏幕参数配制如下:
#define S3CFB_HFP 2//10//20//19 /* front porch */ #define S3CFB_HSW 41//15//27 /* hsync width */ #define S3CFB_HBP 2//30//37 /* back porch */ #define S3CFB_VFP 1//8//3//10 /* front porch */ #define S3CFB_VSW 2//2//13 /* vsync width */ #define S3CFB_VBP 1//20//26 /* back porch */ #define S3CFB_HRES 320 /* horizon pixel x resolition */ #define S3CFB_VRES 480 /* line cnt y resolution */ #define S3CFB_HRES_VIRTUAL 320 /* horizon pixel x resolition */ #define S3CFB_VRES_VIRTUAL 960 /* line cnt y resolution */ #define S3CFB_HRES_OSD 320 /* horizon pixel x resolition */ #define S3CFB_VRES_OSD 480 /* line cnt y resolution */ #define S3CFB_VFRAME_FREQ 80 /* frame rate freq */ #define S3CFB_PIXEL_CLOCK 12
这里说下点时钟的计算方法:
PIXCLK=(S3CFB_VFRAME_FREQ * (S3CFB_HFP + S3CFB_HSW + S3CFB_HBP + S3CFB_HRES) * (S3CFB_VFP + S3CFB_VSW + S3CFB_VBP + S3CFB_VRES))
=80*365*484
=14132800
理论上这里的点时钟应该是14.13M 用示波器量出来应该是这么多,不过上体效果得调了才知道。
我这里设置的
#define S3CFB_PIXEL_CLOCK 12
是多少M具体我就不记得了。