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 <[email protected]>
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
270ac6486eSJeremy Kerr /* notifier actions. notifier call data is the struct i3c_bus */
280ac6486eSJeremy Kerr enum {
290ac6486eSJeremy Kerr I3C_NOTIFY_BUS_ADD,
300ac6486eSJeremy Kerr I3C_NOTIFY_BUS_REMOVE,
310ac6486eSJeremy Kerr };
320ac6486eSJeremy Kerr
333a379bbcSBoris Brezillon struct i3c_master_controller;
343a379bbcSBoris Brezillon struct i3c_bus;
353a379bbcSBoris Brezillon struct i3c_device;
3663c33ca0SBhoomik Gupta extern const struct bus_type i3c_bus_type;
373a379bbcSBoris Brezillon
383a379bbcSBoris Brezillon /**
393a379bbcSBoris Brezillon * struct i3c_i2c_dev_desc - Common part of the I3C/I2C device descriptor
403a379bbcSBoris Brezillon * @node: node element used to insert the slot into the I2C or I3C device
413a379bbcSBoris Brezillon * list
423a379bbcSBoris Brezillon * @master: I3C master that instantiated this device. Will be used to do
433a379bbcSBoris Brezillon * I2C/I3C transfers
443a379bbcSBoris Brezillon * @master_priv: master private data assigned to the device. Can be used to
453a379bbcSBoris Brezillon * add master specific information
463a379bbcSBoris Brezillon *
473a379bbcSBoris Brezillon * This structure is describing common I3C/I2C dev information.
483a379bbcSBoris Brezillon */
493a379bbcSBoris Brezillon struct i3c_i2c_dev_desc {
503a379bbcSBoris Brezillon struct list_head node;
513a379bbcSBoris Brezillon struct i3c_master_controller *master;
523a379bbcSBoris Brezillon void *master_priv;
533a379bbcSBoris Brezillon };
543a379bbcSBoris Brezillon
553a379bbcSBoris Brezillon #define I3C_LVR_I2C_INDEX_MASK GENMASK(7, 5)
563a379bbcSBoris Brezillon #define I3C_LVR_I2C_INDEX(x) ((x) << 5)
573a379bbcSBoris Brezillon #define I3C_LVR_I2C_FM_MODE BIT(4)
583a379bbcSBoris Brezillon
5988c50322SPrzemyslaw Gaj #define I2C_MAX_ADDR GENMASK(6, 0)
603a379bbcSBoris Brezillon
613a379bbcSBoris Brezillon /**
623a379bbcSBoris Brezillon * struct i2c_dev_boardinfo - I2C device board information
633a379bbcSBoris Brezillon * @node: used to insert the boardinfo object in the I2C boardinfo list
643a379bbcSBoris Brezillon * @base: regular I2C board information
653a379bbcSBoris Brezillon * @lvr: LVR (Legacy Virtual Register) needed by the I3C core to know about
663a379bbcSBoris Brezillon * the I2C device limitations
673a379bbcSBoris Brezillon *
683a379bbcSBoris Brezillon * This structure is used to attach board-level information to an I2C device.
693a379bbcSBoris Brezillon * Each I2C device connected on the I3C bus should have one.
703a379bbcSBoris Brezillon */
713a379bbcSBoris Brezillon struct i2c_dev_boardinfo {
723a379bbcSBoris Brezillon struct list_head node;
733a379bbcSBoris Brezillon struct i2c_board_info base;
743a379bbcSBoris Brezillon u8 lvr;
753a379bbcSBoris Brezillon };
763a379bbcSBoris Brezillon
773a379bbcSBoris Brezillon /**
783a379bbcSBoris Brezillon * struct i2c_dev_desc - I2C device descriptor
793a379bbcSBoris Brezillon * @common: common part of the I2C device descriptor
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
1389fd00df0SZbigniew Lukwinski * @wq: workqueue used to execute IBI handlers.
1393a379bbcSBoris Brezillon * @handler: IBI handler specified at i3c_device_request_ibi() call time. This
1403a379bbcSBoris Brezillon * handler will be called from the controller workqueue, and as such
1413a379bbcSBoris Brezillon * is allowed to sleep (though it is recommended to process the IBI
1423a379bbcSBoris Brezillon * as fast as possible to not stall processing of other IBIs queued
1433a379bbcSBoris Brezillon * on the same workqueue).
1443a379bbcSBoris Brezillon * New I3C messages can be sent from the IBI handler
1453a379bbcSBoris Brezillon *
1463a379bbcSBoris Brezillon * The &struct_i3c_device_ibi_info object is allocated when
1473a379bbcSBoris Brezillon * i3c_device_request_ibi() is called and attached to a specific device. This
1483a379bbcSBoris Brezillon * object is here to manage IBIs coming from a specific I3C device.
1493a379bbcSBoris Brezillon *
1503a379bbcSBoris Brezillon * Note that this structure is the generic view of the IBI management
1513a379bbcSBoris Brezillon * infrastructure. I3C master drivers may have their own internal
1523a379bbcSBoris Brezillon * representation which they can associate to the device using
1533a379bbcSBoris Brezillon * controller-private data.
1543a379bbcSBoris Brezillon */
1553a379bbcSBoris Brezillon struct i3c_device_ibi_info {
1563a379bbcSBoris Brezillon struct completion all_ibis_handled;
1573a379bbcSBoris Brezillon atomic_t pending_ibis;
1583a379bbcSBoris Brezillon unsigned int max_payload_len;
1593a379bbcSBoris Brezillon unsigned int num_slots;
1603a379bbcSBoris Brezillon unsigned int enabled;
1619fd00df0SZbigniew Lukwinski struct workqueue_struct *wq;
1623a379bbcSBoris Brezillon void (*handler)(struct i3c_device *dev,
1633a379bbcSBoris Brezillon const struct i3c_ibi_payload *payload);
1643a379bbcSBoris Brezillon };
1653a379bbcSBoris Brezillon
1663a379bbcSBoris Brezillon /**
1673a379bbcSBoris Brezillon * struct i3c_dev_boardinfo - I3C device board information
1683a379bbcSBoris Brezillon * @node: used to insert the boardinfo object in the I3C boardinfo list
1693a379bbcSBoris Brezillon * @init_dyn_addr: initial dynamic address requested by the FW. We provide no
1703a379bbcSBoris Brezillon * guarantee that the device will end up using this address,
1713a379bbcSBoris Brezillon * but try our best to assign this specific address to the
1723a379bbcSBoris Brezillon * device
1733a379bbcSBoris Brezillon * @static_addr: static address the I3C device listen on before it's been
1743a379bbcSBoris Brezillon * assigned a dynamic address by the master. Will be used during
1753a379bbcSBoris Brezillon * bus initialization to assign it a specific dynamic address
1763a379bbcSBoris Brezillon * before starting DAA (Dynamic Address Assignment)
17757ec42b9SMatt Johnston * @pid: I3C Provisioned ID exposed by the device. This is a unique identifier
1783a379bbcSBoris Brezillon * that may be used to attach boardinfo to i3c_dev_desc when the device
1793a379bbcSBoris Brezillon * does not have a static address
1803a379bbcSBoris Brezillon * @of_node: optional DT node in case the device has been described in the DT
1813a379bbcSBoris Brezillon *
1823a379bbcSBoris Brezillon * This structure is used to attach board-level information to an I3C device.
1833a379bbcSBoris Brezillon * Not all I3C devices connected on the bus will have a boardinfo. It's only
1843a379bbcSBoris Brezillon * needed if you want to attach extra resources to a device or assign it a
1853a379bbcSBoris Brezillon * specific dynamic address.
1863a379bbcSBoris Brezillon */
1873a379bbcSBoris Brezillon struct i3c_dev_boardinfo {
1883a379bbcSBoris Brezillon struct list_head node;
1893a379bbcSBoris Brezillon u8 init_dyn_addr;
1903a379bbcSBoris Brezillon u8 static_addr;
1913a379bbcSBoris Brezillon u64 pid;
1923a379bbcSBoris Brezillon struct device_node *of_node;
1933a379bbcSBoris Brezillon };
1943a379bbcSBoris Brezillon
1953a379bbcSBoris Brezillon /**
1963a379bbcSBoris Brezillon * struct i3c_dev_desc - I3C device descriptor
1973a379bbcSBoris Brezillon * @common: common part of the I3C device descriptor
1983a379bbcSBoris Brezillon * @info: I3C device information. Will be automatically filled when you create
1993a379bbcSBoris Brezillon * your device with i3c_master_add_i3c_dev_locked()
2003a379bbcSBoris Brezillon * @ibi_lock: lock used to protect the &struct_i3c_device->ibi
2013a379bbcSBoris Brezillon * @ibi: IBI info attached to a device. Should be NULL until
2023a379bbcSBoris Brezillon * i3c_device_request_ibi() is called
2033a379bbcSBoris Brezillon * @dev: pointer to the I3C device object exposed to I3C device drivers. This
2043a379bbcSBoris Brezillon * should never be accessed from I3C master controller drivers. Only core
2053a379bbcSBoris Brezillon * code should manipulate it in when updating the dev <-> desc link or
2063a379bbcSBoris Brezillon * when propagating IBI events to the driver
2073a379bbcSBoris Brezillon * @boardinfo: pointer to the boardinfo attached to this I3C device
2083a379bbcSBoris Brezillon *
2093a379bbcSBoris Brezillon * Internal representation of an I3C device. This object is only used by the
2103a379bbcSBoris Brezillon * core and passed to I3C master controller drivers when they're requested to
2113a379bbcSBoris Brezillon * do some operations on the device.
2123a379bbcSBoris Brezillon * The core maintains the link between the internal I3C dev descriptor and the
2133a379bbcSBoris Brezillon * object exposed to the I3C device drivers (&struct_i3c_device).
2143a379bbcSBoris Brezillon */
2153a379bbcSBoris Brezillon struct i3c_dev_desc {
2163a379bbcSBoris Brezillon struct i3c_i2c_dev_desc common;
2173a379bbcSBoris Brezillon struct i3c_device_info info;
2183a379bbcSBoris Brezillon struct mutex ibi_lock;
2193a379bbcSBoris Brezillon struct i3c_device_ibi_info *ibi;
2203a379bbcSBoris Brezillon struct i3c_device *dev;
2213a379bbcSBoris Brezillon const struct i3c_dev_boardinfo *boardinfo;
2223a379bbcSBoris Brezillon };
2233a379bbcSBoris Brezillon
2243a379bbcSBoris Brezillon /**
2253a379bbcSBoris Brezillon * struct i3c_device - I3C device object
2263a379bbcSBoris Brezillon * @dev: device object to register the I3C dev to the device model
2273a379bbcSBoris Brezillon * @desc: pointer to an i3c device descriptor object. This link is updated
2283a379bbcSBoris Brezillon * every time the I3C device is rediscovered with a different dynamic
2293a379bbcSBoris Brezillon * address assigned
2303a379bbcSBoris Brezillon * @bus: I3C bus this device is attached to
2313a379bbcSBoris Brezillon *
2323a379bbcSBoris Brezillon * I3C device object exposed to I3C device drivers. The takes care of linking
2333a379bbcSBoris Brezillon * this object to the relevant &struct_i3c_dev_desc one.
2343a379bbcSBoris Brezillon * All I3C devs on the I3C bus are represented, including I3C masters. For each
2353a379bbcSBoris Brezillon * of them, we have an instance of &struct i3c_device.
2363a379bbcSBoris Brezillon */
2373a379bbcSBoris Brezillon struct i3c_device {
2383a379bbcSBoris Brezillon struct device dev;
2393a379bbcSBoris Brezillon struct i3c_dev_desc *desc;
2403a379bbcSBoris Brezillon struct i3c_bus *bus;
2413a379bbcSBoris Brezillon };
2423a379bbcSBoris Brezillon
2433a379bbcSBoris Brezillon /*
2443a379bbcSBoris Brezillon * The I3C specification says the maximum number of devices connected on the
2453a379bbcSBoris Brezillon * bus is 11, but this number depends on external parameters like trace length,
2463a379bbcSBoris Brezillon * capacitive load per Device, and the types of Devices present on the Bus.
2473a379bbcSBoris Brezillon * I3C master can also have limitations, so this number is just here as a
2483a379bbcSBoris Brezillon * reference and should be adjusted on a per-controller/per-board basis.
2493a379bbcSBoris Brezillon */
2503a379bbcSBoris Brezillon #define I3C_BUS_MAX_DEVS 11
2513a379bbcSBoris Brezillon
2523a379bbcSBoris Brezillon #define I3C_BUS_MAX_I3C_SCL_RATE 12900000
2533a379bbcSBoris Brezillon #define I3C_BUS_TYP_I3C_SCL_RATE 12500000
2543a379bbcSBoris Brezillon #define I3C_BUS_I2C_FM_PLUS_SCL_RATE 1000000
2553a379bbcSBoris Brezillon #define I3C_BUS_I2C_FM_SCL_RATE 400000
2563a379bbcSBoris Brezillon #define I3C_BUS_TLOW_OD_MIN_NS 200
2573a379bbcSBoris Brezillon
2583a379bbcSBoris Brezillon /**
2593a379bbcSBoris Brezillon * enum i3c_bus_mode - I3C bus mode
2603a379bbcSBoris Brezillon * @I3C_BUS_MODE_PURE: only I3C devices are connected to the bus. No limitation
2613a379bbcSBoris Brezillon * expected
2623a379bbcSBoris Brezillon * @I3C_BUS_MODE_MIXED_FAST: I2C devices with 50ns spike filter are present on
2633a379bbcSBoris Brezillon * the bus. The only impact in this mode is that the
2643a379bbcSBoris Brezillon * high SCL pulse has to stay below 50ns to trick I2C
2653a379bbcSBoris Brezillon * devices when transmitting I3C frames
266cbf4f732SVitor Soares * @I3C_BUS_MODE_MIXED_LIMITED: I2C devices without 50ns spike filter are
267cbf4f732SVitor Soares * present on the bus. However they allow
268cbf4f732SVitor Soares * compliance up to the maximum SDR SCL clock
269cbf4f732SVitor Soares * frequency.
2703a379bbcSBoris Brezillon * @I3C_BUS_MODE_MIXED_SLOW: I2C devices without 50ns spike filter are present
2713a379bbcSBoris Brezillon * on the bus
2723a379bbcSBoris Brezillon */
2733a379bbcSBoris Brezillon enum i3c_bus_mode {
2743a379bbcSBoris Brezillon I3C_BUS_MODE_PURE,
2753a379bbcSBoris Brezillon I3C_BUS_MODE_MIXED_FAST,
276cbf4f732SVitor Soares I3C_BUS_MODE_MIXED_LIMITED,
2773a379bbcSBoris Brezillon I3C_BUS_MODE_MIXED_SLOW,
2783a379bbcSBoris Brezillon };
2793a379bbcSBoris Brezillon
2803a379bbcSBoris Brezillon /**
281aef79e18SCarlos Song * enum i3c_open_drain_speed - I3C open-drain speed
282aef79e18SCarlos Song * @I3C_OPEN_DRAIN_SLOW_SPEED: Slow open-drain speed for sending the first
283aef79e18SCarlos Song * broadcast address. The first broadcast address at this speed
284aef79e18SCarlos Song * will be visible to all devices on the I3C bus. I3C devices
285aef79e18SCarlos Song * working in I2C mode will turn off their spike filter when
286aef79e18SCarlos Song * switching into I3C mode.
287aef79e18SCarlos Song * @I3C_OPEN_DRAIN_NORMAL_SPEED: Normal open-drain speed in I3C bus mode.
288aef79e18SCarlos Song */
289aef79e18SCarlos Song enum i3c_open_drain_speed {
290aef79e18SCarlos Song I3C_OPEN_DRAIN_SLOW_SPEED,
291aef79e18SCarlos Song I3C_OPEN_DRAIN_NORMAL_SPEED,
292aef79e18SCarlos Song };
293aef79e18SCarlos Song
294aef79e18SCarlos Song /**
2953a379bbcSBoris Brezillon * enum i3c_addr_slot_status - I3C address slot status
2963a379bbcSBoris Brezillon * @I3C_ADDR_SLOT_FREE: address is free
2973a379bbcSBoris Brezillon * @I3C_ADDR_SLOT_RSVD: address is reserved
2983a379bbcSBoris Brezillon * @I3C_ADDR_SLOT_I2C_DEV: address is assigned to an I2C device
2993a379bbcSBoris Brezillon * @I3C_ADDR_SLOT_I3C_DEV: address is assigned to an I3C device
3003a379bbcSBoris Brezillon * @I3C_ADDR_SLOT_STATUS_MASK: address slot mask
301f6ca7306SAlexandre Belloni * @I3C_ADDR_SLOT_EXT_STATUS_MASK: address slot mask with extended information
3022f552fa2SFrank Li * @I3C_ADDR_SLOT_EXT_DESIRED: the bitmask represents addresses that are preferred by some devices,
3032f552fa2SFrank Li * such as the "assigned-address" property in a device tree source.
3043a379bbcSBoris Brezillon * On an I3C bus, addresses are assigned dynamically, and we need to know which
3053a379bbcSBoris Brezillon * addresses are free to use and which ones are already assigned.
3063a379bbcSBoris Brezillon *
3073a379bbcSBoris Brezillon * Addresses marked as reserved are those reserved by the I3C protocol
3083a379bbcSBoris Brezillon * (broadcast address, ...).
3093a379bbcSBoris Brezillon */
3103a379bbcSBoris Brezillon enum i3c_addr_slot_status {
3113a379bbcSBoris Brezillon I3C_ADDR_SLOT_FREE,
3123a379bbcSBoris Brezillon I3C_ADDR_SLOT_RSVD,
3133a379bbcSBoris Brezillon I3C_ADDR_SLOT_I2C_DEV,
3143a379bbcSBoris Brezillon I3C_ADDR_SLOT_I3C_DEV,
3153a379bbcSBoris Brezillon I3C_ADDR_SLOT_STATUS_MASK = 3,
3162f552fa2SFrank Li I3C_ADDR_SLOT_EXT_STATUS_MASK = 7,
3172f552fa2SFrank Li I3C_ADDR_SLOT_EXT_DESIRED = BIT(2),
3183a379bbcSBoris Brezillon };
3193a379bbcSBoris Brezillon
3202f552fa2SFrank Li #define I3C_ADDR_SLOT_STATUS_BITS 4
32116aed0a6SFrank Li
3223a379bbcSBoris Brezillon /**
3233a379bbcSBoris Brezillon * struct i3c_bus - I3C bus object
3243a379bbcSBoris Brezillon * @cur_master: I3C master currently driving the bus. Since I3C is multi-master
3253a379bbcSBoris Brezillon * this can change over the time. Will be used to let a master
3263a379bbcSBoris Brezillon * know whether it needs to request bus ownership before sending
3273a379bbcSBoris Brezillon * a frame or not
3283a379bbcSBoris Brezillon * @id: bus ID. Assigned by the framework when register the bus
3293a379bbcSBoris Brezillon * @addrslots: a bitmap with 2-bits per-slot to encode the address status and
3303a379bbcSBoris Brezillon * ease the DAA (Dynamic Address Assignment) procedure (see
3313a379bbcSBoris Brezillon * &enum i3c_addr_slot_status)
3323a379bbcSBoris Brezillon * @mode: bus mode (see &enum i3c_bus_mode)
3333a379bbcSBoris Brezillon * @scl_rate.i3c: maximum rate for the clock signal when doing I3C SDR/priv
3343a379bbcSBoris Brezillon * transfers
3353a379bbcSBoris Brezillon * @scl_rate.i2c: maximum rate for the clock signal when doing I2C transfers
3363a379bbcSBoris Brezillon * @scl_rate: SCL signal rate for I3C and I2C mode
3373a379bbcSBoris Brezillon * @devs.i3c: contains a list of I3C device descriptors representing I3C
3383a379bbcSBoris Brezillon * devices connected on the bus and successfully attached to the
3393a379bbcSBoris Brezillon * I3C master
3403a379bbcSBoris Brezillon * @devs.i2c: contains a list of I2C device descriptors representing I2C
3413a379bbcSBoris Brezillon * devices connected on the bus and successfully attached to the
3423a379bbcSBoris Brezillon * I3C master
3433a379bbcSBoris Brezillon * @devs: 2 lists containing all I3C/I2C devices connected to the bus
3443a379bbcSBoris Brezillon * @lock: read/write lock on the bus. This is needed to protect against
3453a379bbcSBoris Brezillon * operations that have an impact on the whole bus and the devices
3463a379bbcSBoris Brezillon * connected to it. For example, when asking slaves to drop their
3473a379bbcSBoris Brezillon * dynamic address (RSTDAA CCC), we need to make sure no one is trying
3483a379bbcSBoris Brezillon * to send I3C frames to these devices.
3493a379bbcSBoris Brezillon * Note that this lock does not protect against concurrency between
3503a379bbcSBoris Brezillon * devices: several drivers can send different I3C/I2C frames through
3513a379bbcSBoris Brezillon * the same master in parallel. This is the responsibility of the
3523a379bbcSBoris Brezillon * master to guarantee that frames are actually sent sequentially and
3533a379bbcSBoris Brezillon * not interlaced
3543a379bbcSBoris Brezillon *
3553a379bbcSBoris Brezillon * The I3C bus is represented with its own object and not implicitly described
3563a379bbcSBoris Brezillon * by the I3C master to cope with the multi-master functionality, where one bus
3573a379bbcSBoris Brezillon * can be shared amongst several masters, each of them requesting bus ownership
3583a379bbcSBoris Brezillon * when they need to.
3593a379bbcSBoris Brezillon */
3603a379bbcSBoris Brezillon struct i3c_bus {
3613a379bbcSBoris Brezillon struct i3c_dev_desc *cur_master;
3623a379bbcSBoris Brezillon int id;
36316aed0a6SFrank Li unsigned long addrslots[((I2C_MAX_ADDR + 1) * I3C_ADDR_SLOT_STATUS_BITS) / BITS_PER_LONG];
3643a379bbcSBoris Brezillon enum i3c_bus_mode mode;
3653a379bbcSBoris Brezillon struct {
3663a379bbcSBoris Brezillon unsigned long i3c;
3673a379bbcSBoris Brezillon unsigned long i2c;
3683a379bbcSBoris Brezillon } scl_rate;
3693a379bbcSBoris Brezillon struct {
3703a379bbcSBoris Brezillon struct list_head i3c;
3713a379bbcSBoris Brezillon struct list_head i2c;
3723a379bbcSBoris Brezillon } devs;
3733a379bbcSBoris Brezillon struct rw_semaphore lock;
3743a379bbcSBoris Brezillon };
3753a379bbcSBoris Brezillon
3763a379bbcSBoris Brezillon /**
3773a379bbcSBoris Brezillon * struct i3c_master_controller_ops - I3C master methods
3783a379bbcSBoris Brezillon * @bus_init: hook responsible for the I3C bus initialization. You should at
3793a379bbcSBoris Brezillon * least call master_set_info() from there and set the bus mode.
3803a379bbcSBoris Brezillon * You can also put controller specific initialization in there.
3813a379bbcSBoris Brezillon * This method is mandatory.
3823a379bbcSBoris Brezillon * @bus_cleanup: cleanup everything done in
3833a379bbcSBoris Brezillon * &i3c_master_controller_ops->bus_init().
3843a379bbcSBoris Brezillon * This method is optional.
3853a379bbcSBoris Brezillon * @attach_i3c_dev: called every time an I3C device is attached to the bus. It
3863a379bbcSBoris Brezillon * can be after a DAA or when a device is statically declared
3873a379bbcSBoris Brezillon * by the FW, in which case it will only have a static address
3883a379bbcSBoris Brezillon * and the dynamic address will be 0.
3893a379bbcSBoris Brezillon * When this function is called, device information have not
3903a379bbcSBoris Brezillon * been retrieved yet.
3913a379bbcSBoris Brezillon * This is a good place to attach master controller specific
3923a379bbcSBoris Brezillon * data to I3C devices.
3933a379bbcSBoris Brezillon * This method is optional.
3943a379bbcSBoris Brezillon * @reattach_i3c_dev: called every time an I3C device has its addressed
3953a379bbcSBoris Brezillon * changed. It can be because the device has been powered
3963a379bbcSBoris Brezillon * down and has lost its address, or it can happen when a
3973a379bbcSBoris Brezillon * device had a static address and has been assigned a
3983a379bbcSBoris Brezillon * dynamic address with SETDASA.
3993a379bbcSBoris Brezillon * This method is optional.
4003a379bbcSBoris Brezillon * @detach_i3c_dev: called when an I3C device is detached from the bus. Usually
4013a379bbcSBoris Brezillon * happens when the master device is unregistered.
4023a379bbcSBoris Brezillon * This method is optional.
4033a379bbcSBoris Brezillon * @do_daa: do a DAA (Dynamic Address Assignment) procedure. This is procedure
4043a379bbcSBoris Brezillon * should send an ENTDAA CCC command and then add all devices
4053a379bbcSBoris Brezillon * discovered sure the DAA using i3c_master_add_i3c_dev_locked().
4063a379bbcSBoris Brezillon * Add devices added with i3c_master_add_i3c_dev_locked() will then be
4073a379bbcSBoris Brezillon * attached or re-attached to the controller.
4083a379bbcSBoris Brezillon * This method is mandatory.
4093a379bbcSBoris Brezillon * @supports_ccc_cmd: should return true if the CCC command is supported, false
4103a379bbcSBoris Brezillon * otherwise.
4113a379bbcSBoris Brezillon * This method is optional, if not provided the core assumes
4123a379bbcSBoris Brezillon * all CCC commands are supported.
4133a379bbcSBoris Brezillon * @send_ccc_cmd: send a CCC command
4143a379bbcSBoris Brezillon * This method is mandatory.
4153a379bbcSBoris Brezillon * @priv_xfers: do one or several private I3C SDR transfers
4163a379bbcSBoris Brezillon * This method is mandatory.
4173a379bbcSBoris Brezillon * @attach_i2c_dev: called every time an I2C device is attached to the bus.
4183a379bbcSBoris Brezillon * This is a good place to attach master controller specific
4193a379bbcSBoris Brezillon * data to I2C devices.
4203a379bbcSBoris Brezillon * This method is optional.
4213a379bbcSBoris Brezillon * @detach_i2c_dev: called when an I2C device is detached from the bus. Usually
4223a379bbcSBoris Brezillon * happens when the master device is unregistered.
4233a379bbcSBoris Brezillon * This method is optional.
4243a379bbcSBoris Brezillon * @i2c_xfers: do one or several I2C transfers. Note that, unlike i3c
4253a379bbcSBoris Brezillon * transfers, the core does not guarantee that buffers attached to
4263a379bbcSBoris Brezillon * the transfers are DMA-safe. If drivers want to have DMA-safe
4273a379bbcSBoris Brezillon * buffers, they should use the i2c_get_dma_safe_msg_buf()
4283a379bbcSBoris Brezillon * and i2c_put_dma_safe_msg_buf() helpers provided by the I2C
4293a379bbcSBoris Brezillon * framework.
4303a379bbcSBoris Brezillon * This method is mandatory.
4313a379bbcSBoris Brezillon * @request_ibi: attach an IBI handler to an I3C device. This implies defining
4323a379bbcSBoris Brezillon * an IBI handler and the constraints of the IBI (maximum payload
4333a379bbcSBoris Brezillon * length and number of pre-allocated slots).
4343a379bbcSBoris Brezillon * Some controllers support less IBI-capable devices than regular
4353a379bbcSBoris Brezillon * devices, so this method might return -%EBUSY if there's no
4363a379bbcSBoris Brezillon * more space for an extra IBI registration
4373a379bbcSBoris Brezillon * This method is optional.
4383a379bbcSBoris Brezillon * @free_ibi: free an IBI previously requested with ->request_ibi(). The IBI
4393a379bbcSBoris Brezillon * should have been disabled with ->disable_irq() prior to that
4403a379bbcSBoris Brezillon * This method is mandatory only if ->request_ibi is not NULL.
4413a379bbcSBoris Brezillon * @enable_ibi: enable the IBI. Only valid if ->request_ibi() has been called
4423a379bbcSBoris Brezillon * prior to ->enable_ibi(). The controller should first enable
4433a379bbcSBoris Brezillon * the IBI on the controller end (for example, unmask the hardware
4443a379bbcSBoris Brezillon * IRQ) and then send the ENEC CCC command (with the IBI flag set)
4453a379bbcSBoris Brezillon * to the I3C device.
4463a379bbcSBoris Brezillon * This method is mandatory only if ->request_ibi is not NULL.
4473a379bbcSBoris Brezillon * @disable_ibi: disable an IBI. First send the DISEC CCC command with the IBI
4483a379bbcSBoris Brezillon * flag set and then deactivate the hardware IRQ on the
4493a379bbcSBoris Brezillon * controller end.
4503a379bbcSBoris Brezillon * This method is mandatory only if ->request_ibi is not NULL.
4513a379bbcSBoris Brezillon * @recycle_ibi_slot: recycle an IBI slot. Called every time an IBI has been
4523a379bbcSBoris Brezillon * processed by its handler. The IBI slot should be put back
4533a379bbcSBoris Brezillon * in the IBI slot pool so that the controller can re-use it
4543a379bbcSBoris Brezillon * for a future IBI
4553a379bbcSBoris Brezillon * This method is mandatory only if ->request_ibi is not
4563a379bbcSBoris Brezillon * NULL.
45734d946b7SFrank Li * @enable_hotjoin: enable hot join event detect.
45834d946b7SFrank Li * @disable_hotjoin: disable hot join event detect.
459aef79e18SCarlos Song * @set_speed: adjust I3C open drain mode timing.
4603a379bbcSBoris Brezillon */
4613a379bbcSBoris Brezillon struct i3c_master_controller_ops {
4623a379bbcSBoris Brezillon int (*bus_init)(struct i3c_master_controller *master);
4633a379bbcSBoris Brezillon void (*bus_cleanup)(struct i3c_master_controller *master);
4643a379bbcSBoris Brezillon int (*attach_i3c_dev)(struct i3c_dev_desc *dev);
4653a379bbcSBoris Brezillon int (*reattach_i3c_dev)(struct i3c_dev_desc *dev, u8 old_dyn_addr);
4663a379bbcSBoris Brezillon void (*detach_i3c_dev)(struct i3c_dev_desc *dev);
4673a379bbcSBoris Brezillon int (*do_daa)(struct i3c_master_controller *master);
4683a379bbcSBoris Brezillon bool (*supports_ccc_cmd)(struct i3c_master_controller *master,
4693a379bbcSBoris Brezillon const struct i3c_ccc_cmd *cmd);
4703a379bbcSBoris Brezillon int (*send_ccc_cmd)(struct i3c_master_controller *master,
4713a379bbcSBoris Brezillon struct i3c_ccc_cmd *cmd);
4723a379bbcSBoris Brezillon int (*priv_xfers)(struct i3c_dev_desc *dev,
4733a379bbcSBoris Brezillon struct i3c_priv_xfer *xfers,
4743a379bbcSBoris Brezillon int nxfers);
4753a379bbcSBoris Brezillon int (*attach_i2c_dev)(struct i2c_dev_desc *dev);
4763a379bbcSBoris Brezillon void (*detach_i2c_dev)(struct i2c_dev_desc *dev);
4773a379bbcSBoris Brezillon int (*i2c_xfers)(struct i2c_dev_desc *dev,
478*6866c91fSBilly Tsai struct i2c_msg *xfers, int nxfers);
4793a379bbcSBoris Brezillon int (*request_ibi)(struct i3c_dev_desc *dev,
4803a379bbcSBoris Brezillon const struct i3c_ibi_setup *req);
4813a379bbcSBoris Brezillon void (*free_ibi)(struct i3c_dev_desc *dev);
4823a379bbcSBoris Brezillon int (*enable_ibi)(struct i3c_dev_desc *dev);
4833a379bbcSBoris Brezillon int (*disable_ibi)(struct i3c_dev_desc *dev);
4843a379bbcSBoris Brezillon void (*recycle_ibi_slot)(struct i3c_dev_desc *dev,
4853a379bbcSBoris Brezillon struct i3c_ibi_slot *slot);
486317bacf9SFrank Li int (*enable_hotjoin)(struct i3c_master_controller *master);
487317bacf9SFrank Li int (*disable_hotjoin)(struct i3c_master_controller *master);
488aef79e18SCarlos Song int (*set_speed)(struct i3c_master_controller *master, enum i3c_open_drain_speed speed);
4893a379bbcSBoris Brezillon };
4903a379bbcSBoris Brezillon
4913a379bbcSBoris Brezillon /**
4923a379bbcSBoris Brezillon * struct i3c_master_controller - I3C master controller object
4933a379bbcSBoris Brezillon * @dev: device to be registered to the device-model
4943a379bbcSBoris Brezillon * @this: an I3C device object representing this master. This device will be
4953a379bbcSBoris Brezillon * added to the list of I3C devs available on the bus
4963a379bbcSBoris Brezillon * @i2c: I2C adapter used for backward compatibility. This adapter is
4973a379bbcSBoris Brezillon * registered to the I2C subsystem to be as transparent as possible to
4983a379bbcSBoris Brezillon * existing I2C drivers
4993a379bbcSBoris Brezillon * @ops: master operations. See &struct i3c_master_controller_ops
5003a379bbcSBoris Brezillon * @secondary: true if the master is a secondary master
5013a379bbcSBoris Brezillon * @init_done: true when the bus initialization is done
50234d946b7SFrank Li * @hotjoin: true if the master support hotjoin
5033a379bbcSBoris Brezillon * @boardinfo.i3c: list of I3C boardinfo objects
5043a379bbcSBoris Brezillon * @boardinfo.i2c: list of I2C boardinfo objects
5053a379bbcSBoris Brezillon * @boardinfo: board-level information attached to devices connected on the bus
5063a379bbcSBoris Brezillon * @bus: I3C bus exposed by this master
5079fd00df0SZbigniew Lukwinski * @wq: workqueue which can be used by master
5083a379bbcSBoris Brezillon * drivers if they need to postpone operations that need to take place
5093a379bbcSBoris Brezillon * in a thread context. Typical examples are Hot Join processing which
5103a379bbcSBoris Brezillon * requires taking the bus lock in maintenance, which in turn, can only
5113a379bbcSBoris Brezillon * be done from a sleep-able context
5123a379bbcSBoris Brezillon *
5133a379bbcSBoris Brezillon * A &struct i3c_master_controller has to be registered to the I3C subsystem
5143a379bbcSBoris Brezillon * through i3c_master_register(). None of &struct i3c_master_controller fields
5153a379bbcSBoris Brezillon * should be set manually, just pass appropriate values to
5163a379bbcSBoris Brezillon * i3c_master_register().
5173a379bbcSBoris Brezillon */
5183a379bbcSBoris Brezillon struct i3c_master_controller {
5193a379bbcSBoris Brezillon struct device dev;
5203a379bbcSBoris Brezillon struct i3c_dev_desc *this;
5213a379bbcSBoris Brezillon struct i2c_adapter i2c;
5223a379bbcSBoris Brezillon const struct i3c_master_controller_ops *ops;
5233a379bbcSBoris Brezillon unsigned int secondary : 1;
5243a379bbcSBoris Brezillon unsigned int init_done : 1;
525317bacf9SFrank Li unsigned int hotjoin: 1;
5263a379bbcSBoris Brezillon struct {
5273a379bbcSBoris Brezillon struct list_head i3c;
5283a379bbcSBoris Brezillon struct list_head i2c;
5293a379bbcSBoris Brezillon } boardinfo;
5303a379bbcSBoris Brezillon struct i3c_bus bus;
5313a379bbcSBoris Brezillon struct workqueue_struct *wq;
5323a379bbcSBoris Brezillon };
5333a379bbcSBoris Brezillon
5343a379bbcSBoris Brezillon /**
5353a379bbcSBoris Brezillon * i3c_bus_for_each_i2cdev() - iterate over all I2C devices present on the bus
5363a379bbcSBoris Brezillon * @bus: the I3C bus
5373a379bbcSBoris Brezillon * @dev: an I2C device descriptor pointer updated to point to the current slot
5383a379bbcSBoris Brezillon * at each iteration of the loop
5393a379bbcSBoris Brezillon *
5403a379bbcSBoris Brezillon * Iterate over all I2C devs present on the bus.
5413a379bbcSBoris Brezillon */
5423a379bbcSBoris Brezillon #define i3c_bus_for_each_i2cdev(bus, dev) \
5433a379bbcSBoris Brezillon list_for_each_entry(dev, &(bus)->devs.i2c, common.node)
5443a379bbcSBoris Brezillon
5453a379bbcSBoris Brezillon /**
5463a379bbcSBoris Brezillon * i3c_bus_for_each_i3cdev() - iterate over all I3C devices present on the bus
5473a379bbcSBoris Brezillon * @bus: the I3C bus
5483a379bbcSBoris Brezillon * @dev: and I3C device descriptor pointer updated to point to the current slot
5493a379bbcSBoris Brezillon * at each iteration of the loop
5503a379bbcSBoris Brezillon *
5513a379bbcSBoris Brezillon * Iterate over all I3C devs present on the bus.
5523a379bbcSBoris Brezillon */
5533a379bbcSBoris Brezillon #define i3c_bus_for_each_i3cdev(bus, dev) \
5543a379bbcSBoris Brezillon list_for_each_entry(dev, &(bus)->devs.i3c, common.node)
5553a379bbcSBoris Brezillon
5563a379bbcSBoris Brezillon int i3c_master_do_i2c_xfers(struct i3c_master_controller *master,
5573a379bbcSBoris Brezillon const struct i2c_msg *xfers,
5583a379bbcSBoris Brezillon int nxfers);
5593a379bbcSBoris Brezillon
5603a379bbcSBoris Brezillon int i3c_master_disec_locked(struct i3c_master_controller *master, u8 addr,
5613a379bbcSBoris Brezillon u8 evts);
5623a379bbcSBoris Brezillon int i3c_master_enec_locked(struct i3c_master_controller *master, u8 addr,
5633a379bbcSBoris Brezillon u8 evts);
5643a379bbcSBoris Brezillon int i3c_master_entdaa_locked(struct i3c_master_controller *master);
5653a379bbcSBoris Brezillon int i3c_master_defslvs_locked(struct i3c_master_controller *master);
5663a379bbcSBoris Brezillon
5673a379bbcSBoris Brezillon int i3c_master_get_free_addr(struct i3c_master_controller *master,
5683a379bbcSBoris Brezillon u8 start_addr);
5693a379bbcSBoris Brezillon
5703a379bbcSBoris Brezillon int i3c_master_add_i3c_dev_locked(struct i3c_master_controller *master,
5713a379bbcSBoris Brezillon u8 addr);
5723a379bbcSBoris Brezillon int i3c_master_do_daa(struct i3c_master_controller *master);
5733a379bbcSBoris Brezillon
5743a379bbcSBoris Brezillon int i3c_master_set_info(struct i3c_master_controller *master,
5753a379bbcSBoris Brezillon const struct i3c_device_info *info);
5763a379bbcSBoris Brezillon
5773a379bbcSBoris Brezillon int i3c_master_register(struct i3c_master_controller *master,
5783a379bbcSBoris Brezillon struct device *parent,
5793a379bbcSBoris Brezillon const struct i3c_master_controller_ops *ops,
5803a379bbcSBoris Brezillon bool secondary);
5810f74f8b6SUwe Kleine-König void i3c_master_unregister(struct i3c_master_controller *master);
582317bacf9SFrank Li int i3c_master_enable_hotjoin(struct i3c_master_controller *master);
583317bacf9SFrank Li int i3c_master_disable_hotjoin(struct i3c_master_controller *master);
5843a379bbcSBoris Brezillon
5853a379bbcSBoris Brezillon /**
5863a379bbcSBoris Brezillon * i3c_dev_get_master_data() - get master private data attached to an I3C
5873a379bbcSBoris Brezillon * device descriptor
5883a379bbcSBoris Brezillon * @dev: the I3C device descriptor to get private data from
5893a379bbcSBoris Brezillon *
5903a379bbcSBoris Brezillon * Return: the private data previously attached with i3c_dev_set_master_data()
5913a379bbcSBoris Brezillon * or NULL if no data has been attached to the device.
5923a379bbcSBoris Brezillon */
i3c_dev_get_master_data(const struct i3c_dev_desc * dev)5933a379bbcSBoris Brezillon static inline void *i3c_dev_get_master_data(const struct i3c_dev_desc *dev)
5943a379bbcSBoris Brezillon {
5953a379bbcSBoris Brezillon return dev->common.master_priv;
5963a379bbcSBoris Brezillon }
5973a379bbcSBoris Brezillon
5983a379bbcSBoris Brezillon /**
5993a379bbcSBoris Brezillon * i3c_dev_set_master_data() - attach master private data to an I3C device
6003a379bbcSBoris Brezillon * descriptor
6013a379bbcSBoris Brezillon * @dev: the I3C device descriptor to attach private data to
6023a379bbcSBoris Brezillon * @data: private data
6033a379bbcSBoris Brezillon *
6043a379bbcSBoris Brezillon * This functions allows a master controller to attach per-device private data
6053a379bbcSBoris Brezillon * which can then be retrieved with i3c_dev_get_master_data().
6063a379bbcSBoris Brezillon */
i3c_dev_set_master_data(struct i3c_dev_desc * dev,void * data)6073a379bbcSBoris Brezillon static inline void i3c_dev_set_master_data(struct i3c_dev_desc *dev,
6083a379bbcSBoris Brezillon void *data)
6093a379bbcSBoris Brezillon {
6103a379bbcSBoris Brezillon dev->common.master_priv = data;
6113a379bbcSBoris Brezillon }
6123a379bbcSBoris Brezillon
6133a379bbcSBoris Brezillon /**
6143a379bbcSBoris Brezillon * i2c_dev_get_master_data() - get master private data attached to an I2C
6153a379bbcSBoris Brezillon * device descriptor
6163a379bbcSBoris Brezillon * @dev: the I2C device descriptor to get private data from
6173a379bbcSBoris Brezillon *
6183a379bbcSBoris Brezillon * Return: the private data previously attached with i2c_dev_set_master_data()
6193a379bbcSBoris Brezillon * or NULL if no data has been attached to the device.
6203a379bbcSBoris Brezillon */
i2c_dev_get_master_data(const struct i2c_dev_desc * dev)6213a379bbcSBoris Brezillon static inline void *i2c_dev_get_master_data(const struct i2c_dev_desc *dev)
6223a379bbcSBoris Brezillon {
6233a379bbcSBoris Brezillon return dev->common.master_priv;
6243a379bbcSBoris Brezillon }
6253a379bbcSBoris Brezillon
6263a379bbcSBoris Brezillon /**
6273a379bbcSBoris Brezillon * i2c_dev_set_master_data() - attach master private data to an I2C device
6283a379bbcSBoris Brezillon * descriptor
6293a379bbcSBoris Brezillon * @dev: the I2C device descriptor to attach private data to
6303a379bbcSBoris Brezillon * @data: private data
6313a379bbcSBoris Brezillon *
6323a379bbcSBoris Brezillon * This functions allows a master controller to attach per-device private data
6333a379bbcSBoris Brezillon * which can then be retrieved with i2c_device_get_master_data().
6343a379bbcSBoris Brezillon */
i2c_dev_set_master_data(struct i2c_dev_desc * dev,void * data)6353a379bbcSBoris Brezillon static inline void i2c_dev_set_master_data(struct i2c_dev_desc *dev,
6363a379bbcSBoris Brezillon void *data)
6373a379bbcSBoris Brezillon {
6383a379bbcSBoris Brezillon dev->common.master_priv = data;
6393a379bbcSBoris Brezillon }
6403a379bbcSBoris Brezillon
6413a379bbcSBoris Brezillon /**
6423a379bbcSBoris Brezillon * i3c_dev_get_master() - get master used to communicate with a device
6433a379bbcSBoris Brezillon * @dev: I3C dev
6443a379bbcSBoris Brezillon *
6453a379bbcSBoris Brezillon * Return: the master controller driving @dev
6463a379bbcSBoris Brezillon */
6473a379bbcSBoris Brezillon static inline struct i3c_master_controller *
i3c_dev_get_master(struct i3c_dev_desc * dev)6483a379bbcSBoris Brezillon i3c_dev_get_master(struct i3c_dev_desc *dev)
6493a379bbcSBoris Brezillon {
6503a379bbcSBoris Brezillon return dev->common.master;
6513a379bbcSBoris Brezillon }
6523a379bbcSBoris Brezillon
6533a379bbcSBoris Brezillon /**
6543a379bbcSBoris Brezillon * i2c_dev_get_master() - get master used to communicate with a device
6553a379bbcSBoris Brezillon * @dev: I2C dev
6563a379bbcSBoris Brezillon *
6573a379bbcSBoris Brezillon * Return: the master controller driving @dev
6583a379bbcSBoris Brezillon */
6593a379bbcSBoris Brezillon static inline struct i3c_master_controller *
i2c_dev_get_master(struct i2c_dev_desc * dev)6603a379bbcSBoris Brezillon i2c_dev_get_master(struct i2c_dev_desc *dev)
6613a379bbcSBoris Brezillon {
6623a379bbcSBoris Brezillon return dev->common.master;
6633a379bbcSBoris Brezillon }
6643a379bbcSBoris Brezillon
6653a379bbcSBoris Brezillon /**
6663a379bbcSBoris Brezillon * i3c_master_get_bus() - get the bus attached to a master
6673a379bbcSBoris Brezillon * @master: master object
6683a379bbcSBoris Brezillon *
6693a379bbcSBoris Brezillon * Return: the I3C bus @master is connected to
6703a379bbcSBoris Brezillon */
6713a379bbcSBoris Brezillon static inline struct i3c_bus *
i3c_master_get_bus(struct i3c_master_controller * master)6723a379bbcSBoris Brezillon i3c_master_get_bus(struct i3c_master_controller *master)
6733a379bbcSBoris Brezillon {
6743a379bbcSBoris Brezillon return &master->bus;
6753a379bbcSBoris Brezillon }
6763a379bbcSBoris Brezillon
6773a379bbcSBoris Brezillon struct i3c_generic_ibi_pool;
6783a379bbcSBoris Brezillon
6793a379bbcSBoris Brezillon struct i3c_generic_ibi_pool *
6803a379bbcSBoris Brezillon i3c_generic_ibi_alloc_pool(struct i3c_dev_desc *dev,
6813a379bbcSBoris Brezillon const struct i3c_ibi_setup *req);
6823a379bbcSBoris Brezillon void i3c_generic_ibi_free_pool(struct i3c_generic_ibi_pool *pool);
6833a379bbcSBoris Brezillon
6843a379bbcSBoris Brezillon struct i3c_ibi_slot *
6853a379bbcSBoris Brezillon i3c_generic_ibi_get_free_slot(struct i3c_generic_ibi_pool *pool);
6863a379bbcSBoris Brezillon void i3c_generic_ibi_recycle_slot(struct i3c_generic_ibi_pool *pool,
6873a379bbcSBoris Brezillon struct i3c_ibi_slot *slot);
6883a379bbcSBoris Brezillon
6893a379bbcSBoris Brezillon void i3c_master_queue_ibi(struct i3c_dev_desc *dev, struct i3c_ibi_slot *slot);
6903a379bbcSBoris Brezillon
6913a379bbcSBoris Brezillon struct i3c_ibi_slot *i3c_master_get_free_ibi_slot(struct i3c_dev_desc *dev);
6923a379bbcSBoris Brezillon
6930ac6486eSJeremy Kerr void i3c_for_each_bus_locked(int (*fn)(struct i3c_bus *bus, void *data),
6940ac6486eSJeremy Kerr void *data);
6950ac6486eSJeremy Kerr int i3c_register_notifier(struct notifier_block *nb);
6960ac6486eSJeremy Kerr int i3c_unregister_notifier(struct notifier_block *nb);
6970ac6486eSJeremy Kerr
6983a379bbcSBoris Brezillon #endif /* I3C_MASTER_H */
699