diff --git a/drivers/misc/sx937x/sx937x_sar.c b/drivers/misc/sx937x/sx937x_sar.c index 1884fba726c8..23ec940fab8a 100644 --- a/drivers/misc/sx937x/sx937x_sar.c +++ b/drivers/misc/sx937x/sx937x_sar.c @@ -550,6 +550,74 @@ static ssize_t sx937x_register_read_show(struct class *class, return sprintf(buf, "Register(0x%2x) data(0x%4x)\n", sx937x_temp_regist, sx937x_temp_val); } +static ssize_t reg_show(struct class *class, + struct class_attribute *attr, + char *buf) +{ + u32 *p = (u32*)buf; +#ifdef CONFIG_CAPSENSE_POWER_CONTROL_SUPPORT + psx937x_t pDevice = global_sx937x->pDevice; + psx937x_platform_data_t pdata = pDevice->hw; + + if (!pdata->cap_vdd_en) + if ( power_on_chip(global_sx937x) != 0) + return -1; +#endif + + psx93XX_t this = global_sx937x; + if(this->read_flag){ + this->read_flag = 0; + if (sx937x_i2c_read_16bit(this, this->read_reg, p) < 0) + return -1; + LOG_DBG("%s : read_reg = 0x%x, val = 0x%x\n",__func__,this->read_reg,*p); + return 4; + } + return -1; +} + +/* + reg attr is for TCMD on MTK only, + buf[6]-read_flag: + 0-real write, + 1-just transfer the reg value want to be readed +*/ +static ssize_t reg_store(struct class *class, + struct class_attribute *attr, + const char *buf, size_t count) +{ + psx93XX_t this = global_sx937x; + u16 regaddr = 0; + u32 val = 0; + int i = 0; + +#ifdef CONFIG_CAPSENSE_POWER_CONTROL_SUPPORT + psx937x_t pDevice = global_sx937x->pDevice; + psx937x_platform_data_t pdata = pDevice->hw; + + if (!pdata->cap_vdd_en) + if ( power_on_chip(global_sx937x) != 0) + return -1; +#endif + + if( count != 7){ + LOG_ERR("%s :params error[ count == %lu !=2]\n",__func__,count); + return -1; + } + for(i = 0 ; i < count ; i++) + LOG_DBG("%s : buf[%d] = 0x%x\n",__func__,i,buf[i]); + if(buf[6] == 0){ + regaddr = ((u16)buf[0]<<8) | (u16)buf[1]; + val= ((u32)buf[2]<<24) | ((u32)buf[3]<<16) | ((u32)buf[4]<<8) | ((u32)buf[5]); + if (sx937x_i2c_write_16bit(this, regaddr, val) < 0) + return -1; + } else if(buf[6] == 1) { + this->read_reg = ((u16)buf[0]<<8) | (u16)buf[1]; + this->read_flag = 1; + LOG_DBG("-----------\n"); + } + return count; +} + static ssize_t manual_offset_calibration_show(struct class *class, struct class_attribute *attr, char *buf) @@ -622,6 +690,8 @@ static struct class_attribute class_attr_int_state = __ATTR(int_state, 0440, sx937x_int_state_show, NULL); static struct class_attribute class_attr_reinitialize = __ATTR(reinitialize, 0660, NULL, sx937x_reinitialize_store); +static struct class_attribute class_attr_reg = + __ATTR(reg, 0660, reg_show, reg_store); static struct attribute *capsense_class_attrs[] = { &class_attr_reset.attr, @@ -634,6 +704,7 @@ static struct attribute *capsense_class_attrs[] = { &class_attr_manual_calibrate.attr, &class_attr_int_state.attr, &class_attr_reinitialize.attr, + &class_attr_reg.attr, NULL, }; ATTRIBUTE_GROUPS(capsense_class); @@ -646,6 +717,7 @@ static struct class_attribute capsense_class_attributes[] = { __ATTR(manual_calibrate, 0660, manual_offset_calibration_show,manual_offset_calibration_store), __ATTR(int_state, 0440, sx937x_int_state_show, NULL), __ATTR(reinitialize, 0660, NULL, sx937x_reinitialize_store), + __ATTR(reg, 0660, reg_show, reg_store), __ATTR_NULL, }; #endif diff --git a/include/linux/input/sx937x.h b/include/linux/input/sx937x.h index ca1126b63a5c..aecfe100b17c 100644 --- a/include/linux/input/sx937x.h +++ b/include/linux/input/sx937x.h @@ -522,6 +522,8 @@ struct sx93XX int irqTimeout; /* msecs only set if useIrqTimer is true */ + int read_flag; /* used for dump specified register*/ + u16 read_reg; /* record reg address which want to read*/ /* struct workqueue_struct *ts_workq; */ /* if want to use non default */ struct delayed_work dworker; /* work struct for worker function */ u8 phaseselect;