Takashi Iwai | e3d280f | 2015-02-17 21:46:37 +0100 | [diff] [blame] | 1 | /* |
| 2 | * HD-audio bus |
| 3 | */ |
| 4 | #include <linux/init.h> |
| 5 | #include <linux/device.h> |
| 6 | #include <linux/module.h> |
Subhransu S. Prusty | da23ac1 | 2015-09-29 13:56:10 +0530 | [diff] [blame] | 7 | #include <linux/mod_devicetable.h> |
Takashi Iwai | e3d280f | 2015-02-17 21:46:37 +0100 | [diff] [blame] | 8 | #include <linux/export.h> |
| 9 | #include <sound/hdaudio.h> |
| 10 | |
| 11 | MODULE_DESCRIPTION("HD-audio bus"); |
| 12 | MODULE_LICENSE("GPL"); |
| 13 | |
Vinod Koul | ec71efc | 2015-06-03 12:24:31 +0530 | [diff] [blame] | 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 | |
Takashi Iwai | e3d280f | 2015-02-17 21:46:37 +0100 | [diff] [blame] | 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; |
Vinod Koul | ec71efc | 2015-06-03 12:24:31 +0530 | [diff] [blame] | 55 | |
| 56 | /* |
| 57 | * if driver provided a match function use that otherwise we will |
| 58 | * use hdac_codec_match function |
| 59 | */ |
Takashi Iwai | e3d280f | 2015-02-17 21:46:37 +0100 | [diff] [blame] | 60 | if (hdrv->match) |
| 61 | return hdrv->match(hdev, hdrv); |
Vinod Koul | ec71efc | 2015-06-03 12:24:31 +0530 | [diff] [blame] | 62 | else |
| 63 | return hdac_codec_match(hdev, hdrv); |
Takashi Iwai | e3d280f | 2015-02-17 21:46:37 +0100 | [diff] [blame] | 64 | return 1; |
| 65 | } |
| 66 | |
Thierry Reding | 975c947 | 2015-09-17 12:00:05 +0200 | [diff] [blame] | 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 | |
Takashi Iwai | e3d280f | 2015-02-17 21:46:37 +0100 | [diff] [blame] | 78 | struct bus_type snd_hda_bus_type = { |
| 79 | .name = "hdaudio", |
| 80 | .match = hda_bus_match, |
Thierry Reding | 975c947 | 2015-09-17 12:00:05 +0200 | [diff] [blame] | 81 | .uevent = hda_uevent, |
Takashi Iwai | e3d280f | 2015-02-17 21:46:37 +0100 | [diff] [blame] | 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); |