xref: /openbmc/linux/include/linux/i3c/master.h (revision 4edeb9fa)
13a379bbcSBoris Brezillon /* SPDX-License-Identifier: GPL-2.0 */
23a379bbcSBoris Brezillon /*
33a379bbcSBoris Brezillon  * Copyright (C) 2018 Cadence Design Systems Inc.
43a379bbcSBoris Brezillon  *
53a379bbcSBoris Brezillon  * Author: Boris Brezillon <boris.brezillon@bootlin.com>
63a379bbcSBoris Brezillon  */
73a379bbcSBoris Brezillon 
83a379bbcSBoris Brezillon #ifndef I3C_MASTER_H
93a379bbcSBoris Brezillon #define I3C_MASTER_H
103a379bbcSBoris Brezillon 
113a379bbcSBoris Brezillon #include <asm/bitsperlong.h>
123a379bbcSBoris Brezillon 
133a379bbcSBoris Brezillon #include <linux/bitops.h>
143a379bbcSBoris Brezillon #include <linux/i2c.h>
153a379bbcSBoris Brezillon #include <linux/i3c/ccc.h>
163a379bbcSBoris Brezillon #include <linux/i3c/device.h>
173a379bbcSBoris Brezillon #include <linux/rwsem.h>
183a379bbcSBoris Brezillon #include <linux/spinlock.h>
193a379bbcSBoris Brezillon #include <linux/workqueue.h>
203a379bbcSBoris Brezillon 
213a379bbcSBoris Brezillon #define I3C_HOT_JOIN_ADDR		0x2
223a379bbcSBoris Brezillon #define I3C_BROADCAST_ADDR		0x7e
233a379bbcSBoris Brezillon #define I3C_MAX_ADDR			GENMASK(6, 0)
243a379bbcSBoris Brezillon 
25ce48f955SAndy Shevchenko struct i2c_client;
26ce48f955SAndy Shevchenko 
274edeb9faSJeremy Kerr /* notifier actions. notifier call data is the struct i3c_bus */
284edeb9faSJeremy Kerr enum {
294edeb9faSJeremy Kerr 	I3C_NOTIFY_BUS_ADD,
304edeb9faSJeremy Kerr 	I3C_NOTIFY_BUS_REMOVE,
314edeb9faSJeremy Kerr };
324edeb9faSJeremy Kerr 
333a379bbcSBoris Brezillon struct i3c_master_controller;
343a379bbcSBoris Brezillon struct i3c_bus;
353a379bbcSBoris Brezillon struct i3c_device;
363a379bbcSBoris Brezillon 
373a379bbcSBoris Brezillon /**
383a379bbcSBoris Brezillon  * struct i3c_i2c_dev_desc - Common part of the I3C/I2C device descriptor
393a379bbcSBoris Brezillon  * @node: node element used to insert the slot into the I2C or I3C device
403a379bbcSBoris Brezillon  *	  list
413a379bbcSBoris Brezillon  * @master: I3C master that instantiated this device. Will be used to do
423a379bbcSBoris Brezillon  *	    I2C/I3C transfers
433a379bbcSBoris Brezillon  * @master_priv: master private data assigned to the device. Can be used to
443a379bbcSBoris Brezillon  *		 add master specific information
453a379bbcSBoris Brezillon  *
463a379bbcSBoris Brezillon  * This structure is describing common I3C/I2C dev information.
473a379bbcSBoris Brezillon  */
483a379bbcSBoris Brezillon struct i3c_i2c_dev_desc {
493a379bbcSBoris Brezillon 	struct list_head node;
503a379bbcSBoris Brezillon 	struct i3c_master_controller *master;
513a379bbcSBoris Brezillon 	void *master_priv;
523a379bbcSBoris Brezillon };
533a379bbcSBoris Brezillon 
543a379bbcSBoris Brezillon #define I3C_LVR_I2C_INDEX_MASK		GENMASK(7, 5)
553a379bbcSBoris Brezillon #define I3C_LVR_I2C_INDEX(x)		((x) << 5)
563a379bbcSBoris Brezillon #define I3C_LVR_I2C_FM_MODE		BIT(4)
573a379bbcSBoris Brezillon 
5888c50322SPrzemyslaw Gaj #define I2C_MAX_ADDR			GENMASK(6, 0)
593a379bbcSBoris Brezillon 
603a379bbcSBoris Brezillon /**
613a379bbcSBoris Brezillon  * struct i2c_dev_boardinfo - I2C device board information
623a379bbcSBoris Brezillon  * @node: used to insert the boardinfo object in the I2C boardinfo list
633a379bbcSBoris Brezillon  * @base: regular I2C board information
643a379bbcSBoris Brezillon  * @lvr: LVR (Legacy Virtual Register) needed by the I3C core to know about
653a379bbcSBoris Brezillon  *	 the I2C device limitations
663a379bbcSBoris Brezillon  *
673a379bbcSBoris Brezillon  * This structure is used to attach board-level information to an I2C device.
683a379bbcSBoris Brezillon  * Each I2C device connected on the I3C bus should have one.
693a379bbcSBoris Brezillon  */
703a379bbcSBoris Brezillon struct i2c_dev_boardinfo {
713a379bbcSBoris Brezillon 	struct list_head node;
723a379bbcSBoris Brezillon 	struct i2c_board_info base;
733a379bbcSBoris Brezillon 	u8 lvr;
743a379bbcSBoris Brezillon };
753a379bbcSBoris Brezillon 
763a379bbcSBoris Brezillon /**
773a379bbcSBoris Brezillon  * struct i2c_dev_desc - I2C device descriptor
783a379bbcSBoris Brezillon  * @common: common part of the I2C device descriptor
793a379bbcSBoris Brezillon  * @boardinfo: pointer to the boardinfo attached to this I2C device
803a379bbcSBoris Brezillon  * @dev: I2C device object registered to the I2C framework
81b1ac3a4bSPrzemyslaw Gaj  * @addr: I2C device address
82b1ac3a4bSPrzemyslaw Gaj  * @lvr: LVR (Legacy Virtual Register) needed by the I3C core to know about
83b1ac3a4bSPrzemyslaw Gaj  *	 the I2C device limitations
843a379bbcSBoris Brezillon  *
853a379bbcSBoris Brezillon  * Each I2C device connected on the bus will have an i2c_dev_desc.
863a379bbcSBoris Brezillon  * This object is created by the core and later attached to the controller
873a379bbcSBoris Brezillon  * using &struct_i3c_master_controller->ops->attach_i2c_dev().
883a379bbcSBoris Brezillon  *
893a379bbcSBoris Brezillon  * &struct_i2c_dev_desc is the internal representation of an I2C device
903a379bbcSBoris Brezillon  * connected on an I3C bus. This object is also passed to all
913a379bbcSBoris Brezillon  * &struct_i3c_master_controller_ops hooks.
923a379bbcSBoris Brezillon  */
933a379bbcSBoris Brezillon struct i2c_dev_desc {
943a379bbcSBoris Brezillon 	struct i3c_i2c_dev_desc common;
953a379bbcSBoris Brezillon 	struct i2c_client *dev;
96b1ac3a4bSPrzemyslaw Gaj 	u16 addr;
97b1ac3a4bSPrzemyslaw Gaj 	u8 lvr;
983a379bbcSBoris Brezillon };
993a379bbcSBoris Brezillon 
1003a379bbcSBoris Brezillon /**
1013a379bbcSBoris Brezillon  * struct i3c_ibi_slot - I3C IBI (In-Band Interrupt) slot
1023a379bbcSBoris Brezillon  * @work: work associated to this slot. The IBI handler will be called from
1033a379bbcSBoris Brezillon  *	  there
1043a379bbcSBoris Brezillon  * @dev: the I3C device that has generated this IBI
1053a379bbcSBoris Brezillon  * @len: length of the payload associated to this IBI
1063a379bbcSBoris Brezillon  * @data: payload buffer
1073a379bbcSBoris Brezillon  *
1083a379bbcSBoris Brezillon  * An IBI slot is an object pre-allocated by the controller and used when an
1093a379bbcSBoris Brezillon  * IBI comes in.
1103a379bbcSBoris Brezillon  * Every time an IBI comes in, the I3C master driver should find a free IBI
1113a379bbcSBoris Brezillon  * slot in its IBI slot pool, retrieve the IBI payload and queue the IBI using
1123a379bbcSBoris Brezillon  * i3c_master_queue_ibi().
1133a379bbcSBoris Brezillon  *
1143a379bbcSBoris Brezillon  * How IBI slots are allocated is left to the I3C master driver, though, for
1153a379bbcSBoris Brezillon  * simple kmalloc-based allocation, the generic IBI slot pool can be used.
1163a379bbcSBoris Brezillon  */
1173a379bbcSBoris Brezillon struct i3c_ibi_slot {
1183a379bbcSBoris Brezillon 	struct work_struct work;
1193a379bbcSBoris Brezillon 	struct i3c_dev_desc *dev;
1203a379bbcSBoris Brezillon 	unsigned int len;
1213a379bbcSBoris Brezillon 	void *data;
1223a379bbcSBoris Brezillon };
1233a379bbcSBoris Brezillon 
1243a379bbcSBoris Brezillon /**
1253a379bbcSBoris Brezillon  * struct i3c_device_ibi_info - IBI information attached to a specific device
1263a379bbcSBoris Brezillon  * @all_ibis_handled: used to be informed when no more IBIs are waiting to be
1273a379bbcSBoris Brezillon  *		      processed. Used by i3c_device_disable_ibi() to wait for
1283a379bbcSBoris Brezillon  *		      all IBIs to be dequeued
1293a379bbcSBoris Brezillon  * @pending_ibis: count the number of pending IBIs. Each pending IBI has its
1303a379bbcSBoris Brezillon  *		  work element queued to the controller workqueue
1313a379bbcSBoris Brezillon  * @max_payload_len: maximum payload length for an IBI coming from this device.
1323a379bbcSBoris Brezillon  *		     this value is specified when calling
1333a379bbcSBoris Brezillon  *		     i3c_device_request_ibi() and should not change at run
1343a379bbcSBoris Brezillon  *		     time. All messages IBIs exceeding this limit should be
1353a379bbcSBoris Brezillon  *		     rejected by the master
1363a379bbcSBoris Brezillon  * @num_slots: number of IBI slots reserved for this device
1373a379bbcSBoris Brezillon  * @enabled: reflect the IBI status
1383a379bbcSBoris Brezillon  * @handler: IBI handler specified at i3c_device_request_ibi() call time. This
1393a379bbcSBoris Brezillon  *	     handler will be called from the controller workqueue, and as such
1403a379bbcSBoris Brezillon  *	     is allowed to sleep (though it is recommended to process the IBI
1413a379bbcSBoris Brezillon  *	     as fast as possible to not stall processing of other IBIs queued
1423a379bbcSBoris Brezillon  *	     on the same workqueue).
1433a379bbcSBoris Brezillon  *	     New I3C messages can be sent from the IBI handler
1443a379bbcSBoris Brezillon  *
1453a379bbcSBoris Brezillon  * The &struct_i3c_device_ibi_info object is allocated when
1463a379bbcSBoris Brezillon  * i3c_device_request_ibi() is called and attached to a specific device. This
1473a379bbcSBoris Brezillon  * object is here to manage IBIs coming from a specific I3C device.
1483a379bbcSBoris Brezillon  *
1493a379bbcSBoris Brezillon  * Note that this structure is the generic view of the IBI management
1503a379bbcSBoris Brezillon  * infrastructure. I3C master drivers may have their own internal
1513a379bbcSBoris Brezillon  * representation which they can associate to the device using
1523a379bbcSBoris Brezillon  * controller-private data.
1533a379bbcSBoris Brezillon  */
1543a379bbcSBoris Brezillon struct i3c_device_ibi_info {
1553a379bbcSBoris Brezillon 	struct completion all_ibis_handled;
1563a379bbcSBoris Brezillon 	atomic_t pending_ibis;
1573a379bbcSBoris Brezillon 	unsigned int max_payload_len;
1583a379bbcSBoris Brezillon 	unsigned int num_slots;
1593a379bbcSBoris Brezillon 	unsigned int enabled;
1603a379bbcSBoris Brezillon 	void (*handler)(struct i3c_device *dev,
1613a379bbcSBoris Brezillon 			const struct i3c_ibi_payload *payload);
1623a379bbcSBoris Brezillon };
1633a379bbcSBoris Brezillon 
1643a379bbcSBoris Brezillon /**
1653a379bbcSBoris Brezillon  * struct i3c_dev_boardinfo - I3C device board information
1663a379bbcSBoris Brezillon  * @node: used to insert the boardinfo object in the I3C boardinfo list
1673a379bbcSBoris Brezillon  * @init_dyn_addr: initial dynamic address requested by the FW. We provide no
1683a379bbcSBoris Brezillon  *		   guarantee that the device will end up using this address,
1693a379bbcSBoris Brezillon  *		   but try our best to assign this specific address to the
1703a379bbcSBoris Brezillon  *		   device
1713a379bbcSBoris Brezillon  * @static_addr: static address the I3C device listen on before it's been
1723a379bbcSBoris Brezillon  *		 assigned a dynamic address by the master. Will be used during
1733a379bbcSBoris Brezillon  *		 bus initialization to assign it a specific dynamic address
1743a379bbcSBoris Brezillon  *		 before starting DAA (Dynamic Address Assignment)
1753a379bbcSBoris Brezillon  * @pid: I3C Provisional ID exposed by the device. This is a unique identifier
1763a379bbcSBoris Brezillon  *	 that may be used to attach boardinfo to i3c_dev_desc when the device
1773a379bbcSBoris Brezillon  *	 does not have a static address
1783a379bbcSBoris Brezillon  * @of_node: optional DT node in case the device has been described in the DT
1793a379bbcSBoris Brezillon  *
1803a379bbcSBoris Brezillon  * This structure is used to attach board-level information to an I3C device.
1813a379bbcSBoris Brezillon  * Not all I3C devices connected on the bus will have a boardinfo. It's only
1823a379bbcSBoris Brezillon  * needed if you want to attach extra resources to a device or assign it a
1833a379bbcSBoris Brezillon  * specific dynamic address.
1843a379bbcSBoris Brezillon  */
1853a379bbcSBoris Brezillon struct i3c_dev_boardinfo {
1863a379bbcSBoris Brezillon 	struct list_head node;
1873a379bbcSBoris Brezillon 	u8 init_dyn_addr;
1883a379bbcSBoris Brezillon 	u8 static_addr;
1893a379bbcSBoris Brezillon 	u64 pid;
1903a379bbcSBoris Brezillon 	struct device_node *of_node;
1913a379bbcSBoris Brezillon };
1923a379bbcSBoris Brezillon 
1933a379bbcSBoris Brezillon /**
1943a379bbcSBoris Brezillon  * struct i3c_dev_desc - I3C device descriptor
1953a379bbcSBoris Brezillon  * @common: common part of the I3C device descriptor
1963a379bbcSBoris Brezillon  * @info: I3C device information. Will be automatically filled when you create
1973a379bbcSBoris Brezillon  *	  your device with i3c_master_add_i3c_dev_locked()
1983a379bbcSBoris Brezillon  * @ibi_lock: lock used to protect the &struct_i3c_device->ibi
1993a379bbcSBoris Brezillon  * @ibi: IBI info attached to a device. Should be NULL until
2003a379bbcSBoris Brezillon  *	 i3c_device_request_ibi() is called
2013a379bbcSBoris Brezillon  * @dev: pointer to the I3C device object exposed to I3C device drivers. This
2023a379bbcSBoris Brezillon  *	 should never be accessed from I3C master controller drivers. Only core
2033a379bbcSBoris Brezillon  *	 code should manipulate it in when updating the dev <-> desc link or
2043a379bbcSBoris Brezillon  *	 when propagating IBI events to the driver
2053a379bbcSBoris Brezillon  * @boardinfo: pointer to the boardinfo attached to this I3C device
2063a379bbcSBoris Brezillon  *
2073a379bbcSBoris Brezillon  * Internal representation of an I3C device. This object is only used by the
2083a379bbcSBoris Brezillon  * core and passed to I3C master controller drivers when they're requested to
2093a379bbcSBoris Brezillon  * do some operations on the device.
2103a379bbcSBoris Brezillon  * The core maintains the link between the internal I3C dev descriptor and the
2113a379bbcSBoris Brezillon  * object exposed to the I3C device drivers (&struct_i3c_device).
2123a379bbcSBoris Brezillon  */
2133a379bbcSBoris Brezillon struct i3c_dev_desc {
2143a379bbcSBoris Brezillon 	struct i3c_i2c_dev_desc common;
2153a379bbcSBoris Brezillon 	struct i3c_device_info info;
2163a379bbcSBoris Brezillon 	struct mutex ibi_lock;
2173a379bbcSBoris Brezillon 	struct i3c_device_ibi_info *ibi;
2183a379bbcSBoris Brezillon 	struct i3c_device *dev;
2193a379bbcSBoris Brezillon 	const struct i3c_dev_boardinfo *boardinfo;
2203a379bbcSBoris Brezillon };
2213a379bbcSBoris Brezillon 
2223a379bbcSBoris Brezillon /**
2233a379bbcSBoris Brezillon  * struct i3c_device - I3C device object
2243a379bbcSBoris Brezillon  * @dev: device object to register the I3C dev to the device model
2253a379bbcSBoris Brezillon  * @desc: pointer to an i3c device descriptor object. This link is updated
2263a379bbcSBoris Brezillon  *	  every time the I3C device is rediscovered with a different dynamic
2273a379bbcSBoris Brezillon  *	  address assigned
2283a379bbcSBoris Brezillon  * @bus: I3C bus this device is attached to
2293a379bbcSBoris Brezillon  *
2303a379bbcSBoris Brezillon  * I3C device object exposed to I3C device drivers. The takes care of linking
2313a379bbcSBoris Brezillon  * this object to the relevant &struct_i3c_dev_desc one.
2323a379bbcSBoris Brezillon  * All I3C devs on the I3C bus are represented, including I3C masters. For each
2333a379bbcSBoris Brezillon  * of them, we have an instance of &struct i3c_device.
2343a379bbcSBoris Brezillon  */
2353a379bbcSBoris Brezillon struct i3c_device {
2363a379bbcSBoris Brezillon 	struct device dev;
2373a379bbcSBoris Brezillon 	struct i3c_dev_desc *desc;
2383a379bbcSBoris Brezillon 	struct i3c_bus *bus;
2393a379bbcSBoris Brezillon };
2403a379bbcSBoris Brezillon 
2413a379bbcSBoris Brezillon /*
2423a379bbcSBoris Brezillon  * The I3C specification says the maximum number of devices connected on the
2433a379bbcSBoris Brezillon  * bus is 11, but this number depends on external parameters like trace length,
2443a379bbcSBoris Brezillon  * capacitive load per Device, and the types of Devices present on the Bus.
2453a379bbcSBoris Brezillon  * I3C master can also have limitations, so this number is just here as a
2463a379bbcSBoris Brezillon  * reference and should be adjusted on a per-controller/per-board basis.
2473a379bbcSBoris Brezillon  */
2483a379bbcSBoris Brezillon #define I3C_BUS_MAX_DEVS		11
2493a379bbcSBoris Brezillon 
2503a379bbcSBoris Brezillon #define I3C_BUS_MAX_I3C_SCL_RATE	12900000
2513a379bbcSBoris Brezillon #define I3C_BUS_TYP_I3C_SCL_RATE	12500000
2523a379bbcSBoris Brezillon #define I3C_BUS_I2C_FM_PLUS_SCL_RATE	1000000
2533a379bbcSBoris Brezillon #define I3C_BUS_I2C_FM_SCL_RATE		400000
2543a379bbcSBoris Brezillon #define I3C_BUS_TLOW_OD_MIN_NS		200
2553a379bbcSBoris Brezillon 
2563a379bbcSBoris Brezillon /**
2573a379bbcSBoris Brezillon  * enum i3c_bus_mode - I3C bus mode
2583a379bbcSBoris Brezillon  * @I3C_BUS_MODE_PURE: only I3C devices are connected to the bus. No limitation
2593a379bbcSBoris Brezillon  *		       expected
2603a379bbcSBoris Brezillon  * @I3C_BUS_MODE_MIXED_FAST: I2C devices with 50ns spike filter are present on
2613a379bbcSBoris Brezillon  *			     the bus. The only impact in this mode is that the
2623a379bbcSBoris Brezillon  *			     high SCL pulse has to stay below 50ns to trick I2C
2633a379bbcSBoris Brezillon  *			     devices when transmitting I3C frames
264cbf4f732SVitor Soares  * @I3C_BUS_MODE_MIXED_LIMITED: I2C devices without 50ns spike filter are
265cbf4f732SVitor Soares  *				present on the bus. However they allow
266cbf4f732SVitor Soares  *				compliance up to the maximum SDR SCL clock
267cbf4f732SVitor Soares  *				frequency.
2683a379bbcSBoris Brezillon  * @I3C_BUS_MODE_MIXED_SLOW: I2C devices without 50ns spike filter are present
2693a379bbcSBoris Brezillon  *			     on the bus
2703a379bbcSBoris Brezillon  */
2713a379bbcSBoris Brezillon enum i3c_bus_mode {
2723a379bbcSBoris Brezillon 	I3C_BUS_MODE_PURE,
2733a379bbcSBoris Brezillon 	I3C_BUS_MODE_MIXED_FAST,
274cbf4f732SVitor Soares 	I3C_BUS_MODE_MIXED_LIMITED,
2753a379bbcSBoris Brezillon 	I3C_BUS_MODE_MIXED_SLOW,
2763a379bbcSBoris Brezillon };
2773a379bbcSBoris Brezillon 
2783a379bbcSBoris Brezillon /**
2793a379bbcSBoris Brezillon  * enum i3c_addr_slot_status - I3C address slot status
2803a379bbcSBoris Brezillon  * @I3C_ADDR_SLOT_FREE: address is free
2813a379bbcSBoris Brezillon  * @I3C_ADDR_SLOT_RSVD: address is reserved
2823a379bbcSBoris Brezillon  * @I3C_ADDR_SLOT_I2C_DEV: address is assigned to an I2C device
2833a379bbcSBoris Brezillon  * @I3C_ADDR_SLOT_I3C_DEV: address is assigned to an I3C device
2843a379bbcSBoris Brezillon  * @I3C_ADDR_SLOT_STATUS_MASK: address slot mask
2853a379bbcSBoris Brezillon  *
2863a379bbcSBoris Brezillon  * On an I3C bus, addresses are assigned dynamically, and we need to know which
2873a379bbcSBoris Brezillon  * addresses are free to use and which ones are already assigned.
2883a379bbcSBoris Brezillon  *
2893a379bbcSBoris Brezillon  * Addresses marked as reserved are those reserved by the I3C protocol
2903a379bbcSBoris Brezillon  * (broadcast address, ...).
2913a379bbcSBoris Brezillon  */
2923a379bbcSBoris Brezillon enum i3c_addr_slot_status {
2933a379bbcSBoris Brezillon 	I3C_ADDR_SLOT_FREE,
2943a379bbcSBoris Brezillon 	I3C_ADDR_SLOT_RSVD,
2953a379bbcSBoris Brezillon 	I3C_ADDR_SLOT_I2C_DEV,
2963a379bbcSBoris Brezillon 	I3C_ADDR_SLOT_I3C_DEV,
2973a379bbcSBoris Brezillon 	I3C_ADDR_SLOT_STATUS_MASK = 3,
2983a379bbcSBoris Brezillon };
2993a379bbcSBoris Brezillon 
3003a379bbcSBoris Brezillon /**
3013a379bbcSBoris Brezillon  * struct i3c_bus - I3C bus object
3023a379bbcSBoris Brezillon  * @cur_master: I3C master currently driving the bus. Since I3C is multi-master
3033a379bbcSBoris Brezillon  *		this can change over the time. Will be used to let a master
3043a379bbcSBoris Brezillon  *		know whether it needs to request bus ownership before sending
3053a379bbcSBoris Brezillon  *		a frame or not
3063a379bbcSBoris Brezillon  * @id: bus ID. Assigned by the framework when register the bus
3073a379bbcSBoris Brezillon  * @addrslots: a bitmap with 2-bits per-slot to encode the address status and
3083a379bbcSBoris Brezillon  *	       ease the DAA (Dynamic Address Assignment) procedure (see
3093a379bbcSBoris Brezillon  *	       &enum i3c_addr_slot_status)
3103a379bbcSBoris Brezillon  * @mode: bus mode (see &enum i3c_bus_mode)
3113a379bbcSBoris Brezillon  * @scl_rate.i3c: maximum rate for the clock signal when doing I3C SDR/priv
3123a379bbcSBoris Brezillon  *		  transfers
3133a379bbcSBoris Brezillon  * @scl_rate.i2c: maximum rate for the clock signal when doing I2C transfers
3143a379bbcSBoris Brezillon  * @scl_rate: SCL signal rate for I3C and I2C mode
3153a379bbcSBoris Brezillon  * @devs.i3c: contains a list of I3C device descriptors representing I3C
3163a379bbcSBoris Brezillon  *	      devices connected on the bus and successfully attached to the
3173a379bbcSBoris Brezillon  *	      I3C master
3183a379bbcSBoris Brezillon  * @devs.i2c: contains a list of I2C device descriptors representing I2C
3193a379bbcSBoris Brezillon  *	      devices connected on the bus and successfully attached to the
3203a379bbcSBoris Brezillon  *	      I3C master
3213a379bbcSBoris Brezillon  * @devs: 2 lists containing all I3C/I2C devices connected to the bus
3223a379bbcSBoris Brezillon  * @lock: read/write lock on the bus. This is needed to protect against
3233a379bbcSBoris Brezillon  *	  operations that have an impact on the whole bus and the devices
3243a379bbcSBoris Brezillon  *	  connected to it. For example, when asking slaves to drop their
3253a379bbcSBoris Brezillon  *	  dynamic address (RSTDAA CCC), we need to make sure no one is trying
3263a379bbcSBoris Brezillon  *	  to send I3C frames to these devices.
3273a379bbcSBoris Brezillon  *	  Note that this lock does not protect against concurrency between
3283a379bbcSBoris Brezillon  *	  devices: several drivers can send different I3C/I2C frames through
3293a379bbcSBoris Brezillon  *	  the same master in parallel. This is the responsibility of the
3303a379bbcSBoris Brezillon  *	  master to guarantee that frames are actually sent sequentially and
3313a379bbcSBoris Brezillon  *	  not interlaced
3323a379bbcSBoris Brezillon  *
3333a379bbcSBoris Brezillon  * The I3C bus is represented with its own object and not implicitly described
3343a379bbcSBoris Brezillon  * by the I3C master to cope with the multi-master functionality, where one bus
3353a379bbcSBoris Brezillon  * can be shared amongst several masters, each of them requesting bus ownership
3363a379bbcSBoris Brezillon  * when they need to.
3373a379bbcSBoris Brezillon  */
3383a379bbcSBoris Brezillon struct i3c_bus {
3393a379bbcSBoris Brezillon 	struct i3c_dev_desc *cur_master;
3403a379bbcSBoris Brezillon 	int id;
3413a379bbcSBoris Brezillon 	unsigned long addrslots[((I2C_MAX_ADDR + 1) * 2) / BITS_PER_LONG];
3423a379bbcSBoris Brezillon 	enum i3c_bus_mode mode;
3433a379bbcSBoris Brezillon 	struct {
3443a379bbcSBoris Brezillon 		unsigned long i3c;
3453a379bbcSBoris Brezillon 		unsigned long i2c;
3463a379bbcSBoris Brezillon 	} scl_rate;
3473a379bbcSBoris Brezillon 	struct {
3483a379bbcSBoris Brezillon 		struct list_head i3c;
3493a379bbcSBoris Brezillon 		struct list_head i2c;
3503a379bbcSBoris Brezillon 	} devs;
3513a379bbcSBoris Brezillon 	struct rw_semaphore lock;
3523a379bbcSBoris Brezillon };
3533a379bbcSBoris Brezillon 
3543a379bbcSBoris Brezillon /**
3553a379bbcSBoris Brezillon  * struct i3c_master_controller_ops - I3C master methods
3563a379bbcSBoris Brezillon  * @bus_init: hook responsible for the I3C bus initialization. You should at
3573a379bbcSBoris Brezillon  *	      least call master_set_info() from there and set the bus mode.
3583a379bbcSBoris Brezillon  *	      You can also put controller specific initialization in there.
3593a379bbcSBoris Brezillon  *	      This method is mandatory.
3603a379bbcSBoris Brezillon  * @bus_cleanup: cleanup everything done in
3613a379bbcSBoris Brezillon  *		 &i3c_master_controller_ops->bus_init().
3623a379bbcSBoris Brezillon  *		 This method is optional.
3633a379bbcSBoris Brezillon  * @attach_i3c_dev: called every time an I3C device is attached to the bus. It
3643a379bbcSBoris Brezillon  *		    can be after a DAA or when a device is statically declared
3653a379bbcSBoris Brezillon  *		    by the FW, in which case it will only have a static address
3663a379bbcSBoris Brezillon  *		    and the dynamic address will be 0.
3673a379bbcSBoris Brezillon  *		    When this function is called, device information have not
3683a379bbcSBoris Brezillon  *		    been retrieved yet.
3693a379bbcSBoris Brezillon  *		    This is a good place to attach master controller specific
3703a379bbcSBoris Brezillon  *		    data to I3C devices.
3713a379bbcSBoris Brezillon  *		    This method is optional.
3723a379bbcSBoris Brezillon  * @reattach_i3c_dev: called every time an I3C device has its addressed
3733a379bbcSBoris Brezillon  *		      changed. It can be because the device has been powered
3743a379bbcSBoris Brezillon  *		      down and has lost its address, or it can happen when a
3753a379bbcSBoris Brezillon  *		      device had a static address and has been assigned a
3763a379bbcSBoris Brezillon  *		      dynamic address with SETDASA.
3773a379bbcSBoris Brezillon  *		      This method is optional.
3783a379bbcSBoris Brezillon  * @detach_i3c_dev: called when an I3C device is detached from the bus. Usually
3793a379bbcSBoris Brezillon  *		    happens when the master device is unregistered.
3803a379bbcSBoris Brezillon  *		    This method is optional.
3813a379bbcSBoris Brezillon  * @do_daa: do a DAA (Dynamic Address Assignment) procedure. This is procedure
3823a379bbcSBoris Brezillon  *	    should send an ENTDAA CCC command and then add all devices
3833a379bbcSBoris Brezillon  *	    discovered sure the DAA using i3c_master_add_i3c_dev_locked().
3843a379bbcSBoris Brezillon  *	    Add devices added with i3c_master_add_i3c_dev_locked() will then be
3853a379bbcSBoris Brezillon  *	    attached or re-attached to the controller.
3863a379bbcSBoris Brezillon  *	    This method is mandatory.
3873a379bbcSBoris Brezillon  * @supports_ccc_cmd: should return true if the CCC command is supported, false
3883a379bbcSBoris Brezillon  *		      otherwise.
3893a379bbcSBoris Brezillon  *		      This method is optional, if not provided the core assumes
3903a379bbcSBoris Brezillon  *		      all CCC commands are supported.
3913a379bbcSBoris Brezillon  * @send_ccc_cmd: send a CCC command
3923a379bbcSBoris Brezillon  *		  This method is mandatory.
3933a379bbcSBoris Brezillon  * @priv_xfers: do one or several private I3C SDR transfers
3943a379bbcSBoris Brezillon  *		This method is mandatory.
3953a379bbcSBoris Brezillon  * @attach_i2c_dev: called every time an I2C device is attached to the bus.
3963a379bbcSBoris Brezillon  *		    This is a good place to attach master controller specific
3973a379bbcSBoris Brezillon  *		    data to I2C devices.
3983a379bbcSBoris Brezillon  *		    This method is optional.
3993a379bbcSBoris Brezillon  * @detach_i2c_dev: called when an I2C device is detached from the bus. Usually
4003a379bbcSBoris Brezillon  *		    happens when the master device is unregistered.
4013a379bbcSBoris Brezillon  *		    This method is optional.
4023a379bbcSBoris Brezillon  * @i2c_xfers: do one or several I2C transfers. Note that, unlike i3c
4033a379bbcSBoris Brezillon  *	       transfers, the core does not guarantee that buffers attached to
4043a379bbcSBoris Brezillon  *	       the transfers are DMA-safe. If drivers want to have DMA-safe
4053a379bbcSBoris Brezillon  *	       buffers, they should use the i2c_get_dma_safe_msg_buf()
4063a379bbcSBoris Brezillon  *	       and i2c_put_dma_safe_msg_buf() helpers provided by the I2C
4073a379bbcSBoris Brezillon  *	       framework.
4083a379bbcSBoris Brezillon  *	       This method is mandatory.
4093a379bbcSBoris Brezillon  * @request_ibi: attach an IBI handler to an I3C device. This implies defining
4103a379bbcSBoris Brezillon  *		 an IBI handler and the constraints of the IBI (maximum payload
4113a379bbcSBoris Brezillon  *		 length and number of pre-allocated slots).
4123a379bbcSBoris Brezillon  *		 Some controllers support less IBI-capable devices than regular
4133a379bbcSBoris Brezillon  *		 devices, so this method might return -%EBUSY if there's no
4143a379bbcSBoris Brezillon  *		 more space for an extra IBI registration
4153a379bbcSBoris Brezillon  *		 This method is optional.
4163a379bbcSBoris Brezillon  * @free_ibi: free an IBI previously requested with ->request_ibi(). The IBI
4173a379bbcSBoris Brezillon  *	      should have been disabled with ->disable_irq() prior to that
4183a379bbcSBoris Brezillon  *	      This method is mandatory only if ->request_ibi is not NULL.
4193a379bbcSBoris Brezillon  * @enable_ibi: enable the IBI. Only valid if ->request_ibi() has been called
4203a379bbcSBoris Brezillon  *		prior to ->enable_ibi(). The controller should first enable
4213a379bbcSBoris Brezillon  *		the IBI on the controller end (for example, unmask the hardware
4223a379bbcSBoris Brezillon  *		IRQ) and then send the ENEC CCC command (with the IBI flag set)
4233a379bbcSBoris Brezillon  *		to the I3C device.
4243a379bbcSBoris Brezillon  *		This method is mandatory only if ->request_ibi is not NULL.
4253a379bbcSBoris Brezillon  * @disable_ibi: disable an IBI. First send the DISEC CCC command with the IBI
4263a379bbcSBoris Brezillon  *		 flag set and then deactivate the hardware IRQ on the
4273a379bbcSBoris Brezillon  *		 controller end.
4283a379bbcSBoris Brezillon  *		 This method is mandatory only if ->request_ibi is not NULL.
4293a379bbcSBoris Brezillon  * @recycle_ibi_slot: recycle an IBI slot. Called every time an IBI has been
4303a379bbcSBoris Brezillon  *		      processed by its handler. The IBI slot should be put back
4313a379bbcSBoris Brezillon  *		      in the IBI slot pool so that the controller can re-use it
4323a379bbcSBoris Brezillon  *		      for a future IBI
4333a379bbcSBoris Brezillon  *		      This method is mandatory only if ->request_ibi is not
4343a379bbcSBoris Brezillon  *		      NULL.
4353a379bbcSBoris Brezillon  */
4363a379bbcSBoris Brezillon struct i3c_master_controller_ops {
4373a379bbcSBoris Brezillon 	int (*bus_init)(struct i3c_master_controller *master);
4383a379bbcSBoris Brezillon 	void (*bus_cleanup)(struct i3c_master_controller *master);
4393a379bbcSBoris Brezillon 	int (*attach_i3c_dev)(struct i3c_dev_desc *dev);
4403a379bbcSBoris Brezillon 	int (*reattach_i3c_dev)(struct i3c_dev_desc *dev, u8 old_dyn_addr);
4413a379bbcSBoris Brezillon 	void (*detach_i3c_dev)(struct i3c_dev_desc *dev);
4423a379bbcSBoris Brezillon 	int (*do_daa)(struct i3c_master_controller *master);
4433a379bbcSBoris Brezillon 	bool (*supports_ccc_cmd)(struct i3c_master_controller *master,
4443a379bbcSBoris Brezillon 				 const struct i3c_ccc_cmd *cmd);
4453a379bbcSBoris Brezillon 	int (*send_ccc_cmd)(struct i3c_master_controller *master,
4463a379bbcSBoris Brezillon 			    struct i3c_ccc_cmd *cmd);
4473a379bbcSBoris Brezillon 	int (*priv_xfers)(struct i3c_dev_desc *dev,
4483a379bbcSBoris Brezillon 			  struct i3c_priv_xfer *xfers,
4493a379bbcSBoris Brezillon 			  int nxfers);
4503a379bbcSBoris Brezillon 	int (*attach_i2c_dev)(struct i2c_dev_desc *dev);
4513a379bbcSBoris Brezillon 	void (*detach_i2c_dev)(struct i2c_dev_desc *dev);
4523a379bbcSBoris Brezillon 	int (*i2c_xfers)(struct i2c_dev_desc *dev,
4533a379bbcSBoris Brezillon 			 const struct i2c_msg *xfers, int nxfers);
4543a379bbcSBoris Brezillon 	int (*request_ibi)(struct i3c_dev_desc *dev,
4553a379bbcSBoris Brezillon 			   const struct i3c_ibi_setup *req);
4563a379bbcSBoris Brezillon 	void (*free_ibi)(struct i3c_dev_desc *dev);
4573a379bbcSBoris Brezillon 	int (*enable_ibi)(struct i3c_dev_desc *dev);
4583a379bbcSBoris Brezillon 	int (*disable_ibi)(struct i3c_dev_desc *dev);
4593a379bbcSBoris Brezillon 	void (*recycle_ibi_slot)(struct i3c_dev_desc *dev,
4603a379bbcSBoris Brezillon 				 struct i3c_ibi_slot *slot);
4613a379bbcSBoris Brezillon };
4623a379bbcSBoris Brezillon 
4633a379bbcSBoris Brezillon /**
4643a379bbcSBoris Brezillon  * struct i3c_master_controller - I3C master controller object
4653a379bbcSBoris Brezillon  * @dev: device to be registered to the device-model
4663a379bbcSBoris Brezillon  * @this: an I3C device object representing this master. This device will be
4673a379bbcSBoris Brezillon  *	  added to the list of I3C devs available on the bus
4683a379bbcSBoris Brezillon  * @i2c: I2C adapter used for backward compatibility. This adapter is
4693a379bbcSBoris Brezillon  *	 registered to the I2C subsystem to be as transparent as possible to
4703a379bbcSBoris Brezillon  *	 existing I2C drivers
4713a379bbcSBoris Brezillon  * @ops: master operations. See &struct i3c_master_controller_ops
4723a379bbcSBoris Brezillon  * @secondary: true if the master is a secondary master
4733a379bbcSBoris Brezillon  * @init_done: true when the bus initialization is done
4743a379bbcSBoris Brezillon  * @boardinfo.i3c: list of I3C  boardinfo objects
4753a379bbcSBoris Brezillon  * @boardinfo.i2c: list of I2C boardinfo objects
4763a379bbcSBoris Brezillon  * @boardinfo: board-level information attached to devices connected on the bus
4773a379bbcSBoris Brezillon  * @bus: I3C bus exposed by this master
4783a379bbcSBoris Brezillon  * @wq: workqueue used to execute IBI handlers. Can also be used by master
4793a379bbcSBoris Brezillon  *	drivers if they need to postpone operations that need to take place
4803a379bbcSBoris Brezillon  *	in a thread context. Typical examples are Hot Join processing which
4813a379bbcSBoris Brezillon  *	requires taking the bus lock in maintenance, which in turn, can only
4823a379bbcSBoris Brezillon  *	be done from a sleep-able context
4833a379bbcSBoris Brezillon  *
4843a379bbcSBoris Brezillon  * A &struct i3c_master_controller has to be registered to the I3C subsystem
4853a379bbcSBoris Brezillon  * through i3c_master_register(). None of &struct i3c_master_controller fields
4863a379bbcSBoris Brezillon  * should be set manually, just pass appropriate values to
4873a379bbcSBoris Brezillon  * i3c_master_register().
4883a379bbcSBoris Brezillon  */
4893a379bbcSBoris Brezillon struct i3c_master_controller {
4903a379bbcSBoris Brezillon 	struct device dev;
4913a379bbcSBoris Brezillon 	struct i3c_dev_desc *this;
4923a379bbcSBoris Brezillon 	struct i2c_adapter i2c;
4933a379bbcSBoris Brezillon 	const struct i3c_master_controller_ops *ops;
4943a379bbcSBoris Brezillon 	unsigned int secondary : 1;
4953a379bbcSBoris Brezillon 	unsigned int init_done : 1;
4963a379bbcSBoris Brezillon 	struct {
4973a379bbcSBoris Brezillon 		struct list_head i3c;
4983a379bbcSBoris Brezillon 		struct list_head i2c;
4993a379bbcSBoris Brezillon 	} boardinfo;
5003a379bbcSBoris Brezillon 	struct i3c_bus bus;
5013a379bbcSBoris Brezillon 	struct workqueue_struct *wq;
5023a379bbcSBoris Brezillon };
5033a379bbcSBoris Brezillon 
5043a379bbcSBoris Brezillon /**
5053a379bbcSBoris Brezillon  * i3c_bus_for_each_i2cdev() - iterate over all I2C devices present on the bus
5063a379bbcSBoris Brezillon  * @bus: the I3C bus
5073a379bbcSBoris Brezillon  * @dev: an I2C device descriptor pointer updated to point to the current slot
5083a379bbcSBoris Brezillon  *	 at each iteration of the loop
5093a379bbcSBoris Brezillon  *
5103a379bbcSBoris Brezillon  * Iterate over all I2C devs present on the bus.
5113a379bbcSBoris Brezillon  */
5123a379bbcSBoris Brezillon #define i3c_bus_for_each_i2cdev(bus, dev)				\
5133a379bbcSBoris Brezillon 	list_for_each_entry(dev, &(bus)->devs.i2c, common.node)
5143a379bbcSBoris Brezillon 
5153a379bbcSBoris Brezillon /**
5163a379bbcSBoris Brezillon  * i3c_bus_for_each_i3cdev() - iterate over all I3C devices present on the bus
5173a379bbcSBoris Brezillon  * @bus: the I3C bus
5183a379bbcSBoris Brezillon  * @dev: and I3C device descriptor pointer updated to point to the current slot
5193a379bbcSBoris Brezillon  *	 at each iteration of the loop
5203a379bbcSBoris Brezillon  *
5213a379bbcSBoris Brezillon  * Iterate over all I3C devs present on the bus.
5223a379bbcSBoris Brezillon  */
5233a379bbcSBoris Brezillon #define i3c_bus_for_each_i3cdev(bus, dev)				\
5243a379bbcSBoris Brezillon 	list_for_each_entry(dev, &(bus)->devs.i3c, common.node)
5253a379bbcSBoris Brezillon 
5263a379bbcSBoris Brezillon int i3c_master_do_i2c_xfers(struct i3c_master_controller *master,
5273a379bbcSBoris Brezillon 			    const struct i2c_msg *xfers,
5283a379bbcSBoris Brezillon 			    int nxfers);
5293a379bbcSBoris Brezillon 
5303a379bbcSBoris Brezillon int i3c_master_disec_locked(struct i3c_master_controller *master, u8 addr,
5313a379bbcSBoris Brezillon 			    u8 evts);
5323a379bbcSBoris Brezillon int i3c_master_enec_locked(struct i3c_master_controller *master, u8 addr,
5333a379bbcSBoris Brezillon 			   u8 evts);
5343a379bbcSBoris Brezillon int i3c_master_entdaa_locked(struct i3c_master_controller *master);
5353a379bbcSBoris Brezillon int i3c_master_defslvs_locked(struct i3c_master_controller *master);
5363a379bbcSBoris Brezillon 
5373a379bbcSBoris Brezillon int i3c_master_get_free_addr(struct i3c_master_controller *master,
5383a379bbcSBoris Brezillon 			     u8 start_addr);
5393a379bbcSBoris Brezillon 
5403a379bbcSBoris Brezillon int i3c_master_add_i3c_dev_locked(struct i3c_master_controller *master,
5413a379bbcSBoris Brezillon 				  u8 addr);
5423a379bbcSBoris Brezillon int i3c_master_do_daa(struct i3c_master_controller *master);
5433a379bbcSBoris Brezillon 
5443a379bbcSBoris Brezillon int i3c_master_set_info(struct i3c_master_controller *master,
5453a379bbcSBoris Brezillon 			const struct i3c_device_info *info);
5463a379bbcSBoris Brezillon 
5473a379bbcSBoris Brezillon int i3c_master_register(struct i3c_master_controller *master,
5483a379bbcSBoris Brezillon 			struct device *parent,
5493a379bbcSBoris Brezillon 			const struct i3c_master_controller_ops *ops,
5503a379bbcSBoris Brezillon 			bool secondary);
5510f74f8b6SUwe Kleine-König void i3c_master_unregister(struct i3c_master_controller *master);
5523a379bbcSBoris Brezillon 
5533a379bbcSBoris Brezillon /**
5543a379bbcSBoris Brezillon  * i3c_dev_get_master_data() - get master private data attached to an I3C
5553a379bbcSBoris Brezillon  *			       device descriptor
5563a379bbcSBoris Brezillon  * @dev: the I3C device descriptor to get private data from
5573a379bbcSBoris Brezillon  *
5583a379bbcSBoris Brezillon  * Return: the private data previously attached with i3c_dev_set_master_data()
5593a379bbcSBoris Brezillon  *	   or NULL if no data has been attached to the device.
5603a379bbcSBoris Brezillon  */
i3c_dev_get_master_data(const struct i3c_dev_desc * dev)5613a379bbcSBoris Brezillon static inline void *i3c_dev_get_master_data(const struct i3c_dev_desc *dev)
5623a379bbcSBoris Brezillon {
5633a379bbcSBoris Brezillon 	return dev->common.master_priv;
5643a379bbcSBoris Brezillon }
5653a379bbcSBoris Brezillon 
5663a379bbcSBoris Brezillon /**
5673a379bbcSBoris Brezillon  * i3c_dev_set_master_data() - attach master private data to an I3C device
5683a379bbcSBoris Brezillon  *			       descriptor
5693a379bbcSBoris Brezillon  * @dev: the I3C device descriptor to attach private data to
5703a379bbcSBoris Brezillon  * @data: private data
5713a379bbcSBoris Brezillon  *
5723a379bbcSBoris Brezillon  * This functions allows a master controller to attach per-device private data
5733a379bbcSBoris Brezillon  * which can then be retrieved with i3c_dev_get_master_data().
5743a379bbcSBoris Brezillon  */
i3c_dev_set_master_data(struct i3c_dev_desc * dev,void * data)5753a379bbcSBoris Brezillon static inline void i3c_dev_set_master_data(struct i3c_dev_desc *dev,
5763a379bbcSBoris Brezillon 					   void *data)
5773a379bbcSBoris Brezillon {
5783a379bbcSBoris Brezillon 	dev->common.master_priv = data;
5793a379bbcSBoris Brezillon }
5803a379bbcSBoris Brezillon 
5813a379bbcSBoris Brezillon /**
5823a379bbcSBoris Brezillon  * i2c_dev_get_master_data() - get master private data attached to an I2C
5833a379bbcSBoris Brezillon  *			       device descriptor
5843a379bbcSBoris Brezillon  * @dev: the I2C device descriptor to get private data from
5853a379bbcSBoris Brezillon  *
5863a379bbcSBoris Brezillon  * Return: the private data previously attached with i2c_dev_set_master_data()
5873a379bbcSBoris Brezillon  *	   or NULL if no data has been attached to the device.
5883a379bbcSBoris Brezillon  */
i2c_dev_get_master_data(const struct i2c_dev_desc * dev)5893a379bbcSBoris Brezillon static inline void *i2c_dev_get_master_data(const struct i2c_dev_desc *dev)
5903a379bbcSBoris Brezillon {
5913a379bbcSBoris Brezillon 	return dev->common.master_priv;
5923a379bbcSBoris Brezillon }
5933a379bbcSBoris Brezillon 
5943a379bbcSBoris Brezillon /**
5953a379bbcSBoris Brezillon  * i2c_dev_set_master_data() - attach master private data to an I2C device
5963a379bbcSBoris Brezillon  *			       descriptor
5973a379bbcSBoris Brezillon  * @dev: the I2C device descriptor to attach private data to
5983a379bbcSBoris Brezillon  * @data: private data
5993a379bbcSBoris Brezillon  *
6003a379bbcSBoris Brezillon  * This functions allows a master controller to attach per-device private data
6013a379bbcSBoris Brezillon  * which can then be retrieved with i2c_device_get_master_data().
6023a379bbcSBoris Brezillon  */
i2c_dev_set_master_data(struct i2c_dev_desc * dev,void * data)6033a379bbcSBoris Brezillon static inline void i2c_dev_set_master_data(struct i2c_dev_desc *dev,
6043a379bbcSBoris Brezillon 					   void *data)
6053a379bbcSBoris Brezillon {
6063a379bbcSBoris Brezillon 	dev->common.master_priv = data;
6073a379bbcSBoris Brezillon }
6083a379bbcSBoris Brezillon 
6093a379bbcSBoris Brezillon /**
6103a379bbcSBoris Brezillon  * i3c_dev_get_master() - get master used to communicate with a device
6113a379bbcSBoris Brezillon  * @dev: I3C dev
6123a379bbcSBoris Brezillon  *
6133a379bbcSBoris Brezillon  * Return: the master controller driving @dev
6143a379bbcSBoris Brezillon  */
6153a379bbcSBoris Brezillon static inline struct i3c_master_controller *
i3c_dev_get_master(struct i3c_dev_desc * dev)6163a379bbcSBoris Brezillon i3c_dev_get_master(struct i3c_dev_desc *dev)
6173a379bbcSBoris Brezillon {
6183a379bbcSBoris Brezillon 	return dev->common.master;
6193a379bbcSBoris Brezillon }
6203a379bbcSBoris Brezillon 
6213a379bbcSBoris Brezillon /**
6223a379bbcSBoris Brezillon  * i2c_dev_get_master() - get master used to communicate with a device
6233a379bbcSBoris Brezillon  * @dev: I2C dev
6243a379bbcSBoris Brezillon  *
6253a379bbcSBoris Brezillon  * Return: the master controller driving @dev
6263a379bbcSBoris Brezillon  */
6273a379bbcSBoris Brezillon static inline struct i3c_master_controller *
i2c_dev_get_master(struct i2c_dev_desc * dev)6283a379bbcSBoris Brezillon i2c_dev_get_master(struct i2c_dev_desc *dev)
6293a379bbcSBoris Brezillon {
6303a379bbcSBoris Brezillon 	return dev->common.master;
6313a379bbcSBoris Brezillon }
6323a379bbcSBoris Brezillon 
6333a379bbcSBoris Brezillon /**
6343a379bbcSBoris Brezillon  * i3c_master_get_bus() - get the bus attached to a master
6353a379bbcSBoris Brezillon  * @master: master object
6363a379bbcSBoris Brezillon  *
6373a379bbcSBoris Brezillon  * Return: the I3C bus @master is connected to
6383a379bbcSBoris Brezillon  */
6393a379bbcSBoris Brezillon static inline struct i3c_bus *
i3c_master_get_bus(struct i3c_master_controller * master)6403a379bbcSBoris Brezillon i3c_master_get_bus(struct i3c_master_controller *master)
6413a379bbcSBoris Brezillon {
6423a379bbcSBoris Brezillon 	return &master->bus;
6433a379bbcSBoris Brezillon }
6443a379bbcSBoris Brezillon 
6453a379bbcSBoris Brezillon struct i3c_generic_ibi_pool;
6463a379bbcSBoris Brezillon 
6473a379bbcSBoris Brezillon struct i3c_generic_ibi_pool *
6483a379bbcSBoris Brezillon i3c_generic_ibi_alloc_pool(struct i3c_dev_desc *dev,
6493a379bbcSBoris Brezillon 			   const struct i3c_ibi_setup *req);
6503a379bbcSBoris Brezillon void i3c_generic_ibi_free_pool(struct i3c_generic_ibi_pool *pool);
6513a379bbcSBoris Brezillon 
6523a379bbcSBoris Brezillon struct i3c_ibi_slot *
6533a379bbcSBoris Brezillon i3c_generic_ibi_get_free_slot(struct i3c_generic_ibi_pool *pool);
6543a379bbcSBoris Brezillon void i3c_generic_ibi_recycle_slot(struct i3c_generic_ibi_pool *pool,
6553a379bbcSBoris Brezillon 				  struct i3c_ibi_slot *slot);
6563a379bbcSBoris Brezillon 
6573a379bbcSBoris Brezillon void i3c_master_queue_ibi(struct i3c_dev_desc *dev, struct i3c_ibi_slot *slot);
6583a379bbcSBoris Brezillon 
6593a379bbcSBoris Brezillon struct i3c_ibi_slot *i3c_master_get_free_ibi_slot(struct i3c_dev_desc *dev);
6603a379bbcSBoris Brezillon 
6614edeb9faSJeremy Kerr void i3c_for_each_bus_locked(int (*fn)(struct i3c_bus *bus, void *data),
6624edeb9faSJeremy Kerr 			     void *data);
6634edeb9faSJeremy Kerr int i3c_register_notifier(struct notifier_block *nb);
6644edeb9faSJeremy Kerr int i3c_unregister_notifier(struct notifier_block *nb);
6654edeb9faSJeremy Kerr 
6663a379bbcSBoris Brezillon #endif /* I3C_MASTER_H */
667