~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/sound/soc/mxs/mxs-sgtl5000.c

Version: ~ [ linux-6.3-rc3 ] ~ [ linux-6.2.7 ] ~ [ linux-6.1.20 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.103 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.175 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.237 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.278 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.310 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * Copyright 2011 Freescale Semiconductor, Inc.
  3  *
  4  * This program is free software; you can redistribute it and/or modify
  5  * it under the terms of the GNU General Public License as published by
  6  * the Free Software Foundation; either version 2 of the License, or
  7  * (at your option) any later version.
  8  *
  9  * This program is distributed in the hope that it will be useful,
 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 12  * GNU General Public License for more details.
 13  *
 14  * You should have received a copy of the GNU General Public License along
 15  * with this program; if not, write to the Free Software Foundation, Inc.,
 16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 17  */
 18 
 19 #include <linux/module.h>
 20 #include <linux/device.h>
 21 #include <linux/of.h>
 22 #include <linux/of_device.h>
 23 #include <sound/core.h>
 24 #include <sound/pcm.h>
 25 #include <sound/soc.h>
 26 #include <sound/jack.h>
 27 #include <sound/soc-dapm.h>
 28 
 29 #include "../codecs/sgtl5000.h"
 30 #include "mxs-saif.h"
 31 
 32 static int mxs_sgtl5000_hw_params(struct snd_pcm_substream *substream,
 33         struct snd_pcm_hw_params *params)
 34 {
 35         struct snd_soc_pcm_runtime *rtd = substream->private_data;
 36         struct snd_soc_dai *codec_dai = rtd->codec_dai;
 37         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
 38         unsigned int rate = params_rate(params);
 39         u32 mclk;
 40         int ret;
 41 
 42         /* sgtl5000 does not support 512*rate when in 96000 fs */
 43         switch (rate) {
 44         case 96000:
 45                 mclk = 256 * rate;
 46                 break;
 47         default:
 48                 mclk = 512 * rate;
 49                 break;
 50         }
 51 
 52         /* Set SGTL5000's SYSCLK (provided by SAIF MCLK) */
 53         ret = snd_soc_dai_set_sysclk(codec_dai, SGTL5000_SYSCLK, mclk, 0);
 54         if (ret) {
 55                 dev_err(codec_dai->dev, "Failed to set sysclk to %u.%03uMHz\n",
 56                         mclk / 1000000, mclk / 1000 % 1000);
 57                 return ret;
 58         }
 59 
 60         /* The SAIF MCLK should be the same as SGTL5000_SYSCLK */
 61         ret = snd_soc_dai_set_sysclk(cpu_dai, MXS_SAIF_MCLK, mclk, 0);
 62         if (ret) {
 63                 dev_err(cpu_dai->dev, "Failed to set sysclk to %u.%03uMHz\n",
 64                         mclk / 1000000, mclk / 1000 % 1000);
 65                 return ret;
 66         }
 67 
 68         return 0;
 69 }
 70 
 71 static const struct snd_soc_ops mxs_sgtl5000_hifi_ops = {
 72         .hw_params = mxs_sgtl5000_hw_params,
 73 };
 74 
 75 #define MXS_SGTL5000_DAI_FMT (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | \
 76         SND_SOC_DAIFMT_CBS_CFS)
 77 
 78 static struct snd_soc_dai_link mxs_sgtl5000_dai[] = {
 79         {
 80                 .name           = "HiFi Tx",
 81                 .stream_name    = "HiFi Playback",
 82                 .codec_dai_name = "sgtl5000",
 83                 .dai_fmt        = MXS_SGTL5000_DAI_FMT,
 84                 .ops            = &mxs_sgtl5000_hifi_ops,
 85                 .playback_only  = true,
 86         }, {
 87                 .name           = "HiFi Rx",
 88                 .stream_name    = "HiFi Capture",
 89                 .codec_dai_name = "sgtl5000",
 90                 .dai_fmt        = MXS_SGTL5000_DAI_FMT,
 91                 .ops            = &mxs_sgtl5000_hifi_ops,
 92                 .capture_only   = true,
 93         },
 94 };
 95 
 96 static struct snd_soc_card mxs_sgtl5000 = {
 97         .name           = "mxs_sgtl5000",
 98         .owner          = THIS_MODULE,
 99         .dai_link       = mxs_sgtl5000_dai,
100         .num_links      = ARRAY_SIZE(mxs_sgtl5000_dai),
101 };
102 
103 static int mxs_sgtl5000_probe(struct platform_device *pdev)
104 {
105         struct snd_soc_card *card = &mxs_sgtl5000;
106         int ret, i;
107         struct device_node *np = pdev->dev.of_node;
108         struct device_node *saif_np[2], *codec_np;
109 
110         saif_np[0] = of_parse_phandle(np, "saif-controllers", 0);
111         saif_np[1] = of_parse_phandle(np, "saif-controllers", 1);
112         codec_np = of_parse_phandle(np, "audio-codec", 0);
113         if (!saif_np[0] || !saif_np[1] || !codec_np) {
114                 dev_err(&pdev->dev, "phandle missing or invalid\n");
115                 return -EINVAL;
116         }
117 
118         for (i = 0; i < 2; i++) {
119                 mxs_sgtl5000_dai[i].codec_name = NULL;
120                 mxs_sgtl5000_dai[i].codec_of_node = codec_np;
121                 mxs_sgtl5000_dai[i].cpu_dai_name = NULL;
122                 mxs_sgtl5000_dai[i].cpu_of_node = saif_np[i];
123                 mxs_sgtl5000_dai[i].platform_name = NULL;
124                 mxs_sgtl5000_dai[i].platform_of_node = saif_np[i];
125         }
126 
127         of_node_put(codec_np);
128         of_node_put(saif_np[0]);
129         of_node_put(saif_np[1]);
130 
131         /*
132          * Set an init clock(11.28Mhz) for sgtl5000 initialization(i2c r/w).
133          * The Sgtl5000 sysclk is derived from saif0 mclk and it's range
134          * should be >= 8MHz and <= 27M.
135          */
136         ret = mxs_saif_get_mclk(0, 44100 * 256, 44100);
137         if (ret) {
138                 dev_err(&pdev->dev, "failed to get mclk\n");
139                 return ret;
140         }
141 
142         card->dev = &pdev->dev;
143         platform_set_drvdata(pdev, card);
144 
145         ret = devm_snd_soc_register_card(&pdev->dev, card);
146         if (ret) {
147                 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
148                         ret);
149                 return ret;
150         }
151 
152         return 0;
153 }
154 
155 static int mxs_sgtl5000_remove(struct platform_device *pdev)
156 {
157         mxs_saif_put_mclk(0);
158 
159         return 0;
160 }
161 
162 static const struct of_device_id mxs_sgtl5000_dt_ids[] = {
163         { .compatible = "fsl,mxs-audio-sgtl5000", },
164         { /* sentinel */ }
165 };
166 MODULE_DEVICE_TABLE(of, mxs_sgtl5000_dt_ids);
167 
168 static struct platform_driver mxs_sgtl5000_audio_driver = {
169         .driver = {
170                 .name = "mxs-sgtl5000",
171                 .of_match_table = mxs_sgtl5000_dt_ids,
172         },
173         .probe = mxs_sgtl5000_probe,
174         .remove = mxs_sgtl5000_remove,
175 };
176 
177 module_platform_driver(mxs_sgtl5000_audio_driver);
178 
179 MODULE_AUTHOR("Freescale Semiconductor, Inc.");
180 MODULE_DESCRIPTION("MXS ALSA SoC Machine driver");
181 MODULE_LICENSE("GPL");
182 MODULE_ALIAS("platform:mxs-sgtl5000");
183 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp