Commit a893a804 authored by Mark Brown's avatar Mark Brown

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"
parents d0401d07 9337f15f
......@@ -24,6 +24,11 @@ properties:
description: |
GPIOs used to select the input line.
state-labels:
description: State of input line. default is "Input 1", "Input 2"
$ref: /schemas/types.yaml#/definitions/string-array
maxItems: 2
sound-name-prefix: true
required:
......@@ -37,4 +42,5 @@ examples:
mux {
compatible = "simple-audio-mux";
mux-gpios = <&gpio 3 0>;
state-labels = "Label_A", "Label_B";
};
......@@ -9,12 +9,21 @@
#include <linux/regulator/consumer.h>
#include <sound/soc.h>
#define MUX_TEXT_SIZE 2
#define MUX_WIDGET_SIZE 4
#define MUX_ROUTE_SIZE 3
struct simple_mux {
struct gpio_desc *gpiod_mux;
unsigned int mux;
const char *mux_texts[MUX_TEXT_SIZE];
struct soc_enum mux_enum;
struct snd_kcontrol_new mux_mux;
struct snd_soc_dapm_widget mux_widgets[MUX_WIDGET_SIZE];
struct snd_soc_dapm_route mux_routes[MUX_ROUTE_SIZE];
struct snd_soc_component_driver mux_driver;
};
static const char * const simple_mux_texts[] = {
static const char * const simple_mux_texts[MUX_TEXT_SIZE] = {
"Input 1", "Input 2"
};
......@@ -66,30 +75,23 @@ static unsigned int simple_mux_read(struct snd_soc_component *component,
static const struct snd_kcontrol_new simple_mux_mux =
SOC_DAPM_ENUM_EXT("Muxer", simple_mux_enum, simple_mux_control_get, simple_mux_control_put);
static const struct snd_soc_dapm_widget simple_mux_dapm_widgets[] = {
static const struct snd_soc_dapm_widget simple_mux_dapm_widgets[MUX_WIDGET_SIZE] = {
SND_SOC_DAPM_INPUT("IN1"),
SND_SOC_DAPM_INPUT("IN2"),
SND_SOC_DAPM_MUX("MUX", SND_SOC_NOPM, 0, 0, &simple_mux_mux),
SND_SOC_DAPM_MUX("MUX", SND_SOC_NOPM, 0, 0, &simple_mux_mux), // see simple_mux_probe()
SND_SOC_DAPM_OUTPUT("OUT"),
};
static const struct snd_soc_dapm_route simple_mux_dapm_routes[] = {
static const struct snd_soc_dapm_route simple_mux_dapm_routes[MUX_ROUTE_SIZE] = {
{ "OUT", NULL, "MUX" },
{ "MUX", "Input 1", "IN1" },
{ "MUX", "Input 2", "IN2" },
};
static const struct snd_soc_component_driver simple_mux_component_driver = {
.dapm_widgets = simple_mux_dapm_widgets,
.num_dapm_widgets = ARRAY_SIZE(simple_mux_dapm_widgets),
.dapm_routes = simple_mux_dapm_routes,
.num_dapm_routes = ARRAY_SIZE(simple_mux_dapm_routes),
.read = simple_mux_read,
{ "MUX", "Input 1", "IN1" }, // see simple_mux_probe()
{ "MUX", "Input 2", "IN2" }, // see simple_mux_probe()
};
static int simple_mux_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct device_node *np = dev->of_node;
struct simple_mux *priv;
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
......@@ -103,7 +105,30 @@ static int simple_mux_probe(struct platform_device *pdev)
return dev_err_probe(dev, PTR_ERR(priv->gpiod_mux),
"Failed to get 'mux' gpio");
return devm_snd_soc_register_component(dev, &simple_mux_component_driver, NULL, 0);
/* Copy default settings */
memcpy(&priv->mux_texts, &simple_mux_texts, sizeof(priv->mux_texts));
memcpy(&priv->mux_enum, &simple_mux_enum, sizeof(priv->mux_enum));
memcpy(&priv->mux_mux, &simple_mux_mux, sizeof(priv->mux_mux));
memcpy(&priv->mux_widgets, &simple_mux_dapm_widgets, sizeof(priv->mux_widgets));
memcpy(&priv->mux_routes, &simple_mux_dapm_routes, sizeof(priv->mux_routes));
priv->mux_driver.dapm_widgets = priv->mux_widgets;
priv->mux_driver.num_dapm_widgets = MUX_WIDGET_SIZE;
priv->mux_driver.dapm_routes = priv->mux_routes;
priv->mux_driver.num_dapm_routes = MUX_ROUTE_SIZE;
priv->mux_driver.read = simple_mux_read;
/* Overwrite text ("Input 1", "Input 2") if property exists */
of_property_read_string_array(np, "state-labels", priv->mux_texts, MUX_TEXT_SIZE);
/* switch to use priv data instead of default */
priv->mux_enum.texts = priv->mux_texts;
priv->mux_mux.private_value = (unsigned long)&priv->mux_enum;
priv->mux_widgets[2].kcontrol_news = &priv->mux_mux;
priv->mux_routes[1].control = priv->mux_texts[0]; // "Input 1"
priv->mux_routes[2].control = priv->mux_texts[1]; // "Input 2"
return devm_snd_soc_register_component(dev, &priv->mux_driver, NULL, 0);
}
#ifdef CONFIG_OF
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment