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