Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * snappercl15.c -- SoC audio for Bluewater Systems Snapper CL15 module
0004  *
0005  * Copyright (C) 2008 Bluewater Systems Ltd
0006  * Author: Ryan Mallon
0007  */
0008 
0009 #include <linux/platform_device.h>
0010 #include <linux/module.h>
0011 #include <linux/soc/cirrus/ep93xx.h>
0012 #include <sound/core.h>
0013 #include <sound/pcm.h>
0014 #include <sound/soc.h>
0015 
0016 #include <asm/mach-types.h>
0017 
0018 #include "../codecs/tlv320aic23.h"
0019 
0020 #define CODEC_CLOCK 5644800
0021 
0022 static int snappercl15_hw_params(struct snd_pcm_substream *substream,
0023                  struct snd_pcm_hw_params *params)
0024 {
0025     struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
0026     struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
0027     struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
0028     int err;
0029 
0030     err = snd_soc_dai_set_sysclk(codec_dai, 0, CODEC_CLOCK, 
0031                      SND_SOC_CLOCK_IN);
0032     if (err)
0033         return err;
0034 
0035     err = snd_soc_dai_set_sysclk(cpu_dai, 0, CODEC_CLOCK, 
0036                      SND_SOC_CLOCK_OUT);
0037     if (err)
0038         return err;
0039 
0040     return 0;
0041 }
0042 
0043 static const struct snd_soc_ops snappercl15_ops = {
0044     .hw_params  = snappercl15_hw_params,
0045 };
0046 
0047 static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = {
0048     SND_SOC_DAPM_HP("Headphone Jack", NULL),
0049     SND_SOC_DAPM_LINE("Line In", NULL),
0050     SND_SOC_DAPM_MIC("Mic Jack", NULL),
0051 };
0052 
0053 static const struct snd_soc_dapm_route audio_map[] = {
0054     {"Headphone Jack", NULL, "LHPOUT"},
0055     {"Headphone Jack", NULL, "RHPOUT"},
0056 
0057     {"LLINEIN", NULL, "Line In"},
0058     {"RLINEIN", NULL, "Line In"},
0059 
0060     {"MICIN", NULL, "Mic Jack"},
0061 };
0062 
0063 SND_SOC_DAILINK_DEFS(aic23,
0064     DAILINK_COMP_ARRAY(COMP_CPU("ep93xx-i2s")),
0065     DAILINK_COMP_ARRAY(COMP_CODEC("tlv320aic23-codec.0-001a",
0066                       "tlv320aic23-hifi")),
0067     DAILINK_COMP_ARRAY(COMP_PLATFORM("ep93xx-i2s")));
0068 
0069 static struct snd_soc_dai_link snappercl15_dai = {
0070     .name       = "tlv320aic23",
0071     .stream_name    = "AIC23",
0072     .dai_fmt    = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
0073               SND_SOC_DAIFMT_CBC_CFC,
0074     .ops        = &snappercl15_ops,
0075     SND_SOC_DAILINK_REG(aic23),
0076 };
0077 
0078 static struct snd_soc_card snd_soc_snappercl15 = {
0079     .name       = "Snapper CL15",
0080     .owner      = THIS_MODULE,
0081     .dai_link   = &snappercl15_dai,
0082     .num_links  = 1,
0083 
0084     .dapm_widgets       = tlv320aic23_dapm_widgets,
0085     .num_dapm_widgets   = ARRAY_SIZE(tlv320aic23_dapm_widgets),
0086     .dapm_routes        = audio_map,
0087     .num_dapm_routes    = ARRAY_SIZE(audio_map),
0088 };
0089 
0090 static int snappercl15_probe(struct platform_device *pdev)
0091 {
0092     struct snd_soc_card *card = &snd_soc_snappercl15;
0093     int ret;
0094 
0095     ret = ep93xx_i2s_acquire();
0096     if (ret)
0097         return ret;
0098 
0099     card->dev = &pdev->dev;
0100 
0101     ret = snd_soc_register_card(card);
0102     if (ret) {
0103         dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
0104             ret);
0105         ep93xx_i2s_release();
0106     }
0107 
0108     return ret;
0109 }
0110 
0111 static int snappercl15_remove(struct platform_device *pdev)
0112 {
0113     struct snd_soc_card *card = platform_get_drvdata(pdev);
0114 
0115     snd_soc_unregister_card(card);
0116     ep93xx_i2s_release();
0117 
0118     return 0;
0119 }
0120 
0121 static struct platform_driver snappercl15_driver = {
0122     .driver     = {
0123         .name   = "snappercl15-audio",
0124     },
0125     .probe      = snappercl15_probe,
0126     .remove     = snappercl15_remove,
0127 };
0128 
0129 module_platform_driver(snappercl15_driver);
0130 
0131 MODULE_AUTHOR("Ryan Mallon");
0132 MODULE_DESCRIPTION("ALSA SoC Snapper CL15");
0133 MODULE_LICENSE("GPL");
0134 MODULE_ALIAS("platform:snappercl15-audio");