全志R16触摸屏移植

一、全志的模块自动加载功能
在内核目录下的/driver/input下,有源码sw-device.c文件,此为自动加载模块的源码;
先看一个结构体:`

static struct sw_device_info ctps[] = {
        {"egalax_i2c",{     0x2a},   0x00, {0x00                    },1},
        { "ft5x_ts", {      0x38},   0xa3, {0x11,0x03,0xa3,0x55,0x06,0x08,0x02,0x0a}, 0},
        {   "gt82x", {      0x5d},  0xf7d, {0x13,0x27,0x28          }, 0},
        { "gslX680", {      0x40},   0x00, {0x00                    }, 1},
        {"gslX680new", {    0x40},   0x00, {0x00                    }, 1},
        {"gt9xx_ts", {0x14, 0x5d}, 0x8140, {0x39                    }, 0},
        {"gt9xxf_ts",{ 0x14,0x5d},   0x00, {0x00                    }, 1},
        {   "tu_ts", {      0x5f},   0x00, {0x00                    }, 1},
        {"gt818_ts", {      0x5d},  0x715, {0xc3                    }, 0},
        { "zet622x", {      0x76},   0x00, {0x00                    }, 0},
        {"aw5306_ts", {     0x38},   0x01, {0xA8                    }, 0},
        {"icn83xx_ts",{     0x40},   0x00, {0x00                    }, 1},
};

这个结构体定义了所有需要自动检测的ctp的信息,第一列是driver的name,第二列是设备的i2c地址,第三列是chip的寄存器地址,第四列是chip的值,第五列是是否检测设备的chip_value(0不检测,1检测);
其函数的调用过程如下:(以自动检测ctp为例)

sw_devices_events->sw_register_device_detect->sw_device_detect_start 这个函数再一次调用sw_sysconfig_get_para、get_device_name_info、sw_i2c_test、sw_set_write_info下面重点看函数sw_i2c_test
sw_i2c_test->sw_device_response_test这个函数主要调用i2c_test,i2c_test->i2c_write_bytes来和设备进行通讯,看i2c_test源码:
static bool i2c_test(struct i2c_client * client)
{
        int ret,retry;
        uint8_t test_data[1] = { 0 };   //only write a data address.

        for(retry=0; retry < 5; retry++)
        {
                ret = i2c_write_bytes(client, test_data, 1);    //Test i2c.
            if (ret == 1)
                    break;
            msleep(10);
        }

        return ret==1 ? true : false;
} 

static int i2c_write_bytes(struct i2c_client *client, uint8_t *data, uint16_t len)
{
    struct i2c_msg msg;
    int ret=-1;

    msg.flags = !I2C_M_RD;
    msg.addr = client->addr;
    msg.len = len;
    msg.buf = data;     

    ret=i2c_transfer(client->adapter, &msg,1);
    return ret;
}
源码中向i2c总线上循环发送结构体sw_device_info ctps[]中的i2c地址,如果有设备回复,则结束循环,保存此设备的driver的name,然后通过name加载name.ko文件。

注意并不是sw_device_info ctps[]结构体中的每一个设备都回去检测,sys_config.fex配置文件中有ctp_list配置表目 如下图:
这里写图片描述
如要使用自动加载ctp_dct_used设为1,下面的ctp name的顺序必须和sw_device_info ctps[]结构体一样,要需要自动检测某个设备时,在后面设为1,不需要检测这个设备直接设为0;

这样做的好处是:可以再内核中编译多个ctp的driver模块,然后通过向i2c总线发送地址的方法,来判断连接的是哪个触摸屏,从而加载不同的驱动,提高了使用的便利性;

猜你喜欢

转载自blog.csdn.net/chihunqi5879/article/details/79969416