Commit b9a94a9c authored by Takashi Iwai's avatar Takashi Iwai
Browse files

ALSA: hda - convert to hda_device_id



Finally we have a proper infrastructure to generate the modaliases
automatically, let's move to hda_device_id from the legacy
hda_codec_preset that contains basically the same information.

The patch function hook is stored in driver_data field, which is long,
and we need an explicit cast.  Other than that, the conversion is
mostly straightforward.  Each entry is even simplified using a macro,
and the lengthy (and error-prone) manual modaliases got removed.

As a result, we achieved a quite good diet:
 14 files changed, 407 insertions(+), 595 deletions(-)

Reviewed-by: default avatarVinod Koul <vinod.koul@intel.com>
Tested-by: default avatarSubhransu S Prusty <subhransu.s.prusty@intel.com>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 78abb2af
Loading
Loading
Loading
Loading
+18 −14
Original line number Diff line number Diff line
@@ -15,21 +15,22 @@
#include "hda_local.h"

/*
 * find a matching codec preset
 * find a matching codec id
 */
static int hda_codec_match(struct hdac_device *dev, struct hdac_driver *drv)
{
	struct hda_codec *codec = container_of(dev, struct hda_codec, core);
	struct hda_codec_driver *driver =
		container_of(drv, struct hda_codec_driver, core);
	const struct hda_codec_preset *preset;
	const struct hda_device_id *list;
	/* check probe_id instead of vendor_id if set */
	u32 id = codec->probe_id ? codec->probe_id : codec->core.vendor_id;
	u32 rev_id = codec->core.revision_id;

	for (preset = driver->preset; preset->id; preset++) {
		if (preset->id == id &&
		    (!preset->rev || preset->rev == codec->core.revision_id)) {
			codec->preset = preset;
	for (list = driver->id; list->vendor_id; list++) {
		if (list->vendor_id == id &&
		    (!list->rev_id || list->rev_id == rev_id)) {
			codec->preset = list;
			return 1;
		}
	}
@@ -77,6 +78,7 @@ static int hda_codec_driver_probe(struct device *dev)
{
	struct hda_codec *codec = dev_to_hda_codec(dev);
	struct module *owner = dev->driver->owner;
	hda_codec_patch_t patch;
	int err;

	if (WARN_ON(!codec->preset))
@@ -94,9 +96,12 @@ static int hda_codec_driver_probe(struct device *dev)
		goto error;
	}

	err = codec->preset->patch(codec);
	patch = (hda_codec_patch_t)codec->preset->driver_data;
	if (patch) {
		err = patch(codec);
		if (err < 0)
			goto error_module;
	}

	err = snd_hda_codec_build_pcms(codec);
	if (err < 0)
@@ -173,11 +178,10 @@ static inline bool codec_probed(struct hda_codec *codec)
static void codec_bind_module(struct hda_codec *codec)
{
#ifdef MODULE
	request_module("snd-hda-codec-id:%08x", codec->core.vendor_id);
	if (codec_probed(codec))
		return;
	request_module("snd-hda-codec-id:%04x*",
		       (codec->core.vendor_id >> 16) & 0xffff);
	char modalias[32];

	snd_hdac_codec_modalias(&codec->core, modalias, sizeof(modalias));
	request_module(modalias);
	if (codec_probed(codec))
		return;
#endif
+11 −8
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#define __SOUND_HDA_CODEC_H

#include <linux/kref.h>
#include <linux/mod_devicetable.h>
#include <sound/info.h>
#include <sound/control.h>
#include <sound/pcm.h>
@@ -80,19 +81,21 @@ struct hda_bus {
 * Known codecs have the patch to build and set up the controls/PCMs
 * better than the generic parser.
 */
struct hda_codec_preset {
	unsigned int id;
	unsigned int rev;
	const char *name;
	int (*patch)(struct hda_codec *codec);
};
typedef int (*hda_codec_patch_t)(struct hda_codec *);
	
#define HDA_CODEC_ID_GENERIC_HDMI	0x00000101
#define HDA_CODEC_ID_GENERIC		0x00000201

#define HDA_CODEC_REV_ENTRY(_vid, _rev, _name, _patch) \
	{ .vendor_id = (_vid), .rev_id = (_rev), .name = (_name), \
	  .api_version = HDA_DEV_LEGACY, \
	  .driver_data = (unsigned long)(_patch) }
#define HDA_CODEC_ENTRY(_vid, _name, _patch) \
	HDA_CODEC_REV_ENTRY(_vid, 0, _name, _patch)

struct hda_codec_driver {
	struct hdac_driver core;
	const struct hda_codec_preset *preset;
	const struct hda_device_id *id;
};

int __hda_codec_driver_register(struct hda_codec_driver *drv, const char *name,
@@ -183,7 +186,7 @@ struct hda_codec {
	u32 probe_id; /* overridden id for probing */

	/* detected preset */
	const struct hda_codec_preset *preset;
	const struct hda_device_id *preset;
	const char *modelname;	/* model name for preset */

	/* set by patch */
+4 −3
Original line number Diff line number Diff line
@@ -5877,13 +5877,14 @@ error:
	return err;
}

static const struct hda_codec_preset snd_hda_preset_generic[] = {
	{ .id = HDA_CODEC_ID_GENERIC, .patch = snd_hda_parse_generic_codec },
static const struct hda_device_id snd_hda_id_generic[] = {
	HDA_CODEC_ENTRY(HDA_CODEC_ID_GENERIC, "Generic", snd_hda_parse_generic_codec),
	{} /* terminator */
};
MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_generic);

static struct hda_codec_driver generic_driver = {
	.preset = snd_hda_preset_generic,
	.id = snd_hda_id_generic,
};

module_hda_codec_driver(generic_driver);
+18 −19
Original line number Diff line number Diff line
@@ -1165,32 +1165,31 @@ static int patch_ad1882(struct hda_codec *codec)
/*
 * patch entries
 */
static const struct hda_codec_preset snd_hda_preset_analog[] = {
	{ .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884 },
	{ .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
	{ .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884 },
	{ .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
	{ .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884 },
	{ .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884 },
	{ .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
	{ .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
	{ .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1884 },
	{ .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
	{ .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
	{ .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
	{ .id = 0x11d4882a, .name = "AD1882A", .patch = patch_ad1882 },
	{ .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 },
	{ .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 },
static const struct hda_device_id snd_hda_id_analog[] = {
	HDA_CODEC_ENTRY(0x11d4184a, "AD1884A", patch_ad1884),
	HDA_CODEC_ENTRY(0x11d41882, "AD1882", patch_ad1882),
	HDA_CODEC_ENTRY(0x11d41883, "AD1883", patch_ad1884),
	HDA_CODEC_ENTRY(0x11d41884, "AD1884", patch_ad1884),
	HDA_CODEC_ENTRY(0x11d4194a, "AD1984A", patch_ad1884),
	HDA_CODEC_ENTRY(0x11d4194b, "AD1984B", patch_ad1884),
	HDA_CODEC_ENTRY(0x11d41981, "AD1981", patch_ad1981),
	HDA_CODEC_ENTRY(0x11d41983, "AD1983", patch_ad1983),
	HDA_CODEC_ENTRY(0x11d41984, "AD1984", patch_ad1884),
	HDA_CODEC_ENTRY(0x11d41986, "AD1986A", patch_ad1986a),
	HDA_CODEC_ENTRY(0x11d41988, "AD1988", patch_ad1988),
	HDA_CODEC_ENTRY(0x11d4198b, "AD1988B", patch_ad1988),
	HDA_CODEC_ENTRY(0x11d4882a, "AD1882A", patch_ad1882),
	HDA_CODEC_ENTRY(0x11d4989a, "AD1989A", patch_ad1988),
	HDA_CODEC_ENTRY(0x11d4989b, "AD1989B", patch_ad1988),
	{} /* terminator */
};

MODULE_ALIAS("snd-hda-codec-id:11d4*");
MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_analog);

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Analog Devices HD-audio codec");

static struct hda_codec_driver analog_driver = {
	.preset = snd_hda_preset_analog,
	.id = snd_hda_id_analog,
};

module_hda_codec_driver(analog_driver);
+6 −9
Original line number Diff line number Diff line
@@ -83,22 +83,19 @@ static int patch_ca0110(struct hda_codec *codec)
/*
 * patch entries
 */
static const struct hda_codec_preset snd_hda_preset_ca0110[] = {
	{ .id = 0x1102000a, .name = "CA0110-IBG", .patch = patch_ca0110 },
	{ .id = 0x1102000b, .name = "CA0110-IBG", .patch = patch_ca0110 },
	{ .id = 0x1102000d, .name = "SB0880 X-Fi", .patch = patch_ca0110 },
static const struct hda_device_id snd_hda_id_ca0110[] = {
	HDA_CODEC_ENTRY(0x1102000a, "CA0110-IBG", patch_ca0110),
	HDA_CODEC_ENTRY(0x1102000b, "CA0110-IBG", patch_ca0110),
	HDA_CODEC_ENTRY(0x1102000d, "SB0880 X-Fi", patch_ca0110),
	{} /* terminator */
};

MODULE_ALIAS("snd-hda-codec-id:1102000a");
MODULE_ALIAS("snd-hda-codec-id:1102000b");
MODULE_ALIAS("snd-hda-codec-id:1102000d");
MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_ca0110);

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Creative CA0110-IBG HD-audio codec");

static struct hda_codec_driver ca0110_driver = {
	.preset = snd_hda_preset_ca0110,
	.id = snd_hda_id_ca0110,
};

module_hda_codec_driver(ca0110_driver);
Loading