Skip to content

Commit f686a36

Browse files
gizerojic23
authored andcommitted
iio: adc: mcp320x: Add support for mcp3301
This adds support for Microchip's 13 bit 1 channel AD converter MCP3301 Signed-off-by: Andrea Galbusera <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 47764c7 commit f686a36

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

Documentation/devicetree/bindings/iio/adc/mcp320x.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Required properties:
1818
"mcp3202"
1919
"mcp3204"
2020
"mcp3208"
21+
"mcp3301"
2122

2223

2324
Examples:

drivers/iio/adc/Kconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ config MCP320X
229229
depends on SPI
230230
help
231231
Say yes here to build support for Microchip Technology's
232-
MCP3001, MCP3002, MCP3004, MCP3008, MCP3201, MCP3202, MCP3204 or
233-
MCP3208 analog to digital converter.
232+
MCP3001, MCP3002, MCP3004, MCP3008, MCP3201, MCP3202, MCP3204,
233+
MCP3208 or MCP3301 analog to digital converter.
234234

235235
This driver can also be built as a module. If so, the module will be
236236
called mcp320x.

drivers/iio/adc/mcp320x.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* http://ww1.microchip.com/downloads/en/DeviceDoc/21290D.pdf mcp3201
2626
* http://ww1.microchip.com/downloads/en/DeviceDoc/21034D.pdf mcp3202
2727
* http://ww1.microchip.com/downloads/en/DeviceDoc/21298c.pdf mcp3204/08
28+
* http://ww1.microchip.com/downloads/en/DeviceDoc/21700E.pdf mcp3301
2829
*
2930
* This program is free software; you can redistribute it and/or modify
3031
* it under the terms of the GNU General Public License version 2 as
@@ -47,6 +48,7 @@ enum {
4748
mcp3202,
4849
mcp3204,
4950
mcp3208,
51+
mcp3301,
5052
};
5153

5254
struct mcp320x_chip_info {
@@ -76,6 +78,7 @@ static int mcp320x_channel_to_tx_data(int device_index,
7678
switch (device_index) {
7779
case mcp3001:
7880
case mcp3201:
81+
case mcp3301:
7982
return 0;
8083
case mcp3002:
8184
case mcp3202:
@@ -102,7 +105,7 @@ static int mcp320x_adc_conversion(struct mcp320x *adc, u8 channel,
102105
adc->tx_buf = mcp320x_channel_to_tx_data(device_index,
103106
channel, differential);
104107

105-
if (device_index != mcp3001 && device_index != mcp3201) {
108+
if (device_index != mcp3001 && device_index != mcp3201 && device_index != mcp3301) {
106109
ret = spi_sync(adc->spi, &adc->msg);
107110
if (ret < 0)
108111
return ret;
@@ -125,6 +128,8 @@ static int mcp320x_adc_conversion(struct mcp320x *adc, u8 channel,
125128
case mcp3204:
126129
case mcp3208:
127130
return (adc->rx_buf[0] << 4 | adc->rx_buf[1] >> 4);
131+
case mcp3301:
132+
return sign_extend32((adc->rx_buf[0] & 0x1f) << 8 | adc->rx_buf[1], 12);
128133
default:
129134
return -EINVAL;
130135
}
@@ -274,6 +279,11 @@ static const struct mcp320x_chip_info mcp320x_chip_infos[] = {
274279
.num_channels = ARRAY_SIZE(mcp3208_channels),
275280
.resolution = 12
276281
},
282+
[mcp3301] = {
283+
.channels = mcp3201_channels,
284+
.num_channels = ARRAY_SIZE(mcp3201_channels),
285+
.resolution = 13
286+
},
277287
};
278288

279289
static int mcp320x_probe(struct spi_device *spi)
@@ -366,6 +376,9 @@ static const struct of_device_id mcp320x_dt_ids[] = {
366376
}, {
367377
.compatible = "mcp3208",
368378
.data = &mcp320x_chip_infos[mcp3208],
379+
}, {
380+
.compatible = "mcp3301",
381+
.data = &mcp320x_chip_infos[mcp3301],
369382
}, {
370383
}
371384
};
@@ -381,6 +394,7 @@ static const struct spi_device_id mcp320x_id[] = {
381394
{ "mcp3202", mcp3202 },
382395
{ "mcp3204", mcp3204 },
383396
{ "mcp3208", mcp3208 },
397+
{ "mcp3301", mcp3301 },
384398
{ }
385399
};
386400
MODULE_DEVICE_TABLE(spi, mcp320x_id);

0 commit comments

Comments
 (0)