Received: by 10.213.65.68 with SMTP id h4csp421565imn; Sat, 17 Mar 2018 08:52:05 -0700 (PDT) X-Google-Smtp-Source: AG47ELuEA3FM7jjKNHoZNPQrB6Io5PTNoZ6kOhIUC3mWj0I2CiIWLQXhnTG2XAf53iFYj3F+AlGG X-Received: by 2002:a17:902:264:: with SMTP id 91-v6mr6161233plc.178.1521301925212; Sat, 17 Mar 2018 08:52:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521301925; cv=none; d=google.com; s=arc-20160816; b=tZblvmBrRqwj7T1ikU2/FnNUihg9KsvwzNRAC9V0d3D3Dpkc/5Al/EOCBA4AxVUrla rlJadaZMtycw4b8wDlYPJ4S4K6GuamX86VL98j19L8HOZVZi1AYgZDKOnS6NswvKlvFX Q+MlZmhNw5Hh3YN04rZAf505PKVqVOXnVHKmYQU+LYaItCxiq8WMkX3Vfu9axTNLbuNp yXrV6P4gWU3x8MPl8F4+XrfPCDvOjsisH67MKM8QBLvT9IKKq9AvB0shs2s/B3SnXzsj oOzWI2FxjAgLuk3LmwEzPLCN+Efo/B5aj22RYxKHfNmNT+v4bYmLPUruQ2NTh0Yt0qde 44QA== 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=U89RbItY4u8Fu/uqNRZXC96rkbxbFy4lO2gWl468OUM=; b=JG2hIX+w23mDyW3vLCxuO6H88iuvomLD9vBcRVsL7EtsbKbNsCLes+DU2Ib2t7310t U8ce9APqDnNSxy5wVXXt2c1mQno37X7gq3Ypo75DWZpkur0u8O26GzteJ6oF0XaM4Aad mR2XwyYQaEW6kW48QiOen8+Dui4yUC88fyNC/vQAMEXgm73mmy8XidNLjQ+KGvFgx/y6 52wrbUNdESLhIRWZth+TxOhzrX83vJR4X554ifg6if/UEinqnzTmBf8hdik0fzmssSAV NTMFMwdRz8/OwA4Ejs7NkyRVl7YEdVBrsEaPns/TUx+ezrWUrWeQiKpkCH/+Tt6MyLFM Auxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WfmFqBEh; 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 u8-v6si8877627plr.50.2018.03.17.08.51.51; Sat, 17 Mar 2018 08:52:05 -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=WfmFqBEh; 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 S1753743AbeCQPul (ORCPT + 99 others); Sat, 17 Mar 2018 11:50:41 -0400 Received: from mail-yw0-f196.google.com ([209.85.161.196]:42499 "EHLO mail-yw0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753700AbeCQPui (ORCPT ); Sat, 17 Mar 2018 11:50:38 -0400 Received: by mail-yw0-f196.google.com with SMTP id z82so5939653ywd.9; Sat, 17 Mar 2018 08:50:37 -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=U89RbItY4u8Fu/uqNRZXC96rkbxbFy4lO2gWl468OUM=; b=WfmFqBEhkgaeCgtKsLyMZjRxUSc1RIu74wYjqbuNWrrkm1mNogEK6BQ+Avros87ph0 Bvs8pYE0yBT82atxD67cHD2asC7DmVOaJKZuzupabSJorZH1DVwI+xQJVaSn1d6SEEly XBsY2k/S3fLW4XdXeVZ4gGUV3Ni6wImCkbFoAqCaydEchPUFrSPFg6SBAv+k+dkGKCO5 Im43+LsoSAXKluMmFfffvfNjWvIXbYRT0f8AsUUpzllHN0KGNFz0cNIasWZ6Ux7SG+xy NYFSwyUiPXA6Ond9UYPilpivVr6el8lNbTlgpJ+h0asBvkG5ygF6e30qVwCkXeLpjmQ+ sujw== 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=U89RbItY4u8Fu/uqNRZXC96rkbxbFy4lO2gWl468OUM=; b=UWR/wcX+OOSnCbFLTMMbfBqmLInWq5GHuo3yVIwUfx3N6EoZ+O/vxd6xe5I84Su/bS 78Y+EmZwvgelmzEQ/CitzrCIyR0ek+ctTtErio1UDvvcfmzS2m8l4wYDFcGk/PuSV4MV Xd2ic9CVLX+OkmITUlNz3SkuegIJlAjt0L4n+4upOLrn+glYhNFsIL4gu+R9zODeMrs7 qZOYVfW2cNp8KHD96Yaxu8oEchDY4M97d/+kc4SX0thta8qAKCMvZN2YksPh7whG9Flt Y9e7yCqUFtZ9d1Zjv+HkozB+JDHiQh/PSnWJXOWtPACNhoVvOIE6WtuUC/7gVe2v0T96 5nWw== X-Gm-Message-State: AElRT7EbMZIADQYzE/BClShXvGFVnryBXewob4LyBHiRBrOJThOYzxcY 7qdACafIjHglHENXleoACYw= X-Received: by 10.129.128.198 with SMTP id q189mr3608953ywf.148.1521301837444; Sat, 17 Mar 2018 08:50:37 -0700 (PDT) Received: from localhost ([72.188.97.40]) by smtp.gmail.com with ESMTPSA id v4sm3477103ywh.101.2018.03.17.08.50.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Mar 2018 08:50:36 -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 3/8] gpio: pci-idio-16: Implement get_multiple callback Date: Sat, 17 Mar 2018 11:50:31 -0400 Message-Id: <6ca4bf0ed930c057bdbcd07bab34ed0a474dd78d.1521301345.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 PCI-IDIO-16 series of devices provides 16 optically-isolated digital inputs accessed via two 8-bit ports. Since eight input lines are acquired on a single port input read, the PCI-IDIO-16 GPIO driver may improve multiple input reads by utilizing a get_multiple callback. This patch implements the idio_16_gpio_get_multiple function which serves as the respective get_multiple callback. Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-pci-idio-16.c | 50 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/drivers/gpio/gpio-pci-idio-16.c b/drivers/gpio/gpio-pci-idio-16.c index 57d1b7fbf07b..f273cf776cac 100644 --- a/drivers/gpio/gpio-pci-idio-16.c +++ b/drivers/gpio/gpio-pci-idio-16.c @@ -11,6 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. */ +#include #include #include #include @@ -103,6 +104,54 @@ static int idio_16_gpio_get(struct gpio_chip *chip, unsigned int offset) return !!(ioread8(&idio16gpio->reg->in8_15) & (mask >> 24)); } +static int idio_16_gpio_get_multiple(struct gpio_chip *chip, + unsigned long *mask, unsigned long *bits) +{ + struct idio_16_gpio *const idio16gpio = gpiochip_get_data(chip); + size_t i; + 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; + u8 __iomem ports[] = { + idio16gpio->reg->out0_7, idio16gpio->reg->out8_15, + idio16gpio->reg->in0_7, idio16gpio->reg->in8_15 + }; + + /* 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 = ioread8(ports + i); + + /* store acquired bits at respective bits array offset */ + bits[word_index] |= port_state << word_offset; + } + + return 0; +} + static void idio_16_gpio_set(struct gpio_chip *chip, unsigned int offset, int value) { @@ -299,6 +348,7 @@ static int idio_16_probe(struct pci_dev *pdev, const struct pci_device_id *id) idio16gpio->chip.direction_input = idio_16_gpio_direction_input; idio16gpio->chip.direction_output = idio_16_gpio_direction_output; idio16gpio->chip.get = idio_16_gpio_get; + idio16gpio->chip.get_multiple = idio_16_gpio_get_multiple; idio16gpio->chip.set = idio_16_gpio_set; idio16gpio->chip.set_multiple = idio_16_gpio_set_multiple; -- 2.16.2