Commit | Line | Data |
---|---|---|
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 | ||
12 | MODULE_DESCRIPTION("HD-audio bus"); | |
13 | MODULE_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 | */ | |
23 | const struct hda_device_id * | |
24 | hdac_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 | } | |
39 | EXPORT_SYMBOL_GPL(hdac_get_device_id); | |
40 | ||
41 | static 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 | ||
d69d8048 | 49 | static int hda_bus_match(struct device *dev, const struct device_driver *drv) |
e3d280fc TI |
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 | 68 | static 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 | ||
66e82d21 | 79 | const struct bus_type snd_hda_bus_type = { |
e3d280fc TI |
80 | .name = "hdaudio", |
81 | .match = hda_bus_match, | |
975c947e | 82 | .uevent = hda_uevent, |
e3d280fc TI |
83 | }; |
84 | EXPORT_SYMBOL_GPL(snd_hda_bus_type); | |
85 | ||
86 | static int __init hda_bus_init(void) | |
87 | { | |
88 | return bus_register(&snd_hda_bus_type); | |
89 | } | |
90 | ||
91 | static void __exit hda_bus_exit(void) | |
92 | { | |
93 | bus_unregister(&snd_hda_bus_type); | |
94 | } | |
95 | ||
96 | subsys_initcall(hda_bus_init); | |
97 | module_exit(hda_bus_exit); |