blob: c94d2c372657e4fd3fe7b4f6776df8a815ba0866 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Rajeshwari Shinde511ed5f2012-10-25 19:49:22 +00002/*
3 * Copyright (C) 2012 Samsung Electronics
4 * R. Chandrasekar < rcsekar@samsung.com>
Rajeshwari Shinde511ed5f2012-10-25 19:49:22 +00005 */
6
7#ifndef __SOUND_H__
8#define __SOUND_H__
9
10/* sound codec enum */
Rajeshwari Shinde511ed5f2012-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 Shinde511ed5f2012-10-25 19:49:22 +000020};
21
Simon Glassd4901892018-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 Glassa77bf702014-02-27 13:26:20 -070038 * Generates square wave sound data for 1 second
39 *
Simon Glass7d92b062018-11-15 19:56:13 -070040 * @param sample_rate Sample rate in Hz
Simon Glassa77bf702014-02-27 13:26:20 -070041 * @param data data buffer pointer
Simon Glassd4901892018-12-10 10:37:36 -070042 * @param size size of the buffer in bytes
Simon Glassa77bf702014-02-27 13:26:20 -070043 * @param freq frequency of the wave
44 */
Simon Glass7d92b062018-11-15 19:56:13 -070045void sound_create_square_wave(uint sample_rate, unsigned short *data, int size,
46 uint freq);
Simon Glassa77bf702014-02-27 13:26:20 -070047
48/*
Rajeshwari Shinde511ed5f2012-10-25 19:49:22 +000049 * Initialises audio sub system
Rajeshwari Shindef4823102012-12-26 20:03:17 +000050 * @param blob Pointer of device tree node or NULL if none.
Rajeshwari Shinde511ed5f2012-10-25 19:49:22 +000051 * @return int value 0 for success, -1 for error
52 */
Rajeshwari Shindef4823102012-12-26 20:03:17 +000053int sound_init(const void *blob);
Rajeshwari Shinde511ed5f2012-10-25 19:49:22 +000054
Simon Glassd4901892018-12-10 10:37:36 -070055#ifdef CONFIG_DM_SOUND
56/*
57 * The sound uclass brings together a data transport (currently only I2C) and a
58 * codec (currently connected over I2C).
59 */
60
61/* Operations for sound */
62struct sound_ops {
63 /**
64 * setup() - Set up to play a sound
65 */
66 int (*setup)(struct udevice *dev);
67
68 /**
69 * play() - Play a beep
70 *
71 * @dev: Sound device
72 * @data: Data buffer to play
73 * @data_size: Size of data buffer in bytes
74 * @return 0 if OK, -ve on error
75 */
76 int (*play)(struct udevice *dev, void *data, uint data_size);
77};
78
79#define sound_get_ops(dev) ((struct sound_ops *)(dev)->driver->ops)
80
81/**
82 * setup() - Set up to play a sound
83 */
84int sound_setup(struct udevice *dev);
85
86/**
87 * play() - Play a beep
88 *
89 * @dev: Sound device
90 * @msecs: Duration of beep in milliseconds
91 * @frequency_hz: Frequency of the beep in Hertz
92 * @return 0 if OK, -ve on error
93 */
94int sound_beep(struct udevice *dev, int msecs, int frequency_hz);
95
96/**
97 * sound_find_codec_i2s() - Called by sound drivers to locate codec and i2s
98 *
99 * This finds the audio codec and i2s devices and puts them in the uclass's
100 * private data for this device.
101 */
102int sound_find_codec_i2s(struct udevice *dev);
103
104#else
Rajeshwari Shinde511ed5f2012-10-25 19:49:22 +0000105/*
106 * plays the pcm data buffer in pcm_data.h through i2s1 to make the
107 * sine wave sound
108 *
109 * @return int 0 for success, -1 for error
110 */
111int sound_play(uint32_t msec, uint32_t frequency);
Simon Glassd4901892018-12-10 10:37:36 -0700112#endif /* CONFIG_DM_SOUND */
Rajeshwari Shinde511ed5f2012-10-25 19:49:22 +0000113
114#endif /* __SOUND__H__ */