soc-jack.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* SPDX-License-Identifier: GPL-2.0
  2. *
  3. * soc-jack.h
  4. *
  5. * Copyright (C) 2019 Renesas Electronics Corp.
  6. * Kuninori Morimoto <[email protected]>
  7. */
  8. #ifndef __SOC_JACK_H
  9. #define __SOC_JACK_H
  10. /**
  11. * struct snd_soc_jack_pin - Describes a pin to update based on jack detection
  12. *
  13. * @pin: name of the pin to update
  14. * @mask: bits to check for in reported jack status
  15. * @invert: if non-zero then pin is enabled when status is not reported
  16. * @list: internal list entry
  17. */
  18. struct snd_soc_jack_pin {
  19. struct list_head list;
  20. const char *pin;
  21. int mask;
  22. bool invert;
  23. };
  24. /**
  25. * struct snd_soc_jack_zone - Describes voltage zones of jack detection
  26. *
  27. * @min_mv: start voltage in mv
  28. * @max_mv: end voltage in mv
  29. * @jack_type: type of jack that is expected for this voltage
  30. * @debounce_time: debounce_time for jack, codec driver should wait for this
  31. * duration before reading the adc for voltages
  32. * @list: internal list entry
  33. */
  34. struct snd_soc_jack_zone {
  35. unsigned int min_mv;
  36. unsigned int max_mv;
  37. unsigned int jack_type;
  38. unsigned int debounce_time;
  39. struct list_head list;
  40. };
  41. /**
  42. * struct snd_soc_jack_gpio - Describes a gpio pin for jack detection
  43. *
  44. * @gpio: legacy gpio number
  45. * @idx: gpio descriptor index within the function of the GPIO
  46. * consumer device
  47. * @gpiod_dev: GPIO consumer device
  48. * @name: gpio name. Also as connection ID for the GPIO consumer
  49. * device function name lookup
  50. * @report: value to report when jack detected
  51. * @invert: report presence in low state
  52. * @debounce_time: debounce time in ms
  53. * @wake: enable as wake source
  54. * @jack_status_check: callback function which overrides the detection
  55. * to provide more complex checks (eg, reading an
  56. * ADC).
  57. */
  58. struct snd_soc_jack_gpio {
  59. unsigned int gpio;
  60. unsigned int idx;
  61. struct device *gpiod_dev;
  62. const char *name;
  63. int report;
  64. int invert;
  65. int debounce_time;
  66. bool wake;
  67. /* private: */
  68. struct snd_soc_jack *jack;
  69. struct delayed_work work;
  70. struct notifier_block pm_notifier;
  71. struct gpio_desc *desc;
  72. void *data;
  73. /* public: */
  74. int (*jack_status_check)(void *data);
  75. };
  76. struct snd_soc_jack {
  77. struct mutex mutex;
  78. struct snd_jack *jack;
  79. struct snd_soc_card *card;
  80. struct list_head pins;
  81. int status;
  82. struct blocking_notifier_head notifier;
  83. struct list_head jack_zones;
  84. };
  85. /* Jack reporting */
  86. void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask);
  87. int snd_soc_jack_add_pins(struct snd_soc_jack *jack, int count,
  88. struct snd_soc_jack_pin *pins);
  89. void snd_soc_jack_notifier_register(struct snd_soc_jack *jack,
  90. struct notifier_block *nb);
  91. void snd_soc_jack_notifier_unregister(struct snd_soc_jack *jack,
  92. struct notifier_block *nb);
  93. int snd_soc_jack_add_zones(struct snd_soc_jack *jack, int count,
  94. struct snd_soc_jack_zone *zones);
  95. int snd_soc_jack_get_type(struct snd_soc_jack *jack, int micbias_voltage);
  96. #ifdef CONFIG_GPIOLIB
  97. int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
  98. struct snd_soc_jack_gpio *gpios);
  99. int snd_soc_jack_add_gpiods(struct device *gpiod_dev,
  100. struct snd_soc_jack *jack,
  101. int count, struct snd_soc_jack_gpio *gpios);
  102. void snd_soc_jack_free_gpios(struct snd_soc_jack *jack, int count,
  103. struct snd_soc_jack_gpio *gpios);
  104. #else
  105. static inline int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
  106. struct snd_soc_jack_gpio *gpios)
  107. {
  108. return 0;
  109. }
  110. static inline int snd_soc_jack_add_gpiods(struct device *gpiod_dev,
  111. struct snd_soc_jack *jack,
  112. int count,
  113. struct snd_soc_jack_gpio *gpios)
  114. {
  115. return 0;
  116. }
  117. static inline void snd_soc_jack_free_gpios(struct snd_soc_jack *jack, int count,
  118. struct snd_soc_jack_gpio *gpios)
  119. {
  120. }
  121. #endif
  122. #endif /* __SOC_JACK_H */