Received: by 10.213.65.68 with SMTP id h4csp665238imn; Thu, 22 Mar 2018 06:05:26 -0700 (PDT) X-Google-Smtp-Source: AG47ELuYVX0gEUHnzxJCasZwCWI74YSmRg5emEp+wBc3X7kJmey6LTwnhXLJG44XkUjJR+ouzyXx X-Received: by 2002:a17:902:900b:: with SMTP id a11-v6mr24461196plp.366.1521723926609; Thu, 22 Mar 2018 06:05:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521723926; cv=none; d=google.com; s=arc-20160816; b=EizlgkYqb0gHohyKIP8RPUi+AMYS4EBAtPHIC+56lKXZnVLGlUE5G44yj5cebM5ivN zX1P9d+RoBXwAE5l2aXc2Ue4qOnbvBajX+Q1x7rgXgSSWYuCz9TUExHxA5cAtXfDYfvx 0d7lBq+MfU2//tLHMSC0zQhYA9s+2zLuqvVls/c/m8N0tnG3gBNfNOeeUVZ0nrGQOD9Y Jb+xV4zrCkIdw/mKUOCMlT6bHr95DQpfSgNO5AlVOj9xYzEN28hh115A4YVh8wGreCoB mrXXvk3doFN6VuD1Ai5f2kC3BjYO8Mejvw+P35yBxy8zOWVKZris4pHnhTDSJsTuMcrD QD/A== 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=4TiTZT2rxlS9JLFeREH+g0GEQrlB0+NQ+VnL7eViW84=; b=JpxIF2qH6vI8YBYEnTBhYdmnARvOQmbDkfEUs+CYanJFv+YqaYrb+ZD8oQlx/SVA+i oP+5AjurRcqkSqq3iENGJAKty7hRsKFIPnjOV9zGqGfFAYs9+DqQkrrhAVOl32o3sW2D DoOSCiNE3v00mWh03OvLW1Sa9/sj5uJycxDb8TKH1iReaDt9kVrtuG/WRYpeDVW5N1mz FWz+ZYynDDq4q2tQ5S3RxpZ3jSD8UITpNsB7GJBuWqamdGMPVkMbJxx977TewIi83uRP L+xs+RAFwQjpCdcaGTljx+36ns7+OzgoMP/+XDkHXeO1haewGi+cpJGuaLAoeWfM3F66 aNbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gJANSanH; 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 r8-v6si6299991pli.12.2018.03.22.06.05.03; Thu, 22 Mar 2018 06:05:26 -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=gJANSanH; 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 S1755079AbeCVNAZ (ORCPT + 99 others); Thu, 22 Mar 2018 09:00:25 -0400 Received: from mail-yb0-f196.google.com ([209.85.213.196]:43021 "EHLO mail-yb0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755000AbeCVNAU (ORCPT ); Thu, 22 Mar 2018 09:00:20 -0400 Received: by mail-yb0-f196.google.com with SMTP id z5-v6so2874526ybo.10; Thu, 22 Mar 2018 06:00:20 -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=4TiTZT2rxlS9JLFeREH+g0GEQrlB0+NQ+VnL7eViW84=; b=gJANSanHCJdyjcvQu1sreK7QoCcVUDpQJT2Q3xkh7QCFNAXb0aOrIhJWQw3NpH5RYS ht3gBu/C8teMaXp8089n5b5j0dMGkjwDJkdALjwwtHy12OMgNGT5vVLXm71cFfy0lym7 oKhBs72Yf1vfuEo193y56QRJIB14f1TaaGr2g5crBvvDDvwHxaS1u6QR+xABJ+2TXloE VjxSjErX6iI8D1Lwt0Wg50L7le6ecT0GLMA+ophuzs8IbJSY4w8bxs8va9B00/ek8PB1 mdCCLNVC1hbDC2BOYl8kr2N9lWkMqH+yUbgZhk5HOoz+NDM5MK4D/aIMrBKTrdcFEFZN VkJQ== 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=4TiTZT2rxlS9JLFeREH+g0GEQrlB0+NQ+VnL7eViW84=; b=GKOILGdHxX/YS4IKZHw0pRm/SZNnac19SxNWGZh4wwJ0lfzM8jO6hgj8VTvOheoCdO jVM5xFB1CsnRDlj1uEjcD98bFuxykrA4Sjmsl+cOxRxBYevDecEePqEFqXB58BlPztck EIF7S9ZKBeNuiErX5UxjbulfCC91CsAWrfWVEuy/lohT3bWeltHqVJYYGzfSTpYtTtIG H0dCQB+c6w9+dLdtNiNMBauZAGB1vQ5Yx1E51P3oidFhcBjbThfPzUT0pRi/uxdtKOP3 /5KfCDVZsAFxDhK4PqjiYzCXBmahedEp3QgpOQnywwQC8xk4eQwHhjBnt5Xu8J8dLxm7 Ch9A== X-Gm-Message-State: AElRT7HZxmzGwVEXvPwag4rSmhtxQFzwD2aYNHpexuq6/AGf6fs5NdJ2 k/fMaZHHB4B+wCFey4Bnn7GlBQ== X-Received: by 2002:a25:2782:: with SMTP id n124-v6mr14721882ybn.307.1521723619639; Thu, 22 Mar 2018 06:00:19 -0700 (PDT) Received: from localhost ([72.188.97.40]) by smtp.gmail.com with ESMTPSA id g145sm949485ywb.61.2018.03.22.06.00.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Mar 2018 06:00:19 -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, William Breathitt Gray Subject: [PATCH v4 4/7] gpio: 104-dio-48e: Implement get_multiple callback Date: Thu, 22 Mar 2018 09:00:11 -0400 Message-Id: <35b31cc749162ce549d4d1a82f2d23889590d413.1521723192.git.vilhelm.gray@gmail.com> 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 ACCES I/O 104-DIO-48E series of devices contain two Programmable Peripheral Interface (PPI) chips of type 82C55, which each feature three 8-bit ports of I/O. Since eight input lines are acquired on a single port input read, the 104-DIO-48E GPIO driver may improve multiple input reads by utilizing a get_multiple callback. This patch implements the dio48e_gpio_get_multiple function which serves as the respective get_multiple callback. Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-104-dio-48e.c | 47 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/drivers/gpio/gpio-104-dio-48e.c b/drivers/gpio/gpio-104-dio-48e.c index bab3b94c5cbc..31e22c93e844 100644 --- a/drivers/gpio/gpio-104-dio-48e.c +++ b/drivers/gpio/gpio-104-dio-48e.c @@ -14,6 +14,7 @@ * This driver supports the following ACCES devices: 104-DIO-48E and * 104-DIO-24E. */ +#include #include #include #include @@ -182,6 +183,51 @@ static int dio48e_gpio_get(struct gpio_chip *chip, unsigned offset) return !!(port_state & mask); } +static int dio48e_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, + unsigned long *bits) +{ + struct dio48e_gpio *const dio48egpio = 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 - 1, 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(dio48egpio->base + ports[i]); + + /* store acquired bits at respective bits array offset */ + bits[word_index] |= port_state << word_offset; + } + + return 0; +} + static void dio48e_gpio_set(struct gpio_chip *chip, unsigned offset, int value) { struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip); @@ -384,6 +430,7 @@ static int dio48e_probe(struct device *dev, unsigned int id) dio48egpio->chip.direction_input = dio48e_gpio_direction_input; dio48egpio->chip.direction_output = dio48e_gpio_direction_output; dio48egpio->chip.get = dio48e_gpio_get; + dio48egpio->chip.get_multiple = dio48e_gpio_get_multiple; dio48egpio->chip.set = dio48e_gpio_set; dio48egpio->chip.set_multiple = dio48e_gpio_set_multiple; dio48egpio->base = base[id]; -- 2.16.2