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 13313162d0SPaul Gortmaker struct device; 14*9c9e3214SLinus Walleij struct regulator; 1527e34995SRabin Vincent 1627e34995SRabin Vincent enum stmpe_block { 1727e34995SRabin Vincent STMPE_BLOCK_GPIO = 1 << 0, 1827e34995SRabin Vincent STMPE_BLOCK_KEYPAD = 1 << 1, 1927e34995SRabin Vincent STMPE_BLOCK_TOUCHSCREEN = 1 << 2, 2027e34995SRabin Vincent STMPE_BLOCK_ADC = 1 << 3, 2127e34995SRabin Vincent STMPE_BLOCK_PWM = 1 << 4, 2227e34995SRabin Vincent STMPE_BLOCK_ROTATOR = 1 << 5, 2327e34995SRabin Vincent }; 2427e34995SRabin Vincent 2527e34995SRabin Vincent enum stmpe_partnum { 261cda2394SViresh Kumar STMPE610, 277f7f4ea1SViresh Kumar STMPE801, 2827e34995SRabin Vincent STMPE811, 2927e34995SRabin Vincent STMPE1601, 30230f13a5SJean-Nicolas Graux STMPE1801, 3127e34995SRabin Vincent STMPE2401, 3227e34995SRabin Vincent STMPE2403, 33e31f9b82SChris Blair STMPE_NBR_PARTS 3427e34995SRabin Vincent }; 3527e34995SRabin Vincent 3627e34995SRabin Vincent /* 3727e34995SRabin Vincent * For registers whose locations differ on variants, the correct address is 3827e34995SRabin Vincent * obtained by indexing stmpe->regs with one of the following. 3927e34995SRabin Vincent */ 4027e34995SRabin Vincent enum { 4127e34995SRabin Vincent STMPE_IDX_CHIP_ID, 4227e34995SRabin Vincent STMPE_IDX_ICR_LSB, 4327e34995SRabin Vincent STMPE_IDX_IER_LSB, 44230f13a5SJean-Nicolas Graux STMPE_IDX_ISR_LSB, 4527e34995SRabin Vincent STMPE_IDX_ISR_MSB, 4627e34995SRabin Vincent STMPE_IDX_GPMR_LSB, 4727e34995SRabin Vincent STMPE_IDX_GPSR_LSB, 4827e34995SRabin Vincent STMPE_IDX_GPCR_LSB, 4927e34995SRabin Vincent STMPE_IDX_GPDR_LSB, 5027e34995SRabin Vincent STMPE_IDX_GPEDR_MSB, 5127e34995SRabin Vincent STMPE_IDX_GPRER_LSB, 5227e34995SRabin Vincent STMPE_IDX_GPFER_LSB, 5327e34995SRabin Vincent STMPE_IDX_GPAFR_U_MSB, 5427e34995SRabin Vincent STMPE_IDX_IEGPIOR_LSB, 55230f13a5SJean-Nicolas Graux STMPE_IDX_ISGPIOR_LSB, 5627e34995SRabin Vincent STMPE_IDX_ISGPIOR_MSB, 5727e34995SRabin Vincent STMPE_IDX_MAX, 5827e34995SRabin Vincent }; 5927e34995SRabin Vincent 6027e34995SRabin Vincent 6127e34995SRabin Vincent struct stmpe_variant_info; 621a6e4b74SViresh Kumar struct stmpe_client_info; 6327e34995SRabin Vincent 6427e34995SRabin Vincent /** 6527e34995SRabin Vincent * struct stmpe - STMPE MFD structure 66*9c9e3214SLinus Walleij * @vcc: optional VCC regulator 67*9c9e3214SLinus Walleij * @vio: optional VIO regulator 6827e34995SRabin Vincent * @lock: lock protecting I/O operations 6927e34995SRabin Vincent * @irq_lock: IRQ bus lock 7027e34995SRabin Vincent * @dev: device, mostly for dev_dbg() 7176f93992SLee Jones * @irq_domain: IRQ domain 721a6e4b74SViresh Kumar * @client: client - i2c or spi 731a6e4b74SViresh Kumar * @ci: client specific information 744dcaa6b6SOm Prakash * @partnum: part number 7527e34995SRabin Vincent * @variant: the detected STMPE model number 7627e34995SRabin Vincent * @regs: list of addresses of registers which are at different addresses on 7727e34995SRabin Vincent * different variants. Indexed by one of STMPE_IDX_*. 7873de16dbSViresh Kumar * @irq: irq number for stmpe 7927e34995SRabin Vincent * @irq_base: starting IRQ number for internal IRQs 8027e34995SRabin Vincent * @num_gpios: number of gpios, differs for variants 8127e34995SRabin Vincent * @ier: cache of IER registers for bus_lock 8227e34995SRabin Vincent * @oldier: cache of IER registers for bus_lock 8327e34995SRabin Vincent * @pdata: platform data 8427e34995SRabin Vincent */ 8527e34995SRabin Vincent struct stmpe { 86*9c9e3214SLinus Walleij struct regulator *vcc; 87*9c9e3214SLinus Walleij struct regulator *vio; 8827e34995SRabin Vincent struct mutex lock; 8927e34995SRabin Vincent struct mutex irq_lock; 9027e34995SRabin Vincent struct device *dev; 9176f93992SLee Jones struct irq_domain *domain; 921a6e4b74SViresh Kumar void *client; 931a6e4b74SViresh Kumar struct stmpe_client_info *ci; 9427e34995SRabin Vincent enum stmpe_partnum partnum; 9527e34995SRabin Vincent struct stmpe_variant_info *variant; 9627e34995SRabin Vincent const u8 *regs; 9727e34995SRabin Vincent 9873de16dbSViresh Kumar int irq; 9927e34995SRabin Vincent int irq_base; 10027e34995SRabin Vincent int num_gpios; 10127e34995SRabin Vincent u8 ier[2]; 10227e34995SRabin Vincent u8 oldier[2]; 10327e34995SRabin Vincent struct stmpe_platform_data *pdata; 10427e34995SRabin Vincent }; 10527e34995SRabin Vincent 10627e34995SRabin Vincent extern int stmpe_reg_write(struct stmpe *stmpe, u8 reg, u8 data); 10727e34995SRabin Vincent extern int stmpe_reg_read(struct stmpe *stmpe, u8 reg); 10827e34995SRabin Vincent extern int stmpe_block_read(struct stmpe *stmpe, u8 reg, u8 length, 10927e34995SRabin Vincent u8 *values); 11027e34995SRabin Vincent extern int stmpe_block_write(struct stmpe *stmpe, u8 reg, u8 length, 11127e34995SRabin Vincent const u8 *values); 11227e34995SRabin Vincent extern int stmpe_set_bits(struct stmpe *stmpe, u8 reg, u8 mask, u8 val); 11327e34995SRabin Vincent extern int stmpe_set_altfunc(struct stmpe *stmpe, u32 pins, 11427e34995SRabin Vincent enum stmpe_block block); 11527e34995SRabin Vincent extern int stmpe_enable(struct stmpe *stmpe, unsigned int blocks); 11627e34995SRabin Vincent extern int stmpe_disable(struct stmpe *stmpe, unsigned int blocks); 11727e34995SRabin Vincent 11827e34995SRabin Vincent struct matrix_keymap_data; 11927e34995SRabin Vincent 12027e34995SRabin Vincent /** 12127e34995SRabin Vincent * struct stmpe_keypad_platform_data - STMPE keypad platform data 12227e34995SRabin Vincent * @keymap_data: key map table and size 12327e34995SRabin Vincent * @debounce_ms: debounce interval, in ms. Maximum is 12427e34995SRabin Vincent * %STMPE_KEYPAD_MAX_DEBOUNCE. 12527e34995SRabin Vincent * @scan_count: number of key scanning cycles to confirm key data. 12627e34995SRabin Vincent * Maximum is %STMPE_KEYPAD_MAX_SCAN_COUNT. 12727e34995SRabin Vincent * @no_autorepeat: disable key autorepeat 12827e34995SRabin Vincent */ 12927e34995SRabin Vincent struct stmpe_keypad_platform_data { 1301379f49eSLinus Walleij const struct matrix_keymap_data *keymap_data; 13127e34995SRabin Vincent unsigned int debounce_ms; 13227e34995SRabin Vincent unsigned int scan_count; 13327e34995SRabin Vincent bool no_autorepeat; 13427e34995SRabin Vincent }; 13527e34995SRabin Vincent 136b8e9cf0bSWolfram Sang #define STMPE_GPIO_NOREQ_811_TOUCH (0xf0) 137b8e9cf0bSWolfram Sang 13827e34995SRabin Vincent /** 13927e34995SRabin Vincent * struct stmpe_gpio_platform_data - STMPE GPIO platform data 14027e34995SRabin Vincent * @gpio_base: first gpio number assigned. A maximum of 14127e34995SRabin Vincent * %STMPE_NR_GPIOS GPIOs will be allocated. 142b8e9cf0bSWolfram Sang * @norequest_mask: bitmask specifying which GPIOs should _not_ be 143b8e9cf0bSWolfram Sang * requestable due to different usage (e.g. touch, keypad) 144b8e9cf0bSWolfram Sang * STMPE_GPIO_NOREQ_* macros can be used here. 1454dcaa6b6SOm Prakash * @setup: board specific setup callback. 1464dcaa6b6SOm Prakash * @remove: board specific remove callback 14727e34995SRabin Vincent */ 14827e34995SRabin Vincent struct stmpe_gpio_platform_data { 14927e34995SRabin Vincent int gpio_base; 150b8e9cf0bSWolfram Sang unsigned norequest_mask; 15127e34995SRabin Vincent void (*setup)(struct stmpe *stmpe, unsigned gpio_base); 15227e34995SRabin Vincent void (*remove)(struct stmpe *stmpe, unsigned gpio_base); 15327e34995SRabin Vincent }; 15427e34995SRabin Vincent 15527e34995SRabin Vincent /** 15627e34995SRabin Vincent * struct stmpe_ts_platform_data - stmpe811 touch screen controller platform 15727e34995SRabin Vincent * data 15827e34995SRabin Vincent * @sample_time: ADC converstion time in number of clock. 15927e34995SRabin Vincent * (0 -> 36 clocks, 1 -> 44 clocks, 2 -> 56 clocks, 3 -> 64 clocks, 16027e34995SRabin Vincent * 4 -> 80 clocks, 5 -> 96 clocks, 6 -> 144 clocks), 16127e34995SRabin Vincent * recommended is 4. 16227e34995SRabin Vincent * @mod_12b: ADC Bit mode (0 -> 10bit ADC, 1 -> 12bit ADC) 16327e34995SRabin Vincent * @ref_sel: ADC reference source 16427e34995SRabin Vincent * (0 -> internal reference, 1 -> external reference) 16527e34995SRabin Vincent * @adc_freq: ADC Clock speed 16627e34995SRabin Vincent * (0 -> 1.625 MHz, 1 -> 3.25 MHz, 2 || 3 -> 6.5 MHz) 16727e34995SRabin Vincent * @ave_ctrl: Sample average control 16827e34995SRabin Vincent * (0 -> 1 sample, 1 -> 2 samples, 2 -> 4 samples, 3 -> 8 samples) 16927e34995SRabin Vincent * @touch_det_delay: Touch detect interrupt delay 17027e34995SRabin Vincent * (0 -> 10 us, 1 -> 50 us, 2 -> 100 us, 3 -> 500 us, 17127e34995SRabin Vincent * 4-> 1 ms, 5 -> 5 ms, 6 -> 10 ms, 7 -> 50 ms) 17227e34995SRabin Vincent * recommended is 3 17327e34995SRabin Vincent * @settling: Panel driver settling time 17427e34995SRabin Vincent * (0 -> 10 us, 1 -> 100 us, 2 -> 500 us, 3 -> 1 ms, 17527e34995SRabin Vincent * 4 -> 5 ms, 5 -> 10 ms, 6 for 50 ms, 7 -> 100 ms) 17627e34995SRabin Vincent * recommended is 2 17727e34995SRabin Vincent * @fraction_z: Length of the fractional part in z 17827e34995SRabin Vincent * (fraction_z ([0..7]) = Count of the fractional part) 17927e34995SRabin Vincent * recommended is 7 18027e34995SRabin Vincent * @i_drive: current limit value of the touchscreen drivers 18127e34995SRabin Vincent * (0 -> 20 mA typical 35 mA max, 1 -> 50 mA typical 80 mA max) 18227e34995SRabin Vincent * 18327e34995SRabin Vincent * */ 18427e34995SRabin Vincent struct stmpe_ts_platform_data { 18527e34995SRabin Vincent u8 sample_time; 18627e34995SRabin Vincent u8 mod_12b; 18727e34995SRabin Vincent u8 ref_sel; 18827e34995SRabin Vincent u8 adc_freq; 18927e34995SRabin Vincent u8 ave_ctrl; 19027e34995SRabin Vincent u8 touch_det_delay; 19127e34995SRabin Vincent u8 settling; 19227e34995SRabin Vincent u8 fraction_z; 19327e34995SRabin Vincent u8 i_drive; 19427e34995SRabin Vincent }; 19527e34995SRabin Vincent 19627e34995SRabin Vincent /** 19727e34995SRabin Vincent * struct stmpe_platform_data - STMPE platform data 19827e34995SRabin Vincent * @id: device id to distinguish between multiple STMPEs on the same board 19927e34995SRabin Vincent * @blocks: bitmask of blocks to enable (use STMPE_BLOCK_*) 20027e34995SRabin Vincent * @irq_trigger: IRQ trigger to use for the interrupt to the host 2015981f4e6SSundar R Iyer * @autosleep: bool to enable/disable stmpe autosleep 2025981f4e6SSundar R Iyer * @autosleep_timeout: inactivity timeout in milliseconds for autosleep 20327e34995SRabin Vincent * @irq_base: base IRQ number. %STMPE_NR_IRQS irqs will be used, or 20427e34995SRabin Vincent * %STMPE_NR_INTERNAL_IRQS if the GPIO driver is not used. 20573de16dbSViresh Kumar * @irq_over_gpio: true if gpio is used to get irq 20673de16dbSViresh Kumar * @irq_gpio: gpio number over which irq will be requested (significant only if 20773de16dbSViresh Kumar * irq_over_gpio is true) 20827e34995SRabin Vincent * @gpio: GPIO-specific platform data 20927e34995SRabin Vincent * @keypad: keypad-specific platform data 21027e34995SRabin Vincent * @ts: touchscreen-specific platform data 21127e34995SRabin Vincent */ 21227e34995SRabin Vincent struct stmpe_platform_data { 21327e34995SRabin Vincent int id; 21427e34995SRabin Vincent unsigned int blocks; 21527e34995SRabin Vincent int irq_base; 21627e34995SRabin Vincent unsigned int irq_trigger; 2175981f4e6SSundar R Iyer bool autosleep; 21873de16dbSViresh Kumar bool irq_over_gpio; 21973de16dbSViresh Kumar int irq_gpio; 2205981f4e6SSundar R Iyer int autosleep_timeout; 22127e34995SRabin Vincent 22227e34995SRabin Vincent struct stmpe_gpio_platform_data *gpio; 22327e34995SRabin Vincent struct stmpe_keypad_platform_data *keypad; 22427e34995SRabin Vincent struct stmpe_ts_platform_data *ts; 22527e34995SRabin Vincent }; 22627e34995SRabin Vincent 22727e34995SRabin Vincent #define STMPE_NR_INTERNAL_IRQS 9 22827e34995SRabin Vincent #define STMPE_INT_GPIO(x) (STMPE_NR_INTERNAL_IRQS + (x)) 22927e34995SRabin Vincent 23027e34995SRabin Vincent #define STMPE_NR_GPIOS 24 23127e34995SRabin Vincent #define STMPE_NR_IRQS STMPE_INT_GPIO(STMPE_NR_GPIOS) 23227e34995SRabin Vincent 23327e34995SRabin Vincent #endif 234