Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4545599imw; Tue, 19 Jul 2022 08:33:35 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v6EwCieCCo3b9EXSohJBqQLyDDHDGhpxPvw14dRkq3Vetl+gTeXvPH8LvDu9A0ZtwBXxYw X-Received: by 2002:a05:6402:16:b0:43a:f435:5d07 with SMTP id d22-20020a056402001600b0043af4355d07mr45696640edu.420.1658244815254; Tue, 19 Jul 2022 08:33:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658244815; cv=none; d=google.com; s=arc-20160816; b=xj2ElaXWtchvf6SwU4GrS62Hrc/6X5Wq5g6pBj67qd+Fs00I1ipZGXJpEI2R/CwdCH EIsrpybrzfky2F1RqKxb63zmtWLwm0wpS0aIjpHDqMospu6WqevV2aHwwZo4XFynPzcx s2C00vdHxEoilmRWi2Qs3yVYolONHPyaWNhP2EP0E7GuB5XIurOJMn4wPWgovQbUrOvZ iBDcSiKsiJYD/wFKbhI3Zl2S3ueCrTguk5sE/8ZvC4kIgUBRvWeUUm4GA3iGZOrpeQZv Q/sbg11aN+Q/mPF08JAmVK9zbKq4XcPAUJF6iKANh7Xx/uY7BDe2m9Wb6a6kT9L4xLom Npjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vlq7M6D1RgY2JkdmVKHZ7KjiNHRg1IRrY27s7K5hCY8=; b=Gr2HYQxuURmpBDoyDysUntbzGwmk6V4shFlY9V2TPzjApO4W9FC3zPDGP55+WZBHLs AxIz0fAXnimKGJySaLNyNFVS/R4rKnYl4ApJallMBNFRUiD9FhWGDnyeOWrY9F24aOCx hVLvedJEcykTXjoJ/RnVKvYIsgr5cTp2iHe1SApsij51OvjqoTME+E/YKSefQqW9Dg/p Topwld20pM4Kvg7/ugBBDwdrkioqYGzGMBwNWFWsiVhtc8UjtqWtMTh7yhs9s2Y2JYKj suEGBR955Lrf2H2eiFI8IHE9E4mMFHoFbL6TvdTvAPUaJoShssgPnfvipxN3Wt8sRDHm KeuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CffoA8s3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r15-20020a170906350f00b00726ab6cedddsi15845829eja.220.2022.07.19.08.33.09; Tue, 19 Jul 2022 08:33:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CffoA8s3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238621AbiGSPOl (ORCPT + 99 others); Tue, 19 Jul 2022 11:14:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238576AbiGSPOh (ORCPT ); Tue, 19 Jul 2022 11:14:37 -0400 Received: from mail-oi1-x235.google.com (mail-oi1-x235.google.com [IPv6:2607:f8b0:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 626C2545D4 for ; Tue, 19 Jul 2022 08:14:36 -0700 (PDT) Received: by mail-oi1-x235.google.com with SMTP id p132so7122863oif.9 for ; Tue, 19 Jul 2022 08:14:36 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=vlq7M6D1RgY2JkdmVKHZ7KjiNHRg1IRrY27s7K5hCY8=; b=CffoA8s3mtwv3QVe1eA44irMAvAyxVbNVLv6KEZ2Nswtj2AFsBxi7J/4kuj0t0/8Bt fI+hhFrNDc0A56e+b5zU75C++aWQLe7z3YNOksLI5r8VcZKF7Cc8v4qlCLUAUEziXDf5 5jSY7i91Ai3ZxMZtrSNpzgSPDYRq8MAj1CrGbCQJivBt+e/UrJxOx0wUzh3eY3aclLo3 9sNgtJtzKEq91qOm3HpOiYA9H3ixIs64y/WSn4hvPcrUEi4dGOwuNiVzey2LZAt+5ySH H7vAdqc+qGHX81XJWoZj+CxrHENAWyNjQEQLeBCsxqTtdCYowWgTvlYo9GBku31UfgZU tt3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vlq7M6D1RgY2JkdmVKHZ7KjiNHRg1IRrY27s7K5hCY8=; b=FQdtwtrbw9eWnQe0Bi4EAIs6R5GLlif/nLGlsJEDMpn+W8TWYG12K7BVOQH044CDFO 3/6uduCRjV1+XIh5UFWvidodzDApH+Z0QUGKZ/cwL5WSlBYn3riT39TkyPKBLRwfacI+ Gpa6lZlSoWZS0gbI/HWhWMNhjFH05Q3s4eFCOoGg9lRBKe8SQEThs6ZuJk++b819mpNo bteeFWeRMgcjDrngHP7nptVOeLUHivUd0q5owBxv2l9snnrTrlQ6Gq9k+cYBwr2wLZoO emMJlszJ53Nra8TBicdtZRQS+EgaDCeRd/u9SecTxBpjodQFam1FES5EjBuwNlc2Q7Bp EqOQ== X-Gm-Message-State: AJIora/2VA4DXkZC2/1hsJ8yGMl/wEdqbT9Rnl1/4j8adP/FmFH7IGTt 18Dfo6xXikI1WOSfFsmjGi04Ow== X-Received: by 2002:a05:6808:1c0d:b0:32e:493b:1e2 with SMTP id ch13-20020a0568081c0d00b0032e493b01e2mr19404650oib.101.1658243675704; Tue, 19 Jul 2022 08:14:35 -0700 (PDT) Received: from fedora.attlocal.net (69-109-179-158.lightspeed.dybhfl.sbcglobal.net. [69.109.179.158]) by smtp.gmail.com with ESMTPSA id l24-20020a056830155800b0061c8bca21d8sm2334308otp.2.2022.07.19.08.14.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Jul 2022 08:14:35 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, brgl@bgdev.pl Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, William Breathitt Gray , Fred Eckert , John Hentges , Jay Dolan Subject: [PATCH v4 2/6] gpio: 104-idio-16: Implement and utilize register structures Date: Tue, 19 Jul 2022 09:47:04 -0400 Message-Id: <6fb23e16f5cd9c0222e12c245a2b93d5b14d4b4b.1658236877.git.william.gray@linaro.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Reduce magic numbers and improve code readability by implementing and utilizing named register data structures. Tested-by: Fred Eckert Reviewed-by: Linus Walleij Cc: John Hentges Cc: Jay Dolan Signed-off-by: William Breathitt Gray --- Changes in v4: - Replace superfluous include with drivers/gpio/gpio-104-idio-16.c | 60 +++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/drivers/gpio/gpio-104-idio-16.c b/drivers/gpio/gpio-104-idio-16.c index 45f7ad8573e1..65a5f581d981 100644 --- a/drivers/gpio/gpio-104-idio-16.c +++ b/drivers/gpio/gpio-104-idio-16.c @@ -6,7 +6,7 @@ * This driver supports the following ACCES devices: 104-IDIO-16, * 104-IDIO-16E, 104-IDO-16, 104-IDIO-8, 104-IDIO-8E, and 104-IDO-8. */ -#include +#include #include #include #include @@ -19,6 +19,7 @@ #include #include #include +#include #define IDIO_16_EXTENT 8 #define MAX_NUM_IDIO_16 max_num_isa_dev(IDIO_16_EXTENT) @@ -32,19 +33,42 @@ static unsigned int irq[MAX_NUM_IDIO_16]; module_param_hw_array(irq, uint, irq, NULL, 0); MODULE_PARM_DESC(irq, "ACCES 104-IDIO-16 interrupt line numbers"); +/** + * struct idio_16_reg - device registers structure + * @out0_7: Read: N/A + * Write: FET Drive Outputs 0-7 + * @in0_7: Read: Isolated Inputs 0-7 + * Write: Clear Interrupt + * @irq_ctl: Read: Enable IRQ + * Write: Disable IRQ + * @unused: N/A + * @out8_15: Read: N/A + * Write: FET Drive Outputs 8-15 + * @in8_15: Read: Isolated Inputs 8-15 + * Write: N/A + */ +struct idio_16_reg { + u8 out0_7; + u8 in0_7; + u8 irq_ctl; + u8 unused; + u8 out8_15; + u8 in8_15; +}; + /** * struct idio_16_gpio - GPIO device private data structure * @chip: instance of the gpio_chip * @lock: synchronization lock to prevent I/O race conditions * @irq_mask: I/O bits affected by interrupts - * @base: base port address of the GPIO device + * @reg: I/O address offset for the device registers * @out_state: output bits state */ struct idio_16_gpio { struct gpio_chip chip; raw_spinlock_t lock; unsigned long irq_mask; - void __iomem *base; + struct idio_16_reg __iomem *reg; unsigned int out_state; }; @@ -79,9 +103,9 @@ static int idio_16_gpio_get(struct gpio_chip *chip, unsigned int offset) return -EINVAL; if (offset < 24) - return !!(ioread8(idio16gpio->base + 1) & mask); + return !!(ioread8(&idio16gpio->reg->in0_7) & mask); - return !!(ioread8(idio16gpio->base + 5) & (mask>>8)); + return !!(ioread8(&idio16gpio->reg->in8_15) & (mask>>8)); } static int idio_16_gpio_get_multiple(struct gpio_chip *chip, @@ -91,9 +115,9 @@ static int idio_16_gpio_get_multiple(struct gpio_chip *chip, *bits = 0; if (*mask & GENMASK(23, 16)) - *bits |= (unsigned long)ioread8(idio16gpio->base + 1) << 16; + *bits |= (unsigned long)ioread8(&idio16gpio->reg->in0_7) << 16; if (*mask & GENMASK(31, 24)) - *bits |= (unsigned long)ioread8(idio16gpio->base + 5) << 24; + *bits |= (unsigned long)ioread8(&idio16gpio->reg->in8_15) << 24; return 0; } @@ -116,9 +140,9 @@ static void idio_16_gpio_set(struct gpio_chip *chip, unsigned int offset, idio16gpio->out_state &= ~mask; if (offset > 7) - iowrite8(idio16gpio->out_state >> 8, idio16gpio->base + 4); + iowrite8(idio16gpio->out_state >> 8, &idio16gpio->reg->out8_15); else - iowrite8(idio16gpio->out_state, idio16gpio->base); + iowrite8(idio16gpio->out_state, &idio16gpio->reg->out0_7); raw_spin_unlock_irqrestore(&idio16gpio->lock, flags); } @@ -135,9 +159,9 @@ static void idio_16_gpio_set_multiple(struct gpio_chip *chip, idio16gpio->out_state |= *mask & *bits; if (*mask & 0xFF) - iowrite8(idio16gpio->out_state, idio16gpio->base); + iowrite8(idio16gpio->out_state, &idio16gpio->reg->out0_7); if ((*mask >> 8) & 0xFF) - iowrite8(idio16gpio->out_state >> 8, idio16gpio->base + 4); + iowrite8(idio16gpio->out_state >> 8, &idio16gpio->reg->out8_15); raw_spin_unlock_irqrestore(&idio16gpio->lock, flags); } @@ -158,7 +182,7 @@ static void idio_16_irq_mask(struct irq_data *data) if (!idio16gpio->irq_mask) { raw_spin_lock_irqsave(&idio16gpio->lock, flags); - iowrite8(0, idio16gpio->base + 2); + iowrite8(0, &idio16gpio->reg->irq_ctl); raw_spin_unlock_irqrestore(&idio16gpio->lock, flags); } @@ -177,7 +201,7 @@ static void idio_16_irq_unmask(struct irq_data *data) if (!prev_irq_mask) { raw_spin_lock_irqsave(&idio16gpio->lock, flags); - ioread8(idio16gpio->base + 2); + ioread8(&idio16gpio->reg->irq_ctl); raw_spin_unlock_irqrestore(&idio16gpio->lock, flags); } @@ -212,7 +236,7 @@ static irqreturn_t idio_16_irq_handler(int irq, void *dev_id) raw_spin_lock(&idio16gpio->lock); - iowrite8(0, idio16gpio->base + 1); + iowrite8(0, &idio16gpio->reg->in0_7); raw_spin_unlock(&idio16gpio->lock); @@ -232,8 +256,8 @@ static int idio_16_irq_init_hw(struct gpio_chip *gc) struct idio_16_gpio *const idio16gpio = gpiochip_get_data(gc); /* Disable IRQ by default */ - iowrite8(0, idio16gpio->base + 2); - iowrite8(0, idio16gpio->base + 1); + iowrite8(0, &idio16gpio->reg->irq_ctl); + iowrite8(0, &idio16gpio->reg->in0_7); return 0; } @@ -255,8 +279,8 @@ static int idio_16_probe(struct device *dev, unsigned int id) return -EBUSY; } - idio16gpio->base = devm_ioport_map(dev, base[id], IDIO_16_EXTENT); - if (!idio16gpio->base) + idio16gpio->reg = devm_ioport_map(dev, base[id], IDIO_16_EXTENT); + if (!idio16gpio->reg) return -ENOMEM; idio16gpio->chip.label = name; -- 2.36.1