simple_card_utils.h 4.6 KB
Newer Older
1 2
/* SPDX-License-Identifier: GPL-2.0
 *
3
 * simple_card_utils.h
4 5 6
 *
 * Copyright (c) 2016 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
 */
7

8 9
#ifndef __SIMPLE_CARD_UTILS_H
#define __SIMPLE_CARD_UTILS_H
10 11 12

#include <sound/soc.h>

13 14 15 16 17
#define asoc_simple_card_init_hp(card, sjack, prefix) \
	asoc_simple_card_init_jack(card, sjack, 1, prefix)
#define asoc_simple_card_init_mic(card, sjack, prefix) \
	asoc_simple_card_init_jack(card, sjack, 0, prefix)

18 19 20
struct asoc_simple_dai {
	const char *name;
	unsigned int sysclk;
21
	int clk_direction;
22 23 24 25 26 27 28
	int slots;
	int slot_width;
	unsigned int tx_slot_mask;
	unsigned int rx_slot_mask;
	struct clk *clk;
};

29 30 31 32 33
struct asoc_simple_card_data {
	u32 convert_rate;
	u32 convert_channels;
};

34 35 36 37 38 39
struct asoc_simple_jack {
	struct snd_soc_jack jack;
	struct snd_soc_jack_pin pin;
	struct snd_soc_jack_gpio gpio;
};

40 41 42 43 44
int asoc_simple_card_parse_daifmt(struct device *dev,
				  struct device_node *node,
				  struct device_node *codec,
				  char *prefix,
				  unsigned int *retfmt);
45
__printf(3, 4)
46 47 48
int asoc_simple_card_set_dailink_name(struct device *dev,
				      struct snd_soc_dai_link *dai_link,
				      const char *fmt, ...);
49 50
int asoc_simple_card_parse_card_name(struct snd_soc_card *card,
				     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, NULL)
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, dai_link->codecs)
58 59
int asoc_simple_card_parse_clk(struct device *dev,
			       struct device_node *node,
60
			       struct device_node *dai_of_node,
61
			       struct asoc_simple_dai *simple_dai,
62 63
			       const char *dai_name,
			       struct snd_soc_dai_link_component *dlc);
64 65
int asoc_simple_card_clk_enable(struct asoc_simple_dai *dai);
void asoc_simple_card_clk_disable(struct asoc_simple_dai *dai);
66

67 68
#define asoc_simple_card_parse_cpu(node, dai_link,				\
				   list_name, cells_name, is_single_link)	\
69 70
	asoc_simple_card_parse_dai(node, NULL,					\
		&dai_link->cpu_of_node,						\
71 72
		&dai_link->cpu_dai_name, list_name, cells_name, is_single_link)
#define asoc_simple_card_parse_codec(node, dai_link, list_name, cells_name)	\
73 74 75 76
	asoc_simple_card_parse_dai(node, dai_link->codecs,			\
				   &dai_link->codec_of_node,			\
				   &dai_link->codec_dai_name,			\
				   list_name, cells_name, NULL)
77
#define asoc_simple_card_parse_platform(node, dai_link, list_name, cells_name)	\
78
	asoc_simple_card_parse_dai(node, dai_link->platform,					\
79
		&dai_link->platform_of_node,					\
80 81
		NULL, list_name, cells_name, NULL)
int asoc_simple_card_parse_dai(struct device_node *node,
82
				  struct snd_soc_dai_link_component *dlc,
83 84 85 86 87 88
				  struct device_node **endpoint_np,
				  const char **dai_name,
				  const char *list_name,
				  const char *cells_name,
				  int *is_single_links);

89
#define asoc_simple_card_parse_graph_cpu(ep, dai_link)			\
90 91
	asoc_simple_card_parse_graph_dai(ep, NULL,			\
					 &dai_link->cpu_of_node,	\
92 93
					 &dai_link->cpu_dai_name)
#define asoc_simple_card_parse_graph_codec(ep, dai_link)		\
94 95
	asoc_simple_card_parse_graph_dai(ep, dai_link->codecs,		\
					 &dai_link->codec_of_node,	\
96 97
					 &dai_link->codec_dai_name)
int asoc_simple_card_parse_graph_dai(struct device_node *ep,
98
				     struct snd_soc_dai_link_component *dlc,
99 100 101
				     struct device_node **endpoint_np,
				     const char **dai_name);

102 103 104 105 106 107
#define asoc_simple_card_of_parse_tdm(np, dai)			\
	snd_soc_of_parse_tdm_slot(np,	&(dai)->tx_slot_mask,	\
					&(dai)->rx_slot_mask,	\
					&(dai)->slots,		\
					&(dai)->slot_width);

108 109
int asoc_simple_card_init_dai(struct snd_soc_dai *dai,
			      struct asoc_simple_dai *simple_dai);
110 111

int asoc_simple_card_canonicalize_dailink(struct snd_soc_dai_link *dai_link);
112 113
void asoc_simple_card_canonicalize_cpu(struct snd_soc_dai_link *dai_link,
				      int is_single_links);
114

115 116
int asoc_simple_card_clean_reference(struct snd_soc_card *card);

117 118
void asoc_simple_card_convert_fixup(struct asoc_simple_card_data *data,
				      struct snd_pcm_hw_params *params);
119 120
void asoc_simple_card_parse_convert(struct device *dev,
				    struct device_node *np, char *prefix,
121 122
				    struct asoc_simple_card_data *data);

123 124 125
int asoc_simple_card_of_parse_routing(struct snd_soc_card *card,
				      char *prefix,
				      int optional);
126 127
int asoc_simple_card_of_parse_widgets(struct snd_soc_card *card,
				      char *prefix);
128

129 130 131 132
int asoc_simple_card_init_jack(struct snd_soc_card *card,
			       struct asoc_simple_jack *sjack,
			       int is_hp, char *prefix);

133
#endif /* __SIMPLE_CARD_UTILS_H */