soc-usb.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* SPDX-License-Identifier: GPL-2.0
  2. *
  3. * Copyright (c) 2022-2025 Qualcomm Innovation Center, Inc. All rights reserved.
  4. */
  5. #ifndef __LINUX_SND_SOC_USB_H
  6. #define __LINUX_SND_SOC_USB_H
  7. #include <sound/soc.h>
  8. enum snd_soc_usb_kctl {
  9. SND_SOC_USB_KCTL_CARD_ROUTE,
  10. SND_SOC_USB_KCTL_PCM_ROUTE,
  11. };
  12. /**
  13. * struct snd_soc_usb_device - SoC USB representation of a USB sound device
  14. * @card_idx: sound card index associated with USB device
  15. * @chip_idx: USB sound chip array index
  16. * @cpcm_idx: capture PCM index array associated with USB device
  17. * @ppcm_idx: playback PCM index array associated with USB device
  18. * @num_capture: number of capture streams
  19. * @num_playback: number of playback streams
  20. * @list: list head for SoC USB devices
  21. **/
  22. struct snd_soc_usb_device {
  23. int card_idx;
  24. int chip_idx;
  25. /* PCM index arrays */
  26. unsigned int *cpcm_idx; /* TODO: capture path is not tested yet */
  27. unsigned int *ppcm_idx;
  28. int num_capture; /* TODO: capture path is not tested yet */
  29. int num_playback;
  30. struct list_head list;
  31. };
  32. /**
  33. * struct snd_soc_usb - representation of a SoC USB backend entity
  34. * @list: list head for SND SOC struct list
  35. * @component: reference to ASoC component
  36. * @connection_status_cb: callback to notify connection events
  37. * @update_offload_route_info: callback to fetch mapped ASoC card and pcm
  38. * device pair. This is unrelated to the concept
  39. * of DAPM route. The "route" argument carries
  40. * an array used for a kcontrol output for either
  41. * the card or pcm index. "path" determines the
  42. * which entry to look for. (ie mapped card or pcm)
  43. * @priv_data: driver data
  44. **/
  45. struct snd_soc_usb {
  46. struct list_head list;
  47. struct snd_soc_component *component;
  48. int (*connection_status_cb)(struct snd_soc_usb *usb,
  49. struct snd_soc_usb_device *sdev,
  50. bool connected);
  51. int (*update_offload_route_info)(struct snd_soc_component *component,
  52. int card, int pcm, int direction,
  53. enum snd_soc_usb_kctl path,
  54. long *route);
  55. void *priv_data;
  56. };
  57. #if IS_ENABLED(CONFIG_SND_SOC_USB)
  58. int snd_soc_usb_find_supported_format(int card_idx,
  59. struct snd_pcm_hw_params *params,
  60. int direction);
  61. int snd_soc_usb_connect(struct device *usbdev, struct snd_soc_usb_device *sdev);
  62. int snd_soc_usb_disconnect(struct device *usbdev, struct snd_soc_usb_device *sdev);
  63. void *snd_soc_usb_find_priv_data(struct device *usbdev);
  64. int snd_soc_usb_setup_offload_jack(struct snd_soc_component *component,
  65. struct snd_soc_jack *jack);
  66. int snd_soc_usb_update_offload_route(struct device *dev, int card, int pcm,
  67. int direction, enum snd_soc_usb_kctl path,
  68. long *route);
  69. struct snd_soc_usb *snd_soc_usb_allocate_port(struct snd_soc_component *component,
  70. void *data);
  71. void snd_soc_usb_free_port(struct snd_soc_usb *usb);
  72. void snd_soc_usb_add_port(struct snd_soc_usb *usb);
  73. void snd_soc_usb_remove_port(struct snd_soc_usb *usb);
  74. #else
  75. static inline int
  76. snd_soc_usb_find_supported_format(int card_idx, struct snd_pcm_hw_params *params,
  77. int direction)
  78. {
  79. return -EINVAL;
  80. }
  81. static inline int snd_soc_usb_connect(struct device *usbdev,
  82. struct snd_soc_usb_device *sdev)
  83. {
  84. return -ENODEV;
  85. }
  86. static inline int snd_soc_usb_disconnect(struct device *usbdev,
  87. struct snd_soc_usb_device *sdev)
  88. {
  89. return -EINVAL;
  90. }
  91. static inline void *snd_soc_usb_find_priv_data(struct device *usbdev)
  92. {
  93. return NULL;
  94. }
  95. static inline int snd_soc_usb_setup_offload_jack(struct snd_soc_component *component,
  96. struct snd_soc_jack *jack)
  97. {
  98. return 0;
  99. }
  100. static int snd_soc_usb_update_offload_route(struct device *dev, int card, int pcm,
  101. int direction, enum snd_soc_usb_kctl path,
  102. long *route)
  103. {
  104. return -ENODEV;
  105. }
  106. static inline struct snd_soc_usb *
  107. snd_soc_usb_allocate_port(struct snd_soc_component *component, void *data)
  108. {
  109. return ERR_PTR(-ENOMEM);
  110. }
  111. static inline void snd_soc_usb_free_port(struct snd_soc_usb *usb)
  112. { }
  113. static inline void snd_soc_usb_add_port(struct snd_soc_usb *usb)
  114. { }
  115. static inline void snd_soc_usb_remove_port(struct snd_soc_usb *usb)
  116. { }
  117. #endif /* IS_ENABLED(CONFIG_SND_SOC_USB) */
  118. #endif /*__LINUX_SND_SOC_USB_H */