1 # SoundWire Implementation in coreboot
5 SoundWire is an audio interface specification from the MIPI Alliance.
10 - Two pins (clock and data)
12 - Multiple audio streams
13 - Embedded control/command channel
15 The main *SoundWire Specification* is at version 1.2 and can be downloaded from
16 <https://mipi.org> but it is unfortunately only available to MIPI Alliance members.
18 There is a separate *SoundWire Discovery and Configuration (DisCo) Specification* which
19 is at version 1.0 and is available for non-members after providing name and email at
20 <https://resources.mipi.org/disco_soundwire>.
22 The coreboot implementation is based on the SoundWire DisCo Specification which defines
23 object hierarchy and properties for providing topology and configuration information to
24 OS kernel drivers via ACPI or DeviceTree.
26 SoundWire itself is architecture independent and the coreboot basic definition is also not
27 specific to any to any SoC. The examples in this document use ACPI to generate properties,
28 but the same structures and properties would be needed in a DeviceTree implementation.
32 The SoundWire bus commonly consists of two pins:
34 * Clock: A common clock signal distributed from the master to all of the slaves.
35 * Data: A shared data signal that can be driven by any of the devices, and has a defined
36 value when no device is driving it.
38 While most designs have one data lane it is possible for a multi-lane device to have up
39 to 8 data lanes and thus would have more than two pins.
41 A SoundWire bus consists of one master device, up to 11 slave devices, and an optional
42 monitor interface for debug.
44 SoundWire is an enumerable bus, but not a discoverable one. That means it is required
45 for firmware to provide details about the connected devices to the OS.
49 A SoundWire controller contains one or more master devices. The handling of multiple
50 masters is left up to the implementation, they may share a clock or be operated
51 independently or entirely in tandem. The master devices connected to a controller are
52 also referred to as links.
54 In coreboot the controller device is provided by the SoC or an add-in PCI card.
58 A SoundWire master (or link) device is responsible for clock and data handling, bus
59 management, and bit slot allocation.
61 In coreboot the definition of the master device is left up to the controller and the
62 mainboard should only need to know the controller's SoundWire topology (number of masters)
63 to configure `devicetree.cb`.
65 It may however be expected to provide some additional SoC-specific configuration data to
66 the controller, such as an input clock rate or a list of available masters that cannot
67 be determined at run time.
71 SoundWire slave devices are connected to a master and respond to the two-wire control
72 information on the SoundWire bus. There can be up to 11 slave devices on a bus and they
73 are capable of interrupting and waking the host.
75 Slave devices may also have master links which can be connected to other slave devices.
76 It is also possible for a multi-lane slave device to have multiple data lanes connected
77 to different combinations of master and slave devices.
79 In coreboot the slave device is defined by a codec driver which should be found in the
80 source tree at `src/drivers/soundwire`.
82 The mainboard provides:
84 * Master link that this slave device is connected to.
85 * Unique ID that this codec responds to on the SoundWire bus.
86 * Multi-lane mapping. (optional)
88 The codec driver provides:
90 * Slave device properties.
91 * Audio Mode properties including bus frequencies and sampling rates.
92 * Data Port 1-14 properties such as word lengths, interrupt support, channels.
93 * Data Port 0 and Bulk Register Access properties. (optional)
97 A SoundWire monitor device is defined that allows for test equipment to snoop the bus and
98 take over and issue commands. The monitor interface is not defined for coreboot.
100 ### Example SoundWire Bus
103 +---------------+ +---------------+
105 | Master |-------+-------------------------------| Slave |
106 | Interface | | Data Signal | Interface 1 |
107 | |-------|-------+-----------------------| |
108 +---------------+ | | +---------------+
122 The coreboot implementation of SoundWire integrates with the device model and takes
123 advantage of the hierarchical nature of `devicetree.cb` to populate the topology.
125 The architecture-independent SoundWire tables are defined at
127 src/include/device/soundwire.h
129 Support for new devices comes in three forms:
131 1. New controller and master drivers. The first implementation in coreboot is for an Intel
132 SoC but the SoundWire specification is in wide use on various ARM SoCs.
134 Controller drivers can be implemented in `src/soc` or `src/drivers` and should
135 strive to re-use code as much as possible between different SoC generations from the
138 2. New codec drivers. These should be implemented for each codec that is added which
139 supports SoundWire. The properties vary between codecs and careful study of the data sheet
140 is necessary to ensure proper operation.
142 Codec drivers should be implemented in `src/drivers/soundwire` as separate chip drivers.
143 As every codec is different there may not be opportunities of code re-use except between
144 similar codecs from the same vendor.
146 3. New mainboards with SoundWire support. The mainboard will combine controllers and codecs
147 to form a topology that is described in `devicetree.cb`. Some devices may need to provide
148 board-specific configuration information, and multi-lane devices will need to provide the
149 master/slave lane map.
151 ## ACPI Implementation
153 The implementation for x86 devices relies on ACPI for providing device properties to the OS
156 The ACPI implementation can be found at
160 And used by including
162 #include <acpi/acpi_soundwire.h>
166 The controller driver should populate a `struct soundwire_controller`:
170 * struct soundwire_controller - SoundWire controller properties.
171 * @master_count: Number of masters present on this device.
172 * @master_list: One entry for each master device.
174 struct soundwire_controller {
175 unsigned int master_list_count;
176 struct soundwire_link master_list[SOUNDWIRE_MAX_DEV];
180 Once the detail of the master links are specified in the `master_list` variable, the controller
181 properties for the ACPI object can be generated:
184 struct acpi_dp *dsd = acpi_dp_new_table("_DSD");
185 soundwire_gen_controller(dsd, &soc_controller, NULL);
189 If the controller needs to generate custom properties for links it can provide a callback
190 function to `soundwire_gen_controller()` instead of passing NULL:
193 static void controller_link_prop_cb(struct acpi_dp *dsd, unsigned int id,
194 struct soundwire_controller *controller)
196 acpi_dp_add_integer(dsd, "custom-link-property", 1);
202 The codec driver should populate a *struct soundwire_codec* with necessary properties:
206 * struct soundwire_codec - Contains all configuration for a SoundWire codec slave device.
207 * @slave: Properties for slave device.
208 * @audio_mode: Properties for Audio Mode for Data Ports 1-14.
209 * @dpn: Properties for Data Ports 1-14.
210 * @multilane: Properties for slave multilane device. (optional)
211 * @dp0_bra_mode: Properties for Bulk Register Access mode for Data Port 0. (optional)
212 * @dp0: Properties for Data Port 0 for Bulk Register Access. (optional)
214 struct soundwire_codec {
215 struct soundwire_slave *slave;
216 struct soundwire_audio_mode *audio_mode[SOUNDWIRE_MAX_DEV];
217 struct soundwire_dpn_entry dpn[SOUNDWIRE_MAX_DPN - SOUNDWIRE_MIN_DPN];
218 struct soundwire_multilane *multilane;
219 struct soundwire_bra_mode *dp0_bra_mode[SOUNDWIRE_MAX_DEV];
220 struct soundwire_dp0 *dp0;
224 Many of these properties are optional, and depending on the codec will not be supported.
226 #### Slave Device Properties
228 These properties provide information about the codec device and what features it supports:
231 * Clock stop behavior
232 * Clock and channel state machine behavior
233 * Features like register pages, broadcast read, bank delay, and high performance PHY
235 #### Multi-lane Slave Device Properties
237 Most slave devices have a single data pin and a single lane, but it is possible for up to
238 7 other lanes to be supported on a device. These lanes can be connected to other master
239 links or to other slave devices.
241 If a codec supports this feature it must indicate that by providing an entry for
242 `struct soundwire_multilane` in the chip configuration.
246 * struct drivers_soundwire_example_config - Example codec configuration.
247 * @multilane: Multi-lane slave configuration.
249 struct drivers_soundwire_example_config {
250 struct soundwire_multilane multilane;
254 The mainboard is required to provide the lane map in `devicetree.cb` for any codec that has
255 multiple lanes connected. This includes the definition up to 7 entries that indicate which
256 lane number on the slave devices (array index starting at 1) maps to which other device:
259 chip drivers/soundwire/multilane_codec
260 register "multilane.lane_mapping" = "{
262 # Slave Lane 1 maps to Master Lane 2
264 .direction = MASTER_LANE,
265 .connection.master_lane = 2
268 # Slave Lane 3 maps to Slave Link B
270 .direction = SLAVE_LINK,
271 .connection.slave_link = 1
274 device generic 0.0 on end
278 #### Data Port 0 Properties
280 SoundWire Data Port 0 (DP0) is a special port used for control and status operation relating
281 to the whole device interface, and as a special data port for bulk read/write operations.
283 The properties for data port 0 are different from that of data ports 1-14 and are about the
284 control channel behavior and the overall bulk register mode.
286 Data port 0 is not required to be supported by the slave device.
288 #### Bulk Register Access Mode Properties
290 Bulk Register Access (BRA) is an optional mechanism for transporting higher bandwidth of
291 register operations than the typical command mechanism. The BRA protocol is a particular
292 format of the data on the (optional) data port 0 connection between the master and slave.
294 The BRA protocol may have alignment or timing requirements that are directly related to the
295 bus frequencies. As a result there may be several configurations listed, for symmetry with
296 the audio modes paired with data ports 1-14.
298 #### Data Port 1-14 Properties
300 Data ports 1-14 are typically dedicated to streaming audio payloads, and each data port can
301 have from 1 to 8 channels. There are different levels of data ports, with some registers
302 being required and supported on all data ports and some optional registers only being used
305 Data ports can have both a sink and a source component, and the codec may support one or
306 both of these on each port.
308 Similar to data port 0 the properties defined here describe the capabilities and supported
309 features of each data port, and they may be configured separately. For example the Maxim
310 MAX98373 codec supports a 32bit source data port for speaker output, and a 16bit sink data
311 port for speaker sense data.
313 #### Audio Mode Properties
315 Each data port may be tied to one or more audio modes. The audio mode describes the actual
316 audio capabilities of the codec, including supported frequencies and sample rates. These
317 modes can be shared by multiple data ports and do not need to be duplicated.
322 static struct soundwire_audio_mode audio_mode = {
323 .bus_frequency_max = 24 * MHz,
324 .bus_frequency_min = 24 * KHz,
325 .max_sampling_frequency = 192 * KHz,
326 .min_sampling_frequency = 8 * KHz,
328 static struct soundwire_dpn codec_dp1 = {
330 .port_audio_mode_count = 1,
331 .port_audio_mode_list = {0}
333 static struct soundwire_dpn codec_dp3 = {
335 .port_audio_mode_count = 1,
336 .port_audio_mode_list = {0}
340 ### Generating Codec Properties
342 Once the properties are known it can generate the ACPI code with:
345 struct acpi_dp *dsd = acpi_dp_new_table("_DSD");
346 soundwire_gen_codec(dsd, &soundwire_codec, NULL);
350 If the codec needs to generate custom properties for links it can provide a callback
351 function to `soundwire_gen_codec()` instead of passing NULL:
354 static void codec_dp_prop_cb(struct acpi_dp *dsd, unsigned int id,
355 struct soundwire_codec *codec)
357 acpi_dp_add_integer(dsd, "custom-dp-property", 1);
363 SoundWire slave devices use a SoundWire defined ACPI _ADR that requires a 64-bit integer
364 and uses the master link ID and slave device unique ID to form a unique address for the
365 device on this controller.
367 SoundWire addresses must be distinguishable from all other slave devices on the same master
368 link, so multiple instances of the same manufacturer and part on the same master link will
369 need different unique IDs. The value is typically determined by strapping pins on the codec
370 chip and can be decoded for this table with the codec datasheet and board schematics.
374 * struct soundwire_address - SoundWire ACPI Device Address Encoding.
375 * @version: SoundWire specification version from &enum soundwire_version.
376 * @link_id: Zero-based SoundWire Link Number.
377 * @unique_id: Unique ID for multiple devices.
378 * @manufacturer_id: Manufacturer ID from include/mipi/ids.h.
379 * @part_id: Vendor defined part ID.
380 * @class: MIPI class encoding in &enum mipi_class.
382 struct soundwire_address {
383 enum soundwire_version version;
386 uint16_t manufacturer_id;
388 enum mipi_class class;
392 This ACPI address can be generated by calling the provided acpigen function:
394 acpigen_write_ADR_soundwire_device(const struct soundwire_address *sdw);
398 The mainboard needs to select appropriate drivers in `Kconfig` and define the topology in
399 `devicetree.cb` with the controllers and codecs that exist on the board.
401 The topology uses the **generic** device to describe SoundWire:
404 struct generic_path {
405 unsigned int id; /* SoundWire Master Link ID */
406 unsigned int subid; /* SoundWire Slave Unique ID */
410 This allows devices to be specified in `devicetree.cb` with the necessary information to
411 generate ACPI address and device properties.
414 chip drivers/intel/soundwire
415 # SoundWire Controller 0
417 chip drivers/soundwire/codec1
418 # SoundWire Link 0 ID 0
419 device generic 0.0 on end
421 chip drivers/soundwire/codec2
422 # SoundWire Link 1 ID 2
423 device generic 1.2 on end
431 This is an example of an Intel Tiger Lake reference board using SoundWire Link 0 for the
432 headphone codec connection, and Link 1 for connecting two speaker amps for stereo speakers.
434 The mainboard can be found at
436 src/mainboard/google/volteer
439 +------------------+ +-------------------+
440 | | | Headphone Codec |
441 | Intel Tiger Lake | +--->| Realtek ALC5682 |
442 | SoundWire | | | ID 1 |
443 | Controller | | +-------------------+
445 | Link 0 +----+ +-------------------+
446 | | | Left Speaker Amp |
447 | Link 1 +----+--->| Maxim MAX98373 |
449 | Link 2 | | +-------------------+
451 | Link 3 | | +-------------------+
452 | | | | Right Speaker Amp |
453 +------------------+ +--->| Maxim MAX98373 |
455 +-------------------+
458 This implementation requires a controller driver for the Intel Tigerlake SoC and a codec
459 driver for the Realtek and Maxim chips. If those drivers did not already exist they would
460 need to be added and reviewed separately before adding the support to the mainboard.
462 The volteer example requires some `Kconfig` options to be selected:
465 config BOARD_GOOGLE_BASEBOARD_VOLTEER
466 select DRIVERS_INTEL_SOUNDWIRE
467 select DRIVERS_SOUNDWIRE_ALC5682
468 select DRIVERS_SOUNDWIRE_MAX98373
471 And the following `devicetree.cb` entries to define this topology:
475 chip drivers/intel/soundwire
476 # SoundWire Controller 0
478 chip drivers/soundwire/alc5682
479 # SoundWire Link 0 ID 1
480 register "desc" = ""Headphone Jack""
481 device generic 0.1 on end
483 chip drivers/soundwire/max98373
484 # SoundWire Link 0 ID 1
485 register "desc" = ""Left Speaker Amp""
486 device generic 1.3 on end
488 chip drivers/soundwire/max98373
489 # SoundWire Link 1 ID 7
490 register "desc" = ""Right Speaker Amp""
491 device generic 1.7 on end