iio: inkern: make interface firmware agnostic
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 17 lines · Nuno Sá
The main goal of this patchset is to convert the iio inkern interface to be firmware agnostic.
In the process of doing it, I discover the bug solved in patch 1/6 which also served as motivation for patch 2/6.
Note that patch 3/6 is touching multiple files at once since the changes are very simple. I can separate it in several patches if that is preferred for better tagging though.
The same can be said for patch 5/6 even though in this case it will be more cumbersome to separate it in several patches (we will need to temporarily support both options; convert each driver separately; remove of). I think the changes in the drivers are simple enough that we can have it like it is now...
Quoted 5 lines
Lastly, this is only compile tested with allyesconfig for arm and arm64. While I surely can come up with some dummy devices to make sure I can still properly get IIO channels, having proper tested-by tags on platforms relying on this interface would be very appreciated (and I suspect Jonathan will require it).
Thanks! I will definitely have a look into it later on.
Quoted 41 lines
Nuno Sá (6):
iio: inkern: fix return value indevm_of_iio_channel_get_by_name()
iio: inkern: only return error codes in iio_channel_get_*() APIs
iio: treewide: explicitly add proper header files
iio: inkern: splitof_iio_channel_get_by_name()
iio: inkern: move to fwnode properties
iio: inkern: fix coding style warningsdrivers/iio/adc/ab8500-gpadc.c | 7 +- drivers/iio/adc/ad7606.c | 1 + drivers/iio/adc/ad7606_par.c | 1 + drivers/iio/adc/at91-sama5d2_adc.c | 7 +- drivers/iio/adc/berlin2-adc.c | 2 + drivers/iio/adc/imx7d_adc.c | 1 + drivers/iio/adc/imx8qxp-adc.c | 1 + drivers/iio/adc/ingenic-adc.c | 10 +- drivers/iio/adc/mp2629_adc.c | 1 + drivers/iio/adc/mt6360-adc.c | 1 + drivers/iio/adc/npcm_adc.c | 1 + drivers/iio/adc/qcom-pm8xxx-xoadc.c | 14 +- drivers/iio/adc/qcom-spmi-adc5.c | 13 +- drivers/iio/adc/qcom-spmi-vadc.c | 7 +- drivers/iio/adc/rzg2l_adc.c | 1 + drivers/iio/adc/stm32-adc.c | 7 +- .../cros_ec_sensors/cros_ec_lid_angle.c | 1 + .../common/cros_ec_sensors/cros_ec_sensors.c | 1 + drivers/iio/dac/stm32-dac.c | 2 + drivers/iio/dac/vf610_dac.c | 1 + drivers/iio/humidity/hts221_buffer.c | 1 + drivers/iio/inkern.c | 240 ++++++++++-------- drivers/iio/light/cros_ec_light_prox.c | 1 + drivers/iio/pressure/cros_ec_baro.c | 1 + drivers/iio/trigger/stm32-lptimer-trigger.c | 1 + drivers/thermal/qcom/qcom-spmi-adc-tm5.c | 3 +- include/linux/iio/consumer.h | 28 +- include/linux/iio/iio.h | 7 +- 28 files changed, 200 insertions(+), 162 deletions(-)--
2.36.1
Signature · 2 lines
With Best Regards, Andy Shevchenko
On Thu, Jun 2, 2022 at 4:03 PM Nuno Sá <[email protected]> wrote:
You have in the addresses:
Gwendal Grignou --cc=Dmitry Baryshkov <[email protected]@linaro.org>,
I would recommend using my "smart" script [1] that makes the list automatically.
[1]: https://github.com/andy-shev/home-bin-tools/blob/master/ge2maintainer.sh
P.S. Patches are welcome as usual :)
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 8 lines · Andy Shevchenko
On Thu, Jun 2, 2022 at 4:03 PM Nuno Sá <[email protected]> wrote:
You have in the addresses:
Gwendal Grignou --cc=Dmitry Baryshkov <[email protected]@linaro.org>,
Oh crap :facepalm:
Quoted 6 lines
I would recommend using my "smart" script [1] that makes the list automatically.
[1]:
https://github.com/andy-shev/home-bin-tools/blob/master/ge2maintainer.sh
Interesting, though I'm giving a try to git-publish [1] and integrating it in your script might not make sense. Still there's definitely some stuff that I can use from your script to keep me doing this again.
That said, What's worst is that, somehow, the patches still did not make it into the mailing list. I will wait a bit longer and try to resend them...
[1]: https://github.com/stefanha/git-publish
- Nuno Sá
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [RFC PATCH 1/6] iio: inkern: fix return value in devm_of_iio_channel_get_by_name()
Quoted 8 lines · Nuno Sá
of_iio_channel_get_by_name()can either return NULL or an error pointer so that only doingIS_ERR()is not enough. Fix it by checking the NULL pointer case and return-ENODEVin that case. Note this is done like this so that users of the function (which only check for error pointers) do not need to be changed. This is not ideal since we are losing error codes and as such, in a follow up change, things will be unified so thatof_iio_channel_get_by_name()only returns error codes.
...
Review
Quoted 7 lines
channel = of_iio_channel_get_by_name(np, channel_name);(quoted diff) +4
-1- if (IS_ERR(channel)) + if (IS_ERR_OR_NULL(channel)) { + if (!channel) + return ERR_PTR(-ENODEV); return channel; + }
Why not make it not nested, i.e. just adding two lines after the existing check? if (!channel)
return -ENODEV;
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [RFC PATCH 1/6] iio: inkern: fix return value in devm_of_iio_channel_get_by_name()
Quoted 25 lines · Andy Shevchenko
Quoted 13 lines · Nuno Sá
of_iio_channel_get_by_name()can either return NULL or an error pointer
so that only doingIS_ERR()is not enough. Fix it by checking the NULL
pointer case and return-ENODEVin that case. Note this is done like this
so that users of the function (which only check for error pointers) do
not need to be changed. This is not ideal since we are losing error codes
and as such, in a follow up change, things will be unified so thatof_iio_channel_get_by_name()only returns error codes....
Quoted 7 lines
channel =
of_iio_channel_get_by_name(np, channel_name); - if (IS_ERR(channel))
+ if (IS_ERR_OR_NULL(channel)) {
+ if (!channel)
+ returnERR_PTR(-ENODEV); return channel;
+ }
Quoted 6 lines
Why not make it not nested, i.e. just adding two lines after the existing check?
if (!channel)
return-ENODEV;
I see, well yeah I guess I can do it so the diff is even smaller...
- Nuno Sá
Jonathan Cameron
maintainerRe: [RFC PATCH 1/6] iio: inkern: fix return value in devm_of_iio_channel_get_by_name()
Quoted 26 lines · On Fri, 03 Jun 2022 14:36:15 +0200 Nuno Sá <[email protected]> wrote:
Quoted 25 lines · Andy Shevchenko
Quoted 13 lines · Nuno Sá
of_iio_channel_get_by_name()can either return NULL or an error pointer
so that only doingIS_ERR()is not enough. Fix it by checking the NULL
pointer case and return-ENODEVin that case. Note this is done like this
so that users of the function (which only check for error pointers) do
not need to be changed. This is not ideal since we are losing error codes
and as such, in a follow up change, things will be unified so thatof_iio_channel_get_by_name()only returns error codes....
Quoted 7 lines
channel =
of_iio_channel_get_by_name(np, channel_name); - if (IS_ERR(channel))
+ if (IS_ERR_OR_NULL(channel)) {
+ if (!channel)
+ returnERR_PTR(-ENODEV); return channel;
+ }
Quoted 8 lines
Quoted 6 lines
Why not make it not nested, i.e. just adding two lines after the existing check?
if (!channel)
return-ENODEV;I see, well yeah I guess I can do it so the diff is even smaller...
I'd prefer the way Andy suggested as well due to the slightly simpler control flow.
Thanks,
Jonathan
Quoted 3 lines
- Nuno Sá
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [RFC PATCH 3/6] iio: treewide: explicitly add proper header files
Quoted 5 lines · Nuno Sá
Apparently some drivers are relying on the fact that
iio.hincludesof.hthat in turn includes all the headers these drivers were relying on. Fix it so that in a following patch we can make iio firmware agnostic and removeof.hfromiio.h.
I believe it should be split on driver-basis.
...
drivers/iio/adc/ingenic-adc.c line 22
Quoted 8 lines
drivers/iio/adc/ingenic-adc.c +2
-0@@ -18,6 +18,8 @@#include <linux/mod_devicetable.h> #include <linux/mutex.h> #include <linux/platform_device.h> +#include <linux/property.h> +#include <linux/of.h>
Ordering?
Signature · 2 lines
With Best Regards, Andy Shevchenko
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [RFC PATCH 4/6] iio: inkern: split of_iio_channel_get_by_name()
Quoted 5 lines · Nuno Sá
This change splits
of_iio_channel_get_by_name()so that it decouples looking for channels in the current node from looking in it's parents nodes. This will be helpful when moving to fwnode properties where we need to release the handles when looking for channels in parent's nodes.
...
Quoted 6 lines
(quoted diff) +6
-0+ /* + * For named iio channels, first look up the name in the + * "io-channel-names" property. If it cannot be found, the + * index will be an error code, and of_iio_channel_get() + * will fail. + */
Review
Quoted 10 lines
(quoted diff) +9
-0+ if (name) + index = of_property_match_string(np, "io-channel-names", name); + + chan = of_iio_channel_get(np, index); + if (!IS_ERR(chan) || PTR_ERR(chan) == -EPROBE_DEFER) { + *parent_lookup = false; + } else if (name && index >= 0) { + pr_err("ERROR: could not get IIO channel %pOF:%s(%i)\n", + np, name ? name : "", index);
It's one TAB less now, means you may compress more on one line, including replacing
name ? name : "" --> name ?: ""
Quoted 2 lines
(quoted diff) +2
-0+ *parent_lookup = false; + }
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [RFC PATCH 4/6] iio: inkern: split of_iio_channel_get_by_name()
Quoted 28 lines · Andy Shevchenko
Quoted 9 lines · Nuno Sá
This change splits
of_iio_channel_get_by_name()so that it decouples
looking for channels in the current node from looking in it's parents
nodes. This will be helpful when moving to fwnode properties where we
need to release the handles when looking for channels in parent's nodes....
Quoted 14 lines
+ /*
+ * For named iio channels, first look up the name in the + * "io-channel-names" property. If it cannot be found, the + * index will be an error code, andof_iio_channel_get()+ * will fail.
+ */
+ if (name)
+ index =of_property_match_string(np, "io-channel- names", name);
+
+ chan =of_iio_channel_get(np, index);
+ if (!IS_ERR(chan) ||PTR_ERR(chan)== -EPROBE_DEFER) { +*parent_lookup= false;
+ } else if (name && index >= 0) {
Quoted 8 lines
Quoted 3 lines
+ pr_err("ERROR: could not get IIO channel %pOF:%s(%i)\n",
+ np, name ? name : "", index);It's one TAB less now, means you may compress more on one line, including replacing
name ? name : "" --> name ?: ""
I can taking the 100col limit... AFAIR, Jonathan wants to stick to the old limit unless readability is severely impacted by it which I don't think it' the case here.
That said, I'm more than fine in using the new limit as long as Jonathan agrees with it.
Quoted 1 line
- Nuno Sá
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [RFC PATCH 5/6] iio: inkern: move to fwnode properties
Quoted 6 lines · Nuno Sá
This moves the IIO in kernel interface to use fwnode properties and thus be firmware agnostic.
All the users had to be naturally updated to the new interface exposed by IIO.
I think you may split this in an easy way, i.e. convert core to fwnode, while providing inliners for of_node cases (like it's done in IRQ domain) and then remove them after conversion.
I think of_xlate is not needed to be touched at all. Let it die with OF altogether. Yes, it won't be fully OF-independent, but it will down the scope of the next change where you can convert of_xlate to something agnostic.
...
drivers/iio/adc/ab8500-gpadc.c line 42
Quoted 7 lines
drivers/iio/adc/ab8500-gpadc.c +1
-0@@ -39,6 +39,7 @@#include <linux/slab.h> #include <linux/mfd/abx500.h> #include <linux/mfd/abx500/ab8500.h> +#include <linux/fwnode.h>
Ordering.
...
drivers/iio/adc/qcom-pm8xxx-xoadc.c line 24
Quoted 7 lines
drivers/iio/adc/qcom-pm8xxx-xoadc.c +1
-0@@ -21,6 +21,7 @@#include <linux/init.h> #include <linux/interrupt.h> #include <linux/regulator/consumer.h> +#include <linux/fwnode.h>
Ordering?
...
drivers/iio/adc/qcom-pm8xxx-xoadc.c line 26
Quoted 2 lines
drivers/iio/adc/qcom-pm8xxx-xoadc.c +0
-0* @consumer_channel: Unique name to identify the channel on the consumer * side. This typically describes the channels use within
used / usage ?
...
Quoted 2 lines
drivers/iio/adc/qcom-pm8xxx-xoadc.c +0
-0* @consumer_channel: Unique name to identify the channel on the consumer * side. This typically describes the channels use within
Ditto.
Quoted 1 line
* the consumer. E.g. '
battery_voltage'
...
include/linux/iio/iio.h line 13
Quoted 9 lines
include/linux/iio/iio.h +0
-1@@ -10,13 +10,14 @@#include <linux/device.h> #include <linux/cdev.h> #include <linux/iio/types.h> -#include <linux/of.h>
You may split this change easily since there is nothing from of.h in use. Just add forward declaration as you have done, but for the OF case.
...
That said, I think what you need is to split this series to three logical parts:
1) shuffle header inclusions around so, iio.h will use forward declaration (on driver basis);
2) convert inkern.c to fwnode while providing OF wrappers (to_of_node() helps);
3) convert of_xlate (on driver basis it might be tricky, up to you).
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [RFC PATCH 5/6] iio: inkern: move to fwnode properties
Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Nuno Sá
This moves the IIO in kernel interface to use fwnode properties and thus
be firmware agnostic.
Quoted 8 lines
Quoted 3 lines
All the users had to be naturally updated to the new interface exposed by
IIO.I think you may split this in an easy way, i.e. convert core to fwnode, while providing inliners for
of_nodecases (like it's done in IRQ domain) and then remove them after conversion.
I see, in our case that might be really simple as we only have one user of devm_of_iio_channel_get_by_name() which is the only api directly using OF. of_iio_channel_get_by_name() has no users and all the other public APIs use 'struct device' so we can do the conversion internally...
Quoted 8 lines
I think
of_xlateis not needed to be touched at all. Let it die with OF altogether. Yes, it won't be fully OF-independent, but it will down
the scope of the next change where you can convertof_xlateto something agnostic....
Quoted 10 lines
drivers/iio/adc/ab8500-gpadc.c line 42
Quoted 7 lines
drivers/iio/adc/ab8500-gpadc.c +1
-0@@ -39,6 +39,7 @@ #include <linux/slab.h> #include <linux/mfd/abx500.h> #include <linux/mfd/abx500/ab8500.h> +#include <linux/fwnode.h> Ordering.
The ordering is completely wrong anyways. So, I did not cared about ordering in drivers where it was already bad. Don't mind to fix it while adding the missing headers (if acceptable).
Quoted 48 lines
...
drivers/iio/adc/qcom-pm8xxx-xoadc.c line 24
Quoted 7 lines
drivers/iio/adc/qcom-pm8xxx-xoadc.c +1
-0@@ -21,6 +21,7 @@ #include <linux/init.h> #include <linux/interrupt.h> #include <linux/regulator/consumer.h> +#include <linux/fwnode.h> Ordering?
...
Quoted 4 lines
drivers/iio/adc/qcom-pm8xxx-xoadc.c +0
-0* @consumer_channel: Unique name to identify the channel on theconsumer
* side. This typically describes the channels use withinused / usage ?
...
Quoted 4 lines
* @consumer_channel: Unique name to identify the channel on the consumer
* side. This typically describes the channels use withinDitto.
Quoted 1 line
* the consumer. E.g. '
battery_voltage'...
include/linux/iio/iio.h line 13
Quoted 9 lines
include/linux/iio/iio.h +0
-1@@ -10,13 +10,14 @@ #include <linux/device.h> #include <linux/cdev.h> #include <linux/iio/types.h> -#include <linux/of.h> You may split this change easily since there is nothing from
of.hin use. Just add forward declaration as you have done, but for the OF case.
Quoted 8 lines
...
That said, I think what you need is to split this series to three logical parts:
1) shuffle header inclusions around so,iio.hwill use forward declaration (on driver basis);
2) convertinkern.cto fwnode while providing OF wrappers (to_of_node()helps);
Just to be clear, we should still add an fwnode_xlate() callback? So we have both temporarily and if some new driver needs this interface it can already use it instead of of_xlate...
Quoted 2 lines
3) convert
of_xlate(on driver basis it might be tricky, up to you).
Yeah, I might see how easy it is to fully convert the drivers using of_xlate. If easy enough, I'll probably do it...
- Nuno Sá
Re: [RFC PATCH 5/6] iio: inkern: move to fwnode properties
Quoted 2 lines · Nuno Sá
Quoted 1 line · Andy Shevchenko
On Thu, Jun 2, 2022 at 4:04 PM Nuno Sá <[email protected]> wrote:
...
Quoted 9 lines
Quoted 3 lines
I think you may split this in an easy way, i.e. convert core to fwnode, while providing inliners for
of_nodecases (like it's done in IRQ domain) and then remove them after conversion.I see, in our case that might be really simple as we only have one user of
devm_of_iio_channel_get_by_name()which is the only api directly using OF.of_iio_channel_get_by_name()has no users and all the other public APIs use 'struct device' so we can do the conversion internally...
Even better than I expected!
...
Quoted 10 lines
Quoted 6 lines
That said, I think what you need is to split this series to three logical parts:
1) shuffle header inclusions around so,iio.hwill use forward declaration (on driver basis);
2) convertinkern.cto fwnode while providing OF wrappers (to_of_node()helps);Just to be clear, we should still add an
fwnode_xlate()callback? So we have both temporarily and if some new driver needs this interface it can already use it instead ofof_xlate...
No, I mean to leave a callback to be OF-specific and pass fwnode with to_of_node(). Then convert it separately either on per driver basis (if possible and makes sense) or altogether.
Quoted 4 lines
Quoted 1 line
3) convert
of_xlate(on driver basis it might be tricky, up to you).Yeah, I might see how easy it is to fully convert the drivers using
of_xlate. If easy enough, I'll probably do it...
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [RFC PATCH 5/6] iio: inkern: move to fwnode properties
In reply to a message not in the archiveOn Thu, Jun 2, 2022 at 4:04 PM Nuno Sá <[email protected]> wrote:
...
Review
Quoted 5 lines
(quoted diff) +3
-0+ parent = fwnode_get_parent(fwnode); + while (parent) { + parent = fwnode_get_next_parent(parent); }
Forgot to mention:
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [RFC PATCH 5/6] iio: inkern: move to fwnode properties
Quoted 7 lines · Andy Shevchenko
On Thu, Jun 2, 2022 at 4:04 PM Nuno Sá <[email protected]> wrote:
...
Quoted 2 lines
+ parent =
fwnode_get_parent(fwnode);
+ while (parent) {
Quoted 7 lines
Quoted 2 lines
+ parent =
fwnode_get_next_parent(parent); }Forgot to mention:
I did looked for something like that but it's still not in the IIO testing tree.
(still I actually followed that patchset but completely forgot about the helper)
- Nuno Sá
Re: [RFC PATCH 5/6] iio: inkern: move to fwnode properties
Quoted 2 lines · Nuno Sá
Quoted 1 line · Andy Shevchenko
On Thu, Jun 2, 2022 at 4:04 PM Nuno Sá <[email protected]> wrote:
...
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
(quoted diff) +3
-0+ parent = fwnode_get_parent(fwnode); + while (parent) { + parent = fwnode_get_next_parent(parent); }
Quoted 6 lines
Quoted 3 lines
Forgot to mention:
I did looked for something like that but it's still not in the IIO testing tree.
Now it's in the upstream, which means it is just a matter of time to appear in IIO testing.
Quoted 2 lines
(still I actually followed that patchset but completely forgot about the helper)
Signature · 2 lines
With Best Regards, Andy Shevchenko