sdw.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  1. // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
  2. // Copyright(c) 2015-17 Intel Corporation.
  3. #ifndef __SOUNDWIRE_H
  4. #define __SOUNDWIRE_H
  5. struct sdw_bus;
  6. struct sdw_slave;
  7. /* SDW spec defines and enums, as defined by MIPI 1.1. Spec */
  8. /* SDW Broadcast Device Number */
  9. #define SDW_BROADCAST_DEV_NUM 15
  10. /* SDW Enumeration Device Number */
  11. #define SDW_ENUM_DEV_NUM 0
  12. /* SDW Group Device Numbers */
  13. #define SDW_GROUP12_DEV_NUM 12
  14. #define SDW_GROUP13_DEV_NUM 13
  15. /* SDW Master Device Number, not supported yet */
  16. #define SDW_MASTER_DEV_NUM 14
  17. #define SDW_NUM_DEV_ID_REGISTERS 6
  18. /* frame shape defines */
  19. /*
  20. * Note: The maximum row define in SoundWire spec 1.1 is 23. In order to
  21. * fill hole with 0, one more dummy entry is added
  22. */
  23. #define SDW_FRAME_ROWS 24
  24. #define SDW_FRAME_COLS 8
  25. #define SDW_FRAME_ROW_COLS (SDW_FRAME_ROWS * SDW_FRAME_COLS)
  26. #define SDW_FRAME_CTRL_BITS 48
  27. #define SDW_MAX_DEVICES 11
  28. #define SDW_VALID_PORT_RANGE(n) (n <= 14 && n >= 1)
  29. #define SDW_DAI_ID_RANGE_START 100
  30. #define SDW_DAI_ID_RANGE_END 200
  31. /**
  32. * enum sdw_slave_status - Slave status
  33. * @SDW_SLAVE_UNATTACHED: Slave is not attached with the bus.
  34. * @SDW_SLAVE_ATTACHED: Slave is attached with bus.
  35. * @SDW_SLAVE_ALERT: Some alert condition on the Slave
  36. * @SDW_SLAVE_RESERVED: Reserved for future use
  37. */
  38. enum sdw_slave_status {
  39. SDW_SLAVE_UNATTACHED = 0,
  40. SDW_SLAVE_ATTACHED = 1,
  41. SDW_SLAVE_ALERT = 2,
  42. SDW_SLAVE_RESERVED = 3,
  43. };
  44. /**
  45. * enum sdw_command_response - Command response as defined by SDW spec
  46. * @SDW_CMD_OK: cmd was successful
  47. * @SDW_CMD_IGNORED: cmd was ignored
  48. * @SDW_CMD_FAIL: cmd was NACKed
  49. * @SDW_CMD_TIMEOUT: cmd timedout
  50. * @SDW_CMD_FAIL_OTHER: cmd failed due to other reason than above
  51. *
  52. * NOTE: The enum is different than actual Spec as response in the Spec is
  53. * combination of ACK/NAK bits
  54. *
  55. * SDW_CMD_TIMEOUT/FAIL_OTHER is defined for SW use, not in spec
  56. */
  57. enum sdw_command_response {
  58. SDW_CMD_OK = 0,
  59. SDW_CMD_IGNORED = 1,
  60. SDW_CMD_FAIL = 2,
  61. SDW_CMD_TIMEOUT = 3,
  62. SDW_CMD_FAIL_OTHER = 4,
  63. };
  64. /**
  65. * enum sdw_stream_type: data stream type
  66. *
  67. * @SDW_STREAM_PCM: PCM data stream
  68. * @SDW_STREAM_PDM: PDM data stream
  69. *
  70. * spec doesn't define this, but is used in implementation
  71. */
  72. enum sdw_stream_type {
  73. SDW_STREAM_PCM = 0,
  74. SDW_STREAM_PDM = 1,
  75. };
  76. /**
  77. * enum sdw_data_direction: Data direction
  78. *
  79. * @SDW_DATA_DIR_RX: Data into Port
  80. * @SDW_DATA_DIR_TX: Data out of Port
  81. */
  82. enum sdw_data_direction {
  83. SDW_DATA_DIR_RX = 0,
  84. SDW_DATA_DIR_TX = 1,
  85. };
  86. /*
  87. * SDW properties, defined in MIPI DisCo spec v1.0
  88. */
  89. enum sdw_clk_stop_reset_behave {
  90. SDW_CLK_STOP_KEEP_STATUS = 1,
  91. };
  92. /**
  93. * enum sdw_p15_behave - Slave Port 15 behaviour when the Master attempts a
  94. * read
  95. * @SDW_P15_READ_IGNORED: Read is ignored
  96. * @SDW_P15_CMD_OK: Command is ok
  97. */
  98. enum sdw_p15_behave {
  99. SDW_P15_READ_IGNORED = 0,
  100. SDW_P15_CMD_OK = 1,
  101. };
  102. /**
  103. * enum sdw_dpn_type - Data port types
  104. * @SDW_DPN_FULL: Full Data Port is supported
  105. * @SDW_DPN_SIMPLE: Simplified Data Port as defined in spec.
  106. * DPN_SampleCtrl2, DPN_OffsetCtrl2, DPN_HCtrl and DPN_BlockCtrl3
  107. * are not implemented.
  108. * @SDW_DPN_REDUCED: Reduced Data Port as defined in spec.
  109. * DPN_SampleCtrl2, DPN_HCtrl are not implemented.
  110. */
  111. enum sdw_dpn_type {
  112. SDW_DPN_FULL = 0,
  113. SDW_DPN_SIMPLE = 1,
  114. SDW_DPN_REDUCED = 2,
  115. };
  116. /**
  117. * enum sdw_clk_stop_mode - Clock Stop modes
  118. * @SDW_CLK_STOP_MODE0: Slave can continue operation seamlessly on clock
  119. * restart
  120. * @SDW_CLK_STOP_MODE1: Slave may have entered a deeper power-saving mode,
  121. * not capable of continuing operation seamlessly when the clock restarts
  122. */
  123. enum sdw_clk_stop_mode {
  124. SDW_CLK_STOP_MODE0 = 0,
  125. SDW_CLK_STOP_MODE1 = 1,
  126. };
  127. /**
  128. * struct sdw_dp0_prop - DP0 properties
  129. * @max_word: Maximum number of bits in a Payload Channel Sample, 1 to 64
  130. * (inclusive)
  131. * @min_word: Minimum number of bits in a Payload Channel Sample, 1 to 64
  132. * (inclusive)
  133. * @num_words: number of wordlengths supported
  134. * @words: wordlengths supported
  135. * @flow_controlled: Slave implementation results in an OK_NotReady
  136. * response
  137. * @simple_ch_prep_sm: If channel prepare sequence is required
  138. * @device_interrupts: If implementation-defined interrupts are supported
  139. *
  140. * The wordlengths are specified by Spec as max, min AND number of
  141. * discrete values, implementation can define based on the wordlengths they
  142. * support
  143. */
  144. struct sdw_dp0_prop {
  145. u32 max_word;
  146. u32 min_word;
  147. u32 num_words;
  148. u32 *words;
  149. bool flow_controlled;
  150. bool simple_ch_prep_sm;
  151. bool device_interrupts;
  152. };
  153. /**
  154. * struct sdw_dpn_audio_mode - Audio mode properties for DPn
  155. * @bus_min_freq: Minimum bus frequency, in Hz
  156. * @bus_max_freq: Maximum bus frequency, in Hz
  157. * @bus_num_freq: Number of discrete frequencies supported
  158. * @bus_freq: Discrete bus frequencies, in Hz
  159. * @min_freq: Minimum sampling frequency, in Hz
  160. * @max_freq: Maximum sampling bus frequency, in Hz
  161. * @num_freq: Number of discrete sampling frequency supported
  162. * @freq: Discrete sampling frequencies, in Hz
  163. * @prep_ch_behave: Specifies the dependencies between Channel Prepare
  164. * sequence and bus clock configuration
  165. * If 0, Channel Prepare can happen at any Bus clock rate
  166. * If 1, Channel Prepare sequence shall happen only after Bus clock is
  167. * changed to a frequency supported by this mode or compatible modes
  168. * described by the next field
  169. * @glitchless: Bitmap describing possible glitchless transitions from this
  170. * Audio Mode to other Audio Modes
  171. */
  172. struct sdw_dpn_audio_mode {
  173. u32 bus_min_freq;
  174. u32 bus_max_freq;
  175. u32 bus_num_freq;
  176. u32 *bus_freq;
  177. u32 max_freq;
  178. u32 min_freq;
  179. u32 num_freq;
  180. u32 *freq;
  181. u32 prep_ch_behave;
  182. u32 glitchless;
  183. };
  184. /**
  185. * struct sdw_dpn_prop - Data Port DPn properties
  186. * @num: port number
  187. * @max_word: Maximum number of bits in a Payload Channel Sample, 1 to 64
  188. * (inclusive)
  189. * @min_word: Minimum number of bits in a Payload Channel Sample, 1 to 64
  190. * (inclusive)
  191. * @num_words: Number of discrete supported wordlengths
  192. * @words: Discrete supported wordlength
  193. * @type: Data port type. Full, Simplified or Reduced
  194. * @max_grouping: Maximum number of samples that can be grouped together for
  195. * a full data port
  196. * @simple_ch_prep_sm: If the port supports simplified channel prepare state
  197. * machine
  198. * @ch_prep_timeout: Port-specific timeout value, in milliseconds
  199. * @device_interrupts: If set, each bit corresponds to support for
  200. * implementation-defined interrupts
  201. * @max_ch: Maximum channels supported
  202. * @min_ch: Minimum channels supported
  203. * @num_ch: Number of discrete channels supported
  204. * @ch: Discrete channels supported
  205. * @num_ch_combinations: Number of channel combinations supported
  206. * @ch_combinations: Channel combinations supported
  207. * @modes: SDW mode supported
  208. * @max_async_buffer: Number of samples that this port can buffer in
  209. * asynchronous modes
  210. * @block_pack_mode: Type of block port mode supported
  211. * @port_encoding: Payload Channel Sample encoding schemes supported
  212. * @audio_modes: Audio modes supported
  213. */
  214. struct sdw_dpn_prop {
  215. u32 num;
  216. u32 max_word;
  217. u32 min_word;
  218. u32 num_words;
  219. u32 *words;
  220. enum sdw_dpn_type type;
  221. u32 max_grouping;
  222. bool simple_ch_prep_sm;
  223. u32 ch_prep_timeout;
  224. u32 device_interrupts;
  225. u32 max_ch;
  226. u32 min_ch;
  227. u32 num_ch;
  228. u32 *ch;
  229. u32 num_ch_combinations;
  230. u32 *ch_combinations;
  231. u32 modes;
  232. u32 max_async_buffer;
  233. bool block_pack_mode;
  234. u32 port_encoding;
  235. struct sdw_dpn_audio_mode *audio_modes;
  236. };
  237. /**
  238. * struct sdw_slave_prop - SoundWire Slave properties
  239. * @mipi_revision: Spec version of the implementation
  240. * @wake_capable: Wake-up events are supported
  241. * @test_mode_capable: If test mode is supported
  242. * @clk_stop_mode1: Clock-Stop Mode 1 is supported
  243. * @simple_clk_stop_capable: Simple clock mode is supported
  244. * @clk_stop_timeout: Worst-case latency of the Clock Stop Prepare State
  245. * Machine transitions, in milliseconds
  246. * @ch_prep_timeout: Worst-case latency of the Channel Prepare State Machine
  247. * transitions, in milliseconds
  248. * @reset_behave: Slave keeps the status of the SlaveStopClockPrepare
  249. * state machine (P=1 SCSP_SM) after exit from clock-stop mode1
  250. * @high_PHY_capable: Slave is HighPHY capable
  251. * @paging_support: Slave implements paging registers SCP_AddrPage1 and
  252. * SCP_AddrPage2
  253. * @bank_delay_support: Slave implements bank delay/bridge support registers
  254. * SCP_BankDelay and SCP_NextFrame
  255. * @p15_behave: Slave behavior when the Master attempts a read to the Port15
  256. * alias
  257. * @lane_control_support: Slave supports lane control
  258. * @master_count: Number of Masters present on this Slave
  259. * @source_ports: Bitmap identifying source ports
  260. * @sink_ports: Bitmap identifying sink ports
  261. * @dp0_prop: Data Port 0 properties
  262. * @src_dpn_prop: Source Data Port N properties
  263. * @sink_dpn_prop: Sink Data Port N properties
  264. */
  265. struct sdw_slave_prop {
  266. u32 mipi_revision;
  267. bool wake_capable;
  268. bool test_mode_capable;
  269. bool clk_stop_mode1;
  270. bool simple_clk_stop_capable;
  271. u32 clk_stop_timeout;
  272. u32 ch_prep_timeout;
  273. enum sdw_clk_stop_reset_behave reset_behave;
  274. bool high_PHY_capable;
  275. bool paging_support;
  276. bool bank_delay_support;
  277. enum sdw_p15_behave p15_behave;
  278. bool lane_control_support;
  279. u32 master_count;
  280. u32 source_ports;
  281. u32 sink_ports;
  282. struct sdw_dp0_prop *dp0_prop;
  283. struct sdw_dpn_prop *src_dpn_prop;
  284. struct sdw_dpn_prop *sink_dpn_prop;
  285. };
  286. /**
  287. * struct sdw_master_prop - Master properties
  288. * @revision: MIPI spec version of the implementation
  289. * @master_count: Number of masters
  290. * @clk_stop_mode: Bitmap for Clock Stop modes supported
  291. * @max_freq: Maximum Bus clock frequency, in Hz
  292. * @num_clk_gears: Number of clock gears supported
  293. * @clk_gears: Clock gears supported
  294. * @num_freq: Number of clock frequencies supported, in Hz
  295. * @freq: Clock frequencies supported, in Hz
  296. * @default_frame_rate: Controller default Frame rate, in Hz
  297. * @default_row: Number of rows
  298. * @default_col: Number of columns
  299. * @dynamic_frame: Dynamic frame supported
  300. * @err_threshold: Number of times that software may retry sending a single
  301. * command
  302. * @dpn_prop: Data Port N properties
  303. */
  304. struct sdw_master_prop {
  305. u32 revision;
  306. u32 master_count;
  307. enum sdw_clk_stop_mode clk_stop_mode;
  308. u32 max_freq;
  309. u32 num_clk_gears;
  310. u32 *clk_gears;
  311. u32 num_freq;
  312. u32 *freq;
  313. u32 default_frame_rate;
  314. u32 default_row;
  315. u32 default_col;
  316. bool dynamic_frame;
  317. u32 err_threshold;
  318. struct sdw_dpn_prop *dpn_prop;
  319. };
  320. int sdw_master_read_prop(struct sdw_bus *bus);
  321. int sdw_slave_read_prop(struct sdw_slave *slave);
  322. /*
  323. * SDW Slave Structures and APIs
  324. */
  325. /**
  326. * struct sdw_slave_id - Slave ID
  327. * @mfg_id: MIPI Manufacturer ID
  328. * @part_id: Device Part ID
  329. * @class_id: MIPI Class ID, unused now.
  330. * Currently a placeholder in MIPI SoundWire Spec
  331. * @unique_id: Device unique ID
  332. * @sdw_version: SDW version implemented
  333. *
  334. * The order of the IDs here does not follow the DisCo spec definitions
  335. */
  336. struct sdw_slave_id {
  337. __u16 mfg_id;
  338. __u16 part_id;
  339. __u8 class_id;
  340. __u8 unique_id:4;
  341. __u8 sdw_version:4;
  342. };
  343. /**
  344. * struct sdw_slave_intr_status - Slave interrupt status
  345. * @control_port: control port status
  346. * @port: data port status
  347. */
  348. struct sdw_slave_intr_status {
  349. u8 control_port;
  350. u8 port[15];
  351. };
  352. /**
  353. * sdw_reg_bank - SoundWire register banks
  354. * @SDW_BANK0: Soundwire register bank 0
  355. * @SDW_BANK1: Soundwire register bank 1
  356. */
  357. enum sdw_reg_bank {
  358. SDW_BANK0,
  359. SDW_BANK1,
  360. };
  361. /**
  362. * struct sdw_bus_conf: Bus configuration
  363. *
  364. * @clk_freq: Clock frequency, in Hz
  365. * @num_rows: Number of rows in frame
  366. * @num_cols: Number of columns in frame
  367. * @bank: Next register bank
  368. */
  369. struct sdw_bus_conf {
  370. unsigned int clk_freq;
  371. unsigned int num_rows;
  372. unsigned int num_cols;
  373. unsigned int bank;
  374. };
  375. /**
  376. * struct sdw_prepare_ch: Prepare/De-prepare Data Port channel
  377. *
  378. * @num: Port number
  379. * @ch_mask: Active channel mask
  380. * @prepare: Prepare (true) /de-prepare (false) channel
  381. * @bank: Register bank, which bank Slave/Master driver should program for
  382. * implementation defined registers. This is always updated to next_bank
  383. * value read from bus params.
  384. *
  385. */
  386. struct sdw_prepare_ch {
  387. unsigned int num;
  388. unsigned int ch_mask;
  389. bool prepare;
  390. unsigned int bank;
  391. };
  392. /**
  393. * enum sdw_port_prep_ops: Prepare operations for Data Port
  394. *
  395. * @SDW_OPS_PORT_PRE_PREP: Pre prepare operation for the Port
  396. * @SDW_OPS_PORT_PREP: Prepare operation for the Port
  397. * @SDW_OPS_PORT_POST_PREP: Post prepare operation for the Port
  398. */
  399. enum sdw_port_prep_ops {
  400. SDW_OPS_PORT_PRE_PREP = 0,
  401. SDW_OPS_PORT_PREP = 1,
  402. SDW_OPS_PORT_POST_PREP = 2,
  403. };
  404. /**
  405. * struct sdw_bus_params: Structure holding bus configuration
  406. *
  407. * @curr_bank: Current bank in use (BANK0/BANK1)
  408. * @next_bank: Next bank to use (BANK0/BANK1). next_bank will always be
  409. * set to !curr_bank
  410. * @max_dr_freq: Maximum double rate clock frequency supported, in Hz
  411. * @curr_dr_freq: Current double rate clock frequency, in Hz
  412. * @bandwidth: Current bandwidth
  413. * @col: Active columns
  414. * @row: Active rows
  415. */
  416. struct sdw_bus_params {
  417. enum sdw_reg_bank curr_bank;
  418. enum sdw_reg_bank next_bank;
  419. unsigned int max_dr_freq;
  420. unsigned int curr_dr_freq;
  421. unsigned int bandwidth;
  422. unsigned int col;
  423. unsigned int row;
  424. };
  425. /**
  426. * struct sdw_slave_ops: Slave driver callback ops
  427. *
  428. * @read_prop: Read Slave properties
  429. * @interrupt_callback: Device interrupt notification (invoked in thread
  430. * context)
  431. * @update_status: Update Slave status
  432. * @bus_config: Update the bus config for Slave
  433. * @port_prep: Prepare the port with parameters
  434. */
  435. struct sdw_slave_ops {
  436. int (*read_prop)(struct sdw_slave *sdw);
  437. int (*interrupt_callback)(struct sdw_slave *slave,
  438. struct sdw_slave_intr_status *status);
  439. int (*update_status)(struct sdw_slave *slave,
  440. enum sdw_slave_status status);
  441. int (*bus_config)(struct sdw_slave *slave,
  442. struct sdw_bus_params *params);
  443. int (*port_prep)(struct sdw_slave *slave,
  444. struct sdw_prepare_ch *prepare_ch,
  445. enum sdw_port_prep_ops pre_ops);
  446. };
  447. /**
  448. * struct sdw_slave - SoundWire Slave
  449. * @id: MIPI device ID
  450. * @dev: Linux device
  451. * @status: Status reported by the Slave
  452. * @bus: Bus handle
  453. * @ops: Slave callback ops
  454. * @prop: Slave properties
  455. * @node: node for bus list
  456. * @port_ready: Port ready completion flag for each Slave port
  457. * @dev_num: Device Number assigned by Bus
  458. */
  459. struct sdw_slave {
  460. struct sdw_slave_id id;
  461. struct device dev;
  462. enum sdw_slave_status status;
  463. struct sdw_bus *bus;
  464. const struct sdw_slave_ops *ops;
  465. struct sdw_slave_prop prop;
  466. struct list_head node;
  467. struct completion *port_ready;
  468. u16 dev_num;
  469. };
  470. #define dev_to_sdw_dev(_dev) container_of(_dev, struct sdw_slave, dev)
  471. struct sdw_driver {
  472. const char *name;
  473. int (*probe)(struct sdw_slave *sdw,
  474. const struct sdw_device_id *id);
  475. int (*remove)(struct sdw_slave *sdw);
  476. void (*shutdown)(struct sdw_slave *sdw);
  477. const struct sdw_device_id *id_table;
  478. const struct sdw_slave_ops *ops;
  479. struct device_driver driver;
  480. };
  481. #define SDW_SLAVE_ENTRY(_mfg_id, _part_id, _drv_data) \
  482. { .mfg_id = (_mfg_id), .part_id = (_part_id), \
  483. .driver_data = (unsigned long)(_drv_data) }
  484. int sdw_handle_slave_status(struct sdw_bus *bus,
  485. enum sdw_slave_status status[]);
  486. /*
  487. * SDW master structures and APIs
  488. */
  489. /**
  490. * struct sdw_port_params: Data Port parameters
  491. *
  492. * @num: Port number
  493. * @bps: Word length of the Port
  494. * @flow_mode: Port Data flow mode
  495. * @data_mode: Test modes or normal mode
  496. *
  497. * This is used to program the Data Port based on Data Port stream
  498. * parameters.
  499. */
  500. struct sdw_port_params {
  501. unsigned int num;
  502. unsigned int bps;
  503. unsigned int flow_mode;
  504. unsigned int data_mode;
  505. };
  506. /**
  507. * struct sdw_transport_params: Data Port Transport Parameters
  508. *
  509. * @blk_grp_ctrl_valid: Port implements block group control
  510. * @num: Port number
  511. * @blk_grp_ctrl: Block group control value
  512. * @sample_interval: Sample interval
  513. * @offset1: Blockoffset of the payload data
  514. * @offset2: Blockoffset of the payload data
  515. * @hstart: Horizontal start of the payload data
  516. * @hstop: Horizontal stop of the payload data
  517. * @blk_pkg_mode: Block per channel or block per port
  518. * @lane_ctrl: Data lane Port uses for Data transfer. Currently only single
  519. * data lane is supported in bus
  520. *
  521. * This is used to program the Data Port based on Data Port transport
  522. * parameters. All these parameters are banked and can be modified
  523. * during a bank switch without any artifacts in audio stream.
  524. */
  525. struct sdw_transport_params {
  526. bool blk_grp_ctrl_valid;
  527. unsigned int port_num;
  528. unsigned int blk_grp_ctrl;
  529. unsigned int sample_interval;
  530. unsigned int offset1;
  531. unsigned int offset2;
  532. unsigned int hstart;
  533. unsigned int hstop;
  534. unsigned int blk_pkg_mode;
  535. unsigned int lane_ctrl;
  536. };
  537. /**
  538. * struct sdw_enable_ch: Enable/disable Data Port channel
  539. *
  540. * @num: Port number
  541. * @ch_mask: Active channel mask
  542. * @enable: Enable (true) /disable (false) channel
  543. */
  544. struct sdw_enable_ch {
  545. unsigned int port_num;
  546. unsigned int ch_mask;
  547. bool enable;
  548. };
  549. /**
  550. * struct sdw_master_port_ops: Callback functions from bus to Master
  551. * driver to set Master Data ports.
  552. *
  553. * @dpn_set_port_params: Set the Port parameters for the Master Port.
  554. * Mandatory callback
  555. * @dpn_set_port_transport_params: Set transport parameters for the Master
  556. * Port. Mandatory callback
  557. * @dpn_port_prep: Port prepare operations for the Master Data Port.
  558. * @dpn_port_enable_ch: Enable the channels of Master Port.
  559. */
  560. struct sdw_master_port_ops {
  561. int (*dpn_set_port_params)(struct sdw_bus *bus,
  562. struct sdw_port_params *port_params,
  563. unsigned int bank);
  564. int (*dpn_set_port_transport_params)(struct sdw_bus *bus,
  565. struct sdw_transport_params *transport_params,
  566. enum sdw_reg_bank bank);
  567. int (*dpn_port_prep)(struct sdw_bus *bus,
  568. struct sdw_prepare_ch *prepare_ch);
  569. int (*dpn_port_enable_ch)(struct sdw_bus *bus,
  570. struct sdw_enable_ch *enable_ch, unsigned int bank);
  571. };
  572. struct sdw_msg;
  573. /**
  574. * struct sdw_defer - SDW deffered message
  575. * @length: message length
  576. * @complete: message completion
  577. * @msg: SDW message
  578. */
  579. struct sdw_defer {
  580. int length;
  581. struct completion complete;
  582. struct sdw_msg *msg;
  583. };
  584. /**
  585. * struct sdw_master_ops - Master driver ops
  586. * @read_prop: Read Master properties
  587. * @xfer_msg: Transfer message callback
  588. * @xfer_msg_defer: Defer version of transfer message callback
  589. * @reset_page_addr: Reset the SCP page address registers
  590. * @set_bus_conf: Set the bus configuration
  591. * @pre_bank_switch: Callback for pre bank switch
  592. * @post_bank_switch: Callback for post bank switch
  593. */
  594. struct sdw_master_ops {
  595. int (*read_prop)(struct sdw_bus *bus);
  596. enum sdw_command_response (*xfer_msg)
  597. (struct sdw_bus *bus, struct sdw_msg *msg);
  598. enum sdw_command_response (*xfer_msg_defer)
  599. (struct sdw_bus *bus, struct sdw_msg *msg,
  600. struct sdw_defer *defer);
  601. enum sdw_command_response (*reset_page_addr)
  602. (struct sdw_bus *bus, unsigned int dev_num);
  603. int (*set_bus_conf)(struct sdw_bus *bus,
  604. struct sdw_bus_params *params);
  605. int (*pre_bank_switch)(struct sdw_bus *bus);
  606. int (*post_bank_switch)(struct sdw_bus *bus);
  607. };
  608. /**
  609. * struct sdw_bus - SoundWire bus
  610. * @dev: Master linux device
  611. * @link_id: Link id number, can be 0 to N, unique for each Master
  612. * @slaves: list of Slaves on this bus
  613. * @assigned: Bitmap for Slave device numbers.
  614. * Bit set implies used number, bit clear implies unused number.
  615. * @bus_lock: bus lock
  616. * @msg_lock: message lock
  617. * @ops: Master callback ops
  618. * @port_ops: Master port callback ops
  619. * @params: Current bus parameters
  620. * @prop: Master properties
  621. * @m_rt_list: List of Master instance of all stream(s) running on Bus. This
  622. * is used to compute and program bus bandwidth, clock, frame shape,
  623. * transport and port parameters
  624. * @defer_msg: Defer message
  625. * @clk_stop_timeout: Clock stop timeout computed
  626. * @bank_switch_timeout: Bank switch timeout computed
  627. * @multi_link: Store bus property that indicates if multi links
  628. * are supported. This flag is populated by drivers after reading
  629. * appropriate firmware (ACPI/DT).
  630. */
  631. struct sdw_bus {
  632. struct device *dev;
  633. unsigned int link_id;
  634. struct list_head slaves;
  635. DECLARE_BITMAP(assigned, SDW_MAX_DEVICES);
  636. struct mutex bus_lock;
  637. struct mutex msg_lock;
  638. const struct sdw_master_ops *ops;
  639. const struct sdw_master_port_ops *port_ops;
  640. struct sdw_bus_params params;
  641. struct sdw_master_prop prop;
  642. struct list_head m_rt_list;
  643. struct sdw_defer defer_msg;
  644. unsigned int clk_stop_timeout;
  645. u32 bank_switch_timeout;
  646. bool multi_link;
  647. };
  648. int sdw_add_bus_master(struct sdw_bus *bus);
  649. void sdw_delete_bus_master(struct sdw_bus *bus);
  650. /**
  651. * sdw_port_config: Master or Slave Port configuration
  652. *
  653. * @num: Port number
  654. * @ch_mask: channels mask for port
  655. */
  656. struct sdw_port_config {
  657. unsigned int num;
  658. unsigned int ch_mask;
  659. };
  660. /**
  661. * sdw_stream_config: Master or Slave stream configuration
  662. *
  663. * @frame_rate: Audio frame rate of the stream, in Hz
  664. * @ch_count: Channel count of the stream
  665. * @bps: Number of bits per audio sample
  666. * @direction: Data direction
  667. * @type: Stream type PCM or PDM
  668. */
  669. struct sdw_stream_config {
  670. unsigned int frame_rate;
  671. unsigned int ch_count;
  672. unsigned int bps;
  673. enum sdw_data_direction direction;
  674. enum sdw_stream_type type;
  675. };
  676. /**
  677. * sdw_stream_state: Stream states
  678. *
  679. * @SDW_STREAM_ALLOCATED: New stream allocated.
  680. * @SDW_STREAM_CONFIGURED: Stream configured
  681. * @SDW_STREAM_PREPARED: Stream prepared
  682. * @SDW_STREAM_ENABLED: Stream enabled
  683. * @SDW_STREAM_DISABLED: Stream disabled
  684. * @SDW_STREAM_DEPREPARED: Stream de-prepared
  685. * @SDW_STREAM_RELEASED: Stream released
  686. */
  687. enum sdw_stream_state {
  688. SDW_STREAM_ALLOCATED = 0,
  689. SDW_STREAM_CONFIGURED = 1,
  690. SDW_STREAM_PREPARED = 2,
  691. SDW_STREAM_ENABLED = 3,
  692. SDW_STREAM_DISABLED = 4,
  693. SDW_STREAM_DEPREPARED = 5,
  694. SDW_STREAM_RELEASED = 6,
  695. };
  696. /**
  697. * sdw_stream_params: Stream parameters
  698. *
  699. * @rate: Sampling frequency, in Hz
  700. * @ch_count: Number of channels
  701. * @bps: bits per channel sample
  702. */
  703. struct sdw_stream_params {
  704. unsigned int rate;
  705. unsigned int ch_count;
  706. unsigned int bps;
  707. };
  708. /**
  709. * sdw_stream_runtime: Runtime stream parameters
  710. *
  711. * @name: SoundWire stream name
  712. * @params: Stream parameters
  713. * @state: Current state of the stream
  714. * @type: Stream type PCM or PDM
  715. * @master_list: List of Master runtime(s) in this stream.
  716. * master_list can contain only one m_rt per Master instance
  717. * for a stream
  718. */
  719. struct sdw_stream_runtime {
  720. char *name;
  721. struct sdw_stream_params params;
  722. enum sdw_stream_state state;
  723. enum sdw_stream_type type;
  724. struct list_head master_list;
  725. };
  726. struct sdw_stream_runtime *sdw_alloc_stream(char *stream_name);
  727. void sdw_release_stream(struct sdw_stream_runtime *stream);
  728. int sdw_stream_add_master(struct sdw_bus *bus,
  729. struct sdw_stream_config *stream_config,
  730. struct sdw_port_config *port_config,
  731. unsigned int num_ports,
  732. struct sdw_stream_runtime *stream);
  733. int sdw_stream_add_slave(struct sdw_slave *slave,
  734. struct sdw_stream_config *stream_config,
  735. struct sdw_port_config *port_config,
  736. unsigned int num_ports,
  737. struct sdw_stream_runtime *stream);
  738. int sdw_stream_remove_master(struct sdw_bus *bus,
  739. struct sdw_stream_runtime *stream);
  740. int sdw_stream_remove_slave(struct sdw_slave *slave,
  741. struct sdw_stream_runtime *stream);
  742. int sdw_prepare_stream(struct sdw_stream_runtime *stream);
  743. int sdw_enable_stream(struct sdw_stream_runtime *stream);
  744. int sdw_disable_stream(struct sdw_stream_runtime *stream);
  745. int sdw_deprepare_stream(struct sdw_stream_runtime *stream);
  746. /* messaging and data APIs */
  747. int sdw_read(struct sdw_slave *slave, u32 addr);
  748. int sdw_write(struct sdw_slave *slave, u32 addr, u8 value);
  749. int sdw_nread(struct sdw_slave *slave, u32 addr, size_t count, u8 *val);
  750. int sdw_nwrite(struct sdw_slave *slave, u32 addr, size_t count, u8 *val);
  751. #endif /* __SOUNDWIRE_H */