soc-jack.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* SPDX-License-Identifier: GPL-2.0
  2. *
  3. * soc-jack.h
  4. *
  5. * Copyright (C) 2019 Renesas Electronics Corp.
  6. * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
  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. * @idx: gpio descriptor index within the function of the GPIO
  45. * consumer device
  46. * @gpiod_dev: GPIO consumer device
  47. * @name: gpio name. Also as connection ID for the GPIO consumer
  48. * device function name lookup
  49. * @report: value to report when jack detected
  50. * @invert: report presence in low state
  51. * @debounce_time: debounce time in ms
  52. * @wake: enable as wake source
  53. * @jack_status_check: callback function which overrides the detection
  54. * to provide more complex checks (eg, reading an
  55. * ADC).
  56. */
  57. struct snd_soc_jack_gpio {
  58. unsigned int idx;
  59. struct device *gpiod_dev;
  60. const char *name;
  61. int report;
  62. int invert;
  63. int debounce_time;
  64. bool wake;
  65. /* private: */
  66. struct snd_soc_jack *jack;
  67. struct delayed_work work;
  68. struct notifier_block pm_notifier;
  69. struct gpio_desc *desc;
  70. void *data;
  71. /* public: */
  72. int (*jack_status_check)(void *data);
  73. };
  74. struct snd_soc_jack {
  75. struct mutex mutex;
  76. struct snd_jack *jack;
  77. struct snd_soc_card *card;
  78. struct list_head pins;
  79. int status;
  80. struct blocking_notifier_head notifier;
  81. struct list_head jack_zones;
  82. };
  83. /* Jack reporting */
  84. void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask);
  85. int snd_soc_jack_add_pins(struct snd_soc_jack *jack, int count,
  86. struct snd_soc_jack_pin *pins);
  87. void snd_soc_jack_notifier_register(struct snd_soc_jack *jack,
  88. struct notifier_block *nb);
  89. void snd_soc_jack_notifier_unregister(struct snd_soc_jack *jack,
  90. struct notifier_block *nb);
  91. int snd_soc_jack_add_zones(struct snd_soc_jack *jack, int count,
  92. struct snd_soc_jack_zone *zones);
  93. int snd_soc_jack_get_type(struct snd_soc_jack *jack, int micbias_voltage);
  94. #ifdef CONFIG_GPIOLIB
  95. int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
  96. struct snd_soc_jack_gpio *gpios);
  97. int snd_soc_jack_add_gpiods(struct device *gpiod_dev,
  98. struct snd_soc_jack *jack,
  99. int count, struct snd_soc_jack_gpio *gpios);
  100. void snd_soc_jack_free_gpios(struct snd_soc_jack *jack, int count,
  101. struct snd_soc_jack_gpio *gpios);
  102. #else
  103. static inline int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
  104. struct snd_soc_jack_gpio *gpios)
  105. {
  106. return 0;
  107. }
  108. static inline int snd_soc_jack_add_gpiods(struct device *gpiod_dev,
  109. struct snd_soc_jack *jack,
  110. int count,
  111. struct snd_soc_jack_gpio *gpios)
  112. {
  113. return 0;
  114. }
  115. static inline void snd_soc_jack_free_gpios(struct snd_soc_jack *jack, int count,
  116. struct snd_soc_jack_gpio *gpios)
  117. {
  118. }
  119. #endif
  120. #endif /* __SOC_JACK_H */