linux/sound/soc/tegra/tegra_wm8753.c
<<
>>
Prefs
   1/*
   2 * tegra_wm8753.c - Tegra machine ASoC driver for boards using WM8753 codec.
   3 *
   4 * Author: Stephen Warren <swarren@nvidia.com>
   5 * Copyright (C) 2010-2012 - NVIDIA, Inc.
   6 *
   7 * Based on code copyright/by:
   8 *
   9 * (c) 2009, 2010 Nvidia Graphics Pvt. Ltd.
  10 *
  11 * Copyright 2007 Wolfson Microelectronics PLC.
  12 * Author: Graeme Gregory
  13 *         graeme.gregory@wolfsonmicro.com or linux@wolfsonmicro.com
  14 *
  15 * This program is free software; you can redistribute it and/or
  16 * modify it under the terms of the GNU General Public License
  17 * version 2 as published by the Free Software Foundation.
  18 *
  19 * This program is distributed in the hope that it will be useful, but
  20 * WITHOUT ANY WARRANTY; without even the implied warranty of
  21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  22 * General Public License for more details.
  23 *
  24 * You should have received a copy of the GNU General Public License
  25 * along with this program; if not, write to the Free Software
  26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  27 * 02110-1301 USA
  28 *
  29 */
  30
  31#include <linux/module.h>
  32#include <linux/platform_device.h>
  33#include <linux/slab.h>
  34#include <linux/gpio.h>
  35#include <linux/of_gpio.h>
  36
  37#include <sound/core.h>
  38#include <sound/jack.h>
  39#include <sound/pcm.h>
  40#include <sound/pcm_params.h>
  41#include <sound/soc.h>
  42
  43#include "../codecs/wm8753.h"
  44
  45#include "tegra_asoc_utils.h"
  46
  47#define DRV_NAME "tegra-snd-wm8753"
  48
  49struct tegra_wm8753 {
  50        struct tegra_asoc_utils_data util_data;
  51};
  52
  53static int tegra_wm8753_hw_params(struct snd_pcm_substream *substream,
  54                                        struct snd_pcm_hw_params *params)
  55{
  56        struct snd_soc_pcm_runtime *rtd = substream->private_data;
  57        struct snd_soc_dai *codec_dai = rtd->codec_dai;
  58        struct snd_soc_card *card = rtd->card;
  59        struct tegra_wm8753 *machine = snd_soc_card_get_drvdata(card);
  60        int srate, mclk;
  61        int err;
  62
  63        srate = params_rate(params);
  64        switch (srate) {
  65        case 11025:
  66        case 22050:
  67        case 44100:
  68        case 88200:
  69                mclk = 11289600;
  70                break;
  71        default:
  72                mclk = 12288000;
  73                break;
  74        }
  75
  76        err = tegra_asoc_utils_set_rate(&machine->util_data, srate, mclk);
  77        if (err < 0) {
  78                dev_err(card->dev, "Can't configure clocks\n");
  79                return err;
  80        }
  81
  82        err = snd_soc_dai_set_sysclk(codec_dai, WM8753_MCLK, mclk,
  83                                        SND_SOC_CLOCK_IN);
  84        if (err < 0) {
  85                dev_err(card->dev, "codec_dai clock not set\n");
  86                return err;
  87        }
  88
  89        return 0;
  90}
  91
  92static const struct snd_soc_ops tegra_wm8753_ops = {
  93        .hw_params = tegra_wm8753_hw_params,
  94};
  95
  96static const struct snd_soc_dapm_widget tegra_wm8753_dapm_widgets[] = {
  97        SND_SOC_DAPM_HP("Headphone Jack", NULL),
  98        SND_SOC_DAPM_MIC("Mic Jack", NULL),
  99};
 100
 101static struct snd_soc_dai_link tegra_wm8753_dai = {
 102        .name = "WM8753",
 103        .stream_name = "WM8753 PCM",
 104        .codec_dai_name = "wm8753-hifi",
 105        .ops = &tegra_wm8753_ops,
 106        .dai_fmt = SND_SOC_DAIFMT_I2S |
 107                        SND_SOC_DAIFMT_NB_NF |
 108                        SND_SOC_DAIFMT_CBS_CFS,
 109};
 110
 111static struct snd_soc_card snd_soc_tegra_wm8753 = {
 112        .name = "tegra-wm8753",
 113        .owner = THIS_MODULE,
 114        .dai_link = &tegra_wm8753_dai,
 115        .num_links = 1,
 116
 117        .dapm_widgets = tegra_wm8753_dapm_widgets,
 118        .num_dapm_widgets = ARRAY_SIZE(tegra_wm8753_dapm_widgets),
 119        .fully_routed = true,
 120};
 121
 122static int tegra_wm8753_driver_probe(struct platform_device *pdev)
 123{
 124        struct device_node *np = pdev->dev.of_node;
 125        struct snd_soc_card *card = &snd_soc_tegra_wm8753;
 126        struct tegra_wm8753 *machine;
 127        int ret;
 128
 129        machine = devm_kzalloc(&pdev->dev, sizeof(struct tegra_wm8753),
 130                               GFP_KERNEL);
 131        if (!machine)
 132                return -ENOMEM;
 133
 134        card->dev = &pdev->dev;
 135        snd_soc_card_set_drvdata(card, machine);
 136
 137        ret = snd_soc_of_parse_card_name(card, "nvidia,model");
 138        if (ret)
 139                goto err;
 140
 141        ret = snd_soc_of_parse_audio_routing(card, "nvidia,audio-routing");
 142        if (ret)
 143                goto err;
 144
 145        tegra_wm8753_dai.codec_of_node = of_parse_phandle(np,
 146                        "nvidia,audio-codec", 0);
 147        if (!tegra_wm8753_dai.codec_of_node) {
 148                dev_err(&pdev->dev,
 149                        "Property 'nvidia,audio-codec' missing or invalid\n");
 150                ret = -EINVAL;
 151                goto err;
 152        }
 153
 154        tegra_wm8753_dai.cpu_of_node = of_parse_phandle(np,
 155                        "nvidia,i2s-controller", 0);
 156        if (!tegra_wm8753_dai.cpu_of_node) {
 157                dev_err(&pdev->dev,
 158                        "Property 'nvidia,i2s-controller' missing or invalid\n");
 159                ret = -EINVAL;
 160                goto err;
 161        }
 162
 163        tegra_wm8753_dai.platform_of_node = tegra_wm8753_dai.cpu_of_node;
 164
 165        ret = tegra_asoc_utils_init(&machine->util_data, &pdev->dev);
 166        if (ret)
 167                goto err;
 168
 169        ret = snd_soc_register_card(card);
 170        if (ret) {
 171                dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
 172                        ret);
 173                goto err_fini_utils;
 174        }
 175
 176        return 0;
 177
 178err_fini_utils:
 179        tegra_asoc_utils_fini(&machine->util_data);
 180err:
 181        return ret;
 182}
 183
 184static int tegra_wm8753_driver_remove(struct platform_device *pdev)
 185{
 186        struct snd_soc_card *card = platform_get_drvdata(pdev);
 187        struct tegra_wm8753 *machine = snd_soc_card_get_drvdata(card);
 188
 189        snd_soc_unregister_card(card);
 190
 191        tegra_asoc_utils_fini(&machine->util_data);
 192
 193        return 0;
 194}
 195
 196static const struct of_device_id tegra_wm8753_of_match[] = {
 197        { .compatible = "nvidia,tegra-audio-wm8753", },
 198        {},
 199};
 200
 201static struct platform_driver tegra_wm8753_driver = {
 202        .driver = {
 203                .name = DRV_NAME,
 204                .pm = &snd_soc_pm_ops,
 205                .of_match_table = tegra_wm8753_of_match,
 206        },
 207        .probe = tegra_wm8753_driver_probe,
 208        .remove = tegra_wm8753_driver_remove,
 209};
 210module_platform_driver(tegra_wm8753_driver);
 211
 212MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
 213MODULE_DESCRIPTION("Tegra+WM8753 machine ASoC driver");
 214MODULE_LICENSE("GPL");
 215MODULE_ALIAS("platform:" DRV_NAME);
 216MODULE_DEVICE_TABLE(of, tegra_wm8753_of_match);
 217