Lines Matching +full:0 +full:- +full:1023
1 // SPDX-License-Identifier: GPL-2.0-or-later
12 #include <linux/hwmon-sysfs.h>
43 [DA9052_ADC_TSI_XN] = "ADC TS X-",
44 [DA9052_ADC_TSI_YN] = "ADC TS Y-",
46 [DA9052_ADC_VBBAT] = "BACK-UP BATTERY VOLTAGE",
52 return DIV_ROUND_CLOSEST(value * 2000, 1023) + 2500; in volt_reg_to_mv()
58 return DIV_ROUND_CLOSEST(value * 2500, 1023); in input_reg_to_mv()
64 return DIV_ROUND_CLOSEST(value * 5000, 1023); in vbbat_reg_to_mv()
69 return DIV_ROUND_CLOSEST(value * hwmon->tsiref_mv, 1023); in input_tsireg_to_mv()
82 DA9052_ADCCONT_AUTOVDDEN, 0); in da9052_disable_vddout_channel()
91 mutex_lock(&hwmon->hwmon_lock); in da9052_vddout_show()
93 ret = da9052_enable_vddout_channel(hwmon->da9052); in da9052_vddout_show()
94 if (ret < 0) in da9052_vddout_show()
97 vdd = da9052_reg_read(hwmon->da9052, DA9052_VDD_RES_REG); in da9052_vddout_show()
98 if (vdd < 0) { in da9052_vddout_show()
103 ret = da9052_disable_vddout_channel(hwmon->da9052); in da9052_vddout_show()
104 if (ret < 0) in da9052_vddout_show()
107 mutex_unlock(&hwmon->hwmon_lock); in da9052_vddout_show()
111 da9052_disable_vddout_channel(hwmon->da9052); in da9052_vddout_show()
113 mutex_unlock(&hwmon->hwmon_lock); in da9052_vddout_show()
123 ret = da9052_reg_read(hwmon->da9052, DA9052_ICHG_AV_REG); in da9052_ich_show()
124 if (ret < 0) in da9052_ich_show()
136 return sprintf(buf, "%d\n", da9052_adc_read_temp(hwmon->da9052)); in da9052_tbat_show()
145 ret = da9052_adc_manual_read(hwmon->da9052, DA9052_ADC_VBAT); in da9052_vbat_show()
146 if (ret < 0) in da9052_vbat_show()
157 int channel = to_sensor_dev_attr(devattr)->index; in da9052_misc_channel_show()
160 ret = da9052_adc_manual_read(hwmon->da9052, channel); in da9052_misc_channel_show()
161 if (ret < 0) in da9052_misc_channel_show()
186 return da9052_reg_write(hwmon->da9052, DA9052_TSI_CONT_B_REG, val); in da9052_request_tsi_read()
195 err = da9052_group_read(hwmon->da9052, DA9052_TSI_X_MSB_REG, in da9052_get_tsi_result()
203 msb = regs[0] << DA9052_TSILSB_TSIXL_BITS; in da9052_get_tsi_result()
214 return -EINVAL; in da9052_get_tsi_result()
226 reinit_completion(&hwmon->tsidone); in __da9052_read_tsi()
229 if (ret < 0) in __da9052_read_tsi()
233 if (!wait_for_completion_timeout(&hwmon->tsidone, in __da9052_read_tsi()
235 return -ETIMEDOUT; in __da9052_read_tsi()
244 int channel = to_sensor_dev_attr(devattr)->index; in da9052_tsi_show()
247 mutex_lock(&hwmon->da9052->auxadc_lock); in da9052_tsi_show()
249 mutex_unlock(&hwmon->da9052->auxadc_lock); in da9052_tsi_show()
251 if (ret < 0) in da9052_tsi_show()
264 tjunc = da9052_reg_read(hwmon->da9052, DA9052_TJUNC_RES_REG); in da9052_tjunc_show()
265 if (tjunc < 0) in da9052_tjunc_show()
268 toffset = da9052_reg_read(hwmon->da9052, DA9052_T_OFFSET_REG); in da9052_tjunc_show()
269 if (toffset < 0) in da9052_tjunc_show()
273 * Degrees celsius = 1.708 * (TJUNC_RES - T_OFFSET) - 108.8 in da9052_tjunc_show()
276 return sprintf(buf, "%d\n", 1708 * (tjunc - toffset) - 108800); in da9052_tjunc_show()
285 ret = da9052_adc_manual_read(hwmon->da9052, DA9052_ADC_VBBAT); in da9052_vbbat_show()
286 if (ret < 0) in da9052_vbbat_show()
296 input_names[to_sensor_dev_attr(devattr)->index]); in label_show()
308 if (!hwmon->tsi_as_adc) { in da9052_channel_is_visible()
309 switch (sattr->index) { in da9052_channel_is_visible()
314 return 0; in da9052_channel_is_visible()
318 return attr->mode; in da9052_channel_is_visible()
391 complete(&hwmon->tsidone); in da9052_tsi_datardy_irq()
397 struct device *dev = &pdev->dev; in da9052_hwmon_probe()
404 return -ENOMEM; in da9052_hwmon_probe()
408 mutex_init(&hwmon->hwmon_lock); in da9052_hwmon_probe()
409 hwmon->da9052 = dev_get_drvdata(pdev->dev.parent); in da9052_hwmon_probe()
411 init_completion(&hwmon->tsidone); in da9052_hwmon_probe()
413 hwmon->tsi_as_adc = in da9052_hwmon_probe()
414 device_property_read_bool(pdev->dev.parent, "dlg,tsi-as-adc"); in da9052_hwmon_probe()
416 if (hwmon->tsi_as_adc) { in da9052_hwmon_probe()
417 hwmon->tsiref = devm_regulator_get(pdev->dev.parent, "tsiref"); in da9052_hwmon_probe()
418 if (IS_ERR(hwmon->tsiref)) { in da9052_hwmon_probe()
419 err = PTR_ERR(hwmon->tsiref); in da9052_hwmon_probe()
420 dev_err(&pdev->dev, "failed to get tsiref: %d", err); in da9052_hwmon_probe()
424 err = regulator_enable(hwmon->tsiref); in da9052_hwmon_probe()
428 hwmon->tsiref_mv = regulator_get_voltage(hwmon->tsiref); in da9052_hwmon_probe()
429 if (hwmon->tsiref_mv < 0) { in da9052_hwmon_probe()
430 err = hwmon->tsiref_mv; in da9052_hwmon_probe()
435 hwmon->tsiref_mv /= 1000; in da9052_hwmon_probe()
438 if (hwmon->tsiref_mv < 1800 || hwmon->tsiref_mv > 2600) { in da9052_hwmon_probe()
439 dev_err(hwmon->da9052->dev, "invalid TSIREF voltage: %d", in da9052_hwmon_probe()
440 hwmon->tsiref_mv); in da9052_hwmon_probe()
441 err = -ENXIO; in da9052_hwmon_probe()
446 da9052_reg_write(hwmon->da9052, DA9052_TSI_CONT_A_REG, 0x00); in da9052_hwmon_probe()
449 da9052_reg_update(hwmon->da9052, DA9052_ADC_CONT_REG, in da9052_hwmon_probe()
453 err = da9052_request_irq(hwmon->da9052, DA9052_IRQ_TSIREADY, in da9052_hwmon_probe()
454 "tsiready-irq", da9052_tsi_datardy_irq, in da9052_hwmon_probe()
457 dev_err(&pdev->dev, "Failed to register TSIRDY IRQ: %d", in da9052_hwmon_probe()
470 return 0; in da9052_hwmon_probe()
473 if (hwmon->tsi_as_adc) in da9052_hwmon_probe()
474 da9052_free_irq(hwmon->da9052, DA9052_IRQ_TSIREADY, hwmon); in da9052_hwmon_probe()
476 if (hwmon->tsiref) in da9052_hwmon_probe()
477 regulator_disable(hwmon->tsiref); in da9052_hwmon_probe()
486 if (hwmon->tsi_as_adc) { in da9052_hwmon_remove()
487 da9052_free_irq(hwmon->da9052, DA9052_IRQ_TSIREADY, hwmon); in da9052_hwmon_remove()
488 regulator_disable(hwmon->tsiref); in da9052_hwmon_remove()
491 return 0; in da9052_hwmon_remove()
498 .name = "da9052-hwmon",
507 MODULE_ALIAS("platform:da9052-hwmon");