18c2ecf20Sopenharmony_ciQualcomm's PM8xxx voltage XOADC
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ciThe Qualcomm PM8xxx PMICs contain a HK/XO ADC (Housekeeping/Crystal
48c2ecf20Sopenharmony_cioscillator ADC) encompassing PM8018, PM8038, PM8058 and PM8921.
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ciRequired properties:
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci- compatible: should be one of:
98c2ecf20Sopenharmony_ci  "qcom,pm8018-adc"
108c2ecf20Sopenharmony_ci  "qcom,pm8038-adc"
118c2ecf20Sopenharmony_ci  "qcom,pm8058-adc"
128c2ecf20Sopenharmony_ci  "qcom,pm8921-adc"
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci- reg: should contain the ADC base address in the PMIC, typically
158c2ecf20Sopenharmony_ci  0x197.
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci- xoadc-ref-supply: should reference a regulator that can supply
188c2ecf20Sopenharmony_ci  a reference voltage on demand. The reference voltage may vary
198c2ecf20Sopenharmony_ci  with PMIC variant but is typically something like 2.2 or 1.8V.
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ciThe following required properties are standard for IO channels, see
228c2ecf20Sopenharmony_ciiio-bindings.txt for more details, but notice that this particular
238c2ecf20Sopenharmony_ciADC has a special addressing scheme that require two cells for
248c2ecf20Sopenharmony_ciidentifying each ADC channel:
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci- #address-cells: should be set to <2>, the first cell is the
278c2ecf20Sopenharmony_ci  prescaler (on PM8058) or premux (on PM8921) with two valid bits
288c2ecf20Sopenharmony_ci  so legal values are 0x00, 0x01 or 0x02. The second cell
298c2ecf20Sopenharmony_ci  is the main analog mux setting (0x00..0x0f). The combination
308c2ecf20Sopenharmony_ci  of prescaler/premux and analog mux uniquely addresses a hardware
318c2ecf20Sopenharmony_ci  channel on all systems.
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci- #size-cells: should be set to <0>
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci- #io-channel-cells: should be set to <2>, again the cells are
368c2ecf20Sopenharmony_ci  precaler or premux followed by the analog muxing line.
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci- interrupts: should refer to the parent PMIC interrupt controller
398c2ecf20Sopenharmony_ci  and reference the proper ADC interrupt.
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ciRequired subnodes:
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ciThe ADC channels are configured as subnodes of the ADC.
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ciSince some of them are used for calibrating the ADC, these nodes are
468c2ecf20Sopenharmony_cicompulsory:
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ciadc-channel@c {
498c2ecf20Sopenharmony_ci	reg = <0x00 0x0c>;
508c2ecf20Sopenharmony_ci};
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ciadc-channel@d {
538c2ecf20Sopenharmony_ci	reg = <0x00 0x0d>;
548c2ecf20Sopenharmony_ci};
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ciadc-channel@f {
578c2ecf20Sopenharmony_ci	reg = <0x00 0x0f>;
588c2ecf20Sopenharmony_ci};
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ciThese three nodes are used for absolute and ratiometric calibration
618c2ecf20Sopenharmony_ciand only need to have these reg values: they are by hardware definition
628c2ecf20Sopenharmony_ci1:1 ratio converters that sample 625, 1250 and 0 milliV and create
638c2ecf20Sopenharmony_cian interpolation calibration for all other ADCs.
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ciOptional subnodes: any channels other than channels [0x00 0x0c],
668c2ecf20Sopenharmony_ci[0x00 0x0d] and [0x00 0x0f] are optional.
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ciRequired channel node properties:
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci- reg: should contain the hardware channel number in the range
718c2ecf20Sopenharmony_ci  0 .. 0xff (8 bits).
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ciOptional channel node properties:
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci- qcom,decimation:
768c2ecf20Sopenharmony_ci  Value type: <u32>
778c2ecf20Sopenharmony_ci  Definition: This parameter is used to decrease the ADC sampling rate.
788c2ecf20Sopenharmony_ci          Quicker measurements can be made by reducing the decimation ratio.
798c2ecf20Sopenharmony_ci          Valid values are 512, 1024, 2048, 4096.
808c2ecf20Sopenharmony_ci          If the property is not found, a default value of 512 will be used.
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci- qcom,ratiometric:
838c2ecf20Sopenharmony_ci  Value type: <u32>
848c2ecf20Sopenharmony_ci  Definition: Channel calibration type. If this property is specified
858c2ecf20Sopenharmony_ci          VADC will use a special voltage references for channel
868c2ecf20Sopenharmony_ci          calibration. The available references are specified in the
878c2ecf20Sopenharmony_ci	  as a u32 value setting (see below) and it is compulsory
888c2ecf20Sopenharmony_ci	  to also specify this reference if ratiometric calibration
898c2ecf20Sopenharmony_ci	  is selected.
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci	  If the property is not found, the channel will be
928c2ecf20Sopenharmony_ci          calibrated with the 0.625V and 1.25V reference channels, also
938c2ecf20Sopenharmony_ci          known as an absolute calibration.
948c2ecf20Sopenharmony_ci  The reference voltage pairs when using ratiometric calibration:
958c2ecf20Sopenharmony_ci	  0 = XO_IN/XOADC_GND
968c2ecf20Sopenharmony_ci	  1 = PMIC_IN/XOADC_GND
978c2ecf20Sopenharmony_ci	  2 = PMIC_IN/BMS_CSP
988c2ecf20Sopenharmony_ci	  3 (invalid)
998c2ecf20Sopenharmony_ci	  4 = XOADC_GND/XOADC_GND
1008c2ecf20Sopenharmony_ci	  5 = XOADC_VREF/XOADC_GND
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ciExample:
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_cixoadc: xoadc@197 {
1058c2ecf20Sopenharmony_ci	compatible = "qcom,pm8058-adc";
1068c2ecf20Sopenharmony_ci	reg = <0x197>;
1078c2ecf20Sopenharmony_ci	interrupts-extended = <&pm8058 76 IRQ_TYPE_EDGE_RISING>;
1088c2ecf20Sopenharmony_ci	#address-cells = <2>;
1098c2ecf20Sopenharmony_ci	#size-cells = <0>;
1108c2ecf20Sopenharmony_ci	#io-channel-cells = <2>;
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci	vcoin: adc-channel@0 {
1138c2ecf20Sopenharmony_ci		reg = <0x00 0x00>;
1148c2ecf20Sopenharmony_ci	};
1158c2ecf20Sopenharmony_ci	vbat: adc-channel@1 {
1168c2ecf20Sopenharmony_ci		reg = <0x00 0x01>;
1178c2ecf20Sopenharmony_ci	};
1188c2ecf20Sopenharmony_ci	dcin: adc-channel@2 {
1198c2ecf20Sopenharmony_ci		reg = <0x00 0x02>;
1208c2ecf20Sopenharmony_ci	};
1218c2ecf20Sopenharmony_ci	ichg: adc-channel@3 {
1228c2ecf20Sopenharmony_ci		reg = <0x00 0x03>;
1238c2ecf20Sopenharmony_ci	};
1248c2ecf20Sopenharmony_ci	vph_pwr: adc-channel@4 {
1258c2ecf20Sopenharmony_ci		reg = <0x00 0x04>;
1268c2ecf20Sopenharmony_ci	};
1278c2ecf20Sopenharmony_ci	usb_vbus: adc-channel@a {
1288c2ecf20Sopenharmony_ci		reg = <0x00 0x0a>;
1298c2ecf20Sopenharmony_ci	};
1308c2ecf20Sopenharmony_ci	die_temp: adc-channel@b {
1318c2ecf20Sopenharmony_ci		reg = <0x00 0x0b>;
1328c2ecf20Sopenharmony_ci	};
1338c2ecf20Sopenharmony_ci	ref_625mv: adc-channel@c {
1348c2ecf20Sopenharmony_ci		reg = <0x00 0x0c>;
1358c2ecf20Sopenharmony_ci	};
1368c2ecf20Sopenharmony_ci	ref_1250mv: adc-channel@d {
1378c2ecf20Sopenharmony_ci		reg = <0x00 0x0d>;
1388c2ecf20Sopenharmony_ci	};
1398c2ecf20Sopenharmony_ci	ref_325mv: adc-channel@e {
1408c2ecf20Sopenharmony_ci		reg = <0x00 0x0e>;
1418c2ecf20Sopenharmony_ci	};
1428c2ecf20Sopenharmony_ci	ref_muxoff: adc-channel@f {
1438c2ecf20Sopenharmony_ci		reg = <0x00 0x0f>;
1448c2ecf20Sopenharmony_ci	};
1458c2ecf20Sopenharmony_ci};
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci/* IIO client node */
1488c2ecf20Sopenharmony_ciiio-hwmon {
1498c2ecf20Sopenharmony_ci	compatible = "iio-hwmon";
1508c2ecf20Sopenharmony_ci	io-channels = <&xoadc 0x00 0x01>, /* Battery */
1518c2ecf20Sopenharmony_ci		    <&xoadc 0x00 0x02>, /* DC in (charger) */
1528c2ecf20Sopenharmony_ci		    <&xoadc 0x00 0x04>, /* VPH the main system voltage */
1538c2ecf20Sopenharmony_ci		    <&xoadc 0x00 0x0b>, /* Die temperature */
1548c2ecf20Sopenharmony_ci		    <&xoadc 0x00 0x0c>, /* Reference voltage 1.25V */
1558c2ecf20Sopenharmony_ci		    <&xoadc 0x00 0x0d>, /* Reference voltage 0.625V */
1568c2ecf20Sopenharmony_ci		    <&xoadc 0x00 0x0e>; /* Reference voltage 0.325V */
1578c2ecf20Sopenharmony_ci};
158