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