bus: mhi: core: Add uevent support for module autoloading
authorManivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Thu, 20 Feb 2020 09:58:50 +0000 (15:28 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 19 Mar 2020 06:41:05 +0000 (07:41 +0100)
Add uevent support to MHI bus so that the client drivers can be autoloaded
by udev when the MHI devices gets created. The client drivers are
expected to provide MODULE_DEVICE_TABLE with the MHI id_table struct so
that the alias can be exported.

Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Reviewed-by: Jeffrey Hugo <jhugo@codeaurora.org>
Tested-by: Jeffrey Hugo <jhugo@codeaurora.org>
Link: https://lore.kernel.org/r/20200220095854.4804-13-manivannan.sadhasivam@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/bus/mhi/core/init.c
include/linux/mod_devicetable.h
scripts/mod/devicetable-offsets.c
scripts/mod/file2alias.c

index 7bfffa9..5fb756c 100644 (file)
@@ -1210,6 +1210,14 @@ void mhi_driver_unregister(struct mhi_driver *mhi_drv)
 }
 EXPORT_SYMBOL_GPL(mhi_driver_unregister);
 
+static int mhi_uevent(struct device *dev, struct kobj_uevent_env *env)
+{
+       struct mhi_device *mhi_dev = to_mhi_device(dev);
+
+       return add_uevent_var(env, "MODALIAS=" MHI_DEVICE_MODALIAS_FMT,
+                                       mhi_dev->chan_name);
+}
+
 static int mhi_match(struct device *dev, struct device_driver *drv)
 {
        struct mhi_device *mhi_dev = to_mhi_device(dev);
@@ -1236,6 +1244,7 @@ struct bus_type mhi_bus_type = {
        .name = "mhi",
        .dev_name = "mhi",
        .match = mhi_match,
+       .uevent = mhi_uevent,
 };
 
 static int __init mhi_init(void)
index be15e99..f10e779 100644 (file)
@@ -821,6 +821,7 @@ struct wmi_device_id {
        const void *context;
 };
 
+#define MHI_DEVICE_MODALIAS_FMT "mhi:%s"
 #define MHI_NAME_SIZE 32
 
 /**
index 054405b..fe3f4a9 100644 (file)
@@ -231,5 +231,8 @@ int main(void)
        DEVID(wmi_device_id);
        DEVID_FIELD(wmi_device_id, guid_string);
 
+       DEVID(mhi_device_id);
+       DEVID_FIELD(mhi_device_id, chan);
+
        return 0;
 }
index c91eba7..cae6a4e 100644 (file)
@@ -1335,6 +1335,15 @@ static int do_wmi_entry(const char *filename, void *symval, char *alias)
        return 1;
 }
 
+/* Looks like: mhi:S */
+static int do_mhi_entry(const char *filename, void *symval, char *alias)
+{
+       DEF_FIELD_ADDR(symval, mhi_device_id, chan);
+       sprintf(alias, MHI_DEVICE_MODALIAS_FMT, *chan);
+
+       return 1;
+}
+
 /* Does namelen bytes of name exactly match the symbol? */
 static bool sym_is(const char *name, unsigned namelen, const char *symbol)
 {
@@ -1407,6 +1416,7 @@ static const struct devtable devtable[] = {
        {"typec", SIZE_typec_device_id, do_typec_entry},
        {"tee", SIZE_tee_client_device_id, do_tee_entry},
        {"wmi", SIZE_wmi_device_id, do_wmi_entry},
+       {"mhi", SIZE_mhi_device_id, do_mhi_entry},
 };
 
 /* Create MODULE_ALIAS() statements.