Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3297433pxv; Mon, 26 Jul 2021 00:18:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLm4azBZCBcKWCn6U0RlSTlM7AcdeKL2h5DWzI8MfEOiaDzcWFPjgYQ1QCgttna97+9OW1 X-Received: by 2002:a02:cebb:: with SMTP id z27mr15255490jaq.72.1627283880262; Mon, 26 Jul 2021 00:18:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627283880; cv=none; d=google.com; s=arc-20160816; b=YXk1t9aMDIfX30hmXAcW8ZnTXu6Es3gJj70chpoRVR5WoS3xOep28pNb0zfvlANnOU gbuihWHgsLj1uHYgtK+AmNC0qsCt6dpH2kFz9JEV+quK0KAUsY7b73YkU964KAVd7jo/ 1pd0RZeG9SnfUSI0mAVh7znCKOC9xJ5Ff4PcXMD7k6ZKNK0FFd0el8Zkl4SOHwzOTmmK JL3R4X09tjt83BfwwplEfAqLIbdjCkfsRJJOAtbmwcM8sdtGkELyiuZxuVlPBaWv2k6I ebLcPaJfZJFk48jGo8Qsknj/9hnOUpjURHF349bw4K+9kM7779UKEJjee1IAqdZptyfk Z2mA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=g8moGShRGvbiB7tktKWd5nBN0nDxkNRjRRb+36yZWOw=; b=h4nwgbvlV9oyLfTWX2nSj0Gn5zSmAQVHT9U38gRebNYTjCHJ2rFcgVags9SEzjoDEI 6E1l8+9L25Xjc2H9X8Ey4XlhjCug4feRHxr597aQFLyd/Wiqs9GQRqL55jlxTB8Efg2w BWPbGQy3bd2vrEhbt8a5kivTY2S+/ukZ51EeWwzk50OBp5r3vWNR5LJdi0OdD3nXM+X8 rkUbUUtaOJN2VXH1icds8sPVMqoYmtP16A75mgzdD+gFWaPkxKk7SpKzy7BwtXWn4SN/ yMHXPhbACiSyH/TJQihZU3og3BXR0DuKBEdm3BR8RwIwuSaLgphRcs75f+leEXzU8XMW vNQw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m8si33160575jav.78.2021.07.26.00.17.49; Mon, 26 Jul 2021 00:18:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232347AbhGZGhA (ORCPT + 99 others); Mon, 26 Jul 2021 02:37:00 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:56688 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S232307AbhGZGg7 (ORCPT ); Mon, 26 Jul 2021 02:36:59 -0400 X-UUID: 47b170a8835d494498e0fb4f6ea05f59-20210726 X-UUID: 47b170a8835d494498e0fb4f6ea05f59-20210726 Received: from mtkcas10.mediatek.inc [(172.21.101.39)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1103810837; Mon, 26 Jul 2021 15:17:26 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs01n1.mediatek.inc (172.21.101.68) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 26 Jul 2021 15:17:24 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 26 Jul 2021 15:17:24 +0800 From: Sam Shih To: Rob Herring , Sean Wang , Linus Walleij , Matthias Brugger , Matt Mackall , Herbert Xu , Greg Kroah-Hartman , Wim Van Sebroeck , Guenter Roeck , Michael Turquette , Stephen Boyd , Hsin-Yi Wang , Enric Balletbo i Serra , Fabien Parent , Seiya Wang , , , , , , , , , CC: John Crispin , Ryder Lee , Sam Shih Subject: [PATCH 04/12] pinctrl: mediatek: moore: use pin number in mtk_pin_desc instead of array index Date: Mon, 26 Jul 2021 15:14:31 +0800 Message-ID: <20210726071439.14248-5-sam.shih@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20210726071439.14248-1-sam.shih@mediatek.com> References: <20210726071439.14248-1-sam.shih@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org 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 --- 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