Received: by 10.213.65.68 with SMTP id h4csp663296imn; Thu, 22 Mar 2018 06:03:33 -0700 (PDT) X-Google-Smtp-Source: AG47ELsNpu2IXfH7f1DHjGgc2WIMi+/rA3UbBxIno8oIz0itbNxLk5mr/q3NX1nVO5ef6HbI0/aq X-Received: by 10.98.109.131 with SMTP id i125mr20367162pfc.226.1521723807134; Thu, 22 Mar 2018 06:03:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521723804; cv=none; d=google.com; s=arc-20160816; b=JtEYA0NB/R8bxeTMsZLze3k+Ve00rUVQg7X3viWXH9fgLIGi5pKVVK8u+S75609ZVe 6WqknuP7mtr2+PUsny4ivDmmUKDWU0+wSSsf8JPO0H1a3spOSrP8L2Joi3pnJozbnDLB OZ1oaEhJ8Ttl5hKa8iPoIqapXCT2zDjeNs/B2c2p3zxUTcKqRo26t6WWnxYVg36YyoRM LLtx0xEN8Ry8K0EyF+R6Kpoum0O9TZYrsZlNF/j3axpS0UpHONzBQRMvfIBo2S4sYYpU HDv7dLyPUehZV35FcxZXKWxlW8FcvKoJleQ8q3kWl/At2ZDDWyiPcOCdnywxh8Day0xG 57xQ== 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=8b8caieZG3fncBoV23vo5RXKsfDrNb5y+qLbyBO1Jic=; b=rnFr1PsT1egOmrJQxxd1oEW9CSEkqcSYaH6ooIJTwV0Z5gPu7SDYr7RouNbKn8I+wI 2qzxt/MmRIOooLBbnW9fncF2iySafGG1Ox3OlVsFvWLiSq+LwEXYyweCkq487Pb3cceu utn95C/smikXhZZZj1JkNmOo7cSNiC/AUxR3iEx5mQV1su7+XRpEv5OvK3P3p1YIbZte GPtkRO5aKxAsERiDp6vV9oJrR/GLcKk3Mn/S54ojMjQObBLN63bh/+wBK+KfvOsGv9TL 2nz6MVkVzBrhCNDjv7LMKVdPMDtQbIEl6Me0XJYuxTtn3c/eA1Yc8Es70nCYo5NC8QYO 58JQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Bd8pLojN; 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 t3si3358384pgp.194.2018.03.22.06.03.06; Thu, 22 Mar 2018 06:03:23 -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=Bd8pLojN; 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 S1755189AbeCVNBK (ORCPT + 99 others); Thu, 22 Mar 2018 09:01:10 -0400 Received: from mail-yb0-f193.google.com ([209.85.213.193]:36374 "EHLO mail-yb0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755179AbeCVNBG (ORCPT ); Thu, 22 Mar 2018 09:01:06 -0400 Received: by mail-yb0-f193.google.com with SMTP id o3-v6so362556ybm.3; Thu, 22 Mar 2018 06:01:06 -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=8b8caieZG3fncBoV23vo5RXKsfDrNb5y+qLbyBO1Jic=; b=Bd8pLojNU2q9xQGHnHHfR0gEuwfAZcnK46IK+bSyOHbiixXq67GPEAYlw0kzU2Gkij tz53L1QzRT0BrTamvpqLkIKu/YdRhkH7WsllImZMVp62BK7SXAaY64juY6ja2nzKbZCC FXgymjUCnhpSoUJCexTA0h7y1bD0QTfqp07ZQ0aUCN65Vi2s1geXRQqFr1ZToMT7Blr6 GT2SWZsgg6DJBEJJUdWKB2lOnaZ0s98kZMc+MgHLXz+So2IUmRf59Va5aKLQuGGILTag n0KRRAPFjLkYuKziZ/iQ2XYaJ+fPDXDtB+ewxcgDxkkwwpfsFWTx69eHyYsgFrMHlhb2 LPdw== 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=8b8caieZG3fncBoV23vo5RXKsfDrNb5y+qLbyBO1Jic=; b=NYocjG6qSnboutIXKyJgyIihGSFS0rP1avNdJNt1pEleNvHWlktTrCD9vWROth9YGz +4nav0cztNlp4J8jlTDkDEWVZrPIcI/DCwYD63fn75F2j4RC2Wqj6C2WImU7tBOGe0r5 MEzlxQBE26ANw65oc4PNP4WXVPQlKAn7vRIqR7OHeIzoMTe5+ZjcwBGm56GJrg0AgMgd Z52YXCFya27+VHmeP3jRrsHkMa7wpJPLcanA77Hk4r3/LcSGmrVVUcHXgNgjuB342BNU bGLkoN88pDvbhldsXARiLbdEAZ1kFJ8FJCb0eEGlDEQvXnM8qelAbjOF6vqc0itgCZYy nVFA== X-Gm-Message-State: AElRT7ED6VL33kyshmBGmAnr3738CpK7eWW0RP9Sn4X1lLCSL/N6RtN4 l2lLs7N9CfM7k/qmATvOxIU= X-Received: by 2002:a25:aa2c:: with SMTP id s41-v6mr452813ybi.186.1521723665555; Thu, 22 Mar 2018 06:01:05 -0700 (PDT) Received: from localhost ([72.188.97.40]) by smtp.gmail.com with ESMTPSA id j187sm2395614ywf.87.2018.03.22.06.01.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Mar 2018 06:01:05 -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 7/7] gpio: ws16c48: Implement get_multiple callback Date: Thu, 22 Mar 2018 09:00:59 -0400 Message-Id: <259a3a67b82d2973f4c03a7c3c8a560b3054f7a9.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 WinSystems WS16C48 device provides 48 lines of digital I/O accessed via six 8-bit ports. Since eight input lines are acquired on a single port input read, the WS16C48 GPIO driver may improve multiple input reads by utilizing a get_multiple callback. This patch implements the ws16c48_gpio_get_multiple function which serves as the respective get_multiple callback. Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-ws16c48.c | 47 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/drivers/gpio/gpio-ws16c48.c b/drivers/gpio/gpio-ws16c48.c index 746648244bf3..c7028eb0b8e1 100644 --- a/drivers/gpio/gpio-ws16c48.c +++ b/drivers/gpio/gpio-ws16c48.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 @@ -129,6 +130,51 @@ static int ws16c48_gpio_get(struct gpio_chip *chip, unsigned offset) return !!(port_state & mask); } +static int ws16c48_gpio_get_multiple(struct gpio_chip *chip, + unsigned long *mask, unsigned long *bits) +{ + struct ws16c48_gpio *const ws16c48gpio = gpiochip_get_data(chip); + const unsigned int gpio_reg_size = 8; + size_t i; + const size_t num_ports = chip->ngpio / gpio_reg_size; + 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 < num_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(ws16c48gpio->base + i); + + /* store acquired bits at respective bits array offset */ + bits[word_index] |= port_state << word_offset; + } + + return 0; +} + static void ws16c48_gpio_set(struct gpio_chip *chip, unsigned offset, int value) { struct ws16c48_gpio *const ws16c48gpio = gpiochip_get_data(chip); @@ -383,6 +429,7 @@ static int ws16c48_probe(struct device *dev, unsigned int id) ws16c48gpio->chip.direction_input = ws16c48_gpio_direction_input; ws16c48gpio->chip.direction_output = ws16c48_gpio_direction_output; ws16c48gpio->chip.get = ws16c48_gpio_get; + ws16c48gpio->chip.get_multiple = ws16c48_gpio_get_multiple; ws16c48gpio->chip.set = ws16c48_gpio_set; ws16c48gpio->chip.set_multiple = ws16c48_gpio_set_multiple; ws16c48gpio->base = base[id]; -- 2.16.2