[alsa-devel] [PATCH v2 3/7] ASoC: hda - add soc hda codec driver wrapper

Takashi Iwai tiwai at suse.de
Fri Apr 17 11:42:07 CEST 2015


At Fri, 17 Apr 2015 14:43:16 +0530,
Vinod Koul wrote:
> 
> From: Jeeja KP <jeeja.kp at intel.com>
> 
> This provides match function for ASoC
> codec driver based on id_table and driver
> register/unregister wrapper functions
> 
> Signed-off-by: Jeeja KP <jeeja.kp at intel.com>
> Signed-off-by: Vinod Koul <vinod.koul at intel.com>
> ---
>  sound/soc/codecs/Kconfig         |    3 ++
>  sound/soc/codecs/Makefile        |    2 +
>  sound/soc/codecs/soc-hda-codec.c |   79 ++++++++++++++++++++++++++++++++++++++
>  sound/soc/codecs/soc-hda-codec.h |   43 +++++++++++++++++++++
>  4 files changed, 127 insertions(+)
>  create mode 100644 sound/soc/codecs/soc-hda-codec.c
>  create mode 100644 sound/soc/codecs/soc-hda-codec.h
> 
> diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
> index 061c46587628..4ce30ded2c9c 100644
> --- a/sound/soc/codecs/Kconfig
> +++ b/sound/soc/codecs/Kconfig
> @@ -444,6 +444,9 @@ config SND_SOC_ES8328_SPI
>  	tristate
>  	select SND_SOC_ES8328
>  
> +config SND_SOC_HDA_CODEC
> +	tristate "ASOC HDA Codec Core"
> +
>  config SND_SOC_ISABELLE
>          tristate
>  
> diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
> index abe2d7edf65c..5685ec556942 100644
> --- a/sound/soc/codecs/Makefile
> +++ b/sound/soc/codecs/Makefile
> @@ -55,6 +55,7 @@ snd-soc-dmic-objs := dmic.o
>  snd-soc-es8328-objs := es8328.o
>  snd-soc-es8328-i2c-objs := es8328-i2c.o
>  snd-soc-es8328-spi-objs := es8328-spi.o
> +snd-soc-hda-codec-objs := soc-hda-codec.o
>  snd-soc-isabelle-objs := isabelle.o
>  snd-soc-jz4740-codec-objs := jz4740.o
>  snd-soc-l3-objs := l3.o
> @@ -240,6 +241,7 @@ obj-$(CONFIG_SND_SOC_DMIC)	+= snd-soc-dmic.o
>  obj-$(CONFIG_SND_SOC_ES8328)	+= snd-soc-es8328.o
>  obj-$(CONFIG_SND_SOC_ES8328_I2C)+= snd-soc-es8328-i2c.o
>  obj-$(CONFIG_SND_SOC_ES8328_SPI)+= snd-soc-es8328-spi.o
> +obj-$(CONFIG_SND_SOC_HDA_CODEC)	+= snd-soc-hda-codec.o
>  obj-$(CONFIG_SND_SOC_ISABELLE)	+= snd-soc-isabelle.o
>  obj-$(CONFIG_SND_SOC_JZ4740_CODEC)	+= snd-soc-jz4740-codec.o
>  obj-$(CONFIG_SND_SOC_L3)	+= snd-soc-l3.o
> diff --git a/sound/soc/codecs/soc-hda-codec.c b/sound/soc/codecs/soc-hda-codec.c
> new file mode 100644
> index 000000000000..46bfddd87a7c
> --- /dev/null
> +++ b/sound/soc/codecs/soc-hda-codec.c
> @@ -0,0 +1,79 @@
> +/*
> + * soc-hda-codec.c ASoC High Definition Audio Codec interface Definitions
> + *
> + * Copyright (c) 2014-2015 Intel Corporation
> + *
> + * Author(s): Jeeja KP <jeeja.kp at intel.com>
> + *
> + *
> + *  This driver is free software; you can redistribute it and/or modify
> + *  it under the terms of the GNU General Public License as published by
> + *  the Free Software Foundation; either version 2 of the License, or
> + *  (at your option) any later version.
> + *
> + *  This driver is distributed in the hope that it will be useful,
> + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
> + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + *  GNU General Public License for more details.
> + */
> +
> +#include <linux/module.h>
> +#include <sound/hdaudio.h>
> +#include "soc-hda-codec.h"
> +
> +
> +/*
> + * find a matching vendor id
> + */
> +static int hda_codec_match(struct hdac_device *dev, struct hdac_driver *drv)
> +{
> +	struct hda_soc_codec_driver *driver =
> +		container_of(drv, struct hda_soc_codec_driver, core);
> +
> +	if (driver->id_table) {
> +		const struct hda_soc_device_id *id  = driver->id_table;
> +
> +		while (id->name[0]) {
> +			if (dev->vendor_id == id->id)
> +				return 1;
> +			id++;

Does checking only the vendor id suffice?  In the legacy driver, we
had to check sometimes the revision number.  (Or, some Realtek codecs
give different names depending on the revision id, etc.)


Takashi

> +		}
> +	}
> +	return 0;
> +}
> +
> +int snd_soc_hda_codec_driver_register(struct hda_soc_codec_driver *drv)
> +{
> +	drv->core.driver.bus = &snd_hda_bus_type;
> +	drv->core.type = HDA_DEV_ASOC;
> +	drv->core.match = hda_codec_match;
> +	return driver_register(&drv->core.driver);
> +}
> +EXPORT_SYMBOL_GPL(snd_soc_hda_codec_driver_register);
> +
> +void snd_soc_hda_codec_driver_unregister(struct hda_soc_codec_driver *drv)
> +{
> +	driver_unregister(&drv->core.driver);
> +}
> +EXPORT_SYMBOL_GPL(snd_soc_hda_codec_driver_unregister);
> +
> +const struct hda_soc_device_id *
> +snd_soc_hda_get_device_id(
> +			struct hdac_device *hdev,
> +			struct hda_soc_codec_driver *drv)
> +{
> +	if (drv->id_table) {
> +		const struct hda_soc_device_id *id  = drv->id_table;
> +
> +		while (id->name[0]) {
> +			if (hdev->vendor_id == id->id)
> +				return id;
> +			id++;
> +		}
> +	}
> +	return NULL;
> +}
> +EXPORT_SYMBOL_GPL(snd_soc_hda_get_device_id);
> +
> +MODULE_DESCRIPTION("ASoC HDA codec core");
> +MODULE_LICENSE("GPL v2");
> diff --git a/sound/soc/codecs/soc-hda-codec.h b/sound/soc/codecs/soc-hda-codec.h
> new file mode 100644
> index 000000000000..6c2d107049bb
> --- /dev/null
> +++ b/sound/soc/codecs/soc-hda-codec.h
> @@ -0,0 +1,43 @@
> +/*
> + * ASoC High Definition Audio Codec interface
> + *
> + * Copyright (c) 2015 Intel Corporation
> + *
> + * Author(s): Jeeja KP <jeeja.kp at intel.com>
> + *
> + *  This program is free software; you can redistribute it and/or modify it
> + *  under the terms of the GNU General Public License as published by the Free
> + *  Software Foundation; either version 2 of the License, or (at your option)
> + *  any later version.
> + *
> + *  This program is distributed in the hope that it will be useful, but WITHOUT
> + *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
> + *  more details.
> + *
> + */
> +
> +#include <sound/hdaudio.h>
> +
> +/*HDA device table*/
> +#define HDA_NAME_SIZE      20
> +struct hda_soc_device_id {
> +	__u32 id;
> +	char name[HDA_NAME_SIZE];
> +	unsigned long driver_data;
> +};
> +
> +struct hda_soc_codec_driver {
> +	struct hdac_driver core;
> +	const struct hda_soc_device_id *id_table;
> +};
> +
> +#define to_hdac_driver(drv) (container_of((drv), \
> +				 struct hdac_driver, driver))
> +#define to_hda_soc_codec_driver(hdrv) (container_of((hdrv), \
> +				 struct hda_soc_codec_driver, core))
> +
> +int snd_soc_hda_codec_driver_register(struct hda_soc_codec_driver *drv);
> +void snd_soc_hda_codec_driver_unregister(struct hda_soc_codec_driver *drv);
> +const struct hda_soc_device_id *snd_soc_hda_get_device_id(struct hdac_device *hdev,
> +				struct hda_soc_codec_driver *drv);
> -- 
> 1.7.9.5
> 


More information about the Alsa-devel mailing list