From patchwork Thu Oct 19 22:33:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 116444 Delivered-To: patch@linaro.org Received: by 10.80.163.170 with SMTP id s39csp3917422edb; Thu, 19 Oct 2017 15:35:53 -0700 (PDT) X-Received: by 10.99.56.19 with SMTP id f19mr2591888pga.328.1508452553528; Thu, 19 Oct 2017 15:35:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508452553; cv=none; d=google.com; s=arc-20160816; b=LIhfNazr52exL4Kg3IQ2wod+oZwvyC+gKr6nXv84ty2XQsZRcyonaUmc/fRGqzgxzJ X7i9cqmfYb5MBoDwjg9dlykD5yGwND+KxDU9O0jejD9GsgWxGZGtp2IYsi2ZioskRY46 q4A/hNoZJbTAo3S7eO0mhKuwEtg9y/J5OeWQ6zfj/0mQ6Kp1i3r2hgr6+zRLdyTvY+rb 1xmRoOYVNjmRPNQypm+jQpVjP8VW6A63xfpga/iNAQbb5l6gQFLSn6OyUk1LStDBFuVN Rjr6sMySoxbOjqxl5NPARsi0iuUIpbP5R/YGVsxYokZr2uWB6XNSpLJZxCoV54S0r3Z/ K3ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=psO0svdZo4gVLWrM8TV6y0fFCyXmnK1bRcy9PO99dJ0=; b=BGhzQNTi53hNNlbDxQabLwC9jKtuQLaTz5PK7EfFk3cCd/jECi4fAy7cW7F42U7vi/ d4yEgcYSkRkQOPVeLMUGdn24/eXP5zQmqk/9oiV9Heg6p7Mmk7NpCa/1zVvoMosMbMl0 jKQz9vOKMGlGv8etKM8A8u3SO22s9cqpELYfpD8RxPgdjw+7+L9Nc65TpnUk2Lx4beJH BMloLtDvsNI0eAWID/qmt+v7vd2R0Ge9NTE5dftzyVNBJVX9Zd3LqGPiu40sXltY5EdD FZwtbaIdtRhvIe0YBdpwSljeFZAkQSj8msQ7eyTqiBF43qr9Ta1oL28RWXGK0Fb2qnmv 38LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=IFRiu+rV; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o2si3398974pgp.46.2017.10.19.15.35.53; Thu, 19 Oct 2017 15:35:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=IFRiu+rV; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754449AbdJSWfw (ORCPT + 6 others); Thu, 19 Oct 2017 18:35:52 -0400 Received: from mail-lf0-f66.google.com ([209.85.215.66]:47137 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754445AbdJSWfv (ORCPT ); Thu, 19 Oct 2017 18:35:51 -0400 Received: by mail-lf0-f66.google.com with SMTP id k40so11250226lfi.4 for ; Thu, 19 Oct 2017 15:35:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=NP/3QY6Uvo3fAqAX4XLIh2deF/13HMkS6HOThp910zg=; b=IFRiu+rV/26jGkZ4mtu1tTPMxvM1Z/taQmR5KSV1vnR6qeoCVa1X2fFDwhw/dzzmXi dgbioxt0dn3PtEDx3YrWcIxR1btnBNvmloYt7fXk/18EDVoqB1inPeMAZp/mn40EAAAJ Ro0OEKI4foycFGjdbid+9ikTmn3N1ggPcZb7M= 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; bh=NP/3QY6Uvo3fAqAX4XLIh2deF/13HMkS6HOThp910zg=; b=OPW/pPqHA8rrb2xKh0aRPQeR46vxc8QMIc9EqTZOg1tju5CFPxcMvh05122HzoVxzR 31JBofNqhQTW5s82kF7DILjblBssluEvlPF7rBsXf16bAFw8J6Yf7fjf+O8elrupW+hF xyXw+AO5Bk7BVIwa6DBVPzpxE9AKhJ8P7hRE38Cu91i7RGHhZIl5nbe6xNqaI25CPOSZ RmWNj+eflR3Gw0PkAsnJxk4kAFUYiLBHqBeScXXIp4bpevqgdNddb+16IaUtQ/kMFQsR PLhdM/unraIjtJo/lsuTlyC0DnDx9QX3QLcRAc27T3aGptiC+7RPyrWeUUUpMNoVkVck g27A== X-Gm-Message-State: AMCzsaXZRxo+EcPeHkwS38A+K+p1Ed0i7TNm3xMWB5USzdK5rcYZntn1 o3CLaqlQUm0N8jC5LOXPSmP5io44Lms= X-Google-Smtp-Source: ABhQp+RTLt7puU2vsPBBNvUMy01VKaDDijpGBBmeGQe3yoig/Yr1sEiuA1wAdznXkn3yjJcXJIPoww== X-Received: by 10.25.161.210 with SMTP id k201mr1079296lfe.40.1508452549452; Thu, 19 Oct 2017 15:35:49 -0700 (PDT) Received: from localhost.localdomain (c-5f7c71d5.014-348-6c756e10.cust.bredbandsbolaget.se. [213.113.124.95]) by smtp.gmail.com with ESMTPSA id k37sm3402114lfi.27.2017.10.19.15.35.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 19 Oct 2017 15:35:48 -0700 (PDT) From: Linus Walleij To: linux-gpio@vger.kernel.org Cc: Linus Walleij , Anton Vorontsov , Lukas Wunner Subject: [PATCH v2] gpio-mmio: Use the new .get_multiple() callback Date: Fri, 20 Oct 2017 00:33:43 +0200 Message-Id: <20171019223343.13927-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.13.6 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org It is possible to read all lines of a generic MMIO GPIO chip with a single register read so support this if we are in native endianness. Add an especially quirky callback to read multiple lines for the variants that require you to read values from the output registers if and only if the line is set as output. We managed to do that with a maximum of two register reads, and just one read if the requested lines are all input or all output. Cc: Anton Vorontsov Cc: Lukas Wunner Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Only assign the functions for multiple get if we are in native endianness. Else each bit needs to be processed differently after read and it will be a mess. Likely the old get functions are better in this case. - Directly write into *bits in both functions. --- drivers/gpio/gpio-mmio.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) -- 2.13.6 -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/gpio/gpio-mmio.c b/drivers/gpio/gpio-mmio.c index f7da40e46c55..cdfe1192be1d 100644 --- a/drivers/gpio/gpio-mmio.c +++ b/drivers/gpio/gpio-mmio.c @@ -147,11 +147,49 @@ static int bgpio_get_set(struct gpio_chip *gc, unsigned int gpio) return !!(gc->read_reg(gc->reg_dat) & pinmask); } +/* + * This only works if the bits in the GPIO register are in native endianness. + * We only assign it if we have that. + */ +static int bgpio_get_set_multiple(struct gpio_chip *gc, unsigned long *mask, + unsigned long *bits) +{ + unsigned long get_mask = 0; + unsigned long set_mask = 0; + int bit = 0; + + while ((bit = find_next_bit(mask, gc->ngpio, bit)) != gc->ngpio) { + if (gc->bgpio_dir & BIT(bit)) + set_mask |= BIT(bit); + else + get_mask |= BIT(bit); + } + + if (set_mask) + *bits |= gc->read_reg(gc->reg_set) & set_mask; + if (get_mask) + *bits |= gc->read_reg(gc->reg_dat) & get_mask; + + return 0; +} + static int bgpio_get(struct gpio_chip *gc, unsigned int gpio) { return !!(gc->read_reg(gc->reg_dat) & gc->pin2mask(gc, gpio)); } +/* + * This only works if the bits in the GPIO register are in native endianness. + * We only assign it if we have that. + */ +static int bgpio_get_multiple(struct gpio_chip *gc, unsigned long *mask, + unsigned long *bits) +{ + *bits = gc->read_reg(gc->reg_dat) & *mask; + + return 0; +} + static void bgpio_set_none(struct gpio_chip *gc, unsigned int gpio, int val) { } @@ -462,10 +500,17 @@ static int bgpio_setup_io(struct gpio_chip *gc, } if (!(flags & BGPIOF_UNREADABLE_REG_SET) && - (flags & BGPIOF_READ_OUTPUT_REG_SET)) + (flags & BGPIOF_READ_OUTPUT_REG_SET)) { gc->get = bgpio_get_set; - else + /* If we are in native endianness we can use the quick multiple read */ + if (!(flags & BGPIOF_BIG_ENDIAN_BYTE_ORDER)) + gc->get_multiple = bgpio_get_set_multiple; + } else { gc->get = bgpio_get; + /* If we are in native endianness we can use the quick multiple read */ + if (!(flags & BGPIOF_BIG_ENDIAN_BYTE_ORDER)) + gc->get_multiple = bgpio_get_multiple; + } return 0; }