sound.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. * start_beep() - Start beeping (optional)
  64. *
  65. * This tells the sound hardware to start a beep. It will continue until
  66. * stopped by sound_stop_beep().
  67. *
  68. * @dev: Sound device
  69. * @frequency_hz: Beep frequency in hertz
  70. * @return if OK, -ENOSYS if not supported, -ve on error
  71. */
  72. int (*start_beep)(struct udevice *dev, int frequency_hz);
  73. /**
  74. * stop_beep() - Stop beeping (optional)
  75. *
  76. * This tells the sound hardware to stop a previously started beep.
  77. *
  78. * @dev: Sound device
  79. * @return if OK, -ve on error
  80. */
  81. int (*stop_beep)(struct udevice *dev);
  82. };
  83. #define sound_get_ops(dev) ((struct sound_ops *)(dev)->driver->ops)
  84. /**
  85. * setup() - Set up to play a sound
  86. */
  87. int sound_setup(struct udevice *dev);
  88. /**
  89. * play() - Play a beep
  90. *
  91. * @dev: Sound device
  92. * @msecs: Duration of beep in milliseconds
  93. * @frequency_hz: Frequency of the beep in Hertz
  94. * @return 0 if OK, -ve on error
  95. */
  96. int sound_beep(struct udevice *dev, int msecs, int frequency_hz);
  97. /**
  98. * sound_start_beep() - Start beeping
  99. *
  100. * This tells the sound hardware to start a beep. It will continue until stopped
  101. * by sound_stop_beep().
  102. *
  103. * @dev: Sound device
  104. * @frequency_hz: Beep frequency in hertz
  105. * @return if OK, -ve on error
  106. */
  107. int sound_start_beep(struct udevice *dev, int frequency_hz);
  108. /**
  109. * sound_stop_beep() - Stop beeping
  110. *
  111. * This tells the sound hardware to stop a previously started beep.
  112. *
  113. * @dev: Sound device
  114. * @return if OK, -ve on error
  115. */
  116. int sound_stop_beep(struct udevice *dev);
  117. /**
  118. * sound_find_codec_i2s() - Called by sound drivers to locate codec and i2s
  119. *
  120. * This finds the audio codec and i2s devices and puts them in the uclass's
  121. * private data for this device.
  122. */
  123. int sound_find_codec_i2s(struct udevice *dev);
  124. #endif /* __SOUND__H__ */