From patchwork Mon Mar 12 20:49:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10277437 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 019FC60467 for ; Mon, 12 Mar 2018 20:49:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E804828C22 for ; Mon, 12 Mar 2018 20:49:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DA5F528E55; Mon, 12 Mar 2018 20:49:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 896D528C22 for ; Mon, 12 Mar 2018 20:49:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932416AbeCLUtQ (ORCPT ); Mon, 12 Mar 2018 16:49:16 -0400 Received: from mail-yw0-f196.google.com ([209.85.161.196]:33679 "EHLO mail-yw0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932274AbeCLUtO (ORCPT ); Mon, 12 Mar 2018 16:49:14 -0400 Received: by mail-yw0-f196.google.com with SMTP id l200so6399457ywb.0; Mon, 12 Mar 2018 13:49:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=VY12YUu6hlk5Bq7RxTzYRv59jkAS3swOR0Yq8By0ql4=; b=jDqpjZzoeDOCRFYPyAnQV06l3UEoxFRIVt6PklIWnDUfKdp4LSK3VLE/ExrdTWTnII IkYmB9LBCZHaD/sbMukUMITbT3x+ZGLchRw3foZrOJri14xcn75bn+Fk6HEFtYnybD0r tuVKvcB6vMzK8sL7XMcU13el7ufrtoXeyKBWjRciqs8O91jnwPzyCNyKf8vq+L2N8Eql AS+nF7C5XResGhnpa30XPbUG8GND1hqihqYzVmeegAmh8PXHp6AkSbVuS4lU0fs2gvX2 oMhDpW1DIsPgWeJ/0TSM27utroEKqZbje/l0R/DwmzS/C1l3f007NX+cfszht8wu8ldN q4qQ== 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:in-reply-to :references; bh=VY12YUu6hlk5Bq7RxTzYRv59jkAS3swOR0Yq8By0ql4=; b=JkQMopFs5c7CZC0C/w3G9JXGGzB0QpKppkX5vtkAq+853zLSztn4GIczBwuk0lP3qn BpZDN59qTtkCXCauqNSUMhARTKTp1VNe4BIfqTaled2KHoXDHfzlEOvi/LWi7Aun0ZWP xJ6tvBjXWKpaXchZfbrcRLIVTjv7RulwtLQBRZ+SOL7cDfMFWmJ9S4s3Mm3VCC3JJ/p2 frEwJDhABHiTQ/MXMfvcRdaPTkc7y68bfSejWHcLbqqL2uIc8jLQUhRNcWiCbX3NAUNI NUIJc8yzPUkN/JeH6lG7LcrSahV2/30PMsZraImpPrF0K9F38PTPPD7Glx6pjr89pgIh ey1A== X-Gm-Message-State: AElRT7Elpn30zZCoZrqfdXPrQYQiS9C4g/IY9lrq6LeYU4v3DUn0iRs9 jeqcABE8/MZhdSS8FJgYcKQ= X-Google-Smtp-Source: AG47ELu/N6NpQIyoXb8Vyf2fa4QOJVcP1SvFYUGEzszzoySL0bQRCzC3MTA758QoH/OOBeDYbru8OA== X-Received: by 10.129.107.11 with SMTP id g11mr2029436ywc.459.1520887753717; Mon, 12 Mar 2018 13:49:13 -0700 (PDT) Received: from localhost ([72.188.97.40]) by smtp.gmail.com with ESMTPSA id q11sm3215215ywc.106.2018.03.12.13.49.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Mar 2018 13:49:12 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, William Breathitt Gray Subject: [PATCH 3/8] gpio: pci-idio-16: Implement get_multiple callback Date: Mon, 12 Mar 2018 16:49:07 -0400 Message-Id: X-Mailer: git-send-email 2.16.2 In-Reply-To: References: Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The ACCES I/O PCI-IDIO-16 series of devices provides 16 optically-isolated digital inputs accessed via two 8-bit ports. Since eight input lines are acquired on a single port input read, the PCI-IDIO-16 GPIO driver may improve multiple input reads by utilizing a get_multiple callback. This patch implements the idio_16_gpio_get_multiple function which serves as the respective get_multiple callback. Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-pci-idio-16.c | 48 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/drivers/gpio/gpio-pci-idio-16.c b/drivers/gpio/gpio-pci-idio-16.c index 57d1b7fbf07b..8c5ec301c7ff 100644 --- a/drivers/gpio/gpio-pci-idio-16.c +++ b/drivers/gpio/gpio-pci-idio-16.c @@ -103,6 +103,53 @@ static int idio_16_gpio_get(struct gpio_chip *chip, unsigned int offset) return !!(ioread8(&idio16gpio->reg->in8_15) & (mask >> 24)); } +static int idio_16_gpio_get_multiple(struct gpio_chip *chip, + unsigned long *mask, unsigned long *bits) +{ + struct idio_16_gpio *const idio16gpio = gpiochip_get_data(chip); + unsigned int i; + const unsigned int gpio_reg_size = 8; + unsigned int bit_word_offset; + unsigned int bits_mask; + const unsigned long reg_mask = GENMASK(gpio_reg_size, 0); + unsigned long port_state; + + /* clear bits array to a clean slate */ + for (i = 0; i < chip->ngpio; i += BITS_PER_LONG) + bits[i / BITS_PER_LONG] = 0; + + /* get bits are evaluated a gpio register size at a time */ + for (i = 0; i < chip->ngpio; i += gpio_reg_size) { + bit_word_offset = i % BITS_PER_LONG; + bits_mask = mask[BIT_WORD(i)] & (reg_mask << bit_word_offset); + if (!bits_mask) { + /* no get bits in this register so skip to next one */ + continue; + } + + /* read bits from current gpio register */ + switch (i / gpio_reg_size) { + case 0: + port_state = ioread8(&idio16gpio->reg->out0_7); + break; + case 1: + port_state = ioread8(&idio16gpio->reg->out8_15); + break; + case 2: + port_state = ioread8(&idio16gpio->reg->in0_7); + break; + case 3: + port_state = ioread8(&idio16gpio->reg->in8_15); + break; + } + + /* store acquired bits */ + bits[BIT_WORD(i)] |= port_state << bit_word_offset; + } + + return 0; +} + static void idio_16_gpio_set(struct gpio_chip *chip, unsigned int offset, int value) { @@ -299,6 +346,7 @@ static int idio_16_probe(struct pci_dev *pdev, const struct pci_device_id *id) idio16gpio->chip.direction_input = idio_16_gpio_direction_input; idio16gpio->chip.direction_output = idio_16_gpio_direction_output; idio16gpio->chip.get = idio_16_gpio_get; + idio16gpio->chip.get_multiple = idio_16_gpio_get_multiple; idio16gpio->chip.set = idio_16_gpio_set; idio16gpio->chip.set_multiple = idio_16_gpio_set_multiple;