Blame view

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