xref: /linux/include/linux/mfd/stmpe.h (revision 27e34995e1a863c1e9beba30e51dfe2a083f918d)
1*27e34995SRabin Vincent /*
2*27e34995SRabin Vincent  * Copyright (C) ST-Ericsson SA 2010
3*27e34995SRabin Vincent  *
4*27e34995SRabin Vincent  * License Terms: GNU General Public License, version 2
5*27e34995SRabin Vincent  * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
6*27e34995SRabin Vincent  */
7*27e34995SRabin Vincent 
8*27e34995SRabin Vincent #ifndef __LINUX_MFD_STMPE_H
9*27e34995SRabin Vincent #define __LINUX_MFD_STMPE_H
10*27e34995SRabin Vincent 
11*27e34995SRabin Vincent #include <linux/device.h>
12*27e34995SRabin Vincent 
13*27e34995SRabin Vincent enum stmpe_block {
14*27e34995SRabin Vincent 	STMPE_BLOCK_GPIO	= 1 << 0,
15*27e34995SRabin Vincent 	STMPE_BLOCK_KEYPAD	= 1 << 1,
16*27e34995SRabin Vincent 	STMPE_BLOCK_TOUCHSCREEN	= 1 << 2,
17*27e34995SRabin Vincent 	STMPE_BLOCK_ADC		= 1 << 3,
18*27e34995SRabin Vincent 	STMPE_BLOCK_PWM		= 1 << 4,
19*27e34995SRabin Vincent 	STMPE_BLOCK_ROTATOR	= 1 << 5,
20*27e34995SRabin Vincent };
21*27e34995SRabin Vincent 
22*27e34995SRabin Vincent enum stmpe_partnum {
23*27e34995SRabin Vincent 	STMPE811,
24*27e34995SRabin Vincent 	STMPE1601,
25*27e34995SRabin Vincent 	STMPE2401,
26*27e34995SRabin Vincent 	STMPE2403,
27*27e34995SRabin Vincent };
28*27e34995SRabin Vincent 
29*27e34995SRabin Vincent /*
30*27e34995SRabin Vincent  * For registers whose locations differ on variants,  the correct address is
31*27e34995SRabin Vincent  * obtained by indexing stmpe->regs with one of the following.
32*27e34995SRabin Vincent  */
33*27e34995SRabin Vincent enum {
34*27e34995SRabin Vincent 	STMPE_IDX_CHIP_ID,
35*27e34995SRabin Vincent 	STMPE_IDX_ICR_LSB,
36*27e34995SRabin Vincent 	STMPE_IDX_IER_LSB,
37*27e34995SRabin Vincent 	STMPE_IDX_ISR_MSB,
38*27e34995SRabin Vincent 	STMPE_IDX_GPMR_LSB,
39*27e34995SRabin Vincent 	STMPE_IDX_GPSR_LSB,
40*27e34995SRabin Vincent 	STMPE_IDX_GPCR_LSB,
41*27e34995SRabin Vincent 	STMPE_IDX_GPDR_LSB,
42*27e34995SRabin Vincent 	STMPE_IDX_GPEDR_MSB,
43*27e34995SRabin Vincent 	STMPE_IDX_GPRER_LSB,
44*27e34995SRabin Vincent 	STMPE_IDX_GPFER_LSB,
45*27e34995SRabin Vincent 	STMPE_IDX_GPAFR_U_MSB,
46*27e34995SRabin Vincent 	STMPE_IDX_IEGPIOR_LSB,
47*27e34995SRabin Vincent 	STMPE_IDX_ISGPIOR_MSB,
48*27e34995SRabin Vincent 	STMPE_IDX_MAX,
49*27e34995SRabin Vincent };
50*27e34995SRabin Vincent 
51*27e34995SRabin Vincent 
52*27e34995SRabin Vincent struct stmpe_variant_info;
53*27e34995SRabin Vincent 
54*27e34995SRabin Vincent /**
55*27e34995SRabin Vincent  * struct stmpe - STMPE MFD structure
56*27e34995SRabin Vincent  * @lock: lock protecting I/O operations
57*27e34995SRabin Vincent  * @irq_lock: IRQ bus lock
58*27e34995SRabin Vincent  * @dev: device, mostly for dev_dbg()
59*27e34995SRabin Vincent  * @i2c: i2c client
60*27e34995SRabin Vincent  * @variant: the detected STMPE model number
61*27e34995SRabin Vincent  * @regs: list of addresses of registers which are at different addresses on
62*27e34995SRabin Vincent  *	  different variants.  Indexed by one of STMPE_IDX_*.
63*27e34995SRabin Vincent  * @irq_base: starting IRQ number for internal IRQs
64*27e34995SRabin Vincent  * @num_gpios: number of gpios, differs for variants
65*27e34995SRabin Vincent  * @ier: cache of IER registers for bus_lock
66*27e34995SRabin Vincent  * @oldier: cache of IER registers for bus_lock
67*27e34995SRabin Vincent  * @pdata: platform data
68*27e34995SRabin Vincent  */
69*27e34995SRabin Vincent struct stmpe {
70*27e34995SRabin Vincent 	struct mutex lock;
71*27e34995SRabin Vincent 	struct mutex irq_lock;
72*27e34995SRabin Vincent 	struct device *dev;
73*27e34995SRabin Vincent 	struct i2c_client *i2c;
74*27e34995SRabin Vincent 	enum stmpe_partnum partnum;
75*27e34995SRabin Vincent 	struct stmpe_variant_info *variant;
76*27e34995SRabin Vincent 	const u8 *regs;
77*27e34995SRabin Vincent 
78*27e34995SRabin Vincent 	int irq_base;
79*27e34995SRabin Vincent 	int num_gpios;
80*27e34995SRabin Vincent 	u8 ier[2];
81*27e34995SRabin Vincent 	u8 oldier[2];
82*27e34995SRabin Vincent 	struct stmpe_platform_data *pdata;
83*27e34995SRabin Vincent };
84*27e34995SRabin Vincent 
85*27e34995SRabin Vincent extern int stmpe_reg_write(struct stmpe *stmpe, u8 reg, u8 data);
86*27e34995SRabin Vincent extern int stmpe_reg_read(struct stmpe *stmpe, u8 reg);
87*27e34995SRabin Vincent extern int stmpe_block_read(struct stmpe *stmpe, u8 reg, u8 length,
88*27e34995SRabin Vincent 			    u8 *values);
89*27e34995SRabin Vincent extern int stmpe_block_write(struct stmpe *stmpe, u8 reg, u8 length,
90*27e34995SRabin Vincent 			     const u8 *values);
91*27e34995SRabin Vincent extern int stmpe_set_bits(struct stmpe *stmpe, u8 reg, u8 mask, u8 val);
92*27e34995SRabin Vincent extern int stmpe_set_altfunc(struct stmpe *stmpe, u32 pins,
93*27e34995SRabin Vincent 			     enum stmpe_block block);
94*27e34995SRabin Vincent extern int stmpe_enable(struct stmpe *stmpe, unsigned int blocks);
95*27e34995SRabin Vincent extern int stmpe_disable(struct stmpe *stmpe, unsigned int blocks);
96*27e34995SRabin Vincent 
97*27e34995SRabin Vincent struct matrix_keymap_data;
98*27e34995SRabin Vincent 
99*27e34995SRabin Vincent /**
100*27e34995SRabin Vincent  * struct stmpe_keypad_platform_data - STMPE keypad platform data
101*27e34995SRabin Vincent  * @keymap_data: key map table and size
102*27e34995SRabin Vincent  * @debounce_ms: debounce interval, in ms.  Maximum is
103*27e34995SRabin Vincent  *		 %STMPE_KEYPAD_MAX_DEBOUNCE.
104*27e34995SRabin Vincent  * @scan_count: number of key scanning cycles to confirm key data.
105*27e34995SRabin Vincent  *		Maximum is %STMPE_KEYPAD_MAX_SCAN_COUNT.
106*27e34995SRabin Vincent  * @no_autorepeat: disable key autorepeat
107*27e34995SRabin Vincent  */
108*27e34995SRabin Vincent struct stmpe_keypad_platform_data {
109*27e34995SRabin Vincent 	struct matrix_keymap_data *keymap_data;
110*27e34995SRabin Vincent 	unsigned int debounce_ms;
111*27e34995SRabin Vincent 	unsigned int scan_count;
112*27e34995SRabin Vincent 	bool no_autorepeat;
113*27e34995SRabin Vincent };
114*27e34995SRabin Vincent 
115*27e34995SRabin Vincent /**
116*27e34995SRabin Vincent  * struct stmpe_gpio_platform_data - STMPE GPIO platform data
117*27e34995SRabin Vincent  * @gpio_base: first gpio number assigned.  A maximum of
118*27e34995SRabin Vincent  *	       %STMPE_NR_GPIOS GPIOs will be allocated.
119*27e34995SRabin Vincent  */
120*27e34995SRabin Vincent struct stmpe_gpio_platform_data {
121*27e34995SRabin Vincent 	int gpio_base;
122*27e34995SRabin Vincent 	void (*setup)(struct stmpe *stmpe, unsigned gpio_base);
123*27e34995SRabin Vincent 	void (*remove)(struct stmpe *stmpe, unsigned gpio_base);
124*27e34995SRabin Vincent };
125*27e34995SRabin Vincent 
126*27e34995SRabin Vincent /**
127*27e34995SRabin Vincent  * struct stmpe_ts_platform_data - stmpe811 touch screen controller platform
128*27e34995SRabin Vincent  * data
129*27e34995SRabin Vincent  * @sample_time: ADC converstion time in number of clock.
130*27e34995SRabin Vincent  * (0 -> 36 clocks, 1 -> 44 clocks, 2 -> 56 clocks, 3 -> 64 clocks,
131*27e34995SRabin Vincent  * 4 -> 80 clocks, 5 -> 96 clocks, 6 -> 144 clocks),
132*27e34995SRabin Vincent  * recommended is 4.
133*27e34995SRabin Vincent  * @mod_12b: ADC Bit mode (0 -> 10bit ADC, 1 -> 12bit ADC)
134*27e34995SRabin Vincent  * @ref_sel: ADC reference source
135*27e34995SRabin Vincent  * (0 -> internal reference, 1 -> external reference)
136*27e34995SRabin Vincent  * @adc_freq: ADC Clock speed
137*27e34995SRabin Vincent  * (0 -> 1.625 MHz, 1 -> 3.25 MHz, 2 || 3 -> 6.5 MHz)
138*27e34995SRabin Vincent  * @ave_ctrl: Sample average control
139*27e34995SRabin Vincent  * (0 -> 1 sample, 1 -> 2 samples, 2 -> 4 samples, 3 -> 8 samples)
140*27e34995SRabin Vincent  * @touch_det_delay: Touch detect interrupt delay
141*27e34995SRabin Vincent  * (0 -> 10 us, 1 -> 50 us, 2 -> 100 us, 3 -> 500 us,
142*27e34995SRabin Vincent  * 4-> 1 ms, 5 -> 5 ms, 6 -> 10 ms, 7 -> 50 ms)
143*27e34995SRabin Vincent  * recommended is 3
144*27e34995SRabin Vincent  * @settling: Panel driver settling time
145*27e34995SRabin Vincent  * (0 -> 10 us, 1 -> 100 us, 2 -> 500 us, 3 -> 1 ms,
146*27e34995SRabin Vincent  * 4 -> 5 ms, 5 -> 10 ms, 6 for 50 ms, 7 -> 100 ms)
147*27e34995SRabin Vincent  * recommended is 2
148*27e34995SRabin Vincent  * @fraction_z: Length of the fractional part in z
149*27e34995SRabin Vincent  * (fraction_z ([0..7]) = Count of the fractional part)
150*27e34995SRabin Vincent  * recommended is 7
151*27e34995SRabin Vincent  * @i_drive: current limit value of the touchscreen drivers
152*27e34995SRabin Vincent  * (0 -> 20 mA typical 35 mA max, 1 -> 50 mA typical 80 mA max)
153*27e34995SRabin Vincent  *
154*27e34995SRabin Vincent  * */
155*27e34995SRabin Vincent struct stmpe_ts_platform_data {
156*27e34995SRabin Vincent        u8 sample_time;
157*27e34995SRabin Vincent        u8 mod_12b;
158*27e34995SRabin Vincent        u8 ref_sel;
159*27e34995SRabin Vincent        u8 adc_freq;
160*27e34995SRabin Vincent        u8 ave_ctrl;
161*27e34995SRabin Vincent        u8 touch_det_delay;
162*27e34995SRabin Vincent        u8 settling;
163*27e34995SRabin Vincent        u8 fraction_z;
164*27e34995SRabin Vincent        u8 i_drive;
165*27e34995SRabin Vincent };
166*27e34995SRabin Vincent 
167*27e34995SRabin Vincent /**
168*27e34995SRabin Vincent  * struct stmpe_platform_data - STMPE platform data
169*27e34995SRabin Vincent  * @id: device id to distinguish between multiple STMPEs on the same board
170*27e34995SRabin Vincent  * @blocks: bitmask of blocks to enable (use STMPE_BLOCK_*)
171*27e34995SRabin Vincent  * @irq_trigger: IRQ trigger to use for the interrupt to the host
172*27e34995SRabin Vincent  * @irq_invert_polarity: IRQ line is connected with reversed polarity
173*27e34995SRabin Vincent  * @irq_base: base IRQ number.  %STMPE_NR_IRQS irqs will be used, or
174*27e34995SRabin Vincent  *	      %STMPE_NR_INTERNAL_IRQS if the GPIO driver is not used.
175*27e34995SRabin Vincent  * @gpio: GPIO-specific platform data
176*27e34995SRabin Vincent  * @keypad: keypad-specific platform data
177*27e34995SRabin Vincent  * @ts: touchscreen-specific platform data
178*27e34995SRabin Vincent  */
179*27e34995SRabin Vincent struct stmpe_platform_data {
180*27e34995SRabin Vincent 	int id;
181*27e34995SRabin Vincent 	unsigned int blocks;
182*27e34995SRabin Vincent 	int irq_base;
183*27e34995SRabin Vincent 	unsigned int irq_trigger;
184*27e34995SRabin Vincent 	bool irq_invert_polarity;
185*27e34995SRabin Vincent 
186*27e34995SRabin Vincent 	struct stmpe_gpio_platform_data *gpio;
187*27e34995SRabin Vincent 	struct stmpe_keypad_platform_data *keypad;
188*27e34995SRabin Vincent 	struct stmpe_ts_platform_data *ts;
189*27e34995SRabin Vincent };
190*27e34995SRabin Vincent 
191*27e34995SRabin Vincent #define STMPE_NR_INTERNAL_IRQS	9
192*27e34995SRabin Vincent #define STMPE_INT_GPIO(x)	(STMPE_NR_INTERNAL_IRQS + (x))
193*27e34995SRabin Vincent 
194*27e34995SRabin Vincent #define STMPE_NR_GPIOS		24
195*27e34995SRabin Vincent #define STMPE_NR_IRQS		STMPE_INT_GPIO(STMPE_NR_GPIOS)
196*27e34995SRabin Vincent 
197*27e34995SRabin Vincent #endif
198