mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	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>
This commit is contained in:
		
							parent
							
								
									b4da37db3e
								
							
						
					
					
						commit
						317bacf960
					
				
					 2 changed files with 88 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -557,6 +557,88 @@ static ssize_t i2c_scl_frequency_show(struct device *dev,
 | 
			
		|||
}
 | 
			
		||||
static DEVICE_ATTR_RO(i2c_scl_frequency);
 | 
			
		||||
 | 
			
		||||
static int i3c_set_hotjoin(struct i3c_master_controller *master, bool enable)
 | 
			
		||||
{
 | 
			
		||||
	int ret;
 | 
			
		||||
 | 
			
		||||
	if (!master || !master->ops)
 | 
			
		||||
		return -EINVAL;
 | 
			
		||||
 | 
			
		||||
	if (!master->ops->enable_hotjoin || !master->ops->disable_hotjoin)
 | 
			
		||||
		return -EINVAL;
 | 
			
		||||
 | 
			
		||||
	i3c_bus_normaluse_lock(&master->bus);
 | 
			
		||||
 | 
			
		||||
	if (enable)
 | 
			
		||||
		ret = master->ops->enable_hotjoin(master);
 | 
			
		||||
	else
 | 
			
		||||
		ret = master->ops->disable_hotjoin(master);
 | 
			
		||||
 | 
			
		||||
	master->hotjoin = enable;
 | 
			
		||||
 | 
			
		||||
	i3c_bus_normaluse_unlock(&master->bus);
 | 
			
		||||
 | 
			
		||||
	return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static ssize_t hotjoin_store(struct device *dev, struct device_attribute *attr,
 | 
			
		||||
			     const char *buf, size_t count)
 | 
			
		||||
{
 | 
			
		||||
	struct i3c_bus *i3cbus = dev_to_i3cbus(dev);
 | 
			
		||||
	int ret;
 | 
			
		||||
	bool res;
 | 
			
		||||
 | 
			
		||||
	if (!i3cbus->cur_master)
 | 
			
		||||
		return -EINVAL;
 | 
			
		||||
 | 
			
		||||
	if (kstrtobool(buf, &res))
 | 
			
		||||
		return -EINVAL;
 | 
			
		||||
 | 
			
		||||
	ret = i3c_set_hotjoin(i3cbus->cur_master->common.master, res);
 | 
			
		||||
	if (ret)
 | 
			
		||||
		return ret;
 | 
			
		||||
 | 
			
		||||
	return count;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * i3c_master_enable_hotjoin - Enable hotjoin
 | 
			
		||||
 * @master: I3C master object
 | 
			
		||||
 *
 | 
			
		||||
 * Return: a 0 in case of success, an negative error code otherwise.
 | 
			
		||||
 */
 | 
			
		||||
int i3c_master_enable_hotjoin(struct i3c_master_controller *master)
 | 
			
		||||
{
 | 
			
		||||
	return i3c_set_hotjoin(master, true);
 | 
			
		||||
}
 | 
			
		||||
EXPORT_SYMBOL_GPL(i3c_master_enable_hotjoin);
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * i3c_master_disable_hotjoin - Disable hotjoin
 | 
			
		||||
 * @master: I3C master object
 | 
			
		||||
 *
 | 
			
		||||
 * Return: a 0 in case of success, an negative error code otherwise.
 | 
			
		||||
 */
 | 
			
		||||
int i3c_master_disable_hotjoin(struct i3c_master_controller *master)
 | 
			
		||||
{
 | 
			
		||||
	return i3c_set_hotjoin(master, false);
 | 
			
		||||
}
 | 
			
		||||
EXPORT_SYMBOL_GPL(i3c_master_disable_hotjoin);
 | 
			
		||||
 | 
			
		||||
static ssize_t hotjoin_show(struct device *dev, struct device_attribute *da, char *buf)
 | 
			
		||||
{
 | 
			
		||||
	struct i3c_bus *i3cbus = dev_to_i3cbus(dev);
 | 
			
		||||
	ssize_t ret;
 | 
			
		||||
 | 
			
		||||
	i3c_bus_normaluse_lock(i3cbus);
 | 
			
		||||
	ret = sysfs_emit(buf, "%d\n", i3cbus->cur_master->common.master->hotjoin);
 | 
			
		||||
	i3c_bus_normaluse_unlock(i3cbus);
 | 
			
		||||
 | 
			
		||||
	return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static DEVICE_ATTR_RW(hotjoin);
 | 
			
		||||
 | 
			
		||||
static struct attribute *i3c_masterdev_attrs[] = {
 | 
			
		||||
	&dev_attr_mode.attr,
 | 
			
		||||
	&dev_attr_current_master.attr,
 | 
			
		||||
| 
						 | 
				
			
			@ -567,6 +649,7 @@ static struct attribute *i3c_masterdev_attrs[] = {
 | 
			
		|||
	&dev_attr_pid.attr,
 | 
			
		||||
	&dev_attr_dynamic_address.attr,
 | 
			
		||||
	&dev_attr_hdrcap.attr,
 | 
			
		||||
	&dev_attr_hotjoin.attr,
 | 
			
		||||
	NULL,
 | 
			
		||||
};
 | 
			
		||||
ATTRIBUTE_GROUPS(i3c_masterdev);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -460,6 +460,8 @@ struct i3c_master_controller_ops {
 | 
			
		|||
	int (*disable_ibi)(struct i3c_dev_desc *dev);
 | 
			
		||||
	void (*recycle_ibi_slot)(struct i3c_dev_desc *dev,
 | 
			
		||||
				 struct i3c_ibi_slot *slot);
 | 
			
		||||
	int (*enable_hotjoin)(struct i3c_master_controller *master);
 | 
			
		||||
	int (*disable_hotjoin)(struct i3c_master_controller *master);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
| 
						 | 
				
			
			@ -495,6 +497,7 @@ struct i3c_master_controller {
 | 
			
		|||
	const struct i3c_master_controller_ops *ops;
 | 
			
		||||
	unsigned int secondary : 1;
 | 
			
		||||
	unsigned int init_done : 1;
 | 
			
		||||
	unsigned int hotjoin: 1;
 | 
			
		||||
	struct {
 | 
			
		||||
		struct list_head i3c;
 | 
			
		||||
		struct list_head i2c;
 | 
			
		||||
| 
						 | 
				
			
			@ -551,6 +554,8 @@ int i3c_master_register(struct i3c_master_controller *master,
 | 
			
		|||
			const struct i3c_master_controller_ops *ops,
 | 
			
		||||
			bool secondary);
 | 
			
		||||
void i3c_master_unregister(struct i3c_master_controller *master);
 | 
			
		||||
int i3c_master_enable_hotjoin(struct i3c_master_controller *master);
 | 
			
		||||
int i3c_master_disable_hotjoin(struct i3c_master_controller *master);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * i3c_dev_get_master_data() - get master private data attached to an I3C
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue