ASoC: rockchip: coding style.
[firefly-linux-kernel-4.4.55.git] / sound / soc / rockchip / card_info.c
1 /*
2  *  card_info.c
3  *
4  *  This program is free software; you can redistribute  it and/or modify it
5  *  under  the terms of  the GNU General  Public License as published by the
6  *  Free Software Foundation;  either version 2 of the  License, or (at your
7  *  option) any later version.
8  *
9  */
10
11 #include <linux/module.h>
12 #include <linux/device.h>
13 #include <linux/of.h>
14 #include <sound/core.h>
15 #include <sound/pcm.h>
16 #include <sound/soc.h>
17
18 /*
19   Get sound card infos:
20       audio-codec
21       audio-controller
22
23       format
24
25       continuous-clock
26
27       bitclock-inversion
28       frame-inversion
29
30       bitclock-master
31       frame-master
32
33   Get audio-codec and audio-controller in this fun,
34   and get oher infos in fun snd_soc_of_parse_daifmt().
35
36   Set in dts:
37                 dais {
38                         dai0 {
39                                 audio-codec = <&codec_of_node>;
40                                 audio-controller = <&cpu_of_node>;
41                                 format = "i2s";
42                                 //continuous-clock;
43                                 //bitclock-inversion;
44                                 //frame-inversion;
45                                 //bitclock-master;
46                                 //frame-master;
47                         };
48
49                         dai1 {
50                                 audio-codec = <&codec_of_node>;
51                                 audio-controller = <&cpu_of_node>;
52                                 format = "dsp_a";
53                                 //continuous-clock;
54                                 bitclock-inversion;
55                                 //frame-inversion;
56                                 //bitclock-master;
57                                 //frame-master;
58                         };
59                 };
60  */
61 int rockchip_of_get_sound_card_info_(struct snd_soc_card *card,
62                                      bool is_need_fmt)
63 {
64         struct device_node *dai_node, *child_dai_node;
65         int dai_num;
66
67         dai_node = of_get_child_by_name(card->dev->of_node, "dais");
68         if (!dai_node) {
69                 dev_err(card->dev, "%s() Can not get child: dais\n",
70                         __func__);
71                 return -EINVAL;
72         }
73
74         dai_num = 0;
75
76         for_each_child_of_node(dai_node, child_dai_node) {
77                 if (is_need_fmt) {
78                         card->dai_link[dai_num].dai_fmt =
79                                 snd_soc_of_parse_daifmt(child_dai_node, NULL);
80                         if ((card->dai_link[dai_num].dai_fmt &
81                                 SND_SOC_DAIFMT_MASTER_MASK) == 0) {
82                                 dev_err(card->dev,
83                                         "Property 'format' missing or invalid\n");
84                                 return -EINVAL;
85                         }
86                 }
87
88                 card->dai_link[dai_num].codec_name = NULL;
89                 card->dai_link[dai_num].cpu_dai_name = NULL;
90                 card->dai_link[dai_num].platform_name = NULL;
91
92                 card->dai_link[dai_num].codec_of_node = of_parse_phandle(
93                         child_dai_node,
94                         "audio-codec", 0);
95                 if (!card->dai_link[dai_num].codec_of_node) {
96                         dev_err(card->dev,
97                                 "Property 'audio-codec' missing or invalid\n");
98                         return -EINVAL;
99                 }
100
101                 card->dai_link[dai_num].cpu_of_node = of_parse_phandle(
102                         child_dai_node,
103                         "audio-controller", 0);
104                 if (!card->dai_link[dai_num].cpu_of_node) {
105                         dev_err(card->dev,
106                                 "Property 'audio-controller' missing or invalid\n");
107                         return -EINVAL;
108                 }
109
110                 card->dai_link[dai_num].platform_of_node =
111                         card->dai_link[dai_num].cpu_of_node;
112
113                 if (++dai_num >= card->num_links)
114                         break;
115         }
116
117         if (dai_num < card->num_links) {
118                 dev_err(card->dev, "%s() Can not get enough property for dais, dai: %d, max dai num: %d\n",
119                         __func__, dai_num, card->num_links);
120                 return -EINVAL;
121         }
122
123         return 0;
124 }
125 EXPORT_SYMBOL_GPL(rockchip_of_get_sound_card_info_);
126
127 int rockchip_of_get_sound_card_info(struct snd_soc_card *card)
128 {
129         return rockchip_of_get_sound_card_info_(card, true);
130 }
131 EXPORT_SYMBOL_GPL(rockchip_of_get_sound_card_info);
132
133 /* Module information */
134 MODULE_AUTHOR("Jear <Jear.Chen@rock-chips.com>");
135 MODULE_DESCRIPTION("ROCKCHIP ASoC Interface");
136 MODULE_LICENSE("GPL");