Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Copyright (C) 2018 Cadence Design Systems Inc.
0004  *
0005  * Author: Boris Brezillon <boris.brezillon@bootlin.com>
0006  */
0007 
0008 #ifndef I3C_MASTER_H
0009 #define I3C_MASTER_H
0010 
0011 #include <asm/bitsperlong.h>
0012 
0013 #include <linux/bitops.h>
0014 #include <linux/i2c.h>
0015 #include <linux/i3c/ccc.h>
0016 #include <linux/i3c/device.h>
0017 #include <linux/rwsem.h>
0018 #include <linux/spinlock.h>
0019 #include <linux/workqueue.h>
0020 
0021 #define I3C_HOT_JOIN_ADDR       0x2
0022 #define I3C_BROADCAST_ADDR      0x7e
0023 #define I3C_MAX_ADDR            GENMASK(6, 0)
0024 
0025 struct i3c_master_controller;
0026 struct i3c_bus;
0027 struct i2c_device;
0028 struct i3c_device;
0029 
0030 /**
0031  * struct i3c_i2c_dev_desc - Common part of the I3C/I2C device descriptor
0032  * @node: node element used to insert the slot into the I2C or I3C device
0033  *    list
0034  * @master: I3C master that instantiated this device. Will be used to do
0035  *      I2C/I3C transfers
0036  * @master_priv: master private data assigned to the device. Can be used to
0037  *       add master specific information
0038  *
0039  * This structure is describing common I3C/I2C dev information.
0040  */
0041 struct i3c_i2c_dev_desc {
0042     struct list_head node;
0043     struct i3c_master_controller *master;
0044     void *master_priv;
0045 };
0046 
0047 #define I3C_LVR_I2C_INDEX_MASK      GENMASK(7, 5)
0048 #define I3C_LVR_I2C_INDEX(x)        ((x) << 5)
0049 #define I3C_LVR_I2C_FM_MODE     BIT(4)
0050 
0051 #define I2C_MAX_ADDR            GENMASK(6, 0)
0052 
0053 /**
0054  * struct i2c_dev_boardinfo - I2C device board information
0055  * @node: used to insert the boardinfo object in the I2C boardinfo list
0056  * @base: regular I2C board information
0057  * @lvr: LVR (Legacy Virtual Register) needed by the I3C core to know about
0058  *   the I2C device limitations
0059  *
0060  * This structure is used to attach board-level information to an I2C device.
0061  * Each I2C device connected on the I3C bus should have one.
0062  */
0063 struct i2c_dev_boardinfo {
0064     struct list_head node;
0065     struct i2c_board_info base;
0066     u8 lvr;
0067 };
0068 
0069 /**
0070  * struct i2c_dev_desc - I2C device descriptor
0071  * @common: common part of the I2C device descriptor
0072  * @boardinfo: pointer to the boardinfo attached to this I2C device
0073  * @dev: I2C device object registered to the I2C framework
0074  * @addr: I2C device address
0075  * @lvr: LVR (Legacy Virtual Register) needed by the I3C core to know about
0076  *   the I2C device limitations
0077  *
0078  * Each I2C device connected on the bus will have an i2c_dev_desc.
0079  * This object is created by the core and later attached to the controller
0080  * using &struct_i3c_master_controller->ops->attach_i2c_dev().
0081  *
0082  * &struct_i2c_dev_desc is the internal representation of an I2C device
0083  * connected on an I3C bus. This object is also passed to all
0084  * &struct_i3c_master_controller_ops hooks.
0085  */
0086 struct i2c_dev_desc {
0087     struct i3c_i2c_dev_desc common;
0088     struct i2c_client *dev;
0089     u16 addr;
0090     u8 lvr;
0091 };
0092 
0093 /**
0094  * struct i3c_ibi_slot - I3C IBI (In-Band Interrupt) slot
0095  * @work: work associated to this slot. The IBI handler will be called from
0096  *    there
0097  * @dev: the I3C device that has generated this IBI
0098  * @len: length of the payload associated to this IBI
0099  * @data: payload buffer
0100  *
0101  * An IBI slot is an object pre-allocated by the controller and used when an
0102  * IBI comes in.
0103  * Every time an IBI comes in, the I3C master driver should find a free IBI
0104  * slot in its IBI slot pool, retrieve the IBI payload and queue the IBI using
0105  * i3c_master_queue_ibi().
0106  *
0107  * How IBI slots are allocated is left to the I3C master driver, though, for
0108  * simple kmalloc-based allocation, the generic IBI slot pool can be used.
0109  */
0110 struct i3c_ibi_slot {
0111     struct work_struct work;
0112     struct i3c_dev_desc *dev;
0113     unsigned int len;
0114     void *data;
0115 };
0116 
0117 /**
0118  * struct i3c_device_ibi_info - IBI information attached to a specific device
0119  * @all_ibis_handled: used to be informed when no more IBIs are waiting to be
0120  *            processed. Used by i3c_device_disable_ibi() to wait for
0121  *            all IBIs to be dequeued
0122  * @pending_ibis: count the number of pending IBIs. Each pending IBI has its
0123  *        work element queued to the controller workqueue
0124  * @max_payload_len: maximum payload length for an IBI coming from this device.
0125  *           this value is specified when calling
0126  *           i3c_device_request_ibi() and should not change at run
0127  *           time. All messages IBIs exceeding this limit should be
0128  *           rejected by the master
0129  * @num_slots: number of IBI slots reserved for this device
0130  * @enabled: reflect the IBI status
0131  * @handler: IBI handler specified at i3c_device_request_ibi() call time. This
0132  *       handler will be called from the controller workqueue, and as such
0133  *       is allowed to sleep (though it is recommended to process the IBI
0134  *       as fast as possible to not stall processing of other IBIs queued
0135  *       on the same workqueue).
0136  *       New I3C messages can be sent from the IBI handler
0137  *
0138  * The &struct_i3c_device_ibi_info object is allocated when
0139  * i3c_device_request_ibi() is called and attached to a specific device. This
0140  * object is here to manage IBIs coming from a specific I3C device.
0141  *
0142  * Note that this structure is the generic view of the IBI management
0143  * infrastructure. I3C master drivers may have their own internal
0144  * representation which they can associate to the device using
0145  * controller-private data.
0146  */
0147 struct i3c_device_ibi_info {
0148     struct completion all_ibis_handled;
0149     atomic_t pending_ibis;
0150     unsigned int max_payload_len;
0151     unsigned int num_slots;
0152     unsigned int enabled;
0153     void (*handler)(struct i3c_device *dev,
0154             const struct i3c_ibi_payload *payload);
0155 };
0156 
0157 /**
0158  * struct i3c_dev_boardinfo - I3C device board information
0159  * @node: used to insert the boardinfo object in the I3C boardinfo list
0160  * @init_dyn_addr: initial dynamic address requested by the FW. We provide no
0161  *         guarantee that the device will end up using this address,
0162  *         but try our best to assign this specific address to the
0163  *         device
0164  * @static_addr: static address the I3C device listen on before it's been
0165  *       assigned a dynamic address by the master. Will be used during
0166  *       bus initialization to assign it a specific dynamic address
0167  *       before starting DAA (Dynamic Address Assignment)
0168  * @pid: I3C Provisional ID exposed by the device. This is a unique identifier
0169  *   that may be used to attach boardinfo to i3c_dev_desc when the device
0170  *   does not have a static address
0171  * @of_node: optional DT node in case the device has been described in the DT
0172  *
0173  * This structure is used to attach board-level information to an I3C device.
0174  * Not all I3C devices connected on the bus will have a boardinfo. It's only
0175  * needed if you want to attach extra resources to a device or assign it a
0176  * specific dynamic address.
0177  */
0178 struct i3c_dev_boardinfo {
0179     struct list_head node;
0180     u8 init_dyn_addr;
0181     u8 static_addr;
0182     u64 pid;
0183     struct device_node *of_node;
0184 };
0185 
0186 /**
0187  * struct i3c_dev_desc - I3C device descriptor
0188  * @common: common part of the I3C device descriptor
0189  * @info: I3C device information. Will be automatically filled when you create
0190  *    your device with i3c_master_add_i3c_dev_locked()
0191  * @ibi_lock: lock used to protect the &struct_i3c_device->ibi
0192  * @ibi: IBI info attached to a device. Should be NULL until
0193  *   i3c_device_request_ibi() is called
0194  * @dev: pointer to the I3C device object exposed to I3C device drivers. This
0195  *   should never be accessed from I3C master controller drivers. Only core
0196  *   code should manipulate it in when updating the dev <-> desc link or
0197  *   when propagating IBI events to the driver
0198  * @boardinfo: pointer to the boardinfo attached to this I3C device
0199  *
0200  * Internal representation of an I3C device. This object is only used by the
0201  * core and passed to I3C master controller drivers when they're requested to
0202  * do some operations on the device.
0203  * The core maintains the link between the internal I3C dev descriptor and the
0204  * object exposed to the I3C device drivers (&struct_i3c_device).
0205  */
0206 struct i3c_dev_desc {
0207     struct i3c_i2c_dev_desc common;
0208     struct i3c_device_info info;
0209     struct mutex ibi_lock;
0210     struct i3c_device_ibi_info *ibi;
0211     struct i3c_device *dev;
0212     const struct i3c_dev_boardinfo *boardinfo;
0213 };
0214 
0215 /**
0216  * struct i3c_device - I3C device object
0217  * @dev: device object to register the I3C dev to the device model
0218  * @desc: pointer to an i3c device descriptor object. This link is updated
0219  *    every time the I3C device is rediscovered with a different dynamic
0220  *    address assigned
0221  * @bus: I3C bus this device is attached to
0222  *
0223  * I3C device object exposed to I3C device drivers. The takes care of linking
0224  * this object to the relevant &struct_i3c_dev_desc one.
0225  * All I3C devs on the I3C bus are represented, including I3C masters. For each
0226  * of them, we have an instance of &struct i3c_device.
0227  */
0228 struct i3c_device {
0229     struct device dev;
0230     struct i3c_dev_desc *desc;
0231     struct i3c_bus *bus;
0232 };
0233 
0234 /*
0235  * The I3C specification says the maximum number of devices connected on the
0236  * bus is 11, but this number depends on external parameters like trace length,
0237  * capacitive load per Device, and the types of Devices present on the Bus.
0238  * I3C master can also have limitations, so this number is just here as a
0239  * reference and should be adjusted on a per-controller/per-board basis.
0240  */
0241 #define I3C_BUS_MAX_DEVS        11
0242 
0243 #define I3C_BUS_MAX_I3C_SCL_RATE    12900000
0244 #define I3C_BUS_TYP_I3C_SCL_RATE    12500000
0245 #define I3C_BUS_I2C_FM_PLUS_SCL_RATE    1000000
0246 #define I3C_BUS_I2C_FM_SCL_RATE     400000
0247 #define I3C_BUS_TLOW_OD_MIN_NS      200
0248 
0249 /**
0250  * enum i3c_bus_mode - I3C bus mode
0251  * @I3C_BUS_MODE_PURE: only I3C devices are connected to the bus. No limitation
0252  *             expected
0253  * @I3C_BUS_MODE_MIXED_FAST: I2C devices with 50ns spike filter are present on
0254  *               the bus. The only impact in this mode is that the
0255  *               high SCL pulse has to stay below 50ns to trick I2C
0256  *               devices when transmitting I3C frames
0257  * @I3C_BUS_MODE_MIXED_LIMITED: I2C devices without 50ns spike filter are
0258  *              present on the bus. However they allow
0259  *              compliance up to the maximum SDR SCL clock
0260  *              frequency.
0261  * @I3C_BUS_MODE_MIXED_SLOW: I2C devices without 50ns spike filter are present
0262  *               on the bus
0263  */
0264 enum i3c_bus_mode {
0265     I3C_BUS_MODE_PURE,
0266     I3C_BUS_MODE_MIXED_FAST,
0267     I3C_BUS_MODE_MIXED_LIMITED,
0268     I3C_BUS_MODE_MIXED_SLOW,
0269 };
0270 
0271 /**
0272  * enum i3c_addr_slot_status - I3C address slot status
0273  * @I3C_ADDR_SLOT_FREE: address is free
0274  * @I3C_ADDR_SLOT_RSVD: address is reserved
0275  * @I3C_ADDR_SLOT_I2C_DEV: address is assigned to an I2C device
0276  * @I3C_ADDR_SLOT_I3C_DEV: address is assigned to an I3C device
0277  * @I3C_ADDR_SLOT_STATUS_MASK: address slot mask
0278  *
0279  * On an I3C bus, addresses are assigned dynamically, and we need to know which
0280  * addresses are free to use and which ones are already assigned.
0281  *
0282  * Addresses marked as reserved are those reserved by the I3C protocol
0283  * (broadcast address, ...).
0284  */
0285 enum i3c_addr_slot_status {
0286     I3C_ADDR_SLOT_FREE,
0287     I3C_ADDR_SLOT_RSVD,
0288     I3C_ADDR_SLOT_I2C_DEV,
0289     I3C_ADDR_SLOT_I3C_DEV,
0290     I3C_ADDR_SLOT_STATUS_MASK = 3,
0291 };
0292 
0293 /**
0294  * struct i3c_bus - I3C bus object
0295  * @cur_master: I3C master currently driving the bus. Since I3C is multi-master
0296  *      this can change over the time. Will be used to let a master
0297  *      know whether it needs to request bus ownership before sending
0298  *      a frame or not
0299  * @id: bus ID. Assigned by the framework when register the bus
0300  * @addrslots: a bitmap with 2-bits per-slot to encode the address status and
0301  *         ease the DAA (Dynamic Address Assignment) procedure (see
0302  *         &enum i3c_addr_slot_status)
0303  * @mode: bus mode (see &enum i3c_bus_mode)
0304  * @scl_rate.i3c: maximum rate for the clock signal when doing I3C SDR/priv
0305  *        transfers
0306  * @scl_rate.i2c: maximum rate for the clock signal when doing I2C transfers
0307  * @scl_rate: SCL signal rate for I3C and I2C mode
0308  * @devs.i3c: contains a list of I3C device descriptors representing I3C
0309  *        devices connected on the bus and successfully attached to the
0310  *        I3C master
0311  * @devs.i2c: contains a list of I2C device descriptors representing I2C
0312  *        devices connected on the bus and successfully attached to the
0313  *        I3C master
0314  * @devs: 2 lists containing all I3C/I2C devices connected to the bus
0315  * @lock: read/write lock on the bus. This is needed to protect against
0316  *    operations that have an impact on the whole bus and the devices
0317  *    connected to it. For example, when asking slaves to drop their
0318  *    dynamic address (RSTDAA CCC), we need to make sure no one is trying
0319  *    to send I3C frames to these devices.
0320  *    Note that this lock does not protect against concurrency between
0321  *    devices: several drivers can send different I3C/I2C frames through
0322  *    the same master in parallel. This is the responsibility of the
0323  *    master to guarantee that frames are actually sent sequentially and
0324  *    not interlaced
0325  *
0326  * The I3C bus is represented with its own object and not implicitly described
0327  * by the I3C master to cope with the multi-master functionality, where one bus
0328  * can be shared amongst several masters, each of them requesting bus ownership
0329  * when they need to.
0330  */
0331 struct i3c_bus {
0332     struct i3c_dev_desc *cur_master;
0333     int id;
0334     unsigned long addrslots[((I2C_MAX_ADDR + 1) * 2) / BITS_PER_LONG];
0335     enum i3c_bus_mode mode;
0336     struct {
0337         unsigned long i3c;
0338         unsigned long i2c;
0339     } scl_rate;
0340     struct {
0341         struct list_head i3c;
0342         struct list_head i2c;
0343     } devs;
0344     struct rw_semaphore lock;
0345 };
0346 
0347 /**
0348  * struct i3c_master_controller_ops - I3C master methods
0349  * @bus_init: hook responsible for the I3C bus initialization. You should at
0350  *        least call master_set_info() from there and set the bus mode.
0351  *        You can also put controller specific initialization in there.
0352  *        This method is mandatory.
0353  * @bus_cleanup: cleanup everything done in
0354  *       &i3c_master_controller_ops->bus_init().
0355  *       This method is optional.
0356  * @attach_i3c_dev: called every time an I3C device is attached to the bus. It
0357  *          can be after a DAA or when a device is statically declared
0358  *          by the FW, in which case it will only have a static address
0359  *          and the dynamic address will be 0.
0360  *          When this function is called, device information have not
0361  *          been retrieved yet.
0362  *          This is a good place to attach master controller specific
0363  *          data to I3C devices.
0364  *          This method is optional.
0365  * @reattach_i3c_dev: called every time an I3C device has its addressed
0366  *            changed. It can be because the device has been powered
0367  *            down and has lost its address, or it can happen when a
0368  *            device had a static address and has been assigned a
0369  *            dynamic address with SETDASA.
0370  *            This method is optional.
0371  * @detach_i3c_dev: called when an I3C device is detached from the bus. Usually
0372  *          happens when the master device is unregistered.
0373  *          This method is optional.
0374  * @do_daa: do a DAA (Dynamic Address Assignment) procedure. This is procedure
0375  *      should send an ENTDAA CCC command and then add all devices
0376  *      discovered sure the DAA using i3c_master_add_i3c_dev_locked().
0377  *      Add devices added with i3c_master_add_i3c_dev_locked() will then be
0378  *      attached or re-attached to the controller.
0379  *      This method is mandatory.
0380  * @supports_ccc_cmd: should return true if the CCC command is supported, false
0381  *            otherwise.
0382  *            This method is optional, if not provided the core assumes
0383  *            all CCC commands are supported.
0384  * @send_ccc_cmd: send a CCC command
0385  *        This method is mandatory.
0386  * @priv_xfers: do one or several private I3C SDR transfers
0387  *      This method is mandatory.
0388  * @attach_i2c_dev: called every time an I2C device is attached to the bus.
0389  *          This is a good place to attach master controller specific
0390  *          data to I2C devices.
0391  *          This method is optional.
0392  * @detach_i2c_dev: called when an I2C device is detached from the bus. Usually
0393  *          happens when the master device is unregistered.
0394  *          This method is optional.
0395  * @i2c_xfers: do one or several I2C transfers. Note that, unlike i3c
0396  *         transfers, the core does not guarantee that buffers attached to
0397  *         the transfers are DMA-safe. If drivers want to have DMA-safe
0398  *         buffers, they should use the i2c_get_dma_safe_msg_buf()
0399  *         and i2c_put_dma_safe_msg_buf() helpers provided by the I2C
0400  *         framework.
0401  *         This method is mandatory.
0402  * @request_ibi: attach an IBI handler to an I3C device. This implies defining
0403  *       an IBI handler and the constraints of the IBI (maximum payload
0404  *       length and number of pre-allocated slots).
0405  *       Some controllers support less IBI-capable devices than regular
0406  *       devices, so this method might return -%EBUSY if there's no
0407  *       more space for an extra IBI registration
0408  *       This method is optional.
0409  * @free_ibi: free an IBI previously requested with ->request_ibi(). The IBI
0410  *        should have been disabled with ->disable_irq() prior to that
0411  *        This method is mandatory only if ->request_ibi is not NULL.
0412  * @enable_ibi: enable the IBI. Only valid if ->request_ibi() has been called
0413  *      prior to ->enable_ibi(). The controller should first enable
0414  *      the IBI on the controller end (for example, unmask the hardware
0415  *      IRQ) and then send the ENEC CCC command (with the IBI flag set)
0416  *      to the I3C device.
0417  *      This method is mandatory only if ->request_ibi is not NULL.
0418  * @disable_ibi: disable an IBI. First send the DISEC CCC command with the IBI
0419  *       flag set and then deactivate the hardware IRQ on the
0420  *       controller end.
0421  *       This method is mandatory only if ->request_ibi is not NULL.
0422  * @recycle_ibi_slot: recycle an IBI slot. Called every time an IBI has been
0423  *            processed by its handler. The IBI slot should be put back
0424  *            in the IBI slot pool so that the controller can re-use it
0425  *            for a future IBI
0426  *            This method is mandatory only if ->request_ibi is not
0427  *            NULL.
0428  */
0429 struct i3c_master_controller_ops {
0430     int (*bus_init)(struct i3c_master_controller *master);
0431     void (*bus_cleanup)(struct i3c_master_controller *master);
0432     int (*attach_i3c_dev)(struct i3c_dev_desc *dev);
0433     int (*reattach_i3c_dev)(struct i3c_dev_desc *dev, u8 old_dyn_addr);
0434     void (*detach_i3c_dev)(struct i3c_dev_desc *dev);
0435     int (*do_daa)(struct i3c_master_controller *master);
0436     bool (*supports_ccc_cmd)(struct i3c_master_controller *master,
0437                  const struct i3c_ccc_cmd *cmd);
0438     int (*send_ccc_cmd)(struct i3c_master_controller *master,
0439                 struct i3c_ccc_cmd *cmd);
0440     int (*priv_xfers)(struct i3c_dev_desc *dev,
0441               struct i3c_priv_xfer *xfers,
0442               int nxfers);
0443     int (*attach_i2c_dev)(struct i2c_dev_desc *dev);
0444     void (*detach_i2c_dev)(struct i2c_dev_desc *dev);
0445     int (*i2c_xfers)(struct i2c_dev_desc *dev,
0446              const struct i2c_msg *xfers, int nxfers);
0447     int (*request_ibi)(struct i3c_dev_desc *dev,
0448                const struct i3c_ibi_setup *req);
0449     void (*free_ibi)(struct i3c_dev_desc *dev);
0450     int (*enable_ibi)(struct i3c_dev_desc *dev);
0451     int (*disable_ibi)(struct i3c_dev_desc *dev);
0452     void (*recycle_ibi_slot)(struct i3c_dev_desc *dev,
0453                  struct i3c_ibi_slot *slot);
0454 };
0455 
0456 /**
0457  * struct i3c_master_controller - I3C master controller object
0458  * @dev: device to be registered to the device-model
0459  * @this: an I3C device object representing this master. This device will be
0460  *    added to the list of I3C devs available on the bus
0461  * @i2c: I2C adapter used for backward compatibility. This adapter is
0462  *   registered to the I2C subsystem to be as transparent as possible to
0463  *   existing I2C drivers
0464  * @ops: master operations. See &struct i3c_master_controller_ops
0465  * @secondary: true if the master is a secondary master
0466  * @init_done: true when the bus initialization is done
0467  * @boardinfo.i3c: list of I3C  boardinfo objects
0468  * @boardinfo.i2c: list of I2C boardinfo objects
0469  * @boardinfo: board-level information attached to devices connected on the bus
0470  * @bus: I3C bus exposed by this master
0471  * @wq: workqueue used to execute IBI handlers. Can also be used by master
0472  *  drivers if they need to postpone operations that need to take place
0473  *  in a thread context. Typical examples are Hot Join processing which
0474  *  requires taking the bus lock in maintenance, which in turn, can only
0475  *  be done from a sleep-able context
0476  *
0477  * A &struct i3c_master_controller has to be registered to the I3C subsystem
0478  * through i3c_master_register(). None of &struct i3c_master_controller fields
0479  * should be set manually, just pass appropriate values to
0480  * i3c_master_register().
0481  */
0482 struct i3c_master_controller {
0483     struct device dev;
0484     struct i3c_dev_desc *this;
0485     struct i2c_adapter i2c;
0486     const struct i3c_master_controller_ops *ops;
0487     unsigned int secondary : 1;
0488     unsigned int init_done : 1;
0489     struct {
0490         struct list_head i3c;
0491         struct list_head i2c;
0492     } boardinfo;
0493     struct i3c_bus bus;
0494     struct workqueue_struct *wq;
0495 };
0496 
0497 /**
0498  * i3c_bus_for_each_i2cdev() - iterate over all I2C devices present on the bus
0499  * @bus: the I3C bus
0500  * @dev: an I2C device descriptor pointer updated to point to the current slot
0501  *   at each iteration of the loop
0502  *
0503  * Iterate over all I2C devs present on the bus.
0504  */
0505 #define i3c_bus_for_each_i2cdev(bus, dev)               \
0506     list_for_each_entry(dev, &(bus)->devs.i2c, common.node)
0507 
0508 /**
0509  * i3c_bus_for_each_i3cdev() - iterate over all I3C devices present on the bus
0510  * @bus: the I3C bus
0511  * @dev: and I3C device descriptor pointer updated to point to the current slot
0512  *   at each iteration of the loop
0513  *
0514  * Iterate over all I3C devs present on the bus.
0515  */
0516 #define i3c_bus_for_each_i3cdev(bus, dev)               \
0517     list_for_each_entry(dev, &(bus)->devs.i3c, common.node)
0518 
0519 int i3c_master_do_i2c_xfers(struct i3c_master_controller *master,
0520                 const struct i2c_msg *xfers,
0521                 int nxfers);
0522 
0523 int i3c_master_disec_locked(struct i3c_master_controller *master, u8 addr,
0524                 u8 evts);
0525 int i3c_master_enec_locked(struct i3c_master_controller *master, u8 addr,
0526                u8 evts);
0527 int i3c_master_entdaa_locked(struct i3c_master_controller *master);
0528 int i3c_master_defslvs_locked(struct i3c_master_controller *master);
0529 
0530 int i3c_master_get_free_addr(struct i3c_master_controller *master,
0531                  u8 start_addr);
0532 
0533 int i3c_master_add_i3c_dev_locked(struct i3c_master_controller *master,
0534                   u8 addr);
0535 int i3c_master_do_daa(struct i3c_master_controller *master);
0536 
0537 int i3c_master_set_info(struct i3c_master_controller *master,
0538             const struct i3c_device_info *info);
0539 
0540 int i3c_master_register(struct i3c_master_controller *master,
0541             struct device *parent,
0542             const struct i3c_master_controller_ops *ops,
0543             bool secondary);
0544 int i3c_master_unregister(struct i3c_master_controller *master);
0545 
0546 /**
0547  * i3c_dev_get_master_data() - get master private data attached to an I3C
0548  *                 device descriptor
0549  * @dev: the I3C device descriptor to get private data from
0550  *
0551  * Return: the private data previously attached with i3c_dev_set_master_data()
0552  *     or NULL if no data has been attached to the device.
0553  */
0554 static inline void *i3c_dev_get_master_data(const struct i3c_dev_desc *dev)
0555 {
0556     return dev->common.master_priv;
0557 }
0558 
0559 /**
0560  * i3c_dev_set_master_data() - attach master private data to an I3C device
0561  *                 descriptor
0562  * @dev: the I3C device descriptor to attach private data to
0563  * @data: private data
0564  *
0565  * This functions allows a master controller to attach per-device private data
0566  * which can then be retrieved with i3c_dev_get_master_data().
0567  */
0568 static inline void i3c_dev_set_master_data(struct i3c_dev_desc *dev,
0569                        void *data)
0570 {
0571     dev->common.master_priv = data;
0572 }
0573 
0574 /**
0575  * i2c_dev_get_master_data() - get master private data attached to an I2C
0576  *                 device descriptor
0577  * @dev: the I2C device descriptor to get private data from
0578  *
0579  * Return: the private data previously attached with i2c_dev_set_master_data()
0580  *     or NULL if no data has been attached to the device.
0581  */
0582 static inline void *i2c_dev_get_master_data(const struct i2c_dev_desc *dev)
0583 {
0584     return dev->common.master_priv;
0585 }
0586 
0587 /**
0588  * i2c_dev_set_master_data() - attach master private data to an I2C device
0589  *                 descriptor
0590  * @dev: the I2C device descriptor to attach private data to
0591  * @data: private data
0592  *
0593  * This functions allows a master controller to attach per-device private data
0594  * which can then be retrieved with i2c_device_get_master_data().
0595  */
0596 static inline void i2c_dev_set_master_data(struct i2c_dev_desc *dev,
0597                        void *data)
0598 {
0599     dev->common.master_priv = data;
0600 }
0601 
0602 /**
0603  * i3c_dev_get_master() - get master used to communicate with a device
0604  * @dev: I3C dev
0605  *
0606  * Return: the master controller driving @dev
0607  */
0608 static inline struct i3c_master_controller *
0609 i3c_dev_get_master(struct i3c_dev_desc *dev)
0610 {
0611     return dev->common.master;
0612 }
0613 
0614 /**
0615  * i2c_dev_get_master() - get master used to communicate with a device
0616  * @dev: I2C dev
0617  *
0618  * Return: the master controller driving @dev
0619  */
0620 static inline struct i3c_master_controller *
0621 i2c_dev_get_master(struct i2c_dev_desc *dev)
0622 {
0623     return dev->common.master;
0624 }
0625 
0626 /**
0627  * i3c_master_get_bus() - get the bus attached to a master
0628  * @master: master object
0629  *
0630  * Return: the I3C bus @master is connected to
0631  */
0632 static inline struct i3c_bus *
0633 i3c_master_get_bus(struct i3c_master_controller *master)
0634 {
0635     return &master->bus;
0636 }
0637 
0638 struct i3c_generic_ibi_pool;
0639 
0640 struct i3c_generic_ibi_pool *
0641 i3c_generic_ibi_alloc_pool(struct i3c_dev_desc *dev,
0642                const struct i3c_ibi_setup *req);
0643 void i3c_generic_ibi_free_pool(struct i3c_generic_ibi_pool *pool);
0644 
0645 struct i3c_ibi_slot *
0646 i3c_generic_ibi_get_free_slot(struct i3c_generic_ibi_pool *pool);
0647 void i3c_generic_ibi_recycle_slot(struct i3c_generic_ibi_pool *pool,
0648                   struct i3c_ibi_slot *slot);
0649 
0650 void i3c_master_queue_ibi(struct i3c_dev_desc *dev, struct i3c_ibi_slot *slot);
0651 
0652 struct i3c_ibi_slot *i3c_master_get_free_ibi_slot(struct i3c_dev_desc *dev);
0653 
0654 #endif /* I3C_MASTER_H */