xref: /linux/drivers/mfd/stmpe.c (revision 7f7f4ea15ef4645f3888310a7a761fc2c4f689c9)
127e34995SRabin Vincent /*
21a6e4b74SViresh Kumar  * ST Microelectronics MFD: stmpe's driver
31a6e4b74SViresh Kumar  *
427e34995SRabin Vincent  * Copyright (C) ST-Ericsson SA 2010
527e34995SRabin Vincent  *
627e34995SRabin Vincent  * License Terms: GNU General Public License, version 2
727e34995SRabin Vincent  * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
827e34995SRabin Vincent  */
927e34995SRabin Vincent 
1073de16dbSViresh Kumar #include <linux/gpio.h>
1127e34995SRabin Vincent #include <linux/kernel.h>
1227e34995SRabin Vincent #include <linux/interrupt.h>
1327e34995SRabin Vincent #include <linux/irq.h>
141a6e4b74SViresh Kumar #include <linux/pm.h>
1527e34995SRabin Vincent #include <linux/slab.h>
1627e34995SRabin Vincent #include <linux/mfd/core.h>
1727e34995SRabin Vincent #include "stmpe.h"
1827e34995SRabin Vincent 
1927e34995SRabin Vincent static int __stmpe_enable(struct stmpe *stmpe, unsigned int blocks)
2027e34995SRabin Vincent {
2127e34995SRabin Vincent 	return stmpe->variant->enable(stmpe, blocks, true);
2227e34995SRabin Vincent }
2327e34995SRabin Vincent 
2427e34995SRabin Vincent static int __stmpe_disable(struct stmpe *stmpe, unsigned int blocks)
2527e34995SRabin Vincent {
2627e34995SRabin Vincent 	return stmpe->variant->enable(stmpe, blocks, false);
2727e34995SRabin Vincent }
2827e34995SRabin Vincent 
2927e34995SRabin Vincent static int __stmpe_reg_read(struct stmpe *stmpe, u8 reg)
3027e34995SRabin Vincent {
3127e34995SRabin Vincent 	int ret;
3227e34995SRabin Vincent 
331a6e4b74SViresh Kumar 	ret = stmpe->ci->read_byte(stmpe, reg);
3427e34995SRabin Vincent 	if (ret < 0)
351a6e4b74SViresh Kumar 		dev_err(stmpe->dev, "failed to read reg %#x: %d\n", reg, ret);
3627e34995SRabin Vincent 
3727e34995SRabin Vincent 	dev_vdbg(stmpe->dev, "rd: reg %#x => data %#x\n", reg, ret);
3827e34995SRabin Vincent 
3927e34995SRabin Vincent 	return ret;
4027e34995SRabin Vincent }
4127e34995SRabin Vincent 
4227e34995SRabin Vincent static int __stmpe_reg_write(struct stmpe *stmpe, u8 reg, u8 val)
4327e34995SRabin Vincent {
4427e34995SRabin Vincent 	int ret;
4527e34995SRabin Vincent 
4627e34995SRabin Vincent 	dev_vdbg(stmpe->dev, "wr: reg %#x <= %#x\n", reg, val);
4727e34995SRabin Vincent 
481a6e4b74SViresh Kumar 	ret = stmpe->ci->write_byte(stmpe, reg, val);
4927e34995SRabin Vincent 	if (ret < 0)
501a6e4b74SViresh Kumar 		dev_err(stmpe->dev, "failed to write reg %#x: %d\n", reg, ret);
5127e34995SRabin Vincent 
5227e34995SRabin Vincent 	return ret;
5327e34995SRabin Vincent }
5427e34995SRabin Vincent 
5527e34995SRabin Vincent static int __stmpe_set_bits(struct stmpe *stmpe, u8 reg, u8 mask, u8 val)
5627e34995SRabin Vincent {
5727e34995SRabin Vincent 	int ret;
5827e34995SRabin Vincent 
5927e34995SRabin Vincent 	ret = __stmpe_reg_read(stmpe, reg);
6027e34995SRabin Vincent 	if (ret < 0)
6127e34995SRabin Vincent 		return ret;
6227e34995SRabin Vincent 
6327e34995SRabin Vincent 	ret &= ~mask;
6427e34995SRabin Vincent 	ret |= val;
6527e34995SRabin Vincent 
6627e34995SRabin Vincent 	return __stmpe_reg_write(stmpe, reg, ret);
6727e34995SRabin Vincent }
6827e34995SRabin Vincent 
6927e34995SRabin Vincent static int __stmpe_block_read(struct stmpe *stmpe, u8 reg, u8 length,
7027e34995SRabin Vincent 			      u8 *values)
7127e34995SRabin Vincent {
7227e34995SRabin Vincent 	int ret;
7327e34995SRabin Vincent 
741a6e4b74SViresh Kumar 	ret = stmpe->ci->read_block(stmpe, reg, length, values);
7527e34995SRabin Vincent 	if (ret < 0)
761a6e4b74SViresh Kumar 		dev_err(stmpe->dev, "failed to read regs %#x: %d\n", reg, ret);
7727e34995SRabin Vincent 
7827e34995SRabin Vincent 	dev_vdbg(stmpe->dev, "rd: reg %#x (%d) => ret %#x\n", reg, length, ret);
7927e34995SRabin Vincent 	stmpe_dump_bytes("stmpe rd: ", values, length);
8027e34995SRabin Vincent 
8127e34995SRabin Vincent 	return ret;
8227e34995SRabin Vincent }
8327e34995SRabin Vincent 
8427e34995SRabin Vincent static int __stmpe_block_write(struct stmpe *stmpe, u8 reg, u8 length,
8527e34995SRabin Vincent 			const u8 *values)
8627e34995SRabin Vincent {
8727e34995SRabin Vincent 	int ret;
8827e34995SRabin Vincent 
8927e34995SRabin Vincent 	dev_vdbg(stmpe->dev, "wr: regs %#x (%d)\n", reg, length);
9027e34995SRabin Vincent 	stmpe_dump_bytes("stmpe wr: ", values, length);
9127e34995SRabin Vincent 
921a6e4b74SViresh Kumar 	ret = stmpe->ci->write_block(stmpe, reg, length, values);
9327e34995SRabin Vincent 	if (ret < 0)
941a6e4b74SViresh Kumar 		dev_err(stmpe->dev, "failed to write regs %#x: %d\n", reg, ret);
9527e34995SRabin Vincent 
9627e34995SRabin Vincent 	return ret;
9727e34995SRabin Vincent }
9827e34995SRabin Vincent 
9927e34995SRabin Vincent /**
10027e34995SRabin Vincent  * stmpe_enable - enable blocks on an STMPE device
10127e34995SRabin Vincent  * @stmpe:	Device to work on
10227e34995SRabin Vincent  * @blocks:	Mask of blocks (enum stmpe_block values) to enable
10327e34995SRabin Vincent  */
10427e34995SRabin Vincent int stmpe_enable(struct stmpe *stmpe, unsigned int blocks)
10527e34995SRabin Vincent {
10627e34995SRabin Vincent 	int ret;
10727e34995SRabin Vincent 
10827e34995SRabin Vincent 	mutex_lock(&stmpe->lock);
10927e34995SRabin Vincent 	ret = __stmpe_enable(stmpe, blocks);
11027e34995SRabin Vincent 	mutex_unlock(&stmpe->lock);
11127e34995SRabin Vincent 
11227e34995SRabin Vincent 	return ret;
11327e34995SRabin Vincent }
11427e34995SRabin Vincent EXPORT_SYMBOL_GPL(stmpe_enable);
11527e34995SRabin Vincent 
11627e34995SRabin Vincent /**
11727e34995SRabin Vincent  * stmpe_disable - disable blocks on an STMPE device
11827e34995SRabin Vincent  * @stmpe:	Device to work on
11927e34995SRabin Vincent  * @blocks:	Mask of blocks (enum stmpe_block values) to enable
12027e34995SRabin Vincent  */
12127e34995SRabin Vincent int stmpe_disable(struct stmpe *stmpe, unsigned int blocks)
12227e34995SRabin Vincent {
12327e34995SRabin Vincent 	int ret;
12427e34995SRabin Vincent 
12527e34995SRabin Vincent 	mutex_lock(&stmpe->lock);
12627e34995SRabin Vincent 	ret = __stmpe_disable(stmpe, blocks);
12727e34995SRabin Vincent 	mutex_unlock(&stmpe->lock);
12827e34995SRabin Vincent 
12927e34995SRabin Vincent 	return ret;
13027e34995SRabin Vincent }
13127e34995SRabin Vincent EXPORT_SYMBOL_GPL(stmpe_disable);
13227e34995SRabin Vincent 
13327e34995SRabin Vincent /**
13427e34995SRabin Vincent  * stmpe_reg_read() - read a single STMPE register
13527e34995SRabin Vincent  * @stmpe:	Device to read from
13627e34995SRabin Vincent  * @reg:	Register to read
13727e34995SRabin Vincent  */
13827e34995SRabin Vincent int stmpe_reg_read(struct stmpe *stmpe, u8 reg)
13927e34995SRabin Vincent {
14027e34995SRabin Vincent 	int ret;
14127e34995SRabin Vincent 
14227e34995SRabin Vincent 	mutex_lock(&stmpe->lock);
14327e34995SRabin Vincent 	ret = __stmpe_reg_read(stmpe, reg);
14427e34995SRabin Vincent 	mutex_unlock(&stmpe->lock);
14527e34995SRabin Vincent 
14627e34995SRabin Vincent 	return ret;
14727e34995SRabin Vincent }
14827e34995SRabin Vincent EXPORT_SYMBOL_GPL(stmpe_reg_read);
14927e34995SRabin Vincent 
15027e34995SRabin Vincent /**
15127e34995SRabin Vincent  * stmpe_reg_write() - write a single STMPE register
15227e34995SRabin Vincent  * @stmpe:	Device to write to
15327e34995SRabin Vincent  * @reg:	Register to write
15427e34995SRabin Vincent  * @val:	Value to write
15527e34995SRabin Vincent  */
15627e34995SRabin Vincent int stmpe_reg_write(struct stmpe *stmpe, u8 reg, u8 val)
15727e34995SRabin Vincent {
15827e34995SRabin Vincent 	int ret;
15927e34995SRabin Vincent 
16027e34995SRabin Vincent 	mutex_lock(&stmpe->lock);
16127e34995SRabin Vincent 	ret = __stmpe_reg_write(stmpe, reg, val);
16227e34995SRabin Vincent 	mutex_unlock(&stmpe->lock);
16327e34995SRabin Vincent 
16427e34995SRabin Vincent 	return ret;
16527e34995SRabin Vincent }
16627e34995SRabin Vincent EXPORT_SYMBOL_GPL(stmpe_reg_write);
16727e34995SRabin Vincent 
16827e34995SRabin Vincent /**
16927e34995SRabin Vincent  * stmpe_set_bits() - set the value of a bitfield in a STMPE register
17027e34995SRabin Vincent  * @stmpe:	Device to write to
17127e34995SRabin Vincent  * @reg:	Register to write
17227e34995SRabin Vincent  * @mask:	Mask of bits to set
17327e34995SRabin Vincent  * @val:	Value to set
17427e34995SRabin Vincent  */
17527e34995SRabin Vincent int stmpe_set_bits(struct stmpe *stmpe, u8 reg, u8 mask, u8 val)
17627e34995SRabin Vincent {
17727e34995SRabin Vincent 	int ret;
17827e34995SRabin Vincent 
17927e34995SRabin Vincent 	mutex_lock(&stmpe->lock);
18027e34995SRabin Vincent 	ret = __stmpe_set_bits(stmpe, reg, mask, val);
18127e34995SRabin Vincent 	mutex_unlock(&stmpe->lock);
18227e34995SRabin Vincent 
18327e34995SRabin Vincent 	return ret;
18427e34995SRabin Vincent }
18527e34995SRabin Vincent EXPORT_SYMBOL_GPL(stmpe_set_bits);
18627e34995SRabin Vincent 
18727e34995SRabin Vincent /**
18827e34995SRabin Vincent  * stmpe_block_read() - read multiple STMPE registers
18927e34995SRabin Vincent  * @stmpe:	Device to read from
19027e34995SRabin Vincent  * @reg:	First register
19127e34995SRabin Vincent  * @length:	Number of registers
19227e34995SRabin Vincent  * @values:	Buffer to write to
19327e34995SRabin Vincent  */
19427e34995SRabin Vincent int stmpe_block_read(struct stmpe *stmpe, u8 reg, u8 length, u8 *values)
19527e34995SRabin Vincent {
19627e34995SRabin Vincent 	int ret;
19727e34995SRabin Vincent 
19827e34995SRabin Vincent 	mutex_lock(&stmpe->lock);
19927e34995SRabin Vincent 	ret = __stmpe_block_read(stmpe, reg, length, values);
20027e34995SRabin Vincent 	mutex_unlock(&stmpe->lock);
20127e34995SRabin Vincent 
20227e34995SRabin Vincent 	return ret;
20327e34995SRabin Vincent }
20427e34995SRabin Vincent EXPORT_SYMBOL_GPL(stmpe_block_read);
20527e34995SRabin Vincent 
20627e34995SRabin Vincent /**
20727e34995SRabin Vincent  * stmpe_block_write() - write multiple STMPE registers
20827e34995SRabin Vincent  * @stmpe:	Device to write to
20927e34995SRabin Vincent  * @reg:	First register
21027e34995SRabin Vincent  * @length:	Number of registers
21127e34995SRabin Vincent  * @values:	Values to write
21227e34995SRabin Vincent  */
21327e34995SRabin Vincent int stmpe_block_write(struct stmpe *stmpe, u8 reg, u8 length,
21427e34995SRabin Vincent 		      const u8 *values)
21527e34995SRabin Vincent {
21627e34995SRabin Vincent 	int ret;
21727e34995SRabin Vincent 
21827e34995SRabin Vincent 	mutex_lock(&stmpe->lock);
21927e34995SRabin Vincent 	ret = __stmpe_block_write(stmpe, reg, length, values);
22027e34995SRabin Vincent 	mutex_unlock(&stmpe->lock);
22127e34995SRabin Vincent 
22227e34995SRabin Vincent 	return ret;
22327e34995SRabin Vincent }
22427e34995SRabin Vincent EXPORT_SYMBOL_GPL(stmpe_block_write);
22527e34995SRabin Vincent 
22627e34995SRabin Vincent /**
2274dcaa6b6SOm Prakash  * stmpe_set_altfunc()- set the alternate function for STMPE pins
22827e34995SRabin Vincent  * @stmpe:	Device to configure
22927e34995SRabin Vincent  * @pins:	Bitmask of pins to affect
23027e34995SRabin Vincent  * @block:	block to enable alternate functions for
23127e34995SRabin Vincent  *
23227e34995SRabin Vincent  * @pins is assumed to have a bit set for each of the bits whose alternate
23327e34995SRabin Vincent  * function is to be changed, numbered according to the GPIOXY numbers.
23427e34995SRabin Vincent  *
23527e34995SRabin Vincent  * If the GPIO module is not enabled, this function automatically enables it in
23627e34995SRabin Vincent  * order to perform the change.
23727e34995SRabin Vincent  */
23827e34995SRabin Vincent int stmpe_set_altfunc(struct stmpe *stmpe, u32 pins, enum stmpe_block block)
23927e34995SRabin Vincent {
24027e34995SRabin Vincent 	struct stmpe_variant_info *variant = stmpe->variant;
24127e34995SRabin Vincent 	u8 regaddr = stmpe->regs[STMPE_IDX_GPAFR_U_MSB];
24227e34995SRabin Vincent 	int af_bits = variant->af_bits;
24327e34995SRabin Vincent 	int numregs = DIV_ROUND_UP(stmpe->num_gpios * af_bits, 8);
24427e34995SRabin Vincent 	int mask = (1 << af_bits) - 1;
24527e34995SRabin Vincent 	u8 regs[numregs];
246*7f7f4ea1SViresh Kumar 	int af, afperreg, ret;
24727e34995SRabin Vincent 
248*7f7f4ea1SViresh Kumar 	if (!variant->get_altfunc)
249*7f7f4ea1SViresh Kumar 		return 0;
250*7f7f4ea1SViresh Kumar 
251*7f7f4ea1SViresh Kumar 	afperreg = 8 / af_bits;
25227e34995SRabin Vincent 	mutex_lock(&stmpe->lock);
25327e34995SRabin Vincent 
25427e34995SRabin Vincent 	ret = __stmpe_enable(stmpe, STMPE_BLOCK_GPIO);
25527e34995SRabin Vincent 	if (ret < 0)
25627e34995SRabin Vincent 		goto out;
25727e34995SRabin Vincent 
25827e34995SRabin Vincent 	ret = __stmpe_block_read(stmpe, regaddr, numregs, regs);
25927e34995SRabin Vincent 	if (ret < 0)
26027e34995SRabin Vincent 		goto out;
26127e34995SRabin Vincent 
26227e34995SRabin Vincent 	af = variant->get_altfunc(stmpe, block);
26327e34995SRabin Vincent 
26427e34995SRabin Vincent 	while (pins) {
26527e34995SRabin Vincent 		int pin = __ffs(pins);
26627e34995SRabin Vincent 		int regoffset = numregs - (pin / afperreg) - 1;
26727e34995SRabin Vincent 		int pos = (pin % afperreg) * (8 / afperreg);
26827e34995SRabin Vincent 
26927e34995SRabin Vincent 		regs[regoffset] &= ~(mask << pos);
27027e34995SRabin Vincent 		regs[regoffset] |= af << pos;
27127e34995SRabin Vincent 
27227e34995SRabin Vincent 		pins &= ~(1 << pin);
27327e34995SRabin Vincent 	}
27427e34995SRabin Vincent 
27527e34995SRabin Vincent 	ret = __stmpe_block_write(stmpe, regaddr, numregs, regs);
27627e34995SRabin Vincent 
27727e34995SRabin Vincent out:
27827e34995SRabin Vincent 	mutex_unlock(&stmpe->lock);
27927e34995SRabin Vincent 	return ret;
28027e34995SRabin Vincent }
28127e34995SRabin Vincent EXPORT_SYMBOL_GPL(stmpe_set_altfunc);
28227e34995SRabin Vincent 
28327e34995SRabin Vincent /*
28427e34995SRabin Vincent  * GPIO (all variants)
28527e34995SRabin Vincent  */
28627e34995SRabin Vincent 
28727e34995SRabin Vincent static struct resource stmpe_gpio_resources[] = {
28827e34995SRabin Vincent 	/* Start and end filled dynamically */
28927e34995SRabin Vincent 	{
29027e34995SRabin Vincent 		.flags	= IORESOURCE_IRQ,
29127e34995SRabin Vincent 	},
29227e34995SRabin Vincent };
29327e34995SRabin Vincent 
29427e34995SRabin Vincent static struct mfd_cell stmpe_gpio_cell = {
29527e34995SRabin Vincent 	.name		= "stmpe-gpio",
29627e34995SRabin Vincent 	.resources	= stmpe_gpio_resources,
29727e34995SRabin Vincent 	.num_resources	= ARRAY_SIZE(stmpe_gpio_resources),
29827e34995SRabin Vincent };
29927e34995SRabin Vincent 
30027e34995SRabin Vincent /*
30127e34995SRabin Vincent  * Keypad (1601, 2401, 2403)
30227e34995SRabin Vincent  */
30327e34995SRabin Vincent 
30427e34995SRabin Vincent static struct resource stmpe_keypad_resources[] = {
30527e34995SRabin Vincent 	{
30627e34995SRabin Vincent 		.name	= "KEYPAD",
30727e34995SRabin Vincent 		.start	= 0,
30827e34995SRabin Vincent 		.end	= 0,
30927e34995SRabin Vincent 		.flags	= IORESOURCE_IRQ,
31027e34995SRabin Vincent 	},
31127e34995SRabin Vincent 	{
31227e34995SRabin Vincent 		.name	= "KEYPAD_OVER",
31327e34995SRabin Vincent 		.start	= 1,
31427e34995SRabin Vincent 		.end	= 1,
31527e34995SRabin Vincent 		.flags	= IORESOURCE_IRQ,
31627e34995SRabin Vincent 	},
31727e34995SRabin Vincent };
31827e34995SRabin Vincent 
31927e34995SRabin Vincent static struct mfd_cell stmpe_keypad_cell = {
32027e34995SRabin Vincent 	.name		= "stmpe-keypad",
32127e34995SRabin Vincent 	.resources	= stmpe_keypad_resources,
32227e34995SRabin Vincent 	.num_resources	= ARRAY_SIZE(stmpe_keypad_resources),
32327e34995SRabin Vincent };
32427e34995SRabin Vincent 
32527e34995SRabin Vincent /*
326*7f7f4ea1SViresh Kumar  * STMPE801
327*7f7f4ea1SViresh Kumar  */
328*7f7f4ea1SViresh Kumar static const u8 stmpe801_regs[] = {
329*7f7f4ea1SViresh Kumar 	[STMPE_IDX_CHIP_ID]	= STMPE801_REG_CHIP_ID,
330*7f7f4ea1SViresh Kumar 	[STMPE_IDX_ICR_LSB]	= STMPE801_REG_SYS_CTRL,
331*7f7f4ea1SViresh Kumar 	[STMPE_IDX_GPMR_LSB]	= STMPE801_REG_GPIO_MP_STA,
332*7f7f4ea1SViresh Kumar 	[STMPE_IDX_GPSR_LSB]	= STMPE801_REG_GPIO_SET_PIN,
333*7f7f4ea1SViresh Kumar 	[STMPE_IDX_GPCR_LSB]	= STMPE801_REG_GPIO_SET_PIN,
334*7f7f4ea1SViresh Kumar 	[STMPE_IDX_GPDR_LSB]	= STMPE801_REG_GPIO_DIR,
335*7f7f4ea1SViresh Kumar 	[STMPE_IDX_IEGPIOR_LSB] = STMPE801_REG_GPIO_INT_EN,
336*7f7f4ea1SViresh Kumar 	[STMPE_IDX_ISGPIOR_MSB] = STMPE801_REG_GPIO_INT_STA,
337*7f7f4ea1SViresh Kumar 
338*7f7f4ea1SViresh Kumar };
339*7f7f4ea1SViresh Kumar 
340*7f7f4ea1SViresh Kumar static struct stmpe_variant_block stmpe801_blocks[] = {
341*7f7f4ea1SViresh Kumar 	{
342*7f7f4ea1SViresh Kumar 		.cell	= &stmpe_gpio_cell,
343*7f7f4ea1SViresh Kumar 		.irq	= 0,
344*7f7f4ea1SViresh Kumar 		.block	= STMPE_BLOCK_GPIO,
345*7f7f4ea1SViresh Kumar 	},
346*7f7f4ea1SViresh Kumar };
347*7f7f4ea1SViresh Kumar 
348*7f7f4ea1SViresh Kumar static int stmpe801_enable(struct stmpe *stmpe, unsigned int blocks,
349*7f7f4ea1SViresh Kumar 			   bool enable)
350*7f7f4ea1SViresh Kumar {
351*7f7f4ea1SViresh Kumar 	if (blocks & STMPE_BLOCK_GPIO)
352*7f7f4ea1SViresh Kumar 		return 0;
353*7f7f4ea1SViresh Kumar 	else
354*7f7f4ea1SViresh Kumar 		return -EINVAL;
355*7f7f4ea1SViresh Kumar }
356*7f7f4ea1SViresh Kumar 
357*7f7f4ea1SViresh Kumar static struct stmpe_variant_info stmpe801 = {
358*7f7f4ea1SViresh Kumar 	.name		= "stmpe801",
359*7f7f4ea1SViresh Kumar 	.id_val		= STMPE801_ID,
360*7f7f4ea1SViresh Kumar 	.id_mask	= 0xffff,
361*7f7f4ea1SViresh Kumar 	.num_gpios	= 8,
362*7f7f4ea1SViresh Kumar 	.regs		= stmpe801_regs,
363*7f7f4ea1SViresh Kumar 	.blocks		= stmpe801_blocks,
364*7f7f4ea1SViresh Kumar 	.num_blocks	= ARRAY_SIZE(stmpe801_blocks),
365*7f7f4ea1SViresh Kumar 	.num_irqs	= STMPE801_NR_INTERNAL_IRQS,
366*7f7f4ea1SViresh Kumar 	.enable		= stmpe801_enable,
367*7f7f4ea1SViresh Kumar };
368*7f7f4ea1SViresh Kumar 
369*7f7f4ea1SViresh Kumar /*
3701cda2394SViresh Kumar  * Touchscreen (STMPE811 or STMPE610)
37127e34995SRabin Vincent  */
37227e34995SRabin Vincent 
37327e34995SRabin Vincent static struct resource stmpe_ts_resources[] = {
37427e34995SRabin Vincent 	{
37527e34995SRabin Vincent 		.name	= "TOUCH_DET",
37627e34995SRabin Vincent 		.start	= 0,
37727e34995SRabin Vincent 		.end	= 0,
37827e34995SRabin Vincent 		.flags	= IORESOURCE_IRQ,
37927e34995SRabin Vincent 	},
38027e34995SRabin Vincent 	{
38127e34995SRabin Vincent 		.name	= "FIFO_TH",
38227e34995SRabin Vincent 		.start	= 1,
38327e34995SRabin Vincent 		.end	= 1,
38427e34995SRabin Vincent 		.flags	= IORESOURCE_IRQ,
38527e34995SRabin Vincent 	},
38627e34995SRabin Vincent };
38727e34995SRabin Vincent 
38827e34995SRabin Vincent static struct mfd_cell stmpe_ts_cell = {
38927e34995SRabin Vincent 	.name		= "stmpe-ts",
39027e34995SRabin Vincent 	.resources	= stmpe_ts_resources,
39127e34995SRabin Vincent 	.num_resources	= ARRAY_SIZE(stmpe_ts_resources),
39227e34995SRabin Vincent };
39327e34995SRabin Vincent 
39427e34995SRabin Vincent /*
3951cda2394SViresh Kumar  * STMPE811 or STMPE610
39627e34995SRabin Vincent  */
39727e34995SRabin Vincent 
39827e34995SRabin Vincent static const u8 stmpe811_regs[] = {
39927e34995SRabin Vincent 	[STMPE_IDX_CHIP_ID]	= STMPE811_REG_CHIP_ID,
40027e34995SRabin Vincent 	[STMPE_IDX_ICR_LSB]	= STMPE811_REG_INT_CTRL,
40127e34995SRabin Vincent 	[STMPE_IDX_IER_LSB]	= STMPE811_REG_INT_EN,
40227e34995SRabin Vincent 	[STMPE_IDX_ISR_MSB]	= STMPE811_REG_INT_STA,
40327e34995SRabin Vincent 	[STMPE_IDX_GPMR_LSB]	= STMPE811_REG_GPIO_MP_STA,
40427e34995SRabin Vincent 	[STMPE_IDX_GPSR_LSB]	= STMPE811_REG_GPIO_SET_PIN,
40527e34995SRabin Vincent 	[STMPE_IDX_GPCR_LSB]	= STMPE811_REG_GPIO_CLR_PIN,
40627e34995SRabin Vincent 	[STMPE_IDX_GPDR_LSB]	= STMPE811_REG_GPIO_DIR,
40727e34995SRabin Vincent 	[STMPE_IDX_GPRER_LSB]	= STMPE811_REG_GPIO_RE,
40827e34995SRabin Vincent 	[STMPE_IDX_GPFER_LSB]	= STMPE811_REG_GPIO_FE,
40927e34995SRabin Vincent 	[STMPE_IDX_GPAFR_U_MSB]	= STMPE811_REG_GPIO_AF,
41027e34995SRabin Vincent 	[STMPE_IDX_IEGPIOR_LSB]	= STMPE811_REG_GPIO_INT_EN,
41127e34995SRabin Vincent 	[STMPE_IDX_ISGPIOR_MSB]	= STMPE811_REG_GPIO_INT_STA,
41227e34995SRabin Vincent 	[STMPE_IDX_GPEDR_MSB]	= STMPE811_REG_GPIO_ED,
41327e34995SRabin Vincent };
41427e34995SRabin Vincent 
41527e34995SRabin Vincent static struct stmpe_variant_block stmpe811_blocks[] = {
41627e34995SRabin Vincent 	{
41727e34995SRabin Vincent 		.cell	= &stmpe_gpio_cell,
41827e34995SRabin Vincent 		.irq	= STMPE811_IRQ_GPIOC,
41927e34995SRabin Vincent 		.block	= STMPE_BLOCK_GPIO,
42027e34995SRabin Vincent 	},
42127e34995SRabin Vincent 	{
42227e34995SRabin Vincent 		.cell	= &stmpe_ts_cell,
42327e34995SRabin Vincent 		.irq	= STMPE811_IRQ_TOUCH_DET,
42427e34995SRabin Vincent 		.block	= STMPE_BLOCK_TOUCHSCREEN,
42527e34995SRabin Vincent 	},
42627e34995SRabin Vincent };
42727e34995SRabin Vincent 
42827e34995SRabin Vincent static int stmpe811_enable(struct stmpe *stmpe, unsigned int blocks,
42927e34995SRabin Vincent 			   bool enable)
43027e34995SRabin Vincent {
43127e34995SRabin Vincent 	unsigned int mask = 0;
43227e34995SRabin Vincent 
43327e34995SRabin Vincent 	if (blocks & STMPE_BLOCK_GPIO)
43427e34995SRabin Vincent 		mask |= STMPE811_SYS_CTRL2_GPIO_OFF;
43527e34995SRabin Vincent 
43627e34995SRabin Vincent 	if (blocks & STMPE_BLOCK_ADC)
43727e34995SRabin Vincent 		mask |= STMPE811_SYS_CTRL2_ADC_OFF;
43827e34995SRabin Vincent 
43927e34995SRabin Vincent 	if (blocks & STMPE_BLOCK_TOUCHSCREEN)
44027e34995SRabin Vincent 		mask |= STMPE811_SYS_CTRL2_TSC_OFF;
44127e34995SRabin Vincent 
44227e34995SRabin Vincent 	return __stmpe_set_bits(stmpe, STMPE811_REG_SYS_CTRL2, mask,
44327e34995SRabin Vincent 				enable ? 0 : mask);
44427e34995SRabin Vincent }
44527e34995SRabin Vincent 
44627e34995SRabin Vincent static int stmpe811_get_altfunc(struct stmpe *stmpe, enum stmpe_block block)
44727e34995SRabin Vincent {
44827e34995SRabin Vincent 	/* 0 for touchscreen, 1 for GPIO */
44927e34995SRabin Vincent 	return block != STMPE_BLOCK_TOUCHSCREEN;
45027e34995SRabin Vincent }
45127e34995SRabin Vincent 
45227e34995SRabin Vincent static struct stmpe_variant_info stmpe811 = {
45327e34995SRabin Vincent 	.name		= "stmpe811",
45427e34995SRabin Vincent 	.id_val		= 0x0811,
45527e34995SRabin Vincent 	.id_mask	= 0xffff,
45627e34995SRabin Vincent 	.num_gpios	= 8,
45727e34995SRabin Vincent 	.af_bits	= 1,
45827e34995SRabin Vincent 	.regs		= stmpe811_regs,
45927e34995SRabin Vincent 	.blocks		= stmpe811_blocks,
46027e34995SRabin Vincent 	.num_blocks	= ARRAY_SIZE(stmpe811_blocks),
46127e34995SRabin Vincent 	.num_irqs	= STMPE811_NR_INTERNAL_IRQS,
46227e34995SRabin Vincent 	.enable		= stmpe811_enable,
46327e34995SRabin Vincent 	.get_altfunc	= stmpe811_get_altfunc,
46427e34995SRabin Vincent };
46527e34995SRabin Vincent 
4661cda2394SViresh Kumar /* Similar to 811, except number of gpios */
4671cda2394SViresh Kumar static struct stmpe_variant_info stmpe610 = {
4681cda2394SViresh Kumar 	.name		= "stmpe610",
4691cda2394SViresh Kumar 	.id_val		= 0x0811,
4701cda2394SViresh Kumar 	.id_mask	= 0xffff,
4711cda2394SViresh Kumar 	.num_gpios	= 6,
4721cda2394SViresh Kumar 	.af_bits	= 1,
4731cda2394SViresh Kumar 	.regs		= stmpe811_regs,
4741cda2394SViresh Kumar 	.blocks		= stmpe811_blocks,
4751cda2394SViresh Kumar 	.num_blocks	= ARRAY_SIZE(stmpe811_blocks),
4761cda2394SViresh Kumar 	.num_irqs	= STMPE811_NR_INTERNAL_IRQS,
4771cda2394SViresh Kumar 	.enable		= stmpe811_enable,
4781cda2394SViresh Kumar 	.get_altfunc	= stmpe811_get_altfunc,
4791cda2394SViresh Kumar };
4801cda2394SViresh Kumar 
48127e34995SRabin Vincent /*
48227e34995SRabin Vincent  * STMPE1601
48327e34995SRabin Vincent  */
48427e34995SRabin Vincent 
48527e34995SRabin Vincent static const u8 stmpe1601_regs[] = {
48627e34995SRabin Vincent 	[STMPE_IDX_CHIP_ID]	= STMPE1601_REG_CHIP_ID,
48727e34995SRabin Vincent 	[STMPE_IDX_ICR_LSB]	= STMPE1601_REG_ICR_LSB,
48827e34995SRabin Vincent 	[STMPE_IDX_IER_LSB]	= STMPE1601_REG_IER_LSB,
48927e34995SRabin Vincent 	[STMPE_IDX_ISR_MSB]	= STMPE1601_REG_ISR_MSB,
49027e34995SRabin Vincent 	[STMPE_IDX_GPMR_LSB]	= STMPE1601_REG_GPIO_MP_LSB,
49127e34995SRabin Vincent 	[STMPE_IDX_GPSR_LSB]	= STMPE1601_REG_GPIO_SET_LSB,
49227e34995SRabin Vincent 	[STMPE_IDX_GPCR_LSB]	= STMPE1601_REG_GPIO_CLR_LSB,
49327e34995SRabin Vincent 	[STMPE_IDX_GPDR_LSB]	= STMPE1601_REG_GPIO_SET_DIR_LSB,
49427e34995SRabin Vincent 	[STMPE_IDX_GPRER_LSB]	= STMPE1601_REG_GPIO_RE_LSB,
49527e34995SRabin Vincent 	[STMPE_IDX_GPFER_LSB]	= STMPE1601_REG_GPIO_FE_LSB,
49627e34995SRabin Vincent 	[STMPE_IDX_GPAFR_U_MSB]	= STMPE1601_REG_GPIO_AF_U_MSB,
49727e34995SRabin Vincent 	[STMPE_IDX_IEGPIOR_LSB]	= STMPE1601_REG_INT_EN_GPIO_MASK_LSB,
49827e34995SRabin Vincent 	[STMPE_IDX_ISGPIOR_MSB]	= STMPE1601_REG_INT_STA_GPIO_MSB,
49927e34995SRabin Vincent 	[STMPE_IDX_GPEDR_MSB]	= STMPE1601_REG_GPIO_ED_MSB,
50027e34995SRabin Vincent };
50127e34995SRabin Vincent 
50227e34995SRabin Vincent static struct stmpe_variant_block stmpe1601_blocks[] = {
50327e34995SRabin Vincent 	{
50427e34995SRabin Vincent 		.cell	= &stmpe_gpio_cell,
50527e34995SRabin Vincent 		.irq	= STMPE24XX_IRQ_GPIOC,
50627e34995SRabin Vincent 		.block	= STMPE_BLOCK_GPIO,
50727e34995SRabin Vincent 	},
50827e34995SRabin Vincent 	{
50927e34995SRabin Vincent 		.cell	= &stmpe_keypad_cell,
51027e34995SRabin Vincent 		.irq	= STMPE24XX_IRQ_KEYPAD,
51127e34995SRabin Vincent 		.block	= STMPE_BLOCK_KEYPAD,
51227e34995SRabin Vincent 	},
51327e34995SRabin Vincent };
51427e34995SRabin Vincent 
5155981f4e6SSundar R Iyer /* supported autosleep timeout delay (in msecs) */
5165981f4e6SSundar R Iyer static const int stmpe_autosleep_delay[] = {
5175981f4e6SSundar R Iyer 	4, 16, 32, 64, 128, 256, 512, 1024,
5185981f4e6SSundar R Iyer };
5195981f4e6SSundar R Iyer 
5205981f4e6SSundar R Iyer static int stmpe_round_timeout(int timeout)
5215981f4e6SSundar R Iyer {
5225981f4e6SSundar R Iyer 	int i;
5235981f4e6SSundar R Iyer 
5245981f4e6SSundar R Iyer 	for (i = 0; i < ARRAY_SIZE(stmpe_autosleep_delay); i++) {
5255981f4e6SSundar R Iyer 		if (stmpe_autosleep_delay[i] >= timeout)
5265981f4e6SSundar R Iyer 			return i;
5275981f4e6SSundar R Iyer 	}
5285981f4e6SSundar R Iyer 
5295981f4e6SSundar R Iyer 	/*
5305981f4e6SSundar R Iyer 	 * requests for delays longer than supported should not return the
5315981f4e6SSundar R Iyer 	 * longest supported delay
5325981f4e6SSundar R Iyer 	 */
5335981f4e6SSundar R Iyer 	return -EINVAL;
5345981f4e6SSundar R Iyer }
5355981f4e6SSundar R Iyer 
5365981f4e6SSundar R Iyer static int stmpe_autosleep(struct stmpe *stmpe, int autosleep_timeout)
5375981f4e6SSundar R Iyer {
5385981f4e6SSundar R Iyer 	int ret;
5395981f4e6SSundar R Iyer 
5405981f4e6SSundar R Iyer 	if (!stmpe->variant->enable_autosleep)
5415981f4e6SSundar R Iyer 		return -ENOSYS;
5425981f4e6SSundar R Iyer 
5435981f4e6SSundar R Iyer 	mutex_lock(&stmpe->lock);
5445981f4e6SSundar R Iyer 	ret = stmpe->variant->enable_autosleep(stmpe, autosleep_timeout);
5455981f4e6SSundar R Iyer 	mutex_unlock(&stmpe->lock);
5465981f4e6SSundar R Iyer 
5475981f4e6SSundar R Iyer 	return ret;
5485981f4e6SSundar R Iyer }
5495981f4e6SSundar R Iyer 
5505981f4e6SSundar R Iyer /*
5515981f4e6SSundar R Iyer  * Both stmpe 1601/2403 support same layout for autosleep
5525981f4e6SSundar R Iyer  */
5535981f4e6SSundar R Iyer static int stmpe1601_autosleep(struct stmpe *stmpe,
5545981f4e6SSundar R Iyer 		int autosleep_timeout)
5555981f4e6SSundar R Iyer {
5565981f4e6SSundar R Iyer 	int ret, timeout;
5575981f4e6SSundar R Iyer 
5585981f4e6SSundar R Iyer 	/* choose the best available timeout */
5595981f4e6SSundar R Iyer 	timeout = stmpe_round_timeout(autosleep_timeout);
5605981f4e6SSundar R Iyer 	if (timeout < 0) {
5615981f4e6SSundar R Iyer 		dev_err(stmpe->dev, "invalid timeout\n");
5625981f4e6SSundar R Iyer 		return timeout;
5635981f4e6SSundar R Iyer 	}
5645981f4e6SSundar R Iyer 
5655981f4e6SSundar R Iyer 	ret = __stmpe_set_bits(stmpe, STMPE1601_REG_SYS_CTRL2,
5665981f4e6SSundar R Iyer 			STMPE1601_AUTOSLEEP_TIMEOUT_MASK,
5675981f4e6SSundar R Iyer 			timeout);
5685981f4e6SSundar R Iyer 	if (ret < 0)
5695981f4e6SSundar R Iyer 		return ret;
5705981f4e6SSundar R Iyer 
5715981f4e6SSundar R Iyer 	return __stmpe_set_bits(stmpe, STMPE1601_REG_SYS_CTRL2,
5725981f4e6SSundar R Iyer 			STPME1601_AUTOSLEEP_ENABLE,
5735981f4e6SSundar R Iyer 			STPME1601_AUTOSLEEP_ENABLE);
5745981f4e6SSundar R Iyer }
5755981f4e6SSundar R Iyer 
57627e34995SRabin Vincent static int stmpe1601_enable(struct stmpe *stmpe, unsigned int blocks,
57727e34995SRabin Vincent 			    bool enable)
57827e34995SRabin Vincent {
57927e34995SRabin Vincent 	unsigned int mask = 0;
58027e34995SRabin Vincent 
58127e34995SRabin Vincent 	if (blocks & STMPE_BLOCK_GPIO)
58227e34995SRabin Vincent 		mask |= STMPE1601_SYS_CTRL_ENABLE_GPIO;
58327e34995SRabin Vincent 
58427e34995SRabin Vincent 	if (blocks & STMPE_BLOCK_KEYPAD)
58527e34995SRabin Vincent 		mask |= STMPE1601_SYS_CTRL_ENABLE_KPC;
58627e34995SRabin Vincent 
58727e34995SRabin Vincent 	return __stmpe_set_bits(stmpe, STMPE1601_REG_SYS_CTRL, mask,
58827e34995SRabin Vincent 				enable ? mask : 0);
58927e34995SRabin Vincent }
59027e34995SRabin Vincent 
59127e34995SRabin Vincent static int stmpe1601_get_altfunc(struct stmpe *stmpe, enum stmpe_block block)
59227e34995SRabin Vincent {
59327e34995SRabin Vincent 	switch (block) {
59427e34995SRabin Vincent 	case STMPE_BLOCK_PWM:
59527e34995SRabin Vincent 		return 2;
59627e34995SRabin Vincent 
59727e34995SRabin Vincent 	case STMPE_BLOCK_KEYPAD:
59827e34995SRabin Vincent 		return 1;
59927e34995SRabin Vincent 
60027e34995SRabin Vincent 	case STMPE_BLOCK_GPIO:
60127e34995SRabin Vincent 	default:
60227e34995SRabin Vincent 		return 0;
60327e34995SRabin Vincent 	}
60427e34995SRabin Vincent }
60527e34995SRabin Vincent 
60627e34995SRabin Vincent static struct stmpe_variant_info stmpe1601 = {
60727e34995SRabin Vincent 	.name		= "stmpe1601",
60827e34995SRabin Vincent 	.id_val		= 0x0210,
60927e34995SRabin Vincent 	.id_mask	= 0xfff0,	/* at least 0x0210 and 0x0212 */
61027e34995SRabin Vincent 	.num_gpios	= 16,
61127e34995SRabin Vincent 	.af_bits	= 2,
61227e34995SRabin Vincent 	.regs		= stmpe1601_regs,
61327e34995SRabin Vincent 	.blocks		= stmpe1601_blocks,
61427e34995SRabin Vincent 	.num_blocks	= ARRAY_SIZE(stmpe1601_blocks),
61527e34995SRabin Vincent 	.num_irqs	= STMPE1601_NR_INTERNAL_IRQS,
61627e34995SRabin Vincent 	.enable		= stmpe1601_enable,
61727e34995SRabin Vincent 	.get_altfunc	= stmpe1601_get_altfunc,
6185981f4e6SSundar R Iyer 	.enable_autosleep	= stmpe1601_autosleep,
61927e34995SRabin Vincent };
62027e34995SRabin Vincent 
62127e34995SRabin Vincent /*
62227e34995SRabin Vincent  * STMPE24XX
62327e34995SRabin Vincent  */
62427e34995SRabin Vincent 
62527e34995SRabin Vincent static const u8 stmpe24xx_regs[] = {
62627e34995SRabin Vincent 	[STMPE_IDX_CHIP_ID]	= STMPE24XX_REG_CHIP_ID,
62727e34995SRabin Vincent 	[STMPE_IDX_ICR_LSB]	= STMPE24XX_REG_ICR_LSB,
62827e34995SRabin Vincent 	[STMPE_IDX_IER_LSB]	= STMPE24XX_REG_IER_LSB,
62927e34995SRabin Vincent 	[STMPE_IDX_ISR_MSB]	= STMPE24XX_REG_ISR_MSB,
63027e34995SRabin Vincent 	[STMPE_IDX_GPMR_LSB]	= STMPE24XX_REG_GPMR_LSB,
63127e34995SRabin Vincent 	[STMPE_IDX_GPSR_LSB]	= STMPE24XX_REG_GPSR_LSB,
63227e34995SRabin Vincent 	[STMPE_IDX_GPCR_LSB]	= STMPE24XX_REG_GPCR_LSB,
63327e34995SRabin Vincent 	[STMPE_IDX_GPDR_LSB]	= STMPE24XX_REG_GPDR_LSB,
63427e34995SRabin Vincent 	[STMPE_IDX_GPRER_LSB]	= STMPE24XX_REG_GPRER_LSB,
63527e34995SRabin Vincent 	[STMPE_IDX_GPFER_LSB]	= STMPE24XX_REG_GPFER_LSB,
63627e34995SRabin Vincent 	[STMPE_IDX_GPAFR_U_MSB]	= STMPE24XX_REG_GPAFR_U_MSB,
63727e34995SRabin Vincent 	[STMPE_IDX_IEGPIOR_LSB]	= STMPE24XX_REG_IEGPIOR_LSB,
63827e34995SRabin Vincent 	[STMPE_IDX_ISGPIOR_MSB]	= STMPE24XX_REG_ISGPIOR_MSB,
63927e34995SRabin Vincent 	[STMPE_IDX_GPEDR_MSB]	= STMPE24XX_REG_GPEDR_MSB,
64027e34995SRabin Vincent };
64127e34995SRabin Vincent 
64227e34995SRabin Vincent static struct stmpe_variant_block stmpe24xx_blocks[] = {
64327e34995SRabin Vincent 	{
64427e34995SRabin Vincent 		.cell	= &stmpe_gpio_cell,
64527e34995SRabin Vincent 		.irq	= STMPE24XX_IRQ_GPIOC,
64627e34995SRabin Vincent 		.block	= STMPE_BLOCK_GPIO,
64727e34995SRabin Vincent 	},
64827e34995SRabin Vincent 	{
64927e34995SRabin Vincent 		.cell	= &stmpe_keypad_cell,
65027e34995SRabin Vincent 		.irq	= STMPE24XX_IRQ_KEYPAD,
65127e34995SRabin Vincent 		.block	= STMPE_BLOCK_KEYPAD,
65227e34995SRabin Vincent 	},
65327e34995SRabin Vincent };
65427e34995SRabin Vincent 
65527e34995SRabin Vincent static int stmpe24xx_enable(struct stmpe *stmpe, unsigned int blocks,
65627e34995SRabin Vincent 			    bool enable)
65727e34995SRabin Vincent {
65827e34995SRabin Vincent 	unsigned int mask = 0;
65927e34995SRabin Vincent 
66027e34995SRabin Vincent 	if (blocks & STMPE_BLOCK_GPIO)
66127e34995SRabin Vincent 		mask |= STMPE24XX_SYS_CTRL_ENABLE_GPIO;
66227e34995SRabin Vincent 
66327e34995SRabin Vincent 	if (blocks & STMPE_BLOCK_KEYPAD)
66427e34995SRabin Vincent 		mask |= STMPE24XX_SYS_CTRL_ENABLE_KPC;
66527e34995SRabin Vincent 
66627e34995SRabin Vincent 	return __stmpe_set_bits(stmpe, STMPE24XX_REG_SYS_CTRL, mask,
66727e34995SRabin Vincent 				enable ? mask : 0);
66827e34995SRabin Vincent }
66927e34995SRabin Vincent 
67027e34995SRabin Vincent static int stmpe24xx_get_altfunc(struct stmpe *stmpe, enum stmpe_block block)
67127e34995SRabin Vincent {
67227e34995SRabin Vincent 	switch (block) {
67327e34995SRabin Vincent 	case STMPE_BLOCK_ROTATOR:
67427e34995SRabin Vincent 		return 2;
67527e34995SRabin Vincent 
67627e34995SRabin Vincent 	case STMPE_BLOCK_KEYPAD:
67727e34995SRabin Vincent 		return 1;
67827e34995SRabin Vincent 
67927e34995SRabin Vincent 	case STMPE_BLOCK_GPIO:
68027e34995SRabin Vincent 	default:
68127e34995SRabin Vincent 		return 0;
68227e34995SRabin Vincent 	}
68327e34995SRabin Vincent }
68427e34995SRabin Vincent 
68527e34995SRabin Vincent static struct stmpe_variant_info stmpe2401 = {
68627e34995SRabin Vincent 	.name		= "stmpe2401",
68727e34995SRabin Vincent 	.id_val		= 0x0101,
68827e34995SRabin Vincent 	.id_mask	= 0xffff,
68927e34995SRabin Vincent 	.num_gpios	= 24,
69027e34995SRabin Vincent 	.af_bits	= 2,
69127e34995SRabin Vincent 	.regs		= stmpe24xx_regs,
69227e34995SRabin Vincent 	.blocks		= stmpe24xx_blocks,
69327e34995SRabin Vincent 	.num_blocks	= ARRAY_SIZE(stmpe24xx_blocks),
69427e34995SRabin Vincent 	.num_irqs	= STMPE24XX_NR_INTERNAL_IRQS,
69527e34995SRabin Vincent 	.enable		= stmpe24xx_enable,
69627e34995SRabin Vincent 	.get_altfunc	= stmpe24xx_get_altfunc,
69727e34995SRabin Vincent };
69827e34995SRabin Vincent 
69927e34995SRabin Vincent static struct stmpe_variant_info stmpe2403 = {
70027e34995SRabin Vincent 	.name		= "stmpe2403",
70127e34995SRabin Vincent 	.id_val		= 0x0120,
70227e34995SRabin Vincent 	.id_mask	= 0xffff,
70327e34995SRabin Vincent 	.num_gpios	= 24,
70427e34995SRabin Vincent 	.af_bits	= 2,
70527e34995SRabin Vincent 	.regs		= stmpe24xx_regs,
70627e34995SRabin Vincent 	.blocks		= stmpe24xx_blocks,
70727e34995SRabin Vincent 	.num_blocks	= ARRAY_SIZE(stmpe24xx_blocks),
70827e34995SRabin Vincent 	.num_irqs	= STMPE24XX_NR_INTERNAL_IRQS,
70927e34995SRabin Vincent 	.enable		= stmpe24xx_enable,
71027e34995SRabin Vincent 	.get_altfunc	= stmpe24xx_get_altfunc,
7115981f4e6SSundar R Iyer 	.enable_autosleep	= stmpe1601_autosleep, /* same as stmpe1601 */
71227e34995SRabin Vincent };
71327e34995SRabin Vincent 
71427e34995SRabin Vincent static struct stmpe_variant_info *stmpe_variant_info[] = {
7151cda2394SViresh Kumar 	[STMPE610]	= &stmpe610,
716*7f7f4ea1SViresh Kumar 	[STMPE801]	= &stmpe801,
71727e34995SRabin Vincent 	[STMPE811]	= &stmpe811,
71827e34995SRabin Vincent 	[STMPE1601]	= &stmpe1601,
71927e34995SRabin Vincent 	[STMPE2401]	= &stmpe2401,
72027e34995SRabin Vincent 	[STMPE2403]	= &stmpe2403,
72127e34995SRabin Vincent };
72227e34995SRabin Vincent 
72327e34995SRabin Vincent static irqreturn_t stmpe_irq(int irq, void *data)
72427e34995SRabin Vincent {
72527e34995SRabin Vincent 	struct stmpe *stmpe = data;
72627e34995SRabin Vincent 	struct stmpe_variant_info *variant = stmpe->variant;
72727e34995SRabin Vincent 	int num = DIV_ROUND_UP(variant->num_irqs, 8);
72827e34995SRabin Vincent 	u8 israddr = stmpe->regs[STMPE_IDX_ISR_MSB];
72927e34995SRabin Vincent 	u8 isr[num];
73027e34995SRabin Vincent 	int ret;
73127e34995SRabin Vincent 	int i;
73227e34995SRabin Vincent 
733*7f7f4ea1SViresh Kumar 	if (variant->id_val == STMPE801_ID) {
734*7f7f4ea1SViresh Kumar 		handle_nested_irq(stmpe->irq_base);
735*7f7f4ea1SViresh Kumar 		return IRQ_HANDLED;
736*7f7f4ea1SViresh Kumar 	}
737*7f7f4ea1SViresh Kumar 
73827e34995SRabin Vincent 	ret = stmpe_block_read(stmpe, israddr, num, isr);
73927e34995SRabin Vincent 	if (ret < 0)
74027e34995SRabin Vincent 		return IRQ_NONE;
74127e34995SRabin Vincent 
74227e34995SRabin Vincent 	for (i = 0; i < num; i++) {
74327e34995SRabin Vincent 		int bank = num - i - 1;
74427e34995SRabin Vincent 		u8 status = isr[i];
74527e34995SRabin Vincent 		u8 clear;
74627e34995SRabin Vincent 
74727e34995SRabin Vincent 		status &= stmpe->ier[bank];
74827e34995SRabin Vincent 		if (!status)
74927e34995SRabin Vincent 			continue;
75027e34995SRabin Vincent 
75127e34995SRabin Vincent 		clear = status;
75227e34995SRabin Vincent 		while (status) {
75327e34995SRabin Vincent 			int bit = __ffs(status);
75427e34995SRabin Vincent 			int line = bank * 8 + bit;
75527e34995SRabin Vincent 
75627e34995SRabin Vincent 			handle_nested_irq(stmpe->irq_base + line);
75727e34995SRabin Vincent 			status &= ~(1 << bit);
75827e34995SRabin Vincent 		}
75927e34995SRabin Vincent 
76027e34995SRabin Vincent 		stmpe_reg_write(stmpe, israddr + i, clear);
76127e34995SRabin Vincent 	}
76227e34995SRabin Vincent 
76327e34995SRabin Vincent 	return IRQ_HANDLED;
76427e34995SRabin Vincent }
76527e34995SRabin Vincent 
76643b8c084SMark Brown static void stmpe_irq_lock(struct irq_data *data)
76727e34995SRabin Vincent {
76843b8c084SMark Brown 	struct stmpe *stmpe = irq_data_get_irq_chip_data(data);
76927e34995SRabin Vincent 
77027e34995SRabin Vincent 	mutex_lock(&stmpe->irq_lock);
77127e34995SRabin Vincent }
77227e34995SRabin Vincent 
77343b8c084SMark Brown static void stmpe_irq_sync_unlock(struct irq_data *data)
77427e34995SRabin Vincent {
77543b8c084SMark Brown 	struct stmpe *stmpe = irq_data_get_irq_chip_data(data);
77627e34995SRabin Vincent 	struct stmpe_variant_info *variant = stmpe->variant;
77727e34995SRabin Vincent 	int num = DIV_ROUND_UP(variant->num_irqs, 8);
77827e34995SRabin Vincent 	int i;
77927e34995SRabin Vincent 
78027e34995SRabin Vincent 	for (i = 0; i < num; i++) {
78127e34995SRabin Vincent 		u8 new = stmpe->ier[i];
78227e34995SRabin Vincent 		u8 old = stmpe->oldier[i];
78327e34995SRabin Vincent 
78427e34995SRabin Vincent 		if (new == old)
78527e34995SRabin Vincent 			continue;
78627e34995SRabin Vincent 
78727e34995SRabin Vincent 		stmpe->oldier[i] = new;
78827e34995SRabin Vincent 		stmpe_reg_write(stmpe, stmpe->regs[STMPE_IDX_IER_LSB] - i, new);
78927e34995SRabin Vincent 	}
79027e34995SRabin Vincent 
79127e34995SRabin Vincent 	mutex_unlock(&stmpe->irq_lock);
79227e34995SRabin Vincent }
79327e34995SRabin Vincent 
79443b8c084SMark Brown static void stmpe_irq_mask(struct irq_data *data)
79527e34995SRabin Vincent {
79643b8c084SMark Brown 	struct stmpe *stmpe = irq_data_get_irq_chip_data(data);
79743b8c084SMark Brown 	int offset = data->irq - stmpe->irq_base;
79827e34995SRabin Vincent 	int regoffset = offset / 8;
79927e34995SRabin Vincent 	int mask = 1 << (offset % 8);
80027e34995SRabin Vincent 
80127e34995SRabin Vincent 	stmpe->ier[regoffset] &= ~mask;
80227e34995SRabin Vincent }
80327e34995SRabin Vincent 
80443b8c084SMark Brown static void stmpe_irq_unmask(struct irq_data *data)
80527e34995SRabin Vincent {
80643b8c084SMark Brown 	struct stmpe *stmpe = irq_data_get_irq_chip_data(data);
80743b8c084SMark Brown 	int offset = data->irq - stmpe->irq_base;
80827e34995SRabin Vincent 	int regoffset = offset / 8;
80927e34995SRabin Vincent 	int mask = 1 << (offset % 8);
81027e34995SRabin Vincent 
81127e34995SRabin Vincent 	stmpe->ier[regoffset] |= mask;
81227e34995SRabin Vincent }
81327e34995SRabin Vincent 
81427e34995SRabin Vincent static struct irq_chip stmpe_irq_chip = {
81527e34995SRabin Vincent 	.name			= "stmpe",
81643b8c084SMark Brown 	.irq_bus_lock		= stmpe_irq_lock,
81743b8c084SMark Brown 	.irq_bus_sync_unlock	= stmpe_irq_sync_unlock,
81843b8c084SMark Brown 	.irq_mask		= stmpe_irq_mask,
81943b8c084SMark Brown 	.irq_unmask		= stmpe_irq_unmask,
82027e34995SRabin Vincent };
82127e34995SRabin Vincent 
82227e34995SRabin Vincent static int __devinit stmpe_irq_init(struct stmpe *stmpe)
82327e34995SRabin Vincent {
824*7f7f4ea1SViresh Kumar 	struct irq_chip *chip = NULL;
82527e34995SRabin Vincent 	int num_irqs = stmpe->variant->num_irqs;
82627e34995SRabin Vincent 	int base = stmpe->irq_base;
82727e34995SRabin Vincent 	int irq;
82827e34995SRabin Vincent 
829*7f7f4ea1SViresh Kumar 	if (stmpe->variant->id_val != STMPE801_ID)
830*7f7f4ea1SViresh Kumar 		chip = &stmpe_irq_chip;
831*7f7f4ea1SViresh Kumar 
83227e34995SRabin Vincent 	for (irq = base; irq < base + num_irqs; irq++) {
833d5bb1221SThomas Gleixner 		irq_set_chip_data(irq, stmpe);
834*7f7f4ea1SViresh Kumar 		irq_set_chip_and_handler(irq, chip, handle_edge_irq);
835d5bb1221SThomas Gleixner 		irq_set_nested_thread(irq, 1);
83627e34995SRabin Vincent #ifdef CONFIG_ARM
83727e34995SRabin Vincent 		set_irq_flags(irq, IRQF_VALID);
83827e34995SRabin Vincent #else
839d5bb1221SThomas Gleixner 		irq_set_noprobe(irq);
84027e34995SRabin Vincent #endif
84127e34995SRabin Vincent 	}
84227e34995SRabin Vincent 
84327e34995SRabin Vincent 	return 0;
84427e34995SRabin Vincent }
84527e34995SRabin Vincent 
84627e34995SRabin Vincent static void stmpe_irq_remove(struct stmpe *stmpe)
84727e34995SRabin Vincent {
84827e34995SRabin Vincent 	int num_irqs = stmpe->variant->num_irqs;
84927e34995SRabin Vincent 	int base = stmpe->irq_base;
85027e34995SRabin Vincent 	int irq;
85127e34995SRabin Vincent 
85227e34995SRabin Vincent 	for (irq = base; irq < base + num_irqs; irq++) {
85327e34995SRabin Vincent #ifdef CONFIG_ARM
85427e34995SRabin Vincent 		set_irq_flags(irq, 0);
85527e34995SRabin Vincent #endif
856d5bb1221SThomas Gleixner 		irq_set_chip_and_handler(irq, NULL, NULL);
857d5bb1221SThomas Gleixner 		irq_set_chip_data(irq, NULL);
85827e34995SRabin Vincent 	}
85927e34995SRabin Vincent }
86027e34995SRabin Vincent 
86127e34995SRabin Vincent static int __devinit stmpe_chip_init(struct stmpe *stmpe)
86227e34995SRabin Vincent {
86327e34995SRabin Vincent 	unsigned int irq_trigger = stmpe->pdata->irq_trigger;
8645981f4e6SSundar R Iyer 	int autosleep_timeout = stmpe->pdata->autosleep_timeout;
86527e34995SRabin Vincent 	struct stmpe_variant_info *variant = stmpe->variant;
866*7f7f4ea1SViresh Kumar 	u8 icr;
86727e34995SRabin Vincent 	unsigned int id;
86827e34995SRabin Vincent 	u8 data[2];
86927e34995SRabin Vincent 	int ret;
87027e34995SRabin Vincent 
87127e34995SRabin Vincent 	ret = stmpe_block_read(stmpe, stmpe->regs[STMPE_IDX_CHIP_ID],
87227e34995SRabin Vincent 			       ARRAY_SIZE(data), data);
87327e34995SRabin Vincent 	if (ret < 0)
87427e34995SRabin Vincent 		return ret;
87527e34995SRabin Vincent 
87627e34995SRabin Vincent 	id = (data[0] << 8) | data[1];
87727e34995SRabin Vincent 	if ((id & variant->id_mask) != variant->id_val) {
87827e34995SRabin Vincent 		dev_err(stmpe->dev, "unknown chip id: %#x\n", id);
87927e34995SRabin Vincent 		return -EINVAL;
88027e34995SRabin Vincent 	}
88127e34995SRabin Vincent 
88227e34995SRabin Vincent 	dev_info(stmpe->dev, "%s detected, chip id: %#x\n", variant->name, id);
88327e34995SRabin Vincent 
88427e34995SRabin Vincent 	/* Disable all modules -- subdrivers should enable what they need. */
88527e34995SRabin Vincent 	ret = stmpe_disable(stmpe, ~0);
88627e34995SRabin Vincent 	if (ret)
88727e34995SRabin Vincent 		return ret;
88827e34995SRabin Vincent 
889*7f7f4ea1SViresh Kumar 	if (id == STMPE801_ID)
890*7f7f4ea1SViresh Kumar 		icr = STMPE801_REG_SYS_CTRL_INT_EN;
891*7f7f4ea1SViresh Kumar 	else
892*7f7f4ea1SViresh Kumar 		icr = STMPE_ICR_LSB_GIM;
893*7f7f4ea1SViresh Kumar 
894*7f7f4ea1SViresh Kumar 	/* STMPE801 doesn't support Edge interrupts */
895*7f7f4ea1SViresh Kumar 	if (id != STMPE801_ID) {
89627e34995SRabin Vincent 		if (irq_trigger == IRQF_TRIGGER_FALLING ||
89727e34995SRabin Vincent 				irq_trigger == IRQF_TRIGGER_RISING)
89827e34995SRabin Vincent 			icr |= STMPE_ICR_LSB_EDGE;
899*7f7f4ea1SViresh Kumar 	}
90027e34995SRabin Vincent 
90127e34995SRabin Vincent 	if (irq_trigger == IRQF_TRIGGER_RISING ||
902*7f7f4ea1SViresh Kumar 			irq_trigger == IRQF_TRIGGER_HIGH) {
903*7f7f4ea1SViresh Kumar 		if (id == STMPE801_ID)
904*7f7f4ea1SViresh Kumar 			icr |= STMPE801_REG_SYS_CTRL_INT_HI;
905*7f7f4ea1SViresh Kumar 		else
90627e34995SRabin Vincent 			icr |= STMPE_ICR_LSB_HIGH;
907*7f7f4ea1SViresh Kumar 	}
90827e34995SRabin Vincent 
909*7f7f4ea1SViresh Kumar 	if (stmpe->pdata->irq_invert_polarity) {
910*7f7f4ea1SViresh Kumar 		if (id == STMPE801_ID)
911*7f7f4ea1SViresh Kumar 			icr ^= STMPE801_REG_SYS_CTRL_INT_HI;
912*7f7f4ea1SViresh Kumar 		else
91327e34995SRabin Vincent 			icr ^= STMPE_ICR_LSB_HIGH;
914*7f7f4ea1SViresh Kumar 	}
91527e34995SRabin Vincent 
9165981f4e6SSundar R Iyer 	if (stmpe->pdata->autosleep) {
9175981f4e6SSundar R Iyer 		ret = stmpe_autosleep(stmpe, autosleep_timeout);
9185981f4e6SSundar R Iyer 		if (ret)
9195981f4e6SSundar R Iyer 			return ret;
9205981f4e6SSundar R Iyer 	}
9215981f4e6SSundar R Iyer 
92227e34995SRabin Vincent 	return stmpe_reg_write(stmpe, stmpe->regs[STMPE_IDX_ICR_LSB], icr);
92327e34995SRabin Vincent }
92427e34995SRabin Vincent 
92527e34995SRabin Vincent static int __devinit stmpe_add_device(struct stmpe *stmpe,
92627e34995SRabin Vincent 				      struct mfd_cell *cell, int irq)
92727e34995SRabin Vincent {
92827e34995SRabin Vincent 	return mfd_add_devices(stmpe->dev, stmpe->pdata->id, cell, 1,
92927e34995SRabin Vincent 			       NULL, stmpe->irq_base + irq);
93027e34995SRabin Vincent }
93127e34995SRabin Vincent 
93227e34995SRabin Vincent static int __devinit stmpe_devices_init(struct stmpe *stmpe)
93327e34995SRabin Vincent {
93427e34995SRabin Vincent 	struct stmpe_variant_info *variant = stmpe->variant;
93527e34995SRabin Vincent 	unsigned int platform_blocks = stmpe->pdata->blocks;
93627e34995SRabin Vincent 	int ret = -EINVAL;
93727e34995SRabin Vincent 	int i;
93827e34995SRabin Vincent 
93927e34995SRabin Vincent 	for (i = 0; i < variant->num_blocks; i++) {
94027e34995SRabin Vincent 		struct stmpe_variant_block *block = &variant->blocks[i];
94127e34995SRabin Vincent 
94227e34995SRabin Vincent 		if (!(platform_blocks & block->block))
94327e34995SRabin Vincent 			continue;
94427e34995SRabin Vincent 
94527e34995SRabin Vincent 		platform_blocks &= ~block->block;
94627e34995SRabin Vincent 		ret = stmpe_add_device(stmpe, block->cell, block->irq);
94727e34995SRabin Vincent 		if (ret)
94827e34995SRabin Vincent 			return ret;
94927e34995SRabin Vincent 	}
95027e34995SRabin Vincent 
95127e34995SRabin Vincent 	if (platform_blocks)
95227e34995SRabin Vincent 		dev_warn(stmpe->dev,
95327e34995SRabin Vincent 			 "platform wants blocks (%#x) not present on variant",
95427e34995SRabin Vincent 			 platform_blocks);
95527e34995SRabin Vincent 
95627e34995SRabin Vincent 	return ret;
95727e34995SRabin Vincent }
95827e34995SRabin Vincent 
9591a6e4b74SViresh Kumar /* Called from client specific probe routines */
9601a6e4b74SViresh Kumar int stmpe_probe(struct stmpe_client_info *ci, int partnum)
961208c4343SSundar Iyer {
9621a6e4b74SViresh Kumar 	struct stmpe_platform_data *pdata = dev_get_platdata(ci->dev);
96327e34995SRabin Vincent 	struct stmpe *stmpe;
96427e34995SRabin Vincent 	int ret;
96527e34995SRabin Vincent 
96627e34995SRabin Vincent 	if (!pdata)
96727e34995SRabin Vincent 		return -EINVAL;
96827e34995SRabin Vincent 
96927e34995SRabin Vincent 	stmpe = kzalloc(sizeof(struct stmpe), GFP_KERNEL);
97027e34995SRabin Vincent 	if (!stmpe)
97127e34995SRabin Vincent 		return -ENOMEM;
97227e34995SRabin Vincent 
97327e34995SRabin Vincent 	mutex_init(&stmpe->irq_lock);
97427e34995SRabin Vincent 	mutex_init(&stmpe->lock);
97527e34995SRabin Vincent 
9761a6e4b74SViresh Kumar 	stmpe->dev = ci->dev;
9771a6e4b74SViresh Kumar 	stmpe->client = ci->client;
97827e34995SRabin Vincent 	stmpe->pdata = pdata;
97927e34995SRabin Vincent 	stmpe->irq_base = pdata->irq_base;
9801a6e4b74SViresh Kumar 	stmpe->ci = ci;
9811a6e4b74SViresh Kumar 	stmpe->partnum = partnum;
9821a6e4b74SViresh Kumar 	stmpe->variant = stmpe_variant_info[partnum];
98327e34995SRabin Vincent 	stmpe->regs = stmpe->variant->regs;
98427e34995SRabin Vincent 	stmpe->num_gpios = stmpe->variant->num_gpios;
9851a6e4b74SViresh Kumar 	dev_set_drvdata(stmpe->dev, stmpe);
98627e34995SRabin Vincent 
9871a6e4b74SViresh Kumar 	if (ci->init)
9881a6e4b74SViresh Kumar 		ci->init(stmpe);
98927e34995SRabin Vincent 
99073de16dbSViresh Kumar 	if (pdata->irq_over_gpio) {
99173de16dbSViresh Kumar 		ret = gpio_request_one(pdata->irq_gpio, GPIOF_DIR_IN, "stmpe");
99273de16dbSViresh Kumar 		if (ret) {
99373de16dbSViresh Kumar 			dev_err(stmpe->dev, "failed to request IRQ GPIO: %d\n",
99473de16dbSViresh Kumar 					ret);
99573de16dbSViresh Kumar 			goto out_free;
99673de16dbSViresh Kumar 		}
99773de16dbSViresh Kumar 
99873de16dbSViresh Kumar 		stmpe->irq = gpio_to_irq(pdata->irq_gpio);
99973de16dbSViresh Kumar 	} else {
10001a6e4b74SViresh Kumar 		stmpe->irq = ci->irq;
100173de16dbSViresh Kumar 	}
100273de16dbSViresh Kumar 
100327e34995SRabin Vincent 	ret = stmpe_chip_init(stmpe);
100427e34995SRabin Vincent 	if (ret)
100573de16dbSViresh Kumar 		goto free_gpio;
100627e34995SRabin Vincent 
100727e34995SRabin Vincent 	ret = stmpe_irq_init(stmpe);
100827e34995SRabin Vincent 	if (ret)
100973de16dbSViresh Kumar 		goto free_gpio;
101027e34995SRabin Vincent 
101173de16dbSViresh Kumar 	ret = request_threaded_irq(stmpe->irq, NULL, stmpe_irq,
10121a6e4b74SViresh Kumar 			pdata->irq_trigger | IRQF_ONESHOT, "stmpe", stmpe);
101327e34995SRabin Vincent 	if (ret) {
101427e34995SRabin Vincent 		dev_err(stmpe->dev, "failed to request IRQ: %d\n", ret);
101527e34995SRabin Vincent 		goto out_removeirq;
101627e34995SRabin Vincent 	}
101727e34995SRabin Vincent 
101827e34995SRabin Vincent 	ret = stmpe_devices_init(stmpe);
101927e34995SRabin Vincent 	if (ret) {
102027e34995SRabin Vincent 		dev_err(stmpe->dev, "failed to add children\n");
102127e34995SRabin Vincent 		goto out_removedevs;
102227e34995SRabin Vincent 	}
102327e34995SRabin Vincent 
102427e34995SRabin Vincent 	return 0;
102527e34995SRabin Vincent 
102627e34995SRabin Vincent out_removedevs:
102727e34995SRabin Vincent 	mfd_remove_devices(stmpe->dev);
102873de16dbSViresh Kumar 	free_irq(stmpe->irq, stmpe);
102927e34995SRabin Vincent out_removeirq:
103027e34995SRabin Vincent 	stmpe_irq_remove(stmpe);
103173de16dbSViresh Kumar free_gpio:
103273de16dbSViresh Kumar 	if (pdata->irq_over_gpio)
103373de16dbSViresh Kumar 		gpio_free(pdata->irq_gpio);
103427e34995SRabin Vincent out_free:
103527e34995SRabin Vincent 	kfree(stmpe);
103627e34995SRabin Vincent 	return ret;
103727e34995SRabin Vincent }
103827e34995SRabin Vincent 
10391a6e4b74SViresh Kumar int stmpe_remove(struct stmpe *stmpe)
104027e34995SRabin Vincent {
104127e34995SRabin Vincent 	mfd_remove_devices(stmpe->dev);
104227e34995SRabin Vincent 
104373de16dbSViresh Kumar 	free_irq(stmpe->irq, stmpe);
104427e34995SRabin Vincent 	stmpe_irq_remove(stmpe);
104527e34995SRabin Vincent 
104673de16dbSViresh Kumar 	if (stmpe->pdata->irq_over_gpio)
104773de16dbSViresh Kumar 		gpio_free(stmpe->pdata->irq_gpio);
104873de16dbSViresh Kumar 
104927e34995SRabin Vincent 	kfree(stmpe);
105027e34995SRabin Vincent 
105127e34995SRabin Vincent 	return 0;
105227e34995SRabin Vincent }
105327e34995SRabin Vincent 
1054208c4343SSundar Iyer #ifdef CONFIG_PM
10551a6e4b74SViresh Kumar static int stmpe_suspend(struct device *dev)
10561a6e4b74SViresh Kumar {
10571a6e4b74SViresh Kumar 	struct stmpe *stmpe = dev_get_drvdata(dev);
10581a6e4b74SViresh Kumar 
10591a6e4b74SViresh Kumar 	if (device_may_wakeup(dev))
10601a6e4b74SViresh Kumar 		enable_irq_wake(stmpe->irq);
10611a6e4b74SViresh Kumar 
10621a6e4b74SViresh Kumar 	return 0;
10631a6e4b74SViresh Kumar }
10641a6e4b74SViresh Kumar 
10651a6e4b74SViresh Kumar static int stmpe_resume(struct device *dev)
10661a6e4b74SViresh Kumar {
10671a6e4b74SViresh Kumar 	struct stmpe *stmpe = dev_get_drvdata(dev);
10681a6e4b74SViresh Kumar 
10691a6e4b74SViresh Kumar 	if (device_may_wakeup(dev))
10701a6e4b74SViresh Kumar 		disable_irq_wake(stmpe->irq);
10711a6e4b74SViresh Kumar 
10721a6e4b74SViresh Kumar 	return 0;
10731a6e4b74SViresh Kumar }
10741a6e4b74SViresh Kumar 
10751a6e4b74SViresh Kumar const struct dev_pm_ops stmpe_dev_pm_ops = {
1076208c4343SSundar Iyer 	.suspend	= stmpe_suspend,
1077208c4343SSundar Iyer 	.resume		= stmpe_resume,
1078208c4343SSundar Iyer };
1079208c4343SSundar Iyer #endif
1080