core.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. enum wm8994_type {
  19. WM8994 = 0,
  20. WM8958 = 1,
  21. WM1811 = 2,
  22. };
  23. struct regulator_dev;
  24. struct regulator_bulk_data;
  25. struct regmap;
  26. #define WM8994_NUM_GPIO_REGS 11
  27. #define WM8994_NUM_LDO_REGS 2
  28. #define WM8994_NUM_IRQ_REGS 2
  29. #define WM8994_IRQ_TEMP_SHUT 0
  30. #define WM8994_IRQ_MIC1_DET 1
  31. #define WM8994_IRQ_MIC1_SHRT 2
  32. #define WM8994_IRQ_MIC2_DET 3
  33. #define WM8994_IRQ_MIC2_SHRT 4
  34. #define WM8994_IRQ_FLL1_LOCK 5
  35. #define WM8994_IRQ_FLL2_LOCK 6
  36. #define WM8994_IRQ_SRC1_LOCK 7
  37. #define WM8994_IRQ_SRC2_LOCK 8
  38. #define WM8994_IRQ_AIF1DRC1_SIG_DET 9
  39. #define WM8994_IRQ_AIF1DRC2_SIG_DET 10
  40. #define WM8994_IRQ_AIF2DRC_SIG_DET 11
  41. #define WM8994_IRQ_FIFOS_ERR 12
  42. #define WM8994_IRQ_WSEQ_DONE 13
  43. #define WM8994_IRQ_DCS_DONE 14
  44. #define WM8994_IRQ_TEMP_WARN 15
  45. /* GPIOs in the chip are numbered from 1-11 */
  46. #define WM8994_IRQ_GPIO(x) (x + WM8994_IRQ_TEMP_WARN)
  47. struct wm8994 {
  48. struct mutex irq_lock;
  49. enum wm8994_type type;
  50. struct device *dev;
  51. struct regmap *regmap;
  52. bool ldo_ena_always_driven;
  53. int gpio_base;
  54. int irq_base;
  55. int irq;
  56. u16 irq_masks_cur[WM8994_NUM_IRQ_REGS];
  57. u16 irq_masks_cache[WM8994_NUM_IRQ_REGS];
  58. /* Used over suspend/resume */
  59. bool suspended;
  60. u16 ldo_regs[WM8994_NUM_LDO_REGS];
  61. u16 gpio_regs[WM8994_NUM_GPIO_REGS];
  62. struct regulator_dev *dbvdd;
  63. int num_supplies;
  64. struct regulator_bulk_data *supplies;
  65. };
  66. /* Device I/O API */
  67. int wm8994_reg_read(struct wm8994 *wm8994, unsigned short reg);
  68. int wm8994_reg_write(struct wm8994 *wm8994, unsigned short reg,
  69. unsigned short val);
  70. int wm8994_set_bits(struct wm8994 *wm8994, unsigned short reg,
  71. unsigned short mask, unsigned short val);
  72. int wm8994_bulk_read(struct wm8994 *wm8994, unsigned short reg,
  73. int count, u16 *buf);
  74. int wm8994_bulk_write(struct wm8994 *wm8994, unsigned short reg,
  75. int count, const u16 *buf);
  76. /* Helper to save on boilerplate */
  77. static inline int wm8994_request_irq(struct wm8994 *wm8994, int irq,
  78. irq_handler_t handler, const char *name,
  79. void *data)
  80. {
  81. if (!wm8994->irq_base)
  82. return -EINVAL;
  83. return request_threaded_irq(wm8994->irq_base + irq, NULL, handler,
  84. IRQF_TRIGGER_RISING, name,
  85. data);
  86. }
  87. static inline void wm8994_free_irq(struct wm8994 *wm8994, int irq, void *data)
  88. {
  89. if (!wm8994->irq_base)
  90. return;
  91. free_irq(wm8994->irq_base + irq, data);
  92. }
  93. int wm8994_irq_init(struct wm8994 *wm8994);
  94. void wm8994_irq_exit(struct wm8994 *wm8994);
  95. #endif