Received: by 10.213.65.68 with SMTP id h4csp422097imn; Sat, 17 Mar 2018 08:53:32 -0700 (PDT) X-Google-Smtp-Source: AG47ELuwUtBVNOE+Yh8xn+oomO2GH7Xg7B1Ak9e1Z2xQYRmg6hgMOvpsFs7zkYQuAVB5Fe44jXsL X-Received: by 10.99.186.72 with SMTP id l8mr4755805pgu.410.1521302012402; Sat, 17 Mar 2018 08:53:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521302012; cv=none; d=google.com; s=arc-20160816; b=T2kCBOXF7JjiUZ/Uy8sc02pNBCQZ6c6tojjunHP0Cru6OYxM0rkqfKykkedCYOmr4S hrIsCkT5A2irsxGmVjIpCCV0+LVXrj+YRbp41QCsNd3Ak/FDIEMPZB218CojAxUfkEfs XPlcU3fd4IhvHXCSP4GCVvxvSVtaDVcLfbxiCwul2Dzf4B/3aiTxUca9xTb2HHjDrjXa zcRu4ECUykSGHKi5BlcbXmv1cgJ8/H5QHUyWuXGO9iLdk9d83DrT8U1hI//tQN3+CTAf 440yMfKyB5m8qMy+J3MFcPvpS3OKb82FE8l8V/N6QQ4p7cP9W9jK/dh5itlPoQ30rGU7 b4GA== 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=FgdzAYkd35mvy5DoHUhCKyZbh1sE9eAZUNU1nPQq2DE=; b=Kh1kb6XOrA4RbQ0+JnCHafNKw5n9wUAWqzyYJJimV/0g/PVi0mcYsQAIKWsiweUObc /PkfUAIrVPV4GYDTrOCdypDQA9en5AIrdIrb8gdzDJixVe+aDwj4AhhkL+DPQzN2Wiqu PC3irK3nU3dfnXuWnzE11ful573jhQ57SN49Lfc0SS1AuOeVFNPrIQQXF+Qygw5XBdhz t+FlmOzNpSIBAna+o25hSn2YfGs36vJO1Qgfn8f78hOKuNCNhXCDiJzJFoPdnAreQhhw 0DpF8f8WX7a6bm4SePcFFIWvMsXP2IV3aJHFT1O8jtxpYILCyA3Vch+t4LixC1dht1L7 WMkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lTk35chs; 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 l5si6650024pgo.397.2018.03.17.08.53.18; Sat, 17 Mar 2018 08:53:32 -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=lTk35chs; 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 S1753875AbeCQPv7 (ORCPT + 99 others); Sat, 17 Mar 2018 11:51:59 -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-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-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 | 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]; -- 2.16.2