From patchwork Sat Mar 17 15:51: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: 10290901 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 799EB602C2 for ; Sat, 17 Mar 2018 15:52:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6DBDC28E90 for ; Sat, 17 Mar 2018 15:52:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 62A2A28F77; Sat, 17 Mar 2018 15:52:13 +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 0CAA728E90 for ; Sat, 17 Mar 2018 15:52:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753546AbeCQPvq (ORCPT ); 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-Google-Smtp-Source: AG47ELvSbGZ/HeLo+V4avajzMrvlSL39vw5Qe0/FapRZ/6Db7ZMa7ZnBi+fA4vzyY2mE4QQXZtwAQA== 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-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 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);