brcm2708: switch to linux 4.4 and update patches
[openwrt.git] / target / linux / brcm2708 / patches-4.1 / 0037-ASoC-Add-support-for-HifiBerry-DAC.patch
1 From 2c73e8800199fad97e5a23897b490bdea01a37e0 Mon Sep 17 00:00:00 2001
2 From: Florian Meier <florian.meier@koalo.de>
3 Date: Fri, 22 Nov 2013 19:19:08 +0100
4 Subject: [PATCH 037/222] ASoC: Add support for HifiBerry DAC
5
6 This adds a machine driver for the HifiBerry DAC.
7 It is a sound card that can
8 be stacked onto the Raspberry Pi.
9
10 Signed-off-by: Florian Meier <florian.meier@koalo.de>
11 ---
12  sound/soc/bcm/Kconfig         |   7 +++
13  sound/soc/bcm/Makefile        |   5 +++
14  sound/soc/bcm/hifiberry_dac.c | 100 ++++++++++++++++++++++++++++++++++++++++++
15  3 files changed, 112 insertions(+)
16  create mode 100644 sound/soc/bcm/hifiberry_dac.c
17
18 --- a/sound/soc/bcm/Kconfig
19 +++ b/sound/soc/bcm/Kconfig
20 @@ -18,3 +18,10 @@ config SND_BCM2708_SOC_I2S
21           Say Y or M if you want to add support for codecs attached to
22           the BCM2708 I2S interface. You will also need
23           to select the audio interfaces to support below.
24 +
25 +config SND_BCM2708_SOC_HIFIBERRY_DAC
26 +        tristate "Support for HifiBerry DAC"
27 +        depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
28 +        select SND_SOC_PCM5102A
29 +        help
30 +         Say Y or M if you want to add support for HifiBerry DAC.
31 --- a/sound/soc/bcm/Makefile
32 +++ b/sound/soc/bcm/Makefile
33 @@ -7,3 +7,8 @@ obj-$(CONFIG_SND_BCM2835_SOC_I2S) += snd
34  snd-soc-bcm2708-i2s-objs := bcm2708-i2s.o
35  
36  obj-$(CONFIG_SND_BCM2708_SOC_I2S) += snd-soc-bcm2708-i2s.o
37 +
38 +# BCM2708 Machine Support
39 +snd-soc-hifiberry-dac-objs := hifiberry_dac.o
40 +
41 +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
42 --- /dev/null
43 +++ b/sound/soc/bcm/hifiberry_dac.c
44 @@ -0,0 +1,100 @@
45 +/*
46 + * ASoC Driver for HifiBerry DAC
47 + *
48 + * Author:     Florian Meier <florian.meier@koalo.de>
49 + *             Copyright 2013
50 + *
51 + * This program is free software; you can redistribute it and/or
52 + * modify it under the terms of the GNU General Public License
53 + * version 2 as published by the Free Software Foundation.
54 + *
55 + * This program is distributed in the hope that it will be useful, but
56 + * WITHOUT ANY WARRANTY; without even the implied warranty of
57 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
58 + * General Public License for more details.
59 + */
60 +
61 +#include <linux/module.h>
62 +#include <linux/platform_device.h>
63 +
64 +#include <sound/core.h>
65 +#include <sound/pcm.h>
66 +#include <sound/pcm_params.h>
67 +#include <sound/soc.h>
68 +#include <sound/jack.h>
69 +
70 +static int snd_rpi_hifiberry_dac_init(struct snd_soc_pcm_runtime *rtd)
71 +{
72 +       return 0;
73 +}
74 +
75 +static int snd_rpi_hifiberry_dac_hw_params(struct snd_pcm_substream *substream,
76 +                                      struct snd_pcm_hw_params *params)
77 +{
78 +       struct snd_soc_pcm_runtime *rtd = substream->private_data;
79 +       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
80 +
81 +       unsigned int sample_bits =
82 +               snd_pcm_format_physical_width(params_format(params));
83 +
84 +       return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
85 +}
86 +
87 +/* machine stream operations */
88 +static struct snd_soc_ops snd_rpi_hifiberry_dac_ops = {
89 +       .hw_params = snd_rpi_hifiberry_dac_hw_params,
90 +};
91 +
92 +static struct snd_soc_dai_link snd_rpi_hifiberry_dac_dai[] = {
93 +{
94 +       .name           = "HifiBerry DAC",
95 +       .stream_name    = "HifiBerry DAC HiFi",
96 +       .cpu_dai_name   = "bcm2708-i2s.0",
97 +       .codec_dai_name = "pcm5102a-hifi",
98 +       .platform_name  = "bcm2708-i2s.0",
99 +       .codec_name     = "pcm5102a-codec",
100 +       .dai_fmt        = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
101 +                               SND_SOC_DAIFMT_CBS_CFS,
102 +       .ops            = &snd_rpi_hifiberry_dac_ops,
103 +       .init           = snd_rpi_hifiberry_dac_init,
104 +},
105 +};
106 +
107 +/* audio machine driver */
108 +static struct snd_soc_card snd_rpi_hifiberry_dac = {
109 +       .name         = "snd_rpi_hifiberry_dac",
110 +       .dai_link     = snd_rpi_hifiberry_dac_dai,
111 +       .num_links    = ARRAY_SIZE(snd_rpi_hifiberry_dac_dai),
112 +};
113 +
114 +static int snd_rpi_hifiberry_dac_probe(struct platform_device *pdev)
115 +{
116 +       int ret = 0;
117 +
118 +       snd_rpi_hifiberry_dac.dev = &pdev->dev;
119 +       ret = snd_soc_register_card(&snd_rpi_hifiberry_dac);
120 +       if (ret)
121 +               dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
122 +
123 +       return ret;
124 +}
125 +
126 +static int snd_rpi_hifiberry_dac_remove(struct platform_device *pdev)
127 +{
128 +       return snd_soc_unregister_card(&snd_rpi_hifiberry_dac);
129 +}
130 +
131 +static struct platform_driver snd_rpi_hifiberry_dac_driver = {
132 +        .driver = {
133 +                .name   = "snd-hifiberry-dac",
134 +                .owner  = THIS_MODULE,
135 +        },
136 +        .probe          = snd_rpi_hifiberry_dac_probe,
137 +        .remove         = snd_rpi_hifiberry_dac_remove,
138 +};
139 +
140 +module_platform_driver(snd_rpi_hifiberry_dac_driver);
141 +
142 +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
143 +MODULE_DESCRIPTION("ASoC Driver for HifiBerry DAC");
144 +MODULE_LICENSE("GPL v2");