From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.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 4E6232DF138 for ; Tue, 2 Jun 2026 05:02:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780376524; cv=none; b=c+hm+6VwUwREpLEwMQWg5WQg+gtydc32aof2+fQb/stJsmtY4xJwvb6iwu3LrfzcNBqwA1Tb6EQuq8qabUGFF7eFpVQkxMFFHxuQCmuxADlFAtv3PTE6b/y3YKT6IxjiI+lFG0Nb+OYf4W0HS7pvFKMqkldJvTIPtgde2IIWQ5M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780376524; c=relaxed/simple; bh=YvQLjBWJRjLxKpMXlc55gK1BvM98fsTCqmx+fq/wk7U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XZ7w9lIh9vJhgLmfljvA0TEL5TYXDWiQAF2FDquTdMSplelTqEZM+9whod/KaiwJrmOKLkVLEPHSUx/9rSLw3NfR89zoZB6Jzlrq0bB3SNmdfZO2Xrz78LGH0voXPwDfeajXp8u8bT74TS4lyRwrCKS7FwwhhrQ55+XWbdKPfNM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=cQ9xQXz4; arc=none smtp.client-ip=209.85.216.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cQ9xQXz4" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-36ba3ea5c46so2432127a91.1 for ; Mon, 01 Jun 2026 22:02:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780376522; x=1780981322; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=p3KbSzoRI/icX/VWbVUw16WYqo0/swLg71aVPGe0bc4=; b=cQ9xQXz4fsmKfPrQwcnPY5ceEz1IfoRepnqIwQbhoMCPg0B2kEZY7aq947ryErH/im Dmw+l4nv0rmSksv8qFrVgJloBPD2jU2yIhwN49oIi2MiAYlr+67bFRN7JsrZfmRJYiUL hxTl4N0kyE0hagXbtn+cHiA8E2vMWlaS8R6jU16nx2iqCnt62eT19JZ3J0PfJZuxOMU3 ApigeYtiVdHREJkc8iR+CLzEUpv/SmLT5P7duYM1RGSB3wA9DDdDlB6p1htBD6hc5iIh r1PZkAfM+fJC7ks/Aq5x+rqvD1Vvtv1bDTppfXJtMDBYxnY15l8LFpKOwxsEq0w+DbRw i5ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780376522; x=1780981322; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=p3KbSzoRI/icX/VWbVUw16WYqo0/swLg71aVPGe0bc4=; b=Bl6t63bYANYeBIyqsLv+1J092+l23hxjxTEL0wJ0RisqVMZK6wjJTPQJV86HUI2sCi EN5gdzhXOiq4eGj0U9jgz37uLvd7Dk/BgLtnAcf1hBtckmRCHGt/aagTg9CSyjXU6Wvw cMSCBPr/CPZTS7wYwt4YCfOCmj0mQ3Va3JCnf+rmRB8oYwGf+CVKIwQRpDszO6p6YOfP rewR/dUw9T0VY9HuAMnYxYguTEce2MOFFxSeFe/CcvomzviHlKtrSFU86u7XEHX2tmyM 5B2DRrOYcq5/4FjtZSqG1/ouvW/jU+ld2Cpu1NQJJ6Oq3uCoPiDX3o+qDEE1QUVcCS3g DYNw== X-Forwarded-Encrypted: i=1; AFNElJ8TrdsaQTEhRpCddlOpNMU9pBonoqi/MLmO4/JaXruEiLqzTVLdfKD3nXZXcjo3OedpjT3Gb+6TAd+ScUU=@vger.kernel.org X-Gm-Message-State: AOJu0Yyh3xy3mt8KWrxv2z53ymGx6eXIDTglRqPoniDKCG4POiRDMXus G6YGYgtlM29+NQSwuBXV/pYivhXj82hfgHQrRMqWUHRSX3jG0EBCLp0FIdGHyhFZ X-Gm-Gg: Acq92OH1F/T8fVWYMu3c33q4hZCUZGtI0kV86ENfOiHJz0NJr7CYQvOVP3bqjQNpGm9 RJWd604BRlz/GN+C9nd1lJHXLBa2Q5kFCCsdXzzlo2qyU038gL6j6mkTjXZqP892tU8xQROAFwZ 6MnyNJ5mjAWM0N9+TZOMGDp2G775mTCDHStHl42l+HgPr2cgFDvPYdJcDC+g2uX+pVsjkbzq+5j mfRvPCOHUvKO0L2j0+AiP5mX2Hqw7nWI/A1dZHYUN751P/HP4Id8JSnoMLCi2Ge9x9dyWENZSqw ChBXLB6HYJfdoOW4mxhDCH4YSkAnZWCt9zE29Zaqy8Y2exeaYf1V9AqX91sDoKvgLJRUXKiJEH1 xaoB7pcr/BFvucZ/XA8r0A9bs4cv3L6FEE1IBp75wWYhvH5QkGXnDVcsrl48lzZLTGdf/viBx9H pY6iSkmwjRoqsGT2e434VcQ/lgYw7LSx/NfO6IO02p6DgmmXeigs5dcfYXnN/HKQtlbRhWk09aS +0jRyiCYfo/yqKNjS98WLeIbrpdu2+c1tFFS6TZahcAYw== X-Received: by 2002:a05:6a20:748d:b0:3a3:a55f:405d with SMTP id adf61e73a8af0-3b427c572e9mr15361175637.13.1780376522535; Mon, 01 Jun 2026 22:02:02 -0700 (PDT) Received: from ryzen ([2601:644:8000:5b5d:7285:c2ff:fe45:8a32]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c8589d055c7sm8958467a12.9.2026.06.01.22.02.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jun 2026 22:02:01 -0700 (PDT) From: Rosen Penev To: linux-gpio@vger.kernel.org Cc: Madhavan Srinivasan , chleroy@kernel.org, Michael Ellerman , Nicholas Piggin , Linus Walleij , Bartosz Golaszewski , linuxppc-dev@lists.ozlabs.org (open list:LINUX FOR POWERPC (32-BIT AND 64-BIT)), linux-kernel@vger.kernel.org (open list) Subject: [PATCH 5/7] gpio: ppc44x: Convert GPIO to generic MMIO Date: Mon, 1 Jun 2026 22:01:29 -0700 Message-ID: <20260602050131.856789-6-rosenp@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260602050131.856789-1-rosenp@gmail.com> References: <20260602050131.856789-1-rosenp@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Use gpio_generic_chip_init() to set up the PPC44x GPIO chip instead of open-coding the basic get, set, locking and state handling. Keep the PPC44x-specific direction callbacks because they still need to program ODR and the OSR/TSR registers around the generic data and direction registers. Assisted-by: Codex:GPT-5.5 Signed-off-by: Rosen Penev --- drivers/gpio/gpio-ppc44x.c | 82 +++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 46 deletions(-) diff --git a/drivers/gpio/gpio-ppc44x.c b/drivers/gpio/gpio-ppc44x.c index b30ca357ab74..6b4814ed12b5 100644 --- a/drivers/gpio/gpio-ppc44x.c +++ b/drivers/gpio/gpio-ppc44x.c @@ -11,10 +11,9 @@ #include #include -#include #include #include -#include +#include #include #include #include @@ -45,9 +44,8 @@ struct ppc4xx_gpio { }; struct ppc4xx_gpio_chip { - struct gpio_chip gc; + struct gpio_generic_chip chip; void __iomem *regs; - spinlock_t lock; }; /* @@ -56,55 +54,35 @@ struct ppc4xx_gpio_chip { * There are a maximum of 32 gpios in each gpio controller. */ -static int ppc4xx_gpio_get(struct gpio_chip *gc, unsigned int gpio) -{ - struct ppc4xx_gpio_chip *chip = gpiochip_get_data(gc); - struct ppc4xx_gpio __iomem *regs = chip->regs; - - return !!(in_be32(®s->ir) & GPIO_MASK(gpio)); -} - static inline void __ppc4xx_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val) { struct ppc4xx_gpio_chip *chip = gpiochip_get_data(gc); - struct ppc4xx_gpio __iomem *regs = chip->regs; + struct gpio_generic_chip *gen_gc = &chip->chip; if (val) - setbits32(®s->or, GPIO_MASK(gpio)); + gen_gc->sdata |= GPIO_MASK(gpio); else - clrbits32(®s->or, GPIO_MASK(gpio)); -} + gen_gc->sdata &= ~GPIO_MASK(gpio); -static int ppc4xx_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val) -{ - struct ppc4xx_gpio_chip *chip = gpiochip_get_data(gc); - unsigned long flags; - - spin_lock_irqsave(&chip->lock, flags); - - __ppc4xx_gpio_set(gc, gpio, val); - - spin_unlock_irqrestore(&chip->lock, flags); - - pr_debug("%s: gpio: %d val: %d\n", __func__, gpio, val); - - return 0; + gpio_generic_write_reg(gen_gc, gen_gc->reg_set, gen_gc->sdata); } static int ppc4xx_gpio_dir_in(struct gpio_chip *gc, unsigned int gpio) { struct ppc4xx_gpio_chip *chip = gpiochip_get_data(gc); + struct gpio_generic_chip *gen_gc = &chip->chip; struct ppc4xx_gpio __iomem *regs = chip->regs; unsigned long flags; - spin_lock_irqsave(&chip->lock, flags); + gpio_generic_chip_lock_irqsave(gen_gc, flags); /* Disable open-drain function */ clrbits32(®s->odr, GPIO_MASK(gpio)); /* Float the pin */ clrbits32(®s->tcr, GPIO_MASK(gpio)); + gen_gc->sdir &= ~GPIO_MASK(gpio); /* Bits 0-15 use TSRL/OSRL, bits 16-31 use TSRH/OSRH */ if (gpio < 16) { @@ -115,7 +93,7 @@ static int ppc4xx_gpio_dir_in(struct gpio_chip *gc, unsigned int gpio) clrbits32(®s->tsrh, GPIO_MASK2(gpio)); } - spin_unlock_irqrestore(&chip->lock, flags); + gpio_generic_chip_unlock_irqrestore(gen_gc, flags); return 0; } @@ -124,10 +102,11 @@ static int ppc4xx_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) { struct ppc4xx_gpio_chip *chip = gpiochip_get_data(gc); + struct gpio_generic_chip *gen_gc = &chip->chip; struct ppc4xx_gpio __iomem *regs = chip->regs; unsigned long flags; - spin_lock_irqsave(&chip->lock, flags); + gpio_generic_chip_lock_irqsave(gen_gc, flags); /* First set initial value */ __ppc4xx_gpio_set(gc, gpio, val); @@ -137,6 +116,7 @@ ppc4xx_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) /* Drive the pin */ setbits32(®s->tcr, GPIO_MASK(gpio)); + gen_gc->sdir |= GPIO_MASK(gpio); /* Bits 0-15 use TSRL, bits 16-31 use TSRH */ if (gpio < 16) { @@ -147,7 +127,7 @@ ppc4xx_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) clrbits32(®s->tsrh, GPIO_MASK2(gpio)); } - spin_unlock_irqrestore(&chip->lock, flags); + gpio_generic_chip_unlock_irqrestore(gen_gc, flags); pr_debug("%s: gpio: %d val: %d\n", __func__, gpio, val); @@ -159,33 +139,43 @@ static int ppc4xx_gpio_probe(struct platform_device *ofdev) struct device *dev = &ofdev->dev; struct device_node *np = dev->of_node; struct ppc4xx_gpio_chip *chip; + struct gpio_generic_chip_config config; struct gpio_chip *gc; + struct ppc4xx_gpio __iomem *regs; + int ret; chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); if (!chip) return -ENOMEM; - spin_lock_init(&chip->lock); - - gc = &chip->gc; + chip->regs = devm_platform_ioremap_resource(ofdev, 0); + if (IS_ERR(chip->regs)) + return PTR_ERR(chip->regs); - gc->parent = dev; + regs = chip->regs; + config = (struct gpio_generic_chip_config) { + .dev = dev, + .sz = 4, + .dat = ®s->ir, + .set = ®s->or, + .dirout = ®s->tcr, + .flags = GPIO_GENERIC_BIG_ENDIAN | + GPIO_GENERIC_BIG_ENDIAN_BYTE_ORDER, + }; + + ret = gpio_generic_chip_init(&chip->chip, &config); + if (ret) + return ret; + + gc = &chip->chip.gc; gc->fwnode = dev_fwnode(dev); - gc->base = -1; - gc->ngpio = 32; gc->direction_input = ppc4xx_gpio_dir_in; gc->direction_output = ppc4xx_gpio_dir_out; - gc->get = ppc4xx_gpio_get; - gc->set = ppc4xx_gpio_set; gc->label = devm_kasprintf(dev, GFP_KERNEL, "%pOF", np); if (!gc->label) return -ENOMEM; - chip->regs = devm_platform_ioremap_resource(ofdev, 0); - if (IS_ERR(chip->regs)) - return PTR_ERR(chip->regs); - return devm_gpiochip_add_data(dev, gc, chip); } -- 2.54.0