1 /* SPDX-License-Identifier: GPL-2.0
2  *
3  * simple_card_utils.h
4  *
5  * Copyright (c) 2016 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6  */
7 
8 #ifndef __SIMPLE_CARD_UTILS_H
9 #define __SIMPLE_CARD_UTILS_H
10 
11 #include <sound/soc.h>
12 
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)
17 
18 struct asoc_simple_dai {
19 	const char *name;
20 	unsigned int sysclk;
21 	int clk_direction;
22 	int slots;
23 	int slot_width;
24 	unsigned int tx_slot_mask;
25 	unsigned int rx_slot_mask;
26 	struct clk *clk;
27 };
28 
29 struct asoc_simple_card_data {
30 	u32 convert_rate;
31 	u32 convert_channels;
32 };
33 
34 struct asoc_simple_jack {
35 	struct snd_soc_jack jack;
36 	struct snd_soc_jack_pin pin;
37 	struct snd_soc_jack_gpio gpio;
38 };
39 
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);
45 __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);
51 
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);
65 
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);
82 
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)			\
94 	snd_soc_of_parse_tdm_slot(np,	&(dai)->tx_slot_mask,	\
95 					&(dai)->rx_slot_mask,	\
96 					&(dai)->slots,		\
97 					&(dai)->slot_width);
98 
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,
104 				      int is_single_links);
105 
106 int asoc_simple_card_clean_reference(struct snd_soc_card *card);
107 
108 void asoc_simple_card_convert_fixup(struct asoc_simple_card_data *data,
109 				      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);
112 
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,
117 				      char *prefix);
118 
119 int asoc_simple_card_init_jack(struct snd_soc_card *card,
120 			       struct asoc_simple_jack *sjack,
121 			       int is_hp, char *prefix);
122 
123 #endif /* __SIMPLE_CARD_UTILS_H */
124