1 /* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
2 /* Copyright(c) 2015-17 Intel Corporation. */
7 #include <linux/bitfield.h>
9 #include <linux/completion.h>
10 #include <linux/device.h>
11 #include <linux/irq.h>
12 #include <linux/irqdomain.h>
13 #include <linux/lockdep_types.h>
14 #include <linux/mod_devicetable.h>
15 #include <linux/mutex.h>
16 #include <linux/types.h>
17 #include <sound/sdca.h>
25 /* SDW spec defines and enums, as defined by MIPI 1.1. Spec */
27 /* SDW Broadcast Device Number */
28 #define SDW_BROADCAST_DEV_NUM 15
30 /* SDW Enumeration Device Number */
31 #define SDW_ENUM_DEV_NUM 0
33 /* SDW Group Device Numbers */
34 #define SDW_GROUP12_DEV_NUM 12
35 #define SDW_GROUP13_DEV_NUM 13
37 /* SDW Master Device Number, not supported yet */
38 #define SDW_MASTER_DEV_NUM 14
40 #define SDW_NUM_DEV_ID_REGISTERS 6
41 /* frame shape defines */
44 * Note: The maximum row define in SoundWire spec 1.1 is 23. In order to
45 * fill hole with 0, one more dummy entry is added
47 #define SDW_FRAME_ROWS 24
48 #define SDW_FRAME_COLS 8
49 #define SDW_FRAME_ROW_COLS (SDW_FRAME_ROWS * SDW_FRAME_COLS)
51 #define SDW_FRAME_CTRL_BITS 48
52 #define SDW_MAX_DEVICES 11
54 #define SDW_MAX_PORTS 15
55 #define SDW_VALID_PORT_RANGE(n) ((n) < SDW_MAX_PORTS && (n) >= 1)
58 SDW_PORT_DIRN_SINK = 0,
64 * constants for flow control, ports and transport
66 * these are bit masks as devices can have multiple capabilities
70 * flow modes for SDW port. These can be isochronous, tx controlled,
71 * rx controlled or async
73 #define SDW_PORT_FLOW_MODE_ISOCH 0
74 #define SDW_PORT_FLOW_MODE_TX_CNTRL BIT(0)
75 #define SDW_PORT_FLOW_MODE_RX_CNTRL BIT(1)
76 #define SDW_PORT_FLOW_MODE_ASYNC GENMASK(1, 0)
78 /* sample packaging for block. It can be per port or per channel */
79 #define SDW_BLOCK_PACKG_PER_PORT BIT(0)
80 #define SDW_BLOCK_PACKG_PER_CH BIT(1)
83 * enum sdw_slave_status - Slave status
84 * @SDW_SLAVE_UNATTACHED: Slave is not attached with the bus.
85 * @SDW_SLAVE_ATTACHED: Slave is attached with bus.
86 * @SDW_SLAVE_ALERT: Some alert condition on the Slave
87 * @SDW_SLAVE_RESERVED: Reserved for future use
89 enum sdw_slave_status {
90 SDW_SLAVE_UNATTACHED = 0,
91 SDW_SLAVE_ATTACHED = 1,
93 SDW_SLAVE_RESERVED = 3,
97 * enum sdw_clk_stop_type: clock stop operations
99 * @SDW_CLK_PRE_PREPARE: pre clock stop prepare
100 * @SDW_CLK_POST_PREPARE: post clock stop prepare
101 * @SDW_CLK_PRE_DEPREPARE: pre clock stop de-prepare
102 * @SDW_CLK_POST_DEPREPARE: post clock stop de-prepare
104 enum sdw_clk_stop_type {
105 SDW_CLK_PRE_PREPARE = 0,
106 SDW_CLK_POST_PREPARE,
107 SDW_CLK_PRE_DEPREPARE,
108 SDW_CLK_POST_DEPREPARE,
112 * enum sdw_command_response - Command response as defined by SDW spec
113 * @SDW_CMD_OK: cmd was successful
114 * @SDW_CMD_IGNORED: cmd was ignored
115 * @SDW_CMD_FAIL: cmd was NACKed
116 * @SDW_CMD_TIMEOUT: cmd timedout
117 * @SDW_CMD_FAIL_OTHER: cmd failed due to other reason than above
119 * NOTE: The enum is different than actual Spec as response in the Spec is
120 * combination of ACK/NAK bits
122 * SDW_CMD_TIMEOUT/FAIL_OTHER is defined for SW use, not in spec
124 enum sdw_command_response {
129 SDW_CMD_FAIL_OTHER = 4,
132 /* block group count enum */
133 enum sdw_dpn_grouping {
134 SDW_BLK_GRP_CNT_1 = 0,
135 SDW_BLK_GRP_CNT_2 = 1,
136 SDW_BLK_GRP_CNT_3 = 2,
137 SDW_BLK_GRP_CNT_4 = 3,
140 /* block packing mode enum */
141 enum sdw_dpn_pkg_mode {
142 SDW_BLK_PKG_PER_PORT = 0,
143 SDW_BLK_PKG_PER_CHANNEL = 1
147 * enum sdw_stream_type: data stream type
149 * @SDW_STREAM_PCM: PCM data stream
150 * @SDW_STREAM_PDM: PDM data stream
152 * spec doesn't define this, but is used in implementation
154 enum sdw_stream_type {
160 * enum sdw_data_direction: Data direction
162 * @SDW_DATA_DIR_RX: Data into Port
163 * @SDW_DATA_DIR_TX: Data out of Port
165 enum sdw_data_direction {
171 * enum sdw_port_data_mode: Data Port mode
173 * @SDW_PORT_DATA_MODE_NORMAL: Normal data mode where audio data is received
175 * @SDW_PORT_DATA_MODE_PRBS: Test mode which uses a PRBS generator to produce
176 * a pseudo random data pattern that is transferred
177 * @SDW_PORT_DATA_MODE_STATIC_0: Simple test mode which uses static value of
178 * logic 0. The encoding will result in no signal transitions
179 * @SDW_PORT_DATA_MODE_STATIC_1: Simple test mode which uses static value of
180 * logic 1. The encoding will result in signal transitions at every bitslot
183 enum sdw_port_data_mode {
184 SDW_PORT_DATA_MODE_NORMAL = 0,
185 SDW_PORT_DATA_MODE_PRBS = 1,
186 SDW_PORT_DATA_MODE_STATIC_0 = 2,
187 SDW_PORT_DATA_MODE_STATIC_1 = 3,
191 * SDW properties, defined in MIPI DisCo spec v1.0
193 enum sdw_clk_stop_reset_behave {
194 SDW_CLK_STOP_KEEP_STATUS = 1,
198 * enum sdw_p15_behave - Slave Port 15 behaviour when the Master attempts a
200 * @SDW_P15_READ_IGNORED: Read is ignored
201 * @SDW_P15_CMD_OK: Command is ok
203 enum sdw_p15_behave {
204 SDW_P15_READ_IGNORED = 0,
209 * enum sdw_dpn_type - Data port types
210 * @SDW_DPN_FULL: Full Data Port is supported
211 * @SDW_DPN_SIMPLE: Simplified Data Port as defined in spec.
212 * DPN_SampleCtrl2, DPN_OffsetCtrl2, DPN_HCtrl and DPN_BlockCtrl3
213 * are not implemented.
214 * @SDW_DPN_REDUCED: Reduced Data Port as defined in spec.
215 * DPN_SampleCtrl2, DPN_HCtrl are not implemented.
224 * enum sdw_clk_stop_mode - Clock Stop modes
225 * @SDW_CLK_STOP_MODE0: Slave can continue operation seamlessly on clock
227 * @SDW_CLK_STOP_MODE1: Slave may have entered a deeper power-saving mode,
228 * not capable of continuing operation seamlessly when the clock restarts
230 enum sdw_clk_stop_mode {
231 SDW_CLK_STOP_MODE0 = 0,
232 SDW_CLK_STOP_MODE1 = 1,
236 * struct sdw_dp0_prop - DP0 properties
237 * @words: wordlengths supported
238 * @max_word: Maximum number of bits in a Payload Channel Sample, 1 to 64
240 * @min_word: Minimum number of bits in a Payload Channel Sample, 1 to 64
242 * @num_words: number of wordlengths supported
243 * @ch_prep_timeout: Port-specific timeout value, in milliseconds
244 * @BRA_flow_controlled: Slave implementation results in an OK_NotReady
246 * @simple_ch_prep_sm: If channel prepare sequence is required
247 * @imp_def_interrupts: If set, each bit corresponds to support for
248 * implementation-defined interrupts
249 * @num_lanes: array size of @lane_list
250 * @lane_list: indicates which Lanes can be used by DP0
252 * The wordlengths are specified by Spec as max, min AND number of
253 * discrete values, implementation can define based on the wordlengths they
256 struct sdw_dp0_prop {
262 bool BRA_flow_controlled;
263 bool simple_ch_prep_sm;
264 bool imp_def_interrupts;
270 * struct sdw_dpn_prop - Data Port DPn properties
272 * @max_word: Maximum number of bits in a Payload Channel Sample, 1 to 64
274 * @min_word: Minimum number of bits in a Payload Channel Sample, 1 to 64
276 * @num_words: Number of discrete supported wordlengths
277 * @words: Discrete supported wordlength
278 * @type: Data port type. Full, Simplified or Reduced
279 * @max_grouping: Maximum number of samples that can be grouped together for
281 * @ch_prep_timeout: Port-specific timeout value, in milliseconds
282 * @imp_def_interrupts: If set, each bit corresponds to support for
283 * implementation-defined interrupts
284 * @max_ch: Maximum channels supported
285 * @min_ch: Minimum channels supported
286 * @num_channels: Number of discrete channels supported
287 * @num_ch_combinations: Number of channel combinations supported
288 * @channels: Discrete channels supported
289 * @ch_combinations: Channel combinations supported
290 * @lane_list: indicates which Lanes can be used by DPn
291 * @num_lanes: array size of @lane_list
292 * @modes: SDW mode supported
293 * @max_async_buffer: Number of samples that this port can buffer in
295 * @port_encoding: Payload Channel Sample encoding schemes supported
296 * @block_pack_mode: Type of block port mode supported
297 * @read_only_wordlength: Read Only wordlength field in DPN_BlockCtrl1 register
298 * @simple_ch_prep_sm: If the port supports simplified channel prepare state
301 struct sdw_dpn_prop {
307 enum sdw_dpn_type type;
310 u32 imp_def_interrupts;
314 u32 num_ch_combinations;
316 u32 *ch_combinations;
320 u32 max_async_buffer;
322 bool block_pack_mode;
323 bool read_only_wordlength;
324 bool simple_ch_prep_sm;
328 * struct sdw_slave_prop - SoundWire Slave properties
329 * @dp0_prop: Data Port 0 properties
330 * @src_dpn_prop: Source Data Port N properties
331 * @sink_dpn_prop: Sink Data Port N properties
332 * @mipi_revision: Spec version of the implementation
333 * @wake_capable: Wake-up events are supported
334 * @test_mode_capable: If test mode is supported
335 * @clk_stop_mode1: Clock-Stop Mode 1 is supported
336 * @simple_clk_stop_capable: Simple clock mode is supported
337 * @clk_stop_timeout: Worst-case latency of the Clock Stop Prepare State
338 * Machine transitions, in milliseconds
339 * @ch_prep_timeout: Worst-case latency of the Channel Prepare State Machine
340 * transitions, in milliseconds
341 * @reset_behave: Slave keeps the status of the SlaveStopClockPrepare
342 * state machine (P=1 SCSP_SM) after exit from clock-stop mode1
343 * @high_PHY_capable: Slave is HighPHY capable
344 * @paging_support: Slave implements paging registers SCP_AddrPage1 and
346 * @bank_delay_support: Slave implements bank delay/bridge support registers
347 * SCP_BankDelay and SCP_NextFrame
348 * @lane_control_support: Slave supports lane control
349 * @p15_behave: Slave behavior when the Master attempts a read to the Port15
351 * @master_count: Number of Masters present on this Slave
352 * @source_ports: Bitmap identifying source ports
353 * @sink_ports: Bitmap identifying sink ports
354 * @quirks: bitmask identifying deltas from the MIPI specification
355 * @sdca_interrupt_register_list: indicates which sets of SDCA interrupt status
356 * and masks are supported
357 * @commit_register_supported: is PCP_Commit register supported
358 * @scp_int1_mask: SCP_INT1_MASK desired settings
359 * @clock_reg_supported: the Peripheral implements the clock base and scale
360 * registers introduced with the SoundWire 1.2 specification. SDCA devices
361 * do not need to set this boolean property as the registers are required.
362 * @use_domain_irq: call actual IRQ handler on slave, as well as callback
364 struct sdw_slave_prop {
365 struct sdw_dp0_prop *dp0_prop;
366 struct sdw_dpn_prop *src_dpn_prop;
367 struct sdw_dpn_prop *sink_dpn_prop;
370 bool test_mode_capable;
372 bool simple_clk_stop_capable;
373 u32 clk_stop_timeout;
375 enum sdw_clk_stop_reset_behave reset_behave;
376 bool high_PHY_capable;
378 bool bank_delay_support;
379 bool lane_control_support;
380 enum sdw_p15_behave p15_behave;
385 u32 sdca_interrupt_register_list;
386 u8 commit_register_supported;
388 bool clock_reg_supported;
392 #define SDW_SLAVE_QUIRKS_INVALID_INITIAL_PARITY BIT(0)
395 * struct sdw_master_prop - Master properties
396 * @clk_gears: Clock gears supported
397 * @clk_freq: Clock frequencies supported, in Hz
398 * @quirks: bitmask identifying optional behavior beyond the scope of the MIPI specification
399 * @revision: MIPI spec version of the implementation
400 * @clk_stop_modes: Bitmap, bit N set when clock-stop-modeN supported
401 * @max_clk_freq: Maximum Bus clock frequency, in Hz
402 * @num_clk_gears: Number of clock gears supported
403 * @num_clk_freq: Number of clock frequencies supported, in Hz
404 * @default_frame_rate: Controller default Frame rate, in Hz
405 * @default_row: Number of rows
406 * @default_col: Number of columns
407 * @dynamic_frame: Dynamic frame shape supported
408 * @err_threshold: Number of times that software may retry sending a single
410 * @mclk_freq: clock reference passed to SoundWire Master, in Hz.
411 * @hw_disabled: if true, the Master is not functional, typically due to pin-mux
413 struct sdw_master_prop {
422 u32 default_frame_rate;
431 /* Definitions for Master quirks */
434 * In a number of platforms bus clashes are reported after a hardware
435 * reset but without any explanations or evidence of a real problem.
436 * The following quirk will discard all initial bus clash interrupts
437 * but will leave the detection on should real bus clashes happen
439 #define SDW_MASTER_QUIRKS_CLEAR_INITIAL_CLASH BIT(0)
442 * Some Slave devices have known issues with incorrect parity errors
443 * reported after a hardware reset. However during integration unexplained
444 * parity errors can be reported by Slave devices, possibly due to electrical
445 * issues at the Master level.
446 * The following quirk will discard all initial parity errors but will leave
447 * the detection on should real parity errors happen.
449 #define SDW_MASTER_QUIRKS_CLEAR_INITIAL_PARITY BIT(1)
451 int sdw_master_read_prop(struct sdw_bus *bus);
452 int sdw_slave_read_prop(struct sdw_slave *slave);
455 * SDW Slave Structures and APIs
458 #define SDW_IGNORED_UNIQUE_ID 0xFF
461 * struct sdw_slave_id - Slave ID
462 * @mfg_id: MIPI Manufacturer ID
463 * @part_id: Device Part ID
464 * @class_id: MIPI Class ID (defined starting with SoundWire 1.2 spec)
465 * @unique_id: Device unique ID
466 * @sdw_version: SDW version implemented
468 * The order of the IDs here does not follow the DisCo spec definitions
470 struct sdw_slave_id {
478 struct sdw_peripherals {
480 struct sdw_slave *array[];
484 * Helper macros to extract the MIPI-defined IDs
487 * Register Bit Contents
488 * DevId_0 [7:4] 47:44 sdw_version
489 * DevId_0 [3:0] 43:40 unique_id
490 * DevId_1 39:32 mfg_id [15:8]
491 * DevId_2 31:24 mfg_id [7:0]
492 * DevId_3 23:16 part_id [15:8]
493 * DevId_4 15:08 part_id [7:0]
494 * DevId_5 07:00 class_id
496 * The MIPI DisCo for SoundWire defines in addition the link_id as bits 51:48
498 #define SDW_DISCO_LINK_ID_MASK GENMASK_ULL(51, 48)
499 #define SDW_VERSION_MASK GENMASK_ULL(47, 44)
500 #define SDW_UNIQUE_ID_MASK GENMASK_ULL(43, 40)
501 #define SDW_MFG_ID_MASK GENMASK_ULL(39, 24)
502 #define SDW_PART_ID_MASK GENMASK_ULL(23, 8)
503 #define SDW_CLASS_ID_MASK GENMASK_ULL(7, 0)
505 #define SDW_DISCO_LINK_ID(addr) FIELD_GET(SDW_DISCO_LINK_ID_MASK, addr)
506 #define SDW_VERSION(addr) FIELD_GET(SDW_VERSION_MASK, addr)
507 #define SDW_UNIQUE_ID(addr) FIELD_GET(SDW_UNIQUE_ID_MASK, addr)
508 #define SDW_MFG_ID(addr) FIELD_GET(SDW_MFG_ID_MASK, addr)
509 #define SDW_PART_ID(addr) FIELD_GET(SDW_PART_ID_MASK, addr)
510 #define SDW_CLASS_ID(addr) FIELD_GET(SDW_CLASS_ID_MASK, addr)
513 * struct sdw_slave_intr_status - Slave interrupt status
514 * @sdca_cascade: set if the Slave device reports an SDCA interrupt
515 * @control_port: control port status
516 * @port: data port status
518 struct sdw_slave_intr_status {
525 * sdw_reg_bank - SoundWire register banks
526 * @SDW_BANK0: Soundwire register bank 0
527 * @SDW_BANK1: Soundwire register bank 1
535 * struct sdw_prepare_ch: Prepare/De-prepare Data Port channel
538 * @ch_mask: Active channel mask
539 * @prepare: Prepare (true) /de-prepare (false) channel
540 * @bank: Register bank, which bank Slave/Master driver should program for
541 * implementation defined registers. This is always updated to next_bank
542 * value read from bus params.
545 struct sdw_prepare_ch {
547 unsigned int ch_mask;
553 * enum sdw_port_prep_ops: Prepare operations for Data Port
555 * @SDW_OPS_PORT_PRE_PREP: Pre prepare operation for the Port
556 * @SDW_OPS_PORT_PRE_DEPREP: Pre deprepare operation for the Port
557 * @SDW_OPS_PORT_POST_PREP: Post prepare operation for the Port
558 * @SDW_OPS_PORT_POST_DEPREP: Post deprepare operation for the Port
560 enum sdw_port_prep_ops {
561 SDW_OPS_PORT_PRE_PREP = 0,
562 SDW_OPS_PORT_PRE_DEPREP,
563 SDW_OPS_PORT_POST_PREP,
564 SDW_OPS_PORT_POST_DEPREP,
568 * struct sdw_bus_params: Structure holding bus configuration
570 * @curr_bank: Current bank in use (BANK0/BANK1)
571 * @next_bank: Next bank to use (BANK0/BANK1). next_bank will always be
573 * @max_dr_freq: Maximum double rate clock frequency supported, in Hz
574 * @curr_dr_freq: Current double rate clock frequency, in Hz
575 * @bandwidth: Current bandwidth
576 * @col: Active columns
578 * @s_data_mode: NORMAL, STATIC or PRBS mode for all Slave ports
579 * @m_data_mode: NORMAL, STATIC or PRBS mode for all Master ports. The value
580 * should be the same to detect transmission issues, but can be different to
581 * test the interrupt reports
583 struct sdw_bus_params {
584 enum sdw_reg_bank curr_bank;
585 enum sdw_reg_bank next_bank;
586 unsigned int max_dr_freq;
587 unsigned int curr_dr_freq;
588 unsigned int bandwidth;
596 * struct sdw_slave_ops: Slave driver callback ops
598 * @read_prop: Read Slave properties
599 * @interrupt_callback: Device interrupt notification (invoked in thread
601 * @update_status: Update Slave status
602 * @bus_config: Update the bus config for Slave
603 * @port_prep: Prepare the port with parameters
604 * @clk_stop: handle imp-def sequences before and after prepare and de-prepare
606 struct sdw_slave_ops {
607 int (*read_prop)(struct sdw_slave *sdw);
608 int (*interrupt_callback)(struct sdw_slave *slave,
609 struct sdw_slave_intr_status *status);
610 int (*update_status)(struct sdw_slave *slave,
611 enum sdw_slave_status status);
612 int (*bus_config)(struct sdw_slave *slave,
613 struct sdw_bus_params *params);
614 int (*port_prep)(struct sdw_slave *slave,
615 struct sdw_prepare_ch *prepare_ch,
616 enum sdw_port_prep_ops pre_ops);
617 int (*clk_stop)(struct sdw_slave *slave,
618 enum sdw_clk_stop_mode mode,
619 enum sdw_clk_stop_type type);
623 * struct sdw_slave - SoundWire Slave
624 * @id: MIPI device ID
627 * @status: Status reported by the Slave
629 * @prop: Slave properties
630 * @debugfs: Slave debugfs
631 * @node: node for bus list
632 * @port_ready: Port ready completion flag for each Slave port
633 * @m_port_map: static Master port map for each Slave port
634 * @dev_num: Current Device Number, values can be 0 or dev_num_sticky
635 * @dev_num_sticky: one-time static Device Number assigned by Bus
636 * @probed: boolean tracking driver state
637 * @enumeration_complete: completion utility to control potential races
638 * on startup between device enumeration and read/write access to the
640 * @initialization_complete: completion utility to control potential races
641 * on startup between device enumeration and settings being restored
642 * @unattach_request: mask field to keep track why the Slave re-attached and
643 * was re-initialized. This is useful to deal with potential race conditions
644 * between the Master suspending and the codec resuming, and make sure that
645 * when the Master triggered a reset the Slave is properly enumerated and
647 * @first_interrupt_done: status flag tracking if the interrupt handling
648 * for a Slave happens for the first time after enumeration
649 * @is_mockup_device: status flag used to squelch errors in the command/control
650 * protocol for SoundWire mockup devices
651 * @sdw_dev_lock: mutex used to protect callbacks/remove races
652 * @sdca_data: structure containing all device data for SDCA helpers
655 struct sdw_slave_id id;
658 enum sdw_slave_status status;
660 struct sdw_slave_prop prop;
661 #ifdef CONFIG_DEBUG_FS
662 struct dentry *debugfs;
664 struct list_head node;
665 struct completion port_ready[SDW_MAX_PORTS];
666 unsigned int m_port_map[SDW_MAX_PORTS];
670 struct completion enumeration_complete;
671 struct completion initialization_complete;
672 u32 unattach_request;
673 bool first_interrupt_done;
674 bool is_mockup_device;
675 struct mutex sdw_dev_lock; /* protect callbacks/remove races */
676 struct sdca_device_data sdca_data;
679 #define dev_to_sdw_dev(_dev) container_of(_dev, struct sdw_slave, dev)
682 * struct sdw_master_device - SoundWire 'Master Device' representation
683 * @dev: Linux device for this Master
684 * @bus: Bus handle shortcut
686 struct sdw_master_device {
691 #define dev_to_sdw_master_device(d) \
692 container_of(d, struct sdw_master_device, dev)
695 int (*probe)(struct sdw_slave *sdw, const struct sdw_device_id *id);
696 int (*remove)(struct sdw_slave *sdw);
697 void (*shutdown)(struct sdw_slave *sdw);
699 const struct sdw_device_id *id_table;
700 const struct sdw_slave_ops *ops;
702 struct device_driver driver;
705 #define SDW_SLAVE_ENTRY_EXT(_mfg_id, _part_id, _version, _c_id, _drv_data) \
706 { .mfg_id = (_mfg_id), .part_id = (_part_id), \
707 .sdw_version = (_version), .class_id = (_c_id), \
708 .driver_data = (unsigned long)(_drv_data) }
710 #define SDW_SLAVE_ENTRY(_mfg_id, _part_id, _drv_data) \
711 SDW_SLAVE_ENTRY_EXT((_mfg_id), (_part_id), 0, 0, (_drv_data))
713 int sdw_handle_slave_status(struct sdw_bus *bus,
714 enum sdw_slave_status status[]);
717 * SDW master structures and APIs
721 * struct sdw_port_params: Data Port parameters
724 * @bps: Word length of the Port
725 * @flow_mode: Port Data flow mode
726 * @data_mode: Test modes or normal mode
728 * This is used to program the Data Port based on Data Port stream
731 struct sdw_port_params {
734 unsigned int flow_mode;
735 unsigned int data_mode;
739 * struct sdw_transport_params: Data Port Transport Parameters
741 * @blk_grp_ctrl_valid: Port implements block group control
743 * @blk_grp_ctrl: Block group control value
744 * @sample_interval: Sample interval
745 * @offset1: Blockoffset of the payload data
746 * @offset2: Blockoffset of the payload data
747 * @hstart: Horizontal start of the payload data
748 * @hstop: Horizontal stop of the payload data
749 * @blk_pkg_mode: Block per channel or block per port
750 * @lane_ctrl: Data lane Port uses for Data transfer. Currently only single
751 * data lane is supported in bus
753 * This is used to program the Data Port based on Data Port transport
754 * parameters. All these parameters are banked and can be modified
755 * during a bank switch without any artifacts in audio stream.
757 struct sdw_transport_params {
758 bool blk_grp_ctrl_valid;
759 unsigned int port_num;
760 unsigned int blk_grp_ctrl;
761 unsigned int sample_interval;
762 unsigned int offset1;
763 unsigned int offset2;
766 unsigned int blk_pkg_mode;
767 unsigned int lane_ctrl;
771 * struct sdw_enable_ch: Enable/disable Data Port channel
774 * @ch_mask: Active channel mask
775 * @enable: Enable (true) /disable (false) channel
777 struct sdw_enable_ch {
778 unsigned int port_num;
779 unsigned int ch_mask;
784 * struct sdw_master_port_ops: Callback functions from bus to Master
785 * driver to set Master Data ports.
787 * @dpn_set_port_params: Set the Port parameters for the Master Port.
789 * @dpn_set_port_transport_params: Set transport parameters for the Master
790 * Port. Mandatory callback
791 * @dpn_port_prep: Port prepare operations for the Master Data Port.
792 * @dpn_port_enable_ch: Enable the channels of Master Port.
794 struct sdw_master_port_ops {
795 int (*dpn_set_port_params)(struct sdw_bus *bus,
796 struct sdw_port_params *port_params,
798 int (*dpn_set_port_transport_params)(struct sdw_bus *bus,
799 struct sdw_transport_params *transport_params,
800 enum sdw_reg_bank bank);
801 int (*dpn_port_prep)(struct sdw_bus *bus, struct sdw_prepare_ch *prepare_ch);
802 int (*dpn_port_enable_ch)(struct sdw_bus *bus,
803 struct sdw_enable_ch *enable_ch, unsigned int bank);
809 * struct sdw_defer - SDW deferred message
810 * @complete: message completion
812 * @length: message length
817 struct completion complete;
821 * struct sdw_master_ops - Master driver ops
822 * @read_prop: Read Master properties
823 * @override_adr: Override value read from firmware (quirk for buggy firmware)
824 * @xfer_msg: Transfer message callback
825 * @xfer_msg_defer: Defer version of transfer message callback. The message is handled with the
826 * bus struct @sdw_defer
827 * @set_bus_conf: Set the bus configuration
828 * @pre_bank_switch: Callback for pre bank switch
829 * @post_bank_switch: Callback for post bank switch
830 * @read_ping_status: Read status from PING frames, reported with two bits per Device.
831 * Bits 31:24 are reserved.
832 * @get_device_num: Callback for vendor-specific device_number allocation
833 * @put_device_num: Callback for vendor-specific device_number release
834 * @new_peripheral_assigned: Callback to handle enumeration of new peripheral.
836 struct sdw_master_ops {
837 int (*read_prop)(struct sdw_bus *bus);
838 u64 (*override_adr)(struct sdw_bus *bus, u64 addr);
839 enum sdw_command_response (*xfer_msg)(struct sdw_bus *bus, struct sdw_msg *msg);
840 enum sdw_command_response (*xfer_msg_defer)(struct sdw_bus *bus);
841 int (*set_bus_conf)(struct sdw_bus *bus,
842 struct sdw_bus_params *params);
843 int (*pre_bank_switch)(struct sdw_bus *bus);
844 int (*post_bank_switch)(struct sdw_bus *bus);
845 u32 (*read_ping_status)(struct sdw_bus *bus);
846 int (*get_device_num)(struct sdw_bus *bus, struct sdw_slave *slave);
847 void (*put_device_num)(struct sdw_bus *bus, struct sdw_slave *slave);
848 void (*new_peripheral_assigned)(struct sdw_bus *bus,
849 struct sdw_slave *slave,
854 * struct sdw_bus - SoundWire bus
855 * @dev: Shortcut to &bus->md->dev to avoid changing the entire code.
857 * @bus_lock_key: bus lock key associated to @bus_lock
858 * @bus_lock: bus lock
859 * @slaves: list of Slaves on this bus
860 * @msg_lock_key: message lock key associated to @msg_lock
861 * @msg_lock: message lock
862 * @m_rt_list: List of Master instance of all stream(s) running on Bus. This
863 * is used to compute and program bus bandwidth, clock, frame shape,
864 * transport and port parameters
865 * @defer_msg: Defer message
866 * @params: Current bus parameters
867 * @stream_refcount: number of streams currently using this bus
868 * @ops: Master callback ops
869 * @port_ops: Master port callback ops
870 * @prop: Master properties
871 * @vendor_specific_prop: pointer to non-standard properties
872 * @hw_sync_min_links: Number of links used by a stream above which
873 * hardware-based synchronization is required. This value is only
874 * meaningful if multi_link is set. If set to 1, hardware-based
875 * synchronization will be used even if a stream only uses a single
877 * @controller_id: system-unique controller ID. If set to -1, the bus @id will be used.
878 * @link_id: Link id number, can be 0 to N, unique for each Controller
879 * @id: bus system-wide unique id
880 * @compute_params: points to Bus resource management implementation
881 * @assigned: Bitmap for Slave device numbers.
882 * Bit set implies used number, bit clear implies unused number.
883 * @clk_stop_timeout: Clock stop timeout computed
884 * @bank_switch_timeout: Bank switch timeout computed
885 * @domain: IRQ domain
886 * @irq_chip: IRQ chip
887 * @debugfs: Bus debugfs (optional)
888 * @multi_link: Store bus property that indicates if multi links
889 * are supported. This flag is populated by drivers after reading
890 * appropriate firmware (ACPI/DT).
894 struct sdw_master_device *md;
895 struct lock_class_key bus_lock_key;
896 struct mutex bus_lock;
897 struct list_head slaves;
898 struct lock_class_key msg_lock_key;
899 struct mutex msg_lock;
900 struct list_head m_rt_list;
901 struct sdw_defer defer_msg;
902 struct sdw_bus_params params;
904 const struct sdw_master_ops *ops;
905 const struct sdw_master_port_ops *port_ops;
906 struct sdw_master_prop prop;
907 void *vendor_specific_prop;
908 int hw_sync_min_links;
910 unsigned int link_id;
912 int (*compute_params)(struct sdw_bus *bus);
913 DECLARE_BITMAP(assigned, SDW_MAX_DEVICES);
914 unsigned int clk_stop_timeout;
915 u32 bank_switch_timeout;
916 struct irq_chip irq_chip;
917 struct irq_domain *domain;
918 #ifdef CONFIG_DEBUG_FS
919 struct dentry *debugfs;
924 int sdw_bus_master_add(struct sdw_bus *bus, struct device *parent,
925 struct fwnode_handle *fwnode);
926 void sdw_bus_master_delete(struct sdw_bus *bus);
928 void sdw_show_ping_status(struct sdw_bus *bus, bool sync_delay);
931 * sdw_port_config: Master or Slave Port configuration
934 * @ch_mask: channels mask for port
936 struct sdw_port_config {
938 unsigned int ch_mask;
942 * sdw_stream_config: Master or Slave stream configuration
944 * @frame_rate: Audio frame rate of the stream, in Hz
945 * @ch_count: Channel count of the stream
946 * @bps: Number of bits per audio sample
947 * @direction: Data direction
948 * @type: Stream type PCM or PDM
950 struct sdw_stream_config {
951 unsigned int frame_rate;
952 unsigned int ch_count;
954 enum sdw_data_direction direction;
955 enum sdw_stream_type type;
959 * sdw_stream_state: Stream states
961 * @SDW_STREAM_ALLOCATED: New stream allocated.
962 * @SDW_STREAM_CONFIGURED: Stream configured
963 * @SDW_STREAM_PREPARED: Stream prepared
964 * @SDW_STREAM_ENABLED: Stream enabled
965 * @SDW_STREAM_DISABLED: Stream disabled
966 * @SDW_STREAM_DEPREPARED: Stream de-prepared
967 * @SDW_STREAM_RELEASED: Stream released
969 enum sdw_stream_state {
970 SDW_STREAM_ALLOCATED = 0,
971 SDW_STREAM_CONFIGURED = 1,
972 SDW_STREAM_PREPARED = 2,
973 SDW_STREAM_ENABLED = 3,
974 SDW_STREAM_DISABLED = 4,
975 SDW_STREAM_DEPREPARED = 5,
976 SDW_STREAM_RELEASED = 6,
980 * sdw_stream_params: Stream parameters
982 * @rate: Sampling frequency, in Hz
983 * @ch_count: Number of channels
984 * @bps: bits per channel sample
986 struct sdw_stream_params {
988 unsigned int ch_count;
993 * sdw_stream_runtime: Runtime stream parameters
995 * @name: SoundWire stream name
996 * @params: Stream parameters
997 * @state: Current state of the stream
998 * @type: Stream type PCM or PDM
999 * @m_rt_count: Count of Master runtime(s) in this stream
1000 * @master_list: List of Master runtime(s) in this stream.
1001 * master_list can contain only one m_rt per Master instance
1004 struct sdw_stream_runtime {
1006 struct sdw_stream_params params;
1007 enum sdw_stream_state state;
1008 enum sdw_stream_type type;
1010 struct list_head master_list;
1013 struct sdw_stream_runtime *sdw_alloc_stream(const char *stream_name);
1014 void sdw_release_stream(struct sdw_stream_runtime *stream);
1016 int sdw_compute_params(struct sdw_bus *bus);
1018 int sdw_stream_add_master(struct sdw_bus *bus,
1019 struct sdw_stream_config *stream_config,
1020 const struct sdw_port_config *port_config,
1021 unsigned int num_ports,
1022 struct sdw_stream_runtime *stream);
1023 int sdw_stream_remove_master(struct sdw_bus *bus,
1024 struct sdw_stream_runtime *stream);
1025 int sdw_startup_stream(void *sdw_substream);
1026 int sdw_prepare_stream(struct sdw_stream_runtime *stream);
1027 int sdw_enable_stream(struct sdw_stream_runtime *stream);
1028 int sdw_disable_stream(struct sdw_stream_runtime *stream);
1029 int sdw_deprepare_stream(struct sdw_stream_runtime *stream);
1030 void sdw_shutdown_stream(void *sdw_substream);
1031 int sdw_bus_prep_clk_stop(struct sdw_bus *bus);
1032 int sdw_bus_clk_stop(struct sdw_bus *bus);
1033 int sdw_bus_exit_clk_stop(struct sdw_bus *bus);
1035 int sdw_compare_devid(struct sdw_slave *slave, struct sdw_slave_id id);
1036 void sdw_extract_slave_id(struct sdw_bus *bus, u64 addr, struct sdw_slave_id *id);
1038 #if IS_ENABLED(CONFIG_SOUNDWIRE)
1040 int sdw_stream_add_slave(struct sdw_slave *slave,
1041 struct sdw_stream_config *stream_config,
1042 const struct sdw_port_config *port_config,
1043 unsigned int num_ports,
1044 struct sdw_stream_runtime *stream);
1045 int sdw_stream_remove_slave(struct sdw_slave *slave,
1046 struct sdw_stream_runtime *stream);
1048 /* messaging and data APIs */
1049 int sdw_read(struct sdw_slave *slave, u32 addr);
1050 int sdw_write(struct sdw_slave *slave, u32 addr, u8 value);
1051 int sdw_write_no_pm(struct sdw_slave *slave, u32 addr, u8 value);
1052 int sdw_read_no_pm(struct sdw_slave *slave, u32 addr);
1053 int sdw_nread(struct sdw_slave *slave, u32 addr, size_t count, u8 *val);
1054 int sdw_nread_no_pm(struct sdw_slave *slave, u32 addr, size_t count, u8 *val);
1055 int sdw_nwrite(struct sdw_slave *slave, u32 addr, size_t count, const u8 *val);
1056 int sdw_nwrite_no_pm(struct sdw_slave *slave, u32 addr, size_t count, const u8 *val);
1057 int sdw_update(struct sdw_slave *slave, u32 addr, u8 mask, u8 val);
1058 int sdw_update_no_pm(struct sdw_slave *slave, u32 addr, u8 mask, u8 val);
1062 static inline int sdw_stream_add_slave(struct sdw_slave *slave,
1063 struct sdw_stream_config *stream_config,
1064 const struct sdw_port_config *port_config,
1065 unsigned int num_ports,
1066 struct sdw_stream_runtime *stream)
1068 WARN_ONCE(1, "SoundWire API is disabled");
1072 static inline int sdw_stream_remove_slave(struct sdw_slave *slave,
1073 struct sdw_stream_runtime *stream)
1075 WARN_ONCE(1, "SoundWire API is disabled");
1079 /* messaging and data APIs */
1080 static inline int sdw_read(struct sdw_slave *slave, u32 addr)
1082 WARN_ONCE(1, "SoundWire API is disabled");
1086 static inline int sdw_write(struct sdw_slave *slave, u32 addr, u8 value)
1088 WARN_ONCE(1, "SoundWire API is disabled");
1092 static inline int sdw_write_no_pm(struct sdw_slave *slave, u32 addr, u8 value)
1094 WARN_ONCE(1, "SoundWire API is disabled");
1098 static inline int sdw_read_no_pm(struct sdw_slave *slave, u32 addr)
1100 WARN_ONCE(1, "SoundWire API is disabled");
1104 static inline int sdw_nread(struct sdw_slave *slave, u32 addr, size_t count, u8 *val)
1106 WARN_ONCE(1, "SoundWire API is disabled");
1110 static inline int sdw_nread_no_pm(struct sdw_slave *slave, u32 addr, size_t count, u8 *val)
1112 WARN_ONCE(1, "SoundWire API is disabled");
1116 static inline int sdw_nwrite(struct sdw_slave *slave, u32 addr, size_t count, const u8 *val)
1118 WARN_ONCE(1, "SoundWire API is disabled");
1122 static inline int sdw_nwrite_no_pm(struct sdw_slave *slave, u32 addr, size_t count, const u8 *val)
1124 WARN_ONCE(1, "SoundWire API is disabled");
1128 static inline int sdw_update(struct sdw_slave *slave, u32 addr, u8 mask, u8 val)
1130 WARN_ONCE(1, "SoundWire API is disabled");
1134 static inline int sdw_update_no_pm(struct sdw_slave *slave, u32 addr, u8 mask, u8 val)
1136 WARN_ONCE(1, "SoundWire API is disabled");
1140 #endif /* CONFIG_SOUNDWIRE */
1142 #endif /* __SOUNDWIRE_H */