1 /*
2  * simple_card_utils.h
3  *
4  * Copyright (c) 2016 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  */
10 #ifndef __SIMPLE_CARD_UTILS_H
11 #define __SIMPLE_CARD_UTILS_H
12 
13 #include <sound/soc.h>
14 
15 struct asoc_simple_dai {
16 	const char *name;
17 	unsigned int sysclk;
18 	int slots;
19 	int slot_width;
20 	unsigned int tx_slot_mask;
21 	unsigned int rx_slot_mask;
22 	struct clk *clk;
23 };
24 
25 struct asoc_simple_card_data {
26 	u32 convert_rate;
27 	u32 convert_channels;
28 };
29 
30 int asoc_simple_card_parse_daifmt(struct device *dev,
31 				  struct device_node *node,
32 				  struct device_node *codec,
33 				  char *prefix,
34 				  unsigned int *retfmt);
35 __printf(3, 4)
36 int asoc_simple_card_set_dailink_name(struct device *dev,
37 				      struct snd_soc_dai_link *dai_link,
38 				      const char *fmt, ...);
39 int asoc_simple_card_parse_card_name(struct snd_soc_card *card,
40 				     char *prefix);
41 
42 #define asoc_simple_card_parse_clk_cpu(dev, node, dai_link, simple_dai)		\
43 	asoc_simple_card_parse_clk(dev, node, dai_link->cpu_of_node, simple_dai, \
44 				   dai_link->cpu_dai_name)
45 #define asoc_simple_card_parse_clk_codec(dev, node, dai_link, simple_dai)	\
46 	asoc_simple_card_parse_clk(dev, node, dai_link->codec_of_node, simple_dai,\
47 				   dai_link->codec_dai_name)
48 int asoc_simple_card_parse_clk(struct device *dev,
49 			       struct device_node *node,
50 			       struct device_node *dai_of_node,
51 			       struct asoc_simple_dai *simple_dai,
52 			       const char *name);
53 int asoc_simple_card_clk_enable(struct asoc_simple_dai *dai);
54 void asoc_simple_card_clk_disable(struct asoc_simple_dai *dai);
55 
56 #define asoc_simple_card_parse_cpu(node, dai_link,				\
57 				   list_name, cells_name, is_single_link)	\
58 	asoc_simple_card_parse_dai(node, &dai_link->cpu_of_node,		\
59 		&dai_link->cpu_dai_name, list_name, cells_name, is_single_link)
60 #define asoc_simple_card_parse_codec(node, dai_link, list_name, cells_name)	\
61 	asoc_simple_card_parse_dai(node, &dai_link->codec_of_node,		\
62 		&dai_link->codec_dai_name, list_name, cells_name, NULL)
63 #define asoc_simple_card_parse_platform(node, dai_link, list_name, cells_name)	\
64 	asoc_simple_card_parse_dai(node, &dai_link->platform_of_node,		\
65 		NULL, list_name, cells_name, NULL)
66 int asoc_simple_card_parse_dai(struct device_node *node,
67 				  struct device_node **endpoint_np,
68 				  const char **dai_name,
69 				  const char *list_name,
70 				  const char *cells_name,
71 				  int *is_single_links);
72 
73 #define asoc_simple_card_parse_graph_cpu(ep, dai_link)			\
74 	asoc_simple_card_parse_graph_dai(ep, &dai_link->cpu_of_node,	\
75 					 &dai_link->cpu_dai_name)
76 #define asoc_simple_card_parse_graph_codec(ep, dai_link)		\
77 	asoc_simple_card_parse_graph_dai(ep, &dai_link->codec_of_node,	\
78 					 &dai_link->codec_dai_name)
79 int asoc_simple_card_parse_graph_dai(struct device_node *ep,
80 				     struct device_node **endpoint_np,
81 				     const char **dai_name);
82 
83 #define asoc_simple_card_of_parse_tdm(np, dai)			\
84 	snd_soc_of_parse_tdm_slot(np,	&(dai)->tx_slot_mask,	\
85 					&(dai)->rx_slot_mask,	\
86 					&(dai)->slots,		\
87 					&(dai)->slot_width);
88 
89 int asoc_simple_card_init_dai(struct snd_soc_dai *dai,
90 			      struct asoc_simple_dai *simple_dai);
91 
92 int asoc_simple_card_canonicalize_dailink(struct snd_soc_dai_link *dai_link);
93 void asoc_simple_card_canonicalize_cpu(struct snd_soc_dai_link *dai_link,
94 				      int is_single_links);
95 
96 int asoc_simple_card_clean_reference(struct snd_soc_card *card);
97 
98 void asoc_simple_card_convert_fixup(struct asoc_simple_card_data *data,
99 				      struct snd_pcm_hw_params *params);
100 void asoc_simple_card_parse_convert(struct device *dev, char *prefix,
101 				    struct asoc_simple_card_data *data);
102 
103 int asoc_simple_card_of_parse_routing(struct snd_soc_card *card,
104 				      char *prefix,
105 				      int optional);
106 int asoc_simple_card_of_parse_widgets(struct snd_soc_card *card,
107 				      char *prefix);
108 
109 #endif /* __SIMPLE_CARD_UTILS_H */
110