linux-arm-msm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mayank Grover <groverm@codeaurora.org>
To: linus.walleij@linaro.org, agross@kernel.org, bjorn.andersson@linaro.org
Cc: linux-gpio@vger.kernel.org, linux-arm-msm@vger.kernel.org,
	linux-kernel@vger.kernel.org, neeraju@codeaurora.org,
	Mayank Grover <groverm@codeaurora.org>
Subject: [PATCH] pinctrl: msm: Add check for pinctrl group is valid
Date: Mon, 18 May 2020 21:20:25 +0530	[thread overview]
Message-ID: <1589817025-21886-1-git-send-email-groverm@codeaurora.org> (raw)

The list of reserved gpio pins for platform are populated
in gpiochip valid_mask.

Here on MSM common driver introduce ability to check if
pingroup is valid, by parsing pins in pingroup against
reserved pins for gpios. This does not handle non-gpio
pingroups.

Signed-off-by: Mayank Grover <groverm@codeaurora.org>
---
 drivers/pinctrl/qcom/pinctrl-msm.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/drivers/pinctrl/qcom/pinctrl-msm.c b/drivers/pinctrl/qcom/pinctrl-msm.c
index 85858c1..b6ebe26 100644
--- a/drivers/pinctrl/qcom/pinctrl-msm.c
+++ b/drivers/pinctrl/qcom/pinctrl-msm.c
@@ -261,6 +261,24 @@ static unsigned msm_regval_to_drive(u32 val)
 	return (val + 1) * 2;
 }
 
+static bool msm_pingroup_is_valid(struct msm_pinctrl *pctrl,
+				  const struct msm_pingroup *g)
+{
+	const unsigned int *pins = g->pins;
+	unsigned int num_pins = g->npins;
+	struct gpio_chip *chip = &pctrl->chip;
+	unsigned int max_gpios = chip->ngpio;
+	unsigned int i;
+
+	for (i = 0; i < num_pins; i++) {
+		/* Doesn't handle non-gpio pingroups */
+		if (pins[i] < max_gpios &&
+		    !gpiochip_line_is_valid(chip, pins[i]))
+			return false;
+	}
+	return true;
+}
+
 static int msm_config_group_get(struct pinctrl_dev *pctldev,
 				unsigned int group,
 				unsigned long *config)
@@ -276,6 +294,10 @@ static int msm_config_group_get(struct pinctrl_dev *pctldev,
 
 	g = &pctrl->soc->groups[group];
 
+	/* Check if group has all valid pins */
+	if (!msm_pingroup_is_valid(pctrl, g))
+		return -EINVAL;
+
 	ret = msm_config_reg(pctrl, g, param, &mask, &bit);
 	if (ret < 0)
 		return ret;
@@ -355,6 +377,10 @@ static int msm_config_group_set(struct pinctrl_dev *pctldev,
 
 	g = &pctrl->soc->groups[group];
 
+	/* Check if group has all valid pins */
+	if (!msm_pingroup_is_valid(pctrl, g))
+		return -EINVAL;
+
 	for (i = 0; i < num_configs; i++) {
 		param = pinconf_to_config_param(configs[i]);
 		arg = pinconf_to_config_argument(configs[i]);
-- 
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a
member of the Code Aurora Forum, hosted by The Linux Foundation

             reply	other threads:[~2020-05-18 15:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-18 15:50 Mayank Grover [this message]
2020-05-19  1:38 ` [PATCH] pinctrl: msm: Add check for pinctrl group is valid Bjorn Andersson
2020-05-19 11:31   ` Mayank Grover
2020-05-25  9:02   ` Linus Walleij
2020-06-02 12:26     ` Mayank Grover

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=1589817025-21886-1-git-send-email-groverm@codeaurora.org \
    --to=groverm@codeaurora.org \
    --cc=agross@kernel.org \
    --cc=bjorn.andersson@linaro.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=neeraju@codeaurora.org \
    /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).