From: Jakkapong Saksrisuwan <me@jakkapong.dev>
To: linux-iio@vger.kernel.org
Cc: jic23@kernel.org, andy@kernel.org, dlechner@baylibre.com,
nuno.sa@analog.com, robh@kernel.org, krzk+dt@kernel.org,
conor+dt@kernel.org, devicetree@vger.kernel.org,
Jakkapong Saksrisuwan <me@jakkapong.dev>
Subject: [PATCH 2/2] iio: adc: mcp320x: Add support for MCP3302 and MCP3304
Date: Fri, 4 Dec 2026 18:02:14 +0700 [thread overview]
Message-ID: <20261204110214.40106-2-me@jakkapong.dev> (raw)
In-Reply-To: <20261204110214.40106-1-me@jakkapong.dev>
The MCP3302 and MCP3304 are 13-bit output ADCs with pseudo-differential
inputs. They share the command frame and channel layout of the MCP3204
and MCP3208. The sign bit is not counted toward resolution, which is
set to 12.
Datasheet: https://ww1.microchip.com/downloads/en/DeviceDoc/21697F.pdf
Signed-off-by: Jakkapong Saksrisuwan <me@jakkapong.dev>
---
Notes:
This is based on the datasheet (DS21697F) and the driver cross-check
only. I do not have an MCP3302/04, so it is untested on hardware.
AI assistance: I used an AI assistant (Qwen) to help read the
datasheet and the driver and to draft this message. I checked the
channel tables (DS21697F Tables 6-1/6-2, cross-checked against the
MCP3204/08 datasheet DS21298E) and the RX bit math against the timing
diagrams (Figures 6-2 and 6-3) myself. Build-tested (W=1, C=1) and
checked with checkpatch.pl --strict; not tested on hardware.
drivers/iio/adc/Kconfig | 4 ++--
drivers/iio/adc/mcp320x.c | 32 ++++++++++++++++++++++++++++++++
2 files changed, 34 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 82e2eb652e16..53be5911bf42 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -1210,8 +1210,8 @@ config MCP320X
help
Say yes here to build support for Microchip Technology's
MCP3001, MCP3002, MCP3004, MCP3008, MCP3201, MCP3202, MCP3204,
- MCP3208, MCP3301, MCP3550, MCP3551 and MCP3553 analog to digital
- converters.
+ MCP3208, MCP3301, MCP3302, MCP3304, MCP3550, MCP3551 and MCP3553
+ analog to digital converters.
This driver can also be built as a module. If so, the module will be
called mcp320x.
diff --git a/drivers/iio/adc/mcp320x.c b/drivers/iio/adc/mcp320x.c
index 18cb957e7095..fe0c47ba582d 100644
--- a/drivers/iio/adc/mcp320x.c
+++ b/drivers/iio/adc/mcp320x.c
@@ -20,6 +20,8 @@
* ------------
* 13 bit converter
* MCP3301
+ * MCP3302
+ * MCP3304
* ------------
* 22 bit converter
* MCP3550
@@ -34,6 +36,7 @@
* http://ww1.microchip.com/downloads/en/DeviceDoc/21034D.pdf mcp3202
* http://ww1.microchip.com/downloads/en/DeviceDoc/21298c.pdf mcp3204/08
* https://ww1.microchip.com/downloads/en/DeviceDoc/21700E.pdf mcp3301
+ * https://ww1.microchip.com/downloads/en/DeviceDoc/21697F.pdf mcp3302/04
* http://ww1.microchip.com/downloads/en/DeviceDoc/21950D.pdf mcp3550/1/3
*/
@@ -54,6 +57,8 @@ enum {
mcp3204,
mcp3208,
mcp3301,
+ mcp3302,
+ mcp3304,
mcp3550_50,
mcp3550_60,
mcp3551,
@@ -105,8 +110,10 @@ static int mcp320x_channel_to_tx_data(int device_index,
case mcp3202:
return ((start_bit << 4) | (!differential << 3) |
(channel << 2));
+ case mcp3302:
case mcp3004:
case mcp3204:
+ case mcp3304:
case mcp3008:
case mcp3208:
return ((start_bit << 6) | (!differential << 5) |
@@ -160,6 +167,15 @@ static int mcp320x_adc_conversion(struct mcp320x *adc, u8 channel,
*val = sign_extend32((adc->rx_buf[0] & 0x1f) << 8
| adc->rx_buf[1], 12);
return 0;
+ case mcp3302:
+ case mcp3304:
+ /*
+ * rx_buf[0] reads SB, B11, B10, ... , B5
+ * rx_buf[1] reads B4, B3, ... , B0, X, X, X
+ */
+ *val = sign_extend32(adc->rx_buf[0] << 5 |
+ adc->rx_buf[1] >> 3, 12);
+ return 0;
case mcp3550_50:
case mcp3550_60:
case mcp3551:
@@ -343,6 +359,18 @@ static const struct mcp320x_chip_info mcp320x_chip_infos[] = {
.num_channels = ARRAY_SIZE(mcp3201_channels),
.resolution = 13
},
+ [mcp3302] = {
+ /* same channel layout as the MCP3204 */
+ .channels = mcp3204_channels,
+ .num_channels = ARRAY_SIZE(mcp3204_channels),
+ .resolution = 12,
+ },
+ [mcp3304] = {
+ /* same channel layout as the MCP3208 */
+ .channels = mcp3208_channels,
+ .num_channels = ARRAY_SIZE(mcp3208_channels),
+ .resolution = 12,
+ },
[mcp3550_50] = {
.channels = mcp3201_channels,
.num_channels = ARRAY_SIZE(mcp3201_channels),
@@ -467,6 +495,8 @@ static const struct of_device_id mcp320x_dt_ids[] = {
{ .compatible = "microchip,mcp3204" },
{ .compatible = "microchip,mcp3208" },
{ .compatible = "microchip,mcp3301" },
+ { .compatible = "microchip,mcp3302" },
+ { .compatible = "microchip,mcp3304" },
{ .compatible = "microchip,mcp3550-50" },
{ .compatible = "microchip,mcp3550-60" },
{ .compatible = "microchip,mcp3551" },
@@ -485,6 +515,8 @@ static const struct spi_device_id mcp320x_id[] = {
{ .name = "mcp3204", .driver_data = mcp3204 },
{ .name = "mcp3208", .driver_data = mcp3208 },
{ .name = "mcp3301", .driver_data = mcp3301 },
+ { .name = "mcp3302", .driver_data = mcp3302 },
+ { .name = "mcp3304", .driver_data = mcp3304 },
{ .name = "mcp3550-50", .driver_data = mcp3550_50 },
{ .name = "mcp3550-60", .driver_data = mcp3550_60 },
{ .name = "mcp3551", .driver_data = mcp3551 },
--
2.47.3
next prev parent reply other threads:[~2026-12-04 11:03 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 11:02 [PATCH 1/2] dt-bindings: iio: adc: microchip,mcp3201: add MCP3302 and MCP3304 Jakkapong Saksrisuwan
2026-12-04 11:02 ` Jakkapong Saksrisuwan [this message]
2026-12-04 12:21 ` [PATCH 2/2] iio: adc: mcp320x: Add support for " Andy Shevchenko
2026-12-04 13:26 ` Joshua Crofts
2026-12-04 14:59 ` Andy Shevchenko
2026-12-04 14:56 ` Jakkapong Saksrisuwan
2026-12-04 16:56 ` [PATCH 1/2] dt-bindings: iio: adc: microchip,mcp3201: add " Conor Dooley
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261204110214.40106-2-me@jakkapong.dev \
--to=me@jakkapong.dev \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=robh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox