diff --git a/drivers/misc/aw9610x/aw9610x_sar.c b/drivers/misc/aw9610x/aw9610x_sar.c index 90b3d0d719b2..308d2d66d1f1 100644 --- a/drivers/misc/aw9610x/aw9610x_sar.c +++ b/drivers/misc/aw9610x/aw9610x_sar.c @@ -1395,7 +1395,7 @@ static int capsensor_set_enable(struct sensors_classdev *sensors_cdev, unsigned for (i = 0; i < aw9610x->aw_channel_number; i++) { - if (aw9610x->aw_ref_channel == i) continue; + if ((aw9610x->aw_ref_channel >> i) & 0x1) continue; if (!strcmp(sensors_cdev->name, aw9610x->aw_ch_name[aw9610x->sar_num * AW_CHANNEL_MAX + i])) { if (enable == 1){ input_report_abs(aw9610x->aw_pad[i].input, ABS_DISTANCE, 0); @@ -1979,14 +1979,37 @@ aw9610x_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) aw9610x_i2c_set(i2c, aw9610x); + aw9610x->pwr_by_gpio = of_property_read_bool(np, "sar-gpio-vcc-enable"); + if (aw9610x->pwr_by_gpio) + { + aw9610x->vcc_3v0_Pin = of_get_named_gpio(np, "sar-gpio_3v0_en", 0); + if (!gpio_is_valid(aw9610x->vcc_3v0_Pin)) + { + LOG_ERR("vcc_3v0_Pin gpio is invalid."); + return -ENODEV; + } + ret = gpio_request(aw9610x->vcc_3v0_Pin, "vcc_3v0_Pin"); + if (ret < 0) + { + LOG_ERR("vcc_3v0_Pin Request gpio fail ret = %d", ret); + return ret; + } + ret = gpio_direction_output(aw9610x->vcc_3v0_Pin, 1); + if(ret < 0){ + LOG_ERR("vcc_3v0_Pin gpio direction set fail ret = %d", ret); + return ret; + } + LOG_ERR("vcc_3v0_Pin gpio num is %d", aw9610x->vcc_3v0_Pin); + }else{ #ifdef AW_POWER_ON - /* aw9610x power init */ - ret = aw9610x_power_init(aw9610x); - if (ret) - LOG_ERR("aw9610x power init failed"); - else - aw9610x_power_enable(aw9610x, true); + /* aw9610x power init */ + ret = aw9610x_power_init(aw9610x); + if (ret) + LOG_ERR("aw9610x power init failed"); + else + aw9610x_power_enable(aw9610x, true); #endif + } /* aw9610x chip id */ ret = aw9610x_read_chipid(aw9610x); @@ -2086,7 +2109,7 @@ aw9610x_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) #ifdef USE_SENSORS_CLASS for (i = 0; i < aw9610x->aw_channel_number; i++){ - if (aw9610x->aw_ref_channel == i) continue; + if ((aw9610x->aw_ref_channel >> i) & 0x1) continue; sensors_capsensor_chs[i].sensors_enable = capsensor_set_enable; sensors_capsensor_chs[i].sensors_poll_delay = NULL; sensors_capsensor_chs[i].name = aw9610x->aw_ch_name[aw9610x->sar_num * AW_CHANNEL_MAX + i]; @@ -2145,9 +2168,13 @@ err_first_irq: err_pase_dt: err_vers_load: err_chipid: - if (aw9610x->power_enable) { - regulator_disable(aw9610x->vcc); - regulator_put(aw9610x->vcc); + if (aw9610x->pwr_by_gpio){ + gpio_free(aw9610x->vcc_3v0_Pin); + }else{ + if (aw9610x->power_enable) { + regulator_disable(aw9610x->vcc); + regulator_put(aw9610x->vcc); + } } err_malloc: return ret; @@ -2159,14 +2186,19 @@ static int32_t aw9610x_i2c_remove(struct i2c_client *i2c) uint32_t i = 0; uint32_t j = aw9610x->sar_num; - if (aw9610x->power_enable) { - regulator_disable(aw9610x->vcc); - regulator_put(aw9610x->vcc); + if (aw9610x->pwr_by_gpio){ + gpio_free(aw9610x->vcc_3v0_Pin); + }else{ + if (aw9610x->power_enable) { + regulator_disable(aw9610x->vcc); + regulator_put(aw9610x->vcc); + } } + #ifdef USE_SENSORS_CLASS for (i = 0; i < aw9610x->aw_channel_number; i++) { - if (aw9610x->aw_ref_channel == i) continue; + if ((aw9610x->aw_ref_channel >> i) & 0x1) continue; sensors_classdev_unregister(&sensors_capsensor_chs[i]); } #endif diff --git a/include/linux/input/aw9610x.h b/include/linux/input/aw9610x.h index 316f1dbb5c39..3afac62f1c5f 100644 --- a/include/linux/input/aw9610x.h +++ b/include/linux/input/aw9610x.h @@ -195,6 +195,8 @@ struct aw9610x { uint32_t aw_ref_channel; const char *aw_ch_name[12]; + int32_t vcc_3v0_Pin; + int32_t pwr_by_gpio; uint32_t sar_num; int32_t irq_gpio; int32_t to_irq;