staging: vc04_services: Support module autoloading using MODULE_DEVICE_TABLE
authorUmang Jain <umang.jain@ideasonboard.com>
Thu, 19 Oct 2023 09:01:26 +0000 (14:31 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 21 Oct 2023 09:56:26 +0000 (11:56 +0200)
VC04 has now a independent bus vchiq_bus to register its devices.
However, the module auto-loading for bcm2835-audio and bcm2835-camera
currently happens through MODULE_ALIAS() macro specified explicitly.

The correct way to auto-load a module, is when the alias is picked
out from MODULE_DEVICE_TABLE(). In order to get there, we need to
introduce  vchiq_device_id and add relevant entries in file2alias.c
infrastructure so that aliases can be generated. This patch targets
adding vchiq_device_id and do_vchiq_entry, in order to
generate those alias using the /script/mod/file2alias.c.

Going forward the MODULE_ALIAS() from bcm2835-camera and bcm2835-audio
will be dropped, in favour of MODULE_DEVICE_TABLE being used there.

The alias format for vchiq_bus devices will be "vchiq:<dev_name>".
Adjust the vchiq_bus_uevent() to reflect that.

Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Link: https://lore.kernel.org/r/20231019090128.430297-2-umang.jain@ideasonboard.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_bus.c
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_bus.h
include/linux/mod_devicetable.h
scripts/mod/devicetable-offsets.c
scripts/mod/file2alias.c

index 0076d091b9b2893e1f8a45cc9298b7f536062937..933027e0011ecf8d72568735b36ed5f2cbccf1f2 100644 (file)
@@ -26,7 +26,7 @@ static int vchiq_bus_uevent(const struct device *dev, struct kobj_uevent_env *en
 {
        const struct vchiq_device *device = container_of_const(dev, struct vchiq_device, dev);
 
-       return add_uevent_var(env, "MODALIAS=%s", dev_name(&device->dev));
+       return add_uevent_var(env, "MODALIAS=vchiq:%s", dev_name(&device->dev));
 }
 
 static int vchiq_bus_probe(struct device *dev)
index 7eaaf9a91cda2b33f23cdd44073647b57be8761d..caa6fdf25bb1df69fd2a2fb0b1885f12884f9754 100644 (file)
@@ -7,6 +7,7 @@
 #define _VCHIQ_DEVICE_H
 
 #include <linux/device.h>
+#include <linux/mod_devicetable.h>
 
 struct vchiq_device {
        struct device dev;
@@ -18,6 +19,8 @@ struct vchiq_driver {
        int             (*resume)(struct vchiq_device *device);
        int             (*suspend)(struct vchiq_device *device,
                                   pm_message_t state);
+
+       const struct vchiq_device_id *id_table;
        struct device_driver driver;
 };
 
index b0678b093cb271f35ea4d28f895b0d9f59e311e3..700cbf34c3b8c8a9945e12fa87f9feeb0773ea6a 100644 (file)
@@ -946,4 +946,8 @@ struct cdx_device_id {
        __u32 override_only;
 };
 
+struct vchiq_device_id {
+       char name[32];
+};
+
 #endif /* LINUX_MOD_DEVICETABLE_H */
index abe65f8968dd59957b785483d457b0413640c73f..e8aadc780da52221a081d3768f0d817225d596c4 100644 (file)
@@ -267,5 +267,8 @@ int main(void)
        DEVID_FIELD(cdx_device_id, device);
        DEVID_FIELD(cdx_device_id, override_only);
 
+       DEVID(vchiq_device_id);
+       DEVID_FIELD(vchiq_device_id, name);
+
        return 0;
 }
index 38120f932b0dc1c9dcca19865223c9bb3881a844..78dfae5a8720c817d9e5a3444eef142899d5bfb8 100644 (file)
@@ -1478,6 +1478,14 @@ static int do_cdx_entry(const char *filename, void *symval,
        return 1;
 }
 
+static int do_vchiq_entry(const char *filename, void *symval, char *alias)
+{
+       DEF_FIELD_ADDR(symval, vchiq_device_id, name);
+       sprintf(alias, "vchiq:%s", *name);
+
+       return 1;
+}
+
 /* Does namelen bytes of name exactly match the symbol? */
 static bool sym_is(const char *name, unsigned namelen, const char *symbol)
 {
@@ -1558,6 +1566,7 @@ static const struct devtable devtable[] = {
        {"dfl", SIZE_dfl_device_id, do_dfl_entry},
        {"ishtp", SIZE_ishtp_device_id, do_ishtp_entry},
        {"cdx", SIZE_cdx_device_id, do_cdx_entry},
+       {"vchiq", SIZE_vchiq_device_id, do_vchiq_entry},
 };
 
 /* Create MODULE_ALIAS() statements.