Register a panel to kernel

本文档介绍了如何在内核配置中生成'CONFIG_LCD_PANELNAME=y',这用于注册LCD面板。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. Select LCD panel by means of 'make menuconfig':    device drivers -> Graphic Support -> Support for LCD panels

        This step generates a defination looks like "CONFIG_LCD_PANELNAME=y" in .config file.


2. in kernel/arch/arm/mach-tcc893x/board-tcc8930st-panel.c, the kernel define platform device according to CONFIG_LCD_PANELNAME (.config). Such as:
        #ifdef CONFIG_LCD_AT070TN93
            static struct platform_device at07070tn93_lcd = {
                .name = "at07070tn93_lcd",
                .dev = {
                                .platform_data = &lcd_pdata,
                                },
            };
        #endif  
                 
        
        Then register it to the platform bus.
以下是一个简单的Linux Touch Panel驱动的demo: ```c #include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/input.h> #include <linux/i2c.h> #include <linux/delay.h> #define DEVICE_NAME "touchpanel" static struct i2c_device_id touchpanel_id_table[] = { {DEVICE_NAME, 0}, {} }; MODULE_DEVICE_TABLE(i2c, touchpanel_id_table); static int touchpanel_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct input_dev *input; int error = 0; input = input_allocate_device(); if (!input) { dev_err(&client->dev, "input_allocate_device failed\n"); error = -ENOMEM; goto err_free_mem; } input->name = "Touch Panel"; input->id.bustype = BUS_I2C; input->dev.parent = &client->dev; input_set_capability(input, EV_KEY, BTN_TOUCH); error = input_register_device(input); if (error) { dev_err(&client->dev, "input_register_device failed\n"); goto err_free_mem; } return 0; err_free_mem: input_free_device(input); return error; } static int touchpanel_remove(struct i2c_client *client) { struct input_dev *input = i2c_get_clientdata(client); input_unregister_device(input); input_free_device(input); return 0; } static const struct of_device_id touchpanel_of_match[] = { { .compatible = "linux,touchpanel", }, {} }; MODULE_DEVICE_TABLE(of, touchpanel_of_match); static struct i2c_driver touchpanel_driver = { .probe = touchpanel_probe, .remove = touchpanel_remove, .id_table = touchpanel_id_table, .driver = { .name = DEVICE_NAME, .of_match_table = touchpanel_of_match, }, }; module_i2c_driver(touchpanel_driver); MODULE_AUTHOR("Your Name"); MODULE_DESCRIPTION("Touch Panel Driver"); MODULE_LICENSE("GPL"); ``` 这个驱动程序使用I2C总线与触摸屏进行通信,并向输入子系统注册输入设备。在`probe`函数中,它分配了一个新的输入设备并配置其名称、总线类型和父设备。它还设置了该设备支持BTN_TOUCH事件。在`remove`函数中,它注销了输入设备并释放了分配的内存。这个驱动程序还包含了一些必要的Linux模块元数据,如作者、描述和许可证信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值