tsc2007.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2008 MtekVision Co., Ltd.
  4. * Kwangwoo Lee <kwlee@mtekvision.com>
  5. *
  6. * Using code from:
  7. * - ads7846.c
  8. * Copyright (c) 2005 David Brownell
  9. * Copyright (c) 2006 Nokia Corporation
  10. * - corgi_ts.c
  11. * Copyright (C) 2004-2005 Richard Purdie
  12. * - omap_ts.[hc], ads7846.h, ts_osk.c
  13. * Copyright (C) 2002 MontaVista Software
  14. * Copyright (C) 2004 Texas Instruments
  15. * Copyright (C) 2005 Dirk Behme
  16. */
  17. #ifndef _TSC2007_H
  18. #define _TSC2007_H
  19. #include <linux/input/touchscreen.h>
  20. struct gpio_desc;
  21. #define TSC2007_MEASURE_TEMP0 (0x0 << 4)
  22. #define TSC2007_MEASURE_AUX (0x2 << 4)
  23. #define TSC2007_MEASURE_TEMP1 (0x4 << 4)
  24. #define TSC2007_ACTIVATE_XN (0x8 << 4)
  25. #define TSC2007_ACTIVATE_YN (0x9 << 4)
  26. #define TSC2007_ACTIVATE_YP_XN (0xa << 4)
  27. #define TSC2007_SETUP (0xb << 4)
  28. #define TSC2007_MEASURE_X (0xc << 4)
  29. #define TSC2007_MEASURE_Y (0xd << 4)
  30. #define TSC2007_MEASURE_Z1 (0xe << 4)
  31. #define TSC2007_MEASURE_Z2 (0xf << 4)
  32. #define TSC2007_POWER_OFF_IRQ_EN (0x0 << 2)
  33. #define TSC2007_ADC_ON_IRQ_DIS0 (0x1 << 2)
  34. #define TSC2007_ADC_OFF_IRQ_EN (0x2 << 2)
  35. #define TSC2007_ADC_ON_IRQ_DIS1 (0x3 << 2)
  36. #define TSC2007_12BIT (0x0 << 1)
  37. #define TSC2007_8BIT (0x1 << 1)
  38. #define MAX_12BIT ((1 << 12) - 1)
  39. #define ADC_ON_12BIT (TSC2007_12BIT | TSC2007_ADC_ON_IRQ_DIS0)
  40. #define READ_Y (ADC_ON_12BIT | TSC2007_MEASURE_Y)
  41. #define READ_Z1 (ADC_ON_12BIT | TSC2007_MEASURE_Z1)
  42. #define READ_Z2 (ADC_ON_12BIT | TSC2007_MEASURE_Z2)
  43. #define READ_X (ADC_ON_12BIT | TSC2007_MEASURE_X)
  44. #define PWRDOWN (TSC2007_12BIT | TSC2007_POWER_OFF_IRQ_EN)
  45. struct ts_event {
  46. u16 x;
  47. u16 y;
  48. u16 z1, z2;
  49. };
  50. struct tsc2007 {
  51. struct input_dev *input;
  52. char phys[32];
  53. struct i2c_client *client;
  54. struct touchscreen_properties prop;
  55. u16 model;
  56. u16 x_plate_ohms;
  57. u16 max_rt;
  58. unsigned long poll_period; /* in jiffies */
  59. int fuzzx;
  60. int fuzzy;
  61. int fuzzz;
  62. struct gpio_desc *gpiod;
  63. int irq;
  64. wait_queue_head_t wait;
  65. bool stopped;
  66. int (*get_pendown_state)(struct device *);
  67. void (*clear_penirq)(void);
  68. struct mutex mlock;
  69. };
  70. int tsc2007_xfer(struct tsc2007 *tsc, u8 cmd);
  71. u32 tsc2007_calculate_resistance(struct tsc2007 *tsc, struct ts_event *tc);
  72. bool tsc2007_is_pen_down(struct tsc2007 *ts);
  73. #if IS_ENABLED(CONFIG_TOUCHSCREEN_TSC2007_IIO)
  74. /* defined in tsc2007_iio.c */
  75. int tsc2007_iio_configure(struct tsc2007 *ts);
  76. #else
  77. static inline int tsc2007_iio_configure(struct tsc2007 *ts)
  78. {
  79. return 0;
  80. }
  81. #endif /* CONFIG_TOUCHSCREEN_TSC2007_IIO */
  82. #endif /* _TSC2007_H */