slimbus.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2011-2017, The Linux Foundation
  4. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef _DRIVERS_SLIMBUS_H
  7. #define _DRIVERS_SLIMBUS_H
  8. #include <linux/ipc_logging.h>
  9. #include <linux/module.h>
  10. #include <linux/device.h>
  11. #include <linux/mutex.h>
  12. #include <linux/completion.h>
  13. #include <linux/slimbus.h>
  14. /* Standard values per SLIMbus spec needed by controllers and devices */
  15. #define SLIM_CL_PER_SUPERFRAME 6144
  16. #define SLIM_CL_PER_SUPERFRAME_DIV8 (SLIM_CL_PER_SUPERFRAME >> 3)
  17. /* SLIMbus message types. Related to interpretation of message code. */
  18. #define SLIM_MSG_MT_CORE 0x0
  19. #define SLIM_MSG_MT_DEST_REFERRED_USER 0x2
  20. #define SLIM_MSG_MT_SRC_REFERRED_USER 0x6
  21. /*
  22. * SLIM Broadcast header format
  23. * BYTE 0: MT[7:5] RL[4:0]
  24. * BYTE 1: RSVD[7] MC[6:0]
  25. * BYTE 2: RSVD[7:6] DT[5:4] PI[3:0]
  26. */
  27. #define SLIM_MSG_MT_MASK GENMASK(2, 0)
  28. #define SLIM_MSG_MT_SHIFT 5
  29. #define SLIM_MSG_RL_MASK GENMASK(4, 0)
  30. #define SLIM_MSG_RL_SHIFT 0
  31. #define SLIM_MSG_MC_MASK GENMASK(6, 0)
  32. #define SLIM_MSG_MC_SHIFT 0
  33. #define SLIM_MSG_DT_MASK GENMASK(1, 0)
  34. #define SLIM_MSG_DT_SHIFT 4
  35. #define SLIM_HEADER_GET_MT(b) ((b >> SLIM_MSG_MT_SHIFT) & SLIM_MSG_MT_MASK)
  36. #define SLIM_HEADER_GET_RL(b) ((b >> SLIM_MSG_RL_SHIFT) & SLIM_MSG_RL_MASK)
  37. #define SLIM_HEADER_GET_MC(b) ((b >> SLIM_MSG_MC_SHIFT) & SLIM_MSG_MC_MASK)
  38. #define SLIM_HEADER_GET_DT(b) ((b >> SLIM_MSG_DT_SHIFT) & SLIM_MSG_DT_MASK)
  39. /* Device management messages used by this framework */
  40. #define SLIM_MSG_MC_REPORT_PRESENT 0x1
  41. #define SLIM_MSG_MC_ASSIGN_LOGICAL_ADDRESS 0x2
  42. #define SLIM_MSG_MC_REPORT_ABSENT 0xF
  43. /* Data channel management messages */
  44. #define SLIM_MSG_MC_CONNECT_SOURCE 0x10
  45. #define SLIM_MSG_MC_CONNECT_SINK 0x11
  46. #define SLIM_MSG_MC_DISCONNECT_PORT 0x14
  47. #define SLIM_MSG_MC_CHANGE_CONTENT 0x18
  48. /* Clock pause Reconfiguration messages */
  49. #define SLIM_MSG_MC_BEGIN_RECONFIGURATION 0x40
  50. #define SLIM_MSG_MC_NEXT_PAUSE_CLOCK 0x4A
  51. #define SLIM_MSG_MC_NEXT_DEFINE_CHANNEL 0x50
  52. #define SLIM_MSG_MC_NEXT_DEFINE_CONTENT 0x51
  53. #define SLIM_MSG_MC_NEXT_ACTIVATE_CHANNEL 0x54
  54. #define SLIM_MSG_MC_NEXT_DEACTIVATE_CHANNEL 0x55
  55. #define SLIM_MSG_MC_NEXT_REMOVE_CHANNEL 0x58
  56. #define SLIM_MSG_MC_RECONFIGURE_NOW 0x5F
  57. /* Clock pause values per SLIMbus spec */
  58. #define SLIM_CLK_FAST 0
  59. #define SLIM_CLK_CONST_PHASE 1
  60. #define SLIM_CLK_UNSPECIFIED 2
  61. /* Destination type Values */
  62. #define SLIM_MSG_DEST_LOGICALADDR 0
  63. #define SLIM_MSG_DEST_ENUMADDR 1
  64. #define SLIM_MSG_DEST_BROADCAST 3
  65. /* Standard values per SLIMbus spec needed by controllers and devices */
  66. #define SLIM_MAX_CLK_GEAR 10
  67. #define SLIM_MIN_CLK_GEAR 1
  68. #define SLIM_SLOT_LEN_BITS 4
  69. /* Indicate that the frequency of the flow and the bus frequency are locked */
  70. #define SLIM_CHANNEL_CONTENT_FL BIT(7)
  71. /* Standard values per SLIMbus spec needed by controllers and devices */
  72. #define SLIM_CL_PER_SUPERFRAME 6144
  73. #define SLIM_SLOTS_PER_SUPERFRAME (SLIM_CL_PER_SUPERFRAME >> 2)
  74. #define SLIM_SL_PER_SUPERFRAME (SLIM_CL_PER_SUPERFRAME >> 2)
  75. /* Manager's logical address is set to 0xFF per spec */
  76. #define SLIM_LA_MANAGER 0xFF
  77. #define SLIM_MAX_TIDS 256
  78. void __slimbus_dbg(const char *func, const char *fmt, ...);
  79. #define slimbus_dbg(fmt, ...) \
  80. __slimbus_dbg(__func__, \
  81. fmt, ##__VA_ARGS__) \
  82. /* slimbus supported frequency values */
  83. #define SLIM_FREQ_441 44100
  84. #define SLIM_FREQ_882 88200
  85. /* slimbus base frequency values */
  86. #define SLIM_BASE_FREQ_11 11025
  87. #define SLIM_BASE_FREQ_4 4000
  88. /**
  89. * This is Workaround implementation to avoid redzone overwritten corruption
  90. * causing by ngd child device name change in BT driver, changed device name
  91. * must be having the same size according to the device name allocated in
  92. * slimbus driver.
  93. * Adding EXTRA_CHAR to support the name change as expected name change in
  94. * BT driver is not possible due to dependent drivers.
  95. */
  96. #define BT_WAR
  97. #ifdef BT_WAR
  98. #define EXTRA_CHAR " "
  99. #else
  100. #define EXTRA_CHAR ""
  101. #endif
  102. /**
  103. * struct slim_framer - Represents SLIMbus framer.
  104. * Every controller may have multiple framers. There is 1 active framer device
  105. * responsible for clocking the bus.
  106. * Manager is responsible for framer hand-over.
  107. * @dev: Driver model representation of the device.
  108. * @e_addr: Enumeration address of the framer.
  109. * @rootfreq: Root Frequency at which the framer can run. This is maximum
  110. * frequency ('clock gear 10') at which the bus can operate.
  111. * @superfreq: Superframes per root frequency. Every frame is 6144 bits.
  112. */
  113. struct slim_framer {
  114. struct device dev;
  115. struct slim_eaddr e_addr;
  116. int rootfreq;
  117. int superfreq;
  118. };
  119. #define to_slim_framer(d) container_of(d, struct slim_framer, dev)
  120. /**
  121. * struct slim_msg_txn - Message to be sent by the controller.
  122. * This structure has packet header,
  123. * payload and buffer to be filled (if any)
  124. * @rl: Header field. remaining length.
  125. * @mt: Header field. Message type.
  126. * @mc: Header field. LSB is message code for type mt.
  127. * @dt: Header field. Destination type.
  128. * @ec: Element code. Used for elemental access APIs.
  129. * @tid: Transaction ID. Used for messages expecting response.
  130. * (relevant for message-codes involving read operation)
  131. * @la: Logical address of the device this message is going to.
  132. * (Not used when destination type is broadcast.)
  133. * @msg: Elemental access message to be read/written
  134. * @comp: completion if read/write is synchronous, used internally
  135. * for tid based transactions.
  136. */
  137. struct slim_msg_txn {
  138. u8 rl;
  139. u8 mt;
  140. u8 mc;
  141. u8 dt;
  142. u16 ec;
  143. u8 tid;
  144. u8 la;
  145. struct slim_val_inf *msg;
  146. struct completion *comp;
  147. };
  148. /* Frequently used message transaction structures */
  149. #define DEFINE_SLIM_LDEST_TXN(name, mc, rl, la, msg) \
  150. struct slim_msg_txn name = { rl, 0, mc, SLIM_MSG_DEST_LOGICALADDR, 0,\
  151. 0, la, msg, }
  152. #define DEFINE_SLIM_BCAST_TXN(name, mc, rl, la, msg) \
  153. struct slim_msg_txn name = { rl, 0, mc, SLIM_MSG_DEST_BROADCAST, 0,\
  154. 0, la, msg, }
  155. #define DEFINE_SLIM_EDEST_TXN(name, mc, rl, la, msg) \
  156. struct slim_msg_txn name = { rl, 0, mc, SLIM_MSG_DEST_ENUMADDR, 0,\
  157. 0, la, msg, }
  158. /**
  159. * enum slim_clk_state: SLIMbus controller's clock state used internally for
  160. * maintaining current clock state.
  161. * @SLIM_CLK_ACTIVE: SLIMbus clock is active
  162. * @SLIM_CLK_ENTERING_PAUSE: SLIMbus clock pause sequence is being sent on the
  163. * bus. If this succeeds, state changes to SLIM_CLK_PAUSED. If the
  164. * transition fails, state changes back to SLIM_CLK_ACTIVE
  165. * @SLIM_CLK_PAUSED: SLIMbus controller clock has paused.
  166. */
  167. enum slim_clk_state {
  168. SLIM_CLK_ACTIVE,
  169. SLIM_CLK_ENTERING_PAUSE,
  170. SLIM_CLK_PAUSED,
  171. };
  172. /**
  173. * struct slim_sched: Framework uses this structure internally for scheduling.
  174. * @clk_state: Controller's clock state from enum slim_clk_state
  175. * @pause_comp: Signals completion of clock pause sequence. This is useful when
  176. * client tries to call SLIMbus transaction when controller is entering
  177. * clock pause.
  178. * @m_reconf: This mutex is held until current reconfiguration (data channel
  179. * scheduling, message bandwidth reservation) is done. Message APIs can
  180. * use the bus concurrently when this mutex is held since elemental access
  181. * messages can be sent on the bus when reconfiguration is in progress.
  182. */
  183. struct slim_sched {
  184. enum slim_clk_state clk_state;
  185. struct completion pause_comp;
  186. struct mutex m_reconf;
  187. };
  188. /**
  189. * enum slim_port_direction: SLIMbus port direction
  190. *
  191. * @SLIM_PORT_SINK: SLIMbus port is a sink
  192. * @SLIM_PORT_SOURCE: SLIMbus port is a source
  193. */
  194. enum slim_port_direction {
  195. SLIM_PORT_SINK = 0,
  196. SLIM_PORT_SOURCE,
  197. };
  198. /**
  199. * enum slim_port_state: SLIMbus Port/Endpoint state machine
  200. * according to SLIMbus Spec 2.0
  201. * @SLIM_PORT_DISCONNECTED: SLIMbus port is disconnected
  202. * entered from Unconfigure/configured state after
  203. * DISCONNECT_PORT or REMOVE_CHANNEL core command
  204. * @SLIM_PORT_UNCONFIGURED: SLIMbus port is in unconfigured state.
  205. * entered from disconnect state after CONNECT_SOURCE/SINK core command
  206. * @SLIM_PORT_CONFIGURED: SLIMbus port is in configured state.
  207. * entered from unconfigured state after DEFINE_CHANNEL, DEFINE_CONTENT
  208. * and ACTIVATE_CHANNEL core commands. Ready for data transmission.
  209. */
  210. enum slim_port_state {
  211. SLIM_PORT_DISCONNECTED = 0,
  212. SLIM_PORT_UNCONFIGURED,
  213. SLIM_PORT_CONFIGURED,
  214. };
  215. /**
  216. * enum slim_channel_state: SLIMbus channel state machine used by core.
  217. * @SLIM_CH_STATE_DISCONNECTED: SLIMbus channel is disconnected
  218. * @SLIM_CH_STATE_ALLOCATED: SLIMbus channel is allocated
  219. * @SLIM_CH_STATE_ASSOCIATED: SLIMbus channel is associated with port
  220. * @SLIM_CH_STATE_DEFINED: SLIMbus channel parameters are defined
  221. * @SLIM_CH_STATE_CONTENT_DEFINED: SLIMbus channel content is defined
  222. * @SLIM_CH_STATE_ACTIVE: SLIMbus channel is active and ready for data
  223. * @SLIM_CH_STATE_REMOVED: SLIMbus channel is inactive and removed
  224. */
  225. enum slim_channel_state {
  226. SLIM_CH_STATE_DISCONNECTED = 0,
  227. SLIM_CH_STATE_ALLOCATED,
  228. SLIM_CH_STATE_ASSOCIATED,
  229. SLIM_CH_STATE_DEFINED,
  230. SLIM_CH_STATE_CONTENT_DEFINED,
  231. SLIM_CH_STATE_ACTIVE,
  232. SLIM_CH_STATE_REMOVED,
  233. };
  234. /**
  235. * enum slim_ch_data_fmt: SLIMbus channel data Type identifiers according to
  236. * Table 60 of SLIMbus Spec 1.01.01
  237. * @SLIM_CH_DATA_FMT_NOT_DEFINED: Undefined
  238. * @SLIM_CH_DATA_FMT_LPCM_AUDIO: LPCM audio
  239. * @SLIM_CH_DATA_FMT_IEC61937_COMP_AUDIO: IEC61937 Compressed audio
  240. * @SLIM_CH_DATA_FMT_PACKED_PDM_AUDIO: Packed PDM audio
  241. */
  242. enum slim_ch_data_fmt {
  243. SLIM_CH_DATA_FMT_NOT_DEFINED = 0,
  244. SLIM_CH_DATA_FMT_LPCM_AUDIO = 1,
  245. SLIM_CH_DATA_FMT_IEC61937_COMP_AUDIO = 2,
  246. SLIM_CH_DATA_FMT_PACKED_PDM_AUDIO = 3,
  247. };
  248. /**
  249. * enum slim_ch_aux_bit_fmt: SLIMbus channel Aux Field format IDs according to
  250. * Table 63 of SLIMbus Spec 2.0
  251. * @SLIM_CH_AUX_FMT_NOT_APPLICABLE: Undefined
  252. * @SLIM_CH_AUX_FMT_ZCUV_TUNNEL_IEC60958: ZCUV for tunneling IEC60958
  253. * @SLIM_CH_AUX_FMT_USER_DEFINED: User defined
  254. */
  255. enum slim_ch_aux_bit_fmt {
  256. SLIM_CH_AUX_FMT_NOT_APPLICABLE = 0,
  257. SLIM_CH_AUX_FMT_ZCUV_TUNNEL_IEC60958 = 1,
  258. SLIM_CH_AUX_FMT_USER_DEFINED = 0xF,
  259. };
  260. /**
  261. * struct slim_channel - SLIMbus channel, used for state machine
  262. *
  263. * @id: ID of channel
  264. * @prrate: Presense rate of channel from Table 66 of SLIMbus 2.0 Specs
  265. * @seg_dist: segment distribution code from Table 20 of SLIMbus 2.0 Specs
  266. * @data_fmt: Data format of channel.
  267. * @aux_fmt: Aux format for this channel.
  268. * @state: channel state machine
  269. */
  270. struct slim_channel {
  271. int id;
  272. int prrate;
  273. int seg_dist;
  274. enum slim_ch_data_fmt data_fmt;
  275. enum slim_ch_aux_bit_fmt aux_fmt;
  276. enum slim_channel_state state;
  277. };
  278. /**
  279. * struct slim_port - SLIMbus port
  280. *
  281. * @id: Port id
  282. * @direction: Port direction, Source or Sink.
  283. * @state: state machine of port.
  284. * @ch: channel associated with this port.
  285. */
  286. struct slim_port {
  287. int id;
  288. enum slim_port_direction direction;
  289. enum slim_port_state state;
  290. struct slim_channel ch;
  291. };
  292. /**
  293. * enum slim_transport_protocol: SLIMbus Transport protocol list from
  294. * Table 47 of SLIMbus 2.0 specs.
  295. * @SLIM_PROTO_ISO: Isochronous Protocol, no flow control as data rate match
  296. * channel rate flow control embedded in the data.
  297. * @SLIM_RESERVED: Reserved protocol bit specific to satellite driver.
  298. * @SLIM_PROTO_PUSH: Pushed Protocol, includes flow control, Used to carry
  299. * data whose rate is equal to, or lower than the channel rate.
  300. * @SLIM_PROTO_PULL: Pulled Protocol, similar usage as pushed protocol
  301. * but pull is a unicast.
  302. * @SLIM_PROTO_LOCKED: Locked Protocol
  303. * @SLIM_PROTO_ASYNC_SMPLX: Asynchronous Protocol-Simplex
  304. * @SLIM_PROTO_ASYNC_HALF_DUP: Asynchronous Protocol-Half-duplex
  305. * @SLIM_PROTO_EXT_SMPLX: Extended Asynchronous Protocol-Simplex
  306. * @SLIM_PROTO_EXT_HALF_DUP: Extended Asynchronous Protocol-Half-duplex
  307. */
  308. enum slim_transport_protocol {
  309. SLIM_PROTO_ISO = 0,
  310. SLIM_RESERVED,
  311. SLIM_PROTO_PUSH,
  312. SLIM_PROTO_PULL,
  313. SLIM_PROTO_LOCKED,
  314. SLIM_PROTO_ASYNC_SMPLX,
  315. SLIM_PROTO_ASYNC_HALF_DUP,
  316. SLIM_PROTO_EXT_SMPLX,
  317. SLIM_PROTO_EXT_HALF_DUP,
  318. };
  319. /*
  320. * enum slim_ch_control: Channel control.
  321. * Activate will schedule channel and/or group of channels in the TDM frame.
  322. * Suspend will keep the schedule but data-transfer won't happen.
  323. * Remove will remove the channel/group from the TDM frame.
  324. */
  325. enum slim_ch_control {
  326. SLIM_CH_ACTIVATE,
  327. SLIM_CH_SUSPEND,
  328. SLIM_CH_REMOVE,
  329. };
  330. /**
  331. * struct slim_stream_runtime - SLIMbus stream runtime instance
  332. *
  333. * @name: Name of the stream
  334. * @dev: SLIM Device instance associated with this stream
  335. * @direction: direction of stream
  336. * @prot: Transport protocol used in this stream
  337. * @rate: Data rate of samples *
  338. * @bps: bits per sample
  339. * @ratem: rate multipler which is super frame rate/data rate
  340. * @num_ports: number of ports
  341. * @ports: pointer to instance of ports
  342. * @node: list head for stream associated with slim device.
  343. */
  344. struct slim_stream_runtime {
  345. const char *name;
  346. struct slim_device *dev;
  347. int direction;
  348. enum slim_transport_protocol prot;
  349. unsigned int rate;
  350. unsigned int bps;
  351. unsigned int ratem;
  352. int num_ports;
  353. struct slim_port *ports;
  354. struct list_head node;
  355. };
  356. /**
  357. * struct slim_controller - Controls every instance of SLIMbus
  358. * (similar to 'master' on SPI)
  359. * @dev: Device interface to this driver
  360. * @id: Board-specific number identifier for this controller/bus
  361. * @name: Name for this controller
  362. * @min_cg: Minimum clock gear supported by this controller (default value: 1)
  363. * @max_cg: Maximum clock gear supported by this controller (default value: 10)
  364. * @clkgear: Current clock gear in which this bus is running
  365. * @laddr_ida: logical address id allocator
  366. * @a_framer: Active framer which is clocking the bus managed by this controller
  367. * @lock: Mutex protecting controller data structures
  368. * @devices: Slim device list
  369. * @tid_idr: tid id allocator
  370. * @txn_lock: Lock to protect table of transactions
  371. * @sched: scheduler structure used by the controller
  372. * @xfer_msg: Transfer a message on this controller (this can be a broadcast
  373. * control/status message like data channel setup, or a unicast message
  374. * like value element read/write.
  375. * @set_laddr: Setup logical address at laddr for the slave with elemental
  376. * address e_addr. Drivers implementing controller will be expected to
  377. * send unicast message to this device with its logical address.
  378. * @get_laddr: It is possible that controller needs to set fixed logical
  379. * address table and get_laddr can be used in that case so that controller
  380. * can do this assignment. Use case is when the master is on the remote
  381. * processor side, who is resposible for allocating laddr.
  382. * @wakeup: This function pointer implements controller-specific procedure
  383. * to wake it up from clock-pause. Framework will call this to bring
  384. * the controller out of clock pause.
  385. * @suspend_slimbus: Called to initiate immediate suspend of slimbus.
  386. * @enable_stream: This function pointer implements controller-specific procedure
  387. * to enable a stream.
  388. * @disable_stream: This function pointer implements controller-specific procedure
  389. * to disable stream.
  390. *
  391. * 'Manager device' is responsible for device management, bandwidth
  392. * allocation, channel setup, and port associations per channel.
  393. * Device management means Logical address assignment/removal based on
  394. * enumeration (report-present, report-absent) of a device.
  395. * Bandwidth allocation is done dynamically by the manager based on active
  396. * channels on the bus, message-bandwidth requests made by SLIMbus devices.
  397. * Based on current bandwidth usage, manager chooses a frequency to run
  398. * the bus at (in steps of 'clock-gear', 1 through 10, each clock gear
  399. * representing twice the frequency than the previous gear).
  400. * Manager is also responsible for entering (and exiting) low-power-mode
  401. * (known as 'clock pause').
  402. * Manager can do handover of framer if there are multiple framers on the
  403. * bus and a certain usecase warrants using certain framer to avoid keeping
  404. * previous framer being powered-on.
  405. *
  406. * Controller here performs duties of the manager device, and 'interface
  407. * device'. Interface device is responsible for monitoring the bus and
  408. * reporting information such as loss-of-synchronization, data
  409. * slot-collision.
  410. */
  411. struct slim_controller {
  412. struct device *dev;
  413. unsigned int id;
  414. char name[SLIMBUS_NAME_SIZE];
  415. int min_cg;
  416. int max_cg;
  417. int clkgear;
  418. struct ida laddr_ida;
  419. struct slim_framer *a_framer;
  420. struct mutex lock;
  421. struct list_head devices;
  422. struct idr tid_idr;
  423. spinlock_t txn_lock;
  424. struct slim_sched sched;
  425. int (*xfer_msg)(struct slim_controller *ctrl,
  426. struct slim_msg_txn *tx);
  427. int (*set_laddr)(struct slim_controller *ctrl,
  428. struct slim_eaddr *ea, u8 laddr);
  429. int (*get_laddr)(struct slim_controller *ctrl,
  430. struct slim_eaddr *ea, u8 *laddr);
  431. int (*enable_stream)(struct slim_stream_runtime *rt);
  432. int (*disable_stream)(struct slim_stream_runtime *rt);
  433. int (*wakeup)(struct slim_controller *ctrl);
  434. int (*suspend_slimbus)(struct slim_controller *ctrl);
  435. struct mutex stream_lock;
  436. };
  437. /* IPC logging stuff */
  438. #define IPC_SLIMBUS_LOG_PAGES 10
  439. /* Log levels */
  440. enum {
  441. FATAL_LEV = 0U,
  442. ERR_LEV = 1U,
  443. WARN_LEV = 2U,
  444. INFO_LEV = 3U,
  445. DBG_LEV = 4U,
  446. };
  447. /* Default IPC log level INFO */
  448. #define SLIM_DBG(dev, x...) do { \
  449. pr_debug(x); \
  450. slimbus_dbg(x); \
  451. if (dev->ipc_log_mask >= DBG_LEV) { \
  452. ipc_log_string(dev->ipc_slimbus_log, x); \
  453. } \
  454. if (dev->ipc_log_mask == FATAL_LEV) { \
  455. ipc_log_string(dev->ipc_slimbus_log_err, x); \
  456. } \
  457. } while (0)
  458. #define SLIM_INFO(dev, x...) do { \
  459. pr_debug(x); \
  460. slimbus_dbg(x); \
  461. if (dev->ipc_log_mask >= INFO_LEV) {\
  462. ipc_log_string(dev->ipc_slimbus_log, x); \
  463. } \
  464. if (dev->ipc_log_mask == FATAL_LEV) { \
  465. ipc_log_string(dev->ipc_slimbus_log_err, x); \
  466. } \
  467. } while (0)
  468. /* warnings and errors show up on console always */
  469. #define SLIM_WARN(dev, x...) do { \
  470. slimbus_dbg(x); \
  471. if (dev->ipc_log_mask >= WARN_LEV) { \
  472. pr_warn(x); \
  473. ipc_log_string(dev->ipc_slimbus_log, x); \
  474. } \
  475. if (dev->ipc_log_mask == FATAL_LEV) { \
  476. ipc_log_string(dev->ipc_slimbus_log_err, x); \
  477. } \
  478. } while (0)
  479. /* ERROR condition in the driver sets the ipc_log_mask
  480. * to ERR_FATAL level, so that this message can be seen
  481. * in IPC logging. Further errors continue to log on the error IPC logging.
  482. */
  483. #define SLIM_ERR(dev, x...) do { \
  484. slimbus_dbg(x); \
  485. if (dev->ipc_log_mask >= ERR_LEV) { \
  486. pr_err(x); \
  487. ipc_log_string(dev->ipc_slimbus_log, x); \
  488. dev->default_ipc_log_mask = dev->ipc_log_mask; \
  489. dev->ipc_log_mask = FATAL_LEV; \
  490. } \
  491. if (dev->ipc_log_mask == FATAL_LEV) { \
  492. ipc_log_string(dev->ipc_slimbus_log_err, x); \
  493. } \
  494. } while (0)
  495. #define SLIM_RST_LOGLVL(dev) { \
  496. dev->ipc_log_mask = dev->default_ipc_log_mask; \
  497. }
  498. int slim_device_report_present(struct slim_controller *ctrl,
  499. struct slim_eaddr *e_addr, u8 *laddr);
  500. void slim_report_absent(struct slim_device *sbdev);
  501. int slim_register_controller(struct slim_controller *ctrl);
  502. int slim_unregister_controller(struct slim_controller *ctrl);
  503. void slim_msg_response(struct slim_controller *ctrl, u8 *reply, u8 tid, u8 l);
  504. int slim_do_transfer(struct slim_controller *ctrl, struct slim_msg_txn *txn);
  505. int slim_ctrl_clk_pause(struct slim_controller *ctrl, bool wakeup, u8 restart);
  506. int slim_alloc_txn_tid(struct slim_controller *ctrl, struct slim_msg_txn *txn);
  507. void slim_free_txn_tid(struct slim_controller *ctrl, struct slim_msg_txn *txn);
  508. static inline bool slim_tid_txn(u8 mt, u8 mc)
  509. {
  510. return (mt == SLIM_MSG_MT_CORE &&
  511. (mc == SLIM_MSG_MC_REQUEST_INFORMATION ||
  512. mc == SLIM_MSG_MC_REQUEST_CLEAR_INFORMATION ||
  513. mc == SLIM_MSG_MC_REQUEST_VALUE ||
  514. mc == SLIM_MSG_MC_REQUEST_CHANGE_VALUE));
  515. }
  516. static inline bool slim_ec_txn(u8 mt, u8 mc)
  517. {
  518. return (mt == SLIM_MSG_MT_CORE &&
  519. ((mc >= SLIM_MSG_MC_REQUEST_INFORMATION &&
  520. mc <= SLIM_MSG_MC_REPORT_INFORMATION) ||
  521. (mc >= SLIM_MSG_MC_REQUEST_VALUE &&
  522. mc <= SLIM_MSG_MC_CHANGE_VALUE)));
  523. }
  524. #endif /* _LINUX_SLIMBUS_H */