Date:2013-04-15 19:19:49 (10 years 1 month ago)
Author:Lars C.
Commit:9529ae761db851eb2c86ddc61032059b831738f3
Message:ASoC: Add snd_soc_{add, remove}_platform

snd_soc_{add,remove}_platform are similar to snd_soc_register_platform and
snd_soc_unregister_platform with the difference that they won't allocate and
free the snd_soc_platform structure.

Also add snd_soc_lookup_platform which looks up a platform by the device it has
been registered for.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Tested-by: Stephen Warren <swarren@nvidia.com>
Tested-by: Shawn Guo <shawn.guo@linaro.org>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Files: include/sound/soc.h (1 diff)
sound/soc/soc-core.c (2 diffs)

Change Details

include/sound/soc.h
373373int snd_soc_register_platform(struct device *dev,
374374        const struct snd_soc_platform_driver *platform_drv);
375375void snd_soc_unregister_platform(struct device *dev);
376int snd_soc_add_platform(struct device *dev, struct snd_soc_platform *platform,
377        const struct snd_soc_platform_driver *platform_drv);
378void snd_soc_remove_platform(struct snd_soc_platform *platform);
379struct snd_soc_platform *snd_soc_lookup_platform(struct device *dev);
376380int snd_soc_register_codec(struct device *dev,
377381        const struct snd_soc_codec_driver *codec_drv,
378382        struct snd_soc_dai_driver *dai_drv, int num_dai);
sound/soc/soc-core.c
39033903EXPORT_SYMBOL_GPL(snd_soc_unregister_dais);
39043904
39053905/**
3906 * snd_soc_register_platform - Register a platform with the ASoC core
3907 *
3908 * @platform: platform to register
3906 * snd_soc_add_platform - Add a platform to the ASoC core
3907 * @dev: The parent device for the platform
3908 * @platform: The platform to add
3909 * @platform_driver: The driver for the platform
39093910 */
3910int snd_soc_register_platform(struct device *dev,
3911int snd_soc_add_platform(struct device *dev, struct snd_soc_platform *platform,
39113912        const struct snd_soc_platform_driver *platform_drv)
39123913{
3913    struct snd_soc_platform *platform;
3914
3915    dev_dbg(dev, "ASoC: platform register %s\n", dev_name(dev));
3916
3917    platform = kzalloc(sizeof(struct snd_soc_platform), GFP_KERNEL);
3918    if (platform == NULL)
3919        return -ENOMEM;
3920
39213914    /* create platform component name */
39223915    platform->name = fmt_single_name(dev, &platform->id);
39233916    if (platform->name == NULL) {
...... 
39403933
39413934    return 0;
39423935}
3943EXPORT_SYMBOL_GPL(snd_soc_register_platform);
3936EXPORT_SYMBOL_GPL(snd_soc_add_platform);
39443937
39453938/**
3946 * snd_soc_unregister_platform - Unregister a platform from the ASoC core
3939 * snd_soc_register_platform - Register a platform with the ASoC core
39473940 *
3948 * @platform: platform to unregister
3941 * @platform: platform to register
39493942 */
3950void snd_soc_unregister_platform(struct device *dev)
3943int snd_soc_register_platform(struct device *dev,
3944        const struct snd_soc_platform_driver *platform_drv)
39513945{
39523946    struct snd_soc_platform *platform;
3947    int ret;
39533948
3954    list_for_each_entry(platform, &platform_list, list) {
3955        if (dev == platform->dev)
3956            goto found;
3957    }
3958    return;
3949    dev_dbg(dev, "ASoC: platform register %s\n", dev_name(dev));
39593950
3960found:
3951    platform = kzalloc(sizeof(struct snd_soc_platform), GFP_KERNEL);
3952    if (platform == NULL)
3953        return -ENOMEM;
3954
3955    ret = snd_soc_add_platform(dev, platform, platform_drv);
3956    if (ret)
3957        kfree(platform);
3958
3959    return ret;
3960}
3961EXPORT_SYMBOL_GPL(snd_soc_register_platform);
3962
3963/**
3964 * snd_soc_remove_platform - Remove a platform from the ASoC core
3965 * @platform: the platform to remove
3966 */
3967void snd_soc_remove_platform(struct snd_soc_platform *platform)
3968{
39613969    mutex_lock(&client_mutex);
39623970    list_del(&platform->list);
39633971    mutex_unlock(&client_mutex);
39643972
3965    dev_dbg(dev, "ASoC: Unregistered platform '%s'\n", platform->name);
3973    dev_dbg(platform->dev, "ASoC: Unregistered platform '%s'\n",
3974        platform->name);
39663975    kfree(platform->name);
3976}
3977EXPORT_SYMBOL_GPL(snd_soc_remove_platform);
3978
3979struct snd_soc_platform *snd_soc_lookup_platform(struct device *dev)
3980{
3981    struct snd_soc_platform *platform;
3982
3983    list_for_each_entry(platform, &platform_list, list) {
3984        if (dev == platform->dev)
3985            return platform;
3986    }
3987
3988    return NULL;
3989}
3990EXPORT_SYMBOL_GPL(snd_soc_lookup_platform);
3991
3992/**
3993 * snd_soc_unregister_platform - Unregister a platform from the ASoC core
3994 *
3995 * @platform: platform to unregister
3996 */
3997void snd_soc_unregister_platform(struct device *dev)
3998{
3999    struct snd_soc_platform *platform;
4000
4001    platform = snd_soc_lookup_platform(dev);
4002    if (!platform)
4003        return;
4004
4005    snd_soc_remove_platform(platform);
39674006    kfree(platform);
39684007}
39694008EXPORT_SYMBOL_GPL(snd_soc_unregister_platform);

Archive Download the corresponding diff file



interactive