1 /* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
2 /* Copyright(c) 2015-17 Intel Corporation. */
7 #include <linux/mod_devicetable.h>
12 /* SDW spec defines and enums, as defined by MIPI 1.1. Spec */
14 /* SDW Broadcast Device Number */
15 #define SDW_BROADCAST_DEV_NUM 15
17 /* SDW Enumeration Device Number */
18 #define SDW_ENUM_DEV_NUM 0
20 /* SDW Group Device Numbers */
21 #define SDW_GROUP12_DEV_NUM 12
22 #define SDW_GROUP13_DEV_NUM 13
24 /* SDW Master Device Number, not supported yet */
25 #define SDW_MASTER_DEV_NUM 14
27 #define SDW_NUM_DEV_ID_REGISTERS 6
28 /* frame shape defines */
31 * Note: The maximum row define in SoundWire spec 1.1 is 23. In order to
32 * fill hole with 0, one more dummy entry is added
34 #define SDW_FRAME_ROWS 24
35 #define SDW_FRAME_COLS 8
36 #define SDW_FRAME_ROW_COLS (SDW_FRAME_ROWS * SDW_FRAME_COLS)
38 #define SDW_FRAME_CTRL_BITS 48
39 #define SDW_MAX_DEVICES 11
41 #define SDW_VALID_PORT_RANGE(n) ((n) <= 14 && (n) >= 1)
43 #define SDW_DAI_ID_RANGE_START 100
44 #define SDW_DAI_ID_RANGE_END 200
47 SDW_PORT_DIRN_SINK = 0,
53 * constants for flow control, ports and transport
55 * these are bit masks as devices can have multiple capabilities
59 * flow modes for SDW port. These can be isochronous, tx controlled,
60 * rx controlled or async
62 #define SDW_PORT_FLOW_MODE_ISOCH 0
63 #define SDW_PORT_FLOW_MODE_TX_CNTRL BIT(0)
64 #define SDW_PORT_FLOW_MODE_RX_CNTRL BIT(1)
65 #define SDW_PORT_FLOW_MODE_ASYNC GENMASK(1, 0)
67 /* sample packaging for block. It can be per port or per channel */
68 #define SDW_BLOCK_PACKG_PER_PORT BIT(0)
69 #define SDW_BLOCK_PACKG_PER_CH BIT(1)
72 * enum sdw_slave_status - Slave status
73 * @SDW_SLAVE_UNATTACHED: Slave is not attached with the bus.
74 * @SDW_SLAVE_ATTACHED: Slave is attached with bus.
75 * @SDW_SLAVE_ALERT: Some alert condition on the Slave
76 * @SDW_SLAVE_RESERVED: Reserved for future use
78 enum sdw_slave_status {
79 SDW_SLAVE_UNATTACHED = 0,
80 SDW_SLAVE_ATTACHED = 1,
82 SDW_SLAVE_RESERVED = 3,
86 * enum sdw_command_response - Command response as defined by SDW spec
87 * @SDW_CMD_OK: cmd was successful
88 * @SDW_CMD_IGNORED: cmd was ignored
89 * @SDW_CMD_FAIL: cmd was NACKed
90 * @SDW_CMD_TIMEOUT: cmd timedout
91 * @SDW_CMD_FAIL_OTHER: cmd failed due to other reason than above
93 * NOTE: The enum is different than actual Spec as response in the Spec is
94 * combination of ACK/NAK bits
96 * SDW_CMD_TIMEOUT/FAIL_OTHER is defined for SW use, not in spec
98 enum sdw_command_response {
103 SDW_CMD_FAIL_OTHER = 4,
106 /* block group count enum */
107 enum sdw_dpn_grouping {
108 SDW_BLK_GRP_CNT_1 = 0,
109 SDW_BLK_GRP_CNT_2 = 1,
110 SDW_BLK_GRP_CNT_3 = 2,
111 SDW_BLK_GRP_CNT_4 = 3,
115 * enum sdw_stream_type: data stream type
117 * @SDW_STREAM_PCM: PCM data stream
118 * @SDW_STREAM_PDM: PDM data stream
120 * spec doesn't define this, but is used in implementation
122 enum sdw_stream_type {
128 * enum sdw_data_direction: Data direction
130 * @SDW_DATA_DIR_RX: Data into Port
131 * @SDW_DATA_DIR_TX: Data out of Port
133 enum sdw_data_direction {
139 * enum sdw_port_data_mode: Data Port mode
141 * @SDW_PORT_DATA_MODE_NORMAL: Normal data mode where audio data is received
143 * @SDW_PORT_DATA_MODE_STATIC_1: Simple test mode which uses static value of
144 * logic 1. The encoding will result in signal transitions at every bitslot
146 * @SDW_PORT_DATA_MODE_STATIC_0: Simple test mode which uses static value of
147 * logic 0. The encoding will result in no signal transitions
148 * @SDW_PORT_DATA_MODE_PRBS: Test mode which uses a PRBS generator to produce
149 * a pseudo random data pattern that is transferred
151 enum sdw_port_data_mode {
152 SDW_PORT_DATA_MODE_NORMAL = 0,
153 SDW_PORT_DATA_MODE_STATIC_1 = 1,
154 SDW_PORT_DATA_MODE_STATIC_0 = 2,
155 SDW_PORT_DATA_MODE_PRBS = 3,
159 * SDW properties, defined in MIPI DisCo spec v1.0
161 enum sdw_clk_stop_reset_behave {
162 SDW_CLK_STOP_KEEP_STATUS = 1,
166 * enum sdw_p15_behave - Slave Port 15 behaviour when the Master attempts a
168 * @SDW_P15_READ_IGNORED: Read is ignored
169 * @SDW_P15_CMD_OK: Command is ok
171 enum sdw_p15_behave {
172 SDW_P15_READ_IGNORED = 0,
177 * enum sdw_dpn_type - Data port types
178 * @SDW_DPN_FULL: Full Data Port is supported
179 * @SDW_DPN_SIMPLE: Simplified Data Port as defined in spec.
180 * DPN_SampleCtrl2, DPN_OffsetCtrl2, DPN_HCtrl and DPN_BlockCtrl3
181 * are not implemented.
182 * @SDW_DPN_REDUCED: Reduced Data Port as defined in spec.
183 * DPN_SampleCtrl2, DPN_HCtrl are not implemented.
192 * enum sdw_clk_stop_mode - Clock Stop modes
193 * @SDW_CLK_STOP_MODE0: Slave can continue operation seamlessly on clock
195 * @SDW_CLK_STOP_MODE1: Slave may have entered a deeper power-saving mode,
196 * not capable of continuing operation seamlessly when the clock restarts
198 enum sdw_clk_stop_mode {
199 SDW_CLK_STOP_MODE0 = 0,
200 SDW_CLK_STOP_MODE1 = 1,
204 * struct sdw_dp0_prop - DP0 properties
205 * @max_word: Maximum number of bits in a Payload Channel Sample, 1 to 64
207 * @min_word: Minimum number of bits in a Payload Channel Sample, 1 to 64
209 * @num_words: number of wordlengths supported
210 * @words: wordlengths supported
211 * @BRA_flow_controlled: Slave implementation results in an OK_NotReady
213 * @simple_ch_prep_sm: If channel prepare sequence is required
214 * @imp_def_interrupts: If set, each bit corresponds to support for
215 * implementation-defined interrupts
217 * The wordlengths are specified by Spec as max, min AND number of
218 * discrete values, implementation can define based on the wordlengths they
221 struct sdw_dp0_prop {
226 bool BRA_flow_controlled;
227 bool simple_ch_prep_sm;
228 bool imp_def_interrupts;
232 * struct sdw_dpn_audio_mode - Audio mode properties for DPn
233 * @bus_min_freq: Minimum bus frequency, in Hz
234 * @bus_max_freq: Maximum bus frequency, in Hz
235 * @bus_num_freq: Number of discrete frequencies supported
236 * @bus_freq: Discrete bus frequencies, in Hz
237 * @min_freq: Minimum sampling frequency, in Hz
238 * @max_freq: Maximum sampling bus frequency, in Hz
239 * @num_freq: Number of discrete sampling frequency supported
240 * @freq: Discrete sampling frequencies, in Hz
241 * @prep_ch_behave: Specifies the dependencies between Channel Prepare
242 * sequence and bus clock configuration
243 * If 0, Channel Prepare can happen at any Bus clock rate
244 * If 1, Channel Prepare sequence shall happen only after Bus clock is
245 * changed to a frequency supported by this mode or compatible modes
246 * described by the next field
247 * @glitchless: Bitmap describing possible glitchless transitions from this
248 * Audio Mode to other Audio Modes
250 struct sdw_dpn_audio_mode {
264 * struct sdw_dpn_prop - Data Port DPn properties
266 * @max_word: Maximum number of bits in a Payload Channel Sample, 1 to 64
268 * @min_word: Minimum number of bits in a Payload Channel Sample, 1 to 64
270 * @num_words: Number of discrete supported wordlengths
271 * @words: Discrete supported wordlength
272 * @type: Data port type. Full, Simplified or Reduced
273 * @max_grouping: Maximum number of samples that can be grouped together for
275 * @simple_ch_prep_sm: If the port supports simplified channel prepare state
277 * @ch_prep_timeout: Port-specific timeout value, in milliseconds
278 * @imp_def_interrupts: If set, each bit corresponds to support for
279 * implementation-defined interrupts
280 * @max_ch: Maximum channels supported
281 * @min_ch: Minimum channels supported
282 * @num_ch: Number of discrete channels supported
283 * @ch: Discrete channels supported
284 * @num_ch_combinations: Number of channel combinations supported
285 * @ch_combinations: Channel combinations supported
286 * @modes: SDW mode supported
287 * @max_async_buffer: Number of samples that this port can buffer in
289 * @block_pack_mode: Type of block port mode supported
290 * @port_encoding: Payload Channel Sample encoding schemes supported
291 * @audio_modes: Audio modes supported
293 struct sdw_dpn_prop {
299 enum sdw_dpn_type type;
301 bool simple_ch_prep_sm;
303 u32 imp_def_interrupts;
308 u32 num_ch_combinations;
309 u32 *ch_combinations;
311 u32 max_async_buffer;
312 bool block_pack_mode;
314 struct sdw_dpn_audio_mode *audio_modes;
318 * struct sdw_slave_prop - SoundWire Slave properties
319 * @mipi_revision: Spec version of the implementation
320 * @wake_capable: Wake-up events are supported
321 * @test_mode_capable: If test mode is supported
322 * @clk_stop_mode1: Clock-Stop Mode 1 is supported
323 * @simple_clk_stop_capable: Simple clock mode is supported
324 * @clk_stop_timeout: Worst-case latency of the Clock Stop Prepare State
325 * Machine transitions, in milliseconds
326 * @ch_prep_timeout: Worst-case latency of the Channel Prepare State Machine
327 * transitions, in milliseconds
328 * @reset_behave: Slave keeps the status of the SlaveStopClockPrepare
329 * state machine (P=1 SCSP_SM) after exit from clock-stop mode1
330 * @high_PHY_capable: Slave is HighPHY capable
331 * @paging_support: Slave implements paging registers SCP_AddrPage1 and
333 * @bank_delay_support: Slave implements bank delay/bridge support registers
334 * SCP_BankDelay and SCP_NextFrame
335 * @p15_behave: Slave behavior when the Master attempts a read to the Port15
337 * @lane_control_support: Slave supports lane control
338 * @master_count: Number of Masters present on this Slave
339 * @source_ports: Bitmap identifying source ports
340 * @sink_ports: Bitmap identifying sink ports
341 * @dp0_prop: Data Port 0 properties
342 * @src_dpn_prop: Source Data Port N properties
343 * @sink_dpn_prop: Sink Data Port N properties
345 struct sdw_slave_prop {
348 bool test_mode_capable;
350 bool simple_clk_stop_capable;
351 u32 clk_stop_timeout;
353 enum sdw_clk_stop_reset_behave reset_behave;
354 bool high_PHY_capable;
356 bool bank_delay_support;
357 enum sdw_p15_behave p15_behave;
358 bool lane_control_support;
362 struct sdw_dp0_prop *dp0_prop;
363 struct sdw_dpn_prop *src_dpn_prop;
364 struct sdw_dpn_prop *sink_dpn_prop;
368 * struct sdw_master_prop - Master properties
369 * @revision: MIPI spec version of the implementation
370 * @clk_stop_modes: Bitmap, bit N set when clock-stop-modeN supported
371 * @max_clk_freq: Maximum Bus clock frequency, in Hz
372 * @num_clk_gears: Number of clock gears supported
373 * @clk_gears: Clock gears supported
374 * @num_clk_freq: Number of clock frequencies supported, in Hz
375 * @clk_freq: Clock frequencies supported, in Hz
376 * @default_frame_rate: Controller default Frame rate, in Hz
377 * @default_row: Number of rows
378 * @default_col: Number of columns
379 * @dynamic_frame: Dynamic frame shape supported
380 * @err_threshold: Number of times that software may retry sending a single
382 * @mclk_freq: clock reference passed to SoundWire Master, in Hz.
383 * @hw_disabled: if true, the Master is not functional, typically due to pin-mux
385 struct sdw_master_prop {
393 u32 default_frame_rate;
402 int sdw_master_read_prop(struct sdw_bus *bus);
403 int sdw_slave_read_prop(struct sdw_slave *slave);
406 * SDW Slave Structures and APIs
410 * struct sdw_slave_id - Slave ID
411 * @mfg_id: MIPI Manufacturer ID
412 * @part_id: Device Part ID
413 * @class_id: MIPI Class ID, unused now.
414 * Currently a placeholder in MIPI SoundWire Spec
415 * @unique_id: Device unique ID
416 * @sdw_version: SDW version implemented
418 * The order of the IDs here does not follow the DisCo spec definitions
420 struct sdw_slave_id {
429 * struct sdw_slave_intr_status - Slave interrupt status
430 * @control_port: control port status
431 * @port: data port status
433 struct sdw_slave_intr_status {
439 * sdw_reg_bank - SoundWire register banks
440 * @SDW_BANK0: Soundwire register bank 0
441 * @SDW_BANK1: Soundwire register bank 1
449 * struct sdw_bus_conf: Bus configuration
451 * @clk_freq: Clock frequency, in Hz
452 * @num_rows: Number of rows in frame
453 * @num_cols: Number of columns in frame
454 * @bank: Next register bank
456 struct sdw_bus_conf {
457 unsigned int clk_freq;
458 unsigned int num_rows;
459 unsigned int num_cols;
464 * struct sdw_prepare_ch: Prepare/De-prepare Data Port channel
467 * @ch_mask: Active channel mask
468 * @prepare: Prepare (true) /de-prepare (false) channel
469 * @bank: Register bank, which bank Slave/Master driver should program for
470 * implementation defined registers. This is always updated to next_bank
471 * value read from bus params.
474 struct sdw_prepare_ch {
476 unsigned int ch_mask;
482 * enum sdw_port_prep_ops: Prepare operations for Data Port
484 * @SDW_OPS_PORT_PRE_PREP: Pre prepare operation for the Port
485 * @SDW_OPS_PORT_PREP: Prepare operation for the Port
486 * @SDW_OPS_PORT_POST_PREP: Post prepare operation for the Port
488 enum sdw_port_prep_ops {
489 SDW_OPS_PORT_PRE_PREP = 0,
490 SDW_OPS_PORT_PREP = 1,
491 SDW_OPS_PORT_POST_PREP = 2,
495 * struct sdw_bus_params: Structure holding bus configuration
497 * @curr_bank: Current bank in use (BANK0/BANK1)
498 * @next_bank: Next bank to use (BANK0/BANK1). next_bank will always be
500 * @max_dr_freq: Maximum double rate clock frequency supported, in Hz
501 * @curr_dr_freq: Current double rate clock frequency, in Hz
502 * @bandwidth: Current bandwidth
503 * @col: Active columns
506 struct sdw_bus_params {
507 enum sdw_reg_bank curr_bank;
508 enum sdw_reg_bank next_bank;
509 unsigned int max_dr_freq;
510 unsigned int curr_dr_freq;
511 unsigned int bandwidth;
517 * struct sdw_slave_ops: Slave driver callback ops
519 * @read_prop: Read Slave properties
520 * @interrupt_callback: Device interrupt notification (invoked in thread
522 * @update_status: Update Slave status
523 * @bus_config: Update the bus config for Slave
524 * @port_prep: Prepare the port with parameters
526 struct sdw_slave_ops {
527 int (*read_prop)(struct sdw_slave *sdw);
528 int (*interrupt_callback)(struct sdw_slave *slave,
529 struct sdw_slave_intr_status *status);
530 int (*update_status)(struct sdw_slave *slave,
531 enum sdw_slave_status status);
532 int (*bus_config)(struct sdw_slave *slave,
533 struct sdw_bus_params *params);
534 int (*port_prep)(struct sdw_slave *slave,
535 struct sdw_prepare_ch *prepare_ch,
536 enum sdw_port_prep_ops pre_ops);
540 * struct sdw_slave - SoundWire Slave
541 * @id: MIPI device ID
543 * @status: Status reported by the Slave
545 * @ops: Slave callback ops
546 * @prop: Slave properties
547 * @debugfs: Slave debugfs
548 * @node: node for bus list
549 * @port_ready: Port ready completion flag for each Slave port
550 * @dev_num: Device Number assigned by Bus
553 struct sdw_slave_id id;
555 enum sdw_slave_status status;
557 const struct sdw_slave_ops *ops;
558 struct sdw_slave_prop prop;
559 #ifdef CONFIG_DEBUG_FS
560 struct dentry *debugfs;
562 struct list_head node;
563 struct completion *port_ready;
567 #define dev_to_sdw_dev(_dev) container_of(_dev, struct sdw_slave, dev)
572 int (*probe)(struct sdw_slave *sdw,
573 const struct sdw_device_id *id);
574 int (*remove)(struct sdw_slave *sdw);
575 void (*shutdown)(struct sdw_slave *sdw);
577 const struct sdw_device_id *id_table;
578 const struct sdw_slave_ops *ops;
580 struct device_driver driver;
583 #define SDW_SLAVE_ENTRY(_mfg_id, _part_id, _drv_data) \
584 { .mfg_id = (_mfg_id), .part_id = (_part_id), \
585 .driver_data = (unsigned long)(_drv_data) }
587 int sdw_handle_slave_status(struct sdw_bus *bus,
588 enum sdw_slave_status status[]);
591 * SDW master structures and APIs
595 * struct sdw_port_params: Data Port parameters
598 * @bps: Word length of the Port
599 * @flow_mode: Port Data flow mode
600 * @data_mode: Test modes or normal mode
602 * This is used to program the Data Port based on Data Port stream
605 struct sdw_port_params {
608 unsigned int flow_mode;
609 unsigned int data_mode;
613 * struct sdw_transport_params: Data Port Transport Parameters
615 * @blk_grp_ctrl_valid: Port implements block group control
617 * @blk_grp_ctrl: Block group control value
618 * @sample_interval: Sample interval
619 * @offset1: Blockoffset of the payload data
620 * @offset2: Blockoffset of the payload data
621 * @hstart: Horizontal start of the payload data
622 * @hstop: Horizontal stop of the payload data
623 * @blk_pkg_mode: Block per channel or block per port
624 * @lane_ctrl: Data lane Port uses for Data transfer. Currently only single
625 * data lane is supported in bus
627 * This is used to program the Data Port based on Data Port transport
628 * parameters. All these parameters are banked and can be modified
629 * during a bank switch without any artifacts in audio stream.
631 struct sdw_transport_params {
632 bool blk_grp_ctrl_valid;
633 unsigned int port_num;
634 unsigned int blk_grp_ctrl;
635 unsigned int sample_interval;
636 unsigned int offset1;
637 unsigned int offset2;
640 unsigned int blk_pkg_mode;
641 unsigned int lane_ctrl;
645 * struct sdw_enable_ch: Enable/disable Data Port channel
648 * @ch_mask: Active channel mask
649 * @enable: Enable (true) /disable (false) channel
651 struct sdw_enable_ch {
652 unsigned int port_num;
653 unsigned int ch_mask;
658 * struct sdw_master_port_ops: Callback functions from bus to Master
659 * driver to set Master Data ports.
661 * @dpn_set_port_params: Set the Port parameters for the Master Port.
663 * @dpn_set_port_transport_params: Set transport parameters for the Master
664 * Port. Mandatory callback
665 * @dpn_port_prep: Port prepare operations for the Master Data Port.
666 * @dpn_port_enable_ch: Enable the channels of Master Port.
668 struct sdw_master_port_ops {
669 int (*dpn_set_port_params)(struct sdw_bus *bus,
670 struct sdw_port_params *port_params,
672 int (*dpn_set_port_transport_params)(struct sdw_bus *bus,
673 struct sdw_transport_params *transport_params,
674 enum sdw_reg_bank bank);
675 int (*dpn_port_prep)(struct sdw_bus *bus,
676 struct sdw_prepare_ch *prepare_ch);
677 int (*dpn_port_enable_ch)(struct sdw_bus *bus,
678 struct sdw_enable_ch *enable_ch, unsigned int bank);
684 * struct sdw_defer - SDW deffered message
685 * @length: message length
686 * @complete: message completion
691 struct completion complete;
696 * struct sdw_master_ops - Master driver ops
697 * @read_prop: Read Master properties
698 * @xfer_msg: Transfer message callback
699 * @xfer_msg_defer: Defer version of transfer message callback
700 * @reset_page_addr: Reset the SCP page address registers
701 * @set_bus_conf: Set the bus configuration
702 * @pre_bank_switch: Callback for pre bank switch
703 * @post_bank_switch: Callback for post bank switch
705 struct sdw_master_ops {
706 int (*read_prop)(struct sdw_bus *bus);
708 enum sdw_command_response (*xfer_msg)
709 (struct sdw_bus *bus, struct sdw_msg *msg);
710 enum sdw_command_response (*xfer_msg_defer)
711 (struct sdw_bus *bus, struct sdw_msg *msg,
712 struct sdw_defer *defer);
713 enum sdw_command_response (*reset_page_addr)
714 (struct sdw_bus *bus, unsigned int dev_num);
715 int (*set_bus_conf)(struct sdw_bus *bus,
716 struct sdw_bus_params *params);
717 int (*pre_bank_switch)(struct sdw_bus *bus);
718 int (*post_bank_switch)(struct sdw_bus *bus);
723 * struct sdw_bus - SoundWire bus
724 * @dev: Master linux device
725 * @link_id: Link id number, can be 0 to N, unique for each Master
726 * @slaves: list of Slaves on this bus
727 * @assigned: Bitmap for Slave device numbers.
728 * Bit set implies used number, bit clear implies unused number.
729 * @bus_lock: bus lock
730 * @msg_lock: message lock
731 * @compute_params: points to Bus resource management implementation
732 * @ops: Master callback ops
733 * @port_ops: Master port callback ops
734 * @params: Current bus parameters
735 * @prop: Master properties
736 * @m_rt_list: List of Master instance of all stream(s) running on Bus. This
737 * is used to compute and program bus bandwidth, clock, frame shape,
738 * transport and port parameters
739 * @debugfs: Bus debugfs
740 * @defer_msg: Defer message
741 * @clk_stop_timeout: Clock stop timeout computed
742 * @bank_switch_timeout: Bank switch timeout computed
743 * @multi_link: Store bus property that indicates if multi links
744 * are supported. This flag is populated by drivers after reading
745 * appropriate firmware (ACPI/DT).
749 unsigned int link_id;
750 struct list_head slaves;
751 DECLARE_BITMAP(assigned, SDW_MAX_DEVICES);
752 struct mutex bus_lock;
753 struct mutex msg_lock;
754 int (*compute_params)(struct sdw_bus *bus);
755 const struct sdw_master_ops *ops;
756 const struct sdw_master_port_ops *port_ops;
757 struct sdw_bus_params params;
758 struct sdw_master_prop prop;
759 struct list_head m_rt_list;
760 #ifdef CONFIG_DEBUG_FS
761 struct dentry *debugfs;
763 struct sdw_defer defer_msg;
764 unsigned int clk_stop_timeout;
765 u32 bank_switch_timeout;
769 int sdw_add_bus_master(struct sdw_bus *bus);
770 void sdw_delete_bus_master(struct sdw_bus *bus);
773 * sdw_port_config: Master or Slave Port configuration
776 * @ch_mask: channels mask for port
778 struct sdw_port_config {
780 unsigned int ch_mask;
784 * sdw_stream_config: Master or Slave stream configuration
786 * @frame_rate: Audio frame rate of the stream, in Hz
787 * @ch_count: Channel count of the stream
788 * @bps: Number of bits per audio sample
789 * @direction: Data direction
790 * @type: Stream type PCM or PDM
792 struct sdw_stream_config {
793 unsigned int frame_rate;
794 unsigned int ch_count;
796 enum sdw_data_direction direction;
797 enum sdw_stream_type type;
801 * sdw_stream_state: Stream states
803 * @SDW_STREAM_ALLOCATED: New stream allocated.
804 * @SDW_STREAM_CONFIGURED: Stream configured
805 * @SDW_STREAM_PREPARED: Stream prepared
806 * @SDW_STREAM_ENABLED: Stream enabled
807 * @SDW_STREAM_DISABLED: Stream disabled
808 * @SDW_STREAM_DEPREPARED: Stream de-prepared
809 * @SDW_STREAM_RELEASED: Stream released
811 enum sdw_stream_state {
812 SDW_STREAM_ALLOCATED = 0,
813 SDW_STREAM_CONFIGURED = 1,
814 SDW_STREAM_PREPARED = 2,
815 SDW_STREAM_ENABLED = 3,
816 SDW_STREAM_DISABLED = 4,
817 SDW_STREAM_DEPREPARED = 5,
818 SDW_STREAM_RELEASED = 6,
822 * sdw_stream_params: Stream parameters
824 * @rate: Sampling frequency, in Hz
825 * @ch_count: Number of channels
826 * @bps: bits per channel sample
828 struct sdw_stream_params {
830 unsigned int ch_count;
835 * sdw_stream_runtime: Runtime stream parameters
837 * @name: SoundWire stream name
838 * @params: Stream parameters
839 * @state: Current state of the stream
840 * @type: Stream type PCM or PDM
841 * @master_list: List of Master runtime(s) in this stream.
842 * master_list can contain only one m_rt per Master instance
844 * @m_rt_count: Count of Master runtime(s) in this stream
846 struct sdw_stream_runtime {
848 struct sdw_stream_params params;
849 enum sdw_stream_state state;
850 enum sdw_stream_type type;
851 struct list_head master_list;
855 struct sdw_stream_runtime *sdw_alloc_stream(const char *stream_name);
856 void sdw_release_stream(struct sdw_stream_runtime *stream);
857 int sdw_stream_add_master(struct sdw_bus *bus,
858 struct sdw_stream_config *stream_config,
859 struct sdw_port_config *port_config,
860 unsigned int num_ports,
861 struct sdw_stream_runtime *stream);
862 int sdw_stream_add_slave(struct sdw_slave *slave,
863 struct sdw_stream_config *stream_config,
864 struct sdw_port_config *port_config,
865 unsigned int num_ports,
866 struct sdw_stream_runtime *stream);
867 int sdw_stream_remove_master(struct sdw_bus *bus,
868 struct sdw_stream_runtime *stream);
869 int sdw_stream_remove_slave(struct sdw_slave *slave,
870 struct sdw_stream_runtime *stream);
871 int sdw_prepare_stream(struct sdw_stream_runtime *stream);
872 int sdw_enable_stream(struct sdw_stream_runtime *stream);
873 int sdw_disable_stream(struct sdw_stream_runtime *stream);
874 int sdw_deprepare_stream(struct sdw_stream_runtime *stream);
876 /* messaging and data APIs */
878 int sdw_read(struct sdw_slave *slave, u32 addr);
879 int sdw_write(struct sdw_slave *slave, u32 addr, u8 value);
880 int sdw_nread(struct sdw_slave *slave, u32 addr, size_t count, u8 *val);
881 int sdw_nwrite(struct sdw_slave *slave, u32 addr, size_t count, u8 *val);
883 #endif /* __SOUNDWIRE_H */