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