twl4030-madc.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * twl4030_madc.h - Header for TWL4030 MADC
  3. *
  4. * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
  5. * J Keerthy <j-keerthy@ti.com>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * version 2 as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  19. * 02110-1301 USA
  20. *
  21. */
  22. #ifndef _TWL4030_MADC_H
  23. #define _TWL4030_MADC_H
  24. struct twl4030_madc_conversion_method {
  25. u8 sel;
  26. u8 avg;
  27. u8 rbase;
  28. u8 ctrl;
  29. };
  30. #define TWL4030_MADC_MAX_CHANNELS 16
  31. /*
  32. * twl4030_madc_request- madc request packet for channel conversion
  33. * @channels: 16 bit bitmap for individual channels
  34. * @do_avgP: sample the input channel for 4 consecutive cycles
  35. * @method: RT, SW1, SW2
  36. * @type: Polling or interrupt based method
  37. * @raw: Return raw value, do not convert it
  38. */
  39. struct twl4030_madc_request {
  40. unsigned long channels;
  41. bool do_avg;
  42. u16 method;
  43. u16 type;
  44. bool active;
  45. bool result_pending;
  46. bool raw;
  47. int rbuf[TWL4030_MADC_MAX_CHANNELS];
  48. void (*func_cb)(int len, int channels, int *buf);
  49. };
  50. enum conversion_methods {
  51. TWL4030_MADC_RT,
  52. TWL4030_MADC_SW1,
  53. TWL4030_MADC_SW2,
  54. TWL4030_MADC_NUM_METHODS
  55. };
  56. enum sample_type {
  57. TWL4030_MADC_WAIT,
  58. TWL4030_MADC_IRQ_ONESHOT,
  59. TWL4030_MADC_IRQ_REARM
  60. };
  61. #define TWL4030_MADC_CTRL1 0x00
  62. #define TWL4030_MADC_CTRL2 0x01
  63. #define TWL4030_MADC_RTSELECT_LSB 0x02
  64. #define TWL4030_MADC_SW1SELECT_LSB 0x06
  65. #define TWL4030_MADC_SW2SELECT_LSB 0x0A
  66. #define TWL4030_MADC_RTAVERAGE_LSB 0x04
  67. #define TWL4030_MADC_SW1AVERAGE_LSB 0x08
  68. #define TWL4030_MADC_SW2AVERAGE_LSB 0x0C
  69. #define TWL4030_MADC_CTRL_SW1 0x12
  70. #define TWL4030_MADC_CTRL_SW2 0x13
  71. #define TWL4030_MADC_RTCH0_LSB 0x17
  72. #define TWL4030_MADC_GPCH0_LSB 0x37
  73. #define TWL4030_MADC_MADCON (1 << 0) /* MADC power on */
  74. #define TWL4030_MADC_BUSY (1 << 0) /* MADC busy */
  75. /* MADC conversion completion */
  76. #define TWL4030_MADC_EOC_SW (1 << 1)
  77. /* MADC SWx start conversion */
  78. #define TWL4030_MADC_SW_START (1 << 5)
  79. #define TWL4030_MADC_ADCIN0 (1 << 0)
  80. #define TWL4030_MADC_ADCIN1 (1 << 1)
  81. #define TWL4030_MADC_ADCIN2 (1 << 2)
  82. #define TWL4030_MADC_ADCIN3 (1 << 3)
  83. #define TWL4030_MADC_ADCIN4 (1 << 4)
  84. #define TWL4030_MADC_ADCIN5 (1 << 5)
  85. #define TWL4030_MADC_ADCIN6 (1 << 6)
  86. #define TWL4030_MADC_ADCIN7 (1 << 7)
  87. #define TWL4030_MADC_ADCIN8 (1 << 8)
  88. #define TWL4030_MADC_ADCIN9 (1 << 9)
  89. #define TWL4030_MADC_ADCIN10 (1 << 10)
  90. #define TWL4030_MADC_ADCIN11 (1 << 11)
  91. #define TWL4030_MADC_ADCIN12 (1 << 12)
  92. #define TWL4030_MADC_ADCIN13 (1 << 13)
  93. #define TWL4030_MADC_ADCIN14 (1 << 14)
  94. #define TWL4030_MADC_ADCIN15 (1 << 15)
  95. /* Fixed channels */
  96. #define TWL4030_MADC_BTEMP TWL4030_MADC_ADCIN1
  97. #define TWL4030_MADC_VBUS TWL4030_MADC_ADCIN8
  98. #define TWL4030_MADC_VBKB TWL4030_MADC_ADCIN9
  99. #define TWL4030_MADC_ICHG TWL4030_MADC_ADCIN10
  100. #define TWL4030_MADC_VCHG TWL4030_MADC_ADCIN11
  101. #define TWL4030_MADC_VBAT TWL4030_MADC_ADCIN12
  102. /* Step size and prescaler ratio */
  103. #define TEMP_STEP_SIZE 147
  104. #define TEMP_PSR_R 100
  105. #define CURR_STEP_SIZE 147
  106. #define CURR_PSR_R1 44
  107. #define CURR_PSR_R2 88
  108. #define TWL4030_BCI_BCICTL1 0x23
  109. #define TWL4030_BCI_CGAIN 0x020
  110. #define TWL4030_BCI_MESBAT (1 << 1)
  111. #define TWL4030_BCI_TYPEN (1 << 4)
  112. #define TWL4030_BCI_ITHEN (1 << 3)
  113. #define REG_BCICTL2 0x024
  114. #define TWL4030_BCI_ITHSENS 0x007
  115. /* Register and bits for GPBR1 register */
  116. #define TWL4030_REG_GPBR1 0x0c
  117. #define TWL4030_GPBR1_MADC_HFCLK_EN (1 << 7)
  118. struct twl4030_madc_user_parms {
  119. int channel;
  120. int average;
  121. int status;
  122. u16 result;
  123. };
  124. int twl4030_madc_conversion(struct twl4030_madc_request *conv);
  125. int twl4030_get_madc_conversion(int channel_no);
  126. #endif