Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 1 | /* |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 2 | * ASoC simple SCU sound card support |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2015 Renesas Solutions Corp. |
| 5 | * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> |
| 6 | * |
| 7 | * based on ${LINUX}/sound/soc/generic/simple-card.c |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | */ |
| 13 | #include <linux/clk.h> |
| 14 | #include <linux/device.h> |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/of.h> |
| 17 | #include <linux/of_device.h> |
| 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/string.h> |
| 20 | #include <sound/jack.h> |
| 21 | #include <sound/soc.h> |
| 22 | #include <sound/soc-dai.h> |
Kuninori Morimoto | d6a4a9a4 | 2016-06-30 06:03:13 +0000 | [diff] [blame] | 23 | #include <sound/simple_card_utils.h> |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 24 | |
Kuninori Morimoto | 6910e86 | 2016-10-28 03:37:44 +0000 | [diff] [blame] | 25 | struct simple_card_data { |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 26 | struct snd_soc_card snd_card; |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 27 | struct snd_soc_codec_conf codec_conf; |
Kuninori Morimoto | 303c3be | 2016-07-11 23:58:50 +0000 | [diff] [blame] | 28 | struct asoc_simple_dai *dai_props; |
Kuninori Morimoto | 3433bf0 | 2015-06-15 06:22:30 +0000 | [diff] [blame] | 29 | struct snd_soc_dai_link *dai_link; |
Kuninori Morimoto | af7e2be | 2015-03-26 04:01:46 +0000 | [diff] [blame] | 30 | u32 convert_rate; |
Kuninori Morimoto | f90432f | 2016-02-25 05:51:44 +0000 | [diff] [blame] | 31 | u32 convert_channels; |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 32 | }; |
| 33 | |
Kuninori Morimoto | d27f3b4 | 2017-03-15 04:44:16 +0000 | [diff] [blame] | 34 | #define simple_priv_to_card(priv) (&(priv)->snd_card) |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 35 | #define simple_priv_to_props(priv, i) ((priv)->dai_props + (i)) |
Kuninori Morimoto | d27f3b4 | 2017-03-15 04:44:16 +0000 | [diff] [blame] | 36 | #define simple_priv_to_dev(priv) (simple_priv_to_card(priv)->dev) |
| 37 | #define simple_priv_to_link(priv, i) (simple_priv_to_card(priv)->dai_link + (i)) |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 38 | |
Kuninori Morimoto | 5bbf3866 | 2016-08-08 06:02:31 +0000 | [diff] [blame] | 39 | #define DAI "sound-dai" |
| 40 | #define CELL "#sound-dai-cells" |
Kuninori Morimoto | 64df0e6 | 2016-08-23 01:34:43 +0000 | [diff] [blame] | 41 | #define PREFIX "simple-audio-card," |
Kuninori Morimoto | 5bbf3866 | 2016-08-08 06:02:31 +0000 | [diff] [blame] | 42 | |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 43 | static int asoc_simple_card_startup(struct snd_pcm_substream *substream) |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 44 | { |
| 45 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Kuninori Morimoto | 6910e86 | 2016-10-28 03:37:44 +0000 | [diff] [blame] | 46 | struct simple_card_data *priv = snd_soc_card_get_drvdata(rtd->card); |
Kuninori Morimoto | 303c3be | 2016-07-11 23:58:50 +0000 | [diff] [blame] | 47 | struct asoc_simple_dai *dai_props = |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 48 | simple_priv_to_props(priv, rtd->num); |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 49 | |
Kuninori Morimoto | 0470002 | 2015-06-15 06:24:15 +0000 | [diff] [blame] | 50 | return clk_prepare_enable(dai_props->clk); |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 51 | } |
| 52 | |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 53 | static void asoc_simple_card_shutdown(struct snd_pcm_substream *substream) |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 54 | { |
| 55 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Kuninori Morimoto | 6910e86 | 2016-10-28 03:37:44 +0000 | [diff] [blame] | 56 | struct simple_card_data *priv = snd_soc_card_get_drvdata(rtd->card); |
Kuninori Morimoto | 303c3be | 2016-07-11 23:58:50 +0000 | [diff] [blame] | 57 | struct asoc_simple_dai *dai_props = |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 58 | simple_priv_to_props(priv, rtd->num); |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 59 | |
Kuninori Morimoto | 0470002 | 2015-06-15 06:24:15 +0000 | [diff] [blame] | 60 | clk_disable_unprepare(dai_props->clk); |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Julia Lawall | 9b6fdef | 2016-10-15 16:55:49 +0200 | [diff] [blame] | 63 | static const struct snd_soc_ops asoc_simple_card_ops = { |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 64 | .startup = asoc_simple_card_startup, |
| 65 | .shutdown = asoc_simple_card_shutdown, |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 66 | }; |
| 67 | |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 68 | static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd) |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 69 | { |
Kuninori Morimoto | 6910e86 | 2016-10-28 03:37:44 +0000 | [diff] [blame] | 70 | struct simple_card_data *priv = snd_soc_card_get_drvdata(rtd->card); |
Kuninori Morimoto | 0470002 | 2015-06-15 06:24:15 +0000 | [diff] [blame] | 71 | struct snd_soc_dai *dai; |
| 72 | struct snd_soc_dai_link *dai_link; |
Kuninori Morimoto | 303c3be | 2016-07-11 23:58:50 +0000 | [diff] [blame] | 73 | struct asoc_simple_dai *dai_props; |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 74 | int num = rtd->num; |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 75 | |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 76 | dai_link = simple_priv_to_link(priv, num); |
| 77 | dai_props = simple_priv_to_props(priv, num); |
Kuninori Morimoto | 0470002 | 2015-06-15 06:24:15 +0000 | [diff] [blame] | 78 | dai = dai_link->dynamic ? |
| 79 | rtd->cpu_dai : |
| 80 | rtd->codec_dai; |
| 81 | |
Kuninori Morimoto | 600ee20 | 2016-08-09 05:49:21 +0000 | [diff] [blame] | 82 | return asoc_simple_card_init_dai(dai, dai_props); |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 85 | static int asoc_simple_card_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, |
Kuninori Morimoto | af7e2be | 2015-03-26 04:01:46 +0000 | [diff] [blame] | 86 | struct snd_pcm_hw_params *params) |
| 87 | { |
Kuninori Morimoto | 6910e86 | 2016-10-28 03:37:44 +0000 | [diff] [blame] | 88 | struct simple_card_data *priv = snd_soc_card_get_drvdata(rtd->card); |
Kuninori Morimoto | af7e2be | 2015-03-26 04:01:46 +0000 | [diff] [blame] | 89 | struct snd_interval *rate = hw_param_interval(params, |
| 90 | SNDRV_PCM_HW_PARAM_RATE); |
Kuninori Morimoto | f90432f | 2016-02-25 05:51:44 +0000 | [diff] [blame] | 91 | struct snd_interval *channels = hw_param_interval(params, |
| 92 | SNDRV_PCM_HW_PARAM_CHANNELS); |
Kuninori Morimoto | af7e2be | 2015-03-26 04:01:46 +0000 | [diff] [blame] | 93 | |
Kuninori Morimoto | f90432f | 2016-02-25 05:51:44 +0000 | [diff] [blame] | 94 | if (priv->convert_rate) |
| 95 | rate->min = |
| 96 | rate->max = priv->convert_rate; |
Kuninori Morimoto | af7e2be | 2015-03-26 04:01:46 +0000 | [diff] [blame] | 97 | |
Kuninori Morimoto | f90432f | 2016-02-25 05:51:44 +0000 | [diff] [blame] | 98 | if (priv->convert_channels) |
| 99 | channels->min = |
| 100 | channels->max = priv->convert_channels; |
Kuninori Morimoto | af7e2be | 2015-03-26 04:01:46 +0000 | [diff] [blame] | 101 | |
| 102 | return 0; |
| 103 | } |
| 104 | |
Kuninori Morimoto | 15a190ff | 2016-10-28 03:37:26 +0000 | [diff] [blame] | 105 | static int asoc_simple_card_dai_link_of(struct device_node *np, |
Kuninori Morimoto | 6910e86 | 2016-10-28 03:37:44 +0000 | [diff] [blame] | 106 | struct simple_card_data *priv, |
Kuninori Morimoto | 83216f3 | 2016-08-25 01:57:30 +0000 | [diff] [blame] | 107 | unsigned int daifmt, |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 108 | int idx, bool is_fe) |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 109 | { |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 110 | struct device *dev = simple_priv_to_dev(priv); |
| 111 | struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, idx); |
| 112 | struct asoc_simple_dai *dai_props = simple_priv_to_props(priv, idx); |
Kuninori Morimoto | d27f3b4 | 2017-03-15 04:44:16 +0000 | [diff] [blame] | 113 | struct snd_soc_card *card = simple_priv_to_card(priv); |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 114 | int ret; |
| 115 | |
Kuninori Morimoto | 0470002 | 2015-06-15 06:24:15 +0000 | [diff] [blame] | 116 | if (is_fe) { |
Kuninori Morimoto | 27b0108 | 2016-08-10 02:21:03 +0000 | [diff] [blame] | 117 | int is_single_links = 0; |
| 118 | |
Kuninori Morimoto | 0470002 | 2015-06-15 06:24:15 +0000 | [diff] [blame] | 119 | /* BE is dummy */ |
| 120 | dai_link->codec_of_node = NULL; |
| 121 | dai_link->codec_dai_name = "snd-soc-dummy-dai"; |
| 122 | dai_link->codec_name = "snd-soc-dummy"; |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 123 | |
Kuninori Morimoto | 0470002 | 2015-06-15 06:24:15 +0000 | [diff] [blame] | 124 | /* FE settings */ |
| 125 | dai_link->dynamic = 1; |
| 126 | dai_link->dpcm_merged_format = 1; |
Kuninori Morimoto | 5bbf3866 | 2016-08-08 06:02:31 +0000 | [diff] [blame] | 127 | |
| 128 | ret = asoc_simple_card_parse_cpu(np, dai_link, DAI, CELL, |
| 129 | &is_single_links); |
| 130 | if (ret) |
Kuninori Morimoto | 575f1f9 | 2015-12-01 08:33:23 +0000 | [diff] [blame] | 131 | return ret; |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 132 | |
Kuninori Morimoto | e984fd6 | 2017-01-23 07:29:42 +0000 | [diff] [blame] | 133 | ret = asoc_simple_card_parse_clk_cpu(dev, np, dai_link, dai_props); |
Kuninori Morimoto | c9a235d | 2016-07-19 02:53:32 +0000 | [diff] [blame] | 134 | if (ret < 0) |
| 135 | return ret; |
| 136 | |
Kuninori Morimoto | 8a99a6b | 2016-07-11 23:58:25 +0000 | [diff] [blame] | 137 | ret = asoc_simple_card_set_dailink_name(dev, dai_link, |
| 138 | "fe.%s", |
| 139 | dai_link->cpu_dai_name); |
| 140 | if (ret < 0) |
| 141 | return ret; |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 142 | |
Kuninori Morimoto | 27b0108 | 2016-08-10 02:21:03 +0000 | [diff] [blame] | 143 | asoc_simple_card_canonicalize_cpu(dai_link, is_single_links); |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 144 | } else { |
Kuninori Morimoto | 0470002 | 2015-06-15 06:24:15 +0000 | [diff] [blame] | 145 | /* FE is dummy */ |
| 146 | dai_link->cpu_of_node = NULL; |
| 147 | dai_link->cpu_dai_name = "snd-soc-dummy-dai"; |
| 148 | dai_link->cpu_name = "snd-soc-dummy"; |
| 149 | |
| 150 | /* BE settings */ |
| 151 | dai_link->no_pcm = 1; |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 152 | dai_link->be_hw_params_fixup = asoc_simple_card_be_hw_params_fixup; |
Kuninori Morimoto | 5bbf3866 | 2016-08-08 06:02:31 +0000 | [diff] [blame] | 153 | |
| 154 | ret = asoc_simple_card_parse_codec(np, dai_link, DAI, CELL); |
Kuninori Morimoto | 575f1f9 | 2015-12-01 08:33:23 +0000 | [diff] [blame] | 155 | if (ret < 0) |
| 156 | return ret; |
Kuninori Morimoto | 0470002 | 2015-06-15 06:24:15 +0000 | [diff] [blame] | 157 | |
Kuninori Morimoto | e984fd6 | 2017-01-23 07:29:42 +0000 | [diff] [blame] | 158 | ret = asoc_simple_card_parse_clk_codec(dev, np, dai_link, dai_props); |
Kuninori Morimoto | c9a235d | 2016-07-19 02:53:32 +0000 | [diff] [blame] | 159 | if (ret < 0) |
| 160 | return ret; |
| 161 | |
Kuninori Morimoto | 8a99a6b | 2016-07-11 23:58:25 +0000 | [diff] [blame] | 162 | ret = asoc_simple_card_set_dailink_name(dev, dai_link, |
| 163 | "be.%s", |
| 164 | dai_link->codec_dai_name); |
| 165 | if (ret < 0) |
| 166 | return ret; |
| 167 | |
Kuninori Morimoto | d27f3b4 | 2017-03-15 04:44:16 +0000 | [diff] [blame] | 168 | snd_soc_of_parse_audio_prefix(card, |
Kuninori Morimoto | 64df0e6 | 2016-08-23 01:34:43 +0000 | [diff] [blame] | 169 | &priv->codec_conf, |
| 170 | dai_link->codec_of_node, |
| 171 | PREFIX "prefix"); |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 172 | } |
| 173 | |
Kuninori Morimoto | 9f64542 | 2016-08-25 01:58:55 +0000 | [diff] [blame] | 174 | ret = snd_soc_of_parse_tdm_slot(np, |
| 175 | &dai_props->tx_slot_mask, |
| 176 | &dai_props->rx_slot_mask, |
| 177 | &dai_props->slots, |
| 178 | &dai_props->slot_width); |
| 179 | if (ret) |
| 180 | return ret; |
| 181 | |
Kuninori Morimoto | a09f383 | 2016-08-09 05:50:19 +0000 | [diff] [blame] | 182 | ret = asoc_simple_card_canonicalize_dailink(dai_link); |
| 183 | if (ret < 0) |
| 184 | return ret; |
| 185 | |
Kuninori Morimoto | 83216f3 | 2016-08-25 01:57:30 +0000 | [diff] [blame] | 186 | dai_link->dai_fmt = daifmt; |
Kuninori Morimoto | 0470002 | 2015-06-15 06:24:15 +0000 | [diff] [blame] | 187 | dai_link->dpcm_playback = 1; |
| 188 | dai_link->dpcm_capture = 1; |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 189 | dai_link->ops = &asoc_simple_card_ops; |
| 190 | dai_link->init = asoc_simple_card_dai_init; |
Kuninori Morimoto | 0470002 | 2015-06-15 06:24:15 +0000 | [diff] [blame] | 191 | |
Kuninori Morimoto | 0470002 | 2015-06-15 06:24:15 +0000 | [diff] [blame] | 192 | dev_dbg(dev, "\t%s / %04x / %d\n", |
Kuninori Morimoto | 8a99a6b | 2016-07-11 23:58:25 +0000 | [diff] [blame] | 193 | dai_link->name, |
Kuninori Morimoto | ae638b7 | 2015-12-17 02:48:58 +0000 | [diff] [blame] | 194 | dai_link->dai_fmt, |
Kuninori Morimoto | 0470002 | 2015-06-15 06:24:15 +0000 | [diff] [blame] | 195 | dai_props->sysclk); |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 196 | |
Kuninori Morimoto | c9a235d | 2016-07-19 02:53:32 +0000 | [diff] [blame] | 197 | return 0; |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 198 | } |
| 199 | |
Kuninori Morimoto | 15a190ff | 2016-10-28 03:37:26 +0000 | [diff] [blame] | 200 | static int asoc_simple_card_parse_of(struct device_node *node, |
Kuninori Morimoto | 6910e86 | 2016-10-28 03:37:44 +0000 | [diff] [blame] | 201 | struct simple_card_data *priv) |
Kuninori Morimoto | 15a190ff | 2016-10-28 03:37:26 +0000 | [diff] [blame] | 202 | |
Kuninori Morimoto | af998f8 | 2015-12-17 02:49:43 +0000 | [diff] [blame] | 203 | { |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 204 | struct device *dev = simple_priv_to_dev(priv); |
Kuninori Morimoto | af998f8 | 2015-12-17 02:49:43 +0000 | [diff] [blame] | 205 | struct device_node *np; |
Kuninori Morimoto | d27f3b4 | 2017-03-15 04:44:16 +0000 | [diff] [blame] | 206 | struct snd_soc_card *card = simple_priv_to_card(priv); |
Kuninori Morimoto | af998f8 | 2015-12-17 02:49:43 +0000 | [diff] [blame] | 207 | unsigned int daifmt = 0; |
Kuninori Morimoto | af998f8 | 2015-12-17 02:49:43 +0000 | [diff] [blame] | 208 | bool is_fe; |
Kuninori Morimoto | 15a190ff | 2016-10-28 03:37:26 +0000 | [diff] [blame] | 209 | int ret, i; |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 210 | |
| 211 | if (!node) |
| 212 | return -EINVAL; |
| 213 | |
Kuninori Morimoto | d27f3b4 | 2017-03-15 04:44:16 +0000 | [diff] [blame] | 214 | ret = snd_soc_of_parse_audio_routing(card, PREFIX "routing"); |
Kuninori Morimoto | 64df0e6 | 2016-08-23 01:34:43 +0000 | [diff] [blame] | 215 | if (ret < 0) |
| 216 | return ret; |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 217 | |
Kuninori Morimoto | af7e2be | 2015-03-26 04:01:46 +0000 | [diff] [blame] | 218 | /* sampling rate convert */ |
Kuninori Morimoto | 64df0e6 | 2016-08-23 01:34:43 +0000 | [diff] [blame] | 219 | of_property_read_u32(node, PREFIX "convert-rate", &priv->convert_rate); |
Kuninori Morimoto | af7e2be | 2015-03-26 04:01:46 +0000 | [diff] [blame] | 220 | |
Kuninori Morimoto | f90432f | 2016-02-25 05:51:44 +0000 | [diff] [blame] | 221 | /* channels transfer */ |
Kuninori Morimoto | 64df0e6 | 2016-08-23 01:34:43 +0000 | [diff] [blame] | 222 | of_property_read_u32(node, PREFIX "convert-channels", &priv->convert_channels); |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 223 | |
Kuninori Morimoto | 15a190ff | 2016-10-28 03:37:26 +0000 | [diff] [blame] | 224 | /* find 1st codec */ |
| 225 | np = of_get_child_by_name(node, PREFIX "codec"); |
| 226 | if (!np) |
| 227 | return -ENODEV; |
| 228 | |
| 229 | ret = asoc_simple_card_parse_daifmt(dev, node, np, PREFIX, &daifmt); |
Kuninori Morimoto | af998f8 | 2015-12-17 02:49:43 +0000 | [diff] [blame] | 230 | if (ret < 0) |
| 231 | return ret; |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 232 | |
Kuninori Morimoto | 15a190ff | 2016-10-28 03:37:26 +0000 | [diff] [blame] | 233 | i = 0; |
| 234 | for_each_child_of_node(node, np) { |
| 235 | is_fe = false; |
| 236 | if (strcmp(np->name, PREFIX "cpu") == 0) |
| 237 | is_fe = true; |
| 238 | |
| 239 | ret = asoc_simple_card_dai_link_of(np, priv, daifmt, i, is_fe); |
| 240 | if (ret < 0) |
| 241 | return ret; |
| 242 | i++; |
| 243 | } |
| 244 | |
Kuninori Morimoto | d27f3b4 | 2017-03-15 04:44:16 +0000 | [diff] [blame] | 245 | ret = asoc_simple_card_parse_card_name(card, PREFIX); |
Kuninori Morimoto | 53ae918 | 2016-07-12 00:00:00 +0000 | [diff] [blame] | 246 | if (ret < 0) |
| 247 | return ret; |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 248 | |
Kuninori Morimoto | 64df0e6 | 2016-08-23 01:34:43 +0000 | [diff] [blame] | 249 | dev_dbg(dev, "New card: %s\n", |
Kuninori Morimoto | d27f3b4 | 2017-03-15 04:44:16 +0000 | [diff] [blame] | 250 | card->name ? card->name : ""); |
Kuninori Morimoto | 64df0e6 | 2016-08-23 01:34:43 +0000 | [diff] [blame] | 251 | dev_dbg(dev, "convert_rate %d\n", priv->convert_rate); |
| 252 | dev_dbg(dev, "convert_channels %d\n", priv->convert_channels); |
| 253 | |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 254 | return 0; |
| 255 | } |
| 256 | |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 257 | static int asoc_simple_card_probe(struct platform_device *pdev) |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 258 | { |
Kuninori Morimoto | 6910e86 | 2016-10-28 03:37:44 +0000 | [diff] [blame] | 259 | struct simple_card_data *priv; |
Kuninori Morimoto | 1935992 | 2016-10-28 03:38:00 +0000 | [diff] [blame] | 260 | struct snd_soc_dai_link *dai_link; |
| 261 | struct asoc_simple_dai *dai_props; |
Kuninori Morimoto | d27f3b4 | 2017-03-15 04:44:16 +0000 | [diff] [blame] | 262 | struct snd_soc_card *card; |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 263 | struct device *dev = &pdev->dev; |
Kuninori Morimoto | 40b68da | 2017-03-15 04:43:40 +0000 | [diff] [blame] | 264 | struct device_node *np = dev->of_node; |
Kuninori Morimoto | 15a190ff | 2016-10-28 03:37:26 +0000 | [diff] [blame] | 265 | int num, ret; |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 266 | |
| 267 | /* Allocate the private data */ |
| 268 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); |
| 269 | if (!priv) |
| 270 | return -ENOMEM; |
| 271 | |
Kuninori Morimoto | 15a190ff | 2016-10-28 03:37:26 +0000 | [diff] [blame] | 272 | num = of_get_child_count(np); |
| 273 | |
Kuninori Morimoto | 1935992 | 2016-10-28 03:38:00 +0000 | [diff] [blame] | 274 | dai_props = devm_kzalloc(dev, sizeof(*dai_props) * num, GFP_KERNEL); |
| 275 | dai_link = devm_kzalloc(dev, sizeof(*dai_link) * num, GFP_KERNEL); |
| 276 | if (!dai_props || !dai_link) |
Kuninori Morimoto | 15a190ff | 2016-10-28 03:37:26 +0000 | [diff] [blame] | 277 | return -ENOMEM; |
| 278 | |
Kuninori Morimoto | 1935992 | 2016-10-28 03:38:00 +0000 | [diff] [blame] | 279 | priv->dai_props = dai_props; |
| 280 | priv->dai_link = dai_link; |
Kuninori Morimoto | 15a190ff | 2016-10-28 03:37:26 +0000 | [diff] [blame] | 281 | |
| 282 | /* Init snd_soc_card */ |
Kuninori Morimoto | d27f3b4 | 2017-03-15 04:44:16 +0000 | [diff] [blame] | 283 | card = simple_priv_to_card(priv); |
| 284 | card->owner = THIS_MODULE; |
| 285 | card->dev = dev; |
| 286 | card->dai_link = priv->dai_link; |
| 287 | card->num_links = num; |
| 288 | card->codec_conf = &priv->codec_conf; |
| 289 | card->num_configs = 1; |
Kuninori Morimoto | 15a190ff | 2016-10-28 03:37:26 +0000 | [diff] [blame] | 290 | |
| 291 | ret = asoc_simple_card_parse_of(np, priv); |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 292 | if (ret < 0) { |
| 293 | if (ret != -EPROBE_DEFER) |
| 294 | dev_err(dev, "parse error %d\n", ret); |
| 295 | goto err; |
| 296 | } |
| 297 | |
Kuninori Morimoto | d27f3b4 | 2017-03-15 04:44:16 +0000 | [diff] [blame] | 298 | snd_soc_card_set_drvdata(card, priv); |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 299 | |
Kuninori Morimoto | d27f3b4 | 2017-03-15 04:44:16 +0000 | [diff] [blame] | 300 | ret = devm_snd_soc_register_card(dev, card); |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 301 | if (ret >= 0) |
| 302 | return ret; |
| 303 | err: |
Kuninori Morimoto | d27f3b4 | 2017-03-15 04:44:16 +0000 | [diff] [blame] | 304 | asoc_simple_card_clean_reference(card); |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 305 | |
| 306 | return ret; |
| 307 | } |
| 308 | |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 309 | static int asoc_simple_card_remove(struct platform_device *pdev) |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 310 | { |
| 311 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
| 312 | |
Kuninori Morimoto | 239486b | 2016-08-10 02:22:01 +0000 | [diff] [blame] | 313 | return asoc_simple_card_clean_reference(card); |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 314 | } |
| 315 | |
Kuninori Morimoto | f4d70709 | 2016-08-25 01:58:31 +0000 | [diff] [blame] | 316 | static const struct of_device_id asoc_simple_of_match[] = { |
| 317 | { .compatible = "renesas,rsrc-card", }, |
| 318 | { .compatible = "simple-scu-audio-card", }, |
| 319 | {}, |
| 320 | }; |
| 321 | MODULE_DEVICE_TABLE(of, asoc_simple_of_match); |
| 322 | |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 323 | static struct platform_driver asoc_simple_card = { |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 324 | .driver = { |
Kuninori Morimoto | 64df0e6 | 2016-08-23 01:34:43 +0000 | [diff] [blame] | 325 | .name = "simple-scu-audio-card", |
Kuninori Morimoto | f4d70709 | 2016-08-25 01:58:31 +0000 | [diff] [blame] | 326 | .of_match_table = asoc_simple_of_match, |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 327 | }, |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 328 | .probe = asoc_simple_card_probe, |
| 329 | .remove = asoc_simple_card_remove, |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 330 | }; |
| 331 | |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 332 | module_platform_driver(asoc_simple_card); |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 333 | |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 334 | MODULE_ALIAS("platform:asoc-simple-scu-card"); |
Kuninori Morimoto | 93bc047 | 2016-08-25 01:56:38 +0000 | [diff] [blame] | 335 | MODULE_LICENSE("GPL v2"); |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 336 | MODULE_DESCRIPTION("ASoC Simple SCU Sound Card"); |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 337 | MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>"); |