]> git.ipfire.org Git - thirdparty/u-boot.git/blame - include/sound.h
ARC: dwmmc: Adding DesignWare MMC driver support for ARC devboards
[thirdparty/u-boot.git] / include / sound.h
CommitLineData
83d290c5 1/* SPDX-License-Identifier: GPL-2.0+ */
511ed5fd
RS
2/*
3 * Copyright (C) 2012 Samsung Electronics
4 * R. Chandrasekar < rcsekar@samsung.com>
511ed5fd
RS
5 */
6
7#ifndef __SOUND_H__
8#define __SOUND_H__
9
511ed5fd
RS
10/* sound codec enum */
11enum sound_compat {
12 AUDIO_COMPAT_SPI,
13 AUDIO_COMPAT_I2C,
14};
15
16/* Codec information structure to store the info from device tree */
17struct sound_codec_info {
18 int i2c_bus;
19 int i2c_dev_addr;
511ed5fd
RS
20};
21
d4901898
SG
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 */
31struct sound_uc_priv {
32 struct udevice *codec;
33 struct udevice *i2s;
34 int setup_done;
35};
36
37/**
a77bf709
SG
38 * Generates square wave sound data for 1 second
39 *
f987177d
SG
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
a77bf709 45 */
7d92b060 46void sound_create_square_wave(uint sample_rate, unsigned short *data, int size,
f987177d 47 uint freq, uint channels);
a77bf709 48
d4901898
SG
49/*
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 */
55struct sound_ops {
56 /**
e65f9ef9 57 * setup() - Set up to play a sound (optional)
d4901898
SG
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);
28502669
SG
70
71 /**
72 * start_beep() - Start beeping (optional)
73 *
74 * This tells the sound hardware to start a beep. It will continue until
75 * stopped by sound_stop_beep().
76 *
77 * @dev: Sound device
78 * @frequency_hz: Beep frequency in hertz
79 * @return if OK, -ENOSYS if not supported, -ve on error
80 */
81 int (*start_beep)(struct udevice *dev, int frequency_hz);
82
83 /**
84 * stop_beep() - Stop beeping (optional)
85 *
86 * This tells the sound hardware to stop a previously started beep.
87 *
88 * @dev: Sound device
89 * @return if OK, -ve on error
90 */
91 int (*stop_beep)(struct udevice *dev);
d4901898
SG
92};
93
94#define sound_get_ops(dev) ((struct sound_ops *)(dev)->driver->ops)
95
96/**
97 * setup() - Set up to play a sound
98 */
99int sound_setup(struct udevice *dev);
100
101/**
102 * play() - Play a beep
103 *
104 * @dev: Sound device
105 * @msecs: Duration of beep in milliseconds
106 * @frequency_hz: Frequency of the beep in Hertz
107 * @return 0 if OK, -ve on error
108 */
109int sound_beep(struct udevice *dev, int msecs, int frequency_hz);
110
28502669
SG
111/**
112 * sound_start_beep() - Start beeping
113 *
114 * This tells the sound hardware to start a beep. It will continue until stopped
115 * by sound_stop_beep().
116 *
117 * @dev: Sound device
118 * @frequency_hz: Beep frequency in hertz
119 * @return if OK, -ve on error
120 */
121int sound_start_beep(struct udevice *dev, int frequency_hz);
122
123/**
124 * sound_stop_beep() - Stop beeping
125 *
126 * This tells the sound hardware to stop a previously started beep.
127 *
128 * @dev: Sound device
129 * @return if OK, -ve on error
130 */
131int sound_stop_beep(struct udevice *dev);
132
d4901898
SG
133/**
134 * sound_find_codec_i2s() - Called by sound drivers to locate codec and i2s
135 *
136 * This finds the audio codec and i2s devices and puts them in the uclass's
137 * private data for this device.
138 */
139int sound_find_codec_i2s(struct udevice *dev);
140
511ed5fd 141#endif /* __SOUND__H__ */