tsc2000.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * Functions to access the TSC2000 controller on TRAB board (used for scanning
  3. * thermo sensors)
  4. *
  5. * Copyright (C) 2003 Martin Krause, TQ-Systems GmbH, martin.krause@tqs.de
  6. *
  7. * Copyright (C) 2002 DENX Software Engineering, Wolfgang Denk, wd@denx.de
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. #ifndef _TSC2000_H_
  28. #define _TSC2000_H_
  29. /* temperature channel multiplexer definitions */
  30. #define CON_MUX0 (gpio->PCCON = (gpio->PCCON & 0x0FFFFFCFF) | 0x00000100)
  31. #define CLR_MUX0 (gpio->PCDAT &= 0x0FFEF)
  32. #define SET_MUX0 (gpio->PCDAT |= 0x00010)
  33. #define CON_MUX1 (gpio->PCCON = (gpio->PCCON & 0x0FFFFF3FF) | 0x00000400)
  34. #define CLR_MUX1 (gpio->PCDAT &= 0x0FFDF)
  35. #define SET_MUX1 (gpio->PCDAT |= 0x00020)
  36. #define CON_MUX1_ENABLE (gpio->PCCON = (gpio->PCCON & 0x0FFFFCFFF) | 0x00001000)
  37. #define CLR_MUX1_ENABLE (gpio->PCDAT |= 0x00040)
  38. #define SET_MUX1_ENABLE (gpio->PCDAT &= 0x0FFBF)
  39. #define CON_MUX2_ENABLE (gpio->PCCON = (gpio->PCCON & 0x0FFFF3FFF) | 0x00004000)
  40. #define CLR_MUX2_ENABLE (gpio->PCDAT |= 0x00080)
  41. #define SET_MUX2_ENABLE (gpio->PCDAT &= 0x0FF7F)
  42. #define CON_MUX3_ENABLE (gpio->PCCON = (gpio->PCCON & 0x0FFFCFFFF) | 0x00010000)
  43. #define CLR_MUX3_ENABLE (gpio->PCDAT |= 0x00100)
  44. #define SET_MUX3_ENABLE (gpio->PCDAT &= 0x0FEFF)
  45. #define CON_MUX4_ENABLE (gpio->PCCON = (gpio->PCCON & 0x0FFF3FFFF) | 0x00040000)
  46. #define CLR_MUX4_ENABLE (gpio->PCDAT |= 0x00200)
  47. #define SET_MUX4_ENABLE (gpio->PCDAT &= 0x0FDFF)
  48. #define CON_SEL_TEMP_V_0 (gpio->PCCON = (gpio->PCCON & 0x0FFCFFFFF) | 0x00100000)
  49. #define CLR_SEL_TEMP_V_0 (gpio->PCDAT &= 0x0FBFF)
  50. #define SET_SEL_TEMP_V_0 (gpio->PCDAT |= 0x00400)
  51. #define CON_SEL_TEMP_V_1 (gpio->PCCON = (gpio->PCCON & 0x0FF3FFFFF) | 0x00400000)
  52. #define CLR_SEL_TEMP_V_1 (gpio->PCDAT &= 0x0F7FF)
  53. #define SET_SEL_TEMP_V_1 (gpio->PCDAT |= 0x00800)
  54. #define CON_SEL_TEMP_V_2 (gpio->PCCON = (gpio->PCCON & 0x0FCFFFFFF) | 0x01000000)
  55. #define CLR_SEL_TEMP_V_2 (gpio->PCDAT &= 0x0EFFF)
  56. #define SET_SEL_TEMP_V_2 (gpio->PCDAT |= 0x01000)
  57. #define CON_SEL_TEMP_V_3 (gpio->PCCON = (gpio->PCCON & 0x0F3FFFFFF) | 0x04000000)
  58. #define CLR_SEL_TEMP_V_3 (gpio->PCDAT &= 0x0DFFF)
  59. #define SET_SEL_TEMP_V_3 (gpio->PCDAT |= 0x02000)
  60. /* TSC2000 register definition */
  61. #define TSC2000_REG_X ((0 << 11) | (0 << 5))
  62. #define TSC2000_REG_Y ((0 << 11) | (1 << 5))
  63. #define TSC2000_REG_Z1 ((0 << 11) | (2 << 5))
  64. #define TSC2000_REG_Z2 ((0 << 11) | (3 << 5))
  65. #define TSC2000_REG_BAT1 ((0 << 11) | (5 << 5))
  66. #define TSC2000_REG_BAT2 ((0 << 11) | (6 << 5))
  67. #define TSC2000_REG_AUX1 ((0 << 11) | (7 << 5))
  68. #define TSC2000_REG_AUX2 ((0 << 11) | (8 << 5))
  69. #define TSC2000_REG_TEMP1 ((0 << 11) | (9 << 5))
  70. #define TSC2000_REG_TEMP2 ((0 << 11) | (0xA << 5))
  71. #define TSC2000_REG_DAC ((0 << 11) | (0xB << 5))
  72. #define TSC2000_REG_ZERO ((0 << 11) | (0x10 << 5))
  73. #define TSC2000_REG_ADC ((1 << 11) | (0 << 5))
  74. #define TSC2000_REG_DACCTL ((1 << 11) | (2 << 5))
  75. #define TSC2000_REG_REF ((1 << 11) | (3 << 5))
  76. #define TSC2000_REG_RESET ((1 << 11) | (4 << 5))
  77. #define TSC2000_REG_CONFIG ((1 << 11) | (5 << 5))
  78. /* bit definition of TSC2000 ADC register */
  79. #define TC_PSM (1 << 15)
  80. #define TC_STS (1 << 14)
  81. #define TC_AD3 (1 << 13)
  82. #define TC_AD2 (1 << 12)
  83. #define TC_AD1 (1 << 11)
  84. #define TC_AD0 (1 << 10)
  85. #define TC_RS1 (1 << 9)
  86. #define TC_RS0 (1 << 8)
  87. #define TC_AV1 (1 << 7)
  88. #define TC_AV0 (1 << 6)
  89. #define TC_CL1 (1 << 5)
  90. #define TC_CL0 (1 << 4)
  91. #define TC_PV2 (1 << 3)
  92. #define TC_PV1 (1 << 2)
  93. #define TC_PV0 (1 << 1)
  94. /* default value for TSC2000 ADC register for use with touch functions */
  95. #define DEFAULT_ADC (TC_PV1 | TC_AV0 | TC_AV1 | TC_RS0)
  96. #define TSC2000_DELAY_BASE 500
  97. #define TSC2000_NO_SENSOR -0x10000
  98. #define ERROR_BATTERY 220 /* must be adjusted, if R68 is changed on
  99. * TRAB */
  100. void tsc2000_write(unsigned short, unsigned short);
  101. unsigned short tsc2000_read (unsigned short);
  102. u16 tsc2000_read_channel (unsigned int);
  103. void tsc2000_set_mux (unsigned int);
  104. void tsc2000_set_range (unsigned int);
  105. void tsc2000_reg_init (void);
  106. s32 tsc2000_contact_temp (void);
  107. void spi_wait_transmit_done (void);
  108. void spi_init(void);
  109. int tsc2000_interpolate(long value, long data[][2], long *result);
  110. void adc_wait_conversion_done(void);
  111. static inline void SET_CS_TOUCH(void)
  112. {
  113. S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO();
  114. gpio->PDDAT &= 0x5FF;
  115. }
  116. static inline void CLR_CS_TOUCH(void)
  117. {
  118. S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO();
  119. gpio->PDDAT |= 0x200;
  120. }
  121. #endif /* _TSC2000_H_ */