mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Rohit Kumar <rohitkr@codeaurora.org>
To: Cheng-Yi Chiang <cychiang@chromium.org>, linux-kernel@vger.kernel.org
Cc: alsa-devel@alsa-project.org, Mark Brown <broonie@kernel.org>,
	dgreid@chromium.org, ryans.lee@maximintegrated.com
Subject: Re: [alsa-devel] [PATCH 2/2] ASoC: max98927: Add reset-gpio support
Date: Wed, 12 Sep 2018 22:17:24 +0530	[thread overview]
Message-ID: <7aa3c049-5ba0-1db3-08c8-510da1cf779d@codeaurora.org> (raw)
In-Reply-To: <20180912121955.33048-2-cychiang@chromium.org>



On 9/12/2018 5:49 PM, Cheng-Yi Chiang wrote:
> Toggle reset line in max98927_i2c_probe.
> Use a list to store max98927 instances so we do not toggle reset line
> again if more than one instances share the same reset line.
>
> Signed-off-by: Cheng-Yi Chiang <cychiang@chromium.org>
Reviewed-and-tested-by: Rohit kumar <rohitkr@codeaurora.org>

> ---
>   sound/soc/codecs/max98927.c | 78 +++++++++++++++++++++++++++++++++++++++++++++
>   sound/soc/codecs/max98927.h |  2 ++
>   2 files changed, 80 insertions(+)
>
> diff --git a/sound/soc/codecs/max98927.c b/sound/soc/codecs/max98927.c
> index 941712058a8f5..789b27cdfd9e0 100644
> --- a/sound/soc/codecs/max98927.c
> +++ b/sound/soc/codecs/max98927.c
> @@ -11,6 +11,7 @@
>    */
>   
>   #include <linux/acpi.h>
> +#include <linux/delay.h>
>   #include <linux/i2c.h>
>   #include <linux/module.h>
>   #include <linux/regmap.h>
> @@ -24,6 +25,11 @@
>   #include <sound/tlv.h>
>   #include "max98927.h"
>   
> +#define MAX98927_MIN_RESET_US 1
> +#define MAX98927_RELEASE_RESET_DELAY_US 500
> +
> +static LIST_HEAD(reset_list);
> +
>   static struct reg_default max98927_reg[] = {
>   	{MAX98927_R0001_INT_RAW1,  0x00},
>   	{MAX98927_R0002_INT_RAW2,  0x00},
> @@ -877,6 +883,54 @@ static void max98927_slot_config(struct i2c_client *i2c,
>   		max98927->i_l_slot = 1;
>   }
>   
> +static int max98927_i2c_toggle_reset(struct device *dev,
> +				     struct max98927_priv *max98927)
> +{
> +	/*
> +	 * If we do not have reset gpio, assume platform firmware
> +	 * controls the regulator and toggles it for us.
> +	 */
> +	if (!max98927->reset_gpio)
> +		return 0;
> +
> +	gpiod_set_value_cansleep(max98927->reset_gpio, 1);
> +
> +	/*
> +	 * We need to wait a bit before we are allowed to release reset GPIO.
> +	 */
> +	usleep_range(MAX98927_MIN_RESET_US, MAX98927_MIN_RESET_US + 5);
> +
> +	gpiod_set_value_cansleep(max98927->reset_gpio, 0);
> +
> +	/*
> +	 * We need to wait a bit before I2C communication is available.
> +	 */
> +	usleep_range(MAX98927_RELEASE_RESET_DELAY_US,
> +		     MAX98927_RELEASE_RESET_DELAY_US + 5);
> +
> +	/*
> +	 * Release reset GPIO because we are not going to use it.
> +	 */
> +	devm_gpiod_put(dev, max98927->reset_gpio);
> +
> +	return 0;
> +}
> +
> +static bool max98927_is_first_to_reset(struct max98927_priv *max98927)
> +{
> +	struct max98927_priv *p;
> +
> +	if (!max98927->reset_gpio)
> +		return false;
> +
> +	list_for_each_entry(p, &reset_list, list) {
> +		if (max98927->reset_gpio == p->reset_gpio)
> +			return false;
> +	}
> +
> +	return true;
> +}
> +
>   static int max98927_i2c_probe(struct i2c_client *i2c,
>   	const struct i2c_device_id *id)
>   {
> @@ -904,6 +958,28 @@ static int max98927_i2c_probe(struct i2c_client *i2c,
>   	} else
>   		max98927->interleave_mode = 0;
>   
> +	/* Gets optional GPIO for reset line. */
> +	max98927->reset_gpio = devm_gpiod_get_optional(
> +			&i2c->dev, "reset", GPIOD_OUT_LOW);
> +	if (IS_ERR(max98927->reset_gpio)) {
> +		ret = PTR_ERR(max98927->reset_gpio);
> +		dev_err(&i2c->dev, "error getting reset gpio: %d\n", ret);
> +		return ret;
> +	}
> +
> +	/*
> +	 * Only toggle reset line for the first instance when the
> +	 * reset line is shared among instances. For example,
> +	 * left and right amplifier share the same reset line, and
> +	 * we should only toggle the reset line once.
> +	 */
> +	if (max98927_is_first_to_reset(max98927)) {
> +		dev_info(&i2c->dev, "%s: toggle reset line\n", __func__);
> +		ret = max98927_i2c_toggle_reset(&i2c->dev, max98927);
> +		if (ret)
> +			return ret;
> +	}
> +
>   	/* regmap initialization */
>   	max98927->regmap
>   		= devm_regmap_init_i2c(i2c, &max98927_regmap);
> @@ -934,6 +1010,8 @@ static int max98927_i2c_probe(struct i2c_client *i2c,
>   	if (ret < 0)
>   		dev_err(&i2c->dev, "Failed to register component: %d\n", ret);
>   
> +	list_add(&max98927->list, &reset_list);
> +
>   	return ret;
>   }
>   
> diff --git a/sound/soc/codecs/max98927.h b/sound/soc/codecs/max98927.h
> index 538992a238b28..d48f61f6c3ba5 100644
> --- a/sound/soc/codecs/max98927.h
> +++ b/sound/soc/codecs/max98927.h
> @@ -275,5 +275,7 @@ struct max98927_priv {
>   	unsigned int master;
>   	unsigned int digital_gain;
>   	bool tdm_mode;
> +	struct gpio_desc *reset_gpio;
> +	struct list_head list;
>   };
>   #endif


  reply	other threads:[~2018-09-12 16:47 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-12 12:19 [PATCH 1/2] ASoC: max9892x: Add documentation for " Cheng-Yi Chiang
2018-09-12 12:19 ` [PATCH 2/2] ASoC: max98927: Add " Cheng-Yi Chiang
2018-09-12 16:47   ` Rohit Kumar [this message]
2018-09-17  9:00     ` [alsa-devel] " Cheng-yi Chiang
2018-09-17 17:47       ` Mark Brown
2018-09-20 11:36   ` kbuild test robot
2018-09-20 16:19   ` Mark Brown
2018-10-09 13:46     ` Cheng-yi Chiang
2018-10-12 10:05       ` Philipp Zabel
2018-10-12 13:46         ` Maxime Ripard
2018-10-17 17:02           ` Philipp Zabel
2018-11-20  1:19             ` Cheng-yi Chiang
2018-09-12 12:28 ` [PATCH 1/2] ASoC: max9892x: Add documentation for " Mark Brown
2018-09-13  4:25   ` Cheng-yi Chiang

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=7aa3c049-5ba0-1db3-08c8-510da1cf779d@codeaurora.org \
    --to=rohitkr@codeaurora.org \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=cychiang@chromium.org \
    --cc=dgreid@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ryans.lee@maximintegrated.com \
    /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

Powered by JetHome