Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright (C) ST-Ericsson SA 2010
0004  *
0005  * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
0006  */
0007 
0008 #ifndef __STMPE_H
0009 #define __STMPE_H
0010 
0011 #include <linux/device.h>
0012 #include <linux/mfd/core.h>
0013 #include <linux/mfd/stmpe.h>
0014 #include <linux/printk.h>
0015 #include <linux/types.h>
0016 
0017 extern const struct dev_pm_ops stmpe_dev_pm_ops;
0018 
0019 #ifdef STMPE_DUMP_BYTES
0020 static inline void stmpe_dump_bytes(const char *str, const void *buf,
0021                     size_t len)
0022 {
0023     print_hex_dump_bytes(str, DUMP_PREFIX_OFFSET, buf, len);
0024 }
0025 #else
0026 static inline void stmpe_dump_bytes(const char *str, const void *buf,
0027                     size_t len)
0028 {
0029 }
0030 #endif
0031 
0032 /**
0033  * struct stmpe_variant_block - information about block
0034  * @cell:   base mfd cell
0035  * @irq:    interrupt number to be added to each IORESOURCE_IRQ
0036  *      in the cell
0037  * @block:  block id; used for identification with platform data and for
0038  *      enable and altfunc callbacks
0039  */
0040 struct stmpe_variant_block {
0041     const struct mfd_cell   *cell;
0042     int         irq;
0043     enum stmpe_block    block;
0044 };
0045 
0046 /**
0047  * struct stmpe_variant_info - variant-specific information
0048  * @name:   part name
0049  * @id_val: content of CHIPID register
0050  * @id_mask:    bits valid in CHIPID register for comparison with id_val
0051  * @num_gpios:  number of GPIOS
0052  * @af_bits:    number of bits used to specify the alternate function
0053  * @regs: variant specific registers.
0054  * @blocks: list of blocks present on this device
0055  * @num_blocks: number of blocks present on this device
0056  * @num_irqs:   number of internal IRQs available on this device
0057  * @enable: callback to enable the specified blocks.
0058  *      Called with the I/O lock held.
0059  * @get_altfunc: callback to get the alternate function number for the
0060  *       specific block
0061  * @enable_autosleep: callback to configure autosleep with specified timeout
0062  */
0063 struct stmpe_variant_info {
0064     const char *name;
0065     u16 id_val;
0066     u16 id_mask;
0067     int num_gpios;
0068     int af_bits;
0069     const u8 *regs;
0070     struct stmpe_variant_block *blocks;
0071     int num_blocks;
0072     int num_irqs;
0073     int (*enable)(struct stmpe *stmpe, unsigned int blocks, bool enable);
0074     int (*get_altfunc)(struct stmpe *stmpe, enum stmpe_block block);
0075     int (*enable_autosleep)(struct stmpe *stmpe, int autosleep_timeout);
0076 };
0077 
0078 /**
0079  * struct stmpe_client_info - i2c or spi specific routines/info
0080  * @data: client specific data
0081  * @read_byte: read single byte
0082  * @write_byte: write single byte
0083  * @read_block: read block or multiple bytes
0084  * @write_block: write block or multiple bytes
0085  * @init: client init routine, called during probe
0086  */
0087 struct stmpe_client_info {
0088     void *data;
0089     int irq;
0090     void *client;
0091     struct device *dev;
0092     int (*read_byte)(struct stmpe *stmpe, u8 reg);
0093     int (*write_byte)(struct stmpe *stmpe, u8 reg, u8 val);
0094     int (*read_block)(struct stmpe *stmpe, u8 reg, u8 len, u8 *values);
0095     int (*write_block)(struct stmpe *stmpe, u8 reg, u8 len,
0096             const u8 *values);
0097     void (*init)(struct stmpe *stmpe);
0098 };
0099 
0100 int stmpe_probe(struct stmpe_client_info *ci, enum stmpe_partnum partnum);
0101 void stmpe_remove(struct stmpe *stmpe);
0102 
0103 #define STMPE_ICR_LSB_HIGH  (1 << 2)
0104 #define STMPE_ICR_LSB_EDGE  (1 << 1)
0105 #define STMPE_ICR_LSB_GIM   (1 << 0)
0106 
0107 #define STMPE_SYS_CTRL_RESET    (1 << 7)
0108 #define STMPE_SYS_CTRL_INT_EN   (1 << 2)
0109 #define STMPE_SYS_CTRL_INT_HI   (1 << 0)
0110 
0111 /*
0112  * STMPE801
0113  */
0114 #define STMPE801_ID         0x0108
0115 #define STMPE801_NR_INTERNAL_IRQS   1
0116 
0117 #define STMPE801_REG_CHIP_ID        0x00
0118 #define STMPE801_REG_VERSION_ID     0x02
0119 #define STMPE801_REG_SYS_CTRL       0x04
0120 #define STMPE801_REG_GPIO_INT_EN    0x08
0121 #define STMPE801_REG_GPIO_INT_STA   0x09
0122 #define STMPE801_REG_GPIO_MP_STA    0x10
0123 #define STMPE801_REG_GPIO_SET_PIN   0x11
0124 #define STMPE801_REG_GPIO_DIR       0x12
0125 
0126 /*
0127  * STMPE811
0128  */
0129 #define STMPE811_ID         0x0811
0130 
0131 #define STMPE811_IRQ_TOUCH_DET      0
0132 #define STMPE811_IRQ_FIFO_TH        1
0133 #define STMPE811_IRQ_FIFO_OFLOW     2
0134 #define STMPE811_IRQ_FIFO_FULL      3
0135 #define STMPE811_IRQ_FIFO_EMPTY     4
0136 #define STMPE811_IRQ_TEMP_SENS      5
0137 #define STMPE811_IRQ_ADC        6
0138 #define STMPE811_IRQ_GPIOC      7
0139 #define STMPE811_NR_INTERNAL_IRQS   8
0140 
0141 #define STMPE811_REG_CHIP_ID        0x00
0142 #define STMPE811_REG_SYS_CTRL       0x03
0143 #define STMPE811_REG_SYS_CTRL2      0x04
0144 #define STMPE811_REG_SPI_CFG        0x08
0145 #define STMPE811_REG_INT_CTRL       0x09
0146 #define STMPE811_REG_INT_EN     0x0A
0147 #define STMPE811_REG_INT_STA        0x0B
0148 #define STMPE811_REG_GPIO_INT_EN    0x0C
0149 #define STMPE811_REG_GPIO_INT_STA   0x0D
0150 #define STMPE811_REG_GPIO_SET_PIN   0x10
0151 #define STMPE811_REG_GPIO_CLR_PIN   0x11
0152 #define STMPE811_REG_GPIO_MP_STA    0x12
0153 #define STMPE811_REG_GPIO_DIR       0x13
0154 #define STMPE811_REG_GPIO_ED        0x14
0155 #define STMPE811_REG_GPIO_RE        0x15
0156 #define STMPE811_REG_GPIO_FE        0x16
0157 #define STMPE811_REG_GPIO_AF        0x17
0158 
0159 #define STMPE811_SYS_CTRL_RESET     (1 << 1)
0160 
0161 #define STMPE811_SYS_CTRL2_ADC_OFF  (1 << 0)
0162 #define STMPE811_SYS_CTRL2_TSC_OFF  (1 << 1)
0163 #define STMPE811_SYS_CTRL2_GPIO_OFF (1 << 2)
0164 #define STMPE811_SYS_CTRL2_TS_OFF   (1 << 3)
0165 
0166 /*
0167  * STMPE1600
0168  */
0169 #define STMPE1600_ID            0x0016
0170 #define STMPE1600_NR_INTERNAL_IRQS  16
0171 
0172 #define STMPE1600_REG_CHIP_ID       0x00
0173 #define STMPE1600_REG_SYS_CTRL      0x03
0174 #define STMPE1600_REG_IEGPIOR_LSB   0x08
0175 #define STMPE1600_REG_IEGPIOR_MSB   0x09
0176 #define STMPE1600_REG_ISGPIOR_LSB   0x0A
0177 #define STMPE1600_REG_ISGPIOR_MSB   0x0B
0178 #define STMPE1600_REG_GPMR_LSB      0x10
0179 #define STMPE1600_REG_GPMR_MSB      0x11
0180 #define STMPE1600_REG_GPSR_LSB      0x12
0181 #define STMPE1600_REG_GPSR_MSB      0x13
0182 #define STMPE1600_REG_GPDR_LSB      0x14
0183 #define STMPE1600_REG_GPDR_MSB      0x15
0184 #define STMPE1600_REG_GPPIR_LSB     0x16
0185 #define STMPE1600_REG_GPPIR_MSB     0x17
0186 
0187 /*
0188  * STMPE1601
0189  */
0190 
0191 #define STMPE1601_IRQ_GPIOC     8
0192 #define STMPE1601_IRQ_PWM3      7
0193 #define STMPE1601_IRQ_PWM2      6
0194 #define STMPE1601_IRQ_PWM1      5
0195 #define STMPE1601_IRQ_PWM0      4
0196 #define STMPE1601_IRQ_KEYPAD_OVER   2
0197 #define STMPE1601_IRQ_KEYPAD        1
0198 #define STMPE1601_IRQ_WAKEUP        0
0199 #define STMPE1601_NR_INTERNAL_IRQS  9
0200 
0201 #define STMPE1601_REG_SYS_CTRL          0x02
0202 #define STMPE1601_REG_SYS_CTRL2         0x03
0203 #define STMPE1601_REG_ICR_MSB           0x10
0204 #define STMPE1601_REG_ICR_LSB           0x11
0205 #define STMPE1601_REG_IER_MSB           0x12
0206 #define STMPE1601_REG_IER_LSB           0x13
0207 #define STMPE1601_REG_ISR_MSB           0x14
0208 #define STMPE1601_REG_ISR_LSB           0x15
0209 #define STMPE1601_REG_INT_EN_GPIO_MASK_MSB  0x16
0210 #define STMPE1601_REG_INT_EN_GPIO_MASK_LSB  0x17
0211 #define STMPE1601_REG_INT_STA_GPIO_MSB      0x18
0212 #define STMPE1601_REG_INT_STA_GPIO_LSB      0x19
0213 #define STMPE1601_REG_CHIP_ID           0x80
0214 #define STMPE1601_REG_GPIO_SET_MSB      0x82
0215 #define STMPE1601_REG_GPIO_SET_LSB      0x83
0216 #define STMPE1601_REG_GPIO_CLR_MSB      0x84
0217 #define STMPE1601_REG_GPIO_CLR_LSB      0x85
0218 #define STMPE1601_REG_GPIO_MP_MSB       0x86
0219 #define STMPE1601_REG_GPIO_MP_LSB       0x87
0220 #define STMPE1601_REG_GPIO_SET_DIR_MSB      0x88
0221 #define STMPE1601_REG_GPIO_SET_DIR_LSB      0x89
0222 #define STMPE1601_REG_GPIO_ED_MSB       0x8A
0223 #define STMPE1601_REG_GPIO_ED_LSB       0x8B
0224 #define STMPE1601_REG_GPIO_RE_MSB       0x8C
0225 #define STMPE1601_REG_GPIO_RE_LSB       0x8D
0226 #define STMPE1601_REG_GPIO_FE_MSB       0x8E
0227 #define STMPE1601_REG_GPIO_FE_LSB       0x8F
0228 #define STMPE1601_REG_GPIO_PU_MSB       0x90
0229 #define STMPE1601_REG_GPIO_PU_LSB       0x91
0230 #define STMPE1601_REG_GPIO_AF_U_MSB     0x92
0231 
0232 #define STMPE1601_SYS_CTRL_ENABLE_GPIO      (1 << 3)
0233 #define STMPE1601_SYS_CTRL_ENABLE_KPC       (1 << 1)
0234 #define STMPE1601_SYS_CTRL_ENABLE_SPWM      (1 << 0)
0235 
0236 /* The 1601/2403 share the same masks */
0237 #define STMPE1601_AUTOSLEEP_TIMEOUT_MASK    (0x7)
0238 #define STPME1601_AUTOSLEEP_ENABLE      (1 << 3)
0239 
0240 /*
0241  * STMPE1801
0242  */
0243 #define STMPE1801_ID            0xc110
0244 #define STMPE1801_NR_INTERNAL_IRQS  5
0245 #define STMPE1801_IRQ_KEYPAD_COMBI  4
0246 #define STMPE1801_IRQ_GPIOC     3
0247 #define STMPE1801_IRQ_KEYPAD_OVER   2
0248 #define STMPE1801_IRQ_KEYPAD        1
0249 #define STMPE1801_IRQ_WAKEUP        0
0250 
0251 #define STMPE1801_REG_CHIP_ID           0x00
0252 #define STMPE1801_REG_SYS_CTRL          0x02
0253 #define STMPE1801_REG_INT_CTRL_LOW      0x04
0254 #define STMPE1801_REG_INT_EN_MASK_LOW       0x06
0255 #define STMPE1801_REG_INT_STA_LOW       0x08
0256 #define STMPE1801_REG_INT_EN_GPIO_MASK_LOW  0x0A
0257 #define STMPE1801_REG_INT_EN_GPIO_MASK_MID  0x0B
0258 #define STMPE1801_REG_INT_EN_GPIO_MASK_HIGH 0x0C
0259 #define STMPE1801_REG_INT_STA_GPIO_LOW      0x0D
0260 #define STMPE1801_REG_INT_STA_GPIO_MID      0x0E
0261 #define STMPE1801_REG_INT_STA_GPIO_HIGH     0x0F
0262 #define STMPE1801_REG_GPIO_SET_LOW      0x10
0263 #define STMPE1801_REG_GPIO_SET_MID      0x11
0264 #define STMPE1801_REG_GPIO_SET_HIGH     0x12
0265 #define STMPE1801_REG_GPIO_CLR_LOW      0x13
0266 #define STMPE1801_REG_GPIO_CLR_MID      0x14
0267 #define STMPE1801_REG_GPIO_CLR_HIGH     0x15
0268 #define STMPE1801_REG_GPIO_MP_LOW       0x16
0269 #define STMPE1801_REG_GPIO_MP_MID       0x17
0270 #define STMPE1801_REG_GPIO_MP_HIGH      0x18
0271 #define STMPE1801_REG_GPIO_SET_DIR_LOW      0x19
0272 #define STMPE1801_REG_GPIO_SET_DIR_MID      0x1A
0273 #define STMPE1801_REG_GPIO_SET_DIR_HIGH     0x1B
0274 #define STMPE1801_REG_GPIO_RE_LOW       0x1C
0275 #define STMPE1801_REG_GPIO_RE_MID       0x1D
0276 #define STMPE1801_REG_GPIO_RE_HIGH      0x1E
0277 #define STMPE1801_REG_GPIO_FE_LOW       0x1F
0278 #define STMPE1801_REG_GPIO_FE_MID       0x20
0279 #define STMPE1801_REG_GPIO_FE_HIGH      0x21
0280 #define STMPE1801_REG_GPIO_PULL_UP_LOW      0x22
0281 #define STMPE1801_REG_GPIO_PULL_UP_MID      0x23
0282 #define STMPE1801_REG_GPIO_PULL_UP_HIGH     0x24
0283 
0284 #define STMPE1801_MSK_INT_EN_KPC        (1 << 1)
0285 #define STMPE1801_MSK_INT_EN_GPIO       (1 << 3)
0286 
0287 /*
0288  * STMPE24xx
0289  */
0290 
0291 #define STMPE24XX_IRQ_GPIOC     8
0292 #define STMPE24XX_IRQ_PWM2      7
0293 #define STMPE24XX_IRQ_PWM1      6
0294 #define STMPE24XX_IRQ_PWM0      5
0295 #define STMPE24XX_IRQ_ROT_OVER      4
0296 #define STMPE24XX_IRQ_ROT       3
0297 #define STMPE24XX_IRQ_KEYPAD_OVER   2
0298 #define STMPE24XX_IRQ_KEYPAD        1
0299 #define STMPE24XX_IRQ_WAKEUP        0
0300 #define STMPE24XX_NR_INTERNAL_IRQS  9
0301 
0302 #define STMPE24XX_REG_SYS_CTRL      0x02
0303 #define STMPE24XX_REG_SYS_CTRL2     0x03
0304 #define STMPE24XX_REG_ICR_MSB       0x10
0305 #define STMPE24XX_REG_ICR_LSB       0x11
0306 #define STMPE24XX_REG_IER_MSB       0x12
0307 #define STMPE24XX_REG_IER_LSB       0x13
0308 #define STMPE24XX_REG_ISR_MSB       0x14
0309 #define STMPE24XX_REG_ISR_LSB       0x15
0310 #define STMPE24XX_REG_IEGPIOR_MSB   0x16
0311 #define STMPE24XX_REG_IEGPIOR_CSB   0x17
0312 #define STMPE24XX_REG_IEGPIOR_LSB   0x18
0313 #define STMPE24XX_REG_ISGPIOR_MSB   0x19
0314 #define STMPE24XX_REG_ISGPIOR_CSB   0x1A
0315 #define STMPE24XX_REG_ISGPIOR_LSB   0x1B
0316 #define STMPE24XX_REG_CHIP_ID       0x80
0317 #define STMPE24XX_REG_GPSR_MSB      0x83
0318 #define STMPE24XX_REG_GPSR_CSB      0x84
0319 #define STMPE24XX_REG_GPSR_LSB      0x85
0320 #define STMPE24XX_REG_GPCR_MSB      0x86
0321 #define STMPE24XX_REG_GPCR_CSB      0x87
0322 #define STMPE24XX_REG_GPCR_LSB      0x88
0323 #define STMPE24XX_REG_GPDR_MSB      0x89
0324 #define STMPE24XX_REG_GPDR_CSB      0x8A
0325 #define STMPE24XX_REG_GPDR_LSB      0x8B
0326 #define STMPE24XX_REG_GPEDR_MSB     0x8C
0327 #define STMPE24XX_REG_GPEDR_CSB     0x8D
0328 #define STMPE24XX_REG_GPEDR_LSB     0x8E
0329 #define STMPE24XX_REG_GPRER_MSB     0x8F
0330 #define STMPE24XX_REG_GPRER_CSB     0x90
0331 #define STMPE24XX_REG_GPRER_LSB     0x91
0332 #define STMPE24XX_REG_GPFER_MSB     0x92
0333 #define STMPE24XX_REG_GPFER_CSB     0x93
0334 #define STMPE24XX_REG_GPFER_LSB     0x94
0335 #define STMPE24XX_REG_GPPUR_MSB     0x95
0336 #define STMPE24XX_REG_GPPUR_CSB     0x96
0337 #define STMPE24XX_REG_GPPUR_LSB     0x97
0338 #define STMPE24XX_REG_GPPDR_MSB     0x98
0339 #define STMPE24XX_REG_GPPDR_CSB     0x99
0340 #define STMPE24XX_REG_GPPDR_LSB     0x9A
0341 #define STMPE24XX_REG_GPAFR_U_MSB   0x9B
0342 #define STMPE24XX_REG_GPMR_MSB      0xA2
0343 #define STMPE24XX_REG_GPMR_CSB      0xA3
0344 #define STMPE24XX_REG_GPMR_LSB      0xA4
0345 #define STMPE24XX_SYS_CTRL_ENABLE_GPIO      (1 << 3)
0346 #define STMPE24XX_SYSCON_ENABLE_PWM     (1 << 2)
0347 #define STMPE24XX_SYS_CTRL_ENABLE_KPC       (1 << 1)
0348 #define STMPE24XX_SYSCON_ENABLE_ROT     (1 << 0)
0349 
0350 #endif