alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
To: alsa-devel@alsa-project.org
Cc: Rob Herring <robh+dt@kernel.org>,
	linux-gpio@vger.kernel.org, tiwai@suse.de,
	Linus Walleij <linus.walleij@linaro.org>,
	Stephen Boyd <sboyd@kernel.org>,
	Daniel Matuschek <daniel@hifiberry.com>,
	Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>,
	Hui Wang <hui.wang@canonical.com>,
	Matthias Reichl <hias@horus.com>,
	broonie@kernel.org,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Michael Turquette <mturquette@baylibre.com>,
	linux-clk@vger.kernel.org
Subject: [RFC PATCH 03/16] ASoC: Intel: sof-pcm512x: use gpiod for LED
Date: Thu,  9 Apr 2020 14:58:28 -0500	[thread overview]
Message-ID: <20200409195841.18901-4-pierre-louis.bossart@linux.intel.com> (raw)
In-Reply-To: <20200409195841.18901-1-pierre-louis.bossart@linux.intel.com>

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@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


  parent reply	other threads:[~2020-04-09 20:03 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-09 19:58 [RFC PATCH 00/16] ASoC/SOF/clk/gpio/dt: add Hifiberry DAC+ PRO support Pierre-Louis Bossart
2020-04-09 19:58 ` [RFC PATCH 01/16] ASoC: pcm512x: expose 6 GPIOs Pierre-Louis Bossart
2020-04-14 17:09   ` Andy Shevchenko
2020-04-14 17:52     ` Pierre-Louis Bossart
2020-04-15  9:49       ` Andy Shevchenko
2020-04-16 11:42     ` Linus Walleij
2020-04-16 14:25       ` Pierre-Louis Bossart
2020-04-09 19:58 ` [RFC PATCH 02/16] ASoC: pcm512x: use "sclk" string to retrieve clock Pierre-Louis Bossart
2020-04-14 17:11   ` Andy Shevchenko
2020-04-14 17:54     ` Pierre-Louis Bossart
2020-04-15  9:52       ` Andy Shevchenko
2020-04-15 14:19         ` Pierre-Louis Bossart
2020-04-15 15:10           ` Andy Shevchenko
2020-04-14 17:45   ` Mark Brown
2020-04-14 18:14     ` Pierre-Louis Bossart
2020-04-14 18:27       ` Mark Brown
2020-04-14 19:15         ` Pierre-Louis Bossart
2020-04-14 19:50           ` Mark Brown
2020-04-14 20:13             ` Pierre-Louis Bossart
2020-04-14 21:02               ` Pierre-Louis Bossart
2020-04-15 11:07                 ` Mark Brown
2020-04-15 11:36               ` Mark Brown
2020-04-15 14:44                 ` Pierre-Louis Bossart
2020-04-15 16:22                   ` Mark Brown
2020-04-15 17:26                     ` Pierre-Louis Bossart
2020-04-15 19:50                       ` Mark Brown
2020-04-15 20:22                         ` Pierre-Louis Bossart
2020-04-15 20:39                           ` Mark Brown
2020-04-09 19:58 ` Pierre-Louis Bossart [this message]
2020-04-14 17:17   ` [RFC PATCH 03/16] ASoC: Intel: sof-pcm512x: use gpiod for LED Andy Shevchenko
2020-04-14 17:52     ` Mark Brown
2020-04-14 17:57     ` Pierre-Louis Bossart
2020-04-15  9:51       ` Andy Shevchenko
2020-04-09 19:58 ` [RFC PATCH 04/16] ASoC: Intel: sof-pcm512x: detect Hifiberry DAC+ PRO Pierre-Louis Bossart
2020-04-14 17:20   ` Andy Shevchenko
2020-04-14 18:02     ` Pierre-Louis Bossart
2020-04-15  9:55       ` Andy Shevchenko
2020-04-15 14:07         ` Pierre-Louis Bossart
2020-04-15 15:05           ` Andy Shevchenko
2020-04-09 19:58 ` [RFC PATCH 05/16] ASoC: Intel: sof-pcm512x: reconfigure sclk in hw_params if needed Pierre-Louis Bossart
2020-04-14 17:24   ` Andy Shevchenko
2020-04-14 18:06     ` Pierre-Louis Bossart
2020-04-09 19:58 ` [RFC PATCH 06/16] ASoC: Intel: sof-pcm512x: select HIFIBERRY_DACPRO clk Pierre-Louis Bossart
2020-04-09 19:58 ` [RFC PATCH 07/16] clk: hifiberry-dacpro: initial import Pierre-Louis Bossart
2020-04-14 17:31   ` Andy Shevchenko
2020-04-14 18:09     ` Pierre-Louis Bossart
2020-04-15 10:00       ` Andy Shevchenko
2020-04-09 19:58 ` [RFC PATCH 08/16] clk: hifiberry-dacpro: update SDPX/copyright Pierre-Louis Bossart
2020-04-09 19:58 ` [RFC PATCH 09/16] clk: hifiberry-dacpro: style cleanups, use devm_ Pierre-Louis Bossart
2020-04-09 19:58 ` [RFC PATCH 10/16] clk: hifiberry-dacpro: add OF dependency Pierre-Louis Bossart
2020-04-09 19:58 ` [RFC PATCH 11/16] clk: hifiberry-dacpro: transition to _hw functions Pierre-Louis Bossart
2020-04-09 19:58 ` [RFC PATCH 12/16] clk: hifiberry-dacpro: add ACPI support Pierre-Louis Bossart
2020-04-22  9:32   ` Stephen Boyd
2020-04-22  9:47     ` Andy Shevchenko
2020-04-22  9:54     ` Pierre-Louis Bossart
2020-04-22 20:52       ` Stephen Boyd
2020-04-22 21:08         ` Pierre-Louis Bossart
2020-04-09 19:58 ` [RFC PATCH 13/16] clk: hifiberry-dacpro: add "sclk" lookup Pierre-Louis Bossart
2020-04-22  9:35   ` Stephen Boyd
2020-04-22  9:51     ` Pierre-Louis Bossart
2020-04-22 11:54       ` Andy Shevchenko
2020-04-09 19:58 ` [RFC PATCH 14/16] clk: hifiberry-dacpro: toggle GPIOs on prepare/unprepare Pierre-Louis Bossart
2020-04-09 19:58 ` [RFC PATCH 15/16] clk: hifiberry-dacpro: add delay on clock prepare/deprepare Pierre-Louis Bossart
2020-04-09 19:58 ` [RFC PATCH 16/16] ASoC: dt-bindings: add document for Hifiberry DAC+ PRO clock Pierre-Louis Bossart
2020-04-14 17:27   ` Andy Shevchenko
2020-04-14 18:10     ` Pierre-Louis Bossart
2020-04-14 16:50 ` [RFC PATCH 00/16] ASoC/SOF/clk/gpio/dt: add Hifiberry DAC+ PRO support Andy Shevchenko
2020-04-14 16:57   ` Pierre-Louis Bossart

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200409195841.18901-4-pierre-louis.bossart@linux.intel.com \
    --to=pierre-louis.bossart@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=broonie@kernel.org \
    --cc=daniel@hifiberry.com \
    --cc=hias@horus.com \
    --cc=hui.wang@canonical.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=robh+dt@kernel.org \
    --cc=sboyd@kernel.org \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).