All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Shubham Paralikar" <shubham.paralikar@mediatek.com>
Cc: linux-gpio@vger.kernel.org
Subject: Re: [PATCH v4 1/1] pinctrl: mediatek: Add MT8901/MT8971 ACPI driver
Date: Fri, 20 Nov 2026 17:29:28 +0000	[thread overview]
Message-ID: <sashiko-outbox-225664@kernel.org> (raw)
In-Reply-To: <20261120165908.3204369-2-shubham.paralikar@mediatek.com>

Thank you for your contribution! Sashiko AI review found 8 potential
issues to consider:
- [High] pinctrl: mediatek: dom_en clobber and resume masking of
  skip_eint_list
- [High] pinctrl: mediatek: missing bias_set_combo and bias_get_combo in
  mt8971_data
- [High] pinctrl: mediatek: broken zero and edge debounce in
  mtk_eint_set_debounce()
- [Medium] pinctrl: mediatek: mt8971_eint_hw leaves has_event_mask unset
- [Medium] pinctrl: mediatek: MMIO mapping leak of EINT bases in
  mtk_build_eint()
- [Medium] pinctrl: mediatek: late gpiochip_add_pin_range() in
  mtk_build_gpiochip()
- [Medium] pinctrl: mediatek: 5-bit DRV_ADV mask on MT8971 exceeds
  mtk_drv_adv_to_uA()
- [Low] pinctrl: mediatek: bus-hold misreported as pull-up in Moore
  mtk_pinconf_get()
--

commit 2b689323e13770cc2d8b01816cd9e413c2dc20fb
Author: Shubham Paralikar <shubham.paralikar@mediatek.com>

pinctrl: mediatek: Add MT8901/MT8971 ACPI driver

This commit adds an ACPI probe helper and SoC drivers for the MediaTek
MT8901 and MT8971 Paris pin controllers, along with ACPI, wake-event,
skip-list, reg_order, and bus-hold support in the shared pinctrl and EINT
drivers.

> diff --git a/drivers/pinctrl/mediatek/mtk-eint.c b/drivers/pinctrl/mediatek/mtk-eint.c
> index 389ceaffcee4a..1f8d68673725b 100644
> --- a/drivers/pinctrl/mediatek/mtk-eint.c
> +++ b/drivers/pinctrl/mediatek/mtk-eint.c

[ ... ]

> @@ -327,12 +486,38 @@ static unsigned int mtk_eint_hw_init(struct mtk_eint *eint)
>  		mask_reg = eint->base[i] + eint->regs->mask_set;
>  		for (j = 0; j < eint->base_pin_num[i]; j += 32) {
>  			writel(0xffffffff, dom_reg);
> -			writel(0xffffffff, mask_reg);
> +			writel(mtk_eint_mask_word_for_skip(eint, i, j), mask_reg);
>  			dom_reg += 4;
>  			mask_reg += 4;
>  		}
>  	}
> +	return 0;
> +}
>  
> +/* Make sure skip-listed EINTs are unmasked and domain enabled. */
> +static int mtk_eint_restore_skip_list(struct mtk_eint *eint)
> +{
> +	unsigned int k, eint_num, inst, idx;
> +	void __iomem *reg;
> +
> +	if (!eint->skip_eint_list || !eint->num_skip_eint)
> +		return 0;
> +
> +	for (k = 0; k < eint->num_skip_eint; k++) {
> +		eint_num = eint->skip_eint_list[k];
> +		if (eint_num >= eint->hw->ap_num)
> +			continue;
> +		inst = eint->pins[eint_num].instance;
> +		if (inst >= eint->nbase)
> +			continue;
> +		idx = eint->pins[eint_num].index;
> +
> +		reg = mtk_eint_get_offset(eint, eint_num, eint->regs->mask_clr);
> +		writel(BIT(idx & 0x1f), reg);
> +
> +		reg = mtk_eint_get_offset(eint, eint_num, eint->regs->dom_en);
> +		writel(BIT(idx & 0x1f), reg);
> +	}
>  	return 0;
>  }
>  
> @@ -371,6 +556,8 @@ static void mtk_eint_irq_handler(struct irq_desc *desc)
>  				shift = __ffs(status);
>  				status &= ~BIT(shift);
>  				mask = BIT(shift);
> +				if (shift + j >= eint->base_pin_num[i])
> +					continue;
>  				eint_num = eint->pin_list[i][shift + j];

[ ... ]

> @@ -436,6 +623,8 @@ EXPORT_SYMBOL_GPL(mtk_eint_do_suspend);
>  int mtk_eint_do_resume(struct mtk_eint *eint)
>  {
>  	mtk_eint_chip_write_mask(eint, eint->cur_mask);
> +	mtk_eint_apply_event_unmask(eint);
> +	mtk_eint_apply_wake_event_unmask(eint);
>  
>  	return 0;
>  }

[Severity: High]
Does mtk_eint_restore_skip_list() clobber dom_en for sibling EINTs, and do
mtk_eint_do_resume() and mtk_eint_irq_handler() end up masking skip-listed
firmware EINTs?

Unlike mask_clr, dom_en is a plain 32-bit bitmask register that
mtk_eint_hw_init() just set to 0xffffffff, so writing BIT(idx & 0x1f) to
dom_en clears domain enable for the other 31 EINTs in that word.

Also, skip-listed EINTs never have their bits set in eint->cur_mask (where
1 means unmasked), and mtk_eint_do_resume() calls
mtk_eint_chip_write_mask(eint, eint->cur_mask) without restoring the skip
list, which writes ~cur_mask to mask_set and leaves EINT215 masked after
resume.  Finally, if a skip-listed EINT asserts while AP domain access is
enabled, mtk_eint_irq_handler() dispatches it via
generic_handle_domain_irq() to handle_level_irq(), which calls
mask_ack_irq() and masks the firmware-owned interrupt because no Linux
irqaction is registered.

> diff --git a/drivers/pinctrl/mediatek/pinctrl-mt8971.c b/drivers/pinctrl/mediatek/pinctrl-mt8971.c
> new file mode 100644
> index 0000000000000..6b0ac68e834ef
> --- /dev/null
> +++ b/drivers/pinctrl/mediatek/pinctrl-mt8971.c
> @@ -0,0 +1,91 @@

[ ... ]

> +static const struct mtk_eint_hw mt8971_eint_hw = {
> +	.port_mask = 0xf,
> +	.ports     = 4,
> +	.ap_num    = 216,
> +	.db_cnt    = 32,
> +	/*
> +	 * The debounce registers are not confirmed for MT8971 yet, so leave
> +	 * db_time unset and report debounce as unsupported.
> +	 */
> +	.db_time   = NULL,
> +};
> +
> +static const unsigned int eint_event_mt8971[] = {20};

[Severity: Medium]
Should mt8971_eint_hw set .has_event_mask = true?

mt8971_data wires up eint_event_mt8971, but mtk_eint_write_event_mask()
returns early when !eint->hw->has_event_mask, so eint_event_mt8971 and
wake-event unmasking in mtk_eint_irq_set_wake() and mtk_eint_do_resume()
have no effect on MT8971.

> +/* EINT215 is used by firmware for PROCHOT and must stay unmasked. */
> +static const unsigned int mt8971_skip_eint_list[] = {215};
> +
> +static const struct mtk_pin_soc mt8971_data = {
> +	.reg_order = mt8971_reg_order,
> +	.reg_order_stride = 0x4000,
> +	.pins = mtk_pins_mt8971,
> +	.npins = ARRAY_SIZE(mtk_pins_mt8971),
> +	.ngrps = ARRAY_SIZE(mtk_pins_mt8971),
> +	.eint_hw = &mt8971_eint_hw,
> +	.eint_pin = eint_pins_mt8971,
> +	.nfuncs = 16,
> +	.gpio_m = 0,
> +	.base_names = mt8971_pinctrl_register_base_name,
> +	.nbase_names = ARRAY_SIZE(mt8971_pinctrl_register_base_name),
> +	.pull_type = NULL,
> +	.drive_set = mtk_pinconf_drive_set_rev1,
> +	.drive_get = mtk_pinconf_drive_get_rev1,
> +	.adv_drive_set = mtk_pinconf_adv_drive_set_raw,
> +	.adv_drive_get = mtk_pinconf_adv_drive_get_raw,
> +	.eint_event = eint_event_mt8971,
> +	.total_wake_eints = ARRAY_SIZE(eint_event_mt8971),
> +	.skip_eint_list = mt8971_skip_eint_list,
> +	.n_skip_eint = ARRAY_SIZE(mt8971_skip_eint_list),
> +};

[Severity: High]
Are .bias_set_combo, .bias_get_combo, and .pull_type missing from
mt8971_data?

mtk_pinconf_get() and mtk_pinconf_set() in pinctrl-paris.c handle all
PIN_CONFIG_BIAS_* parameters exclusively through bias_get_combo and
bias_set_combo, so every bias configuration or query on MT8971 currently
fails with -ENOTSUPP.  In addition, because mt8971_reg_order defines
non-zero masks for PU, PD, RSEL, PUPD, R0, and R1 on every non-virtual pin,
leaving pull_type as NULL causes mtk_pinconf_bias_set_combo() and
mtk_pinconf_bias_get_combo() to always match the RSEL / PU_PD branches and
never reach PUPD_R1R0.

> diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
> index ca8782f9358ac..e1bf3a4e089b3 100644
> --- a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
> +++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c

[ ... ]

> @@ -398,16 +444,25 @@ int mtk_build_eint(struct mtk_pinctrl *hw, struct platform_device *pdev)
>  	}
>  
>  	for (i = hw->soc->nbase_names, j = 0; i < count_reg_names; i++, j++) {
> -		hw->eint->base[j] = of_iomap(np, i);
> +		if (is_of_node(fwnode)) {
> +			hw->eint->base[j] = of_iomap(np, i);
> +		} else {
> +			res = platform_get_resource(pdev, IORESOURCE_MEM, i);
> +			hw->eint->base[j] = res ? ioremap(res->start,
> +							  resource_size(res)) : NULL;
> +		}
>  		if (!hw->eint->base[j]) {
>  			ret = -ENOMEM;
>  			goto err_free_eint;
>  		}
>  	}

[Severity: Medium]
Does this leak the ioremap() mappings in hw->eint->base[] if a later step
in mtk_paris_pinctrl_probe_soc() fails or when the device is unbound?

Once mtk_build_eint() returns 0, neither mtk_eint_teardown() nor any devres
action unmaps hw->eint->base[].  Using devm_platform_ioremap_resource() (or
unmapping in mtk_eint_teardown()) would avoid leaking the MMIO mappings.

[ ... ]

> @@ -905,8 +989,12 @@ static int mtk_pinconf_bias_get_pu_pd(struct mtk_pinctrl *hw,
>  	} else if (pu == 0 && pd == 1) {
>  		*pullup = 0;
>  		*enable = MTK_ENABLE;
> -	} else
> +	} else if (pu == 1 && pd == 1) {
> +		*pullup = MTK_BUS_HOLD;
> +		*enable = MTK_ENABLE;
> +	} else {
>  		err = -EINVAL;
> +	}
>  
>  out:
>  	return err;

[Severity: Low]
Can returning *pullup = MTK_BUS_HOLD (2) from mtk_pinconf_bias_get_pu_pd()
and mtk_pinconf_bias_get_pu_pd_rsel() cause mtk_pinconf_get() in
pinctrl-moore.c to misreport bus-hold as PIN_CONFIG_BIAS_PULL_UP?

pinctrl-paris.c was updated to check pullup != MTK_PULLUP, but
pinctrl-moore.c still checks:

drivers/pinctrl/mediatek/pinctrl-moore.c:mtk_pinconf_get() {
	...
	case PIN_CONFIG_BIAS_PULL_UP:
		if (hw->soc->bias_get_combo) {
			err = hw->soc->bias_get_combo(hw, desc, &pullup, &ret);
			if (err)
				return err;
			if (ret == MTK_PUPD_SET_R1R0_00 || ret == MTK_DISABLE)
				return -EINVAL;
			if (!pullup)
				return -EINVAL;
	...
}

When pu == 1 && pd == 1, pullup is MTK_BUS_HOLD, so !pullup is false and
PIN_CONFIG_BIAS_PULL_UP succeeds instead of returning -EINVAL.

> diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-mt8971.h b/drivers/pinctrl/mediatek/pinctrl-mtk-mt8971.h
> new file mode 100644
> index 0000000000000..7e59bc9507a18
> --- /dev/null
> +++ b/drivers/pinctrl/mediatek/pinctrl-mtk-mt8971.h
> @@ -0,0 +1,1646 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * Copyright (C) 2026 MediaTek Inc.
> + *
> + * MediaTek MT8971 pin data.
> + */
> +#ifndef __PINCTRL_MTK_MT8971_H
> +#define __PINCTRL_MTK_MT8971_H
> +
> +#include "pinctrl-paris.h"
> +
> +static const struct mtk_pin_field_order mt8971_reg_order[PINCTRL_PIN_REG_MAX] = {
> +	[PINCTRL_PIN_REG_DIR]     = { .index = 0, .offset = 0x00, .mask = 0x1,  .bitpos = 0 },
> +	[PINCTRL_PIN_REG_DO]      = { .index = 0, .offset = 0x10, .mask = 0x1,  .bitpos = 0 },
> +	[PINCTRL_PIN_REG_DI]      = { .index = 0, .offset = 0x20, .mask = 0x1,  .bitpos = 0 },
> +	[PINCTRL_PIN_REG_MODE]    = { .index = 0, .offset = 0x30, .mask = 0xf,  .bitpos = 0 },
> +	[PINCTRL_PIN_REG_DRV]     = { .index = 1, .offset = 0x00, .mask = 0x7,  .bitpos = 0 },
> +	[PINCTRL_PIN_REG_DRV_ADV] = { .index = 1, .offset = 0x00, .mask = 0x1f, .bitpos = 8 },

[Severity: Medium]
Is the 0x1f mask for PINCTRL_PIN_REG_DRV_ADV in mt8971_reg_order compatible
with mtk_drv_adv_to_uA()?

mt8971_data uses mtk_pinconf_adv_drive_get_raw(), which reads a 5-bit value
(0..31) with this mask and passes it to mtk_drv_adv_to_uA() in
pinctrl-paris.c during PIN_CONFIG_DRIVE_STRENGTH and
PIN_CONFIG_DRIVE_STRENGTH_UA queries.  mtk_drv_adv_to_uA() expects a 3-bit
value and triggers WARN_ON_ONCE(val < 0 || val > 7) if bits 3 or 4 are set.

> diff --git a/drivers/pinctrl/mediatek/pinctrl-paris.c b/drivers/pinctrl/mediatek/pinctrl-paris.c
> index 1ae8133dd9c55..51f180839c94c 100644
> --- a/drivers/pinctrl/mediatek/pinctrl-paris.c
> +++ b/drivers/pinctrl/mediatek/pinctrl-paris.c

[ ... ]

> @@ -928,9 +955,17 @@ static int mtk_gpio_set_config(struct gpio_chip *chip, unsigned int offset,
>  
>  	desc = (const struct mtk_pin_desc *)&hw->soc->pins[offset];
>  
> +	/*
> +	 * Not every EINT has debounce hardware, the virtual GPIOs among them,
> +	 * and some SoCs have no debounce table at all (db_time is NULL).
> +	 * Report that as unsupported so gpiolib treats the request as optional
> +	 * rather than warning about an -EINVAL from the EINT driver.
> +	 */
>  	if (!hw->eint ||
>  	    pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE ||
> -	    desc->eint.eint_n == EINT_NA)
> +	    desc->eint.eint_n == EINT_NA ||
> +	    !hw->eint->hw->db_time ||
> +	    !hw->eint->pins[desc->eint.eint_n].debounce)
>  		return -ENOTSUPP;
>  
>  	debounce = pinconf_to_config_argument(config);

[Severity: High]
On MT8901 (where db_time is non-NULL), what happens when ACPI configures a
debounce-capable pin with debounce == 0 or before irq_set_irq_type() sets
level sensitivity?

acpi_dev_gpio_irq_wake_get_by() and acpi_find_gpio() unconditionally call
gpio_set_debounce_timeout() even when the ACPI resource specifies a
debounce timeout of 0, and before irq_set_irq_type() runs.
mtk_gpio_set_config() forwards that call to mtk_eint_set_debounce():

drivers/pinctrl/mediatek/mtk-eint.c:mtk_eint_set_debounce() {
	...
	if (!mtk_eint_can_en_debounce(eint, eint_num))
		return -EINVAL;

	dbnc = eint->num_db_time;
	for (i = 0; i < eint->num_db_time; i++) {
		if (debounce <= eint->hw->db_time[i]) {
			dbnc = i;
			break;
		}
	}
	...
}

If the EINT sens register bit is 0 (edge-sensitive),
mtk_eint_can_en_debounce() returns 0 and mtk_eint_set_debounce() returns
-EINVAL, which gpio_set_config_with_argument_optional() does not ignore,
failing the ACPI GpioInt/GpioIo lookup.  If the EINT is level-sensitive and
debounce == 0, the loop matches 0 <= db_time[0] (156 us) and enables a
156 us hardware debounce filter via MTK_EINT_DBNC_SET_EN instead of
disabling debounce.

> @@ -961,9 +996,21 @@ static int mtk_build_gpiochip(struct mtk_pinctrl *hw)
>  	if (ret < 0)
>  		return ret;
>  
> +	/* On DT the range comes from the gpio-ranges property. */
> +	if (!is_of_node(dev_fwnode(hw->dev)))
> +		return gpiochip_add_pin_range(chip, dev_name(hw->dev), 0, 0,
> +					      chip->ngpio);
> +
>  	return 0;
>  }

[Severity: Medium]
Can calling gpiochip_add_pin_range() after devm_gpiochip_add_data() miss
pinmux setup for GPIOs requested during chip registration?

devm_gpiochip_add_data() registers the ACPI GeneralPurposeIo OpRegion (which
evaluates AML _REG), clears ACPI _DEP dependencies, and exposes the GPIO
device before returning.  Any GPIO requested during that window sees an
empty pin_ranges list in gpiochip_generic_request(), skipping
pinctrl_gpio_request() / mtk_pinmux_gpio_request_enable() and racing with
the unlocked list_add_tail() in gpiochip_add_pin_range().  Registering the
range via chip->add_pin_ranges would populate pin_ranges before
acpi_gpiochip_add() runs.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261120165908.3204369-1-shubham.paralikar@mediatek.com?part=1

      reply	other threads:[~2026-11-20 17:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 16:58 [PATCH v4 0/1] pinctrl: mediatek: Add MT8901/MT8971 ACPI driver Shubham Paralikar
2026-11-20 16:58 ` [PATCH v4 1/1] " Shubham Paralikar
2026-11-20 17:29   ` sashiko-bot [this message]

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=sashiko-outbox-225664@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shubham.paralikar@mediatek.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.