1 /* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
2 /* Copyright(c) 2015-17 Intel Corporation. */
8 #include <linux/lockdep_types.h>
10 #include <linux/irqdomain.h>
11 #include <linux/mod_devicetable.h>
12 #include <linux/bitfield.h>
17 /* SDW spec defines and enums, as defined by MIPI 1.1. Spec */
19 /* SDW Broadcast Device Number */
20 #define SDW_BROADCAST_DEV_NUM 15
22 /* SDW Enumeration Device Number */
23 #define SDW_ENUM_DEV_NUM 0
25 /* SDW Group Device Numbers */
26 #define SDW_GROUP12_DEV_NUM 12
27 #define SDW_GROUP13_DEV_NUM 13
29 /* SDW Master Device Number, not supported yet */
30 #define SDW_MASTER_DEV_NUM 14
32 #define SDW_NUM_DEV_ID_REGISTERS 6
33 /* frame shape defines */
36 * Note: The maximum row define in SoundWire spec 1.1 is 23. In order to
37 * fill hole with 0, one more dummy entry is added
39 #define SDW_FRAME_ROWS 24
40 #define SDW_FRAME_COLS 8
41 #define SDW_FRAME_ROW_COLS (SDW_FRAME_ROWS * SDW_FRAME_COLS)
43 #define SDW_FRAME_CTRL_BITS 48
44 #define SDW_MAX_DEVICES 11
46 #define SDW_MAX_PORTS 15
47 #define SDW_VALID_PORT_RANGE(n) ((n) < SDW_MAX_PORTS && (n) >= 1)
50 SDW_PORT_DIRN_SINK = 0,
56 * constants for flow control, ports and transport
58 * these are bit masks as devices can have multiple capabilities
62 * flow modes for SDW port. These can be isochronous, tx controlled,
63 * rx controlled or async
65 #define SDW_PORT_FLOW_MODE_ISOCH 0
66 #define SDW_PORT_FLOW_MODE_TX_CNTRL BIT(0)
67 #define SDW_PORT_FLOW_MODE_RX_CNTRL BIT(1)
68 #define SDW_PORT_FLOW_MODE_ASYNC GENMASK(1, 0)
70 /* sample packaging for block. It can be per port or per channel */
71 #define SDW_BLOCK_PACKG_PER_PORT BIT(0)
72 #define SDW_BLOCK_PACKG_PER_CH BIT(1)
75 * enum sdw_slave_status - Slave status
76 * @SDW_SLAVE_UNATTACHED: Slave is not attached with the bus.
77 * @SDW_SLAVE_ATTACHED: Slave is attached with bus.
78 * @SDW_SLAVE_ALERT: Some alert condition on the Slave
79 * @SDW_SLAVE_RESERVED: Reserved for future use
81 enum sdw_slave_status {
82 SDW_SLAVE_UNATTACHED = 0,
83 SDW_SLAVE_ATTACHED = 1,
85 SDW_SLAVE_RESERVED = 3,
89 * enum sdw_clk_stop_type: clock stop operations
91 * @SDW_CLK_PRE_PREPARE: pre clock stop prepare
92 * @SDW_CLK_POST_PREPARE: post clock stop prepare
93 * @SDW_CLK_PRE_DEPREPARE: pre clock stop de-prepare
94 * @SDW_CLK_POST_DEPREPARE: post clock stop de-prepare
96 enum sdw_clk_stop_type {
97 SDW_CLK_PRE_PREPARE = 0,
99 SDW_CLK_PRE_DEPREPARE,
100 SDW_CLK_POST_DEPREPARE,
104 * enum sdw_command_response - Command response as defined by SDW spec
105 * @SDW_CMD_OK: cmd was successful
106 * @SDW_CMD_IGNORED: cmd was ignored
107 * @SDW_CMD_FAIL: cmd was NACKed
108 * @SDW_CMD_TIMEOUT: cmd timedout
109 * @SDW_CMD_FAIL_OTHER: cmd failed due to other reason than above
111 * NOTE: The enum is different than actual Spec as response in the Spec is
112 * combination of ACK/NAK bits
114 * SDW_CMD_TIMEOUT/FAIL_OTHER is defined for SW use, not in spec
116 enum sdw_command_response {
121 SDW_CMD_FAIL_OTHER = 4,
124 /* block group count enum */
125 enum sdw_dpn_grouping {
126 SDW_BLK_GRP_CNT_1 = 0,
127 SDW_BLK_GRP_CNT_2 = 1,
128 SDW_BLK_GRP_CNT_3 = 2,
129 SDW_BLK_GRP_CNT_4 = 3,
132 /* block packing mode enum */
133 enum sdw_dpn_pkg_mode {
134 SDW_BLK_PKG_PER_PORT = 0,
135 SDW_BLK_PKG_PER_CHANNEL = 1
139 * enum sdw_stream_type: data stream type
141 * @SDW_STREAM_PCM: PCM data stream
142 * @SDW_STREAM_PDM: PDM data stream
144 * spec doesn't define this, but is used in implementation
146 enum sdw_stream_type {
152 * enum sdw_data_direction: Data direction
154 * @SDW_DATA_DIR_RX: Data into Port
155 * @SDW_DATA_DIR_TX: Data out of Port
157 enum sdw_data_direction {
163 * enum sdw_port_data_mode: Data Port mode
165 * @SDW_PORT_DATA_MODE_NORMAL: Normal data mode where audio data is received
167 * @SDW_PORT_DATA_MODE_PRBS: Test mode which uses a PRBS generator to produce
168 * a pseudo random data pattern that is transferred
169 * @SDW_PORT_DATA_MODE_STATIC_0: Simple test mode which uses static value of
170 * logic 0. The encoding will result in no signal transitions
171 * @SDW_PORT_DATA_MODE_STATIC_1: Simple test mode which uses static value of
172 * logic 1. The encoding will result in signal transitions at every bitslot
175 enum sdw_port_data_mode {
176 SDW_PORT_DATA_MODE_NORMAL = 0,
177 SDW_PORT_DATA_MODE_PRBS = 1,
178 SDW_PORT_DATA_MODE_STATIC_0 = 2,
179 SDW_PORT_DATA_MODE_STATIC_1 = 3,
183 * SDW properties, defined in MIPI DisCo spec v1.0
185 enum sdw_clk_stop_reset_behave {
186 SDW_CLK_STOP_KEEP_STATUS = 1,
190 * enum sdw_p15_behave - Slave Port 15 behaviour when the Master attempts a
192 * @SDW_P15_READ_IGNORED: Read is ignored
193 * @SDW_P15_CMD_OK: Command is ok
195 enum sdw_p15_behave {
196 SDW_P15_READ_IGNORED = 0,
201 * enum sdw_dpn_type - Data port types
202 * @SDW_DPN_FULL: Full Data Port is supported
203 * @SDW_DPN_SIMPLE: Simplified Data Port as defined in spec.
204 * DPN_SampleCtrl2, DPN_OffsetCtrl2, DPN_HCtrl and DPN_BlockCtrl3
205 * are not implemented.
206 * @SDW_DPN_REDUCED: Reduced Data Port as defined in spec.
207 * DPN_SampleCtrl2, DPN_HCtrl are not implemented.
216 * enum sdw_clk_stop_mode - Clock Stop modes
217 * @SDW_CLK_STOP_MODE0: Slave can continue operation seamlessly on clock
219 * @SDW_CLK_STOP_MODE1: Slave may have entered a deeper power-saving mode,
220 * not capable of continuing operation seamlessly when the clock restarts
222 enum sdw_clk_stop_mode {
223 SDW_CLK_STOP_MODE0 = 0,
224 SDW_CLK_STOP_MODE1 = 1,
228 * struct sdw_dp0_prop - DP0 properties
229 * @max_word: Maximum number of bits in a Payload Channel Sample, 1 to 64
231 * @min_word: Minimum number of bits in a Payload Channel Sample, 1 to 64
233 * @num_words: number of wordlengths supported
234 * @words: wordlengths supported
235 * @BRA_flow_controlled: Slave implementation results in an OK_NotReady
237 * @simple_ch_prep_sm: If channel prepare sequence is required
238 * @ch_prep_timeout: Port-specific timeout value, in milliseconds
239 * @imp_def_interrupts: If set, each bit corresponds to support for
240 * implementation-defined interrupts
242 * The wordlengths are specified by Spec as max, min AND number of
243 * discrete values, implementation can define based on the wordlengths they
246 struct sdw_dp0_prop {
251 bool BRA_flow_controlled;
252 bool simple_ch_prep_sm;
254 bool imp_def_interrupts;
258 * struct sdw_dpn_audio_mode - Audio mode properties for DPn
259 * @bus_min_freq: Minimum bus frequency, in Hz
260 * @bus_max_freq: Maximum bus frequency, in Hz
261 * @bus_num_freq: Number of discrete frequencies supported
262 * @bus_freq: Discrete bus frequencies, in Hz
263 * @min_freq: Minimum sampling frequency, in Hz
264 * @max_freq: Maximum sampling bus frequency, in Hz
265 * @num_freq: Number of discrete sampling frequency supported
266 * @freq: Discrete sampling frequencies, in Hz
267 * @prep_ch_behave: Specifies the dependencies between Channel Prepare
268 * sequence and bus clock configuration
269 * If 0, Channel Prepare can happen at any Bus clock rate
270 * If 1, Channel Prepare sequence shall happen only after Bus clock is
271 * changed to a frequency supported by this mode or compatible modes
272 * described by the next field
273 * @glitchless: Bitmap describing possible glitchless transitions from this
274 * Audio Mode to other Audio Modes
276 struct sdw_dpn_audio_mode {
290 * struct sdw_dpn_prop - Data Port DPn properties
292 * @max_word: Maximum number of bits in a Payload Channel Sample, 1 to 64
294 * @min_word: Minimum number of bits in a Payload Channel Sample, 1 to 64
296 * @num_words: Number of discrete supported wordlengths
297 * @words: Discrete supported wordlength
298 * @type: Data port type. Full, Simplified or Reduced
299 * @max_grouping: Maximum number of samples that can be grouped together for
301 * @simple_ch_prep_sm: If the port supports simplified channel prepare state
303 * @ch_prep_timeout: Port-specific timeout value, in milliseconds
304 * @imp_def_interrupts: If set, each bit corresponds to support for
305 * implementation-defined interrupts
306 * @max_ch: Maximum channels supported
307 * @min_ch: Minimum channels supported
308 * @num_channels: Number of discrete channels supported
309 * @channels: Discrete channels supported
310 * @num_ch_combinations: Number of channel combinations supported
311 * @ch_combinations: Channel combinations supported
312 * @modes: SDW mode supported
313 * @max_async_buffer: Number of samples that this port can buffer in
315 * @block_pack_mode: Type of block port mode supported
316 * @read_only_wordlength: Read Only wordlength field in DPN_BlockCtrl1 register
317 * @port_encoding: Payload Channel Sample encoding schemes supported
318 * @audio_modes: Audio modes supported
320 struct sdw_dpn_prop {
326 enum sdw_dpn_type type;
328 bool simple_ch_prep_sm;
330 u32 imp_def_interrupts;
335 u32 num_ch_combinations;
336 u32 *ch_combinations;
338 u32 max_async_buffer;
339 bool block_pack_mode;
340 bool read_only_wordlength;
342 struct sdw_dpn_audio_mode *audio_modes;
346 * struct sdw_slave_prop - SoundWire Slave properties
347 * @mipi_revision: Spec version of the implementation
348 * @wake_capable: Wake-up events are supported
349 * @test_mode_capable: If test mode is supported
350 * @clk_stop_mode1: Clock-Stop Mode 1 is supported
351 * @simple_clk_stop_capable: Simple clock mode is supported
352 * @clk_stop_timeout: Worst-case latency of the Clock Stop Prepare State
353 * Machine transitions, in milliseconds
354 * @ch_prep_timeout: Worst-case latency of the Channel Prepare State Machine
355 * transitions, in milliseconds
356 * @reset_behave: Slave keeps the status of the SlaveStopClockPrepare
357 * state machine (P=1 SCSP_SM) after exit from clock-stop mode1
358 * @high_PHY_capable: Slave is HighPHY capable
359 * @paging_support: Slave implements paging registers SCP_AddrPage1 and
361 * @bank_delay_support: Slave implements bank delay/bridge support registers
362 * SCP_BankDelay and SCP_NextFrame
363 * @p15_behave: Slave behavior when the Master attempts a read to the Port15
365 * @lane_control_support: Slave supports lane control
366 * @master_count: Number of Masters present on this Slave
367 * @source_ports: Bitmap identifying source ports
368 * @sink_ports: Bitmap identifying sink ports
369 * @dp0_prop: Data Port 0 properties
370 * @src_dpn_prop: Source Data Port N properties
371 * @sink_dpn_prop: Sink Data Port N properties
372 * @scp_int1_mask: SCP_INT1_MASK desired settings
373 * @quirks: bitmask identifying deltas from the MIPI specification
374 * @clock_reg_supported: the Peripheral implements the clock base and scale
375 * registers introduced with the SoundWire 1.2 specification. SDCA devices
376 * do not need to set this boolean property as the registers are required.
377 * @use_domain_irq: call actual IRQ handler on slave, as well as callback
379 struct sdw_slave_prop {
382 bool test_mode_capable;
384 bool simple_clk_stop_capable;
385 u32 clk_stop_timeout;
387 enum sdw_clk_stop_reset_behave reset_behave;
388 bool high_PHY_capable;
390 bool bank_delay_support;
391 enum sdw_p15_behave p15_behave;
392 bool lane_control_support;
396 struct sdw_dp0_prop *dp0_prop;
397 struct sdw_dpn_prop *src_dpn_prop;
398 struct sdw_dpn_prop *sink_dpn_prop;
401 bool clock_reg_supported;
405 #define SDW_SLAVE_QUIRKS_INVALID_INITIAL_PARITY BIT(0)
408 * struct sdw_master_prop - Master properties
409 * @revision: MIPI spec version of the implementation
410 * @clk_stop_modes: Bitmap, bit N set when clock-stop-modeN supported
411 * @max_clk_freq: Maximum Bus clock frequency, in Hz
412 * @num_clk_gears: Number of clock gears supported
413 * @clk_gears: Clock gears supported
414 * @num_clk_freq: Number of clock frequencies supported, in Hz
415 * @clk_freq: Clock frequencies supported, in Hz
416 * @default_frame_rate: Controller default Frame rate, in Hz
417 * @default_row: Number of rows
418 * @default_col: Number of columns
419 * @dynamic_frame: Dynamic frame shape supported
420 * @err_threshold: Number of times that software may retry sending a single
422 * @mclk_freq: clock reference passed to SoundWire Master, in Hz.
423 * @hw_disabled: if true, the Master is not functional, typically due to pin-mux
424 * @quirks: bitmask identifying optional behavior beyond the scope of the MIPI specification
426 struct sdw_master_prop {
434 u32 default_frame_rate;
444 /* Definitions for Master quirks */
447 * In a number of platforms bus clashes are reported after a hardware
448 * reset but without any explanations or evidence of a real problem.
449 * The following quirk will discard all initial bus clash interrupts
450 * but will leave the detection on should real bus clashes happen
452 #define SDW_MASTER_QUIRKS_CLEAR_INITIAL_CLASH BIT(0)
455 * Some Slave devices have known issues with incorrect parity errors
456 * reported after a hardware reset. However during integration unexplained
457 * parity errors can be reported by Slave devices, possibly due to electrical
458 * issues at the Master level.
459 * The following quirk will discard all initial parity errors but will leave
460 * the detection on should real parity errors happen.
462 #define SDW_MASTER_QUIRKS_CLEAR_INITIAL_PARITY BIT(1)
464 int sdw_master_read_prop(struct sdw_bus *bus);
465 int sdw_slave_read_prop(struct sdw_slave *slave);
468 * SDW Slave Structures and APIs
471 #define SDW_IGNORED_UNIQUE_ID 0xFF
474 * struct sdw_slave_id - Slave ID
475 * @mfg_id: MIPI Manufacturer ID
476 * @part_id: Device Part ID
477 * @class_id: MIPI Class ID (defined starting with SoundWire 1.2 spec)
478 * @unique_id: Device unique ID
479 * @sdw_version: SDW version implemented
481 * The order of the IDs here does not follow the DisCo spec definitions
483 struct sdw_slave_id {
491 struct sdw_extended_slave_id {
493 struct sdw_slave_id id;
497 * Helper macros to extract the MIPI-defined IDs
500 * Register Bit Contents
501 * DevId_0 [7:4] 47:44 sdw_version
502 * DevId_0 [3:0] 43:40 unique_id
503 * DevId_1 39:32 mfg_id [15:8]
504 * DevId_2 31:24 mfg_id [7:0]
505 * DevId_3 23:16 part_id [15:8]
506 * DevId_4 15:08 part_id [7:0]
507 * DevId_5 07:00 class_id
509 * The MIPI DisCo for SoundWire defines in addition the link_id as bits 51:48
511 #define SDW_DISCO_LINK_ID_MASK GENMASK_ULL(51, 48)
512 #define SDW_VERSION_MASK GENMASK_ULL(47, 44)
513 #define SDW_UNIQUE_ID_MASK GENMASK_ULL(43, 40)
514 #define SDW_MFG_ID_MASK GENMASK_ULL(39, 24)
515 #define SDW_PART_ID_MASK GENMASK_ULL(23, 8)
516 #define SDW_CLASS_ID_MASK GENMASK_ULL(7, 0)
518 #define SDW_DISCO_LINK_ID(addr) FIELD_GET(SDW_DISCO_LINK_ID_MASK, addr)
519 #define SDW_VERSION(addr) FIELD_GET(SDW_VERSION_MASK, addr)
520 #define SDW_UNIQUE_ID(addr) FIELD_GET(SDW_UNIQUE_ID_MASK, addr)
521 #define SDW_MFG_ID(addr) FIELD_GET(SDW_MFG_ID_MASK, addr)
522 #define SDW_PART_ID(addr) FIELD_GET(SDW_PART_ID_MASK, addr)
523 #define SDW_CLASS_ID(addr) FIELD_GET(SDW_CLASS_ID_MASK, addr)
526 * struct sdw_slave_intr_status - Slave interrupt status
527 * @sdca_cascade: set if the Slave device reports an SDCA interrupt
528 * @control_port: control port status
529 * @port: data port status
531 struct sdw_slave_intr_status {
538 * sdw_reg_bank - SoundWire register banks
539 * @SDW_BANK0: Soundwire register bank 0
540 * @SDW_BANK1: Soundwire register bank 1
548 * struct sdw_prepare_ch: Prepare/De-prepare Data Port channel
551 * @ch_mask: Active channel mask
552 * @prepare: Prepare (true) /de-prepare (false) channel
553 * @bank: Register bank, which bank Slave/Master driver should program for
554 * implementation defined registers. This is always updated to next_bank
555 * value read from bus params.
558 struct sdw_prepare_ch {
560 unsigned int ch_mask;
566 * enum sdw_port_prep_ops: Prepare operations for Data Port
568 * @SDW_OPS_PORT_PRE_PREP: Pre prepare operation for the Port
569 * @SDW_OPS_PORT_PRE_DEPREP: Pre deprepare operation for the Port
570 * @SDW_OPS_PORT_POST_PREP: Post prepare operation for the Port
571 * @SDW_OPS_PORT_POST_DEPREP: Post deprepare operation for the Port
573 enum sdw_port_prep_ops {
574 SDW_OPS_PORT_PRE_PREP = 0,
575 SDW_OPS_PORT_PRE_DEPREP,
576 SDW_OPS_PORT_POST_PREP,
577 SDW_OPS_PORT_POST_DEPREP,
581 * struct sdw_bus_params: Structure holding bus configuration
583 * @curr_bank: Current bank in use (BANK0/BANK1)
584 * @next_bank: Next bank to use (BANK0/BANK1). next_bank will always be
586 * @max_dr_freq: Maximum double rate clock frequency supported, in Hz
587 * @curr_dr_freq: Current double rate clock frequency, in Hz
588 * @bandwidth: Current bandwidth
589 * @col: Active columns
591 * @s_data_mode: NORMAL, STATIC or PRBS mode for all Slave ports
592 * @m_data_mode: NORMAL, STATIC or PRBS mode for all Master ports. The value
593 * should be the same to detect transmission issues, but can be different to
594 * test the interrupt reports
596 struct sdw_bus_params {
597 enum sdw_reg_bank curr_bank;
598 enum sdw_reg_bank next_bank;
599 unsigned int max_dr_freq;
600 unsigned int curr_dr_freq;
601 unsigned int bandwidth;
609 * struct sdw_slave_ops: Slave driver callback ops
611 * @read_prop: Read Slave properties
612 * @interrupt_callback: Device interrupt notification (invoked in thread
614 * @update_status: Update Slave status
615 * @bus_config: Update the bus config for Slave
616 * @port_prep: Prepare the port with parameters
617 * @clk_stop: handle imp-def sequences before and after prepare and de-prepare
619 struct sdw_slave_ops {
620 int (*read_prop)(struct sdw_slave *sdw);
621 int (*interrupt_callback)(struct sdw_slave *slave,
622 struct sdw_slave_intr_status *status);
623 int (*update_status)(struct sdw_slave *slave,
624 enum sdw_slave_status status);
625 int (*bus_config)(struct sdw_slave *slave,
626 struct sdw_bus_params *params);
627 int (*port_prep)(struct sdw_slave *slave,
628 struct sdw_prepare_ch *prepare_ch,
629 enum sdw_port_prep_ops pre_ops);
630 int (*clk_stop)(struct sdw_slave *slave,
631 enum sdw_clk_stop_mode mode,
632 enum sdw_clk_stop_type type);
637 * struct sdw_slave - SoundWire Slave
638 * @id: MIPI device ID
641 * @status: Status reported by the Slave
643 * @prop: Slave properties
644 * @debugfs: Slave debugfs
645 * @node: node for bus list
646 * @port_ready: Port ready completion flag for each Slave port
647 * @m_port_map: static Master port map for each Slave port
648 * @dev_num: Current Device Number, values can be 0 or dev_num_sticky
649 * @dev_num_sticky: one-time static Device Number assigned by Bus
650 * @probed: boolean tracking driver state
651 * @enumeration_complete: completion utility to control potential races
652 * on startup between device enumeration and read/write access to the
654 * @initialization_complete: completion utility to control potential races
655 * on startup between device enumeration and settings being restored
656 * @unattach_request: mask field to keep track why the Slave re-attached and
657 * was re-initialized. This is useful to deal with potential race conditions
658 * between the Master suspending and the codec resuming, and make sure that
659 * when the Master triggered a reset the Slave is properly enumerated and
661 * @first_interrupt_done: status flag tracking if the interrupt handling
662 * for a Slave happens for the first time after enumeration
663 * @is_mockup_device: status flag used to squelch errors in the command/control
664 * protocol for SoundWire mockup devices
665 * @sdw_dev_lock: mutex used to protect callbacks/remove races
668 struct sdw_slave_id id;
671 enum sdw_slave_status status;
673 struct sdw_slave_prop prop;
674 #ifdef CONFIG_DEBUG_FS
675 struct dentry *debugfs;
677 struct list_head node;
678 struct completion port_ready[SDW_MAX_PORTS];
679 unsigned int m_port_map[SDW_MAX_PORTS];
683 struct completion enumeration_complete;
684 struct completion initialization_complete;
685 u32 unattach_request;
686 bool first_interrupt_done;
687 bool is_mockup_device;
688 struct mutex sdw_dev_lock; /* protect callbacks/remove races */
691 #define dev_to_sdw_dev(_dev) container_of(_dev, struct sdw_slave, dev)
694 * struct sdw_master_device - SoundWire 'Master Device' representation
695 * @dev: Linux device for this Master
696 * @bus: Bus handle shortcut
698 struct sdw_master_device {
703 #define dev_to_sdw_master_device(d) \
704 container_of(d, struct sdw_master_device, dev)
709 int (*probe)(struct sdw_slave *sdw,
710 const struct sdw_device_id *id);
711 int (*remove)(struct sdw_slave *sdw);
712 void (*shutdown)(struct sdw_slave *sdw);
714 const struct sdw_device_id *id_table;
715 const struct sdw_slave_ops *ops;
717 struct device_driver driver;
720 #define SDW_SLAVE_ENTRY_EXT(_mfg_id, _part_id, _version, _c_id, _drv_data) \
721 { .mfg_id = (_mfg_id), .part_id = (_part_id), \
722 .sdw_version = (_version), .class_id = (_c_id), \
723 .driver_data = (unsigned long)(_drv_data) }
725 #define SDW_SLAVE_ENTRY(_mfg_id, _part_id, _drv_data) \
726 SDW_SLAVE_ENTRY_EXT((_mfg_id), (_part_id), 0, 0, (_drv_data))
728 int sdw_handle_slave_status(struct sdw_bus *bus,
729 enum sdw_slave_status status[]);
732 * SDW master structures and APIs
736 * struct sdw_port_params: Data Port parameters
739 * @bps: Word length of the Port
740 * @flow_mode: Port Data flow mode
741 * @data_mode: Test modes or normal mode
743 * This is used to program the Data Port based on Data Port stream
746 struct sdw_port_params {
749 unsigned int flow_mode;
750 unsigned int data_mode;
754 * struct sdw_transport_params: Data Port Transport Parameters
756 * @blk_grp_ctrl_valid: Port implements block group control
758 * @blk_grp_ctrl: Block group control value
759 * @sample_interval: Sample interval
760 * @offset1: Blockoffset of the payload data
761 * @offset2: Blockoffset of the payload data
762 * @hstart: Horizontal start of the payload data
763 * @hstop: Horizontal stop of the payload data
764 * @blk_pkg_mode: Block per channel or block per port
765 * @lane_ctrl: Data lane Port uses for Data transfer. Currently only single
766 * data lane is supported in bus
768 * This is used to program the Data Port based on Data Port transport
769 * parameters. All these parameters are banked and can be modified
770 * during a bank switch without any artifacts in audio stream.
772 struct sdw_transport_params {
773 bool blk_grp_ctrl_valid;
774 unsigned int port_num;
775 unsigned int blk_grp_ctrl;
776 unsigned int sample_interval;
777 unsigned int offset1;
778 unsigned int offset2;
781 unsigned int blk_pkg_mode;
782 unsigned int lane_ctrl;
786 * struct sdw_enable_ch: Enable/disable Data Port channel
789 * @ch_mask: Active channel mask
790 * @enable: Enable (true) /disable (false) channel
792 struct sdw_enable_ch {
793 unsigned int port_num;
794 unsigned int ch_mask;
799 * struct sdw_master_port_ops: Callback functions from bus to Master
800 * driver to set Master Data ports.
802 * @dpn_set_port_params: Set the Port parameters for the Master Port.
804 * @dpn_set_port_transport_params: Set transport parameters for the Master
805 * Port. Mandatory callback
806 * @dpn_port_prep: Port prepare operations for the Master Data Port.
807 * @dpn_port_enable_ch: Enable the channels of Master Port.
809 struct sdw_master_port_ops {
810 int (*dpn_set_port_params)(struct sdw_bus *bus,
811 struct sdw_port_params *port_params,
813 int (*dpn_set_port_transport_params)(struct sdw_bus *bus,
814 struct sdw_transport_params *transport_params,
815 enum sdw_reg_bank bank);
816 int (*dpn_port_prep)(struct sdw_bus *bus,
817 struct sdw_prepare_ch *prepare_ch);
818 int (*dpn_port_enable_ch)(struct sdw_bus *bus,
819 struct sdw_enable_ch *enable_ch, unsigned int bank);
825 * struct sdw_defer - SDW deffered message
826 * @length: message length
827 * @complete: message completion
832 struct completion complete;
837 * struct sdw_master_ops - Master driver ops
838 * @read_prop: Read Master properties
839 * @override_adr: Override value read from firmware (quirk for buggy firmware)
840 * @xfer_msg: Transfer message callback
841 * @xfer_msg_defer: Defer version of transfer message callback. The message is handled with the
842 * bus struct @sdw_defer
843 * @set_bus_conf: Set the bus configuration
844 * @pre_bank_switch: Callback for pre bank switch
845 * @post_bank_switch: Callback for post bank switch
846 * @read_ping_status: Read status from PING frames, reported with two bits per Device.
847 * Bits 31:24 are reserved.
848 * @get_device_num: Callback for vendor-specific device_number allocation
849 * @put_device_num: Callback for vendor-specific device_number release
850 * @new_peripheral_assigned: Callback to handle enumeration of new peripheral.
852 struct sdw_master_ops {
853 int (*read_prop)(struct sdw_bus *bus);
855 (struct sdw_bus *bus, u64 addr);
856 enum sdw_command_response (*xfer_msg)
857 (struct sdw_bus *bus, struct sdw_msg *msg);
858 enum sdw_command_response (*xfer_msg_defer)
859 (struct sdw_bus *bus);
860 int (*set_bus_conf)(struct sdw_bus *bus,
861 struct sdw_bus_params *params);
862 int (*pre_bank_switch)(struct sdw_bus *bus);
863 int (*post_bank_switch)(struct sdw_bus *bus);
864 u32 (*read_ping_status)(struct sdw_bus *bus);
865 int (*get_device_num)(struct sdw_bus *bus, struct sdw_slave *slave);
866 void (*put_device_num)(struct sdw_bus *bus, struct sdw_slave *slave);
867 void (*new_peripheral_assigned)(struct sdw_bus *bus,
868 struct sdw_slave *slave,
873 * struct sdw_bus - SoundWire bus
874 * @dev: Shortcut to &bus->md->dev to avoid changing the entire code.
876 * @controller_id: system-unique controller ID. If set to -1, the bus @id will be used.
877 * @link_id: Link id number, can be 0 to N, unique for each Controller
878 * @id: bus system-wide unique id
879 * @slaves: list of Slaves on this bus
880 * @assigned: Bitmap for Slave device numbers.
881 * Bit set implies used number, bit clear implies unused number.
882 * @bus_lock: bus lock
883 * @msg_lock: message lock
884 * @compute_params: points to Bus resource management implementation
885 * @ops: Master callback ops
886 * @port_ops: Master port callback ops
887 * @params: Current bus parameters
888 * @prop: Master properties
889 * @vendor_specific_prop: pointer to non-standard properties
890 * @m_rt_list: List of Master instance of all stream(s) running on Bus. This
891 * is used to compute and program bus bandwidth, clock, frame shape,
892 * transport and port parameters
893 * @debugfs: Bus debugfs
894 * @domain: IRQ domain
895 * @defer_msg: Defer message
896 * @clk_stop_timeout: Clock stop timeout computed
897 * @bank_switch_timeout: Bank switch timeout computed
898 * @multi_link: Store bus property that indicates if multi links
899 * are supported. This flag is populated by drivers after reading
900 * appropriate firmware (ACPI/DT).
901 * @hw_sync_min_links: Number of links used by a stream above which
902 * hardware-based synchronization is required. This value is only
903 * meaningful if multi_link is set. If set to 1, hardware-based
904 * synchronization will be used even if a stream only uses a single
909 struct sdw_master_device *md;
911 unsigned int link_id;
913 struct list_head slaves;
914 DECLARE_BITMAP(assigned, SDW_MAX_DEVICES);
915 struct mutex bus_lock;
916 struct lock_class_key bus_lock_key;
917 struct mutex msg_lock;
918 struct lock_class_key msg_lock_key;
919 int (*compute_params)(struct sdw_bus *bus);
920 const struct sdw_master_ops *ops;
921 const struct sdw_master_port_ops *port_ops;
922 struct sdw_bus_params params;
923 struct sdw_master_prop prop;
924 void *vendor_specific_prop;
925 struct list_head m_rt_list;
926 #ifdef CONFIG_DEBUG_FS
927 struct dentry *debugfs;
929 struct irq_chip irq_chip;
930 struct irq_domain *domain;
931 struct sdw_defer defer_msg;
932 unsigned int clk_stop_timeout;
933 u32 bank_switch_timeout;
935 int hw_sync_min_links;
938 int sdw_bus_master_add(struct sdw_bus *bus, struct device *parent,
939 struct fwnode_handle *fwnode);
940 void sdw_bus_master_delete(struct sdw_bus *bus);
942 void sdw_show_ping_status(struct sdw_bus *bus, bool sync_delay);
945 * sdw_port_config: Master or Slave Port configuration
948 * @ch_mask: channels mask for port
950 struct sdw_port_config {
952 unsigned int ch_mask;
956 * sdw_stream_config: Master or Slave stream configuration
958 * @frame_rate: Audio frame rate of the stream, in Hz
959 * @ch_count: Channel count of the stream
960 * @bps: Number of bits per audio sample
961 * @direction: Data direction
962 * @type: Stream type PCM or PDM
964 struct sdw_stream_config {
965 unsigned int frame_rate;
966 unsigned int ch_count;
968 enum sdw_data_direction direction;
969 enum sdw_stream_type type;
973 * sdw_stream_state: Stream states
975 * @SDW_STREAM_ALLOCATED: New stream allocated.
976 * @SDW_STREAM_CONFIGURED: Stream configured
977 * @SDW_STREAM_PREPARED: Stream prepared
978 * @SDW_STREAM_ENABLED: Stream enabled
979 * @SDW_STREAM_DISABLED: Stream disabled
980 * @SDW_STREAM_DEPREPARED: Stream de-prepared
981 * @SDW_STREAM_RELEASED: Stream released
983 enum sdw_stream_state {
984 SDW_STREAM_ALLOCATED = 0,
985 SDW_STREAM_CONFIGURED = 1,
986 SDW_STREAM_PREPARED = 2,
987 SDW_STREAM_ENABLED = 3,
988 SDW_STREAM_DISABLED = 4,
989 SDW_STREAM_DEPREPARED = 5,
990 SDW_STREAM_RELEASED = 6,
994 * sdw_stream_params: Stream parameters
996 * @rate: Sampling frequency, in Hz
997 * @ch_count: Number of channels
998 * @bps: bits per channel sample
1000 struct sdw_stream_params {
1002 unsigned int ch_count;
1007 * sdw_stream_runtime: Runtime stream parameters
1009 * @name: SoundWire stream name
1010 * @params: Stream parameters
1011 * @state: Current state of the stream
1012 * @type: Stream type PCM or PDM
1013 * @master_list: List of Master runtime(s) in this stream.
1014 * master_list can contain only one m_rt per Master instance
1016 * @m_rt_count: Count of Master runtime(s) in this stream
1018 struct sdw_stream_runtime {
1020 struct sdw_stream_params params;
1021 enum sdw_stream_state state;
1022 enum sdw_stream_type type;
1023 struct list_head master_list;
1027 struct sdw_stream_runtime *sdw_alloc_stream(const char *stream_name);
1028 void sdw_release_stream(struct sdw_stream_runtime *stream);
1030 int sdw_compute_params(struct sdw_bus *bus);
1032 int sdw_stream_add_master(struct sdw_bus *bus,
1033 struct sdw_stream_config *stream_config,
1034 const struct sdw_port_config *port_config,
1035 unsigned int num_ports,
1036 struct sdw_stream_runtime *stream);
1037 int sdw_stream_remove_master(struct sdw_bus *bus,
1038 struct sdw_stream_runtime *stream);
1039 int sdw_startup_stream(void *sdw_substream);
1040 int sdw_prepare_stream(struct sdw_stream_runtime *stream);
1041 int sdw_enable_stream(struct sdw_stream_runtime *stream);
1042 int sdw_disable_stream(struct sdw_stream_runtime *stream);
1043 int sdw_deprepare_stream(struct sdw_stream_runtime *stream);
1044 void sdw_shutdown_stream(void *sdw_substream);
1045 int sdw_bus_prep_clk_stop(struct sdw_bus *bus);
1046 int sdw_bus_clk_stop(struct sdw_bus *bus);
1047 int sdw_bus_exit_clk_stop(struct sdw_bus *bus);
1049 int sdw_compare_devid(struct sdw_slave *slave, struct sdw_slave_id id);
1050 void sdw_extract_slave_id(struct sdw_bus *bus, u64 addr, struct sdw_slave_id *id);
1052 #if IS_ENABLED(CONFIG_SOUNDWIRE)
1054 int sdw_stream_add_slave(struct sdw_slave *slave,
1055 struct sdw_stream_config *stream_config,
1056 const struct sdw_port_config *port_config,
1057 unsigned int num_ports,
1058 struct sdw_stream_runtime *stream);
1059 int sdw_stream_remove_slave(struct sdw_slave *slave,
1060 struct sdw_stream_runtime *stream);
1062 /* messaging and data APIs */
1063 int sdw_read(struct sdw_slave *slave, u32 addr);
1064 int sdw_write(struct sdw_slave *slave, u32 addr, u8 value);
1065 int sdw_write_no_pm(struct sdw_slave *slave, u32 addr, u8 value);
1066 int sdw_read_no_pm(struct sdw_slave *slave, u32 addr);
1067 int sdw_nread(struct sdw_slave *slave, u32 addr, size_t count, u8 *val);
1068 int sdw_nread_no_pm(struct sdw_slave *slave, u32 addr, size_t count, u8 *val);
1069 int sdw_nwrite(struct sdw_slave *slave, u32 addr, size_t count, const u8 *val);
1070 int sdw_nwrite_no_pm(struct sdw_slave *slave, u32 addr, size_t count, const u8 *val);
1071 int sdw_update(struct sdw_slave *slave, u32 addr, u8 mask, u8 val);
1072 int sdw_update_no_pm(struct sdw_slave *slave, u32 addr, u8 mask, u8 val);
1076 static inline int sdw_stream_add_slave(struct sdw_slave *slave,
1077 struct sdw_stream_config *stream_config,
1078 const struct sdw_port_config *port_config,
1079 unsigned int num_ports,
1080 struct sdw_stream_runtime *stream)
1082 WARN_ONCE(1, "SoundWire API is disabled");
1086 static inline int sdw_stream_remove_slave(struct sdw_slave *slave,
1087 struct sdw_stream_runtime *stream)
1089 WARN_ONCE(1, "SoundWire API is disabled");
1093 /* messaging and data APIs */
1094 static inline int sdw_read(struct sdw_slave *slave, u32 addr)
1096 WARN_ONCE(1, "SoundWire API is disabled");
1100 static inline int sdw_write(struct sdw_slave *slave, u32 addr, u8 value)
1102 WARN_ONCE(1, "SoundWire API is disabled");
1106 static inline int sdw_write_no_pm(struct sdw_slave *slave, u32 addr, u8 value)
1108 WARN_ONCE(1, "SoundWire API is disabled");
1112 static inline int sdw_read_no_pm(struct sdw_slave *slave, u32 addr)
1114 WARN_ONCE(1, "SoundWire API is disabled");
1118 static inline int sdw_nread(struct sdw_slave *slave, u32 addr, size_t count, u8 *val)
1120 WARN_ONCE(1, "SoundWire API is disabled");
1124 static inline int sdw_nread_no_pm(struct sdw_slave *slave, u32 addr, size_t count, u8 *val)
1126 WARN_ONCE(1, "SoundWire API is disabled");
1130 static inline int sdw_nwrite(struct sdw_slave *slave, u32 addr, size_t count, const u8 *val)
1132 WARN_ONCE(1, "SoundWire API is disabled");
1136 static inline int sdw_nwrite_no_pm(struct sdw_slave *slave, u32 addr, size_t count, const u8 *val)
1138 WARN_ONCE(1, "SoundWire API is disabled");
1142 static inline int sdw_update(struct sdw_slave *slave, u32 addr, u8 mask, u8 val)
1144 WARN_ONCE(1, "SoundWire API is disabled");
1148 static inline int sdw_update_no_pm(struct sdw_slave *slave, u32 addr, u8 mask, u8 val)
1150 WARN_ONCE(1, "SoundWire API is disabled");
1154 #endif /* CONFIG_SOUNDWIRE */
1156 #endif /* __SOUNDWIRE_H */