Patchwork [2/2] hda-codec: make mixemu selectable at runtime

login
register
mail settings
Submitter Bandan Das
Date Aug. 27, 2013, 7:17 p.m.
Message ID <1377631034-24409-3-git-send-email-bsd@redhat.com>
Download mbox | patch
Permalink /patch/270205/
State New
Headers show

Comments

Bandan Das - Aug. 27, 2013, 7:17 p.m.
Define PARAM so that we have two versions of the "desc_codec 
and family" structs. Add a property called "mixer" whose default
value depends on whether CONFIG_MIXEMU is defined or not which
will help us call the appropriate instance init functions.

Signed-off-by: Bandan Das <bsd@redhat.com>
---
 hw/audio/hda-codec-common.h | 114 +++++++++++++++++++++++---------------------
 hw/audio/hda-codec.c        |  48 +++++++++++++++++--
 2 files changed, 105 insertions(+), 57 deletions(-)

Patch

diff --git a/hw/audio/hda-codec-common.h b/hw/audio/hda-codec-common.h
index 8433e40..01319af 100644
--- a/hw/audio/hda-codec-common.h
+++ b/hw/audio/hda-codec-common.h
@@ -20,7 +20,7 @@ 
 
 
 /* common: audio output widget */
-static const desc_param common_params_audio_dac[] = {
+static const desc_param glue(common_params_audio_dac_, PARAM)[] = {
     {
         .id  = AC_PAR_AUDIO_WIDGET_CAP,
         .val = ((AC_WID_AUD_OUT << AC_WCAP_TYPE_SHIFT) |
@@ -44,7 +44,7 @@  static const desc_param common_params_audio_dac[] = {
 };
 
 /* common: audio input widget */
-static const desc_param common_params_audio_adc[] = {
+static const desc_param glue(common_params_audio_adc_, PARAM)[] = {
     {
         .id  = AC_PAR_AUDIO_WIDGET_CAP,
         .val = ((AC_WID_AUD_IN << AC_WCAP_TYPE_SHIFT) |
@@ -72,7 +72,7 @@  static const desc_param common_params_audio_adc[] = {
 };
 
 /* common: pin widget (line-out) */
-static const desc_param common_params_audio_lineout[] = {
+static const desc_param glue(common_params_audio_lineout_, PARAM)[] = {
     {
         .id  = AC_PAR_AUDIO_WIDGET_CAP,
         .val = ((AC_WID_PIN << AC_WCAP_TYPE_SHIFT) |
@@ -94,7 +94,7 @@  static const desc_param common_params_audio_lineout[] = {
 };
 
 /* common: pin widget (line-in) */
-static const desc_param common_params_audio_linein[] = {
+static const desc_param glue(common_params_audio_linein_, PARAM)[] = {
     {
         .id  = AC_PAR_AUDIO_WIDGET_CAP,
         .val = ((AC_WID_PIN << AC_WCAP_TYPE_SHIFT) |
@@ -112,7 +112,7 @@  static const desc_param common_params_audio_linein[] = {
 };
 
 /* output: root node */
-static const desc_param output_params_root[] = {
+static const desc_param glue(output_params_root_, PARAM)[] = {
     {
         .id  = AC_PAR_VENDOR_ID,
         .val = QEMU_HDA_ID_OUTPUT,
@@ -129,7 +129,7 @@  static const desc_param output_params_root[] = {
 };
 
 /* output: audio function */
-static const desc_param output_params_audio_func[] = {
+static const desc_param glue(output_params_audio_func_, PARAM)[] = {
     {
         .id  = AC_PAR_FUNCTION_TYPE,
         .val = AC_GRP_AUDIO_FUNCTION,
@@ -164,28 +164,28 @@  static const desc_param output_params_audio_func[] = {
 };
 
 /* output: nodes */
-static const desc_node output_nodes[] = {
+static const desc_node glue(output_nodes_, PARAM)[] = {
     {
         .nid     = AC_NODE_ROOT,
         .name    = "root",
-        .params  = output_params_root,
-        .nparams = ARRAY_SIZE(output_params_root),
+        .params  = glue(output_params_root_, PARAM),
+        .nparams = ARRAY_SIZE(glue(output_params_root_, PARAM)),
     },{
         .nid     = 1,
         .name    = "func",
-        .params  = output_params_audio_func,
-        .nparams = ARRAY_SIZE(output_params_audio_func),
+        .params  = glue(output_params_audio_func_, PARAM),
+        .nparams = ARRAY_SIZE(glue(output_params_audio_func_, PARAM)),
     },{
         .nid     = 2,
         .name    = "dac",
-        .params  = common_params_audio_dac,
-        .nparams = ARRAY_SIZE(common_params_audio_dac),
+        .params  = glue(common_params_audio_dac_, PARAM),
+        .nparams = ARRAY_SIZE(glue(common_params_audio_dac_, PARAM)),
         .stindex = 0,
     },{
         .nid     = 3,
         .name    = "out",
-        .params  = common_params_audio_lineout,
-        .nparams = ARRAY_SIZE(common_params_audio_lineout),
+        .params  = glue(common_params_audio_lineout_, PARAM),
+        .nparams = ARRAY_SIZE(glue(common_params_audio_lineout_, PARAM)),
         .config  = ((AC_JACK_PORT_COMPLEX << AC_DEFCFG_PORT_CONN_SHIFT) |
                     (AC_JACK_LINE_OUT     << AC_DEFCFG_DEVICE_SHIFT)    |
                     (AC_JACK_CONN_UNKNOWN << AC_DEFCFG_CONN_TYPE_SHIFT) |
@@ -197,15 +197,15 @@  static const desc_node output_nodes[] = {
 };
 
 /* output: codec */
-static const desc_codec output = {
+static const desc_codec glue(output_, PARAM) = {
     .name   = "output",
     .iid    = QEMU_HDA_ID_OUTPUT,
-    .nodes  = output_nodes,
-    .nnodes = ARRAY_SIZE(output_nodes),
+    .nodes  = glue(output_nodes_, PARAM),
+    .nnodes = ARRAY_SIZE(glue(output_nodes_, PARAM)),
 };
 
 /* duplex: root node */
-static const desc_param duplex_params_root[] = {
+static const desc_param glue(duplex_params_root_, PARAM)[] = {
     {
         .id  = AC_PAR_VENDOR_ID,
         .val = QEMU_HDA_ID_DUPLEX,
@@ -222,7 +222,7 @@  static const desc_param duplex_params_root[] = {
 };
 
 /* duplex: audio function */
-static const desc_param duplex_params_audio_func[] = {
+static const desc_param glue(duplex_params_audio_func_, PARAM)[] = {
     {
         .id  = AC_PAR_FUNCTION_TYPE,
         .val = AC_GRP_AUDIO_FUNCTION,
@@ -257,28 +257,28 @@  static const desc_param duplex_params_audio_func[] = {
 };
 
 /* duplex: nodes */
-static const desc_node duplex_nodes[] = {
+static const desc_node glue(duplex_nodes_, PARAM)[] = {
     {
         .nid     = AC_NODE_ROOT,
         .name    = "root",
-        .params  = duplex_params_root,
-        .nparams = ARRAY_SIZE(duplex_params_root),
+        .params  = glue(duplex_params_root_, PARAM),
+        .nparams = ARRAY_SIZE(glue(duplex_params_root_, PARAM)),
     },{
         .nid     = 1,
         .name    = "func",
-        .params  = duplex_params_audio_func,
-        .nparams = ARRAY_SIZE(duplex_params_audio_func),
+        .params  = glue(duplex_params_audio_func_, PARAM),
+        .nparams = ARRAY_SIZE(glue(duplex_params_audio_func_, PARAM)),
     },{
         .nid     = 2,
         .name    = "dac",
-        .params  = common_params_audio_dac,
-        .nparams = ARRAY_SIZE(common_params_audio_dac),
+        .params  = glue(common_params_audio_dac_, PARAM),
+        .nparams = ARRAY_SIZE(glue(common_params_audio_dac_, PARAM)),
         .stindex = 0,
     },{
         .nid     = 3,
         .name    = "out",
-        .params  = common_params_audio_lineout,
-        .nparams = ARRAY_SIZE(common_params_audio_lineout),
+        .params  = glue(common_params_audio_lineout_, PARAM),
+        .nparams = ARRAY_SIZE(glue(common_params_audio_lineout_, PARAM)),
         .config  = ((AC_JACK_PORT_COMPLEX << AC_DEFCFG_PORT_CONN_SHIFT) |
                     (AC_JACK_LINE_OUT     << AC_DEFCFG_DEVICE_SHIFT)    |
                     (AC_JACK_CONN_UNKNOWN << AC_DEFCFG_CONN_TYPE_SHIFT) |
@@ -289,15 +289,15 @@  static const desc_node duplex_nodes[] = {
     },{
         .nid     = 4,
         .name    = "adc",
-        .params  = common_params_audio_adc,
-        .nparams = ARRAY_SIZE(common_params_audio_adc),
+        .params  = glue(common_params_audio_adc_, PARAM),
+        .nparams = ARRAY_SIZE(glue(common_params_audio_adc_, PARAM)),
         .stindex = 1,
         .conn    = (uint32_t[]) { 5 },
     },{
         .nid     = 5,
         .name    = "in",
-        .params  = common_params_audio_linein,
-        .nparams = ARRAY_SIZE(common_params_audio_linein),
+        .params  = glue(common_params_audio_linein_, PARAM),
+        .nparams = ARRAY_SIZE(glue(common_params_audio_linein_, PARAM)),
         .config  = ((AC_JACK_PORT_COMPLEX << AC_DEFCFG_PORT_CONN_SHIFT) |
                     (AC_JACK_LINE_IN      << AC_DEFCFG_DEVICE_SHIFT)    |
                     (AC_JACK_CONN_UNKNOWN << AC_DEFCFG_CONN_TYPE_SHIFT) |
@@ -308,15 +308,15 @@  static const desc_node duplex_nodes[] = {
 };
 
 /* duplex: codec */
-static const desc_codec duplex = {
+static const desc_codec glue(duplex_, PARAM) = {
     .name   = "duplex",
     .iid    = QEMU_HDA_ID_DUPLEX,
-    .nodes  = duplex_nodes,
-    .nnodes = ARRAY_SIZE(duplex_nodes),
+    .nodes  = glue(duplex_nodes_, PARAM),
+    .nnodes = ARRAY_SIZE(glue(duplex_nodes_, PARAM)),
 };
 
 /* micro: root node */
-static const desc_param micro_params_root[] = {
+static const desc_param glue(micro_params_root_, PARAM)[] = {
     {
         .id  = AC_PAR_VENDOR_ID,
         .val = QEMU_HDA_ID_MICRO,
@@ -333,7 +333,7 @@  static const desc_param micro_params_root[] = {
 };
 
 /* micro: audio function */
-static const desc_param micro_params_audio_func[] = {
+static const desc_param glue(micro_params_audio_func_, PARAM)[] = {
     {
         .id  = AC_PAR_FUNCTION_TYPE,
         .val = AC_GRP_AUDIO_FUNCTION,
@@ -368,28 +368,28 @@  static const desc_param micro_params_audio_func[] = {
 };
 
 /* micro: nodes */
-static const desc_node micro_nodes[] = {
+static const desc_node glue(micro_nodes_, PARAM)[] = {
     {
         .nid     = AC_NODE_ROOT,
         .name    = "root",
-        .params  = micro_params_root,
-        .nparams = ARRAY_SIZE(micro_params_root),
+        .params  = glue(micro_params_root_, PARAM),
+        .nparams = ARRAY_SIZE(glue(micro_params_root_, PARAM)),
     },{
         .nid     = 1,
         .name    = "func",
-        .params  = micro_params_audio_func,
-        .nparams = ARRAY_SIZE(micro_params_audio_func),
+        .params  = glue(micro_params_audio_func_, PARAM),
+        .nparams = ARRAY_SIZE(glue(micro_params_audio_func_, PARAM)),
     },{
         .nid     = 2,
         .name    = "dac",
-        .params  = common_params_audio_dac,
-        .nparams = ARRAY_SIZE(common_params_audio_dac),
+        .params  = glue(common_params_audio_dac_, PARAM),
+        .nparams = ARRAY_SIZE(glue(common_params_audio_dac_, PARAM)),
         .stindex = 0,
     },{
         .nid     = 3,
         .name    = "out",
-        .params  = common_params_audio_lineout,
-        .nparams = ARRAY_SIZE(common_params_audio_lineout),
+        .params  = glue(common_params_audio_lineout_, PARAM),
+        .nparams = ARRAY_SIZE(glue(common_params_audio_lineout_, PARAM)),
         .config  = ((AC_JACK_PORT_COMPLEX << AC_DEFCFG_PORT_CONN_SHIFT) |
                     (AC_JACK_SPEAKER      << AC_DEFCFG_DEVICE_SHIFT)    |
                     (AC_JACK_CONN_UNKNOWN << AC_DEFCFG_CONN_TYPE_SHIFT) |
@@ -400,15 +400,15 @@  static const desc_node micro_nodes[] = {
     },{
         .nid     = 4,
         .name    = "adc",
-        .params  = common_params_audio_adc,
-        .nparams = ARRAY_SIZE(common_params_audio_adc),
+        .params  = glue(common_params_audio_adc_, PARAM),
+        .nparams = ARRAY_SIZE(glue(common_params_audio_adc_, PARAM)),
         .stindex = 1,
         .conn    = (uint32_t[]) { 5 },
     },{
         .nid     = 5,
         .name    = "in",
-        .params  = common_params_audio_linein,
-        .nparams = ARRAY_SIZE(common_params_audio_linein),
+        .params  = glue(common_params_audio_linein_, PARAM),
+        .nparams = ARRAY_SIZE(glue(common_params_audio_linein_, PARAM)),
         .config  = ((AC_JACK_PORT_COMPLEX << AC_DEFCFG_PORT_CONN_SHIFT) |
                     (AC_JACK_MIC_IN       << AC_DEFCFG_DEVICE_SHIFT)    |
                     (AC_JACK_CONN_UNKNOWN << AC_DEFCFG_CONN_TYPE_SHIFT) |
@@ -419,9 +419,15 @@  static const desc_node micro_nodes[] = {
 };
 
 /* micro: codec */
-static const desc_codec micro = {
+static const desc_codec glue(micro_, PARAM) = {
     .name   = "micro",
     .iid    = QEMU_HDA_ID_MICRO,
-    .nodes  = micro_nodes,
-    .nnodes = ARRAY_SIZE(micro_nodes),
+    .nodes  = glue(micro_nodes_, PARAM),
+    .nnodes = ARRAY_SIZE(glue(micro_nodes_, PARAM)),
 };
+
+#undef PARAM
+#undef QEMU_HDA_ID_OUTPUT
+#undef QEMU_HDA_ID_DUPLEX
+#undef QEMU_HDA_ID_MICRO
+#undef QEMU_HDA_AMP_CAPS
diff --git a/hw/audio/hda-codec.c b/hw/audio/hda-codec.c
index 65fbb2a..30aa709 100644
--- a/hw/audio/hda-codec.c
+++ b/hw/audio/hda-codec.c
@@ -163,6 +163,7 @@  struct HDAAudioState {
 
     /* properties */
     uint32_t debug;
+    uint32_t mixer;
 };
 
 static void hda_audio_input_cb(void *opaque, int avail)
@@ -585,22 +586,63 @@  static const VMStateDescription vmstate_hda_audio = {
 
 static Property hda_audio_properties[] = {
     DEFINE_PROP_UINT32("debug", HDAAudioState, debug, 0),
+#ifdef CONFIG_MIXEMU
+    DEFINE_PROP_UINT32("mixer", HDAAudioState, mixer, 1),
+#else
+    DEFINE_PROP_UINT32("mixer", HDAAudioState, mixer, 0),
+#endif
     DEFINE_PROP_END_OF_LIST(),
 };
 
+#ifdef CONFIG_MIXEMU
+#define PARAM mixemu
+#include "hda-codec-common.h"
+#undef CONFIG_MIXEMU
+#else
+/* keep the compiler quiet */
+static const desc_codec output_mixemu;
+static const desc_codec duplex_mixemu;
+static const desc_codec micro_mixemu;
+#endif
+
+#define PARAM nomixemu
+#include "hda-codec-common.h"
+
 static int hda_audio_init_output(HDACodecDevice *hda)
 {
-    return hda_audio_init(hda, &output);
+    HDAAudioState *a = DO_UPCAST(HDAAudioState, hda, hda);
+
+    if (!a->mixer) {
+        return hda_audio_init(hda, &output_nomixemu);
+    }
+
+    else {
+        return hda_audio_init(hda, &output_mixemu);
+    }
 }
 
 static int hda_audio_init_duplex(HDACodecDevice *hda)
 {
-    return hda_audio_init(hda, &duplex);
+    HDAAudioState *a = DO_UPCAST(HDAAudioState, hda, hda);
+
+    if (!a->mixer) {
+        return hda_audio_init(hda, &duplex_nomixemu);
+    }
+
+    else {
+        return hda_audio_init(hda, &duplex_mixemu);
+    }
 }
 
 static int hda_audio_init_micro(HDACodecDevice *hda)
 {
-    return hda_audio_init(hda, &micro);
+    HDAAudioState *a = DO_UPCAST(HDAAudioState, hda, hda);
+
+    if (!a->mixer) {
+        return hda_audio_init(hda, &micro_nomixemu);
+    } else {
+        return hda_audio_init(hda, &micro_mixemu);
+    }
 }
 
 static void hda_audio_output_class_init(ObjectClass *klass, void *data)