stmpe.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * Copyright (C) ST-Ericsson SA 2010
  3. *
  4. * License Terms: GNU General Public License, version 2
  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/device.h>
  10. enum stmpe_block {
  11. STMPE_BLOCK_GPIO = 1 << 0,
  12. STMPE_BLOCK_KEYPAD = 1 << 1,
  13. STMPE_BLOCK_TOUCHSCREEN = 1 << 2,
  14. STMPE_BLOCK_ADC = 1 << 3,
  15. STMPE_BLOCK_PWM = 1 << 4,
  16. STMPE_BLOCK_ROTATOR = 1 << 5,
  17. };
  18. enum stmpe_partnum {
  19. STMPE811,
  20. STMPE1601,
  21. STMPE2401,
  22. STMPE2403,
  23. };
  24. /*
  25. * For registers whose locations differ on variants, the correct address is
  26. * obtained by indexing stmpe->regs with one of the following.
  27. */
  28. enum {
  29. STMPE_IDX_CHIP_ID,
  30. STMPE_IDX_ICR_LSB,
  31. STMPE_IDX_IER_LSB,
  32. STMPE_IDX_ISR_MSB,
  33. STMPE_IDX_GPMR_LSB,
  34. STMPE_IDX_GPSR_LSB,
  35. STMPE_IDX_GPCR_LSB,
  36. STMPE_IDX_GPDR_LSB,
  37. STMPE_IDX_GPEDR_MSB,
  38. STMPE_IDX_GPRER_LSB,
  39. STMPE_IDX_GPFER_LSB,
  40. STMPE_IDX_GPAFR_U_MSB,
  41. STMPE_IDX_IEGPIOR_LSB,
  42. STMPE_IDX_ISGPIOR_MSB,
  43. STMPE_IDX_MAX,
  44. };
  45. struct stmpe_variant_info;
  46. /**
  47. * struct stmpe - STMPE MFD structure
  48. * @lock: lock protecting I/O operations
  49. * @irq_lock: IRQ bus lock
  50. * @dev: device, mostly for dev_dbg()
  51. * @i2c: i2c client
  52. * @variant: the detected STMPE model number
  53. * @regs: list of addresses of registers which are at different addresses on
  54. * different variants. Indexed by one of STMPE_IDX_*.
  55. * @irq_base: starting IRQ number for internal IRQs
  56. * @num_gpios: number of gpios, differs for variants
  57. * @ier: cache of IER registers for bus_lock
  58. * @oldier: cache of IER registers for bus_lock
  59. * @pdata: platform data
  60. */
  61. struct stmpe {
  62. struct mutex lock;
  63. struct mutex irq_lock;
  64. struct device *dev;
  65. struct i2c_client *i2c;
  66. enum stmpe_partnum partnum;
  67. struct stmpe_variant_info *variant;
  68. const u8 *regs;
  69. int irq_base;
  70. int num_gpios;
  71. u8 ier[2];
  72. u8 oldier[2];
  73. struct stmpe_platform_data *pdata;
  74. };
  75. extern int stmpe_reg_write(struct stmpe *stmpe, u8 reg, u8 data);
  76. extern int stmpe_reg_read(struct stmpe *stmpe, u8 reg);
  77. extern int stmpe_block_read(struct stmpe *stmpe, u8 reg, u8 length,
  78. u8 *values);
  79. extern int stmpe_block_write(struct stmpe *stmpe, u8 reg, u8 length,
  80. const u8 *values);
  81. extern int stmpe_set_bits(struct stmpe *stmpe, u8 reg, u8 mask, u8 val);
  82. extern int stmpe_set_altfunc(struct stmpe *stmpe, u32 pins,
  83. enum stmpe_block block);
  84. extern int stmpe_enable(struct stmpe *stmpe, unsigned int blocks);
  85. extern int stmpe_disable(struct stmpe *stmpe, unsigned int blocks);
  86. struct matrix_keymap_data;
  87. /**
  88. * struct stmpe_keypad_platform_data - STMPE keypad platform data
  89. * @keymap_data: key map table and size
  90. * @debounce_ms: debounce interval, in ms. Maximum is
  91. * %STMPE_KEYPAD_MAX_DEBOUNCE.
  92. * @scan_count: number of key scanning cycles to confirm key data.
  93. * Maximum is %STMPE_KEYPAD_MAX_SCAN_COUNT.
  94. * @no_autorepeat: disable key autorepeat
  95. */
  96. struct stmpe_keypad_platform_data {
  97. struct matrix_keymap_data *keymap_data;
  98. unsigned int debounce_ms;
  99. unsigned int scan_count;
  100. bool no_autorepeat;
  101. };
  102. #define STMPE_GPIO_NOREQ_811_TOUCH (0xf0)
  103. /**
  104. * struct stmpe_gpio_platform_data - STMPE GPIO platform data
  105. * @gpio_base: first gpio number assigned. A maximum of
  106. * %STMPE_NR_GPIOS GPIOs will be allocated.
  107. * @norequest_mask: bitmask specifying which GPIOs should _not_ be
  108. * requestable due to different usage (e.g. touch, keypad)
  109. * STMPE_GPIO_NOREQ_* macros can be used here.
  110. */
  111. struct stmpe_gpio_platform_data {
  112. int gpio_base;
  113. unsigned norequest_mask;
  114. void (*setup)(struct stmpe *stmpe, unsigned gpio_base);
  115. void (*remove)(struct stmpe *stmpe, unsigned gpio_base);
  116. };
  117. /**
  118. * struct stmpe_ts_platform_data - stmpe811 touch screen controller platform
  119. * data
  120. * @sample_time: ADC converstion time in number of clock.
  121. * (0 -> 36 clocks, 1 -> 44 clocks, 2 -> 56 clocks, 3 -> 64 clocks,
  122. * 4 -> 80 clocks, 5 -> 96 clocks, 6 -> 144 clocks),
  123. * recommended is 4.
  124. * @mod_12b: ADC Bit mode (0 -> 10bit ADC, 1 -> 12bit ADC)
  125. * @ref_sel: ADC reference source
  126. * (0 -> internal reference, 1 -> external reference)
  127. * @adc_freq: ADC Clock speed
  128. * (0 -> 1.625 MHz, 1 -> 3.25 MHz, 2 || 3 -> 6.5 MHz)
  129. * @ave_ctrl: Sample average control
  130. * (0 -> 1 sample, 1 -> 2 samples, 2 -> 4 samples, 3 -> 8 samples)
  131. * @touch_det_delay: Touch detect interrupt delay
  132. * (0 -> 10 us, 1 -> 50 us, 2 -> 100 us, 3 -> 500 us,
  133. * 4-> 1 ms, 5 -> 5 ms, 6 -> 10 ms, 7 -> 50 ms)
  134. * recommended is 3
  135. * @settling: Panel driver settling time
  136. * (0 -> 10 us, 1 -> 100 us, 2 -> 500 us, 3 -> 1 ms,
  137. * 4 -> 5 ms, 5 -> 10 ms, 6 for 50 ms, 7 -> 100 ms)
  138. * recommended is 2
  139. * @fraction_z: Length of the fractional part in z
  140. * (fraction_z ([0..7]) = Count of the fractional part)
  141. * recommended is 7
  142. * @i_drive: current limit value of the touchscreen drivers
  143. * (0 -> 20 mA typical 35 mA max, 1 -> 50 mA typical 80 mA max)
  144. *
  145. * */
  146. struct stmpe_ts_platform_data {
  147. u8 sample_time;
  148. u8 mod_12b;
  149. u8 ref_sel;
  150. u8 adc_freq;
  151. u8 ave_ctrl;
  152. u8 touch_det_delay;
  153. u8 settling;
  154. u8 fraction_z;
  155. u8 i_drive;
  156. };
  157. /**
  158. * struct stmpe_platform_data - STMPE platform data
  159. * @id: device id to distinguish between multiple STMPEs on the same board
  160. * @blocks: bitmask of blocks to enable (use STMPE_BLOCK_*)
  161. * @irq_trigger: IRQ trigger to use for the interrupt to the host
  162. * @irq_invert_polarity: IRQ line is connected with reversed polarity
  163. * @autosleep: bool to enable/disable stmpe autosleep
  164. * @autosleep_timeout: inactivity timeout in milliseconds for autosleep
  165. * @irq_base: base IRQ number. %STMPE_NR_IRQS irqs will be used, or
  166. * %STMPE_NR_INTERNAL_IRQS if the GPIO driver is not used.
  167. * @gpio: GPIO-specific platform data
  168. * @keypad: keypad-specific platform data
  169. * @ts: touchscreen-specific platform data
  170. */
  171. struct stmpe_platform_data {
  172. int id;
  173. unsigned int blocks;
  174. int irq_base;
  175. unsigned int irq_trigger;
  176. bool irq_invert_polarity;
  177. bool autosleep;
  178. int autosleep_timeout;
  179. struct stmpe_gpio_platform_data *gpio;
  180. struct stmpe_keypad_platform_data *keypad;
  181. struct stmpe_ts_platform_data *ts;
  182. };
  183. #define STMPE_NR_INTERNAL_IRQS 9
  184. #define STMPE_INT_GPIO(x) (STMPE_NR_INTERNAL_IRQS + (x))
  185. #define STMPE_NR_GPIOS 24
  186. #define STMPE_NR_IRQS STMPE_INT_GPIO(STMPE_NR_GPIOS)
  187. #endif