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