Skip to contentSkip to conversation

mfd: arizona: Add GPIO control register bit definitions

PATCH Superseded Charles Keepax 2 participants 5 messages Jul 2, 2013

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 mfd: arizona: Add GPIO control register bit definitions

---
 include/linux/mfd/arizona/registers.h |   35 +++++++++++++++++++++++++++++++++
 1 files changed, 35 insertions(+), 0 deletions(-)
include/linux/mfd/arizona/registers.h +35 -0
index 715b6ba..522798d 100644
@@ -4131,6 +4131,41 @@
 #define ARIZONA_SLIMTX1_PORT_STS_WIDTH                1  /* SLIMTX1_PORT_STS */
 
 /*
+ * R3072 - R3076 (0xC00 - 0xC04) ARIZONA_GPIO1_CTRL - ARIZONA_GPIO5_CTRL
+ */
+#define ARIZONA_GPN_DIR                          0x8000  /* GPN_DIR */
+#define ARIZONA_GPN_DIR_MASK                     0x8000  /* GPN_DIR */
+#define ARIZONA_GPN_DIR_SHIFT                        15  /* GPN_DIR */
+#define ARIZONA_GPN_DIR_WIDTH                         1  /* GPN_DIR */
+#define ARIZONA_GPN_PU                           0x4000  /* GPN_PU */
+#define ARIZONA_GPN_PU_MASK                      0x4000  /* GPN_PU */
+#define ARIZONA_GPN_PU_SHIFT                         14  /* GPN_PU */
+#define ARIZONA_GPN_PU_WIDTH                          1  /* GPN_PU */
+#define ARIZONA_GPN_PD                           0x2000  /* GPN_PD */
+#define ARIZONA_GPN_PD_MASK                      0x2000  /* GPN_PD */
+#define ARIZONA_GPN_PD_SHIFT                         13  /* GPN_PD */
+#define ARIZONA_GPN_PD_WIDTH                          1  /* GPN_PD */
+#define ARIZONA_GPN_LVL                          0x0800  /* GPN_LVL */
+#define ARIZONA_GPN_LVL_MASK                     0x0800  /* GPN_LVL */
+#define ARIZONA_GPN_LVL_SHIFT                        11  /* GPN_LVL */
+#define ARIZONA_GPN_LVL_WIDTH                         1  /* GPN_LVL */
+#define ARIZONA_GPN_POL                          0x0400  /* GPN_POL */
+#define ARIZONA_GPN_POL_MASK                     0x0400  /* GPN_POL */
+#define ARIZONA_GPN_POL_SHIFT                        10  /* GPN_POL */
+#define ARIZONA_GPN_POL_WIDTH                         1  /* GPN_POL */
+#define ARIZONA_GPN_OP_CFG                       0x0200  /* GPN_OP_CFG */
+#define ARIZONA_GPN_OP_CFG_MASK                  0x0200  /* GPN_OP_CFG */
+#define ARIZONA_GPN_OP_CFG_SHIFT                      9  /* GPN_OP_CFG */
+#define ARIZONA_GPN_OP_CFG_WIDTH                      1  /* GPN_OP_CFG */
+#define ARIZONA_GPN_DB                           0x0100  /* GPN_DB */
+#define ARIZONA_GPN_DB_MASK                      0x0100  /* GPN_DB */
+#define ARIZONA_GPN_DB_SHIFT                          8  /* GPN_DB */
+#define ARIZONA_GPN_DB_WIDTH                          1  /* GPN_DB */
+#define ARIZONA_GPN_FN_MASK                      0x007F  /* GPN_DB */
+#define ARIZONA_GPN_FN_SHIFT                          0  /* GPN_DB */
+#define ARIZONA_GPN_FN_WIDTH                          7  /* GPN_DB */
+
+/*
  * R3087 (0xC0F) - IRQ CTRL 1
  */
 #define ARIZONA_IRQ_POL                          0x0400  /* IRQ_POL */
Signature · 1 line
1.7.2.5
#1 lore raw

PATCH 2/2 ASoC: arizona: Add GPIO output for DRC

In some use cases, such as signal activity detection, the only output from the DRC will be a GPIO pin. This patch adds GPIO outputs to the CODEC driver and hooks these up to the DRC when a GPIO is configured to output the DRC activity detection.

---
 sound/soc/codecs/arizona.c |   52 ++++++++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/arizona.h |    1 +
 sound/soc/codecs/wm5102.c  |    7 ++++++
 sound/soc/codecs/wm5110.c  |    7 ++++++
 4 files changed, 67 insertions(+), 0 deletions(-)
sound/soc/codecs/arizona.c +52 -0
index 389f232..5879ec5 100644
@@ -223,6 +223,58 @@ int arizona_init_spk(struct snd_soc_codec *codec)
 }
 EXPORT_SYMBOL_GPL(arizona_init_spk);
 
+static const char * const arizona_gpio_name[] = {
+	"GPIO1",
+	"GPIO2",
+	"GPIO3",
+	"GPIO4",
+	"GPIO5",
+};
+
+int arizona_init_gpio(struct snd_soc_codec *codec)
+{
+	struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec);
+	struct arizona *arizona = priv->arizona;
+	struct snd_soc_dapm_route routes[2];
+	int i, ret;
+	bool add;
+
+	memset(&routes, 0, sizeof(routes));
+
+	for (i = 0; i < ARRAY_SIZE(arizona->pdata.gpio_defaults); i++) {
+		add = false;
+
+		switch (arizona->pdata.gpio_defaults[i] & ARIZONA_GPN_FN_MASK) {
+		case 0x1d: /* DRC1 Signal Detect */
+			routes[0].source = "DRC1L";
+			routes[1].source = "DRC1R";
+			add = true;
+			break;
+		case 0x22: /* DRC2 Signal Detect */
+			routes[0].source = "DRC2L";
+			routes[1].source = "DRC2R";
+			add = true;
+			break;
+		default:
+			break;
+		}
+
+		if (add) {
+			routes[0].sink = arizona_gpio_name[i];
+			routes[1].sink = arizona_gpio_name[i];
+
+			ret = snd_soc_dapm_add_routes(&codec->dapm,
+						      routes,
+						      ARRAY_SIZE(routes));
+			if (ret < 0)
+				return ret;
+		}
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(arizona_init_gpio);
+
 const char *arizona_mixer_texts[ARIZONA_NUM_MIXER_INPUTS] = {
 	"None",
 	"Tone Generator 1",
sound/soc/codecs/arizona.h +1 -0
index af39f10..fe8bd3d 100644
@@ -241,6 +241,7 @@ extern int arizona_set_fll(struct arizona_fll *fll, int source,
 			   unsigned int Fref, unsigned int Fout);
 
 extern int arizona_init_spk(struct snd_soc_codec *codec);
+extern int arizona_init_gpio(struct snd_soc_codec *codec);
 
 extern int arizona_init_dai(struct arizona_priv *priv, int dai);
 
sound/soc/codecs/wm5102.c +7 -0
index 100fdad..2ff2a65 100644
@@ -967,6 +967,12 @@ SND_SOC_DAPM_INPUT("IN2R"),
 SND_SOC_DAPM_INPUT("IN3L"),
 SND_SOC_DAPM_INPUT("IN3R"),
 
+SND_SOC_DAPM_OUTPUT("GPIO1"),
+SND_SOC_DAPM_OUTPUT("GPIO2"),
+SND_SOC_DAPM_OUTPUT("GPIO3"),
+SND_SOC_DAPM_OUTPUT("GPIO4"),
+SND_SOC_DAPM_OUTPUT("GPIO5"),
+
 SND_SOC_DAPM_PGA_E("IN1L PGA", ARIZONA_INPUT_ENABLES, ARIZONA_IN1L_ENA_SHIFT,
 		   0, NULL, 0, arizona_in_ev,
 		   SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD |
@@ -1578,6 +1584,7 @@ static int wm5102_codec_probe(struct snd_soc_codec *codec)
 		return ret;
 
 	arizona_init_spk(codec);
+	arizona_init_gpio(codec);
 
 	snd_soc_dapm_disable_pin(&codec->dapm, "HAPTICS");
 
sound/soc/codecs/wm5110.c +7 -0
index 88ad7db..4f8611f 100644
@@ -414,6 +414,12 @@ SND_SOC_DAPM_INPUT("IN3R"),
 SND_SOC_DAPM_INPUT("IN4L"),
 SND_SOC_DAPM_INPUT("IN4R"),
 
+SND_SOC_DAPM_OUTPUT("GPIO1"),
+SND_SOC_DAPM_OUTPUT("GPIO2"),
+SND_SOC_DAPM_OUTPUT("GPIO3"),
+SND_SOC_DAPM_OUTPUT("GPIO4"),
+SND_SOC_DAPM_OUTPUT("GPIO5"),
+
 SND_SOC_DAPM_PGA_E("IN1L PGA", ARIZONA_INPUT_ENABLES, ARIZONA_IN1L_ENA_SHIFT,
 		   0, NULL, 0, arizona_in_ev,
 		   SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD |
@@ -978,6 +984,7 @@ static int wm5110_codec_probe(struct snd_soc_codec *codec)
 		return ret;
 
 	arizona_init_spk(codec);
+	arizona_init_gpio(codec);
 
 	snd_soc_dapm_disable_pin(&codec->dapm, "HAPTICS");
 
Signature · 1 line
1.7.2.5
#2 lore raw

Re: [PATCH 2/2] ASoC: arizona: Add GPIO output for DRC

Sorry has just occurred to me these are based off Mark's for-next branch, probably would make more sense for me to base them off the mfd tree.

Let me know if this is a problem and I will respin.

Thanks,
Charles

maintainer
#3 lore raw

Re: [PATCH 2/2] ASoC: arizona: Add GPIO output for DRC

In reply to Charles Keepax

sound/soc/codecs/arizona.c int arizona_init_spk(struct snd_soc_codec *codec) · line 232

Quoted 12 lines · Charles Keepax

In some use cases, such as signal activity detection, the only output from the DRC will be a GPIO pin. This patch adds GPIO outputs to the CODEC driver and hooks these up to the DRC when a GPIO is configured to output the DRC activity detection.

sound/soc/codecs/arizona.c +7 -0
+static const char * const arizona_gpio_name[] = {
+	"GPIO1",
+	"GPIO2",
+	"GPIO3",
+	"GPIO4",
+	"GPIO5",
+};

This seems like the wrong way to be doing things - having the GPIOs in the routing table is needlessly complicated as the don't go anywhere routing wise and they're not exactly helping anything usability wise as the function of the output is translated into a magic number making it harder for people to write code interacting with this (eg, turning it on and off depending on use case), you need to know which GPIO is in use so it's harder to write generic code.

Just have a functional thing in there, enabling or disabling it by default depending on the GPIO settings seems reasonable.

sound/soc/codecs/arizona.c int arizona_init_spk(struct snd_soc_codec *codec) · line 253

Quoted 7 lines
sound/soc/codecs/arizona.c +7 -0
+		switch (arizona->pdata.gpio_defaults[i] & ARIZONA_GPN_FN_MASK) {
+		case 0x1d: /* DRC1 Signal Detect */
+			routes[0].source = "DRC1L";
+			routes[1].source = "DRC1R";
+			add = true;
+			break;
+		case 0x22: /* DRC2 Signal Detect */

You're going to be using these in multiple places, #defines..