blob: 7d528c479efb1cab041981a9c157ea8ad0375aae [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Rajeshwari Shinde836a66c2012-10-25 19:49:22 +00002/*
3 * Copyright (C) 2012 Samsung Electronics
4 * R. Chandrasekar < rcsekar@samsung.com>
Rajeshwari Shinde836a66c2012-10-25 19:49:22 +00005 */
6
7#ifndef __SOUND_H__
8#define __SOUND_H__
9
10/* sound codec enum */
Rajeshwari Shinde836a66c2012-10-25 19:49:22 +000011enum 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;
Rajeshwari Shinde836a66c2012-10-25 19:49:22 +000020};
21
Simon Glass76072ac2018-12-10 10:37:36 -070022/**
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/**
Simon Glass59c021e2014-02-27 13:26:20 -070038 * Generates square wave sound data for 1 second
39 *
Simon Glass51aa8602018-12-10 10:37:51 -070040 * @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 Glass59c021e2014-02-27 13:26:20 -070045 */
Simon Glassddad0322018-11-15 19:56:13 -070046void sound_create_square_wave(uint sample_rate, unsigned short *data, int size,
Simon Glass51aa8602018-12-10 10:37:51 -070047 uint freq, uint channels);
Simon Glass59c021e2014-02-27 13:26:20 -070048
49/*
Simon Glass76072ac2018-12-10 10:37:36 -070050 * 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 /**
Simon Glass7dfe5272019-02-16 20:24:53 -070057 * setup() - Set up to play a sound (optional)
Simon Glass76072ac2018-12-10 10:37:36 -070058 */
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);
70};
71
72#define sound_get_ops(dev) ((struct sound_ops *)(dev)->driver->ops)
73
74/**
75 * setup() - Set up to play a sound
76 */
77int sound_setup(struct udevice *dev);
78
79/**
80 * play() - Play a beep
81 *
82 * @dev: Sound device
83 * @msecs: Duration of beep in milliseconds
84 * @frequency_hz: Frequency of the beep in Hertz
85 * @return 0 if OK, -ve on error
86 */
87int sound_beep(struct udevice *dev, int msecs, int frequency_hz);
88
89/**
90 * sound_find_codec_i2s() - Called by sound drivers to locate codec and i2s
91 *
92 * This finds the audio codec and i2s devices and puts them in the uclass's
93 * private data for this device.
94 */
95int sound_find_codec_i2s(struct udevice *dev);
96
Rajeshwari Shinde836a66c2012-10-25 19:49:22 +000097#endif /* __SOUND__H__ */