From patchwork Mon Mar 12 20:49:57 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: 10277457 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 AC8D1602BD for ; Mon, 12 Mar 2018 20:51:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A054828EA8 for ; Mon, 12 Mar 2018 20:51:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 94C2C28E74; Mon, 12 Mar 2018 20:51:01 +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 3D98628E74 for ; Mon, 12 Mar 2018 20:51:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932313AbeCLUuU (ORCPT ); Mon, 12 Mar 2018 16:50:20 -0400 Received: from mail-yw0-f194.google.com ([209.85.161.194]:33751 "EHLO mail-yw0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932525AbeCLUuD (ORCPT ); Mon, 12 Mar 2018 16:50:03 -0400 Received: by mail-yw0-f194.google.com with SMTP id l200so6401097ywb.0; Mon, 12 Mar 2018 13:50:03 -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=9f18JN+BWd/gT8Hh1qfUHDGD7k3kMF/bONsOVu5XxaA=; b=RD2996o4D/JrVS0wJM+6zwvXVYEkbt8z/wbrAObUBWZU0EYplTcBB6iuf/x8gzBhPt Z2xZ4x+Eh10AYE0dahzqYe95TdGngUybNNhc6iUySB/MBsajgrYdt/pdOez9qsOhxYBL bCOHp/14K84wxRwP/IiNlKI+gXUXyqTYCmEedCLyH+zGwkpYtPiuDkQhXebJ4xiZeHEw XCcFqfUq9N4MsDTHPaj7wQy4OruVUuX3xH30Y3V0KaxWcuQ3Y8JCZqNx6rRQdHlSXSQs VlBZatwuXHkMOAZiP+x9wgwJoHITo3vVtUjcP9LeyeBJyQIhTX9s6CJLBTxKVvBIr3vk 1MNw== 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=9f18JN+BWd/gT8Hh1qfUHDGD7k3kMF/bONsOVu5XxaA=; b=Hvj9w2BsTWjOpq5f/rINlcP1nd6/fHZC6KLoz9mMdQDEIj92Jm/jp7YKNVAHDk83Sq Z9aCAlnNuj4F17+QQA/iFM5rQ5qr4cucwUeqUYPqeV3LU696JJPr3YkInjcTCTj5hMLy VtQg6gutrPK4JcuWZOZA9RwvJoSjk1fGZeSIwBAnVNPX0KwHqtQo8sNt9a68ppGA7uel uEcNDCWlCpCg2H8eQ+VVXTsFtkZOMZH6jzb4AapSVKxwKiLtKRRDEgGuXyv3IQj7e/Cg QXUOBINwZEc31fhggTjqa+TvS4UnCv26w4BkNLnSZFoqRvKvNsXQdxi7j9+xuC2SQAm4 +jAw== X-Gm-Message-State: AElRT7HjCNPmOmqmrbwtczs/Hf3WOC3F606NQ9ZsfCJKw2/RlPMiWcM3 +y+KXCBn8HhH6QbxPJG9iG0= X-Google-Smtp-Source: AG47ELtnJPQ6lhzCwMOioBNx3IPmPuApnCVGXxvR4iyx0UezJoypKUCgfGNoW3keprl0o3e1OOqyRA== X-Received: by 10.129.114.213 with SMTP id n204mr5761216ywc.513.1520887803261; Mon, 12 Mar 2018 13:50:03 -0700 (PDT) Received: from localhost ([72.188.97.40]) by smtp.gmail.com with ESMTPSA id e188sm2629363ywd.37.2018.03.12.13.50.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Mar 2018 13:50:02 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, William Breathitt Gray Subject: [PATCH 6/8] gpio: 104-idi-48: Implement get_multiple callback Date: Mon, 12 Mar 2018 16:49:57 -0400 Message-Id: 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 | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/drivers/gpio/gpio-104-idi-48.c b/drivers/gpio/gpio-104-idi-48.c index add859d59766..d82139c3117a 100644 --- a/drivers/gpio/gpio-104-idi-48.c +++ b/drivers/gpio/gpio-104-idi-48.c @@ -88,6 +88,46 @@ 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); + unsigned int i; + const unsigned int gpio_reg_size = 8; + unsigned int bit_word_offset; + unsigned int bits_mask; + const unsigned long reg_mask = GENMASK(gpio_reg_size, 0); + unsigned int port; + unsigned int in_port; + unsigned long port_state; + + /* clear bits array to a clean slate */ + for (i = 0; i < chip->ngpio; i += BITS_PER_LONG) + bits[i / BITS_PER_LONG] = 0; + + /* get bits are evaluated a gpio register size at a time */ + for (i = 0; i < chip->ngpio; i += gpio_reg_size) { + bit_word_offset = i % BITS_PER_LONG; + bits_mask = mask[BIT_WORD(i)] & (reg_mask << bit_word_offset); + if (!bits_mask) { + /* no get bits in this register so skip to next one */ + continue; + } + + /* compute input port offset */ + port = i / gpio_reg_size; + in_port = (port > 2) ? port + 1 : port; + + /* get input bits */ + port_state = inb(idi48gpio->base + in_port); + + /* store acquired bits */ + bits[BIT_WORD(i)] |= port_state << bit_word_offset; + } + + return 0; +} + static void idi_48_irq_ack(struct irq_data *data) { } @@ -256,6 +296,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);