From: Jeremy Kerr <jk@codeconstruct.com.au>
To: Ryan Chen <ryan_chen@aspeedtech.com>,
"andriy.shevchenko@linux.intel.com"
<andriy.shevchenko@linux.intel.com>,
Andi Shyti <andi.shyti@kernel.org>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>, Joel Stanley <joel@jms.id.au>,
Andrew Jeffery <andrew@codeconstruct.com.au>,
Benjamin Herrenschmidt <benh@kernel.crashing.org>,
Philipp Zabel <p.zabel@pengutronix.de>
Cc: "linux-i2c@vger.kernel.org" <linux-i2c@vger.kernel.org>,
"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"linux-aspeed@lists.ozlabs.org" <linux-aspeed@lists.ozlabs.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"openbmc@lists.ozlabs.org" <openbmc@lists.ozlabs.org>
Subject: Re: [PATCH v27 3/4] i2c: ast2600: Add controller driver for AST2600 new register set
Date: Wed, 25 Mar 2026 17:15:54 +0800 [thread overview]
Message-ID: <28eee6d05ed1e1814f09ec907d56798a279f226d.camel@codeconstruct.com.au> (raw)
In-Reply-To: <TY2PPF5CB9A1BE6D451E8AFDBA03B81AFB4F249A@TY2PPF5CB9A1BE6.apcprd06.prod.outlook.com>
Hi Ryan,
> > I would suggest separating the string parsing from the "is the mode available"
> > logic, more on that below.
> >
> I will separate with following.
>
> static int ast2600_i2c_xfer_mode_parse(const char *buf, enum xfer_mode *mode)
> {
> if (sysfs_streq(buf, "byte")) { *mode = BYTE_MODE; return 0; }
> if (sysfs_streq(buf, "buffer")) { *mode = BUFF_MODE; return 0; }
> if (sysfs_streq(buf, "dma")) { *mode = DMA_MODE; return 0; }
> return -EINVAL;
> }
OK, but with kernel-style formatting.
>
> static int ast2600_i2c_xfer_mode_check(struct ast2600_i2c_bus *i2c_bus,
> enum xfer_mode mode)
> {
> if (mode == BUFF_MODE && !i2c_bus->buf_base)
> return -EINVAL;
> if (mode == DMA_MODE && !i2c_bus->dma_available)
> return -EINVAL;
> return 0;
> }
>
> > > +
> > > +static const char *ast2600_i2c_xfer_mode_name(enum xfer_mode mode) {
> > > + switch (mode) {
> > > + case BYTE_MODE:
> > > + return "byte";
> > > + case DMA_MODE:
> > > + return "dma";
> > > + case BUFF_MODE:
> > > + default:
> > > + return "buffer";
> > > + }
> > > +}
> > > +
> > > +static ssize_t xfer_mode_show(struct device *dev, struct
> > > +device_attribute *attr, char *buf) {
> > > + struct ast2600_i2c_bus *i2c_bus = dev_get_drvdata(dev);
> > > +
> > > + return sysfs_emit(buf, "%s\n",
> > > +ast2600_i2c_xfer_mode_name(i2c_bus->mode));
> > > +}
> > > +
> > > +static ssize_t xfer_mode_store(struct device *dev,
> > > + struct device_attribute *attr,
> > > + const char *buf, size_t count)
> > {
> > > + struct ast2600_i2c_bus *i2c_bus = dev_get_drvdata(dev);
> > > + enum xfer_mode mode;
> > > + int ret;
> > > +
> > > + ret = ast2600_i2c_xfer_mode_parse(i2c_bus, buf, &mode);
> > > + if (ret)
> > > + return ret;
> > > +
> > > + i2c_lock_bus(&i2c_bus->adap, I2C_LOCK_ROOT_ADAPTER);
> > > + ast2600_i2c_set_xfer_mode(i2c_bus, mode);
> > > + i2c_unlock_bus(&i2c_bus->adap, I2C_LOCK_ROOT_ADAPTER);
> > > +
> > > + return count;
> > > +}
> > > +
> > > +static DEVICE_ATTR_RW(xfer_mode);
> >
> > This will need sysfs ABI documentation.
>
> Since it is in sysfs /sys/bus/platform/drivers/i2c_ast2600
> So I add Documentation/ABI/testing/sysfs-bus-platform-drivers-i2c-ast2600
> am I right?
I would suggest Documentation/ABI/testing/sysfs-driver-ast2600-i2c
>
> What: /sys/bus/platform/drivers/i2c-ast2600/.../xfer_mode
> Date: March 2026
> KernelVersion: 6.x
KernelVersion is optional, but if you include it, it would be 7.x.
> Contact: Ryan Chen <ryan_chen@aspeedtech.com>
> Description:
Keep the first line of the description on the same line.
> Shows or sets the transfer mode for the ASPEED AST2600 I2C
> controller. Valid values are:
>
> - "byte": Programmed I/O, one byte at a time.
> - "buffer": Programmed I/O using the hardware FIFO buffer.
> - "dma": DMA transfer (only available if aspeed,enable-dma
> is set in the device tree).
Decouple this from the device tree configuration mechanism:
- "dma": DMA transfer (if DMA is available for this
controller)
> i2c_bus->buf_base = devm_platform_get_and_ioremap_resource(pdev, 1, &res);
> if (!IS_ERR(i2c_bus->buf_base))
> i2c_bus->buf_size = resource_size(res) / 2;
> else
> i2c_bus->buf_base = NULL;
I would suggest a temporary, so there's no chance that future changes
could see an ERR_PTR value in i2c_bus->buf_base:
buf_base = devm_platform_get_and_ioremap_resource(pdev, 1, &res);
if (!IS_ERR(buf_base)) {
i2c_bus->buf_base = buf_base
i2c_bus->buf_size = resource_size(res) / 2;
}
and you have kzalloc()ed, so no need for the NULL init in the error path.
Cheers,
Jeremy
next prev parent reply other threads:[~2026-03-25 9:16 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-24 3:06 [PATCH v27 0/4] Add ASPEED AST2600 I2C controller driver Ryan Chen
2026-03-24 3:06 ` [PATCH v27 1/4] dt-bindings: i2c: Split AST2600 binding into a new YAML Ryan Chen
2026-03-24 3:06 ` [PATCH v27 2/4] dt-bindings: i2c: ast2600-i2c.yaml: Add global-regs and transfer-mode properties Ryan Chen
2026-03-24 3:11 ` Jeremy Kerr
2026-03-25 8:11 ` Ryan Chen
2026-03-25 16:52 ` Rob Herring
2026-03-26 2:19 ` Ryan Chen
2026-03-25 1:46 ` Rob Herring (Arm)
2026-03-24 3:06 ` [PATCH v27 3/4] i2c: ast2600: Add controller driver for AST2600 new register set Ryan Chen
2026-03-24 3:37 ` Jeremy Kerr
2026-03-25 8:46 ` Ryan Chen
2026-03-25 9:15 ` Jeremy Kerr [this message]
2026-03-26 2:04 ` Ryan Chen
2026-03-25 10:48 ` kernel test robot
2026-03-25 11:20 ` kernel test robot
2026-03-25 11:26 ` Krzysztof Kozlowski
2026-03-24 3:06 ` [PATCH v27 4/4] i2c: ast2600: Add target mode support Ryan Chen
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=28eee6d05ed1e1814f09ec907d56798a279f226d.camel@codeconstruct.com.au \
--to=jk@codeconstruct.com.au \
--cc=andi.shyti@kernel.org \
--cc=andrew@codeconstruct.com.au \
--cc=andriy.shevchenko@linux.intel.com \
--cc=benh@kernel.crashing.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=joel@jms.id.au \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-aspeed@lists.ozlabs.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=openbmc@lists.ozlabs.org \
--cc=p.zabel@pengutronix.de \
--cc=robh@kernel.org \
--cc=ryan_chen@aspeedtech.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