From patchwork Thu Mar 15 15:53:28 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: 10284911 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 5CCCD60386 for ; Thu, 15 Mar 2018 15:53:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B8CE28AD5 for ; Thu, 15 Mar 2018 15:53:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D83A28AFA; Thu, 15 Mar 2018 15:53:39 +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 D16F428AD5 for ; Thu, 15 Mar 2018 15:53:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932710AbeCOPxi (ORCPT ); Thu, 15 Mar 2018 11:53:38 -0400 Received: from mail-yw0-f193.google.com ([209.85.161.193]:38202 "EHLO mail-yw0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932665AbeCOPxf (ORCPT ); Thu, 15 Mar 2018 11:53:35 -0400 Received: by mail-yw0-f193.google.com with SMTP id y203so4919793ywg.5; Thu, 15 Mar 2018 08:53:35 -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=yFrvuwmF4wZClOqqeNrQ4n6lVfIANwYffSZYqb93XBg=; b=dYFy+HdbT3DOkPYGrjwQoVWkNIYPfJ2ElkAyhDdFoW5sXCnEYk/Api+sVyP/nDv8NB /zhMws8SNA2Z09xF++M5KLHt8BWNimB7YGLrw4kYGjl4eIt+Z0qWSA8p+FtCZp2Fil4L BaHoR5LzU+sPQslJUexKwTBZiT+MBbShrosod51p03QdsmSP/rURz9jE0WV6XgTrnneN hLSsvGoH+5IH+5KsnoAoZ45H3HW8SMWVj8k4Cf1W1O3cqqxCkzRXbRomZ3rABL8Uc44B 09379dEgVxgJosTxRzsZ8vjrGX36L0ehkwv62Or3OrMgfrh9gWgOuftNbGY5a6TBCYdb KTwA== 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=yFrvuwmF4wZClOqqeNrQ4n6lVfIANwYffSZYqb93XBg=; b=BauiMKtVzvKjilMM/k09dJHwRgB5mshLBB6TNghMpYPpJjd4D2tu+AkMYsELRaPEFZ J17JzsArCg4RWd1Kbn7H0k4aBGkyEQKsy1FOCPRrUORRW8KO0tgWOrWi69TznAnPcl+P YEDYEu3pka9Q0zGUFJgQ7pDuYiykfhLMLq9kH7jbol9HVA3m9qPSKkCT50Jdn2uuknGm gTfcQDcNVlgIN2jZte21CovpWiLoWiiyxKQ7/XyTfMs+yLjXJq3SKbIzRzgr4OwLpRXb ofJjuDsdCFxk5+Ri9F2oUgkNXjf+W9Avin5qcmpFiBQGkXoF5EnpOmNjj10rDN8Zmv1c pE/A== X-Gm-Message-State: AElRT7HaLgUzMtZpZk/lKTHKhZG9FQbuArHT29z++2kL55kK4PvICX9y rMqFK684lRsNHShlHITtzUGnMw== X-Google-Smtp-Source: AG47ELs6v6MGwjA1Q/KpaSCSCAogQFwMCR+a7vDTD93kkv7A7h2vY8u1OrGSh18LpI8kQT6QRZpKOQ== X-Received: by 10.129.226.65 with SMTP id z1mr6331357ywl.333.1521129214817; Thu, 15 Mar 2018 08:53:34 -0700 (PDT) Received: from localhost ([72.188.97.40]) by smtp.gmail.com with ESMTPSA id c15sm324855ywh.38.2018.03.15.08.53.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Mar 2018 08:53:34 -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 7/8] gpio: gpio-mm: Implement get_multiple callback Date: Thu, 15 Mar 2018 11:53:28 -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 | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/drivers/gpio/gpio-gpio-mm.c b/drivers/gpio/gpio-gpio-mm.c index 11ade5b288f8..d9be9ebe41cf 100644 --- a/drivers/gpio/gpio-gpio-mm.c +++ b/drivers/gpio/gpio-gpio-mm.c @@ -171,6 +171,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 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(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 +313,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];