iio: adc: introduce Qualcomm SPMI Round Robin ADC
Subsystems (5)
v2 cover iio: adc: introduce Qualcomm SPMI Round Robin ADC
The RRADC is responsible for reading data about the current and voltage from the USB or DC in jacks, it can also read the battery ID (resistence) and some temperatures. It is found on the PMI8998 and PM660 Qualcomm PMICs.
The RRADC has to calibrate some ADC values based on which chip fab the PMIC was produced in, to facilitate this the patch ("mfd: qcom-spmi-pmic: expose the PMIC revid information to clients") exposes the PMIC revision information as a struct and registers it as driver data in the Qualcomm SPMI PMIC driver so that it can be read by the RRADC.
Changes since v1:
* Rework the RRADC driver based on Jonathan's feedback
* Pick up Rob's reviewed by for the dt-binding patch.
Caleb Connolly (7):
mfd: qcom-spmi-pmic: expose the PMIC revid information to clients
dt-bindings: iio: adc: document qcom-spmi-rradc
iio: adc: qcom-spmi-rradc: introduce round robin adc
arm64: dts: qcom: pmi8998: add rradc node
arm64: dts: qcom: sdm845-oneplus: enable rradc
arm64: dts: qcom: sdm845-db845c: enable rradc
arm64: dts: qcom: sdm845-xiaomi-beryllium: enable RRADC
.../bindings/iio/adc/qcom,spmi-rradc.yaml | 54 + arch/arm64/boot/dts/qcom/pmi8998.dtsi | 8 + arch/arm64/boot/dts/qcom/sdm845-db845c.dts | 4 + .../boot/dts/qcom/sdm845-oneplus-common.dtsi | 4 + .../boot/dts/qcom/sdm845-xiaomi-beryllium.dts | 4 + drivers/iio/adc/Kconfig | 13 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/qcom-spmi-rradc.c | 1070 +++++++++++++++++ drivers/mfd/qcom-spmi-pmic.c | 108 +- include/soc/qcom/qcom-pmic.h | 63 + 10 files changed, 1272 insertions(+), 57 deletions(-) create mode 100644 Documentation/devicetree/bindings/iio/adc/qcom,spmi-rradc.yaml create mode 100644 drivers/iio/adc/qcom-spmi-rradc.c create mode 100644 include/soc/qcom/qcom-pmic.h
Signature · 1 line
2.34.1
PATCH v2 1/7 mfd: qcom-spmi-pmic: expose the PMIC revid information to clients
Some PMIC functions such as the RRADC need to be aware of the PMIC chip revision information to implement errata or otherwise adjust behaviour, export the PMIC information to enable this.
This is specifically required to enable the RRADC to adjust coefficients based on which chip fab the PMIC was produced in, this can vary per unique device and therefore has to be read at runtime.
--- drivers/mfd/qcom-spmi-pmic.c | 108 +++++++++++++++++------------------ include/soc/qcom/qcom-pmic.h | 63 ++++++++++++++++++++ 2 files changed, 114 insertions(+), 57 deletions(-) create mode 100644 include/soc/qcom/qcom-pmic.h
drivers/mfd/qcom-spmi-pmic.c +51 -57
@@ -3,51 +3,24 @@* Copyright (c) 2014, The Linux Foundation. All rights reserved. */ +#include <linux/device.h> +#include <linux/gfp.h> #include <linux/kernel.h> #include <linux/module.h> +#include <linux/slab.h> #include <linux/spmi.h> #include <linux/regmap.h> #include <linux/of_platform.h> +#include <soc/qcom/qcom-pmic.h> #define PMIC_REV2 0x101#define PMIC_REV3 0x102#define PMIC_REV4 0x103#define PMIC_TYPE 0x104#define PMIC_SUBTYPE 0x105 - +#define PMIC_FAB_ID 0x1f2#define PMIC_TYPE_VALUE 0x51 -#define COMMON_SUBTYPE 0x00 -#define PM8941_SUBTYPE 0x01 -#define PM8841_SUBTYPE 0x02 -#define PM8019_SUBTYPE 0x03 -#define PM8226_SUBTYPE 0x04 -#define PM8110_SUBTYPE 0x05 -#define PMA8084_SUBTYPE 0x06 -#define PMI8962_SUBTYPE 0x07 -#define PMD9635_SUBTYPE 0x08 -#define PM8994_SUBTYPE 0x09 -#define PMI8994_SUBTYPE 0x0a -#define PM8916_SUBTYPE 0x0b -#define PM8004_SUBTYPE 0x0c -#define PM8909_SUBTYPE 0x0d -#define PM8028_SUBTYPE 0x0e -#define PM8901_SUBTYPE 0x0f -#define PM8950_SUBTYPE 0x10 -#define PMI8950_SUBTYPE 0x11 -#define PM8998_SUBTYPE 0x14 -#define PMI8998_SUBTYPE 0x15 -#define PM8005_SUBTYPE 0x18 -#define PM660L_SUBTYPE 0x1A -#define PM660_SUBTYPE 0x1B -#define PM8150_SUBTYPE 0x1E -#define PM8150L_SUBTYPE 0x1f -#define PM8150B_SUBTYPE 0x20 -#define PMK8002_SUBTYPE 0x21 -#define PM8009_SUBTYPE 0x24 -#define PM8150C_SUBTYPE 0x26 -#define SMB2351_SUBTYPE 0x29 -static const struct of_device_id pmic_spmi_id_table[] = { { .compatible ="qcom,pm660" , .data = (void *)PM660_SUBTYPE }, { .compatible ="qcom,pm660l" , .data = (void *)PM660L_SUBTYPE },
@@ -81,42 +54,47 @@ static const struct of_device_id pmic_spmi_id_table[] = { { } }; -static void pmic_spmi_show_revid (struct regmap *map,struct device *dev) +static int pmic_spmi_load_revid (struct regmap *map,struct device *dev, +struct qcom_spmi_pmic *pmic) { -unsigned int rev2, minor, major, type, subtype; -const char *name ="unknown" ;int ret, i; - ret =regmap_read (map,PMIC_TYPE , &type); + ret =regmap_read (map,PMIC_TYPE , &pmic->type);if (ret <0 ) -return ; +return ret; -if (type !=PMIC_TYPE_VALUE ) -return ; +if (pmic->type !=PMIC_TYPE_VALUE ) +return ret; - ret =regmap_read (map,PMIC_SUBTYPE , &subtype); + ret =regmap_read (map,PMIC_SUBTYPE , &pmic->subtype);if (ret <0 ) -return ; +return ret;for (i =0 ; i <ARRAY_SIZE (pmic_spmi_id_table); i++) { -if (subtype == (unsigned long )pmic_spmi_id_table[i].data) +if (pmic->subtype == (unsigned long )pmic_spmi_id_table[i].data)break ; }if (i !=ARRAY_SIZE (pmic_spmi_id_table)) - name = pmic_spmi_id_table[i].compatible; + pmic->name =devm_kstrdup_const (dev, pmic_spmi_id_table[i].compatible,GFP_KERNEL ); - ret =regmap_read (map,PMIC_REV2 , &rev2); + ret =regmap_read (map,PMIC_REV2 , &pmic->rev2);if (ret <0 ) -return ; +return ret; - ret =regmap_read (map,PMIC_REV3 , &minor); + ret =regmap_read (map,PMIC_REV3 , &pmic->minor);if (ret <0 ) -return ; +return ret; - ret =regmap_read (map,PMIC_REV4 , &major); + ret =regmap_read (map,PMIC_REV4 , &pmic->major);if (ret <0 ) -return ; +return ret; + +if (pmic->subtype ==PMI8998_SUBTYPE || pmic->subtype ==PM660_SUBTYPE ) { + ret =regmap_read (map,PMIC_FAB_ID , &pmic->fab_id); +if (ret <0 ) +return ret; + }/* * In early versions of PM8941 and PM8226, the major revision number
@@ -124,14 +102,14 @@ static void pmic_spmi_show_revid(struct regmap *map, struct device *dev)* Increment the major revision number here if the chip is an early * version of PM8941 or PM8226. */ -if ((subtype ==PM8941_SUBTYPE || subtype ==PM8226_SUBTYPE ) && - major <0x02 ) - major++; +if ((pmic->subtype ==PM8941_SUBTYPE || pmic->subtype ==PM8226_SUBTYPE ) && + pmic->major <0x02 ) + pmic->major++; -if (subtype ==PM8110_SUBTYPE ) - minor = rev2; +if (pmic->subtype ==PM8110_SUBTYPE ) + pmic->minor = pmic->rev2; -dev_dbg (dev,"%x: %s v%d.%d\n" , subtype, name, major, minor); +return 0 ; }static const struct regmap_config spmi_regmap_config = {
@@ -144,22 +122,38 @@ static const struct regmap_config spmi_regmap_config = {static int pmic_spmi_probe (struct spmi_device *sdev) {struct regmap *regmap; +struct qcom_spmi_pmic *pmic; regmap =devm_regmap_init_spmi_ext (sdev, &spmi_regmap_config);if (IS_ERR (regmap))return PTR_ERR (regmap); + pmic =devm_kzalloc (&sdev->dev,sizeof (*pmic),GFP_KERNEL ); +if (!pmic) +return -ENOMEM ; +/* Only the first slave id for a PMIC contains this information */ -if (sdev->usid %2 ==0 ) -pmic_spmi_show_revid (regmap, &sdev->dev); +if (sdev->usid %2 ==0 ) { +pmic_spmi_load_revid (regmap, &sdev->dev, pmic); +spmi_device_set_drvdata (sdev, pmic); +qcom_pmic_print_info (&sdev->dev, pmic); + }return devm_of_platform_populate (&sdev->dev); } +static void pmic_spmi_remove (struct spmi_device *sdev) +{ +struct qcom_spmi_pmic *pmic =spmi_device_get_drvdata (sdev); + +kfree (pmic->name); +} +MODULE_DEVICE_TABLE (of, pmic_spmi_id_table);static struct spmi_driver pmic_spmi_driver = { .probe = pmic_spmi_probe, + .remove = pmic_spmi_remove, .driver = { .name ="pmic-spmi" , .of_match_table = pmic_spmi_id_table,
include/soc/qcom/qcom-pmic.h new file +63 -0
63 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 2/7 dt-bindings: iio: adc: document qcom-spmi-rradc
In reply to Caleb ConnollyAdd dt-binding docs for the Qualcomm SPMI RRADC found in PMICs like PMI8998 and PMI8994
--- .../bindings/iio/adc/qcom,spmi-rradc.yaml | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/qcom,spmi-rradc.yaml
Documentation/devicetree/bindings/iio/adc/qcom,spmi-rradc.yaml new file +54 -0
@@ -0,0 +1,54 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/adc/qcom,spmi-rradc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Qualcomm's SPMI PMIC Round Robin ADC + +maintainers: + - Caleb Connolly <[email protected]> + +description: | + The Qualcomm SPMI Round Robin ADC (RRADC) provides interface to clients to read the + voltage, current and temperature for supported peripherals such as the battery thermistor + die temperature, charger temperature, USB and DC input voltage / current and battery ID + resistor. + +properties: + compatible: + enum: + - qcom,pmi8998-rradc + - qcom,pm660-rradc + + reg: + description: rradc base address and length in the SPMI PMIC register map + maxItems: 1 + + qcom,batt-id-delay-ms: + description: + Sets the hardware settling time for the battery ID resistor. + enum: [0, 1, 4, 12, 20, 40, 60, 80] + + "#io-channel-cells": + const: 1 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + pmic { + #address-cells = <1>; + #size-cells = <0>; + + pmic_rradc: adc@4500 { + compatible = "qcom,pmi8998-rradc"; + reg = <0x4500>; + #io-channel-cells = <1>; + }; + }; +...
Signature · 1 line
2.34.1
PATCH v2 3/7 iio: adc: qcom-spmi-rradc: introduce round robin adc
In reply to Caleb ConnollyThe Round Robin ADC is responsible for reading data about the rate of charge from the USB or DC in jacks, it can also read the battery ID (resistence) and some temperatures. It is found on the PMI8998 and PM660 Qualcomm PMICs.
--- drivers/iio/adc/Kconfig | 13 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/qcom-spmi-rradc.c | 1070 +++++++++++++++++++++++++++++ 3 files changed, 1084 insertions(+) create mode 100644 drivers/iio/adc/qcom-spmi-rradc.c
drivers/iio/adc/Kconfig +13 -0
@@ -812,6 +812,19 @@ config QCOM_PM8XXX_XOADC To compile this driver as a module, choose M here: the module will be called qcom-pm8xxx-xoadc. +config QCOM_SPMI_RRADC + tristate "Qualcomm SPMI RRADC" + depends on MFD_SPMI_PMIC + help + This is for the PMIC Round Robin ADC driver. + + This driver exposes the battery ID resistor, battery thermal, PMIC die + temperature, charger USB in and DC in voltage and current. + + To compile this driver as a module, choose M here: the module will + be called qcom-qpmi-rradc. + + config QCOM_SPMI_IADC tristate "Qualcomm SPMI PMIC current ADC" depends on SPMI
drivers/iio/adc/Makefile +1 -0
@@ -77,6 +77,7 @@ obj-$(CONFIG_NPCM_ADC) += npcm_adc.o obj-$(CONFIG_PALMAS_GPADC) += palmas_gpadc.o obj-$(CONFIG_QCOM_SPMI_ADC5) += qcom-spmi-adc5.o obj-$(CONFIG_QCOM_SPMI_IADC) += qcom-spmi-iadc.o +obj-$(CONFIG_QCOM_SPMI_RRADC) += qcom-spmi-rradc.o obj-$(CONFIG_QCOM_VADC_COMMON) += qcom-vadc-common.o obj-$(CONFIG_QCOM_SPMI_VADC) += qcom-spmi-vadc.o obj-$(CONFIG_QCOM_PM8XXX_XOADC) += qcom-pm8xxx-xoadc.o
drivers/iio/adc/qcom-spmi-rradc.c new file +1070 -0
1,070 lines not on this page · raw message
Signature · 1 line
2.34.1
kernel test robot
build botRe: [PATCH v2 3/7] iio: adc: qcom-spmi-rradc: introduce round robin adc
Thank you for the patch! Yet something to improve:
Hi Caleb,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on robh/for-next]
[also build test ERROR on jic23-iio/togreg lee-mfd/for-mfd-next v5.16-rc8 next-20220105] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Caleb-Connolly/iio-adc-introduce-Qualcomm-SPMI-Round-Robin-ADC/20220106-023716 base: https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next config: sh-allmodconfig (https://download.01.org/0day-ci/archive/20220106/202201060438.QiDzs9rA-lkp(a)intel.com/config) compiler: sh4-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/167368793a009e8c1ce75b0b8b0965a4574af527
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Caleb-Connolly/iio-adc-introduce-Qualcomm-SPMI-Round-Robin-ADC/20220106-023716 git checkout 167368793a009e8c1ce75b0b8b0965a4574af527
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=sh SHELL=/bin/bash drivers/iio/adc/
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
drivers/iio/adc/qcom-spmi-rradc.c: In function 'rradc_prepare_batt_id_conversion':
>> drivers/iio/adc/qcom-spmi-rradc.c:624:25: error: implicit declaration of function 'FIELD_PREP' [-Werror=implicit-function-declaration]
624 | FIELD_PREP(BATT_ID_SETTLE_MASK, chip->batt_id_delay);
| ^~~~~~~~~~cc1: some warnings being treated as errors
vim +/FIELD_PREP +624 drivers/iio/adc/qcom-spmi-rradc.c
607
608 static int rradc_prepare_batt_id_conversion(struct rradc_chip *chip,
609 enum rradc_channel_id chan_id,
610 u16 *data)
611 {
612 int ret, batt_id_delay;
613
614 ret = regmap_update_bits(chip->regmap, chip->base + RR_ADC_BATT_ID_CTRL,
615 RR_ADC_BATT_ID_CTRL_CHANNEL_CONV,
616 RR_ADC_BATT_ID_CTRL_CHANNEL_CONV);
617 if (ret < 0) {
618 dev_err(chip->dev, "Enabling BATT ID channel failed:%d\n", ret);
619 return ret;
620 }
621
622 if (chip->batt_id_delay != -EINVAL) {
623 batt_id_delay =
> 624 FIELD_PREP(BATT_ID_SETTLE_MASK, chip->batt_id_delay);
625 ret = regmap_update_bits(chip->regmap,
626 chip->base + RR_ADC_BATT_ID_CFG,
627 batt_id_delay, batt_id_delay);
628 if (ret < 0) {
629 dev_err(chip->dev,
630 "BATT_ID settling time config failed:%d\n",
631 ret);
632 goto out_disable_batt_id;
633 }
634 }
635
636 ret = regmap_update_bits(chip->regmap,
637 chip->base + RR_ADC_BATT_ID_TRIGGER,
638 RR_ADC_TRIGGER_CTL, RR_ADC_TRIGGER_CTL);
639 if (ret < 0) {
640 dev_err(chip->dev, "BATT_ID trigger set failed:%d\n", ret);
641 goto out_disable_batt_id;
642 }
643
644 ret = rradc_read_status_in_cont_mode(chip, chan_id);
645 if (ret < 0)
646 dev_err(chip->dev, "Error reading in continuous mode:%d\n",
647 ret);
648
649 /*
650 * Reset registers back to default values
651 */
652 ret = regmap_update_bits(chip->regmap,
653 chip->base + RR_ADC_BATT_ID_TRIGGER,
654 RR_ADC_TRIGGER_CTL, 0);
655 if (ret < 0)
656 dev_err(chip->dev, "BATT_ID trigger re-set failed:%d\n", ret);
657
658 out_disable_batt_id:
659 ret = regmap_update_bits(chip->regmap, chip->base + RR_ADC_BATT_ID_CTRL,
660 RR_ADC_BATT_ID_CTRL_CHANNEL_CONV, 0);
661 if (ret < 0)
662 dev_err(chip->dev, "Disabling BATT ID channel failed:%d\n",
663 ret);
664
665 return ret;
666 }
667
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
PATCH v2 4/7 arm64: dts: qcom: pmi8998: add rradc node
In reply to Caleb ConnollyAdd a DT node for the Round Robin ADC found in the PMI8998 PMIC.
--- arch/arm64/boot/dts/qcom/pmi8998.dtsi | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/arm64/boot/dts/qcom/pmi8998.dtsi +8 -0
@@ -18,6 +18,14 @@ pmi8998_gpio: gpios@c000 { interrupt-controller; #interrupt-cells = <2>; }; + + pmi8998_rradc: rradc@4500 { + compatible = "qcom,pmi8998-rradc"; + reg = <0x4500>; + #io-channel-cells = <1>; + + status = "disabled"; + }; }; pmi8998_lsid1: pmic@3 {
Signature · 1 line
2.34.1
PATCH v2 5/7 arm64: dts: qcom: sdm845-oneplus: enable rradc
In reply to Caleb ConnollyEnable the RRADC for the OnePlus 6.
--- arch/arm64/boot/dts/qcom/sdm845-oneplus-common.dtsi | 4 ++++ 1 file changed, 4 insertions(+)
arch/arm64/boot/dts/qcom/sdm845-oneplus-common.dtsi +4 -0
@@ -450,6 +450,10 @@ pinconf { }; }; +&pmi8998_rradc { + status = "okay"; +}; + &qupv3_id_1 { status = "okay"; };
Signature · 1 line
2.34.1
PATCH v2 6/7 arm64: dts: qcom: sdm845-db845c: enable rradc
In reply to Caleb ConnollyEnable the Round Robin ADC for the db845c.
--- arch/arm64/boot/dts/qcom/sdm845-db845c.dts | 4 ++++ 1 file changed, 4 insertions(+)
arch/arm64/boot/dts/qcom/sdm845-db845c.dts +4 -0
@@ -595,6 +595,10 @@ resin { }; }; +&pmi8998_rradc { + status = "okay"; +}; + /* QUAT I2S Uses 4 I2S SD Lines for audio on LT9611 HDMI Bridge */ &q6afedai { qi2s@22 {
Signature · 1 line
2.34.1
PATCH v2 7/7 arm64: dts: qcom: sdm845-xiaomi-beryllium: enable RRADC
In reply to Caleb ConnollyEnable the PMI8998 RRADC.
--- arch/arm64/boot/dts/qcom/sdm845-xiaomi-beryllium.dts | 4 ++++ 1 file changed, 4 insertions(+)
arch/arm64/boot/dts/qcom/sdm845-xiaomi-beryllium.dts +4 -0
@@ -312,6 +312,10 @@ resin { }; }; +&pmi8998_rradc { + status = "okay"; +}; + /* QUAT I2S Uses 1 I2S SD Line for audio on TAS2559/60 amplifiers */ &q6afedai { qi2s@22 {
Signature · 1 line
2.34.1