From patchwork Mon Aug 6 15:12:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 953943 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="svGms5Th"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="iBw/Iapy"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41kh3K1crmz9s3q for ; Tue, 7 Aug 2018 01:12:45 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=VPhx9uu4dkK4JDbp3BdofASNPIBi0no69D8UFGd6rpw=; b=svG ms5ThnKMW5WIkaEK665pnUfs0Xd6blEwVHuCXmx+DZaNkFX4quo6CLDhfY1UUUyKgl05kWIr8m6u/ Wjtn60eEl/rd2j93Ac5IcLpfllTOAfgkydMyAM+wpkAToNk3ZA3s8rVGaNO5MgnNoWmnrulQLRMmR KrTXBqnH9uoTTWBAkQ2RgT+xKsyONtIegMzOHYiV1jJQhLhlMPeMQOrlyEBd6tso5BeDUZR3hyjDP rkq2tLL+6/h3hGcRSuK064O49Y1Fxa7Gw3HBEbOWhVhVb9xU0b6eEm0tEGj3aTzqLVMxtao159LEK nIKCem3Ot7Vda43uRN+/40H/aPZAjDg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fmhBb-00046e-3o; Mon, 06 Aug 2018 15:12:43 +0000 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fmhBX-00044k-RC for linux-snps-arc@lists.infradead.org; Mon, 06 Aug 2018 15:12:42 +0000 Received: by mail-wm0-x242.google.com with SMTP id s9-v6so14203335wmh.3 for ; Mon, 06 Aug 2018 08:12:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=VtBk3vD++1QBFK6ZO9rw9D2wIYwiVNGsrz1B8jRW3AY=; b=iBw/IapyVAEFYjdBsNbgj55tb2Zi8V5MX7Hx3bz2z0R/FpRS8qaVnhCjEn3bAzHQnv vpHb+fstFA3dN7fhf9YfmXW+kncSAEIYYr5eTaGPYgoSuIfQ8Fikv51Jr85ftLg2lPkP e44C+bLV6e/ROhW8M7cvmVjEuoaYR6/Zr8ldU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=VtBk3vD++1QBFK6ZO9rw9D2wIYwiVNGsrz1B8jRW3AY=; b=dSrijpF/bqRvqzlNK7XIEDND6iQrN+TlG+bEPBU0U77IyS8QSrepoqu+FK9JvLMspU PIbrvfbKdsXG2B6U6bfF4erY6ZZ7HVLf847VKc+9bvVcOpFU9StzdPqkOpqdHuMuWVwD oACdCAdJAc/g86iRQnXHEe/9CtSKmJBO9GJla6lJvz38nDa/pzrmidk/1zK1DnNZOzJe jlxAzol1XxYCh2BeBaXVebrNQ2dckP7omvoPVFrscG/WlUQIaEDpz3z8yC4eVJpaE3a5 uCSycEFa74QnuHJmxZY6wT3bY9dfBonuCDTwnlw7fHoXh+Le0MlvRiOaY/Rpiid6XvqL XqXw== X-Gm-Message-State: AOUpUlFM/OXNFpo5XyklwodghfWB8nO6TbdVC7ZKvLQtxPTFritjca9C vCQ4ftZTFiiNh0+7OjK6nKrCOw== X-Google-Smtp-Source: AAOMgpcI1Wtg8i++MttgUXAGyucxi5+BZpWEU678Ma9fChm0Y4sZAinqXx8RK+lSrRQjDLW5IyLJmA== X-Received: by 2002:a1c:dc41:: with SMTP id t62-v6mr12313650wmg.42.1533568348191; Mon, 06 Aug 2018 08:12:28 -0700 (PDT) Received: from localhost.localdomain (catv-89-135-96-219.catv.broadband.hu. [89.135.96.219]) by smtp.gmail.com with ESMTPSA id v65-v6sm5608096wme.22.2018.08.06.08.12.26 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 06 Aug 2018 08:12:27 -0700 (PDT) From: Linus Walleij To: linux-gpio@vger.kernel.org Subject: [PATCH 1/2] gpio: tb10x: Create local helper variables Date: Mon, 6 Aug 2018 17:12:24 +0200 Message-Id: <20180806151224.2338-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180806_081239_882916_2230D599 X-CRM114-Status: GOOD ( 12.16 ) X-Spam-Score: -0.1 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-0.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2a00:1450:400c:c09:0:0:0:242 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-snps-arc@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux on Synopsys ARC Processors List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Linus Walleij , linux-snps-arc@lists.infradead.org, Christian Ruppert MIME-Version: 1.0 Sender: "linux-snps-arc" Errors-To: linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Create a local struct device *dev helper variable to make the code easier to read. Most GPIO drivers use "np" (node pointer) rather than "dn" (device node) to point to the device tree node. Let's follow this convention. Cc: linux-snps-arc@lists.infradead.org Cc: Christian Ruppert Signed-off-by: Linus Walleij Acked-by: Christian Ruppert --- drivers/gpio/gpio-tb10x.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/drivers/gpio/gpio-tb10x.c b/drivers/gpio/gpio-tb10x.c index a12cd0b5c972..422b0ac5a9de 100644 --- a/drivers/gpio/gpio-tb10x.c +++ b/drivers/gpio/gpio-tb10x.c @@ -169,29 +169,30 @@ static int tb10x_gpio_probe(struct platform_device *pdev) { struct tb10x_gpio *tb10x_gpio; struct resource *mem; - struct device_node *dn = pdev->dev.of_node; + struct device *dev = &pdev->dev; + struct device_node *np = dev->of_node; int ret = -EBUSY; u32 ngpio; - if (!dn) + if (!np) return -EINVAL; - if (of_property_read_u32(dn, "abilis,ngpio", &ngpio)) + if (of_property_read_u32(np, "abilis,ngpio", &ngpio)) return -EINVAL; - tb10x_gpio = devm_kzalloc(&pdev->dev, sizeof(*tb10x_gpio), GFP_KERNEL); + tb10x_gpio = devm_kzalloc(dev, sizeof(*tb10x_gpio), GFP_KERNEL); if (tb10x_gpio == NULL) return -ENOMEM; spin_lock_init(&tb10x_gpio->spinlock); mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); - tb10x_gpio->base = devm_ioremap_resource(&pdev->dev, mem); + tb10x_gpio->base = devm_ioremap_resource(dev, mem); if (IS_ERR(tb10x_gpio->base)) return PTR_ERR(tb10x_gpio->base); - tb10x_gpio->gc.label = - devm_kasprintf(&pdev->dev, GFP_KERNEL, "%pOF", pdev->dev.of_node); + tb10x_gpio->gc.label = + devm_kasprintf(dev, GFP_KERNEL, "%pOF", pdev->dev.of_node); if (!tb10x_gpio->gc.label) return -ENOMEM; @@ -210,31 +211,31 @@ static int tb10x_gpio_probe(struct platform_device *pdev) ret = devm_gpiochip_add_data(&pdev->dev, &tb10x_gpio->gc, tb10x_gpio); if (ret < 0) { - dev_err(&pdev->dev, "Could not add gpiochip.\n"); + dev_err(dev, "Could not add gpiochip.\n"); return ret; } platform_set_drvdata(pdev, tb10x_gpio); - if (of_find_property(dn, "interrupt-controller", NULL)) { + if (of_find_property(np, "interrupt-controller", NULL)) { struct irq_chip_generic *gc; ret = platform_get_irq(pdev, 0); if (ret < 0) { - dev_err(&pdev->dev, "No interrupt specified.\n"); + dev_err(dev, "No interrupt specified.\n"); return ret; } tb10x_gpio->gc.to_irq = tb10x_gpio_to_irq; tb10x_gpio->irq = ret; - ret = devm_request_irq(&pdev->dev, ret, tb10x_gpio_irq_cascade, + ret = devm_request_irq(dev, ret, tb10x_gpio_irq_cascade, IRQF_TRIGGER_NONE | IRQF_SHARED, - dev_name(&pdev->dev), tb10x_gpio); + dev_name(dev), tb10x_gpio); if (ret != 0) return ret; - tb10x_gpio->domain = irq_domain_add_linear(dn, + tb10x_gpio->domain = irq_domain_add_linear(np, tb10x_gpio->gc.ngpio, &irq_generic_chip_ops, NULL); if (!tb10x_gpio->domain) { From patchwork Mon Aug 6 15:12:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 953944 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="L+f6H38T"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="W45K1QTs"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41kh3V1RbYz9s0n for ; Tue, 7 Aug 2018 01:12:54 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=g1sBDI4R6lpfFa/Gsgg9rSX4vTaiTHXWLNap0hlgUpE=; b=L+f 6H38TD2a1ErAseBKvvU0xJyF9iWLLA7sXbi+P75+dn99tYVqBKYLtOm5Wb1fvdK8buMEAzZEPt410 aHscRzSZx4FjH6m3yqc0+WRJmqeWtFWbiDCrZBPoqHWFF4U4qoRV3mm3RX/+lYsHy35eaUbkxzMMh 2urJrKz8fw2RN6os1WwFv/BsX3PiHRiEGx5qwa/X1HOWu6mhQdjtrgKGGGiy/FbnHu22vs5/DACLq mYu4p+EWOFbLsZGwSUqv2qLK+F0XuAIuWeZFUE+kxtX93w5/m83t0QL7UNQYSAMtBmjHiW1cHosih PwSBWHRjTtSjZ4KcJaNMRICoDYz8GCQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fmhBk-00047l-7w; Mon, 06 Aug 2018 15:12:52 +0000 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fmhBh-000469-6s for linux-snps-arc@lists.infradead.org; Mon, 06 Aug 2018 15:12:50 +0000 Received: by mail-wm0-x241.google.com with SMTP id q8-v6so14792933wmq.4 for ; Mon, 06 Aug 2018 08:12:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=aD+9ZzPxRkmJjjGUKuvGDxd5lZ7g0DRV3RTmROi4C3k=; b=W45K1QTsiBmtFk9XHZQQRFwo7HlkPj+yj56qDeTcZ7jmUcs12FVuX1pG8+ZNEkEbaJ /7McC6aFIsKDaFL8g7ajuT8Q5yofFAdDZLTJf5uc6kGBvuKWB6doY3ahHQFpwM5EDPQI fq325P9L2275Vt6ynw2N6x95uxuYiqhdYU2KE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=aD+9ZzPxRkmJjjGUKuvGDxd5lZ7g0DRV3RTmROi4C3k=; b=oRXXPqnqX1fN6YLcCwQt/PJJ70SGMJ9g/aVIITBucxvfNfwhSly5pawvR0lxD5Mg2U 4nOEztUdC6D/G2/CSbieVXUAtqMwPbZlMoKSt69sYv/C7g4aMkRqzQIvvphsfyozQNzz iOFtRGxz4sjyVziMM+sFt8AKtTJiFcW1JoAosh54r7U5Z94kKIA80npmPOdpcX900cSx M6vppMGF9ztDqhOOAHmRz7KCueNVrFGL6Ne6hIct3P6lI1uO9oGsd9wEBMMjbe06bRQQ wc3vYtRpDARLCF5QHdWjldLa9cIlspSNxxcgnT6mP86fMJGnLQbfzhtOTvVsa83sox0w ILBA== X-Gm-Message-State: AOUpUlHmRZhDr/RdgasYpmGYt2eHlZlqpYn3l3gY1cq954gp9pNCcSyQ ixcvArrYaZ5wwRWVCR6axo9Y5yOsKx4= X-Google-Smtp-Source: AAOMgpfUA25qE4MLMJjo8/m37Z8gPB5kQrhsusKwx+b03LQ9MdvT2uskCBnXOghHy+32LOuP4BpJ/A== X-Received: by 2002:a1c:5e48:: with SMTP id s69-v6mr11604922wmb.19.1533568357507; Mon, 06 Aug 2018 08:12:37 -0700 (PDT) Received: from localhost.localdomain (catv-89-135-96-219.catv.broadband.hu. [89.135.96.219]) by smtp.gmail.com with ESMTPSA id s1-v6sm7958121wrt.82.2018.08.06.08.12.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 06 Aug 2018 08:12:36 -0700 (PDT) From: Linus Walleij To: linux-gpio@vger.kernel.org Subject: [PATCH 2/2] gpio: tb10x: Use GENERIC_GPIO Date: Mon, 6 Aug 2018 17:12:33 +0200 Message-Id: <20180806151233.2408-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180806_081249_248848_10616FD1 X-CRM114-Status: GOOD ( 15.99 ) X-Spam-Score: -0.1 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-0.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2a00:1450:400c:c09:0:0:0:241 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-snps-arc@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux on Synopsys ARC Processors List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Linus Walleij , linux-snps-arc@lists.infradead.org, Christian Ruppert MIME-Version: 1.0 Sender: "linux-snps-arc" Errors-To: linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Instead of open coding logic for reading and writing GPIO lines, use the generic GPIO library. Also switch to using the spinlock from the generic GPIO to protect the registers. Cc: linux-snps-arc@lists.infradead.org Cc: Christian Ruppert Signed-off-by: Linus Walleij Acked-by: Christian Ruppert --- drivers/gpio/Kconfig | 1 + drivers/gpio/gpio-tb10x.c | 96 ++++++++++++--------------------------- 2 files changed, 31 insertions(+), 66 deletions(-) diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 7429b30e61b0..d351548d0257 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -480,6 +480,7 @@ config GPIO_SYSCON config GPIO_TB10X bool + select GPIO_GENERIC select GENERIC_IRQ_CHIP select OF_GPIO diff --git a/drivers/gpio/gpio-tb10x.c b/drivers/gpio/gpio-tb10x.c index 422b0ac5a9de..d5e5d19f4c0a 100644 --- a/drivers/gpio/gpio-tb10x.c +++ b/drivers/gpio/gpio-tb10x.c @@ -45,14 +45,12 @@ /** - * @spinlock: used for atomic read/modify/write of registers * @base: register base address * @domain: IRQ domain of GPIO generated interrupts managed by this controller * @irq: Interrupt line of parent interrupt controller * @gc: gpio_chip structure associated to this GPIO controller */ struct tb10x_gpio { - spinlock_t spinlock; void __iomem *base; struct irq_domain *domain; int irq; @@ -76,60 +74,14 @@ static inline void tb10x_set_bits(struct tb10x_gpio *gpio, unsigned int offs, u32 r; unsigned long flags; - spin_lock_irqsave(&gpio->spinlock, flags); + spin_lock_irqsave(&gpio->gc.bgpio_lock, flags); r = tb10x_reg_read(gpio, offs); r = (r & ~mask) | (val & mask); tb10x_reg_write(gpio, offs, r); - spin_unlock_irqrestore(&gpio->spinlock, flags); -} - -static int tb10x_gpio_direction_in(struct gpio_chip *chip, unsigned offset) -{ - struct tb10x_gpio *tb10x_gpio = gpiochip_get_data(chip); - int mask = BIT(offset); - int val = TB10X_GPIO_DIR_IN << offset; - - tb10x_set_bits(tb10x_gpio, OFFSET_TO_REG_DDR, mask, val); - - return 0; -} - -static int tb10x_gpio_get(struct gpio_chip *chip, unsigned offset) -{ - struct tb10x_gpio *tb10x_gpio = gpiochip_get_data(chip); - int val; - - val = tb10x_reg_read(tb10x_gpio, OFFSET_TO_REG_DATA); - - if (val & BIT(offset)) - return 1; - else - return 0; -} - -static void tb10x_gpio_set(struct gpio_chip *chip, unsigned offset, int value) -{ - struct tb10x_gpio *tb10x_gpio = gpiochip_get_data(chip); - int mask = BIT(offset); - int val = value << offset; - - tb10x_set_bits(tb10x_gpio, OFFSET_TO_REG_DATA, mask, val); -} - -static int tb10x_gpio_direction_out(struct gpio_chip *chip, - unsigned offset, int value) -{ - struct tb10x_gpio *tb10x_gpio = gpiochip_get_data(chip); - int mask = BIT(offset); - int val = TB10X_GPIO_DIR_OUT << offset; - - tb10x_gpio_set(chip, offset, value); - tb10x_set_bits(tb10x_gpio, OFFSET_TO_REG_DDR, mask, val); - - return 0; + spin_unlock_irqrestore(&gpio->gc.bgpio_lock, flags); } static int tb10x_gpio_to_irq(struct gpio_chip *chip, unsigned offset) @@ -184,8 +136,6 @@ static int tb10x_gpio_probe(struct platform_device *pdev) if (tb10x_gpio == NULL) return -ENOMEM; - spin_lock_init(&tb10x_gpio->spinlock); - mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); tb10x_gpio->base = devm_ioremap_resource(dev, mem); if (IS_ERR(tb10x_gpio->base)) @@ -196,20 +146,34 @@ static int tb10x_gpio_probe(struct platform_device *pdev) if (!tb10x_gpio->gc.label) return -ENOMEM; - tb10x_gpio->gc.parent = &pdev->dev; - tb10x_gpio->gc.owner = THIS_MODULE; - tb10x_gpio->gc.direction_input = tb10x_gpio_direction_in; - tb10x_gpio->gc.get = tb10x_gpio_get; - tb10x_gpio->gc.direction_output = tb10x_gpio_direction_out; - tb10x_gpio->gc.set = tb10x_gpio_set; - tb10x_gpio->gc.request = gpiochip_generic_request; - tb10x_gpio->gc.free = gpiochip_generic_free; - tb10x_gpio->gc.base = -1; - tb10x_gpio->gc.ngpio = ngpio; - tb10x_gpio->gc.can_sleep = false; - - - ret = devm_gpiochip_add_data(&pdev->dev, &tb10x_gpio->gc, tb10x_gpio); + /* + * Initialize generic GPIO with one single register for reading and setting + * the lines, no special set or clear registers and a data direction register + * wher 1 means "output". + */ + ret = bgpio_init(&tb10x_gpio->gc, dev, 4, + tb10x_gpio->base + OFFSET_TO_REG_DATA, + NULL, + NULL, + tb10x_gpio->base + OFFSET_TO_REG_DDR, + NULL, + 0); + if (ret) { + dev_err(dev, "unable to init generic GPIO\n"); + return ret; + } + tb10x_gpio->gc.base = -1; + tb10x_gpio->gc.parent = dev; + tb10x_gpio->gc.owner = THIS_MODULE; + /* + * ngpio is set by bgpio_init() but we override it, this .request() + * callback also overrides the one set up by generic GPIO. + */ + tb10x_gpio->gc.ngpio = ngpio; + tb10x_gpio->gc.request = gpiochip_generic_request; + tb10x_gpio->gc.free = gpiochip_generic_free; + + ret = devm_gpiochip_add_data(dev, &tb10x_gpio->gc, tb10x_gpio); if (ret < 0) { dev_err(dev, "Could not add gpiochip.\n"); return ret;