Received: by 10.213.65.68 with SMTP id h4csp35426imn; Thu, 15 Mar 2018 08:48:25 -0700 (PDT) X-Google-Smtp-Source: AG47ELvf70AslmIjpEiYnSzY6kbTAXkKMgEhApWMAN2TwDend+/HDUYs8kdb98h9VgNHrf0zxrnH X-Received: by 10.101.100.9 with SMTP id a9mr243778pgv.209.1521128905662; Thu, 15 Mar 2018 08:48:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521128905; cv=none; d=google.com; s=arc-20160816; b=eBdLSAIX8gcCja4nHxfmaFzPQCNyjGXfpzIFEeIXdHkCjX67g1A7vXEjUTYqRmj3VO XBnPJMtMZnWGfhDjovrnSx2zGF0NnJCBLtQHai/vRDlMiO6twF3p73Jagb1AHfyhnBPU Wc3ZE3e8H1jQb+Vjpyz5Z/R8Z4fBGWRi/QBqJsuImebrHd+LXpGc87htyxcPiNv05eml psIodK7FaP2PcdUmbMrdra1rOTVMJXyWhvU1V8VvuOX9KCmuqwLZt16Eyo1S2RENSFKq dxtCYUjv8JZkc54Qs66n7JoRiRP1ib9x4hUWoHezpVPyycr9p3BIhSGfi40SJrHrwrnt uVIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=oaC+eeSvETSipBZQ8G9tGZdQO0J0x1rT3ToK/tMEqww=; b=rxmVNvwFX/NQwDVU3A5Tmnk83R3mIcH5CFXj5wugxQvqPQ+INPWV9G/0VUxKR0OJyJ rMkNbo4Avd1Uw/3N5DwzwR5E421jxM+aXry8IsBLNUMcgCiN82C07VLRABJIcVIGgjMt 3cJAYOyVbMAwDKuB79k3e2nz2Vdh5ebWU5Ek6Z3/U+PAJ91WPKei8+zrbQkCXdRtvxkU 1LjBd92B79nz6FR8+8Xasa/ZT//Qu4exIqtdpeW2Ialal54X0XnqGOYgq+j2Nwd09z17 DyUya0X0NbCLRXF6ffWxiBQ/y/8ADBqLf7HTR9xWF+TbjgXEswSjRUcWbp+Jhlg+wleD 0Erg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=GYq83h8u; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 91-v6si4228008plh.296.2018.03.15.08.48.10; Thu, 15 Mar 2018 08:48:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=GYq83h8u; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932777AbeCOPrV (ORCPT + 99 others); Thu, 15 Mar 2018 11:47:21 -0400 Received: from mail-yw0-f193.google.com ([209.85.161.193]:41227 "EHLO mail-yw0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932427AbeCOPrS (ORCPT ); Thu, 15 Mar 2018 11:47:18 -0400 Received: by mail-yw0-f193.google.com with SMTP id w12so4899192ywa.8; Thu, 15 Mar 2018 08:47:17 -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=oaC+eeSvETSipBZQ8G9tGZdQO0J0x1rT3ToK/tMEqww=; b=GYq83h8uxmqshYOBrI9RSWzFK1l6eWQTV07c6EIQJm5GLWIPlSu4I/Cli+W9zAYrUj saepf4CSyunEWKBQXC9t3P6kPKX2JI9irxSNNx2Xc7zh6x2p0hxW98VLvQlbBIJl18xI Qohy+EGv2NgmHRlvtPOSOg8FZ17VCU5jo4mO1Vt5LMN8gNaW3NbTlA0OKUbiCOyFKI/G 9bdzaZfqu0we5gWmmWTbQSzcHepb1Tl7sTBqgVjabQcorl2CnKUDmpV2v9PLbjI6siGW N2F0cuMBgkRLGN7WJwKseyguvA2YNA59yD+Rd6bmAKb4q9vJUDEMucAQedWjui+nhA5N vkzg== 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=oaC+eeSvETSipBZQ8G9tGZdQO0J0x1rT3ToK/tMEqww=; b=IzK9J2OnOfKe3OC+uEQVOp4/GdetvS7fJDbKjNr2Ve0R6xxPC6nzMlIDDLedRlYCL6 kn6vrMh6shp96+fyb/h2BjzutzjoNekt+Db9rYKwpIkU0lB7357ZQrrXDv6MjZP60joP BLrRqYZSvhMlsyYOnFZuO0EiMA32aBgqCx/4iDaNgKxBGjjk+Q71mqHRnXuSLM5Cgem0 RmAob+MTJsexhYB0oanEg0qz2Od4yx67acKLopPsWoAg4MhWUlZqmpxcmUrh2rDkU2ew LK/eEUufbUwX1yCcu+SdKDa2/SJnMA5lNS88VYEP83FiLRRd+ube8YZHyP2r8kfLzgmF ns1Q== X-Gm-Message-State: AElRT7EyBUzbN+/ORxmPoOtjKL9lvCyvCXY0bz2mg6DALOQCyUmhHCkN LckbHqtv4Sg6Hx2p1qOaK9E= X-Received: by 10.13.209.132 with SMTP id t126mr1492493ywd.126.1521128837519; Thu, 15 Mar 2018 08:47:17 -0700 (PDT) Received: from localhost ([72.188.97.40]) by smtp.gmail.com with ESMTPSA id t131sm1972753ywe.77.2018.03.15.08.47.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Mar 2018 08:47:16 -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, linux-iio@vger.kernel.org, William Breathitt Gray Subject: [PATCH v2 3/8] gpio: pci-idio-16: Implement get_multiple callback Date: Thu, 15 Mar 2018 11:47:11 -0400 Message-Id: X-Mailer: git-send-email 2.16.2 In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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..ef43a37ccaff 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 mask_word; + const unsigned long port_mask = GENMASK(gpio_reg_size, 0); + unsigned long port_state; + const 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; -- 2.16.2