From patchwork Thu Mar 22 12:59:37 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: 889363 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="U0U+GhDt"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 406Rgx2Y37z9s21 for ; Fri, 23 Mar 2018 00:03:57 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755326AbeCVNDc (ORCPT ); Thu, 22 Mar 2018 09:03:32 -0400 Received: from mail-yw0-f193.google.com ([209.85.161.193]:46885 "EHLO mail-yw0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754920AbeCVM7o (ORCPT ); Thu, 22 Mar 2018 08:59:44 -0400 Received: by mail-yw0-f193.google.com with SMTP id v68so2760435ywg.13; Thu, 22 Mar 2018 05:59:44 -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=0PGIwpjptKrmxrHuWkj1CXzN2iorTnCkvuqkLiPOBL8=; b=U0U+GhDtalUeDyQOs8TVANSFdgh2rWLozVthU6kOeiDTcm19D1E8ap3UJ+eLUjuIkP Q1wY9D5YhHiK0VpIjmXFHd8xuQ2gl1alS6Z+f4LgBjrXxZBj6t7y8YK8zjY+m7odEh9m d7sak60oN4v7nppBb/3bF1Q/aCOXUmYXeUZxtXHLy0GWmgNSzj/eaCgJQkMKyq5CHT54 kDa4HgONsCw/9rU+oHQS2S3vmOsfAJ9m9mFpNwfUX30oFzomilAZjwNEGsACxfh8MoU1 H/PeBEP2CgxKUaMKd/ippxy9YDFvUwq5hnlIOS1tRi1gd+RRWbMymJe11EJRP7CuYyeC MXOQ== 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=0PGIwpjptKrmxrHuWkj1CXzN2iorTnCkvuqkLiPOBL8=; b=NQQyxcRy0S2KpoWsM4+8s+pWxOQXHcIkEns2kyKtA+pUalF7+xOPLB+qX/g3JWrZcr pXNP49/nhvSZXtrggo5zRtdoPviM8AGyIbvKJrqUfgbbcUT7am9QWmXJGeoUqrcTL/RH Zg8r+VOSf19kptHvAwVHsgIjT0BTvQ8hlfQp/bUZk592KYyOl35Gvx4uu6j+WEyUrBVu 4gDvQssj/+8B8fMpHvInRAqszhuYBKg6EYNQdHXTCLYqEKSJlOb+NhLh1KpiyEgsNeJT 4r+XvPcln8TaGPkLVpbk5LpKazjKICz0V9nYSl6rD2CP5JASBVjHD/ZVToIo5NQNRPEH Ac/g== X-Gm-Message-State: AElRT7GWPnHF1nVVlA9VCCrMJxSZo2vgFBPT0HQ2l8kYZgqIOfHg9X4M UQKoy/CLtn73wsAZ+1hzJ3g= X-Google-Smtp-Source: AG47ELu5XupfVZibCE2PL8Ek0RRq9WMOo4zD49T6gmcpA6MV5rr+2hBZcdcdeqNN4al7y2h5UMyCZQ== X-Received: by 10.129.113.139 with SMTP id m133mr14463973ywc.164.1521723584029; Thu, 22 Mar 2018 05:59:44 -0700 (PDT) Received: from localhost ([72.188.97.40]) by smtp.gmail.com with ESMTPSA id t131sm2543927ywe.77.2018.03.22.05.59.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Mar 2018 05:59:43 -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 1/7] gpio: 104-idio-16: Implement get_multiple callback Date: Thu, 22 Mar 2018 08:59:37 -0400 Message-Id: <1699105253cb33680bb27ca61e6fc9fb0bd2aaf8.1521723192.git.vilhelm.gray@gmail.com> 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 104-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 104-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-104-idio-16.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/gpio/gpio-104-idio-16.c b/drivers/gpio/gpio-104-idio-16.c index 2f16638a0589..96700308c1e3 100644 --- a/drivers/gpio/gpio-104-idio-16.c +++ b/drivers/gpio/gpio-104-idio-16.c @@ -90,6 +90,20 @@ static int idio_16_gpio_get(struct gpio_chip *chip, unsigned offset) return !!(inb(idio16gpio->base + 5) & (mask>>8)); } +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); + + *bits = 0; + if (*mask & GENMASK(23, 16)) + *bits |= (unsigned long)inb(idio16gpio->base + 1) << 16; + if (*mask & GENMASK(31, 24)) + *bits |= (unsigned long)inb(idio16gpio->base + 5) << 24; + + return 0; +} + static void idio_16_gpio_set(struct gpio_chip *chip, unsigned offset, int value) { struct idio_16_gpio *const idio16gpio = gpiochip_get_data(chip); @@ -244,6 +258,7 @@ static int idio_16_probe(struct device *dev, unsigned int 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; idio16gpio->base = base[id]; 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; From patchwork Thu Mar 22 13:00:00 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: 889361 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="Thr8AKfU"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 406Rff3YTVz9s3W for ; Fri, 23 Mar 2018 00:02:50 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755272AbeCVNCh (ORCPT ); Thu, 22 Mar 2018 09:02:37 -0400 Received: from mail-yb0-f195.google.com ([209.85.213.195]:39510 "EHLO mail-yb0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755010AbeCVNAH (ORCPT ); Thu, 22 Mar 2018 09:00:07 -0400 Received: by mail-yb0-f195.google.com with SMTP id k8-v6so2879748ybd.6; Thu, 22 Mar 2018 06:00:06 -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=l/47NoDMDyW7hmRu2p0Eox6zgZqQU21+L3Ez8FhPak0=; b=Thr8AKfU2iYkmPzKzpqENuEL8OCcUSuezix/boUACYrCI8BlJHKHw2GxYArdnRcqXP Onr1D7X+Y+O3xJUmQZ63wezy9iRrqhj+t2LZC/dsHseTNrHzjNbf3fS2V9NUBiM0W6B8 Bai9eQbHe2jENBncVqT1VtM8NcE4RYvt5eeAZCy9PI6EcBbBd1fgB0NgrJcrdXSQ2VZk FZSUS/xPh4Q0m4tcnw0kZ1nmoSswbipRCe788dcyC6c/CZJBDgSc8u8SkQfc57OtFKhh vk6gg/+P9nUhnNP6sJgjWZupgDLE69Ij6QvqRmDvxF+V2S7pubz+Jud+HS5Op/uU8vSV CuuQ== 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=l/47NoDMDyW7hmRu2p0Eox6zgZqQU21+L3Ez8FhPak0=; b=Ao6V5bJv7Cp4FcZ7/HyMsAZcGFXV4FBZNWvqXhBlQPFgaDBWjmwmxAGFH+lWRNo6XA 8stu0TbmRaiKHJFHO8+PA730C0dWFS65Z8++9K/5gPrw6bSWrL32bWNL7MkLTyqBMlVP sV0wwAPyoQvqXqT1zQP5cViUlrAUbgmubFMmX+bYRYGHsREgjRISD8sl1xKbwuu93LQa 1WvJfWIWRv0wU4kl5SyIpuBe8v8b0mF4AZtVpAZx+rNcipZeKLf4kFB4EKfznRmANOu1 1eAPZ33PQES0Hjtc2Izz6buCmaeh9vLJfqpJeiiyZnKKiDiCC59c0hbnlKU7gXuRIWzZ L1Sw== X-Gm-Message-State: AElRT7HBpuv0sA6GjOh7Slqx4GZmv/su1GdOWzn7oYjfObxBPAUg1+ew OeAInIJ2oFMyOBkukta7uF0= X-Google-Smtp-Source: AG47ELsbIcXxBJ7r2oM2En28ebEkDOlDebSJjD2sQMtsMDDsVsIG3jfwHo1o1jD76yAFy8vwCEGnJg== X-Received: by 2002:a25:9782:: with SMTP id i2-v6mr2823343ybo.351.1521723606343; Thu, 22 Mar 2018 06:00:06 -0700 (PDT) Received: from localhost ([72.188.97.40]) by smtp.gmail.com with ESMTPSA id l145sm2486975ywb.105.2018.03.22.06.00.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Mar 2018 06:00:05 -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 3/7] gpio: pcie-idio-24: Implement get_multiple/set_multiple callbacks Date: Thu, 22 Mar 2018 09:00:00 -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 PCIe-IDIO-24 series of devices provides 24 optically-isolated digital I/O accessed via six 8-bit ports. Since eight input lines are acquired on a single port input read -- and similarly eight output lines are set on a single port output write -- the PCIe-IDIO-24 GPIO driver may improve multiple I/O reads/writes by utilizing a get_multiple/set_multiple callbacks. This patch implements the idio_24_gpio_get_multiple function which serves as the respective get_multiple callback, and implements the idio_24_gpio_set_multiple function which serves as the respective set_multiple callback. Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-pcie-idio-24.c | 117 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/drivers/gpio/gpio-pcie-idio-24.c b/drivers/gpio/gpio-pcie-idio-24.c index f666e2e69074..835607ecf658 100644 --- a/drivers/gpio/gpio-pcie-idio-24.c +++ b/drivers/gpio/gpio-pcie-idio-24.c @@ -15,6 +15,7 @@ * This driver supports the following ACCES devices: PCIe-IDIO-24, * PCIe-IDI-24, PCIe-IDO-24, and PCIe-IDIO-12. */ +#include #include #include #include @@ -193,6 +194,61 @@ static int idio_24_gpio_get(struct gpio_chip *chip, unsigned int offset) return !!(ioread8(&idio24gpio->reg->ttl_in0_7) & offset_mask); } +static int idio_24_gpio_get_multiple(struct gpio_chip *chip, + unsigned long *mask, unsigned long *bits) +{ + struct idio_24_gpio *const idio24gpio = 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[] = { + idio24gpio->reg->out0_7, idio24gpio->reg->out8_15, + idio24gpio->reg->out16_23, idio24gpio->reg->in0_7, + idio24gpio->reg->in8_15, idio24gpio->reg->in16_23, + }; + const unsigned long out_mode_mask = BIT(1); + + /* 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 6 is TTL GPIO) */ + if (i < 6) + port_state = ioread8(ports + i); + else if (ioread8(&idio24gpio->reg->ctl) & out_mode_mask) + port_state = ioread8(&idio24gpio->reg->ttl_out0_7); + else + port_state = ioread8(&idio24gpio->reg->ttl_in0_7); + + /* store acquired bits at respective bits array offset */ + bits[word_index] |= port_state << word_offset; + } + + return 0; +} + static void idio_24_gpio_set(struct gpio_chip *chip, unsigned int offset, int value) { @@ -234,6 +290,65 @@ static void idio_24_gpio_set(struct gpio_chip *chip, unsigned int offset, raw_spin_unlock_irqrestore(&idio24gpio->lock, flags); } +static void idio_24_gpio_set_multiple(struct gpio_chip *chip, + unsigned long *mask, unsigned long *bits) +{ + struct idio_24_gpio *const idio24gpio = gpiochip_get_data(chip); + size_t i; + unsigned long bits_offset; + unsigned long gpio_mask; + const unsigned int gpio_reg_size = 8; + const unsigned long port_mask = GENMASK(gpio_reg_size, 0); + unsigned long flags; + unsigned int out_state; + u8 __iomem ports[] = { + idio24gpio->reg->out0_7, idio24gpio->reg->out8_15, + idio24gpio->reg->out16_23 + }; + const unsigned long out_mode_mask = BIT(1); + const unsigned int ttl_offset = 48; + const size_t ttl_i = BIT_WORD(ttl_offset); + const unsigned int word_offset = ttl_offset % BITS_PER_LONG; + const unsigned long ttl_mask = (mask[ttl_i] >> word_offset) & port_mask; + const unsigned long ttl_bits = (bits[ttl_i] >> word_offset) & ttl_mask; + + /* set bits are processed 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; + + /* check if any set bits for current port */ + gpio_mask = (*mask >> bits_offset) & port_mask; + if (!gpio_mask) { + /* no set bits for this port so move on to next port */ + continue; + } + + raw_spin_lock_irqsave(&idio24gpio->lock, flags); + + /* process output lines */ + out_state = ioread8(ports + i) & ~gpio_mask; + out_state |= (*bits >> bits_offset) & gpio_mask; + iowrite8(out_state, ports + i); + + raw_spin_unlock_irqrestore(&idio24gpio->lock, flags); + } + + /* check if setting TTL lines and if they are in output mode */ + if (!ttl_mask || !(ioread8(&idio24gpio->reg->ctl) & out_mode_mask)) + return; + + /* handle TTL output */ + raw_spin_lock_irqsave(&idio24gpio->lock, flags); + + /* process output lines */ + out_state = ioread8(&idio24gpio->reg->ttl_out0_7) & ~ttl_mask; + out_state |= ttl_bits; + iowrite8(out_state, &idio24gpio->reg->ttl_out0_7); + + raw_spin_unlock_irqrestore(&idio24gpio->lock, flags); +} + static void idio_24_irq_ack(struct irq_data *data) { } @@ -397,7 +512,9 @@ static int idio_24_probe(struct pci_dev *pdev, const struct pci_device_id *id) idio24gpio->chip.direction_input = idio_24_gpio_direction_input; idio24gpio->chip.direction_output = idio_24_gpio_direction_output; idio24gpio->chip.get = idio_24_gpio_get; + idio24gpio->chip.get_multiple = idio_24_gpio_get_multiple; idio24gpio->chip.set = idio_24_gpio_set; + idio24gpio->chip.set_multiple = idio_24_gpio_set_multiple; raw_spin_lock_init(&idio24gpio->lock); From patchwork Thu Mar 22 13:00:11 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: 889360 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="gJANSanH"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 406Rf830gZz9s2M for ; Fri, 23 Mar 2018 00:02:24 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755063AbeCVNAY (ORCPT ); Thu, 22 Mar 2018 09:00:24 -0400 Received: from mail-yb0-f196.google.com ([209.85.213.196]:43021 "EHLO mail-yb0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755000AbeCVNAU (ORCPT ); Thu, 22 Mar 2018 09:00:20 -0400 Received: by mail-yb0-f196.google.com with SMTP id z5-v6so2874526ybo.10; Thu, 22 Mar 2018 06:00:20 -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=4TiTZT2rxlS9JLFeREH+g0GEQrlB0+NQ+VnL7eViW84=; b=gJANSanHCJdyjcvQu1sreK7QoCcVUDpQJT2Q3xkh7QCFNAXb0aOrIhJWQw3NpH5RYS ht3gBu/C8teMaXp8089n5b5j0dMGkjwDJkdALjwwtHy12OMgNGT5vVLXm71cFfy0lym7 oKhBs72Yf1vfuEo193y56QRJIB14f1TaaGr2g5crBvvDDvwHxaS1u6QR+xABJ+2TXloE VjxSjErX6iI8D1Lwt0Wg50L7le6ecT0GLMA+ophuzs8IbJSY4w8bxs8va9B00/ek8PB1 mdCCLNVC1hbDC2BOYl8kr2N9lWkMqH+yUbgZhk5HOoz+NDM5MK4D/aIMrBKTrdcFEFZN VkJQ== 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=4TiTZT2rxlS9JLFeREH+g0GEQrlB0+NQ+VnL7eViW84=; b=GKOILGdHxX/YS4IKZHw0pRm/SZNnac19SxNWGZh4wwJ0lfzM8jO6hgj8VTvOheoCdO jVM5xFB1CsnRDlj1uEjcD98bFuxykrA4Sjmsl+cOxRxBYevDecEePqEFqXB58BlPztck EIF7S9ZKBeNuiErX5UxjbulfCC91CsAWrfWVEuy/lohT3bWeltHqVJYYGzfSTpYtTtIG H0dCQB+c6w9+dLdtNiNMBauZAGB1vQ5Yx1E51P3oidFhcBjbThfPzUT0pRi/uxdtKOP3 /5KfCDVZsAFxDhK4PqjiYzCXBmahedEp3QgpOQnywwQC8xk4eQwHhjBnt5Xu8J8dLxm7 Ch9A== X-Gm-Message-State: AElRT7HZxmzGwVEXvPwag4rSmhtxQFzwD2aYNHpexuq6/AGf6fs5NdJ2 k/fMaZHHB4B+wCFey4Bnn7GlBQ== X-Google-Smtp-Source: AG47ELs81hXB30MCHhOkOqx43oyKZzI2v6Lvrgbo3lWSM05yjRt2k8dE0A8LCK4vROsm2E1cUspEuA== X-Received: by 2002:a25:2782:: with SMTP id n124-v6mr14721882ybn.307.1521723619639; Thu, 22 Mar 2018 06:00:19 -0700 (PDT) Received: from localhost ([72.188.97.40]) by smtp.gmail.com with ESMTPSA id g145sm949485ywb.61.2018.03.22.06.00.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Mar 2018 06:00:19 -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 4/7] gpio: 104-dio-48e: Implement get_multiple callback Date: Thu, 22 Mar 2018 09:00:11 -0400 Message-Id: <35b31cc749162ce549d4d1a82f2d23889590d413.1521723192.git.vilhelm.gray@gmail.com> 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 104-DIO-48E series of devices contain two Programmable Peripheral Interface (PPI) chips of type 82C55, which each feature three 8-bit ports of I/O. Since eight input lines are acquired on a single port input read, the 104-DIO-48E GPIO driver may improve multiple input reads by utilizing a get_multiple callback. This patch implements the dio48e_gpio_get_multiple function which serves as the respective get_multiple callback. Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-104-dio-48e.c | 47 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/drivers/gpio/gpio-104-dio-48e.c b/drivers/gpio/gpio-104-dio-48e.c index bab3b94c5cbc..31e22c93e844 100644 --- a/drivers/gpio/gpio-104-dio-48e.c +++ b/drivers/gpio/gpio-104-dio-48e.c @@ -14,6 +14,7 @@ * This driver supports the following ACCES devices: 104-DIO-48E and * 104-DIO-24E. */ +#include #include #include #include @@ -182,6 +183,51 @@ static int dio48e_gpio_get(struct gpio_chip *chip, unsigned offset) return !!(port_state & mask); } +static int dio48e_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, + unsigned long *bits) +{ + struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip); + size_t i; + const size_t ports[] = { 0, 1, 2, 4, 5, 6 }; + 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; + + /* 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 = inb(dio48egpio->base + ports[i]); + + /* store acquired bits at respective bits array offset */ + bits[word_index] |= port_state << word_offset; + } + + return 0; +} + static void dio48e_gpio_set(struct gpio_chip *chip, unsigned offset, int value) { struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip); @@ -384,6 +430,7 @@ static int dio48e_probe(struct device *dev, unsigned int id) dio48egpio->chip.direction_input = dio48e_gpio_direction_input; dio48egpio->chip.direction_output = dio48e_gpio_direction_output; dio48egpio->chip.get = dio48e_gpio_get; + dio48egpio->chip.get_multiple = dio48e_gpio_get_multiple; dio48egpio->chip.set = dio48e_gpio_set; dio48egpio->chip.set_multiple = dio48e_gpio_set_multiple; dio48egpio->base = base[id]; From patchwork Thu Mar 22 13:00:31 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: 889359 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="fzMgPN4Y"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 406RdP1NpZz9s37 for ; Fri, 23 Mar 2018 00:01:45 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754777AbeCVNBb (ORCPT ); Thu, 22 Mar 2018 09:01:31 -0400 Received: from mail-yb0-f195.google.com ([209.85.213.195]:35567 "EHLO mail-yb0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755104AbeCVNAi (ORCPT ); Thu, 22 Mar 2018 09:00:38 -0400 Received: by mail-yb0-f195.google.com with SMTP id v66-v6so2881893ybv.2; Thu, 22 Mar 2018 06:00:37 -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=+h8UT5Dqonzntc4wd2Fgi+xwBgZAHcaUa52pq621/nk=; b=fzMgPN4YFbcb4TRKhuEdBKw1i9Xz1lbNug40mrv6OeXHv41UsP8A/hm/pbfjsHUuVr Yzw/5VCS5seqh11ncdzuj6cp6fLwZTYqkdoGsC8XLFwYJp9EavTn3SX2f6uM3QD5iQpk 51BLnNoY+qDoU1ET5U3OKh6iXDzFwGL49ZpMIxyER3eF4/byY8be+5VyrY9gDRoO62Zg gV0tf9tfyDgZmaN5UzhpCSYKJDUjdsnMemR7PyugUulqTC3SL9TmfCgICUp1yqB/z17L lfdElf6FXkwIEv+lXldjxMFLB52p5xW46sHwj3O0o+L/f4ai9eNaOCZuOrpUiBrYFN/g TBhQ== 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=+h8UT5Dqonzntc4wd2Fgi+xwBgZAHcaUa52pq621/nk=; b=G3SBN4af3xpgc+DHGcTJHLyBuUTL9Cl3DMmL161u9qOBm/AiI8YKsClV9T4WMn6CSa bnWSuxGGy0yebOiH+H8/fZKN1P76T0oOk/JI4TPRipjWE2WdK5C39rMu/SDgR8kcFhcm YkCnc2X9gB5WIxcepZtzbt3NMJgDv5Dt64Gwq/oWdAygkrgiDJuIpMQVQzIVUFeGyF9L gmpBaT4Q0Qcmsqan5g68raeB6F2eFKu3yCTfsy3/1lU+XlqGiWNtOoFHWA2ewTpVMT2W FSnHChU5YixGELLfEBwGi1i6QSgND5rkEAgBe8mLNF8179QRWerdaVHsAf+1IM3KM0Yd mzHQ== X-Gm-Message-State: AElRT7HWFgj4YsLow7hjnv76U1CzhQxGJJ8f/FzwglVWFh9lYtDwAUrl /rjVZ0ICuKYG6tNanrVbYps= X-Google-Smtp-Source: AG47ELuRpHYWMI6Z9UAxnVV3O0Jyt3ZZ88hi+bRX7stIHmQJoyih/7E1OlHvpkHh2EJ5Ds9GzfkGtw== X-Received: by 2002:a25:7345:: with SMTP id o66-v6mr11288017ybc.391.1521723637305; Thu, 22 Mar 2018 06:00:37 -0700 (PDT) Received: from localhost ([72.188.97.40]) by smtp.gmail.com with ESMTPSA id j187sm2395259ywf.87.2018.03.22.06.00.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Mar 2018 06:00:36 -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 5/7] gpio: 104-idi-48: Implement get_multiple callback Date: Thu, 22 Mar 2018 09:00:31 -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 104-IDI-48 series of devices provides 48 optically-isolated inputs accessed via six 8-bit ports. Since eight input lines are acquired on a single port input read, the 104-IDI-48 GPIO driver may improve multiple input reads by utilizing a get_multiple callback. This patch implements the idi_48_gpio_get_multiple function which serves as the respective get_multiple callback. Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-104-idi-48.c | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/drivers/gpio/gpio-104-idi-48.c b/drivers/gpio/gpio-104-idi-48.c index add859d59766..f35632609379 100644 --- a/drivers/gpio/gpio-104-idi-48.c +++ b/drivers/gpio/gpio-104-idi-48.c @@ -14,6 +14,7 @@ * This driver supports the following ACCES devices: 104-IDI-48A, * 104-IDI-48AC, 104-IDI-48B, and 104-IDI-48BC. */ +#include #include #include #include @@ -88,6 +89,51 @@ static int idi_48_gpio_get(struct gpio_chip *chip, unsigned offset) return 0; } +static int idi_48_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, + unsigned long *bits) +{ + struct idi_48_gpio *const idi48gpio = gpiochip_get_data(chip); + size_t i; + const size_t ports[] = { 0, 1, 2, 4, 5, 6 }; + 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; + + /* 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 = inb(idi48gpio->base + ports[i]); + + /* store acquired bits at respective bits array offset */ + bits[word_index] |= port_state << word_offset; + } + + return 0; +} + static void idi_48_irq_ack(struct irq_data *data) { } @@ -256,6 +302,7 @@ static int idi_48_probe(struct device *dev, unsigned int id) idi48gpio->chip.get_direction = idi_48_gpio_get_direction; idi48gpio->chip.direction_input = idi_48_gpio_direction_input; idi48gpio->chip.get = idi_48_gpio_get; + idi48gpio->chip.get_multiple = idi_48_gpio_get_multiple; idi48gpio->base = base[id]; raw_spin_lock_init(&idi48gpio->lock); From patchwork Thu Mar 22 13:00:42 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: 889357 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="MEMm+i8f"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 406Rcg4GBlz9s2g for ; Fri, 23 Mar 2018 00:01:07 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754786AbeCVNAw (ORCPT ); Thu, 22 Mar 2018 09:00:52 -0400 Received: from mail-yb0-f196.google.com ([209.85.213.196]:46847 "EHLO mail-yb0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754792AbeCVNAs (ORCPT ); Thu, 22 Mar 2018 09:00:48 -0400 Received: by mail-yb0-f196.google.com with SMTP id t5-v6so2879623ybg.13; Thu, 22 Mar 2018 06:00:48 -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=SifEabFKuDUm0sjFPLAZbLsou7qG9ZFEsyKz06z7oqQ=; b=MEMm+i8f8gMMXE+ixp5sJLITnL5s5ySJuTSiabZWA4vDKWhvudN8r935IjuYiVANdw rKnHWYsVzb23WZy+kM8m5Mz7pAw0hcPmZx2GwYN6O2sZxQtZCZWGhYpv3WXyZdlRJPVk fhF1RvWKgTNMpWEePCgD4bwRrSjcpGZyfPkbaRPwUByx7dYqqs0jnc1FhH62wwvYcWvQ BIawINQsL6bwFlWWOfshd+09gOYNSssSnxujNFt23d/3/RKe+l1BmRA07Tm/UQOMIaLE fJSjBLLP5SC3+F0e1HNMDWOoaXkq8yJc18ns4ymTNVWNGxkBVFuZr936Or/pi/UXwK09 Y5QA== 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=SifEabFKuDUm0sjFPLAZbLsou7qG9ZFEsyKz06z7oqQ=; b=S+U9711b1uhLZvHSrYWbwetB14wjoS+vClkIn8G4Wtqq55DHchoteFd1/maQrc/ibg DVBeFsGca5tlAqXSds+iaWNAhPc/z6kY0oCKUK2In6mFQqVr/bjLlCEIngXQapauMGDB FCTWSbUQzKwbrazWZEdZEEJs4wFxgWneRkPjZu+ObRHEFzfWXkVHEUAL+46TwH92MANC QV6UX6/pQCD3qPj8ScC7fRdY5lcoXww7RdxPBHlAVAZ56DnuP1vDqD4k+NqxgNeziUSD oz9fBoiXbTrhKClAXJ7bBlwMOPIimMrO1l1qlQ594/P+R0c8wsDeh4G8lC0rbm/DYa8z rFwQ== X-Gm-Message-State: AElRT7Fv+hyPMnQuOzABdPky8yoZfDwzwNSLe2VfPcF/oobEMoxd55T/ LWkr5PlfXvr/G8uMQkM1jBE= X-Google-Smtp-Source: AG47ELvPVVPf7Ndj2n2Y20l/1h1Kp/BDkEfcJqRRd1XWmh+WO+d6HbBXfwlsVscQHaU6MU+BWlFffQ== X-Received: by 2002:a25:3d86:: with SMTP id k128-v6mr14119308yba.392.1521723647950; Thu, 22 Mar 2018 06:00:47 -0700 (PDT) Received: from localhost ([72.188.97.40]) by smtp.gmail.com with ESMTPSA id h7sm502536ywf.100.2018.03.22.06.00.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Mar 2018 06:00:47 -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 6/7] gpio: gpio-mm: Implement get_multiple callback Date: Thu, 22 Mar 2018 09:00:42 -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 Diamond Systems GPIO-MM series of devices contain two 82C55A devices, which each feature three 8-bit ports of I/O. Since eight input lines are acquired on a single port input read, the GPIO-MM GPIO driver may improve multiple input reads by utilizing a get_multiple callback. This patch implements the gpiomm_gpio_get_multiple function which serves as the respective get_multiple callback. Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-gpio-mm.c | 47 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/drivers/gpio/gpio-gpio-mm.c b/drivers/gpio/gpio-gpio-mm.c index 11ade5b288f8..d496cc56c2a2 100644 --- a/drivers/gpio/gpio-gpio-mm.c +++ b/drivers/gpio/gpio-gpio-mm.c @@ -14,6 +14,7 @@ * This driver supports the following Diamond Systems devices: GPIO-MM and * GPIO-MM-12. */ +#include #include #include #include @@ -171,6 +172,51 @@ static int gpiomm_gpio_get(struct gpio_chip *chip, unsigned int offset) return !!(port_state & mask); } +static int gpiomm_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, + unsigned long *bits) +{ + struct gpiomm_gpio *const gpiommgpio = gpiochip_get_data(chip); + size_t i; + const size_t ports[] = { 0, 1, 2, 4, 5, 6 }; + 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; + + /* 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 = inb(gpiommgpio->base + ports[i]); + + /* store acquired bits at respective bits array offset */ + bits[word_index] |= port_state << word_offset; + } + + return 0; +} + static void gpiomm_gpio_set(struct gpio_chip *chip, unsigned int offset, int value) { @@ -268,6 +314,7 @@ static int gpiomm_probe(struct device *dev, unsigned int id) gpiommgpio->chip.direction_input = gpiomm_gpio_direction_input; gpiommgpio->chip.direction_output = gpiomm_gpio_direction_output; gpiommgpio->chip.get = gpiomm_gpio_get; + gpiommgpio->chip.get_multiple = gpiomm_gpio_get_multiple; gpiommgpio->chip.set = gpiomm_gpio_set; gpiommgpio->chip.set_multiple = gpiomm_gpio_set_multiple; gpiommgpio->base = base[id]; From patchwork Thu Mar 22 13:00:59 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: 889358 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="Bd8pLojN"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 406Rd51B6lz9s34 for ; Fri, 23 Mar 2018 00:01:20 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755177AbeCVNBI (ORCPT ); Thu, 22 Mar 2018 09:01:08 -0400 Received: from mail-yb0-f193.google.com ([209.85.213.193]:36374 "EHLO mail-yb0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755179AbeCVNBG (ORCPT ); Thu, 22 Mar 2018 09:01:06 -0400 Received: by mail-yb0-f193.google.com with SMTP id o3-v6so362556ybm.3; Thu, 22 Mar 2018 06:01:06 -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=8b8caieZG3fncBoV23vo5RXKsfDrNb5y+qLbyBO1Jic=; b=Bd8pLojNU2q9xQGHnHHfR0gEuwfAZcnK46IK+bSyOHbiixXq67GPEAYlw0kzU2Gkij tz53L1QzRT0BrTamvpqLkIKu/YdRhkH7WsllImZMVp62BK7SXAaY64juY6ja2nzKbZCC FXgymjUCnhpSoUJCexTA0h7y1bD0QTfqp07ZQ0aUCN65Vi2s1geXRQqFr1ZToMT7Blr6 GT2SWZsgg6DJBEJJUdWKB2lOnaZ0s98kZMc+MgHLXz+So2IUmRf59Va5aKLQuGGILTag n0KRRAPFjLkYuKziZ/iQ2XYaJ+fPDXDtB+ewxcgDxkkwwpfsFWTx69eHyYsgFrMHlhb2 LPdw== 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=8b8caieZG3fncBoV23vo5RXKsfDrNb5y+qLbyBO1Jic=; b=NYocjG6qSnboutIXKyJgyIihGSFS0rP1avNdJNt1pEleNvHWlktTrCD9vWROth9YGz +4nav0cztNlp4J8jlTDkDEWVZrPIcI/DCwYD63fn75F2j4RC2Wqj6C2WImU7tBOGe0r5 MEzlxQBE26ANw65oc4PNP4WXVPQlKAn7vRIqR7OHeIzoMTe5+ZjcwBGm56GJrg0AgMgd Z52YXCFya27+VHmeP3jRrsHkMa7wpJPLcanA77Hk4r3/LcSGmrVVUcHXgNgjuB342BNU bGLkoN88pDvbhldsXARiLbdEAZ1kFJ8FJCb0eEGlDEQvXnM8qelAbjOF6vqc0itgCZYy nVFA== X-Gm-Message-State: AElRT7ED6VL33kyshmBGmAnr3738CpK7eWW0RP9Sn4X1lLCSL/N6RtN4 l2lLs7N9CfM7k/qmATvOxIU= X-Google-Smtp-Source: AG47ELvDE+twJ8tOB1v8zj8epLHwillkJrqq7HVmfB/KKIDbf7sTj0qsODg+Y03KpkZRlcJ9PZ1l8A== X-Received: by 2002:a25:aa2c:: with SMTP id s41-v6mr452813ybi.186.1521723665555; Thu, 22 Mar 2018 06:01:05 -0700 (PDT) Received: from localhost ([72.188.97.40]) by smtp.gmail.com with ESMTPSA id j187sm2395614ywf.87.2018.03.22.06.01.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Mar 2018 06:01:05 -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 7/7] gpio: ws16c48: Implement get_multiple callback Date: Thu, 22 Mar 2018 09:00:59 -0400 Message-Id: <259a3a67b82d2973f4c03a7c3c8a560b3054f7a9.1521723192.git.vilhelm.gray@gmail.com> 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 WinSystems WS16C48 device provides 48 lines of digital I/O accessed via six 8-bit ports. Since eight input lines are acquired on a single port input read, the WS16C48 GPIO driver may improve multiple input reads by utilizing a get_multiple callback. This patch implements the ws16c48_gpio_get_multiple function which serves as the respective get_multiple callback. Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-ws16c48.c | 47 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/drivers/gpio/gpio-ws16c48.c b/drivers/gpio/gpio-ws16c48.c index 746648244bf3..c7028eb0b8e1 100644 --- a/drivers/gpio/gpio-ws16c48.c +++ b/drivers/gpio/gpio-ws16c48.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 @@ -129,6 +130,51 @@ static int ws16c48_gpio_get(struct gpio_chip *chip, unsigned offset) return !!(port_state & mask); } +static int ws16c48_gpio_get_multiple(struct gpio_chip *chip, + unsigned long *mask, unsigned long *bits) +{ + struct ws16c48_gpio *const ws16c48gpio = gpiochip_get_data(chip); + const unsigned int gpio_reg_size = 8; + size_t i; + const size_t num_ports = chip->ngpio / gpio_reg_size; + 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; + + /* 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 < num_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 = inb(ws16c48gpio->base + i); + + /* store acquired bits at respective bits array offset */ + bits[word_index] |= port_state << word_offset; + } + + return 0; +} + static void ws16c48_gpio_set(struct gpio_chip *chip, unsigned offset, int value) { struct ws16c48_gpio *const ws16c48gpio = gpiochip_get_data(chip); @@ -383,6 +429,7 @@ static int ws16c48_probe(struct device *dev, unsigned int id) ws16c48gpio->chip.direction_input = ws16c48_gpio_direction_input; ws16c48gpio->chip.direction_output = ws16c48_gpio_direction_output; ws16c48gpio->chip.get = ws16c48_gpio_get; + ws16c48gpio->chip.get_multiple = ws16c48_gpio_get_multiple; ws16c48gpio->chip.set = ws16c48_gpio_set; ws16c48gpio->chip.set_multiple = ws16c48_gpio_set_multiple; ws16c48gpio->base = base[id];