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, 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 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 *dai_name, 63 struct snd_soc_dai_link_component *dlc); 64 int asoc_simple_card_clk_enable(struct asoc_simple_dai *dai); 65 void asoc_simple_card_clk_disable(struct asoc_simple_dai *dai); 66 67 #define asoc_simple_card_parse_cpu(node, dai_link, \ 68 list_name, cells_name, is_single_link) \ 69 asoc_simple_card_parse_dai(node, NULL, \ 70 &dai_link->cpu_of_node, \ 71 &dai_link->cpu_dai_name, list_name, cells_name, is_single_link) 72 #define asoc_simple_card_parse_codec(node, dai_link, list_name, cells_name) \ 73 asoc_simple_card_parse_dai(node, dai_link->codecs, \ 74 &dai_link->codec_of_node, \ 75 &dai_link->codec_dai_name, \ 76 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 NULL, list_name, cells_name, NULL) 81 int asoc_simple_card_parse_dai(struct device_node *node, 82 struct snd_soc_dai_link_component *dlc, 83 struct device_node **endpoint_np, 84 const char **dai_name, 85 const char *list_name, 86 const char *cells_name, 87 int *is_single_links); 88 89 #define asoc_simple_card_parse_graph_cpu(ep, dai_link) \ 90 asoc_simple_card_parse_graph_dai(ep, NULL, \ 91 &dai_link->cpu_of_node, \ 92 &dai_link->cpu_dai_name) 93 #define asoc_simple_card_parse_graph_codec(ep, dai_link) \ 94 asoc_simple_card_parse_graph_dai(ep, dai_link->codecs, \ 95 &dai_link->codec_of_node, \ 96 &dai_link->codec_dai_name) 97 int asoc_simple_card_parse_graph_dai(struct device_node *ep, 98 struct snd_soc_dai_link_component *dlc, 99 struct device_node **endpoint_np, 100 const char **dai_name); 101 102 #define asoc_simple_card_of_parse_tdm(np, dai) \ 103 snd_soc_of_parse_tdm_slot(np, &(dai)->tx_slot_mask, \ 104 &(dai)->rx_slot_mask, \ 105 &(dai)->slots, \ 106 &(dai)->slot_width); 107 108 int asoc_simple_card_init_dai(struct snd_soc_dai *dai, 109 struct asoc_simple_dai *simple_dai); 110 111 int asoc_simple_card_canonicalize_dailink(struct snd_soc_dai_link *dai_link); 112 void asoc_simple_card_canonicalize_cpu(struct snd_soc_dai_link *dai_link, 113 int is_single_links); 114 115 int asoc_simple_card_clean_reference(struct snd_soc_card *card); 116 117 void asoc_simple_card_convert_fixup(struct asoc_simple_card_data *data, 118 struct snd_pcm_hw_params *params); 119 void asoc_simple_card_parse_convert(struct device *dev, char *prefix, 120 struct asoc_simple_card_data *data); 121 122 int asoc_simple_card_of_parse_routing(struct snd_soc_card *card, 123 char *prefix, 124 int optional); 125 int asoc_simple_card_of_parse_widgets(struct snd_soc_card *card, 126 char *prefix); 127 128 int asoc_simple_card_init_jack(struct snd_soc_card *card, 129 struct asoc_simple_jack *sjack, 130 int is_hp, char *prefix); 131 132 #endif /* __SIMPLE_CARD_UTILS_H */ 133