From nobody Fri Oct 3 01:09:32 2025 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (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 6E9EC2D876C for ; Tue, 9 Sep 2025 09:15:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757409352; cv=none; b=kw85WMYmtGYec3PMbrVHekqQau1M8g2JhZ9q8J3sPLYIPnqHOhKugvG8TB23D45DZpNjwqQjx/iqwE9dxH92maMdGeQVLxVZEL90wPKDqPYA5fsj34lJkV7QcRYJrF81l+2wS7qz4kZYbVMXFTNk0JY5VOzYzHfP8IBOkaQsKdA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757409352; c=relaxed/simple; bh=STVkcjbGQD0bnhkXi0awJ4N/O75AAoIkAEKNoy3xklM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aljxfXzx3SqRthrFKY7sEEqrMpC+lu4gSRwaBsEu829APAdbmUi/MtzjPjICrOiUVmJiks8DD6JE7wubt5GppBVIUBTOsl++ekdemhOKvmRVY2SYoHqgdVNKQqEsM302LEL2/wAYZxibIIrMqILtsTt7PjBHeXBusbdsyzCq33U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=G6aAFNBh; arc=none smtp.client-ip=209.85.221.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="G6aAFNBh" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-3df2f4aedc7so3053378f8f.2 for ; Tue, 09 Sep 2025 02:15:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1757409348; x=1758014148; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=MIZTqFFdI7c5GSdgApLwsnSgJwJyJjuHVWKySxCM3/s=; b=G6aAFNBhBZ/5OnaxmMXKOThXOuj3RmcdhVd3W8WPQROB7FZxd1Jdkf6nNA0SjJekfX tbgdp8W/wjlNAMMSDQGa2YCObRGezU5oxX5PuivtYLH5NUHyhhLFZ1oxVemSQQC/9APG Bqe/aBLGZW839+/bkmYjculhDrPJEkQC1mwxHMCuERdzncR4puVT5k/hZon4My+sIerR 9vf/UhtG4gdsIgkM3AJOmR8n5++4xFIviEy5eQPtAiC2+bTJLPOL1OGcGxWVlGeymOdK iC5sZDJddFtcbL1hNJIs7SsEurzCrCetMo09oGyrmaFot8vJ5WZ/+bHsdgjnnrRWuHgP qRZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757409348; x=1758014148; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MIZTqFFdI7c5GSdgApLwsnSgJwJyJjuHVWKySxCM3/s=; b=GcvcXOjMTDMYU0DAHzu4/DflMYIArL7CO5eCWh8saK820SH2FACH5a/NjtP7abXhWo xWE7p+oBnhF0Kd/sWDqbvG6toHCVf0+pfMhCsFWLJtt5WQUOw2joR7oWVsYxiVrLKWSC 6+MCLnsVlLYzX8j/j/jgjTKREvfWarPDitMqMv23u7pfn4ei91GwXmEYBrE+GPRuf/M/ VB274W4v36pi/nDhtpw0CHoYA6d3QbJ4JMPUOr8aRnTNWrNStOFEH8gDsb+paIXiMhOJ QvVVcCMRC1Q1DnZKt9DP1tlfElC1epETx2YYo/r8fwxVOV9wedhBJqtLz7gzeEzqeNVb Puiw== X-Forwarded-Encrypted: i=1; AJvYcCXQI+5KLwz6wmmGLxPpCirZtft/dBKUrSCjUHZwWcGrTkQxK0KD7vc7nd+w8v8EfoW8dbODhP5+1/Wt0sI=@vger.kernel.org X-Gm-Message-State: AOJu0YzfodxAVwclk+Cw8wp84t0lM85KajR2hKXdv8havr+R0Qn0Lx6L zBF1CEVMtYpWxVAMZrZild9YceIs+iNlHgJmzhlj8z11ld6MN8clRkKAwRgbdQOJET0= X-Gm-Gg: ASbGncvS4OJiFfu25FtzjtmxtAfVnsEU6WiSrXsPzk3PP1yWKcIJMZckV+ArBle8RNz ojOsgE9xl3Obz+BBTTgliu3OWelBI6FaRZ5Rn1WzPzBMHgTA3GVnLHfcFl5NKxZnDonc4fn7bPz zbXDzd2/bfHh/LP/bTbTGXl60MLhqHaEamdR9g9gWp793rqYDl563WTjM9dpobM/yRxhz3KLQ24 EmUbnOQ231u0EgJF/7IIF+PFQYN0UGzTKccD0ZpaZfX1+b3oVwK4Dr9fmt6XCq7IpMCwe+Ofbiw aiEUbla9LFIuihuOeilg8Ut+yb35PWSXb/nPencuSFj12opjUthetou1UmaV7SIZDLWwmlLdckS 4vwfhPZsEmKqvNNBnHg== X-Google-Smtp-Source: AGHT+IEebt0pWOlSircy048VueTsw1+cXr5WEVoP9l1+AiT3ryRkfTg5u9QKZqm+iQAcvnX+nKkItg== X-Received: by 2002:a05:6000:22c2:b0:3c7:308e:4dff with SMTP id ffacd0b85a97d-3e643c1b67emr7845415f8f.57.1757409347611; Tue, 09 Sep 2025 02:15:47 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:c1ee:7be9:3ebb:6cc0]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3e7521c9caasm1900039f8f.19.2025.09.09.02.15.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Sep 2025 02:15:46 -0700 (PDT) From: Bartosz Golaszewski Date: Tue, 09 Sep 2025 11:15:30 +0200 Subject: [PATCH 03/15] gpio: hlwd: use new generic GPIO chip API Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250909-gpio-mmio-gpio-conv-part4-v1-3-9f723dc3524a@linaro.org> References: <20250909-gpio-mmio-gpio-conv-part4-v1-0-9f723dc3524a@linaro.org> In-Reply-To: <20250909-gpio-mmio-gpio-conv-part4-v1-0-9f723dc3524a@linaro.org> To: Linus Walleij , Bartosz Golaszewski , Keguang Zhang , Alban Bedel , Doug Berger , Florian Fainelli , Broadcom internal kernel review list , Matthias Brugger , AngeloGioacchino Del Regno , Paul Walmsley , Samuel Holland , Yixun Lan , Andy Shevchenko Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-riscv@lists.infradead.org, spacemit@lists.linux.dev, Bartosz Golaszewski X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=8081; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=iTmYTpIN0EhHVtpfw10p3x+EmvoqbGnXwIDBsyAwgI8=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBov/A2XiwccfT2vsbmpFgNl+2ytz7arhOWgEJQo yZ2y+hedzaJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaL/wNgAKCRARpy6gFHHX ctMBEADWw+EV0P2U4YY57HCZxBhGQI8Jymslio2V/cvuO7G36gSw4j9IooHJ1Lc/vZ66kpeHZq+ pv2Ei149dPUSiYnWM6RIDDlaQJfih8gGzscjFniHf9M71UP/5vESKeRd+JhBlB3Jc8uyHlbvFQl IsmTm5rbCEaBM5linFdBWjOsG+hyCRyP/iuwVSY1VBqLKGzFoWMgp770F9spm54j2mO+zZe/1yG hcitMkrtFA7XeupJ/p596xXbKa/hJHNebFnEEjnlTVc2MbDpvVVahnX8u7LSjkrEQU36bpgUSCX njBVdcuJuy0rCoyqo80IIwDG86/Gt6JgoCf+qQaVrlXGfYFIznFPxU+9+1RYZSJ+zmaGaWaht1L SbTDoRM2tGNx+6rBPsoP2YVQYE6R8yoFg9uwit4N6/KvVqlb/9Acz7jvKAJKtZ/mNVogv3ShZO9 zOwWuxR4zqF/2XzqTITWS1a1dwsO492OSJGaClj5MdNoSXRWXwQoIhVdMv9wbwxFTOaM7gSad0o H4kV94dTKnLPgRv2ClfdScpzlc6NEy6GOsfbDN8queDSIIr7zE02+z30G7CAGRcO9gqEu935HlC htTpMhq504bjQ/p/Di904UnZkQO0Fb4V4FaSN65J5EvaXIa0w3rYMlcImbKbK3DnwyXM2KkUnGY TH/8sEVjgkhInSA== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski Convert the driver to using the new generic GPIO chip interfaces from linux/gpio/generic.h. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-hlwd.c | 105 ++++++++++++++++++++++++-------------------= ---- 1 file changed, 54 insertions(+), 51 deletions(-) diff --git a/drivers/gpio/gpio-hlwd.c b/drivers/gpio/gpio-hlwd.c index 0580f6712bea9a4d510bd332645982adbc5c6a32..137f17c9ff221d524a4281fdbf9= 1d8f27ee24182 100644 --- a/drivers/gpio/gpio-hlwd.c +++ b/drivers/gpio/gpio-hlwd.c @@ -6,6 +6,7 @@ // Nintendo Wii (Hollywood) GPIO driver =20 #include +#include #include #include #include @@ -48,7 +49,7 @@ #define HW_GPIO_OWNER 0x3c =20 struct hlwd_gpio { - struct gpio_chip gpioc; + struct gpio_generic_chip gpioc; struct device *dev; void __iomem *regs; int irq; @@ -61,45 +62,44 @@ static void hlwd_gpio_irqhandler(struct irq_desc *desc) struct hlwd_gpio *hlwd =3D gpiochip_get_data(irq_desc_get_handler_data(desc)); struct irq_chip *chip =3D irq_desc_get_chip(desc); - unsigned long flags; unsigned long pending; int hwirq; u32 emulated_pending; =20 - raw_spin_lock_irqsave(&hlwd->gpioc.bgpio_lock, flags); - pending =3D ioread32be(hlwd->regs + HW_GPIOB_INTFLAG); - pending &=3D ioread32be(hlwd->regs + HW_GPIOB_INTMASK); + scoped_guard(gpio_generic_lock_irqsave, &hlwd->gpioc) { + pending =3D ioread32be(hlwd->regs + HW_GPIOB_INTFLAG); + pending &=3D ioread32be(hlwd->regs + HW_GPIOB_INTMASK); =20 - /* Treat interrupts due to edge trigger emulation separately */ - emulated_pending =3D hlwd->edge_emulation & pending; - pending &=3D ~emulated_pending; - if (emulated_pending) { - u32 level, rising, falling; + /* Treat interrupts due to edge trigger emulation separately */ + emulated_pending =3D hlwd->edge_emulation & pending; + pending &=3D ~emulated_pending; + if (emulated_pending) { + u32 level, rising, falling; =20 - level =3D ioread32be(hlwd->regs + HW_GPIOB_INTLVL); - rising =3D level & emulated_pending; - falling =3D ~level & emulated_pending; + level =3D ioread32be(hlwd->regs + HW_GPIOB_INTLVL); + rising =3D level & emulated_pending; + falling =3D ~level & emulated_pending; =20 - /* Invert the levels */ - iowrite32be(level ^ emulated_pending, - hlwd->regs + HW_GPIOB_INTLVL); + /* Invert the levels */ + iowrite32be(level ^ emulated_pending, + hlwd->regs + HW_GPIOB_INTLVL); =20 - /* Ack all emulated-edge interrupts */ - iowrite32be(emulated_pending, hlwd->regs + HW_GPIOB_INTFLAG); + /* Ack all emulated-edge interrupts */ + iowrite32be(emulated_pending, hlwd->regs + HW_GPIOB_INTFLAG); =20 - /* Signal interrupts only on the correct edge */ - rising &=3D hlwd->rising_edge; - falling &=3D hlwd->falling_edge; + /* Signal interrupts only on the correct edge */ + rising &=3D hlwd->rising_edge; + falling &=3D hlwd->falling_edge; =20 - /* Mark emulated interrupts as pending */ - pending |=3D rising | falling; + /* Mark emulated interrupts as pending */ + pending |=3D rising | falling; + } } - raw_spin_unlock_irqrestore(&hlwd->gpioc.bgpio_lock, flags); =20 chained_irq_enter(chip, desc); =20 for_each_set_bit(hwirq, &pending, 32) - generic_handle_domain_irq(hlwd->gpioc.irq.domain, hwirq); + generic_handle_domain_irq(hlwd->gpioc.gc.irq.domain, hwirq); =20 chained_irq_exit(chip, desc); } @@ -116,30 +116,29 @@ static void hlwd_gpio_irq_mask(struct irq_data *data) { struct hlwd_gpio *hlwd =3D gpiochip_get_data(irq_data_get_irq_chip_data(data)); - unsigned long flags; u32 mask; =20 - raw_spin_lock_irqsave(&hlwd->gpioc.bgpio_lock, flags); - mask =3D ioread32be(hlwd->regs + HW_GPIOB_INTMASK); - mask &=3D ~BIT(data->hwirq); - iowrite32be(mask, hlwd->regs + HW_GPIOB_INTMASK); - raw_spin_unlock_irqrestore(&hlwd->gpioc.bgpio_lock, flags); - gpiochip_disable_irq(&hlwd->gpioc, irqd_to_hwirq(data)); + scoped_guard(gpio_generic_lock_irqsave, &hlwd->gpioc) { + mask =3D ioread32be(hlwd->regs + HW_GPIOB_INTMASK); + mask &=3D ~BIT(data->hwirq); + iowrite32be(mask, hlwd->regs + HW_GPIOB_INTMASK); + } + gpiochip_disable_irq(&hlwd->gpioc.gc, irqd_to_hwirq(data)); } =20 static void hlwd_gpio_irq_unmask(struct irq_data *data) { struct hlwd_gpio *hlwd =3D gpiochip_get_data(irq_data_get_irq_chip_data(data)); - unsigned long flags; u32 mask; =20 - gpiochip_enable_irq(&hlwd->gpioc, irqd_to_hwirq(data)); - raw_spin_lock_irqsave(&hlwd->gpioc.bgpio_lock, flags); + gpiochip_enable_irq(&hlwd->gpioc.gc, irqd_to_hwirq(data)); + + guard(gpio_generic_lock_irqsave)(&hlwd->gpioc); + mask =3D ioread32be(hlwd->regs + HW_GPIOB_INTMASK); mask |=3D BIT(data->hwirq); iowrite32be(mask, hlwd->regs + HW_GPIOB_INTMASK); - raw_spin_unlock_irqrestore(&hlwd->gpioc.bgpio_lock, flags); } =20 static void hlwd_gpio_irq_enable(struct irq_data *data) @@ -173,10 +172,9 @@ static int hlwd_gpio_irq_set_type(struct irq_data *dat= a, unsigned int flow_type) { struct hlwd_gpio *hlwd =3D gpiochip_get_data(irq_data_get_irq_chip_data(data)); - unsigned long flags; u32 level; =20 - raw_spin_lock_irqsave(&hlwd->gpioc.bgpio_lock, flags); + guard(gpio_generic_lock_irqsave)(&hlwd->gpioc); =20 hlwd->edge_emulation &=3D ~BIT(data->hwirq); =20 @@ -197,11 +195,9 @@ static int hlwd_gpio_irq_set_type(struct irq_data *dat= a, unsigned int flow_type) hlwd_gpio_irq_setup_emulation(hlwd, data->hwirq, flow_type); break; default: - raw_spin_unlock_irqrestore(&hlwd->gpioc.bgpio_lock, flags); return -EINVAL; } =20 - raw_spin_unlock_irqrestore(&hlwd->gpioc.bgpio_lock, flags); return 0; } =20 @@ -225,6 +221,7 @@ static const struct irq_chip hlwd_gpio_irq_chip =3D { =20 static int hlwd_gpio_probe(struct platform_device *pdev) { + struct gpio_generic_chip_config config; struct hlwd_gpio *hlwd; u32 ngpios; int res; @@ -244,25 +241,31 @@ static int hlwd_gpio_probe(struct platform_device *pd= ev) * systems where the AHBPROT memory firewall hasn't been configured to * permit PPC access to HW_GPIO_*. * - * Note that this has to happen before bgpio_init reads the - * HW_GPIOB_OUT and HW_GPIOB_DIR, because otherwise it reads the wrong - * values. + * Note that this has to happen before gpio_generic_chip_init() reads + * the HW_GPIOB_OUT and HW_GPIOB_DIR, because otherwise it reads the + * wrong values. */ iowrite32be(0xffffffff, hlwd->regs + HW_GPIO_OWNER); =20 - res =3D bgpio_init(&hlwd->gpioc, &pdev->dev, 4, - hlwd->regs + HW_GPIOB_IN, hlwd->regs + HW_GPIOB_OUT, - NULL, hlwd->regs + HW_GPIOB_DIR, NULL, - BGPIOF_BIG_ENDIAN_BYTE_ORDER); + config =3D (typeof(config)){ + .dev =3D &pdev->dev, + .sz =3D 4, + .dat =3D hlwd->regs + HW_GPIOB_IN, + .set =3D hlwd->regs + HW_GPIOB_OUT, + .dirout =3D hlwd->regs + HW_GPIOB_DIR, + .flags =3D BGPIOF_BIG_ENDIAN_BYTE_ORDER, + }; + + res =3D gpio_generic_chip_init(&hlwd->gpioc, &config); if (res < 0) { - dev_warn(&pdev->dev, "bgpio_init failed: %d\n", res); + dev_warn(&pdev->dev, "failed to initialize generic GPIO chip: %d\n", res= ); return res; } =20 res =3D of_property_read_u32(pdev->dev.of_node, "ngpios", &ngpios); if (res) ngpios =3D 32; - hlwd->gpioc.ngpio =3D ngpios; + hlwd->gpioc.gc.ngpio =3D ngpios; =20 /* Mask and ack all interrupts */ iowrite32be(0, hlwd->regs + HW_GPIOB_INTMASK); @@ -282,7 +285,7 @@ static int hlwd_gpio_probe(struct platform_device *pdev) return hlwd->irq; } =20 - girq =3D &hlwd->gpioc.irq; + girq =3D &hlwd->gpioc.gc.irq; gpio_irq_chip_set_chip(girq, &hlwd_gpio_irq_chip); girq->parent_handler =3D hlwd_gpio_irqhandler; girq->num_parents =3D 1; @@ -296,7 +299,7 @@ static int hlwd_gpio_probe(struct platform_device *pdev) girq->handler =3D handle_level_irq; } =20 - return devm_gpiochip_add_data(&pdev->dev, &hlwd->gpioc, hlwd); + return devm_gpiochip_add_data(&pdev->dev, &hlwd->gpioc.gc, hlwd); } =20 static const struct of_device_id hlwd_gpio_match[] =3D { --=20 2.48.1