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