[RFC PATCH 03/16] ASoC: Intel: sof-pcm512x: use gpiod for LED
Pierre-Louis Bossart
pierre-louis.bossart at linux.intel.com
Thu Apr 9 21:58:28 CEST 2020
Remove direct regmap access, use gpios exposed by PCM512x codec
Keep the codec_init function, this will be used in following patches
The gpios handling is done with an explicit lookup table. We cannot
use ACPI-based mappings since we don't have an ACPI device for the
machine driver, and the gpiochip is created during the probe of the
PCM512x driver.
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart at linux.intel.com>
---
sound/soc/intel/boards/sof_pcm512x.c | 45 ++++++++++++++++++++--------
1 file changed, 32 insertions(+), 13 deletions(-)
diff --git a/sound/soc/intel/boards/sof_pcm512x.c b/sound/soc/intel/boards/sof_pcm512x.c
index fb7811899999..dcd769b352fa 100644
--- a/sound/soc/intel/boards/sof_pcm512x.c
+++ b/sound/soc/intel/boards/sof_pcm512x.c
@@ -10,6 +10,8 @@
#include <linux/i2c.h>
#include <linux/input.h>
#include <linux/module.h>
+#include <linux/gpio/consumer.h>
+#include <linux/gpio/machine.h>
#include <linux/platform_device.h>
#include <linux/types.h>
#include <sound/core.h>
@@ -43,6 +45,7 @@ struct sof_hdmi_pcm {
struct sof_card_private {
struct list_head hdmi_pcm_list;
bool idisp_codec;
+ struct gpio_desc *gpio_4;
};
static int sof_pcm512x_quirk_cb(const struct dmi_system_id *id)
@@ -84,23 +87,16 @@ static int sof_hdmi_init(struct snd_soc_pcm_runtime *rtd)
static int sof_pcm512x_codec_init(struct snd_soc_pcm_runtime *rtd)
{
- struct snd_soc_component *codec = asoc_rtd_to_codec(rtd, 0)->component;
-
- snd_soc_component_update_bits(codec, PCM512x_GPIO_EN, 0x08, 0x08);
- snd_soc_component_update_bits(codec, PCM512x_GPIO_OUTPUT_4, 0x0f, 0x02);
- snd_soc_component_update_bits(codec, PCM512x_GPIO_CONTROL_1,
- 0x08, 0x08);
-
return 0;
}
static int aif1_startup(struct snd_pcm_substream *substream)
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
- struct snd_soc_component *codec = asoc_rtd_to_codec(rtd, 0)->component;
+ struct sof_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
- snd_soc_component_update_bits(codec, PCM512x_GPIO_CONTROL_1,
- 0x08, 0x08);
+ /* Turn LED on */
+ gpiod_set_value(ctx->gpio_4, 1);
return 0;
}
@@ -108,10 +104,10 @@ static int aif1_startup(struct snd_pcm_substream *substream)
static void aif1_shutdown(struct snd_pcm_substream *substream)
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
- struct snd_soc_component *codec = asoc_rtd_to_codec(rtd, 0)->component;
+ struct sof_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
- snd_soc_component_update_bits(codec, PCM512x_GPIO_CONTROL_1,
- 0x08, 0x00);
+ /* Turn LED off */
+ gpiod_set_value(ctx->gpio_4, 0);
}
static const struct snd_soc_ops sof_pcm512x_ops = {
@@ -354,6 +350,14 @@ static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev,
return NULL;
}
+static struct gpiod_lookup_table pcm512x_gpios_table = {
+ /* .dev_id set during probe */
+ .table = {
+ GPIO_LOOKUP("pcm512x-gpio", 3, "PCM512x-GPIO4", GPIO_ACTIVE_HIGH),
+ { },
+ },
+};
+
static int sof_audio_probe(struct platform_device *pdev)
{
struct snd_soc_acpi_mach *mach = pdev->dev.platform_data;
@@ -413,6 +417,21 @@ static int sof_audio_probe(struct platform_device *pdev)
snd_soc_card_set_drvdata(&sof_audio_card_pcm512x, ctx);
+ /*
+ * Enable GPIO4 for LED
+ */
+ pcm512x_gpios_table.dev_id = dev_name(&pdev->dev);
+ gpiod_add_lookup_table(&pcm512x_gpios_table);
+
+ ctx->gpio_4 = devm_gpiod_get(&pdev->dev, "PCM512x-GPIO4",
+ GPIOD_OUT_LOW);
+
+ if (IS_ERR(ctx->gpio_4)) {
+ dev_err(&pdev->dev, "gpio4 not found\n");
+ ret = PTR_ERR(ctx->gpio_4);
+ return ret;
+ }
+
return devm_snd_soc_register_card(&pdev->dev,
&sof_audio_card_pcm512x);
}
--
2.20.1
More information about the Alsa-devel
mailing list