|
| 1 | +/* |
| 2 | + * ASoC Driver for HifiBerry AMP |
| 3 | + * |
| 4 | + * Author: Sebastian Eickhoff <[email protected]> |
| 5 | + * Copyright 2014 |
| 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_hifiberry_amp_init(struct snd_soc_pcm_runtime *rtd) |
| 27 | +{ |
| 28 | + // ToDo: init of the dsp-registers. |
| 29 | + return 0; |
| 30 | +} |
| 31 | + |
| 32 | +static int snd_rpi_hifiberry_amp_hw_params( struct snd_pcm_substream *substream, |
| 33 | + struct snd_pcm_hw_params *params ) |
| 34 | +{ |
| 35 | + struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 36 | + struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 37 | + |
| 38 | + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64); |
| 39 | +} |
| 40 | + |
| 41 | +static struct snd_soc_ops snd_rpi_hifiberry_amp_ops = { |
| 42 | + .hw_params = snd_rpi_hifiberry_amp_hw_params, |
| 43 | +}; |
| 44 | + |
| 45 | +static struct snd_soc_dai_link snd_rpi_hifiberry_amp_dai[] = { |
| 46 | + { |
| 47 | + .name = "HifiBerry AMP", |
| 48 | + .stream_name = "HifiBerry AMP HiFi", |
| 49 | + .cpu_dai_name = "bcm2708-i2s.0", |
| 50 | + .codec_dai_name = "tas5713-hifi", |
| 51 | + .platform_name = "bcm2708-i2s.0", |
| 52 | + .codec_name = "tas5713.1-001b", |
| 53 | + .dai_fmt = SND_SOC_DAIFMT_I2S | |
| 54 | + SND_SOC_DAIFMT_NB_NF | |
| 55 | + SND_SOC_DAIFMT_CBS_CFS, |
| 56 | + .ops = &snd_rpi_hifiberry_amp_ops, |
| 57 | + .init = snd_rpi_hifiberry_amp_init, |
| 58 | + }, |
| 59 | +}; |
| 60 | + |
| 61 | + |
| 62 | +static struct snd_soc_card snd_rpi_hifiberry_amp = { |
| 63 | + .name = "snd_rpi_hifiberry_amp", |
| 64 | + .driver_name = "HifiberryAmp", |
| 65 | + .owner = THIS_MODULE, |
| 66 | + .dai_link = snd_rpi_hifiberry_amp_dai, |
| 67 | + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_amp_dai), |
| 68 | +}; |
| 69 | + |
| 70 | +static const struct of_device_id snd_rpi_hifiberry_amp_of_match[] = { |
| 71 | + { .compatible = "hifiberry,hifiberry-amp", }, |
| 72 | + {}, |
| 73 | +}; |
| 74 | +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_amp_of_match); |
| 75 | + |
| 76 | + |
| 77 | +static int snd_rpi_hifiberry_amp_probe(struct platform_device *pdev) |
| 78 | +{ |
| 79 | + int ret = 0; |
| 80 | + |
| 81 | + snd_rpi_hifiberry_amp.dev = &pdev->dev; |
| 82 | + |
| 83 | + if (pdev->dev.of_node) { |
| 84 | + struct device_node *i2s_node; |
| 85 | + struct snd_soc_dai_link *dai = &snd_rpi_hifiberry_amp_dai[0]; |
| 86 | + i2s_node = of_parse_phandle(pdev->dev.of_node, |
| 87 | + "i2s-controller", 0); |
| 88 | + |
| 89 | + if (i2s_node) { |
| 90 | + dai->cpu_dai_name = NULL; |
| 91 | + dai->cpu_of_node = i2s_node; |
| 92 | + dai->platform_name = NULL; |
| 93 | + dai->platform_of_node = i2s_node; |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + ret = snd_soc_register_card(&snd_rpi_hifiberry_amp); |
| 98 | + |
| 99 | + if (ret != 0) { |
| 100 | + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret); |
| 101 | + } |
| 102 | + |
| 103 | + return ret; |
| 104 | +} |
| 105 | + |
| 106 | + |
| 107 | +static int snd_rpi_hifiberry_amp_remove(struct platform_device *pdev) |
| 108 | +{ |
| 109 | + return snd_soc_unregister_card(&snd_rpi_hifiberry_amp); |
| 110 | +} |
| 111 | + |
| 112 | + |
| 113 | +static struct platform_driver snd_rpi_hifiberry_amp_driver = { |
| 114 | + .driver = { |
| 115 | + .name = "snd-hifiberry-amp", |
| 116 | + .owner = THIS_MODULE, |
| 117 | + .of_match_table = snd_rpi_hifiberry_amp_of_match, |
| 118 | + }, |
| 119 | + .probe = snd_rpi_hifiberry_amp_probe, |
| 120 | + .remove = snd_rpi_hifiberry_amp_remove, |
| 121 | +}; |
| 122 | + |
| 123 | + |
| 124 | +module_platform_driver(snd_rpi_hifiberry_amp_driver); |
| 125 | + |
| 126 | + |
| 127 | +MODULE_AUTHOR( "Sebastian Eickhoff <[email protected]>"); |
| 128 | +MODULE_DESCRIPTION("ASoC driver for HiFiBerry-AMP"); |
| 129 | +MODULE_LICENSE("GPL v2"); |
0 commit comments