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