|
| 1 | +/* |
| 2 | + * ASoC Driver for IQaudIO DAC |
| 3 | + * |
| 4 | + * Author: Florian Meier <[email protected]> |
| 5 | + * Copyright 2013 |
| 6 | + * |
| 7 | + * This program is free software; you can redistribute it and/or |
| 8 | + * modify it under the terms of the GNU General Public License |
| 9 | + * version 2 as published by the Free Software Foundation. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, but |
| 12 | + * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | + * General Public License for more details. |
| 15 | + */ |
| 16 | + |
| 17 | +#include <linux/module.h> |
| 18 | +#include <linux/platform_device.h> |
| 19 | + |
| 20 | +#include <sound/core.h> |
| 21 | +#include <sound/pcm.h> |
| 22 | +#include <sound/pcm_params.h> |
| 23 | +#include <sound/soc.h> |
| 24 | +#include <sound/jack.h> |
| 25 | + |
| 26 | +static int snd_rpi_iqaudio_dac_init(struct snd_soc_pcm_runtime *rtd) |
| 27 | +{ |
| 28 | +// NOT USED struct snd_soc_codec *codec = rtd->codec; |
| 29 | + |
| 30 | + return 0; |
| 31 | +} |
| 32 | + |
| 33 | +static int snd_rpi_iqaudio_dac_hw_params(struct snd_pcm_substream *substream, |
| 34 | + struct snd_pcm_hw_params *params) |
| 35 | +{ |
| 36 | + struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 37 | +// NOT USED struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 38 | +// NOT USED struct snd_soc_codec *codec = rtd->codec; |
| 39 | + struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 40 | + |
| 41 | + unsigned int sample_bits = |
| 42 | + snd_pcm_format_physical_width(params_format(params)); |
| 43 | + |
| 44 | + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2); |
| 45 | +} |
| 46 | + |
| 47 | +/* machine stream operations */ |
| 48 | +static struct snd_soc_ops snd_rpi_iqaudio_dac_ops = { |
| 49 | + .hw_params = snd_rpi_iqaudio_dac_hw_params, |
| 50 | +}; |
| 51 | + |
| 52 | +static struct snd_soc_dai_link snd_rpi_iqaudio_dac_dai[] = { |
| 53 | +{ |
| 54 | + .name = "IQaudIO DAC", |
| 55 | + .stream_name = "IQaudIO DAC HiFi", |
| 56 | + .cpu_dai_name = "bcm2708-i2s.0", |
| 57 | + .codec_dai_name = "pcm512x-hifi", |
| 58 | + .platform_name = "bcm2708-i2s.0", |
| 59 | + .codec_name = "pcm512x.1-004c", |
| 60 | + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
| 61 | + SND_SOC_DAIFMT_CBS_CFS, |
| 62 | + .ops = &snd_rpi_iqaudio_dac_ops, |
| 63 | + .init = snd_rpi_iqaudio_dac_init, |
| 64 | +}, |
| 65 | +}; |
| 66 | + |
| 67 | +/* audio machine driver */ |
| 68 | +static struct snd_soc_card snd_rpi_iqaudio_dac = { |
| 69 | + .name = "snd_rpi_iqaudio_dac", |
| 70 | + .dai_link = snd_rpi_iqaudio_dac_dai, |
| 71 | + .num_links = ARRAY_SIZE(snd_rpi_iqaudio_dac_dai), |
| 72 | +}; |
| 73 | + |
| 74 | +static int snd_rpi_iqaudio_dac_probe(struct platform_device *pdev) |
| 75 | +{ |
| 76 | + int ret = 0; |
| 77 | + |
| 78 | + snd_rpi_iqaudio_dac.dev = &pdev->dev; |
| 79 | + ret = snd_soc_register_card(&snd_rpi_iqaudio_dac); |
| 80 | + if (ret) |
| 81 | + dev_err(&pdev->dev, |
| 82 | + "snd_soc_register_card() failed: %d\n", ret); |
| 83 | + |
| 84 | + return ret; |
| 85 | +} |
| 86 | + |
| 87 | +static int snd_rpi_iqaudio_dac_remove(struct platform_device *pdev) |
| 88 | +{ |
| 89 | + return snd_soc_unregister_card(&snd_rpi_iqaudio_dac); |
| 90 | +} |
| 91 | + |
| 92 | +static const struct of_device_id iqaudio_of_match[] = { |
| 93 | + { .compatible = "iqaudio,iqaudio-dac", }, |
| 94 | + {}, |
| 95 | +}; |
| 96 | + |
| 97 | +static struct platform_driver snd_rpi_iqaudio_dac_driver = { |
| 98 | + .driver = { |
| 99 | + .name = "snd-rpi-iqaudio-dac", |
| 100 | + .owner = THIS_MODULE, |
| 101 | + .of_match_table = iqaudio_of_match, |
| 102 | + }, |
| 103 | + .probe = snd_rpi_iqaudio_dac_probe, |
| 104 | + .remove = snd_rpi_iqaudio_dac_remove, |
| 105 | +}; |
| 106 | + |
| 107 | +module_platform_driver(snd_rpi_iqaudio_dac_driver); |
| 108 | + |
| 109 | +MODULE_AUTHOR( "Florian Meier <[email protected]>"); |
| 110 | +MODULE_DESCRIPTION("ASoC Driver for IQAudio DAC"); |
| 111 | +MODULE_LICENSE("GPL v2"); |
0 commit comments