diff --git a/drivers/misc/sx937x_multi/sx937x_multi.c b/drivers/misc/sx937x_multi/sx937x_multi.c index 4c11542ceacb..f077cbe815bb 100644 --- a/drivers/misc/sx937x_multi/sx937x_multi.c +++ b/drivers/misc/sx937x_multi/sx937x_multi.c @@ -38,18 +38,16 @@ #define LOG_TAG "[sar SX937x]: " -#define LOG_INFO(fmt, args...) pr_info(LOG_TAG "[INFO]" "<%s><%d>"fmt, __func__, __LINE__, ##args) -#define LOG_DBG(fmt, args...) pr_debug(LOG_TAG "[DBG]" "<%s><%d>"fmt, __func__, __LINE__, ##args) -#define LOG_ERR(fmt, args...) pr_err(LOG_TAG "[ERR]" "<%s><%d>"fmt, __func__, __LINE__, ##args) +#define LOG_INFO(fmt, args...) pr_info(LOG_TAG "[INFO]" "<%s><%d>"fmt, __func__, __LINE__, ##args) +#define LOG_DBG(fmt, args...) pr_debug(LOG_TAG "[DBG]" "<%s><%d>"fmt, __func__, __LINE__, ##args) +#define LOG_ERR(fmt, args...) pr_err(LOG_TAG "[ERR]" "<%s><%d>"fmt, __func__, __LINE__, ##args) -#define SX937x_I2C_M_WR 0 /* for i2c Write */ -#define SX937x_I2C_M_RD 1 /* for i2c Read */ +#define SX937x_I2C_M_WR 0 /* for i2c Write */ +#define SX937x_I2C_M_RD 1 /* for i2c Read */ -#define IDLE 0 -#define PROXACTIVE 1 -#define BODYACTIVE 2 - -#define MAIN_SENSOR 1 //CS1 +#define IDLE 0 +#define PROXACTIVE 1 +#define BODYACTIVE 2 /* Failer Index */ #define SX937x_ID_ERROR 0x1 @@ -57,9 +55,6 @@ #define SX937x_CONN_ERROR 0x4 #define SX937x_I2C_ERROR 0x8 -#define SX937X_I2C_WATCHDOG_TIME 10000 -#define SX937X_I2C_WATCHDOG_TIME_ERR 2000 - #define MAX_CHANNEL_NUMBER 8 static struct class *capsense_class; @@ -483,34 +478,32 @@ static ssize_t capsense_reset_store(struct device *dev, if (!count) return -EINVAL; - LOG_INFO("%s sx937x_fac_cal_store\n", this->hw->dbg_name); if (!strncmp(buf, "cal", 3) ) { - + LOG_INFO("%s sx937x capsense_reset_store msg: cal\n", this->hw->dbg_name); if (temp & 0x000000FF) { - LOG_INFO("Going to refresh baseline %s\n",buf); + LOG_DBG("Going to refresh baseline %s\n",buf); manual_offset_calibration(this->hw); } } - if (!strncmp(buf, "flip_near", 9)){ + if (!strncmp(buf, "flip_near", 9)) { + LOG_INFO("%s sx937x capsense_reset_store msg: flip_near\n", this->hw->dbg_name); for (i = 0; i < this->hw->flip_reg_num; i++) { sx937x_i2c_write_16bit(this->bus, this->hw->flip_near_reg[i].reg,this->hw->flip_near_reg[i].val); - LOG_INFO("flip near download params set Reg 0x%x Value: 0x%x\n", + LOG_DBG("flip near download params set Reg 0x%x Value: 0x%x\n", this->hw->flip_near_reg[i].reg,this->hw->flip_near_reg[i].val); } - } - if (!strncmp(buf, "flip_far", 8)) - { + if (!strncmp(buf, "flip_far", 8)) { + LOG_INFO("%s sx937x capsense_reset_store msg: flip_far\n", this->hw->dbg_name); for (i = 0; i < this->hw->flip_reg_num; i++) { sx937x_i2c_write_16bit(this->bus, this->hw->flip_far_reg[i].reg,this->hw->flip_far_reg[i].val); - LOG_INFO("flip far download params set Reg 0x%x Value: 0x%x\n", + LOG_DBG("flip far download params set Reg 0x%x Value: 0x%x\n", this->hw->flip_far_reg[i].reg,this->hw->flip_far_reg[i].val); } - } return count; @@ -741,11 +734,11 @@ static DEVICE_ATTR(name, 0444, capsense_name_show, NULL); static DEVICE_ATTR(reset, 0220, NULL, capsense_reset_store); static DEVICE_ATTR(raw_data, 0444, capsense_raw_data_show, NULL); static DEVICE_ATTR(register_write, 0220, NULL, sx937x_register_write_store); -static DEVICE_ATTR(register_read, 0660, NULL, sx937x_register_read_store); +static DEVICE_ATTR(register_read, 0220, NULL, sx937x_register_read_store); static DEVICE_ATTR(fac_irq_state, 0444, sx937x_irq_state_show, NULL); static DEVICE_ATTR(fac_detect, 0444, sx937x_fac_detect_show, NULL); -static DEVICE_ATTR(fac_enable, 0444, NULL, sx937x_fac_enable_store); -static DEVICE_ATTR(fac_cal, 0444, NULL, sx937x_fac_cal_store); +static DEVICE_ATTR(fac_enable, 0220, NULL, sx937x_fac_enable_store); +static DEVICE_ATTR(fac_cal, 0220, NULL, sx937x_fac_cal_store); static DEVICE_ATTR(fac_compensation, 0444, sx937x_fac_comp_show, NULL); static DEVICE_ATTR(fac_raw, 0444, sx937x_fac_raw_show, NULL); @@ -826,21 +819,25 @@ static void sx937x_reg_init(psx93XX_t this) static int initialize(psx93XX_t this) { int ret, retry; + bool reset_ok = false; if (this) { - LOG_INFO("SX937x income initialize\n"); + LOG_INFO("SX937x initialize\n"); /* prepare reset by disabling any irq handling */ this->irq_disabled = 1; disable_irq(this->irq); /* perform a reset */ for ( retry = 10; retry > 0; retry-- ) { if (sx937x_i2c_write_16bit(this->bus, SX937X_DEVICE_RESET, 0xDE) >= 0){ - LOG_DBG("write ok"); + reset_ok = true; + LOG_INFO("write ok"); break; } - LOG_DBG("SX937x write SX937X_RESET_REG retry:%d\n", 11 - retry); + LOG_INFO("SX937x write SX937X_RESET_REG retry:%d\n", 11 - retry); msleep(10); } + if (reset_ok == false) + return -ENOMEM; /* wait until the reset has finished by monitoring NIRQ */ LOG_INFO("Sent Software Reset. Waiting until device is back from reset to continue.\n"); /* just sleep for awhile instead of using a loop with reading irq status */ @@ -995,7 +992,7 @@ static int sx937x_parse_dts(struct sx937x_platform_data *pdata, struct device *d LOG_INFO("used button 0x%x \n", pdata->button_used_flag); name_count = of_property_count_strings(dNode, "Semtech,button-names"); - LOG_INFO("name_count %d pdata->buttonSize==%d\n", name_count, pdata->buttonSize); + LOG_DBG("name_count %d pdata->buttonSize==%d\n", name_count, pdata->buttonSize); for (i = 0, name_index = 0; i < pdata->buttonSize & name_index < name_count; i++) { if (pdata->button_used_flag>>i & 0x01) { @@ -1027,14 +1024,14 @@ static int sx937x_parse_dts(struct sx937x_platform_data *pdata, struct device *d if (pdata->ref_phase_b == 0xff) pdata->ref_phase_b = -1; if (pdata->ref_phase_c == 0xff) pdata->ref_phase_c = -1; - LOG_INFO("[SX937x]: %s ref_phase_a= %d ref_phase_b= %d ref_phase_c= %d\n", - __func__, pdata->ref_phase_a, pdata->ref_phase_b, pdata->ref_phase_c); + LOG_INFO("ref_phase_a= %d ref_phase_b= %d ref_phase_c= %d\n", + pdata->ref_phase_a, pdata->ref_phase_b, pdata->ref_phase_c); // load in registers from device tree of_property_read_u32(dNode,"Semtech,reg-num",&pdata->i2c_reg_num); // layout is register, value, register, value.... // if an extra item is after just ignore it. reading the array in will cause it to fail anyway - LOG_INFO("size of elements %d \n", pdata->i2c_reg_num); + LOG_INFO("size of default elements %d \n", pdata->i2c_reg_num); if (pdata->i2c_reg_num > 0) { // initialize platform reg data array @@ -1052,7 +1049,7 @@ static int sx937x_parse_dts(struct sx937x_platform_data *pdata, struct device *d //load param when flip near of_property_read_u32(dNode,"Semtech,flip_operation_num",&pdata->flip_reg_num); - LOG_INFO("size of elements %d \n", pdata->flip_reg_num); + LOG_INFO("size of flip state elements %d \n", pdata->flip_reg_num); if(pdata->flip_reg_num >0) { pdata->flip_near_reg = devm_kzalloc(dev,sizeof(struct smtc_reg_data)*pdata->flip_reg_num, GFP_KERNEL); @@ -1072,8 +1069,6 @@ static int sx937x_parse_dts(struct sx937x_platform_data *pdata, struct device *d // initialize the array if (of_property_read_u32_array(dNode,"Semtech,flip_near_init",(u32*)&(pdata->flip_near_reg[0]),sizeof(struct smtc_reg_data)*pdata->flip_reg_num/sizeof(u32))) return -ENOMEM; - - } //extract register and value when flip far for(i = 0;iflip_reg_num;i++) @@ -1087,11 +1082,11 @@ static int sx937x_parse_dts(struct sx937x_platform_data *pdata, struct device *d } } - LOG_INFO("flip_far_reg params set Reg 0x%x Value: 0x%x\n", + LOG_DBG("flip_far_reg params set Reg 0x%x Value: 0x%x\n", pdata->flip_far_reg[i].reg,pdata->flip_far_reg[i].val); } - LOG_INFO("-[%d] parse_dt complete\n", pdata->irq_gpio); + LOG_DBG("-[%d] parse_dt complete\n", pdata->irq_gpio); return 0; } @@ -1300,7 +1295,7 @@ static int sx937x_probe(struct i2c_client *client, const struct i2c_device_id *i LOG_ERR("capsense_class dbg dev create fail\n"); return PTR_ERR(this->dbg_dev);; } - LOG_INFO("this->dbg_dev ok\n"); + for (i = 0; i < ARRAY_SIZE(capsense_class_attrs); ++i) { err = device_create_file(this->dbg_dev, capsense_class_attrs[i]); if (err) @@ -1362,7 +1357,9 @@ static int sx937x_probe(struct i2c_client *client, const struct i2c_device_id *i } LOG_INFO("Failed to get regulator\n"); } else { - LOG_INFO("with cap_vdd\n"); + LOG_INFO("cap_vdd init regulator is %s\n", + regulator_is_enabled(pplatData->cap_vdd) ? + "on" : "off"); err = regulator_enable(pplatData->cap_vdd); if (err) { regulator_put(pplatData->cap_vdd); @@ -1397,20 +1394,18 @@ static int sx937x_probe(struct i2c_client *client, const struct i2c_device_id *i break; } sx93XX_IRQ_init(this); - /* call init function pointer (this should initialize all registers */ - if (this->init) { - this->init(this); - } - else { - LOG_ERR("No init function!!!!\n"); - return -ENOMEM; - } } else { return -1; } pplatData->exit_platform_hw = sx937x_exit_platform_hw; + /* call init function pointer (this should initialize all registers */ + if (this->init) { + if (this->init(this) != 0) + goto Hardware_CheckFail; + } + if (sx937x_Hardware_Check(this) != 0) { LOG_ERR("sx937x_Hardware_CheckFail!\n"); if (this->failStatusCode & SX937x_I2C_ERROR) {