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