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 __STMPE_H 927e34995SRabin Vincent #define __STMPE_H 1027e34995SRabin Vincent 11*1a6e4b74SViresh Kumar #include <linux/device.h> 12*1a6e4b74SViresh Kumar #include <linux/mfd/core.h> 13*1a6e4b74SViresh Kumar #include <linux/mfd/stmpe.h> 14*1a6e4b74SViresh Kumar #include <linux/printk.h> 15*1a6e4b74SViresh Kumar #include <linux/types.h> 16*1a6e4b74SViresh Kumar 17*1a6e4b74SViresh Kumar extern const struct dev_pm_ops stmpe_dev_pm_ops; 18*1a6e4b74SViresh Kumar 1927e34995SRabin Vincent #ifdef STMPE_DUMP_BYTES 2027e34995SRabin Vincent static inline void stmpe_dump_bytes(const char *str, const void *buf, 2127e34995SRabin Vincent size_t len) 2227e34995SRabin Vincent { 2327e34995SRabin Vincent print_hex_dump_bytes(str, DUMP_PREFIX_OFFSET, buf, len); 2427e34995SRabin Vincent } 2527e34995SRabin Vincent #else 2627e34995SRabin Vincent static inline void stmpe_dump_bytes(const char *str, const void *buf, 2727e34995SRabin Vincent size_t len) 2827e34995SRabin Vincent { 2927e34995SRabin Vincent } 3027e34995SRabin Vincent #endif 3127e34995SRabin Vincent 3227e34995SRabin Vincent /** 3327e34995SRabin Vincent * struct stmpe_variant_block - information about block 3427e34995SRabin Vincent * @cell: base mfd cell 3527e34995SRabin Vincent * @irq: interrupt number to be added to each IORESOURCE_IRQ 3627e34995SRabin Vincent * in the cell 3727e34995SRabin Vincent * @block: block id; used for identification with platform data and for 3827e34995SRabin Vincent * enable and altfunc callbacks 3927e34995SRabin Vincent */ 4027e34995SRabin Vincent struct stmpe_variant_block { 4127e34995SRabin Vincent struct mfd_cell *cell; 4227e34995SRabin Vincent int irq; 4327e34995SRabin Vincent enum stmpe_block block; 4427e34995SRabin Vincent }; 4527e34995SRabin Vincent 4627e34995SRabin Vincent /** 4727e34995SRabin Vincent * struct stmpe_variant_info - variant-specific information 4827e34995SRabin Vincent * @name: part name 4927e34995SRabin Vincent * @id_val: content of CHIPID register 5027e34995SRabin Vincent * @id_mask: bits valid in CHIPID register for comparison with id_val 5127e34995SRabin Vincent * @num_gpios: number of GPIOS 5227e34995SRabin Vincent * @af_bits: number of bits used to specify the alternate function 534dcaa6b6SOm Prakash * @regs: variant specific registers. 5427e34995SRabin Vincent * @blocks: list of blocks present on this device 5527e34995SRabin Vincent * @num_blocks: number of blocks present on this device 5627e34995SRabin Vincent * @num_irqs: number of internal IRQs available on this device 5727e34995SRabin Vincent * @enable: callback to enable the specified blocks. 5827e34995SRabin Vincent * Called with the I/O lock held. 5927e34995SRabin Vincent * @get_altfunc: callback to get the alternate function number for the 6027e34995SRabin Vincent * specific block 615981f4e6SSundar R Iyer * @enable_autosleep: callback to configure autosleep with specified timeout 6227e34995SRabin Vincent */ 6327e34995SRabin Vincent struct stmpe_variant_info { 6427e34995SRabin Vincent const char *name; 6527e34995SRabin Vincent u16 id_val; 6627e34995SRabin Vincent u16 id_mask; 6727e34995SRabin Vincent int num_gpios; 6827e34995SRabin Vincent int af_bits; 6927e34995SRabin Vincent const u8 *regs; 7027e34995SRabin Vincent struct stmpe_variant_block *blocks; 7127e34995SRabin Vincent int num_blocks; 7227e34995SRabin Vincent int num_irqs; 7327e34995SRabin Vincent int (*enable)(struct stmpe *stmpe, unsigned int blocks, bool enable); 7427e34995SRabin Vincent int (*get_altfunc)(struct stmpe *stmpe, enum stmpe_block block); 755981f4e6SSundar R Iyer int (*enable_autosleep)(struct stmpe *stmpe, int autosleep_timeout); 7627e34995SRabin Vincent }; 7727e34995SRabin Vincent 78*1a6e4b74SViresh Kumar /** 79*1a6e4b74SViresh Kumar * struct stmpe_client_info - i2c or spi specific routines/info 80*1a6e4b74SViresh Kumar * @data: client specific data 81*1a6e4b74SViresh Kumar * @read_byte: read single byte 82*1a6e4b74SViresh Kumar * @write_byte: write single byte 83*1a6e4b74SViresh Kumar * @read_block: read block or multiple bytes 84*1a6e4b74SViresh Kumar * @write_block: write block or multiple bytes 85*1a6e4b74SViresh Kumar * @init: client init routine, called during probe 86*1a6e4b74SViresh Kumar */ 87*1a6e4b74SViresh Kumar struct stmpe_client_info { 88*1a6e4b74SViresh Kumar void *data; 89*1a6e4b74SViresh Kumar int irq; 90*1a6e4b74SViresh Kumar void *client; 91*1a6e4b74SViresh Kumar struct device *dev; 92*1a6e4b74SViresh Kumar int (*read_byte)(struct stmpe *stmpe, u8 reg); 93*1a6e4b74SViresh Kumar int (*write_byte)(struct stmpe *stmpe, u8 reg, u8 val); 94*1a6e4b74SViresh Kumar int (*read_block)(struct stmpe *stmpe, u8 reg, u8 len, u8 *values); 95*1a6e4b74SViresh Kumar int (*write_block)(struct stmpe *stmpe, u8 reg, u8 len, 96*1a6e4b74SViresh Kumar const u8 *values); 97*1a6e4b74SViresh Kumar void (*init)(struct stmpe *stmpe); 98*1a6e4b74SViresh Kumar }; 99*1a6e4b74SViresh Kumar 100*1a6e4b74SViresh Kumar int stmpe_probe(struct stmpe_client_info *ci, int partnum); 101*1a6e4b74SViresh Kumar int stmpe_remove(struct stmpe *stmpe); 102*1a6e4b74SViresh Kumar 10327e34995SRabin Vincent #define STMPE_ICR_LSB_HIGH (1 << 2) 10427e34995SRabin Vincent #define STMPE_ICR_LSB_EDGE (1 << 1) 10527e34995SRabin Vincent #define STMPE_ICR_LSB_GIM (1 << 0) 10627e34995SRabin Vincent 10727e34995SRabin Vincent /* 10827e34995SRabin Vincent * STMPE811 10927e34995SRabin Vincent */ 11027e34995SRabin Vincent 11127e34995SRabin Vincent #define STMPE811_IRQ_TOUCH_DET 0 11227e34995SRabin Vincent #define STMPE811_IRQ_FIFO_TH 1 11327e34995SRabin Vincent #define STMPE811_IRQ_FIFO_OFLOW 2 11427e34995SRabin Vincent #define STMPE811_IRQ_FIFO_FULL 3 11527e34995SRabin Vincent #define STMPE811_IRQ_FIFO_EMPTY 4 11627e34995SRabin Vincent #define STMPE811_IRQ_TEMP_SENS 5 11727e34995SRabin Vincent #define STMPE811_IRQ_ADC 6 11827e34995SRabin Vincent #define STMPE811_IRQ_GPIOC 7 11927e34995SRabin Vincent #define STMPE811_NR_INTERNAL_IRQS 8 12027e34995SRabin Vincent 12127e34995SRabin Vincent #define STMPE811_REG_CHIP_ID 0x00 12227e34995SRabin Vincent #define STMPE811_REG_SYS_CTRL2 0x04 12327e34995SRabin Vincent #define STMPE811_REG_INT_CTRL 0x09 12427e34995SRabin Vincent #define STMPE811_REG_INT_EN 0x0A 12527e34995SRabin Vincent #define STMPE811_REG_INT_STA 0x0B 12627e34995SRabin Vincent #define STMPE811_REG_GPIO_INT_EN 0x0C 12727e34995SRabin Vincent #define STMPE811_REG_GPIO_INT_STA 0x0D 12827e34995SRabin Vincent #define STMPE811_REG_GPIO_SET_PIN 0x10 12927e34995SRabin Vincent #define STMPE811_REG_GPIO_CLR_PIN 0x11 13027e34995SRabin Vincent #define STMPE811_REG_GPIO_MP_STA 0x12 13127e34995SRabin Vincent #define STMPE811_REG_GPIO_DIR 0x13 13227e34995SRabin Vincent #define STMPE811_REG_GPIO_ED 0x14 13327e34995SRabin Vincent #define STMPE811_REG_GPIO_RE 0x15 13427e34995SRabin Vincent #define STMPE811_REG_GPIO_FE 0x16 13527e34995SRabin Vincent #define STMPE811_REG_GPIO_AF 0x17 13627e34995SRabin Vincent 13727e34995SRabin Vincent #define STMPE811_SYS_CTRL2_ADC_OFF (1 << 0) 13827e34995SRabin Vincent #define STMPE811_SYS_CTRL2_TSC_OFF (1 << 1) 13927e34995SRabin Vincent #define STMPE811_SYS_CTRL2_GPIO_OFF (1 << 2) 14027e34995SRabin Vincent #define STMPE811_SYS_CTRL2_TS_OFF (1 << 3) 14127e34995SRabin Vincent 14227e34995SRabin Vincent /* 14327e34995SRabin Vincent * STMPE1601 14427e34995SRabin Vincent */ 14527e34995SRabin Vincent 14627e34995SRabin Vincent #define STMPE1601_IRQ_GPIOC 8 14727e34995SRabin Vincent #define STMPE1601_IRQ_PWM3 7 14827e34995SRabin Vincent #define STMPE1601_IRQ_PWM2 6 14927e34995SRabin Vincent #define STMPE1601_IRQ_PWM1 5 15027e34995SRabin Vincent #define STMPE1601_IRQ_PWM0 4 15127e34995SRabin Vincent #define STMPE1601_IRQ_KEYPAD_OVER 2 15227e34995SRabin Vincent #define STMPE1601_IRQ_KEYPAD 1 15327e34995SRabin Vincent #define STMPE1601_IRQ_WAKEUP 0 15427e34995SRabin Vincent #define STMPE1601_NR_INTERNAL_IRQS 9 15527e34995SRabin Vincent 15627e34995SRabin Vincent #define STMPE1601_REG_SYS_CTRL 0x02 1575981f4e6SSundar R Iyer #define STMPE1601_REG_SYS_CTRL2 0x03 15827e34995SRabin Vincent #define STMPE1601_REG_ICR_LSB 0x11 15927e34995SRabin Vincent #define STMPE1601_REG_IER_LSB 0x13 16027e34995SRabin Vincent #define STMPE1601_REG_ISR_MSB 0x14 16127e34995SRabin Vincent #define STMPE1601_REG_CHIP_ID 0x80 16227e34995SRabin Vincent #define STMPE1601_REG_INT_EN_GPIO_MASK_LSB 0x17 16327e34995SRabin Vincent #define STMPE1601_REG_INT_STA_GPIO_MSB 0x18 16427e34995SRabin Vincent #define STMPE1601_REG_GPIO_MP_LSB 0x87 16527e34995SRabin Vincent #define STMPE1601_REG_GPIO_SET_LSB 0x83 16627e34995SRabin Vincent #define STMPE1601_REG_GPIO_CLR_LSB 0x85 16727e34995SRabin Vincent #define STMPE1601_REG_GPIO_SET_DIR_LSB 0x89 16827e34995SRabin Vincent #define STMPE1601_REG_GPIO_ED_MSB 0x8A 16927e34995SRabin Vincent #define STMPE1601_REG_GPIO_RE_LSB 0x8D 17027e34995SRabin Vincent #define STMPE1601_REG_GPIO_FE_LSB 0x8F 17127e34995SRabin Vincent #define STMPE1601_REG_GPIO_AF_U_MSB 0x92 17227e34995SRabin Vincent 17327e34995SRabin Vincent #define STMPE1601_SYS_CTRL_ENABLE_GPIO (1 << 3) 17427e34995SRabin Vincent #define STMPE1601_SYS_CTRL_ENABLE_KPC (1 << 1) 17527e34995SRabin Vincent #define STMPE1601_SYSCON_ENABLE_SPWM (1 << 0) 17627e34995SRabin Vincent 1775981f4e6SSundar R Iyer /* The 1601/2403 share the same masks */ 1785981f4e6SSundar R Iyer #define STMPE1601_AUTOSLEEP_TIMEOUT_MASK (0x7) 1795981f4e6SSundar R Iyer #define STPME1601_AUTOSLEEP_ENABLE (1 << 3) 1805981f4e6SSundar R Iyer 18127e34995SRabin Vincent /* 18227e34995SRabin Vincent * STMPE24xx 18327e34995SRabin Vincent */ 18427e34995SRabin Vincent 18527e34995SRabin Vincent #define STMPE24XX_IRQ_GPIOC 8 18627e34995SRabin Vincent #define STMPE24XX_IRQ_PWM2 7 18727e34995SRabin Vincent #define STMPE24XX_IRQ_PWM1 6 18827e34995SRabin Vincent #define STMPE24XX_IRQ_PWM0 5 18927e34995SRabin Vincent #define STMPE24XX_IRQ_ROT_OVER 4 19027e34995SRabin Vincent #define STMPE24XX_IRQ_ROT 3 19127e34995SRabin Vincent #define STMPE24XX_IRQ_KEYPAD_OVER 2 19227e34995SRabin Vincent #define STMPE24XX_IRQ_KEYPAD 1 19327e34995SRabin Vincent #define STMPE24XX_IRQ_WAKEUP 0 19427e34995SRabin Vincent #define STMPE24XX_NR_INTERNAL_IRQS 9 19527e34995SRabin Vincent 19627e34995SRabin Vincent #define STMPE24XX_REG_SYS_CTRL 0x02 19727e34995SRabin Vincent #define STMPE24XX_REG_ICR_LSB 0x11 19827e34995SRabin Vincent #define STMPE24XX_REG_IER_LSB 0x13 19927e34995SRabin Vincent #define STMPE24XX_REG_ISR_MSB 0x14 20027e34995SRabin Vincent #define STMPE24XX_REG_CHIP_ID 0x80 20127e34995SRabin Vincent #define STMPE24XX_REG_IEGPIOR_LSB 0x18 20227e34995SRabin Vincent #define STMPE24XX_REG_ISGPIOR_MSB 0x19 20327e34995SRabin Vincent #define STMPE24XX_REG_GPMR_LSB 0xA5 20427e34995SRabin Vincent #define STMPE24XX_REG_GPSR_LSB 0x85 20527e34995SRabin Vincent #define STMPE24XX_REG_GPCR_LSB 0x88 20627e34995SRabin Vincent #define STMPE24XX_REG_GPDR_LSB 0x8B 20727e34995SRabin Vincent #define STMPE24XX_REG_GPEDR_MSB 0x8C 20827e34995SRabin Vincent #define STMPE24XX_REG_GPRER_LSB 0x91 20927e34995SRabin Vincent #define STMPE24XX_REG_GPFER_LSB 0x94 21027e34995SRabin Vincent #define STMPE24XX_REG_GPAFR_U_MSB 0x9B 21127e34995SRabin Vincent 21227e34995SRabin Vincent #define STMPE24XX_SYS_CTRL_ENABLE_GPIO (1 << 3) 21327e34995SRabin Vincent #define STMPE24XX_SYSCON_ENABLE_PWM (1 << 2) 21427e34995SRabin Vincent #define STMPE24XX_SYS_CTRL_ENABLE_KPC (1 << 1) 21527e34995SRabin Vincent #define STMPE24XX_SYSCON_ENABLE_ROT (1 << 0) 21627e34995SRabin Vincent 21727e34995SRabin Vincent #endif 218