From nobody Sat Jun 13 23:11:43 2026 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BEFDC402BA7 for ; Tue, 5 May 2026 10:41:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777977664; cv=none; b=PUmqspHQlTepBpAjHzkXbgEHqCnL87gPhAYHMcW1v3WiflqGjz20ov5SRnPOCFMH+WchSnsXZ9brq1xMw/hm4Cw51hkj26jJ1kWCKjguq+sswbzhJG/AQebptagbsGZ9H198OacnEOzvTEBMupgwr/e9iLsefpW/AXf+f0q8hU4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777977664; c=relaxed/simple; bh=HejP0PadiaBCwlq4NkMh3b6gnRbSP97LAOiJPTPXaUs=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Q0hdO8VcigTyQRF3NzxyLstwmtCvqjl/DiN+umHq/Q81didvA2zfo2FvB6PPHyb9zwctd3Zi46t3DeCZ7O+MM/XRqnxK3ZJ5627DA2ErZ7nKm9BccDQ2mdBlpNHdRt9iXA/AX9amNgIO1RsTDgQGuXF1+s0nP5MXZwZOYjlIYGs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=GF7FcYDg; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="GF7FcYDg" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-2ba0714574fso12397375ad.2 for ; Tue, 05 May 2026 03:41:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1777977662; x=1778582462; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=+mNgWlyrL8XJotrTax0tHAhgn97GtRZawZOuedgrq/s=; b=GF7FcYDgtZ7xoW30OWrlcwPB22Qh+DfatKSNtxn8iaiqK0TPZ7/B/BPw8dBbagB+S5 mj1RiAUyDJfW9GZ4YxCSjy73GyajNM7dooQVyWEO7kia2HAN7Bp5Bp7m2GIkj33QQmsM NbbaGrohm0tF6PHZkxjZ6Kj8Jb0xc6VRdsmTc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777977662; x=1778582462; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=+mNgWlyrL8XJotrTax0tHAhgn97GtRZawZOuedgrq/s=; b=m3kqHdvgFMUzvOBdRsffHRr8+/++32Fs038gG1+LWRGle7Pv2GjRhgpC+90Y7Dqxty MFD4n1qbLbL7FFjwkvrY9KQ3A8pofOoQH8j524r1t4lp0gCzbGGb4Cj5JoO0220oLWLZ QAwGF+ZDdjk02AI56xpBPw0RQW/Uma5l7734rHcKR79Y+Oa6VkkN7rw3W1IgT0t9J2ra ApD2k01y3Sj9L4DY3D7HCR7MWsBXZ7eRiGLFEPleMLY+Wf8KJoejxf6HkBD3xGbAqNlO g6wUDmpKhJqgj9LK+vyaOhhhx+ea8ccnTvB4re1pqJaBPo1x6KMht2WxY6NIgr707VLs 0l6A== X-Forwarded-Encrypted: i=1; AFNElJ+XzQ/XBOVvh7WPr+rZtz2MMUC1zQ0A5EnhFC4Mwb2MGNqOKwgME6Y9RNWxumKUzQTFU9fH9vH0Wh04rj8=@vger.kernel.org X-Gm-Message-State: AOJu0Yy/lUyFS9p0eroGvbqeKWSvbNDveXstMIWyeDLEwIh/lrxmq/Pe nEhGCatKdOxtbwgzDEEgSUx16sCdjmhqRpohEBvRel062yEWWA8+iDkNEN21xPHNTg== X-Gm-Gg: AeBDievWRyR0KrA91sdEAo3ZxRG8gss/1FT//326Edsf8XmBQvsRNzWRcrtrYkMBP2i UQ6BUCIc1yBfzlcE7otZvrD6RQpo20YhHtkazrQV/TYtWPqVMfLRo1HVzytV1e+XrA7glJoY1WB Te3zDR/9xN7fODxwJwcfsyghbJczvMwdC0iGrFuaTs0yGPojrdUB2wIiXyvO64C8FmP7zqKmMof 1+CaKv7Og90E4xvD0evtJpLRWY1JcaANhVZR4sgsVl4vL826qg22OjXumX3aYAe/PE5henRRliv K+Wh61B0zsiAns68KNGaXUey6ccVrKzCYXdvU4bxNjtE4nmKyuiwpV0xGe0lkEXoJtt+EDS10YJ yCUy8SCLUeABUZtOp5ZlM8F8P0guwMinsvQVCQOGJsowrP8v3LG/Dtfuv51mvhLHA1d1FjdwBMx 6qSQrl6FBdnngDhw4x618xqTqC7/dnr3xfx2StwRlfzZ55z4VgCFLwXFz8Hfg+/EwdOr4H1HhAO 1dLy8o4F0HNd6OGheQ= X-Received: by 2002:a17:903:3c66:b0:2b2:4cd2:e16c with SMTP id d9443c01a7336-2b9f260d87bmr130052675ad.20.1777977662215; Tue, 05 May 2026 03:41:02 -0700 (PDT) Received: from wenstp920.tpe.corp.google.com ([2a00:79e0:201d:8:f1d4:2ef0:7d08:9dd8]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b9cae3b8e6sm126670035ad.65.2026.05.05.03.41.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2026 03:41:01 -0700 (PDT) From: Chen-Yu Tsai To: Sean Wang , Matthias Brugger , AngeloGioacchino Del Regno , Linus Walleij Cc: Chen-Yu Tsai , linux-mediatek@lists.infradead.org, linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] pinctrl: mediatek: common-v1: bypass pinctrl GPIO layer in set GPIO direction Date: Tue, 5 May 2026 18:40:55 +0800 Message-ID: <20260505104056.1812343-1-wenst@chromium.org> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" pinctrl_gpio_direction_input() / pinctrl_gpio_direction_output() take the pinctrl mutex. This causes a gpiochip operations to need to sleep. Worse yet, the .can_sleep field in the gpiochip is not set. This causes the shared GPIO proxy to trip over, as it uses gpiod_cansleep() to check whether it can use a spinlock or needs a mutex. In this case, it ends up taking a spinlock, then calls pinctrl_gpio_direction_output(), which takes a mutex. This causes a huge warning. Since the Mediatek hardware has separate clear/set registers, there is no risk of clobbering other bits like with a read-modify-write pattern. Also, once the GPIO function is selected / muxed in, further GPIO operations do not involve pinctrl operations or state. The GPIO direction and level values do not require toggling the pinmux or any other pin config options. Switch to directly calling mtk_pmx_gpio_set_direction() in the GPIO set direction callbacks to avoid taking the pinctrl mutex. Drop the .gpio_set_direction field in mtk_pmx_ops to signal we are no longer using the pinctrl GPIO layer for setting the direction. Signed-off-by: Chen-Yu Tsai --- Only compile tested. Accidentally fixed the wrong file when my target actually used pinctrl-paris.c This was pinctrl: mediatek: common-v1: Directly modify registers to set GPIO dir= ection Changes since v1: - Dropped .gpio_set_direction field in mtk_pmx_ops - Fixed direction in mtk_gpio_direction_output() - Updated commit subject and message - Link to v1: https://lore.kernel.org/all/20260427061720.2393355-1-wenst@chromium.org/ --- drivers/pinctrl/mediatek/pinctrl-mtk-common.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c b/drivers/pinctr= l/mediatek/pinctrl-mtk-common.c index 3f518dce6d23..dd2c8aa03938 100644 --- a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c +++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c @@ -802,20 +802,27 @@ static const struct pinmux_ops mtk_pmx_ops =3D { .get_function_name =3D mtk_pmx_get_func_name, .get_function_groups =3D mtk_pmx_get_func_groups, .set_mux =3D mtk_pmx_set_mux, - .gpio_set_direction =3D mtk_pmx_gpio_set_direction, .gpio_request_enable =3D mtk_pmx_gpio_request_enable, }; =20 +static int mtk_gpio_direction_input(struct gpio_chip *chip, unsigned offse= t) +{ + struct mtk_pinctrl *pctl =3D gpiochip_get_data(chip); + + return mtk_pmx_gpio_set_direction(pctl->pctl_dev, NULL, offset, true); +} + static int mtk_gpio_direction_output(struct gpio_chip *chip, unsigned offset, int value) { + struct mtk_pinctrl *pctl =3D gpiochip_get_data(chip); int ret; =20 ret =3D mtk_gpio_set(chip, offset, value); if (ret) return ret; =20 - return pinctrl_gpio_direction_output(chip, offset); + return mtk_pmx_gpio_set_direction(pctl->pctl_dev, NULL, offset, false); } =20 static int mtk_gpio_get_direction(struct gpio_chip *chip, unsigned offset) @@ -895,7 +902,7 @@ static const struct gpio_chip mtk_gpio_chip =3D { .request =3D gpiochip_generic_request, .free =3D gpiochip_generic_free, .get_direction =3D mtk_gpio_get_direction, - .direction_input =3D pinctrl_gpio_direction_input, + .direction_input =3D mtk_gpio_direction_input, .direction_output =3D mtk_gpio_direction_output, .get =3D mtk_gpio_get, .set =3D mtk_gpio_set, --=20 2.54.0.545.g6539524ca2-goog