lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210726071439.14248-5-sam.shih@mediatek.com>
Date:   Mon, 26 Jul 2021 15:14:31 +0800
From:   Sam Shih <sam.shih@...iatek.com>
To:     Rob Herring <robh+dt@...nel.org>, Sean Wang <sean.wang@...nel.org>,
        Linus Walleij <linus.walleij@...aro.org>,
        Matthias Brugger <matthias.bgg@...il.com>,
        Matt Mackall <mpm@...enic.com>,
        Herbert Xu <herbert@...dor.apana.org.au>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        Wim Van Sebroeck <wim@...ux-watchdog.org>,
        Guenter Roeck <linux@...ck-us.net>,
        Michael Turquette <mturquette@...libre.com>,
        Stephen Boyd <sboyd@...nel.org>,
        Hsin-Yi Wang <hsinyi@...omium.org>,
        Enric Balletbo i Serra <enric.balletbo@...labora.com>,
        Fabien Parent <fparent@...libre.com>,
        Seiya Wang <seiya.wang@...iatek.com>,
        <devicetree@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
        <linux-mediatek@...ts.infradead.org>, <linux-gpio@...r.kernel.org>,
        <linux-arm-kernel@...ts.infradead.org>,
        <linux-crypto@...r.kernel.org>, <linux-serial@...r.kernel.org>,
        <linux-watchdog@...r.kernel.org>, <linux-clk@...r.kernel.org>
CC:     John Crispin <john@...ozen.org>,
        Ryder Lee <Ryder.Lee@...iatek.com>,
        Sam Shih <sam.shih@...iatek.com>
Subject: [PATCH 04/12] pinctrl: mediatek: moore: use pin number in mtk_pin_desc instead of array index

Certain SoC are missing the middle part gpios in consecutive pins,
it's better to use pin number in mtk_pin_desc instead of array index
for the extensibility

Signed-off-by: Sam Shih <sam.shih@...iatek.com>
---
 drivers/pinctrl/mediatek/pinctrl-moore.c | 61 ++++++++++++++++++++++++
 1 file changed, 61 insertions(+)

diff --git a/drivers/pinctrl/mediatek/pinctrl-moore.c b/drivers/pinctrl/mediatek/pinctrl-moore.c
index 3a4a23c40a71..16206254ec3d 100644
--- a/drivers/pinctrl/mediatek/pinctrl-moore.c
+++ b/drivers/pinctrl/mediatek/pinctrl-moore.c
@@ -35,6 +35,19 @@ static const struct pin_config_item mtk_conf_items[] = {
 };
 #endif
 
+static int mtk_pin_desc_lookup(struct mtk_pinctrl *hw, int pin)
+{
+	int idx;
+
+	for (idx = 0 ; idx < hw->soc->npins ; idx++)
+		if (hw->soc->pins[idx].number == pin)
+			break;
+	if (idx < hw->soc->npins)
+		return idx;
+
+	return -EINVAL;
+}
+
 static int mtk_pinmux_set_mux(struct pinctrl_dev *pctldev,
 			      unsigned int selector, unsigned int group)
 {
@@ -74,6 +87,13 @@ static int mtk_pinmux_gpio_request_enable(struct pinctrl_dev *pctldev,
 {
 	struct mtk_pinctrl *hw = pinctrl_dev_get_drvdata(pctldev);
 	const struct mtk_pin_desc *desc;
+	int err;
+
+	err = mtk_pin_desc_lookup(hw, pin);
+	if (err >= 0)
+		pin = err;
+	else
+		return err;
 
 	desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin];
 
@@ -87,6 +107,13 @@ static int mtk_pinmux_gpio_set_direction(struct pinctrl_dev *pctldev,
 {
 	struct mtk_pinctrl *hw = pinctrl_dev_get_drvdata(pctldev);
 	const struct mtk_pin_desc *desc;
+	int err;
+
+	err = mtk_pin_desc_lookup(hw, pin);
+	if (err >= 0)
+		pin = err;
+	else
+		return err;
 
 	desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin];
 
@@ -102,6 +129,12 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
 	int val, val2, err, reg, ret = 1;
 	const struct mtk_pin_desc *desc;
 
+	err = mtk_pin_desc_lookup(hw, pin);
+	if (err >= 0)
+		pin = err;
+	else
+		return err;
+
 	desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin];
 
 	switch (param) {
@@ -217,6 +250,12 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
 	u32 reg, param, arg;
 	int cfg, err = 0;
 
+	err = mtk_pin_desc_lookup(hw, pin);
+	if (err >= 0)
+		pin = err;
+	else
+		return err;
+
 	desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin];
 
 	for (cfg = 0; cfg < num_configs; cfg++) {
@@ -434,6 +473,12 @@ static int mtk_gpio_get(struct gpio_chip *chip, unsigned int gpio)
 	const struct mtk_pin_desc *desc;
 	int value, err;
 
+	err = mtk_pin_desc_lookup(hw, gpio);
+	if (err >= 0)
+		gpio = err;
+	else
+		return err;
+
 	desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio];
 
 	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DI, &value);
@@ -447,6 +492,15 @@ static void mtk_gpio_set(struct gpio_chip *chip, unsigned int gpio, int value)
 {
 	struct mtk_pinctrl *hw = gpiochip_get_data(chip);
 	const struct mtk_pin_desc *desc;
+	int err;
+
+	err = mtk_pin_desc_lookup(hw, gpio);
+	if (err >= 0) {
+		gpio = err;
+	} else {
+		dev_err(hw->dev, "Failed to set gpio %d\n", gpio);
+		return;
+	}
 
 	desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio];
 
@@ -488,6 +542,13 @@ static int mtk_gpio_set_config(struct gpio_chip *chip, unsigned int offset,
 	struct mtk_pinctrl *hw = gpiochip_get_data(chip);
 	const struct mtk_pin_desc *desc;
 	u32 debounce;
+	int err;
+
+	err = mtk_pin_desc_lookup(hw, offset);
+	if (err >= 0)
+		offset = err;
+	else
+		return err;
 
 	desc = (const struct mtk_pin_desc *)&hw->soc->pins[offset];
 
-- 
2.29.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ