Skip to contentSkip to conversation

iio: adc: cpcap: Add minimal support for CPCAP PMIC ADC

PATCH Superseded Tony Lindgren 1 participant 2 messages Mar 22, 2017 – Mar 23, 2017 1 message not in the archive

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 iio: adc: cpcap: Add minimal support for CPCAP PMIC ADC

On Motorola phones like droid 4 there is a custom CPCAP PMIC. This PMIC has ADCs that are used for battery charging and USB PHY VBUS and ID pin detection.

Unfortunately the only documentation for this ADC seems to be the Motorola mapphone Linux kernel tree. I have tested that reading raw and scaled values works, but I have not used the timed sampling that the ADC seems to support.

Let's add a minimal support for it so we can eventually provide IIO channels for the related battery charging and USB PHY drivers.

Cc Marcel Partap <[email protected]>
Cc Michael Scott <[email protected]>
Cc Sebastian Reichel <[email protected]>

---

Changes since v1:

- Fix numerous issues pointed out by Peter Meerwald-Stadler <[email protected]> and Jonathan Cameron <[email protected]>

- Simplify things further by limiting read functions to a single channel instead of a bank and got rid of the driver specific cpcap_adc_conv_type in favor of IIO generic types

---
 .../devicetree/bindings/iio/adc/cpcap-adc.txt      |   18 +
 drivers/iio/adc/Kconfig                            |   11 +
 drivers/iio/adc/Makefile                           |    1 +
 drivers/iio/adc/cpcap-adc.c                        | 1031 ++++++++++++++++++++
 4 files changed, 1061 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/cpcap-adc.txt
 create mode 100644 drivers/iio/adc/cpcap-adc.c
Documentation/devicetree/bindings/iio/adc/cpcap-adc.txt new file +18 -0
new file mode 100644
@@ -0,0 +1,18 @@
+Motorola CPCAP PMIC ADC binding
+
+Required properties:
+- compatible: Should be "motorola,cpcap-adc" or "motorola,mapphone-cpcap-adc"
+- interrupt-parent: The interrupt controller
+- interrupts: The interrupt number for the ADC device
+- interrupt-names: Should be "adcdone"
+- #io-channel-cells: Number of cells in an IIO specifier
+
+Example:
+
+cpcap_adc: adc {
+	compatible = "motorola,mapphone-cpcap-adc";
+	interrupt-parent = <&cpcap>;
+	interrupts = <8 IRQ_TYPE_NONE>;
+	interrupt-names = "adcdone";
+	#io-channel-cells = <1>;
+};
drivers/iio/adc/Kconfig +11 -0
@@ -195,6 +195,17 @@ config CC10001_ADC
 	  This driver can also be built as a module. If so, the module will be
 	  called cc10001_adc.
 
+config CPCAP_ADC
+	tristate "Motorola CPCAP PMIC ADC driver"
+	depends on MFD_CPCAP
+	select IIO_BUFFER
+	select IIO_TRIGGERED_BUFFER
+	help
+	  Say yes here to build support for Motorola CPCAP PMIC ADC.
+
+	  This driver can also be built as a module. If so, the module will be
+	  called cpcap-adc.
+
 config DA9150_GPADC
 	tristate "Dialog DA9150 GPADC driver support"
 	depends on MFD_DA9150
drivers/iio/adc/Makefile +1 -0
@@ -20,6 +20,7 @@ obj-$(CONFIG_AXP288_ADC) += axp288_adc.o
 obj-$(CONFIG_BCM_IPROC_ADC) += bcm_iproc_adc.o
 obj-$(CONFIG_BERLIN2_ADC) += berlin2-adc.o
 obj-$(CONFIG_CC10001_ADC) += cc10001_adc.o
+obj-$(CONFIG_CPCAP_ADC) += cpcap-adc.o
 obj-$(CONFIG_DA9150_GPADC) += da9150-gpadc.o
 obj-$(CONFIG_ENVELOPE_DETECTOR) += envelope-detector.o
 obj-$(CONFIG_EXYNOS_ADC) += exynos_adc.o
drivers/iio/adc/cpcap-adc.c new file +1031 -0

1,031 lines not on this page · raw message

Signature · 1 line
2.11.1

A message that is not in the archive (sent off-list or not yet received): 20170322233726.5391-1-tony-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org

#2 lore raw

drivers/iio/adc/cpcap-adc.c line 174

Quoted 11 lines · Tony Lindgren
drivers/iio/adc/cpcap-adc.c new file +11 -0
+/**
+ * enum cpcap_adc_type - cpcap adc types
+ *
+ * Two banks of channels with eight channels in each. The first two channels
+ * in bank0 can be muxed for other functionality with CPCAP_ADC_TYPE_BATT_PI.
+ */
+enum cpcap_adc_type {
+	CPCAP_ADC_TYPE_BANK_0,
+	CPCAP_ADC_TYPE_BANK_1,
+	CPCAP_ADC_TYPE_BATT_PI,
+};

Hmm looks like I only got half done yesterday.. I can now get rid of the above in favor of using just channels.

Quoted 16 lines
drivers/iio/adc/cpcap-adc.c new file +16 -0
+static void cpcap_adc_phase(struct cpcap_adc_request *req, int index)
+{
+	const struct cpcap_adc_conversion_tbl *conv_tbl;
+	const struct cpcap_adc_phasing_tbl *phase_tbl;
+	int tbl_index;
+
+	switch (req->type) {
+	case CPCAP_ADC_TYPE_BANK_0:
+		conv_tbl = bank0_conversion;
+		phase_tbl = bank0_phasing;
+		tbl_index = index;
+		break;
+	case CPCAP_ADC_TYPE_BANK_1:
+		conv_tbl = bank1_conversion;
+		phase_tbl = bank1_phasing;
+		tbl_index = index;

drivers/iio/adc/cpcap-adc.c line 699

Quoted 10 lines
drivers/iio/adc/cpcap-adc.c new file +10 -0
+		break;
+	case CPCAP_ADC_TYPE_BATT_PI:
+		conv_tbl = bank0_conversion;
+		phase_tbl = bank0_phasing;
+		tbl_index = (index % 2) ? CPCAP_ADC_BATTI :
+			CPCAP_ADC_BATTP;
+		break;
+	default:
+		return;
+	}

And then the above switch will go away.

Quoted 12 lines
drivers/iio/adc/cpcap-adc.c new file +12 -0
+static void cpcap_adc_convert(struct cpcap_adc_request *req, int index)
+{
+	const struct cpcap_adc_conversion_tbl *conv_tbl;
+	int tbl_index;
+
+	switch (req->type) {
+	case CPCAP_ADC_TYPE_BANK_0:
+		conv_tbl = bank0_conversion;
+		tbl_index = index;
+		break;
+	case CPCAP_ADC_TYPE_BANK_1:
+		conv_tbl = bank1_conversion;

drivers/iio/adc/cpcap-adc.c line 781

Quoted 10 lines
drivers/iio/adc/cpcap-adc.c new file +10 -0
+		tbl_index = index;
+		break;
+	case CPCAP_ADC_TYPE_BATT_PI:
+		conv_tbl = bank0_conversion;
+		tbl_index = (index % 2) ?
+			CPCAP_ADC_BATTI : CPCAP_ADC_BATTP;
+		break;
+	default:
+		return;
+	}

And here too.

Quoted 12 lines
drivers/iio/adc/cpcap-adc.c new file +12 -0
+static int cpcap_adc_init_request(struct cpcap_adc_request *req,
+				  int channel)
+{
+	switch (channel) {
+	case 0 ... 7:
+		req->bank_index = channel;
+		req->type = CPCAP_ADC_TYPE_BANK_0;
+		break;
+	case 8 ... 15:
+		req->bank_index = channel - 8;
+		req->type = CPCAP_ADC_TYPE_BANK_1;
+		break;

drivers/iio/adc/cpcap-adc.c line 864

Quoted 10 lines
drivers/iio/adc/cpcap-adc.c new file +10 -0
+	case 16 ... 17:
+		req->bank_index = channel - 16;
+		req->type = CPCAP_ADC_TYPE_BATT_PI;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}

And this can be done by indexing everything with just the channels. So I'll be posting v3 of this patch at some point hopefully later on today.

Regards,

Tony