linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: <patrice.chotard@st.com>
To: <lee.jones@linaro.org>, <linus.walleij@linaro.org>,
	<gnurou@gmail.com>, <linux-gpio@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Cc: <linux-arm-kernel@lists.infradead.org>, <maxime.coquelin@st.com>,
	<amelie.delaunay@st.com>, <shawnguo@kernel.org>,
	<kernel@pengutronix.de>, <dinguyen@opensource.altera.com>,
	<vireshk@kernel.org>, <shiraz.linux.kernel@gmail.com>,
	<thierry.reding@gmail.com>, <gnurou@gmail.com>,
	Patrice Chotard <patrice.chotard@st.com>,
	<marcel.ziswiler@toradex.com>, <stefan@agner.ch>,
	<dev@lynxeye.de>
Subject: [PATCH v2 10/10] gpio: stmpe: Add STMPE1600 support
Date: Thu, 28 Apr 2016 14:13:09 +0200	[thread overview]
Message-ID: <1461845589-4826-11-git-send-email-patrice.chotard@st.com> (raw)
In-Reply-To: <1461845589-4826-1-git-send-email-patrice.chotard@st.com>

From: Patrice Chotard <patrice.chotard@st.com>

The particularities of this variant are:
- GPIO_XXX_LSB and GPIO_XXX_MSB memory locations are inverted compared
  to other variants.
- There is no Edge detection, Rising Edge and Falling Edge registers.
- IRQ flags are cleared when read, no need to write in Status register.

Signed-off-by: Amelie DELAUNAY <amelie.delaunay@st.com>
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
---
 drivers/gpio/gpio-stmpe.c | 48 +++++++++++++++++++++++++++++++++++++----------
 1 file changed, 38 insertions(+), 10 deletions(-)

diff --git a/drivers/gpio/gpio-stmpe.c b/drivers/gpio/gpio-stmpe.c
index 6d6d76a..32c5a72 100644
--- a/drivers/gpio/gpio-stmpe.c
+++ b/drivers/gpio/gpio-stmpe.c
@@ -128,8 +128,9 @@ static int stmpe_gpio_irq_set_type(struct irq_data *d, unsigned int type)
 	if (type & IRQ_TYPE_LEVEL_LOW || type & IRQ_TYPE_LEVEL_HIGH)
 		return -EINVAL;
 
-	/* STMPE801 doesn't have RE and FE registers */
-	if (stmpe_gpio->stmpe->partnum == STMPE801)
+	/* STMPE801 and STMPE 1600 don't have RE and FE registers */
+	if (stmpe_gpio->stmpe->partnum == STMPE801 ||
+	    stmpe_gpio->stmpe->partnum == STMPE1600)
 		return 0;
 
 	if (type & IRQ_TYPE_EDGE_RISING)
@@ -173,9 +174,10 @@ static void stmpe_gpio_irq_sync_unlock(struct irq_data *d)
 	int i, j;
 
 	for (i = 0; i < CACHE_NR_REGS; i++) {
-		/* STMPE801 doesn't have RE and FE registers */
-		if ((stmpe->partnum == STMPE801) &&
-				(i != REG_IE))
+		/* STMPE801 and STMPE1600 don't have RE and FE registers */
+		if ((stmpe->partnum == STMPE801 ||
+		     stmpe->partnum == STMPE1600) &&
+		     (i != REG_IE))
 			continue;
 
 		for (j = 0; j < num_banks; j++) {
@@ -208,11 +210,21 @@ static void stmpe_gpio_irq_unmask(struct irq_data *d)
 {
 	struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
 	struct stmpe_gpio *stmpe_gpio = gpiochip_get_data(gc);
+	struct stmpe *stmpe = stmpe_gpio->stmpe;
 	int offset = d->hwirq;
 	int regoffset = offset / 8;
 	int mask = 1 << (offset % 8);
 
 	stmpe_gpio->regs[REG_IE][regoffset] |= mask;
+
+	/*
+	 * STMPE1600 workaround: to be able to get IRQ from pins,
+	 * a read must be done on GPMR register, or a write in
+	 * GPSR or GPCR registers
+	 */
+	if (stmpe->partnum == STMPE1600)
+		stmpe_reg_read(stmpe,
+			       stmpe->regs[STMPE_IDX_GPMR_LSB + regoffset]);
 }
 
 static void stmpe_dbg_show_one(struct seq_file *s,
@@ -285,6 +297,7 @@ static void stmpe_dbg_show_one(struct seq_file *s,
 			fall = !!(ret & mask);
 
 		case STMPE801:
+		case STMPE1600:
 			irqen_reg = stmpe->regs[STMPE_IDX_IEGPIOR_LSB + bank];
 			break;
 
@@ -331,18 +344,32 @@ static irqreturn_t stmpe_gpio_irq(int irq, void *dev)
 {
 	struct stmpe_gpio *stmpe_gpio = dev;
 	struct stmpe *stmpe = stmpe_gpio->stmpe;
-	u8 statmsbreg = stmpe->regs[STMPE_IDX_ISGPIOR_MSB];
+	u8 statmsbreg;
 	int num_banks = DIV_ROUND_UP(stmpe->num_gpios, 8);
 	u8 status[num_banks];
 	int ret;
 	int i;
 
+	/*
+	 * the stmpe_block_read() call below, imposes to set statmsbreg
+	 * with the register located at the lowest address. As STMPE1600
+	 * variant is the only one which respect registers address's order
+	 * (LSB regs located at lowest address than MSB ones) whereas all
+	 * the others have a registers layout with MSB located before the
+	 * LSB regs.
+	 */
+	if (stmpe->partnum == STMPE1600)
+		statmsbreg = stmpe->regs[STMPE_IDX_ISGPIOR_LSB];
+	else
+		statmsbreg = stmpe->regs[STMPE_IDX_ISGPIOR_MSB];
+
 	ret = stmpe_block_read(stmpe, statmsbreg, num_banks, status);
 	if (ret < 0)
 		return IRQ_NONE;
 
 	for (i = 0; i < num_banks; i++) {
-		int bank = num_banks - i - 1;
+		int bank = (stmpe_gpio->stmpe->partnum == STMPE1600) ? i :
+			   num_banks - i - 1;
 		unsigned int enabled = stmpe_gpio->regs[REG_IE][bank];
 		unsigned int stat = status[i];
 
@@ -362,10 +389,11 @@ static irqreturn_t stmpe_gpio_irq(int irq, void *dev)
 
 		/*
 		 * interrupt status register write has no effect on
-		 * 801 and 1801, bits are cleared when read.
-		 * Edge detect register is not present on 801 and 1801
+		 * 801/1801/1600, bits are cleared when read.
+		 * Edge detect register is not present on 801/1600/1801
 		 */
-		if (stmpe->partnum != STMPE801 || stmpe->partnum != STMPE1801) {
+		if (stmpe->partnum != STMPE801 || stmpe->partnum != STMPE1600 ||
+		    stmpe->partnum != STMPE1801) {
 			stmpe_reg_write(stmpe, statmsbreg + i, status[i]);
 			stmpe_reg_write(stmpe,
 					stmpe->regs[STMPE_IDX_GPEDR_LSB + i],
-- 
1.9.1

  parent reply	other threads:[~2016-04-28 12:14 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-28 12:12 [PATCH v2 00/10] STMPE fixes/rework and add STMPE1600 support patrice.chotard
2016-04-28 12:13 ` [PATCH v2 01/10] mfd: stmpe: Add STMPE_IDX_SYS_CTRL/2 enum patrice.chotard
2016-04-28 12:13 ` [PATCH v2 02/10] mfd: stmpe: Add reset support for all STMPE variant patrice.chotard
2016-08-07  2:54   ` Stefan Agner
2016-08-10 16:00     ` Patrice Chotard
2016-04-28 12:13 ` [PATCH v2 03/10] gpio: stmpe: fix edge and rising/falling edge detection patrice.chotard
2016-04-28 12:13 ` [PATCH v2 04/10] gpio: stmpe: write int status register only when needed patrice.chotard
2016-04-28 12:13 ` [PATCH v2 05/10] mfd: stmpe: use generic bit mask name patrice.chotard
2016-08-04 15:05   ` Lee Jones
2016-04-28 12:13 ` [PATCH v2 06/10] mfd: stmpe: rework registers access patrice.chotard
2016-04-29  7:42   ` Linus Walleij
2016-04-28 12:13 ` [PATCH v2 07/10] gpio: " patrice.chotard
2016-04-29  7:42   ` Linus Walleij
2016-04-28 12:13 ` [PATCH v2 08/10] Documentation: dt: add stmpe1600 compatible string to stmpe mfd patrice.chotard
2016-04-28 12:13 ` [PATCH v2 09/10] mfd: Add STMPE1600 support patrice.chotard
2016-08-04 15:10   ` Lee Jones
2016-04-28 12:13 ` patrice.chotard [this message]
2016-04-29  7:44   ` [PATCH v2 10/10] gpio: stmpe: " Linus Walleij
2016-04-29  7:45 ` [PATCH v2 00/10] STMPE fixes/rework and add " Linus Walleij
2016-04-29 19:23 ` Marcel Ziswiler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1461845589-4826-11-git-send-email-patrice.chotard@st.com \
    --to=patrice.chotard@st.com \
    --cc=amelie.delaunay@st.com \
    --cc=dev@lynxeye.de \
    --cc=dinguyen@opensource.altera.com \
    --cc=gnurou@gmail.com \
    --cc=kernel@pengutronix.de \
    --cc=lee.jones@linaro.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcel.ziswiler@toradex.com \
    --cc=maxime.coquelin@st.com \
    --cc=shawnguo@kernel.org \
    --cc=shiraz.linux.kernel@gmail.com \
    --cc=stefan@agner.ch \
    --cc=thierry.reding@gmail.com \
    --cc=vireshk@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).