通常touch都是根据panel的型号来确定config文件的,Gt系列也一样,首先在
static int goodix_ts_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
......
ret = gtp_init_panel(ts);
......
}
看看这个
static s32 gtp_init_panel(struct goodix_ts_data *ts)
{
s32 ret = -1;
#if GTP_DRIVER_SEND_CFG
s32 i = 0;
u8 check_sum = 0;
u8 opr_buf[16] = {0};
u8 sensor_id = 0;
u8 drv_cfg_version;
u8 flash_cfg_version;
/* if defined CONFIG_OF, parse config data from dtsi
* else parse config data form header file.
*/
#ifndef GTP_CONFIG_OF
u8 cfg_info_group0[] = CTP_CFG_GROUP0; //在这里把h文件里的config都装进buf里
u8 cfg_info_group1[] = CTP_CFG_GROUP1;
u8 cfg_info_group2[] = CTP_CFG_GROUP2;
u8 cfg_info_group3[] = CTP_CFG_GROUP3;
u8 cfg_info_group4[] = CTP_CFG_GROUP4;
u8 cfg_info_group5[] = CTP_CFG_GROUP5;
u8 *send_cfg_buf[] = {cfg_info_group0,cfg_info_group1, //在这里把h文件里的config都装进buf里
cfg_info_group2, cfg_info_group3,
cfg_info_group4, cfg_info_group5};
u8 cfg_info_len[] = { CFG_GROUP_LEN(cfg_info_group0),
CFG_GROUP_LEN(cfg_info_group1),
CFG_GROUP_LEN(cfg_info_group2),
CFG_GROUP_LEN(cfg_info_group3),
CFG_GROUP_LEN(cfg_info_group4),
CFG_GROUP_LEN(cfg_info_group5)};
#endif
#if GTP_COMPATIBLE_MODE
if (CHIP_TYPE_GT9F == ts->chip_type) {
ts->fw_error = 0;
}
else
#endif
{ /* check firmware */
ret = gtp_i2c_read_dbl_check(ts->client, 0x41E4, opr_buf, 1); //检查fw
if (SUCCESS == ret)
{
if (opr_buf[0] != 0xBE)
{
ts->fw_error = 1;
GTP_ERROR("Firmware error, no config sent!");
return -1;
}
}
}
/* read sensor id */
#if GTP_COMPATIBLE_MODE
msleep(50);
#endif
ret = gtp_i2c_read_dbl_check(ts->client, GTP_REG_SENSOR_ID, &sensor_id, 1); //在这里读出sensor_id
if (SUCCESS == ret)
{
if (sensor_id >= 0x06)
{
GTP_ERROR("Invalid sensor_id(0x%02X), No Config Sent!", sensor_id);
ts->pnl_init_error = 1;
return -1;
}
}
else
{
GTP_ERROR("Failed to get sensor_id, No config sent!");
ts->pnl_init_error = 1;
return -1;
}
GTP_INFO("Sensor_ID: %d", sensor_id);
/* parse config data*/
#ifdef GTP_CONFIG_OF
GTP_DEBUG("Get config data from device tree.");
ret = gtp_parse_dt_cfg(&ts->client->dev, &config[GTP_ADDR_LENGTH], &ts->gtp_cfg_len, sensor_id); //看define是否存在,存在则从dtsi解析出config用
if (ret < 0) {
GTP_ERROR("Failed to parse config data form device tree.");
ts->pnl_init_error = 1;
return -1;
}
#else
GTP_DEBUG("Get config data from header file.");
if ((!cfg_info_len[1]) && (!cfg_info_len[2]) &&
(!cfg_info_len[3]) && (!cfg_info_len[4]) &&
(!cfg_info_len[5]))
{
sensor_id = 0;
}
ts->gtp_cfg_len = cfg_info_len[sensor_id];
memset(&config[GTP_ADDR_LENGTH], 0, GTP_CONFIG_MAX_LENGTH);
memcpy(&config[GTP_ADDR_LENGTH], send_cfg_buf[sensor_id], ts->gtp_cfg_len); //否则从之前的buf里抓出config
#endif
GTP_INFO("Config group%d used,length: %d", sensor_id, ts->gtp_cfg_len);
if (ts->gtp_cfg_len < GTP_CONFIG_MIN_LENGTH)
{
ts->pnl_init_error = 1;
return -1;
}
#if GTP_COMPATIBLE_MODE
if (ts->chip_type != CHIP_TYPE_GT9F)
#endif
{
ret = gtp_i2c_read_dbl_check(ts->client, GTP_REG_CONFIG_DATA, &opr_buf[0], 1);
if (ret == SUCCESS) {
GTP_DEBUG("Config Version: %d, 0x%02X; IC Config Version: %d, 0x%02X",
config[GTP_ADDR_LENGTH], config[GTP_ADDR_LENGTH], opr_buf[0], opr_buf[0]);
flash_cfg_version = opr_buf[0];
drv_cfg_version = config[GTP_ADDR_LENGTH];
if (flash_cfg_version < 90 && flash_cfg_version > drv_cfg_version) {
config[GTP_ADDR_LENGTH] = 0x00;
}
} else {
GTP_ERROR("Failed to get ic config version!No config sent!");
return -1;
}
}
#if GTP_CUSTOM_CFG
config[RESOLUTION_LOC] = (u8)GTP_MAX_WIDTH;
config[RESOLUTION_LOC + 1] = (u8)(GTP_MAX_WIDTH>>8);
config[RESOLUTION_LOC + 2] = (u8)GTP_MAX_HEIGHT;
config[RESOLUTION_LOC + 3] = (u8)(GTP_MAX_HEIGHT>>8);
if (GTP_INT_TRIGGER == 0) //RISING
{
config[TRIGGER_LOC] &= 0xfe;
}
else if (GTP_INT_TRIGGER == 1) //FALLING
{
config[TRIGGER_LOC] |= 0x01;
}
#endif // GTP_CUSTOM_CFG
check_sum = 0;
for (i = GTP_ADDR_LENGTH; i < ts->gtp_cfg_len; i++)
{
check_sum += config[i];
}
config[ts->gtp_cfg_len] = (~check_sum) + 1;
#else // driver not send config
ts->gtp_cfg_len = GTP_CONFIG_MAX_LENGTH;
ret = gtp_i2c_read(ts->client, config, ts->gtp_cfg_len + GTP_ADDR_LENGTH);
if (ret < 0)
{
GTP_ERROR("Read Config Failed, Using Default Resolution & INT Trigger!");
ts->abs_x_max = GTP_MAX_WIDTH;
ts->abs_y_max = GTP_MAX_HEIGHT;
ts->int_trigger_type = GTP_INT_TRIGGER;
}
#endif // GTP_DRIVER_SEND_CFG
if ((ts->abs_x_max == 0) && (ts->abs_y_max == 0))
{
ts->abs_x_max = (config[RESOLUTION_LOC + 1] << 8) + config[RESOLUTION_LOC];
ts->abs_y_max = (config[RESOLUTION_LOC + 3] << 8) + config[RESOLUTION_LOC + 2];
ts->int_trigger_type = (config[TRIGGER_LOC]) & 0x03;
}
#if GTP_COMPATIBLE_MODE
if (CHIP_TYPE_GT9F == ts->chip_type)
{
u8 sensor_num = 0;
u8 driver_num = 0;
u8 have_key = 0;
have_key = (config[GTP_REG_HAVE_KEY - GTP_REG_CONFIG_DATA + 2] & 0x01);
if (1 == ts->is_950)
{
driver_num = config[GTP_REG_MATRIX_DRVNUM - GTP_REG_CONFIG_DATA + 2];
sensor_num = config[GTP_REG_MATRIX_SENNUM - GTP_REG_CONFIG_DATA + 2];
if (have_key)
{
driver_num--;
}
ts->bak_ref_len = (driver_num * (sensor_num - 1) + 2) * 2 * 6;
}
else
{
driver_num = (config[CFG_LOC_DRVA_NUM] & 0x1F) + (config[CFG_LOC_DRVB_NUM]&0x1F);
if (have_key)
{
driver_num--;
}
sensor_num = (config[CFG_LOC_SENS_NUM] & 0x0F) + ((config[CFG_LOC_SENS_NUM] >> 4) & 0x0F);
ts->bak_ref_len = (driver_num * (sensor_num - 2) + 2) * 2;
}
return 0;
}
else
#endif
{
#if GTP_DRIVER_SEND_CFG
ret = gtp_send_cfg(ts->client); //把config写进touch sensor中
if (ret < 0)
{
GTP_ERROR("Send config error.");
}
#if GTP_COMPATIBLE_MODE
if (ts->chip_type != CHIP_TYPE_GT9F)
#endif
{
if (flash_cfg_version < 90 && flash_cfg_version > drv_cfg_version) {
check_sum = 0;
config[GTP_ADDR_LENGTH] = drv_cfg_version;
for (i = GTP_ADDR_LENGTH; i < ts->gtp_cfg_len; i++) {
check_sum += config[i];
}
config[ts->gtp_cfg_len] = (~check_sum) + 1;
}
}
#endif
}
msleep(10);
return 0;
}
唯一奇怪的就是找不到GTP_REG_SENSOR_ID这个地址之前是谁去写了