Skip to content

Commit

Permalink
i2c device: add twi id judge
Browse files Browse the repository at this point in the history
  • Loading branch information
yanggq authored and yanggq committed Nov 30, 2011
1 parent c700505 commit e37c7df
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 28 deletions.
19 changes: 15 additions & 4 deletions drivers/gsensor/bma250.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ static union{
unsigned short dirty_addr_buf[2];
const unsigned short normal_i2c[2];
}u_i2c_addr = {{0x00},};
static __u32 twi_id = 0;

#ifdef CONFIG_HAS_EARLYSUSPEND
static void bma250_early_suspend(struct early_suspend *h);
Expand Down Expand Up @@ -280,6 +281,12 @@ static int gsensor_fetch_sysconfig_para(void)
printk("%s: after: gsensor_twi_addr is 0x%x, dirty_addr_buf: 0x%hx. dirty_addr_buf[1]: 0x%hx \n", \
__func__, twi_addr, u_i2c_addr.dirty_addr_buf[0], u_i2c_addr.dirty_addr_buf[1]);

if(SCRIPT_PARSER_OK != script_parser_fetch("gsensor_para", "gsensor_twi_id", &twi_id, 1)){
pr_err("%s: script_parser_fetch err. \n", name);
goto script_parser_fetch_err;
}
printk("%s: twi_id is %d. \n", __func__, twi_id);

ret = 0;

}else{
Expand All @@ -305,11 +312,15 @@ int gsensor_detect(struct i2c_client *client, struct i2c_board_info *info)
{
struct i2c_adapter *adapter = client->adapter;

pr_info("%s: Detected chip %s at adapter %d, address 0x%02x\n",
__func__, SENSOR_NAME, i2c_adapter_id(adapter), client->addr);
if(twi_id == adapter->nr){
pr_info("%s: Detected chip %s at adapter %d, address 0x%02x\n",
__func__, SENSOR_NAME, i2c_adapter_id(adapter), client->addr);

strlcpy(info->type, SENSOR_NAME, I2C_NAME_SIZE);
return 0;
strlcpy(info->type, SENSOR_NAME, I2C_NAME_SIZE);
return 0;
}else{
return -ENODEV;
}
}

static int bma250_smbus_read_byte(struct i2c_client *client,
Expand Down
22 changes: 16 additions & 6 deletions drivers/gsensor/mxc622x.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static union{
unsigned short dirty_addr_buf[2];
const unsigned short normal_i2c[2];
}u_i2c_addr = {{0x00},};

static __u32 twi_id = 0;

/**
* gsensor_fetch_sysconfig_para - get config info from sysconfig.fex file.
Expand Down Expand Up @@ -108,6 +108,12 @@ static int gsensor_fetch_sysconfig_para(void)
printk("%s: after: gsensor_twi_addr is 0x%x, dirty_addr_buf: 0x%hx. dirty_addr_buf[1]: 0x%hx \n", \
__func__, twi_addr, u_i2c_addr.dirty_addr_buf[0], u_i2c_addr.dirty_addr_buf[1]);

if(SCRIPT_PARSER_OK != script_parser_fetch("gsensor_para", "gsensor_twi_id", &twi_id, 1)){
pr_err("%s: script_parser_fetch err. \n", name);
goto script_parser_fetch_err;
}
printk("%s: tkey_twi_id is %d. \n", __func__, twi_id);

ret = 0;

}else{
Expand All @@ -132,12 +138,16 @@ static int gsensor_fetch_sysconfig_para(void)
int gsensor_detect(struct i2c_client *client, struct i2c_board_info *info)
{
struct i2c_adapter *adapter = client->adapter;

if(twi_id == adapter->nr){
pr_info("%s: Detected chip %s at adapter %d, address 0x%02x\n",
__func__, SENSOR_NAME, i2c_adapter_id(adapter), client->addr);

pr_info("%s: Detected chip %s at adapter %d, address 0x%02x\n",
__func__, SENSOR_NAME, i2c_adapter_id(adapter), client->addr);

strlcpy(info->type, SENSOR_NAME, I2C_NAME_SIZE);
return 0;
strlcpy(info->type, SENSOR_NAME, I2C_NAME_SIZE);
return 0;
}else{
return -ENODEV;
}
}

#ifdef CONFIG_HAS_EARLYSUSPEND
Expand Down
21 changes: 16 additions & 5 deletions drivers/hwmon/mma7660.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ static union{
unsigned short dirty_addr_buf[2];
const unsigned short normal_i2c[2];
}u_i2c_addr = {{0x00},};
static __u32 twi_id = 0;

#ifdef CONFIG_HAS_EARLYSUSPEND
static int mma7660_early_suspend(struct early_suspend *h);
Expand Down Expand Up @@ -140,6 +141,12 @@ static int gsensor_fetch_sysconfig_para(void)
printk("%s: after: gsensor_twi_addr is 0x%x, dirty_addr_buf: 0x%hx. dirty_addr_buf[1]: 0x%hx \n", \
__func__, twi_addr, u_i2c_addr.dirty_addr_buf[0], u_i2c_addr.dirty_addr_buf[1]);

if(SCRIPT_PARSER_OK != script_parser_fetch("gsensor_para", "gsensor_twi_id", &twi_id, 1)){
pr_err("%s: script_parser_fetch err. \n", name);
goto script_parser_fetch_err;
}
printk("%s: twi_id is %d. \n", __func__, twi_id);

ret = 0;

}else{
Expand All @@ -164,12 +171,16 @@ static int gsensor_fetch_sysconfig_para(void)
int gsensor_detect(struct i2c_client *client, struct i2c_board_info *info)
{
struct i2c_adapter *adapter = client->adapter;

if(twi_id == adapter->nr){
pr_info("%s: Detected chip %s at adapter %d, address 0x%02x\n",
__func__, SENSOR_NAME, i2c_adapter_id(adapter), client->addr);

pr_info("%s: Detected chip %s at adapter %d, address 0x%02x\n",
__func__, SENSOR_NAME, i2c_adapter_id(adapter), client->addr);

strlcpy(info->type, SENSOR_NAME, I2C_NAME_SIZE);
return 0;
strlcpy(info->type, SENSOR_NAME, I2C_NAME_SIZE);
return 0;
}else{
return -ENODEV;
}
}

static void mma7660_read_xyz(int idx, s8 *pf)
Expand Down
21 changes: 17 additions & 4 deletions drivers/input/keyboard/hv2605.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ static union{
unsigned short dirty_addr_buf[2];
const unsigned short normal_i2c[2];
}u_i2c_addr = {{0x00},};
static __u32 twi_id = 0;

#ifdef CONFIG_HAS_EARLYSUSPEND
struct hv2605_keyboard_data {
Expand All @@ -102,6 +103,7 @@ static int tkey_fetch_sysconfig_para(void)
int ret = -1;
int device_used = -1;
__u32 twi_addr = 0;

char name[I2C_NAME_SIZE];
script_parser_value_type_t type = SCIRPT_PARSER_VALUE_TYPE_STRING;

Expand Down Expand Up @@ -132,6 +134,12 @@ static int tkey_fetch_sysconfig_para(void)
printk("%s: after: tkey_twi_addr is 0x%x, dirty_addr_buf: 0x%hx. dirty_addr_buf[1]: 0x%hx \n", \
__func__, twi_addr, u_i2c_addr.dirty_addr_buf[0], u_i2c_addr.dirty_addr_buf[1]);

if(SCRIPT_PARSER_OK != script_parser_fetch("tkey_para", "tkey_twi_id", &twi_id, 1)){
pr_err("%s: script_parser_fetch err. \n", name);
goto script_parser_fetch_err;
}
printk("%s: tkey_twi_id is %d. \n", __func__, twi_id);

}else{
pr_err("%s: tkey_unused. \n", __func__);
ret = -1;
Expand All @@ -155,11 +163,16 @@ int tkey_detect(struct i2c_client *client, struct i2c_board_info *info)
{
struct i2c_adapter *adapter = client->adapter;

pr_info("%s: Detected chip %s at adapter %d, address 0x%02x\n",
__func__, HV_NAME, i2c_adapter_id(adapter), client->addr);
if(twi_id == adapter->nr)
{
pr_info("%s: Detected chip %s at adapter %d, address 0x%02x\n",
__func__, HV_NAME, i2c_adapter_id(adapter), client->addr);

strlcpy(info->type, HV_NAME, I2C_NAME_SIZE);
return 0;
strlcpy(info->type, HV_NAME, I2C_NAME_SIZE);
return 0;
}else{
return -ENODEV;
}
}

#ifdef CONFIG_HAS_EARLYSUSPEND
Expand Down
16 changes: 11 additions & 5 deletions drivers/input/touchscreen/ft5x_ts.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ static union{
unsigned short dirty_addr_buf[2];
const unsigned short normal_i2c[2];
}u_i2c_addr = {{0x00},};
static __u32 twi_id = 0;

/*
* ctp_get_pendown_state : get the int_line data state,
Expand Down Expand Up @@ -351,7 +352,7 @@ static int ctp_fetch_sysconfig_para(void)
int ctp_used = -1;
char name[I2C_NAME_SIZE];
__u32 twi_addr = 0;
__u32 twi_id = 0;
//__u32 twi_id = 0;
script_parser_value_type_t type = SCIRPT_PARSER_VALUE_TYPE_STRING;

printk("%s. \n", __func__);
Expand Down Expand Up @@ -480,11 +481,16 @@ int ctp_detect(struct i2c_client *client, struct i2c_board_info *info)
{
struct i2c_adapter *adapter = client->adapter;

pr_info("%s: Detected chip %s at adapter %d, address 0x%02x\n",
__func__, CTP_NAME, i2c_adapter_id(adapter), client->addr);
if(twi_id == adapter->nr)
{
pr_info("%s: Detected chip %s at adapter %d, address 0x%02x\n",
__func__, CTP_NAME, i2c_adapter_id(adapter), client->addr);

strlcpy(info->type, CTP_NAME, I2C_NAME_SIZE);
return 0;
strlcpy(info->type, CTP_NAME, I2C_NAME_SIZE);
return 0;
}else{
return -ENODEV;
}
}
////////////////////////////////////////////////////////////////

Expand Down
13 changes: 9 additions & 4 deletions drivers/input/touchscreen/goodix_touch.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,11 +487,16 @@ int ctp_detect(struct i2c_client *client, struct i2c_board_info *info)
{
struct i2c_adapter *adapter = client->adapter;

pr_info("%s: Detected chip %s at adapter %d, address 0x%02x\n",
__func__, CTP_NAME, i2c_adapter_id(adapter), client->addr);
if(twi_id == adapter->nr)
{
pr_info("%s: Detected chip %s at adapter %d, address 0x%02x\n",
__func__, CTP_NAME, i2c_adapter_id(adapter), client->addr);

strlcpy(info->type, CTP_NAME, I2C_NAME_SIZE);
return 0;
strlcpy(info->type, CTP_NAME, I2C_NAME_SIZE);
return 0;
}else{
return -ENODEV;
}
}
////////////////////////////////////////////////////////////////

Expand Down

0 comments on commit e37c7df

Please sign in to comment.