hda_component.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * HD audio Component Binding Interface
  4. *
  5. * Copyright (C) 2021 Cirrus Logic, Inc. and
  6. * Cirrus Logic International Semiconductor Ltd.
  7. */
  8. #ifndef __HDA_COMPONENT_H__
  9. #define __HDA_COMPONENT_H__
  10. #include <linux/acpi.h>
  11. #include <linux/component.h>
  12. #include <linux/mutex.h>
  13. #include <sound/hda_codec.h>
  14. #define HDA_MAX_COMPONENTS 4
  15. #define HDA_MAX_NAME_SIZE 50
  16. struct hda_component {
  17. struct device *dev;
  18. char name[HDA_MAX_NAME_SIZE];
  19. struct acpi_device *adev;
  20. bool acpi_notifications_supported;
  21. void (*acpi_notify)(acpi_handle handle, u32 event, struct device *dev);
  22. void (*pre_playback_hook)(struct device *dev, int action);
  23. void (*playback_hook)(struct device *dev, int action);
  24. void (*post_playback_hook)(struct device *dev, int action);
  25. };
  26. struct hda_component_parent {
  27. struct mutex mutex;
  28. struct hda_codec *codec;
  29. struct hda_component comps[HDA_MAX_COMPONENTS];
  30. };
  31. #ifdef CONFIG_ACPI
  32. void hda_component_acpi_device_notify(struct hda_component_parent *parent,
  33. acpi_handle handle, u32 event, void *data);
  34. int hda_component_manager_bind_acpi_notifications(struct hda_codec *cdc,
  35. struct hda_component_parent *parent,
  36. acpi_notify_handler handler, void *data);
  37. void hda_component_manager_unbind_acpi_notifications(struct hda_codec *cdc,
  38. struct hda_component_parent *parent,
  39. acpi_notify_handler handler);
  40. #else
  41. static inline void hda_component_acpi_device_notify(struct hda_component_parent *parent,
  42. acpi_handle handle,
  43. u32 event,
  44. void *data)
  45. {
  46. }
  47. static inline int hda_component_manager_bind_acpi_notifications(struct hda_codec *cdc,
  48. struct hda_component_parent *parent,
  49. acpi_notify_handler handler,
  50. void *data)
  51. {
  52. return 0;
  53. }
  54. static inline void hda_component_manager_unbind_acpi_notifications(struct hda_codec *cdc,
  55. struct hda_component_parent *parent,
  56. acpi_notify_handler handler)
  57. {
  58. }
  59. #endif /* ifdef CONFIG_ACPI */
  60. void hda_component_manager_playback_hook(struct hda_component_parent *parent, int action);
  61. int hda_component_manager_init(struct hda_codec *cdc,
  62. struct hda_component_parent *parent, int count,
  63. const char *bus, const char *hid,
  64. const char *match_str,
  65. const struct component_master_ops *ops);
  66. void hda_component_manager_free(struct hda_component_parent *parent,
  67. const struct component_master_ops *ops);
  68. int hda_component_manager_bind(struct hda_codec *cdc, struct hda_component_parent *parent);
  69. static inline struct hda_component *hda_component_from_index(struct hda_component_parent *parent,
  70. int index)
  71. {
  72. if (!parent)
  73. return NULL;
  74. if (index < 0 || index >= ARRAY_SIZE(parent->comps))
  75. return NULL;
  76. return &parent->comps[index];
  77. }
  78. static inline void hda_component_manager_unbind(struct hda_codec *cdc,
  79. struct hda_component_parent *parent)
  80. {
  81. mutex_lock(&parent->mutex);
  82. component_unbind_all(hda_codec_dev(cdc), parent);
  83. mutex_unlock(&parent->mutex);
  84. }
  85. #endif /* ifndef __HDA_COMPONENT_H__ */