1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2018 Cadence Design Systems Inc.
5 * Author: Boris Brezillon <boris.brezillon@bootlin.com>
8 #include <linux/atomic.h>
10 #include <linux/device.h>
11 #include <linux/err.h>
12 #include <linux/export.h>
13 #include <linux/kernel.h>
14 #include <linux/list.h>
16 #include <linux/pm_runtime.h>
17 #include <linux/slab.h>
18 #include <linux/spinlock.h>
19 #include <linux/workqueue.h>
21 #include "internals.h"
23 static DEFINE_IDR(i3c_bus_idr
);
24 static DEFINE_MUTEX(i3c_core_lock
);
25 static int __i3c_first_dynamic_bus_num
;
26 static BLOCKING_NOTIFIER_HEAD(i3c_bus_notifier
);
29 * i3c_bus_maintenance_lock - Lock the bus for a maintenance operation
30 * @bus: I3C bus to take the lock on
32 * This function takes the bus lock so that no other operations can occur on
33 * the bus. This is needed for all kind of bus maintenance operation, like
34 * - enabling/disabling slave events
36 * - changing the dynamic address of a device
37 * - relinquishing mastership
40 * The reason for this kind of locking is that we don't want drivers and core
41 * logic to rely on I3C device information that could be changed behind their
44 static void i3c_bus_maintenance_lock(struct i3c_bus
*bus
)
46 down_write(&bus
->lock
);
50 * i3c_bus_maintenance_unlock - Release the bus lock after a maintenance
52 * @bus: I3C bus to release the lock on
54 * Should be called when the bus maintenance operation is done. See
55 * i3c_bus_maintenance_lock() for more details on what these maintenance
58 static void i3c_bus_maintenance_unlock(struct i3c_bus
*bus
)
64 * i3c_bus_normaluse_lock - Lock the bus for a normal operation
65 * @bus: I3C bus to take the lock on
67 * This function takes the bus lock for any operation that is not a maintenance
68 * operation (see i3c_bus_maintenance_lock() for a non-exhaustive list of
69 * maintenance operations). Basically all communications with I3C devices are
70 * normal operations (HDR, SDR transfers or CCC commands that do not change bus
71 * state or I3C dynamic address).
73 * Note that this lock is not guaranteeing serialization of normal operations.
74 * In other words, transfer requests passed to the I3C master can be submitted
75 * in parallel and I3C master drivers have to use their own locking to make
76 * sure two different communications are not inter-mixed, or access to the
77 * output/input queue is not done while the engine is busy.
79 void i3c_bus_normaluse_lock(struct i3c_bus
*bus
)
81 down_read(&bus
->lock
);
85 * i3c_bus_normaluse_unlock - Release the bus lock after a normal operation
86 * @bus: I3C bus to release the lock on
88 * Should be called when a normal operation is done. See
89 * i3c_bus_normaluse_lock() for more details on what these normal operations
92 void i3c_bus_normaluse_unlock(struct i3c_bus
*bus
)
97 static struct i3c_master_controller
*
98 i3c_bus_to_i3c_master(struct i3c_bus
*i3cbus
)
100 return container_of(i3cbus
, struct i3c_master_controller
, bus
);
103 static struct i3c_master_controller
*dev_to_i3cmaster(struct device
*dev
)
105 return container_of(dev
, struct i3c_master_controller
, dev
);
108 static const struct device_type i3c_device_type
;
110 static struct i3c_bus
*dev_to_i3cbus(struct device
*dev
)
112 struct i3c_master_controller
*master
;
114 if (dev
->type
== &i3c_device_type
)
115 return dev_to_i3cdev(dev
)->bus
;
117 master
= dev_to_i3cmaster(dev
);
122 static struct i3c_dev_desc
*dev_to_i3cdesc(struct device
*dev
)
124 struct i3c_master_controller
*master
;
126 if (dev
->type
== &i3c_device_type
)
127 return dev_to_i3cdev(dev
)->desc
;
129 master
= dev_to_i3cmaster(dev
);
134 static ssize_t
bcr_show(struct device
*dev
,
135 struct device_attribute
*da
,
138 struct i3c_bus
*bus
= dev_to_i3cbus(dev
);
139 struct i3c_dev_desc
*desc
;
142 i3c_bus_normaluse_lock(bus
);
143 desc
= dev_to_i3cdesc(dev
);
144 ret
= sprintf(buf
, "%x\n", desc
->info
.bcr
);
145 i3c_bus_normaluse_unlock(bus
);
149 static DEVICE_ATTR_RO(bcr
);
151 static ssize_t
dcr_show(struct device
*dev
,
152 struct device_attribute
*da
,
155 struct i3c_bus
*bus
= dev_to_i3cbus(dev
);
156 struct i3c_dev_desc
*desc
;
159 i3c_bus_normaluse_lock(bus
);
160 desc
= dev_to_i3cdesc(dev
);
161 ret
= sprintf(buf
, "%x\n", desc
->info
.dcr
);
162 i3c_bus_normaluse_unlock(bus
);
166 static DEVICE_ATTR_RO(dcr
);
168 static ssize_t
pid_show(struct device
*dev
,
169 struct device_attribute
*da
,
172 struct i3c_bus
*bus
= dev_to_i3cbus(dev
);
173 struct i3c_dev_desc
*desc
;
176 i3c_bus_normaluse_lock(bus
);
177 desc
= dev_to_i3cdesc(dev
);
178 ret
= sprintf(buf
, "%llx\n", desc
->info
.pid
);
179 i3c_bus_normaluse_unlock(bus
);
183 static DEVICE_ATTR_RO(pid
);
185 static ssize_t
dynamic_address_show(struct device
*dev
,
186 struct device_attribute
*da
,
189 struct i3c_bus
*bus
= dev_to_i3cbus(dev
);
190 struct i3c_dev_desc
*desc
;
193 i3c_bus_normaluse_lock(bus
);
194 desc
= dev_to_i3cdesc(dev
);
195 ret
= sprintf(buf
, "%02x\n", desc
->info
.dyn_addr
);
196 i3c_bus_normaluse_unlock(bus
);
200 static DEVICE_ATTR_RO(dynamic_address
);
202 static const char * const hdrcap_strings
[] = {
203 "hdr-ddr", "hdr-tsp", "hdr-tsl",
206 static ssize_t
hdrcap_show(struct device
*dev
,
207 struct device_attribute
*da
,
210 struct i3c_bus
*bus
= dev_to_i3cbus(dev
);
211 struct i3c_dev_desc
*desc
;
212 ssize_t offset
= 0, ret
;
216 i3c_bus_normaluse_lock(bus
);
217 desc
= dev_to_i3cdesc(dev
);
218 caps
= desc
->info
.hdr_cap
;
219 for_each_set_bit(mode
, &caps
, 8) {
220 if (mode
>= ARRAY_SIZE(hdrcap_strings
))
223 if (!hdrcap_strings
[mode
])
226 ret
= sprintf(buf
+ offset
, offset
? " %s" : "%s",
227 hdrcap_strings
[mode
]);
234 ret
= sprintf(buf
+ offset
, "\n");
241 i3c_bus_normaluse_unlock(bus
);
245 static DEVICE_ATTR_RO(hdrcap
);
247 static ssize_t
modalias_show(struct device
*dev
,
248 struct device_attribute
*da
, char *buf
)
250 struct i3c_device
*i3c
= dev_to_i3cdev(dev
);
251 struct i3c_device_info devinfo
;
252 u16 manuf
, part
, ext
;
254 i3c_device_get_info(i3c
, &devinfo
);
255 manuf
= I3C_PID_MANUF_ID(devinfo
.pid
);
256 part
= I3C_PID_PART_ID(devinfo
.pid
);
257 ext
= I3C_PID_EXTRA_INFO(devinfo
.pid
);
259 if (I3C_PID_RND_LOWER_32BITS(devinfo
.pid
))
260 return sprintf(buf
, "i3c:dcr%02Xmanuf%04X", devinfo
.dcr
,
263 return sprintf(buf
, "i3c:dcr%02Xmanuf%04Xpart%04Xext%04X",
264 devinfo
.dcr
, manuf
, part
, ext
);
266 static DEVICE_ATTR_RO(modalias
);
268 static struct attribute
*i3c_device_attrs
[] = {
272 &dev_attr_dynamic_address
.attr
,
273 &dev_attr_hdrcap
.attr
,
274 &dev_attr_modalias
.attr
,
277 ATTRIBUTE_GROUPS(i3c_device
);
279 static int i3c_device_uevent(const struct device
*dev
, struct kobj_uevent_env
*env
)
281 const struct i3c_device
*i3cdev
= dev_to_i3cdev(dev
);
282 struct i3c_device_info devinfo
;
283 u16 manuf
, part
, ext
;
286 devinfo
= i3cdev
->desc
->info
;
287 manuf
= I3C_PID_MANUF_ID(devinfo
.pid
);
288 part
= I3C_PID_PART_ID(devinfo
.pid
);
289 ext
= I3C_PID_EXTRA_INFO(devinfo
.pid
);
291 if (I3C_PID_RND_LOWER_32BITS(devinfo
.pid
))
292 return add_uevent_var(env
, "MODALIAS=i3c:dcr%02Xmanuf%04X",
295 return add_uevent_var(env
,
296 "MODALIAS=i3c:dcr%02Xmanuf%04Xpart%04Xext%04X",
297 devinfo
.dcr
, manuf
, part
, ext
);
300 static const struct device_type i3c_device_type
= {
301 .groups
= i3c_device_groups
,
302 .uevent
= i3c_device_uevent
,
305 static int i3c_device_match(struct device
*dev
, const struct device_driver
*drv
)
307 struct i3c_device
*i3cdev
;
308 const struct i3c_driver
*i3cdrv
;
310 if (dev
->type
!= &i3c_device_type
)
313 i3cdev
= dev_to_i3cdev(dev
);
314 i3cdrv
= drv_to_i3cdrv(drv
);
315 if (i3c_device_match_id(i3cdev
, i3cdrv
->id_table
))
321 static int i3c_device_probe(struct device
*dev
)
323 struct i3c_device
*i3cdev
= dev_to_i3cdev(dev
);
324 struct i3c_driver
*driver
= drv_to_i3cdrv(dev
->driver
);
326 return driver
->probe(i3cdev
);
329 static void i3c_device_remove(struct device
*dev
)
331 struct i3c_device
*i3cdev
= dev_to_i3cdev(dev
);
332 struct i3c_driver
*driver
= drv_to_i3cdrv(dev
->driver
);
335 driver
->remove(i3cdev
);
337 i3c_device_free_ibi(i3cdev
);
340 const struct bus_type i3c_bus_type
= {
342 .match
= i3c_device_match
,
343 .probe
= i3c_device_probe
,
344 .remove
= i3c_device_remove
,
346 EXPORT_SYMBOL_GPL(i3c_bus_type
);
348 static enum i3c_addr_slot_status
349 i3c_bus_get_addr_slot_status_mask(struct i3c_bus
*bus
, u16 addr
, u32 mask
)
351 unsigned long status
;
352 int bitpos
= addr
* I3C_ADDR_SLOT_STATUS_BITS
;
354 if (addr
> I2C_MAX_ADDR
)
355 return I3C_ADDR_SLOT_RSVD
;
357 status
= bus
->addrslots
[bitpos
/ BITS_PER_LONG
];
358 status
>>= bitpos
% BITS_PER_LONG
;
360 return status
& mask
;
363 static enum i3c_addr_slot_status
364 i3c_bus_get_addr_slot_status(struct i3c_bus
*bus
, u16 addr
)
366 return i3c_bus_get_addr_slot_status_mask(bus
, addr
, I3C_ADDR_SLOT_STATUS_MASK
);
369 static void i3c_bus_set_addr_slot_status_mask(struct i3c_bus
*bus
, u16 addr
,
370 enum i3c_addr_slot_status status
, u32 mask
)
372 int bitpos
= addr
* I3C_ADDR_SLOT_STATUS_BITS
;
375 if (addr
> I2C_MAX_ADDR
)
378 ptr
= bus
->addrslots
+ (bitpos
/ BITS_PER_LONG
);
379 *ptr
&= ~((unsigned long)mask
<< (bitpos
% BITS_PER_LONG
));
380 *ptr
|= ((unsigned long)status
& mask
) << (bitpos
% BITS_PER_LONG
);
383 static void i3c_bus_set_addr_slot_status(struct i3c_bus
*bus
, u16 addr
,
384 enum i3c_addr_slot_status status
)
386 i3c_bus_set_addr_slot_status_mask(bus
, addr
, status
, I3C_ADDR_SLOT_STATUS_MASK
);
389 static bool i3c_bus_dev_addr_is_avail(struct i3c_bus
*bus
, u8 addr
)
391 enum i3c_addr_slot_status status
;
393 status
= i3c_bus_get_addr_slot_status(bus
, addr
);
395 return status
== I3C_ADDR_SLOT_FREE
;
399 * ┌────┬─────────────┬───┬─────────┬───┐
400 * │S/Sr│ 7'h7E RnW=0 │ACK│ ENTDAA │ T ├────┐
401 * └────┴─────────────┴───┴─────────┴───┘ │
402 * ┌─────────────────────────────────────────┘
403 * │ ┌──┬─────────────┬───┬─────────────────┬────────────────┬───┬─────────┐
404 * └─►│Sr│7'h7E RnW=1 │ACK│48bit UID BCR DCR│Assign 7bit Addr│PAR│ ACK/NACK│
405 * └──┴─────────────┴───┴─────────────────┴────────────────┴───┴─────────┘
406 * Some master controllers (such as HCI) need to prepare the entire above transaction before
407 * sending it out to the I3C bus. This means that a 7-bit dynamic address needs to be allocated
408 * before knowing the target device's UID information.
410 * However, some I3C targets may request specific addresses (called as "init_dyn_addr"), which is
411 * typically specified by the DT-'s assigned-address property. Lower addresses having higher IBI
412 * priority. If it is available, i3c_bus_get_free_addr() preferably return a free address that is
413 * not in the list of desired addresses (called as "init_dyn_addr"). This allows the device with
414 * the "init_dyn_addr" to switch to its "init_dyn_addr" when it hot-joins the I3C bus. Otherwise,
415 * if the "init_dyn_addr" is already in use by another I3C device, the target device will not be
416 * able to switch to its desired address.
418 * If the previous step fails, fallback returning one of the remaining unassigned address,
419 * regardless of its state in the desired list.
421 static int i3c_bus_get_free_addr(struct i3c_bus
*bus
, u8 start_addr
)
423 enum i3c_addr_slot_status status
;
426 for (addr
= start_addr
; addr
< I3C_MAX_ADDR
; addr
++) {
427 status
= i3c_bus_get_addr_slot_status_mask(bus
, addr
,
428 I3C_ADDR_SLOT_EXT_STATUS_MASK
);
429 if (status
== I3C_ADDR_SLOT_FREE
)
433 for (addr
= start_addr
; addr
< I3C_MAX_ADDR
; addr
++) {
434 status
= i3c_bus_get_addr_slot_status_mask(bus
, addr
,
435 I3C_ADDR_SLOT_STATUS_MASK
);
436 if (status
== I3C_ADDR_SLOT_FREE
)
443 static void i3c_bus_init_addrslots(struct i3c_bus
*bus
)
447 /* Addresses 0 to 7 are reserved. */
448 for (i
= 0; i
< 8; i
++)
449 i3c_bus_set_addr_slot_status(bus
, i
, I3C_ADDR_SLOT_RSVD
);
452 * Reserve broadcast address and all addresses that might collide
453 * with the broadcast address when facing a single bit error.
455 i3c_bus_set_addr_slot_status(bus
, I3C_BROADCAST_ADDR
,
457 for (i
= 0; i
< 7; i
++)
458 i3c_bus_set_addr_slot_status(bus
, I3C_BROADCAST_ADDR
^ BIT(i
),
462 static void i3c_bus_cleanup(struct i3c_bus
*i3cbus
)
464 mutex_lock(&i3c_core_lock
);
465 idr_remove(&i3c_bus_idr
, i3cbus
->id
);
466 mutex_unlock(&i3c_core_lock
);
469 static int i3c_bus_init(struct i3c_bus
*i3cbus
, struct device_node
*np
)
471 int ret
, start
, end
, id
= -1;
473 init_rwsem(&i3cbus
->lock
);
474 INIT_LIST_HEAD(&i3cbus
->devs
.i2c
);
475 INIT_LIST_HEAD(&i3cbus
->devs
.i3c
);
476 i3c_bus_init_addrslots(i3cbus
);
477 i3cbus
->mode
= I3C_BUS_MODE_PURE
;
480 id
= of_alias_get_id(np
, "i3c");
482 mutex_lock(&i3c_core_lock
);
487 start
= __i3c_first_dynamic_bus_num
;
491 ret
= idr_alloc(&i3c_bus_idr
, i3cbus
, start
, end
, GFP_KERNEL
);
492 mutex_unlock(&i3c_core_lock
);
502 void i3c_for_each_bus_locked(int (*fn
)(struct i3c_bus
*bus
, void *data
),
508 mutex_lock(&i3c_core_lock
);
509 idr_for_each_entry(&i3c_bus_idr
, bus
, id
)
511 mutex_unlock(&i3c_core_lock
);
513 EXPORT_SYMBOL_GPL(i3c_for_each_bus_locked
);
515 int i3c_register_notifier(struct notifier_block
*nb
)
517 return blocking_notifier_chain_register(&i3c_bus_notifier
, nb
);
519 EXPORT_SYMBOL_GPL(i3c_register_notifier
);
521 int i3c_unregister_notifier(struct notifier_block
*nb
)
523 return blocking_notifier_chain_unregister(&i3c_bus_notifier
, nb
);
525 EXPORT_SYMBOL_GPL(i3c_unregister_notifier
);
527 static void i3c_bus_notify(struct i3c_bus
*bus
, unsigned int action
)
529 blocking_notifier_call_chain(&i3c_bus_notifier
, action
, bus
);
532 static const char * const i3c_bus_mode_strings
[] = {
533 [I3C_BUS_MODE_PURE
] = "pure",
534 [I3C_BUS_MODE_MIXED_FAST
] = "mixed-fast",
535 [I3C_BUS_MODE_MIXED_LIMITED
] = "mixed-limited",
536 [I3C_BUS_MODE_MIXED_SLOW
] = "mixed-slow",
539 static ssize_t
mode_show(struct device
*dev
,
540 struct device_attribute
*da
,
543 struct i3c_bus
*i3cbus
= dev_to_i3cbus(dev
);
546 i3c_bus_normaluse_lock(i3cbus
);
547 if (i3cbus
->mode
< 0 ||
548 i3cbus
->mode
>= ARRAY_SIZE(i3c_bus_mode_strings
) ||
549 !i3c_bus_mode_strings
[i3cbus
->mode
])
550 ret
= sprintf(buf
, "unknown\n");
552 ret
= sprintf(buf
, "%s\n", i3c_bus_mode_strings
[i3cbus
->mode
]);
553 i3c_bus_normaluse_unlock(i3cbus
);
557 static DEVICE_ATTR_RO(mode
);
559 static ssize_t
current_master_show(struct device
*dev
,
560 struct device_attribute
*da
,
563 struct i3c_bus
*i3cbus
= dev_to_i3cbus(dev
);
566 i3c_bus_normaluse_lock(i3cbus
);
567 ret
= sprintf(buf
, "%d-%llx\n", i3cbus
->id
,
568 i3cbus
->cur_master
->info
.pid
);
569 i3c_bus_normaluse_unlock(i3cbus
);
573 static DEVICE_ATTR_RO(current_master
);
575 static ssize_t
i3c_scl_frequency_show(struct device
*dev
,
576 struct device_attribute
*da
,
579 struct i3c_bus
*i3cbus
= dev_to_i3cbus(dev
);
582 i3c_bus_normaluse_lock(i3cbus
);
583 ret
= sprintf(buf
, "%ld\n", i3cbus
->scl_rate
.i3c
);
584 i3c_bus_normaluse_unlock(i3cbus
);
588 static DEVICE_ATTR_RO(i3c_scl_frequency
);
590 static ssize_t
i2c_scl_frequency_show(struct device
*dev
,
591 struct device_attribute
*da
,
594 struct i3c_bus
*i3cbus
= dev_to_i3cbus(dev
);
597 i3c_bus_normaluse_lock(i3cbus
);
598 ret
= sprintf(buf
, "%ld\n", i3cbus
->scl_rate
.i2c
);
599 i3c_bus_normaluse_unlock(i3cbus
);
603 static DEVICE_ATTR_RO(i2c_scl_frequency
);
605 static int i3c_set_hotjoin(struct i3c_master_controller
*master
, bool enable
)
609 if (!master
|| !master
->ops
)
612 if (!master
->ops
->enable_hotjoin
|| !master
->ops
->disable_hotjoin
)
615 i3c_bus_normaluse_lock(&master
->bus
);
618 ret
= master
->ops
->enable_hotjoin(master
);
620 ret
= master
->ops
->disable_hotjoin(master
);
622 master
->hotjoin
= enable
;
624 i3c_bus_normaluse_unlock(&master
->bus
);
629 static ssize_t
hotjoin_store(struct device
*dev
, struct device_attribute
*attr
,
630 const char *buf
, size_t count
)
632 struct i3c_bus
*i3cbus
= dev_to_i3cbus(dev
);
636 if (!i3cbus
->cur_master
)
639 if (kstrtobool(buf
, &res
))
642 ret
= i3c_set_hotjoin(i3cbus
->cur_master
->common
.master
, res
);
650 * i3c_master_enable_hotjoin - Enable hotjoin
651 * @master: I3C master object
653 * Return: a 0 in case of success, an negative error code otherwise.
655 int i3c_master_enable_hotjoin(struct i3c_master_controller
*master
)
657 return i3c_set_hotjoin(master
, true);
659 EXPORT_SYMBOL_GPL(i3c_master_enable_hotjoin
);
662 * i3c_master_disable_hotjoin - Disable hotjoin
663 * @master: I3C master object
665 * Return: a 0 in case of success, an negative error code otherwise.
667 int i3c_master_disable_hotjoin(struct i3c_master_controller
*master
)
669 return i3c_set_hotjoin(master
, false);
671 EXPORT_SYMBOL_GPL(i3c_master_disable_hotjoin
);
673 static ssize_t
hotjoin_show(struct device
*dev
, struct device_attribute
*da
, char *buf
)
675 struct i3c_bus
*i3cbus
= dev_to_i3cbus(dev
);
678 i3c_bus_normaluse_lock(i3cbus
);
679 ret
= sysfs_emit(buf
, "%d\n", i3cbus
->cur_master
->common
.master
->hotjoin
);
680 i3c_bus_normaluse_unlock(i3cbus
);
685 static DEVICE_ATTR_RW(hotjoin
);
687 static struct attribute
*i3c_masterdev_attrs
[] = {
689 &dev_attr_current_master
.attr
,
690 &dev_attr_i3c_scl_frequency
.attr
,
691 &dev_attr_i2c_scl_frequency
.attr
,
695 &dev_attr_dynamic_address
.attr
,
696 &dev_attr_hdrcap
.attr
,
697 &dev_attr_hotjoin
.attr
,
700 ATTRIBUTE_GROUPS(i3c_masterdev
);
702 static void i3c_masterdev_release(struct device
*dev
)
704 struct i3c_master_controller
*master
= dev_to_i3cmaster(dev
);
705 struct i3c_bus
*bus
= dev_to_i3cbus(dev
);
708 destroy_workqueue(master
->wq
);
710 WARN_ON(!list_empty(&bus
->devs
.i2c
) || !list_empty(&bus
->devs
.i3c
));
711 i3c_bus_cleanup(bus
);
713 of_node_put(dev
->of_node
);
716 static const struct device_type i3c_masterdev_type
= {
717 .groups
= i3c_masterdev_groups
,
720 static int i3c_bus_set_mode(struct i3c_bus
*i3cbus
, enum i3c_bus_mode mode
,
721 unsigned long max_i2c_scl_rate
)
723 struct i3c_master_controller
*master
= i3c_bus_to_i3c_master(i3cbus
);
727 switch (i3cbus
->mode
) {
728 case I3C_BUS_MODE_PURE
:
729 if (!i3cbus
->scl_rate
.i3c
)
730 i3cbus
->scl_rate
.i3c
= I3C_BUS_TYP_I3C_SCL_RATE
;
732 case I3C_BUS_MODE_MIXED_FAST
:
733 case I3C_BUS_MODE_MIXED_LIMITED
:
734 if (!i3cbus
->scl_rate
.i3c
)
735 i3cbus
->scl_rate
.i3c
= I3C_BUS_TYP_I3C_SCL_RATE
;
736 if (!i3cbus
->scl_rate
.i2c
)
737 i3cbus
->scl_rate
.i2c
= max_i2c_scl_rate
;
739 case I3C_BUS_MODE_MIXED_SLOW
:
740 if (!i3cbus
->scl_rate
.i2c
)
741 i3cbus
->scl_rate
.i2c
= max_i2c_scl_rate
;
742 if (!i3cbus
->scl_rate
.i3c
||
743 i3cbus
->scl_rate
.i3c
> i3cbus
->scl_rate
.i2c
)
744 i3cbus
->scl_rate
.i3c
= i3cbus
->scl_rate
.i2c
;
750 dev_dbg(&master
->dev
, "i2c-scl = %ld Hz i3c-scl = %ld Hz\n",
751 i3cbus
->scl_rate
.i2c
, i3cbus
->scl_rate
.i3c
);
754 * I3C/I2C frequency may have been overridden, check that user-provided
755 * values are not exceeding max possible frequency.
757 if (i3cbus
->scl_rate
.i3c
> I3C_BUS_MAX_I3C_SCL_RATE
||
758 i3cbus
->scl_rate
.i2c
> I3C_BUS_I2C_FM_PLUS_SCL_RATE
)
764 static struct i3c_master_controller
*
765 i2c_adapter_to_i3c_master(struct i2c_adapter
*adap
)
767 return container_of(adap
, struct i3c_master_controller
, i2c
);
770 static struct i2c_adapter
*
771 i3c_master_to_i2c_adapter(struct i3c_master_controller
*master
)
776 static void i3c_master_free_i2c_dev(struct i2c_dev_desc
*dev
)
781 static struct i2c_dev_desc
*
782 i3c_master_alloc_i2c_dev(struct i3c_master_controller
*master
,
785 struct i2c_dev_desc
*dev
;
787 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
789 return ERR_PTR(-ENOMEM
);
791 dev
->common
.master
= master
;
798 static void *i3c_ccc_cmd_dest_init(struct i3c_ccc_cmd_dest
*dest
, u8 addr
,
802 dest
->payload
.len
= payloadlen
;
804 dest
->payload
.data
= kzalloc(payloadlen
, GFP_KERNEL
);
806 dest
->payload
.data
= NULL
;
808 return dest
->payload
.data
;
811 static void i3c_ccc_cmd_dest_cleanup(struct i3c_ccc_cmd_dest
*dest
)
813 kfree(dest
->payload
.data
);
816 static void i3c_ccc_cmd_init(struct i3c_ccc_cmd
*cmd
, bool rnw
, u8 id
,
817 struct i3c_ccc_cmd_dest
*dests
,
820 cmd
->rnw
= rnw
? 1 : 0;
823 cmd
->ndests
= ndests
;
824 cmd
->err
= I3C_ERROR_UNKNOWN
;
827 static int i3c_master_send_ccc_cmd_locked(struct i3c_master_controller
*master
,
828 struct i3c_ccc_cmd
*cmd
)
835 if (WARN_ON(master
->init_done
&&
836 !rwsem_is_locked(&master
->bus
.lock
)))
839 if (!master
->ops
->send_ccc_cmd
)
842 if ((cmd
->id
& I3C_CCC_DIRECT
) && (!cmd
->dests
|| !cmd
->ndests
))
845 if (master
->ops
->supports_ccc_cmd
&&
846 !master
->ops
->supports_ccc_cmd(master
, cmd
))
849 ret
= master
->ops
->send_ccc_cmd(master
, cmd
);
851 if (cmd
->err
!= I3C_ERROR_UNKNOWN
)
860 static struct i2c_dev_desc
*
861 i3c_master_find_i2c_dev_by_addr(const struct i3c_master_controller
*master
,
864 struct i2c_dev_desc
*dev
;
866 i3c_bus_for_each_i2cdev(&master
->bus
, dev
) {
867 if (dev
->addr
== addr
)
875 * i3c_master_get_free_addr() - get a free address on the bus
876 * @master: I3C master object
877 * @start_addr: where to start searching
879 * This function must be called with the bus lock held in write mode.
881 * Return: the first free address starting at @start_addr (included) or -ENOMEM
882 * if there's no more address available.
884 int i3c_master_get_free_addr(struct i3c_master_controller
*master
,
887 return i3c_bus_get_free_addr(&master
->bus
, start_addr
);
889 EXPORT_SYMBOL_GPL(i3c_master_get_free_addr
);
891 static void i3c_device_release(struct device
*dev
)
893 struct i3c_device
*i3cdev
= dev_to_i3cdev(dev
);
895 WARN_ON(i3cdev
->desc
);
897 of_node_put(i3cdev
->dev
.of_node
);
901 static void i3c_master_free_i3c_dev(struct i3c_dev_desc
*dev
)
906 static struct i3c_dev_desc
*
907 i3c_master_alloc_i3c_dev(struct i3c_master_controller
*master
,
908 const struct i3c_device_info
*info
)
910 struct i3c_dev_desc
*dev
;
912 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
914 return ERR_PTR(-ENOMEM
);
916 dev
->common
.master
= master
;
918 mutex_init(&dev
->ibi_lock
);
923 static int i3c_master_rstdaa_locked(struct i3c_master_controller
*master
,
926 enum i3c_addr_slot_status addrstat
;
927 struct i3c_ccc_cmd_dest dest
;
928 struct i3c_ccc_cmd cmd
;
934 addrstat
= i3c_bus_get_addr_slot_status(&master
->bus
, addr
);
935 if (addr
!= I3C_BROADCAST_ADDR
&& addrstat
!= I3C_ADDR_SLOT_I3C_DEV
)
938 i3c_ccc_cmd_dest_init(&dest
, addr
, 0);
939 i3c_ccc_cmd_init(&cmd
, false,
940 I3C_CCC_RSTDAA(addr
== I3C_BROADCAST_ADDR
),
942 ret
= i3c_master_send_ccc_cmd_locked(master
, &cmd
);
943 i3c_ccc_cmd_dest_cleanup(&dest
);
949 * i3c_master_entdaa_locked() - start a DAA (Dynamic Address Assignment)
951 * @master: master used to send frames on the bus
953 * Send a ENTDAA CCC command to start a DAA procedure.
955 * Note that this function only sends the ENTDAA CCC command, all the logic
956 * behind dynamic address assignment has to be handled in the I3C master
959 * This function must be called with the bus lock held in write mode.
961 * Return: 0 in case of success, a positive I3C error code if the error is
962 * one of the official Mx error codes, and a negative error code otherwise.
964 int i3c_master_entdaa_locked(struct i3c_master_controller
*master
)
966 struct i3c_ccc_cmd_dest dest
;
967 struct i3c_ccc_cmd cmd
;
970 i3c_ccc_cmd_dest_init(&dest
, I3C_BROADCAST_ADDR
, 0);
971 i3c_ccc_cmd_init(&cmd
, false, I3C_CCC_ENTDAA
, &dest
, 1);
972 ret
= i3c_master_send_ccc_cmd_locked(master
, &cmd
);
973 i3c_ccc_cmd_dest_cleanup(&dest
);
977 EXPORT_SYMBOL_GPL(i3c_master_entdaa_locked
);
979 static int i3c_master_enec_disec_locked(struct i3c_master_controller
*master
,
980 u8 addr
, bool enable
, u8 evts
)
982 struct i3c_ccc_events
*events
;
983 struct i3c_ccc_cmd_dest dest
;
984 struct i3c_ccc_cmd cmd
;
987 events
= i3c_ccc_cmd_dest_init(&dest
, addr
, sizeof(*events
));
991 events
->events
= evts
;
992 i3c_ccc_cmd_init(&cmd
, false,
994 I3C_CCC_ENEC(addr
== I3C_BROADCAST_ADDR
) :
995 I3C_CCC_DISEC(addr
== I3C_BROADCAST_ADDR
),
997 ret
= i3c_master_send_ccc_cmd_locked(master
, &cmd
);
998 i3c_ccc_cmd_dest_cleanup(&dest
);
1004 * i3c_master_disec_locked() - send a DISEC CCC command
1005 * @master: master used to send frames on the bus
1006 * @addr: a valid I3C slave address or %I3C_BROADCAST_ADDR
1007 * @evts: events to disable
1009 * Send a DISEC CCC command to disable some or all events coming from a
1010 * specific slave, or all devices if @addr is %I3C_BROADCAST_ADDR.
1012 * This function must be called with the bus lock held in write mode.
1014 * Return: 0 in case of success, a positive I3C error code if the error is
1015 * one of the official Mx error codes, and a negative error code otherwise.
1017 int i3c_master_disec_locked(struct i3c_master_controller
*master
, u8 addr
,
1020 return i3c_master_enec_disec_locked(master
, addr
, false, evts
);
1022 EXPORT_SYMBOL_GPL(i3c_master_disec_locked
);
1025 * i3c_master_enec_locked() - send an ENEC CCC command
1026 * @master: master used to send frames on the bus
1027 * @addr: a valid I3C slave address or %I3C_BROADCAST_ADDR
1028 * @evts: events to disable
1030 * Sends an ENEC CCC command to enable some or all events coming from a
1031 * specific slave, or all devices if @addr is %I3C_BROADCAST_ADDR.
1033 * This function must be called with the bus lock held in write mode.
1035 * Return: 0 in case of success, a positive I3C error code if the error is
1036 * one of the official Mx error codes, and a negative error code otherwise.
1038 int i3c_master_enec_locked(struct i3c_master_controller
*master
, u8 addr
,
1041 return i3c_master_enec_disec_locked(master
, addr
, true, evts
);
1043 EXPORT_SYMBOL_GPL(i3c_master_enec_locked
);
1046 * i3c_master_defslvs_locked() - send a DEFSLVS CCC command
1047 * @master: master used to send frames on the bus
1049 * Send a DEFSLVS CCC command containing all the devices known to the @master.
1050 * This is useful when you have secondary masters on the bus to propagate
1051 * device information.
1053 * This should be called after all I3C devices have been discovered (in other
1054 * words, after the DAA procedure has finished) and instantiated in
1055 * &i3c_master_controller_ops->bus_init().
1056 * It should also be called if a master ACKed an Hot-Join request and assigned
1057 * a dynamic address to the device joining the bus.
1059 * This function must be called with the bus lock held in write mode.
1061 * Return: 0 in case of success, a positive I3C error code if the error is
1062 * one of the official Mx error codes, and a negative error code otherwise.
1064 int i3c_master_defslvs_locked(struct i3c_master_controller
*master
)
1066 struct i3c_ccc_defslvs
*defslvs
;
1067 struct i3c_ccc_dev_desc
*desc
;
1068 struct i3c_ccc_cmd_dest dest
;
1069 struct i3c_dev_desc
*i3cdev
;
1070 struct i2c_dev_desc
*i2cdev
;
1071 struct i3c_ccc_cmd cmd
;
1072 struct i3c_bus
*bus
;
1079 bus
= i3c_master_get_bus(master
);
1080 i3c_bus_for_each_i3cdev(bus
, i3cdev
) {
1083 if (i3cdev
== master
->this)
1086 if (I3C_BCR_DEVICE_ROLE(i3cdev
->info
.bcr
) ==
1091 /* No other master on the bus, skip DEFSLVS. */
1095 i3c_bus_for_each_i2cdev(bus
, i2cdev
)
1098 defslvs
= i3c_ccc_cmd_dest_init(&dest
, I3C_BROADCAST_ADDR
,
1099 struct_size(defslvs
, slaves
,
1104 defslvs
->count
= ndevs
;
1105 defslvs
->master
.bcr
= master
->this->info
.bcr
;
1106 defslvs
->master
.dcr
= master
->this->info
.dcr
;
1107 defslvs
->master
.dyn_addr
= master
->this->info
.dyn_addr
<< 1;
1108 defslvs
->master
.static_addr
= I3C_BROADCAST_ADDR
<< 1;
1110 desc
= defslvs
->slaves
;
1111 i3c_bus_for_each_i2cdev(bus
, i2cdev
) {
1112 desc
->lvr
= i2cdev
->lvr
;
1113 desc
->static_addr
= i2cdev
->addr
<< 1;
1117 i3c_bus_for_each_i3cdev(bus
, i3cdev
) {
1118 /* Skip the I3C dev representing this master. */
1119 if (i3cdev
== master
->this)
1122 desc
->bcr
= i3cdev
->info
.bcr
;
1123 desc
->dcr
= i3cdev
->info
.dcr
;
1124 desc
->dyn_addr
= i3cdev
->info
.dyn_addr
<< 1;
1125 desc
->static_addr
= i3cdev
->info
.static_addr
<< 1;
1129 i3c_ccc_cmd_init(&cmd
, false, I3C_CCC_DEFSLVS
, &dest
, 1);
1130 ret
= i3c_master_send_ccc_cmd_locked(master
, &cmd
);
1131 i3c_ccc_cmd_dest_cleanup(&dest
);
1135 EXPORT_SYMBOL_GPL(i3c_master_defslvs_locked
);
1137 static int i3c_master_setda_locked(struct i3c_master_controller
*master
,
1138 u8 oldaddr
, u8 newaddr
, bool setdasa
)
1140 struct i3c_ccc_cmd_dest dest
;
1141 struct i3c_ccc_setda
*setda
;
1142 struct i3c_ccc_cmd cmd
;
1145 if (!oldaddr
|| !newaddr
)
1148 setda
= i3c_ccc_cmd_dest_init(&dest
, oldaddr
, sizeof(*setda
));
1152 setda
->addr
= newaddr
<< 1;
1153 i3c_ccc_cmd_init(&cmd
, false,
1154 setdasa
? I3C_CCC_SETDASA
: I3C_CCC_SETNEWDA
,
1156 ret
= i3c_master_send_ccc_cmd_locked(master
, &cmd
);
1157 i3c_ccc_cmd_dest_cleanup(&dest
);
1162 static int i3c_master_setdasa_locked(struct i3c_master_controller
*master
,
1163 u8 static_addr
, u8 dyn_addr
)
1165 return i3c_master_setda_locked(master
, static_addr
, dyn_addr
, true);
1168 static int i3c_master_setnewda_locked(struct i3c_master_controller
*master
,
1169 u8 oldaddr
, u8 newaddr
)
1171 return i3c_master_setda_locked(master
, oldaddr
, newaddr
, false);
1174 static int i3c_master_getmrl_locked(struct i3c_master_controller
*master
,
1175 struct i3c_device_info
*info
)
1177 struct i3c_ccc_cmd_dest dest
;
1178 struct i3c_ccc_mrl
*mrl
;
1179 struct i3c_ccc_cmd cmd
;
1182 mrl
= i3c_ccc_cmd_dest_init(&dest
, info
->dyn_addr
, sizeof(*mrl
));
1187 * When the device does not have IBI payload GETMRL only returns 2
1190 if (!(info
->bcr
& I3C_BCR_IBI_PAYLOAD
))
1191 dest
.payload
.len
-= 1;
1193 i3c_ccc_cmd_init(&cmd
, true, I3C_CCC_GETMRL
, &dest
, 1);
1194 ret
= i3c_master_send_ccc_cmd_locked(master
, &cmd
);
1198 switch (dest
.payload
.len
) {
1200 info
->max_ibi_len
= mrl
->ibi_len
;
1203 info
->max_read_len
= be16_to_cpu(mrl
->read_len
);
1211 i3c_ccc_cmd_dest_cleanup(&dest
);
1216 static int i3c_master_getmwl_locked(struct i3c_master_controller
*master
,
1217 struct i3c_device_info
*info
)
1219 struct i3c_ccc_cmd_dest dest
;
1220 struct i3c_ccc_mwl
*mwl
;
1221 struct i3c_ccc_cmd cmd
;
1224 mwl
= i3c_ccc_cmd_dest_init(&dest
, info
->dyn_addr
, sizeof(*mwl
));
1228 i3c_ccc_cmd_init(&cmd
, true, I3C_CCC_GETMWL
, &dest
, 1);
1229 ret
= i3c_master_send_ccc_cmd_locked(master
, &cmd
);
1233 if (dest
.payload
.len
!= sizeof(*mwl
)) {
1238 info
->max_write_len
= be16_to_cpu(mwl
->len
);
1241 i3c_ccc_cmd_dest_cleanup(&dest
);
1246 static int i3c_master_getmxds_locked(struct i3c_master_controller
*master
,
1247 struct i3c_device_info
*info
)
1249 struct i3c_ccc_getmxds
*getmaxds
;
1250 struct i3c_ccc_cmd_dest dest
;
1251 struct i3c_ccc_cmd cmd
;
1254 getmaxds
= i3c_ccc_cmd_dest_init(&dest
, info
->dyn_addr
,
1259 i3c_ccc_cmd_init(&cmd
, true, I3C_CCC_GETMXDS
, &dest
, 1);
1260 ret
= i3c_master_send_ccc_cmd_locked(master
, &cmd
);
1263 * Retry when the device does not support max read turnaround
1264 * while expecting shorter length from this CCC command.
1266 dest
.payload
.len
-= 3;
1267 ret
= i3c_master_send_ccc_cmd_locked(master
, &cmd
);
1272 if (dest
.payload
.len
!= 2 && dest
.payload
.len
!= 5) {
1277 info
->max_read_ds
= getmaxds
->maxrd
;
1278 info
->max_write_ds
= getmaxds
->maxwr
;
1279 if (dest
.payload
.len
== 5)
1280 info
->max_read_turnaround
= getmaxds
->maxrdturn
[0] |
1281 ((u32
)getmaxds
->maxrdturn
[1] << 8) |
1282 ((u32
)getmaxds
->maxrdturn
[2] << 16);
1285 i3c_ccc_cmd_dest_cleanup(&dest
);
1290 static int i3c_master_gethdrcap_locked(struct i3c_master_controller
*master
,
1291 struct i3c_device_info
*info
)
1293 struct i3c_ccc_gethdrcap
*gethdrcap
;
1294 struct i3c_ccc_cmd_dest dest
;
1295 struct i3c_ccc_cmd cmd
;
1298 gethdrcap
= i3c_ccc_cmd_dest_init(&dest
, info
->dyn_addr
,
1299 sizeof(*gethdrcap
));
1303 i3c_ccc_cmd_init(&cmd
, true, I3C_CCC_GETHDRCAP
, &dest
, 1);
1304 ret
= i3c_master_send_ccc_cmd_locked(master
, &cmd
);
1308 if (dest
.payload
.len
!= 1) {
1313 info
->hdr_cap
= gethdrcap
->modes
;
1316 i3c_ccc_cmd_dest_cleanup(&dest
);
1321 static int i3c_master_getpid_locked(struct i3c_master_controller
*master
,
1322 struct i3c_device_info
*info
)
1324 struct i3c_ccc_getpid
*getpid
;
1325 struct i3c_ccc_cmd_dest dest
;
1326 struct i3c_ccc_cmd cmd
;
1329 getpid
= i3c_ccc_cmd_dest_init(&dest
, info
->dyn_addr
, sizeof(*getpid
));
1333 i3c_ccc_cmd_init(&cmd
, true, I3C_CCC_GETPID
, &dest
, 1);
1334 ret
= i3c_master_send_ccc_cmd_locked(master
, &cmd
);
1339 for (i
= 0; i
< sizeof(getpid
->pid
); i
++) {
1340 int sft
= (sizeof(getpid
->pid
) - i
- 1) * 8;
1342 info
->pid
|= (u64
)getpid
->pid
[i
] << sft
;
1346 i3c_ccc_cmd_dest_cleanup(&dest
);
1351 static int i3c_master_getbcr_locked(struct i3c_master_controller
*master
,
1352 struct i3c_device_info
*info
)
1354 struct i3c_ccc_getbcr
*getbcr
;
1355 struct i3c_ccc_cmd_dest dest
;
1356 struct i3c_ccc_cmd cmd
;
1359 getbcr
= i3c_ccc_cmd_dest_init(&dest
, info
->dyn_addr
, sizeof(*getbcr
));
1363 i3c_ccc_cmd_init(&cmd
, true, I3C_CCC_GETBCR
, &dest
, 1);
1364 ret
= i3c_master_send_ccc_cmd_locked(master
, &cmd
);
1368 info
->bcr
= getbcr
->bcr
;
1371 i3c_ccc_cmd_dest_cleanup(&dest
);
1376 static int i3c_master_getdcr_locked(struct i3c_master_controller
*master
,
1377 struct i3c_device_info
*info
)
1379 struct i3c_ccc_getdcr
*getdcr
;
1380 struct i3c_ccc_cmd_dest dest
;
1381 struct i3c_ccc_cmd cmd
;
1384 getdcr
= i3c_ccc_cmd_dest_init(&dest
, info
->dyn_addr
, sizeof(*getdcr
));
1388 i3c_ccc_cmd_init(&cmd
, true, I3C_CCC_GETDCR
, &dest
, 1);
1389 ret
= i3c_master_send_ccc_cmd_locked(master
, &cmd
);
1393 info
->dcr
= getdcr
->dcr
;
1396 i3c_ccc_cmd_dest_cleanup(&dest
);
1401 static int i3c_master_retrieve_dev_info(struct i3c_dev_desc
*dev
)
1403 struct i3c_master_controller
*master
= i3c_dev_get_master(dev
);
1404 enum i3c_addr_slot_status slot_status
;
1407 if (!dev
->info
.dyn_addr
)
1410 slot_status
= i3c_bus_get_addr_slot_status(&master
->bus
,
1411 dev
->info
.dyn_addr
);
1412 if (slot_status
== I3C_ADDR_SLOT_RSVD
||
1413 slot_status
== I3C_ADDR_SLOT_I2C_DEV
)
1416 ret
= i3c_master_getpid_locked(master
, &dev
->info
);
1420 ret
= i3c_master_getbcr_locked(master
, &dev
->info
);
1424 ret
= i3c_master_getdcr_locked(master
, &dev
->info
);
1428 if (dev
->info
.bcr
& I3C_BCR_MAX_DATA_SPEED_LIM
) {
1429 ret
= i3c_master_getmxds_locked(master
, &dev
->info
);
1434 if (dev
->info
.bcr
& I3C_BCR_IBI_PAYLOAD
)
1435 dev
->info
.max_ibi_len
= 1;
1437 i3c_master_getmrl_locked(master
, &dev
->info
);
1438 i3c_master_getmwl_locked(master
, &dev
->info
);
1440 if (dev
->info
.bcr
& I3C_BCR_HDR_CAP
) {
1441 ret
= i3c_master_gethdrcap_locked(master
, &dev
->info
);
1449 static void i3c_master_put_i3c_addrs(struct i3c_dev_desc
*dev
)
1451 struct i3c_master_controller
*master
= i3c_dev_get_master(dev
);
1453 if (dev
->info
.static_addr
)
1454 i3c_bus_set_addr_slot_status(&master
->bus
,
1455 dev
->info
.static_addr
,
1456 I3C_ADDR_SLOT_FREE
);
1458 if (dev
->info
.dyn_addr
)
1459 i3c_bus_set_addr_slot_status(&master
->bus
, dev
->info
.dyn_addr
,
1460 I3C_ADDR_SLOT_FREE
);
1462 if (dev
->boardinfo
&& dev
->boardinfo
->init_dyn_addr
)
1463 i3c_bus_set_addr_slot_status(&master
->bus
, dev
->boardinfo
->init_dyn_addr
,
1464 I3C_ADDR_SLOT_FREE
);
1467 static int i3c_master_get_i3c_addrs(struct i3c_dev_desc
*dev
)
1469 struct i3c_master_controller
*master
= i3c_dev_get_master(dev
);
1470 enum i3c_addr_slot_status status
;
1472 if (!dev
->info
.static_addr
&& !dev
->info
.dyn_addr
)
1475 if (dev
->info
.static_addr
) {
1476 status
= i3c_bus_get_addr_slot_status(&master
->bus
,
1477 dev
->info
.static_addr
);
1478 /* Since static address and assigned dynamic address can be
1479 * equal, allow this case to pass.
1481 if (status
!= I3C_ADDR_SLOT_FREE
&&
1482 dev
->info
.static_addr
!= dev
->boardinfo
->init_dyn_addr
)
1485 i3c_bus_set_addr_slot_status(&master
->bus
,
1486 dev
->info
.static_addr
,
1487 I3C_ADDR_SLOT_I3C_DEV
);
1491 * ->init_dyn_addr should have been reserved before that, so, if we're
1492 * trying to apply a pre-reserved dynamic address, we should not try
1493 * to reserve the address slot a second time.
1495 if (dev
->info
.dyn_addr
&&
1497 dev
->boardinfo
->init_dyn_addr
!= dev
->info
.dyn_addr
)) {
1498 status
= i3c_bus_get_addr_slot_status(&master
->bus
,
1499 dev
->info
.dyn_addr
);
1500 if (status
!= I3C_ADDR_SLOT_FREE
)
1501 goto err_release_static_addr
;
1503 i3c_bus_set_addr_slot_status(&master
->bus
, dev
->info
.dyn_addr
,
1504 I3C_ADDR_SLOT_I3C_DEV
);
1509 err_release_static_addr
:
1510 if (dev
->info
.static_addr
)
1511 i3c_bus_set_addr_slot_status(&master
->bus
,
1512 dev
->info
.static_addr
,
1513 I3C_ADDR_SLOT_FREE
);
1518 static int i3c_master_attach_i3c_dev(struct i3c_master_controller
*master
,
1519 struct i3c_dev_desc
*dev
)
1524 * We don't attach devices to the controller until they are
1525 * addressable on the bus.
1527 if (!dev
->info
.static_addr
&& !dev
->info
.dyn_addr
)
1530 ret
= i3c_master_get_i3c_addrs(dev
);
1534 /* Do not attach the master device itself. */
1535 if (master
->this != dev
&& master
->ops
->attach_i3c_dev
) {
1536 ret
= master
->ops
->attach_i3c_dev(dev
);
1538 i3c_master_put_i3c_addrs(dev
);
1543 list_add_tail(&dev
->common
.node
, &master
->bus
.devs
.i3c
);
1548 static int i3c_master_reattach_i3c_dev(struct i3c_dev_desc
*dev
,
1551 struct i3c_master_controller
*master
= i3c_dev_get_master(dev
);
1554 if (dev
->info
.dyn_addr
!= old_dyn_addr
) {
1555 i3c_bus_set_addr_slot_status(&master
->bus
,
1557 I3C_ADDR_SLOT_I3C_DEV
);
1559 i3c_bus_set_addr_slot_status(&master
->bus
, old_dyn_addr
,
1560 I3C_ADDR_SLOT_FREE
);
1563 if (master
->ops
->reattach_i3c_dev
) {
1564 ret
= master
->ops
->reattach_i3c_dev(dev
, old_dyn_addr
);
1566 i3c_master_put_i3c_addrs(dev
);
1574 static void i3c_master_detach_i3c_dev(struct i3c_dev_desc
*dev
)
1576 struct i3c_master_controller
*master
= i3c_dev_get_master(dev
);
1578 /* Do not detach the master device itself. */
1579 if (master
->this != dev
&& master
->ops
->detach_i3c_dev
)
1580 master
->ops
->detach_i3c_dev(dev
);
1582 i3c_master_put_i3c_addrs(dev
);
1583 list_del(&dev
->common
.node
);
1586 static int i3c_master_attach_i2c_dev(struct i3c_master_controller
*master
,
1587 struct i2c_dev_desc
*dev
)
1591 if (master
->ops
->attach_i2c_dev
) {
1592 ret
= master
->ops
->attach_i2c_dev(dev
);
1597 list_add_tail(&dev
->common
.node
, &master
->bus
.devs
.i2c
);
1602 static void i3c_master_detach_i2c_dev(struct i2c_dev_desc
*dev
)
1604 struct i3c_master_controller
*master
= i2c_dev_get_master(dev
);
1606 list_del(&dev
->common
.node
);
1608 if (master
->ops
->detach_i2c_dev
)
1609 master
->ops
->detach_i2c_dev(dev
);
1612 static int i3c_master_early_i3c_dev_add(struct i3c_master_controller
*master
,
1613 struct i3c_dev_boardinfo
*boardinfo
)
1615 struct i3c_device_info info
= {
1616 .static_addr
= boardinfo
->static_addr
,
1617 .pid
= boardinfo
->pid
,
1619 struct i3c_dev_desc
*i3cdev
;
1622 i3cdev
= i3c_master_alloc_i3c_dev(master
, &info
);
1626 i3cdev
->boardinfo
= boardinfo
;
1628 ret
= i3c_master_attach_i3c_dev(master
, i3cdev
);
1632 ret
= i3c_master_setdasa_locked(master
, i3cdev
->info
.static_addr
,
1633 i3cdev
->boardinfo
->init_dyn_addr
);
1635 goto err_detach_dev
;
1637 i3cdev
->info
.dyn_addr
= i3cdev
->boardinfo
->init_dyn_addr
;
1638 ret
= i3c_master_reattach_i3c_dev(i3cdev
, 0);
1642 ret
= i3c_master_retrieve_dev_info(i3cdev
);
1649 i3c_master_rstdaa_locked(master
, i3cdev
->boardinfo
->init_dyn_addr
);
1651 i3c_master_detach_i3c_dev(i3cdev
);
1653 i3c_master_free_i3c_dev(i3cdev
);
1659 i3c_master_register_new_i3c_devs(struct i3c_master_controller
*master
)
1661 struct i3c_dev_desc
*desc
;
1664 if (!master
->init_done
)
1667 i3c_bus_for_each_i3cdev(&master
->bus
, desc
) {
1668 if (desc
->dev
|| !desc
->info
.dyn_addr
|| desc
== master
->this)
1671 desc
->dev
= kzalloc(sizeof(*desc
->dev
), GFP_KERNEL
);
1675 desc
->dev
->bus
= &master
->bus
;
1676 desc
->dev
->desc
= desc
;
1677 desc
->dev
->dev
.parent
= &master
->dev
;
1678 desc
->dev
->dev
.type
= &i3c_device_type
;
1679 desc
->dev
->dev
.bus
= &i3c_bus_type
;
1680 desc
->dev
->dev
.release
= i3c_device_release
;
1681 dev_set_name(&desc
->dev
->dev
, "%d-%llx", master
->bus
.id
,
1684 if (desc
->boardinfo
)
1685 desc
->dev
->dev
.of_node
= desc
->boardinfo
->of_node
;
1687 ret
= device_register(&desc
->dev
->dev
);
1689 dev_err(&master
->dev
,
1690 "Failed to add I3C device (err = %d)\n", ret
);
1691 put_device(&desc
->dev
->dev
);
1697 * i3c_master_do_daa() - do a DAA (Dynamic Address Assignment)
1698 * @master: master doing the DAA
1700 * This function is instantiating an I3C device object and adding it to the
1701 * I3C device list. All device information are automatically retrieved using
1702 * standard CCC commands.
1704 * The I3C device object is returned in case the master wants to attach
1705 * private data to it using i3c_dev_set_master_data().
1707 * This function must be called with the bus lock held in write mode.
1709 * Return: a 0 in case of success, an negative error code otherwise.
1711 int i3c_master_do_daa(struct i3c_master_controller
*master
)
1715 i3c_bus_maintenance_lock(&master
->bus
);
1716 ret
= master
->ops
->do_daa(master
);
1717 i3c_bus_maintenance_unlock(&master
->bus
);
1722 i3c_bus_normaluse_lock(&master
->bus
);
1723 i3c_master_register_new_i3c_devs(master
);
1724 i3c_bus_normaluse_unlock(&master
->bus
);
1728 EXPORT_SYMBOL_GPL(i3c_master_do_daa
);
1731 * i3c_master_set_info() - set master device information
1732 * @master: master used to send frames on the bus
1733 * @info: I3C device information
1735 * Set master device info. This should be called from
1736 * &i3c_master_controller_ops->bus_init().
1738 * Not all &i3c_device_info fields are meaningful for a master device.
1739 * Here is a list of fields that should be properly filled:
1741 * - &i3c_device_info->dyn_addr
1742 * - &i3c_device_info->bcr
1743 * - &i3c_device_info->dcr
1744 * - &i3c_device_info->pid
1745 * - &i3c_device_info->hdr_cap if %I3C_BCR_HDR_CAP bit is set in
1746 * &i3c_device_info->bcr
1748 * This function must be called with the bus lock held in maintenance mode.
1750 * Return: 0 if @info contains valid information (not every piece of
1751 * information can be checked, but we can at least make sure @info->dyn_addr
1752 * and @info->bcr are correct), -EINVAL otherwise.
1754 int i3c_master_set_info(struct i3c_master_controller
*master
,
1755 const struct i3c_device_info
*info
)
1757 struct i3c_dev_desc
*i3cdev
;
1760 if (!i3c_bus_dev_addr_is_avail(&master
->bus
, info
->dyn_addr
))
1763 if (I3C_BCR_DEVICE_ROLE(info
->bcr
) == I3C_BCR_I3C_MASTER
&&
1770 i3cdev
= i3c_master_alloc_i3c_dev(master
, info
);
1772 return PTR_ERR(i3cdev
);
1774 master
->this = i3cdev
;
1775 master
->bus
.cur_master
= master
->this;
1777 ret
= i3c_master_attach_i3c_dev(master
, i3cdev
);
1784 i3c_master_free_i3c_dev(i3cdev
);
1788 EXPORT_SYMBOL_GPL(i3c_master_set_info
);
1790 static void i3c_master_detach_free_devs(struct i3c_master_controller
*master
)
1792 struct i3c_dev_desc
*i3cdev
, *i3ctmp
;
1793 struct i2c_dev_desc
*i2cdev
, *i2ctmp
;
1795 list_for_each_entry_safe(i3cdev
, i3ctmp
, &master
->bus
.devs
.i3c
,
1797 i3c_master_detach_i3c_dev(i3cdev
);
1799 if (i3cdev
->boardinfo
&& i3cdev
->boardinfo
->init_dyn_addr
)
1800 i3c_bus_set_addr_slot_status(&master
->bus
,
1801 i3cdev
->boardinfo
->init_dyn_addr
,
1802 I3C_ADDR_SLOT_FREE
);
1804 i3c_master_free_i3c_dev(i3cdev
);
1807 list_for_each_entry_safe(i2cdev
, i2ctmp
, &master
->bus
.devs
.i2c
,
1809 i3c_master_detach_i2c_dev(i2cdev
);
1810 i3c_bus_set_addr_slot_status(&master
->bus
,
1812 I3C_ADDR_SLOT_FREE
);
1813 i3c_master_free_i2c_dev(i2cdev
);
1818 * i3c_master_bus_init() - initialize an I3C bus
1819 * @master: main master initializing the bus
1821 * This function is following all initialisation steps described in the I3C
1824 * 1. Attach I2C devs to the master so that the master can fill its internal
1825 * device table appropriately
1827 * 2. Call &i3c_master_controller_ops->bus_init() method to initialize
1828 * the master controller. That's usually where the bus mode is selected
1829 * (pure bus or mixed fast/slow bus)
1831 * 3. Instruct all devices on the bus to drop their dynamic address. This is
1832 * particularly important when the bus was previously configured by someone
1833 * else (for example the bootloader)
1835 * 4. Disable all slave events.
1837 * 5. Reserve address slots for I3C devices with init_dyn_addr. And if devices
1838 * also have static_addr, try to pre-assign dynamic addresses requested by
1839 * the FW with SETDASA and attach corresponding statically defined I3C
1840 * devices to the master.
1842 * 6. Do a DAA (Dynamic Address Assignment) to assign dynamic addresses to all
1843 * remaining I3C devices
1845 * Once this is done, all I3C and I2C devices should be usable.
1847 * Return: a 0 in case of success, an negative error code otherwise.
1849 static int i3c_master_bus_init(struct i3c_master_controller
*master
)
1851 enum i3c_addr_slot_status status
;
1852 struct i2c_dev_boardinfo
*i2cboardinfo
;
1853 struct i3c_dev_boardinfo
*i3cboardinfo
;
1854 struct i2c_dev_desc
*i2cdev
;
1858 * First attach all devices with static definitions provided by the
1861 list_for_each_entry(i2cboardinfo
, &master
->boardinfo
.i2c
, node
) {
1862 status
= i3c_bus_get_addr_slot_status(&master
->bus
,
1863 i2cboardinfo
->base
.addr
);
1864 if (status
!= I3C_ADDR_SLOT_FREE
) {
1866 goto err_detach_devs
;
1869 i3c_bus_set_addr_slot_status(&master
->bus
,
1870 i2cboardinfo
->base
.addr
,
1871 I3C_ADDR_SLOT_I2C_DEV
);
1873 i2cdev
= i3c_master_alloc_i2c_dev(master
,
1874 i2cboardinfo
->base
.addr
,
1876 if (IS_ERR(i2cdev
)) {
1877 ret
= PTR_ERR(i2cdev
);
1878 goto err_detach_devs
;
1881 ret
= i3c_master_attach_i2c_dev(master
, i2cdev
);
1883 i3c_master_free_i2c_dev(i2cdev
);
1884 goto err_detach_devs
;
1889 * Now execute the controller specific ->bus_init() routine, which
1890 * might configure its internal logic to match the bus limitations.
1892 ret
= master
->ops
->bus_init(master
);
1894 goto err_detach_devs
;
1897 * The master device should have been instantiated in ->bus_init(),
1898 * complain if this was not the case.
1900 if (!master
->this) {
1901 dev_err(&master
->dev
,
1902 "master_set_info() was not called in ->bus_init()\n");
1904 goto err_bus_cleanup
;
1907 if (master
->ops
->set_speed
) {
1908 ret
= master
->ops
->set_speed(master
, I3C_OPEN_DRAIN_SLOW_SPEED
);
1910 goto err_bus_cleanup
;
1914 * Reset all dynamic address that may have been assigned before
1915 * (assigned by the bootloader for example).
1917 ret
= i3c_master_rstdaa_locked(master
, I3C_BROADCAST_ADDR
);
1918 if (ret
&& ret
!= I3C_ERROR_M2
)
1919 goto err_bus_cleanup
;
1921 if (master
->ops
->set_speed
) {
1922 master
->ops
->set_speed(master
, I3C_OPEN_DRAIN_NORMAL_SPEED
);
1924 goto err_bus_cleanup
;
1927 /* Disable all slave events before starting DAA. */
1928 ret
= i3c_master_disec_locked(master
, I3C_BROADCAST_ADDR
,
1929 I3C_CCC_EVENT_SIR
| I3C_CCC_EVENT_MR
|
1931 if (ret
&& ret
!= I3C_ERROR_M2
)
1932 goto err_bus_cleanup
;
1935 * Reserve init_dyn_addr first, and then try to pre-assign dynamic
1936 * address and retrieve device information if needed.
1937 * In case pre-assign dynamic address fails, setting dynamic address to
1938 * the requested init_dyn_addr is retried after DAA is done in
1939 * i3c_master_add_i3c_dev_locked().
1941 list_for_each_entry(i3cboardinfo
, &master
->boardinfo
.i3c
, node
) {
1944 * We don't reserve a dynamic address for devices that
1945 * don't explicitly request one.
1947 if (!i3cboardinfo
->init_dyn_addr
)
1950 ret
= i3c_bus_get_addr_slot_status(&master
->bus
,
1951 i3cboardinfo
->init_dyn_addr
);
1952 if (ret
!= I3C_ADDR_SLOT_FREE
) {
1957 /* Do not mark as occupied until real device exist in bus */
1958 i3c_bus_set_addr_slot_status_mask(&master
->bus
,
1959 i3cboardinfo
->init_dyn_addr
,
1960 I3C_ADDR_SLOT_EXT_DESIRED
,
1961 I3C_ADDR_SLOT_EXT_STATUS_MASK
);
1964 * Only try to create/attach devices that have a static
1965 * address. Other devices will be created/attached when
1966 * DAA happens, and the requested dynamic address will
1967 * be set using SETNEWDA once those devices become
1971 if (i3cboardinfo
->static_addr
)
1972 i3c_master_early_i3c_dev_add(master
, i3cboardinfo
);
1975 ret
= i3c_master_do_daa(master
);
1982 i3c_master_rstdaa_locked(master
, I3C_BROADCAST_ADDR
);
1985 if (master
->ops
->bus_cleanup
)
1986 master
->ops
->bus_cleanup(master
);
1989 i3c_master_detach_free_devs(master
);
1994 static void i3c_master_bus_cleanup(struct i3c_master_controller
*master
)
1996 if (master
->ops
->bus_cleanup
)
1997 master
->ops
->bus_cleanup(master
);
1999 i3c_master_detach_free_devs(master
);
2002 static void i3c_master_attach_boardinfo(struct i3c_dev_desc
*i3cdev
)
2004 struct i3c_master_controller
*master
= i3cdev
->common
.master
;
2005 struct i3c_dev_boardinfo
*i3cboardinfo
;
2007 list_for_each_entry(i3cboardinfo
, &master
->boardinfo
.i3c
, node
) {
2008 if (i3cdev
->info
.pid
!= i3cboardinfo
->pid
)
2011 i3cdev
->boardinfo
= i3cboardinfo
;
2012 i3cdev
->info
.static_addr
= i3cboardinfo
->static_addr
;
2017 static struct i3c_dev_desc
*
2018 i3c_master_search_i3c_dev_duplicate(struct i3c_dev_desc
*refdev
)
2020 struct i3c_master_controller
*master
= i3c_dev_get_master(refdev
);
2021 struct i3c_dev_desc
*i3cdev
;
2023 i3c_bus_for_each_i3cdev(&master
->bus
, i3cdev
) {
2024 if (i3cdev
!= refdev
&& i3cdev
->info
.pid
== refdev
->info
.pid
)
2032 * i3c_master_add_i3c_dev_locked() - add an I3C slave to the bus
2033 * @master: master used to send frames on the bus
2034 * @addr: I3C slave dynamic address assigned to the device
2036 * This function is instantiating an I3C device object and adding it to the
2037 * I3C device list. All device information are automatically retrieved using
2038 * standard CCC commands.
2040 * The I3C device object is returned in case the master wants to attach
2041 * private data to it using i3c_dev_set_master_data().
2043 * This function must be called with the bus lock held in write mode.
2045 * Return: a 0 in case of success, an negative error code otherwise.
2047 int i3c_master_add_i3c_dev_locked(struct i3c_master_controller
*master
,
2050 struct i3c_device_info info
= { .dyn_addr
= addr
};
2051 struct i3c_dev_desc
*newdev
, *olddev
;
2052 u8 old_dyn_addr
= addr
, expected_dyn_addr
;
2053 struct i3c_ibi_setup ibireq
= { };
2054 bool enable_ibi
= false;
2060 newdev
= i3c_master_alloc_i3c_dev(master
, &info
);
2062 return PTR_ERR(newdev
);
2064 ret
= i3c_master_attach_i3c_dev(master
, newdev
);
2068 ret
= i3c_master_retrieve_dev_info(newdev
);
2070 goto err_detach_dev
;
2072 i3c_master_attach_boardinfo(newdev
);
2074 olddev
= i3c_master_search_i3c_dev_duplicate(newdev
);
2076 newdev
->dev
= olddev
->dev
;
2078 newdev
->dev
->desc
= newdev
;
2081 * We need to restore the IBI state too, so let's save the
2082 * IBI information and try to restore them after olddev has
2083 * been detached+released and its IBI has been stopped and
2084 * the associated resources have been freed.
2086 mutex_lock(&olddev
->ibi_lock
);
2088 ibireq
.handler
= olddev
->ibi
->handler
;
2089 ibireq
.max_payload_len
= olddev
->ibi
->max_payload_len
;
2090 ibireq
.num_slots
= olddev
->ibi
->num_slots
;
2092 if (olddev
->ibi
->enabled
)
2095 * The olddev should not receive any commands on the
2096 * i3c bus as it does not exist and has been assigned
2097 * a new address. This will result in NACK or timeout.
2098 * So, update the olddev->ibi->enabled flag to false
2099 * to avoid DISEC with OldAddr.
2101 olddev
->ibi
->enabled
= false;
2102 i3c_dev_free_ibi_locked(olddev
);
2104 mutex_unlock(&olddev
->ibi_lock
);
2106 old_dyn_addr
= olddev
->info
.dyn_addr
;
2108 i3c_master_detach_i3c_dev(olddev
);
2109 i3c_master_free_i3c_dev(olddev
);
2113 * Depending on our previous state, the expected dynamic address might
2115 * - if the device already had a dynamic address assigned, let's try to
2117 * - if the device did not have a dynamic address and the firmware
2118 * requested a specific address, pick this one
2119 * - in any other case, keep the address automatically assigned by the
2122 if (old_dyn_addr
&& old_dyn_addr
!= newdev
->info
.dyn_addr
)
2123 expected_dyn_addr
= old_dyn_addr
;
2124 else if (newdev
->boardinfo
&& newdev
->boardinfo
->init_dyn_addr
)
2125 expected_dyn_addr
= newdev
->boardinfo
->init_dyn_addr
;
2127 expected_dyn_addr
= newdev
->info
.dyn_addr
;
2129 if (newdev
->info
.dyn_addr
!= expected_dyn_addr
&&
2130 i3c_bus_get_addr_slot_status(&master
->bus
, expected_dyn_addr
) == I3C_ADDR_SLOT_FREE
) {
2132 * Try to apply the expected dynamic address. If it fails, keep
2133 * the address assigned by the master.
2135 ret
= i3c_master_setnewda_locked(master
,
2136 newdev
->info
.dyn_addr
,
2139 old_dyn_addr
= newdev
->info
.dyn_addr
;
2140 newdev
->info
.dyn_addr
= expected_dyn_addr
;
2141 i3c_master_reattach_i3c_dev(newdev
, old_dyn_addr
);
2143 dev_err(&master
->dev
,
2144 "Failed to assign reserved/old address to device %d%llx",
2145 master
->bus
.id
, newdev
->info
.pid
);
2150 * Now is time to try to restore the IBI setup. If we're lucky,
2151 * everything works as before, otherwise, all we can do is complain.
2152 * FIXME: maybe we should add callback to inform the driver that it
2153 * should request the IBI again instead of trying to hide that from
2156 if (ibireq
.handler
) {
2157 mutex_lock(&newdev
->ibi_lock
);
2158 ret
= i3c_dev_request_ibi_locked(newdev
, &ibireq
);
2160 dev_err(&master
->dev
,
2161 "Failed to request IBI on device %d-%llx",
2162 master
->bus
.id
, newdev
->info
.pid
);
2163 } else if (enable_ibi
) {
2164 ret
= i3c_dev_enable_ibi_locked(newdev
);
2166 dev_err(&master
->dev
,
2167 "Failed to re-enable IBI on device %d-%llx",
2168 master
->bus
.id
, newdev
->info
.pid
);
2170 mutex_unlock(&newdev
->ibi_lock
);
2176 if (newdev
->dev
&& newdev
->dev
->desc
)
2177 newdev
->dev
->desc
= NULL
;
2179 i3c_master_detach_i3c_dev(newdev
);
2182 i3c_master_free_i3c_dev(newdev
);
2186 EXPORT_SYMBOL_GPL(i3c_master_add_i3c_dev_locked
);
2188 #define OF_I3C_REG1_IS_I2C_DEV BIT(31)
2191 of_i3c_master_add_i2c_boardinfo(struct i3c_master_controller
*master
,
2192 struct device_node
*node
, u32
*reg
)
2194 struct i2c_dev_boardinfo
*boardinfo
;
2195 struct device
*dev
= &master
->dev
;
2198 boardinfo
= devm_kzalloc(dev
, sizeof(*boardinfo
), GFP_KERNEL
);
2202 ret
= of_i2c_get_board_info(dev
, node
, &boardinfo
->base
);
2207 * The I3C Specification does not clearly say I2C devices with 10-bit
2208 * address are supported. These devices can't be passed properly through
2211 if (boardinfo
->base
.flags
& I2C_CLIENT_TEN
) {
2212 dev_err(dev
, "I2C device with 10 bit address not supported.");
2216 /* LVR is encoded in reg[2]. */
2217 boardinfo
->lvr
= reg
[2];
2219 list_add_tail(&boardinfo
->node
, &master
->boardinfo
.i2c
);
2226 of_i3c_master_add_i3c_boardinfo(struct i3c_master_controller
*master
,
2227 struct device_node
*node
, u32
*reg
)
2229 struct i3c_dev_boardinfo
*boardinfo
;
2230 struct device
*dev
= &master
->dev
;
2231 enum i3c_addr_slot_status addrstatus
;
2232 u32 init_dyn_addr
= 0;
2234 boardinfo
= devm_kzalloc(dev
, sizeof(*boardinfo
), GFP_KERNEL
);
2239 if (reg
[0] > I3C_MAX_ADDR
)
2242 addrstatus
= i3c_bus_get_addr_slot_status(&master
->bus
,
2244 if (addrstatus
!= I3C_ADDR_SLOT_FREE
)
2248 boardinfo
->static_addr
= reg
[0];
2250 if (!of_property_read_u32(node
, "assigned-address", &init_dyn_addr
)) {
2251 if (init_dyn_addr
> I3C_MAX_ADDR
)
2254 addrstatus
= i3c_bus_get_addr_slot_status(&master
->bus
,
2256 if (addrstatus
!= I3C_ADDR_SLOT_FREE
)
2260 boardinfo
->pid
= ((u64
)reg
[1] << 32) | reg
[2];
2262 if ((boardinfo
->pid
& GENMASK_ULL(63, 48)) ||
2263 I3C_PID_RND_LOWER_32BITS(boardinfo
->pid
))
2266 boardinfo
->init_dyn_addr
= init_dyn_addr
;
2267 boardinfo
->of_node
= of_node_get(node
);
2268 list_add_tail(&boardinfo
->node
, &master
->boardinfo
.i3c
);
2273 static int of_i3c_master_add_dev(struct i3c_master_controller
*master
,
2274 struct device_node
*node
)
2279 if (!master
|| !node
)
2282 ret
= of_property_read_u32_array(node
, "reg", reg
, ARRAY_SIZE(reg
));
2287 * The manufacturer ID can't be 0. If reg[1] == 0 that means we're
2288 * dealing with an I2C device.
2291 ret
= of_i3c_master_add_i2c_boardinfo(master
, node
, reg
);
2293 ret
= of_i3c_master_add_i3c_boardinfo(master
, node
, reg
);
2298 static int of_populate_i3c_bus(struct i3c_master_controller
*master
)
2300 struct device
*dev
= &master
->dev
;
2301 struct device_node
*i3cbus_np
= dev
->of_node
;
2302 struct device_node
*node
;
2309 for_each_available_child_of_node(i3cbus_np
, node
) {
2310 ret
= of_i3c_master_add_dev(master
, node
);
2318 * The user might want to limit I2C and I3C speed in case some devices
2319 * on the bus are not supporting typical rates, or if the bus topology
2320 * prevents it from using max possible rate.
2322 if (!of_property_read_u32(i3cbus_np
, "i2c-scl-hz", &val
))
2323 master
->bus
.scl_rate
.i2c
= val
;
2325 if (!of_property_read_u32(i3cbus_np
, "i3c-scl-hz", &val
))
2326 master
->bus
.scl_rate
.i3c
= val
;
2331 static int i3c_master_i2c_adapter_xfer(struct i2c_adapter
*adap
,
2332 struct i2c_msg
*xfers
, int nxfers
)
2334 struct i3c_master_controller
*master
= i2c_adapter_to_i3c_master(adap
);
2335 struct i2c_dev_desc
*dev
;
2339 if (!xfers
|| !master
|| nxfers
<= 0)
2342 if (!master
->ops
->i2c_xfers
)
2345 /* Doing transfers to different devices is not supported. */
2346 addr
= xfers
[0].addr
;
2347 for (i
= 1; i
< nxfers
; i
++) {
2348 if (addr
!= xfers
[i
].addr
)
2352 i3c_bus_normaluse_lock(&master
->bus
);
2353 dev
= i3c_master_find_i2c_dev_by_addr(master
, addr
);
2357 ret
= master
->ops
->i2c_xfers(dev
, xfers
, nxfers
);
2358 i3c_bus_normaluse_unlock(&master
->bus
);
2360 return ret
? ret
: nxfers
;
2363 static u32
i3c_master_i2c_funcs(struct i2c_adapter
*adapter
)
2365 return I2C_FUNC_SMBUS_EMUL
| I2C_FUNC_I2C
;
2368 static u8
i3c_master_i2c_get_lvr(struct i2c_client
*client
)
2370 /* Fall back to no spike filters and FM bus mode. */
2371 u8 lvr
= I3C_LVR_I2C_INDEX(2) | I3C_LVR_I2C_FM_MODE
;
2373 if (client
->dev
.of_node
) {
2376 if (!of_property_read_u32_array(client
->dev
.of_node
, "reg",
2377 reg
, ARRAY_SIZE(reg
)))
2384 static int i3c_master_i2c_attach(struct i2c_adapter
*adap
, struct i2c_client
*client
)
2386 struct i3c_master_controller
*master
= i2c_adapter_to_i3c_master(adap
);
2387 enum i3c_addr_slot_status status
;
2388 struct i2c_dev_desc
*i2cdev
;
2391 /* Already added by board info? */
2392 if (i3c_master_find_i2c_dev_by_addr(master
, client
->addr
))
2395 status
= i3c_bus_get_addr_slot_status(&master
->bus
, client
->addr
);
2396 if (status
!= I3C_ADDR_SLOT_FREE
)
2399 i3c_bus_set_addr_slot_status(&master
->bus
, client
->addr
,
2400 I3C_ADDR_SLOT_I2C_DEV
);
2402 i2cdev
= i3c_master_alloc_i2c_dev(master
, client
->addr
,
2403 i3c_master_i2c_get_lvr(client
));
2404 if (IS_ERR(i2cdev
)) {
2405 ret
= PTR_ERR(i2cdev
);
2406 goto out_clear_status
;
2409 ret
= i3c_master_attach_i2c_dev(master
, i2cdev
);
2416 i3c_master_free_i2c_dev(i2cdev
);
2418 i3c_bus_set_addr_slot_status(&master
->bus
, client
->addr
,
2419 I3C_ADDR_SLOT_FREE
);
2424 static int i3c_master_i2c_detach(struct i2c_adapter
*adap
, struct i2c_client
*client
)
2426 struct i3c_master_controller
*master
= i2c_adapter_to_i3c_master(adap
);
2427 struct i2c_dev_desc
*dev
;
2429 dev
= i3c_master_find_i2c_dev_by_addr(master
, client
->addr
);
2433 i3c_master_detach_i2c_dev(dev
);
2434 i3c_bus_set_addr_slot_status(&master
->bus
, dev
->addr
,
2435 I3C_ADDR_SLOT_FREE
);
2436 i3c_master_free_i2c_dev(dev
);
2441 static const struct i2c_algorithm i3c_master_i2c_algo
= {
2442 .master_xfer
= i3c_master_i2c_adapter_xfer
,
2443 .functionality
= i3c_master_i2c_funcs
,
2446 static int i3c_i2c_notifier_call(struct notifier_block
*nb
, unsigned long action
,
2449 struct i2c_adapter
*adap
;
2450 struct i2c_client
*client
;
2451 struct device
*dev
= data
;
2452 struct i3c_master_controller
*master
;
2455 if (dev
->type
!= &i2c_client_type
)
2458 client
= to_i2c_client(dev
);
2459 adap
= client
->adapter
;
2461 if (adap
->algo
!= &i3c_master_i2c_algo
)
2464 master
= i2c_adapter_to_i3c_master(adap
);
2466 i3c_bus_maintenance_lock(&master
->bus
);
2468 case BUS_NOTIFY_ADD_DEVICE
:
2469 ret
= i3c_master_i2c_attach(adap
, client
);
2471 case BUS_NOTIFY_DEL_DEVICE
:
2472 ret
= i3c_master_i2c_detach(adap
, client
);
2475 i3c_bus_maintenance_unlock(&master
->bus
);
2480 static struct notifier_block i2cdev_notifier
= {
2481 .notifier_call
= i3c_i2c_notifier_call
,
2484 static int i3c_master_i2c_adapter_init(struct i3c_master_controller
*master
)
2486 struct i2c_adapter
*adap
= i3c_master_to_i2c_adapter(master
);
2487 struct i2c_dev_desc
*i2cdev
;
2488 struct i2c_dev_boardinfo
*i2cboardinfo
;
2491 adap
->dev
.parent
= master
->dev
.parent
;
2492 adap
->owner
= master
->dev
.parent
->driver
->owner
;
2493 adap
->algo
= &i3c_master_i2c_algo
;
2494 strscpy(adap
->name
, dev_name(master
->dev
.parent
), sizeof(adap
->name
));
2496 /* FIXME: Should we allow i3c masters to override these values? */
2497 adap
->timeout
= 1000;
2500 ret
= i2c_add_adapter(adap
);
2505 * We silently ignore failures here. The bus should keep working
2506 * correctly even if one or more i2c devices are not registered.
2508 list_for_each_entry(i2cboardinfo
, &master
->boardinfo
.i2c
, node
) {
2509 i2cdev
= i3c_master_find_i2c_dev_by_addr(master
,
2510 i2cboardinfo
->base
.addr
);
2511 if (WARN_ON(!i2cdev
))
2513 i2cdev
->dev
= i2c_new_client_device(adap
, &i2cboardinfo
->base
);
2519 static void i3c_master_i2c_adapter_cleanup(struct i3c_master_controller
*master
)
2521 struct i2c_dev_desc
*i2cdev
;
2523 i2c_del_adapter(&master
->i2c
);
2525 i3c_bus_for_each_i2cdev(&master
->bus
, i2cdev
)
2529 static void i3c_master_unregister_i3c_devs(struct i3c_master_controller
*master
)
2531 struct i3c_dev_desc
*i3cdev
;
2533 i3c_bus_for_each_i3cdev(&master
->bus
, i3cdev
) {
2537 i3cdev
->dev
->desc
= NULL
;
2538 if (device_is_registered(&i3cdev
->dev
->dev
))
2539 device_unregister(&i3cdev
->dev
->dev
);
2541 put_device(&i3cdev
->dev
->dev
);
2547 * i3c_master_queue_ibi() - Queue an IBI
2548 * @dev: the device this IBI is coming from
2549 * @slot: the IBI slot used to store the payload
2551 * Queue an IBI to the controller workqueue. The IBI handler attached to
2552 * the dev will be called from a workqueue context.
2554 void i3c_master_queue_ibi(struct i3c_dev_desc
*dev
, struct i3c_ibi_slot
*slot
)
2556 atomic_inc(&dev
->ibi
->pending_ibis
);
2557 queue_work(dev
->ibi
->wq
, &slot
->work
);
2559 EXPORT_SYMBOL_GPL(i3c_master_queue_ibi
);
2561 static void i3c_master_handle_ibi(struct work_struct
*work
)
2563 struct i3c_ibi_slot
*slot
= container_of(work
, struct i3c_ibi_slot
,
2565 struct i3c_dev_desc
*dev
= slot
->dev
;
2566 struct i3c_master_controller
*master
= i3c_dev_get_master(dev
);
2567 struct i3c_ibi_payload payload
;
2569 payload
.data
= slot
->data
;
2570 payload
.len
= slot
->len
;
2573 dev
->ibi
->handler(dev
->dev
, &payload
);
2575 master
->ops
->recycle_ibi_slot(dev
, slot
);
2576 if (atomic_dec_and_test(&dev
->ibi
->pending_ibis
))
2577 complete(&dev
->ibi
->all_ibis_handled
);
2580 static void i3c_master_init_ibi_slot(struct i3c_dev_desc
*dev
,
2581 struct i3c_ibi_slot
*slot
)
2584 INIT_WORK(&slot
->work
, i3c_master_handle_ibi
);
2587 struct i3c_generic_ibi_slot
{
2588 struct list_head node
;
2589 struct i3c_ibi_slot base
;
2592 struct i3c_generic_ibi_pool
{
2594 unsigned int num_slots
;
2595 struct i3c_generic_ibi_slot
*slots
;
2597 struct list_head free_slots
;
2598 struct list_head pending
;
2602 * i3c_generic_ibi_free_pool() - Free a generic IBI pool
2603 * @pool: the IBI pool to free
2605 * Free all IBI slots allated by a generic IBI pool.
2607 void i3c_generic_ibi_free_pool(struct i3c_generic_ibi_pool
*pool
)
2609 struct i3c_generic_ibi_slot
*slot
;
2610 unsigned int nslots
= 0;
2612 while (!list_empty(&pool
->free_slots
)) {
2613 slot
= list_first_entry(&pool
->free_slots
,
2614 struct i3c_generic_ibi_slot
, node
);
2615 list_del(&slot
->node
);
2620 * If the number of freed slots is not equal to the number of allocated
2621 * slots we have a leak somewhere.
2623 WARN_ON(nslots
!= pool
->num_slots
);
2625 kfree(pool
->payload_buf
);
2629 EXPORT_SYMBOL_GPL(i3c_generic_ibi_free_pool
);
2632 * i3c_generic_ibi_alloc_pool() - Create a generic IBI pool
2633 * @dev: the device this pool will be used for
2634 * @req: IBI setup request describing what the device driver expects
2636 * Create a generic IBI pool based on the information provided in @req.
2638 * Return: a valid IBI pool in case of success, an ERR_PTR() otherwise.
2640 struct i3c_generic_ibi_pool
*
2641 i3c_generic_ibi_alloc_pool(struct i3c_dev_desc
*dev
,
2642 const struct i3c_ibi_setup
*req
)
2644 struct i3c_generic_ibi_pool
*pool
;
2645 struct i3c_generic_ibi_slot
*slot
;
2649 pool
= kzalloc(sizeof(*pool
), GFP_KERNEL
);
2651 return ERR_PTR(-ENOMEM
);
2653 spin_lock_init(&pool
->lock
);
2654 INIT_LIST_HEAD(&pool
->free_slots
);
2655 INIT_LIST_HEAD(&pool
->pending
);
2657 pool
->slots
= kcalloc(req
->num_slots
, sizeof(*slot
), GFP_KERNEL
);
2663 if (req
->max_payload_len
) {
2664 pool
->payload_buf
= kcalloc(req
->num_slots
,
2665 req
->max_payload_len
, GFP_KERNEL
);
2666 if (!pool
->payload_buf
) {
2672 for (i
= 0; i
< req
->num_slots
; i
++) {
2673 slot
= &pool
->slots
[i
];
2674 i3c_master_init_ibi_slot(dev
, &slot
->base
);
2676 if (req
->max_payload_len
)
2677 slot
->base
.data
= pool
->payload_buf
+
2678 (i
* req
->max_payload_len
);
2680 list_add_tail(&slot
->node
, &pool
->free_slots
);
2687 i3c_generic_ibi_free_pool(pool
);
2688 return ERR_PTR(ret
);
2690 EXPORT_SYMBOL_GPL(i3c_generic_ibi_alloc_pool
);
2693 * i3c_generic_ibi_get_free_slot() - Get a free slot from a generic IBI pool
2694 * @pool: the pool to query an IBI slot on
2696 * Search for a free slot in a generic IBI pool.
2697 * The slot should be returned to the pool using i3c_generic_ibi_recycle_slot()
2698 * when it's no longer needed.
2700 * Return: a pointer to a free slot, or NULL if there's no free slot available.
2702 struct i3c_ibi_slot
*
2703 i3c_generic_ibi_get_free_slot(struct i3c_generic_ibi_pool
*pool
)
2705 struct i3c_generic_ibi_slot
*slot
;
2706 unsigned long flags
;
2708 spin_lock_irqsave(&pool
->lock
, flags
);
2709 slot
= list_first_entry_or_null(&pool
->free_slots
,
2710 struct i3c_generic_ibi_slot
, node
);
2712 list_del(&slot
->node
);
2713 spin_unlock_irqrestore(&pool
->lock
, flags
);
2715 return slot
? &slot
->base
: NULL
;
2717 EXPORT_SYMBOL_GPL(i3c_generic_ibi_get_free_slot
);
2720 * i3c_generic_ibi_recycle_slot() - Return a slot to a generic IBI pool
2721 * @pool: the pool to return the IBI slot to
2722 * @s: IBI slot to recycle
2724 * Add an IBI slot back to its generic IBI pool. Should be called from the
2725 * master driver struct_master_controller_ops->recycle_ibi() method.
2727 void i3c_generic_ibi_recycle_slot(struct i3c_generic_ibi_pool
*pool
,
2728 struct i3c_ibi_slot
*s
)
2730 struct i3c_generic_ibi_slot
*slot
;
2731 unsigned long flags
;
2736 slot
= container_of(s
, struct i3c_generic_ibi_slot
, base
);
2737 spin_lock_irqsave(&pool
->lock
, flags
);
2738 list_add_tail(&slot
->node
, &pool
->free_slots
);
2739 spin_unlock_irqrestore(&pool
->lock
, flags
);
2741 EXPORT_SYMBOL_GPL(i3c_generic_ibi_recycle_slot
);
2743 static int i3c_master_check_ops(const struct i3c_master_controller_ops
*ops
)
2745 if (!ops
|| !ops
->bus_init
|| !ops
->priv_xfers
||
2746 !ops
->send_ccc_cmd
|| !ops
->do_daa
|| !ops
->i2c_xfers
)
2749 if (ops
->request_ibi
&&
2750 (!ops
->enable_ibi
|| !ops
->disable_ibi
|| !ops
->free_ibi
||
2751 !ops
->recycle_ibi_slot
))
2758 * i3c_master_register() - register an I3C master
2759 * @master: master used to send frames on the bus
2760 * @parent: the parent device (the one that provides this I3C master
2762 * @ops: the master controller operations
2763 * @secondary: true if you are registering a secondary master. Will return
2764 * -ENOTSUPP if set to true since secondary masters are not yet
2767 * This function takes care of everything for you:
2769 * - creates and initializes the I3C bus
2770 * - populates the bus with static I2C devs if @parent->of_node is not
2772 * - registers all I3C devices added by the controller during bus
2774 * - registers the I2C adapter and all I2C devices
2776 * Return: 0 in case of success, a negative error code otherwise.
2778 int i3c_master_register(struct i3c_master_controller
*master
,
2779 struct device
*parent
,
2780 const struct i3c_master_controller_ops
*ops
,
2783 unsigned long i2c_scl_rate
= I3C_BUS_I2C_FM_PLUS_SCL_RATE
;
2784 struct i3c_bus
*i3cbus
= i3c_master_get_bus(master
);
2785 enum i3c_bus_mode mode
= I3C_BUS_MODE_PURE
;
2786 struct i2c_dev_boardinfo
*i2cbi
;
2789 /* We do not support secondary masters yet. */
2793 ret
= i3c_master_check_ops(ops
);
2797 master
->dev
.parent
= parent
;
2798 master
->dev
.of_node
= of_node_get(parent
->of_node
);
2799 master
->dev
.bus
= &i3c_bus_type
;
2800 master
->dev
.type
= &i3c_masterdev_type
;
2801 master
->dev
.release
= i3c_masterdev_release
;
2803 master
->secondary
= secondary
;
2804 INIT_LIST_HEAD(&master
->boardinfo
.i2c
);
2805 INIT_LIST_HEAD(&master
->boardinfo
.i3c
);
2807 ret
= i3c_bus_init(i3cbus
, master
->dev
.of_node
);
2811 device_initialize(&master
->dev
);
2812 dev_set_name(&master
->dev
, "i3c-%d", i3cbus
->id
);
2814 master
->dev
.dma_mask
= parent
->dma_mask
;
2815 master
->dev
.coherent_dma_mask
= parent
->coherent_dma_mask
;
2816 master
->dev
.dma_parms
= parent
->dma_parms
;
2818 ret
= of_populate_i3c_bus(master
);
2822 list_for_each_entry(i2cbi
, &master
->boardinfo
.i2c
, node
) {
2823 switch (i2cbi
->lvr
& I3C_LVR_I2C_INDEX_MASK
) {
2824 case I3C_LVR_I2C_INDEX(0):
2825 if (mode
< I3C_BUS_MODE_MIXED_FAST
)
2826 mode
= I3C_BUS_MODE_MIXED_FAST
;
2828 case I3C_LVR_I2C_INDEX(1):
2829 if (mode
< I3C_BUS_MODE_MIXED_LIMITED
)
2830 mode
= I3C_BUS_MODE_MIXED_LIMITED
;
2832 case I3C_LVR_I2C_INDEX(2):
2833 if (mode
< I3C_BUS_MODE_MIXED_SLOW
)
2834 mode
= I3C_BUS_MODE_MIXED_SLOW
;
2841 if (i2cbi
->lvr
& I3C_LVR_I2C_FM_MODE
)
2842 i2c_scl_rate
= I3C_BUS_I2C_FM_SCL_RATE
;
2845 ret
= i3c_bus_set_mode(i3cbus
, mode
, i2c_scl_rate
);
2849 master
->wq
= alloc_workqueue("%s", 0, 0, dev_name(parent
));
2855 ret
= i3c_master_bus_init(master
);
2859 ret
= device_add(&master
->dev
);
2861 goto err_cleanup_bus
;
2864 * Expose our I3C bus as an I2C adapter so that I2C devices are exposed
2865 * through the I2C subsystem.
2867 ret
= i3c_master_i2c_adapter_init(master
);
2871 i3c_bus_notify(i3cbus
, I3C_NOTIFY_BUS_ADD
);
2873 pm_runtime_no_callbacks(&master
->dev
);
2874 pm_suspend_ignore_children(&master
->dev
, true);
2875 pm_runtime_enable(&master
->dev
);
2878 * We're done initializing the bus and the controller, we can now
2879 * register I3C devices discovered during the initial DAA.
2881 master
->init_done
= true;
2882 i3c_bus_normaluse_lock(&master
->bus
);
2883 i3c_master_register_new_i3c_devs(master
);
2884 i3c_bus_normaluse_unlock(&master
->bus
);
2889 device_del(&master
->dev
);
2892 i3c_master_bus_cleanup(master
);
2895 put_device(&master
->dev
);
2899 EXPORT_SYMBOL_GPL(i3c_master_register
);
2902 * i3c_master_unregister() - unregister an I3C master
2903 * @master: master used to send frames on the bus
2905 * Basically undo everything done in i3c_master_register().
2907 void i3c_master_unregister(struct i3c_master_controller
*master
)
2909 i3c_bus_notify(&master
->bus
, I3C_NOTIFY_BUS_REMOVE
);
2911 i3c_master_i2c_adapter_cleanup(master
);
2912 i3c_master_unregister_i3c_devs(master
);
2913 i3c_master_bus_cleanup(master
);
2914 pm_runtime_disable(&master
->dev
);
2915 device_unregister(&master
->dev
);
2917 EXPORT_SYMBOL_GPL(i3c_master_unregister
);
2919 int i3c_dev_setdasa_locked(struct i3c_dev_desc
*dev
)
2921 struct i3c_master_controller
*master
;
2926 master
= i3c_dev_get_master(dev
);
2930 if (!dev
->boardinfo
|| !dev
->boardinfo
->init_dyn_addr
||
2931 !dev
->boardinfo
->static_addr
)
2934 return i3c_master_setdasa_locked(master
, dev
->info
.static_addr
,
2935 dev
->boardinfo
->init_dyn_addr
);
2938 int i3c_dev_do_priv_xfers_locked(struct i3c_dev_desc
*dev
,
2939 struct i3c_priv_xfer
*xfers
,
2942 struct i3c_master_controller
*master
;
2947 master
= i3c_dev_get_master(dev
);
2948 if (!master
|| !xfers
)
2951 if (!master
->ops
->priv_xfers
)
2954 return master
->ops
->priv_xfers(dev
, xfers
, nxfers
);
2957 int i3c_dev_disable_ibi_locked(struct i3c_dev_desc
*dev
)
2959 struct i3c_master_controller
*master
;
2965 master
= i3c_dev_get_master(dev
);
2966 ret
= master
->ops
->disable_ibi(dev
);
2970 reinit_completion(&dev
->ibi
->all_ibis_handled
);
2971 if (atomic_read(&dev
->ibi
->pending_ibis
))
2972 wait_for_completion(&dev
->ibi
->all_ibis_handled
);
2974 dev
->ibi
->enabled
= false;
2979 int i3c_dev_enable_ibi_locked(struct i3c_dev_desc
*dev
)
2981 struct i3c_master_controller
*master
= i3c_dev_get_master(dev
);
2987 ret
= master
->ops
->enable_ibi(dev
);
2989 dev
->ibi
->enabled
= true;
2994 int i3c_dev_request_ibi_locked(struct i3c_dev_desc
*dev
,
2995 const struct i3c_ibi_setup
*req
)
2997 struct i3c_master_controller
*master
= i3c_dev_get_master(dev
);
2998 struct i3c_device_ibi_info
*ibi
;
3001 if (!master
->ops
->request_ibi
)
3007 ibi
= kzalloc(sizeof(*ibi
), GFP_KERNEL
);
3011 ibi
->wq
= alloc_ordered_workqueue(dev_name(i3cdev_to_dev(dev
->dev
)), WQ_MEM_RECLAIM
);
3017 atomic_set(&ibi
->pending_ibis
, 0);
3018 init_completion(&ibi
->all_ibis_handled
);
3019 ibi
->handler
= req
->handler
;
3020 ibi
->max_payload_len
= req
->max_payload_len
;
3021 ibi
->num_slots
= req
->num_slots
;
3024 ret
= master
->ops
->request_ibi(dev
, req
);
3033 void i3c_dev_free_ibi_locked(struct i3c_dev_desc
*dev
)
3035 struct i3c_master_controller
*master
= i3c_dev_get_master(dev
);
3040 if (WARN_ON(dev
->ibi
->enabled
))
3041 WARN_ON(i3c_dev_disable_ibi_locked(dev
));
3043 master
->ops
->free_ibi(dev
);
3046 destroy_workqueue(dev
->ibi
->wq
);
3047 dev
->ibi
->wq
= NULL
;
3054 static int __init
i3c_init(void)
3058 res
= of_alias_get_highest_id("i3c");
3060 mutex_lock(&i3c_core_lock
);
3061 __i3c_first_dynamic_bus_num
= res
+ 1;
3062 mutex_unlock(&i3c_core_lock
);
3065 res
= bus_register_notifier(&i2c_bus_type
, &i2cdev_notifier
);
3069 res
= bus_register(&i3c_bus_type
);
3071 goto out_unreg_notifier
;
3076 bus_unregister_notifier(&i2c_bus_type
, &i2cdev_notifier
);
3080 subsys_initcall(i3c_init
);
3082 static void __exit
i3c_exit(void)
3084 bus_unregister_notifier(&i2c_bus_type
, &i2cdev_notifier
);
3085 idr_destroy(&i3c_bus_idr
);
3086 bus_unregister(&i3c_bus_type
);
3088 module_exit(i3c_exit
);
3090 MODULE_AUTHOR("Boris Brezillon <boris.brezillon@bootlin.com>");
3091 MODULE_DESCRIPTION("I3C core");
3092 MODULE_LICENSE("GPL v2");