@@ -467,6 +467,53 @@ static const char * const i3c_bus_mode_strings[] = {
[I3C_BUS_MODE_MIXED_SLOW] = "mixed-slow",
};
+static int i3c_master_enable_mr_events(struct i3c_master_controller *master)
+{
+ int ret;
+
+ master->ops->enable_mr_events(master);
+ i3c_bus_maintenance_lock(&master->bus);
+ ret = i3c_master_enec_locked(master, I3C_BROADCAST_ADDR,
+ I3C_CCC_EVENT_MR | I3C_CCC_EVENT_HJ);
+ i3c_bus_maintenance_unlock(&master->bus);
+
+ return ret;
+}
+
+/* This function is expected to be called with normaluse_lock */
+int i3c_master_acquire_bus(struct i3c_master_controller *master)
+{
+ int ret = 0;
+
+ if (!master->this || master->this != master->bus.cur_master) {
+ if (master->mr_state == I3C_MR_IDLE) {
+ master->mr_state = I3C_MR_WAIT_DA;
+ init_completion(&master->mr_comp);
+ queue_work(master->wq, &master->sec_mst_work);
+ /*
+ * Bus acquire procedure may need write lock
+ * so release read lock before yielding
+ * to bus acquire state machine
+ */
+ i3c_bus_normaluse_unlock(&master->bus);
+ wait_for_completion(&master->mr_comp);
+ i3c_bus_normaluse_lock(&master->bus);
+ if (master->mr_state != I3C_MR_DONE)
+ ret = -EAGAIN;
+ master->mr_state = I3C_MR_IDLE;
+ } else {
+ /*
+ * MR request is already in process for
+ * this master
+ */
+ ret = -EAGAIN;
+ }
+ }
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(i3c_master_acquire_bus);
+
static ssize_t mode_show(struct device *dev,
struct device_attribute *da,
char *buf)
@@ -533,6 +580,23 @@ static ssize_t i2c_scl_frequency_show(struct device *dev,
}
static DEVICE_ATTR_RO(i2c_scl_frequency);
+static ssize_t i3c_acquire_bus_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct i3c_master_controller *master = dev_to_i3cmaster(dev);
+ int ret;
+
+ i3c_bus_normaluse_lock(&master->bus);
+ ret = i3c_master_acquire_bus(master);
+ i3c_bus_normaluse_unlock(&master->bus);
+ if (!ret)
+ i3c_master_enable_mr_events(master);
+
+ return ret ?: count;
+}
+static DEVICE_ATTR_WO(i3c_acquire_bus);
+
static struct attribute *i3c_masterdev_attrs[] = {
&dev_attr_mode.attr,
&dev_attr_current_master.attr,
@@ -543,6 +607,7 @@ static struct attribute *i3c_masterdev_attrs[] = {
&dev_attr_pid.attr,
&dev_attr_dynamic_address.attr,
&dev_attr_hdrcap.attr,
+ &dev_attr_i3c_acquire_bus.attr,
NULL,
};
ATTRIBUTE_GROUPS(i3c_masterdev);
@@ -1244,19 +1309,6 @@ static int i3c_master_get_accmst_locked(struct i3c_master_controller *master,
return ret;
}
-static int i3c_master_enable_mr_events(struct i3c_master_controller *master)
-{
- int ret;
-
- master->ops->enable_mr_events(master);
- i3c_bus_maintenance_lock(&master->bus);
- ret = i3c_master_enec_locked(master, I3C_BROADCAST_ADDR,
- I3C_CCC_EVENT_MR | I3C_CCC_EVENT_HJ);
- i3c_bus_maintenance_unlock(&master->bus);
-
- return ret;
-}
-
static int i3c_master_getaccmst(struct i3c_master_controller *master)
{
int ret;
@@ -1792,40 +1844,6 @@ void i3c_sec_mst_mr_dis_event(struct i3c_master_controller *m)
}
EXPORT_SYMBOL_GPL(i3c_sec_mst_mr_dis_event);
-/* This function is expected to be called with normaluse_lock */
-int i3c_master_acquire_bus(struct i3c_master_controller *master)
-{
- int ret = 0;
-
- if (!master->this || master->this != master->bus.cur_master) {
- if (master->mr_state == I3C_MR_IDLE) {
- master->mr_state = I3C_MR_WAIT_DA;
- init_completion(&master->mr_comp);
- queue_work(master->wq, &master->sec_mst_work);
- /*
- * Bus acquire procedure may need write lock
- * so release read lock before yielding
- * to bus acquire state machine
- */
- i3c_bus_normaluse_unlock(&master->bus);
- wait_for_completion(&master->mr_comp);
- i3c_bus_normaluse_lock(&master->bus);
- if (master->mr_state != I3C_MR_DONE)
- ret = -EAGAIN;
- master->mr_state = I3C_MR_IDLE;
- } else {
- /*
- * MR request is already in process for
- * this master
- */
- ret = -EAGAIN;
- }
- }
-
- return ret;
-}
-EXPORT_SYMBOL_GPL(i3c_master_acquire_bus);
-
static struct i2c_dev_boardinfo *
i3c_master_alloc_i2c_boardinfo(struct i3c_master_controller *master,
u16 addr, u8 lvr)
This patch add sysfs key 'i3c_acquire_bus' to acquire I3C bus. Signed-off-by: Parshuram Thombare <pthombar@cadence.com> --- drivers/i3c/master.c | 112 +++++++++++++++++++++++++------------------ 1 file changed, 65 insertions(+), 47 deletions(-)