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; 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, 31e31f9b82SChris Blair STMPE_NBR_PARTS 3227e34995SRabin Vincent }; 3327e34995SRabin Vincent 3427e34995SRabin Vincent /* 3527e34995SRabin Vincent * For registers whose locations differ on variants, the correct address is 3627e34995SRabin Vincent * obtained by indexing stmpe->regs with one of the following. 3727e34995SRabin Vincent */ 3827e34995SRabin Vincent enum { 3927e34995SRabin Vincent STMPE_IDX_CHIP_ID, 4027e34995SRabin Vincent STMPE_IDX_ICR_LSB, 4127e34995SRabin Vincent STMPE_IDX_IER_LSB, 4227e34995SRabin Vincent STMPE_IDX_ISR_MSB, 4327e34995SRabin Vincent STMPE_IDX_GPMR_LSB, 4427e34995SRabin Vincent STMPE_IDX_GPSR_LSB, 4527e34995SRabin Vincent STMPE_IDX_GPCR_LSB, 4627e34995SRabin Vincent STMPE_IDX_GPDR_LSB, 4727e34995SRabin Vincent STMPE_IDX_GPEDR_MSB, 4827e34995SRabin Vincent STMPE_IDX_GPRER_LSB, 4927e34995SRabin Vincent STMPE_IDX_GPFER_LSB, 5027e34995SRabin Vincent STMPE_IDX_GPAFR_U_MSB, 5127e34995SRabin Vincent STMPE_IDX_IEGPIOR_LSB, 5227e34995SRabin Vincent STMPE_IDX_ISGPIOR_MSB, 5327e34995SRabin Vincent STMPE_IDX_MAX, 5427e34995SRabin Vincent }; 5527e34995SRabin Vincent 5627e34995SRabin Vincent 5727e34995SRabin Vincent struct stmpe_variant_info; 581a6e4b74SViresh Kumar struct stmpe_client_info; 5927e34995SRabin Vincent 6027e34995SRabin Vincent /** 6127e34995SRabin Vincent * struct stmpe - STMPE MFD structure 6227e34995SRabin Vincent * @lock: lock protecting I/O operations 6327e34995SRabin Vincent * @irq_lock: IRQ bus lock 6427e34995SRabin Vincent * @dev: device, mostly for dev_dbg() 65*76f93992SLee Jones * @irq_domain: IRQ domain 661a6e4b74SViresh Kumar * @client: client - i2c or spi 671a6e4b74SViresh Kumar * @ci: client specific information 684dcaa6b6SOm Prakash * @partnum: part number 6927e34995SRabin Vincent * @variant: the detected STMPE model number 7027e34995SRabin Vincent * @regs: list of addresses of registers which are at different addresses on 7127e34995SRabin Vincent * different variants. Indexed by one of STMPE_IDX_*. 7273de16dbSViresh Kumar * @irq: irq number for stmpe 7327e34995SRabin Vincent * @irq_base: starting IRQ number for internal IRQs 7427e34995SRabin Vincent * @num_gpios: number of gpios, differs for variants 7527e34995SRabin Vincent * @ier: cache of IER registers for bus_lock 7627e34995SRabin Vincent * @oldier: cache of IER registers for bus_lock 7727e34995SRabin Vincent * @pdata: platform data 7827e34995SRabin Vincent */ 7927e34995SRabin Vincent struct stmpe { 8027e34995SRabin Vincent struct mutex lock; 8127e34995SRabin Vincent struct mutex irq_lock; 8227e34995SRabin Vincent struct device *dev; 83*76f93992SLee Jones struct irq_domain *domain; 841a6e4b74SViresh Kumar void *client; 851a6e4b74SViresh Kumar struct stmpe_client_info *ci; 8627e34995SRabin Vincent enum stmpe_partnum partnum; 8727e34995SRabin Vincent struct stmpe_variant_info *variant; 8827e34995SRabin Vincent const u8 *regs; 8927e34995SRabin Vincent 9073de16dbSViresh Kumar int irq; 9127e34995SRabin Vincent int irq_base; 9227e34995SRabin Vincent int num_gpios; 9327e34995SRabin Vincent u8 ier[2]; 9427e34995SRabin Vincent u8 oldier[2]; 9527e34995SRabin Vincent struct stmpe_platform_data *pdata; 9627e34995SRabin Vincent }; 9727e34995SRabin Vincent 9827e34995SRabin Vincent extern int stmpe_reg_write(struct stmpe *stmpe, u8 reg, u8 data); 9927e34995SRabin Vincent extern int stmpe_reg_read(struct stmpe *stmpe, u8 reg); 10027e34995SRabin Vincent extern int stmpe_block_read(struct stmpe *stmpe, u8 reg, u8 length, 10127e34995SRabin Vincent u8 *values); 10227e34995SRabin Vincent extern int stmpe_block_write(struct stmpe *stmpe, u8 reg, u8 length, 10327e34995SRabin Vincent const u8 *values); 10427e34995SRabin Vincent extern int stmpe_set_bits(struct stmpe *stmpe, u8 reg, u8 mask, u8 val); 10527e34995SRabin Vincent extern int stmpe_set_altfunc(struct stmpe *stmpe, u32 pins, 10627e34995SRabin Vincent enum stmpe_block block); 10727e34995SRabin Vincent extern int stmpe_enable(struct stmpe *stmpe, unsigned int blocks); 10827e34995SRabin Vincent extern int stmpe_disable(struct stmpe *stmpe, unsigned int blocks); 10927e34995SRabin Vincent 11027e34995SRabin Vincent struct matrix_keymap_data; 11127e34995SRabin Vincent 11227e34995SRabin Vincent /** 11327e34995SRabin Vincent * struct stmpe_keypad_platform_data - STMPE keypad platform data 11427e34995SRabin Vincent * @keymap_data: key map table and size 11527e34995SRabin Vincent * @debounce_ms: debounce interval, in ms. Maximum is 11627e34995SRabin Vincent * %STMPE_KEYPAD_MAX_DEBOUNCE. 11727e34995SRabin Vincent * @scan_count: number of key scanning cycles to confirm key data. 11827e34995SRabin Vincent * Maximum is %STMPE_KEYPAD_MAX_SCAN_COUNT. 11927e34995SRabin Vincent * @no_autorepeat: disable key autorepeat 12027e34995SRabin Vincent */ 12127e34995SRabin Vincent struct stmpe_keypad_platform_data { 1221379f49eSLinus Walleij const struct matrix_keymap_data *keymap_data; 12327e34995SRabin Vincent unsigned int debounce_ms; 12427e34995SRabin Vincent unsigned int scan_count; 12527e34995SRabin Vincent bool no_autorepeat; 12627e34995SRabin Vincent }; 12727e34995SRabin Vincent 128b8e9cf0bSWolfram Sang #define STMPE_GPIO_NOREQ_811_TOUCH (0xf0) 129b8e9cf0bSWolfram Sang 13027e34995SRabin Vincent /** 13127e34995SRabin Vincent * struct stmpe_gpio_platform_data - STMPE GPIO platform data 13227e34995SRabin Vincent * @gpio_base: first gpio number assigned. A maximum of 13327e34995SRabin Vincent * %STMPE_NR_GPIOS GPIOs will be allocated. 134b8e9cf0bSWolfram Sang * @norequest_mask: bitmask specifying which GPIOs should _not_ be 135b8e9cf0bSWolfram Sang * requestable due to different usage (e.g. touch, keypad) 136b8e9cf0bSWolfram Sang * STMPE_GPIO_NOREQ_* macros can be used here. 1374dcaa6b6SOm Prakash * @setup: board specific setup callback. 1384dcaa6b6SOm Prakash * @remove: board specific remove callback 13927e34995SRabin Vincent */ 14027e34995SRabin Vincent struct stmpe_gpio_platform_data { 14127e34995SRabin Vincent int gpio_base; 142b8e9cf0bSWolfram Sang unsigned norequest_mask; 14327e34995SRabin Vincent void (*setup)(struct stmpe *stmpe, unsigned gpio_base); 14427e34995SRabin Vincent void (*remove)(struct stmpe *stmpe, unsigned gpio_base); 14527e34995SRabin Vincent }; 14627e34995SRabin Vincent 14727e34995SRabin Vincent /** 14827e34995SRabin Vincent * struct stmpe_ts_platform_data - stmpe811 touch screen controller platform 14927e34995SRabin Vincent * data 15027e34995SRabin Vincent * @sample_time: ADC converstion time in number of clock. 15127e34995SRabin Vincent * (0 -> 36 clocks, 1 -> 44 clocks, 2 -> 56 clocks, 3 -> 64 clocks, 15227e34995SRabin Vincent * 4 -> 80 clocks, 5 -> 96 clocks, 6 -> 144 clocks), 15327e34995SRabin Vincent * recommended is 4. 15427e34995SRabin Vincent * @mod_12b: ADC Bit mode (0 -> 10bit ADC, 1 -> 12bit ADC) 15527e34995SRabin Vincent * @ref_sel: ADC reference source 15627e34995SRabin Vincent * (0 -> internal reference, 1 -> external reference) 15727e34995SRabin Vincent * @adc_freq: ADC Clock speed 15827e34995SRabin Vincent * (0 -> 1.625 MHz, 1 -> 3.25 MHz, 2 || 3 -> 6.5 MHz) 15927e34995SRabin Vincent * @ave_ctrl: Sample average control 16027e34995SRabin Vincent * (0 -> 1 sample, 1 -> 2 samples, 2 -> 4 samples, 3 -> 8 samples) 16127e34995SRabin Vincent * @touch_det_delay: Touch detect interrupt delay 16227e34995SRabin Vincent * (0 -> 10 us, 1 -> 50 us, 2 -> 100 us, 3 -> 500 us, 16327e34995SRabin Vincent * 4-> 1 ms, 5 -> 5 ms, 6 -> 10 ms, 7 -> 50 ms) 16427e34995SRabin Vincent * recommended is 3 16527e34995SRabin Vincent * @settling: Panel driver settling time 16627e34995SRabin Vincent * (0 -> 10 us, 1 -> 100 us, 2 -> 500 us, 3 -> 1 ms, 16727e34995SRabin Vincent * 4 -> 5 ms, 5 -> 10 ms, 6 for 50 ms, 7 -> 100 ms) 16827e34995SRabin Vincent * recommended is 2 16927e34995SRabin Vincent * @fraction_z: Length of the fractional part in z 17027e34995SRabin Vincent * (fraction_z ([0..7]) = Count of the fractional part) 17127e34995SRabin Vincent * recommended is 7 17227e34995SRabin Vincent * @i_drive: current limit value of the touchscreen drivers 17327e34995SRabin Vincent * (0 -> 20 mA typical 35 mA max, 1 -> 50 mA typical 80 mA max) 17427e34995SRabin Vincent * 17527e34995SRabin Vincent * */ 17627e34995SRabin Vincent struct stmpe_ts_platform_data { 17727e34995SRabin Vincent u8 sample_time; 17827e34995SRabin Vincent u8 mod_12b; 17927e34995SRabin Vincent u8 ref_sel; 18027e34995SRabin Vincent u8 adc_freq; 18127e34995SRabin Vincent u8 ave_ctrl; 18227e34995SRabin Vincent u8 touch_det_delay; 18327e34995SRabin Vincent u8 settling; 18427e34995SRabin Vincent u8 fraction_z; 18527e34995SRabin Vincent u8 i_drive; 18627e34995SRabin Vincent }; 18727e34995SRabin Vincent 18827e34995SRabin Vincent /** 18927e34995SRabin Vincent * struct stmpe_platform_data - STMPE platform data 19027e34995SRabin Vincent * @id: device id to distinguish between multiple STMPEs on the same board 19127e34995SRabin Vincent * @blocks: bitmask of blocks to enable (use STMPE_BLOCK_*) 19227e34995SRabin Vincent * @irq_trigger: IRQ trigger to use for the interrupt to the host 19327e34995SRabin Vincent * @irq_invert_polarity: IRQ line is connected with reversed polarity 1945981f4e6SSundar R Iyer * @autosleep: bool to enable/disable stmpe autosleep 1955981f4e6SSundar R Iyer * @autosleep_timeout: inactivity timeout in milliseconds for autosleep 19627e34995SRabin Vincent * @irq_base: base IRQ number. %STMPE_NR_IRQS irqs will be used, or 19727e34995SRabin Vincent * %STMPE_NR_INTERNAL_IRQS if the GPIO driver is not used. 19873de16dbSViresh Kumar * @irq_over_gpio: true if gpio is used to get irq 19973de16dbSViresh Kumar * @irq_gpio: gpio number over which irq will be requested (significant only if 20073de16dbSViresh Kumar * irq_over_gpio is true) 20127e34995SRabin Vincent * @gpio: GPIO-specific platform data 20227e34995SRabin Vincent * @keypad: keypad-specific platform data 20327e34995SRabin Vincent * @ts: touchscreen-specific platform data 20427e34995SRabin Vincent */ 20527e34995SRabin Vincent struct stmpe_platform_data { 20627e34995SRabin Vincent int id; 20727e34995SRabin Vincent unsigned int blocks; 20827e34995SRabin Vincent int irq_base; 20927e34995SRabin Vincent unsigned int irq_trigger; 21027e34995SRabin Vincent bool irq_invert_polarity; 2115981f4e6SSundar R Iyer bool autosleep; 21273de16dbSViresh Kumar bool irq_over_gpio; 21373de16dbSViresh Kumar int irq_gpio; 2145981f4e6SSundar R Iyer int autosleep_timeout; 21527e34995SRabin Vincent 21627e34995SRabin Vincent struct stmpe_gpio_platform_data *gpio; 21727e34995SRabin Vincent struct stmpe_keypad_platform_data *keypad; 21827e34995SRabin Vincent struct stmpe_ts_platform_data *ts; 21927e34995SRabin Vincent }; 22027e34995SRabin Vincent 22127e34995SRabin Vincent #define STMPE_NR_INTERNAL_IRQS 9 22227e34995SRabin Vincent #define STMPE_INT_GPIO(x) (STMPE_NR_INTERNAL_IRQS + (x)) 22327e34995SRabin Vincent 22427e34995SRabin Vincent #define STMPE_NR_GPIOS 24 22527e34995SRabin Vincent #define STMPE_NR_IRQS STMPE_INT_GPIO(STMPE_NR_GPIOS) 22627e34995SRabin Vincent 22727e34995SRabin Vincent #endif 228