From: Jonathan Cameron <jic23@kernel.org>
To: David Jander <david@protonic.nl>
Cc: "Uwe Kleine-König" <u.kleine-koenig@baylibre.com>,
linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org,
"Jonathan Corbet" <corbet@lwn.net>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
devicetree@vger.kernel.org, linux-doc@vger.kernel.org,
"Nuno Sa" <nuno.sa@analog.com>,
"Oleksij Rempel" <o.rempel@pengutronix.de>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>
Subject: Re: [RFC PATCH 1/7] drivers: Add motion control subsystem
Date: Sun, 9 Mar 2025 17:32:50 +0000 [thread overview]
Message-ID: <20250309173250.68956c88@jic23-huawei> (raw)
In-Reply-To: <20250306102540.7f0f6146@erd003.prtnl>
On Thu, 6 Mar 2025 10:25:40 +0100
David Jander <david@protonic.nl> wrote:
> On Thu, 6 Mar 2025 00:21:22 +0100
> Uwe Kleine-König <u.kleine-koenig@baylibre.com> wrote:
>
> > Hello David,
> >
> > On Wed, Mar 05, 2025 at 04:40:45PM +0100, David Jander wrote:
> > > On Fri, 28 Feb 2025 17:44:27 +0100
> > > Uwe Kleine-König <u.kleine-koenig@baylibre.com> wrote:
> > > > On Thu, Feb 27, 2025 at 05:28:17PM +0100, David Jander wrote:
> > > > [...]
> > > > > +static int motion_open(struct inode *inode, struct file *file)
> > > > > +{
> > > > > + int minor = iminor(inode);
> > > > > + struct motion_device *mdev = NULL, *iter;
> > > > > + int err;
> > > > > +
> > > > > + mutex_lock(&motion_mtx);
> > > >
> > > > If you use guard(), error handling gets a bit easier.
> > >
> > > This looks interesting. I didn't know about guard(). Thanks. I see the
> > > benefits, but in some cases it also makes the locked region less clearly
> > > visible. While I agree that guard() in this particular place is nice,
> > > I'm hesitant to try and replace all mutex_lock()/_unlock() calls with guard().
> > > Let me know if my assessment of the intended use of guard() is incorrect.
> >
> > I agree that guard() makes it harder for non-trivial functions to spot
> > the critical section. In my eyes this is outweight by not having to
> > unlock in all exit paths, but that might be subjective. Annother
> > downside of guard is that sparse doesn't understand it and reports
> > unbalanced locking.
>
> What I was referring to, and what I want to know is, is it okay to mix guard()
> with lock/unlock? I.e. Use guard() when there are multiple exit paths involved
> and revert back to simple lock/unlock if it is just to encase a handful of
> non-exiting operations?
Mixing is fine. In some cases scoped_guard() can also make things
clearer though at the cost of increased indent.
> >
> > Sad, so a userspace process still has to know some internal things about
> > the motor it drives. :-\
>
> Unfortunately that is almost impossible to avoid entirely.
> You can replace one stepper motor driver with another that might have
> different micro-stepping subdivision, by looking at struct
> mot_capabilities.subdiv, but a simple brushed DC motor just isn't able to
> replace a stepper motor in all but the most trivial applications. I also think
> that burdening the kernel with all sorts of complicated math to model the
> mechanical conversion factors involved in anything that's connected to the
> motor drive shaft is overkill. As well as trying to emulate all missing
> capabilities from a motion device that is lacking that functionality natively.
>
> So just like in IIO you cannot just replace one ADC with any other, in LMC you
> also cannot replace any device with any other.
>
> That's why there is struct mot_capabilities and MOT_IOCTL_GET_CAPA. It enables
> user-space to optionally support different devices more easily. It is probably
> best used in conjunction with a LMC user-space library, although I don't want
> to rely on such a library for being able to use LMC. There is some middle
> ground here I guess... just like in IIO.
>
> One thing I could try to improve though, is to include some additional
> information in struct mot_capabilities that tells something more about the
> nature of the used units, just like the speed_conv and accel_conv constants do
> for time conversion. Something that can be placed in the device tree (possibly
> in a motor child-node connected to the motor-controller) that contains some
> conversion constant for distance. That way, if one were to (for example)
> replace a stepper motor with a BLDC motor + encoder in a new hardware
> revision, this constant could be used to make the units backwards compatible.
>
> As background information: A stepper motor controller counts distance in steps
> and/or micro-steps. There are mot_capabilities.subdiv micro-steps in each
> step. The amount of angle the actual motor shaft advances with each whole step
> depends on the motor construction and is often 200 steps per revolution (1.8
> degrees), but can vary from 4 to 400 steps per revolution depending on the
> motor. So it is not only the controller that matters but also the type of
> motor. This suggests the need of motor sub-nodes in the device-tree if one
> wanted to extend the hardware knowledge further down from the motor driver.
> But then there are gear boxes, pulleys, etc... it's basically conversion
> factors all the way down. How many of them is sensible to bother the kernel
> with?
I'd have a motor description that is sufficient to be able to swap steppers
between hardware versions and present sufficient info to userspace to allow
a library to hide those differences. That description might well be of
an aggregate device consisting of motor and whatever mechanics to get you
to the point you care about (actuator motion). Hardest bit will be documenting
'where' in the system the DT is describing.
It's not that heavily used but we do have analog front ends in IIO that
provide a not dissimilar thing to the various potential mechanisms here.
Jonathan
>
> Best regards,
>
next prev parent reply other threads:[~2025-03-09 17:33 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-27 16:28 [RFC PATCH 0/7] Add Linux Motion Control subsystem David Jander
2025-02-27 16:28 ` [RFC PATCH 1/7] drivers: Add motion control subsystem David Jander
2025-02-28 16:44 ` Uwe Kleine-König
2025-03-05 15:40 ` David Jander
2025-03-05 23:21 ` Uwe Kleine-König
2025-03-06 7:18 ` Greg Kroah-Hartman
2025-03-06 8:20 ` David Jander
2025-03-06 9:03 ` Greg Kroah-Hartman
2025-03-06 9:34 ` David Jander
2025-03-06 13:39 ` Greg Kroah-Hartman
2025-03-06 14:25 ` David Jander
2025-03-06 14:54 ` Greg Kroah-Hartman
2025-03-06 9:25 ` David Jander
2025-03-09 17:32 ` Jonathan Cameron [this message]
2025-03-10 8:45 ` David Jander
2025-02-28 22:36 ` David Lechner
2025-03-03 8:36 ` David Jander
2025-03-03 11:01 ` Pavel Pisa
2025-03-03 16:04 ` David Jander
2025-02-27 16:28 ` [RFC PATCH 2/7] motion: Add ADI/Trinamic TMC5240 stepper motor controller David Jander
2025-02-27 16:28 ` [RFC PATCH 3/7] motion: Add simple-pwm.c PWM based DC motor controller driver David Jander
2025-02-27 16:28 ` [RFC PATCH 4/7] Documentation: Add Linux Motion Control documentation David Jander
2025-02-27 16:37 ` Jonathan Corbet
2025-02-28 13:02 ` David Jander
2025-02-28 14:42 ` Jonathan Corbet
2025-02-28 15:06 ` David Jander
2025-02-27 16:28 ` [RFC PATCH 5/7] dt-bindings: motion: Add common motion device properties David Jander
2025-02-28 7:06 ` Krzysztof Kozlowski
2025-02-28 7:13 ` Krzysztof Kozlowski
2025-02-27 16:28 ` [RFC PATCH 6/7] dt-bindings: motion: Add adi,tmc5240 bindings David Jander
2025-02-28 7:11 ` Krzysztof Kozlowski
2025-02-28 8:48 ` David Jander
2025-02-28 9:35 ` Krzysztof Kozlowski
2025-02-28 9:51 ` David Jander
2025-02-28 14:01 ` Krzysztof Kozlowski
2025-02-28 22:38 ` David Lechner
2025-03-03 11:22 ` David Jander
2025-03-03 12:28 ` David Lechner
2025-03-03 13:18 ` David Jander
2025-02-27 16:28 ` [RFC PATCH 7/7] dt-bindings: motion: Add motion-simple-pwm bindings David Jander
2025-02-27 17:38 ` Rob Herring (Arm)
2025-02-28 7:12 ` Krzysztof Kozlowski
2025-02-28 9:22 ` David Jander
2025-02-28 9:37 ` Krzysztof Kozlowski
2025-02-28 10:09 ` David Jander
2025-02-28 15:18 ` Uwe Kleine-König
2025-03-03 10:53 ` Maud Spierings
2025-03-03 11:40 ` David Jander
2025-03-03 14:18 ` Krzysztof Kozlowski
2025-03-03 16:09 ` David Jander
2025-02-28 22:41 ` David Lechner
2025-03-03 12:54 ` David Jander
2025-02-28 9:34 ` [RFC PATCH 0/7] Add Linux Motion Control subsystem Pavel Pisa
2025-02-28 9:35 ` Pavel Pisa
2025-02-28 11:57 ` David Jander
2025-02-28 15:23 ` Pavel Pisa
2025-03-03 10:45 ` David Jander
2025-02-28 22:36 ` David Lechner
2025-03-03 8:28 ` David Jander
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=20250309173250.68956c88@jic23-huawei \
--to=jic23@kernel.org \
--cc=conor+dt@kernel.org \
--cc=corbet@lwn.net \
--cc=david@protonic.nl \
--cc=devicetree@vger.kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=krzk+dt@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=o.rempel@pengutronix.de \
--cc=robh@kernel.org \
--cc=u.kleine-koenig@baylibre.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