ASoC: hdac: Add hdac generic driver
v2 cover ASoC: hdac: Add hdac generic driver
HDA devices generically can be modelled with DAPM in ASoC.
We would like to create a framework for the HDA devices in ASoC. This will follow HDA standard. This will be registered as generic "virtual" class device (Not implemented in this series). If there is no match found for vendor id and device id, then the class driver will be loaded. For vendor specific devices, vendor quirks will be loaded based on the match. Additional widgets, controls and route will be created in a vendor specific way through vendor ops.
This series adds a framework in ASoC to model HDA codecs. HDA widgets are enumerated and one or multiple DAPM widget(s) are created. Connection list is queried for each widget to identify the connection between two endpoints and modelled using DAPM graph.
Set of event handlers are defined for each widget type. Based on DAPM events required verbs are sent to program codec.
Finally a function is exported to query for the device endpoint configuration to create machine controls.
Features yet to be added:
- Optional features of widgets will be added using additional dapm widgets or controls
- Pin retasking will be done by adding all possible dapm route map
- Class driver to load the generic driver if no match found
- Jack detection
changes in v2:
- Addressed review comment from Takashi
- Moved the widget_list to hdac_ext_device
- helper to fill the widget list is now called from hdac_ext_bus_device_init instead of driver probe
- Fixed a NULL pointer dereferencing issue
- Reorder patch to fix 'auto build test error'
- Playback with hs/spk and amic capture now working for rt286
- And some more cleanup and code refactoring to avoid long function definition
Subhransu S. Prusty (11):
ALSA: hdac: Add codec helper library
ALSA: hda - Add macro to test pin widget's input capability
ASoC: hdac: Add a generic hdac driver framework
ALSA: hdac: Move 'to_hda_ext_device' helper to core
ASoC: hdac: Create DAPM model for HDA widgets
ASoC: hdac: Build DAPM graph by querying through widget connection
list
ASoC: hdac: Register widget event handlers
ALSA: hda - macro to get default config device of pin widgets
ASoC: hdac: Export API to create machine controls
ALSA: hdac: Implement a match function
ASoC: hdac: Add coefficient init callback for RT286
include/sound/hdaudio_ext.h | 40 + sound/hda/ext/Makefile | 3 +- sound/hda/ext/hdac_ext_bus.c | 24 + sound/hda/ext/hdac_ext_codec.c | 156 ++++ sound/hda/ext/hdac_ext_codec.h | 26 + sound/hda/local.h | 13 + sound/soc/codecs/Kconfig | 5 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/hdac_generic.c | 1743 +++++++++++++++++++++++++++++++++++++++ sound/soc/codecs/hdac_generic.h | 36 + sound/soc/codecs/hdac_hdmi.c | 8 +- 11 files changed, 2048 insertions(+), 8 deletions(-) create mode 100644 sound/hda/ext/hdac_ext_codec.c create mode 100644 sound/hda/ext/hdac_ext_codec.h create mode 100644 sound/soc/codecs/hdac_generic.c create mode 100644 sound/soc/codecs/hdac_generic.h
Signature · 1 line
1.9.1
PATCH v2 1/11 ALSA: hdac: Add codec helper library
Add hdac helpers to enumerate the HDA widgets and fill connection lists for each. During ext device init, these helpers are used to parse the HDA codec for the widgets and cache them in a list.
--- include/sound/hdaudio_ext.h | 31 ++++++++ sound/hda/ext/Makefile | 3 +- sound/hda/ext/hdac_ext_bus.c | 6 ++ sound/hda/ext/hdac_ext_codec.c | 156 +++++++++++++++++++++++++++++++++++++++++ sound/hda/ext/hdac_ext_codec.h | 26 +++++++ 5 files changed, 221 insertions(+), 1 deletion(-) create mode 100644 sound/hda/ext/hdac_ext_codec.c create mode 100644 sound/hda/ext/hdac_ext_codec.h
include/sound/hdaudio_ext.h +31 -0
@@ -193,6 +193,35 @@ struct hda_dai_map { };#define HDA_MAX_NIDS 16 +#define HDA_MAX_CONNECTIONS 32 +/* amp values */ +#define AMP_IN_MUTE (idx) (0x7080 | ((idx)<<8)) +#define AMP_IN_UNMUTE (idx) (0x7000 | ((idx)<<8)) +#define AMP_OUT_MUTE 0xb080 +#define AMP_OUT_UNMUTE 0xb000 + + +struct hdac_ext_codec_widget ; + +struct hdac_ext_codec_connection_list { +hda_nid_t nid; +unsigned int type; +struct hdac_ext_codec_widget *input_w; +}; + +/** +* struct hdac_ext_device - HDAC Ext device +*/ +struct hdac_ext_codec_widget { +struct list_head head; +hda_nid_t nid; +unsigned int caps; +unsigned int type; +int num_inputs; +struct hdac_ext_codec_connection_list conn_list[HDA_MAX_CONNECTIONS ]; +void *priv;/* Codec specific widget data */ +void *params;/* Widget specific parameters */ +};/** * struct hdac_ext_device - HDAC Ext device
@@ -217,6 +246,8 @@ struct hdac_ext_device {struct snd_card *card;void *scodec;void *private_data; + +struct list_head widget_list; };struct hdac_ext_dma_params {
sound/hda/ext/Makefile +2 -1
@@ -1,3 +1,4 @@ -snd-hda-ext-core-objs := hdac_ext_bus.o hdac_ext_controller.o hdac_ext_stream.o +snd-hda-ext-core-objs := hdac_ext_bus.o hdac_ext_controller.o hdac_ext_stream.o \ + hdac_ext_codec.o obj-$(CONFIG_SND_HDA_EXT_CORE) += snd-hda-ext-core.o
sound/hda/ext/hdac_ext_bus.c +6 -0
@@ -21,6 +21,7 @@#include <linux/slab.h> #include <linux/io.h> #include <sound/hdaudio_ext.h> +#include "hdac_ext_codec.h" MODULE_DESCRIPTION ("HDA extended core" );MODULE_LICENSE ("GPL v2" );
@@ -128,6 +129,7 @@ static void default_release(struct device *dev)snd_hdac_ext_bus_device_exit (container_of(dev ,struct hdac_device ,dev )); } +/** * snd_hdac_ext_bus_device_init - initialize the HDA extended codec base device * @ebus: hdac extended bus to attach to
@@ -159,6 +161,9 @@ int snd_hdac_ext_bus_device_init(struct hdac_ext_bus *ebus, int addr) hdev->type =HDA_DEV_ASOC ; hdev->dev.release = default_release; +INIT_LIST_HEAD (&edev->widget_list); +snd_hdac_ext_parse_widgets (edev); + ret =snd_hdac_device_register (hdev);if (ret) {dev_err (bus->dev,"failed to register hdac device\n" );
@@ -178,6 +183,7 @@ void snd_hdac_ext_bus_device_exit(struct hdac_device *hdev) {struct hdac_ext_device *edev =to_ehdac_device (hdev); +snd_hdac_ext_codec_cleanup (edev);snd_hdac_device_exit (hdev);kfree (edev); }
sound/hda/ext/hdac_ext_codec.c new file +156 -0
156 lines not on this page · raw message
sound/hda/ext/hdac_ext_codec.h new file +26 -0
@@ -0,0 +1,26 @@ +/* +* hdac_ext_codec.h - HDA ext codec helpers +* +* Copyright (C) 2016 Intel Corp +* Author: Subhransu S. Prusty <[email protected]> +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* +* 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; version 2 of the License. +* +* 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. +* +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +*/ + +#ifndef __HDAC_EXT_CODEC_H__ +#define __HDAC_EXT_CODEC_H__ + +int snd_hdac_ext_parse_widgets (struct hdac_ext_device *hdac); +void snd_hdac_ext_codec_cleanup (struct hdac_ext_device *hdac); + +#endif /* __HDAC_EXT_CODEC_H__ */
Signature · 1 line
1.9.1
PATCH v2 2/11 ALSA: hda - Add macro to test pin widget's input capability
In reply to Subhransu S. PrustyThe macro will be used to identify pins input capability. Based on the capability ASoC driver creates DAPM widget for pin. Also based on input capability widget parsing is done for DAPM graph creation.
--- sound/hda/local.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
sound/hda/local.h +10 -0
@@ -8,6 +8,16 @@#define get_wcaps (codec, nid) \ snd_hdac_read_parm(codec, nid, AC_PAR_AUDIO_WIDGET_CAP) +#define get_pcaps (codec, nid) \ + snd_hdac_read_parm(codec, nid, AC_PAR_PIN_CAP) + +static inline bool is_input_pin (struct hdac_device *codec,hda_nid_t nid) +{ +unsigned int pincap =get_pcaps (codec, nid); + +return (pincap &AC_PINCAP_IN ) !=0 ; +} +/* get the widget type from widget capability bits */ static inline int get_wcaps_type (unsigned int wcaps) {
Signature · 1 line
1.9.1
PATCH v2 3/11 ASoC: hdac: Add a generic hdac driver framework
In reply to Subhransu S. PrustyThis patch adds support to register the hdac driver with the HDA bus and enumerate the driver if a device is found.
It uses the hdac core helper APIs to parse the HDA widgets and identifies the number of mapping dapm widgets to be created. Based on the ADCs and DACs queries the codec dais are allocated and registers with asoc.
The AFG node is power managed through set_bias_level callback. Format is programmed though hw_params dai ops. Stream tag is programmed thorugh the set_tdm_slot callback.
--- sound/hda/ext/hdac_ext_bus.c | 7 +- sound/soc/codecs/Kconfig | 5 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/hdac_generic.c | 421 ++++++++++++++++++++++++++++++++++++++++ sound/soc/codecs/hdac_generic.h | 25 +++ 5 files changed, 459 insertions(+), 1 deletion(-) create mode 100644 sound/soc/codecs/hdac_generic.c create mode 100644 sound/soc/codecs/hdac_generic.h
sound/hda/ext/hdac_ext_bus.c +6 -1
@@ -162,7 +162,12 @@ int snd_hdac_ext_bus_device_init(struct hdac_ext_bus *ebus, int addr) hdev->dev.release = default_release;INIT_LIST_HEAD (&edev->widget_list); -snd_hdac_ext_parse_widgets (edev); + ret =snd_hdac_ext_parse_widgets (edev); +if (ret <0 ) { +dev_err (bus->dev,"Failed to parse widgets with err: %d\n" , + ret); +return ret; + } ret =snd_hdac_device_register (hdev);if (ret) {
sound/soc/codecs/Kconfig +5 -0
@@ -71,6 +71,7 @@ config SND_SOC_ALL_CODECS select SND_SOC_ES8328_SPI if SPI_MASTER select SND_SOC_ES8328_I2C if I2C select SND_SOC_GTM601 + select SND_SOC_HDAC_GENERIC select SND_SOC_HDAC_HDMI select SND_SOC_ICS43432 select SND_SOC_INNO_RK3036
@@ -523,6 +524,10 @@ config SND_SOC_ES8328_SPI config SND_SOC_GTM601 tristate 'GTM601 UMTS modem audio codec' +config SND_SOC_HDAC_GENERIC + tristate + select SND_HDA_EXT_CORE + config SND_SOC_HDAC_HDMI tristate select SND_HDA_EXT_CORE
sound/soc/codecs/Makefile +2 -0
@@ -65,6 +65,7 @@ snd-soc-es8328-objs := es8328.o snd-soc-es8328-i2c-objs := es8328-i2c.o snd-soc-es8328-spi-objs := es8328-spi.o snd-soc-gtm601-objs := gtm601.o +snd-soc-hdac-generic-objs := hdac_generic.o snd-soc-hdac-hdmi-objs := hdac_hdmi.o snd-soc-ics43432-objs := ics43432.o snd-soc-inno-rk3036-objs := inno_rk3036.o
@@ -287,6 +288,7 @@ 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_GTM601) += snd-soc-gtm601.o +obj-$(CONFIG_SND_SOC_HDAC_GENERIC) += snd-soc-hdac-generic.o obj-$(CONFIG_SND_SOC_HDAC_HDMI) += snd-soc-hdac-hdmi.o obj-$(CONFIG_SND_SOC_ICS43432) += snd-soc-ics43432.o obj-$(CONFIG_SND_SOC_INNO_RK3036) += snd-soc-inno-rk3036.o
sound/soc/codecs/hdac_generic.c new file +421 -0
421 lines not on this page · raw message
sound/soc/codecs/hdac_generic.h new file +25 -0
@@ -0,0 +1,25 @@ +/* +* hdac_generic.h - ASoc HDA generic codec driver +* +* Copyright (C) 2016 Intel Corp +* Author: Subhransu S. Prusty <[email protected]> +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* +* 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; version 2 of the License. +* +* 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. +* +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +*/ + +#ifndef __HDAC_GENERIC_H__ +#define __HDAC_GENERIC_H__ + +#define HDAC_GENERIC_NAME_SIZE 32 + +#endif /* __HDAC_GENERIC_H__ */
Signature · 1 line
1.9.1
PATCH v2 4/11 ALSA: hdac: Move 'to_hda_ext_device' helper to core
In reply to Subhransu S. PrustyThis helper is also useful for generic codec framework. So moving this to core for reuse.
--- include/sound/hdaudio_ext.h | 8 ++++++++ sound/soc/codecs/hdac_hdmi.c | 8 +------- 2 files changed, 9 insertions(+), 7 deletions(-)
include/sound/hdaudio_ext.h +8 -0
@@ -256,6 +256,14 @@ struct hdac_ext_dma_params { };#define to_ehdac_device (dev) (container_of((dev), \ struct hdac_ext_device, hdac)) + +static inline struct hdac_ext_device *to_hda_ext_device (struct device *dev) +{ +struct hdac_device *hdac =dev_to_hdac_dev (dev); + +return to_ehdac_device (hdac); +} +/* * HD-audio codec base driver */
sound/soc/codecs/hdac_hdmi.c +1 -7
@@ -30,6 +30,7 @@#include <sound/hda_i915.h> #include <sound/pcm_drm_eld.h> #include <sound/hda_chmap.h> +#include <sound/hdaudio_ext.h> #include "../../hda/local.h" #include "hdac_hdmi.h"
@@ -127,13 +128,6 @@ static struct hdac_hdmi_pcm *get_hdmi_pcm_from_id(struct hdac_hdmi_priv *hdmi,return NULL ; } -static inline struct hdac_ext_device *to_hda_ext_device (struct device *dev) -{ -struct hdac_device *hdac =dev_to_hdac_dev (dev); - -return to_ehdac_device (hdac); -} -static unsigned int sad_format (const u8 *sad) {return ((sad[0 ] >>0x3 ) &0x1f );
Signature · 1 line
1.9.1
PATCH v2 5/11 ASoC: hdac: Create DAPM model for HDA widgets
In reply to Subhransu S. PrustyHDA device widgets are mapped to dapm widgets to take advantage of DAPM. Each HDA widget can be mapped to one or multiple dapm widgets based on interface and how it is connected with other widgets.
For example, a PIN widget 2 or 3 dapm widgets are created depending on the capability. A dapm input/out widget is created to represent the input/output capability, a pga widget is created so that pin with retasking capability can be properly represented in a dapm graph and a mux widget for output pin is created, if the connection list has more than one input.
--- sound/soc/codecs/hdac_generic.c | 483 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 482 insertions(+), 1 deletion(-)
sound/soc/codecs/hdac_generic.c +482 -1
@@ -43,6 +43,16 @@ struct hdac_generic_priv {unsigned int num_dapm_widgets; }; +/* +* Widgets types can be accessed using an array with an index except vendor +* types. So fill NULL for the invalid indexes. +*/ +static char *wid_names[] = { +"dac" ,"adc" ,"mixer" ,"mux" ,"pin" ,"power" , +"volme knob" ,"beep" ,NULL ,NULL ,NULL ,NULL , +NULL ,NULL ,NULL ,"vendor" , +}; +static void hdac_generic_set_power_state (struct hdac_ext_device *edev,hda_nid_t nid,unsigned int pwr_state) {
@@ -52,6 +62,472 @@ static void hdac_generic_set_power_state(struct hdac_ext_device *edev, AC_VERB_SET_POWER_STATE, pwr_state); } +static inline int hdac_generic_fill_widget_info (struct device *dev, +struct snd_soc_dapm_widget *w,enum snd_soc_dapm_type id, +void *priv,const char *wname,const char *stream, +struct snd_kcontrol_new *wc,int numkc, +int (*event)(struct snd_soc_dapm_widget *, +struct snd_kcontrol *,int ),unsigned short event_flags) +{ + w->id = id; + w->name =devm_kstrdup (dev, wname,GFP_KERNEL ); +if (!w->name) +return -ENOMEM ; + + w->sname = stream; + w->reg =SND_SOC_NOPM ; + w->shift =0 ; + w->kcontrol_news = wc; + w->num_kcontrols = numkc; + w->priv = priv; + w->event = event; + w->event_flags = event_flags; + +return 0 ; +} + +static int hdac_generic_alloc_mux_widget (struct snd_soc_dapm_context *dapm, +struct snd_soc_dapm_widget *widgets,int index, +struct hdac_ext_codec_widget *wid) + +{ +struct snd_kcontrol_new *kc; +struct soc_enum *se; +char kc_name[HDAC_GENERIC_NAME_SIZE ]; +char mux_items[HDAC_GENERIC_NAME_SIZE ]; +char widget_name[HDAC_GENERIC_NAME_SIZE ]; +const char *name; +/* To hold inputs to the Pin mux */ +char *items[HDA_MAX_CONNECTIONS ]; +int i =0 , ret; +int num_items = wid->num_inputs +1 ; + +if (wid->type ==AC_WID_AUD_SEL ) +sprintf (widget_name,"Mux %x" , wid->nid); +else if (wid->type ==AC_WID_PIN ) +sprintf (widget_name,"Pin %x Mux" , wid->nid); +else +return -EINVAL ; + + kc =devm_kzalloc (dapm->dev,sizeof (*kc),GFP_KERNEL ); +if (!kc) +return -ENOMEM ; + + se =devm_kzalloc (dapm->dev,sizeof (*se),GFP_KERNEL ); +if (!se) +return -ENOMEM ; + +sprintf (kc_name,"Mux %d Input" , wid->nid); + kc->name =devm_kstrdup (dapm->dev, kc_name,GFP_KERNEL ); +if (!kc->name) +return -ENOMEM ; + + kc->private_value = (long )se; + kc->iface =SNDRV_CTL_ELEM_IFACE_MIXER ; + kc->access =0 ; + kc->info = snd_soc_info_enum_double; + kc->put = snd_soc_dapm_put_enum_double; + kc->get = snd_soc_dapm_get_enum_double; + + se->reg =SND_SOC_NOPM ; + + se->items = num_items; + se->mask =roundup_pow_of_two (se->items) -1 ; + +sprintf (mux_items,"NONE" ); + items[i] =devm_kstrdup (dapm->dev, mux_items,GFP_KERNEL ); +if (!items[i]) +return -ENOMEM ; + +for (i =0 ; i < wid->num_inputs; i++) { + name = wid_names[wid->conn_list[i].type]; +if (!name) +return -EINVAL ; + +sprintf (mux_items,"%s %x" , name, wid->conn_list[i].nid); + items[i +1 ] =devm_kstrdup (dapm->dev, mux_items,GFP_KERNEL ); +if (!items[i]) +return -ENOMEM ; + } + + se->texts =devm_kmemdup (dapm->dev, items, + (num_items *sizeof (char *)),GFP_KERNEL ); +if (!se->texts) +return -ENOMEM ; + + ret =hdac_generic_fill_widget_info (dapm->dev, &widgets[index], + snd_soc_dapm_mux, wid, widget_name,NULL , kc,1 , +NULL ,0 ); + +if (ret <0 ) +return ret; + + wid->priv = &widgets[index]; + +return 0 ; +} + +static const char *get_dai_stream (struct snd_soc_dai_driver *dai_drv, +int num_dais,struct hdac_ext_codec_widget *wid) +{ +int i; +struct hdac_ext_codec_widget *tmp; + +for (i =0 ; i < num_dais; i++) { + tmp = dai_drv[i].dobj.private; +if (tmp->nid == wid->nid) { +if (wid->type ==AC_WID_AUD_IN ) +return dai_drv[i].capture.stream_name; +else +return dai_drv[i].playback.stream_name; + } + } + +return NULL ; +} + +static int hdac_codec_alloc_cvt_widget (struct snd_soc_dapm_context *dapm, +struct snd_soc_dapm_widget *widgets,int index, +struct hdac_ext_codec_widget *wid) +{ +struct snd_soc_dai_driver *dai_drv = dapm->component->dai_drv; +char widget_name[HDAC_GENERIC_NAME_SIZE ]; +const char *dai_strm_name; +int ret =0 ; + + dai_strm_name =get_dai_stream (dai_drv, + dapm->component->num_dai, wid); +if (!dai_strm_name) +return -EINVAL ; + +if (wid->type ==AC_WID_AUD_IN ) { +sprintf (widget_name,"ADC %x" , wid->nid); + }else { +sprintf (widget_name,"%s DAC %x" , + (wid->caps &AC_WCAP_DIGITAL ) ?"Digital" :"Analog" , + wid->nid); + } + + ret =hdac_generic_fill_widget_info (dapm->dev, &widgets[index], + wid->type ==AC_WID_AUD_IN ? + snd_soc_dapm_aif_in : snd_soc_dapm_aif_out, + wid, widget_name, dai_strm_name,NULL ,0 ,NULL ,0 ); +if (ret <0 ) +return ret; + + wid->priv = &widgets[index]; + +return 0 ; +} + +static int hdac_codec_alloc_mixer_widget (struct snd_soc_dapm_context *dapm, +struct snd_soc_dapm_widget *w,int index, +struct hdac_ext_codec_widget *wid) +{ +struct snd_kcontrol_new *kc; +struct soc_mixer_control *mc; +char kc_name[HDAC_GENERIC_NAME_SIZE ]; +char widget_name[HDAC_GENERIC_NAME_SIZE ]; +const char *name; +int i, ret; + + kc =devm_kcalloc (dapm->dev, wid->num_inputs,sizeof (*kc),GFP_KERNEL ); +if (!kc) +return -ENOMEM ; + +for (i =0 ; i < wid->num_inputs; i++) { + name = wid_names[wid->conn_list[i].type]; +if (!name) +return -EINVAL ; + +sprintf (kc_name,"%s %x in Switch" , + name, wid->conn_list[i].nid); + kc[i].name =devm_kstrdup (dapm->dev, kc_name,GFP_KERNEL ); +if (!kc[i].name) +return -ENOMEM ; + + mc =devm_kzalloc (dapm->dev, (sizeof (*mc)),GFP_KERNEL ); +if (!mc) +return -ENOMEM ; + + mc->reg =SND_SOC_NOPM ; + mc->rreg =SND_SOC_NOPM ; + mc->max =1 ; + + kc[i].private_value = (long )mc; + kc[i].iface =SNDRV_CTL_ELEM_IFACE_MIXER ; + kc[i].info = snd_soc_info_volsw; + kc[i].put = snd_soc_dapm_put_volsw; + kc[i].get = snd_soc_dapm_get_volsw; + } + +sprintf (widget_name,"Mixer %x" , wid->nid); + ret =hdac_generic_fill_widget_info (dapm->dev, &w[index], + snd_soc_dapm_mixer, wid, widget_name,NULL , + kc, wid->num_inputs,NULL ,0 ); +if (ret <0 ) +return ret; + + wid->priv = &w[index]; + +return 0 ; +} + +/* +* Each Pin widget will be represented with: +* DAPM input/output - Based on out/in capability queried +* DAPM PGA - To program the PIN configuration +* DAPM Mux - Create a virtual Mux widget, if output capable pin can +* select from multiple inputs. +* +* Returns number of dapm widgets created on success else returns -ve error +* code. +*/ +static int hdac_codec_alloc_pin_widget (struct snd_soc_dapm_context *dapm, +struct snd_soc_dapm_widget *widgets,int index, +struct hdac_ext_codec_widget *wid) +{ +struct hdac_ext_device *edev =to_hda_ext_device (dapm->dev); +char widget_name[HDAC_GENERIC_NAME_SIZE ]; +int i = index; +int ret; +bool input; +/* +* Pin complex are represented with multiple dapm widgets. Cache them +* for easy reference. wid_ref[0]->input/output, wid_ref[1]->pga, +* wid_ref[2]->mux. +*/ +struct snd_soc_dapm_widget **wid_ref; + + input =is_input_pin (&edev->hdac, wid->nid); + + wid_ref =devm_kmalloc_array (dapm->dev,3 ,sizeof (wid_ref),GFP_KERNEL ); +if (!wid_ref) +return -ENOMEM ; +memset (wid_ref,0 ,3 *sizeof (wid_ref)); + +/* Create output/input widget */ +sprintf (widget_name,"Pin %x %s" , wid->nid, + input ?"Input" :"Output" ); + + ret =hdac_generic_fill_widget_info (dapm->dev, &widgets[i], + input ? snd_soc_dapm_input : snd_soc_dapm_output, + wid, widget_name,NULL ,NULL ,0 ,NULL ,0 ); +if (ret <0 ) +return ret; + + wid_ref[0 ] = &widgets[i++]; + +/* Create PGA widget */ +sprintf (widget_name,"Pin %x PGA" , wid->nid); + ret =hdac_generic_fill_widget_info (dapm->dev, &widgets[i], + snd_soc_dapm_pga, wid, widget_name,NULL , +NULL ,0 ,NULL ,0 ); +if (ret <0 ) +return ret; + + wid_ref[1 ] = &widgets[i++]; + +/* Create Mux if Pin widget can select from multiple inputs */ +if (!input && wid->num_inputs >1 ) { +sprintf (widget_name,"Pin %x Mux" , wid->nid); + ret =hdac_generic_alloc_mux_widget (dapm, widgets, i, wid); +if (ret <0 ) +return ret; + + wid_ref[2 ] = &widgets[i++]; + } + +/* override hda widget private with dapm widget group */ + wid->priv = wid_ref; + +/* Return number of dapm widgets created */ +return i - index; +} + +static int hdac_codec_alloc_power_widget (struct snd_soc_dapm_context *dapm, +struct snd_soc_dapm_widget *widgets,int index, +struct hdac_ext_codec_widget *wid) +{ +char widget_name[HDAC_GENERIC_NAME_SIZE ]; +int ret =0 ; + +sprintf (widget_name,"Power %x" , wid->nid); + ret =hdac_generic_fill_widget_info (dapm->dev, &widgets[index], + snd_soc_dapm_supply, wid, widget_name, +NULL ,NULL ,0 ,NULL ,0 ); +if (ret <0 ) +return ret; + + wid->priv = &widgets[index]; + +return 0 ; +} + +/* +* Each Beep hda widget will be represented with two dapm widget a siggen +* and a PGA. A virtual switch control will be added to turn on/off DAPM. +*/ +static int hdac_codec_alloc_beep_widget (struct snd_soc_dapm_context *dapm, +struct snd_soc_dapm_widget *widgets,int index, +struct hdac_ext_codec_widget *wid) +{ +char widget_name[HDAC_GENERIC_NAME_SIZE ]; +int i = index, ret =0 ; +struct soc_mixer_control *mc; +struct snd_kcontrol_new *kc; +char kc_name[HDAC_GENERIC_NAME_SIZE ]; +/* +* Beep widgets are represented with multiple dapm widgets. Cache them +* for each reference. wid_ref[0]->siggen, wid_ref[1]->pga. +*/ +struct snd_soc_dapm_widget **wid_ref; + + wid_ref =devm_kmalloc_array (dapm->dev,2 ,sizeof (wid_ref),GFP_KERNEL ); +if (!wid_ref) +return -ENOMEM ; +memset (wid_ref,0 ,2 *sizeof (wid_ref)); + +sprintf (widget_name,"Beep Gen %x" , wid->nid); + ret =hdac_generic_fill_widget_info (dapm->dev, &widgets[i++], + snd_soc_dapm_siggen, wid, widget_name, +NULL ,NULL ,0 ,NULL ,0 ); +if (ret <0 ) +return ret; + + kc =devm_kzalloc (dapm->dev, + (sizeof (*kc) * wid->num_inputs), +GFP_KERNEL ); +if (!kc) +return -ENOMEM ; + +sprintf (kc_name,"%s %x in Switch" , wid_names[wid->type], wid->nid); + kc[i].name =devm_kstrdup (dapm->dev, kc_name,GFP_KERNEL ); +if (!kc[i].name) +return -ENOMEM ; + mc =devm_kzalloc (dapm->dev, (sizeof (*mc)),GFP_KERNEL ); +if (!mc) +return -ENOMEM ; + + mc->reg =SND_SOC_NOPM ; + mc->rreg =SND_SOC_NOPM ; + mc->max =1 ; + + kc[i].private_value = (long )mc; + kc[i].iface =SNDRV_CTL_ELEM_IFACE_MIXER ; + kc[i].info = snd_soc_info_volsw; + kc[i].put = snd_soc_dapm_get_volsw; + kc[i].get = snd_soc_dapm_put_volsw; + +sprintf (widget_name,"Beep Gen %x PGA" , wid->nid); + ret =hdac_generic_fill_widget_info (dapm->dev, &widgets[i], + snd_soc_dapm_pga, wid, widget_name, +NULL , kc,1 ,NULL ,0 ); +if (ret <0 ) +return ret; + + wid->priv = wid_ref; + +return 0 ; +} + +/* Create DAPM widgets to represent each codec widget */ +static int hdac_codec_alloc_widgets (struct snd_soc_dapm_context *dapm, +struct snd_soc_dapm_widget *widgets) +{ +struct hdac_ext_device *edev =to_hda_ext_device (dapm->dev); +struct hdac_ext_codec_widget *wid; +int index =0 ; +int ret =0 ; + +list_for_each_entry (wid, &edev->widget_list, head) { +switch (wid->type) { +case AC_WID_AUD_IN : +case AC_WID_AUD_OUT : + ret =hdac_codec_alloc_cvt_widget (dapm, widgets, + index, wid); +if (ret <0 ) +return ret; + index++; +break ; + +case AC_WID_PIN : + ret =hdac_codec_alloc_pin_widget (dapm, widgets, + index, wid); +if (ret <0 ) +return ret; + index += ret; +break ; + +case AC_WID_AUD_MIX : + ret =hdac_codec_alloc_mixer_widget (dapm, widgets, + index, wid); +if (ret <0 ) +return ret; + index++; +break ; + +case AC_WID_AUD_SEL : + ret =hdac_generic_alloc_mux_widget (dapm, widgets, + index, wid); +if (ret <0 ) +return ret; + index++; +break ; + +case AC_WID_POWER : + ret =hdac_codec_alloc_power_widget (dapm, widgets, + index, wid); +if (ret <0 ) +return ret; + index++; +break ; + +case AC_WID_BEEP : + ret =hdac_codec_alloc_beep_widget (dapm, widgets, + index, wid); +if (ret <0 ) +return ret; + index +=2 ; +break ; + +default : +dev_warn (&edev->hdac.dev, +"dapm widget not allocated for type: %d\n" , + wid->type); +break ; + } + } + +return ret; +} + +static int hdac_generic_create_fill_widget_route_map ( +struct snd_soc_dapm_context *dapm) +{ +struct snd_soc_dapm_widget *widgets; +struct hdac_ext_device *edev =to_hda_ext_device (dapm->dev); +struct hdac_generic_priv *hdac_priv = edev->private_data; +int ret; + + widgets =devm_kzalloc (dapm->dev, + (sizeof (*widgets) * hdac_priv->num_dapm_widgets), +GFP_KERNEL ); +if (!widgets) +return -ENOMEM ; + +/* Create DAPM widgets */ + ret =hdac_codec_alloc_widgets (dapm, widgets); +if (ret <0 ) +return ret; + +snd_soc_dapm_new_controls (dapm, widgets, hdac_priv->num_dapm_widgets); + +/* TODO: Add each path to dapm graph when enumerated */ + +return 0 ; +} +static void hdac_generic_calc_dapm_widgets (struct hdac_ext_device *edev) {struct hdac_generic_priv *hdac_priv = edev->private_data;
@@ -192,10 +668,15 @@ static int hdac_codec_probe(struct snd_soc_codec *codec)struct hdac_ext_device *edev =snd_soc_codec_get_drvdata (codec);struct snd_soc_dapm_context *dapm =snd_soc_component_get_dapm (&codec->component); +int ret; edev->scodec = codec; -/* TODO: create widget, route and controls */ +/* create widget, route and controls */ + ret =hdac_generic_create_fill_widget_route_map (dapm); +if (ret <0 ) +return ret; +/* TODO: jack sense */ /* Imp: Store the card pointer in hda_codec */
Signature · 1 line
1.9.1
PATCH v2 6/11 ASoC: hdac: Build DAPM graph by querying through widget connection list
In reply to Subhransu S. PrustyThis patch recursively traverses the HDA codec widgets and builds the graph by querying connection list of each.
Only output pin widget and adc widget endpoints can support connection list. So for a playback path query happens from output pin widget end and for a capture path query happens from adc widget end till an input endpoint is found.
--- sound/soc/codecs/hdac_generic.c | 331 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 330 insertions(+), 1 deletion(-)
sound/soc/codecs/hdac_generic.c +330 -1
@@ -53,6 +53,19 @@ static char *wid_names[] = { NULL, NULL, NULL, "vendor", }; +struct route_map { +struct list_head head; +const char *sink; +char *control; +const char *src; +}; + +struct widget_node_entries { +struct hdac_ext_codec_widget *wid; +struct snd_soc_dapm_widget *w; +int num_nodes; +}; +static void hdac_generic_set_power_state (struct hdac_ext_device *edev,hda_nid_t nid,unsigned int pwr_state) {
@@ -62,6 +75,316 @@ static void hdac_generic_set_power_state(struct hdac_ext_device *edev, AC_VERB_SET_POWER_STATE, pwr_state); } +static bool is_duplicate_route (struct list_head *route_list, +const char *sink,const char *control,const char *src) +{ +struct route_map *map; + +list_for_each_entry (map, route_list, head) { + +if (strcmp (src, map->src)) +continue ; +if (strcmp (sink, map->sink)) +continue ; +if (!control && !map->control) +return true; +if ((control && map->control) && + !strcmp (control, map->control)) +return true; + } + +return false; +} + +static int hdac_generic_add_route (struct snd_soc_dapm_context *dapm, +const char *sink,const char *control,const char *src, +struct list_head *route_list) +{ +struct snd_soc_dapm_route route; +struct route_map *map; + +/* +* During parsing a loop can be created from input pin to output pin. +* An input pin is represented with pga and input dapm widgets. +* There is possibility of duplicate route between these two pga and +* input widgets as the input can appear for multiple output pins or +* adcs during connection list query. So check the duplication. +*/ +if (is_duplicate_route (route_list, sink, control, src)) +return 0 ; + + route.sink = sink; + route.source = src; + route.control = control; + route.connected =NULL ; + +snd_soc_dapm_add_routes (dapm, &route,1 ); + + map =kzalloc (sizeof (*map),GFP_KERNEL ); +if (!map) +return -ENOMEM ; + + map->sink = sink; + map->src = src; +if (control) { + map->control =kcalloc (SNDRV_CTL_ELEM_ID_NAME_MAXLEN , +sizeof (char ),GFP_KERNEL ); +if (!map->control) { +kfree (map); +return -ENOMEM ; + } + +strcpy (map->control, control); + } + +list_add_tail (&map->head, route_list); + +return 0 ; +} + +/* Returns the only dapm widget which can be connected to other hda widgets */ +static struct snd_soc_dapm_widget *hda_widget_to_dapm_widget ( +struct hdac_ext_device *edev, +struct hdac_ext_codec_widget *wid) +{ +struct snd_soc_dapm_widget **wid_ref; + +switch (wid->type) { +case AC_WID_PIN : + wid_ref = wid->priv; + +if (is_input_pin (&edev->hdac, wid->nid)) +return wid_ref[1 ]; + +if (wid->num_inputs ==1 ) +return wid_ref[1 ]; + +return wid_ref[2 ]; + +case AC_WID_BEEP : + wid_ref = wid->priv; + +return wid_ref[1 ]; + +case AC_WID_AUD_OUT : +case AC_WID_AUD_IN : +case AC_WID_AUD_MIX : +case AC_WID_AUD_SEL : +case AC_WID_POWER : +return wid->priv; + +default : +dev_info (&edev->hdac.dev,"Widget type %d not handled\n" , + wid->type); +return NULL ; + } + +return NULL ; +} + +static void fill_pinout_next_wid_entry (struct hdac_ext_device *edev, +struct widget_node_entries *next, +struct widget_node_entries *wid_entry, +const char **control,int index) +{ +struct snd_soc_dapm_widget **wid_ref = wid_entry->wid->priv; +const struct snd_kcontrol_new *kc; +struct soc_enum *se; + +switch (wid_entry->w->id) { +case snd_soc_dapm_output: + next->w = wid_ref[1 ]; + next->num_nodes =1 ; + next->wid = wid_entry->wid; + +break ; + +case snd_soc_dapm_pga: +if (wid_entry->wid->num_inputs ==1 ) { + next->wid = wid_entry->wid->conn_list[index].input_w; + next->w =hda_widget_to_dapm_widget ( + edev, next->wid); + next->num_nodes = next->wid->num_inputs; + }else { + next->wid = wid_entry->wid; + next->w = wid_ref[2 ]; + next->num_nodes = wid_entry->wid->num_inputs; + } + +break ; + +case snd_soc_dapm_mux: + kc = wid_entry->w->kcontrol_news; + se = (struct soc_enum *)kc->private_value; + + next->wid = wid_entry->wid->conn_list[index].input_w; + next->num_nodes = next->wid->num_inputs; + next->w =hda_widget_to_dapm_widget (edev, next->wid); + + *control = se->texts[index +1 ]; + +break ; + +default : +dev_warn (&edev->hdac.dev, +"widget nid: %d id: %d not handled\n" , + wid_entry->wid->nid, wid_entry->w->id); +break ; + } +} + +static int parse_node_and_add_route (struct snd_soc_dapm_context *dapm, +struct widget_node_entries *wid_entry, +struct list_head *route_list) +{ +struct hdac_ext_device *edev =to_hda_ext_device (dapm->dev); +int i, ret; +struct widget_node_entries next; +const char *control =NULL ; + +if (!wid_entry->num_nodes) +return 0 ; + +if ((wid_entry->w->id == snd_soc_dapm_dac) || + (wid_entry->w->id == snd_soc_dapm_input) || + (wid_entry->w->id == snd_soc_dapm_siggen)) { + +return 0 ; + } + +for (i =0 ; i < wid_entry->num_nodes; i++) { + +if (wid_entry->wid->type ==AC_WID_PIN ) { + control =NULL ; + +if (is_input_pin (&edev->hdac, wid_entry->wid->nid)) { + +struct snd_soc_dapm_widget **wid_ref = + wid_entry->wid->priv; + +if (wid_entry->w->id == snd_soc_dapm_pga) { + next.w = wid_ref[0 ]; + next.num_nodes =1 ; + next.wid = wid_entry->wid; + } + }else {/* if output pin */ +fill_pinout_next_wid_entry (edev, &next, + wid_entry, &control, i); + } + }else { +struct snd_soc_dapm_widget *w = wid_entry->wid->priv; +const struct snd_kcontrol_new *kc; +struct soc_enum *se; + + next.wid = wid_entry->wid->conn_list[i].input_w; + next.w =hda_widget_to_dapm_widget (edev, next.wid); +if (next.wid->type ==AC_WID_PIN && +is_input_pin (&edev->hdac, + next.wid->nid)) + next.num_nodes =1 ; +else + next.num_nodes = next.wid->num_inputs; + +switch (w->id) { +case snd_soc_dapm_mux: + kc = &w->kcontrol_news[0 ]; + se = (struct soc_enum *)kc->private_value; + control = se->texts[i +1 ]; + +break ; + +case snd_soc_dapm_mixer: + kc = &w->kcontrol_news[i]; + control = kc->name; + +break ; +default : +break ; + } + } + + ret =hdac_generic_add_route (dapm, wid_entry->w->name, + control, next.w->name, route_list); +if (ret <0 ) +return ret; + + ret =parse_node_and_add_route (dapm, &next, route_list); +if (ret <0 ) +return ret; + } + +return 0 ; +} + +/* +* Example graph connection from a output PIN to a DAC: +* DAC1-> +* Mixer 1 -------> +* DAC2-> Virtual Mux -> PIN PGA -> OUTPUT PIN +* -> +* LOUT1 ----------------| +* +* Widget connection map can be created by querying the connection list for +* each widget. The parsing can happen from two endpoints: +* 1) PIN widget 2) ADC widget. +* +* This goes through both pin list and adc list and builds the graph. +*/ + +static int hdac_generic_add_route_to_list (struct snd_soc_dapm_context *dapm, +struct snd_soc_dapm_widget *widgets) +{ +struct hdac_ext_device *edev =to_hda_ext_device (dapm->dev); +struct hdac_ext_codec_widget *wid; +struct snd_soc_dapm_widget **wid_ref; +struct widget_node_entries wid_entry; +struct list_head route_list; +struct route_map *map, *tmp; +int ret =0 ; + +/* +* manage the routes through a temp list to identify duplicate +* routes from being added. +*/ +INIT_LIST_HEAD (&route_list); +list_for_each_entry (wid, &edev->widget_list, head) { +if ((wid->type !=AC_WID_PIN ) && (wid->type !=AC_WID_AUD_IN )) +continue ; +/* +* input capable pins don't have a connection list, so skip +* them. +*/ +if ((wid->type ==AC_WID_PIN ) && + (is_input_pin (&edev->hdac, wid->nid))) +continue ; + +if (wid->type ==AC_WID_PIN ) { + wid_ref = wid->priv; + + wid_entry.wid = wid; + wid_entry.num_nodes =1 ; + wid_entry.w = wid_ref[0 ]; + }else { + wid_entry.wid = wid; + wid_entry.num_nodes = wid->num_inputs; + wid_entry.w = wid->priv; + } + + ret =parse_node_and_add_route (dapm, &wid_entry, &route_list); +if (ret <0 ) + goto fail; + } + +fail: +list_for_each_entry_safe (map, tmp, &route_list, head) { +kfree (map->control); +list_del (&map->head); +kfree (map); + } + +return ret; +} + static inline int hdac_generic_fill_widget_info(struct device *dev, struct snd_soc_dapm_widget *w, enum snd_soc_dapm_type id, void *priv, const char *wname, const char *stream,
@@ -523,7 +846,13 @@ static int hdac_generic_create_fill_widget_route_map(snd_soc_dapm_new_controls (dapm, widgets, hdac_priv->num_dapm_widgets); -/* TODO: Add each path to dapm graph when enumerated */ +/* Add each path to dapm graph when enumerated */ + ret =hdac_generic_add_route_to_list (dapm, widgets); +if (ret <0 ) +return ret; + +snd_soc_dapm_new_widgets (dapm->card); +return 0 ; }
Signature · 1 line
1.9.1
PATCH v2 7/11 ASoC: hdac: Register widget event handlers
In reply to Subhransu S. PrustyRegister the event handlers and program the codec by sending required verbs in the event handlers.
--- sound/soc/codecs/hdac_generic.c | 329 +++++++++++++++++++++++++++++++++++++++- sound/soc/codecs/hdac_generic.h | 3 + 2 files changed, 326 insertions(+), 6 deletions(-)
sound/soc/codecs/hdac_generic.c +323 -6
@@ -75,6 +75,305 @@ static void hdac_generic_set_power_state(struct hdac_ext_device *edev, AC_VERB_SET_POWER_STATE, pwr_state); } +/* TODO: Add feature to program by querying capability */ +static void hdac_generic_set_eapd (struct hdac_ext_device *edev, +hda_nid_t nid,bool enable) +{ +u32 pin_caps =snd_hdac_read_parm_uncached (&edev->hdac, + nid,AC_PAR_PIN_CAP ); + +if (pin_caps &AC_PINCAP_EAPD ) +snd_hdac_codec_write (&edev->hdac, nid,0 , +AC_VERB_SET_EAPD_BTLENABLE , enable ?2 :0 ); +} + +static int hdac_generic_pin_io_event (struct snd_soc_dapm_widget *w, +struct snd_kcontrol *kc,int event) +{ +struct hdac_ext_device *edev =to_hda_ext_device (w->dapm->dev); +struct hdac_ext_codec_widget *wid = w->priv; +int val; + +dev_dbg (&edev->hdac.dev,"%s: widget: %s event: %x\n" , + __func__, w->name, event); + + val =snd_hdac_codec_read (&edev->hdac, wid->nid,0 , +AC_VERB_GET_PIN_WIDGET_CONTROL ,0 ); + +switch (event) { +case SND_SOC_DAPM_PRE_PMU : +if (w->id == snd_soc_dapm_output) { +/* TODO: program using a eapd widget */ +hdac_generic_set_eapd (edev, wid->nid, true); + val |=AC_PINCTL_OUT_EN ; + }else { + +/* TODO: program vref using a mixer control */ + val |=AC_PINCTL_VREF_80 ; + val |=AC_PINCTL_IN_EN ; + } + +break ; + +case SND_SOC_DAPM_POST_PMD : +if (w->id == snd_soc_dapm_output) { +/* TODO: program using a eapd widget */ +hdac_generic_set_eapd (edev, wid->nid, false); + val &= ~AC_PINCTL_OUT_EN ; + }else { + val &=AC_PINCTL_VREF_HIZ ; + val &= ~AC_PINCTL_IN_EN ; + } + +break ; + +default : +dev_warn (&edev->hdac.dev,"Event %d not handled\n" , event); +return 0 ; + } + +snd_hdac_codec_write (&edev->hdac, wid->nid,0 , +AC_VERB_SET_PIN_WIDGET_CONTROL , val); + +return 0 ; +} + +static int hdac_generic_pin_mux_event (struct snd_soc_dapm_widget *w, +struct snd_kcontrol *kc,int event) +{ +struct hdac_ext_device *edev =to_hda_ext_device (w->dapm->dev); +struct hdac_ext_codec_widget *wid = w->priv; +int mux_idx; + +dev_dbg (&edev->hdac.dev,"%s: widget: %s event: %x\n" , + __func__, w->name, event); +if (!kc) + kc = w->kcontrols[0 ]; + + mux_idx =dapm_kcontrol_get_value (kc); +if (mux_idx >0 ) { +snd_hdac_codec_write (&edev->hdac, wid->nid,0 , +AC_VERB_SET_CONNECT_SEL , (mux_idx -1 )); + } + +return 0 ; +} + +static int hdac_generic_pin_pga_event (struct snd_soc_dapm_widget *w, +struct snd_kcontrol *kc,int event) +{ +struct hdac_ext_device *edev =to_hda_ext_device (w->dapm->dev); +struct hdac_ext_codec_widget *wid = w->priv; + +dev_dbg (&edev->hdac.dev,"%s: widget: %s event: %x\n" , + __func__, w->name, event); + +if (event ==SND_SOC_DAPM_POST_PMD ) { +hdac_generic_set_power_state (edev, wid->nid,AC_PWRST_D3 ); +snd_hdac_codec_write (&edev->hdac, wid->nid,0 , +AC_VERB_SET_AMP_GAIN_MUTE ,AMP_OUT_MUTE ); + }else { +hdac_generic_set_power_state (edev, wid->nid,AC_PWRST_D0 ); +snd_hdac_codec_write (&edev->hdac, wid->nid,0 , +AC_VERB_SET_AMP_GAIN_MUTE ,AMP_OUT_UNMUTE ); + } + +return 0 ; +} + +static int hdac_generic_widget_power_event (struct snd_soc_dapm_widget *w, +struct snd_kcontrol *kc,int event) +{ +struct hdac_ext_device *edev =to_hda_ext_device (w->dapm->dev); +struct hdac_ext_codec_widget *wid = w->priv; + +dev_dbg (&edev->hdac.dev,"%s: widget: %s event: %x\n" , + __func__, w->name, event); +hdac_generic_set_power_state (edev, wid->nid, + (event ==SND_SOC_DAPM_POST_PMD ?AC_PWRST_D3 :AC_PWRST_D0 )); + +return 0 ; +} + +static int hdac_generic_cvt_event (struct snd_soc_dapm_widget *w, +struct snd_kcontrol *kc,int event) +{ +struct hdac_ext_device *edev =to_hda_ext_device (w->dapm->dev); +struct hdac_ext_codec_widget *wid = w->priv; + +hdac_generic_widget_power_event (w, kc, event); + +if (event ==SND_SOC_DAPM_POST_PMD ) +snd_hdac_codec_write (&edev->hdac, wid->nid,0 , +AC_VERB_SET_AMP_GAIN_MUTE , +AMP_IN_MUTE (0 )); +else +snd_hdac_codec_write (&edev->hdac, wid->nid,0 , +AC_VERB_SET_AMP_GAIN_MUTE , +AMP_IN_UNMUTE (0 ) |0x5b ); + +return 0 ; +} + +static int get_mixer_control_index (struct snd_soc_dapm_widget *w, +struct snd_kcontrol *kc) +{ +int i; + +for (i =0 ; i < w->num_kcontrols; i++) { +if (w->kcontrols[i] == kc) +return i; + } + +return -EINVAL ; +} + +static int hdac_generic_mixer_event (struct snd_soc_dapm_widget *w, +struct snd_kcontrol *kc,int event) +{ +struct hdac_ext_device *edev =to_hda_ext_device (w->dapm->dev); +struct hdac_ext_codec_widget *wid = w->priv; +bool no_input = true; +int i; + +dev_dbg (&edev->hdac.dev,"%s: widget: %s event: %x\n" , + __func__, w->name, event); + +switch (event) { +case SND_SOC_DAPM_PRE_PMU : +hdac_generic_set_power_state (edev, wid->nid,AC_PWRST_D0 ); + + +snd_hdac_codec_write (&edev->hdac, wid->nid,0 , +AC_VERB_SET_AMP_GAIN_MUTE ,AMP_OUT_UNMUTE ); + +for (i =0 ; i < w->num_kcontrols; i++) { +if (dapm_kcontrol_get_value (w->kcontrols[i])) { +snd_hdac_codec_write (&edev->hdac, wid->nid,0 , +AC_VERB_SET_AMP_GAIN_MUTE , +AMP_IN_UNMUTE (i)); + } + } + +return 0 ; + +case SND_SOC_DAPM_POST_PMD : +snd_hdac_codec_write (&edev->hdac, wid->nid,0 , +AC_VERB_SET_AMP_GAIN_MUTE ,AMP_OUT_MUTE ); + +for (i =0 ; i < w->num_kcontrols; i++) { +if (dapm_kcontrol_get_value (w->kcontrols[i])) { +snd_hdac_codec_write (&edev->hdac, wid->nid,0 , +AC_VERB_SET_AMP_GAIN_MUTE , +AMP_IN_MUTE (i)); + } + } + +hdac_generic_set_power_state (edev, wid->nid,AC_PWRST_D3 ); + +return 0 ; + +case SND_SOC_DAPM_POST_REG : + i =get_mixer_control_index (w, kc); +if (i <0 ) { +dev_err (&edev->hdac.dev, +"%s: Wrong kcontrol event: %s\n" , + __func__, kc->id.name); +return i; + } +if (dapm_kcontrol_get_value (kc)) { +snd_hdac_codec_write (&edev->hdac, wid->nid,0 , +AC_VERB_SET_AMP_GAIN_MUTE ,AMP_IN_UNMUTE (i)); + no_input = false; + }else { +snd_hdac_codec_write (&edev->hdac, wid->nid,0 , +AC_VERB_SET_AMP_GAIN_MUTE ,AMP_IN_MUTE (i)); + } + +if (no_input) +snd_hdac_codec_write (&edev->hdac, wid->nid,0 , +AC_VERB_SET_AMP_GAIN_MUTE ,AMP_OUT_MUTE ); + +return 0 ; + +default : +dev_warn (&edev->hdac.dev,"Event %d not handled\n" , event); +return 0 ; + } + +return 0 ; +} + +static void update_mux_amp_switch (struct hdac_ext_device *edev, +hda_nid_t nid,struct snd_kcontrol *kc,bool enable) +{ +struct soc_enum *e = (struct soc_enum *)kc->private_value; +int mux_idx, i; + + mux_idx =dapm_kcontrol_get_value (kc); + +if (!enable || !mux_idx) { +for (i =1 ; i < (e->items -1 ); i++) +snd_hdac_codec_write (&edev->hdac, nid,0 , +AC_VERB_SET_AMP_GAIN_MUTE ,AMP_IN_MUTE (i -1 )); + +snd_hdac_codec_write (&edev->hdac, nid,0 , +AC_VERB_SET_AMP_GAIN_MUTE ,AMP_OUT_MUTE ); + }else { +for (i =1 ; i < (e->items -1 ); i++) { +if (i == mux_idx) +snd_hdac_codec_write (&edev->hdac, nid,0 , +AC_VERB_SET_AMP_GAIN_MUTE , +AMP_IN_UNMUTE (i -1 )); +else +snd_hdac_codec_write (&edev->hdac, nid,0 , +AC_VERB_SET_AMP_GAIN_MUTE , +AMP_IN_MUTE (i -1 )); + } + +snd_hdac_codec_write (&edev->hdac, nid,0 , +AC_VERB_SET_AMP_GAIN_MUTE ,AMP_OUT_UNMUTE ); + } +} + +static int hdac_generic_selector_event (struct snd_soc_dapm_widget *w, +struct snd_kcontrol *kc,int event) +{ +struct hdac_ext_device *edev =to_hda_ext_device (w->dapm->dev); +struct hdac_ext_codec_widget *wid = w->priv; + +dev_dbg (&edev->hdac.dev,"%s: widget: %s event: %x\n" , + __func__, w->name, event); + +switch (event) { +case SND_SOC_DAPM_PRE_PMU : +hdac_generic_set_power_state (edev, wid->nid,AC_PWRST_D0 ); +snd_hdac_codec_write (&edev->hdac, wid->nid,0 , +AC_VERB_SET_CONNECT_SEL , + (dapm_kcontrol_get_value (w->kcontrols[0 ]) -1 )); +update_mux_amp_switch (edev, wid->nid, w->kcontrols[0 ], true); + +return 0 ; + +case SND_SOC_DAPM_POST_REG : +update_mux_amp_switch (edev, wid->nid, kc, true); + +return 0 ; + +case SND_SOC_DAPM_POST_PMD : +update_mux_amp_switch (edev, wid->nid, w->kcontrols[0 ], false); +hdac_generic_set_power_state (edev, wid->nid,AC_PWRST_D3 ); + +return 0 ; + +default : +dev_warn (&edev->hdac.dev,"Event %d not handled\n" , event); +return 0 ; + } + +return 0 ; +} +static bool is_duplicate_route (struct list_head *route_list,const char *sink,const char *control,const char *src) {
@@ -480,7 +779,8 @@ static int hdac_generic_alloc_mux_widget(struct snd_soc_dapm_context *dapm, ret =hdac_generic_fill_widget_info (dapm->dev, &widgets[index], snd_soc_dapm_mux, wid, widget_name,NULL , kc,1 , -NULL ,0 ); + hdac_generic_selector_event,SND_SOC_DAPM_PRE_PMU | +SND_SOC_DAPM_POST_PMD |SND_SOC_DAPM_POST_REG );if (ret <0 )return ret;
@@ -534,7 +834,9 @@ static int hdac_codec_alloc_cvt_widget(struct snd_soc_dapm_context *dapm, ret =hdac_generic_fill_widget_info (dapm->dev, &widgets[index], wid->type ==AC_WID_AUD_IN ? snd_soc_dapm_aif_in : snd_soc_dapm_aif_out, - wid, widget_name, dai_strm_name,NULL ,0 ,NULL ,0 ); + wid, widget_name, dai_strm_name,NULL ,0 , + hdac_generic_cvt_event, +SND_SOC_DAPM_PRE_PMU |SND_SOC_DAPM_POST_PMD );if (ret <0 )return ret;
@@ -587,7 +889,9 @@ static int hdac_codec_alloc_mixer_widget(struct snd_soc_dapm_context *dapm,sprintf (widget_name,"Mixer %x" , wid->nid); ret =hdac_generic_fill_widget_info (dapm->dev, &w[index], snd_soc_dapm_mixer, wid, widget_name,NULL , - kc, wid->num_inputs,NULL ,0 ); + kc, wid->num_inputs, hdac_generic_mixer_event, +SND_SOC_DAPM_PRE_PMU |SND_SOC_DAPM_POST_PMD | +SND_SOC_DAPM_POST_REG );if (ret <0 )return ret;
@@ -635,7 +939,9 @@ static int hdac_codec_alloc_pin_widget(struct snd_soc_dapm_context *dapm, ret =hdac_generic_fill_widget_info (dapm->dev, &widgets[i], input ? snd_soc_dapm_input : snd_soc_dapm_output, - wid, widget_name,NULL ,NULL ,0 ,NULL ,0 ); + wid, widget_name,NULL ,NULL ,0 , + hdac_generic_pin_io_event, +SND_SOC_DAPM_PRE_PMU |SND_SOC_DAPM_POST_PMD );if (ret <0 )return ret;
@@ -645,7 +951,8 @@ static int hdac_codec_alloc_pin_widget(struct snd_soc_dapm_context *dapm,sprintf (widget_name,"Pin %x PGA" , wid->nid); ret =hdac_generic_fill_widget_info (dapm->dev, &widgets[i], snd_soc_dapm_pga, wid, widget_name,NULL , -NULL ,0 ,NULL ,0 ); +NULL ,0 , hdac_generic_pin_pga_event, +SND_SOC_DAPM_PRE_PMU |SND_SOC_DAPM_POST_PMD );if (ret <0 )return ret;
@@ -657,6 +964,15 @@ static int hdac_codec_alloc_pin_widget(struct snd_soc_dapm_context *dapm, ret =hdac_generic_alloc_mux_widget (dapm, widgets, i, wid);if (ret <0 )return ret; +/* +* Pin mux will not use generic selector handler, so +* override. Also mux widget create will increment the +* index, so assign the previous widget. +*/ + widgets[i].event_flags =SND_SOC_DAPM_PRE_PMU | +SND_SOC_DAPM_POST_PMD | +SND_SOC_DAPM_POST_REG ; + widgets[i].event = hdac_generic_pin_mux_event; wid_ref[2 ] = &widgets[i++]; }
@@ -678,7 +994,8 @@ static int hdac_codec_alloc_power_widget(struct snd_soc_dapm_context *dapm,sprintf (widget_name,"Power %x" , wid->nid); ret =hdac_generic_fill_widget_info (dapm->dev, &widgets[index], snd_soc_dapm_supply, wid, widget_name, -NULL ,NULL ,0 ,NULL ,0 ); +NULL ,NULL ,0 , hdac_generic_widget_power_event, +SND_SOC_DAPM_PRE_PMU |SND_SOC_DAPM_POST_PMD );if (ret <0 )return ret;
sound/soc/codecs/hdac_generic.h +3 -0
@@ -21,5 +21,8 @@#define __HDAC_GENERIC_H__#define HDAC_GENERIC_NAME_SIZE 32 +#define AMP_OUT_MUTE 0xb080 +#define AMP_OUT_UNMUTE 0xb000 +#define PIN_OUT (AC_PINCTL_OUT_EN)#endif /* __HDAC_GENERIC_H__ */
Signature · 1 line
1.9.1
PATCH v2 8/11 ALSA: hda - macro to get default config device of pin widgets
In reply to Subhransu S. PrustyIn ASoC this easy macro can be used to identify the default endpoint configuration and create DAPM endpoint widgets.
--- sound/hda/local.h | 3 +++ 1 file changed, 3 insertions(+)
sound/hda/local.h +3 -0
@@ -11,6 +11,9 @@#define get_pcaps (codec, nid) \ snd_hdac_read_parm(codec, nid, AC_PAR_PIN_CAP) +#define get_defcfg_device (cfg) \ + ((cfg & AC_DEFCFG_DEVICE) >> AC_DEFCFG_DEVICE_SHIFT) +static inline bool is_input_pin (struct hdac_device *codec,hda_nid_t nid) {unsigned int pincap =get_pcaps (codec, nid);
Signature · 1 line
1.9.1
PATCH v2 9/11 ASoC: hdac: Export API to create machine controls
In reply to Subhransu S. PrustyThe default configuration of pin complex is queried and machine controls are created.
--- sound/soc/codecs/hdac_generic.c | 170 ++++++++++++++++++++++++++++++++++++++++ sound/soc/codecs/hdac_generic.h | 3 + 2 files changed, 173 insertions(+)
sound/soc/codecs/hdac_generic.c +170 -0
@@ -708,6 +708,176 @@ static inline int hdac_generic_fill_widget_info(struct device *dev,return 0 ; } +static int hdac_generic_add_machine_control (struct snd_soc_dapm_context *dapm, +enum snd_soc_dapm_type id,const char *name, +struct hdac_ext_codec_widget *wid,int dir) +{ +struct snd_soc_dapm_widget **wid_ref; +struct snd_soc_dapm_widget *dapm_w; +struct snd_soc_dapm_route route; +char widget_name[HDAC_GENERIC_NAME_SIZE ]; +int ret; + + dapm_w =devm_kzalloc (dapm->dev,sizeof (*dapm_w),GFP_KERNEL ); +if (!dapm_w) +return -ENOMEM ; + +sprintf (widget_name,"%s %x" , name, wid->nid); + + ret =hdac_generic_fill_widget_info (dapm->dev, dapm_w, + id,NULL , widget_name, +NULL ,NULL ,0 ,NULL ,0 ); +if (ret <0 ) +return ret; + + wid_ref = wid->priv; + +snd_soc_dapm_new_control (dapm, dapm_w); +if (dir ==SNDRV_PCM_STREAM_PLAYBACK ) { + route.sink = dapm_w->name; + route.control =NULL ; + route.source = wid_ref[0 ]->name; + route.connected =NULL ; + }else { + route.sink = wid_ref[0 ]->name; + route.control =NULL ; + route.source = dapm_w->name; + route.connected =NULL ; + } +snd_soc_dapm_add_routes (dapm, &route,1 ); +snd_soc_dapm_new_widgets (dapm->card); + +return 0 ; +} + +/** +* hdac_generic_machine_control_init - Add machine widgets and graph +* @dapm: machine dapm context +* @codec: codec object +* +* Reads the default configuration parameters and builds the machine +* controls and graph. +*/ +int hdac_generic_machine_control_init (struct snd_soc_dapm_context *dapm, +struct snd_soc_codec *codec) +{ +struct hdac_ext_device *edev =snd_soc_codec_get_drvdata (codec); +struct hdac_ext_codec_widget *wid; +struct snd_soc_dapm_widget **wid_ref; +unsigned int *cfg; +short dev; +int ret; + +list_for_each_entry (wid, &edev->widget_list, head) { + +dev_dbg (dapm->dev,"For wid: %x type: %d\n" , + wid->nid, wid->type); +if (wid->type !=AC_WID_PIN ) +continue ; + + cfg = wid->params; + dev =get_defcfg_device (*cfg); + +if (is_input_pin (&edev->hdac, wid->nid) && + ((dev ==AC_JACK_LINE_OUT ) || + (dev ==AC_JACK_SPEAKER ) || + (dev ==AC_JACK_DIG_OTHER_OUT ) || + (dev ==AC_JACK_HP_OUT ) || + (dev ==AC_JACK_SPDIF_OUT ))) { + +dev_warn (dapm->dev, +"Wrong pin and dev configuration, nid: %x\n" , + wid->nid); + +continue ; + } + +switch (dev) { +case AC_JACK_LINE_OUT : + ret =hdac_generic_add_machine_control (dapm, + snd_soc_dapm_line,"Lineout" , + wid,SNDRV_PCM_STREAM_PLAYBACK ); +if (ret <0 ) +return ret; +break ; +case AC_JACK_SPEAKER : + ret =hdac_generic_add_machine_control (dapm, + snd_soc_dapm_spk,"spk" , + wid,SNDRV_PCM_STREAM_PLAYBACK ); +if (ret <0 ) +return ret; +break ; +case AC_JACK_SPDIF_OUT : + ret =hdac_generic_add_machine_control (dapm, + snd_soc_dapm_spk,"spdif_out" , + wid,SNDRV_PCM_STREAM_PLAYBACK ); +if (ret <0 ) +return ret; +break ; +case AC_JACK_DIG_OTHER_OUT : + ret =hdac_generic_add_machine_control (dapm, + snd_soc_dapm_spk,"dig_other_out" , + wid,SNDRV_PCM_STREAM_PLAYBACK ); +if (ret <0 ) +return ret; +break ; + +case AC_JACK_HP_OUT : + ret =hdac_generic_add_machine_control (dapm, + snd_soc_dapm_hp,"hp" , + wid,SNDRV_PCM_STREAM_PLAYBACK ); +if (ret <0 ) +return ret; +break ; + +case AC_JACK_AUX : + ret =hdac_generic_add_machine_control (dapm, + snd_soc_dapm_line,"Aux" , + wid,SNDRV_PCM_STREAM_CAPTURE ); +if (ret <0 ) +return ret; +break ; +case AC_JACK_LINE_IN : + ret =hdac_generic_add_machine_control (dapm, + snd_soc_dapm_line,"Linein" , + wid,SNDRV_PCM_STREAM_CAPTURE ); +if (ret <0 ) +return ret; +break ; + +case AC_JACK_MIC_IN : + ret =hdac_generic_add_machine_control (dapm, + snd_soc_dapm_mic,"MIC" , + wid,SNDRV_PCM_STREAM_CAPTURE ); +if (ret <0 ) +return ret; +break ; +case AC_JACK_SPDIF_IN : + ret =hdac_generic_add_machine_control (dapm, + snd_soc_dapm_mic,"spdif_in" , + wid,SNDRV_PCM_STREAM_CAPTURE ); +if (ret <0 ) +return ret; +break ; +case AC_JACK_DIG_OTHER_IN : + ret =hdac_generic_add_machine_control (dapm, + snd_soc_dapm_mic,"dig_other_in" , + wid,SNDRV_PCM_STREAM_CAPTURE ); +if (ret <0 ) +return ret; +break ; + +default : + wid_ref = wid->priv; +snd_soc_dapm_nc_pin (dapm, wid_ref[0 ]->name); +break ; + } + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (hdac_generic_machine_control_init); +static int hdac_generic_alloc_mux_widget (struct snd_soc_dapm_context *dapm,struct snd_soc_dapm_widget *widgets,int index,struct hdac_ext_codec_widget *wid)
sound/soc/codecs/hdac_generic.h +3 -0
@@ -25,4 +25,7 @@#define AMP_OUT_UNMUTE 0xb000#define PIN_OUT (AC_PINCTL_OUT_EN) +int hdac_generic_machine_control_init (struct snd_soc_dapm_context *dapm, +struct snd_soc_codec *codec); +#endif /* __HDAC_GENERIC_H__ */
Signature · 1 line
1.9.1
PATCH v2 10/11 ALSA: hdac: Implement a match function
In reply to Subhransu S. PrustyExt driver match function will be used to apply any hdac device specific quirks.
--- include/sound/hdaudio_ext.h | 1 + sound/hda/ext/hdac_ext_bus.c | 13 +++++++++++++ 2 files changed, 14 insertions(+)
include/sound/hdaudio_ext.h +1 -0
@@ -248,6 +248,7 @@ struct hdac_ext_device {void *private_data;struct list_head widget_list; +const struct hda_device_id *id_entry; };struct hdac_ext_dma_params {
sound/hda/ext/hdac_ext_bus.c +13 -0
@@ -246,6 +246,18 @@ static void hdac_ext_drv_shutdown(struct device *dev)return (get_edrv (dev))->shutdown (get_edev (dev)); } +static int hdac_ext_drv_match (struct hdac_device *dev,struct hdac_driver *drv) +{ +struct hdac_ext_device *edev =get_edev (&dev->dev); +const struct hda_device_id *id_entry =hdac_get_device_id (dev, drv); + +if (id_entry) { + edev->id_entry = id_entry; +return 1 ; + }else +return 0 ; +} +/** * snd_hda_ext_driver_register - register a driver for ext hda devices *
@@ -255,6 +267,7 @@ int snd_hda_ext_driver_register(struct hdac_ext_driver *drv) { drv->hdac.type =HDA_DEV_ASOC ; drv->hdac.driver.bus = &snd_hda_bus_type; + drv->hdac.match = hdac_ext_drv_match;/* we use default match */ if (drv->probe)
Signature · 1 line
1.9.1
PATCH v2 11/11 ASoC: hdac: Add coefficient init callback for RT286
In reply to Subhransu S. PrustyConfigure the combojack for rt286 with the init callback.
--- sound/soc/codecs/hdac_generic.c | 39 ++++++++++++++++++++++++++++++++------- sound/soc/codecs/hdac_generic.h | 5 +++++ 2 files changed, 37 insertions(+), 7 deletions(-)
sound/soc/codecs/hdac_generic.c +32 -7
@@ -41,6 +41,7 @@ struct hdac_generic_priv {unsigned int num_adcs;unsigned int num_dacs;unsigned int num_dapm_widgets; +struct hdac_generic_vendor_ops *vendor_ops; };/*
@@ -1643,6 +1644,7 @@ static int hdac_generic_dev_probe(struct hdac_ext_device *edev)struct hdac_device *codec = &edev->hdac;struct hdac_generic_priv *hdac_priv;struct snd_soc_dai_driver *codec_dais =NULL ; +struct hdac_generic_vendor_ops *ops;int num_dais =0 ;int ret =0 ;
@@ -1672,19 +1674,42 @@ static int hdac_generic_dev_probe(struct hdac_ext_device *edev)return ret; } +/* codec specific init if any */ + ops = (struct hdac_generic_vendor_ops *)edev->id_entry->driver_data; +if (ops && ops->init) { + ret = ops->init (edev); +if (ret <0 ) +return ret; + } + + hdac_priv->vendor_ops = ops; +/* ASoC specific initialization */ return snd_soc_register_codec (&codec->dev, &hdac_generic_codec, codec_dais, num_dais); } -/* -* TODO: -* Driver_data will be used to perform any vendor specific init, register -* specific dai ops. -* Driver will implement it's own match function to retrieve driver data. -*/ +static void write_def_coeffs (struct hdac_ext_device *edev) +{ +snd_hdac_codec_write (&edev->hdac,0x20 ,0 , +AC_VERB_SET_COEF_INDEX ,0x4f ); +snd_hdac_codec_write (&edev->hdac,0x20 ,0 , +AC_VERB_SET_PROC_COEF ,0x5000 ); +} + +int hdac_realtek_init (struct hdac_ext_device *edev) +{ +write_def_coeffs (edev); + +return 0 ; +} + +struct hdac_generic_vendor_ops realtek_ops = { + .init = hdac_realtek_init, +}; +static const struct hda_device_id codec_list[] = { -HDA_CODEC_EXT_ENTRY (0x10ec0286 ,0x100002 ,"ALC286" ,0 ), +HDA_CODEC_EXT_ENTRY (0x10ec0286 ,0x100002 ,"ALC286" , &realtek_ops), {} };MODULE_DEVICE_TABLE (hdaudio, codec_list);
sound/soc/codecs/hdac_generic.h +5 -0
@@ -25,6 +25,11 @@#define AMP_OUT_UNMUTE 0xb000#define PIN_OUT (AC_PINCTL_OUT_EN) +struct hdac_generic_vendor_ops { +int (*init)(struct hdac_ext_device *edev); +int (*cleanup)(struct hdac_ext_device *edev); +}; +int hdac_generic_machine_control_init (struct snd_soc_dapm_context *dapm,struct snd_soc_codec *codec);
Signature · 1 line
1.9.1