/include/linux/mfd/wcd9xxx/core.h

https://github.com/airy09/android_kernel_sony_apq8064 · C Header · 223 lines · 187 code · 24 blank · 12 comment · 11 complexity · e344d183d2cba66b5af0c5b3e21e25aa MD5 · raw file

  1. /* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #ifndef __MFD_TABLA_CORE_H__
  13. #define __MFD_TABLA_CORE_H__
  14. #include <linux/interrupt.h>
  15. #include <linux/pm_qos.h>
  16. #define WCD9XXX_NUM_IRQ_REGS 3
  17. #define WCD9XXX_SLIM_NUM_PORT_REG 3
  18. #define WCD9XXX_INTERFACE_TYPE_SLIMBUS 0x00
  19. #define WCD9XXX_INTERFACE_TYPE_I2C 0x01
  20. #define TABLA_VERSION_1_0 0
  21. #define TABLA_VERSION_1_1 1
  22. #define TABLA_VERSION_2_0 2
  23. #define TABLA_IS_1_X(ver) \
  24. (((ver == TABLA_VERSION_1_0) || (ver == TABLA_VERSION_1_1)) ? 1 : 0)
  25. #define TABLA_IS_2_0(ver) ((ver == TABLA_VERSION_2_0) ? 1 : 0)
  26. #define SITAR_VERSION_1P0 0
  27. #define SITAR_VERSION_1P1 1
  28. #define SITAR_IS_1P0(ver) \
  29. ((ver == SITAR_VERSION_1P0) ? 1 : 0)
  30. #define SITAR_IS_1P1(ver) \
  31. ((ver == SITAR_VERSION_1P1) ? 1 : 0)
  32. enum {
  33. TABLA_IRQ_SLIMBUS = 0,
  34. TABLA_IRQ_MBHC_REMOVAL,
  35. TABLA_IRQ_MBHC_SHORT_TERM,
  36. TABLA_IRQ_MBHC_PRESS,
  37. TABLA_IRQ_MBHC_RELEASE,
  38. TABLA_IRQ_MBHC_POTENTIAL,
  39. TABLA_IRQ_MBHC_INSERTION,
  40. TABLA_IRQ_BG_PRECHARGE,
  41. TABLA_IRQ_PA1_STARTUP,
  42. TABLA_IRQ_PA2_STARTUP,
  43. TABLA_IRQ_PA3_STARTUP,
  44. TABLA_IRQ_PA4_STARTUP,
  45. TABLA_IRQ_PA5_STARTUP,
  46. TABLA_IRQ_MICBIAS1_PRECHARGE,
  47. TABLA_IRQ_MICBIAS2_PRECHARGE,
  48. TABLA_IRQ_MICBIAS3_PRECHARGE,
  49. TABLA_IRQ_HPH_PA_OCPL_FAULT,
  50. TABLA_IRQ_HPH_PA_OCPR_FAULT,
  51. TABLA_IRQ_EAR_PA_OCPL_FAULT,
  52. TABLA_IRQ_HPH_L_PA_STARTUP,
  53. TABLA_IRQ_HPH_R_PA_STARTUP,
  54. TABLA_IRQ_EAR_PA_STARTUP,
  55. TABLA_NUM_IRQS,
  56. };
  57. enum {
  58. SITAR_IRQ_SLIMBUS = 0,
  59. SITAR_IRQ_MBHC_REMOVAL,
  60. SITAR_IRQ_MBHC_SHORT_TERM,
  61. SITAR_IRQ_MBHC_PRESS,
  62. SITAR_IRQ_MBHC_RELEASE,
  63. SITAR_IRQ_MBHC_POTENTIAL,
  64. SITAR_IRQ_MBHC_INSERTION,
  65. SITAR_IRQ_BG_PRECHARGE,
  66. SITAR_IRQ_PA1_STARTUP,
  67. SITAR_IRQ_PA2_STARTUP,
  68. SITAR_IRQ_PA3_STARTUP,
  69. SITAR_IRQ_PA4_STARTUP,
  70. SITAR_IRQ_PA5_STARTUP,
  71. SITAR_IRQ_MICBIAS1_PRECHARGE,
  72. SITAR_IRQ_MICBIAS2_PRECHARGE,
  73. SITAR_IRQ_MICBIAS3_PRECHARGE,
  74. SITAR_IRQ_HPH_PA_OCPL_FAULT,
  75. SITAR_IRQ_HPH_PA_OCPR_FAULT,
  76. SITAR_IRQ_EAR_PA_OCPL_FAULT,
  77. SITAR_IRQ_HPH_L_PA_STARTUP,
  78. SITAR_IRQ_HPH_R_PA_STARTUP,
  79. SITAR_IRQ_EAR_PA_STARTUP,
  80. SITAR_NUM_IRQS,
  81. };
  82. enum {
  83. TAIKO_IRQ_SLIMBUS = 0,
  84. TAIKO_IRQ_MBHC_REMOVAL,
  85. TAIKO_IRQ_MBHC_SHORT_TERM,
  86. TAIKO_IRQ_MBHC_PRESS,
  87. TAIKO_IRQ_MBHC_RELEASE,
  88. TAIKO_IRQ_MBHC_POTENTIAL,
  89. TAIKO_IRQ_MBHC_INSERTION,
  90. TAIKO_IRQ_BG_PRECHARGE,
  91. TAIKO_IRQ_PA1_STARTUP,
  92. TAIKO_IRQ_PA2_STARTUP,
  93. TAIKO_IRQ_PA3_STARTUP,
  94. TAIKO_IRQ_PA4_STARTUP,
  95. TAIKO_IRQ_PA5_STARTUP,
  96. TAIKO_IRQ_MICBIAS1_PRECHARGE,
  97. TAIKO_IRQ_MICBIAS2_PRECHARGE,
  98. TAIKO_IRQ_MICBIAS3_PRECHARGE,
  99. TAIKO_IRQ_HPH_PA_OCPL_FAULT,
  100. TAIKO_IRQ_HPH_PA_OCPR_FAULT,
  101. TAIKO_IRQ_EAR_PA_OCPL_FAULT,
  102. TAIKO_IRQ_HPH_L_PA_STARTUP,
  103. TAIKO_IRQ_HPH_R_PA_STARTUP,
  104. TAIKO_IRQ_EAR_PA_STARTUP,
  105. TAIKO_NUM_IRQS,
  106. };
  107. enum wcd9xxx_pm_state {
  108. WCD9XXX_PM_SLEEPABLE,
  109. WCD9XXX_PM_AWAKE,
  110. WCD9XXX_PM_ASLEEP,
  111. };
  112. struct wcd9xxx {
  113. struct device *dev;
  114. struct slim_device *slim;
  115. struct slim_device *slim_slave;
  116. struct mutex io_lock;
  117. struct mutex xfer_lock;
  118. struct mutex irq_lock;
  119. struct mutex nested_irq_lock;
  120. u8 version;
  121. unsigned int irq_base;
  122. unsigned int irq;
  123. u8 irq_masks_cur[WCD9XXX_NUM_IRQ_REGS];
  124. u8 irq_masks_cache[WCD9XXX_NUM_IRQ_REGS];
  125. u8 irq_level[WCD9XXX_NUM_IRQ_REGS];
  126. int reset_gpio;
  127. int (*read_dev)(struct wcd9xxx *wcd9xxx, unsigned short reg,
  128. int bytes, void *dest, bool interface_reg);
  129. int (*write_dev)(struct wcd9xxx *wcd9xxx, unsigned short reg,
  130. int bytes, void *src, bool interface_reg);
  131. u32 num_of_supplies;
  132. struct regulator_bulk_data *supplies;
  133. enum wcd9xxx_pm_state pm_state;
  134. struct mutex pm_lock;
  135. /* pm_wq notifies change of pm_state */
  136. wait_queue_head_t pm_wq;
  137. struct pm_qos_request pm_qos_req;
  138. int wlock_holders;
  139. int num_rx_port;
  140. int num_tx_port;
  141. u8 idbyte[4];
  142. };
  143. int wcd9xxx_reg_read(struct wcd9xxx *wcd9xxx, unsigned short reg);
  144. int wcd9xxx_reg_write(struct wcd9xxx *wcd9xxx, unsigned short reg,
  145. u8 val);
  146. int wcd9xxx_interface_reg_read(struct wcd9xxx *wcd9xxx, unsigned short reg);
  147. int wcd9xxx_interface_reg_write(struct wcd9xxx *wcd9xxx, unsigned short reg,
  148. u8 val);
  149. int wcd9xxx_bulk_read(struct wcd9xxx *wcd9xxx, unsigned short reg,
  150. int count, u8 *buf);
  151. int wcd9xxx_bulk_write(struct wcd9xxx *wcd9xxx, unsigned short reg,
  152. int count, u8 *buf);
  153. int wcd9xxx_irq_init(struct wcd9xxx *wcd9xxx);
  154. void wcd9xxx_irq_exit(struct wcd9xxx *wcd9xxx);
  155. int wcd9xxx_get_logical_addresses(u8 *pgd_la, u8 *inf_la);
  156. int wcd9xxx_get_intf_type(void);
  157. bool wcd9xxx_lock_sleep(struct wcd9xxx *wcd9xxx);
  158. void wcd9xxx_unlock_sleep(struct wcd9xxx *wcd9xxx);
  159. void wcd9xxx_nested_irq_lock(struct wcd9xxx *wcd9xxx);
  160. void wcd9xxx_nested_irq_unlock(struct wcd9xxx *wcd9xxx);
  161. enum wcd9xxx_pm_state wcd9xxx_pm_cmpxchg(struct wcd9xxx *wcd9xxx,
  162. enum wcd9xxx_pm_state o,
  163. enum wcd9xxx_pm_state n);
  164. static inline int wcd9xxx_request_irq(struct wcd9xxx *wcd9xxx, int irq,
  165. irq_handler_t handler, const char *name,
  166. void *data)
  167. {
  168. if (!wcd9xxx->irq_base)
  169. return -EINVAL;
  170. return request_threaded_irq(wcd9xxx->irq_base + irq, NULL, handler,
  171. IRQF_TRIGGER_RISING, name,
  172. data);
  173. }
  174. static inline void wcd9xxx_free_irq(struct wcd9xxx *wcd9xxx,
  175. int irq, void *data)
  176. {
  177. if (!wcd9xxx->irq_base)
  178. return;
  179. free_irq(wcd9xxx->irq_base + irq, data);
  180. }
  181. static inline void wcd9xxx_enable_irq(struct wcd9xxx *wcd9xxx, int irq)
  182. {
  183. if (!wcd9xxx->irq_base)
  184. return;
  185. enable_irq(wcd9xxx->irq_base + irq);
  186. }
  187. static inline void wcd9xxx_disable_irq(struct wcd9xxx *wcd9xxx, int irq)
  188. {
  189. if (!wcd9xxx->irq_base)
  190. return;
  191. disable_irq_nosync(wcd9xxx->irq_base + irq);
  192. }
  193. static inline void wcd9xxx_disable_irq_sync(struct wcd9xxx *wcd9xxx, int irq)
  194. {
  195. if (!wcd9xxx->irq_base)
  196. return;
  197. disable_irq(wcd9xxx->irq_base + irq);
  198. }
  199. #endif