sound.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (C) 2012 Samsung Electronics
  4. * R. Chandrasekar < rcsekar@samsung.com>
  5. */
  6. #ifndef __SOUND_H__
  7. #define __SOUND_H__
  8. /* sound codec enum */
  9. enum sound_compat {
  10. AUDIO_COMPAT_SPI,
  11. AUDIO_COMPAT_I2C,
  12. };
  13. /* Codec information structure to store the info from device tree */
  14. struct sound_codec_info {
  15. int i2c_bus;
  16. int i2c_dev_addr;
  17. };
  18. /**
  19. * struct sound_uc_priv - private uclass information about each sound device
  20. *
  21. * This is used to line the codec and i2s together
  22. *
  23. * @codec: Codec that is used for this sound device
  24. * @i2s: I2S bus that is used for this sound device
  25. * @setup_done: true if setup() has been called
  26. */
  27. struct sound_uc_priv {
  28. struct udevice *codec;
  29. struct udevice *i2s;
  30. int setup_done;
  31. };
  32. /**
  33. * Generates square wave sound data for 1 second
  34. *
  35. * @sample_rate: Sample rate in Hz
  36. * @data: data buffer pointer
  37. * @size: size of the buffer in bytes
  38. * @freq: frequency of the wave
  39. * @channels: Number of channels to use
  40. */
  41. void sound_create_square_wave(uint sample_rate, unsigned short *data, int size,
  42. uint freq, uint channels);
  43. /*
  44. * The sound uclass brings together a data transport (currently only I2C) and a
  45. * codec (currently connected over I2C).
  46. */
  47. /* Operations for sound */
  48. struct sound_ops {
  49. /**
  50. * setup() - Set up to play a sound (optional)
  51. */
  52. int (*setup)(struct udevice *dev);
  53. /**
  54. * play() - Play a beep
  55. *
  56. * @dev: Sound device
  57. * @data: Data buffer to play
  58. * @data_size: Size of data buffer in bytes
  59. * @return 0 if OK, -ve on error
  60. */
  61. int (*play)(struct udevice *dev, void *data, uint data_size);
  62. /**
  63. * stop_play() - Indicate that there is no more data coming
  64. *
  65. * This is called once play() has finished sending all the data to the
  66. * output device. This may be used to tell the hardware to turn off the
  67. * codec, for example.
  68. *
  69. * @dev: Sound device
  70. * @return 0 if OK, -ve on error
  71. */
  72. int (*stop_play)(struct udevice *dev);
  73. /**
  74. * start_beep() - Start beeping (optional)
  75. *
  76. * This tells the sound hardware to start a beep. It will continue until
  77. * stopped by sound_stop_beep().
  78. *
  79. * @dev: Sound device
  80. * @frequency_hz: Beep frequency in hertz
  81. * @return if OK, -ENOSYS if not supported, -ve on error
  82. */
  83. int (*start_beep)(struct udevice *dev, int frequency_hz);
  84. /**
  85. * stop_beep() - Stop beeping (optional)
  86. *
  87. * This tells the sound hardware to stop a previously started beep.
  88. *
  89. * @dev: Sound device
  90. * @return if OK, -ve on error
  91. */
  92. int (*stop_beep)(struct udevice *dev);
  93. };
  94. #define sound_get_ops(dev) ((struct sound_ops *)(dev)->driver->ops)
  95. /**
  96. * setup() - Set up to play a sound
  97. */
  98. int sound_setup(struct udevice *dev);
  99. /**
  100. * play() - Play a beep
  101. *
  102. * @dev: Sound device
  103. * @msecs: Duration of beep in milliseconds
  104. * @frequency_hz: Frequency of the beep in Hertz
  105. * @return 0 if OK, -ve on error
  106. */
  107. int sound_beep(struct udevice *dev, int msecs, int frequency_hz);
  108. /**
  109. * sound_start_beep() - Start beeping
  110. *
  111. * This tells the sound hardware to start a beep. It will continue until stopped
  112. * by sound_stop_beep().
  113. *
  114. * @dev: Sound device
  115. * @frequency_hz: Beep frequency in hertz
  116. * @return if OK, -ve on error
  117. */
  118. int sound_start_beep(struct udevice *dev, int frequency_hz);
  119. /**
  120. * sound_stop_beep() - Stop beeping
  121. *
  122. * This tells the sound hardware to stop a previously started beep.
  123. *
  124. * @dev: Sound device
  125. * @return if OK, -ve on error
  126. */
  127. int sound_stop_beep(struct udevice *dev);
  128. /**
  129. * sound_find_codec_i2s() - Called by sound drivers to locate codec and i2s
  130. *
  131. * This finds the audio codec and i2s devices and puts them in the uclass's
  132. * private data for this device.
  133. */
  134. int sound_find_codec_i2s(struct udevice *dev);
  135. #endif /* __SOUND__H__ */