1 // SPDX-License-Identifier: GPL-2.0-only
5 #include <linux/init.h>
6 #include <linux/device.h>
7 #include <linux/module.h>
8 #include <linux/mod_devicetable.h>
9 #include <linux/export.h>
10 #include <sound/hdaudio.h>
12 MODULE_DESCRIPTION("HD-audio bus");
13 MODULE_LICENSE("GPL");
16 * hdac_get_device_id - gets the hdac device id entry
17 * @hdev: HD-audio core device
18 * @drv: HD-audio codec driver
20 * Compares the hdac device vendor_id and revision_id to the hdac_device
21 * driver id_table and returns the matching device id entry.
23 const struct hda_device_id *
24 hdac_get_device_id(struct hdac_device *hdev, struct hdac_driver *drv)
27 const struct hda_device_id *id = drv->id_table;
29 while (id->vendor_id) {
30 if (hdev->vendor_id == id->vendor_id &&
31 (!id->rev_id || id->rev_id == hdev->revision_id))
39 EXPORT_SYMBOL_GPL(hdac_get_device_id);
41 static int hdac_codec_match(struct hdac_device *dev, struct hdac_driver *drv)
43 if (hdac_get_device_id(dev, drv))
49 static int hda_bus_match(struct device *dev, struct device_driver *drv)
51 struct hdac_device *hdev = dev_to_hdac_dev(dev);
52 struct hdac_driver *hdrv = drv_to_hdac_driver(drv);
54 if (hdev->type != hdrv->type)
58 * if driver provided a match function use that otherwise we will
59 * use hdac_codec_match function
62 return hdrv->match(hdev, hdrv);
64 return hdac_codec_match(hdev, hdrv);
68 static int hda_uevent(struct device *dev, struct kobj_uevent_env *env)
72 snd_hdac_codec_modalias(dev_to_hdac_dev(dev), modalias,
74 if (add_uevent_var(env, "MODALIAS=%s", modalias))
79 struct bus_type snd_hda_bus_type = {
81 .match = hda_bus_match,
84 EXPORT_SYMBOL_GPL(snd_hda_bus_type);
86 static int __init hda_bus_init(void)
88 return bus_register(&snd_hda_bus_type);
91 static void __exit hda_bus_exit(void)
93 bus_unregister(&snd_hda_bus_type);
96 subsys_initcall(hda_bus_init);
97 module_exit(hda_bus_exit);