From: Jonathan Cameron <jic23@kernel.org>
To: Salih Erim <salih.erim@amd.com>
Cc: "Andy Shevchenko" <andy@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>, "Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Conall O'Griofa" <conall.ogriofa@amd.com>,
"Michal Simek" <michal.simek@amd.com>,
"Guenter Roeck" <linux@roeck-us.net>,
"Salih Erim" <erimsalih@gmail.com>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 3/5] iio: adc: versal-sysmon: add I2C driver
Date: Thu, 28 May 2026 13:42:11 +0100 [thread overview]
Message-ID: <20260528134211.259d8c19@jic23-huawei> (raw)
In-Reply-To: <20260527114211.174288-4-salih.erim@amd.com>
On Wed, 27 May 2026 12:42:09 +0100
Salih Erim <salih.erim@amd.com> wrote:
> Add an I2C transport driver for the Versal SysMon block. The SysMon
> provides an I2C slave interface that allows an external master to
> read voltage and temperature measurements through the same register
> map used by the MMIO path.
>
> The I2C command frame is an 8-byte structure containing a 4-byte data
> payload, a 2-byte register offset, and a 1-byte instruction field.
> Read operations send the frame with a read instruction, then receive
> a 4-byte response containing the register value.
>
> Events are not supported on the I2C path because there is no
> interrupt line and the I2C regmap backend cannot be called from
> atomic context.
>
> Co-developed-by: Conall O'Griofa <conall.ogriofa@amd.com>
> Signed-off-by: Conall O'Griofa <conall.ogriofa@amd.com>
> Signed-off-by: Salih Erim <salih.erim@amd.com>
A few minor things inline.
> diff --git a/drivers/iio/adc/versal-sysmon-i2c.c b/drivers/iio/adc/versal-sysmon-i2c.c
> new file mode 100644
> index 00000000000..92d149f517e
> --- /dev/null
> +++ b/drivers/iio/adc/versal-sysmon-i2c.c
> @@ -0,0 +1,153 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * AMD Versal SysMon I2C driver
> + *
> + * Copyright (C) 2023 - 2026, Advanced Micro Devices, Inc.
> + */
> +
> +#include <linux/bitfield.h>
> +#include <linux/bits.h>
> +#include <linux/i2c.h>
> +#include <linux/module.h>
> +#include <linux/regmap.h>
> +
> +#include "versal-sysmon.h"
> +
> +#define SYSMON_I2C_INSTR_READ BIT(2)
> +#define SYSMON_I2C_INSTR_WRITE BIT(3)
> +
> +#define SYSMON_I2C_DATA0_MASK GENMASK(7, 0)
> +#define SYSMON_I2C_DATA1_MASK GENMASK(15, 8)
> +#define SYSMON_I2C_DATA2_MASK GENMASK(23, 16)
> +#define SYSMON_I2C_DATA3_MASK GENMASK(31, 24)
> +
> +#define SYSMON_I2C_OFS_LOW_MASK GENMASK(9, 2)
> +#define SYSMON_I2C_OFS_HIGH_MASK GENMASK(15, 10)
> +
> +/* Byte positions within the 8-byte I2C command frame (HW-defined) */
> +enum sysmon_i2c_payload_idx {
> + SYSMON_I2C_DATA0_IDX = 0,
> + SYSMON_I2C_DATA1_IDX = 1,
> + SYSMON_I2C_DATA2_IDX = 2,
> + SYSMON_I2C_DATA3_IDX = 3,
> + SYSMON_I2C_OFS_LOW_IDX = 4,
> + SYSMON_I2C_OFS_HIGH_IDX = 5,
With changes suggested below I think you only need the two base
offsets and the final one. As such maybe 3 defines makes more sense
than an enum
> + SYSMON_I2C_INSTR_IDX = 6,
If you do keep an enum, it would be good to add an entry for the final
byte to give some indication of why it is 8 bytes. Even if that is
reserved0
> +};
> +
> +static int sysmon_i2c_reg_read(void *context, unsigned int reg,
> + unsigned int *val)
> +{
> + struct i2c_client *client = context;
> + u8 write_buf[8] = { };
> + u8 read_buf[4];
> + int ret;
> +
> + write_buf[SYSMON_I2C_OFS_LOW_IDX] =
> + FIELD_GET(SYSMON_I2C_OFS_LOW_MASK, reg);
> + write_buf[SYSMON_I2C_OFS_HIGH_IDX] =
> + FIELD_GET(SYSMON_I2C_OFS_HIGH_MASK, reg);
I'd guess an unaligned put works here a well? though you'll need
to do a FIELD_GET() to extract the slightly shifted content.
> + write_buf[SYSMON_I2C_INSTR_IDX] = SYSMON_I2C_INSTR_READ;
> +
> + ret = i2c_master_send(client, write_buf, sizeof(write_buf));
> + if (ret < 0)
> + return ret;
> + if (ret != sizeof(write_buf))
> + return -EIO;
> +
> + ret = i2c_master_recv(client, read_buf, sizeof(read_buf));
> + if (ret < 0)
> + return ret;
> + if (ret != sizeof(read_buf))
> + return -EIO;
> +
> + *val = FIELD_PREP(SYSMON_I2C_DATA0_MASK,
> + read_buf[SYSMON_I2C_DATA0_IDX]) |
> + FIELD_PREP(SYSMON_I2C_DATA1_MASK,
> + read_buf[SYSMON_I2C_DATA1_IDX]) |
> + FIELD_PREP(SYSMON_I2C_DATA2_MASK,
> + read_buf[SYSMON_I2C_DATA2_IDX]) |
> + FIELD_PREP(SYSMON_I2C_DATA3_MASK,
> + read_buf[SYSMON_I2C_DATA3_IDX]);
Very complex way to express what I think is
*val = get_unaligned_le32(&read_buf[0]);
> +
> + return 0;
> +}
> +
> +static int sysmon_i2c_reg_write(void *context, unsigned int reg,
> + unsigned int val)
> +{
> + struct i2c_client *client = context;
> + u8 write_buf[8] = { };
> + int ret;
> +
> + write_buf[SYSMON_I2C_DATA0_IDX] =
> + FIELD_GET(SYSMON_I2C_DATA0_MASK, val);
> + write_buf[SYSMON_I2C_DATA1_IDX] =
> + FIELD_GET(SYSMON_I2C_DATA1_MASK, val);
> + write_buf[SYSMON_I2C_DATA2_IDX] =
> + FIELD_GET(SYSMON_I2C_DATA2_MASK, val);
> + write_buf[SYSMON_I2C_DATA3_IDX] =
> + FIELD_GET(SYSMON_I2C_DATA3_MASK, val);
That's a put_unaligned_le32() I think?
> + write_buf[SYSMON_I2C_OFS_LOW_IDX] =
> + FIELD_GET(SYSMON_I2C_OFS_LOW_MASK, reg);
> + write_buf[SYSMON_I2C_OFS_HIGH_IDX] =
> + FIELD_GET(SYSMON_I2C_OFS_HIGH_MASK, reg);
I'd guess put_unaligned_le16()? Will need a a FIELD_PREP()
for the full thing though.
> + write_buf[SYSMON_I2C_INSTR_IDX] = SYSMON_I2C_INSTR_WRITE;
> +
> + ret = i2c_master_send(client, write_buf, sizeof(write_buf));
> + if (ret < 0)
> + return ret;
> + if (ret != sizeof(write_buf))
> + return -EIO;
> +
> + return 0;
> +}
> +static const struct of_device_id sysmon_i2c_of_match_table[] = {
> + { .compatible = "xlnx,versal-sysmon" },
> + { }
> +};
> +MODULE_DEVICE_TABLE(of, sysmon_i2c_of_match_table);
> +
> +static const struct i2c_device_id sysmon_i2c_id_table[] = {
> + { "versal-sysmon" },
Named initializer for this. Uwe is cleaning these up across IIO;
let us not add another one!
> + { }
> +};
> +MODULE_DEVICE_TABLE(i2c, sysmon_i2c_id_table);
> +
> +static struct i2c_driver sysmon_i2c_driver = {
> + .probe = sysmon_i2c_probe,
> + .driver = {
> + .name = "versal-sysmon-i2c",
> + .of_match_table = sysmon_i2c_of_match_table,
> + },
> + .id_table = sysmon_i2c_id_table,
> +};
> +module_i2c_driver(sysmon_i2c_driver);
> +
> +MODULE_LICENSE("GPL");
> +MODULE_DESCRIPTION("AMD Versal SysMon I2C Driver");
> +MODULE_AUTHOR("Conall O'Griofa <conall.ogriofa@amd.com>");
> +MODULE_AUTHOR("Salih Erim <salih.erim@amd.com>");
next prev parent reply other threads:[~2026-05-28 12:42 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-27 11:42 [PATCH v3 0/5] iio: adc: add AMD/Xilinx Versal SysMon driver Salih Erim
2026-05-27 11:42 ` [PATCH v3 1/5] dt-bindings: iio: adc: add xlnx,versal-sysmon binding Salih Erim
2026-05-28 8:38 ` Krzysztof Kozlowski
2026-05-27 11:42 ` [PATCH v3 2/5] iio: adc: add Versal SysMon driver Salih Erim
2026-05-27 12:29 ` sashiko-bot
2026-05-28 12:24 ` Jonathan Cameron
2026-05-28 22:07 ` Erim, Salih
2026-05-27 11:42 ` [PATCH v3 3/5] iio: adc: versal-sysmon: add I2C driver Salih Erim
2026-05-27 13:01 ` sashiko-bot
2026-05-28 12:42 ` Jonathan Cameron [this message]
2026-05-28 22:12 ` Erim, Salih
2026-05-27 11:42 ` [PATCH v3 4/5] iio: adc: versal-sysmon: add threshold event support Salih Erim
2026-05-27 13:31 ` sashiko-bot
2026-05-28 13:01 ` Jonathan Cameron
2026-05-28 22:18 ` Erim, Salih
2026-05-27 11:42 ` [PATCH v3 5/5] iio: adc: versal-sysmon: add oversampling support Salih Erim
2026-05-27 13:52 ` sashiko-bot
2026-05-28 13:05 ` Jonathan Cameron
2026-05-28 22:27 ` Erim, Salih
2026-05-28 12:06 ` [PATCH v3 0/5] iio: adc: add AMD/Xilinx Versal SysMon driver Jonathan Cameron
2026-05-28 21:46 ` Erim, Salih
2026-05-29 9:03 ` Jonathan Cameron
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=20260528134211.259d8c19@jic23-huawei \
--to=jic23@kernel.org \
--cc=andy@kernel.org \
--cc=conall.ogriofa@amd.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=erimsalih@gmail.com \
--cc=krzk+dt@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=michal.simek@amd.com \
--cc=nuno.sa@analog.com \
--cc=robh@kernel.org \
--cc=salih.erim@amd.com \
/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