ccc.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2018 Cadence Design Systems Inc.
  4. *
  5. * Author: Boris Brezillon <boris.brezillon@bootlin.com>
  6. */
  7. #ifndef I3C_CCC_H
  8. #define I3C_CCC_H
  9. #include <linux/bitops.h>
  10. #include <linux/i3c/device.h>
  11. /* I3C CCC (Common Command Codes) related definitions */
  12. #define I3C_CCC_DIRECT BIT(7)
  13. #define I3C_CCC_ID(id, broadcast) \
  14. ((id) | ((broadcast) ? 0 : I3C_CCC_DIRECT))
  15. /* Commands valid in both broadcast and unicast modes */
  16. #define I3C_CCC_ENEC(broadcast) I3C_CCC_ID(0x0, broadcast)
  17. #define I3C_CCC_DISEC(broadcast) I3C_CCC_ID(0x1, broadcast)
  18. #define I3C_CCC_ENTAS(as, broadcast) I3C_CCC_ID(0x2 + (as), broadcast)
  19. #define I3C_CCC_RSTDAA(broadcast) I3C_CCC_ID(0x6, broadcast)
  20. #define I3C_CCC_SETMWL(broadcast) I3C_CCC_ID(0x9, broadcast)
  21. #define I3C_CCC_SETMRL(broadcast) I3C_CCC_ID(0xa, broadcast)
  22. #define I3C_CCC_SETXTIME(broadcast) ((broadcast) ? 0x28 : 0x98)
  23. #define I3C_CCC_VENDOR(id, broadcast) ((id) + ((broadcast) ? 0x61 : 0xe0))
  24. /* Broadcast-only commands */
  25. #define I3C_CCC_ENTDAA I3C_CCC_ID(0x7, true)
  26. #define I3C_CCC_DEFSLVS I3C_CCC_ID(0x8, true)
  27. #define I3C_CCC_ENTTM I3C_CCC_ID(0xb, true)
  28. #define I3C_CCC_ENTHDR(x) I3C_CCC_ID(0x20 + (x), true)
  29. /* Unicast-only commands */
  30. #define I3C_CCC_SETDASA I3C_CCC_ID(0x7, false)
  31. #define I3C_CCC_SETNEWDA I3C_CCC_ID(0x8, false)
  32. #define I3C_CCC_GETMWL I3C_CCC_ID(0xb, false)
  33. #define I3C_CCC_GETMRL I3C_CCC_ID(0xc, false)
  34. #define I3C_CCC_GETPID I3C_CCC_ID(0xd, false)
  35. #define I3C_CCC_GETBCR I3C_CCC_ID(0xe, false)
  36. #define I3C_CCC_GETDCR I3C_CCC_ID(0xf, false)
  37. #define I3C_CCC_GETSTATUS I3C_CCC_ID(0x10, false)
  38. #define I3C_CCC_GETACCMST I3C_CCC_ID(0x11, false)
  39. #define I3C_CCC_SETBRGTGT I3C_CCC_ID(0x13, false)
  40. #define I3C_CCC_GETMXDS I3C_CCC_ID(0x14, false)
  41. #define I3C_CCC_GETHDRCAP I3C_CCC_ID(0x15, false)
  42. #define I3C_CCC_GETXTIME I3C_CCC_ID(0x19, false)
  43. #define I3C_CCC_EVENT_SIR BIT(0)
  44. #define I3C_CCC_EVENT_MR BIT(1)
  45. #define I3C_CCC_EVENT_HJ BIT(3)
  46. /**
  47. * struct i3c_ccc_events - payload passed to ENEC/DISEC CCC
  48. *
  49. * @events: bitmask of I3C_CCC_EVENT_xxx events.
  50. *
  51. * Depending on the CCC command, the specific events coming from all devices
  52. * (broadcast version) or a specific device (unicast version) will be
  53. * enabled (ENEC) or disabled (DISEC).
  54. */
  55. struct i3c_ccc_events {
  56. u8 events;
  57. };
  58. /**
  59. * struct i3c_ccc_mwl - payload passed to SETMWL/GETMWL CCC
  60. *
  61. * @len: maximum write length in bytes
  62. *
  63. * The maximum write length is only applicable to SDR private messages or
  64. * extended Write CCCs (like SETXTIME).
  65. */
  66. struct i3c_ccc_mwl {
  67. __be16 len;
  68. };
  69. /**
  70. * struct i3c_ccc_mrl - payload passed to SETMRL/GETMRL CCC
  71. *
  72. * @len: maximum read length in bytes
  73. * @ibi_len: maximum IBI payload length
  74. *
  75. * The maximum read length is only applicable to SDR private messages or
  76. * extended Read CCCs (like GETXTIME).
  77. * The IBI length is only valid if the I3C slave is IBI capable
  78. * (%I3C_BCR_IBI_REQ_CAP is set).
  79. */
  80. struct i3c_ccc_mrl {
  81. __be16 read_len;
  82. u8 ibi_len;
  83. } __packed;
  84. /**
  85. * struct i3c_ccc_dev_desc - I3C/I2C device descriptor used for DEFSLVS
  86. *
  87. * @dyn_addr: dynamic address assigned to the I3C slave or 0 if the entry is
  88. * describing an I2C slave.
  89. * @dcr: DCR value (not applicable to entries describing I2C devices)
  90. * @lvr: LVR value (not applicable to entries describing I3C devices)
  91. * @bcr: BCR value or 0 if this entry is describing an I2C slave
  92. * @static_addr: static address or 0 if the device does not have a static
  93. * address
  94. *
  95. * The DEFSLVS command should be passed an array of i3c_ccc_dev_desc
  96. * descriptors (one entry per I3C/I2C dev controlled by the master).
  97. */
  98. struct i3c_ccc_dev_desc {
  99. u8 dyn_addr;
  100. union {
  101. u8 dcr;
  102. u8 lvr;
  103. };
  104. u8 bcr;
  105. u8 static_addr;
  106. };
  107. /**
  108. * struct i3c_ccc_defslvs - payload passed to DEFSLVS CCC
  109. *
  110. * @count: number of dev descriptors
  111. * @master: descriptor describing the current master
  112. * @slaves: array of descriptors describing slaves controlled by the
  113. * current master
  114. *
  115. * Information passed to the broadcast DEFSLVS to propagate device
  116. * information to all masters currently acting as slaves on the bus.
  117. * This is only meaningful if you have more than one master.
  118. */
  119. struct i3c_ccc_defslvs {
  120. u8 count;
  121. struct i3c_ccc_dev_desc master;
  122. struct i3c_ccc_dev_desc slaves[0];
  123. } __packed;
  124. /**
  125. * enum i3c_ccc_test_mode - enum listing all available test modes
  126. *
  127. * @I3C_CCC_EXIT_TEST_MODE: exit test mode
  128. * @I3C_CCC_VENDOR_TEST_MODE: enter vendor test mode
  129. */
  130. enum i3c_ccc_test_mode {
  131. I3C_CCC_EXIT_TEST_MODE,
  132. I3C_CCC_VENDOR_TEST_MODE,
  133. };
  134. /**
  135. * struct i3c_ccc_enttm - payload passed to ENTTM CCC
  136. *
  137. * @mode: one of the &enum i3c_ccc_test_mode modes
  138. *
  139. * Information passed to the ENTTM CCC to instruct an I3C device to enter a
  140. * specific test mode.
  141. */
  142. struct i3c_ccc_enttm {
  143. u8 mode;
  144. };
  145. /**
  146. * struct i3c_ccc_setda - payload passed to SETNEWDA and SETDASA CCCs
  147. *
  148. * @addr: dynamic address to assign to an I3C device
  149. *
  150. * Information passed to the SETNEWDA and SETDASA CCCs to assign/change the
  151. * dynamic address of an I3C device.
  152. */
  153. struct i3c_ccc_setda {
  154. u8 addr;
  155. };
  156. /**
  157. * struct i3c_ccc_getpid - payload passed to GETPID CCC
  158. *
  159. * @pid: 48 bits PID in big endian
  160. */
  161. struct i3c_ccc_getpid {
  162. u8 pid[6];
  163. };
  164. /**
  165. * struct i3c_ccc_getbcr - payload passed to GETBCR CCC
  166. *
  167. * @bcr: BCR (Bus Characteristic Register) value
  168. */
  169. struct i3c_ccc_getbcr {
  170. u8 bcr;
  171. };
  172. /**
  173. * struct i3c_ccc_getdcr - payload passed to GETDCR CCC
  174. *
  175. * @dcr: DCR (Device Characteristic Register) value
  176. */
  177. struct i3c_ccc_getdcr {
  178. u8 dcr;
  179. };
  180. #define I3C_CCC_STATUS_PENDING_INT(status) ((status) & GENMASK(3, 0))
  181. #define I3C_CCC_STATUS_PROTOCOL_ERROR BIT(5)
  182. #define I3C_CCC_STATUS_ACTIVITY_MODE(status) \
  183. (((status) & GENMASK(7, 6)) >> 6)
  184. /**
  185. * struct i3c_ccc_getstatus - payload passed to GETSTATUS CCC
  186. *
  187. * @status: status of the I3C slave (see I3C_CCC_STATUS_xxx macros for more
  188. * information).
  189. */
  190. struct i3c_ccc_getstatus {
  191. __be16 status;
  192. };
  193. /**
  194. * struct i3c_ccc_getaccmst - payload passed to GETACCMST CCC
  195. *
  196. * @newmaster: address of the master taking bus ownership
  197. */
  198. struct i3c_ccc_getaccmst {
  199. u8 newmaster;
  200. };
  201. /**
  202. * struct i3c_ccc_bridged_slave_desc - bridged slave descriptor
  203. *
  204. * @addr: dynamic address of the bridged device
  205. * @id: ID of the slave device behind the bridge
  206. */
  207. struct i3c_ccc_bridged_slave_desc {
  208. u8 addr;
  209. __be16 id;
  210. } __packed;
  211. /**
  212. * struct i3c_ccc_setbrgtgt - payload passed to SETBRGTGT CCC
  213. *
  214. * @count: number of bridged slaves
  215. * @bslaves: bridged slave descriptors
  216. */
  217. struct i3c_ccc_setbrgtgt {
  218. u8 count;
  219. struct i3c_ccc_bridged_slave_desc bslaves[0];
  220. } __packed;
  221. /**
  222. * enum i3c_sdr_max_data_rate - max data rate values for private SDR transfers
  223. */
  224. enum i3c_sdr_max_data_rate {
  225. I3C_SDR0_FSCL_MAX,
  226. I3C_SDR1_FSCL_8MHZ,
  227. I3C_SDR2_FSCL_6MHZ,
  228. I3C_SDR3_FSCL_4MHZ,
  229. I3C_SDR4_FSCL_2MHZ,
  230. };
  231. /**
  232. * enum i3c_tsco - clock to data turn-around
  233. */
  234. enum i3c_tsco {
  235. I3C_TSCO_8NS,
  236. I3C_TSCO_9NS,
  237. I3C_TSCO_10NS,
  238. I3C_TSCO_11NS,
  239. I3C_TSCO_12NS,
  240. };
  241. #define I3C_CCC_MAX_SDR_FSCL_MASK GENMASK(2, 0)
  242. #define I3C_CCC_MAX_SDR_FSCL(x) ((x) & I3C_CCC_MAX_SDR_FSCL_MASK)
  243. /**
  244. * struct i3c_ccc_getmxds - payload passed to GETMXDS CCC
  245. *
  246. * @maxwr: write limitations
  247. * @maxrd: read limitations
  248. * @maxrdturn: maximum read turn-around expressed micro-seconds and
  249. * little-endian formatted
  250. */
  251. struct i3c_ccc_getmxds {
  252. u8 maxwr;
  253. u8 maxrd;
  254. u8 maxrdturn[3];
  255. } __packed;
  256. #define I3C_CCC_HDR_MODE(mode) BIT(mode)
  257. /**
  258. * struct i3c_ccc_gethdrcap - payload passed to GETHDRCAP CCC
  259. *
  260. * @modes: bitmap of supported HDR modes
  261. */
  262. struct i3c_ccc_gethdrcap {
  263. u8 modes;
  264. } __packed;
  265. /**
  266. * enum i3c_ccc_setxtime_subcmd - SETXTIME sub-commands
  267. */
  268. enum i3c_ccc_setxtime_subcmd {
  269. I3C_CCC_SETXTIME_ST = 0x7f,
  270. I3C_CCC_SETXTIME_DT = 0xbf,
  271. I3C_CCC_SETXTIME_ENTER_ASYNC_MODE0 = 0xdf,
  272. I3C_CCC_SETXTIME_ENTER_ASYNC_MODE1 = 0xef,
  273. I3C_CCC_SETXTIME_ENTER_ASYNC_MODE2 = 0xf7,
  274. I3C_CCC_SETXTIME_ENTER_ASYNC_MODE3 = 0xfb,
  275. I3C_CCC_SETXTIME_ASYNC_TRIGGER = 0xfd,
  276. I3C_CCC_SETXTIME_TPH = 0x3f,
  277. I3C_CCC_SETXTIME_TU = 0x9f,
  278. I3C_CCC_SETXTIME_ODR = 0x8f,
  279. };
  280. /**
  281. * struct i3c_ccc_setxtime - payload passed to SETXTIME CCC
  282. *
  283. * @subcmd: one of the sub-commands ddefined in &enum i3c_ccc_setxtime_subcmd
  284. * @data: sub-command payload. Amount of data is determined by
  285. * &i3c_ccc_setxtime->subcmd
  286. */
  287. struct i3c_ccc_setxtime {
  288. u8 subcmd;
  289. u8 data[0];
  290. } __packed;
  291. #define I3C_CCC_GETXTIME_SYNC_MODE BIT(0)
  292. #define I3C_CCC_GETXTIME_ASYNC_MODE(x) BIT((x) + 1)
  293. #define I3C_CCC_GETXTIME_OVERFLOW BIT(7)
  294. /**
  295. * struct i3c_ccc_getxtime - payload retrieved from GETXTIME CCC
  296. *
  297. * @supported_modes: bitmap describing supported XTIME modes
  298. * @state: current status (enabled mode and overflow status)
  299. * @frequency: slave's internal oscillator frequency in 500KHz steps
  300. * @inaccuracy: slave's internal oscillator inaccuracy in 0.1% steps
  301. */
  302. struct i3c_ccc_getxtime {
  303. u8 supported_modes;
  304. u8 state;
  305. u8 frequency;
  306. u8 inaccuracy;
  307. } __packed;
  308. /**
  309. * struct i3c_ccc_cmd_payload - CCC payload
  310. *
  311. * @len: payload length
  312. * @data: payload data. This buffer must be DMA-able
  313. */
  314. struct i3c_ccc_cmd_payload {
  315. u16 len;
  316. void *data;
  317. };
  318. /**
  319. * struct i3c_ccc_cmd_dest - CCC command destination
  320. *
  321. * @addr: can be an I3C device address or the broadcast address if this is a
  322. * broadcast CCC
  323. * @payload: payload to be sent to this device or broadcasted
  324. */
  325. struct i3c_ccc_cmd_dest {
  326. u8 addr;
  327. struct i3c_ccc_cmd_payload payload;
  328. };
  329. /**
  330. * struct i3c_ccc_cmd - CCC command
  331. *
  332. * @rnw: true if the CCC should retrieve data from the device. Only valid for
  333. * unicast commands
  334. * @id: CCC command id
  335. * @ndests: number of destinations. Should always be one for broadcast commands
  336. * @dests: array of destinations and associated payload for this CCC. Most of
  337. * the time, only one destination is provided
  338. * @err: I3C error code
  339. */
  340. struct i3c_ccc_cmd {
  341. u8 rnw;
  342. u8 id;
  343. unsigned int ndests;
  344. struct i3c_ccc_cmd_dest *dests;
  345. enum i3c_error_code err;
  346. };
  347. #endif /* I3C_CCC_H */