Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 //
0003 // Copyright 2007,2008 Simtec Electronics
0004 //
0005 // Based on sound/soc/pxa/spitz.c
0006 //  Copyright 2005 Wolfson Microelectronics PLC.
0007 //  Copyright 2005 Openedhand Ltd.
0008 
0009 #include <linux/module.h>
0010 #include <sound/soc.h>
0011 
0012 #include <asm/mach-types.h>
0013 
0014 #include "s3c2412-i2s.h"
0015 #include "../codecs/wm8750.h"
0016 
0017 static const struct snd_soc_dapm_route audio_map[] = {
0018     { "Headphone Jack", NULL, "LOUT1" },
0019     { "Headphone Jack", NULL, "ROUT1" },
0020     { "Internal Speaker", NULL, "LOUT2" },
0021     { "Internal Speaker", NULL, "ROUT2" },
0022     { "LINPUT1", NULL, "Line Input" },
0023     { "RINPUT1", NULL, "Line Input" },
0024 };
0025 
0026 static const struct snd_soc_dapm_widget wm8750_dapm_widgets[] = {
0027     SND_SOC_DAPM_HP("Headphone Jack", NULL),
0028     SND_SOC_DAPM_SPK("Internal Speaker", NULL),
0029     SND_SOC_DAPM_LINE("Line In", NULL),
0030 };
0031 
0032 static int jive_hw_params(struct snd_pcm_substream *substream,
0033               struct snd_pcm_hw_params *params)
0034 {
0035     struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
0036     struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
0037     struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
0038     struct s3c_i2sv2_rate_calc div;
0039     unsigned int clk = 0;
0040     int ret = 0;
0041 
0042     switch (params_rate(params)) {
0043     case 8000:
0044     case 16000:
0045     case 48000:
0046     case 96000:
0047         clk = 12288000;
0048         break;
0049     case 11025:
0050     case 22050:
0051     case 44100:
0052         clk = 11289600;
0053         break;
0054     }
0055 
0056     s3c_i2sv2_iis_calc_rate(&div, NULL, params_rate(params),
0057                 s3c_i2sv2_get_clock(cpu_dai));
0058 
0059     /* set the codec system clock for DAC and ADC */
0060     ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk,
0061                      SND_SOC_CLOCK_IN);
0062     if (ret < 0)
0063         return ret;
0064 
0065     ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C2412_DIV_RCLK, div.fs_div);
0066     if (ret < 0)
0067         return ret;
0068 
0069     ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C2412_DIV_PRESCALER,
0070                      div.clk_div - 1);
0071     if (ret < 0)
0072         return ret;
0073 
0074     return 0;
0075 }
0076 
0077 static const struct snd_soc_ops jive_ops = {
0078     .hw_params  = jive_hw_params,
0079 };
0080 
0081 SND_SOC_DAILINK_DEFS(wm8750,
0082     DAILINK_COMP_ARRAY(COMP_CPU("s3c2412-i2s")),
0083     DAILINK_COMP_ARRAY(COMP_CODEC("wm8750.0-001a", "wm8750-hifi")),
0084     DAILINK_COMP_ARRAY(COMP_PLATFORM("s3c2412-i2s")));
0085 
0086 static struct snd_soc_dai_link jive_dai = {
0087     .name       = "wm8750",
0088     .stream_name    = "WM8750",
0089     .dai_fmt    = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
0090               SND_SOC_DAIFMT_CBS_CFS,
0091     .ops        = &jive_ops,
0092     SND_SOC_DAILINK_REG(wm8750),
0093 };
0094 
0095 /* jive audio machine driver */
0096 static struct snd_soc_card snd_soc_machine_jive = {
0097     .name       = "Jive",
0098     .owner      = THIS_MODULE,
0099     .dai_link   = &jive_dai,
0100     .num_links  = 1,
0101 
0102     .dapm_widgets   = wm8750_dapm_widgets,
0103     .num_dapm_widgets = ARRAY_SIZE(wm8750_dapm_widgets),
0104     .dapm_routes    = audio_map,
0105     .num_dapm_routes = ARRAY_SIZE(audio_map),
0106     .fully_routed   = true,
0107 };
0108 
0109 static struct platform_device *jive_snd_device;
0110 
0111 static int __init jive_init(void)
0112 {
0113     int ret;
0114 
0115     if (!machine_is_jive())
0116         return 0;
0117 
0118     printk("JIVE WM8750 Audio support\n");
0119 
0120     jive_snd_device = platform_device_alloc("soc-audio", -1);
0121     if (!jive_snd_device)
0122         return -ENOMEM;
0123 
0124     platform_set_drvdata(jive_snd_device, &snd_soc_machine_jive);
0125     ret = platform_device_add(jive_snd_device);
0126 
0127     if (ret)
0128         platform_device_put(jive_snd_device);
0129 
0130     return ret;
0131 }
0132 
0133 static void __exit jive_exit(void)
0134 {
0135     platform_device_unregister(jive_snd_device);
0136 }
0137 
0138 module_init(jive_init);
0139 module_exit(jive_exit);
0140 
0141 MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
0142 MODULE_DESCRIPTION("ALSA SoC Jive Audio support");
0143 MODULE_LICENSE("GPL");