linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vladimir Zapolskiy <vz@mleia.com>
To: Mark Brown <broonie@kernel.org>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Alexandre Courbot <acourbot@nvidia.com>
Cc: Oder Chiou <oder_chiou@realtek.com>,
	alsa-devel@alsa-project.org, Takashi Iwai <tiwai@suse.de>,
	linux-gpio@vger.kernel.org, Bard Liao <bardliao@realtek.com>
Subject: [PATCH 2/7] ASoC: rt5677: clean up gpiolib callbacks
Date: Tue,  2 Jun 2015 02:09:13 +0300	[thread overview]
Message-ID: <1433200158-6890-2-git-send-email-vz@mleia.com> (raw)
In-Reply-To: <1433200031-6748-1-git-send-email-vz@mleia.com>

The main intention of the change is to remove bitwise operations on
GPIO level value as a preceding change before updating gpiolib
callbacks to utilize bool type representing a GPIO level. Usage of
generic over GPIO[1-5] macros allows to remove calculations with magic
numbers.

No functional change.

Signed-off-by: Vladimir Zapolskiy <vz@mleia.com>
Cc: Bard Liao <bardliao@realtek.com>
Cc: Oder Chiou <oder_chiou@realtek.com>
---
 sound/soc/codecs/rt5677.c | 32 ++++++++++++++++++++++++--------
 1 file changed, 24 insertions(+), 8 deletions(-)

diff --git a/sound/soc/codecs/rt5677.c b/sound/soc/codecs/rt5677.c
index 31d969a..28908f5a 100644
--- a/sound/soc/codecs/rt5677.c
+++ b/sound/soc/codecs/rt5677.c
@@ -4507,16 +4507,23 @@ static inline struct rt5677_priv *gpio_to_rt5677(struct gpio_chip *chip)
 static void rt5677_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
 {
 	struct rt5677_priv *rt5677 = gpio_to_rt5677(chip);
+	unsigned int val = 0;
 
 	switch (offset) {
 	case RT5677_GPIO1 ... RT5677_GPIO5:
+		if (value)
+			val = RT5677_GPIO_OUT_HI(offset);
+
 		regmap_update_bits(rt5677->regmap, RT5677_GPIO_CTRL2,
-			0x1 << (offset * 3 + 1), !!value << (offset * 3 + 1));
+				   RT5677_GPIO_OUT_MASK(offset), val);
 		break;
 
 	case RT5677_GPIO6:
+		if (value)
+			val = RT5677_GPIO6_OUT_HI;
+
 		regmap_update_bits(rt5677->regmap, RT5677_GPIO_CTRL3,
-			RT5677_GPIO6_OUT_MASK, !!value << RT5677_GPIO6_OUT_SFT);
+				   RT5677_GPIO6_OUT_MASK, val);
 		break;
 
 	default:
@@ -4528,18 +4535,27 @@ static int rt5677_gpio_direction_out(struct gpio_chip *chip,
 				     unsigned offset, int value)
 {
 	struct rt5677_priv *rt5677 = gpio_to_rt5677(chip);
+	unsigned int val;
 
 	switch (offset) {
 	case RT5677_GPIO1 ... RT5677_GPIO5:
+		val = RT5677_GPIO_DIR_OUT(offset);
+
+		if (value)
+			val |= RT5677_GPIO_OUT_HI(offset);
+
 		regmap_update_bits(rt5677->regmap, RT5677_GPIO_CTRL2,
-			0x3 << (offset * 3 + 1),
-			(0x2 | !!value) << (offset * 3 + 1));
+				   RT5677_GPIO_DIR_OUT_MASK(offset), val);
 		break;
 
 	case RT5677_GPIO6:
+		val = RT5677_GPIO6_DIR_OUT;
+
+		if (value)
+			val |= RT5677_GPIO6_OUT_HI;
+
 		regmap_update_bits(rt5677->regmap, RT5677_GPIO_CTRL3,
-			RT5677_GPIO6_DIR_MASK | RT5677_GPIO6_OUT_MASK,
-			RT5677_GPIO6_DIR_OUT | !!value << RT5677_GPIO6_OUT_SFT);
+			RT5677_GPIO6_DIR_MASK | RT5677_GPIO6_OUT_MASK, val);
 		break;
 
 	default:
@@ -4568,12 +4584,12 @@ static int rt5677_gpio_direction_in(struct gpio_chip *chip, unsigned offset)
 	switch (offset) {
 	case RT5677_GPIO1 ... RT5677_GPIO5:
 		regmap_update_bits(rt5677->regmap, RT5677_GPIO_CTRL2,
-			0x1 << (offset * 3 + 2), 0x0);
+				   RT5677_GPIO_DIR_MASK(offset), 0x0);
 		break;
 
 	case RT5677_GPIO6:
 		regmap_update_bits(rt5677->regmap, RT5677_GPIO_CTRL3,
-			RT5677_GPIO6_DIR_MASK, RT5677_GPIO6_DIR_IN);
+				   RT5677_GPIO6_DIR_MASK, RT5677_GPIO6_DIR_IN);
 		break;
 
 	default:
-- 
2.1.4

  parent reply	other threads:[~2015-06-01 23:09 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-01 23:07 [PATCH 0/7] ASoC: remove bitwise operations on GPIO level value Vladimir Zapolskiy
2015-06-01 23:09 ` [PATCH 1/7] ASoC: rt5677: add GPIO helper macros Vladimir Zapolskiy
2015-06-02  5:23   ` Takashi Iwai
2015-06-01 23:09 ` Vladimir Zapolskiy [this message]
2015-06-02 19:38   ` [PATCH 2/7] ASoC: rt5677: clean up gpiolib callbacks Mark Brown
2015-06-02 20:39     ` Vladimir Zapolskiy
2015-06-02 20:50       ` Mark Brown
2015-06-02 21:54         ` Vladimir Zapolskiy
2015-06-03 11:38           ` Mark Brown
2015-06-01 23:09 ` [PATCH 3/7] ASoC: wm8903: generalize GPIO control register bits Vladimir Zapolskiy
2015-06-02  9:19   ` Charles Keepax
2015-06-04  8:30   ` Linus Walleij
2015-06-04  8:47     ` [alsa-devel] " Charles Keepax
2015-06-04  9:19     ` Mark Brown
2015-06-04  9:24       ` Charles Keepax
2015-06-04 10:34         ` Mark Brown
2015-06-01 23:09 ` [PATCH 4/7] ASoC: wm8903: simplify gpiolib callbacks Vladimir Zapolskiy
2015-06-02  8:38   ` Charles Keepax
2015-06-02 19:41   ` Mark Brown
2015-06-02 20:18     ` Vladimir Zapolskiy
2015-06-02 20:31       ` Mark Brown
2015-06-02 20:41         ` Vladimir Zapolskiy
2015-06-01 23:09 ` [PATCH 5/7] ASoC: wm5100: remove bitwise operations involving GPIO level value Vladimir Zapolskiy
2015-06-02  8:40   ` Charles Keepax
2015-06-02 19:45   ` Mark Brown
2015-06-02 20:23     ` Vladimir Zapolskiy
2015-06-02 20:36       ` Mark Brown
2015-06-02 20:58         ` Vladimir Zapolskiy
2015-06-03 10:50       ` Trent Piepho
2015-06-03 11:07         ` Mark Brown
2015-06-03 19:13         ` [alsa-devel] " Vladimir Zapolskiy
2015-06-03 21:51           ` Trent Piepho
2015-06-03 22:58             ` Vladimir Zapolskiy
2015-06-01 23:09 ` [PATCH 6/7] ASoC: wm8962: " Vladimir Zapolskiy
2015-06-02  8:41   ` Charles Keepax
2015-06-01 23:09 ` [PATCH 7/7] ASoC: wm8996: " Vladimir Zapolskiy
2015-06-02  8:43   ` Charles Keepax

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=1433200158-6890-2-git-send-email-vz@mleia.com \
    --to=vz@mleia.com \
    --cc=acourbot@nvidia.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=bardliao@realtek.com \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=oder_chiou@realtek.com \
    --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).