[PATCH 10/14] staging: most: allow speculative configuration

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch makes the driver accept a link confiiguration eventhough no
device is attached to the bus. Instead the configuration is being applied
as soon as a device is being registered with the core.

Signed-off-by: Christian Gromm <christian.gromm@xxxxxxxxxxxxx>
---
 drivers/staging/most/configfs.c    | 63 +++++++++++++++++++++++++++-----------
 drivers/staging/most/core.c        | 16 +++-------
 drivers/staging/most/core.h        |  1 +
 drivers/staging/most/sound/sound.c |  6 ++--
 4 files changed, 54 insertions(+), 32 deletions(-)

diff --git a/drivers/staging/most/configfs.c b/drivers/staging/most/configfs.c
index cefce69..84a4bd3 100644
--- a/drivers/staging/most/configfs.c
+++ b/drivers/staging/most/configfs.c
@@ -16,6 +16,7 @@
 
 struct mdev_link {
 	struct config_item item;
+	struct list_head list;
 	int create;
 	u16 num_buffers;
 	u16 buffer_size;
@@ -31,6 +32,8 @@ struct mdev_link {
 	char param[MAX_LEN];
 };
 
+struct list_head mdev_link_list;
+
 int set_cfg_buffer_size(struct mdev_link *link)
 {
 	if (!link->buffer_size)
@@ -107,13 +110,30 @@ static ssize_t mdev_link_create_show(struct config_item *item, char *page)
 	return sprintf(page, "%d\n", to_mdev_link(item)->create);
 }
 
+static int set_config_and_add_link(struct mdev_link *mdev_link)
+{
+	int i;
+	int ret;
+
+	for (i = 0; i < ARRAY_SIZE(set_config_val); i++) {
+		ret = set_config_val[i](mdev_link);
+		if (ret == -ENODATA) {
+			pr_err("Config failed\n");
+			return ret;
+		}
+	}
+
+	return most_add_link(mdev_link->mdev, mdev_link->channel,
+			     mdev_link->comp, mdev_link->name,
+			     mdev_link->param);
+}
+
 static ssize_t mdev_link_create_store(struct config_item *item,
 				      const char *page, size_t count)
 {
 	struct mdev_link *mdev_link = to_mdev_link(item);
 	u16 tmp;
 	int ret;
-	int i;
 	char *p = (char *)page;
 
 	ret = kstrtou16(p, 0, &tmp);
@@ -121,28 +141,18 @@ static ssize_t mdev_link_create_store(struct config_item *item,
 		return ret;
 	if (tmp > 1)
 		return -ERANGE;
-
-	for (i = 0; i < ARRAY_SIZE(set_config_val); i++) {
-		ret = set_config_val[i](mdev_link);
-		if (ret < 0) {
-			pr_err("Config failed\n");
-			return ret;
-		}
-	}
+	if (!tmp)
+		return most_remove_link(mdev_link->mdev, mdev_link->channel,
+					mdev_link->comp);
 
 	if (!mdev_link->mdev || !mdev_link->channel || !mdev_link->comp) {
 		pr_err("Config parameters incomplete\n");
-		return -EIO;
+		return -ENODATA;
 	}
-	if (tmp)
-		ret = most_add_link(mdev_link->mdev, mdev_link->channel,
-				    mdev_link->comp, mdev_link->name,
-				    mdev_link->param);
-	else
-		ret = most_remove_link(mdev_link->mdev, mdev_link->channel,
-				       mdev_link->comp);
-	if (ret)
+	ret = set_config_and_add_link(mdev_link);
+	if (ret && ret != -ENODEV)
 		return ret;
+	list_add_tail(&mdev_link->list, &mdev_link_list);
 	mdev_link->create = tmp;
 	return count;
 }
@@ -622,6 +632,22 @@ int most_register_configfs_subsys(struct core_component *c)
 }
 EXPORT_SYMBOL_GPL(most_register_configfs_subsys);
 
+void most_interface_register_notify(const char *mdev)
+{
+	bool register_snd_card = false;
+	struct mdev_link *mdev_link;
+
+	list_for_each_entry(mdev_link, &mdev_link_list, list) {
+		if (!strcmp(mdev_link->mdev, mdev)) {
+			set_config_and_add_link(mdev_link);
+			if (!strcmp(mdev_link->comp, "sound"))
+				register_snd_card = true;
+		}
+	}
+	if (register_snd_card)
+		most_cfg_complete("sound");
+}
+
 void most_deregister_configfs_subsys(struct core_component *c)
 {
 	if (!strcmp(c->name, "cdev"))
@@ -650,6 +676,7 @@ int __init configfs_init(void)
 	mutex_init(&most_sound_subsys.subsys.su_mutex);
 
 	INIT_LIST_HEAD(&most_sound_subsys.soundcard_list);
+	INIT_LIST_HEAD(&mdev_link_list);
 
 	return 0;
 }
diff --git a/drivers/staging/most/core.c b/drivers/staging/most/core.c
index 31291bc..765a74c0 100644
--- a/drivers/staging/most/core.c
+++ b/drivers/staging/most/core.c
@@ -720,19 +720,10 @@ int most_cfg_complete(char *comp_name)
 int most_add_link(char *mdev, char *mdev_ch, char *comp_name, char *link_name,
 		  char *comp_param)
 {
-	struct most_channel *c;
-	struct core_component *comp;
-	char buf[STRING_SIZE];
+	struct most_channel *c = get_channel(mdev, mdev_ch);
+	struct core_component *comp = match_component(comp_name);
 
-	comp = match_component(comp_name);
-	if (!comp)
-		return -ENODEV;
-	if (!comp_param || *comp_param == 0) {
-		snprintf(buf, sizeof(buf), "%s-%s", mdev, mdev_ch);
-		comp_param = buf;
-	}
-	c = get_channel(mdev, mdev_ch);
-	if (!c)
+	if (!c || !comp)
 		return -ENODEV;
 
 	return link_channel_to_component(c, comp, link_name, comp_param);
@@ -1462,6 +1453,7 @@ int most_register_interface(struct most_interface *iface)
 	}
 	pr_info("registered new device mdev%d (%s)\n",
 		id, iface->description);
+	most_interface_register_notify(iface->description);
 	return 0;
 
 err_free_most_channel:
diff --git a/drivers/staging/most/core.h b/drivers/staging/most/core.h
index f875159..22a0a29 100644
--- a/drivers/staging/most/core.h
+++ b/drivers/staging/most/core.h
@@ -335,4 +335,5 @@ int most_set_cfg_datatype(char *mdev, char *mdev_ch, char *buf);
 int most_set_cfg_direction(char *mdev, char *mdev_ch, char *buf);
 int most_set_cfg_packets_xact(char *mdev, char *mdev_ch, u16 val);
 int most_cfg_complete(char *comp_name);
+void most_interface_register_notify(const char *mdev_name);
 #endif /* MOST_CORE_H_ */
diff --git a/drivers/staging/most/sound/sound.c b/drivers/staging/most/sound/sound.c
index fd089e6..44c9146 100644
--- a/drivers/staging/most/sound/sound.c
+++ b/drivers/staging/most/sound/sound.c
@@ -20,6 +20,7 @@
 #include <most/core.h>
 
 #define DRIVER_NAME "sound"
+#define STRING_SIZE	80
 
 static struct core_component comp;
 
@@ -582,6 +583,7 @@ static int audio_probe_channel(struct most_interface *iface, int channel_id,
 	int direction;
 	u16 ch_num;
 	char *sample_res;
+	char arg_list_cpy[STRING_SIZE];
 
 	if (!iface)
 		return -EINVAL;
@@ -590,8 +592,8 @@ static int audio_probe_channel(struct most_interface *iface, int channel_id,
 		pr_err("Incompatible channel type\n");
 		return -EINVAL;
 	}
-
-	ret = split_arg_list(arg_list, &ch_num, &sample_res);
+	strlcpy(arg_list_cpy, arg_list, STRING_SIZE);
+	ret = split_arg_list(arg_list_cpy, &ch_num, &sample_res);
 	if (ret < 0)
 		return ret;
 
-- 
2.7.4

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel



[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux