summaryrefslogtreecommitdiff
path: root/target/linux/coldfire/patches/033-m5445x_ssi_cleanup.patch
blob: 068323b06dbe75413f1a08e2befbb3652a604816 (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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
From 98e15babf1e25868d22c024dac6133cc29059d39 Mon Sep 17 00:00:00 2001
From: Kurt Mahan <kmahan@freescale.com>
Date: Sun, 9 Dec 2007 02:24:13 -0700
Subject: [PATCH] Fix DMA mode and cleanup driver.

LTIBName: m5445x-ssi-cleanup
Signed-off-by: Kurt Mahan <kmahan@freescale.com>
---
 drivers/spi/ssi_audio.c |  207 ++++++++++++++++++++++++-----------------------
 1 files changed, 104 insertions(+), 103 deletions(-)

--- a/drivers/spi/ssi_audio.c
+++ b/drivers/spi/ssi_audio.c
@@ -2,7 +2,7 @@
  * MCF5445x audio driver.
  *
  * Yaroslav Vinogradov yaroslav.vinogradov@freescale.com
- * Copyright Freescale Semiconductor, Inc. 2006
+ * Copyright Freescale Semiconductor, Inc. 2006, 2007
  *
  * 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
@@ -25,9 +25,11 @@
 
 #include <asm/coldfire.h>
 #include <asm/coldfire_edma.h>
+#ifdef CONFIG_M54455
 #include <asm/mcf5445x_ssi.h>
 #include <asm/mcf5445x_ccm.h>
 #include <asm/mcf5445x_gpio.h>
+#endif
 
 #define SOUND_DEVICE_NAME "sound"
 #define DRIVER_NAME "ssi_audio"
@@ -47,8 +49,8 @@
 
 /* TLV320DAC23 audio chip registers */
 
-#define CODEC_LEFT_IN_REG			(0x00)
-#define CODEC_RIGHT_IN_REG			(0x01)
+#define CODEC_LEFT_IN_REG		(0x00)
+#define CODEC_RIGHT_IN_REG		(0x01)
 #define CODEC_LEFT_HP_VOL_REG		(0x02)
 #define CODEC_RIGHT_HP_VOL_REG		(0x03)
 #define CODEC_ANALOG_APATH_REG		(0x04)
@@ -57,7 +59,7 @@
 #define CODEC_DIGITAL_IF_FMT_REG	(0x07)
 #define CODEC_SAMPLE_RATE_REG		(0x08)
 #define CODEC_DIGITAL_IF_ACT_REG	(0x09)
-#define CODEC_RESET_REG				(0x0f)
+#define CODEC_RESET_REG			(0x0f)
 
 #define CODEC_SAMPLE_8KHZ		(0x0C)
 #define CODEC_SAMPLE_16KHZ		(0x58)
@@ -71,21 +73,21 @@
 /* DMA transfer size */
 #define DMASIZE		(16*1024)
 
-/* transmit eDMA channel for SSI channel 0 */
-#define DMA_TCD 	10
-/* transmit eDMA channel for SSI channel 1 */
-#define DMA_TCD2 	11
+/* eDMA channel for SSI channel 0 TX */
+#define DMA_TCD 	MCF_EDMA_CHAN_TIMER2
+/* eDMA channel for SSI channel 1 TX */
+#define DMA_TCD2 	MCF_EDMA_CHAN_TIMER3
 
 struct ssi_audio {
-	struct spi_device	*spi;
+	struct spi_device *spi;
 	u32 speed;
 	u32 stereo;
 	u32 bits;
 	u32 format;
-	u8  isopen;
-	u8  dmaing;
-	u8  ssi_enabled;
-	u8  channel;
+	u8 isopen;
+	u8 dmaing;
+	u8 ssi_enabled;
+	u8 channel;
 	spinlock_t lock;
 	u8* audio_buf;
 };
@@ -129,7 +131,8 @@ static void ssi_audio_setsamplesize(int 
 	}
 
 #ifdef AUDIO_DEBUG
-	printk(DRIVER_NAME ":ssi_audio_setsamplesize %d %d\n", audio_device->format, audio_device->bits);
+	printk(DRIVER_NAME ":ssi_audio_setsamplesize %d %d\n",
+	       audio_device->format, audio_device->bits);
 #endif
 }
 
@@ -157,62 +160,57 @@ void __inline__ ssi_audio_dmarun(void)
 {
 	set_edma_params(DMA_TCD,
 #ifdef USE_MMU
-					virt_to_phys(&(audio_device->audio_buf[audio_start])),
+			virt_to_phys(&(audio_device->audio_buf[audio_start])),
 #else
-					(u32)&(audio_device->audio_buf[audio_start]),
+			(u32)&(audio_device->audio_buf[audio_start]),
 #endif
-					(u32)&MCF_SSI_TX0,
-					MCF_EDMA_TCD_ATTR_SSIZE_32BIT | MCF_EDMA_TCD_ATTR_DSIZE_32BIT,
-					8,
-					4,
-					0,
-					audio_count/8,
-					audio_count/8,
-					0,
-					0,
-					0, // major_int
-					0  // disable_req
-					);
+			(u32)&MCF_SSI_TX0,
+			MCF_EDMA_TCD_ATTR_SSIZE_32BIT | MCF_EDMA_TCD_ATTR_DSIZE_32BIT,
+			8,
+			4,
+			0,
+			audio_count/8,
+			audio_count/8,
+			0,
+			0,
+			0, // major_int
+			0  // disable_req
+			);
 
 	set_edma_params(DMA_TCD2,
 #ifdef USE_MMU
-					virt_to_phys(&(audio_device->audio_buf[audio_start+4])),
+			virt_to_phys(&(audio_device->audio_buf[audio_start+4])),
 #else
-					(u32)&(audio_device->audio_buf[audio_start+4]),
+			(u32)&(audio_device->audio_buf[audio_start+4]),
 #endif
-					(u32)&MCF_SSI_TX1,
-					MCF_EDMA_TCD_ATTR_SSIZE_32BIT | MCF_EDMA_TCD_ATTR_DSIZE_32BIT,
-					8,
-					4,
-					0,
-					audio_count/8,
-					audio_count/8,
-					0,
-					0,
-					1, // major_int
-                    0  // disable_req
-					);
+			(u32)&MCF_SSI_TX1,
+			MCF_EDMA_TCD_ATTR_SSIZE_32BIT | MCF_EDMA_TCD_ATTR_DSIZE_32BIT,
+			8,
+			4,
+			0,
+			audio_count/8,
+			audio_count/8,
+			0,
+			0,
+			1, // major_int
+                    	0  // disable_req
+			);
 
 	audio_device->dmaing = 1;
 	audio_txbusy = 1;
 
 	start_edma_transfer(DMA_TCD);
 	start_edma_transfer(DMA_TCD2);
-#if 0
-	MCF_EDMA_ERQ |= (1<<DMA_TCD) | (1<<DMA_TCD2);
-	MCF_EDMA_SSRT = DMA_TCD;
-	MCF_EDMA_SSRT = DMA_TCD2;
-#endif
-
 }
 
-/*
- *	Start DMA'ing a new buffer of data if any available.
+/**
+ * ssi_audio_dmabuf - Start DMA'ing a new buffer of data if any available.
  */
 static void ssi_audio_dmabuf(void)
 {
 #ifdef AUDIO_DEBUG
-	printk(DRIVER_NAME ":ssi_audio_dmabuf(): append=%x start=%x\n", audio_append, audio_appstart);
+	printk(DRIVER_NAME ":ssi_audio_dmabuf(): append=%x start=%x\n",
+	       audio_append, audio_appstart);
 #endif
 
 	/* If already running then nothing to do... */
@@ -241,7 +239,8 @@ static void ssi_audio_dmabuf(void)
 	}
 }
 
-void __inline__ stop_dma(void) {
+void __inline__ stop_dma(void)
+{
 	stop_edma_transfer(DMA_TCD);
 	stop_edma_transfer(DMA_TCD2);
 }
@@ -283,7 +282,6 @@ static void init_dma(void)
 
 #endif	/* CONFIG_SSIAUDIO_USE_EDMA */
 
-
 /* Write CODEC register using SPI
  *   address - CODEC register address
  *   data - data to be written into register
@@ -296,7 +294,8 @@ static int codec_write(u8 addr, u16 data
 		return -ENODEV;
 
 	spi_word = ((addr & 0x7F)<<9)|(data & 0x1FF);
-	return spi_write(audio_device->spi, (const u8*)&spi_word, sizeof(spi_word));
+	return spi_write(audio_device->spi, (const u8*)&spi_word,
+			 sizeof(spi_word));
 }
 
 static inline void enable_ssi(void)
@@ -359,7 +358,7 @@ static void init_audio_codec(void)
 	codec_write(CODEC_DIGITAL_APATH_REG, 0x007); /* Set A path */
 
 	/* set sample rate */
-    adjust_codec_speed();
+	adjust_codec_speed();
 
 	codec_write(CODEC_LEFT_HP_VOL_REG, 0x075); /* set volume */
 	codec_write(CODEC_RIGHT_HP_VOL_REG, 0x075); /* set volume */
@@ -375,13 +374,12 @@ static void chip_init(void)
 #endif
 
 	/* Enable the SSI pins */
-	MCF_GPIO_PAR_SSI = ( 0
-							| MCF_GPIO_PAR_SSI_MCLK
-							| MCF_GPIO_PAR_SSI_STXD(3)
-							| MCF_GPIO_PAR_SSI_SRXD(3)
-							| MCF_GPIO_PAR_SSI_FS(3)
-							| MCF_GPIO_PAR_SSI_BCLK(3) );
-
+	MCF_GPIO_PAR_SSI = (0
+			    | MCF_GPIO_PAR_SSI_MCLK
+			    | MCF_GPIO_PAR_SSI_STXD(3)
+			    | MCF_GPIO_PAR_SSI_SRXD(3)
+			    | MCF_GPIO_PAR_SSI_FS(3)
+			    | MCF_GPIO_PAR_SSI_BCLK(3) );
 }
 
 static void init_ssi(void)
@@ -430,8 +428,8 @@ static void init_ssi(void)
 			;
 
 	MCF_SSI_FCSR = 0
-			| MCF_SSI_FCSR_TFWM0(0)
-			| MCF_SSI_FCSR_TFWM1(0)
+			| MCF_SSI_FCSR_TFWM0(2)
+			| MCF_SSI_FCSR_TFWM1(2)
 			;
 
 	MCF_SSI_IER =   0 // interrupts
@@ -459,9 +457,8 @@ static int ssi_audio_isr(int irq, void *
 {
 	unsigned long	*bp;
 
-	if (audio_txbusy==0) {
+	if (audio_txbusy==0)
 		return IRQ_HANDLED;
-	}
 
 	spin_lock(&(audio_device->lock));
 
@@ -560,7 +557,8 @@ static int ssi_audio_close(struct inode 
 }
 
 /* write to audio device */
-static ssize_t ssi_audio_write(struct file *filp, const char *buf, size_t count, loff_t *ppos)
+static ssize_t ssi_audio_write(struct file *filp, const char *buf,
+	size_t count, loff_t *ppos)
 {
 	unsigned long	*dp, *buflp;
 	unsigned short	*bufwp;
@@ -568,10 +566,12 @@ static ssize_t ssi_audio_write(struct fi
 	unsigned int	slen, bufcnt, i, s, e;
 
 #ifdef AUDIO_DEBUG
-	printk(DRIVER_NAME ":ssi_audio_write(buf=%x,count=%d)\n", (int) buf, count);
+	printk(DRIVER_NAME ":ssi_audio_write(buf=%x,count=%d)\n",
+	       (int)buf, count);
 #endif
 
-	if (audio_device==NULL) return (-ENODEV);
+	if (audio_device==NULL)
+		return (-ENODEV);
 
 	if (count <= 0)
 		return 0;
@@ -592,8 +592,8 @@ static ssize_t ssi_audio_write(struct fi
 
 tryagain:
 	/*
-	 *	Get a snapshot of buffer, so we can figure out how
-	 *	much data we can fit in...
+	 * Get a snapshot of buffer, so we can figure out how
+	 * much data we can fit in...
 	 */
 	s = audio_start;
 	e = audio_append;
@@ -613,11 +613,12 @@ tryagain:
 		goto tryagain;
 	}
 
-	/* For DMA we need to have data as 32 bit
-	   values (since SSI TX register is 32 bit).
-	   So, the incomming 16 bit data must be put to buffer as 32 bit values.
-	   Also, the endianess is converted if needed
-	*/
+	/*
+	 * For DMA we need to have data as 32 bit
+	 * values (since SSI TX register is 32 bit).
+	 * So, the incoming 16 bit data must be put to buffer as 32 bit values.
+	 * Also, the endianess is converted if needed
+	 */
 	if (audio_device->stereo) {
 		if (audio_device->bits == 16) {
 			if (audio_device->format==AFMT_S16_LE) {
@@ -678,16 +679,19 @@ tryagain:
 }
 
 /* ioctl: control the driver */
-static int ssi_audio_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg)
+static int ssi_audio_ioctl(struct inode *inode, struct file *filp,
+	unsigned int cmd, unsigned long arg)
 {
-	long	val;
-	int	rc = 0;
+	long val;
+	int rc = 0;
 
 #ifdef AUDIO_DEBUG
-    printk(DRIVER_NAME ":ssi_audio_ioctl(cmd=%x,arg=%x)\n", (int) cmd, (int) arg);
+    printk(DRIVER_NAME ":ssi_audio_ioctl(cmd=%x,arg=%x)\n",
+	   (int)cmd, (int)arg);
 #endif
 
-	if (audio_device==NULL) return (-ENODEV);
+	if (audio_device==NULL)
+		return (-ENODEV);
 
 	switch (cmd) {
 
@@ -744,8 +748,6 @@ static int ssi_audio_ioctl(struct inode 
 	return rc;
 }
 
-/****************************************************************************/
-
 struct file_operations	ssi_audio_fops = {
 	open: ssi_audio_open,		/* open */
 	release: ssi_audio_close,	/* close */
@@ -756,8 +758,8 @@ struct file_operations	ssi_audio_fops = 
 /* initialize audio driver */
 static int __devinit ssi_audio_probe(struct spi_device *spi)
 {
-	struct ssi_audio	*audio;
-	int	err;
+	struct ssi_audio *audio;
+	int err;
 
 #ifdef AUDIO_DEBUG
 	printk(DRIVER_NAME": probe\n");
@@ -804,7 +806,7 @@ static int __devinit ssi_audio_probe(str
 	audio->spi = spi;
 
 #ifndef CONFIG_SSIAUDIO_USE_EDMA
-	if (request_irq(spi->irq, ssi_audio_isr, SA_INTERRUPT,	spi->dev.bus_id, audio)) {
+	if (request_irq(spi->irq, ssi_audio_isr, IRQF_DISABLED,	spi->dev.bus_id, audio)) {
 		dev_dbg(&spi->dev, "irq %d busy?\n", spi->irq);
 		err = -EBUSY;
 		goto err_free_mem;
@@ -813,25 +815,21 @@ static int __devinit ssi_audio_probe(str
 #else
 	/* request 2 eDMA channels since two channel output mode is used */
 	if (request_edma_channel(DMA_TCD,
-							ssi_audio_dma_handler_empty,
-							NULL,
-							audio,
-							&(audio_device->lock),
-							DRIVER_NAME
-							)!=0)
-	{
+				 ssi_audio_dma_handler_empty,
+				 NULL,
+				 audio,
+				 &(audio_device->lock),
+				 DRIVER_NAME)!=0) {
 		dev_dbg(&spi->dev, "DMA channel %d busy?\n", DMA_TCD);
 		err = -EBUSY;
 		goto err_free_mem;
 	}
 	if (request_edma_channel(DMA_TCD2,
-							ssi_audio_dma_handler,
-							NULL,
-							audio,
-							&(audio_device->lock),
-							DRIVER_NAME
-							)!=0)
-	{
+				 ssi_audio_dma_handler,
+				 NULL,
+				 audio,
+				 &(audio_device->lock),
+				 DRIVER_NAME)!=0) {
 		dev_dbg(&spi->dev, "DMA channel %d busy?\n", DMA_TCD2);
 		err = -EBUSY;
 		goto err_free_mem;
@@ -870,11 +868,13 @@ static int __devexit ssi_audio_remove(st
 	return 0;
 }
 
-static int ssi_audio_suspend(struct spi_device *spi, pm_message_t message) {
+static int ssi_audio_suspend(struct spi_device *spi, pm_message_t message)
+{
 	return 0;
 }
 
-static int ssi_audio_resume(struct spi_device *spi) {
+static int ssi_audio_resume(struct spi_device *spi)
+{
 	return 0;
 }
 
@@ -902,5 +902,6 @@ static void __exit ssi_audio_exit(void)
 }
 module_exit(ssi_audio_exit);
 
-MODULE_DESCRIPTION("SSI/I2S Audio Driver");
 MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Freescale Semiconductor, Inc.");
+MODULE_DESCRIPTION("SSI/I2S Audio Driver");