From patchwork Sat Mar 17 15:51:48 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: 10290897 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 231E960385 for ; Sat, 17 Mar 2018 15:51:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 15D4D28E90 for ; Sat, 17 Mar 2018 15:51:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0A3F828F77; Sat, 17 Mar 2018 15:51:59 +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=ham 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 898E928E90 for ; Sat, 17 Mar 2018 15:51:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753861AbeCQPv5 (ORCPT ); Sat, 17 Mar 2018 11:51:57 -0400 Received: from mail-yw0-f194.google.com ([209.85.161.194]:41577 "EHLO mail-yw0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753847AbeCQPvy (ORCPT ); Sat, 17 Mar 2018 11:51:54 -0400 Received: by mail-yw0-f194.google.com with SMTP id w12so8923265ywa.8; Sat, 17 Mar 2018 08:51:54 -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=FgdzAYkd35mvy5DoHUhCKyZbh1sE9eAZUNU1nPQq2DE=; b=lTk35chs5q+P3Nhfw+ollIEZ6EqpFeJGAKYnPAQSZEkE3lutDzF7nf1gYwo543FbeE H7Ljdh1kQ1lBLWQqcZ4RWxDsgho4GmHt54u9IJt7SUqLn/J7xMO2vciDAfmaDir6kA+h hwC3jhBmoXZ0iVycsCHKXvnQ14LYrzkTAavSQLnEQTOwkjRzUN/RpcBMi+kaFZMJ9ab6 lhvEdktGbBM4zyCVDKP/Qjjszkm+AIvF2ct35wtJWhmptm7AvUfiCtwKDFXne8NmVSSN utpFS+bXryw73gBIX98bHl6zIZDKyxJ8P61Yv8fKE6FkC2BTcXy5HijpNrD7B82GvTOd kn2Q== 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=FgdzAYkd35mvy5DoHUhCKyZbh1sE9eAZUNU1nPQq2DE=; b=kx081IE1Wm++/rrsdz+PyisSiWTNFd4aji2qHUdmaWeJXHRULjg4+Uq5uS8JZKNobk wFlCbz+o8EzMPBgkt2tmkk0tSZDX/ZplleOCqYLPER71sZq431RcDfg+EX8uZgVAQDnt CV6N8cySWyklbZLbuaYi2VKFUX7W2r8hXv0lY2hWMe9obVF4fB1j8dG4COGlawgzu7W2 059sl4Gt0BmkwNp3FQLu0PEX29j136NvJB6NVC8KOb6SLdooNaM+SEPYjVQB+zOeAX8y 8rIKMtemkm9+zRWXTk7Gx1zDi8vzQNuz1rV9ylqEX/83KWGmYwHeg4jPzccL4kJ26U/Z dtIA== X-Gm-Message-State: AElRT7GL5xb74EdadAFbApsIfsY3ZTerWIqXI5e/XjRSxEsaMbwC8bjB TaPT3Mup1AbtND/fpV4QhfM= X-Google-Smtp-Source: AG47ELu5J5uVi3xizlX1mtZVgC1rts2Q8QLS6HCPquBvsU4vnM+FzCwK5Zs6TQPOLwL6Ny3ykhXglQ== X-Received: by 2002:a25:870a:: with SMTP id a10-v6mr3624368ybl.477.1521301914194; Sat, 17 Mar 2018 08:51:54 -0700 (PDT) Received: from localhost ([72.188.97.40]) by smtp.gmail.com with ESMTPSA id k132sm3957363ywb.3.2018.03.17.08.51.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Mar 2018 08:51:53 -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 7/8] gpio: gpio-mm: Implement get_multiple callback Date: Sat, 17 Mar 2018 11:51:48 -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 Diamond Systems GPIO-MM series of devices contain two 82C55A devices, which each feature three 8-bit ports of I/O. Since eight input lines are acquired on a single port input read, the GPIO-MM GPIO driver may improve multiple input reads by utilizing a get_multiple callback. This patch implements the gpiomm_gpio_get_multiple function which serves as the respective get_multiple callback. Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-gpio-mm.c | 47 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/drivers/gpio/gpio-gpio-mm.c b/drivers/gpio/gpio-gpio-mm.c index 11ade5b288f8..94b86fca65ba 100644 --- a/drivers/gpio/gpio-gpio-mm.c +++ b/drivers/gpio/gpio-gpio-mm.c @@ -14,6 +14,7 @@ * This driver supports the following Diamond Systems devices: GPIO-MM and * GPIO-MM-12. */ +#include #include #include #include @@ -171,6 +172,51 @@ static int gpiomm_gpio_get(struct gpio_chip *chip, unsigned int offset) return !!(port_state & mask); } +static int gpiomm_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, + unsigned long *bits) +{ + struct gpiomm_gpio *const gpiommgpio = 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(gpiommgpio->base + ports[i]); + + /* store acquired bits at respective bits array offset */ + bits[word_index] |= port_state << word_offset; + } + + return 0; +} + static void gpiomm_gpio_set(struct gpio_chip *chip, unsigned int offset, int value) { @@ -268,6 +314,7 @@ static int gpiomm_probe(struct device *dev, unsigned int id) gpiommgpio->chip.direction_input = gpiomm_gpio_direction_input; gpiommgpio->chip.direction_output = gpiomm_gpio_direction_output; gpiommgpio->chip.get = gpiomm_gpio_get; + gpiommgpio->chip.get_multiple = gpiomm_gpio_get_multiple; gpiommgpio->chip.set = gpiomm_gpio_set; gpiommgpio->chip.set_multiple = gpiomm_gpio_set_multiple; gpiommgpio->base = base[id];