Skip to contentSkip to conversation

stmpe: mfd & gpio updates

PATCH Superseded Viresh Kumar 2 participants 8 messages Nov 16, 2011 – Nov 17, 2011

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover stmpe: mfd & gpio updates

This patchset does following:
- Fixes bug with "mfd/stmpe: Pass partnum as param to stmpe_probe()" patch
- Adds in support for STMPE610 and 801

STMPE801 has a different set of register as compared to other variants. So it is specially handled at few places in mfd's and gpio's stmpe driver.

Note: To successfully apply this patchset, first apply following patches already sent and acked over list:
- mfd/stmpe: Add support for irq over gpio pin
- mfd/stmpe: separate out controller and interface specific code
- mfd/stmpe: Add support for SPI interface

Pratyush Anand (1):
mfd/stmpe: Move struct stmpe_variant_info to linux/mfd/stmpe.h

Viresh Kumar (4):
mfd/stmpe: Pass partnum as param to stmpe_probe() mfd/stmpe: Add support for stmpe variant 610 mfd/stmpe: ADD support for stmpe variant 801 gpio/gpio-stmpe: ADD support for stmpe variant 801

 drivers/gpio/gpio-stmpe.c |   31 ++++++++++-
 drivers/mfd/stmpe-i2c.c   |   13 +----
 drivers/mfd/stmpe-spi.c   |    7 ++-
 drivers/mfd/stmpe.c       |  125 ++++++++++++++++++++++++++++++++++++++-------
 drivers/mfd/stmpe.h       |   53 +++++++------------
 include/linux/mfd/stmpe.h |   37 +++++++++++++-
 6 files changed, 198 insertions(+), 68 deletions(-)
Signature · 1 line
1.7.2.2
#1 lore raw

PATCH 1/5 mfd/stmpe: Pass partnum as param to stmpe_probe()

partnum is required during probe to get variant's info. Currently partnum was getting set in i2c interface after it is used and is not at all getting set in spi interface.

This can be passed as param to stmpe_probe, so that it is available early. With this, there is no need of i2c interface's init() routine, as it does nothing else than calling dev_set_drvdata(). So better remove this routine for i2c.

partnum defined in struct stmpe is of no use now, as it is only used once during probe of stmpe, so we can remove it from struct stmpe too.

---
 drivers/mfd/stmpe-i2c.c   |   11 +----------
 drivers/mfd/stmpe-spi.c   |    5 +++--
 drivers/mfd/stmpe.c       |    8 +++++---
 drivers/mfd/stmpe.h       |    2 +-
 include/linux/mfd/stmpe.h |    2 --
 5 files changed, 10 insertions(+), 18 deletions(-)
drivers/mfd/stmpe-i2c.c +1 -10
index 72fa08b..671fd5c 100644
@@ -45,20 +45,11 @@ static int i2c_block_write(struct stmpe *stmpe, u8 reg, u8 length,
 	return i2c_smbus_write_i2c_block_data(i2c, reg, length, values);
 }
 
-static void i2c_init(struct stmpe *stmpe)
-{
-	struct i2c_device_id *id = stmpe->ci->data;
-
-	stmpe->partnum = id->driver_data;
-	dev_set_drvdata(stmpe->dev, stmpe);
-}
-
 static struct stmpe_client_info i2c_ci = {
 	.read_byte = i2c_reg_read,
 	.write_byte = i2c_reg_write,
 	.read_block = i2c_block_read,
 	.write_block = i2c_block_write,
-	.init = i2c_init,
 };
 
 static int __devinit
@@ -69,7 +60,7 @@ stmpe_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
 	i2c_ci.client = i2c;
 	i2c_ci.dev = &i2c->dev;
 
-	return stmpe_probe(&i2c_ci);
+	return stmpe_probe(&i2c_ci, id->driver_data);
 }
 
 static int __devexit stmpe_i2c_remove(struct i2c_client *i2c)
drivers/mfd/stmpe-spi.c +3 -2
index 6f1c0ad3..21861d8 100644
@@ -64,7 +64,6 @@ static void spi_init(struct stmpe *stmpe)
 {
 	struct spi_device *spi = stmpe->client;
 
-	dev_set_drvdata(stmpe->dev, stmpe);
 	spi->bits_per_word = 8;
 
 	/* This register is only present for stmpe811 */
@@ -86,6 +85,8 @@ static struct stmpe_client_info spi_ci = {
 static int __devinit
 stmpe_spi_probe(struct spi_device *spi)
 {
+	const struct spi_device_id *id = spi_get_device_id(spi);
+
 	/* don't exceed max specified rate - 1MHz - Limitation of STMPE */
 	if (spi->max_speed_hz > 1000000) {
 		dev_dbg(&spi->dev, "f(sample) %d KHz?\n",
@@ -97,7 +98,7 @@ stmpe_spi_probe(struct spi_device *spi)
 	spi_ci.client = spi;
 	spi_ci.dev = &spi->dev;
 
-	return stmpe_probe(&spi_ci);
+	return stmpe_probe(&spi_ci, id->driver_data);
 }
 
 static int __devexit stmpe_spi_remove(struct spi_device *spi)
drivers/mfd/stmpe.c +5 -3
index 3ff2edb..a564f91 100644
@@ -870,7 +870,7 @@ static int __devinit stmpe_devices_init(struct stmpe *stmpe)
 }
 
 /* Called from client specific probe routines */
-int stmpe_probe(struct stmpe_client_info *ci)
+int stmpe_probe(struct stmpe_client_info *ci, int partnum)
 {
 	struct stmpe_platform_data *pdata = dev_get_platdata(ci->dev);
 	struct stmpe *stmpe;
@@ -891,11 +891,13 @@ int stmpe_probe(struct stmpe_client_info *ci)
 	stmpe->pdata = pdata;
 	stmpe->irq_base = pdata->irq_base;
 	stmpe->ci = ci;
-	stmpe->variant = stmpe_variant_info[stmpe->partnum];
+	stmpe->variant = stmpe_variant_info[partnum];
 	stmpe->regs = stmpe->variant->regs;
 	stmpe->num_gpios = stmpe->variant->num_gpios;
+	dev_set_drvdata(stmpe->dev, stmpe);
 
-	ci->init(stmpe);
+	if (ci->init)
+		ci->init(stmpe);
 
 	if (pdata->irq_over_gpio) {
 		ret = gpio_request_one(pdata->irq_gpio, GPIOF_DIR_IN, "stmpe");
drivers/mfd/stmpe.h +1 -1
index 908f482..a73f4c1 100644
@@ -97,7 +97,7 @@ struct stmpe_client_info {
 	void (*init)(struct stmpe *stmpe);
 };
 
-int stmpe_probe(struct stmpe_client_info *ci);
+int stmpe_probe(struct stmpe_client_info *ci, int partnum);
 int stmpe_remove(struct stmpe *stmpe);
 
 #define STMPE_ICR_LSB_HIGH	(1 << 2)
include/linux/mfd/stmpe.h +0 -2
index babc6b2..5afaf89 100644
@@ -59,7 +59,6 @@ struct stmpe_client_info;
  * @dev: device, mostly for dev_dbg()
  * @client: client - i2c or spi
  * @ci: client specific information
- * @partnum: part number
  * @variant: the detected STMPE model number
  * @regs: list of addresses of registers which are at different addresses on
  *	  different variants.  Indexed by one of STMPE_IDX_*.
@@ -76,7 +75,6 @@ struct stmpe {
 	struct device *dev;
 	void *client;
 	struct stmpe_client_info *ci;
-	enum stmpe_partnum partnum;
 	struct stmpe_variant_info *variant;
 	const u8 *regs;
 
Signature · 1 line
1.7.2.2
#2 lore raw

Re: [PATCH 1/5] mfd/stmpe: Pass partnum as param to stmpe_probe()

Quoted 3 lines · Viresh Kumar

partnum is required during probe to get variant's info. Currently partnum was getting set in i2c interface after it is used and is not at all getting set in spi interface.

So your previous patch is broken? Please fix it and resend it instead since it's not merged yet.

Quoted 7 lines

This can be passed as param to stmpe_probe, so that it is available early. With this, there is no need of i2c interface's init() routine, as it does nothing else than calling dev_set_drvdata(). So better remove this routine for i2c.

partnum defined in struct stmpe is of no use now, as it is only used once during probe of stmpe, so we can remove it from struct stmpe too.

Not quite; it's used from drivers/input/keyboard/stmpe-keypad.c. Please preserve this stmpe->partnum, drop your 2/5 patch which exposes variant externally, and instead use stmpe->partnum in 5/5.

#3 lore raw

Re: [PATCH 1/5] mfd/stmpe: Pass partnum as param to stmpe_probe()

Quoted 8 lines · Rabin Vincent
Quoted 3 lines · Viresh Kumar

partnum is required during probe to get variant's info. Currently partnum was getting set in i2c interface after it is used and is not at all getting set in spi interface.

So your previous patch is broken? Please fix it and resend it instead since it's not merged yet.

Sure.

Quoted 11 lines
Quoted 7 lines

This can be passed as param to stmpe_probe, so that it is available early. With this, there is no need of i2c interface's init() routine, as it does nothing else than calling dev_set_drvdata(). So better remove this routine for i2c.

partnum defined in struct stmpe is of no use now, as it is only used once during probe of stmpe, so we can remove it from struct stmpe too.

Not quite; it's used from drivers/input/keyboard/stmpe-keypad.c. Please preserve this stmpe->partnum, drop your 2/5 patch which exposes variant externally, and instead use stmpe->partnum in 5/5.

Yes, will do this.

Signature · 1 line
viresh
#4 lore raw

PATCH 2/5 mfd/stmpe: Move struct stmpe_variant_info to linux/mfd/stmpe.h

In reply to Viresh Kumar

From: Pratyush Anand <[email protected]>

Some variants like GPIO of STMPE801 have different register definition. So, variant ID will be needed by stmpe-gpio.c to distinguish between STMPE801. Move this struct definition from drivers/mfd/stmpe.h to include/linux/stmpe.h

---
 drivers/mfd/stmpe.h       |   32 --------------------------------
 include/linux/mfd/stmpe.h |   33 +++++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 32 deletions(-)
drivers/mfd/stmpe.h +0 -32
index a73f4c1..7df0bda 100644
@@ -44,38 +44,6 @@ struct stmpe_variant_block {
 };
 
 /**
- * struct stmpe_variant_info - variant-specific information
- * @name:	part name
- * @id_val:	content of CHIPID register
- * @id_mask:	bits valid in CHIPID register for comparison with id_val
- * @num_gpios:	number of GPIOS
- * @af_bits:	number of bits used to specify the alternate function
- * @regs: variant specific registers.
- * @blocks:	list of blocks present on this device
- * @num_blocks:	number of blocks present on this device
- * @num_irqs:	number of internal IRQs available on this device
- * @enable:	callback to enable the specified blocks.
- *		Called with the I/O lock held.
- * @get_altfunc: callback to get the alternate function number for the
- *		 specific block
- * @enable_autosleep: callback to configure autosleep with specified timeout
- */
-struct stmpe_variant_info {
-	const char *name;
-	u16 id_val;
-	u16 id_mask;
-	int num_gpios;
-	int af_bits;
-	const u8 *regs;
-	struct stmpe_variant_block *blocks;
-	int num_blocks;
-	int num_irqs;
-	int (*enable)(struct stmpe *stmpe, unsigned int blocks, bool enable);
-	int (*get_altfunc)(struct stmpe *stmpe, enum stmpe_block block);
-	int (*enable_autosleep)(struct stmpe *stmpe, int autosleep_timeout);
-};
-
-/**
  * struct stmpe_client_info - i2c or spi specific routines/info
  * @data: client specific data
  * @read_byte: read single byte
include/linux/mfd/stmpe.h +33 -0
index 5afaf89..102c06d 100644
@@ -51,6 +51,7 @@ enum {
 
 struct stmpe_variant_info;
 struct stmpe_client_info;
+struct stmpe_variant_block;
 
 /**
  * struct stmpe - STMPE MFD structure
@@ -86,6 +87,38 @@ struct stmpe {
 	struct stmpe_platform_data *pdata;
 };
 
+/**
+ * struct stmpe_variant_info - variant-specific information
+ * @name:	part name
+ * @id_val:	content of CHIPID register
+ * @id_mask:	bits valid in CHIPID register for comparison with id_val
+ * @num_gpios:	number of GPIOS
+ * @af_bits:	number of bits used to specify the alternate function
+ * @regs: variant specific registers.
+ * @blocks:	list of blocks present on this device
+ * @num_blocks:	number of blocks present on this device
+ * @num_irqs:	number of internal IRQs available on this device
+ * @enable:	callback to enable the specified blocks.
+ *		Called with the I/O lock held.
+ * @get_altfunc: callback to get the alternate function number for the
+ *		 specific block
+ * @enable_autosleep: callback to configure autosleep with specified timeout
+ */
+struct stmpe_variant_info {
+	const char *name;
+	u16 id_val;
+	u16 id_mask;
+	int num_gpios;
+	int af_bits;
+	const u8 *regs;
+	struct stmpe_variant_block *blocks;
+	int num_blocks;
+	int num_irqs;
+	int (*enable)(struct stmpe *stmpe, unsigned int blocks, bool enable);
+	int (*get_altfunc)(struct stmpe *stmpe, enum stmpe_block block);
+	int (*enable_autosleep)(struct stmpe *stmpe, int autosleep_timeout);
+};
+
 extern int stmpe_reg_write(struct stmpe *stmpe, u8 reg, u8 data);
 extern int stmpe_reg_read(struct stmpe *stmpe, u8 reg);
 extern int stmpe_block_read(struct stmpe *stmpe, u8 reg, u8 length,
Signature · 1 line
1.7.2.2
#5 lore raw

PATCH 3/5 mfd/stmpe: Add support for stmpe variant 610

In reply to Viresh Kumar

STMPE610 is very much like STMPE811, except the number of gpio pins, which is 8 in 811 and 6 in 610. This patch adds support for variant 610. STMPE610 will share most of the code with STMPE811.

---
 drivers/mfd/stmpe-i2c.c   |    1 +
 drivers/mfd/stmpe-spi.c   |    1 +
 drivers/mfd/stmpe.c       |   20 ++++++++++++++++++--
 include/linux/mfd/stmpe.h |    1 +
 4 files changed, 21 insertions(+), 2 deletions(-)
drivers/mfd/stmpe-i2c.c +1 -0
index 671fd5c..c004319 100644
@@ -71,6 +71,7 @@ static int __devexit stmpe_i2c_remove(struct i2c_client *i2c)
 }
 
 static const struct i2c_device_id stmpe_i2c_id[] = {
+	{ "stmpe610", STMPE610 },
 	{ "stmpe811", STMPE811 },
 	{ "stmpe1601", STMPE1601 },
 	{ "stmpe2401", STMPE2401 },
drivers/mfd/stmpe-spi.c +1 -0
index 21861d8..25928f6 100644
@@ -109,6 +109,7 @@ static int __devexit stmpe_spi_remove(struct spi_device *spi)
 }
 
 static const struct spi_device_id stmpe_spi_id[] = {
+	{ "stmpe610", STMPE610 },
 	{ "stmpe811", STMPE811 },
 	{ "stmpe1601", STMPE1601 },
 	{ "stmpe2401", STMPE2401 },
drivers/mfd/stmpe.c +18 -2
index a564f91..34046b5 100644
@@ -321,7 +321,7 @@ static struct mfd_cell stmpe_keypad_cell = {
 };
 
 /*
- * Touchscreen (STMPE811)
+ * Touchscreen (STMPE811 or STMPE610)
  */
 
 static struct resource stmpe_ts_resources[] = {
@@ -346,7 +346,7 @@ static struct mfd_cell stmpe_ts_cell = {
 };
 
 /*
- * STMPE811
+ * STMPE811 or STMPE610
  */
 
 static const u8 stmpe811_regs[] = {
@@ -417,6 +417,21 @@ static struct stmpe_variant_info stmpe811 = {
 	.get_altfunc	= stmpe811_get_altfunc,
 };
 
+/* Similar to 811, except number of gpios */
+static struct stmpe_variant_info stmpe610 = {
+	.name		= "stmpe610",
+	.id_val		= 0x0811,
+	.id_mask	= 0xffff,
+	.num_gpios	= 6,
+	.af_bits	= 1,
+	.regs		= stmpe811_regs,
+	.blocks		= stmpe811_blocks,
+	.num_blocks	= ARRAY_SIZE(stmpe811_blocks),
+	.num_irqs	= STMPE811_NR_INTERNAL_IRQS,
+	.enable		= stmpe811_enable,
+	.get_altfunc	= stmpe811_get_altfunc,
+};
+
 /*
  * STMPE1601
  */
@@ -651,6 +666,7 @@ static struct stmpe_variant_info stmpe2403 = {
 };
 
 static struct stmpe_variant_info *stmpe_variant_info[] = {
+	[STMPE610]	= &stmpe610,
 	[STMPE811]	= &stmpe811,
 	[STMPE1601]	= &stmpe1601,
 	[STMPE2401]	= &stmpe2401,
include/linux/mfd/stmpe.h +1 -0
index 102c06d..79e4fc4 100644
@@ -20,6 +20,7 @@ enum stmpe_block {
 };
 
 enum stmpe_partnum {
+	STMPE610,
 	STMPE811,
 	STMPE1601,
 	STMPE2401,
Signature · 1 line
1.7.2.2
#6 lore raw

PATCH 4/5 mfd/stmpe: ADD support for stmpe variant 801

In reply to Viresh Kumar

STMPE801 is a GPIO expander. Registers for 801 are much different from other variants. This patch adds support for STMPE801 in stmpe mfd driver.

---
 drivers/mfd/stmpe-i2c.c   |    1 +
 drivers/mfd/stmpe-spi.c   |    1 +
 drivers/mfd/stmpe.c       |   97 +++++++++++++++++++++++++++++++++++++++------
 drivers/mfd/stmpe.h       |   19 +++++++++
 include/linux/mfd/stmpe.h |    1 +
 5 files changed, 106 insertions(+), 13 deletions(-)
drivers/mfd/stmpe-i2c.c +1 -0
index c004319..278da8a 100644
@@ -72,6 +72,7 @@ static int __devexit stmpe_i2c_remove(struct i2c_client *i2c)
 
 static const struct i2c_device_id stmpe_i2c_id[] = {
 	{ "stmpe610", STMPE610 },
+	{ "stmpe801", STMPE801 },
 	{ "stmpe811", STMPE811 },
 	{ "stmpe1601", STMPE1601 },
 	{ "stmpe2401", STMPE2401 },
drivers/mfd/stmpe-spi.c +1 -0
index 25928f6..ac7ac99 100644
@@ -110,6 +110,7 @@ static int __devexit stmpe_spi_remove(struct spi_device *spi)
 
 static const struct spi_device_id stmpe_spi_id[] = {
 	{ "stmpe610", STMPE610 },
+	{ "stmpe801", STMPE801 },
 	{ "stmpe811", STMPE811 },
 	{ "stmpe1601", STMPE1601 },
 	{ "stmpe2401", STMPE2401 },
drivers/mfd/stmpe.c +84 -13

151 lines not on this page · raw message

drivers/mfd/stmpe.h +19 -0
index 7df0bda..476d1bb 100644
@@ -73,6 +73,25 @@ int stmpe_remove(struct stmpe *stmpe);
 #define STMPE_ICR_LSB_GIM	(1 << 0)
 
 /*
+ * STMPE801
+ */
+#define STMPE801_ID			0x0108
+#define STMPE801_NR_INTERNAL_IRQS	1
+
+#define STMPE801_REG_CHIP_ID		0x00
+#define STMPE801_REG_VERSION_ID		0x02
+#define STMPE801_REG_SYS_CTRL		0x04
+#define STMPE801_REG_GPIO_INT_EN	0x08
+#define STMPE801_REG_GPIO_INT_STA	0x09
+#define STMPE801_REG_GPIO_MP_STA	0x10
+#define STMPE801_REG_GPIO_SET_PIN	0x11
+#define STMPE801_REG_GPIO_DIR		0x12
+
+#define STMPE801_REG_SYS_CTRL_RESET	(1 << 7)
+#define STMPE801_REG_SYS_CTRL_INT_EN	(1 << 2)
+#define STMPE801_REG_SYS_CTRL_INT_HI	(1 << 0)
+
+/*
  * STMPE811
  */
 
include/linux/mfd/stmpe.h +1 -0
index 79e4fc4..17f3de8 100644
@@ -21,6 +21,7 @@ enum stmpe_block {
 
 enum stmpe_partnum {
 	STMPE610,
+	STMPE801,
 	STMPE811,
 	STMPE1601,
 	STMPE2401,
Signature · 1 line
1.7.2.2
#7 lore raw

PATCH 5/5 gpio/gpio-stmpe: ADD support for stmpe variant 801

In reply to Viresh Kumar

STMPE801 is a GPIO expander. GPIO registers for 801 are slightly different from other variants. This patch adds support for STMPE801 in stmpe gpio driver.

---
 drivers/gpio/gpio-stmpe.c |   31 ++++++++++++++++++++++++++++---
 1 files changed, 28 insertions(+), 3 deletions(-)
drivers/gpio/gpio-stmpe.c +28 -3
index 4c980b5..cba57f6 100644
@@ -65,7 +65,15 @@ static void stmpe_gpio_set(struct gpio_chip *chip, unsigned offset, int val)
 	u8 reg = stmpe->regs[which] - (offset / 8);
 	u8 mask = 1 << (offset % 8);
 
-	stmpe_reg_write(stmpe, reg, mask);
+	/*
+	 * Some variants have single register for gpio set/clear functionality.
+	 * For them we need to write 0 to clear and 1 to set.
+	 */
+	if (!val && (stmpe->regs[STMPE_IDX_GPSR_LSB] ==
+				stmpe->regs[STMPE_IDX_GPCR_LSB]))
+		stmpe_set_bits(stmpe, reg, mask, ~mask);
+	else
+		stmpe_set_bits(stmpe, reg, mask, mask);
 }
 
 static int stmpe_gpio_direction_output(struct gpio_chip *chip,
@@ -125,10 +133,19 @@ static struct gpio_chip template_chip = {
 static int stmpe_gpio_irq_set_type(struct irq_data *d, unsigned int type)
 {
 	struct stmpe_gpio *stmpe_gpio = irq_data_get_irq_chip_data(d);
+	struct stmpe *stmpe = stmpe_gpio->stmpe;
 	int offset = d->irq - stmpe_gpio->irq_base;
 	int regoffset = offset / 8;
 	int mask = 1 << (offset % 8);
 
+	/* STMPE801 doesn't have RE and FE registers */
+	if (stmpe->variant->id_val == STMPE801) {
+		if (type == IRQ_TYPE_LEVEL_LOW || type == IRQ_TYPE_LEVEL_HIGH)
+			return 0;
+		else
+			return -EINVAL;
+	}
+
 	if (type == IRQ_TYPE_LEVEL_LOW || type == IRQ_TYPE_LEVEL_HIGH)
 		return -EINVAL;
 
@@ -165,6 +182,11 @@ 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->variant->id_val == STMPE801) &&
+				(i != REG_IE))
+			continue;
+
 		for (j = 0; j < num_banks; j++) {
 			u8 old = stmpe_gpio->oldregs[i][j];
 			u8 new = stmpe_gpio->regs[i][j];
@@ -241,8 +263,11 @@ static irqreturn_t stmpe_gpio_irq(int irq, void *dev)
 		}
 
 		stmpe_reg_write(stmpe, statmsbreg + i, status[i]);
-		stmpe_reg_write(stmpe, stmpe->regs[STMPE_IDX_GPEDR_MSB] + i,
-				status[i]);
+
+		/* Edge detect register is not present on 801 */
+		if (stmpe->variant->id_val != STMPE801)
+			stmpe_reg_write(stmpe, stmpe->regs[STMPE_IDX_GPEDR_MSB]
+					+ i, status[i]);
 	}
 
 	return IRQ_HANDLED;
Signature · 1 line
1.7.2.2