|
| 1 | +/* |
| 2 | + * ASoC Driver for HiFiBerry DAC+ |
| 3 | + * |
| 4 | + * Author: Daniel Matuschek |
| 5 | + * Copyright 2014 |
| 6 | + * based on code by Florian Meier <florian.meier@koalo.de> |
| 7 | + * |
| 8 | + * This program is free software; you can redistribute it and/or |
| 9 | + * modify it under the terms of the GNU General Public License |
| 10 | + * version 2 as published by the Free Software Foundation. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, but |
| 13 | + * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | + * General Public License for more details. |
| 16 | + */ |
| 17 | + |
| 18 | +#include <linux/module.h> |
| 19 | +#include <linux/platform_device.h> |
| 20 | + |
| 21 | +#include <sound/core.h> |
| 22 | +#include <sound/pcm.h> |
| 23 | +#include <sound/pcm_params.h> |
| 24 | +#include <sound/soc.h> |
| 25 | +#include <sound/jack.h> |
| 26 | + |
| 27 | +#include "../codecs/pcm512x.h" |
| 28 | + |
| 29 | +static int snd_rpi_hifiberry_dacplus_init(struct snd_soc_pcm_runtime *rtd) |
| 30 | +{ |
| 31 | + struct snd_soc_codec *codec = rtd->codec; |
| 32 | + snd_soc_update_bits(codec, PCM512x_GPIO_EN, 0x08, 0x08); |
| 33 | + snd_soc_update_bits(codec, PCM512x_GPIO_OUTPUT_4, 0xf, 0x02); |
| 34 | + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x08); |
| 35 | + return 0; |
| 36 | +} |
| 37 | + |
| 38 | +static int snd_rpi_hifiberry_dacplus_hw_params(struct snd_pcm_substream *substream, |
| 39 | + struct snd_pcm_hw_params *params) |
| 40 | +{ |
| 41 | + struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 42 | + struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 43 | + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64); |
| 44 | +} |
| 45 | + |
| 46 | +static int snd_rpi_hifiberry_dacplus_startup(struct snd_pcm_substream *substream) { |
| 47 | + struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 48 | + struct snd_soc_codec *codec = rtd->codec; |
| 49 | + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x08); |
| 50 | + return 0; |
| 51 | +} |
| 52 | + |
| 53 | +static void snd_rpi_hifiberry_dacplus_shutdown(struct snd_pcm_substream *substream) { |
| 54 | + struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 55 | + struct snd_soc_codec *codec = rtd->codec; |
| 56 | + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x00); |
| 57 | +} |
| 58 | + |
| 59 | +/* machine stream operations */ |
| 60 | +static struct snd_soc_ops snd_rpi_hifiberry_dacplus_ops = { |
| 61 | + .hw_params = snd_rpi_hifiberry_dacplus_hw_params, |
| 62 | + .startup = snd_rpi_hifiberry_dacplus_startup, |
| 63 | + .shutdown = snd_rpi_hifiberry_dacplus_shutdown, |
| 64 | +}; |
| 65 | + |
| 66 | +static struct snd_soc_dai_link snd_rpi_hifiberry_dacplus_dai[] = { |
| 67 | +{ |
| 68 | + .name = "HiFiBerry DAC+", |
| 69 | + .stream_name = "HiFiBerry DAC+ HiFi", |
| 70 | + .cpu_dai_name = "bcm2708-i2s.0", |
| 71 | + .codec_dai_name = "pcm512x-hifi", |
| 72 | + .platform_name = "bcm2708-i2s.0", |
| 73 | + .codec_name = "pcm512x.1-004d", |
| 74 | + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
| 75 | + SND_SOC_DAIFMT_CBS_CFS, |
| 76 | + .ops = &snd_rpi_hifiberry_dacplus_ops, |
| 77 | + .init = snd_rpi_hifiberry_dacplus_init, |
| 78 | +}, |
| 79 | +}; |
| 80 | + |
| 81 | +/* audio machine driver */ |
| 82 | +static struct snd_soc_card snd_rpi_hifiberry_dacplus = { |
| 83 | + .name = "snd_rpi_hifiberry_dacplus", |
| 84 | + .dai_link = snd_rpi_hifiberry_dacplus_dai, |
| 85 | + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dacplus_dai), |
| 86 | +}; |
| 87 | + |
| 88 | +static int snd_rpi_hifiberry_dacplus_probe(struct platform_device *pdev) |
| 89 | +{ |
| 90 | + int ret = 0; |
| 91 | + |
| 92 | + snd_rpi_hifiberry_dacplus.dev = &pdev->dev; |
| 93 | + ret = snd_soc_register_card(&snd_rpi_hifiberry_dacplus); |
| 94 | + if (ret) |
| 95 | + dev_err(&pdev->dev, |
| 96 | + "snd_soc_register_card() failed: %d\n", ret); |
| 97 | + |
| 98 | + return ret; |
| 99 | +} |
| 100 | + |
| 101 | +static int snd_rpi_hifiberry_dacplus_remove(struct platform_device *pdev) |
| 102 | +{ |
| 103 | + return snd_soc_unregister_card(&snd_rpi_hifiberry_dacplus); |
| 104 | +} |
| 105 | + |
| 106 | +static struct platform_driver snd_rpi_hifiberry_dacplus_driver = { |
| 107 | + .driver = { |
| 108 | + .name = "snd-rpi-hifiberry-dacplus", |
| 109 | + .owner = THIS_MODULE, |
| 110 | + }, |
| 111 | + .probe = snd_rpi_hifiberry_dacplus_probe, |
| 112 | + .remove = snd_rpi_hifiberry_dacplus_remove, |
| 113 | +}; |
| 114 | + |
| 115 | +module_platform_driver(snd_rpi_hifiberry_dacplus_driver); |
| 116 | + |
| 117 | +MODULE_AUTHOR("Daniel Matuschek <daniel@hifiberry.com>"); |
| 118 | +MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+"); |
| 119 | +MODULE_LICENSE("GPL v2"); |
0 commit comments