mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Rosin <peda@axentia.se>
To: <linux-kernel@vger.kernel.org>
Cc: Peter Rosin <peda@axentia.se>,
	Linus Walleij <linus.walleij@linaro.org>,
	Andrey Smirnov <andrew.smirnov@gmail.com>,
	Neil Armstrong <narmstrong@baylibre.com>,
	<linux-gpio@vger.kernel.org>
Subject: [PATCH 2/2] pinctrl: sx150x: support setting multiple pins at once
Date: Tue, 22 Nov 2016 17:06:02 +0100	[thread overview]
Message-ID: <1479830762-1839-3-git-send-email-peda@axentia.se> (raw)
In-Reply-To: <1479830762-1839-1-git-send-email-peda@axentia.se>

The mask of a possible oscio pin is cached, making it easier to test
for the exception.

Signed-off-by: Peter Rosin <peda@axentia.se>
---
 drivers/pinctrl/pinctrl-sx150x.c | 37 +++++++++++++++++++++++++++++--------
 1 file changed, 29 insertions(+), 8 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-sx150x.c b/drivers/pinctrl/pinctrl-sx150x.c
index ef4ef88e0ee9..5bcede2b2cd8 100644
--- a/drivers/pinctrl/pinctrl-sx150x.c
+++ b/drivers/pinctrl/pinctrl-sx150x.c
@@ -114,6 +114,7 @@ struct sx150x_pinctrl {
 	} irq;
 	struct mutex lock;
 	const struct sx150x_device_data *data;
+	unsigned long oscio_mask;
 };
 
 static const struct pinctrl_pin_desc sx150x_8_pins[] = {
@@ -290,14 +291,7 @@ static const struct pinctrl_ops sx150x_pinctrl_ops = {
 
 static bool sx150x_pin_is_oscio(struct sx150x_pinctrl *pctl, unsigned int pin)
 {
-	if (pin >= pctl->data->npins)
-		return false;
-
-	/* OSCIO pin is only present in 789 devices */
-	if (pctl->data->model != SX150X_789)
-		return false;
-
-	return !strcmp(pctl->data->pins[pin].name, "oscio");
+	return !!(BIT(pin) & pctl->oscio_mask);
 }
 
 static int sx150x_gpio_get_direction(struct gpio_chip *chip,
@@ -395,6 +389,15 @@ static void sx150x_gpio_set(struct gpio_chip *chip, unsigned int offset,
 
 }
 
+static void sx150x_gpio_set_multiple(struct gpio_chip *chip,
+				     unsigned long *mask,
+				     unsigned long *bits)
+{
+	struct sx150x_pinctrl *pctl = gpiochip_get_data(chip);
+
+	regmap_write_bits(pctl->regmap, pctl->data->reg_data, *mask, *bits);
+}
+
 static int sx150x_gpio_direction_input(struct gpio_chip *chip,
 				       unsigned int offset)
 {
@@ -996,6 +999,20 @@ static int sx150x_regmap_reg_write(void *context, unsigned int reg,
 	return 0;
 }
 
+static void sx150x_oscio_mask_init(struct sx150x_pinctrl *pctl)
+{
+	int pin;
+
+	/* OSCIO pin is only present in 789 devices */
+	if (pctl->data->model != SX150X_789)
+		return;
+
+	for (pin = 0; pin < pctl->data->npins; ++pin) {
+		if (!strcmp(pctl->data->pins[pin].name, "oscio"))
+			pctl->oscio_mask |= BIT(pin);
+	}
+}
+
 static bool sx150x_reg_volatile(struct device *dev, unsigned int reg)
 {
 	struct sx150x_pinctrl *pctl = i2c_get_clientdata(to_i2c_client(dev));
@@ -1045,6 +1062,8 @@ static int sx150x_probe(struct i2c_client *client,
 	if (!pctl->data)
 		return -EINVAL;
 
+	sx150x_oscio_mask_init(pctl);
+
 	pctl->regmap = devm_regmap_init(dev, NULL, pctl,
 					&sx150x_regmap_config);
 	if (IS_ERR(pctl->regmap)) {
@@ -1069,6 +1088,8 @@ static int sx150x_probe(struct i2c_client *client,
 	pctl->gpio.direction_output = sx150x_gpio_direction_output;
 	pctl->gpio.get = sx150x_gpio_get;
 	pctl->gpio.set = sx150x_gpio_set;
+	if (!pctl->oscio_mask)
+		pctl->gpio.set_multiple = sx150x_gpio_set_multiple;
 	pctl->gpio.set_single_ended = sx150x_gpio_set_single_ended;
 	pctl->gpio.parent = dev;
 #ifdef CONFIG_OF_GPIO
-- 
2.1.4

  parent reply	other threads:[~2016-11-22 16:21 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-22 16:06 [PATCH 0/2] pinctrl: sx150x: set " Peter Rosin
2016-11-22 16:06 ` [PATCH 1/2] pinctrl: sx150x: various spelling fixes and some white-space cleanup Peter Rosin
2016-11-23  9:13   ` Neil Armstrong
2016-11-22 16:06 ` Peter Rosin [this message]
2016-11-23  9:17   ` [PATCH 2/2] pinctrl: sx150x: support setting multiple pins at once Neil Armstrong
2016-11-23  9:20 ` [PATCH 0/2] pinctrl: sx150x: set " Neil Armstrong
2016-11-23  9:39   ` Peter Rosin

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=1479830762-1839-3-git-send-email-peda@axentia.se \
    --to=peda@axentia.se \
    --cc=andrew.smirnov@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=narmstrong@baylibre.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

all inboxes | Powered by JetHome®