Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1137025ybe; Thu, 5 Sep 2019 10:52:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqzb9wxojoMNutoGlpikEwqHNoSyio4EdwQKSqufVwCLqP6rc4P2t+gjsmDBSi/jvNJ05Rv2 X-Received: by 2002:a62:60c7:: with SMTP id u190mr5476250pfb.54.1567705922123; Thu, 05 Sep 2019 10:52:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567705922; cv=none; d=google.com; s=arc-20160816; b=0QkjWuXj7wdnoL8nYXKX7os7Htq5xEb9ABiSXkgd7kRBOZ0jrI+KmnHl1yTk+gjdJR tsD5WaQ4zqptDXa2RNvMrRyIO27HQBRr0sC9CvPkerRq6xuBQUrjpJCND4mKD92WTHAz RAgbhBVG4IJr/gX7xaNrgp832HjsIaNAvizMAY2QVepE1qNF1/3MqtK8xp9n1e9Yn44I y18wjFGomLjgipipNsGs8BhxZKBJlgtA+Cinf4DIMP4uXs6SNXERMo/pwfrN9I4bAmgq d/ncSkL9V/j/5NrDpkxn3irVijfL0yC5ocXkIjRgclwg8GlnerQ9O/ilb0htiGXXJfBU C6Mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=0J2eF/GJkYBlAV9bsnnTBObhosClR3AQeu2oGuzNZNA=; b=pL2oz9WMBs05EN+r3NnRpk6PYz4QR0AfefgakFwtvnQltoHA0ts2IgD978WFiHHygz t1Dq4SFN8eqDB8elFt3HnWhKZUCws1YJVKCFIqiCl1LTf50bvAEcn9QQ51vwzK9lV2R1 4aU9weSZyCPOpbPsTQLYDHXpsdL2WV02aofH3Q69GmupS51sf6xeIP81DKl8QXy0u4as GGKO9yFMgeEqhRcd1Ru1Fqj7QIZC1z2fTAAW1cXpZwMcB3Wxl51FbjXPAFibf2GBxaga kdMZELO9EQeGpq4I8WJDuzf8ixP0viA6xgjs19rwiyfUuLdKnOQdhUlqPtJrnTMGPkHw PPAQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a190si2373345pge.4.2019.09.05.10.51.44; Thu, 05 Sep 2019 10:52:02 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730443AbfIEONQ (ORCPT + 99 others); Thu, 5 Sep 2019 10:13:16 -0400 Received: from relay7-d.mail.gandi.net ([217.70.183.200]:43949 "EHLO relay7-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726048AbfIEONQ (ORCPT ); Thu, 5 Sep 2019 10:13:16 -0400 X-Originating-IP: 86.207.98.53 Received: from localhost (aclermont-ferrand-651-1-259-53.w86-207.abo.wanadoo.fr [86.207.98.53]) (Authenticated sender: alexandre.belloni@bootlin.com) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id DF4D72002B; Thu, 5 Sep 2019 14:13:13 +0000 (UTC) From: Alexandre Belloni To: Linus Walleij Cc: Ludovic Desroches , Nicolas Ferre , linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Alexandre Belloni Subject: [PATCH] pinctrl: at91-pio4: implement .get_multiple and .set_multiple Date: Thu, 5 Sep 2019 16:13:04 +0200 Message-Id: <20190905141304.22005-1-alexandre.belloni@bootlin.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Implement .get_multiple and .set_multiple to allow reading or setting multiple pins simultaneously. Pins in the same bank will all be switched at the same time, improving synchronization and performances. Signed-off-by: Alexandre Belloni --- drivers/pinctrl/pinctrl-at91-pio4.c | 60 +++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/drivers/pinctrl/pinctrl-at91-pio4.c b/drivers/pinctrl/pinctrl-at91-pio4.c index d6de4d360cd4..488a302a60d4 100644 --- a/drivers/pinctrl/pinctrl-at91-pio4.c +++ b/drivers/pinctrl/pinctrl-at91-pio4.c @@ -328,6 +328,35 @@ static int atmel_gpio_get(struct gpio_chip *chip, unsigned offset) return !!(reg & BIT(pin->line)); } +static int atmel_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, + unsigned long *bits) +{ + struct atmel_pioctrl *atmel_pioctrl = gpiochip_get_data(chip); + unsigned int bank; + + bitmap_zero(bits, atmel_pioctrl->npins); + + for (bank = 0; bank < atmel_pioctrl->nbanks; bank++) { + unsigned int word = bank; + unsigned int offset = 0; + unsigned int reg; + +#if ATMEL_PIO_NPINS_PER_BANK != BITS_PER_LONG + word = BIT_WORD(bank * ATMEL_PIO_NPINS_PER_BANK); + offset = bank * ATMEL_PIO_NPINS_PER_BANK % BITS_PER_LONG; +#endif + if (!mask[word]) + continue; + + reg = atmel_gpio_read(atmel_pioctrl, bank, ATMEL_PIO_PDSR); + bits[word] |= mask[word] & (reg << offset); + + pr_err("ABE: %d %08x\n", bank, bits[word]); + } + + return 0; +} + static int atmel_gpio_direction_output(struct gpio_chip *chip, unsigned offset, int value) { @@ -358,11 +387,42 @@ static void atmel_gpio_set(struct gpio_chip *chip, unsigned offset, int val) BIT(pin->line)); } +static void atmel_gpio_set_multiple(struct gpio_chip *chip, unsigned long *mask, + unsigned long *bits) +{ + struct atmel_pioctrl *atmel_pioctrl = gpiochip_get_data(chip); + unsigned int bank; + + for (bank = 0; bank < atmel_pioctrl->nbanks; bank++) { + unsigned int bitmask; + unsigned int word = bank; + +#if ATMEL_PIO_NPINS_PER_BANK != BITS_PER_LONG + word = BIT_WORD(bank * ATMEL_PIO_NPINS_PER_BANK); +#endif + if (!mask[word]) + continue; + + bitmask = mask[word] & bits[word]; + atmel_gpio_write(atmel_pioctrl, bank, ATMEL_PIO_SODR, bitmask); + + bitmask = mask[word] & ~bits[word]; + atmel_gpio_write(atmel_pioctrl, bank, ATMEL_PIO_CODR, bitmask); + +#if ATMEL_PIO_NPINS_PER_BANK != BITS_PER_LONG + mask[word] >>= ATMEL_PIO_NPINS_PER_BANK; + bits[word] >>= ATMEL_PIO_NPINS_PER_BANK; +#endif + } +} + static struct gpio_chip atmel_gpio_chip = { .direction_input = atmel_gpio_direction_input, .get = atmel_gpio_get, + .get_multiple = atmel_gpio_get_multiple, .direction_output = atmel_gpio_direction_output, .set = atmel_gpio_set, + .set_multiple = atmel_gpio_set_multiple, .to_irq = atmel_gpio_to_irq, .base = 0, }; -- 2.21.0