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);