slimbus.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2011-2017, The Linux Foundation
  4. */
  5. #ifndef _LINUX_SLIMBUS_H
  6. #define _LINUX_SLIMBUS_H
  7. #include <linux/device.h>
  8. #include <linux/module.h>
  9. #include <linux/completion.h>
  10. #include <linux/mod_devicetable.h>
  11. extern struct bus_type slimbus_bus;
  12. /**
  13. * struct slim_eaddr - Enumeration address for a SLIMbus device
  14. * @instance: Instance value
  15. * @dev_index: Device index
  16. * @prod_code: Product code
  17. * @manf_id: Manufacturer Id for the device
  18. */
  19. struct slim_eaddr {
  20. u8 instance;
  21. u8 dev_index;
  22. u16 prod_code;
  23. u16 manf_id;
  24. } __packed;
  25. /**
  26. * enum slim_device_status - slim device status
  27. * @SLIM_DEVICE_STATUS_DOWN: Slim device is absent or not reported yet.
  28. * @SLIM_DEVICE_STATUS_UP: Slim device is announced on the bus.
  29. * @SLIM_DEVICE_STATUS_RESERVED: Reserved for future use.
  30. */
  31. enum slim_device_status {
  32. SLIM_DEVICE_STATUS_DOWN = 0,
  33. SLIM_DEVICE_STATUS_UP,
  34. SLIM_DEVICE_STATUS_RESERVED,
  35. };
  36. struct slim_controller;
  37. /**
  38. * struct slim_device - Slim device handle.
  39. * @dev: Driver model representation of the device.
  40. * @e_addr: Enumeration address of this device.
  41. * @status: slim device status
  42. * @ctrl: slim controller instance.
  43. * @laddr: 1-byte Logical address of this device.
  44. * @is_laddr_valid: indicates if the laddr is valid or not
  45. * @stream_list: List of streams on this device
  46. * @stream_list_lock: lock to protect the stream list
  47. *
  48. * This is the client/device handle returned when a SLIMbus
  49. * device is registered with a controller.
  50. * Pointer to this structure is used by client-driver as a handle.
  51. */
  52. struct slim_device {
  53. struct device dev;
  54. struct slim_eaddr e_addr;
  55. struct slim_controller *ctrl;
  56. enum slim_device_status status;
  57. u8 laddr;
  58. bool is_laddr_valid;
  59. struct list_head stream_list;
  60. spinlock_t stream_list_lock;
  61. };
  62. #define to_slim_device(d) container_of(d, struct slim_device, dev)
  63. /**
  64. * struct slim_driver - SLIMbus 'generic device' (slave) device driver
  65. * (similar to 'spi_device' on SPI)
  66. * @probe: Binds this driver to a SLIMbus device.
  67. * @remove: Unbinds this driver from the SLIMbus device.
  68. * @shutdown: Standard shutdown callback used during powerdown/halt.
  69. * @device_status: This callback is called when
  70. * - The device reports present and gets a laddr assigned
  71. * - The device reports absent, or the bus goes down.
  72. * @driver: SLIMbus device drivers should initialize name and owner field of
  73. * this structure
  74. * @id_table: List of SLIMbus devices supported by this driver
  75. */
  76. struct slim_driver {
  77. int (*probe)(struct slim_device *sl);
  78. void (*remove)(struct slim_device *sl);
  79. void (*shutdown)(struct slim_device *sl);
  80. int (*device_status)(struct slim_device *sl,
  81. enum slim_device_status s);
  82. struct device_driver driver;
  83. const struct slim_device_id *id_table;
  84. };
  85. #define to_slim_driver(d) container_of(d, struct slim_driver, driver)
  86. /**
  87. * struct slim_val_inf - Slimbus value or information element
  88. * @start_offset: Specifies starting offset in information/value element map
  89. * @rbuf: buffer to read the values
  90. * @wbuf: buffer to write
  91. * @num_bytes: upto 16. This ensures that the message will fit the slicesize
  92. * per SLIMbus spec
  93. * @comp: completion for asynchronous operations, valid only if TID is
  94. * required for transaction, like REQUEST operations.
  95. * Rest of the transactions are synchronous anyway.
  96. */
  97. struct slim_val_inf {
  98. u16 start_offset;
  99. u8 num_bytes;
  100. u8 *rbuf;
  101. const u8 *wbuf;
  102. struct completion *comp;
  103. };
  104. #define SLIM_DEVICE_MAX_CHANNELS 256
  105. /* A SLIMBus Device may have frmo 0 to 31 Ports (inclusive) */
  106. #define SLIM_DEVICE_MAX_PORTS 32
  107. /**
  108. * struct slim_stream_config - SLIMbus stream configuration
  109. * Configuring a stream is done at hw_params or prepare call
  110. * from audio drivers where they have all the required information
  111. * regarding rate, number of channels and so on.
  112. * There is a 1:1 mapping of channel and ports.
  113. *
  114. * @rate: data rate
  115. * @bps: bits per data sample
  116. * @ch_count: number of channels
  117. * @chs: pointer to list of channel numbers
  118. * @port_mask: port mask of ports to use for this stream
  119. * @direction: direction of the stream, SNDRV_PCM_STREAM_PLAYBACK
  120. * or SNDRV_PCM_STREAM_CAPTURE.
  121. */
  122. struct slim_stream_config {
  123. unsigned int rate;
  124. unsigned int bps;
  125. /* MAX 256 channels */
  126. unsigned int ch_count;
  127. unsigned int *chs;
  128. /* Max 32 ports per device */
  129. unsigned long port_mask;
  130. int direction;
  131. };
  132. /*
  133. * use a macro to avoid include chaining to get THIS_MODULE
  134. */
  135. #define slim_driver_register(drv) \
  136. __slim_driver_register(drv, THIS_MODULE)
  137. int __slim_driver_register(struct slim_driver *drv, struct module *owner);
  138. void slim_driver_unregister(struct slim_driver *drv);
  139. /**
  140. * module_slim_driver() - Helper macro for registering a SLIMbus driver
  141. * @__slim_driver: slimbus_driver struct
  142. *
  143. * Helper macro for SLIMbus drivers which do not do anything special in module
  144. * init/exit. This eliminates a lot of boilerplate. Each module may only
  145. * use this macro once, and calling it replaces module_init() and module_exit()
  146. */
  147. #define module_slim_driver(__slim_driver) \
  148. module_driver(__slim_driver, slim_driver_register, \
  149. slim_driver_unregister)
  150. static inline void *slim_get_devicedata(const struct slim_device *dev)
  151. {
  152. return dev_get_drvdata(&dev->dev);
  153. }
  154. static inline void slim_set_devicedata(struct slim_device *dev, void *data)
  155. {
  156. dev_set_drvdata(&dev->dev, data);
  157. }
  158. struct slim_device *of_slim_get_device(struct slim_controller *ctrl,
  159. struct device_node *np);
  160. struct slim_device *slim_get_device(struct slim_controller *ctrl,
  161. struct slim_eaddr *e_addr);
  162. int slim_get_logical_addr(struct slim_device *sbdev);
  163. /*
  164. * slim_vote_for_suspend : initiate immediate suspend.
  165. * @sb: client handle requesting the address.
  166. *
  167. * return zero in case of suspended success.
  168. */
  169. extern int slim_vote_for_suspend(struct slim_device *sb);
  170. /* Information Element management messages */
  171. #define SLIM_MSG_MC_REQUEST_INFORMATION 0x20
  172. #define SLIM_MSG_MC_REQUEST_CLEAR_INFORMATION 0x21
  173. #define SLIM_MSG_MC_REPLY_INFORMATION 0x24
  174. #define SLIM_MSG_MC_CLEAR_INFORMATION 0x28
  175. #define SLIM_MSG_MC_REPORT_INFORMATION 0x29
  176. /* Value Element management messages */
  177. #define SLIM_MSG_MC_REQUEST_VALUE 0x60
  178. #define SLIM_MSG_MC_REQUEST_CHANGE_VALUE 0x61
  179. #define SLIM_MSG_MC_REPLY_VALUE 0x64
  180. #define SLIM_MSG_MC_CHANGE_VALUE 0x68
  181. int slim_xfer_msg(struct slim_device *sbdev, struct slim_val_inf *msg,
  182. u8 mc);
  183. int slim_readb(struct slim_device *sdev, u32 addr);
  184. int slim_writeb(struct slim_device *sdev, u32 addr, u8 value);
  185. int slim_read(struct slim_device *sdev, u32 addr, size_t count, u8 *val);
  186. int slim_write(struct slim_device *sdev, u32 addr, size_t count, u8 *val);
  187. /* SLIMbus Stream apis */
  188. struct slim_stream_runtime;
  189. struct slim_stream_runtime *slim_stream_allocate(struct slim_device *dev,
  190. const char *sname);
  191. int slim_stream_prepare(struct slim_stream_runtime *stream,
  192. struct slim_stream_config *c);
  193. int slim_stream_enable(struct slim_stream_runtime *stream);
  194. int slim_stream_disable(struct slim_stream_runtime *stream);
  195. int slim_stream_unprepare(struct slim_stream_runtime *stream);
  196. int slim_stream_unprepare_disconnect_port(struct slim_stream_runtime *stream,
  197. bool disconnect_ports, bool is_session_completed);
  198. int slim_stream_free(struct slim_stream_runtime *stream);
  199. #endif /* _LINUX_SLIMBUS_H */