|
| 1 | +/* |
| 2 | + * ASoC Driver for ADAU1977 ADC |
| 3 | + * |
| 4 | + * Author: Andrey Grodzovsky <[email protected]> |
| 5 | + * Copyright 2016 |
| 6 | + * |
| 7 | + * This file is based on hifibery_dac driver by Florian Meier. |
| 8 | + * |
| 9 | + * This program is free software; you can redistribute it and/or |
| 10 | + * modify it under the terms of the GNU General Public License |
| 11 | + * version 2 as published by the Free Software Foundation. |
| 12 | + * |
| 13 | + * This program is distributed in the hope that it will be useful, but |
| 14 | + * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | + * General Public License for more details. |
| 17 | + */ |
| 18 | + |
| 19 | +#include <linux/module.h> |
| 20 | +#include <linux/platform_device.h> |
| 21 | + |
| 22 | +#include <sound/core.h> |
| 23 | +#include <sound/pcm.h> |
| 24 | +#include <sound/pcm_params.h> |
| 25 | +#include <sound/soc.h> |
| 26 | +#include <sound/jack.h> |
| 27 | + |
| 28 | +enum adau1977_clk_id { |
| 29 | + ADAU1977_SYSCLK, |
| 30 | +}; |
| 31 | + |
| 32 | +enum adau1977_sysclk_src { |
| 33 | + ADAU1977_SYSCLK_SRC_MCLK, |
| 34 | + ADAU1977_SYSCLK_SRC_LRCLK, |
| 35 | +}; |
| 36 | + |
| 37 | +static int eval_adau1977_init(struct snd_soc_pcm_runtime *rtd) |
| 38 | +{ |
| 39 | + int ret; |
| 40 | + struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 41 | + |
| 42 | + ret = snd_soc_dai_set_tdm_slot(codec_dai, 0, 0, 0, 0); |
| 43 | + if (ret < 0) |
| 44 | + return ret; |
| 45 | + |
| 46 | + return snd_soc_codec_set_sysclk(rtd->codec, ADAU1977_SYSCLK, |
| 47 | + ADAU1977_SYSCLK_SRC_MCLK, 11289600, SND_SOC_CLOCK_IN); |
| 48 | +} |
| 49 | + |
| 50 | +static struct snd_soc_dai_link snd_rpi_adau1977_dai[] = { |
| 51 | + { |
| 52 | + .name = "adau1977", |
| 53 | + .stream_name = "ADAU1977", |
| 54 | + .cpu_dai_name = "bcm2708-i2s.0", |
| 55 | + .codec_dai_name = "adau1977-hifi", |
| 56 | + .platform_name = "bcm2708-i2s.0", |
| 57 | + .codec_name = "adau1977.1-0011", |
| 58 | + .init = eval_adau1977_init, |
| 59 | + .dai_fmt = SND_SOC_DAIFMT_I2S | |
| 60 | + SND_SOC_DAIFMT_NB_NF | |
| 61 | + SND_SOC_DAIFMT_CBM_CFM, |
| 62 | + }, |
| 63 | +}; |
| 64 | + |
| 65 | +/* audio machine driver */ |
| 66 | +static struct snd_soc_card snd_adau1977_adc = { |
| 67 | + .name = "snd_rpi_adau1977_adc", |
| 68 | + .owner = THIS_MODULE, |
| 69 | + .dai_link = snd_rpi_adau1977_dai, |
| 70 | + .num_links = ARRAY_SIZE(snd_rpi_adau1977_dai), |
| 71 | +}; |
| 72 | + |
| 73 | +static int snd_adau1977_adc_probe(struct platform_device *pdev) |
| 74 | +{ |
| 75 | + int ret = 0; |
| 76 | + |
| 77 | + snd_adau1977_adc.dev = &pdev->dev; |
| 78 | + if (pdev->dev.of_node) { |
| 79 | + struct device_node *i2s_node; |
| 80 | + struct snd_soc_dai_link *dai = &snd_rpi_adau1977_dai[0]; |
| 81 | + i2s_node = of_parse_phandle(pdev->dev.of_node, |
| 82 | + "i2s-controller", 0); |
| 83 | + |
| 84 | + if (i2s_node) { |
| 85 | + dai->cpu_dai_name = NULL; |
| 86 | + dai->cpu_of_node = i2s_node; |
| 87 | + dai->platform_name = NULL; |
| 88 | + dai->platform_of_node = i2s_node; |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + ret = snd_soc_register_card(&snd_adau1977_adc); |
| 93 | + if (ret) |
| 94 | + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret); |
| 95 | + |
| 96 | + return ret; |
| 97 | +} |
| 98 | + |
| 99 | +static int snd_adau1977_adc_remove(struct platform_device *pdev) |
| 100 | +{ |
| 101 | + return snd_soc_unregister_card(&snd_adau1977_adc); |
| 102 | +} |
| 103 | + |
| 104 | +static const struct of_device_id snd_adau1977_adc_of_match[] = { |
| 105 | + { .compatible = "adi,adau1977-adc", }, |
| 106 | + {}, |
| 107 | +}; |
| 108 | + |
| 109 | +MODULE_DEVICE_TABLE(of, snd_adau1977_adc_of_match); |
| 110 | + |
| 111 | +static struct platform_driver snd_adau1977_adc_driver = { |
| 112 | + .driver = { |
| 113 | + .name = "snd-adau1977-adc", |
| 114 | + .owner = THIS_MODULE, |
| 115 | + .of_match_table = snd_adau1977_adc_of_match, |
| 116 | + }, |
| 117 | + .probe = snd_adau1977_adc_probe, |
| 118 | + .remove = snd_adau1977_adc_remove, |
| 119 | +}; |
| 120 | + |
| 121 | +module_platform_driver(snd_adau1977_adc_driver); |
| 122 | + |
| 123 | +MODULE_AUTHOR( "Andrey Grodzovsky <[email protected]>"); |
| 124 | +MODULE_DESCRIPTION("ASoC Driver for ADAU1977 ADC"); |
| 125 | +MODULE_LICENSE("GPL v2"); |
0 commit comments