.. | .. |
---|
8 | 8 | #ifndef __SIMPLE_CARD_UTILS_H |
---|
9 | 9 | #define __SIMPLE_CARD_UTILS_H |
---|
10 | 10 | |
---|
| 11 | +#include <linux/clk.h> |
---|
11 | 12 | #include <sound/soc.h> |
---|
12 | 13 | |
---|
13 | | -#define asoc_simple_card_init_hp(card, sjack, prefix) \ |
---|
14 | | - asoc_simple_card_init_jack(card, sjack, 1, prefix) |
---|
15 | | -#define asoc_simple_card_init_mic(card, sjack, prefix) \ |
---|
16 | | - asoc_simple_card_init_jack(card, sjack, 0, prefix) |
---|
| 14 | +#define asoc_simple_init_hp(card, sjack, prefix) \ |
---|
| 15 | + asoc_simple_init_jack(card, sjack, 1, prefix, NULL) |
---|
| 16 | +#define asoc_simple_init_mic(card, sjack, prefix) \ |
---|
| 17 | + asoc_simple_init_jack(card, sjack, 0, prefix, NULL) |
---|
17 | 18 | |
---|
18 | 19 | struct asoc_simple_dai { |
---|
19 | 20 | const char *name; |
---|
.. | .. |
---|
26 | 27 | struct clk *clk; |
---|
27 | 28 | }; |
---|
28 | 29 | |
---|
29 | | -struct asoc_simple_card_data { |
---|
| 30 | +struct asoc_simple_data { |
---|
30 | 31 | u32 convert_rate; |
---|
31 | 32 | u32 convert_channels; |
---|
32 | 33 | }; |
---|
.. | .. |
---|
37 | 38 | struct snd_soc_jack_gpio gpio; |
---|
38 | 39 | }; |
---|
39 | 40 | |
---|
40 | | -int asoc_simple_card_parse_daifmt(struct device *dev, |
---|
41 | | - struct device_node *node, |
---|
42 | | - struct device_node *codec, |
---|
43 | | - char *prefix, |
---|
44 | | - unsigned int *retfmt); |
---|
| 41 | +struct asoc_simple_priv { |
---|
| 42 | + struct snd_soc_card snd_card; |
---|
| 43 | + struct simple_dai_props { |
---|
| 44 | + struct asoc_simple_dai *cpu_dai; |
---|
| 45 | + struct asoc_simple_dai *codec_dai; |
---|
| 46 | + struct snd_soc_dai_link_component cpus; /* single cpu */ |
---|
| 47 | + struct snd_soc_dai_link_component codecs; /* single codec */ |
---|
| 48 | + struct snd_soc_dai_link_component platforms; |
---|
| 49 | + struct asoc_simple_data adata; |
---|
| 50 | + struct snd_soc_codec_conf *codec_conf; |
---|
| 51 | + unsigned int mclk_fs; |
---|
| 52 | + } *dai_props; |
---|
| 53 | + struct asoc_simple_jack hp_jack; |
---|
| 54 | + struct asoc_simple_jack mic_jack; |
---|
| 55 | + struct snd_soc_dai_link *dai_link; |
---|
| 56 | + struct asoc_simple_dai *dais; |
---|
| 57 | + struct snd_soc_codec_conf *codec_conf; |
---|
| 58 | + struct gpio_desc *pa_gpio; |
---|
| 59 | +}; |
---|
| 60 | +#define simple_priv_to_card(priv) (&(priv)->snd_card) |
---|
| 61 | +#define simple_priv_to_props(priv, i) ((priv)->dai_props + (i)) |
---|
| 62 | +#define simple_priv_to_dev(priv) (simple_priv_to_card(priv)->dev) |
---|
| 63 | +#define simple_priv_to_link(priv, i) (simple_priv_to_card(priv)->dai_link + (i)) |
---|
| 64 | + |
---|
| 65 | +struct link_info { |
---|
| 66 | + int dais; /* number of dai */ |
---|
| 67 | + int link; /* number of link */ |
---|
| 68 | + int conf; /* number of codec_conf */ |
---|
| 69 | + int cpu; /* turn for CPU / Codec */ |
---|
| 70 | +}; |
---|
| 71 | + |
---|
| 72 | +int asoc_simple_parse_daifmt(struct device *dev, |
---|
| 73 | + struct device_node *node, |
---|
| 74 | + struct device_node *codec, |
---|
| 75 | + char *prefix, |
---|
| 76 | + unsigned int *retfmt); |
---|
45 | 77 | __printf(3, 4) |
---|
46 | | -int asoc_simple_card_set_dailink_name(struct device *dev, |
---|
47 | | - struct snd_soc_dai_link *dai_link, |
---|
48 | | - const char *fmt, ...); |
---|
49 | | -int asoc_simple_card_parse_card_name(struct snd_soc_card *card, |
---|
50 | | - char *prefix); |
---|
| 78 | +int asoc_simple_set_dailink_name(struct device *dev, |
---|
| 79 | + struct snd_soc_dai_link *dai_link, |
---|
| 80 | + const char *fmt, ...); |
---|
| 81 | +int asoc_simple_parse_card_name(struct snd_soc_card *card, |
---|
| 82 | + char *prefix); |
---|
51 | 83 | |
---|
52 | | -#define asoc_simple_card_parse_clk_cpu(dev, node, dai_link, simple_dai) \ |
---|
53 | | - asoc_simple_card_parse_clk(dev, node, dai_link->cpu_of_node, simple_dai, \ |
---|
54 | | - dai_link->cpu_dai_name) |
---|
55 | | -#define asoc_simple_card_parse_clk_codec(dev, node, dai_link, simple_dai) \ |
---|
56 | | - asoc_simple_card_parse_clk(dev, node, dai_link->codec_of_node, simple_dai,\ |
---|
57 | | - dai_link->codec_dai_name) |
---|
58 | | -int asoc_simple_card_parse_clk(struct device *dev, |
---|
59 | | - struct device_node *node, |
---|
60 | | - struct device_node *dai_of_node, |
---|
61 | | - struct asoc_simple_dai *simple_dai, |
---|
62 | | - const char *name); |
---|
63 | | -int asoc_simple_card_clk_enable(struct asoc_simple_dai *dai); |
---|
64 | | -void asoc_simple_card_clk_disable(struct asoc_simple_dai *dai); |
---|
| 84 | +#define asoc_simple_parse_clk_cpu(dev, node, dai_link, simple_dai) \ |
---|
| 85 | + asoc_simple_parse_clk(dev, node, simple_dai, dai_link->cpus) |
---|
| 86 | +#define asoc_simple_parse_clk_codec(dev, node, dai_link, simple_dai) \ |
---|
| 87 | + asoc_simple_parse_clk(dev, node, simple_dai, dai_link->codecs) |
---|
| 88 | +int asoc_simple_parse_clk(struct device *dev, |
---|
| 89 | + struct device_node *node, |
---|
| 90 | + struct asoc_simple_dai *simple_dai, |
---|
| 91 | + struct snd_soc_dai_link_component *dlc); |
---|
| 92 | +int asoc_simple_startup(struct snd_pcm_substream *substream); |
---|
| 93 | +void asoc_simple_shutdown(struct snd_pcm_substream *substream); |
---|
| 94 | +int asoc_simple_hw_params(struct snd_pcm_substream *substream, |
---|
| 95 | + struct snd_pcm_hw_params *params); |
---|
| 96 | +int asoc_simple_dai_init(struct snd_soc_pcm_runtime *rtd); |
---|
| 97 | +int asoc_simple_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, |
---|
| 98 | + struct snd_pcm_hw_params *params); |
---|
65 | 99 | |
---|
66 | | -#define asoc_simple_card_parse_cpu(node, dai_link, \ |
---|
67 | | - list_name, cells_name, is_single_link) \ |
---|
68 | | - asoc_simple_card_parse_dai(node, &dai_link->cpu_of_node, \ |
---|
69 | | - &dai_link->cpu_dai_name, list_name, cells_name, is_single_link) |
---|
70 | | -#define asoc_simple_card_parse_codec(node, dai_link, list_name, cells_name) \ |
---|
71 | | - asoc_simple_card_parse_dai(node, &dai_link->codec_of_node, \ |
---|
72 | | - &dai_link->codec_dai_name, list_name, cells_name, NULL) |
---|
73 | | -#define asoc_simple_card_parse_platform(node, dai_link, list_name, cells_name) \ |
---|
74 | | - asoc_simple_card_parse_dai(node, &dai_link->platform_of_node, \ |
---|
75 | | - NULL, list_name, cells_name, NULL) |
---|
76 | | -int asoc_simple_card_parse_dai(struct device_node *node, |
---|
77 | | - struct device_node **endpoint_np, |
---|
78 | | - const char **dai_name, |
---|
79 | | - const char *list_name, |
---|
80 | | - const char *cells_name, |
---|
81 | | - int *is_single_links); |
---|
| 100 | +#define asoc_simple_parse_cpu(node, dai_link, is_single_link) \ |
---|
| 101 | + asoc_simple_parse_dai(node, dai_link->cpus, is_single_link) |
---|
| 102 | +#define asoc_simple_parse_codec(node, dai_link) \ |
---|
| 103 | + asoc_simple_parse_dai(node, dai_link->codecs, NULL) |
---|
| 104 | +#define asoc_simple_parse_platform(node, dai_link) \ |
---|
| 105 | + asoc_simple_parse_dai(node, dai_link->platforms, NULL) |
---|
82 | 106 | |
---|
83 | | -#define asoc_simple_card_parse_graph_cpu(ep, dai_link) \ |
---|
84 | | - asoc_simple_card_parse_graph_dai(ep, &dai_link->cpu_of_node, \ |
---|
85 | | - &dai_link->cpu_dai_name) |
---|
86 | | -#define asoc_simple_card_parse_graph_codec(ep, dai_link) \ |
---|
87 | | - asoc_simple_card_parse_graph_dai(ep, &dai_link->codec_of_node, \ |
---|
88 | | - &dai_link->codec_dai_name) |
---|
89 | | -int asoc_simple_card_parse_graph_dai(struct device_node *ep, |
---|
90 | | - struct device_node **endpoint_np, |
---|
91 | | - const char **dai_name); |
---|
92 | | - |
---|
93 | | -#define asoc_simple_card_of_parse_tdm(np, dai) \ |
---|
| 107 | +#define asoc_simple_parse_tdm(np, dai) \ |
---|
94 | 108 | snd_soc_of_parse_tdm_slot(np, &(dai)->tx_slot_mask, \ |
---|
95 | 109 | &(dai)->rx_slot_mask, \ |
---|
96 | 110 | &(dai)->slots, \ |
---|
97 | 111 | &(dai)->slot_width); |
---|
98 | 112 | |
---|
99 | | -int asoc_simple_card_init_dai(struct snd_soc_dai *dai, |
---|
100 | | - struct asoc_simple_dai *simple_dai); |
---|
101 | | - |
---|
102 | | -int asoc_simple_card_canonicalize_dailink(struct snd_soc_dai_link *dai_link); |
---|
103 | | -void asoc_simple_card_canonicalize_cpu(struct snd_soc_dai_link *dai_link, |
---|
| 113 | +void asoc_simple_canonicalize_platform(struct snd_soc_dai_link *dai_link); |
---|
| 114 | +void asoc_simple_canonicalize_cpu(struct snd_soc_dai_link *dai_link, |
---|
104 | 115 | int is_single_links); |
---|
105 | 116 | |
---|
106 | | -int asoc_simple_card_clean_reference(struct snd_soc_card *card); |
---|
| 117 | +int asoc_simple_clean_reference(struct snd_soc_card *card); |
---|
107 | 118 | |
---|
108 | | -void asoc_simple_card_convert_fixup(struct asoc_simple_card_data *data, |
---|
| 119 | +void asoc_simple_convert_fixup(struct asoc_simple_data *data, |
---|
109 | 120 | struct snd_pcm_hw_params *params); |
---|
110 | | -void asoc_simple_card_parse_convert(struct device *dev, char *prefix, |
---|
111 | | - struct asoc_simple_card_data *data); |
---|
| 121 | +void asoc_simple_parse_convert(struct device *dev, |
---|
| 122 | + struct device_node *np, char *prefix, |
---|
| 123 | + struct asoc_simple_data *data); |
---|
112 | 124 | |
---|
113 | | -int asoc_simple_card_of_parse_routing(struct snd_soc_card *card, |
---|
114 | | - char *prefix, |
---|
115 | | - int optional); |
---|
116 | | -int asoc_simple_card_of_parse_widgets(struct snd_soc_card *card, |
---|
| 125 | +int asoc_simple_parse_routing(struct snd_soc_card *card, |
---|
117 | 126 | char *prefix); |
---|
| 127 | +int asoc_simple_parse_widgets(struct snd_soc_card *card, |
---|
| 128 | + char *prefix); |
---|
| 129 | +int asoc_simple_parse_pin_switches(struct snd_soc_card *card, |
---|
| 130 | + char *prefix); |
---|
118 | 131 | |
---|
119 | | -int asoc_simple_card_init_jack(struct snd_soc_card *card, |
---|
| 132 | +int asoc_simple_init_jack(struct snd_soc_card *card, |
---|
120 | 133 | struct asoc_simple_jack *sjack, |
---|
121 | | - int is_hp, char *prefix); |
---|
| 134 | + int is_hp, char *prefix, char *pin); |
---|
| 135 | +int asoc_simple_init_priv(struct asoc_simple_priv *priv, |
---|
| 136 | + struct link_info *li); |
---|
| 137 | + |
---|
| 138 | +#ifdef DEBUG |
---|
| 139 | +static inline void asoc_simple_debug_dai(struct asoc_simple_priv *priv, |
---|
| 140 | + char *name, |
---|
| 141 | + struct asoc_simple_dai *dai) |
---|
| 142 | +{ |
---|
| 143 | + struct device *dev = simple_priv_to_dev(priv); |
---|
| 144 | + |
---|
| 145 | + /* dai might be NULL */ |
---|
| 146 | + if (!dai) |
---|
| 147 | + return; |
---|
| 148 | + |
---|
| 149 | + if (dai->name) |
---|
| 150 | + dev_dbg(dev, "%s dai name = %s\n", |
---|
| 151 | + name, dai->name); |
---|
| 152 | + if (dai->sysclk) |
---|
| 153 | + dev_dbg(dev, "%s sysclk = %d\n", |
---|
| 154 | + name, dai->sysclk); |
---|
| 155 | + |
---|
| 156 | + dev_dbg(dev, "%s direction = %s\n", |
---|
| 157 | + name, dai->clk_direction ? "OUT" : "IN"); |
---|
| 158 | + |
---|
| 159 | + if (dai->slots) |
---|
| 160 | + dev_dbg(dev, "%s slots = %d\n", name, dai->slots); |
---|
| 161 | + if (dai->slot_width) |
---|
| 162 | + dev_dbg(dev, "%s slot width = %d\n", name, dai->slot_width); |
---|
| 163 | + if (dai->tx_slot_mask) |
---|
| 164 | + dev_dbg(dev, "%s tx slot mask = %d\n", name, dai->tx_slot_mask); |
---|
| 165 | + if (dai->rx_slot_mask) |
---|
| 166 | + dev_dbg(dev, "%s rx slot mask = %d\n", name, dai->rx_slot_mask); |
---|
| 167 | + if (dai->clk) |
---|
| 168 | + dev_dbg(dev, "%s clk %luHz\n", name, clk_get_rate(dai->clk)); |
---|
| 169 | +} |
---|
| 170 | + |
---|
| 171 | +static inline void asoc_simple_debug_info(struct asoc_simple_priv *priv) |
---|
| 172 | +{ |
---|
| 173 | + struct snd_soc_card *card = simple_priv_to_card(priv); |
---|
| 174 | + struct device *dev = simple_priv_to_dev(priv); |
---|
| 175 | + |
---|
| 176 | + int i; |
---|
| 177 | + |
---|
| 178 | + if (card->name) |
---|
| 179 | + dev_dbg(dev, "Card Name: %s\n", card->name); |
---|
| 180 | + |
---|
| 181 | + for (i = 0; i < card->num_links; i++) { |
---|
| 182 | + struct simple_dai_props *props = simple_priv_to_props(priv, i); |
---|
| 183 | + struct snd_soc_dai_link *link = simple_priv_to_link(priv, i); |
---|
| 184 | + |
---|
| 185 | + dev_dbg(dev, "DAI%d\n", i); |
---|
| 186 | + |
---|
| 187 | + asoc_simple_debug_dai(priv, "cpu", props->cpu_dai); |
---|
| 188 | + asoc_simple_debug_dai(priv, "codec", props->codec_dai); |
---|
| 189 | + |
---|
| 190 | + if (link->name) |
---|
| 191 | + dev_dbg(dev, "dai name = %s\n", link->name); |
---|
| 192 | + |
---|
| 193 | + dev_dbg(dev, "dai format = %04x\n", link->dai_fmt); |
---|
| 194 | + |
---|
| 195 | + if (props->adata.convert_rate) |
---|
| 196 | + dev_dbg(dev, "convert_rate = %d\n", |
---|
| 197 | + props->adata.convert_rate); |
---|
| 198 | + if (props->adata.convert_channels) |
---|
| 199 | + dev_dbg(dev, "convert_channels = %d\n", |
---|
| 200 | + props->adata.convert_channels); |
---|
| 201 | + if (props->codec_conf && props->codec_conf->name_prefix) |
---|
| 202 | + dev_dbg(dev, "name prefix = %s\n", |
---|
| 203 | + props->codec_conf->name_prefix); |
---|
| 204 | + if (props->mclk_fs) |
---|
| 205 | + dev_dbg(dev, "mclk-fs = %d\n", |
---|
| 206 | + props->mclk_fs); |
---|
| 207 | + } |
---|
| 208 | +} |
---|
| 209 | +#else |
---|
| 210 | +#define asoc_simple_debug_info(priv) |
---|
| 211 | +#endif /* DEBUG */ |
---|
122 | 212 | |
---|
123 | 213 | #endif /* __SIMPLE_CARD_UTILS_H */ |
---|