From 4b93d45e50cea716e26110444c14deb3ca67b50d Mon Sep 17 00:00:00 2001 From: "tin_bingtai.zou_tmp" Date: Fri, 24 Mar 2023 17:37:25 +0800 Subject: [PATCH] sar sensor bring up 1/2 1.sar sensor bring up 2.modify sx937x driver for secondary sar Change-Id: I3eef88077a14e7e1dab92c860406d0b1ee35a02c Signed-off-by: tin_bingtai.zou_tmp Reviewed-on: https://gerrit.mot.com/2552802 SME-Granted: SME Approvals Granted SLTApproved: Slta Waiver Tested-by: Jira Key Reviewed-by: Reviewed-by: Yuchang Guo Reviewed-by: Xiangpo Zhao Submit-Approved: Jira Key --- drivers/misc/sx937x/sx937x_sar.c | 140 ++++++++++++++++++------------- include/linux/input/sx937x.h | 2 +- 2 files changed, 83 insertions(+), 59 deletions(-) diff --git a/drivers/misc/sx937x/sx937x_sar.c b/drivers/misc/sx937x/sx937x_sar.c index 1ce2acaf7fc4..744928fa2238 100644 --- a/drivers/misc/sx937x/sx937x_sar.c +++ b/drivers/misc/sx937x/sx937x_sar.c @@ -210,14 +210,13 @@ static int sx937x_Hardware_Check(psx93XX_t this) this->failStatusCode = SX937x_I2C_ERROR; } - if(idCode!= SX937X_WHOAMI_VALUE) + if(idCode >> 12 != SX937X_WHOAMI_VALUE >> 4) { this->failStatusCode = SX937x_ID_ERROR; } LOG_INFO("sx937x idcode = 0x%x, failcode = 0x%x\n", idCode, this->failStatusCode); - //return (int)this->failStatusCode; - return 0; + return (int)this->failStatusCode; } static int sx937x_global_variable_init(psx93XX_t this) @@ -638,13 +637,14 @@ static void sx937x_reg_init(psx93XX_t this) psx937x_t pDevice = 0; psx937x_platform_data_t pdata = 0; int i = 0; - uint32_t tmpvalue; + //uint32_t tmpvalue; /* configure device */ if (this && (pDevice = this->pDevice) && (pdata = pDevice->hw)) { /*******************************************************************************/ // try to initialize from device tree! /*******************************************************************************/ + #if 0 while ( i < ARRAY_SIZE(sx937x_i2c_reg_setup)) { /* Write all registers/values contained in i2c_reg */ @@ -661,6 +661,7 @@ static void sx937x_reg_init(psx93XX_t this) sx937x_i2c_write_16bit(this, sx937x_i2c_reg_setup[i].reg, tmpvalue); i++; } + #endif #ifdef USE_DTS_REG if (this->reg_in_dts == true) { @@ -1357,6 +1358,19 @@ static int sx937x_probe(struct i2c_client *client, const struct i2c_device_id *i this = devm_kzalloc(&client->dev,sizeof(sx93XX_t), GFP_KERNEL); /* create memory for main struct */ LOG_DBG("Initialized Main Memory: 0x%p\n",this); + if (!this){ + LOG_ERR("Failed to create this \n"); + return -ENOMEM; + } + + /* setup i2c communication */ + this->bus = client; + i2c_set_clientdata(client, this); + + /* record device struct */ + this->pdev = &client->dev; + + pButtonInformationData = devm_kzalloc(&client->dev , sizeof(struct totalButtonInformation), GFP_KERNEL); if (!pButtonInformationData) @@ -1388,6 +1402,57 @@ static int sx937x_probe(struct i2c_client *client, const struct i2c_device_id *i pplatData->init_platform_hw = sx937x_init_platform_hw; LOG_INFO("SX937x init_platform_hw done!\n"); + switch(pplatData->power_supply_type){ + case SX937X_POWER_SUPPLY_TYPE_PMIC_LDO: + pplatData->cap_vdd = regulator_get(&client->dev, "cap_vdd"); + if (IS_ERR(pplatData->cap_vdd)) { + if (PTR_ERR(pplatData->cap_vdd) == -EPROBE_DEFER) { + err = PTR_ERR(pplatData->cap_vdd); + return err; + } + LOG_INFO("Failed to get regulator\n"); + } else { + LOG_INFO("with cap_vdd\n"); + err = regulator_enable(pplatData->cap_vdd); + if (err) { + regulator_put(pplatData->cap_vdd); + LOG_ERR("Error %d enable regulator\n", + err); + return err; + } + pplatData->cap_vdd_en = true; + LOG_INFO("cap_vdd regulator is %s\n", + regulator_is_enabled(pplatData->cap_vdd) ? + "on" : "off"); + msleep(10); + } + break; + case SX937X_POWER_SUPPLY_TYPE_ALWAYS_ON: + LOG_INFO("using always on power supply\n"); + break; + case SX937X_POWER_SUPPLY_TYPE_EXTERNAL_LDO: + LOG_INFO("enable external LDO, en_gpio:%d\n", + pplatData->eldo_gpio); + err = gpio_request(pplatData->eldo_gpio, "sx937x_eldo_gpio"); + if (err < 0){ + LOG_ERR("SX937x Request eLDO gpio. Fail![%d]\n", err); + return err; + } + err = gpio_direction_output(pplatData->eldo_gpio,1); + if(err < 0){ + LOG_ERR("can not enable external LDO,%d", err); + return err; + } + pplatData->eldo_vdd_en = true; + msleep(20); + break; + } + + if (sx937x_Hardware_Check(this) != 0) { + LOG_ERR("sx937x_Hardware_Check Fail!\n"); + goto FREE_PMIC; + } + if (this) { LOG_INFO("SX937x initialize start!!"); @@ -1417,12 +1482,7 @@ static int sx937x_probe(struct i2c_client *client, const struct i2c_device_id *i this->statusFunc[7] = 0; /* RESET_STAT */ } - /* setup i2c communication */ - this->bus = client; - i2c_set_clientdata(client, this); - /* record device struct */ - this->pdev = &client->dev; /* create memory for device specific struct */ this->pDevice = pDevice = devm_kzalloc(&client->dev,sizeof(sx937x_t), GFP_KERNEL); @@ -1491,50 +1551,7 @@ static int sx937x_probe(struct i2c_client *client, const struct i2c_device_id *i } } - switch(pplatData->power_supply_type){ - case SX937X_POWER_SUPPLY_TYPE_PMIC_LDO: - pplatData->cap_vdd = regulator_get(&client->dev, "cap_vdd"); - if (IS_ERR(pplatData->cap_vdd)) { - if (PTR_ERR(pplatData->cap_vdd) == -EPROBE_DEFER) { - err = PTR_ERR(pplatData->cap_vdd); - return err; - } - LOG_INFO("Failed to get regulator\n"); - } else { - LOG_INFO("with cap_vdd\n"); - err = regulator_enable(pplatData->cap_vdd); - if (err) { - regulator_put(pplatData->cap_vdd); - LOG_ERR("Error %d enable regulator\n", - err); - return err; - } - pplatData->cap_vdd_en = true; - LOG_INFO("cap_vdd regulator is %s\n", - regulator_is_enabled(pplatData->cap_vdd) ? - "on" : "off"); - } - break; - case SX937X_POWER_SUPPLY_TYPE_ALWAYS_ON: - LOG_INFO("using always on power supply\n"); - break; - case SX937X_POWER_SUPPLY_TYPE_EXTERNAL_LDO: - LOG_INFO("enable external LDO, en_gpio:%d\n", - pplatData->eldo_gpio); - err = gpio_request(pplatData->eldo_gpio, "sx937x_eldo_gpio"); - if (err < 0){ - LOG_ERR("SX937x Request eLDO gpio. Fail![%d]\n", err); - return err; - } - err = gpio_direction_output(pplatData->eldo_gpio,1); - if(err < 0){ - LOG_ERR("can not enable external LDO,%d", err); - return err; - } - pplatData->eldo_vdd_en = true; - msleep(20); - break; - } + #ifdef CONFIG_CAPSENSE_USB_CAL /*notify usb state*/ @@ -1591,11 +1608,6 @@ static int sx937x_probe(struct i2c_client *client, const struct i2c_device_id *i pplatData->exit_platform_hw = sx937x_exit_platform_hw; - if (sx937x_Hardware_Check(this) != 0) { - LOG_ERR("sx937x_Hardware_CheckFail!\n"); - //return -1; - } - global_sx937x = this; if(pplatData->reinit_on_i2c_failure) { @@ -1606,6 +1618,18 @@ static int sx937x_probe(struct i2c_client *client, const struct i2c_device_id *i LOG_INFO("sx937x_probe() Done\n"); return 0; + +FREE_PMIC: + LOG_ERR("sx937x FREE_PMIC\n"); + if (pplatData->cap_vdd_en) { + regulator_disable(pplatData->cap_vdd); + regulator_put(pplatData->cap_vdd); + } + + if(pplatData->eldo_vdd_en){ + gpio_direction_output(pplatData->eldo_gpio,0); + } + return -ENXIO; } /*! \fn static int sx937x_remove(struct i2c_client *client) diff --git a/include/linux/input/sx937x.h b/include/linux/input/sx937x.h index 6051507ae186..ca1126b63a5c 100644 --- a/include/linux/input/sx937x.h +++ b/include/linux/input/sx937x.h @@ -253,7 +253,7 @@ /* Chip ID */ -#define SX937X_WHOAMI_VALUE 0x9370 +#define SX937X_WHOAMI_VALUE 0x9375 /*command*/ #define SX937X_PHASE_CONTROL 0x0000000F #define SX937X_COMPENSATION_CONTROL 0x0000000E