mini2440 lcd支持

内核版本:linux-2.6.32.2        实验平台:mini2440 + 统宝3.5寸屏(TD035STED4)

1. 添加平台设备

linux中已经定义好了s3c2440的平台设备,定义在plat-s3c24xx/devs.c中:

/* LCD Controller */

static struct resource s3c_lcd_resource[] = {
	[0] = {
		.start = S3C24XX_PA_LCD,
		.end   = S3C24XX_PA_LCD + S3C24XX_SZ_LCD - 1,
		.flags = IORESOURCE_MEM,
	},
	[1] = {
		.start = IRQ_LCD,
		.end   = IRQ_LCD,
		.flags = IORESOURCE_IRQ,
	}

};

static u64 s3c_device_lcd_dmamask = 0xffffffffUL;

struct platform_device s3c_device_lcd = {
	.name             = "s3c2410-lcd",
	.id               = -1,
	.num_resources    = ARRAY_SIZE(s3c_lcd_resource),
	.resource         = s3c_lcd_resource,
	.dev              = {
		.dma_mask               = &s3c_device_lcd_dmamask,
		.coherent_dma_mask      = 0xffffffffUL
	}
};

EXPORT_SYMBOL(s3c_device_lcd);
现在要将这个平台设备添加到mini2440_devices这个数组中:
static struct platform_device *mini2440_devices[] __initdata = {
	/* ... */
	&s3c_device_lcd,
	/* ... */
};

2. 为lcd添加参数
在mach-mini2440.c中添加如下内容:
static struct s3c2410fb_display mini2440_lcd_cfg __initdata = {
        .lcdcon5        = S3C2410_LCDCON5_FRM565 |
                          S3C2410_LCDCON5_INVVLINE |
                          S3C2410_LCDCON5_INVVFRAME |
                          S3C2410_LCDCON5_PWREN |
                          S3C2410_LCDCON5_HWSWP,

        .type           = S3C2410_LCDCON1_TFT,

        .width          = 0,
        .height         = 0,

        .pixclock       = 170000,
        .xres           = 240,
        .yres           = 320,
        .bpp            = 16,
        .left_margin    = 1,
        .right_margin   = 26,
        .hsync_len      = 5,
        .upper_margin   = 2,
        .lower_margin   = 5,
        .vsync_len      = 2,
};

static struct s3c2410fb_mach_info mini2440_fb_info __initdata = {
        .displays       = &mini2440_lcd_cfg,
        .num_displays   = 1,
        .default_display = 0,

        .gpccon =       0xaa955699,
        .gpccon_mask =  0xffc003cc,
        .gpcup =        0x0000ffff,
        .gpcup_mask =   0xffffffff,

        .gpdcon =       0xaa95aaa1,
        .gpdcon_mask =  0xffc0fff0,
        .gpdup =        0x0000faff,
        .gpdup_mask =   0xffffffff,


        .lpcsel =       0xf82,
};
最后将lcd参数赋值给平台设备:
static void __init mini2440_machine_init(void)
{
	/* ... */
	s3c24xx_fb_set_platdata(&mini2440_fb_info);
	/* ... */
}

3. 添加背光驱动
在drivers/video/backlight目录下添加一个新的文件mini2440_backlight.c,内容如下:
#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/miscdevice.h>
#include <linux/gpio.h>

#include <asm/uaccess.h>

#include <mach/regs-gpio.h>


static unsigned int bl_state;

static inline void set_bl(int state)
{
	bl_state = !!state;
	s3c2410_gpio_setpin(S3C2410_GPG(4), bl_state);
}

static inline unsigned char get_bl(void)
{
	return bl_state;
}

static ssize_t dev_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
{
	int ret;
	unsigned char str[] = {'0', '1'};

	if (!count)
		return 0;

	ret = copy_to_user(buf, str + get_bl(), sizeof(unsigned char)) ? -EFAULT : 0;
	if (ret)
		return ret;

	return sizeof(unsigned char);
}

static ssize_t dev_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
{
	int ret;
	unsigned char ch;

	if (!count)
		return 0;

	ret = copy_from_user(&ch, buf, sizeof(unsigned char)) ? -EFAULT : 0;
	if (ret)
		return ret;

	ch &= 0x01;
	set_bl(ch);

	return count;
}

static struct file_operations dev_fops = {
	.owner	= THIS_MODULE,
	.read	= dev_read,
	.write	= dev_write,
};

static struct miscdevice misc = {
	.minor	= MISC_DYNAMIC_MINOR,
	.name	= "backlight",
	.fops	= &dev_fops,
};

static int __init dev_init(void)
{
	s3c2410_gpio_cfgpin(S3C2410_GPG(4), S3C2410_GPIO_OUTPUT);
	set_bl(1);

	return misc_register(&misc);
}

static void __exit dev_exit(void)
{
	misc_deregister(&misc);
}

module_init(dev_init);
module_exit(dev_exit);

MODULE_LICENSE("Dual BSD/GPL");
LCD的背光驱动很简单,同LED驱动一样,只需要控制GPIO引脚就可以了,mini2440背光驱动的GPIO口使用的是GPG4,拉高即打开LCD背光,拉低关闭LCD背光。

修改当前目录下的Kconfig和Makefile,在文件末尾添加如下内容:

// Kconfig
config BACKLIGHT_MINI2440
	tristate "Backlight Driver for MINI2440"
	depends on BACKLIGHT_LCD_SUPPORT && FB_S3C2410
	help
	  backlight driver for mini2440

// Makefile
obj-$(CONFIG_BACKLIGHT_MINI2440) += mini2440_backlight.o

可以通过echo 0 > /dev/backlight和echo 1 > /dev/backlight来关闭、打开LCD背光。


4. 内核配置

    Device Drivers  --->
	    Graphics support  --->
		<*> Support for frame buffer devices  --->
			<*>   S3C2410 LCD framebuffer support
		[*] Backlight & LCD device support  --->
			<*>   Backlight Driver for MINI2440
		    Console display driver support  --->
			<*> Framebuffer Console support
		[*] Bootup logo  --->
			[*]   Standard 224-color Linux logo

注意,必须配置上<*> Framebuffer Console support,开机LOGO才能够被显示出来。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值