linux/sound/soc/samsung/smdk_wm8580.c
<<
>>
Prefs
   1/*
   2 *  smdk_wm8580.c
   3 *
   4 *  Copyright (c) 2009 Samsung Electronics Co. Ltd
   5 *  Author: Jaswinder Singh <jassisinghbrar@gmail.com>
   6 *
   7 *  This program is free software; you can redistribute  it and/or modify it
   8 *  under  the terms of  the GNU General  Public License as published by the
   9 *  Free Software Foundation;  either version 2 of the  License, or (at your
  10 *  option) any later version.
  11 */
  12
  13#include <linux/module.h>
  14#include <sound/soc.h>
  15#include <sound/pcm_params.h>
  16
  17#include <asm/mach-types.h>
  18
  19#include "../codecs/wm8580.h"
  20#include "i2s.h"
  21
  22/*
  23 * Default CFG switch settings to use this driver:
  24 *
  25 *   SMDK6410: Set CFG1 1-3 Off, CFG2 1-4 On
  26 */
  27
  28/* SMDK has a 12MHZ crystal attached to WM8580 */
  29#define SMDK_WM8580_FREQ 12000000
  30
  31static int smdk_hw_params(struct snd_pcm_substream *substream,
  32        struct snd_pcm_hw_params *params)
  33{
  34        struct snd_soc_pcm_runtime *rtd = substream->private_data;
  35        struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  36        struct snd_soc_dai *codec_dai = rtd->codec_dai;
  37        unsigned int pll_out;
  38        int bfs, rfs, ret;
  39
  40        switch (params_format(params)) {
  41        case SNDRV_PCM_FORMAT_U8:
  42        case SNDRV_PCM_FORMAT_S8:
  43                bfs = 16;
  44                break;
  45        case SNDRV_PCM_FORMAT_U16_LE:
  46        case SNDRV_PCM_FORMAT_S16_LE:
  47                bfs = 32;
  48                break;
  49        default:
  50                return -EINVAL;
  51        }
  52
  53        /* The Fvco for WM8580 PLLs must fall within [90,100]MHz.
  54         * This criterion can't be met if we request PLL output
  55         * as {8000x256, 64000x256, 11025x256}Hz.
  56         * As a wayout, we rather change rfs to a minimum value that
  57         * results in (params_rate(params) * rfs), and itself, acceptable
  58         * to both - the CODEC and the CPU.
  59         */
  60        switch (params_rate(params)) {
  61        case 16000:
  62        case 22050:
  63        case 32000:
  64        case 44100:
  65        case 48000:
  66        case 88200:
  67        case 96000:
  68                rfs = 256;
  69                break;
  70        case 64000:
  71                rfs = 384;
  72                break;
  73        case 8000:
  74        case 11025:
  75                rfs = 512;
  76                break;
  77        default:
  78                return -EINVAL;
  79        }
  80        pll_out = params_rate(params) * rfs;
  81
  82        /* Set the Codec DAI configuration */
  83        ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
  84                                         | SND_SOC_DAIFMT_NB_NF
  85                                         | SND_SOC_DAIFMT_CBM_CFM);
  86        if (ret < 0)
  87                return ret;
  88
  89        /* Set the AP DAI configuration */
  90        ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
  91                                         | SND_SOC_DAIFMT_NB_NF
  92                                         | SND_SOC_DAIFMT_CBM_CFM);
  93        if (ret < 0)
  94                return ret;
  95
  96        /* Set WM8580 to drive MCLK from its PLLA */
  97        ret = snd_soc_dai_set_clkdiv(codec_dai, WM8580_MCLK,
  98                                        WM8580_CLKSRC_PLLA);
  99        if (ret < 0)
 100                return ret;
 101
 102        ret = snd_soc_dai_set_pll(codec_dai, WM8580_PLLA, 0,
 103                                        SMDK_WM8580_FREQ, pll_out);
 104        if (ret < 0)
 105                return ret;
 106
 107        ret = snd_soc_dai_set_sysclk(codec_dai, WM8580_CLKSRC_PLLA,
 108                                     pll_out, SND_SOC_CLOCK_IN);
 109        if (ret < 0)
 110                return ret;
 111
 112        return 0;
 113}
 114
 115/*
 116 * SMDK WM8580 DAI operations.
 117 */
 118static struct snd_soc_ops smdk_ops = {
 119        .hw_params = smdk_hw_params,
 120};
 121
 122/* SMDK Playback widgets */
 123static const struct snd_soc_dapm_widget smdk_wm8580_dapm_widgets[] = {
 124        SND_SOC_DAPM_HP("Front", NULL),
 125        SND_SOC_DAPM_HP("Center+Sub", NULL),
 126        SND_SOC_DAPM_HP("Rear", NULL),
 127
 128        SND_SOC_DAPM_MIC("MicIn", NULL),
 129        SND_SOC_DAPM_LINE("LineIn", NULL),
 130};
 131
 132/* SMDK-PAIFTX connections */
 133static const struct snd_soc_dapm_route smdk_wm8580_audio_map[] = {
 134        /* MicIn feeds AINL */
 135        {"AINL", NULL, "MicIn"},
 136
 137        /* LineIn feeds AINL/R */
 138        {"AINL", NULL, "LineIn"},
 139        {"AINR", NULL, "LineIn"},
 140
 141        /* Front Left/Right are fed VOUT1L/R */
 142        {"Front", NULL, "VOUT1L"},
 143        {"Front", NULL, "VOUT1R"},
 144
 145        /* Center/Sub are fed VOUT2L/R */
 146        {"Center+Sub", NULL, "VOUT2L"},
 147        {"Center+Sub", NULL, "VOUT2R"},
 148
 149        /* Rear Left/Right are fed VOUT3L/R */
 150        {"Rear", NULL, "VOUT3L"},
 151        {"Rear", NULL, "VOUT3R"},
 152};
 153
 154static int smdk_wm8580_init_paiftx(struct snd_soc_pcm_runtime *rtd)
 155{
 156        struct snd_soc_codec *codec = rtd->codec;
 157        struct snd_soc_dapm_context *dapm = &codec->dapm;
 158
 159        /* Enabling the microphone requires the fitting of a 0R
 160         * resistor to connect the line from the microphone jack.
 161         */
 162        snd_soc_dapm_disable_pin(dapm, "MicIn");
 163
 164        return 0;
 165}
 166
 167enum {
 168        PRI_PLAYBACK = 0,
 169        PRI_CAPTURE,
 170        SEC_PLAYBACK,
 171};
 172
 173static struct snd_soc_dai_link smdk_dai[] = {
 174        [PRI_PLAYBACK] = { /* Primary Playback i/f */
 175                .name = "WM8580 PAIF RX",
 176                .stream_name = "Playback",
 177                .cpu_dai_name = "samsung-i2s.0",
 178                .codec_dai_name = "wm8580-hifi-playback",
 179                .platform_name = "samsung-i2s.0",
 180                .codec_name = "wm8580.0-001b",
 181                .ops = &smdk_ops,
 182        },
 183        [PRI_CAPTURE] = { /* Primary Capture i/f */
 184                .name = "WM8580 PAIF TX",
 185                .stream_name = "Capture",
 186                .cpu_dai_name = "samsung-i2s.0",
 187                .codec_dai_name = "wm8580-hifi-capture",
 188                .platform_name = "samsung-i2s.0",
 189                .codec_name = "wm8580.0-001b",
 190                .init = smdk_wm8580_init_paiftx,
 191                .ops = &smdk_ops,
 192        },
 193        [SEC_PLAYBACK] = { /* Sec_Fifo Playback i/f */
 194                .name = "Sec_FIFO TX",
 195                .stream_name = "Playback",
 196                .cpu_dai_name = "samsung-i2s-sec",
 197                .codec_dai_name = "wm8580-hifi-playback",
 198                .platform_name = "samsung-i2s-sec",
 199                .codec_name = "wm8580.0-001b",
 200                .ops = &smdk_ops,
 201        },
 202};
 203
 204static struct snd_soc_card smdk = {
 205        .name = "SMDK-I2S",
 206        .owner = THIS_MODULE,
 207        .dai_link = smdk_dai,
 208        .num_links = 2,
 209
 210        .dapm_widgets = smdk_wm8580_dapm_widgets,
 211        .num_dapm_widgets = ARRAY_SIZE(smdk_wm8580_dapm_widgets),
 212        .dapm_routes = smdk_wm8580_audio_map,
 213        .num_dapm_routes = ARRAY_SIZE(smdk_wm8580_audio_map),
 214};
 215
 216static struct platform_device *smdk_snd_device;
 217
 218static int __init smdk_audio_init(void)
 219{
 220        int ret;
 221        char *str;
 222
 223        if (machine_is_smdkc100()
 224                        || machine_is_smdkv210() || machine_is_smdkc110()) {
 225                smdk.num_links = 3;
 226        } else if (machine_is_smdk6410()) {
 227                str = (char *)smdk_dai[PRI_PLAYBACK].cpu_dai_name;
 228                str[strlen(str) - 1] = '2';
 229                str = (char *)smdk_dai[PRI_CAPTURE].cpu_dai_name;
 230                str[strlen(str) - 1] = '2';
 231        }
 232
 233        smdk_snd_device = platform_device_alloc("soc-audio", -1);
 234        if (!smdk_snd_device)
 235                return -ENOMEM;
 236
 237        platform_set_drvdata(smdk_snd_device, &smdk);
 238        ret = platform_device_add(smdk_snd_device);
 239
 240        if (ret)
 241                platform_device_put(smdk_snd_device);
 242
 243        return ret;
 244}
 245module_init(smdk_audio_init);
 246
 247static void __exit smdk_audio_exit(void)
 248{
 249        platform_device_unregister(smdk_snd_device);
 250}
 251module_exit(smdk_audio_exit);
 252
 253MODULE_AUTHOR("Jaswinder Singh, jassisinghbrar@gmail.com");
 254MODULE_DESCRIPTION("ALSA SoC SMDK WM8580");
 255MODULE_LICENSE("GPL");
 256