da9052.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * da9052 declarations for DA9052 PMICs.
  3. *
  4. * Copyright(c) 2011 Dialog Semiconductor Ltd.
  5. *
  6. * Author: David Dajun Chen <dchen@diasemi.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. *
  22. */
  23. #ifndef __MFD_DA9052_DA9052_H
  24. #define __MFD_DA9052_DA9052_H
  25. #include <linux/interrupt.h>
  26. #include <linux/regmap.h>
  27. #include <linux/slab.h>
  28. #include <linux/completion.h>
  29. #include <linux/list.h>
  30. #include <linux/mfd/core.h>
  31. #include <linux/mfd/da9052/reg.h>
  32. /* Common - HWMON Channel Definations */
  33. #define DA9052_ADC_VDDOUT 0
  34. #define DA9052_ADC_ICH 1
  35. #define DA9052_ADC_TBAT 2
  36. #define DA9052_ADC_VBAT 3
  37. #define DA9052_ADC_IN4 4
  38. #define DA9052_ADC_IN5 5
  39. #define DA9052_ADC_IN6 6
  40. #define DA9052_ADC_TSI 7
  41. #define DA9052_ADC_TJUNC 8
  42. #define DA9052_ADC_VBBAT 9
  43. #define DA9052_IRQ_DCIN 0
  44. #define DA9052_IRQ_VBUS 1
  45. #define DA9052_IRQ_DCINREM 2
  46. #define DA9052_IRQ_VBUSREM 3
  47. #define DA9052_IRQ_VDDLOW 4
  48. #define DA9052_IRQ_ALARM 5
  49. #define DA9052_IRQ_SEQRDY 6
  50. #define DA9052_IRQ_COMP1V2 7
  51. #define DA9052_IRQ_NONKEY 8
  52. #define DA9052_IRQ_IDFLOAT 9
  53. #define DA9052_IRQ_IDGND 10
  54. #define DA9052_IRQ_CHGEND 11
  55. #define DA9052_IRQ_TBAT 12
  56. #define DA9052_IRQ_ADC_EOM 13
  57. #define DA9052_IRQ_PENDOWN 14
  58. #define DA9052_IRQ_TSIREADY 15
  59. #define DA9052_IRQ_GPI0 16
  60. #define DA9052_IRQ_GPI1 17
  61. #define DA9052_IRQ_GPI2 18
  62. #define DA9052_IRQ_GPI3 19
  63. #define DA9052_IRQ_GPI4 20
  64. #define DA9052_IRQ_GPI5 21
  65. #define DA9052_IRQ_GPI6 22
  66. #define DA9052_IRQ_GPI7 23
  67. #define DA9052_IRQ_GPI8 24
  68. #define DA9052_IRQ_GPI9 25
  69. #define DA9052_IRQ_GPI10 26
  70. #define DA9052_IRQ_GPI11 27
  71. #define DA9052_IRQ_GPI12 28
  72. #define DA9052_IRQ_GPI13 29
  73. #define DA9052_IRQ_GPI14 30
  74. #define DA9052_IRQ_GPI15 31
  75. enum da9052_chip_id {
  76. DA9052,
  77. DA9053_AA,
  78. DA9053_BA,
  79. DA9053_BB,
  80. };
  81. struct da9052_pdata;
  82. struct da9052 {
  83. struct device *dev;
  84. struct regmap *regmap;
  85. struct mutex auxadc_lock;
  86. struct completion done;
  87. int irq_base;
  88. u8 chip_id;
  89. int chip_irq;
  90. };
  91. /* ADC API */
  92. int da9052_adc_manual_read(struct da9052 *da9052, unsigned char channel);
  93. int da9052_adc_read_temp(struct da9052 *da9052);
  94. /* Device I/O API */
  95. static inline int da9052_reg_read(struct da9052 *da9052, unsigned char reg)
  96. {
  97. int val, ret;
  98. ret = regmap_read(da9052->regmap, reg, &val);
  99. if (ret < 0)
  100. return ret;
  101. return val;
  102. }
  103. static inline int da9052_reg_write(struct da9052 *da9052, unsigned char reg,
  104. unsigned char val)
  105. {
  106. return regmap_write(da9052->regmap, reg, val);
  107. }
  108. static inline int da9052_group_read(struct da9052 *da9052, unsigned char reg,
  109. unsigned reg_cnt, unsigned char *val)
  110. {
  111. return regmap_bulk_read(da9052->regmap, reg, val, reg_cnt);
  112. }
  113. static inline int da9052_group_write(struct da9052 *da9052, unsigned char reg,
  114. unsigned reg_cnt, unsigned char *val)
  115. {
  116. return regmap_raw_write(da9052->regmap, reg, val, reg_cnt);
  117. }
  118. static inline int da9052_reg_update(struct da9052 *da9052, unsigned char reg,
  119. unsigned char bit_mask,
  120. unsigned char reg_val)
  121. {
  122. return regmap_update_bits(da9052->regmap, reg, bit_mask, reg_val);
  123. }
  124. int da9052_device_init(struct da9052 *da9052, u8 chip_id);
  125. void da9052_device_exit(struct da9052 *da9052);
  126. extern struct regmap_config da9052_regmap_config;
  127. #endif /* __MFD_DA9052_DA9052_H */