rc5t583.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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_EN_REGS 8
  33. #define RC5T583_MAX_INTERRUPT_MASK_REGS 9
  34. /* Interrupt enable register */
  35. #define RC5T583_INT_EN_SYS1 0x19
  36. #define RC5T583_INT_EN_SYS2 0x1D
  37. #define RC5T583_INT_EN_DCDC 0x41
  38. #define RC5T583_INT_EN_RTC 0xED
  39. #define RC5T583_INT_EN_ADC1 0x90
  40. #define RC5T583_INT_EN_ADC2 0x91
  41. #define RC5T583_INT_EN_ADC3 0x92
  42. /* Interrupt status registers (monitor regs in Ricoh)*/
  43. #define RC5T583_INTC_INTPOL 0xAD
  44. #define RC5T583_INTC_INTEN 0xAE
  45. #define RC5T583_INTC_INTMON 0xAF
  46. #define RC5T583_INT_MON_GRP 0xAF
  47. #define RC5T583_INT_MON_SYS1 0x1B
  48. #define RC5T583_INT_MON_SYS2 0x1F
  49. #define RC5T583_INT_MON_DCDC 0x43
  50. #define RC5T583_INT_MON_RTC 0xEE
  51. /* Interrupt clearing registers */
  52. #define RC5T583_INT_IR_SYS1 0x1A
  53. #define RC5T583_INT_IR_SYS2 0x1E
  54. #define RC5T583_INT_IR_DCDC 0x42
  55. #define RC5T583_INT_IR_RTC 0xEE
  56. #define RC5T583_INT_IR_ADCL 0x94
  57. #define RC5T583_INT_IR_ADCH 0x95
  58. #define RC5T583_INT_IR_ADCEND 0x96
  59. #define RC5T583_INT_IR_GPIOR 0xA9
  60. #define RC5T583_INT_IR_GPIOF 0xAA
  61. /* Sleep sequence registers */
  62. #define RC5T583_SLPSEQ1 0x21
  63. #define RC5T583_SLPSEQ2 0x22
  64. #define RC5T583_SLPSEQ3 0x23
  65. #define RC5T583_SLPSEQ4 0x24
  66. #define RC5T583_SLPSEQ5 0x25
  67. #define RC5T583_SLPSEQ6 0x26
  68. #define RC5T583_SLPSEQ7 0x27
  69. #define RC5T583_SLPSEQ8 0x28
  70. #define RC5T583_SLPSEQ9 0x29
  71. #define RC5T583_SLPSEQ10 0x2A
  72. #define RC5T583_SLPSEQ11 0x2B
  73. /* Regulator registers */
  74. #define RC5T583_REG_DC0CTL 0x30
  75. #define RC5T583_REG_DC0DAC 0x31
  76. #define RC5T583_REG_DC0LATCTL 0x32
  77. #define RC5T583_REG_SR0CTL 0x33
  78. #define RC5T583_REG_DC1CTL 0x34
  79. #define RC5T583_REG_DC1DAC 0x35
  80. #define RC5T583_REG_DC1LATCTL 0x36
  81. #define RC5T583_REG_SR1CTL 0x37
  82. #define RC5T583_REG_DC2CTL 0x38
  83. #define RC5T583_REG_DC2DAC 0x39
  84. #define RC5T583_REG_DC2LATCTL 0x3A
  85. #define RC5T583_REG_SR2CTL 0x3B
  86. #define RC5T583_REG_DC3CTL 0x3C
  87. #define RC5T583_REG_DC3DAC 0x3D
  88. #define RC5T583_REG_DC3LATCTL 0x3E
  89. #define RC5T583_REG_SR3CTL 0x3F
  90. #define RC5T583_REG_LDOEN1 0x50
  91. #define RC5T583_REG_LDOEN2 0x51
  92. #define RC5T583_REG_LDODIS1 0x52
  93. #define RC5T583_REG_LDODIS2 0x53
  94. #define RC5T583_REG_LDO0DAC 0x54
  95. #define RC5T583_REG_LDO1DAC 0x55
  96. #define RC5T583_REG_LDO2DAC 0x56
  97. #define RC5T583_REG_LDO3DAC 0x57
  98. #define RC5T583_REG_LDO4DAC 0x58
  99. #define RC5T583_REG_LDO5DAC 0x59
  100. #define RC5T583_REG_LDO6DAC 0x5A
  101. #define RC5T583_REG_LDO7DAC 0x5B
  102. #define RC5T583_REG_LDO8DAC 0x5C
  103. #define RC5T583_REG_LDO9DAC 0x5D
  104. #define RC5T583_REG_DC0DAC_DS 0x60
  105. #define RC5T583_REG_DC1DAC_DS 0x61
  106. #define RC5T583_REG_DC2DAC_DS 0x62
  107. #define RC5T583_REG_DC3DAC_DS 0x63
  108. #define RC5T583_REG_LDO0DAC_DS 0x64
  109. #define RC5T583_REG_LDO1DAC_DS 0x65
  110. #define RC5T583_REG_LDO2DAC_DS 0x66
  111. #define RC5T583_REG_LDO3DAC_DS 0x67
  112. #define RC5T583_REG_LDO4DAC_DS 0x68
  113. #define RC5T583_REG_LDO5DAC_DS 0x69
  114. #define RC5T583_REG_LDO6DAC_DS 0x6A
  115. #define RC5T583_REG_LDO7DAC_DS 0x6B
  116. #define RC5T583_REG_LDO8DAC_DS 0x6C
  117. #define RC5T583_REG_LDO9DAC_DS 0x6D
  118. /* GPIO register base address */
  119. #define RC5T583_GPIO_IOSEL 0xA0
  120. #define RC5T583_GPIO_PDEN 0xA1
  121. #define RC5T583_GPIO_IOOUT 0xA2
  122. #define RC5T583_GPIO_PGSEL 0xA3
  123. #define RC5T583_GPIO_GPINV 0xA4
  124. #define RC5T583_GPIO_GPDEB 0xA5
  125. #define RC5T583_GPIO_GPEDGE1 0xA6
  126. #define RC5T583_GPIO_GPEDGE2 0xA7
  127. #define RC5T583_GPIO_EN_INT 0xA8
  128. #define RC5T583_GPIO_MON_IOIN 0xAB
  129. #define RC5T583_GPIO_GPOFUNC 0xAC
  130. /* RTC registers */
  131. #define RC5T583_RTC_SEC 0xE0
  132. #define RC5T583_RTC_MIN 0xE1
  133. #define RC5T583_RTC_HOUR 0xE2
  134. #define RC5T583_RTC_WDAY 0xE3
  135. #define RC5T583_RTC_DAY 0xE4
  136. #define RC5T583_RTC_MONTH 0xE5
  137. #define RC5T583_RTC_YEAR 0xE6
  138. #define RC5T583_RTC_ADJ 0xE7
  139. #define RC5T583_RTC_AW_MIN 0xE8
  140. #define RC5T583_RTC_AW_HOUR 0xE9
  141. #define RC5T583_RTC_AW_WEEK 0xEA
  142. #define RC5T583_RTC_AD_MIN 0xEB
  143. #define RC5T583_RTC_AD_HOUR 0xEC
  144. #define RC5T583_RTC_CTL1 0xED
  145. #define RC5T583_RTC_CTL2 0xEE
  146. #define RC5T583_RTC_AY_MIN 0xF0
  147. #define RC5T583_RTC_AY_HOUR 0xF1
  148. #define RC5T583_RTC_AY_DAY 0xF2
  149. #define RC5T583_RTC_AY_MONTH 0xF3
  150. #define RC5T583_RTC_AY_YEAR 0xF4
  151. /* RICOH_RC5T583 IRQ definitions */
  152. enum {
  153. RC5T583_IRQ_ONKEY,
  154. RC5T583_IRQ_ACOK,
  155. RC5T583_IRQ_LIDOPEN,
  156. RC5T583_IRQ_PREOT,
  157. RC5T583_IRQ_CLKSTP,
  158. RC5T583_IRQ_ONKEY_OFF,
  159. RC5T583_IRQ_WD,
  160. RC5T583_IRQ_EN_PWRREQ1,
  161. RC5T583_IRQ_EN_PWRREQ2,
  162. RC5T583_IRQ_PRE_VINDET,
  163. RC5T583_IRQ_DC0LIM,
  164. RC5T583_IRQ_DC1LIM,
  165. RC5T583_IRQ_DC2LIM,
  166. RC5T583_IRQ_DC3LIM,
  167. RC5T583_IRQ_CTC,
  168. RC5T583_IRQ_YALE,
  169. RC5T583_IRQ_DALE,
  170. RC5T583_IRQ_WALE,
  171. RC5T583_IRQ_AIN1L,
  172. RC5T583_IRQ_AIN2L,
  173. RC5T583_IRQ_AIN3L,
  174. RC5T583_IRQ_VBATL,
  175. RC5T583_IRQ_VIN3L,
  176. RC5T583_IRQ_VIN8L,
  177. RC5T583_IRQ_AIN1H,
  178. RC5T583_IRQ_AIN2H,
  179. RC5T583_IRQ_AIN3H,
  180. RC5T583_IRQ_VBATH,
  181. RC5T583_IRQ_VIN3H,
  182. RC5T583_IRQ_VIN8H,
  183. RC5T583_IRQ_ADCEND,
  184. RC5T583_IRQ_GPIO0,
  185. RC5T583_IRQ_GPIO1,
  186. RC5T583_IRQ_GPIO2,
  187. RC5T583_IRQ_GPIO3,
  188. RC5T583_IRQ_GPIO4,
  189. RC5T583_IRQ_GPIO5,
  190. RC5T583_IRQ_GPIO6,
  191. RC5T583_IRQ_GPIO7,
  192. /* Should be last entry */
  193. RC5T583_MAX_IRQS,
  194. };
  195. /* Ricoh583 gpio definitions */
  196. enum {
  197. RC5T583_GPIO0,
  198. RC5T583_GPIO1,
  199. RC5T583_GPIO2,
  200. RC5T583_GPIO3,
  201. RC5T583_GPIO4,
  202. RC5T583_GPIO5,
  203. RC5T583_GPIO6,
  204. RC5T583_GPIO7,
  205. /* Should be last entry */
  206. RC5T583_MAX_GPIO,
  207. };
  208. enum {
  209. RC5T583_DS_NONE,
  210. RC5T583_DS_DC0,
  211. RC5T583_DS_DC1,
  212. RC5T583_DS_DC2,
  213. RC5T583_DS_DC3,
  214. RC5T583_DS_LDO0,
  215. RC5T583_DS_LDO1,
  216. RC5T583_DS_LDO2,
  217. RC5T583_DS_LDO3,
  218. RC5T583_DS_LDO4,
  219. RC5T583_DS_LDO5,
  220. RC5T583_DS_LDO6,
  221. RC5T583_DS_LDO7,
  222. RC5T583_DS_LDO8,
  223. RC5T583_DS_LDO9,
  224. RC5T583_DS_PSO0,
  225. RC5T583_DS_PSO1,
  226. RC5T583_DS_PSO2,
  227. RC5T583_DS_PSO3,
  228. RC5T583_DS_PSO4,
  229. RC5T583_DS_PSO5,
  230. RC5T583_DS_PSO6,
  231. RC5T583_DS_PSO7,
  232. /* Should be last entry */
  233. RC5T583_DS_MAX,
  234. };
  235. /*
  236. * Ricoh pmic RC5T583 supports sleep through two external controls.
  237. * The output of gpios and regulator can be enable/disable through
  238. * this external signals.
  239. */
  240. enum {
  241. RC5T583_EXT_PWRREQ1_CONTROL = 0x1,
  242. RC5T583_EXT_PWRREQ2_CONTROL = 0x2,
  243. };
  244. enum {
  245. RC5T583_REGULATOR_DC0,
  246. RC5T583_REGULATOR_DC1,
  247. RC5T583_REGULATOR_DC2,
  248. RC5T583_REGULATOR_DC3,
  249. RC5T583_REGULATOR_LDO0,
  250. RC5T583_REGULATOR_LDO1,
  251. RC5T583_REGULATOR_LDO2,
  252. RC5T583_REGULATOR_LDO3,
  253. RC5T583_REGULATOR_LDO4,
  254. RC5T583_REGULATOR_LDO5,
  255. RC5T583_REGULATOR_LDO6,
  256. RC5T583_REGULATOR_LDO7,
  257. RC5T583_REGULATOR_LDO8,
  258. RC5T583_REGULATOR_LDO9,
  259. /* Should be last entry */
  260. RC5T583_REGULATOR_MAX,
  261. };
  262. struct rc5t583 {
  263. struct device *dev;
  264. struct regmap *regmap;
  265. int chip_irq;
  266. int irq_base;
  267. struct mutex irq_lock;
  268. unsigned long group_irq_en[MAX_MAIN_INTERRUPT];
  269. /* For main interrupt bits in INTC */
  270. uint8_t intc_inten_reg;
  271. /* For group interrupt bits and address */
  272. uint8_t irq_en_reg[RC5T583_MAX_INTERRUPT_EN_REGS];
  273. /* For gpio edge */
  274. uint8_t gpedge_reg[RC5T583_MAX_GPEDGE_REG];
  275. };
  276. /*
  277. * rc5t583_platform_data: Platform data for ricoh rc5t583 pmu.
  278. * The board specific data is provided through this structure.
  279. * @irq_base: Irq base number on which this device registers their interrupts.
  280. * @gpio_base: GPIO base from which gpio of this device will start.
  281. * @enable_shutdown: Enable shutdown through the input pin "shutdown".
  282. * @regulator_deepsleep_slot: The slot number on which device goes to sleep
  283. * in device sleep mode.
  284. * @regulator_ext_pwr_control: External power request regulator control. The
  285. * regulator output enable/disable is controlled by the external
  286. * power request input state.
  287. * @reg_init_data: Regulator init data.
  288. */
  289. struct rc5t583_platform_data {
  290. int irq_base;
  291. int gpio_base;
  292. bool enable_shutdown;
  293. int regulator_deepsleep_slot[RC5T583_REGULATOR_MAX];
  294. unsigned long regulator_ext_pwr_control[RC5T583_REGULATOR_MAX];
  295. struct regulator_init_data *reg_init_data[RC5T583_REGULATOR_MAX];
  296. };
  297. static inline int rc5t583_write(struct device *dev, uint8_t reg, uint8_t val)
  298. {
  299. struct rc5t583 *rc5t583 = dev_get_drvdata(dev);
  300. return regmap_write(rc5t583->regmap, reg, val);
  301. }
  302. static inline int rc5t583_read(struct device *dev, uint8_t reg, uint8_t *val)
  303. {
  304. struct rc5t583 *rc5t583 = dev_get_drvdata(dev);
  305. unsigned int ival;
  306. int ret;
  307. ret = regmap_read(rc5t583->regmap, reg, &ival);
  308. if (!ret)
  309. *val = (uint8_t)ival;
  310. return ret;
  311. }
  312. static inline int rc5t583_set_bits(struct device *dev, unsigned int reg,
  313. unsigned int bit_mask)
  314. {
  315. struct rc5t583 *rc5t583 = dev_get_drvdata(dev);
  316. return regmap_update_bits(rc5t583->regmap, reg, bit_mask, bit_mask);
  317. }
  318. static inline int rc5t583_clear_bits(struct device *dev, unsigned int reg,
  319. unsigned int bit_mask)
  320. {
  321. struct rc5t583 *rc5t583 = dev_get_drvdata(dev);
  322. return regmap_update_bits(rc5t583->regmap, reg, bit_mask, 0);
  323. }
  324. static inline int rc5t583_update(struct device *dev, unsigned int reg,
  325. unsigned int val, unsigned int mask)
  326. {
  327. struct rc5t583 *rc5t583 = dev_get_drvdata(dev);
  328. return regmap_update_bits(rc5t583->regmap, reg, mask, val);
  329. }
  330. int rc5t583_ext_power_req_config(struct device *dev, int deepsleep_id,
  331. int ext_pwr_req, int deepsleep_slot_nr);
  332. int rc5t583_irq_init(struct rc5t583 *rc5t583, int irq, int irq_base);
  333. int rc5t583_irq_exit(struct rc5t583 *rc5t583);
  334. #endif