aboutsummaryrefslogtreecommitdiffstats
path: root/recipes-kernel/linux/linux-raspberrypi/0001-ASoC-Add-BCM2708-fixes.patch
blob: 26c71b87279afd3403417d53cabb35bd76a8fba0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
From e73a69601c65103b0e032e6093af0f00a1e1af3a Mon Sep 17 00:00:00 2001
From: Florian Meier <florian.meier@koalo.de>
Date: Fri, 22 Nov 2013 14:33:38 +0100
Subject: [PATCH 1/2] ASoC: Add BCM2708 fixes
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

(cherry-pick remaining parts of
730cb8a1216f9da3d097072cd9bb06e0db348172)

bcm2708-i2s: Update bclk_ratio to more correct values

Move GPIO setup to hw_params.

This is used to stop the I2S driver from breaking
the GPIO setup for other uses of the PCM interface

Configure GPIOs for I2S based on revision/card settings

With RPi model B+, assignment of the I2S GPIO pins has changed.
This patch uses the board revision to auto-detect the GPIOs used
for I2S. It also allows sound card drivers to set the GPIOs that
should be used. This is especially important with the Compute
Module.

bcm2708-i2s: Avoid leak from iomap when accessing gpio

bcm2708: Eliminate i2s debugfs directory error

Qualify the two regmap ranges uses by bcm2708-i2s ('-i2s' and '-clk')
to avoid the name clash when registering debugfs entries.

Upstream-Status: Pending

Signed-off-by: Petter Mabäcker <petter@technux.se>

Conflicts:
	sound/soc/bcm/Kconfig
	sound/soc/bcm/Makefile
	sound/soc/bcm/bcm2708-i2s.c
---
 sound/soc/bcm/bcm2708-i2s.c | 82 ++++++++++++++++++++++++++++++++++++---------
 sound/soc/bcm/bcm2708-i2s.h | 35 +++++++++++++++++++
 2 files changed, 102 insertions(+), 15 deletions(-)
 create mode 100644 sound/soc/bcm/bcm2708-i2s.h

diff --git a/sound/soc/bcm/bcm2708-i2s.c b/sound/soc/bcm/bcm2708-i2s.c
index 9976571..3fcb740 100644
--- a/sound/soc/bcm/bcm2708-i2s.c
+++ b/sound/soc/bcm/bcm2708-i2s.c
@@ -31,6 +31,8 @@
  * General Public License for more details.
  */
 
+#include "bcm2708-i2s.h"
+
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/device.h>
@@ -38,6 +40,7 @@
 #include <linux/delay.h>
 #include <linux/io.h>
 #include <linux/clk.h>
+#include <mach/gpio.h>
 
 #include <sound/core.h>
 #include <sound/pcm.h>
@@ -46,6 +49,8 @@
 #include <sound/soc.h>
 #include <sound/dmaengine_pcm.h>
 
+#include <asm/system_info.h>
+
 /* Clock registers */
 #define BCM2708_CLK_PCMCTL_REG  0x00
 #define BCM2708_CLK_PCMDIV_REG  0x04
@@ -163,6 +168,9 @@ static const unsigned int bcm2708_clk_freq[BCM2708_CLK_SRC_HDMI+1] = {
 #define BCM2708_DMA_DREQ_PCM_TX		2
 #define BCM2708_DMA_DREQ_PCM_RX		3
 
+/* I2S pin configuration */
+static int bcm2708_i2s_gpio=BCM2708_I2S_GPIO_AUTO;
+
 /* General device struct */
 struct bcm2708_i2s_dev {
 	struct device				*dev;
@@ -174,6 +182,12 @@ struct bcm2708_i2s_dev {
 	struct regmap *clk_regmap;
 };
 
+void bcm2708_i2s_set_gpio(int gpio) {
+	bcm2708_i2s_gpio=gpio;
+}
+EXPORT_SYMBOL(bcm2708_i2s_set_gpio);
+
+
 static void bcm2708_i2s_start_clock(struct bcm2708_i2s_dev *dev)
 {
 	/* Start the clock if in master mode */
@@ -306,6 +320,25 @@ static int bcm2708_i2s_set_dai_bclk_ratio(struct snd_soc_dai *dai,
 }
 
 
+static int bcm2708_i2s_set_function(unsigned offset, int function)
+{
+	#define GPIOFSEL(x)  (0x00+(x)*4)
+	void __iomem *gpio = __io_address(GPIO_BASE);
+	unsigned alt = function <= 3 ? function + 4: function == 4 ? 3 : 2;
+	unsigned gpiodir;
+	unsigned gpio_bank = offset / 10;
+	unsigned gpio_field_offset = (offset - 10 * gpio_bank) * 3;
+
+	if (offset >= BCM2708_NR_GPIOS)
+		return -EINVAL;
+
+	gpiodir = readl(gpio + GPIOFSEL(gpio_bank));
+	gpiodir &= ~(7 << gpio_field_offset);
+	gpiodir |= alt << gpio_field_offset;
+	writel(gpiodir, gpio + GPIOFSEL(gpio_bank));
+	return 0;
+}
+
 static void bcm2708_i2s_setup_gpio(void)
 {
 	/*
@@ -314,20 +347,37 @@ static void bcm2708_i2s_setup_gpio(void)
 	 * TODO Better way would be to handle
 	 * this in the device tree!
 	 */
-#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
-#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
+	int pin,pinconfig,startpin,alt;
+
+	/* SPI is on different GPIOs on different boards */
+        /* for Raspberry Pi B+, this is pin GPIO18-21, for original on 28-31 */
+	if (bcm2708_i2s_gpio==BCM2708_I2S_GPIO_AUTO) {	
+		if ((system_rev & 0xffffff) >= 0x10) {
+			/* Model B+ */
+			pinconfig=BCM2708_I2S_GPIO_PIN18;
+		} else {
+			/* original */
+			pinconfig=BCM2708_I2S_GPIO_PIN28;
+		}
+	} else {
+		pinconfig=bcm2708_i2s_gpio;
+	}
 
-	unsigned int *gpio;
-	int pin;
-	gpio = ioremap(GPIO_BASE, SZ_16K);
+	if (pinconfig==BCM2708_I2S_GPIO_PIN18) {
+		startpin=18;
+		alt=BCM2708_I2S_GPIO_PIN18_ALT;
+	} else if (pinconfig==BCM2708_I2S_GPIO_PIN28) {
+		startpin=28;
+		alt=BCM2708_I2S_GPIO_PIN28_ALT;
+	} else {
+		printk(KERN_INFO "Can't configure I2S GPIOs, unknown pin mode for I2S: %i\n",pinconfig);
+		return;
+	}	
 
-	/* SPI is on GPIO 7..11 */
-	for (pin = 28; pin <= 31; pin++) {
-		INP_GPIO(pin);		/* set mode to GPIO input first */
-		SET_GPIO_ALT(pin, 2);	/* set mode to ALT 0 */
+	/* configure I2S pins to correct ALT mode */
+	for (pin = startpin; pin <= startpin+3; pin++) {
+		bcm2708_i2s_set_function(pin, alt);
 	}
-#undef INP_GPIO
-#undef SET_GPIO_ALT
 }
 
 static int bcm2708_i2s_hw_params(struct snd_pcm_substream *substream,
@@ -372,15 +422,15 @@ static int bcm2708_i2s_hw_params(struct snd_pcm_substream *substream,
 	switch (params_format(params)) {
 	case SNDRV_PCM_FORMAT_S16_LE:
 		data_length = 16;
-		bclk_ratio = 40;
+		bclk_ratio = 50;
 		break;
 	case SNDRV_PCM_FORMAT_S24_LE:
 		data_length = 24;
-		bclk_ratio = 40;
+		bclk_ratio = 50;
 		break;
 	case SNDRV_PCM_FORMAT_S32_LE:
 		data_length = 32;
-		bclk_ratio = 80;
+		bclk_ratio = 100;
 		break;
 	default:
 		return -EINVAL;
@@ -746,7 +796,7 @@ static struct snd_soc_dai_driver bcm2708_i2s_dai = {
 		.channels_max = 2,
 		.rates =	SNDRV_PCM_RATE_8000_192000,
 		.formats =	SNDRV_PCM_FMTBIT_S16_LE
-				// | SNDRV_PCM_FMTBIT_S24_LE : disable for now, it causes white noise with xbmc
+				| SNDRV_PCM_FMTBIT_S24_LE
 				| SNDRV_PCM_FMTBIT_S32_LE
 		},
 	.capture = {
@@ -803,6 +853,7 @@ static const struct regmap_config bcm2708_regmap_config[] = {
 		.precious_reg = bcm2708_i2s_precious_reg,
 		.volatile_reg = bcm2708_i2s_volatile_reg,
 		.cache_type = REGCACHE_RBTREE,
+		.name = "i2s",
 	},
 	{
 		.reg_bits = 32,
@@ -811,6 +862,7 @@ static const struct regmap_config bcm2708_regmap_config[] = {
 		.max_register = BCM2708_CLK_PCMDIV_REG,
 		.volatile_reg = bcm2708_clk_volatile_reg,
 		.cache_type = REGCACHE_RBTREE,
+		.name = "clk",
 	},
 };
 
diff --git a/sound/soc/bcm/bcm2708-i2s.h b/sound/soc/bcm/bcm2708-i2s.h
new file mode 100644
index 0000000..94fed6a
--- /dev/null
+++ b/sound/soc/bcm/bcm2708-i2s.h
@@ -0,0 +1,35 @@
+/*
+ * I2S configuration for sound cards. 
+ *
+ * Copyright (c) 2014 Daniel Matuschek <daniel@hifiberry.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef BCM2708_I2S_H
+#define BCM2708_I2S_H
+
+/* I2S pin assignment */
+#define BCM2708_I2S_GPIO_AUTO	0
+#define BCM2708_I2S_GPIO_PIN18	1
+#define BCM2708_I2S_GPIO_PIN28	2
+
+/* Alt mode to enable I2S */
+#define BCM2708_I2S_GPIO_PIN18_ALT	0
+#define BCM2708_I2S_GPIO_PIN28_ALT	2
+
+extern void bcm2708_i2s_set_gpio(int gpio);
+
+#endif
-- 
1.9.1