bus.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
  2. // Copyright(c) 2015-17 Intel Corporation.
  3. #ifndef __SDW_BUS_H
  4. #define __SDW_BUS_H
  5. #if IS_ENABLED(CONFIG_ACPI)
  6. int sdw_acpi_find_slaves(struct sdw_bus *bus);
  7. #else
  8. static inline int sdw_acpi_find_slaves(struct sdw_bus *bus)
  9. {
  10. return -ENOTSUPP;
  11. }
  12. #endif
  13. void sdw_extract_slave_id(struct sdw_bus *bus,
  14. u64 addr, struct sdw_slave_id *id);
  15. enum {
  16. SDW_MSG_FLAG_READ = 0,
  17. SDW_MSG_FLAG_WRITE,
  18. };
  19. /**
  20. * struct sdw_msg - Message structure
  21. * @addr: Register address accessed in the Slave
  22. * @len: number of messages
  23. * @dev_num: Slave device number
  24. * @addr_page1: SCP address page 1 Slave register
  25. * @addr_page2: SCP address page 2 Slave register
  26. * @flags: transfer flags, indicate if xfer is read or write
  27. * @buf: message data buffer
  28. * @ssp_sync: Send message at SSP (Stream Synchronization Point)
  29. * @page: address requires paging
  30. */
  31. struct sdw_msg {
  32. u16 addr;
  33. u16 len;
  34. u8 dev_num;
  35. u8 addr_page1;
  36. u8 addr_page2;
  37. u8 flags;
  38. u8 *buf;
  39. bool ssp_sync;
  40. bool page;
  41. };
  42. #define SDW_DOUBLE_RATE_FACTOR 2
  43. extern int rows[SDW_FRAME_ROWS];
  44. extern int cols[SDW_FRAME_COLS];
  45. /**
  46. * sdw_port_runtime: Runtime port parameters for Master or Slave
  47. *
  48. * @num: Port number. For audio streams, valid port number ranges from
  49. * [1,14]
  50. * @ch_mask: Channel mask
  51. * @transport_params: Transport parameters
  52. * @port_params: Port parameters
  53. * @port_node: List node for Master or Slave port_list
  54. *
  55. * SoundWire spec has no mention of ports for Master interface but the
  56. * concept is logically extended.
  57. */
  58. struct sdw_port_runtime {
  59. int num;
  60. int ch_mask;
  61. struct sdw_transport_params transport_params;
  62. struct sdw_port_params port_params;
  63. struct list_head port_node;
  64. };
  65. /**
  66. * sdw_slave_runtime: Runtime Stream parameters for Slave
  67. *
  68. * @slave: Slave handle
  69. * @direction: Data direction for Slave
  70. * @ch_count: Number of channels handled by the Slave for
  71. * this stream
  72. * @m_rt_node: sdw_master_runtime list node
  73. * @port_list: List of Slave Ports configured for this stream
  74. */
  75. struct sdw_slave_runtime {
  76. struct sdw_slave *slave;
  77. enum sdw_data_direction direction;
  78. unsigned int ch_count;
  79. struct list_head m_rt_node;
  80. struct list_head port_list;
  81. };
  82. /**
  83. * sdw_master_runtime: Runtime stream parameters for Master
  84. *
  85. * @bus: Bus handle
  86. * @stream: Stream runtime handle
  87. * @direction: Data direction for Master
  88. * @ch_count: Number of channels handled by the Master for
  89. * this stream, can be zero.
  90. * @slave_rt_list: Slave runtime list
  91. * @port_list: List of Master Ports configured for this stream, can be zero.
  92. * @bus_node: sdw_bus m_rt_list node
  93. */
  94. struct sdw_master_runtime {
  95. struct sdw_bus *bus;
  96. struct sdw_stream_runtime *stream;
  97. enum sdw_data_direction direction;
  98. unsigned int ch_count;
  99. struct list_head slave_rt_list;
  100. struct list_head port_list;
  101. struct list_head bus_node;
  102. };
  103. struct sdw_dpn_prop *sdw_get_slave_dpn_prop(struct sdw_slave *slave,
  104. enum sdw_data_direction direction,
  105. unsigned int port_num);
  106. int sdw_configure_dpn_intr(struct sdw_slave *slave, int port,
  107. bool enable, int mask);
  108. int sdw_transfer(struct sdw_bus *bus, struct sdw_msg *msg);
  109. int sdw_transfer_defer(struct sdw_bus *bus, struct sdw_msg *msg,
  110. struct sdw_defer *defer);
  111. #define SDW_READ_INTR_CLEAR_RETRY 10
  112. int sdw_fill_msg(struct sdw_msg *msg, struct sdw_slave *slave,
  113. u32 addr, size_t count, u16 dev_num, u8 flags, u8 *buf);
  114. /* Read-Modify-Write Slave register */
  115. static inline int
  116. sdw_update(struct sdw_slave *slave, u32 addr, u8 mask, u8 val)
  117. {
  118. int tmp;
  119. tmp = sdw_read(slave, addr);
  120. if (tmp < 0)
  121. return tmp;
  122. tmp = (tmp & ~mask) | val;
  123. return sdw_write(slave, addr, tmp);
  124. }
  125. #endif /* __SDW_BUS_H */