From patchwork Thu Mar 15 15:53:17 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: 886309 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="Gby6Ug+Z"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 402Cnj02xvz9s2M for ; Fri, 16 Mar 2018 02:54:17 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932404AbeCOPxZ (ORCPT ); Thu, 15 Mar 2018 11:53:25 -0400 Received: from mail-yw0-f193.google.com ([209.85.161.193]:35829 "EHLO mail-yw0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932755AbeCOPxY (ORCPT ); Thu, 15 Mar 2018 11:53:24 -0400 Received: by mail-yw0-f193.google.com with SMTP id c20so4927582ywa.2; Thu, 15 Mar 2018 08:53:24 -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=rGzDOGiFHbXxrpPvsk2rmMzjICyw2CxgzfYECs2EGrU=; b=Gby6Ug+ZHxa9xSX3116XI/H6TTYHTu/tTEIbp7Ucp4EjeQgepwzJWRwPqTwRDfS5Zc M7jKrD6AbU4L16iHOhGVjhBOYRkz2J4mXZewWyh4pOjooX3FOtJPAwkVpNk87ww71FCr pq6oeWf9IDjRjStXACdbdmpA7aBoB8ak8dZobBZd+HN2pqb16tGtsbu5sgQJLEGCVjAT iEbTJkanSy7witg/0q6H9Q3NeWM7lI1giQl3vIkQBhMTZTwRF/S9HgJRarzDg5k3loKi dO6Sv/tuQcwp0A5tN0dGaoC5cKoc1UixB0sQ5EyCZvASHafi1TqkGO1VbqwQBq4+d/+X ZGKg== 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=rGzDOGiFHbXxrpPvsk2rmMzjICyw2CxgzfYECs2EGrU=; b=iJn38ifibzx8aQE3eBGeIndNBISmhJrXVAsaXMXB1pLE+TYF/haZE6fcDym8XxpxSb soi7BsVt/CAPWnRFx+ar5B5GIM9aD8AZD9h/qLSZQ5BJSFe1dtX3Vqhpn9wQhflG2yK7 2ssWilnlgsT59lQgxnj2mttHElq0+cDwKWsMNfCDBvIqmIoQGfd47OxR5x5K5jK0x0uv k2Qa79WH5sgzOeu7/oXJera/USWVRiWQAAy9KbXDttepDp4icVBfpdrdzSAp/nnZlyca Qz3h9BCMF7WVcklwSS0AOHh9owA4AY5zSrhebhKO9Rjnw7Lr/yp4i3s2tSleqQ23VkVJ pZ4g== X-Gm-Message-State: AElRT7H1ALdKC10zMp8tDd2L9LMaFpXHCTpr0J8HkmM7yDTyVa9cF2W1 lIJx2eXwRNLP5OkDp2Jb5Mo= X-Google-Smtp-Source: AG47ELsxvKAemJIobekbrLGhc8f38kWTRpHqvqMwTus/woXdNHn//w1CzDMW8h+z/maA/7vUiQzLyg== X-Received: by 2002:a25:ad96:: with SMTP id z22-v6mr6142115ybi.296.1521129203836; Thu, 15 Mar 2018 08:53:23 -0700 (PDT) Received: from localhost ([72.188.97.40]) by smtp.gmail.com with ESMTPSA id y195sm2071527ywy.103.2018.03.15.08.53.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Mar 2018 08:53:23 -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 6/8] gpio: 104-idi-48: Implement get_multiple callback Date: Thu, 15 Mar 2018 11:53:17 -0400 Message-Id: <5ec68441ce758b17c21264a1a1bb5ab98b5263e8.1521128287.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-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 | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/drivers/gpio/gpio-104-idi-48.c b/drivers/gpio/gpio-104-idi-48.c index add859d59766..1beb6b0591ee 100644 --- a/drivers/gpio/gpio-104-idi-48.c +++ b/drivers/gpio/gpio-104-idi-48.c @@ -88,6 +88,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 mask_word; + 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(idi48egpio->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 +301,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);