Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ec71efc9 authored by Vinod Koul's avatar Vinod Koul Committed by Takashi Iwai
Browse files

ALSA: hda - add HDA default codec match function



HDA codec drivers can be matched using vendor id and revision id typically.
So provide a match function which does this and is loaded when driver hasn't
provided one (default behaviour)

Signed-off-by: default avatarJeeja KP <jeeja.kp@intel.com>
Signed-off-by: default avatarVinod Koul <vinod.koul@intel.com>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 03b135ce
Loading
Loading
Loading
Loading
+14 −0
Original line number Original line Diff line number Diff line
@@ -27,6 +27,16 @@ struct hdac_widget_tree;
 */
 */
extern struct bus_type snd_hda_bus_type;
extern struct bus_type snd_hda_bus_type;


/*
 * HDA device table
 */
struct hda_device_id {
	__u32 vendor_id;
	__u32 rev_id;
	const char *name;
	unsigned long driver_data;
};

/*
/*
 * generic arrays
 * generic arrays
 */
 */
@@ -171,12 +181,16 @@ static inline void snd_hdac_power_down_pm(struct hdac_device *codec) {}
struct hdac_driver {
struct hdac_driver {
	struct device_driver driver;
	struct device_driver driver;
	int type;
	int type;
	const struct hda_device_id *id_table;
	int (*match)(struct hdac_device *dev, struct hdac_driver *drv);
	int (*match)(struct hdac_device *dev, struct hdac_driver *drv);
	void (*unsol_event)(struct hdac_device *dev, unsigned int event);
	void (*unsol_event)(struct hdac_device *dev, unsigned int event);
};
};


#define drv_to_hdac_driver(_drv) container_of(_drv, struct hdac_driver, driver)
#define drv_to_hdac_driver(_drv) container_of(_drv, struct hdac_driver, driver)


const struct hda_device_id *
hdac_get_device_id(struct hdac_device *hdev, struct hdac_driver *drv);

/*
/*
 * Bus verb operators
 * Bus verb operators
 */
 */
+41 −0
Original line number Original line Diff line number Diff line
@@ -10,6 +10,40 @@
MODULE_DESCRIPTION("HD-audio bus");
MODULE_DESCRIPTION("HD-audio bus");
MODULE_LICENSE("GPL");
MODULE_LICENSE("GPL");


/**
 * hdac_get_device_id - gets the hdac device id entry
 * @hdev: HD-audio core device
 * @drv: HD-audio codec driver
 *
 * Compares the hdac device vendor_id and revision_id to the hdac_device
 * driver id_table and returns the matching device id entry.
 */
const struct hda_device_id *
hdac_get_device_id(struct hdac_device *hdev, struct hdac_driver *drv)
{
	if (drv->id_table) {
		const struct hda_device_id *id  = drv->id_table;

		while (id->vendor_id) {
			if (hdev->vendor_id == id->vendor_id &&
				(!id->rev_id || id->rev_id == hdev->revision_id))
				return id;
			id++;
		}
	}

	return NULL;
}
EXPORT_SYMBOL_GPL(hdac_get_device_id);

static int hdac_codec_match(struct hdac_device *dev, struct hdac_driver *drv)
{
	if (hdac_get_device_id(dev, drv))
		return 1;
	else
		return 0;
}

static int hda_bus_match(struct device *dev, struct device_driver *drv)
static int hda_bus_match(struct device *dev, struct device_driver *drv)
{
{
	struct hdac_device *hdev = dev_to_hdac_dev(dev);
	struct hdac_device *hdev = dev_to_hdac_dev(dev);
@@ -17,8 +51,15 @@ static int hda_bus_match(struct device *dev, struct device_driver *drv)


	if (hdev->type != hdrv->type)
	if (hdev->type != hdrv->type)
		return 0;
		return 0;

	/*
	 * if driver provided a match function use that otherwise we will
	 * use hdac_codec_match function
	 */
	if (hdrv->match)
	if (hdrv->match)
		return hdrv->match(hdev, hdrv);
		return hdrv->match(hdev, hdrv);
	else
		return hdac_codec_match(hdev, hdrv);
	return 1;
	return 1;
}
}