Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ASoC: simple-audio-mux: add state-labels

Merge series from Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>:

simple-audio-mux is designed to be used generally, thus "Input 1" or
"Input 2" are used to selecting MUX input. This numbered inputs would work,
but might be not user friendly in some case, for example in case of system
hardware design has some clear labels.
Adds new "state-labels" property and enable to select MUX by own state names.

Original
> amixer set "MUX" "Input 1"
> amixer set "MUX" "Input 2"

Use mux-names
sound_mux: mux {
compatible = "simple-audio-mux";
mux-gpios = <...>;
=> state-labels = "Label_A", "Label_B";
};

> amixer set "MUX" "Label_A"
> amixer set "MUX" "Label_B"

+46 -15
+6
Documentation/devicetree/bindings/sound/simple-audio-mux.yaml
··· 24 24 description: | 25 25 GPIOs used to select the input line. 26 26 27 + state-labels: 28 + description: State of input line. default is "Input 1", "Input 2" 29 + $ref: /schemas/types.yaml#/definitions/string-array 30 + maxItems: 2 31 + 27 32 sound-name-prefix: true 28 33 29 34 required: ··· 42 37 mux { 43 38 compatible = "simple-audio-mux"; 44 39 mux-gpios = <&gpio 3 0>; 40 + state-labels = "Label_A", "Label_B"; 45 41 };
+40 -15
sound/soc/codecs/simple-mux.c
··· 9 9 #include <linux/regulator/consumer.h> 10 10 #include <sound/soc.h> 11 11 12 + #define MUX_TEXT_SIZE 2 13 + #define MUX_WIDGET_SIZE 4 14 + #define MUX_ROUTE_SIZE 3 12 15 struct simple_mux { 13 16 struct gpio_desc *gpiod_mux; 14 17 unsigned int mux; 18 + const char *mux_texts[MUX_TEXT_SIZE]; 19 + struct soc_enum mux_enum; 20 + struct snd_kcontrol_new mux_mux; 21 + struct snd_soc_dapm_widget mux_widgets[MUX_WIDGET_SIZE]; 22 + struct snd_soc_dapm_route mux_routes[MUX_ROUTE_SIZE]; 23 + struct snd_soc_component_driver mux_driver; 15 24 }; 16 25 17 - static const char * const simple_mux_texts[] = { 26 + static const char * const simple_mux_texts[MUX_TEXT_SIZE] = { 18 27 "Input 1", "Input 2" 19 28 }; 20 29 ··· 75 66 static const struct snd_kcontrol_new simple_mux_mux = 76 67 SOC_DAPM_ENUM_EXT("Muxer", simple_mux_enum, simple_mux_control_get, simple_mux_control_put); 77 68 78 - static const struct snd_soc_dapm_widget simple_mux_dapm_widgets[] = { 69 + static const struct snd_soc_dapm_widget simple_mux_dapm_widgets[MUX_WIDGET_SIZE] = { 79 70 SND_SOC_DAPM_INPUT("IN1"), 80 71 SND_SOC_DAPM_INPUT("IN2"), 81 - SND_SOC_DAPM_MUX("MUX", SND_SOC_NOPM, 0, 0, &simple_mux_mux), 72 + SND_SOC_DAPM_MUX("MUX", SND_SOC_NOPM, 0, 0, &simple_mux_mux), // see simple_mux_probe() 82 73 SND_SOC_DAPM_OUTPUT("OUT"), 83 74 }; 84 75 85 - static const struct snd_soc_dapm_route simple_mux_dapm_routes[] = { 76 + static const struct snd_soc_dapm_route simple_mux_dapm_routes[MUX_ROUTE_SIZE] = { 86 77 { "OUT", NULL, "MUX" }, 87 - { "MUX", "Input 1", "IN1" }, 88 - { "MUX", "Input 2", "IN2" }, 89 - }; 90 - 91 - static const struct snd_soc_component_driver simple_mux_component_driver = { 92 - .dapm_widgets = simple_mux_dapm_widgets, 93 - .num_dapm_widgets = ARRAY_SIZE(simple_mux_dapm_widgets), 94 - .dapm_routes = simple_mux_dapm_routes, 95 - .num_dapm_routes = ARRAY_SIZE(simple_mux_dapm_routes), 96 - .read = simple_mux_read, 78 + { "MUX", "Input 1", "IN1" }, // see simple_mux_probe() 79 + { "MUX", "Input 2", "IN2" }, // see simple_mux_probe() 97 80 }; 98 81 99 82 static int simple_mux_probe(struct platform_device *pdev) 100 83 { 101 84 struct device *dev = &pdev->dev; 85 + struct device_node *np = dev->of_node; 102 86 struct simple_mux *priv; 103 87 104 88 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); ··· 105 103 return dev_err_probe(dev, PTR_ERR(priv->gpiod_mux), 106 104 "Failed to get 'mux' gpio"); 107 105 108 - return devm_snd_soc_register_component(dev, &simple_mux_component_driver, NULL, 0); 106 + /* Copy default settings */ 107 + memcpy(&priv->mux_texts, &simple_mux_texts, sizeof(priv->mux_texts)); 108 + memcpy(&priv->mux_enum, &simple_mux_enum, sizeof(priv->mux_enum)); 109 + memcpy(&priv->mux_mux, &simple_mux_mux, sizeof(priv->mux_mux)); 110 + memcpy(&priv->mux_widgets, &simple_mux_dapm_widgets, sizeof(priv->mux_widgets)); 111 + memcpy(&priv->mux_routes, &simple_mux_dapm_routes, sizeof(priv->mux_routes)); 112 + 113 + priv->mux_driver.dapm_widgets = priv->mux_widgets; 114 + priv->mux_driver.num_dapm_widgets = MUX_WIDGET_SIZE; 115 + priv->mux_driver.dapm_routes = priv->mux_routes; 116 + priv->mux_driver.num_dapm_routes = MUX_ROUTE_SIZE; 117 + priv->mux_driver.read = simple_mux_read; 118 + 119 + /* Overwrite text ("Input 1", "Input 2") if property exists */ 120 + of_property_read_string_array(np, "state-labels", priv->mux_texts, MUX_TEXT_SIZE); 121 + 122 + /* switch to use priv data instead of default */ 123 + priv->mux_enum.texts = priv->mux_texts; 124 + priv->mux_mux.private_value = (unsigned long)&priv->mux_enum; 125 + priv->mux_widgets[2].kcontrol_news = &priv->mux_mux; 126 + priv->mux_routes[1].control = priv->mux_texts[0]; // "Input 1" 127 + priv->mux_routes[2].control = priv->mux_texts[1]; // "Input 2" 128 + 129 + return devm_snd_soc_register_component(dev, &priv->mux_driver, NULL, 0); 109 130 } 110 131 111 132 #ifdef CONFIG_OF