Skip to content

Commit 317bacf

Browse files
nxpfranklialexandrebelloni
authored andcommitted
i3c: master: add enable(disable) hot join in sys entry
Add hotjoin entry in sys file system allow user enable/disable hotjoin feature. Add (*enable(disable)_hotjoin)() to i3c_master_controller_ops. Add api i3c_master_enable(disable)_hotjoin(); Signed-off-by: Frank Li <Frank.Li@nxp.com> Link: https://lore.kernel.org/r/20231201222532.2431484-2-Frank.Li@nxp.com Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
1 parent b4da37d commit 317bacf

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

drivers/i3c/master.c

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,88 @@ static ssize_t i2c_scl_frequency_show(struct device *dev,
557557
}
558558
static DEVICE_ATTR_RO(i2c_scl_frequency);
559559

560+
static int i3c_set_hotjoin(struct i3c_master_controller *master, bool enable)
561+
{
562+
int ret;
563+
564+
if (!master || !master->ops)
565+
return -EINVAL;
566+
567+
if (!master->ops->enable_hotjoin || !master->ops->disable_hotjoin)
568+
return -EINVAL;
569+
570+
i3c_bus_normaluse_lock(&master->bus);
571+
572+
if (enable)
573+
ret = master->ops->enable_hotjoin(master);
574+
else
575+
ret = master->ops->disable_hotjoin(master);
576+
577+
master->hotjoin = enable;
578+
579+
i3c_bus_normaluse_unlock(&master->bus);
580+
581+
return ret;
582+
}
583+
584+
static ssize_t hotjoin_store(struct device *dev, struct device_attribute *attr,
585+
const char *buf, size_t count)
586+
{
587+
struct i3c_bus *i3cbus = dev_to_i3cbus(dev);
588+
int ret;
589+
bool res;
590+
591+
if (!i3cbus->cur_master)
592+
return -EINVAL;
593+
594+
if (kstrtobool(buf, &res))
595+
return -EINVAL;
596+
597+
ret = i3c_set_hotjoin(i3cbus->cur_master->common.master, res);
598+
if (ret)
599+
return ret;
600+
601+
return count;
602+
}
603+
604+
/*
605+
* i3c_master_enable_hotjoin - Enable hotjoin
606+
* @master: I3C master object
607+
*
608+
* Return: a 0 in case of success, an negative error code otherwise.
609+
*/
610+
int i3c_master_enable_hotjoin(struct i3c_master_controller *master)
611+
{
612+
return i3c_set_hotjoin(master, true);
613+
}
614+
EXPORT_SYMBOL_GPL(i3c_master_enable_hotjoin);
615+
616+
/*
617+
* i3c_master_disable_hotjoin - Disable hotjoin
618+
* @master: I3C master object
619+
*
620+
* Return: a 0 in case of success, an negative error code otherwise.
621+
*/
622+
int i3c_master_disable_hotjoin(struct i3c_master_controller *master)
623+
{
624+
return i3c_set_hotjoin(master, false);
625+
}
626+
EXPORT_SYMBOL_GPL(i3c_master_disable_hotjoin);
627+
628+
static ssize_t hotjoin_show(struct device *dev, struct device_attribute *da, char *buf)
629+
{
630+
struct i3c_bus *i3cbus = dev_to_i3cbus(dev);
631+
ssize_t ret;
632+
633+
i3c_bus_normaluse_lock(i3cbus);
634+
ret = sysfs_emit(buf, "%d\n", i3cbus->cur_master->common.master->hotjoin);
635+
i3c_bus_normaluse_unlock(i3cbus);
636+
637+
return ret;
638+
}
639+
640+
static DEVICE_ATTR_RW(hotjoin);
641+
560642
static struct attribute *i3c_masterdev_attrs[] = {
561643
&dev_attr_mode.attr,
562644
&dev_attr_current_master.attr,
@@ -567,6 +649,7 @@ static struct attribute *i3c_masterdev_attrs[] = {
567649
&dev_attr_pid.attr,
568650
&dev_attr_dynamic_address.attr,
569651
&dev_attr_hdrcap.attr,
652+
&dev_attr_hotjoin.attr,
570653
NULL,
571654
};
572655
ATTRIBUTE_GROUPS(i3c_masterdev);

include/linux/i3c/master.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,8 @@ struct i3c_master_controller_ops {
460460
int (*disable_ibi)(struct i3c_dev_desc *dev);
461461
void (*recycle_ibi_slot)(struct i3c_dev_desc *dev,
462462
struct i3c_ibi_slot *slot);
463+
int (*enable_hotjoin)(struct i3c_master_controller *master);
464+
int (*disable_hotjoin)(struct i3c_master_controller *master);
463465
};
464466

465467
/**
@@ -495,6 +497,7 @@ struct i3c_master_controller {
495497
const struct i3c_master_controller_ops *ops;
496498
unsigned int secondary : 1;
497499
unsigned int init_done : 1;
500+
unsigned int hotjoin: 1;
498501
struct {
499502
struct list_head i3c;
500503
struct list_head i2c;
@@ -551,6 +554,8 @@ int i3c_master_register(struct i3c_master_controller *master,
551554
const struct i3c_master_controller_ops *ops,
552555
bool secondary);
553556
void i3c_master_unregister(struct i3c_master_controller *master);
557+
int i3c_master_enable_hotjoin(struct i3c_master_controller *master);
558+
int i3c_master_disable_hotjoin(struct i3c_master_controller *master);
554559

555560
/**
556561
* i3c_dev_get_master_data() - get master private data attached to an I3C

0 commit comments

Comments
 (0)