mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2 1/4] aiodev: Name channels with device instance name
@ 2020-09-25 23:36 Trent Piepho
  0 siblings, 0 replies; 3+ messages in thread
From: Trent Piepho @ 2020-09-25 23:36 UTC (permalink / raw)
  To: barebox; +Cc: Trent Piepho

When dynamically assigning device names, an aiodev's name will be
"aiodev" and an index, not part of the name string itself, will be
allocated dynamically.  These are combined to register a device with a
name like "aiodev0" or "aiodev1".

The shell environment variables use the device name, so one might use
"${aiodev0.in_value0_mV}" and "${aiodev1.in_value0_mV}".

However, the channel names that are used with aiochannel_get_by_name()
just use the aiodev's name and channel name.  So channel 0 of the 1st
aiodev would be "aiodev.in_value0_mV" and the 2nd aiodev would use the
same name.

Change the channel naming to use the device instance name, e.g.
"aiodev0", rather than the aiodev's base name.  This makes the names
used aiochannel_get_by_name() match the environment variable names and
also avoids duplicate names with more than one dynamically allocated
aiodev.

Rename aiochannel_get_by_name() to aiochannel_by_name() so that any out
of tree boards that use it will fail to compile, since they now need to
pass in a different name.

Signed-off-by: Trent Piepho <trent.piepho@synapse.com>
---
Changes in v2:
  * Rename aiochannel_get_by_name()

 drivers/aiodev/core.c | 4 ++--
 include/aiodev.h      | 3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/aiodev/core.c b/drivers/aiodev/core.c
index b8428346a..7240de2c4 100644
--- a/drivers/aiodev/core.c
+++ b/drivers/aiodev/core.c
@@ -24,7 +24,7 @@
 LIST_HEAD(aiodevices);
 EXPORT_SYMBOL(aiodevices);
 
-struct aiochannel *aiochannel_get_by_name(const char *name)
+struct aiochannel *aiochannel_by_name(const char *name)
 {
 	struct aiodevice *aiodev;
 	int i;
@@ -131,7 +131,7 @@ int aiodevice_register(struct aiodevice *aiodev)
 				  aiochannel_param_get_value,
 				  &aiochan->value, "%d", aiochan);
 
-		aiochan->name = xasprintf("%s.%s", aiodev->name, name);
+		aiochan->name = xasprintf("%s.%s", dev_name(&aiodev->dev), name);
 
 		free(name);
 	}
diff --git a/include/aiodev.h b/include/aiodev.h
index 65d817f29..d55771567 100644
--- a/include/aiodev.h
+++ b/include/aiodev.h
@@ -31,7 +31,8 @@ struct aiodevice {
 int aiodevice_register(struct aiodevice *aiodev);
 
 struct aiochannel *aiochannel_get(struct device_d *dev, int index);
-struct aiochannel *aiochannel_get_by_name(const char *name);
+/* Find aiochannel by channel name, e.g. "aiodev0.in_value0_mV" */
+struct aiochannel *aiochannel_by_name(const char *name);
 
 int aiochannel_get_value(struct aiochannel *aiochan, int *value);
 int aiochannel_get_index(struct aiochannel *aiochan);
-- 
2.26.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread
* [PATCH v2 1/4] aiodev: Name channels with device instance name
@ 2020-09-25 23:43 Trent Piepho
  2020-09-29  7:04 ` Sascha Hauer
  0 siblings, 1 reply; 3+ messages in thread
From: Trent Piepho @ 2020-09-25 23:43 UTC (permalink / raw)
  To: barebox; +Cc: Trent Piepho

When dynamically assigning device names, an aiodev's name will be
"aiodev" and an index, not part of the name string itself, will be
allocated dynamically.  These are combined to register a device with a
name like "aiodev0" or "aiodev1".

The shell environment variables use the device name, so one might use
"${aiodev0.in_value0_mV}" and "${aiodev1.in_value0_mV}".

However, the channel names that are used with aiochannel_get_by_name()
just use the aiodev's name and channel name.  So channel 0 of the 1st
aiodev would be "aiodev.in_value0_mV" and the 2nd aiodev would use the
same name.

Change the channel naming to use the device instance name, e.g.
"aiodev0", rather than the aiodev's base name.  This makes the names
used aiochannel_get_by_name() match the environment variable names and
also avoids duplicate names with more than one dynamically allocated
aiodev.

Rename aiochannel_get_by_name() to aiochannel_by_name() so that any out
of tree boards that use it will fail to compile, since they now need to
pass in a different name.

Signed-off-by: Trent Piepho <trent.piepho@synapse.com>
---
Changes in v2:
  * Rename aiochannel_get_by_name()

 drivers/aiodev/core.c | 4 ++--
 include/aiodev.h      | 3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/aiodev/core.c b/drivers/aiodev/core.c
index b8428346a..7240de2c4 100644
--- a/drivers/aiodev/core.c
+++ b/drivers/aiodev/core.c
@@ -24,7 +24,7 @@
 LIST_HEAD(aiodevices);
 EXPORT_SYMBOL(aiodevices);
 
-struct aiochannel *aiochannel_get_by_name(const char *name)
+struct aiochannel *aiochannel_by_name(const char *name)
 {
 	struct aiodevice *aiodev;
 	int i;
@@ -131,7 +131,7 @@ int aiodevice_register(struct aiodevice *aiodev)
 				  aiochannel_param_get_value,
 				  &aiochan->value, "%d", aiochan);
 
-		aiochan->name = xasprintf("%s.%s", aiodev->name, name);
+		aiochan->name = xasprintf("%s.%s", dev_name(&aiodev->dev), name);
 
 		free(name);
 	}
diff --git a/include/aiodev.h b/include/aiodev.h
index 65d817f29..d55771567 100644
--- a/include/aiodev.h
+++ b/include/aiodev.h
@@ -31,7 +31,8 @@ struct aiodevice {
 int aiodevice_register(struct aiodevice *aiodev);
 
 struct aiochannel *aiochannel_get(struct device_d *dev, int index);
-struct aiochannel *aiochannel_get_by_name(const char *name);
+/* Find aiochannel by channel name, e.g. "aiodev0.in_value0_mV" */
+struct aiochannel *aiochannel_by_name(const char *name);
 
 int aiochannel_get_value(struct aiochannel *aiochan, int *value);
 int aiochannel_get_index(struct aiochannel *aiochan);
-- 
2.26.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-09-29  7:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-25 23:36 [PATCH v2 1/4] aiodev: Name channels with device instance name Trent Piepho
2020-09-25 23:43 Trent Piepho
2020-09-29  7:04 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox