]> Git Repo - J-u-boot.git/blame - include/sound.h
dm: sandbox: Allow selection of sample rate and channels
[J-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 < [email protected]>
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 *
7d92b060 40 * @param sample_rate Sample rate in Hz
a77bf709 41 * @param data data buffer pointer
d4901898 42 * @param size size of the buffer in bytes
a77bf709
SG
43 * @param freq frequency of the wave
44 */
7d92b060
SG
45void sound_create_square_wave(uint sample_rate, unsigned short *data, int size,
46 uint freq);
a77bf709 47
d4901898
SG
48/*
49 * The sound uclass brings together a data transport (currently only I2C) and a
50 * codec (currently connected over I2C).
51 */
52
53/* Operations for sound */
54struct sound_ops {
55 /**
56 * setup() - Set up to play a sound
57 */
58 int (*setup)(struct udevice *dev);
59
60 /**
61 * play() - Play a beep
62 *
63 * @dev: Sound device
64 * @data: Data buffer to play
65 * @data_size: Size of data buffer in bytes
66 * @return 0 if OK, -ve on error
67 */
68 int (*play)(struct udevice *dev, void *data, uint data_size);
69};
70
71#define sound_get_ops(dev) ((struct sound_ops *)(dev)->driver->ops)
72
73/**
74 * setup() - Set up to play a sound
75 */
76int sound_setup(struct udevice *dev);
77
78/**
79 * play() - Play a beep
80 *
81 * @dev: Sound device
82 * @msecs: Duration of beep in milliseconds
83 * @frequency_hz: Frequency of the beep in Hertz
84 * @return 0 if OK, -ve on error
85 */
86int sound_beep(struct udevice *dev, int msecs, int frequency_hz);
87
88/**
89 * sound_find_codec_i2s() - Called by sound drivers to locate codec and i2s
90 *
91 * This finds the audio codec and i2s devices and puts them in the uclass's
92 * private data for this device.
93 */
94int sound_find_codec_i2s(struct udevice *dev);
95
511ed5fd 96#endif /* __SOUND__H__ */
This page took 0.512654 seconds and 4 git commands to generate.