MLK-24795-4: mic: cosm: module autoprobing support for cosm drivers

Add uevent callback for cosm_bus and add cosm_device_id for cosm driver
which is needed for MODULE_DEVICE_TABLE.
Cosm driver will be autoloaded when cosm device appears.

Signed-off-by: Sherry Sun <sherry.sun@nxp.com>
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Reviewed-by: Fugang Duan <fugang.duan@nxp.com>
This commit is contained in:
Sherry Sun 2020-09-11 17:21:04 +08:00
parent f7349db6e9
commit 68001bd9cd
5 changed files with 37 additions and 0 deletions

View File

@ -14,6 +14,13 @@
/* Unique numbering for cosm devices. */
static DEFINE_IDA(cosm_index_ida);
static int cosm_uevent(struct device *d, struct kobj_uevent_env *env)
{
struct cosm_device *dev = dev_to_cosm(d);
return add_uevent_var(env, "MODALIAS=cosm:cosm-dev%u", dev->index);
}
static int cosm_dev_probe(struct device *d)
{
struct cosm_device *dev = dev_to_cosm(d);
@ -33,6 +40,7 @@ static int cosm_dev_remove(struct device *d)
static struct bus_type cosm_bus = {
.name = "cosm_bus",
.uevent = cosm_uevent,
.probe = cosm_dev_probe,
.remove = cosm_dev_remove,
};

View File

@ -12,6 +12,7 @@
#include <linux/idr.h>
#include <linux/slab.h>
#include <linux/cred.h>
#include <linux/mod_devicetable.h>
#include "cosm_main.h"
static const char cosm_driver_name[] = "mic";
@ -322,6 +323,12 @@ static int cosm_suspend(struct device *dev)
return 0;
}
static struct cosm_device_id __maybe_unused cosm_driver_id_table[] = {
{ .name = "cosm-dev*" },
{ },
};
MODULE_DEVICE_TABLE(cosm, cosm_driver_id_table);
static const struct dev_pm_ops cosm_pm_ops = {
.suspend = cosm_suspend,
.freeze = cosm_suspend

View File

@ -834,4 +834,12 @@ struct vop_device_id {
};
#define VOP_DEV_ANY_ID 0xffffffff
/* cosm */
#define COSM_NAME_SIZE 32
#define COSM_MODULE_PREFIX "cosm:"
struct cosm_device_id {
char name[COSM_NAME_SIZE];
};
#endif /* LINUX_MOD_DEVICETABLE_H */

View File

@ -235,5 +235,8 @@ int main(void)
DEVID_FIELD(vop_device_id, device);
DEVID_FIELD(vop_device_id, vendor);
DEVID(cosm_device_id);
DEVID_FIELD(cosm_device_id, name);
return 0;
}

View File

@ -1350,6 +1350,16 @@ static int do_vop_entry(const char *filename, void *symval,
return 1;
}
/* Looks like: cosm:S */
static int do_cosm_entry(const char *filename, void *symval,
char *alias)
{
DEF_FIELD_ADDR(symval, cosm_device_id, name);
sprintf(alias, COSM_MODULE_PREFIX "%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)
{
@ -1423,6 +1433,7 @@ static const struct devtable devtable[] = {
{"tee", SIZE_tee_client_device_id, do_tee_entry},
{"wmi", SIZE_wmi_device_id, do_wmi_entry},
{"vop", SIZE_vop_device_id, do_vop_entry},
{"cosm", SIZE_cosm_device_id, do_cosm_entry},
};
/* Create MODULE_ALIAS() statements.