1 /* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */ 2 /* Copyright(c) 2015-17 Intel Corporation. */ 3 4 #ifndef __SOUNDWIRE_H 5 #define __SOUNDWIRE_H 6 7 #include <linux/bitfield.h> 8 #include <linux/bug.h> 9 #include <linux/completion.h> 10 #include <linux/device.h> 11 #include <linux/idr.h> 12 #include <linux/irq.h> 13 #include <linux/irqdomain.h> 14 #include <linux/jiffies.h> 15 #include <linux/lockdep_types.h> 16 #include <linux/device-id/sdw.h> 17 #include <linux/mutex.h> 18 #include <linux/types.h> 19 #include <sound/sdca.h> 20 21 struct dentry; 22 struct fwnode_handle; 23 struct device_node; 24 25 struct sdw_bus; 26 struct sdw_slave; 27 28 /* SDW spec defines and enums, as defined by MIPI 1.1. Spec */ 29 30 /* SDW Broadcast Device Number */ 31 #define SDW_BROADCAST_DEV_NUM 15 32 33 /* SDW Enumeration Device Number */ 34 #define SDW_ENUM_DEV_NUM 0 35 36 /* SDW Group Device Numbers */ 37 #define SDW_GROUP12_DEV_NUM 12 38 #define SDW_GROUP13_DEV_NUM 13 39 40 /* SDW Master Device Number, not supported yet */ 41 #define SDW_MASTER_DEV_NUM 14 42 43 #define SDW_NUM_DEV_ID_REGISTERS 6 44 /* frame shape defines */ 45 46 /* 47 * Note: The maximum row define in SoundWire spec 1.1 is 23. In order to 48 * fill hole with 0, one more dummy entry is added 49 */ 50 #define SDW_FRAME_ROWS 24 51 #define SDW_FRAME_COLS 8 52 #define SDW_FRAME_ROW_COLS (SDW_FRAME_ROWS * SDW_FRAME_COLS) 53 54 #define SDW_FRAME_CTRL_BITS 48 55 #define SDW_MAX_DEVICES 11 56 #define SDW_FW_MAX_DEVICES 16 57 58 #define SDW_MAX_PORTS 15 59 #define SDW_VALID_PORT_RANGE(n) ((n) < SDW_MAX_PORTS && (n) >= 1) 60 61 #define SDW_MAX_LANES 8 62 63 enum { 64 SDW_PORT_DIRN_SINK = 0, 65 SDW_PORT_DIRN_SOURCE, 66 SDW_PORT_DIRN_MAX, 67 }; 68 69 /* 70 * constants for flow control, ports and transport 71 * 72 * these are bit masks as devices can have multiple capabilities 73 */ 74 75 /* 76 * flow modes for SDW port. These can be isochronous, tx controlled, 77 * rx controlled or async 78 */ 79 #define SDW_PORT_FLOW_MODE_ISOCH 0 80 #define SDW_PORT_FLOW_MODE_TX_CNTRL BIT(0) 81 #define SDW_PORT_FLOW_MODE_RX_CNTRL BIT(1) 82 #define SDW_PORT_FLOW_MODE_ASYNC GENMASK(1, 0) 83 84 /* sample packaging for block. It can be per port or per channel */ 85 #define SDW_BLOCK_PACKG_PER_PORT BIT(0) 86 #define SDW_BLOCK_PACKG_PER_CH BIT(1) 87 88 /** 89 * enum sdw_slave_status - Slave status 90 * @SDW_SLAVE_UNATTACHED: Slave is not attached with the bus. 91 * @SDW_SLAVE_ATTACHED: Slave is attached with bus. 92 * @SDW_SLAVE_ALERT: Some alert condition on the Slave 93 * @SDW_SLAVE_RESERVED: Reserved for future use 94 */ 95 enum sdw_slave_status { 96 SDW_SLAVE_UNATTACHED = 0, 97 SDW_SLAVE_ATTACHED = 1, 98 SDW_SLAVE_ALERT = 2, 99 SDW_SLAVE_RESERVED = 3, 100 }; 101 102 /** 103 * enum sdw_clk_stop_type: clock stop operations 104 * 105 * @SDW_CLK_PRE_PREPARE: pre clock stop prepare 106 * @SDW_CLK_POST_PREPARE: post clock stop prepare 107 * @SDW_CLK_PRE_DEPREPARE: pre clock stop de-prepare 108 * @SDW_CLK_POST_DEPREPARE: post clock stop de-prepare 109 */ 110 enum sdw_clk_stop_type { 111 SDW_CLK_PRE_PREPARE = 0, 112 SDW_CLK_POST_PREPARE, 113 SDW_CLK_PRE_DEPREPARE, 114 SDW_CLK_POST_DEPREPARE, 115 }; 116 117 /** 118 * enum sdw_command_response - Command response as defined by SDW spec 119 * @SDW_CMD_OK: cmd was successful 120 * @SDW_CMD_IGNORED: cmd was ignored 121 * @SDW_CMD_FAIL: cmd was NACKed 122 * @SDW_CMD_TIMEOUT: cmd timedout 123 * @SDW_CMD_FAIL_OTHER: cmd failed due to other reason than above 124 * 125 * NOTE: The enum is different than actual Spec as response in the Spec is 126 * combination of ACK/NAK bits 127 * 128 * SDW_CMD_TIMEOUT/FAIL_OTHER is defined for SW use, not in spec 129 */ 130 enum sdw_command_response { 131 SDW_CMD_OK = 0, 132 SDW_CMD_IGNORED = 1, 133 SDW_CMD_FAIL = 2, 134 SDW_CMD_TIMEOUT = 3, 135 SDW_CMD_FAIL_OTHER = 4, 136 }; 137 138 /* block group count enum */ 139 enum sdw_dpn_grouping { 140 SDW_BLK_GRP_CNT_1 = 0, 141 SDW_BLK_GRP_CNT_2 = 1, 142 SDW_BLK_GRP_CNT_3 = 2, 143 SDW_BLK_GRP_CNT_4 = 3, 144 }; 145 146 /* block packing mode enum */ 147 enum sdw_dpn_pkg_mode { 148 SDW_BLK_PKG_PER_PORT = 0, 149 SDW_BLK_PKG_PER_CHANNEL = 1 150 }; 151 152 /** 153 * enum sdw_stream_type: data stream type 154 * 155 * @SDW_STREAM_PCM: PCM data stream 156 * @SDW_STREAM_PDM: PDM data stream 157 * @SDW_STREAM_BPT: BPT data stream 158 * 159 * spec doesn't define this, but is used in implementation 160 */ 161 enum sdw_stream_type { 162 SDW_STREAM_PCM = 0, 163 SDW_STREAM_PDM = 1, 164 SDW_STREAM_BPT = 2, 165 }; 166 167 /** 168 * enum sdw_data_direction: Data direction 169 * 170 * @SDW_DATA_DIR_RX: Data into Port 171 * @SDW_DATA_DIR_TX: Data out of Port 172 */ 173 enum sdw_data_direction { 174 SDW_DATA_DIR_RX = 0, 175 SDW_DATA_DIR_TX = 1, 176 }; 177 178 /** 179 * enum sdw_port_data_mode: Data Port mode 180 * 181 * @SDW_PORT_DATA_MODE_NORMAL: Normal data mode where audio data is received 182 * and transmitted. 183 * @SDW_PORT_DATA_MODE_PRBS: Test mode which uses a PRBS generator to produce 184 * a pseudo random data pattern that is transferred 185 * @SDW_PORT_DATA_MODE_STATIC_0: Simple test mode which uses static value of 186 * logic 0. The encoding will result in no signal transitions 187 * @SDW_PORT_DATA_MODE_STATIC_1: Simple test mode which uses static value of 188 * logic 1. The encoding will result in signal transitions at every bitslot 189 * owned by this Port 190 */ 191 enum sdw_port_data_mode { 192 SDW_PORT_DATA_MODE_NORMAL = 0, 193 SDW_PORT_DATA_MODE_PRBS = 1, 194 SDW_PORT_DATA_MODE_STATIC_0 = 2, 195 SDW_PORT_DATA_MODE_STATIC_1 = 3, 196 }; 197 198 /* 199 * SDW properties, defined in MIPI DisCo spec v1.0 200 */ 201 enum sdw_clk_stop_reset_behave { 202 SDW_CLK_STOP_KEEP_STATUS = 1, 203 }; 204 205 /** 206 * enum sdw_p15_behave - Slave Port 15 behaviour when the Master attempts a 207 * read 208 * @SDW_P15_READ_IGNORED: Read is ignored 209 * @SDW_P15_CMD_OK: Command is ok 210 */ 211 enum sdw_p15_behave { 212 SDW_P15_READ_IGNORED = 0, 213 SDW_P15_CMD_OK = 1, 214 }; 215 216 /** 217 * enum sdw_dpn_type - Data port types 218 * @SDW_DPN_FULL: Full Data Port is supported 219 * @SDW_DPN_SIMPLE: Simplified Data Port as defined in spec. 220 * DPN_SampleCtrl2, DPN_OffsetCtrl2, DPN_HCtrl and DPN_BlockCtrl3 221 * are not implemented. 222 * @SDW_DPN_REDUCED: Reduced Data Port as defined in spec. 223 * DPN_SampleCtrl2, DPN_HCtrl are not implemented. 224 */ 225 enum sdw_dpn_type { 226 SDW_DPN_FULL = 0, 227 SDW_DPN_SIMPLE = 1, 228 SDW_DPN_REDUCED = 2, 229 }; 230 231 /** 232 * enum sdw_clk_stop_mode - Clock Stop modes 233 * @SDW_CLK_STOP_MODE0: Slave can continue operation seamlessly on clock 234 * restart 235 * @SDW_CLK_STOP_MODE1: Slave may have entered a deeper power-saving mode, 236 * not capable of continuing operation seamlessly when the clock restarts 237 */ 238 enum sdw_clk_stop_mode { 239 SDW_CLK_STOP_MODE0 = 0, 240 SDW_CLK_STOP_MODE1 = 1, 241 }; 242 243 /** 244 * struct sdw_dp0_prop - DP0 properties 245 * @words: wordlengths supported 246 * @max_word: Maximum number of bits in a Payload Channel Sample, 1 to 64 247 * (inclusive) 248 * @min_word: Minimum number of bits in a Payload Channel Sample, 1 to 64 249 * (inclusive) 250 * @num_words: number of wordlengths supported 251 * @ch_prep_timeout: Port-specific timeout value, in milliseconds 252 * @BRA_flow_controlled: Slave implementation results in an OK_NotReady 253 * response 254 * @simple_ch_prep_sm: If channel prepare sequence is required 255 * @imp_def_interrupts: If set, each bit corresponds to support for 256 * implementation-defined interrupts 257 * @num_lanes: array size of @lane_list 258 * @lane_list: indicates which Lanes can be used by DP0 259 * 260 * The wordlengths are specified by Spec as max, min AND number of 261 * discrete values, implementation can define based on the wordlengths they 262 * support 263 */ 264 struct sdw_dp0_prop { 265 u32 *words; 266 u32 max_word; 267 u32 min_word; 268 u32 num_words; 269 u32 ch_prep_timeout; 270 bool BRA_flow_controlled; 271 bool simple_ch_prep_sm; 272 bool imp_def_interrupts; 273 int num_lanes; 274 u32 *lane_list; 275 }; 276 277 /** 278 * struct sdw_dpn_prop - Data Port DPn properties 279 * @num: port number 280 * @max_word: Maximum number of bits in a Payload Channel Sample, 1 to 64 281 * (inclusive) 282 * @min_word: Minimum number of bits in a Payload Channel Sample, 1 to 64 283 * (inclusive) 284 * @num_words: Number of discrete supported wordlengths 285 * @words: Discrete supported wordlength 286 * @type: Data port type. Full, Simplified or Reduced 287 * @max_grouping: Maximum number of samples that can be grouped together for 288 * a full data port 289 * @ch_prep_timeout: Port-specific timeout value, in milliseconds 290 * @imp_def_interrupts: If set, each bit corresponds to support for 291 * implementation-defined interrupts 292 * @max_ch: Maximum channels supported 293 * @min_ch: Minimum channels supported 294 * @num_channels: Number of discrete channels supported 295 * @num_ch_combinations: Number of channel combinations supported 296 * @channels: Discrete channels supported 297 * @ch_combinations: Channel combinations supported 298 * @lane_list: indicates which Lanes can be used by DPn 299 * @num_lanes: array size of @lane_list 300 * @modes: SDW mode supported 301 * @max_async_buffer: Number of samples that this port can buffer in 302 * asynchronous modes 303 * @port_encoding: Payload Channel Sample encoding schemes supported 304 * @block_pack_mode: Type of block port mode supported 305 * @read_only_wordlength: Read Only wordlength field in DPN_BlockCtrl1 register 306 * @simple_ch_prep_sm: If the port supports simplified channel prepare state 307 * machine 308 */ 309 struct sdw_dpn_prop { 310 u32 num; 311 u32 max_word; 312 u32 min_word; 313 u32 num_words; 314 u32 *words; 315 enum sdw_dpn_type type; 316 u32 max_grouping; 317 u32 ch_prep_timeout; 318 u32 imp_def_interrupts; 319 u32 max_ch; 320 u32 min_ch; 321 u32 num_channels; 322 u32 num_ch_combinations; 323 u32 *channels; 324 u32 *ch_combinations; 325 u32 *lane_list; 326 int num_lanes; 327 u32 modes; 328 u32 max_async_buffer; 329 u32 port_encoding; 330 bool block_pack_mode; 331 bool read_only_wordlength; 332 bool simple_ch_prep_sm; 333 }; 334 335 /** 336 * struct sdw_slave_prop - SoundWire Slave properties 337 * @dp0_prop: Data Port 0 properties 338 * @src_dpn_prop: Source Data Port N properties 339 * @sink_dpn_prop: Sink Data Port N properties 340 * @mipi_revision: Spec version of the implementation 341 * @wake_capable: Wake-up events are supported 342 * @test_mode_capable: If test mode is supported 343 * @clk_stop_mode1: Clock-Stop Mode 1 is supported 344 * @simple_clk_stop_capable: Simple clock mode is supported 345 * @clk_stop_timeout: Worst-case latency of the Clock Stop Prepare State 346 * Machine transitions, in milliseconds 347 * @ch_prep_timeout: Worst-case latency of the Channel Prepare State Machine 348 * transitions, in milliseconds 349 * @reset_behave: Slave keeps the status of the SlaveStopClockPrepare 350 * state machine (P=1 SCSP_SM) after exit from clock-stop mode1 351 * @high_PHY_capable: Slave is HighPHY capable 352 * @paging_support: Slave implements paging registers SCP_AddrPage1 and 353 * SCP_AddrPage2 354 * @bank_delay_support: Slave implements bank delay/bridge support registers 355 * SCP_BankDelay and SCP_NextFrame 356 * @lane_control_support: Slave supports lane control 357 * @p15_behave: Slave behavior when the Master attempts a read to the Port15 358 * alias 359 * @master_count: Number of Masters present on this Slave 360 * @source_ports: Bitmap identifying source ports 361 * @sink_ports: Bitmap identifying sink ports 362 * @quirks: bitmask identifying deltas from the MIPI specification 363 * @sdca_interrupt_register_list: indicates which sets of SDCA interrupt status 364 * and masks are supported 365 * @commit_register_supported: is PCP_Commit register supported 366 * @scp_int1_mask: SCP_INT1_MASK desired settings 367 * @lane_maps: Lane mapping for the slave, only valid if lane_control_support is set 368 * @bra_block_alignment: If non-zero the length of data in a BRA frame must be 369 * a multiple of this number of bytes. 370 * @bra_max_data_per_frame: If non-zero the maximum data payload size (in bytes per 371 * frame excluding header, CRC, and footer) for this BRA Mode 372 * @clock_reg_supported: the Peripheral implements the clock base and scale 373 * registers introduced with the SoundWire 1.2 specification. SDCA devices 374 * do not need to set this boolean property as the registers are required. 375 * @use_domain_irq: call actual IRQ handler on slave, as well as callback 376 */ 377 struct sdw_slave_prop { 378 struct sdw_dp0_prop *dp0_prop; 379 struct sdw_dpn_prop *src_dpn_prop; 380 struct sdw_dpn_prop *sink_dpn_prop; 381 u32 mipi_revision; 382 bool wake_capable; 383 bool test_mode_capable; 384 bool clk_stop_mode1; 385 bool simple_clk_stop_capable; 386 u32 clk_stop_timeout; 387 u32 ch_prep_timeout; 388 enum sdw_clk_stop_reset_behave reset_behave; 389 bool high_PHY_capable; 390 bool paging_support; 391 bool bank_delay_support; 392 bool lane_control_support; 393 enum sdw_p15_behave p15_behave; 394 u32 master_count; 395 u32 source_ports; 396 u32 sink_ports; 397 u32 quirks; 398 u32 sdca_interrupt_register_list; 399 u8 commit_register_supported; 400 u8 scp_int1_mask; 401 u8 lane_maps[SDW_MAX_LANES]; 402 u32 bra_block_alignment; 403 u32 bra_max_data_per_frame; 404 bool clock_reg_supported; 405 bool use_domain_irq; 406 }; 407 408 #define SDW_SLAVE_QUIRKS_INVALID_INITIAL_PARITY BIT(0) 409 410 /** 411 * struct sdw_master_prop - Master properties 412 * @clk_gears: Clock gears supported 413 * @clk_freq: Clock frequencies supported, in Hz 414 * @quirks: bitmask identifying optional behavior beyond the scope of the MIPI specification 415 * @revision: MIPI spec version of the implementation 416 * @clk_stop_modes: Bitmap, bit N set when clock-stop-modeN supported 417 * @max_clk_freq: Maximum Bus clock frequency, in Hz 418 * @num_clk_gears: Number of clock gears supported 419 * @num_clk_freq: Number of clock frequencies supported, in Hz 420 * @default_frame_rate: Controller default Frame rate, in Hz 421 * @default_row: Number of rows 422 * @default_col: Number of columns 423 * @dynamic_frame: Dynamic frame shape supported 424 * @err_threshold: Number of times that software may retry sending a single 425 * command 426 * @mclk_freq: clock reference passed to SoundWire Master, in Hz. 427 * @hw_disabled: if true, the Master is not functional, typically due to pin-mux 428 */ 429 struct sdw_master_prop { 430 u32 *clk_gears; 431 u32 *clk_freq; 432 u64 quirks; 433 u32 revision; 434 u32 clk_stop_modes; 435 u32 max_clk_freq; 436 u32 num_clk_gears; 437 u32 num_clk_freq; 438 u32 default_frame_rate; 439 u32 default_row; 440 u32 default_col; 441 u32 err_threshold; 442 u32 mclk_freq; 443 bool dynamic_frame; 444 bool hw_disabled; 445 }; 446 447 /* Definitions for Master quirks */ 448 449 /* 450 * In a number of platforms bus clashes are reported after a hardware 451 * reset but without any explanations or evidence of a real problem. 452 * The following quirk will discard all initial bus clash interrupts 453 * but will leave the detection on should real bus clashes happen 454 */ 455 #define SDW_MASTER_QUIRKS_CLEAR_INITIAL_CLASH BIT(0) 456 457 /* 458 * Some Slave devices have known issues with incorrect parity errors 459 * reported after a hardware reset. However during integration unexplained 460 * parity errors can be reported by Slave devices, possibly due to electrical 461 * issues at the Master level. 462 * The following quirk will discard all initial parity errors but will leave 463 * the detection on should real parity errors happen. 464 */ 465 #define SDW_MASTER_QUIRKS_CLEAR_INITIAL_PARITY BIT(1) 466 467 int sdw_master_read_prop(struct sdw_bus *bus); 468 int sdw_slave_read_prop(struct sdw_slave *slave); 469 int sdw_slave_read_lane_mapping(struct sdw_slave *slave); 470 471 /* 472 * SDW Slave Structures and APIs 473 */ 474 475 #define SDW_IGNORED_UNIQUE_ID 0xFF 476 477 /** 478 * struct sdw_slave_id - Slave ID 479 * @mfg_id: MIPI Manufacturer ID 480 * @part_id: Device Part ID 481 * @class_id: MIPI Class ID (defined starting with SoundWire 1.2 spec) 482 * @unique_id: Device unique ID 483 * @sdw_version: SDW version implemented 484 * 485 * The order of the IDs here does not follow the DisCo spec definitions 486 */ 487 struct sdw_slave_id { 488 __u16 mfg_id; 489 __u16 part_id; 490 __u8 class_id; 491 __u8 unique_id; 492 __u8 sdw_version:4; 493 }; 494 495 struct sdw_peripherals { 496 int num_peripherals; 497 struct sdw_slave *array[]; 498 }; 499 500 /* 501 * Helper macros to extract the MIPI-defined IDs 502 * 503 * Spec definition 504 * Register Bit Contents 505 * DevId_0 [7:4] 47:44 sdw_version 506 * DevId_0 [3:0] 43:40 unique_id 507 * DevId_1 39:32 mfg_id [15:8] 508 * DevId_2 31:24 mfg_id [7:0] 509 * DevId_3 23:16 part_id [15:8] 510 * DevId_4 15:08 part_id [7:0] 511 * DevId_5 07:00 class_id 512 * 513 * The MIPI DisCo for SoundWire defines in addition the link_id as bits 51:48 514 */ 515 #define SDW_DISCO_LINK_ID_MASK GENMASK_ULL(51, 48) 516 #define SDW_VERSION_MASK GENMASK_ULL(47, 44) 517 #define SDW_UNIQUE_ID_MASK GENMASK_ULL(43, 40) 518 #define SDW_MFG_ID_MASK GENMASK_ULL(39, 24) 519 #define SDW_PART_ID_MASK GENMASK_ULL(23, 8) 520 #define SDW_CLASS_ID_MASK GENMASK_ULL(7, 0) 521 522 #define SDW_DISCO_LINK_ID(addr) FIELD_GET(SDW_DISCO_LINK_ID_MASK, addr) 523 #define SDW_VERSION(addr) FIELD_GET(SDW_VERSION_MASK, addr) 524 #define SDW_UNIQUE_ID(addr) FIELD_GET(SDW_UNIQUE_ID_MASK, addr) 525 #define SDW_MFG_ID(addr) FIELD_GET(SDW_MFG_ID_MASK, addr) 526 #define SDW_PART_ID(addr) FIELD_GET(SDW_PART_ID_MASK, addr) 527 #define SDW_CLASS_ID(addr) FIELD_GET(SDW_CLASS_ID_MASK, addr) 528 529 /** 530 * struct sdw_slave_intr_status - Slave interrupt status 531 * @sdca_cascade: set if the Slave device reports an SDCA interrupt 532 * @control_port: control port status 533 * @port: data port status 534 */ 535 struct sdw_slave_intr_status { 536 bool sdca_cascade; 537 u8 control_port; 538 u8 port[15]; 539 }; 540 541 /** 542 * enum sdw_reg_bank - SoundWire register banks 543 * @SDW_BANK0: Soundwire register bank 0 544 * @SDW_BANK1: Soundwire register bank 1 545 */ 546 enum sdw_reg_bank { 547 SDW_BANK0, 548 SDW_BANK1, 549 }; 550 551 /** 552 * struct sdw_prepare_ch: Prepare/De-prepare Data Port channel 553 * 554 * @num: Port number 555 * @ch_mask: Active channel mask 556 * @prepare: Prepare (true) /de-prepare (false) channel 557 * @bank: Register bank, which bank Slave/Master driver should program for 558 * implementation defined registers. This is always updated to next_bank 559 * value read from bus params. 560 * 561 */ 562 struct sdw_prepare_ch { 563 unsigned int num; 564 unsigned int ch_mask; 565 bool prepare; 566 unsigned int bank; 567 }; 568 569 /** 570 * enum sdw_port_prep_ops: Prepare operations for Data Port 571 * 572 * @SDW_OPS_PORT_PRE_PREP: Pre prepare operation for the Port 573 * @SDW_OPS_PORT_PRE_DEPREP: Pre deprepare operation for the Port 574 * @SDW_OPS_PORT_POST_PREP: Post prepare operation for the Port 575 * @SDW_OPS_PORT_POST_DEPREP: Post deprepare operation for the Port 576 */ 577 enum sdw_port_prep_ops { 578 SDW_OPS_PORT_PRE_PREP = 0, 579 SDW_OPS_PORT_PRE_DEPREP, 580 SDW_OPS_PORT_POST_PREP, 581 SDW_OPS_PORT_POST_DEPREP, 582 }; 583 584 /** 585 * struct sdw_bus_params: Structure holding bus configuration 586 * 587 * @curr_bank: Current bank in use (BANK0/BANK1) 588 * @next_bank: Next bank to use (BANK0/BANK1). next_bank will always be 589 * set to !curr_bank 590 * @max_dr_freq: Maximum double rate clock frequency supported, in Hz 591 * @curr_dr_freq: Current double rate clock frequency, in Hz 592 * @bandwidth: Current bandwidth 593 * @col: Active columns 594 * @row: Active rows 595 * @s_data_mode: NORMAL, STATIC or PRBS mode for all Slave ports 596 * @m_data_mode: NORMAL, STATIC or PRBS mode for all Master ports. The value 597 * should be the same to detect transmission issues, but can be different to 598 * test the interrupt reports 599 */ 600 struct sdw_bus_params { 601 enum sdw_reg_bank curr_bank; 602 enum sdw_reg_bank next_bank; 603 unsigned int max_dr_freq; 604 unsigned int curr_dr_freq; 605 unsigned int bandwidth; 606 unsigned int col; 607 unsigned int row; 608 int s_data_mode; 609 int m_data_mode; 610 }; 611 612 /** 613 * struct sdw_slave_ops: Slave driver callback ops 614 * 615 * @read_prop: Read Slave properties 616 * @interrupt_callback: Device interrupt notification (invoked in thread 617 * context) 618 * @update_status: Update Slave status 619 * @bus_config: Update the bus config for Slave 620 * @port_prep: Prepare the port with parameters 621 * @get_clk_stop_mode: Get the clock stop mode of the Slave 622 * @clk_stop: handle imp-def sequences before and after prepare and de-prepare 623 */ 624 struct sdw_slave_ops { 625 int (*read_prop)(struct sdw_slave *sdw); 626 int (*interrupt_callback)(struct sdw_slave *slave, 627 struct sdw_slave_intr_status *status); 628 int (*update_status)(struct sdw_slave *slave, 629 enum sdw_slave_status status); 630 int (*bus_config)(struct sdw_slave *slave, 631 struct sdw_bus_params *params); 632 int (*port_prep)(struct sdw_slave *slave, 633 struct sdw_prepare_ch *prepare_ch, 634 enum sdw_port_prep_ops pre_ops); 635 enum sdw_clk_stop_mode (*get_clk_stop_mode)(struct sdw_slave *slave); 636 int (*clk_stop)(struct sdw_slave *slave, 637 enum sdw_clk_stop_mode mode, 638 enum sdw_clk_stop_type type); 639 }; 640 641 /** 642 * struct sdw_slave - SoundWire Slave 643 * @id: MIPI device ID 644 * @dev: Linux device 645 * @index: internal ID for this slave 646 * @irq: IRQ number 647 * @status: Status reported by the Slave 648 * @bus: Bus handle 649 * @prop: Slave properties 650 * @debugfs: Slave debugfs 651 * @node: node for bus list 652 * @port_ready: Port ready completion flag for each Slave port 653 * @m_port_map: static Master port map for each Slave port 654 * @clk_stop_mode: The clock stop mode of the Slave 655 * @dev_num: Current Device Number, values can be 0 or dev_num_sticky 656 * @dev_num_sticky: one-time static Device Number assigned by Bus 657 * @probed: boolean tracking driver state 658 * @enumeration_complete: completion utility to control potential races 659 * on startup between device enumeration and read/write access to the 660 * Slave device 661 * @initialization_complete: completion utility to control potential races 662 * on startup between device enumeration and settings being restored 663 * @unattach_request: mask field to keep track why the Slave re-attached and 664 * was re-initialized. This is useful to deal with potential race conditions 665 * between the Master suspending and the codec resuming, and make sure that 666 * when the Master triggered a reset the Slave is properly enumerated and 667 * initialized 668 * @first_interrupt_done: status flag tracking if the interrupt handling 669 * for a Slave happens for the first time after enumeration 670 * @is_mockup_device: status flag used to squelch errors in the command/control 671 * protocol for SoundWire mockup devices 672 * @sdw_dev_lock: mutex used to protect callbacks/remove races 673 * @sdca_data: structure containing all device data for SDCA helpers 674 */ 675 struct sdw_slave { 676 struct sdw_slave_id id; 677 struct device dev; 678 int index; 679 int irq; 680 enum sdw_slave_status status; 681 struct sdw_bus *bus; 682 struct sdw_slave_prop prop; 683 #ifdef CONFIG_DEBUG_FS 684 struct dentry *debugfs; 685 #endif 686 struct list_head node; 687 struct completion port_ready[SDW_MAX_PORTS]; 688 unsigned int m_port_map[SDW_MAX_PORTS]; 689 enum sdw_clk_stop_mode clk_stop_mode; 690 u16 dev_num; 691 u16 dev_num_sticky; 692 bool probed; 693 struct completion enumeration_complete; 694 struct completion initialization_complete; 695 u32 unattach_request; 696 bool first_interrupt_done; 697 bool is_mockup_device; 698 struct mutex sdw_dev_lock; /* protect callbacks/remove races */ 699 struct sdca_device_data sdca_data; 700 }; 701 702 #define dev_to_sdw_dev(_dev) container_of(_dev, struct sdw_slave, dev) 703 704 /** 705 * struct sdw_master_device - SoundWire 'Master Device' representation 706 * @dev: Linux device for this Master 707 * @bus: Bus handle shortcut 708 */ 709 struct sdw_master_device { 710 struct device dev; 711 struct sdw_bus *bus; 712 }; 713 714 #define dev_to_sdw_master_device(d) \ 715 container_of(d, struct sdw_master_device, dev) 716 717 struct sdw_driver { 718 int (*probe)(struct sdw_slave *sdw, const struct sdw_device_id *id); 719 void (*remove)(struct sdw_slave *sdw); 720 void (*shutdown)(struct sdw_slave *sdw); 721 722 const struct sdw_device_id *id_table; 723 const struct sdw_slave_ops *ops; 724 725 struct device_driver driver; 726 }; 727 728 #define SDW_SLAVE_ENTRY_EXT(_mfg_id, _part_id, _version, _c_id, _drv_data) \ 729 { .mfg_id = (_mfg_id), .part_id = (_part_id), \ 730 .sdw_version = (_version), .class_id = (_c_id), \ 731 .driver_data = (unsigned long)(_drv_data) } 732 733 #define SDW_SLAVE_ENTRY(_mfg_id, _part_id, _drv_data) \ 734 SDW_SLAVE_ENTRY_EXT((_mfg_id), (_part_id), 0, 0, (_drv_data)) 735 736 int sdw_handle_slave_status(struct sdw_bus *bus, 737 enum sdw_slave_status status[]); 738 739 /* 740 * SDW master structures and APIs 741 */ 742 743 /** 744 * struct sdw_port_params: Data Port parameters 745 * 746 * @num: Port number 747 * @bps: Word length of the Port 748 * @flow_mode: Port Data flow mode 749 * @data_mode: Test modes or normal mode 750 * 751 * This is used to program the Data Port based on Data Port stream 752 * parameters. 753 */ 754 struct sdw_port_params { 755 unsigned int num; 756 unsigned int bps; 757 unsigned int flow_mode; 758 unsigned int data_mode; 759 }; 760 761 /** 762 * struct sdw_transport_params: Data Port Transport Parameters 763 * 764 * @blk_grp_ctrl_valid: Port implements block group control 765 * @port_num: Port number 766 * @blk_grp_ctrl: Block group control value 767 * @sample_interval: Sample interval 768 * @offset1: Blockoffset of the payload data 769 * @offset2: Blockoffset of the payload data 770 * @hstart: Horizontal start of the payload data 771 * @hstop: Horizontal stop of the payload data 772 * @blk_pkg_mode: Block per channel or block per port 773 * @lane_ctrl: Data lane Port uses for Data transfer. Currently only single 774 * data lane is supported in bus 775 * 776 * This is used to program the Data Port based on Data Port transport 777 * parameters. All these parameters are banked and can be modified 778 * during a bank switch without any artifacts in audio stream. 779 */ 780 struct sdw_transport_params { 781 bool blk_grp_ctrl_valid; 782 unsigned int port_num; 783 unsigned int blk_grp_ctrl; 784 unsigned int sample_interval; 785 unsigned int offset1; 786 unsigned int offset2; 787 unsigned int hstart; 788 unsigned int hstop; 789 unsigned int blk_pkg_mode; 790 unsigned int lane_ctrl; 791 }; 792 793 /** 794 * struct sdw_enable_ch: Enable/disable Data Port channel 795 * 796 * @port_num: Port number 797 * @ch_mask: Active channel mask 798 * @enable: Enable (true) /disable (false) channel 799 */ 800 struct sdw_enable_ch { 801 unsigned int port_num; 802 unsigned int ch_mask; 803 bool enable; 804 }; 805 806 /** 807 * struct sdw_master_port_ops: Callback functions from bus to Master 808 * driver to set Master Data ports. 809 * 810 * @dpn_set_port_params: Set the Port parameters for the Master Port. 811 * Mandatory callback 812 * @dpn_set_port_transport_params: Set transport parameters for the Master 813 * Port. Mandatory callback 814 * @dpn_port_prep: Port prepare operations for the Master Data Port. 815 * @dpn_port_enable_ch: Enable the channels of Master Port. 816 */ 817 struct sdw_master_port_ops { 818 int (*dpn_set_port_params)(struct sdw_bus *bus, 819 struct sdw_port_params *port_params, 820 unsigned int bank); 821 int (*dpn_set_port_transport_params)(struct sdw_bus *bus, 822 struct sdw_transport_params *transport_params, 823 enum sdw_reg_bank bank); 824 int (*dpn_port_prep)(struct sdw_bus *bus, struct sdw_prepare_ch *prepare_ch); 825 int (*dpn_port_enable_ch)(struct sdw_bus *bus, 826 struct sdw_enable_ch *enable_ch, unsigned int bank); 827 }; 828 829 struct sdw_msg; 830 831 /** 832 * struct sdw_defer - SDW deferred message 833 * @complete: message completion 834 * @msg: SDW message 835 * @length: message length 836 */ 837 struct sdw_defer { 838 struct sdw_msg *msg; 839 int length; 840 struct completion complete; 841 }; 842 843 /* 844 * Add a practical limit to BPT transfer sizes. BPT is typically used 845 * to transfer firmware, and larger firmware transfers will increase 846 * the cold latency beyond typical OS or user requirements. 847 */ 848 #define SDW_BPT_MSG_MAX_BYTES (1024 * 1024) 849 850 /* 851 * According to mipi SoundWire DisCo Specification_v2-1, 852 * this maximum value shall not exceed 470. 853 * Note that the largest number of bytes accessible by a single BRA operation is limited to 470 854 * bytes when using lane 0, but goes up to 502 bytes when using one of the optional extra lanes. 855 */ 856 #define SDW_BRA_MAX_BYTES_PER_FRAME 470 857 858 struct sdw_bpt_msg; 859 860 /** 861 * struct sdw_master_ops - Master driver ops 862 * @read_prop: Read Master properties 863 * @override_adr: Override value read from firmware (quirk for buggy firmware) 864 * @xfer_msg: Transfer message callback 865 * @xfer_msg_defer: Defer version of transfer message callback. The message is handled with the 866 * bus struct @sdw_defer 867 * @set_bus_conf: Set the bus configuration 868 * @pre_bank_switch: Callback for pre bank switch 869 * @post_bank_switch: Callback for post bank switch 870 * @read_ping_status: Read status from PING frames, reported with two bits per Device. 871 * Bits 31:24 are reserved. 872 * @get_device_num: Callback for vendor-specific device_number allocation 873 * @put_device_num: Callback for vendor-specific device_number release 874 * @new_peripheral_assigned: Callback to handle enumeration of new peripheral. 875 * @bpt_send_async: reserve resources for BPT stream and send message 876 * using BTP protocol 877 * @bpt_wait: wait for message completion using BTP protocol 878 * and release resources 879 */ 880 struct sdw_master_ops { 881 int (*read_prop)(struct sdw_bus *bus); 882 u64 (*override_adr)(struct sdw_bus *bus, u64 addr); 883 enum sdw_command_response (*xfer_msg)(struct sdw_bus *bus, struct sdw_msg *msg); 884 enum sdw_command_response (*xfer_msg_defer)(struct sdw_bus *bus); 885 int (*set_bus_conf)(struct sdw_bus *bus, 886 struct sdw_bus_params *params); 887 int (*pre_bank_switch)(struct sdw_bus *bus); 888 int (*post_bank_switch)(struct sdw_bus *bus); 889 u32 (*read_ping_status)(struct sdw_bus *bus); 890 int (*get_device_num)(struct sdw_bus *bus, struct sdw_slave *slave); 891 void (*put_device_num)(struct sdw_bus *bus, struct sdw_slave *slave); 892 void (*new_peripheral_assigned)(struct sdw_bus *bus, 893 struct sdw_slave *slave, 894 int dev_num); 895 int (*bpt_send_async)(struct sdw_bus *bus, struct sdw_slave *slave, 896 struct sdw_bpt_msg *msg); 897 int (*bpt_wait)(struct sdw_bus *bus, struct sdw_slave *slave, struct sdw_bpt_msg *msg); 898 }; 899 900 int sdw_bus_master_add(struct sdw_bus *bus, struct device *parent, 901 struct fwnode_handle *fwnode); 902 void sdw_bus_master_delete(struct sdw_bus *bus); 903 904 void sdw_show_ping_status(struct sdw_bus *bus, bool sync_delay); 905 906 /** 907 * struct sdw_port_config: Master or Slave Port configuration 908 * 909 * @num: Port number 910 * @ch_mask: channels mask for port 911 */ 912 struct sdw_port_config { 913 unsigned int num; 914 unsigned int ch_mask; 915 }; 916 917 /** 918 * struct sdw_stream_config: Master or Slave stream configuration 919 * 920 * @frame_rate: Audio frame rate of the stream, in Hz 921 * @ch_count: Channel count of the stream 922 * @bps: Number of bits per audio sample 923 * @direction: Data direction 924 * @type: Stream type PCM, PDM or BPT 925 */ 926 struct sdw_stream_config { 927 unsigned int frame_rate; 928 unsigned int ch_count; 929 unsigned int bps; 930 enum sdw_data_direction direction; 931 enum sdw_stream_type type; 932 }; 933 934 /** 935 * enum sdw_stream_state: Stream states 936 * 937 * @SDW_STREAM_ALLOCATED: New stream allocated. 938 * @SDW_STREAM_CONFIGURED: Stream configured 939 * @SDW_STREAM_PREPARED: Stream prepared 940 * @SDW_STREAM_ENABLED: Stream enabled 941 * @SDW_STREAM_DISABLED: Stream disabled 942 * @SDW_STREAM_DEPREPARED: Stream de-prepared 943 * @SDW_STREAM_RELEASED: Stream released 944 */ 945 enum sdw_stream_state { 946 SDW_STREAM_ALLOCATED = 0, 947 SDW_STREAM_CONFIGURED = 1, 948 SDW_STREAM_PREPARED = 2, 949 SDW_STREAM_ENABLED = 3, 950 SDW_STREAM_DISABLED = 4, 951 SDW_STREAM_DEPREPARED = 5, 952 SDW_STREAM_RELEASED = 6, 953 }; 954 955 /** 956 * struct sdw_stream_params: Stream parameters 957 * 958 * @rate: Sampling frequency, in Hz 959 * @ch_count: Number of channels 960 * @bps: bits per channel sample 961 */ 962 struct sdw_stream_params { 963 unsigned int rate; 964 unsigned int ch_count; 965 unsigned int bps; 966 }; 967 968 /** 969 * struct sdw_stream_runtime: Runtime stream parameters 970 * 971 * @name: SoundWire stream name 972 * @params: Stream parameters 973 * @state: Current state of the stream 974 * @type: Stream type PCM, PDM or BPT 975 * @m_rt_count: Count of Master runtime(s) in this stream 976 * @master_list: List of Master runtime(s) in this stream. 977 * master_list can contain only one m_rt per Master instance 978 * for a stream 979 */ 980 struct sdw_stream_runtime { 981 const char *name; 982 struct sdw_stream_params params; 983 enum sdw_stream_state state; 984 enum sdw_stream_type type; 985 int m_rt_count; 986 struct list_head master_list; 987 }; 988 989 /** 990 * struct sdw_bus - SoundWire bus 991 * @dev: Shortcut to &bus->md->dev to avoid changing the entire code. 992 * @md: Master device 993 * @bus_lock_key: bus lock key associated to @bus_lock 994 * @bus_lock: bus lock 995 * @slave_ida: IDA for allocating internal slave IDs 996 * @slaves: list of Slaves on this bus 997 * @msg_lock_key: message lock key associated to @msg_lock 998 * @msg_lock: message lock 999 * @m_rt_list: List of Master instance of all stream(s) running on Bus. This 1000 * is used to compute and program bus bandwidth, clock, frame shape, 1001 * transport and port parameters 1002 * @defer_msg: Defer message 1003 * @params: Current bus parameters 1004 * @stream_refcount: number of streams currently using this bus 1005 * @bpt_stream_refcount: number of BTP streams currently using this bus (should 1006 * be zero or one, multiple streams per link is not supported). 1007 * @bpt_stream: pointer stored to handle BTP streams. 1008 * @ops: Master callback ops 1009 * @port_ops: Master port callback ops 1010 * @prop: Master properties 1011 * @vendor_specific_prop: pointer to non-standard properties 1012 * @hw_sync_min_links: Number of links used by a stream above which 1013 * hardware-based synchronization is required. This value is only 1014 * meaningful if multi_link is set. If set to 1, hardware-based 1015 * synchronization will be used even if a stream only uses a single 1016 * SoundWire segment. 1017 * @controller_id: system-unique controller ID. If set to -1, the bus @id will be used. 1018 * @link_id: Link id number, can be 0 to N, unique for each Controller 1019 * @id: bus system-wide unique id 1020 * @compute_params: points to Bus resource management implementation 1021 * @assigned: Bitmap for Slave device numbers. 1022 * Bit set implies used number, bit clear implies unused number. 1023 * @clk_stop_timeout: Clock stop timeout computed 1024 * @bank_switch_timeout: Bank switch timeout computed 1025 * @domain: IRQ domain 1026 * @irq_chip: IRQ chip 1027 * @debugfs: Bus debugfs (optional) 1028 * @multi_link: Store bus property that indicates if multi links 1029 * are supported. This flag is populated by drivers after reading 1030 * appropriate firmware (ACPI/DT). 1031 * @lane_used_bandwidth: how much bandwidth in bits per second is used by each lane 1032 */ 1033 struct sdw_bus { 1034 struct device *dev; 1035 struct sdw_master_device *md; 1036 struct lock_class_key bus_lock_key; 1037 struct mutex bus_lock; 1038 struct ida slave_ida; 1039 struct list_head slaves; 1040 struct lock_class_key msg_lock_key; 1041 struct mutex msg_lock; 1042 struct list_head m_rt_list; 1043 struct sdw_defer defer_msg; 1044 struct sdw_bus_params params; 1045 int stream_refcount; 1046 int bpt_stream_refcount; 1047 struct sdw_stream_runtime *bpt_stream; 1048 const struct sdw_master_ops *ops; 1049 const struct sdw_master_port_ops *port_ops; 1050 struct sdw_master_prop prop; 1051 void *vendor_specific_prop; 1052 int hw_sync_min_links; 1053 int controller_id; 1054 unsigned int link_id; 1055 int id; 1056 int (*compute_params)(struct sdw_bus *bus, struct sdw_stream_runtime *stream); 1057 DECLARE_BITMAP(assigned, SDW_MAX_DEVICES); 1058 unsigned int clk_stop_timeout; 1059 u32 bank_switch_timeout; 1060 struct irq_chip irq_chip; 1061 struct irq_domain *domain; 1062 #ifdef CONFIG_DEBUG_FS 1063 struct dentry *debugfs; 1064 #endif 1065 bool multi_link; 1066 unsigned int lane_used_bandwidth[SDW_MAX_LANES]; 1067 }; 1068 1069 struct sdw_stream_runtime *sdw_alloc_stream(const char *stream_name, enum sdw_stream_type type); 1070 void sdw_release_stream(struct sdw_stream_runtime *stream); 1071 1072 int sdw_compute_params(struct sdw_bus *bus, struct sdw_stream_runtime *stream); 1073 1074 int sdw_stream_add_master(struct sdw_bus *bus, 1075 struct sdw_stream_config *stream_config, 1076 const struct sdw_port_config *port_config, 1077 unsigned int num_ports, 1078 struct sdw_stream_runtime *stream); 1079 int sdw_stream_remove_master(struct sdw_bus *bus, 1080 struct sdw_stream_runtime *stream); 1081 int sdw_startup_stream(void *sdw_substream); 1082 int sdw_prepare_stream(struct sdw_stream_runtime *stream); 1083 int sdw_enable_stream(struct sdw_stream_runtime *stream); 1084 int sdw_disable_stream(struct sdw_stream_runtime *stream); 1085 int sdw_deprepare_stream(struct sdw_stream_runtime *stream); 1086 void sdw_shutdown_stream(void *sdw_substream); 1087 int sdw_bus_prep_clk_stop(struct sdw_bus *bus); 1088 int sdw_bus_clk_stop(struct sdw_bus *bus); 1089 int sdw_bus_exit_clk_stop(struct sdw_bus *bus); 1090 1091 int sdw_compare_devid(struct sdw_slave *slave, struct sdw_slave_id id); 1092 void sdw_extract_slave_id(struct sdw_bus *bus, u64 addr, struct sdw_slave_id *id); 1093 bool is_clock_scaling_supported_by_slave(struct sdw_slave *slave); 1094 1095 int sdw_bpt_send_async(struct sdw_bus *bus, struct sdw_slave *slave, struct sdw_bpt_msg *msg); 1096 int sdw_bpt_wait(struct sdw_bus *bus, struct sdw_slave *slave, struct sdw_bpt_msg *msg); 1097 int sdw_bpt_send_sync(struct sdw_bus *bus, struct sdw_slave *slave, struct sdw_bpt_msg *msg); 1098 1099 #if IS_ENABLED(CONFIG_SOUNDWIRE) 1100 1101 int sdw_stream_add_slave(struct sdw_slave *slave, 1102 struct sdw_stream_config *stream_config, 1103 const struct sdw_port_config *port_config, 1104 unsigned int num_ports, 1105 struct sdw_stream_runtime *stream); 1106 int sdw_stream_remove_slave(struct sdw_slave *slave, 1107 struct sdw_stream_runtime *stream); 1108 1109 struct device *of_sdw_find_device_by_node(struct device_node *np); 1110 1111 int sdw_slave_get_current_bank(struct sdw_slave *sdev); 1112 1113 int sdw_slave_get_scale_index(struct sdw_slave *slave, u8 *base); 1114 1115 /* messaging and data APIs */ 1116 int sdw_read(struct sdw_slave *slave, u32 addr); 1117 int sdw_write(struct sdw_slave *slave, u32 addr, u8 value); 1118 int sdw_write_no_pm(struct sdw_slave *slave, u32 addr, u8 value); 1119 int sdw_read_no_pm(struct sdw_slave *slave, u32 addr); 1120 int sdw_nread(struct sdw_slave *slave, u32 addr, size_t count, u8 *val); 1121 int sdw_nread_no_pm(struct sdw_slave *slave, u32 addr, size_t count, u8 *val); 1122 int sdw_nwrite(struct sdw_slave *slave, u32 addr, size_t count, const u8 *val); 1123 int sdw_nwrite_no_pm(struct sdw_slave *slave, u32 addr, size_t count, const u8 *val); 1124 int sdw_update(struct sdw_slave *slave, u32 addr, u8 mask, u8 val); 1125 int sdw_update_no_pm(struct sdw_slave *slave, u32 addr, u8 mask, u8 val); 1126 1127 #else 1128 1129 static inline int sdw_stream_add_slave(struct sdw_slave *slave, 1130 struct sdw_stream_config *stream_config, 1131 const struct sdw_port_config *port_config, 1132 unsigned int num_ports, 1133 struct sdw_stream_runtime *stream) 1134 { 1135 WARN_ONCE(1, "SoundWire API is disabled"); 1136 return -EINVAL; 1137 } 1138 1139 static inline int sdw_stream_remove_slave(struct sdw_slave *slave, 1140 struct sdw_stream_runtime *stream) 1141 { 1142 WARN_ONCE(1, "SoundWire API is disabled"); 1143 return -EINVAL; 1144 } 1145 1146 static inline struct device *of_sdw_find_device_by_node(struct device_node *np) 1147 { 1148 WARN_ONCE(1, "SoundWire API is disabled"); 1149 return NULL; 1150 } 1151 1152 static inline int sdw_slave_get_current_bank(struct sdw_slave *sdev) 1153 { 1154 WARN_ONCE(1, "SoundWire API is disabled"); 1155 return -EINVAL; 1156 } 1157 1158 /* messaging and data APIs */ 1159 static inline int sdw_read(struct sdw_slave *slave, u32 addr) 1160 { 1161 WARN_ONCE(1, "SoundWire API is disabled"); 1162 return -EINVAL; 1163 } 1164 1165 static inline int sdw_write(struct sdw_slave *slave, u32 addr, u8 value) 1166 { 1167 WARN_ONCE(1, "SoundWire API is disabled"); 1168 return -EINVAL; 1169 } 1170 1171 static inline int sdw_write_no_pm(struct sdw_slave *slave, u32 addr, u8 value) 1172 { 1173 WARN_ONCE(1, "SoundWire API is disabled"); 1174 return -EINVAL; 1175 } 1176 1177 static inline int sdw_read_no_pm(struct sdw_slave *slave, u32 addr) 1178 { 1179 WARN_ONCE(1, "SoundWire API is disabled"); 1180 return -EINVAL; 1181 } 1182 1183 static inline int sdw_nread(struct sdw_slave *slave, u32 addr, size_t count, u8 *val) 1184 { 1185 WARN_ONCE(1, "SoundWire API is disabled"); 1186 return -EINVAL; 1187 } 1188 1189 static inline int sdw_nread_no_pm(struct sdw_slave *slave, u32 addr, size_t count, u8 *val) 1190 { 1191 WARN_ONCE(1, "SoundWire API is disabled"); 1192 return -EINVAL; 1193 } 1194 1195 static inline int sdw_nwrite(struct sdw_slave *slave, u32 addr, size_t count, const u8 *val) 1196 { 1197 WARN_ONCE(1, "SoundWire API is disabled"); 1198 return -EINVAL; 1199 } 1200 1201 static inline int sdw_nwrite_no_pm(struct sdw_slave *slave, u32 addr, size_t count, const u8 *val) 1202 { 1203 WARN_ONCE(1, "SoundWire API is disabled"); 1204 return -EINVAL; 1205 } 1206 1207 static inline int sdw_update(struct sdw_slave *slave, u32 addr, u8 mask, u8 val) 1208 { 1209 WARN_ONCE(1, "SoundWire API is disabled"); 1210 return -EINVAL; 1211 } 1212 1213 static inline int sdw_update_no_pm(struct sdw_slave *slave, u32 addr, u8 mask, u8 val) 1214 { 1215 WARN_ONCE(1, "SoundWire API is disabled"); 1216 return -EINVAL; 1217 } 1218 1219 #endif /* CONFIG_SOUNDWIRE */ 1220 1221 /** 1222 * sdw_slave_wait_for_init - Wait for device initialisation 1223 * @slave: Pointer to the SoundWire peripheral. 1224 * @timeout_ms: Timeout in milliseconds. 1225 * 1226 * Wait for a peripheral device to enumerate and be initialised by the 1227 * SoundWire core. 1228 * 1229 * Return: Zero on success, and a negative error code on failure. 1230 */ 1231 static inline int sdw_slave_wait_for_init(struct sdw_slave *slave, int timeout_ms) 1232 { 1233 unsigned long time; 1234 1235 if (!slave) 1236 return 0; 1237 1238 time = wait_for_completion_timeout(&slave->initialization_complete, 1239 msecs_to_jiffies(timeout_ms)); 1240 if (!time) { 1241 dev_err(&slave->dev, "Initialization not complete\n"); 1242 return -ETIMEDOUT; 1243 } 1244 1245 slave->unattach_request = 0; 1246 1247 return 0; 1248 } 1249 1250 #endif /* __SOUNDWIRE_H */ 1251