Received: by 10.213.65.68 with SMTP id h4csp421959imn; Sat, 17 Mar 2018 08:53:11 -0700 (PDT) X-Google-Smtp-Source: AG47ELtDjBnDd7c6WEbH7dFANr2Izd3Vs5QTG2BwqEHORBOfcIwiT8DOfHe71iOFSwiCkfsnqehN X-Received: by 2002:a17:902:bd4b:: with SMTP id b11-v6mr6085568plx.225.1521301991137; Sat, 17 Mar 2018 08:53:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521301991; cv=none; d=google.com; s=arc-20160816; b=jWd1MIFZP99d7w/uRsWV36dH1ndhkKSYfKozI/dhoRDOfAKGR8/WeWHJasNtHvA/d8 A+mZAnH+4TN8J+PGq5FOr7MxdGJdbUL7VTVrM9yhypX6Rhm77RVtyqVzKuYVaxDsjsnM nfwfgvJC2hJ023kBWIi3OzCkiNVjnb5lVg9/EKQcnnecBqRsmCKRvgzY7R7cV4yOupCE quqG8713pztnI7uAs5NBQL3WIrSebbsqc+a2d4ixyWPXJdD+yJfz3GKCCE+TerGbl0hg wv6IWmyql3Kxopbhe1diEl1/SuJEz7AekVNy98gXAGGQ+ADP8Z6RXUhcWGfyCZL4X+Yk yqBA== 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=HCBzrINXHalnr26+o71ozKJq3pHswpLC4gs9j9o6Iz8=; b=gIm4LLAo34MdpUx8MUK/yqlNNqVd3EFPolJ6Dd1l6GEJCikAj+0dHVPucfgulXc7yY makh2LTET2N/H5tcyZ5/dlo+XPcSmcQ8GPqVdJijCv9+xmeIBWtmJCAS27MmwVnZvoxE nZXzn8Uqt29hp76HHKFfil+LK0PpLEA9Dr73HxbvpvepaBpd+rolRQcC5i5oh7BzzqrF OyVgQBsyzIscjz7h+WCalRnDFRdPzmC4ec+QlPdnJRzjvbTrO1e+ppvFLY/stbCGw1wi LIMi9nepS2pPJ/OOX2and+xFVvrJtANDvSUz3RvaR0y4RW0BxAYDBjxZhrW8PAkZRkmD Qm/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=spvQ8UPm; 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 n20si6841800pgv.214.2018.03.17.08.52.56; Sat, 17 Mar 2018 08:53:11 -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=spvQ8UPm; 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 S1753839AbeCQPvq (ORCPT + 99 others); Sat, 17 Mar 2018 11:51:46 -0400 Received: from mail-yw0-f196.google.com ([209.85.161.196]:46421 "EHLO mail-yw0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753464AbeCQPvn (ORCPT ); Sat, 17 Mar 2018 11:51:43 -0400 Received: by mail-yw0-f196.google.com with SMTP id v68so6347130ywg.13; Sat, 17 Mar 2018 08:51:43 -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=HCBzrINXHalnr26+o71ozKJq3pHswpLC4gs9j9o6Iz8=; b=spvQ8UPmDk+MoWMRqQj5hatSAX7u4kh+jaCslrXSoO+ZEFjmTFEYAPGcXQOp7Jm+Z1 GiDDVyIiOfN3ibojfZ9U8VZlbQD3JFtqc9oJXQeQNl8ag4rsHvDiqL+OeaXkxS5qvR66 X1/CvCe1NvEH5frf49v7tMB7PoTMTi2Et5jwRDujg7Krn8BHe5R4w9yZgccf3BVCM2CH X8H/IwnsvJKD8kqCmPM+oT4+8Kvu9lqniC9sy57fBOnbVjZTP6zRNCddzDyNO+yRGOdb dIs6OCLKn7Uze0GKmvwQAO0uLT1JtInjVJZqiXF3C8RaBgwPPx52ezjorulFB1U9g14c gIIw== 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=HCBzrINXHalnr26+o71ozKJq3pHswpLC4gs9j9o6Iz8=; b=DJIX2q69sxSR+itZOb9S9kPe+e1K+z2mKTGktG+/0k7zmeZpMI6dJEx+eH8BZmw0N+ qvj1jIVRjqp5EZLGVdZuQiGizj70G3cgguoDYDxs7Mt1FE8j1Fsfn+GZOaJsCVW+a6ae SoQ5Ja4sXyDTU6pQAEflq4uP1KN+QtR3Eh2bgj+TXBgk9ekmxWqWY+ZDnkbimygt1R8C cdkyR/DGnt5MtLGNJuIU4U6BgCIRAYyF0XBFwjees13bWSfSP8AwjzFE4LiaJAzGSA4F ZKpZ5V+dhSik/ZYF0vTvjjyv6HWy2KLWSM3870ZfUE2+FtpfMsXyGIXksHYdkCOCmIwQ 9D0A== X-Gm-Message-State: AElRT7E1owRHYFTDWYIdwdISE0S9KuHIFcjSvM2TpC5wzqMyHdPynVfI +A9lzBm36FpBCTqYCXVBRtQ= X-Received: by 10.13.249.6 with SMTP id j6mr3565402ywf.358.1521301902775; Sat, 17 Mar 2018 08:51:42 -0700 (PDT) Received: from localhost ([72.188.97.40]) by smtp.gmail.com with ESMTPSA id a189sm3617297ywc.51.2018.03.17.08.51.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Mar 2018 08:51:42 -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 v3 6/8] gpio: 104-idi-48: Implement get_multiple callback Date: Sat, 17 Mar 2018 11:51:37 -0400 Message-Id: <950454628c8beac8a3f6a3163fb04141d41d00a3.1521301345.git.vilhelm.gray@gmail.com> 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 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..2c230415eeba 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, 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); -- 2.16.2