Hi Mark, Pierre-Louis
I think you're right to want a shorter name but Pierre's probably right that that particular name isn't the best... I'm thinking it might be good to look at the fully expanded definitions and then work back from there, or perhaps just stick with them for a while (since the compact forms are hopefully not a requirement for legibility, even if they are a useful improvement).
These are proposal of modern style macro v2. Any opinions are welcome.
v1 -> v2 - Naming fixup - No difference between with / without Platform (= no more xx_CC and xx_CCP) - It can handle each CPU/Codec/Platform manually (if you want)
/* Macro */ #define SND_DAILINK_REG(cpu, codec, platform) \ .cpus = cpu, \ .num_cpus = ARRAY_SIZE(cpu), \ .codecs = codec, \ .num_codecs = ARRAY_SIZE(codec), \ .platforms = platform, \ .num_platforms = ARRAY_SIZE(platform)
#define SND_DAILINK_REGS(name) \ .cpus = name##_cpus, \ .num_cpus = ARRAY_SIZE(name##_cpus), \ .codecs = name##_codecs, \ .num_codecs = ARRAY_SIZE(name##_codecs), \ .platforms = name##_platforms, \ .num_platforms = ARRAY_SIZE(name##_platforms)
#define SND_DAILINK_DEF(name, def...) \ static struct snd_soc_dai_link_component name[] = def
#define SND_DAILINK_DEFS(name, cpu, codec, platform) \ SND_DAILINK_DEF(name##_cpus, cpu); \ SND_DAILINK_DEF(name##_codecs, codec); \ SND_DAILINK_DEF(name##_platforms, platform)
#define DAILINK_COMPONENT_ARRAY(param...) { param } #define CPU_COMPONENT(_dai) { .dai_name = _dai, } #define CODEC_COMPONENT(_name, _dai) { .name = _name, .dai_name = _dai, } #define PLATFORM_COMPONENT(_name) { .name = _name } #define NO_DAILINK_COMPONENT() { }
struct snd_soc_dai_link_component null_dailink_component[0];
/* Sample1. Single CPU/Codec/Platform */
SND_DAILINK_DEFS(test, DAILINK_COMPONENT_ARRAY(CPU_COMPONENT("cpu_dai")), DAILINK_COMPONENT_ARRAY(CODEC_COMPONENT("codec", "codec_dai")), DAILINK_COMPONENT_ARRAY(PLATFORM_COMPONENT("platform")));
struct snd_soc_dai_link link = { ... SND_DAILINK_REGS(test), };
/* Sample2. Multi CPU/Codec, No Platform */
SND_DAILINK_DEFS(test, DAILINK_COMPONENT_ARRAY(CPU_COMPONENT("cpu_dai1"), CPU_COMPONENT("cpu_dai2")), DAILINK_COMPONENT_ARRAY(CODEC_COMPONENT("codec1", "codec_dai1"), CODEC_COMPONENT("codec2", "codec_dai2")), NO_DAILINK_COMPONENT());
struct snd_soc_dai_link link = { ... SND_DAILINK_REGS(test), };
/* Sample3. Define each CPU/Codec/Platform manually */
SND_DAILINK_DEF(test_cpu, DAILINK_COMPONENT_ARRAY(CPU_COMPONENT("cpu_dai1"), CPU_COMPONENT("cpu_dai2"))); SND_DAILINK_DEF(test_codec, DAILINK_COMPONENT_ARRAY(CODEC_COMPONENT("codec1", "codec_dai1"), CODEC_COMPONENT("codec2", "codec_dai2"))); SND_DAILINK_DEF(test_platform, DAILINK_COMPONENT_ARRAY(PLATFORM_COMPONENT("platform")));
struct snd_soc_dai_link link = { ... SND_DAILINK_REG(test_cpu, test_codec, test_platform), };
/* Sample4. Sample3 + no platform */
struct snd_soc_dai_link link = { ... SND_DAILINK_REG(test_cpu, test_codec, null_dailink_component), };
Thank you for your help !!
Best regards --- Kuninori Morimoto