Lines Matching +full:pmi8998 +full:- +full:gpio

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2016-2017, 2019, The Linux Foundation. All rights reserved.
7 * This driver is for the Round Robin ADC found in the pmi8998 and pm660 PMICs.
28 #include <soc/qcom/qcom-spmi-pmic.h>
30 #define DRIVER_NAME "qcom-spmi-rradc"
219 * struct rradc_channel - rradc channel data
263 dev_err(chip->dev, in rradc_read()
266 return -EINVAL; in rradc_read()
270 ret = regmap_bulk_read(chip->regmap, chip->base + addr, buf, in rradc_read()
273 dev_err(chip->dev, "rr_adc reg 0x%x failed :%d\n", addr, in rradc_read()
278 ret = regmap_bulk_read(chip->regmap, chip->base + addr, in rradc_read()
281 dev_err(chip->dev, "rr_adc reg 0x%x failed :%d\n", addr, in rradc_read()
288 dev_dbg(chip->dev, in rradc_read()
298 dev_err(chip->dev, "Retry exceeded for coherency check\n"); in rradc_read()
306 if (chip->pmic->subtype == PM660_SUBTYPE) { in rradc_get_fab_coeff()
307 switch (chip->pmic->fab_id) { in rradc_get_fab_coeff()
320 } else if (chip->pmic->subtype == PMI8998_SUBTYPE) { in rradc_get_fab_coeff()
321 switch (chip->pmic->fab_id) { in rradc_get_fab_coeff()
331 return -EINVAL; in rradc_get_fab_coeff()
335 return -EINVAL; in rradc_get_fab_coeff()
348 current_value = chip->batt_id_data; in rradc_post_process_batt_id()
361 ret = regmap_set_bits(chip->regmap, chip->base + RR_ADC_LOG, in rradc_enable_continuous_mode()
364 dev_err(chip->dev, "log ctrl update to clear failed:%d\n", ret); in rradc_enable_continuous_mode()
368 ret = regmap_clear_bits(chip->regmap, chip->base + RR_ADC_LOG, in rradc_enable_continuous_mode()
371 dev_err(chip->dev, "log ctrl update to not clear failed:%d\n", in rradc_enable_continuous_mode()
377 ret = regmap_set_bits(chip->regmap, chip->base + RR_ADC_CTL, in rradc_enable_continuous_mode()
380 dev_err(chip->dev, "Update to continuous mode failed:%d\n", in rradc_enable_continuous_mode()
391 ret = regmap_clear_bits(chip->regmap, chip->base + RR_ADC_CTL, in rradc_disable_continuous_mode()
394 dev_err(chip->dev, "Update to non-continuous mode failed:%d\n", in rradc_disable_continuous_mode()
417 ret = regmap_read(chip->regmap, chip->base + chan->status, &status); in rradc_is_ready()
431 if (chan->trigger_mask == 0) { in rradc_read_status_in_cont_mode()
432 dev_err(chip->dev, "Channel doesn't have a trigger mask\n"); in rradc_read_status_in_cont_mode()
433 return -EINVAL; in rradc_read_status_in_cont_mode()
436 ret = regmap_set_bits(chip->regmap, chip->base + chan->trigger_addr, in rradc_read_status_in_cont_mode()
437 chan->trigger_mask); in rradc_read_status_in_cont_mode()
439 dev_err(chip->dev, in rradc_read_status_in_cont_mode()
441 iio_chan->extend_name, ret); in rradc_read_status_in_cont_mode()
447 dev_err(chip->dev, "Failed to switch to continuous mode\n"); in rradc_read_status_in_cont_mode()
463 dev_err(chip->dev, "Channel '%s' is not ready\n", in rradc_read_status_in_cont_mode()
464 iio_chan->extend_name); in rradc_read_status_in_cont_mode()
465 ret = -ETIMEDOUT; in rradc_read_status_in_cont_mode()
471 regmap_clear_bits(chip->regmap, chip->base + chan->trigger_addr, in rradc_read_status_in_cont_mode()
472 chan->trigger_mask); in rradc_read_status_in_cont_mode()
483 ret = regmap_set_bits(chip->regmap, chip->base + RR_ADC_BATT_ID_CTRL, in rradc_prepare_batt_id_conversion()
486 dev_err(chip->dev, "Enabling BATT ID channel failed:%d\n", ret); in rradc_prepare_batt_id_conversion()
490 ret = regmap_set_bits(chip->regmap, in rradc_prepare_batt_id_conversion()
491 chip->base + RR_ADC_BATT_ID_TRIGGER, in rradc_prepare_batt_id_conversion()
494 dev_err(chip->dev, "BATT_ID trigger set failed:%d\n", ret); in rradc_prepare_batt_id_conversion()
501 regmap_clear_bits(chip->regmap, chip->base + RR_ADC_BATT_ID_TRIGGER, in rradc_prepare_batt_id_conversion()
505 regmap_clear_bits(chip->regmap, chip->base + RR_ADC_BATT_ID_CTRL, in rradc_prepare_batt_id_conversion()
519 mutex_lock(&chip->conversion_lock); in rradc_do_conversion()
525 dev_err(chip->dev, "Battery ID conversion failed:%d\n", in rradc_do_conversion()
535 dev_err(chip->dev, in rradc_do_conversion()
547 dev_dbg(chip->dev, "channel '%s' is not ready\n", in rradc_do_conversion()
548 iio_chan->extend_name); in rradc_do_conversion()
549 ret = -ENODATA; in rradc_do_conversion()
555 ret = rradc_read(chip, chan->lsb, buf, chan->size); in rradc_do_conversion()
557 dev_err(chip->dev, "read data failed\n"); in rradc_do_conversion()
571 dev_err(chip->dev, in rradc_do_conversion()
573 ret = -EINVAL; in rradc_do_conversion()
579 chip->batt_id_data = 150; in rradc_do_conversion()
582 chip->batt_id_data = 15; in rradc_do_conversion()
585 chip->batt_id_data = 5; in rradc_do_conversion()
590 * We can rely on the second byte being 0 for 1-byte channels. in rradc_do_conversion()
596 mutex_unlock(&chip->conversion_lock); in rradc_do_conversion()
609 dev_err(chip->dev, "Unable to get fab id coefficients\n"); in rradc_read_scale()
610 return -EINVAL; in rradc_read_scale()
641 *val = -RR_ADC_TEMP_FS_VOLTAGE_NUM; in rradc_read_scale()
654 return -EINVAL; in rradc_read_scale()
677 dev_err(chip->dev, in rradc_read_offset()
679 return -EINVAL; in rradc_read_offset()
681 offset1 = -(fab_offset * RR_ADC_TEMP_FS_VOLTAGE_DEN * in rradc_read_offset()
695 * The -1 is to compensate for lost precision. in rradc_read_offset()
696 * It should actually be -0.7906976744186046. in rradc_read_offset()
700 *val = (int)(offset1 - offset2 - 1); in rradc_read_offset()
703 offset1 = -RR_ADC_DIE_TEMP_OFFSET * in rradc_read_offset()
708 offset2 = -(int64_t)RR_ADC_CHG_TEMP_OFFSET_MILLI_DEGC * in rradc_read_offset()
715 * The result is -339, it should be -338.69789, this results in rradc_read_offset()
717 * -0.004 - -0.0175 degrees C in rradc_read_offset()
719 *val = (int)(offset1 - offset2); in rradc_read_offset()
724 return -EINVAL; in rradc_read_offset()
736 if (chan_spec->address >= RR_ADC_CHAN_MAX) { in rradc_read_raw()
737 dev_err(chip->dev, "Invalid channel index:%lu\n", in rradc_read_raw()
738 chan_spec->address); in rradc_read_raw()
739 return -EINVAL; in rradc_read_raw()
744 return rradc_read_scale(chip, chan_spec->address, val, val2); in rradc_read_raw()
746 return rradc_read_offset(chip, chan_spec->address, val); in rradc_read_raw()
748 ret = rradc_do_conversion(chip, chan_spec->address, &adc_code); in rradc_read_raw()
755 chan = &rradc_chans[chan_spec->address]; in rradc_read_raw()
756 if (!chan->scale_fn) in rradc_read_raw()
757 return -EINVAL; in rradc_read_raw()
758 ret = rradc_do_conversion(chip, chan_spec->address, &adc_code); in rradc_read_raw()
762 *val = chan->scale_fn(chip, adc_code, val); in rradc_read_raw()
765 return -EINVAL; in rradc_read_raw()
773 rradc_chans[chan->address].label); in rradc_read_label()
841 .label = "gpio",
926 struct device *dev = &pdev->dev; in rradc_probe()
933 return -ENOMEM; in rradc_probe()
936 chip->regmap = dev_get_regmap(pdev->dev.parent, NULL); in rradc_probe()
937 if (!chip->regmap) { in rradc_probe()
939 return -EINVAL; in rradc_probe()
942 chip->dev = dev; in rradc_probe()
943 mutex_init(&chip->conversion_lock); in rradc_probe()
945 ret = device_property_read_u32(dev, "reg", &chip->base); in rradc_probe()
947 dev_err(chip->dev, "Couldn't find reg address, ret = %d\n", in rradc_probe()
952 batt_id_delay = -1; in rradc_probe()
953 ret = device_property_read_u32(dev, "qcom,batt-id-delay-ms", in rradc_probe()
961 batt_id_delay = -1; in rradc_probe()
966 ret = regmap_set_bits(chip->regmap, in rradc_probe()
967 chip->base + RR_ADC_BATT_ID_CFG, in rradc_probe()
970 dev_err(chip->dev, in rradc_probe()
977 chip->pmic = qcom_pmic_get(chip->dev); in rradc_probe()
978 if (IS_ERR(chip->pmic)) { in rradc_probe()
979 dev_err(chip->dev, "Unable to get reference to PMIC device\n"); in rradc_probe()
980 return PTR_ERR(chip->pmic); in rradc_probe()
983 switch (chip->pmic->subtype) { in rradc_probe()
985 indio_dev->name = "pmi8998-rradc"; in rradc_probe()
988 indio_dev->name = "pm660-rradc"; in rradc_probe()
991 indio_dev->name = DRIVER_NAME; in rradc_probe()
994 indio_dev->modes = INDIO_DIRECT_MODE; in rradc_probe()
995 indio_dev->info = &rradc_info; in rradc_probe()
996 indio_dev->channels = rradc_iio_chans; in rradc_probe()
997 indio_dev->num_channels = ARRAY_SIZE(rradc_iio_chans); in rradc_probe()
1003 { .compatible = "qcom,pm660-rradc" },
1004 { .compatible = "qcom,pmi8998-rradc" },