From: Jonathan Cameron <jic23@kernel.org>
To: Romain TISSERAND <romain.tisserand@gmail.com>
Cc: "David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org,
sashiko-reviews@lists.linux.dev
Subject: Re: [PATCH 2/4] iio: adc: Add the Miyoo A30 analog stick MCU
Date: Sat, 28 Nov 2026 02:21:57 +0000 [thread overview]
Message-ID: <20261128022157.7984a33d@jic23-hlaptop> (raw)
In-Reply-To: <20261127012612.1589039-3-romain.tisserand@gmail.com>
On Fri, 27 Nov 2026 02:26:10 +0100
Romain TISSERAND <romain.tisserand@gmail.com> wrote:
> The Miyoo A30 handheld (Allwinner A33) reads its analog stick through a
> microcontroller on uart0. From power-up it streams frames at 9600 baud,
> about 67 per second:
>
> 0xff <b0> <b1> <b2> <b3> 0xfe
>
> b2 and b3 are the raw 8-bit readings of the X and Y potentiometers, the
> ones the stock firmware uses. b0 and b1 also move with the stick, but
> their meaning is unknown, so they are not exposed.
>
> Add a serdev driver that exposes X and Y as two raw IIO channels. As
> the MCU pushes its readings, each complete frame also goes to a software
> IIO buffer (kfifo) with a timestamp: adc-joystick then takes the stick
> from the buffer, without polling, both axes from the same frame. Direct
> reads return the last complete frame, -EAGAIN before the first one.
>
> Signed-off-by: Romain TISSERAND <romain.tisserand@gmail.com>
Take a look at what Sashiko noted
https://sashiko.dev/#/patchset/20261127012612.1589039-1-romain.tisserand%40gmail.com
as well as what I have below.
> diff --git a/drivers/iio/adc/miyoo-a30-stick.c b/drivers/iio/adc/miyoo-a30-stick.c
> new file mode 100644
> index 000000000000..d83761558ee7
> --- /dev/null
> +++ b/drivers/iio/adc/miyoo-a30-stick.c
> @@ -0,0 +1,204 @@
> +
> +static size_t a30_stick_receive(struct serdev_device *serdev, const u8 *data,
> + size_t count)
> +{
> + struct a30_stick *st = serdev_device_get_drvdata(serdev);
> + size_t i;
> +
> + for (i = 0; i < count; i++) {
for (size_t i = 0; ...
> + /* resynchronise on the start byte */
> + if (!st->len && data[i] != A30_STICK_START)
> + continue;
> +
> + st->frame[st->len++] = data[i];
> + if (st->len < A30_STICK_FRAME_LEN)
> + continue;
> +
> + st->len = 0;
> + if (st->frame[A30_STICK_FRAME_LEN - 1] != A30_STICK_END)
> + continue;
> +
> + scoped_guard(spinlock, &st->lock) {
> + st->val[0] = st->frame[3];
> + st->val[1] = st->frame[4];
> + st->valid = true;
> + }
> +
> + if (iio_buffer_enabled(st->indio_dev)) {
I'm not sure if the fix sashiko has for racing with the demux is
correct... Please look into whether that works.
> + IIO_DECLARE_BUFFER_WITH_TS(u8, scan, 2) = { };
> +
> + scan[0] = st->frame[3];
> + scan[1] = st->frame[4];
> + iio_push_to_buffers_with_ts(st->indio_dev, scan,
> + sizeof(scan),
> + iio_get_time_ns(st->indio_dev));
> + }
> + }
> +
> + return count;
> +}
> +
> +static int a30_stick_read_raw(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan, int *val,
> + int *val2, long mask)
> +{
> + struct a30_stick *st = iio_priv(indio_dev);
> +
> + if (mask != IIO_CHAN_INFO_RAW)
> + return -EINVAL;
> +
> + guard(spinlock)(&st->lock);
> + if (!st->valid)
> + return -EAGAIN;
> +
> + *val = st->val[chan->channel];
blank line here.
> + return IIO_VAL_INT;
> +}
> +static int a30_stick_probe(struct serdev_device *serdev)
> +{
> + struct device *dev = &serdev->dev;
> + struct iio_dev *indio_dev;
> + struct a30_stick *st;
> + unsigned int baud;
> + int ret;
> +
> + indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
> + if (!indio_dev)
> + return -ENOMEM;
> +
> + st = iio_priv(indio_dev);
> + st->indio_dev = indio_dev;
> + spin_lock_init(&st->lock);
> +
> + indio_dev->name = "miyoo-a30-stick";
> + indio_dev->info = &a30_stick_info;
> + indio_dev->modes = INDIO_DIRECT_MODE;
> + indio_dev->channels = a30_stick_channels;
> + indio_dev->num_channels = ARRAY_SIZE(a30_stick_channels);
> + indio_dev->available_scan_masks = a30_stick_scan_masks;
> +
> + ret = devm_iio_kfifo_buffer_setup(dev, indio_dev, NULL);
> + if (ret)
> + return ret;
> +
> + ret = devm_iio_device_register(dev, indio_dev);
At this point interfaces are all exposed (both to usespace and in kernel).
We normally expect everything to be pretty much fully functioning at that
stage. So not to have to do all the stuff that follows.
> + if (ret)
> + return ret;
> +
> + /*
> + * Open the UART last, so that it is closed first on removal: no frame
> + * is pushed to the buffer once the IIO device is going away. Reads
> + * return -EAGAIN until the first frame.
> + */
> + serdev_device_set_drvdata(serdev, st);
> + serdev_device_set_client_ops(serdev, &a30_stick_serdev_ops);
> +
> + ret = devm_serdev_device_open(dev, serdev);
> + if (ret)
> + return dev_err_probe(dev, ret, "cannot open the UART\n");
> +
> + baud = serdev_device_set_baudrate(serdev, A30_STICK_BAUD);
> + if (baud != A30_STICK_BAUD)
> + return dev_err_probe(dev, -EINVAL, "cannot set %u baud (got %u)\n",
> + A30_STICK_BAUD, baud);
> +
> + serdev_device_set_flow_control(serdev, false);
> + ret = serdev_device_set_parity(serdev, SERDEV_PARITY_NONE);
> + if (ret)
> + return dev_err_probe(dev, ret, "cannot set the parity\n");
> +
> + return 0;
> +}
next prev parent reply other threads:[~2026-11-28 2:22 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 1:26 [PATCH 0/4] iio: adc: Add the Miyoo A30 and PocketGo S30 analog stick MCUs Romain TISSERAND
2026-11-27 1:26 ` [PATCH 1/4] dt-bindings: iio: adc: Add the Miyoo A30 analog stick MCU Romain TISSERAND
2026-11-27 1:26 ` [PATCH 2/4] " Romain TISSERAND
2026-11-27 8:47 ` Uwe Kleine-König
2026-11-28 2:21 ` Jonathan Cameron [this message]
2026-11-27 1:26 ` [PATCH 3/4] dt-bindings: iio: adc: Add the PocketGo S30 " Romain TISSERAND
2026-11-27 1:26 ` [PATCH 4/4] " Romain TISSERAND
2026-11-28 2:33 ` Jonathan Cameron
2026-11-27 11:49 ` [PATCH 0/4] iio: adc: Add the Miyoo A30 and PocketGo S30 analog stick MCUs Andy Shevchenko
2026-11-28 2:11 ` 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=20261128022157.7984a33d@jic23-hlaptop \
--to=jic23@kernel.org \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=krzk+dt@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sunxi@lists.linux.dev \
--cc=nuno.sa@analog.com \
--cc=robh@kernel.org \
--cc=romain.tisserand@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
/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
all inboxes | Powered by JetHome®