Lars-Peter Clausen | 5dcdbee | 2014-05-27 10:53:20 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Machine driver for EVAL-ADAU1x61MINIZ on Analog Devices bfin |
| 3 | * evaluation boards. |
| 4 | * |
| 5 | * Copyright 2011-2014 Analog Devices Inc. |
| 6 | * Author: Lars-Peter Clausen <lars@metafoo.de> |
| 7 | * |
| 8 | * Licensed under the GPL-2 or later. |
| 9 | */ |
| 10 | |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/device.h> |
| 13 | #include <linux/slab.h> |
| 14 | #include <sound/core.h> |
| 15 | #include <sound/pcm.h> |
| 16 | #include <sound/soc.h> |
| 17 | #include <sound/pcm_params.h> |
| 18 | |
| 19 | #include "../codecs/adau17x1.h" |
| 20 | |
| 21 | static const struct snd_soc_dapm_widget bfin_eval_adau1x61_dapm_widgets[] = { |
| 22 | SND_SOC_DAPM_LINE("In 1", NULL), |
| 23 | SND_SOC_DAPM_LINE("In 2", NULL), |
| 24 | SND_SOC_DAPM_LINE("In 3-4", NULL), |
| 25 | |
| 26 | SND_SOC_DAPM_LINE("Diff Out L", NULL), |
| 27 | SND_SOC_DAPM_LINE("Diff Out R", NULL), |
| 28 | SND_SOC_DAPM_LINE("Stereo Out", NULL), |
| 29 | SND_SOC_DAPM_HP("Capless HP Out", NULL), |
| 30 | }; |
| 31 | |
| 32 | static const struct snd_soc_dapm_route bfin_eval_adau1x61_dapm_routes[] = { |
| 33 | { "LAUX", NULL, "In 3-4" }, |
| 34 | { "RAUX", NULL, "In 3-4" }, |
| 35 | { "LINP", NULL, "In 1" }, |
| 36 | { "LINN", NULL, "In 1"}, |
| 37 | { "RINP", NULL, "In 2" }, |
| 38 | { "RINN", NULL, "In 2" }, |
| 39 | |
| 40 | { "In 1", NULL, "MICBIAS" }, |
| 41 | { "In 2", NULL, "MICBIAS" }, |
| 42 | |
| 43 | { "Capless HP Out", NULL, "LHP" }, |
| 44 | { "Capless HP Out", NULL, "RHP" }, |
| 45 | { "Diff Out L", NULL, "LOUT" }, |
| 46 | { "Diff Out R", NULL, "ROUT" }, |
| 47 | { "Stereo Out", NULL, "LOUT" }, |
| 48 | { "Stereo Out", NULL, "ROUT" }, |
| 49 | }; |
| 50 | |
| 51 | static int bfin_eval_adau1x61_hw_params(struct snd_pcm_substream *substream, |
| 52 | struct snd_pcm_hw_params *params) |
| 53 | { |
| 54 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 55 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 56 | int pll_rate; |
| 57 | int ret; |
| 58 | |
| 59 | switch (params_rate(params)) { |
| 60 | case 48000: |
| 61 | case 8000: |
| 62 | case 12000: |
| 63 | case 16000: |
| 64 | case 24000: |
| 65 | case 32000: |
| 66 | case 96000: |
| 67 | pll_rate = 48000 * 1024; |
| 68 | break; |
| 69 | case 44100: |
| 70 | case 7350: |
| 71 | case 11025: |
| 72 | case 14700: |
| 73 | case 22050: |
| 74 | case 29400: |
| 75 | case 88200: |
| 76 | pll_rate = 44100 * 1024; |
| 77 | break; |
| 78 | default: |
| 79 | return -EINVAL; |
| 80 | } |
| 81 | |
| 82 | ret = snd_soc_dai_set_pll(codec_dai, ADAU17X1_PLL, |
| 83 | ADAU17X1_PLL_SRC_MCLK, 12288000, pll_rate); |
| 84 | if (ret) |
| 85 | return ret; |
| 86 | |
| 87 | ret = snd_soc_dai_set_sysclk(codec_dai, ADAU17X1_CLK_SRC_PLL, pll_rate, |
| 88 | SND_SOC_CLOCK_IN); |
| 89 | |
| 90 | return ret; |
| 91 | } |
| 92 | |
| 93 | static const struct snd_soc_ops bfin_eval_adau1x61_ops = { |
| 94 | .hw_params = bfin_eval_adau1x61_hw_params, |
| 95 | }; |
| 96 | |
| 97 | static struct snd_soc_dai_link bfin_eval_adau1x61_dai = { |
| 98 | .name = "adau1x61", |
| 99 | .stream_name = "adau1x61", |
| 100 | .cpu_dai_name = "bfin-i2s.0", |
| 101 | .codec_dai_name = "adau-hifi", |
| 102 | .platform_name = "bfin-i2s-pcm-audio", |
| 103 | .codec_name = "adau1761.0-0038", |
| 104 | .ops = &bfin_eval_adau1x61_ops, |
| 105 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
| 106 | SND_SOC_DAIFMT_CBM_CFM, |
| 107 | }; |
| 108 | |
| 109 | static struct snd_soc_card bfin_eval_adau1x61 = { |
| 110 | .name = "bfin-eval-adau1x61", |
Axel Lin | 54d8697 | 2015-08-21 20:59:21 +0800 | [diff] [blame] | 111 | .owner = THIS_MODULE, |
Lars-Peter Clausen | 5dcdbee | 2014-05-27 10:53:20 +0200 | [diff] [blame] | 112 | .driver_name = "eval-adau1x61", |
| 113 | .dai_link = &bfin_eval_adau1x61_dai, |
| 114 | .num_links = 1, |
| 115 | |
| 116 | .dapm_widgets = bfin_eval_adau1x61_dapm_widgets, |
| 117 | .num_dapm_widgets = ARRAY_SIZE(bfin_eval_adau1x61_dapm_widgets), |
| 118 | .dapm_routes = bfin_eval_adau1x61_dapm_routes, |
| 119 | .num_dapm_routes = ARRAY_SIZE(bfin_eval_adau1x61_dapm_routes), |
| 120 | .fully_routed = true, |
| 121 | }; |
| 122 | |
| 123 | static int bfin_eval_adau1x61_probe(struct platform_device *pdev) |
| 124 | { |
| 125 | bfin_eval_adau1x61.dev = &pdev->dev; |
| 126 | |
| 127 | return devm_snd_soc_register_card(&pdev->dev, &bfin_eval_adau1x61); |
| 128 | } |
| 129 | |
| 130 | static struct platform_driver bfin_eval_adau1x61_driver = { |
| 131 | .driver = { |
| 132 | .name = "bfin-eval-adau1x61", |
Lars-Peter Clausen | 5dcdbee | 2014-05-27 10:53:20 +0200 | [diff] [blame] | 133 | .pm = &snd_soc_pm_ops, |
| 134 | }, |
| 135 | .probe = bfin_eval_adau1x61_probe, |
| 136 | }; |
| 137 | module_platform_driver(bfin_eval_adau1x61_driver); |
| 138 | |
| 139 | MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>"); |
| 140 | MODULE_DESCRIPTION("ALSA SoC bfin adau1x61 driver"); |
| 141 | MODULE_LICENSE("GPL"); |
| 142 | MODULE_ALIAS("platform:bfin-eval-adau1x61"); |