天天看點

全志R16觸摸屏移植

一、全志的子產品自動加載功能

在核心目錄下的/driver/input下,有源碼sw-device.c檔案,此為自動加載子產品的源碼;

先看一個結構體:`

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

這個結構體定義了所有需要自動檢測的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[] = {  };   //only write a data address.

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

        return ret== ? true : false;
} 

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

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

    ret=i2c_transfer(client->adapter, &msg,);
    return ret;
}
源碼中向i2c總線上循環發送結構體sw_device_info ctps[]中的i2c位址,如果有裝置回複,則結束循環,儲存此裝置的driver的name,然後通過name加載name.ko檔案。
           

注意并不是sw_device_info ctps[]結構體中的每一個裝置都回去檢測,sys_config.fex配置檔案中有ctp_list配置表目 如下圖:

全志R16觸摸屏移植

如要使用自動加載ctp_dct_used設為1,下面的ctp name的順序必須和sw_device_info ctps[]結構體一樣,要需要自動檢測某個裝置時,在後面設為1,不需要檢測這個裝置直接設為0;

這樣做的好處是:可以再核心中編譯多個ctp的driver子產品,然後通過向i2c總線發送位址的方法,來判斷連接配接的是哪個觸摸屏,進而加載不同的驅動,提高了使用的便利性;