stmpe.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) ST-Ericsson SA 2010
  4. *
  5. * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
  6. */
  7. #ifndef __LINUX_MFD_STMPE_H
  8. #define __LINUX_MFD_STMPE_H
  9. #include <linux/mutex.h>
  10. #define STMPE_SAMPLE_TIME(x) ((x & 0xf) << 4)
  11. #define STMPE_MOD_12B(x) ((x & 0x1) << 3)
  12. #define STMPE_REF_SEL(x) ((x & 0x1) << 1)
  13. #define STMPE_ADC_FREQ(x) (x & 0x3)
  14. #define STMPE_AVE_CTRL(x) ((x & 0x3) << 6)
  15. #define STMPE_DET_DELAY(x) ((x & 0x7) << 3)
  16. #define STMPE_SETTLING(x) (x & 0x7)
  17. #define STMPE_FRACTION_Z(x) (x & 0x7)
  18. #define STMPE_I_DRIVE(x) (x & 0x1)
  19. #define STMPE_OP_MODE(x) ((x & 0x7) << 1)
  20. #define STMPE811_REG_ADC_CTRL1 0x20
  21. #define STMPE811_REG_ADC_CTRL2 0x21
  22. struct device;
  23. struct regulator;
  24. enum stmpe_block {
  25. STMPE_BLOCK_GPIO = 1 << 0,
  26. STMPE_BLOCK_KEYPAD = 1 << 1,
  27. STMPE_BLOCK_TOUCHSCREEN = 1 << 2,
  28. STMPE_BLOCK_ADC = 1 << 3,
  29. STMPE_BLOCK_PWM = 1 << 4,
  30. STMPE_BLOCK_ROTATOR = 1 << 5,
  31. };
  32. enum stmpe_partnum {
  33. STMPE610,
  34. STMPE801,
  35. STMPE811,
  36. STMPE1600,
  37. STMPE1601,
  38. STMPE1801,
  39. STMPE2401,
  40. STMPE2403,
  41. STMPE_NBR_PARTS
  42. };
  43. /*
  44. * For registers whose locations differ on variants, the correct address is
  45. * obtained by indexing stmpe->regs with one of the following.
  46. */
  47. enum {
  48. STMPE_IDX_CHIP_ID,
  49. STMPE_IDX_SYS_CTRL,
  50. STMPE_IDX_SYS_CTRL2,
  51. STMPE_IDX_ICR_LSB,
  52. STMPE_IDX_IER_LSB,
  53. STMPE_IDX_IER_MSB,
  54. STMPE_IDX_ISR_LSB,
  55. STMPE_IDX_ISR_MSB,
  56. STMPE_IDX_GPMR_LSB,
  57. STMPE_IDX_GPMR_CSB,
  58. STMPE_IDX_GPMR_MSB,
  59. STMPE_IDX_GPSR_LSB,
  60. STMPE_IDX_GPSR_CSB,
  61. STMPE_IDX_GPSR_MSB,
  62. STMPE_IDX_GPCR_LSB,
  63. STMPE_IDX_GPCR_CSB,
  64. STMPE_IDX_GPCR_MSB,
  65. STMPE_IDX_GPDR_LSB,
  66. STMPE_IDX_GPDR_CSB,
  67. STMPE_IDX_GPDR_MSB,
  68. STMPE_IDX_GPEDR_LSB,
  69. STMPE_IDX_GPEDR_CSB,
  70. STMPE_IDX_GPEDR_MSB,
  71. STMPE_IDX_GPRER_LSB,
  72. STMPE_IDX_GPRER_CSB,
  73. STMPE_IDX_GPRER_MSB,
  74. STMPE_IDX_GPFER_LSB,
  75. STMPE_IDX_GPFER_CSB,
  76. STMPE_IDX_GPFER_MSB,
  77. STMPE_IDX_GPPUR_LSB,
  78. STMPE_IDX_GPPDR_LSB,
  79. STMPE_IDX_GPAFR_U_MSB,
  80. STMPE_IDX_IEGPIOR_LSB,
  81. STMPE_IDX_IEGPIOR_CSB,
  82. STMPE_IDX_IEGPIOR_MSB,
  83. STMPE_IDX_ISGPIOR_LSB,
  84. STMPE_IDX_ISGPIOR_CSB,
  85. STMPE_IDX_ISGPIOR_MSB,
  86. STMPE_IDX_MAX,
  87. };
  88. struct stmpe_variant_info;
  89. struct stmpe_client_info;
  90. struct stmpe_platform_data;
  91. /**
  92. * struct stmpe - STMPE MFD structure
  93. * @vcc: optional VCC regulator
  94. * @vio: optional VIO regulator
  95. * @lock: lock protecting I/O operations
  96. * @irq_lock: IRQ bus lock
  97. * @dev: device, mostly for dev_dbg()
  98. * @irq_domain: IRQ domain
  99. * @client: client - i2c or spi
  100. * @ci: client specific information
  101. * @partnum: part number
  102. * @variant: the detected STMPE model number
  103. * @regs: list of addresses of registers which are at different addresses on
  104. * different variants. Indexed by one of STMPE_IDX_*.
  105. * @irq: irq number for stmpe
  106. * @num_gpios: number of gpios, differs for variants
  107. * @ier: cache of IER registers for bus_lock
  108. * @oldier: cache of IER registers for bus_lock
  109. * @pdata: platform data
  110. */
  111. struct stmpe {
  112. struct regulator *vcc;
  113. struct regulator *vio;
  114. struct mutex lock;
  115. struct mutex irq_lock;
  116. struct device *dev;
  117. struct irq_domain *domain;
  118. void *client;
  119. struct stmpe_client_info *ci;
  120. enum stmpe_partnum partnum;
  121. struct stmpe_variant_info *variant;
  122. const u8 *regs;
  123. int irq;
  124. int num_gpios;
  125. u8 ier[2];
  126. u8 oldier[2];
  127. struct stmpe_platform_data *pdata;
  128. /* For devices that use an ADC */
  129. u8 sample_time;
  130. u8 mod_12b;
  131. u8 ref_sel;
  132. u8 adc_freq;
  133. };
  134. extern int stmpe_reg_write(struct stmpe *stmpe, u8 reg, u8 data);
  135. extern int stmpe_reg_read(struct stmpe *stmpe, u8 reg);
  136. extern int stmpe_block_read(struct stmpe *stmpe, u8 reg, u8 length,
  137. u8 *values);
  138. extern int stmpe_block_write(struct stmpe *stmpe, u8 reg, u8 length,
  139. const u8 *values);
  140. extern int stmpe_set_bits(struct stmpe *stmpe, u8 reg, u8 mask, u8 val);
  141. extern int stmpe_set_altfunc(struct stmpe *stmpe, u32 pins,
  142. enum stmpe_block block);
  143. extern int stmpe_enable(struct stmpe *stmpe, unsigned int blocks);
  144. extern int stmpe_disable(struct stmpe *stmpe, unsigned int blocks);
  145. extern int stmpe811_adc_common_init(struct stmpe *stmpe);
  146. #define STMPE_GPIO_NOREQ_811_TOUCH (0xf0)
  147. #endif