xref: /linux/include/linux/mfd/stmpe.h (revision 063755ab1d1c1127adc09703185967862584935b)
127e34995SRabin Vincent /*
227e34995SRabin Vincent  * Copyright (C) ST-Ericsson SA 2010
327e34995SRabin Vincent  *
427e34995SRabin Vincent  * License Terms: GNU General Public License, version 2
527e34995SRabin Vincent  * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
627e34995SRabin Vincent  */
727e34995SRabin Vincent 
827e34995SRabin Vincent #ifndef __LINUX_MFD_STMPE_H
927e34995SRabin Vincent #define __LINUX_MFD_STMPE_H
1027e34995SRabin Vincent 
11313162d0SPaul Gortmaker #include <linux/mutex.h>
12313162d0SPaul Gortmaker 
13*063755abSPhilippe Schenker #define STMPE_SAMPLE_TIME(x)	((x & 0xf) << 4)
14*063755abSPhilippe Schenker #define STMPE_MOD_12B(x)	((x & 0x1) << 3)
15*063755abSPhilippe Schenker #define STMPE_REF_SEL(x)	((x & 0x1) << 1)
16*063755abSPhilippe Schenker #define STMPE_ADC_FREQ(x)	(x & 0x3)
17*063755abSPhilippe Schenker #define STMPE_AVE_CTRL(x)	((x & 0x3) << 6)
18*063755abSPhilippe Schenker #define STMPE_DET_DELAY(x)	((x & 0x7) << 3)
19*063755abSPhilippe Schenker #define STMPE_SETTLING(x)	(x & 0x7)
20*063755abSPhilippe Schenker #define STMPE_FRACTION_Z(x)	(x & 0x7)
21*063755abSPhilippe Schenker #define STMPE_I_DRIVE(x)	(x & 0x1)
22*063755abSPhilippe Schenker #define STMPE_OP_MODE(x)	((x & 0x7) << 1)
23*063755abSPhilippe Schenker 
24313162d0SPaul Gortmaker struct device;
259c9e3214SLinus Walleij struct regulator;
2627e34995SRabin Vincent 
2727e34995SRabin Vincent enum stmpe_block {
2827e34995SRabin Vincent 	STMPE_BLOCK_GPIO	= 1 << 0,
2927e34995SRabin Vincent 	STMPE_BLOCK_KEYPAD	= 1 << 1,
3027e34995SRabin Vincent 	STMPE_BLOCK_TOUCHSCREEN	= 1 << 2,
3127e34995SRabin Vincent 	STMPE_BLOCK_ADC		= 1 << 3,
3227e34995SRabin Vincent 	STMPE_BLOCK_PWM		= 1 << 4,
3327e34995SRabin Vincent 	STMPE_BLOCK_ROTATOR	= 1 << 5,
3427e34995SRabin Vincent };
3527e34995SRabin Vincent 
3627e34995SRabin Vincent enum stmpe_partnum {
371cda2394SViresh Kumar 	STMPE610,
387f7f4ea1SViresh Kumar 	STMPE801,
3927e34995SRabin Vincent 	STMPE811,
406bb9f0d9SPatrice Chotard 	STMPE1600,
4127e34995SRabin Vincent 	STMPE1601,
42230f13a5SJean-Nicolas Graux 	STMPE1801,
4327e34995SRabin Vincent 	STMPE2401,
4427e34995SRabin Vincent 	STMPE2403,
45e31f9b82SChris Blair 	STMPE_NBR_PARTS
4627e34995SRabin Vincent };
4727e34995SRabin Vincent 
4827e34995SRabin Vincent /*
4927e34995SRabin Vincent  * For registers whose locations differ on variants,  the correct address is
5027e34995SRabin Vincent  * obtained by indexing stmpe->regs with one of the following.
5127e34995SRabin Vincent  */
5227e34995SRabin Vincent enum {
5327e34995SRabin Vincent 	STMPE_IDX_CHIP_ID,
540f4be8cfSPatrice Chotard 	STMPE_IDX_SYS_CTRL,
550f4be8cfSPatrice Chotard 	STMPE_IDX_SYS_CTRL2,
5627e34995SRabin Vincent 	STMPE_IDX_ICR_LSB,
5727e34995SRabin Vincent 	STMPE_IDX_IER_LSB,
58897ac667SPatrice Chotard 	STMPE_IDX_IER_MSB,
59230f13a5SJean-Nicolas Graux 	STMPE_IDX_ISR_LSB,
6027e34995SRabin Vincent 	STMPE_IDX_ISR_MSB,
6127e34995SRabin Vincent 	STMPE_IDX_GPMR_LSB,
62897ac667SPatrice Chotard 	STMPE_IDX_GPMR_CSB,
63897ac667SPatrice Chotard 	STMPE_IDX_GPMR_MSB,
6427e34995SRabin Vincent 	STMPE_IDX_GPSR_LSB,
65897ac667SPatrice Chotard 	STMPE_IDX_GPSR_CSB,
66897ac667SPatrice Chotard 	STMPE_IDX_GPSR_MSB,
6727e34995SRabin Vincent 	STMPE_IDX_GPCR_LSB,
68897ac667SPatrice Chotard 	STMPE_IDX_GPCR_CSB,
69897ac667SPatrice Chotard 	STMPE_IDX_GPCR_MSB,
7027e34995SRabin Vincent 	STMPE_IDX_GPDR_LSB,
71897ac667SPatrice Chotard 	STMPE_IDX_GPDR_CSB,
72897ac667SPatrice Chotard 	STMPE_IDX_GPDR_MSB,
73897ac667SPatrice Chotard 	STMPE_IDX_GPEDR_LSB,
74897ac667SPatrice Chotard 	STMPE_IDX_GPEDR_CSB,
7527e34995SRabin Vincent 	STMPE_IDX_GPEDR_MSB,
7627e34995SRabin Vincent 	STMPE_IDX_GPRER_LSB,
77897ac667SPatrice Chotard 	STMPE_IDX_GPRER_CSB,
78897ac667SPatrice Chotard 	STMPE_IDX_GPRER_MSB,
7927e34995SRabin Vincent 	STMPE_IDX_GPFER_LSB,
80897ac667SPatrice Chotard 	STMPE_IDX_GPFER_CSB,
81897ac667SPatrice Chotard 	STMPE_IDX_GPFER_MSB,
8280e1dd82SLinus Walleij 	STMPE_IDX_GPPUR_LSB,
8380e1dd82SLinus Walleij 	STMPE_IDX_GPPDR_LSB,
8427e34995SRabin Vincent 	STMPE_IDX_GPAFR_U_MSB,
8527e34995SRabin Vincent 	STMPE_IDX_IEGPIOR_LSB,
86897ac667SPatrice Chotard 	STMPE_IDX_IEGPIOR_CSB,
87897ac667SPatrice Chotard 	STMPE_IDX_IEGPIOR_MSB,
88230f13a5SJean-Nicolas Graux 	STMPE_IDX_ISGPIOR_LSB,
89897ac667SPatrice Chotard 	STMPE_IDX_ISGPIOR_CSB,
9027e34995SRabin Vincent 	STMPE_IDX_ISGPIOR_MSB,
9127e34995SRabin Vincent 	STMPE_IDX_MAX,
9227e34995SRabin Vincent };
9327e34995SRabin Vincent 
9427e34995SRabin Vincent 
9527e34995SRabin Vincent struct stmpe_variant_info;
961a6e4b74SViresh Kumar struct stmpe_client_info;
97fc1882dcSLinus Walleij struct stmpe_platform_data;
9827e34995SRabin Vincent 
9927e34995SRabin Vincent /**
10027e34995SRabin Vincent  * struct stmpe - STMPE MFD structure
1019c9e3214SLinus Walleij  * @vcc: optional VCC regulator
1029c9e3214SLinus Walleij  * @vio: optional VIO regulator
10327e34995SRabin Vincent  * @lock: lock protecting I/O operations
10427e34995SRabin Vincent  * @irq_lock: IRQ bus lock
10527e34995SRabin Vincent  * @dev: device, mostly for dev_dbg()
10676f93992SLee Jones  * @irq_domain: IRQ domain
1071a6e4b74SViresh Kumar  * @client: client - i2c or spi
1081a6e4b74SViresh Kumar  * @ci: client specific information
1094dcaa6b6SOm Prakash  * @partnum: part number
11027e34995SRabin Vincent  * @variant: the detected STMPE model number
11127e34995SRabin Vincent  * @regs: list of addresses of registers which are at different addresses on
11227e34995SRabin Vincent  *	  different variants.  Indexed by one of STMPE_IDX_*.
11373de16dbSViresh Kumar  * @irq: irq number for stmpe
11427e34995SRabin Vincent  * @num_gpios: number of gpios, differs for variants
11527e34995SRabin Vincent  * @ier: cache of IER registers for bus_lock
11627e34995SRabin Vincent  * @oldier: cache of IER registers for bus_lock
11727e34995SRabin Vincent  * @pdata: platform data
11827e34995SRabin Vincent  */
11927e34995SRabin Vincent struct stmpe {
1209c9e3214SLinus Walleij 	struct regulator *vcc;
1219c9e3214SLinus Walleij 	struct regulator *vio;
12227e34995SRabin Vincent 	struct mutex lock;
12327e34995SRabin Vincent 	struct mutex irq_lock;
12427e34995SRabin Vincent 	struct device *dev;
12576f93992SLee Jones 	struct irq_domain *domain;
1261a6e4b74SViresh Kumar 	void *client;
1271a6e4b74SViresh Kumar 	struct stmpe_client_info *ci;
12827e34995SRabin Vincent 	enum stmpe_partnum partnum;
12927e34995SRabin Vincent 	struct stmpe_variant_info *variant;
13027e34995SRabin Vincent 	const u8 *regs;
13127e34995SRabin Vincent 
13273de16dbSViresh Kumar 	int irq;
13327e34995SRabin Vincent 	int num_gpios;
13427e34995SRabin Vincent 	u8 ier[2];
13527e34995SRabin Vincent 	u8 oldier[2];
13627e34995SRabin Vincent 	struct stmpe_platform_data *pdata;
13727e34995SRabin Vincent };
13827e34995SRabin Vincent 
13927e34995SRabin Vincent extern int stmpe_reg_write(struct stmpe *stmpe, u8 reg, u8 data);
14027e34995SRabin Vincent extern int stmpe_reg_read(struct stmpe *stmpe, u8 reg);
14127e34995SRabin Vincent extern int stmpe_block_read(struct stmpe *stmpe, u8 reg, u8 length,
14227e34995SRabin Vincent 			    u8 *values);
14327e34995SRabin Vincent extern int stmpe_block_write(struct stmpe *stmpe, u8 reg, u8 length,
14427e34995SRabin Vincent 			     const u8 *values);
14527e34995SRabin Vincent extern int stmpe_set_bits(struct stmpe *stmpe, u8 reg, u8 mask, u8 val);
14627e34995SRabin Vincent extern int stmpe_set_altfunc(struct stmpe *stmpe, u32 pins,
14727e34995SRabin Vincent 			     enum stmpe_block block);
14827e34995SRabin Vincent extern int stmpe_enable(struct stmpe *stmpe, unsigned int blocks);
14927e34995SRabin Vincent extern int stmpe_disable(struct stmpe *stmpe, unsigned int blocks);
15027e34995SRabin Vincent 
151b8e9cf0bSWolfram Sang #define STMPE_GPIO_NOREQ_811_TOUCH	(0xf0)
152b8e9cf0bSWolfram Sang 
15327e34995SRabin Vincent #endif
154