[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20250124134918.2779-2-ot_chhao.chang@mediatek.com>
Date: Fri, 24 Jan 2025 21:49:05 +0800
From: Hao Chang <ot_chhao.chang@...iatek.com>
To: Sean Wang <sean.wang@...nel.org>, Linus Walleij
<linus.walleij@...aro.org>, Matthias Brugger <matthias.bgg@...il.com>,
AngeloGioacchino Del Regno <angelogioacchino.delregno@...labora.com>
CC: Wenbin Mei <wenbin.mei@...iatek.com>, Axe Yang <axe.yang@...iatek.com>,
Qingliang Li <qingliang.li@...iatek.com>, Hanks Chen
<hanks.chen@...iatek.com>, Chunhui Li <chunhui.li@...iatek.com>,
<linux-mediatek@...ts.infradead.org>, <linux-gpio@...r.kernel.org>,
<linux-kernel@...r.kernel.org>, <linux-arm-kernel@...ts.infradead.org>, "Hao
Chang" <ot_chhao.chang@...iatek.com>
Subject: [PATCH v3 1/2] pinctrl: mediatek: update EINT base retrieval method
Change the method of obtaining the EINT base from a single value to
multiple values.
Modify the EINT base and add nbase for counting.
Change-Id: I708f2eaa4c57b5705201025c252a7122914c4a40
Signed-off-by: Hao Chang <ot_chhao.chang@...iatek.com>
Signed-off-by: Qingliang Li <qingliang.li@...iatek.com>
---
.../pinctrl/mediatek/pinctrl-mtk-common-v2.c | 50 +++++++++++++------
1 file changed, 35 insertions(+), 15 deletions(-)
diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
index 6411c10cb637..e74fc68f631d 100644
--- a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
+++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
@@ -368,7 +368,7 @@ static const struct mtk_eint_xt mtk_eint_xt = {
int mtk_build_eint(struct mtk_pinctrl *hw, struct platform_device *pdev)
{
struct device_node *np = pdev->dev.of_node;
- unsigned int i, j, count_reg_names;
+ int ret, i, j, count_reg_names;
if (!IS_ENABLED(CONFIG_EINT_MTK))
return 0;
@@ -377,7 +377,7 @@ int mtk_build_eint(struct mtk_pinctrl *hw, struct platform_device *pdev)
return -ENODEV;
count_reg_names = of_property_count_strings(np, "reg-names");
- if (count_reg_names < 0 || count_reg_names < hw->soc->nbase_names)
+ if (count_reg_names < hw->soc->nbase_names)
return -EINVAL;
hw->eint = devm_kmalloc(hw->dev, sizeof(*hw->eint), GFP_KERNEL);
@@ -385,33 +385,53 @@ int mtk_build_eint(struct mtk_pinctrl *hw, struct platform_device *pdev)
return -ENOMEM;
hw->eint->nbase = count_reg_names - hw->soc->nbase_names;
- hw->eint->base = devm_kmalloc_array(&pdev->dev, hw->eint->nbase,
+ hw->eint->base = devm_kmalloc_array(hw->dev, hw->eint->nbase,
sizeof(*hw->eint->base), GFP_KERNEL);
- if (!hw->eint->base)
- return -ENOMEM;
+ if (!hw->eint->base) {
+ ret = -ENOMEM;
+ goto err_free_eint;
+ }
for (i = hw->soc->nbase_names, j = 0; i < count_reg_names; i++, j++) {
hw->eint->base[j] = of_iomap(np, i);
- if (IS_ERR(hw->eint->base[j]))
- return PTR_ERR(hw->eint->base[j]);
+ if (IS_ERR(hw->eint->base[j])) {
+ ret = PTR_ERR(hw->eint->base[j]);
+ goto err_free_eint;
+ }
}
- if (!of_property_read_bool(np, "interrupt-controller"))
- return -ENODEV;
+ if (!of_property_read_bool(np, "interrupt-controller")) {
+ ret = -ENODEV;
+ goto err_free_eint;
+ }
hw->eint->irq = irq_of_parse_and_map(np, 0);
- if (!hw->eint->irq)
- return -EINVAL;
-
- if (hw->soc->eint_pin)
- hw->eint->pins = hw->soc->eint_pin;
+ if (!hw->eint->irq) {
+ ret = -EINVAL;
+ goto err_free_eint;
+ }
hw->eint->dev = &pdev->dev;
hw->eint->hw = hw->soc->eint_hw;
hw->eint->pctl = hw;
hw->eint->gpio_xlate = &mtk_eint_xt;
- return mtk_eint_do_init(hw->eint);
+ ret = mtk_eint_do_init(hw->eint);
+ if (ret)
+ goto err_free_eint;
+
+ return 0;
+
+err_free_eint:
+ for (j = 0; j < hw->eint->nbase; j++) {
+ if (hw->eint->base[j])
+ iounmap(hw->eint->base[j]);
+ }
+ if (hw->eint->base)
+ devm_kfree(hw->dev, hw->eint->base);
+ devm_kfree(hw->dev, hw->eint);
+ hw->eint = NULL;
+ return ret;
}
EXPORT_SYMBOL_GPL(mtk_build_eint);
--
2.46.0
Powered by blists - more mailing lists