[PATCH v5 0/4] pinctrl: mediatek: Enable module build support

Justin Yeh justin.yeh at mediatek.com
Wed Jul 8 23:33:45 PDT 2026


This series lets the MediaTek pinctrl drivers be built as loadable
kernel modules. This is required for Android GKI + vendor_dlkm
deployments, where vendor-specific drivers must be kept separate from
the GKI vmlinux and loaded as modules from the vendor partition.

Enabling the individual SoC drivers as modules is a single logical step,
but it has a few prerequisites, so the series is:

  1. Fix a pre-existing GPIO chip lifecycle bug. The gpio_chip lives in
     device-managed memory but is registered with the non-managed
     gpiochip_add_data(). While the drivers were built-in only this was
     harmless, but once they can be unbound/rmmod'd, devm frees the
     backing memory while the chip is still registered (use-after-free).
     Switch to devm_gpiochip_add_data() in the shared probe/init paths.
     This affects the v1 common code (pinctrl-mtk-common.c) as well as
     the moore and paris common code, which is where the v2 SoCs
     register their gpio_chip (pinctrl-mtk-common-v2.c itself does not
     register one, so it is untouched).

  2. Make the shared common code modular. The SoC drivers link against
     pinctrl-mtk-common.c (v1), pinctrl-moore.c and pinctrl-mtmips.c,
     whose Kconfig symbols were bool and which exported nothing. Without
     this, selecting a SoC driver as =m forces the common symbol to =y
     and the module fails to link against the unexported entry points
     (e.g. allmodconfig would break). Convert PINCTRL_MTK,
     PINCTRL_MTK_MOORE and PINCTRL_MTK_MTMIPS to tristate, export the
     entry points, and add MODULE_LICENSE()/MODULE_DESCRIPTION(). The
     already-modular v2 common code additionally needs mtk_rmw()
     exported, since it is called directly by SoC drivers such as
     mt7623 and would otherwise be undefined once those are modular.

  3. Convert the MT7986 driver to a single initcall. It registers two
     platform drivers (mt7986a/mt7986b) and used to call arch_initcall()
     twice. That is fine when built-in, but a module has only one
     module_init(), so two arch_initcall()s break the module build with
     a redefinition of init_module()/__inittest(). Fold both drivers
     into one platform_register_drivers() call from a single initcall.
     No functional change when built-in.

  4. Flip every SoC driver's Kconfig from bool to tristate and add the
     module metadata.

The series builds cleanly under allmodconfig on arm64 (all SoC drivers
as =m).

Changes since v4:
 - Squashed the 32 per-driver "Enable module build support" patches into
   a single patch (4/4), as requested by Linus Walleij.
 - Added patch 1/4 fixing the gpio_chip lifecycle (devm) bug, as a
   prerequisite for making the drivers unloadable, per Linus Walleij's
   review.
 - Added patch 2/4 converting the shared common drivers to modules, so
   that the v1/moore/mtmips SoC drivers can actually link as modules
   (without it 21 of the SoC drivers would fail to build as =m). Also
   export mtk_rmw() from the v2 common code (fixes a modpost
   "mtk_rmw undefined" error on the mt7623 module).
 - Added patch 3/4 folding MT7986's two arch_initcall()s into a single
   initcall (fixes an init_module()/__inittest() redefinition when the
   driver is built as a module).
 - Dropped the (inappropriate) per-driver Fixes: tags from the module
   enablement patch; it is a feature change, not a fix.

The Reviewed-by on patch 4/4 is carried over from the per-driver patches
reviewed in v4; the reviewer agreed to preserve it across the squash.
Note that the MT7986 single-initcall change that was part of that patch
has been split out into patch 3/4, so patch 4/4 now only flips Kconfig
and adds module metadata. Patches 1/4, 2/4 and 3/4 have not been
reviewed yet.

Justin Yeh (4):
  pinctrl: mediatek: use devm_gpiochip_add_data() for GPIO chip
  pinctrl: mediatek: allow common drivers to be built as modules
  pinctrl: mediatek: mt7986: register both platform drivers from a
    single initcall
  pinctrl: mediatek: enable module build support for all SoC drivers

 drivers/pinctrl/mediatek/Kconfig              | 70 +++++++++----------
 drivers/pinctrl/mediatek/pinctrl-moore.c      | 11 +--
 drivers/pinctrl/mediatek/pinctrl-mt2701.c     |  3 +
 drivers/pinctrl/mediatek/pinctrl-mt2712.c     |  3 +
 drivers/pinctrl/mediatek/pinctrl-mt6397.c     |  3 +
 drivers/pinctrl/mediatek/pinctrl-mt6795.c     |  3 +
 drivers/pinctrl/mediatek/pinctrl-mt6797.c     |  3 +
 drivers/pinctrl/mediatek/pinctrl-mt6878.c     |  1 +
 drivers/pinctrl/mediatek/pinctrl-mt6893.c     |  1 +
 drivers/pinctrl/mediatek/pinctrl-mt7620.c     |  3 +
 drivers/pinctrl/mediatek/pinctrl-mt7621.c     |  3 +
 drivers/pinctrl/mediatek/pinctrl-mt7622.c     |  3 +
 drivers/pinctrl/mediatek/pinctrl-mt7623.c     |  3 +
 drivers/pinctrl/mediatek/pinctrl-mt7629.c     |  3 +
 drivers/pinctrl/mediatek/pinctrl-mt76x8.c     |  3 +
 drivers/pinctrl/mediatek/pinctrl-mt7981.c     |  3 +
 drivers/pinctrl/mediatek/pinctrl-mt7986.c     | 18 ++---
 drivers/pinctrl/mediatek/pinctrl-mt7988.c     |  3 +
 drivers/pinctrl/mediatek/pinctrl-mt8127.c     |  3 +
 drivers/pinctrl/mediatek/pinctrl-mt8135.c     |  3 +
 drivers/pinctrl/mediatek/pinctrl-mt8167.c     |  3 +
 drivers/pinctrl/mediatek/pinctrl-mt8173.c     |  3 +
 drivers/pinctrl/mediatek/pinctrl-mt8183.c     |  3 +
 drivers/pinctrl/mediatek/pinctrl-mt8186.c     |  3 +
 drivers/pinctrl/mediatek/pinctrl-mt8188.c     |  1 +
 drivers/pinctrl/mediatek/pinctrl-mt8189.c     |  1 +
 drivers/pinctrl/mediatek/pinctrl-mt8192.c     |  1 +
 drivers/pinctrl/mediatek/pinctrl-mt8195.c     |  3 +
 drivers/pinctrl/mediatek/pinctrl-mt8196.c     |  1 +
 drivers/pinctrl/mediatek/pinctrl-mt8365.c     |  1 +
 drivers/pinctrl/mediatek/pinctrl-mt8516.c     |  3 +
 .../pinctrl/mediatek/pinctrl-mtk-common-v2.c  |  1 +
 drivers/pinctrl/mediatek/pinctrl-mtk-common.c | 22 +++---
 drivers/pinctrl/mediatek/pinctrl-mtmips.c     |  4 ++
 drivers/pinctrl/mediatek/pinctrl-paris.c      |  2 +-
 drivers/pinctrl/mediatek/pinctrl-rt2880.c     |  3 +
 drivers/pinctrl/mediatek/pinctrl-rt305x.c     |  3 +
 drivers/pinctrl/mediatek/pinctrl-rt3883.c     |  3 +
 38 files changed, 149 insertions(+), 58 deletions(-)


base-commit: 8e9685d3c41c35dd1b37df70d854137abcb2fbac
-- 
2.45.2




More information about the Linux-mediatek mailing list