core.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * include/linux/mfd/wm8994/core.h -- Core interface for WM8994
  3. *
  4. * Copyright 2009 Wolfson Microelectronics PLC.
  5. *
  6. * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. */
  14. #ifndef __MFD_WM8994_CORE_H__
  15. #define __MFD_WM8994_CORE_H__
  16. #include <linux/mutex.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/regmap.h>
  19. #include <linux/mfd/wm8994/pdata.h>
  20. enum wm8994_type {
  21. WM8994 = 0,
  22. WM8958 = 1,
  23. WM1811 = 2,
  24. };
  25. struct regulator_dev;
  26. struct regulator_bulk_data;
  27. struct irq_domain;
  28. #define WM8994_NUM_GPIO_REGS 11
  29. #define WM8994_NUM_LDO_REGS 2
  30. #define WM8994_NUM_IRQ_REGS 2
  31. #define WM8994_IRQ_TEMP_SHUT 0
  32. #define WM8994_IRQ_MIC1_DET 1
  33. #define WM8994_IRQ_MIC1_SHRT 2
  34. #define WM8994_IRQ_MIC2_DET 3
  35. #define WM8994_IRQ_MIC2_SHRT 4
  36. #define WM8994_IRQ_FLL1_LOCK 5
  37. #define WM8994_IRQ_FLL2_LOCK 6
  38. #define WM8994_IRQ_SRC1_LOCK 7
  39. #define WM8994_IRQ_SRC2_LOCK 8
  40. #define WM8994_IRQ_AIF1DRC1_SIG_DET 9
  41. #define WM8994_IRQ_AIF1DRC2_SIG_DET 10
  42. #define WM8994_IRQ_AIF2DRC_SIG_DET 11
  43. #define WM8994_IRQ_FIFOS_ERR 12
  44. #define WM8994_IRQ_WSEQ_DONE 13
  45. #define WM8994_IRQ_DCS_DONE 14
  46. #define WM8994_IRQ_TEMP_WARN 15
  47. /* GPIOs in the chip are numbered from 1-11 */
  48. #define WM8994_IRQ_GPIO(x) (x + WM8994_IRQ_TEMP_WARN)
  49. struct wm8994 {
  50. struct wm8994_pdata pdata;
  51. enum wm8994_type type;
  52. int revision;
  53. int cust_id;
  54. struct device *dev;
  55. struct regmap *regmap;
  56. bool ldo_ena_always_driven;
  57. int gpio_base;
  58. int irq_base;
  59. int irq;
  60. struct regmap_irq_chip_data *irq_data;
  61. struct irq_domain *edge_irq;
  62. /* Used over suspend/resume */
  63. bool suspended;
  64. struct regulator_dev *dbvdd;
  65. int num_supplies;
  66. struct regulator_bulk_data *supplies;
  67. };
  68. /* Device I/O API */
  69. static inline int wm8994_reg_read(struct wm8994 *wm8994, unsigned short reg)
  70. {
  71. unsigned int val;
  72. int ret;
  73. ret = regmap_read(wm8994->regmap, reg, &val);
  74. if (ret < 0)
  75. return ret;
  76. else
  77. return val;
  78. }
  79. static inline int wm8994_reg_write(struct wm8994 *wm8994, unsigned short reg,
  80. unsigned short val)
  81. {
  82. return regmap_write(wm8994->regmap, reg, val);
  83. }
  84. static inline int wm8994_bulk_read(struct wm8994 *wm8994, unsigned short reg,
  85. int count, u16 *buf)
  86. {
  87. return regmap_bulk_read(wm8994->regmap, reg, buf, count);
  88. }
  89. static inline int wm8994_bulk_write(struct wm8994 *wm8994, unsigned short reg,
  90. int count, const u16 *buf)
  91. {
  92. return regmap_raw_write(wm8994->regmap, reg, buf, count * sizeof(u16));
  93. }
  94. static inline int wm8994_set_bits(struct wm8994 *wm8994, unsigned short reg,
  95. unsigned short mask, unsigned short val)
  96. {
  97. return regmap_update_bits(wm8994->regmap, reg, mask, val);
  98. }
  99. /* Helper to save on boilerplate */
  100. static inline int wm8994_request_irq(struct wm8994 *wm8994, int irq,
  101. irq_handler_t handler, const char *name,
  102. void *data)
  103. {
  104. if (!wm8994->irq_data)
  105. return -EINVAL;
  106. return request_threaded_irq(regmap_irq_get_virq(wm8994->irq_data, irq),
  107. NULL, handler, IRQF_TRIGGER_RISING, name,
  108. data);
  109. }
  110. static inline void wm8994_free_irq(struct wm8994 *wm8994, int irq, void *data)
  111. {
  112. if (!wm8994->irq_data)
  113. return;
  114. free_irq(regmap_irq_get_virq(wm8994->irq_data, irq), data);
  115. }
  116. int wm8994_irq_init(struct wm8994 *wm8994);
  117. void wm8994_irq_exit(struct wm8994 *wm8994);
  118. #endif