linux/sound/soc/samsung/jive_wm8750.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0
   2//
   3// Copyright 2007,2008 Simtec Electronics
   4//
   5// Based on sound/soc/pxa/spitz.c
   6//      Copyright 2005 Wolfson Microelectronics PLC.
   7//      Copyright 2005 Openedhand Ltd.
   8
   9#include <linux/module.h>
  10#include <sound/soc.h>
  11
  12#include <asm/mach-types.h>
  13
  14#include "s3c2412-i2s.h"
  15#include "../codecs/wm8750.h"
  16
  17static const struct snd_soc_dapm_route audio_map[] = {
  18        { "Headphone Jack", NULL, "LOUT1" },
  19        { "Headphone Jack", NULL, "ROUT1" },
  20        { "Internal Speaker", NULL, "LOUT2" },
  21        { "Internal Speaker", NULL, "ROUT2" },
  22        { "LINPUT1", NULL, "Line Input" },
  23        { "RINPUT1", NULL, "Line Input" },
  24};
  25
  26static const struct snd_soc_dapm_widget wm8750_dapm_widgets[] = {
  27        SND_SOC_DAPM_HP("Headphone Jack", NULL),
  28        SND_SOC_DAPM_SPK("Internal Speaker", NULL),
  29        SND_SOC_DAPM_LINE("Line In", NULL),
  30};
  31
  32static int jive_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        struct s3c_i2sv2_rate_calc div;
  39        unsigned int clk = 0;
  40        int ret = 0;
  41
  42        switch (params_rate(params)) {
  43        case 8000:
  44        case 16000:
  45        case 48000:
  46        case 96000:
  47                clk = 12288000;
  48                break;
  49        case 11025:
  50        case 22050:
  51        case 44100:
  52                clk = 11289600;
  53                break;
  54        }
  55
  56        s3c_i2sv2_iis_calc_rate(&div, NULL, params_rate(params),
  57                                s3c_i2sv2_get_clock(cpu_dai));
  58
  59        /* set the codec system clock for DAC and ADC */
  60        ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk,
  61                                     SND_SOC_CLOCK_IN);
  62        if (ret < 0)
  63                return ret;
  64
  65        ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C2412_DIV_RCLK, div.fs_div);
  66        if (ret < 0)
  67                return ret;
  68
  69        ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C2412_DIV_PRESCALER,
  70                                     div.clk_div - 1);
  71        if (ret < 0)
  72                return ret;
  73
  74        return 0;
  75}
  76
  77static const struct snd_soc_ops jive_ops = {
  78        .hw_params      = jive_hw_params,
  79};
  80
  81static struct snd_soc_dai_link jive_dai = {
  82        .name           = "wm8750",
  83        .stream_name    = "WM8750",
  84        .cpu_dai_name   = "s3c2412-i2s",
  85        .codec_dai_name = "wm8750-hifi",
  86        .platform_name  = "s3c2412-i2s",
  87        .codec_name     = "wm8750.0-001a",
  88        .dai_fmt        = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  89                          SND_SOC_DAIFMT_CBS_CFS,
  90        .ops            = &jive_ops,
  91};
  92
  93/* jive audio machine driver */
  94static struct snd_soc_card snd_soc_machine_jive = {
  95        .name           = "Jive",
  96        .owner          = THIS_MODULE,
  97        .dai_link       = &jive_dai,
  98        .num_links      = 1,
  99
 100        .dapm_widgets   = wm8750_dapm_widgets,
 101        .num_dapm_widgets = ARRAY_SIZE(wm8750_dapm_widgets),
 102        .dapm_routes    = audio_map,
 103        .num_dapm_routes = ARRAY_SIZE(audio_map),
 104        .fully_routed   = true,
 105};
 106
 107static struct platform_device *jive_snd_device;
 108
 109static int __init jive_init(void)
 110{
 111        int ret;
 112
 113        if (!machine_is_jive())
 114                return 0;
 115
 116        printk("JIVE WM8750 Audio support\n");
 117
 118        jive_snd_device = platform_device_alloc("soc-audio", -1);
 119        if (!jive_snd_device)
 120                return -ENOMEM;
 121
 122        platform_set_drvdata(jive_snd_device, &snd_soc_machine_jive);
 123        ret = platform_device_add(jive_snd_device);
 124
 125        if (ret)
 126                platform_device_put(jive_snd_device);
 127
 128        return ret;
 129}
 130
 131static void __exit jive_exit(void)
 132{
 133        platform_device_unregister(jive_snd_device);
 134}
 135
 136module_init(jive_init);
 137module_exit(jive_exit);
 138
 139MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
 140MODULE_DESCRIPTION("ALSA SoC Jive Audio support");
 141MODULE_LICENSE("GPL");
 142