1 /* 2 * HD-audio bus 3 */ 4 #include <linux/init.h> 5 #include <linux/device.h> 6 #include <linux/module.h> 7 #include <linux/export.h> 8 #include <sound/hdaudio.h> 9 10 MODULE_DESCRIPTION("HD-audio bus"); 11 MODULE_LICENSE("GPL"); 12 13 /** 14 * hdac_get_device_id - gets the hdac device id entry 15 * @hdev: HD-audio core device 16 * @drv: HD-audio codec driver 17 * 18 * Compares the hdac device vendor_id and revision_id to the hdac_device 19 * driver id_table and returns the matching device id entry. 20 */ 21 const struct hda_device_id * 22 hdac_get_device_id(struct hdac_device *hdev, struct hdac_driver *drv) 23 { 24 if (drv->id_table) { 25 const struct hda_device_id *id = drv->id_table; 26 27 while (id->vendor_id) { 28 if (hdev->vendor_id == id->vendor_id && 29 (!id->rev_id || id->rev_id == hdev->revision_id)) 30 return id; 31 id++; 32 } 33 } 34 35 return NULL; 36 } 37 EXPORT_SYMBOL_GPL(hdac_get_device_id); 38 39 static int hdac_codec_match(struct hdac_device *dev, struct hdac_driver *drv) 40 { 41 if (hdac_get_device_id(dev, drv)) 42 return 1; 43 else 44 return 0; 45 } 46 47 static int hda_bus_match(struct device *dev, struct device_driver *drv) 48 { 49 struct hdac_device *hdev = dev_to_hdac_dev(dev); 50 struct hdac_driver *hdrv = drv_to_hdac_driver(drv); 51 52 if (hdev->type != hdrv->type) 53 return 0; 54 55 /* 56 * if driver provided a match function use that otherwise we will 57 * use hdac_codec_match function 58 */ 59 if (hdrv->match) 60 return hdrv->match(hdev, hdrv); 61 else 62 return hdac_codec_match(hdev, hdrv); 63 return 1; 64 } 65 66 struct bus_type snd_hda_bus_type = { 67 .name = "hdaudio", 68 .match = hda_bus_match, 69 }; 70 EXPORT_SYMBOL_GPL(snd_hda_bus_type); 71 72 static int __init hda_bus_init(void) 73 { 74 return bus_register(&snd_hda_bus_type); 75 } 76 77 static void __exit hda_bus_exit(void) 78 { 79 bus_unregister(&snd_hda_bus_type); 80 } 81 82 subsys_initcall(hda_bus_init); 83 module_exit(hda_bus_exit); 84