diff options
author | Christian Gromm <christian.gromm@microchip.com> | 2019-04-03 16:19:52 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2019-04-16 14:25:18 +0300 |
commit | acdbb89753734ff8e3fe7cab97d6898d23ff8ed8 (patch) | |
tree | 07b20abb4fa52def857704ed0aeaf3f4c839d125 | |
parent | a1ee286d5a2fa1f35d2893eb83c858f748f14c15 (diff) | |
download | linux-acdbb89753734ff8e3fe7cab97d6898d23ff8ed8.tar.xz |
staging: most: allow speculative configuration
This patch makes the driver accept a link configuration 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@microchip.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/staging/most/configfs.c | 60 | ||||
-rw-r--r-- | drivers/staging/most/core.c | 16 | ||||
-rw-r--r-- | drivers/staging/most/core.h | 1 | ||||
-rw-r--r-- | drivers/staging/most/sound/sound.c | 6 |
4 files changed, 53 insertions, 30 deletions
diff --git a/drivers/staging/most/configfs.c b/drivers/staging/most/configfs.c index cb714f64d279..aeeb5ec6199c 100644 --- a/drivers/staging/most/configfs.c +++ b/drivers/staging/most/configfs.c @@ -14,6 +14,7 @@ struct mdev_link { struct config_item item; + struct list_head list; bool create_link; u16 num_buffers; u16 buffer_size; @@ -29,6 +30,8 @@ struct mdev_link { char comp_params[PAGE_SIZE]; }; +struct list_head mdev_link_list; + static int set_cfg_buffer_size(struct mdev_link *link) { if (!link->buffer_size) @@ -106,33 +109,41 @@ static ssize_t mdev_link_create_link_show(struct config_item *item, char *page) to_mdev_link(item)->create_link); } +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 < 0 && ret != -ENODEV) { + pr_err("Config failed\n"); + return ret; + } + } + + return most_add_link(mdev_link->device, mdev_link->channel, + mdev_link->comp, mdev_link->name, + mdev_link->comp_params); +} + static ssize_t mdev_link_create_link_store(struct config_item *item, const char *page, size_t count) { struct mdev_link *mdev_link = to_mdev_link(item); bool tmp; int ret; - int i; ret = kstrtobool(page, &tmp); if (ret) return ret; - - for (i = 0; i < ARRAY_SIZE(set_config_val); i++) { - ret = set_config_val[i](mdev_link); - if (ret < 0) - return ret; - } - - if (tmp) - ret = most_add_link(mdev_link->device, mdev_link->channel, - mdev_link->comp, mdev_link->name, - mdev_link->comp_params); - else - ret = most_remove_link(mdev_link->device, mdev_link->channel, - mdev_link->comp); - if (ret) + if (!tmp) + return most_remove_link(mdev_link->device, mdev_link->channel, + mdev_link->comp); + 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_link = tmp; return count; } @@ -594,6 +605,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->device, 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")) @@ -622,6 +649,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 03370551cd8b..306db261cdcc 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 12c5992c4229..652aaa771029 100644 --- a/drivers/staging/most/core.h +++ b/drivers/staging/most/core.h @@ -334,4 +334,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 6b5438c2495b..7c998673a6f8 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; |