master.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  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_MASTER_H
  8. #define I3C_MASTER_H
  9. #include <asm/bitsperlong.h>
  10. #include <linux/bitops.h>
  11. #include <linux/i2c.h>
  12. #include <linux/i3c/ccc.h>
  13. #include <linux/i3c/device.h>
  14. #include <linux/rwsem.h>
  15. #include <linux/spinlock.h>
  16. #include <linux/workqueue.h>
  17. #define I3C_HOT_JOIN_ADDR 0x2
  18. #define I3C_BROADCAST_ADDR 0x7e
  19. #define I3C_MAX_ADDR GENMASK(6, 0)
  20. struct i3c_master_controller;
  21. struct i3c_bus;
  22. struct i2c_device;
  23. struct i3c_device;
  24. /**
  25. * struct i3c_i2c_dev_desc - Common part of the I3C/I2C device descriptor
  26. * @node: node element used to insert the slot into the I2C or I3C device
  27. * list
  28. * @master: I3C master that instantiated this device. Will be used to do
  29. * I2C/I3C transfers
  30. * @master_priv: master private data assigned to the device. Can be used to
  31. * add master specific information
  32. *
  33. * This structure is describing common I3C/I2C dev information.
  34. */
  35. struct i3c_i2c_dev_desc {
  36. struct list_head node;
  37. struct i3c_master_controller *master;
  38. void *master_priv;
  39. };
  40. #define I3C_LVR_I2C_INDEX_MASK GENMASK(7, 5)
  41. #define I3C_LVR_I2C_INDEX(x) ((x) << 5)
  42. #define I3C_LVR_I2C_FM_MODE BIT(4)
  43. #define I2C_MAX_ADDR GENMASK(6, 0)
  44. /**
  45. * struct i2c_dev_boardinfo - I2C device board information
  46. * @node: used to insert the boardinfo object in the I2C boardinfo list
  47. * @base: regular I2C board information
  48. * @lvr: LVR (Legacy Virtual Register) needed by the I3C core to know about
  49. * the I2C device limitations
  50. *
  51. * This structure is used to attach board-level information to an I2C device.
  52. * Each I2C device connected on the I3C bus should have one.
  53. */
  54. struct i2c_dev_boardinfo {
  55. struct list_head node;
  56. struct i2c_board_info base;
  57. u8 lvr;
  58. };
  59. /**
  60. * struct i2c_dev_desc - I2C device descriptor
  61. * @common: common part of the I2C device descriptor
  62. * @boardinfo: pointer to the boardinfo attached to this I2C device
  63. * @dev: I2C device object registered to the I2C framework
  64. * @addr: I2C device address
  65. * @lvr: LVR (Legacy Virtual Register) needed by the I3C core to know about
  66. * the I2C device limitations
  67. *
  68. * Each I2C device connected on the bus will have an i2c_dev_desc.
  69. * This object is created by the core and later attached to the controller
  70. * using &struct_i3c_master_controller->ops->attach_i2c_dev().
  71. *
  72. * &struct_i2c_dev_desc is the internal representation of an I2C device
  73. * connected on an I3C bus. This object is also passed to all
  74. * &struct_i3c_master_controller_ops hooks.
  75. */
  76. struct i2c_dev_desc {
  77. struct i3c_i2c_dev_desc common;
  78. const struct i2c_dev_boardinfo *boardinfo;
  79. struct i2c_client *dev;
  80. u16 addr;
  81. u8 lvr;
  82. };
  83. /**
  84. * struct i3c_ibi_slot - I3C IBI (In-Band Interrupt) slot
  85. * @work: work associated to this slot. The IBI handler will be called from
  86. * there
  87. * @dev: the I3C device that has generated this IBI
  88. * @len: length of the payload associated to this IBI
  89. * @data: payload buffer
  90. *
  91. * An IBI slot is an object pre-allocated by the controller and used when an
  92. * IBI comes in.
  93. * Every time an IBI comes in, the I3C master driver should find a free IBI
  94. * slot in its IBI slot pool, retrieve the IBI payload and queue the IBI using
  95. * i3c_master_queue_ibi().
  96. *
  97. * How IBI slots are allocated is left to the I3C master driver, though, for
  98. * simple kmalloc-based allocation, the generic IBI slot pool can be used.
  99. */
  100. struct i3c_ibi_slot {
  101. struct work_struct work;
  102. struct i3c_dev_desc *dev;
  103. unsigned int len;
  104. void *data;
  105. };
  106. /**
  107. * struct i3c_device_ibi_info - IBI information attached to a specific device
  108. * @all_ibis_handled: used to be informed when no more IBIs are waiting to be
  109. * processed. Used by i3c_device_disable_ibi() to wait for
  110. * all IBIs to be dequeued
  111. * @pending_ibis: count the number of pending IBIs. Each pending IBI has its
  112. * work element queued to the controller workqueue
  113. * @max_payload_len: maximum payload length for an IBI coming from this device.
  114. * this value is specified when calling
  115. * i3c_device_request_ibi() and should not change at run
  116. * time. All messages IBIs exceeding this limit should be
  117. * rejected by the master
  118. * @num_slots: number of IBI slots reserved for this device
  119. * @enabled: reflect the IBI status
  120. * @handler: IBI handler specified at i3c_device_request_ibi() call time. This
  121. * handler will be called from the controller workqueue, and as such
  122. * is allowed to sleep (though it is recommended to process the IBI
  123. * as fast as possible to not stall processing of other IBIs queued
  124. * on the same workqueue).
  125. * New I3C messages can be sent from the IBI handler
  126. *
  127. * The &struct_i3c_device_ibi_info object is allocated when
  128. * i3c_device_request_ibi() is called and attached to a specific device. This
  129. * object is here to manage IBIs coming from a specific I3C device.
  130. *
  131. * Note that this structure is the generic view of the IBI management
  132. * infrastructure. I3C master drivers may have their own internal
  133. * representation which they can associate to the device using
  134. * controller-private data.
  135. */
  136. struct i3c_device_ibi_info {
  137. struct completion all_ibis_handled;
  138. atomic_t pending_ibis;
  139. unsigned int max_payload_len;
  140. unsigned int num_slots;
  141. unsigned int enabled;
  142. void (*handler)(struct i3c_device *dev,
  143. const struct i3c_ibi_payload *payload);
  144. };
  145. /**
  146. * struct i3c_dev_boardinfo - I3C device board information
  147. * @node: used to insert the boardinfo object in the I3C boardinfo list
  148. * @init_dyn_addr: initial dynamic address requested by the FW. We provide no
  149. * guarantee that the device will end up using this address,
  150. * but try our best to assign this specific address to the
  151. * device
  152. * @static_addr: static address the I3C device listen on before it's been
  153. * assigned a dynamic address by the master. Will be used during
  154. * bus initialization to assign it a specific dynamic address
  155. * before starting DAA (Dynamic Address Assignment)
  156. * @pid: I3C Provisional ID exposed by the device. This is a unique identifier
  157. * that may be used to attach boardinfo to i3c_dev_desc when the device
  158. * does not have a static address
  159. * @of_node: optional DT node in case the device has been described in the DT
  160. *
  161. * This structure is used to attach board-level information to an I3C device.
  162. * Not all I3C devices connected on the bus will have a boardinfo. It's only
  163. * needed if you want to attach extra resources to a device or assign it a
  164. * specific dynamic address.
  165. */
  166. struct i3c_dev_boardinfo {
  167. struct list_head node;
  168. u8 init_dyn_addr;
  169. u8 static_addr;
  170. u64 pid;
  171. struct device_node *of_node;
  172. };
  173. /**
  174. * struct i3c_dev_desc - I3C device descriptor
  175. * @common: common part of the I3C device descriptor
  176. * @info: I3C device information. Will be automatically filled when you create
  177. * your device with i3c_master_add_i3c_dev_locked()
  178. * @ibi_lock: lock used to protect the &struct_i3c_device->ibi
  179. * @ibi: IBI info attached to a device. Should be NULL until
  180. * i3c_device_request_ibi() is called
  181. * @dev: pointer to the I3C device object exposed to I3C device drivers. This
  182. * should never be accessed from I3C master controller drivers. Only core
  183. * code should manipulate it in when updating the dev <-> desc link or
  184. * when propagating IBI events to the driver
  185. * @boardinfo: pointer to the boardinfo attached to this I3C device
  186. *
  187. * Internal representation of an I3C device. This object is only used by the
  188. * core and passed to I3C master controller drivers when they're requested to
  189. * do some operations on the device.
  190. * The core maintains the link between the internal I3C dev descriptor and the
  191. * object exposed to the I3C device drivers (&struct_i3c_device).
  192. */
  193. struct i3c_dev_desc {
  194. struct i3c_i2c_dev_desc common;
  195. struct i3c_device_info info;
  196. struct mutex ibi_lock;
  197. struct i3c_device_ibi_info *ibi;
  198. struct i3c_device *dev;
  199. const struct i3c_dev_boardinfo *boardinfo;
  200. };
  201. /**
  202. * struct i3c_device - I3C device object
  203. * @dev: device object to register the I3C dev to the device model
  204. * @desc: pointer to an i3c device descriptor object. This link is updated
  205. * every time the I3C device is rediscovered with a different dynamic
  206. * address assigned
  207. * @bus: I3C bus this device is attached to
  208. *
  209. * I3C device object exposed to I3C device drivers. The takes care of linking
  210. * this object to the relevant &struct_i3c_dev_desc one.
  211. * All I3C devs on the I3C bus are represented, including I3C masters. For each
  212. * of them, we have an instance of &struct i3c_device.
  213. */
  214. struct i3c_device {
  215. struct device dev;
  216. struct i3c_dev_desc *desc;
  217. struct i3c_bus *bus;
  218. };
  219. /*
  220. * The I3C specification says the maximum number of devices connected on the
  221. * bus is 11, but this number depends on external parameters like trace length,
  222. * capacitive load per Device, and the types of Devices present on the Bus.
  223. * I3C master can also have limitations, so this number is just here as a
  224. * reference and should be adjusted on a per-controller/per-board basis.
  225. */
  226. #define I3C_BUS_MAX_DEVS 11
  227. #define I3C_BUS_MAX_I3C_SCL_RATE 12900000
  228. #define I3C_BUS_TYP_I3C_SCL_RATE 12500000
  229. #define I3C_BUS_I2C_FM_PLUS_SCL_RATE 1000000
  230. #define I3C_BUS_I2C_FM_SCL_RATE 400000
  231. #define I3C_BUS_TLOW_OD_MIN_NS 200
  232. /**
  233. * enum i3c_bus_mode - I3C bus mode
  234. * @I3C_BUS_MODE_PURE: only I3C devices are connected to the bus. No limitation
  235. * expected
  236. * @I3C_BUS_MODE_MIXED_FAST: I2C devices with 50ns spike filter are present on
  237. * the bus. The only impact in this mode is that the
  238. * high SCL pulse has to stay below 50ns to trick I2C
  239. * devices when transmitting I3C frames
  240. * @I3C_BUS_MODE_MIXED_LIMITED: I2C devices without 50ns spike filter are
  241. * present on the bus. However they allow
  242. * compliance up to the maximum SDR SCL clock
  243. * frequency.
  244. * @I3C_BUS_MODE_MIXED_SLOW: I2C devices without 50ns spike filter are present
  245. * on the bus
  246. */
  247. enum i3c_bus_mode {
  248. I3C_BUS_MODE_PURE,
  249. I3C_BUS_MODE_MIXED_FAST,
  250. I3C_BUS_MODE_MIXED_LIMITED,
  251. I3C_BUS_MODE_MIXED_SLOW,
  252. };
  253. /**
  254. * enum i3c_addr_slot_status - I3C address slot status
  255. * @I3C_ADDR_SLOT_FREE: address is free
  256. * @I3C_ADDR_SLOT_RSVD: address is reserved
  257. * @I3C_ADDR_SLOT_I2C_DEV: address is assigned to an I2C device
  258. * @I3C_ADDR_SLOT_I3C_DEV: address is assigned to an I3C device
  259. * @I3C_ADDR_SLOT_STATUS_MASK: address slot mask
  260. *
  261. * On an I3C bus, addresses are assigned dynamically, and we need to know which
  262. * addresses are free to use and which ones are already assigned.
  263. *
  264. * Addresses marked as reserved are those reserved by the I3C protocol
  265. * (broadcast address, ...).
  266. */
  267. enum i3c_addr_slot_status {
  268. I3C_ADDR_SLOT_FREE,
  269. I3C_ADDR_SLOT_RSVD,
  270. I3C_ADDR_SLOT_I2C_DEV,
  271. I3C_ADDR_SLOT_I3C_DEV,
  272. I3C_ADDR_SLOT_STATUS_MASK = 3,
  273. };
  274. /**
  275. * struct i3c_bus - I3C bus object
  276. * @cur_master: I3C master currently driving the bus. Since I3C is multi-master
  277. * this can change over the time. Will be used to let a master
  278. * know whether it needs to request bus ownership before sending
  279. * a frame or not
  280. * @id: bus ID. Assigned by the framework when register the bus
  281. * @addrslots: a bitmap with 2-bits per-slot to encode the address status and
  282. * ease the DAA (Dynamic Address Assignment) procedure (see
  283. * &enum i3c_addr_slot_status)
  284. * @mode: bus mode (see &enum i3c_bus_mode)
  285. * @scl_rate.i3c: maximum rate for the clock signal when doing I3C SDR/priv
  286. * transfers
  287. * @scl_rate.i2c: maximum rate for the clock signal when doing I2C transfers
  288. * @scl_rate: SCL signal rate for I3C and I2C mode
  289. * @devs.i3c: contains a list of I3C device descriptors representing I3C
  290. * devices connected on the bus and successfully attached to the
  291. * I3C master
  292. * @devs.i2c: contains a list of I2C device descriptors representing I2C
  293. * devices connected on the bus and successfully attached to the
  294. * I3C master
  295. * @devs: 2 lists containing all I3C/I2C devices connected to the bus
  296. * @lock: read/write lock on the bus. This is needed to protect against
  297. * operations that have an impact on the whole bus and the devices
  298. * connected to it. For example, when asking slaves to drop their
  299. * dynamic address (RSTDAA CCC), we need to make sure no one is trying
  300. * to send I3C frames to these devices.
  301. * Note that this lock does not protect against concurrency between
  302. * devices: several drivers can send different I3C/I2C frames through
  303. * the same master in parallel. This is the responsibility of the
  304. * master to guarantee that frames are actually sent sequentially and
  305. * not interlaced
  306. *
  307. * The I3C bus is represented with its own object and not implicitly described
  308. * by the I3C master to cope with the multi-master functionality, where one bus
  309. * can be shared amongst several masters, each of them requesting bus ownership
  310. * when they need to.
  311. */
  312. struct i3c_bus {
  313. struct i3c_dev_desc *cur_master;
  314. int id;
  315. unsigned long addrslots[((I2C_MAX_ADDR + 1) * 2) / BITS_PER_LONG];
  316. enum i3c_bus_mode mode;
  317. struct {
  318. unsigned long i3c;
  319. unsigned long i2c;
  320. } scl_rate;
  321. struct {
  322. struct list_head i3c;
  323. struct list_head i2c;
  324. } devs;
  325. struct rw_semaphore lock;
  326. };
  327. /**
  328. * struct i3c_master_controller_ops - I3C master methods
  329. * @bus_init: hook responsible for the I3C bus initialization. You should at
  330. * least call master_set_info() from there and set the bus mode.
  331. * You can also put controller specific initialization in there.
  332. * This method is mandatory.
  333. * @bus_cleanup: cleanup everything done in
  334. * &i3c_master_controller_ops->bus_init().
  335. * This method is optional.
  336. * @attach_i3c_dev: called every time an I3C device is attached to the bus. It
  337. * can be after a DAA or when a device is statically declared
  338. * by the FW, in which case it will only have a static address
  339. * and the dynamic address will be 0.
  340. * When this function is called, device information have not
  341. * been retrieved yet.
  342. * This is a good place to attach master controller specific
  343. * data to I3C devices.
  344. * This method is optional.
  345. * @reattach_i3c_dev: called every time an I3C device has its addressed
  346. * changed. It can be because the device has been powered
  347. * down and has lost its address, or it can happen when a
  348. * device had a static address and has been assigned a
  349. * dynamic address with SETDASA.
  350. * This method is optional.
  351. * @detach_i3c_dev: called when an I3C device is detached from the bus. Usually
  352. * happens when the master device is unregistered.
  353. * This method is optional.
  354. * @do_daa: do a DAA (Dynamic Address Assignment) procedure. This is procedure
  355. * should send an ENTDAA CCC command and then add all devices
  356. * discovered sure the DAA using i3c_master_add_i3c_dev_locked().
  357. * Add devices added with i3c_master_add_i3c_dev_locked() will then be
  358. * attached or re-attached to the controller.
  359. * This method is mandatory.
  360. * @supports_ccc_cmd: should return true if the CCC command is supported, false
  361. * otherwise.
  362. * This method is optional, if not provided the core assumes
  363. * all CCC commands are supported.
  364. * @send_ccc_cmd: send a CCC command
  365. * This method is mandatory.
  366. * @priv_xfers: do one or several private I3C SDR transfers
  367. * This method is mandatory.
  368. * @attach_i2c_dev: called every time an I2C device is attached to the bus.
  369. * This is a good place to attach master controller specific
  370. * data to I2C devices.
  371. * This method is optional.
  372. * @detach_i2c_dev: called when an I2C device is detached from the bus. Usually
  373. * happens when the master device is unregistered.
  374. * This method is optional.
  375. * @i2c_xfers: do one or several I2C transfers. Note that, unlike i3c
  376. * transfers, the core does not guarantee that buffers attached to
  377. * the transfers are DMA-safe. If drivers want to have DMA-safe
  378. * buffers, they should use the i2c_get_dma_safe_msg_buf()
  379. * and i2c_put_dma_safe_msg_buf() helpers provided by the I2C
  380. * framework.
  381. * This method is mandatory.
  382. * @request_ibi: attach an IBI handler to an I3C device. This implies defining
  383. * an IBI handler and the constraints of the IBI (maximum payload
  384. * length and number of pre-allocated slots).
  385. * Some controllers support less IBI-capable devices than regular
  386. * devices, so this method might return -%EBUSY if there's no
  387. * more space for an extra IBI registration
  388. * This method is optional.
  389. * @free_ibi: free an IBI previously requested with ->request_ibi(). The IBI
  390. * should have been disabled with ->disable_irq() prior to that
  391. * This method is mandatory only if ->request_ibi is not NULL.
  392. * @enable_ibi: enable the IBI. Only valid if ->request_ibi() has been called
  393. * prior to ->enable_ibi(). The controller should first enable
  394. * the IBI on the controller end (for example, unmask the hardware
  395. * IRQ) and then send the ENEC CCC command (with the IBI flag set)
  396. * to the I3C device.
  397. * This method is mandatory only if ->request_ibi is not NULL.
  398. * @disable_ibi: disable an IBI. First send the DISEC CCC command with the IBI
  399. * flag set and then deactivate the hardware IRQ on the
  400. * controller end.
  401. * This method is mandatory only if ->request_ibi is not NULL.
  402. * @recycle_ibi_slot: recycle an IBI slot. Called every time an IBI has been
  403. * processed by its handler. The IBI slot should be put back
  404. * in the IBI slot pool so that the controller can re-use it
  405. * for a future IBI
  406. * This method is mandatory only if ->request_ibi is not
  407. * NULL.
  408. */
  409. struct i3c_master_controller_ops {
  410. int (*bus_init)(struct i3c_master_controller *master);
  411. void (*bus_cleanup)(struct i3c_master_controller *master);
  412. int (*attach_i3c_dev)(struct i3c_dev_desc *dev);
  413. int (*reattach_i3c_dev)(struct i3c_dev_desc *dev, u8 old_dyn_addr);
  414. void (*detach_i3c_dev)(struct i3c_dev_desc *dev);
  415. int (*do_daa)(struct i3c_master_controller *master);
  416. bool (*supports_ccc_cmd)(struct i3c_master_controller *master,
  417. const struct i3c_ccc_cmd *cmd);
  418. int (*send_ccc_cmd)(struct i3c_master_controller *master,
  419. struct i3c_ccc_cmd *cmd);
  420. int (*priv_xfers)(struct i3c_dev_desc *dev,
  421. struct i3c_priv_xfer *xfers,
  422. int nxfers);
  423. int (*attach_i2c_dev)(struct i2c_dev_desc *dev);
  424. void (*detach_i2c_dev)(struct i2c_dev_desc *dev);
  425. int (*i2c_xfers)(struct i2c_dev_desc *dev,
  426. const struct i2c_msg *xfers, int nxfers);
  427. int (*request_ibi)(struct i3c_dev_desc *dev,
  428. const struct i3c_ibi_setup *req);
  429. void (*free_ibi)(struct i3c_dev_desc *dev);
  430. int (*enable_ibi)(struct i3c_dev_desc *dev);
  431. int (*disable_ibi)(struct i3c_dev_desc *dev);
  432. void (*recycle_ibi_slot)(struct i3c_dev_desc *dev,
  433. struct i3c_ibi_slot *slot);
  434. };
  435. /**
  436. * struct i3c_master_controller - I3C master controller object
  437. * @dev: device to be registered to the device-model
  438. * @this: an I3C device object representing this master. This device will be
  439. * added to the list of I3C devs available on the bus
  440. * @i2c: I2C adapter used for backward compatibility. This adapter is
  441. * registered to the I2C subsystem to be as transparent as possible to
  442. * existing I2C drivers
  443. * @ops: master operations. See &struct i3c_master_controller_ops
  444. * @secondary: true if the master is a secondary master
  445. * @init_done: true when the bus initialization is done
  446. * @boardinfo.i3c: list of I3C boardinfo objects
  447. * @boardinfo.i2c: list of I2C boardinfo objects
  448. * @boardinfo: board-level information attached to devices connected on the bus
  449. * @bus: I3C bus exposed by this master
  450. * @wq: workqueue used to execute IBI handlers. Can also be used by master
  451. * drivers if they need to postpone operations that need to take place
  452. * in a thread context. Typical examples are Hot Join processing which
  453. * requires taking the bus lock in maintenance, which in turn, can only
  454. * be done from a sleep-able context
  455. *
  456. * A &struct i3c_master_controller has to be registered to the I3C subsystem
  457. * through i3c_master_register(). None of &struct i3c_master_controller fields
  458. * should be set manually, just pass appropriate values to
  459. * i3c_master_register().
  460. */
  461. struct i3c_master_controller {
  462. struct device dev;
  463. struct i3c_dev_desc *this;
  464. struct i2c_adapter i2c;
  465. const struct i3c_master_controller_ops *ops;
  466. unsigned int secondary : 1;
  467. unsigned int init_done : 1;
  468. struct {
  469. struct list_head i3c;
  470. struct list_head i2c;
  471. } boardinfo;
  472. struct i3c_bus bus;
  473. struct workqueue_struct *wq;
  474. };
  475. /**
  476. * i3c_bus_for_each_i2cdev() - iterate over all I2C devices present on the bus
  477. * @bus: the I3C bus
  478. * @dev: an I2C device descriptor pointer updated to point to the current slot
  479. * at each iteration of the loop
  480. *
  481. * Iterate over all I2C devs present on the bus.
  482. */
  483. #define i3c_bus_for_each_i2cdev(bus, dev) \
  484. list_for_each_entry(dev, &(bus)->devs.i2c, common.node)
  485. /**
  486. * i3c_bus_for_each_i3cdev() - iterate over all I3C devices present on the bus
  487. * @bus: the I3C bus
  488. * @dev: and I3C device descriptor pointer updated to point to the current slot
  489. * at each iteration of the loop
  490. *
  491. * Iterate over all I3C devs present on the bus.
  492. */
  493. #define i3c_bus_for_each_i3cdev(bus, dev) \
  494. list_for_each_entry(dev, &(bus)->devs.i3c, common.node)
  495. int i3c_master_do_i2c_xfers(struct i3c_master_controller *master,
  496. const struct i2c_msg *xfers,
  497. int nxfers);
  498. int i3c_master_disec_locked(struct i3c_master_controller *master, u8 addr,
  499. u8 evts);
  500. int i3c_master_enec_locked(struct i3c_master_controller *master, u8 addr,
  501. u8 evts);
  502. int i3c_master_entdaa_locked(struct i3c_master_controller *master);
  503. int i3c_master_defslvs_locked(struct i3c_master_controller *master);
  504. int i3c_master_get_free_addr(struct i3c_master_controller *master,
  505. u8 start_addr);
  506. int i3c_master_add_i3c_dev_locked(struct i3c_master_controller *master,
  507. u8 addr);
  508. int i3c_master_do_daa(struct i3c_master_controller *master);
  509. int i3c_master_set_info(struct i3c_master_controller *master,
  510. const struct i3c_device_info *info);
  511. int i3c_master_register(struct i3c_master_controller *master,
  512. struct device *parent,
  513. const struct i3c_master_controller_ops *ops,
  514. bool secondary);
  515. int i3c_master_unregister(struct i3c_master_controller *master);
  516. /**
  517. * i3c_dev_get_master_data() - get master private data attached to an I3C
  518. * device descriptor
  519. * @dev: the I3C device descriptor to get private data from
  520. *
  521. * Return: the private data previously attached with i3c_dev_set_master_data()
  522. * or NULL if no data has been attached to the device.
  523. */
  524. static inline void *i3c_dev_get_master_data(const struct i3c_dev_desc *dev)
  525. {
  526. return dev->common.master_priv;
  527. }
  528. /**
  529. * i3c_dev_set_master_data() - attach master private data to an I3C device
  530. * descriptor
  531. * @dev: the I3C device descriptor to attach private data to
  532. * @data: private data
  533. *
  534. * This functions allows a master controller to attach per-device private data
  535. * which can then be retrieved with i3c_dev_get_master_data().
  536. */
  537. static inline void i3c_dev_set_master_data(struct i3c_dev_desc *dev,
  538. void *data)
  539. {
  540. dev->common.master_priv = data;
  541. }
  542. /**
  543. * i2c_dev_get_master_data() - get master private data attached to an I2C
  544. * device descriptor
  545. * @dev: the I2C device descriptor to get private data from
  546. *
  547. * Return: the private data previously attached with i2c_dev_set_master_data()
  548. * or NULL if no data has been attached to the device.
  549. */
  550. static inline void *i2c_dev_get_master_data(const struct i2c_dev_desc *dev)
  551. {
  552. return dev->common.master_priv;
  553. }
  554. /**
  555. * i2c_dev_set_master_data() - attach master private data to an I2C device
  556. * descriptor
  557. * @dev: the I2C device descriptor to attach private data to
  558. * @data: private data
  559. *
  560. * This functions allows a master controller to attach per-device private data
  561. * which can then be retrieved with i2c_device_get_master_data().
  562. */
  563. static inline void i2c_dev_set_master_data(struct i2c_dev_desc *dev,
  564. void *data)
  565. {
  566. dev->common.master_priv = data;
  567. }
  568. /**
  569. * i3c_dev_get_master() - get master used to communicate with a device
  570. * @dev: I3C dev
  571. *
  572. * Return: the master controller driving @dev
  573. */
  574. static inline struct i3c_master_controller *
  575. i3c_dev_get_master(struct i3c_dev_desc *dev)
  576. {
  577. return dev->common.master;
  578. }
  579. /**
  580. * i2c_dev_get_master() - get master used to communicate with a device
  581. * @dev: I2C dev
  582. *
  583. * Return: the master controller driving @dev
  584. */
  585. static inline struct i3c_master_controller *
  586. i2c_dev_get_master(struct i2c_dev_desc *dev)
  587. {
  588. return dev->common.master;
  589. }
  590. /**
  591. * i3c_master_get_bus() - get the bus attached to a master
  592. * @master: master object
  593. *
  594. * Return: the I3C bus @master is connected to
  595. */
  596. static inline struct i3c_bus *
  597. i3c_master_get_bus(struct i3c_master_controller *master)
  598. {
  599. return &master->bus;
  600. }
  601. struct i3c_generic_ibi_pool;
  602. struct i3c_generic_ibi_pool *
  603. i3c_generic_ibi_alloc_pool(struct i3c_dev_desc *dev,
  604. const struct i3c_ibi_setup *req);
  605. void i3c_generic_ibi_free_pool(struct i3c_generic_ibi_pool *pool);
  606. struct i3c_ibi_slot *
  607. i3c_generic_ibi_get_free_slot(struct i3c_generic_ibi_pool *pool);
  608. void i3c_generic_ibi_recycle_slot(struct i3c_generic_ibi_pool *pool,
  609. struct i3c_ibi_slot *slot);
  610. void i3c_master_queue_ibi(struct i3c_dev_desc *dev, struct i3c_ibi_slot *slot);
  611. struct i3c_ibi_slot *i3c_master_get_free_ibi_slot(struct i3c_dev_desc *dev);
  612. #endif /* I3C_MASTER_H */