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