core.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*
  2. * core.h -- Core driver for NXP PCF50633
  3. *
  4. * (C) 2006-2008 by Openmoko, Inc.
  5. * All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. */
  12. #ifndef __LINUX_MFD_PCF50633_CORE_H
  13. #define __LINUX_MFD_PCF50633_CORE_H
  14. #include <linux/i2c.h>
  15. #include <linux/workqueue.h>
  16. #include <linux/regulator/driver.h>
  17. #include <linux/regulator/machine.h>
  18. #include <linux/power_supply.h>
  19. struct pcf50633;
  20. #define PCF50633_NUM_REGULATORS 11
  21. struct pcf50633_platform_data {
  22. struct regulator_init_data reg_init_data[PCF50633_NUM_REGULATORS];
  23. char **batteries;
  24. int num_batteries;
  25. /* Callbacks */
  26. void (*probe_done)(struct pcf50633 *);
  27. void (*mbc_event_callback)(struct pcf50633 *, int);
  28. void (*regulator_registered)(struct pcf50633 *, int);
  29. void (*force_shutdown)(struct pcf50633 *);
  30. u8 resumers[5];
  31. };
  32. struct pcf50633_subdev_pdata {
  33. struct pcf50633 *pcf;
  34. };
  35. struct pcf50633_irq {
  36. void (*handler) (int, void *);
  37. void *data;
  38. };
  39. int pcf50633_register_irq(struct pcf50633 *pcf, int irq,
  40. void (*handler) (int, void *), void *data);
  41. int pcf50633_free_irq(struct pcf50633 *pcf, int irq);
  42. int pcf50633_irq_mask(struct pcf50633 *pcf, int irq);
  43. int pcf50633_irq_unmask(struct pcf50633 *pcf, int irq);
  44. int pcf50633_irq_mask_get(struct pcf50633 *pcf, int irq);
  45. int pcf50633_read_block(struct pcf50633 *, u8 reg,
  46. int nr_regs, u8 *data);
  47. int pcf50633_write_block(struct pcf50633 *pcf, u8 reg,
  48. int nr_regs, u8 *data);
  49. u8 pcf50633_reg_read(struct pcf50633 *, u8 reg);
  50. int pcf50633_reg_write(struct pcf50633 *pcf, u8 reg, u8 val);
  51. int pcf50633_reg_set_bit_mask(struct pcf50633 *pcf, u8 reg, u8 mask, u8 val);
  52. int pcf50633_reg_clear_bits(struct pcf50633 *pcf, u8 reg, u8 bits);
  53. /* Interrupt registers */
  54. #define PCF50633_REG_INT1 0x02
  55. #define PCF50633_REG_INT2 0x03
  56. #define PCF50633_REG_INT3 0x04
  57. #define PCF50633_REG_INT4 0x05
  58. #define PCF50633_REG_INT5 0x06
  59. #define PCF50633_REG_INT1M 0x07
  60. #define PCF50633_REG_INT2M 0x08
  61. #define PCF50633_REG_INT3M 0x09
  62. #define PCF50633_REG_INT4M 0x0a
  63. #define PCF50633_REG_INT5M 0x0b
  64. enum {
  65. /* Chip IRQs */
  66. PCF50633_IRQ_ADPINS,
  67. PCF50633_IRQ_ADPREM,
  68. PCF50633_IRQ_USBINS,
  69. PCF50633_IRQ_USBREM,
  70. PCF50633_IRQ_RESERVED1,
  71. PCF50633_IRQ_RESERVED2,
  72. PCF50633_IRQ_ALARM,
  73. PCF50633_IRQ_SECOND,
  74. PCF50633_IRQ_ONKEYR,
  75. PCF50633_IRQ_ONKEYF,
  76. PCF50633_IRQ_EXTON1R,
  77. PCF50633_IRQ_EXTON1F,
  78. PCF50633_IRQ_EXTON2R,
  79. PCF50633_IRQ_EXTON2F,
  80. PCF50633_IRQ_EXTON3R,
  81. PCF50633_IRQ_EXTON3F,
  82. PCF50633_IRQ_BATFULL,
  83. PCF50633_IRQ_CHGHALT,
  84. PCF50633_IRQ_THLIMON,
  85. PCF50633_IRQ_THLIMOFF,
  86. PCF50633_IRQ_USBLIMON,
  87. PCF50633_IRQ_USBLIMOFF,
  88. PCF50633_IRQ_ADCRDY,
  89. PCF50633_IRQ_ONKEY1S,
  90. PCF50633_IRQ_LOWSYS,
  91. PCF50633_IRQ_LOWBAT,
  92. PCF50633_IRQ_HIGHTMP,
  93. PCF50633_IRQ_AUTOPWRFAIL,
  94. PCF50633_IRQ_DWN1PWRFAIL,
  95. PCF50633_IRQ_DWN2PWRFAIL,
  96. PCF50633_IRQ_LEDPWRFAIL,
  97. PCF50633_IRQ_LEDOVP,
  98. PCF50633_IRQ_LDO1PWRFAIL,
  99. PCF50633_IRQ_LDO2PWRFAIL,
  100. PCF50633_IRQ_LDO3PWRFAIL,
  101. PCF50633_IRQ_LDO4PWRFAIL,
  102. PCF50633_IRQ_LDO5PWRFAIL,
  103. PCF50633_IRQ_LDO6PWRFAIL,
  104. PCF50633_IRQ_HCLDOPWRFAIL,
  105. PCF50633_IRQ_HCLDOOVL,
  106. /* Always last */
  107. PCF50633_NUM_IRQ,
  108. };
  109. struct pcf50633 {
  110. struct device *dev;
  111. struct i2c_client *i2c_client;
  112. struct pcf50633_platform_data *pdata;
  113. int irq;
  114. struct pcf50633_irq irq_handler[PCF50633_NUM_IRQ];
  115. struct work_struct irq_work;
  116. struct mutex lock;
  117. u8 mask_regs[5];
  118. u8 suspend_irq_masks[5];
  119. u8 resume_reason[5];
  120. int is_suspended;
  121. int onkey1s_held;
  122. struct platform_device *rtc_pdev;
  123. struct platform_device *mbc_pdev;
  124. struct platform_device *adc_pdev;
  125. struct platform_device *input_pdev;
  126. struct platform_device *regulator_pdev[PCF50633_NUM_REGULATORS];
  127. };
  128. enum pcf50633_reg_int1 {
  129. PCF50633_INT1_ADPINS = 0x01, /* Adapter inserted */
  130. PCF50633_INT1_ADPREM = 0x02, /* Adapter removed */
  131. PCF50633_INT1_USBINS = 0x04, /* USB inserted */
  132. PCF50633_INT1_USBREM = 0x08, /* USB removed */
  133. /* reserved */
  134. PCF50633_INT1_ALARM = 0x40, /* RTC alarm time is reached */
  135. PCF50633_INT1_SECOND = 0x80, /* RTC periodic second interrupt */
  136. };
  137. enum pcf50633_reg_int2 {
  138. PCF50633_INT2_ONKEYR = 0x01, /* ONKEY rising edge */
  139. PCF50633_INT2_ONKEYF = 0x02, /* ONKEY falling edge */
  140. PCF50633_INT2_EXTON1R = 0x04, /* EXTON1 rising edge */
  141. PCF50633_INT2_EXTON1F = 0x08, /* EXTON1 falling edge */
  142. PCF50633_INT2_EXTON2R = 0x10, /* EXTON2 rising edge */
  143. PCF50633_INT2_EXTON2F = 0x20, /* EXTON2 falling edge */
  144. PCF50633_INT2_EXTON3R = 0x40, /* EXTON3 rising edge */
  145. PCF50633_INT2_EXTON3F = 0x80, /* EXTON3 falling edge */
  146. };
  147. enum pcf50633_reg_int3 {
  148. PCF50633_INT3_BATFULL = 0x01, /* Battery full */
  149. PCF50633_INT3_CHGHALT = 0x02, /* Charger halt */
  150. PCF50633_INT3_THLIMON = 0x04,
  151. PCF50633_INT3_THLIMOFF = 0x08,
  152. PCF50633_INT3_USBLIMON = 0x10,
  153. PCF50633_INT3_USBLIMOFF = 0x20,
  154. PCF50633_INT3_ADCRDY = 0x40, /* ADC result ready */
  155. PCF50633_INT3_ONKEY1S = 0x80, /* ONKEY pressed 1 second */
  156. };
  157. enum pcf50633_reg_int4 {
  158. PCF50633_INT4_LOWSYS = 0x01,
  159. PCF50633_INT4_LOWBAT = 0x02,
  160. PCF50633_INT4_HIGHTMP = 0x04,
  161. PCF50633_INT4_AUTOPWRFAIL = 0x08,
  162. PCF50633_INT4_DWN1PWRFAIL = 0x10,
  163. PCF50633_INT4_DWN2PWRFAIL = 0x20,
  164. PCF50633_INT4_LEDPWRFAIL = 0x40,
  165. PCF50633_INT4_LEDOVP = 0x80,
  166. };
  167. enum pcf50633_reg_int5 {
  168. PCF50633_INT5_LDO1PWRFAIL = 0x01,
  169. PCF50633_INT5_LDO2PWRFAIL = 0x02,
  170. PCF50633_INT5_LDO3PWRFAIL = 0x04,
  171. PCF50633_INT5_LDO4PWRFAIL = 0x08,
  172. PCF50633_INT5_LDO5PWRFAIL = 0x10,
  173. PCF50633_INT5_LDO6PWRFAIL = 0x20,
  174. PCF50633_INT5_HCLDOPWRFAIL = 0x40,
  175. PCF50633_INT5_HCLDOOVL = 0x80,
  176. };
  177. /* misc. registers */
  178. #define PCF50633_REG_OOCSHDWN 0x0c
  179. /* LED registers */
  180. #define PCF50633_REG_LEDOUT 0x28
  181. #define PCF50633_REG_LEDENA 0x29
  182. #define PCF50633_REG_LEDCTL 0x2a
  183. #define PCF50633_REG_LEDDIM 0x2b
  184. #endif