Received: by 10.213.65.68 with SMTP id h4csp38932imn; Thu, 15 Mar 2018 08:55:15 -0700 (PDT) X-Google-Smtp-Source: AG47ELvwCVSVaWFwlg4Bf6coZWNCBXklw4uB0VYvReUqRsKBhitZJg86iQXkC4VtBB5sgRmzbgq/ X-Received: by 10.167.129.24 with SMTP id b24mr8076410pfi.183.1521129315071; Thu, 15 Mar 2018 08:55:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521129315; cv=none; d=google.com; s=arc-20160816; b=kBUbOSe9LxsHkiZBt3c4yuXuWRvGiX7jNlUTxCXNhvOZipEBq/us7ko9GGH8zf3o05 bRwnX1YpR4W3djCo4j9aKLps8rfFPkWJqQU6y0RNqa1ohrfqQCadf5HcOqZxQTqlQqVv 0e1xP6eqZwTyEV0PcVjP+RGQKG0Zk98V3WvDcJSm20wizp42f+3cfREzo3iImKm38AMS YeAaijhFICZd2jlRoBD0dI3e3GR5dHZUxdSyi9gdbqASThkmUciUqvb9kfAMuERx6WwL XGlXBapJ8DpRMVhMtFU7d3+no3H/MKNblIEzVy86upB9lOKb8FI2vYPm1dzj90XUU5Rr YW4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=yFrvuwmF4wZClOqqeNrQ4n6lVfIANwYffSZYqb93XBg=; b=F0YxzncT8Tiau3c3lB3PM8mHH7ElI6/laTuXwDRc1KJDtM+lTGJn1g9S61RAl13oUx jQGpmGcPKOC73rBK7uioQYn0po8sjW8h63LnSNbwK48zYEfYfTifcLTelRyxFSHeqsuP pa3qQLs5jmk9C2DhU4smj8RDoUilyP1qAmLKYPjgGYBeMRfzAHhSNeXkxWKfDhQUx6ab PnXnshadx5bw/2aLDzrN+feOgWmforM2jTNgWe+Z6sMAdKrhIeGjTmj9Al1f5VRIcbkB EvN1aj+qVd1pnm7/F8769cKxxUVY+MJ7T3eKvfMmZok/CLJ7PWT763wrqRIt7AYC321S 0DRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dYFy+Hdb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o12-v6si4209459plk.449.2018.03.15.08.55.00; Thu, 15 Mar 2018 08:55:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dYFy+Hdb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932825AbeCOPxi (ORCPT + 99 others); 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-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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]; -- 2.16.2