| 1 | # SoundWire Implementation in coreboot |
| 2 | |
| 3 | ## Introduction |
| 4 | |
| 5 | SoundWire is an audio interface specification from the MIPI Alliance. |
| 6 | |
| 7 | - Low complexity |
| 8 | - Low power |
| 9 | - Low latency |
| 10 | - Two pins (clock and data) |
| 11 | - Multi-drop capable |
| 12 | - Multiple audio streams |
| 13 | - Embedded control/command channel |
| 14 | |
| 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. |
| 17 | |
| 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>. |
| 21 | |
| 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. |
| 25 | |
| 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. |
| 29 | |
| 30 | ## Bus |
| 31 | |
| 32 | The SoundWire bus commonly consists of two pins: |
| 33 | |
| 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. |
| 37 | |
| 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. |
| 40 | |
| 41 | A SoundWire bus consists of one master device, up to 11 slave devices, and an optional |
| 42 | monitor interface for debug. |
| 43 | |
| 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. |
| 46 | |
| 47 | ### Controller |
| 48 | |
| 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. |
| 53 | |
| 54 | In coreboot the controller device is provided by the SoC or an add-in PCI card. |
| 55 | |
| 56 | ### Master |
| 57 | |
| 58 | A SoundWire master (or link) device is responsible for clock and data handling, bus |
| 59 | management, and bit slot allocation. |
| 60 | |
| 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`. |
| 64 | |
| 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. |
| 68 | |
| 69 | ### Slave |
| 70 | |
| 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. |
| 74 | |
| 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. |
| 78 | |
| 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`. |
| 81 | |
| 82 | The mainboard provides: |
| 83 | |
| 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) |
| 87 | |
| 88 | The codec driver provides: |
| 89 | |
| 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) |
| 94 | |
| 95 | ### Monitor |
| 96 | |
| 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. |
| 99 | |
| 100 | ### Example SoundWire Bus |
| 101 | |
| 102 | ``` |
| 103 | +---------------+ +---------------+ |
| 104 | | | Clock Signal | | |
| 105 | | Master |-------+-------------------------------| Slave | |
| 106 | | Interface | | Data Signal | Interface 1 | |
| 107 | | |-------|-------+-----------------------| | |
| 108 | +---------------+ | | +---------------+ |
| 109 | | | |
| 110 | | | |
| 111 | | | |
| 112 | +--+-------+--+ |
| 113 | | | |
| 114 | | Slave | |
| 115 | | Interface 2 | |
| 116 | | | |
| 117 | +-------------+ |
| 118 | ``` |
| 119 | |
| 120 | ## coreboot |
| 121 | |
| 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. |
| 124 | |
| 125 | The architecture-independent SoundWire tables are defined at |
| 126 | |
| 127 | src/include/device/soundwire.h |
| 128 | |
| 129 | Support for new devices comes in three forms: |
| 130 | |
| 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. |
| 133 | |
| 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 |
| 136 | same vendor. |
| 137 | |
| 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. |
| 141 | |
| 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. |
| 145 | |
| 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. |
| 150 | |
| 151 | ## ACPI Implementation |
| 152 | |
| 153 | The implementation for x86 devices relies on ACPI for providing device properties to the OS |
| 154 | kernel drivers. |
| 155 | |
| 156 | The ACPI implementation can be found at |
| 157 | |
| 158 | src/acpi/soundwire.c |
| 159 | |
| 160 | And used by including |
| 161 | |
| 162 | #include <acpi/acpi_soundwire.h> |
| 163 | |
| 164 | ### Controller |
| 165 | |
| 166 | The controller driver should populate a `struct soundwire_controller`: |
| 167 | |
| 168 | ```c |
| 169 | /** |
| 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. |
| 173 | */ |
| 174 | struct soundwire_controller { |
| 175 | unsigned int master_list_count; |
| 176 | struct soundwire_link master_list[SOUNDWIRE_MAX_DEV]; |
| 177 | }; |
| 178 | ``` |
| 179 | |
| 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: |
| 182 | |
| 183 | ```c |
| 184 | struct acpi_dp *dsd = acpi_dp_new_table("_DSD"); |
| 185 | soundwire_gen_controller(dsd, &soc_controller, NULL); |
| 186 | acpi_dp_write(dsd); |
| 187 | ``` |
| 188 | |
| 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: |
| 191 | |
| 192 | ```c |
| 193 | static void controller_link_prop_cb(struct acpi_dp *dsd, unsigned int id, |
| 194 | struct soundwire_controller *controller) |
| 195 | { |
| 196 | acpi_dp_add_integer(dsd, "custom-link-property", 1); |
| 197 | } |
| 198 | ``` |
| 199 | |
| 200 | ### Codec |
| 201 | |
| 202 | The codec driver should populate a *struct soundwire_codec* with necessary properties: |
| 203 | |
| 204 | ```c |
| 205 | /** |
| 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) |
| 213 | */ |
| 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; |
| 221 | }; |
| 222 | ``` |
| 223 | |
| 224 | Many of these properties are optional, and depending on the codec will not be supported. |
| 225 | |
| 226 | #### Slave Device Properties |
| 227 | |
| 228 | These properties provide information about the codec device and what features it supports: |
| 229 | |
| 230 | * Wake capability |
| 231 | * Clock stop behavior |
| 232 | * Clock and channel state machine behavior |
| 233 | * Features like register pages, broadcast read, bank delay, and high performance PHY |
| 234 | |
| 235 | #### Multi-lane Slave Device Properties |
| 236 | |
| 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. |
| 240 | |
| 241 | If a codec supports this feature it must indicate that by providing an entry for |
| 242 | `struct soundwire_multilane` in the chip configuration. |
| 243 | |
| 244 | ```c |
| 245 | /** |
| 246 | * struct drivers_soundwire_example_config - Example codec configuration. |
| 247 | * @multilane: Multi-lane slave configuration. |
| 248 | */ |
| 249 | struct drivers_soundwire_example_config { |
| 250 | struct soundwire_multilane multilane; |
| 251 | }; |
| 252 | ``` |
| 253 | |
| 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: |
| 257 | |
| 258 | ``` |
| 259 | chip drivers/soundwire/multilane_codec |
| 260 | register "multilane.lane_mapping" = "{ |
| 261 | { |
| 262 | # Slave Lane 1 maps to Master Lane 2 |
| 263 | .lane = 1, |
| 264 | .direction = MASTER_LANE, |
| 265 | .connection.master_lane = 2 |
| 266 | }, |
| 267 | { |
| 268 | # Slave Lane 3 maps to Slave Link B |
| 269 | .lane = 3, |
| 270 | .direction = SLAVE_LINK, |
| 271 | .connection.slave_link = 1 |
| 272 | } |
| 273 | }" |
| 274 | device generic 0.0 on end |
| 275 | end |
| 276 | ``` |
| 277 | |
| 278 | #### Data Port 0 Properties |
| 279 | |
| 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. |
| 282 | |
| 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. |
| 285 | |
| 286 | Data port 0 is not required to be supported by the slave device. |
| 287 | |
| 288 | #### Bulk Register Access Mode Properties |
| 289 | |
| 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. |
| 293 | |
| 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. |
| 297 | |
| 298 | #### Data Port 1-14 Properties |
| 299 | |
| 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 |
| 303 | on some data ports. |
| 304 | |
| 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. |
| 307 | |
| 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. |
| 312 | |
| 313 | #### Audio Mode Properties |
| 314 | |
| 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. |
| 318 | |
| 319 | For example: |
| 320 | |
| 321 | ``` |
| 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, |
| 327 | }; |
| 328 | static struct soundwire_dpn codec_dp1 = { |
| 329 | [...] |
| 330 | .port_audio_mode_count = 1, |
| 331 | .port_audio_mode_list = {0} |
| 332 | }; |
| 333 | static struct soundwire_dpn codec_dp3 = { |
| 334 | [...] |
| 335 | .port_audio_mode_count = 1, |
| 336 | .port_audio_mode_list = {0} |
| 337 | }; |
| 338 | ``` |
| 339 | |
| 340 | ### Generating Codec Properties |
| 341 | |
| 342 | Once the properties are known it can generate the ACPI code with: |
| 343 | |
| 344 | ```c |
| 345 | struct acpi_dp *dsd = acpi_dp_new_table("_DSD"); |
| 346 | soundwire_gen_codec(dsd, &soundwire_codec, NULL); |
| 347 | acpi_dp_write(dsd); |
| 348 | ``` |
| 349 | |
| 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: |
| 352 | |
| 353 | ```c |
| 354 | static void codec_dp_prop_cb(struct acpi_dp *dsd, unsigned int id, |
| 355 | struct soundwire_codec *codec) |
| 356 | { |
| 357 | acpi_dp_add_integer(dsd, "custom-dp-property", 1); |
| 358 | } |
| 359 | ``` |
| 360 | |
| 361 | #### Codec Address |
| 362 | |
| 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. |
| 366 | |
| 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. |
| 371 | |
| 372 | ```c |
| 373 | /** |
| 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. |
| 381 | */ |
| 382 | struct soundwire_address { |
| 383 | enum soundwire_version version; |
| 384 | uint8_t link_id; |
| 385 | uint8_t unique_id; |
| 386 | uint16_t manufacturer_id; |
| 387 | uint16_t part_id; |
| 388 | enum mipi_class class; |
| 389 | }; |
| 390 | ``` |
| 391 | |
| 392 | This ACPI address can be generated by calling the provided acpigen function: |
| 393 | |
| 394 | acpigen_write_ADR_soundwire_device(const struct soundwire_address *sdw); |
| 395 | |
| 396 | ### Mainboard |
| 397 | |
| 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. |
| 400 | |
| 401 | The topology uses the **generic** device to describe SoundWire: |
| 402 | |
| 403 | ```c |
| 404 | struct generic_path { |
| 405 | unsigned int id; /* SoundWire Master Link ID */ |
| 406 | unsigned int subid; /* SoundWire Slave Unique ID */ |
| 407 | }; |
| 408 | ``` |
| 409 | |
| 410 | This allows devices to be specified in `devicetree.cb` with the necessary information to |
| 411 | generate ACPI address and device properties. |
| 412 | |
| 413 | ``` |
| 414 | chip drivers/intel/soundwire |
| 415 | # SoundWire Controller 0 |
| 416 | device generic 0 on |
| 417 | chip drivers/soundwire/codec1 |
| 418 | # SoundWire Link 0 ID 0 |
| 419 | device generic 0.0 on end |
| 420 | end |
| 421 | chip drivers/soundwire/codec2 |
| 422 | # SoundWire Link 1 ID 2 |
| 423 | device generic 1.2 on end |
| 424 | end |
| 425 | end |
| 426 | end |
| 427 | ``` |
| 428 | |
| 429 | ## Volteer Example |
| 430 | |
| 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. |
| 433 | |
| 434 | The mainboard can be found at |
| 435 | |
| 436 | src/mainboard/google/volteer |
| 437 | |
| 438 | ``` |
| 439 | +------------------+ +-------------------+ |
| 440 | | | | Headphone Codec | |
| 441 | | Intel Tiger Lake | +--->| Realtek ALC5682 | |
| 442 | | SoundWire | | | ID 1 | |
| 443 | | Controller | | +-------------------+ |
| 444 | | | | |
| 445 | | Link 0 +----+ +-------------------+ |
| 446 | | | | Left Speaker Amp | |
| 447 | | Link 1 +----+--->| Maxim MAX98373 | |
| 448 | | | | | ID 3 | |
| 449 | | Link 2 | | +-------------------+ |
| 450 | | | | |
| 451 | | Link 3 | | +-------------------+ |
| 452 | | | | | Right Speaker Amp | |
| 453 | +------------------+ +--->| Maxim MAX98373 | |
| 454 | | ID 7 | |
| 455 | +-------------------+ |
| 456 | ``` |
| 457 | |
| 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. |
| 461 | |
| 462 | The volteer example requires some `Kconfig` options to be selected: |
| 463 | |
| 464 | ``` |
| 465 | config BOARD_GOOGLE_BASEBOARD_VOLTEER |
| 466 | select DRIVERS_INTEL_SOUNDWIRE |
| 467 | select DRIVERS_SOUNDWIRE_ALC5682 |
| 468 | select DRIVERS_SOUNDWIRE_MAX98373 |
| 469 | ``` |
| 470 | |
| 471 | And the following `devicetree.cb` entries to define this topology: |
| 472 | |
| 473 | ``` |
| 474 | device pci 1f.3 on |
| 475 | chip drivers/intel/soundwire |
| 476 | # SoundWire Controller 0 |
| 477 | device generic 0 on |
| 478 | chip drivers/soundwire/alc5682 |
| 479 | # SoundWire Link 0 ID 1 |
| 480 | register "desc" = ""Headphone Jack"" |
| 481 | device generic 0.1 on end |
| 482 | 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 |
| 487 | 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 |
| 492 | end |
| 493 | end |
| 494 | end |
| 495 | end |
| 496 | ``` |