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 1127e34995SRabin Vincent #include <linux/device.h> 1227e34995SRabin Vincent 1327e34995SRabin Vincent enum stmpe_block { 1427e34995SRabin Vincent STMPE_BLOCK_GPIO = 1 << 0, 1527e34995SRabin Vincent STMPE_BLOCK_KEYPAD = 1 << 1, 1627e34995SRabin Vincent STMPE_BLOCK_TOUCHSCREEN = 1 << 2, 1727e34995SRabin Vincent STMPE_BLOCK_ADC = 1 << 3, 1827e34995SRabin Vincent STMPE_BLOCK_PWM = 1 << 4, 1927e34995SRabin Vincent STMPE_BLOCK_ROTATOR = 1 << 5, 2027e34995SRabin Vincent }; 2127e34995SRabin Vincent 2227e34995SRabin Vincent enum stmpe_partnum { 2327e34995SRabin Vincent STMPE811, 2427e34995SRabin Vincent STMPE1601, 2527e34995SRabin Vincent STMPE2401, 2627e34995SRabin Vincent STMPE2403, 2727e34995SRabin Vincent }; 2827e34995SRabin Vincent 2927e34995SRabin Vincent /* 3027e34995SRabin Vincent * For registers whose locations differ on variants, the correct address is 3127e34995SRabin Vincent * obtained by indexing stmpe->regs with one of the following. 3227e34995SRabin Vincent */ 3327e34995SRabin Vincent enum { 3427e34995SRabin Vincent STMPE_IDX_CHIP_ID, 3527e34995SRabin Vincent STMPE_IDX_ICR_LSB, 3627e34995SRabin Vincent STMPE_IDX_IER_LSB, 3727e34995SRabin Vincent STMPE_IDX_ISR_MSB, 3827e34995SRabin Vincent STMPE_IDX_GPMR_LSB, 3927e34995SRabin Vincent STMPE_IDX_GPSR_LSB, 4027e34995SRabin Vincent STMPE_IDX_GPCR_LSB, 4127e34995SRabin Vincent STMPE_IDX_GPDR_LSB, 4227e34995SRabin Vincent STMPE_IDX_GPEDR_MSB, 4327e34995SRabin Vincent STMPE_IDX_GPRER_LSB, 4427e34995SRabin Vincent STMPE_IDX_GPFER_LSB, 4527e34995SRabin Vincent STMPE_IDX_GPAFR_U_MSB, 4627e34995SRabin Vincent STMPE_IDX_IEGPIOR_LSB, 4727e34995SRabin Vincent STMPE_IDX_ISGPIOR_MSB, 4827e34995SRabin Vincent STMPE_IDX_MAX, 4927e34995SRabin Vincent }; 5027e34995SRabin Vincent 5127e34995SRabin Vincent 5227e34995SRabin Vincent struct stmpe_variant_info; 5327e34995SRabin Vincent 5427e34995SRabin Vincent /** 5527e34995SRabin Vincent * struct stmpe - STMPE MFD structure 5627e34995SRabin Vincent * @lock: lock protecting I/O operations 5727e34995SRabin Vincent * @irq_lock: IRQ bus lock 5827e34995SRabin Vincent * @dev: device, mostly for dev_dbg() 5927e34995SRabin Vincent * @i2c: i2c client 6027e34995SRabin Vincent * @variant: the detected STMPE model number 6127e34995SRabin Vincent * @regs: list of addresses of registers which are at different addresses on 6227e34995SRabin Vincent * different variants. Indexed by one of STMPE_IDX_*. 6327e34995SRabin Vincent * @irq_base: starting IRQ number for internal IRQs 6427e34995SRabin Vincent * @num_gpios: number of gpios, differs for variants 6527e34995SRabin Vincent * @ier: cache of IER registers for bus_lock 6627e34995SRabin Vincent * @oldier: cache of IER registers for bus_lock 6727e34995SRabin Vincent * @pdata: platform data 6827e34995SRabin Vincent */ 6927e34995SRabin Vincent struct stmpe { 7027e34995SRabin Vincent struct mutex lock; 7127e34995SRabin Vincent struct mutex irq_lock; 7227e34995SRabin Vincent struct device *dev; 7327e34995SRabin Vincent struct i2c_client *i2c; 7427e34995SRabin Vincent enum stmpe_partnum partnum; 7527e34995SRabin Vincent struct stmpe_variant_info *variant; 7627e34995SRabin Vincent const u8 *regs; 7727e34995SRabin Vincent 7827e34995SRabin Vincent int irq_base; 7927e34995SRabin Vincent int num_gpios; 8027e34995SRabin Vincent u8 ier[2]; 8127e34995SRabin Vincent u8 oldier[2]; 8227e34995SRabin Vincent struct stmpe_platform_data *pdata; 8327e34995SRabin Vincent }; 8427e34995SRabin Vincent 8527e34995SRabin Vincent extern int stmpe_reg_write(struct stmpe *stmpe, u8 reg, u8 data); 8627e34995SRabin Vincent extern int stmpe_reg_read(struct stmpe *stmpe, u8 reg); 8727e34995SRabin Vincent extern int stmpe_block_read(struct stmpe *stmpe, u8 reg, u8 length, 8827e34995SRabin Vincent u8 *values); 8927e34995SRabin Vincent extern int stmpe_block_write(struct stmpe *stmpe, u8 reg, u8 length, 9027e34995SRabin Vincent const u8 *values); 9127e34995SRabin Vincent extern int stmpe_set_bits(struct stmpe *stmpe, u8 reg, u8 mask, u8 val); 9227e34995SRabin Vincent extern int stmpe_set_altfunc(struct stmpe *stmpe, u32 pins, 9327e34995SRabin Vincent enum stmpe_block block); 9427e34995SRabin Vincent extern int stmpe_enable(struct stmpe *stmpe, unsigned int blocks); 9527e34995SRabin Vincent extern int stmpe_disable(struct stmpe *stmpe, unsigned int blocks); 9627e34995SRabin Vincent 9727e34995SRabin Vincent struct matrix_keymap_data; 9827e34995SRabin Vincent 9927e34995SRabin Vincent /** 10027e34995SRabin Vincent * struct stmpe_keypad_platform_data - STMPE keypad platform data 10127e34995SRabin Vincent * @keymap_data: key map table and size 10227e34995SRabin Vincent * @debounce_ms: debounce interval, in ms. Maximum is 10327e34995SRabin Vincent * %STMPE_KEYPAD_MAX_DEBOUNCE. 10427e34995SRabin Vincent * @scan_count: number of key scanning cycles to confirm key data. 10527e34995SRabin Vincent * Maximum is %STMPE_KEYPAD_MAX_SCAN_COUNT. 10627e34995SRabin Vincent * @no_autorepeat: disable key autorepeat 10727e34995SRabin Vincent */ 10827e34995SRabin Vincent struct stmpe_keypad_platform_data { 10927e34995SRabin Vincent struct matrix_keymap_data *keymap_data; 11027e34995SRabin Vincent unsigned int debounce_ms; 11127e34995SRabin Vincent unsigned int scan_count; 11227e34995SRabin Vincent bool no_autorepeat; 11327e34995SRabin Vincent }; 11427e34995SRabin Vincent 115*b8e9cf0bSWolfram Sang #define STMPE_GPIO_NOREQ_811_TOUCH (0xf0) 116*b8e9cf0bSWolfram Sang 11727e34995SRabin Vincent /** 11827e34995SRabin Vincent * struct stmpe_gpio_platform_data - STMPE GPIO platform data 11927e34995SRabin Vincent * @gpio_base: first gpio number assigned. A maximum of 12027e34995SRabin Vincent * %STMPE_NR_GPIOS GPIOs will be allocated. 121*b8e9cf0bSWolfram Sang * @norequest_mask: bitmask specifying which GPIOs should _not_ be 122*b8e9cf0bSWolfram Sang * requestable due to different usage (e.g. touch, keypad) 123*b8e9cf0bSWolfram Sang * STMPE_GPIO_NOREQ_* macros can be used here. 12427e34995SRabin Vincent */ 12527e34995SRabin Vincent struct stmpe_gpio_platform_data { 12627e34995SRabin Vincent int gpio_base; 127*b8e9cf0bSWolfram Sang unsigned norequest_mask; 12827e34995SRabin Vincent void (*setup)(struct stmpe *stmpe, unsigned gpio_base); 12927e34995SRabin Vincent void (*remove)(struct stmpe *stmpe, unsigned gpio_base); 13027e34995SRabin Vincent }; 13127e34995SRabin Vincent 13227e34995SRabin Vincent /** 13327e34995SRabin Vincent * struct stmpe_ts_platform_data - stmpe811 touch screen controller platform 13427e34995SRabin Vincent * data 13527e34995SRabin Vincent * @sample_time: ADC converstion time in number of clock. 13627e34995SRabin Vincent * (0 -> 36 clocks, 1 -> 44 clocks, 2 -> 56 clocks, 3 -> 64 clocks, 13727e34995SRabin Vincent * 4 -> 80 clocks, 5 -> 96 clocks, 6 -> 144 clocks), 13827e34995SRabin Vincent * recommended is 4. 13927e34995SRabin Vincent * @mod_12b: ADC Bit mode (0 -> 10bit ADC, 1 -> 12bit ADC) 14027e34995SRabin Vincent * @ref_sel: ADC reference source 14127e34995SRabin Vincent * (0 -> internal reference, 1 -> external reference) 14227e34995SRabin Vincent * @adc_freq: ADC Clock speed 14327e34995SRabin Vincent * (0 -> 1.625 MHz, 1 -> 3.25 MHz, 2 || 3 -> 6.5 MHz) 14427e34995SRabin Vincent * @ave_ctrl: Sample average control 14527e34995SRabin Vincent * (0 -> 1 sample, 1 -> 2 samples, 2 -> 4 samples, 3 -> 8 samples) 14627e34995SRabin Vincent * @touch_det_delay: Touch detect interrupt delay 14727e34995SRabin Vincent * (0 -> 10 us, 1 -> 50 us, 2 -> 100 us, 3 -> 500 us, 14827e34995SRabin Vincent * 4-> 1 ms, 5 -> 5 ms, 6 -> 10 ms, 7 -> 50 ms) 14927e34995SRabin Vincent * recommended is 3 15027e34995SRabin Vincent * @settling: Panel driver settling time 15127e34995SRabin Vincent * (0 -> 10 us, 1 -> 100 us, 2 -> 500 us, 3 -> 1 ms, 15227e34995SRabin Vincent * 4 -> 5 ms, 5 -> 10 ms, 6 for 50 ms, 7 -> 100 ms) 15327e34995SRabin Vincent * recommended is 2 15427e34995SRabin Vincent * @fraction_z: Length of the fractional part in z 15527e34995SRabin Vincent * (fraction_z ([0..7]) = Count of the fractional part) 15627e34995SRabin Vincent * recommended is 7 15727e34995SRabin Vincent * @i_drive: current limit value of the touchscreen drivers 15827e34995SRabin Vincent * (0 -> 20 mA typical 35 mA max, 1 -> 50 mA typical 80 mA max) 15927e34995SRabin Vincent * 16027e34995SRabin Vincent * */ 16127e34995SRabin Vincent struct stmpe_ts_platform_data { 16227e34995SRabin Vincent u8 sample_time; 16327e34995SRabin Vincent u8 mod_12b; 16427e34995SRabin Vincent u8 ref_sel; 16527e34995SRabin Vincent u8 adc_freq; 16627e34995SRabin Vincent u8 ave_ctrl; 16727e34995SRabin Vincent u8 touch_det_delay; 16827e34995SRabin Vincent u8 settling; 16927e34995SRabin Vincent u8 fraction_z; 17027e34995SRabin Vincent u8 i_drive; 17127e34995SRabin Vincent }; 17227e34995SRabin Vincent 17327e34995SRabin Vincent /** 17427e34995SRabin Vincent * struct stmpe_platform_data - STMPE platform data 17527e34995SRabin Vincent * @id: device id to distinguish between multiple STMPEs on the same board 17627e34995SRabin Vincent * @blocks: bitmask of blocks to enable (use STMPE_BLOCK_*) 17727e34995SRabin Vincent * @irq_trigger: IRQ trigger to use for the interrupt to the host 17827e34995SRabin Vincent * @irq_invert_polarity: IRQ line is connected with reversed polarity 1795981f4e6SSundar R Iyer * @autosleep: bool to enable/disable stmpe autosleep 1805981f4e6SSundar R Iyer * @autosleep_timeout: inactivity timeout in milliseconds for autosleep 18127e34995SRabin Vincent * @irq_base: base IRQ number. %STMPE_NR_IRQS irqs will be used, or 18227e34995SRabin Vincent * %STMPE_NR_INTERNAL_IRQS if the GPIO driver is not used. 18327e34995SRabin Vincent * @gpio: GPIO-specific platform data 18427e34995SRabin Vincent * @keypad: keypad-specific platform data 18527e34995SRabin Vincent * @ts: touchscreen-specific platform data 18627e34995SRabin Vincent */ 18727e34995SRabin Vincent struct stmpe_platform_data { 18827e34995SRabin Vincent int id; 18927e34995SRabin Vincent unsigned int blocks; 19027e34995SRabin Vincent int irq_base; 19127e34995SRabin Vincent unsigned int irq_trigger; 19227e34995SRabin Vincent bool irq_invert_polarity; 1935981f4e6SSundar R Iyer bool autosleep; 1945981f4e6SSundar R Iyer int autosleep_timeout; 19527e34995SRabin Vincent 19627e34995SRabin Vincent struct stmpe_gpio_platform_data *gpio; 19727e34995SRabin Vincent struct stmpe_keypad_platform_data *keypad; 19827e34995SRabin Vincent struct stmpe_ts_platform_data *ts; 19927e34995SRabin Vincent }; 20027e34995SRabin Vincent 20127e34995SRabin Vincent #define STMPE_NR_INTERNAL_IRQS 9 20227e34995SRabin Vincent #define STMPE_INT_GPIO(x) (STMPE_NR_INTERNAL_IRQS + (x)) 20327e34995SRabin Vincent 20427e34995SRabin Vincent #define STMPE_NR_GPIOS 24 20527e34995SRabin Vincent #define STMPE_NR_IRQS STMPE_INT_GPIO(STMPE_NR_GPIOS) 20627e34995SRabin Vincent 20727e34995SRabin Vincent #endif 208