When matching a device, only the vendor ID and product ID are used. As
all bundles in an interface share the same VID and PID, there is no way
to differentiate between two bundles, and they are forced to use the
same driver.
To allow using several vendor bundles in the same device, include the
bundle ID when matching. The assumption here is that bundle IDs are
stable across the lifespan of a product and never change.
The goal of this change is to open the discussion. Greybus standardizes
a bunch of protocols like GPIO, SPI, etc. but also has provisioning for
vendor bundle and protocol. There is only one ID reserved for vendor,
0xFF, so the question is did Greybus ever envision supporting several
vendor bundles, or one vendor bundle with several vendor cports in it?
Or the assumption always was that there could be at most only vendor
cport?
Signed-off-by: Damien Riégel <damien.riegel@silabs.com>
---
drivers/greybus/core.c | 4 ++++
include/linux/greybus.h | 7 ++++---
include/linux/greybus/greybus_id.h | 2 ++
3 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/drivers/greybus/core.c b/drivers/greybus/core.c
index 313eb65cf70..a4968a24a08 100644
--- a/drivers/greybus/core.c
+++ b/drivers/greybus/core.c
@@ -68,6 +68,10 @@ static bool greybus_match_one_id(struct gb_bundle *bundle,
(id->product != bundle->intf->product_id))
return false;
+ if ((id->match_flags & GREYBUS_ID_MATCH_BUNDLE_ID) &&
+ (id->bundle_id != bundle->id))
+ return false;
+
if ((id->match_flags & GREYBUS_ID_MATCH_CLASS) &&
(id->class != bundle->class))
return false;
diff --git a/include/linux/greybus.h b/include/linux/greybus.h
index 4d58e27ceaf..9c29a1099a4 100644
--- a/include/linux/greybus.h
+++ b/include/linux/greybus.h
@@ -38,12 +38,13 @@
#define GREYBUS_VERSION_MINOR 0x01
#define GREYBUS_ID_MATCH_DEVICE \
- (GREYBUS_ID_MATCH_VENDOR | GREYBUS_ID_MATCH_PRODUCT)
+ (GREYBUS_ID_MATCH_VENDOR | GREYBUS_ID_MATCH_PRODUCT | GREYBUS_ID_MATCH_BUNDLE_ID)
-#define GREYBUS_DEVICE(v, p) \
+#define GREYBUS_DEVICE(v, p, id) \
.match_flags = GREYBUS_ID_MATCH_DEVICE, \
.vendor = (v), \
- .product = (p),
+ .product = (p), \
+ .bundle_id = (id),
#define GREYBUS_DEVICE_CLASS(c) \
.match_flags = GREYBUS_ID_MATCH_CLASS, \
diff --git a/include/linux/greybus/greybus_id.h b/include/linux/greybus/greybus_id.h
index f4c8440093e..3e0728e1f44 100644
--- a/include/linux/greybus/greybus_id.h
+++ b/include/linux/greybus/greybus_id.h
@@ -15,6 +15,7 @@ struct greybus_bundle_id {
__u32 vendor;
__u32 product;
__u8 class;
+ __u8 bundle_id;
kernel_ulong_t driver_info __aligned(sizeof(kernel_ulong_t));
};
@@ -23,5 +24,6 @@ struct greybus_bundle_id {
#define GREYBUS_ID_MATCH_VENDOR BIT(0)
#define GREYBUS_ID_MATCH_PRODUCT BIT(1)
#define GREYBUS_ID_MATCH_CLASS BIT(2)
+#define GREYBUS_ID_MATCH_BUNDLE_ID BIT(3)
#endif /* __LINUX_GREYBUS_ID_H */
--
2.49.0
On Fri, Jul 04, 2025 at 08:40:35PM -0400, Damien Riégel wrote: > When matching a device, only the vendor ID and product ID are used. It shouldn't be that way. That was not the intention. > As > all bundles in an interface share the same VID and PID, there is no way > to differentiate between two bundles, and they are forced to use the > same driver. > > To allow using several vendor bundles in the same device, include the > bundle ID when matching. The assumption here is that bundle IDs are > stable across the lifespan of a product and never change. > > The goal of this change is to open the discussion. Greybus standardizes > a bunch of protocols like GPIO, SPI, etc. but also has provisioning for > vendor bundle and protocol. There is only one ID reserved for vendor, > 0xFF, so the question is did Greybus ever envision supporting several > vendor bundles, or one vendor bundle with several vendor cports in it? > Or the assumption always was that there could be at most only vendor > cport? The goal was to emulate what USB does here. If you have a vendor-specific protocol, then set the vendor protocol id (0xff) and then trigger off of the VID and PID. Then you can do whatever you want here in your driver as it's a vendor-specific one. So you are wanting multiple devices with the same vid/pid yet do different things? Why not just change the PID? Like with USB, a bundle id is not guaranteed to be "static", BUT if you want to make that distinction in your driver that is a vendor-specific one, go ahead. Again, that should be like USB interface numbers, right? thanks, greg k-h
© 2016 - 2025 Red Hat, Inc.