Skip to contentSkip to conversation

iio: adc: add driver for MCP3204/08 12-bit ADC

PATCH Superseded Oskar Andero 2 participants 2 messages May 3, 2013 IIO

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 iio: adc: add driver for MCP3204/08 12-bit ADC

This adds support for Microchip's 12 bit AD converters MCP3204 and MCP3208. These chips communicates over SPI and supports single-ended and pseudo-differential configurations.

Cc Jonathan Cameron <[email protected]>
Cc Lars-Peter Clausen <[email protected]>
---
 drivers/iio/adc/Kconfig   |  10 ++
 drivers/iio/adc/Makefile  |   1 +
 drivers/iio/adc/mcp320x.c | 258 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 269 insertions(+)
 create mode 100644 drivers/iio/adc/mcp320x.c
drivers/iio/adc/Kconfig +10 -0
index ab0767e6..93129ec 100644
@@ -133,6 +133,16 @@ config MAX1363
 	  max11646, max11647) Provides direct access via sysfs and buffered
 	  data via the iio dev interface.
 
+config MCP320X
+	tristate "Microchip Technology MCP3204/08"
+	depends on SPI
+	help
+	  Say yes here to build support for Microchip Technology's MCP3204 or
+	  MCP3208 analog to digital converter.
+
+	  This driver can also be built as a module. If so, the module will be
+	  called mcp320x.
+
 config TI_ADC081C
 	tristate "Texas Instruments ADC081C021/027"
 	depends on I2C
drivers/iio/adc/Makefile +1 -0
index 0a825be..8f475d3 100644
@@ -14,6 +14,7 @@ obj-$(CONFIG_AT91_ADC) += at91_adc.o
 obj-$(CONFIG_EXYNOS_ADC) += exynos_adc.o
 obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o
 obj-$(CONFIG_MAX1363) += max1363.o
+obj-$(CONFIG_MCP320X) += mcp320x.o
 obj-$(CONFIG_TI_ADC081C) += ti-adc081c.o
 obj-$(CONFIG_TI_AM335X_ADC) += ti_am335x_adc.o
 obj-$(CONFIG_VIPERBOARD_ADC) += viperboard_adc.o
drivers/iio/adc/mcp320x.c new file +258 -0

258 lines not on this page · raw message

Signature · 1 line
1.8.1.5
#1 lore raw

On 05/03/2013 10:55 AM, Oskar Andero wrote:
[...]

drivers/iio/adc/mcp320x.c line 36

Quoted 11 lines
drivers/iio/adc/mcp320x.c new file +11 -0
+
+struct mcp320x {
+	struct spi_device *spi;
+	struct spi_message msg;
+	struct spi_transfer transfer[2];
+
+	u8 tx_buf;
+	u8 rx_buf[2];
+
+	struct regulator *reg;
+	unsigned int ref_mv;

ref_mv looks unused.

Quoted 4 lines
drivers/iio/adc/mcp320x.c new file +4 -0
+
+	struct mutex lock;
+};
+

[..]

Quoted 2 lines
(quoted diff) +2 -0
+static int mcp320x_probe(struct spi_device *spi)
+{

[...]

drivers/iio/adc/mcp320x.c line 206

Quoted 4 lines
drivers/iio/adc/mcp320x.c new file +4 -0
+
+	ret = regulator_enable(adc->reg);
+	if (ret < 0)
+		goto reg_free;

You shouldn't disable the regulator if enabling it failed.

Quoted 17 lines
drivers/iio/adc/mcp320x.c new file +17 -0
+
+	mutex_init(&adc->lock);
+
+	ret = iio_device_register(indio_dev);
+	if (ret < 0)
+		goto reg_free;
+
+	return 0;
+
+reg_free:
+	regulator_disable(adc->reg);
+	regulator_put(adc->reg);
+iio_free:
+	iio_device_free(indio_dev);
+
+	return ret;
+}

[...]