rc5t583.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. /*
  2. * Core driver interface to access RICOH_RC5T583 power management chip.
  3. *
  4. * Copyright (c) 2011-2012, NVIDIA CORPORATION. All rights reserved.
  5. * Author: Laxman dewangan <ldewangan@nvidia.com>
  6. *
  7. * Based on code
  8. * Copyright (C) 2011 RICOH COMPANY,LTD
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms and conditions of the GNU General Public License,
  12. * version 2, as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope it will be useful, but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  17. * more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. #ifndef __LINUX_MFD_RC5T583_H
  24. #define __LINUX_MFD_RC5T583_H
  25. #include <linux/mutex.h>
  26. #include <linux/types.h>
  27. #include <linux/regmap.h>
  28. #define RC5T583_MAX_REGS 0xF8
  29. /* Maximum number of main interrupts */
  30. #define MAX_MAIN_INTERRUPT 5
  31. #define RC5T583_MAX_GPEDGE_REG 2
  32. #define RC5T583_MAX_INTERRUPT_MASK_REGS 9
  33. /* Interrupt enable register */
  34. #define RC5T583_INT_EN_SYS1 0x19
  35. #define RC5T583_INT_EN_SYS2 0x1D
  36. #define RC5T583_INT_EN_DCDC 0x41
  37. #define RC5T583_INT_EN_RTC 0xED
  38. #define RC5T583_INT_EN_ADC1 0x90
  39. #define RC5T583_INT_EN_ADC2 0x91
  40. #define RC5T583_INT_EN_ADC3 0x92
  41. /* Interrupt status registers (monitor regs in Ricoh)*/
  42. #define RC5T583_INTC_INTPOL 0xAD
  43. #define RC5T583_INTC_INTEN 0xAE
  44. #define RC5T583_INTC_INTMON 0xAF
  45. #define RC5T583_INT_MON_GRP 0xAF
  46. #define RC5T583_INT_MON_SYS1 0x1B
  47. #define RC5T583_INT_MON_SYS2 0x1F
  48. #define RC5T583_INT_MON_DCDC 0x43
  49. #define RC5T583_INT_MON_RTC 0xEE
  50. /* Interrupt clearing registers */
  51. #define RC5T583_INT_IR_SYS1 0x1A
  52. #define RC5T583_INT_IR_SYS2 0x1E
  53. #define RC5T583_INT_IR_DCDC 0x42
  54. #define RC5T583_INT_IR_RTC 0xEE
  55. #define RC5T583_INT_IR_ADCL 0x94
  56. #define RC5T583_INT_IR_ADCH 0x95
  57. #define RC5T583_INT_IR_ADCEND 0x96
  58. #define RC5T583_INT_IR_GPIOR 0xA9
  59. #define RC5T583_INT_IR_GPIOF 0xAA
  60. /* Sleep sequence registers */
  61. #define RC5T583_SLPSEQ1 0x21
  62. #define RC5T583_SLPSEQ2 0x22
  63. #define RC5T583_SLPSEQ3 0x23
  64. #define RC5T583_SLPSEQ4 0x24
  65. #define RC5T583_SLPSEQ5 0x25
  66. #define RC5T583_SLPSEQ6 0x26
  67. #define RC5T583_SLPSEQ7 0x27
  68. #define RC5T583_SLPSEQ8 0x28
  69. #define RC5T583_SLPSEQ9 0x29
  70. #define RC5T583_SLPSEQ10 0x2A
  71. #define RC5T583_SLPSEQ11 0x2B
  72. /* Regulator registers */
  73. #define RC5T583_REG_DC0CTL 0x30
  74. #define RC5T583_REG_DC0DAC 0x31
  75. #define RC5T583_REG_DC0LATCTL 0x32
  76. #define RC5T583_REG_SR0CTL 0x33
  77. #define RC5T583_REG_DC1CTL 0x34
  78. #define RC5T583_REG_DC1DAC 0x35
  79. #define RC5T583_REG_DC1LATCTL 0x36
  80. #define RC5T583_REG_SR1CTL 0x37
  81. #define RC5T583_REG_DC2CTL 0x38
  82. #define RC5T583_REG_DC2DAC 0x39
  83. #define RC5T583_REG_DC2LATCTL 0x3A
  84. #define RC5T583_REG_SR2CTL 0x3B
  85. #define RC5T583_REG_DC3CTL 0x3C
  86. #define RC5T583_REG_DC3DAC 0x3D
  87. #define RC5T583_REG_DC3LATCTL 0x3E
  88. #define RC5T583_REG_SR3CTL 0x3F
  89. #define RC5T583_REG_LDOEN1 0x50
  90. #define RC5T583_REG_LDOEN2 0x51
  91. #define RC5T583_REG_LDODIS1 0x52
  92. #define RC5T583_REG_LDODIS2 0x53
  93. #define RC5T583_REG_LDO0DAC 0x54
  94. #define RC5T583_REG_LDO1DAC 0x55
  95. #define RC5T583_REG_LDO2DAC 0x56
  96. #define RC5T583_REG_LDO3DAC 0x57
  97. #define RC5T583_REG_LDO4DAC 0x58
  98. #define RC5T583_REG_LDO5DAC 0x59
  99. #define RC5T583_REG_LDO6DAC 0x5A
  100. #define RC5T583_REG_LDO7DAC 0x5B
  101. #define RC5T583_REG_LDO8DAC 0x5C
  102. #define RC5T583_REG_LDO9DAC 0x5D
  103. #define RC5T583_REG_DC0DAC_DS 0x60
  104. #define RC5T583_REG_DC1DAC_DS 0x61
  105. #define RC5T583_REG_DC2DAC_DS 0x62
  106. #define RC5T583_REG_DC3DAC_DS 0x63
  107. #define RC5T583_REG_LDO0DAC_DS 0x64
  108. #define RC5T583_REG_LDO1DAC_DS 0x65
  109. #define RC5T583_REG_LDO2DAC_DS 0x66
  110. #define RC5T583_REG_LDO3DAC_DS 0x67
  111. #define RC5T583_REG_LDO4DAC_DS 0x68
  112. #define RC5T583_REG_LDO5DAC_DS 0x69
  113. #define RC5T583_REG_LDO6DAC_DS 0x6A
  114. #define RC5T583_REG_LDO7DAC_DS 0x6B
  115. #define RC5T583_REG_LDO8DAC_DS 0x6C
  116. #define RC5T583_REG_LDO9DAC_DS 0x6D
  117. /* GPIO register base address */
  118. #define RC5T583_GPIO_IOSEL 0xA0
  119. #define RC5T583_GPIO_PDEN 0xA1
  120. #define RC5T583_GPIO_IOOUT 0xA2
  121. #define RC5T583_GPIO_PGSEL 0xA3
  122. #define RC5T583_GPIO_GPINV 0xA4
  123. #define RC5T583_GPIO_GPDEB 0xA5
  124. #define RC5T583_GPIO_GPEDGE1 0xA6
  125. #define RC5T583_GPIO_GPEDGE2 0xA7
  126. #define RC5T583_GPIO_EN_INT 0xA8
  127. #define RC5T583_GPIO_MON_IOIN 0xAB
  128. #define RC5T583_GPIO_GPOFUNC 0xAC
  129. /* RICOH_RC5T583 IRQ definitions */
  130. enum {
  131. RC5T583_IRQ_ONKEY,
  132. RC5T583_IRQ_ACOK,
  133. RC5T583_IRQ_LIDOPEN,
  134. RC5T583_IRQ_PREOT,
  135. RC5T583_IRQ_CLKSTP,
  136. RC5T583_IRQ_ONKEY_OFF,
  137. RC5T583_IRQ_WD,
  138. RC5T583_IRQ_EN_PWRREQ1,
  139. RC5T583_IRQ_EN_PWRREQ2,
  140. RC5T583_IRQ_PRE_VINDET,
  141. RC5T583_IRQ_DC0LIM,
  142. RC5T583_IRQ_DC1LIM,
  143. RC5T583_IRQ_DC2LIM,
  144. RC5T583_IRQ_DC3LIM,
  145. RC5T583_IRQ_CTC,
  146. RC5T583_IRQ_YALE,
  147. RC5T583_IRQ_DALE,
  148. RC5T583_IRQ_WALE,
  149. RC5T583_IRQ_AIN1L,
  150. RC5T583_IRQ_AIN2L,
  151. RC5T583_IRQ_AIN3L,
  152. RC5T583_IRQ_VBATL,
  153. RC5T583_IRQ_VIN3L,
  154. RC5T583_IRQ_VIN8L,
  155. RC5T583_IRQ_AIN1H,
  156. RC5T583_IRQ_AIN2H,
  157. RC5T583_IRQ_AIN3H,
  158. RC5T583_IRQ_VBATH,
  159. RC5T583_IRQ_VIN3H,
  160. RC5T583_IRQ_VIN8H,
  161. RC5T583_IRQ_ADCEND,
  162. RC5T583_IRQ_GPIO0,
  163. RC5T583_IRQ_GPIO1,
  164. RC5T583_IRQ_GPIO2,
  165. RC5T583_IRQ_GPIO3,
  166. RC5T583_IRQ_GPIO4,
  167. RC5T583_IRQ_GPIO5,
  168. RC5T583_IRQ_GPIO6,
  169. RC5T583_IRQ_GPIO7,
  170. /* Should be last entry */
  171. RC5T583_MAX_IRQS,
  172. };
  173. /* Ricoh583 gpio definitions */
  174. enum {
  175. RC5T583_GPIO0,
  176. RC5T583_GPIO1,
  177. RC5T583_GPIO2,
  178. RC5T583_GPIO3,
  179. RC5T583_GPIO4,
  180. RC5T583_GPIO5,
  181. RC5T583_GPIO6,
  182. RC5T583_GPIO7,
  183. /* Should be last entry */
  184. RC5T583_MAX_GPIO,
  185. };
  186. enum {
  187. RC5T583_DS_NONE,
  188. RC5T583_DS_DC0,
  189. RC5T583_DS_DC1,
  190. RC5T583_DS_DC2,
  191. RC5T583_DS_DC3,
  192. RC5T583_DS_LDO0,
  193. RC5T583_DS_LDO1,
  194. RC5T583_DS_LDO2,
  195. RC5T583_DS_LDO3,
  196. RC5T583_DS_LDO4,
  197. RC5T583_DS_LDO5,
  198. RC5T583_DS_LDO6,
  199. RC5T583_DS_LDO7,
  200. RC5T583_DS_LDO8,
  201. RC5T583_DS_LDO9,
  202. RC5T583_DS_PSO0,
  203. RC5T583_DS_PSO1,
  204. RC5T583_DS_PSO2,
  205. RC5T583_DS_PSO3,
  206. RC5T583_DS_PSO4,
  207. RC5T583_DS_PSO5,
  208. RC5T583_DS_PSO6,
  209. RC5T583_DS_PSO7,
  210. /* Should be last entry */
  211. RC5T583_DS_MAX,
  212. };
  213. /*
  214. * Ricoh pmic RC5T583 supports sleep through two external controls.
  215. * The output of gpios and regulator can be enable/disable through
  216. * this external signals.
  217. */
  218. enum {
  219. RC5T583_EXT_PWRREQ1_CONTROL = 0x1,
  220. RC5T583_EXT_PWRREQ2_CONTROL = 0x2,
  221. };
  222. struct rc5t583 {
  223. struct device *dev;
  224. struct regmap *regmap;
  225. int chip_irq;
  226. int irq_base;
  227. struct mutex irq_lock;
  228. unsigned long group_irq_en[MAX_MAIN_INTERRUPT];
  229. /* For main interrupt bits in INTC */
  230. uint8_t intc_inten_reg;
  231. /* For group interrupt bits and address */
  232. uint8_t irq_en_reg[RC5T583_MAX_INTERRUPT_MASK_REGS];
  233. /* For gpio edge */
  234. uint8_t gpedge_reg[RC5T583_MAX_GPEDGE_REG];
  235. };
  236. /*
  237. * rc5t583_platform_data: Platform data for ricoh rc5t583 pmu.
  238. * The board specific data is provided through this structure.
  239. * @irq_base: Irq base number on which this device registers their interrupts.
  240. * @enable_shutdown: Enable shutdown through the input pin "shutdown".
  241. */
  242. struct rc5t583_platform_data {
  243. int irq_base;
  244. bool enable_shutdown;
  245. };
  246. static inline int rc5t583_write(struct device *dev, uint8_t reg, uint8_t val)
  247. {
  248. struct rc5t583 *rc5t583 = dev_get_drvdata(dev);
  249. return regmap_write(rc5t583->regmap, reg, val);
  250. }
  251. static inline int rc5t583_read(struct device *dev, uint8_t reg, uint8_t *val)
  252. {
  253. struct rc5t583 *rc5t583 = dev_get_drvdata(dev);
  254. unsigned int ival;
  255. int ret;
  256. ret = regmap_read(rc5t583->regmap, reg, &ival);
  257. if (!ret)
  258. *val = (uint8_t)ival;
  259. return ret;
  260. }
  261. static inline int rc5t583_set_bits(struct device *dev, unsigned int reg,
  262. unsigned int bit_mask)
  263. {
  264. struct rc5t583 *rc5t583 = dev_get_drvdata(dev);
  265. return regmap_update_bits(rc5t583->regmap, reg, bit_mask, bit_mask);
  266. }
  267. static inline int rc5t583_clear_bits(struct device *dev, unsigned int reg,
  268. unsigned int bit_mask)
  269. {
  270. struct rc5t583 *rc5t583 = dev_get_drvdata(dev);
  271. return regmap_update_bits(rc5t583->regmap, reg, bit_mask, 0);
  272. }
  273. static inline int rc5t583_update(struct device *dev, unsigned int reg,
  274. unsigned int val, unsigned int mask)
  275. {
  276. struct rc5t583 *rc5t583 = dev_get_drvdata(dev);
  277. return regmap_update_bits(rc5t583->regmap, reg, mask, val);
  278. }
  279. int rc5t583_ext_power_req_config(struct device *dev, int deepsleep_id,
  280. int ext_pwr_req, int deepsleep_slot_nr);
  281. int rc5t583_irq_init(struct rc5t583 *rc5t583, int irq, int irq_base);
  282. int rc5t583_irq_exit(struct rc5t583 *rc5t583);
  283. #endif