From patchwork Thu Mar 22 12:59:48 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: 889362 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=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Mef75d5W"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 406Rft1kjdz9s3W for ; Fri, 23 Mar 2018 00:03:02 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754976AbeCVM75 (ORCPT ); Thu, 22 Mar 2018 08:59:57 -0400 Received: from mail-yw0-f194.google.com ([209.85.161.194]:38896 "EHLO mail-yw0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754950AbeCVM7z (ORCPT ); Thu, 22 Mar 2018 08:59:55 -0400 Received: by mail-yw0-f194.google.com with SMTP id x20so1774858ywg.5; Thu, 22 Mar 2018 05:59:55 -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=AQs4TmAnow3Y+GyzKwojtk8yhBk8QlR/byWIz4byFSY=; b=Mef75d5WrbjhIx6GpoPqQe9dAIKkHJau1bYYQ85UUXGtwAEgKZPepy9Fx2nhsbXcro phRwGRA+9N2BupBCEF4fGXz/gXJxxSTRodfHSDg/Uu9TPh2HiqqBiebHqUdSfjideJcO fidMZJFgMQF42SsV2F5UBHezxAsnRSuluI6zJh9SGNBA4v6y3IT6nd7V9bUddininhSP fqg6RdR+MvDKsqRNxkI0mmLLj8VzgsB+7KdcEBeiEWGkGH30pcrEJ+hYOTRDq7Mg+ql2 uYhVSc7/whSZtNjAr0hc2H3xnl5gm+F/cVTVbhkunVqfGLAGN9dRUbG8IYA+Mi95ZqUr Mrlw== 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=AQs4TmAnow3Y+GyzKwojtk8yhBk8QlR/byWIz4byFSY=; b=jlZ7vwm/Kul661z6Saay3QhinetEuFGrmVjR/bKvLz64G8aRllB8//EVmCsDutnfw3 6EywZMJHi67ojAC1upIx0Z6FaD9jAjIYBFhV7FMyXFrrz6HivU7hKVkOFmWdeOcxcUny GbebO5oy/1a1E3sBgjwgorQvzDHrWX/d46uhrSosBN31o6FCDdySuny77zs7agqIVy7K qIr/zhiPIucPcrqjwnUr3unKZR1cRmiGnQHrjW+trl/uJG28TVcH7JQJAP6pc3Q/gEZj vk/30YHI286h2y5ot5LwIHMy7gMqObHEei4wkmh65OeM75wsc0bezm+I0sXFrithOSWL 1o/g== X-Gm-Message-State: AElRT7EYop4cgHwfemqKePwrUlHVdOhjp5AaNkESDy7x5A/Kd3cjC5g8 rMov7E9Ku9uWgMxv4teSUH4= X-Google-Smtp-Source: AG47ELtYxPGjOCSF2KHLZBk7INsOCe8a5d8AWw0SrQMjdD7pQd3CzRX8+HWqDLHndb7opU2bPaFVsg== X-Received: by 10.129.77.9 with SMTP id a9mr2871885ywb.176.1521723594540; Thu, 22 Mar 2018 05:59:54 -0700 (PDT) Received: from localhost ([72.188.97.40]) by smtp.gmail.com with ESMTPSA id d135sm2546155ywh.2.2018.03.22.05.59.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Mar 2018 05:59:54 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org Cc: andy.shevchenko@gmail.com, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, William Breathitt Gray Subject: [PATCH v4 2/7] gpio: pci-idio-16: Implement get_multiple callback Date: Thu, 22 Mar 2018 08:59:48 -0400 Message-Id: X-Mailer: git-send-email 2.16.2 In-Reply-To: References: Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org 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 | 50 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/drivers/gpio/gpio-pci-idio-16.c b/drivers/gpio/gpio-pci-idio-16.c index 57d1b7fbf07b..1948724d8c36 100644 --- a/drivers/gpio/gpio-pci-idio-16.c +++ b/drivers/gpio/gpio-pci-idio-16.c @@ -11,6 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. */ +#include #include #include #include @@ -103,6 +104,54 @@ 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); + size_t i; + const unsigned int gpio_reg_size = 8; + unsigned int bits_offset; + size_t word_index; + unsigned int word_offset; + unsigned long word_mask; + const unsigned long port_mask = GENMASK(gpio_reg_size - 1, 0); + unsigned long port_state; + u8 __iomem ports[] = { + idio16gpio->reg->out0_7, idio16gpio->reg->out8_15, + idio16gpio->reg->in0_7, idio16gpio->reg->in8_15, + }; + + /* clear bits array to a clean slate */ + bitmap_zero(bits, chip->ngpio); + + /* get bits are evaluated a gpio port register at a time */ + for (i = 0; i < ARRAY_SIZE(ports); i++) { + /* gpio offset in bits array */ + bits_offset = i * gpio_reg_size; + + /* word index for bits array */ + word_index = BIT_WORD(bits_offset); + + /* gpio offset within current word of bits array */ + word_offset = bits_offset % BITS_PER_LONG; + + /* mask of get bits for current gpio within current word */ + word_mask = mask[word_index] & (port_mask << word_offset); + if (!word_mask) { + /* no get bits in this port so skip to next one */ + continue; + } + + /* read bits from current gpio port */ + port_state = ioread8(ports + i); + + /* store acquired bits at respective bits array offset */ + bits[word_index] |= port_state << word_offset; + } + + return 0; +} + static void idio_16_gpio_set(struct gpio_chip *chip, unsigned int offset, int value) { @@ -299,6 +348,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;