Merge tag 'pm-6.4-rc1-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael...
[linux-block.git] / sound / hda / hda_bus_type.c
CommitLineData
09c434b8 1// SPDX-License-Identifier: GPL-2.0-only
e3d280fc
TI
2/*
3 * HD-audio bus
4 */
5#include <linux/init.h>
6#include <linux/device.h>
7#include <linux/module.h>
da23ac1e 8#include <linux/mod_devicetable.h>
e3d280fc
TI
9#include <linux/export.h>
10#include <sound/hdaudio.h>
11
12MODULE_DESCRIPTION("HD-audio bus");
13MODULE_LICENSE("GPL");
14
ec71efc9
VK
15/**
16 * hdac_get_device_id - gets the hdac device id entry
17 * @hdev: HD-audio core device
18 * @drv: HD-audio codec driver
19 *
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.
22 */
23const struct hda_device_id *
24hdac_get_device_id(struct hdac_device *hdev, struct hdac_driver *drv)
25{
26 if (drv->id_table) {
27 const struct hda_device_id *id = drv->id_table;
28
29 while (id->vendor_id) {
30 if (hdev->vendor_id == id->vendor_id &&
31 (!id->rev_id || id->rev_id == hdev->revision_id))
32 return id;
33 id++;
34 }
35 }
36
37 return NULL;
38}
39EXPORT_SYMBOL_GPL(hdac_get_device_id);
40
41static int hdac_codec_match(struct hdac_device *dev, struct hdac_driver *drv)
42{
43 if (hdac_get_device_id(dev, drv))
44 return 1;
45 else
46 return 0;
47}
48
e3d280fc
TI
49static int hda_bus_match(struct device *dev, struct device_driver *drv)
50{
51 struct hdac_device *hdev = dev_to_hdac_dev(dev);
52 struct hdac_driver *hdrv = drv_to_hdac_driver(drv);
53
54 if (hdev->type != hdrv->type)
55 return 0;
ec71efc9
VK
56
57 /*
58 * if driver provided a match function use that otherwise we will
59 * use hdac_codec_match function
60 */
e3d280fc
TI
61 if (hdrv->match)
62 return hdrv->match(hdev, hdrv);
ec71efc9
VK
63 else
64 return hdac_codec_match(hdev, hdrv);
e3d280fc
TI
65 return 1;
66}
67
2a81ada3 68static int hda_uevent(const struct device *dev, struct kobj_uevent_env *env)
975c947e
TR
69{
70 char modalias[32];
71
72 snd_hdac_codec_modalias(dev_to_hdac_dev(dev), modalias,
73 sizeof(modalias));
74 if (add_uevent_var(env, "MODALIAS=%s", modalias))
75 return -ENOMEM;
76 return 0;
77}
78
e3d280fc
TI
79struct bus_type snd_hda_bus_type = {
80 .name = "hdaudio",
81 .match = hda_bus_match,
975c947e 82 .uevent = hda_uevent,
e3d280fc
TI
83};
84EXPORT_SYMBOL_GPL(snd_hda_bus_type);
85
86static int __init hda_bus_init(void)
87{
88 return bus_register(&snd_hda_bus_type);
89}
90
91static void __exit hda_bus_exit(void)
92{
93 bus_unregister(&snd_hda_bus_type);
94}
95
96subsys_initcall(hda_bus_init);
97module_exit(hda_bus_exit);