Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: add generic simple-card support

Current ASoC requires card.c file to each platforms in order to
specifies its CPU and Codecs pair.
But the differences between these were only value/strings of setting.
In order to reduce duplicate driver, this patch adds generic/simple-card.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>

authored by

Kuninori Morimoto and committed by
Mark Brown
f2390880 cdc04fd1

+163
+38
include/sound/simple_card.h
··· 1 + /* 2 + * ASoC simple sound card support 3 + * 4 + * Copyright (C) 2012 Renesas Solutions Corp. 5 + * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> 6 + * 7 + * This program is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License version 2 as 9 + * published by the Free Software Foundation. 10 + */ 11 + 12 + #ifndef __SIMPLE_CARD_H 13 + #define __SIMPLE_CARD_H 14 + 15 + #include <sound/soc.h> 16 + 17 + struct asoc_simple_dai_init_info { 18 + unsigned int fmt; 19 + unsigned int cpu_daifmt; 20 + unsigned int codec_daifmt; 21 + unsigned int sysclk; 22 + }; 23 + 24 + struct asoc_simple_card_info { 25 + const char *name; 26 + const char *card; 27 + const char *cpu_dai; 28 + const char *codec; 29 + const char *platform; 30 + const char *codec_dai; 31 + struct asoc_simple_dai_init_info *init; /* for snd_link.init */ 32 + 33 + /* used in simple-card.c */ 34 + struct snd_soc_dai_link snd_link; 35 + struct snd_soc_card snd_card; 36 + }; 37 + 38 + #endif /* __SIMPLE_CARD_H */
+3
sound/soc/Kconfig
··· 51 51 # Supported codecs 52 52 source "sound/soc/codecs/Kconfig" 53 53 54 + # generic frame-work 55 + source "sound/soc/generic/Kconfig" 56 + 54 57 endif # SND_SOC 55 58
+1
sound/soc/Makefile
··· 6 6 7 7 obj-$(CONFIG_SND_SOC) += snd-soc-core.o 8 8 obj-$(CONFIG_SND_SOC) += codecs/ 9 + obj-$(CONFIG_SND_SOC) += generic/ 9 10 obj-$(CONFIG_SND_SOC) += atmel/ 10 11 obj-$(CONFIG_SND_SOC) += au1x/ 11 12 obj-$(CONFIG_SND_SOC) += blackfin/
+4
sound/soc/generic/Kconfig
··· 1 + config SND_SIMPLE_CARD 2 + tristate "ASoC Simple sound card support" 3 + help 4 + This option enables generic simple sound card support
+3
sound/soc/generic/Makefile
··· 1 + snd-soc-simple-card-objs := simple-card.o 2 + 3 + obj-$(CONFIG_SND_SIMPLE_CARD) += snd-soc-simple-card.o
+114
sound/soc/generic/simple-card.c
··· 1 + /* 2 + * ASoC simple sound card support 3 + * 4 + * Copyright (C) 2012 Renesas Solutions Corp. 5 + * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> 6 + * 7 + * This program is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License version 2 as 9 + * published by the Free Software Foundation. 10 + */ 11 + 12 + #include <linux/platform_device.h> 13 + #include <linux/module.h> 14 + #include <sound/simple_card.h> 15 + 16 + #define asoc_simple_get_card_info(p) \ 17 + container_of(p->dai_link, struct asoc_simple_card_info, snd_link) 18 + 19 + static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd) 20 + { 21 + struct asoc_simple_card_info *cinfo = asoc_simple_get_card_info(rtd); 22 + struct asoc_simple_dai_init_info *iinfo = cinfo->init; 23 + struct snd_soc_dai *codec = rtd->codec_dai; 24 + struct snd_soc_dai *cpu = rtd->cpu_dai; 25 + unsigned int cpu_daifmt = iinfo->fmt | iinfo->cpu_daifmt; 26 + unsigned int codec_daifmt = iinfo->fmt | iinfo->codec_daifmt; 27 + int ret; 28 + 29 + if (codec_daifmt) { 30 + ret = snd_soc_dai_set_fmt(codec, codec_daifmt); 31 + if (ret < 0) 32 + return ret; 33 + } 34 + 35 + if (iinfo->sysclk) { 36 + ret = snd_soc_dai_set_sysclk(codec, 0, iinfo->sysclk, 0); 37 + if (ret < 0) 38 + return ret; 39 + } 40 + 41 + if (cpu_daifmt) { 42 + ret = snd_soc_dai_set_fmt(cpu, cpu_daifmt); 43 + if (ret < 0) 44 + return ret; 45 + } 46 + 47 + return 0; 48 + } 49 + 50 + static int asoc_simple_card_probe(struct platform_device *pdev) 51 + { 52 + struct asoc_simple_card_info *cinfo = pdev->dev.platform_data; 53 + 54 + if (!cinfo) { 55 + dev_err(&pdev->dev, "no info for asoc-simple-card\n"); 56 + return -EINVAL; 57 + } 58 + 59 + if (!cinfo->name || 60 + !cinfo->card || 61 + !cinfo->cpu_dai || 62 + !cinfo->codec || 63 + !cinfo->platform || 64 + !cinfo->codec_dai) { 65 + dev_err(&pdev->dev, "insufficient asoc_simple_card_info settings\n"); 66 + return -EINVAL; 67 + } 68 + 69 + /* 70 + * init snd_soc_dai_link 71 + */ 72 + cinfo->snd_link.name = cinfo->name; 73 + cinfo->snd_link.stream_name = cinfo->name; 74 + cinfo->snd_link.cpu_dai_name = cinfo->cpu_dai; 75 + cinfo->snd_link.platform_name = cinfo->platform; 76 + cinfo->snd_link.codec_name = cinfo->codec; 77 + cinfo->snd_link.codec_dai_name = cinfo->codec_dai; 78 + 79 + /* enable snd_link.init if cinfo has settings */ 80 + if (cinfo->init) 81 + cinfo->snd_link.init = asoc_simple_card_dai_init; 82 + 83 + /* 84 + * init snd_soc_card 85 + */ 86 + cinfo->snd_card.name = cinfo->card; 87 + cinfo->snd_card.owner = THIS_MODULE; 88 + cinfo->snd_card.dai_link = &cinfo->snd_link; 89 + cinfo->snd_card.num_links = 1; 90 + cinfo->snd_card.dev = &pdev->dev; 91 + 92 + return snd_soc_register_card(&cinfo->snd_card); 93 + } 94 + 95 + static int asoc_simple_card_remove(struct platform_device *pdev) 96 + { 97 + struct asoc_simple_card_info *cinfo = pdev->dev.platform_data; 98 + 99 + return snd_soc_unregister_card(&cinfo->snd_card); 100 + } 101 + 102 + static struct platform_driver asoc_simple_card = { 103 + .driver = { 104 + .name = "asoc-simple-card", 105 + }, 106 + .probe = asoc_simple_card_probe, 107 + .remove = asoc_simple_card_remove, 108 + }; 109 + 110 + module_platform_driver(asoc_simple_card); 111 + 112 + MODULE_LICENSE("GPL"); 113 + MODULE_DESCRIPTION("ASoC Simple Sound Card"); 114 + MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");