1 From bc755a3b8859e7307a8b10f39ca4cb6401c51987 Mon Sep 17 00:00:00 2001
2 From: Kurt Mahan <kmahan@freescale.com>
3 Date: Tue, 27 Nov 2007 14:39:37 -0700
4 Subject: [PATCH] Add M5445x SPI support.
7 Signed-off-by: Kurt Mahan <kmahan@freescale.com>
9 arch/m68k/configs/m54455evb_defconfig | 24 +-
10 drivers/spi/Kconfig | 36 +
11 drivers/spi/Makefile | 4 +
12 drivers/spi/coldfire_edma.c | 358 ++++++++
13 drivers/spi/spi-m5445x.c | 156 ++++
14 drivers/spi/spi_coldfire.c | 1552 +++++++++++++++++++++++++++++++++
15 drivers/spi/ssi_audio.c | 906 +++++++++++++++++++
16 include/asm-m68k/coldfire_edma.h | 101 ++-
17 include/linux/spi/mcfqspi.h | 80 ++
18 9 files changed, 3196 insertions(+), 21 deletions(-)
19 create mode 100644 drivers/spi/coldfire_edma.c
20 create mode 100644 drivers/spi/spi-m5445x.c
21 create mode 100644 drivers/spi/spi_coldfire.c
22 create mode 100644 drivers/spi/ssi_audio.c
23 create mode 100644 include/linux/spi/mcfqspi.h
25 --- a/arch/m68k/configs/m54455evb_defconfig
26 +++ b/arch/m68k/configs/m54455evb_defconfig
27 @@ -321,6 +321,8 @@ CONFIG_MTD_PHYSMAP_BANKWIDTH=1
29 # Self-contained MTD device drivers
31 +# CONFIG_MTD_DATAFLASH is not set
32 +# CONFIG_MTD_M25P80 is not set
33 # CONFIG_MTD_SLRAM is not set
34 # CONFIG_MTD_PHRAM is not set
35 # CONFIG_MTD_MTDRAM is not set
36 @@ -497,8 +499,26 @@ CONFIG_UNIX98_PTYS=y
40 -# CONFIG_SPI is not set
41 -# CONFIG_SPI_MASTER is not set
43 +# CONFIG_SPI_DEBUG is not set
44 +CONFIG_COLDFIRE_EDMA=y
48 +# SPI Master Controller Drivers
50 +# CONFIG_SPI_BITBANG is not set
51 +CONFIG_SPI_COLDFIRE=y
52 +CONFIG_SPI_COLDFIRE_DSPI_EDMA=y
55 +# SPI Protocol Masters
57 +# CONFIG_SPI_AT25 is not set
58 +# CONFIG_SPI_SPIDEV is not set
59 +# CONFIG_SPI_TLE62X0 is not set
60 +CONFIG_SPI_COLDFIRE_SSI_AUDIO=y
61 +# CONFIG_SSIAUDIO_USE_EDMA is not set
62 # CONFIG_W1 is not set
63 # CONFIG_POWER_SUPPLY is not set
64 # CONFIG_HWMON is not set
65 --- a/drivers/spi/Kconfig
66 +++ b/drivers/spi/Kconfig
67 @@ -35,6 +35,15 @@ config SPI_DEBUG
68 Say "yes" to enable debug messaging (like dev_dbg and pr_debug),
69 sysfs, and debugfs support in SPI controller and protocol drivers.
72 + tristate "Coldfire eDMA"
73 + depends on COLDFIRE && EXPERIMENTAL
75 + Support for Coldfire eDMA controller. Required for example
76 + by SSI audio device driver.
81 # MASTER side ... talking to discrete SPI slave chips including microcontrollers
83 @@ -113,6 +122,21 @@ config SPI_GPIO
88 + tristate "Coldfire QSPI/DSPI SPI Master"
89 + depends on SPI_MASTER && COLDFIRE && EXPERIMENTAL
91 + SPI driver for Freescale Coldfire QSPI module in master mode.
92 + Tested with the 5282 processor, but should also work with other
95 +config SPI_COLDFIRE_DSPI_EDMA
96 + boolean "Coldfire DSPI master driver uses eDMA"
97 + depends on SPI_MASTER && COLDFIRE && SPI_COLDFIRE && EXPERIMENTAL && COLDFIRE_EDMA
100 + Say "yes" if you want DSPI master driver to use eDMA for transfers.
103 tristate "Freescale iMX SPI controller"
104 depends on SPI_MASTER && ARCH_IMX && EXPERIMENTAL
105 @@ -255,6 +279,18 @@ config SPI_TLE62X0
107 # Add new SPI protocol masters in alphabetical order above this line
109 +config SPI_COLDFIRE_SSI_AUDIO
110 + tristate "Coldfire SSI AUDIO"
111 + depends on SPI_MASTER && SPI_COLDFIRE && EXPERIMENTAL
113 + SSI audio device driver
115 +config SSIAUDIO_USE_EDMA
116 + boolean "Coldfire DSPI master driver uses eDMA"
118 + depends on EXPERIMENTAL && COLDFIRE_EDMA && SPI_COLDFIRE_SSI_AUDIO
120 + Say "yes" if you want SSI audio driver to use eDMA for SSI transfers.
122 # (slave support would go here)
124 --- a/drivers/spi/Makefile
125 +++ b/drivers/spi/Makefile
126 @@ -6,6 +6,8 @@ ifeq ($(CONFIG_SPI_DEBUG),y)
127 EXTRA_CFLAGS += -DDEBUG
130 +obj-$(CONFIG_COLDFIRE_EDMA) += coldfire_edma.o
132 # small core, mostly translating board-specific
133 # config declarations into driver model code
134 obj-$(CONFIG_SPI_MASTER) += spi.o
135 @@ -16,6 +18,7 @@ obj-$(CONFIG_SPI_BFIN) += spi_bfin5xx.
136 obj-$(CONFIG_SPI_BITBANG) += spi_bitbang.o
137 obj-$(CONFIG_SPI_AU1550) += au1550_spi.o
138 obj-$(CONFIG_SPI_BUTTERFLY) += spi_butterfly.o
139 +obj-$(CONFIG_SPI_COLDFIRE) += spi_coldfire.o spi-m5445x.o
140 obj-$(CONFIG_SPI_GPIO) += spi_gpio.o
141 obj-$(CONFIG_SPI_IMX) += spi_imx.o
142 obj-$(CONFIG_SPI_LM70_LLP) += spi_lm70llp.o
143 @@ -35,6 +38,7 @@ obj-$(CONFIG_SPI_SH_SCI) += spi_sh_sci.
144 obj-$(CONFIG_SPI_AT25) += at25.o
145 obj-$(CONFIG_SPI_SPIDEV) += spidev.o
146 obj-$(CONFIG_SPI_TLE62X0) += tle62x0.o
147 +obj-$(CONFIG_SPI_COLDFIRE_SSI_AUDIO) += ssi_audio.o
148 # ... add above this line ...
150 # SPI slave controller drivers (upstream link)
152 +++ b/drivers/spi/coldfire_edma.c
156 + * coldfire_edma.c - eDMA driver for Coldfire MCF5445x
158 + * Yaroslav Vinogradov yaroslav.vinogradov@freescale.com
160 + * Copyright Freescale Semiconductor, Inc. 2007
162 + * This program is free software; you can redistribute it and/or modify it
163 + * under the terms of the GNU General Public License as published by the
164 + * Free Software Foundation; either version 2 of the License, or (at your
165 + * option) any later version.
168 +#include <linux/init.h>
169 +#include <linux/module.h>
170 +#include <asm/virtconvert.h>
171 +#include <asm/coldfire.h>
172 +#include <linux/fs.h>
173 +#include <linux/cdev.h>
174 +#include <linux/seq_file.h>
175 +#include <linux/proc_fs.h>
176 +#include <asm/mcf5445x_edma.h>
177 +#include <asm/mcf5445x_intc.h>
178 +#include <asm/coldfire_edma.h>
181 +/* callback handler data for each TCD */
182 +struct edma_isr_record {
183 + edma_irq_handler irq_handler; /* interrupt handler */
184 + edma_error_handler error_handler; /* error interrupt handler */
185 + void* dev; /* device used for the channel */
186 + int allocated; /* busy flag */
187 + spinlock_t *lock; /* spin lock (if needs to be locked in interrupt) */
188 + const char* device_id; /* device id string, used in proc file system */
191 +/* device structure */
192 +struct coldfire_edma_dev {
193 + struct cdev cdev; /* character device */
194 + struct edma_isr_record dma_interrupt_handlers[EDMA_CHANNELS]; /* channel handlers */
197 +/* allocated major device number */
198 +static int coldfire_dma_major;
199 +/* device driver structure */
200 +static struct coldfire_edma_dev* devp = NULL;
202 +/* device driver file operations */
203 +struct file_operations coldfire_edma_fops = {
204 + .owner = THIS_MODULE,
207 +/* eDMA channel interrupt handler */
208 +static int dmaisr(int irq, void *dev_id)
210 + int channel = irq - EDMA_INT_CONTROLLER_BASE - EDMA_INT_CHANNEL_BASE;
211 + int result = IRQ_HANDLED;
213 + if (devp!=NULL && devp->dma_interrupt_handlers[channel].lock) {
214 + spin_lock(devp->dma_interrupt_handlers[channel].lock);
217 + if (devp!=NULL && devp->dma_interrupt_handlers[channel].irq_handler) {
218 + result = devp->dma_interrupt_handlers[channel].irq_handler(channel,
219 + devp->dma_interrupt_handlers[channel].dev);
221 + confirm_edma_interrupt_handled(channel);
222 + printk(EDMA_DRIVER_NAME ": No handler for DMA channel %d\n", channel);
225 + if (devp!=NULL && devp->dma_interrupt_handlers[channel].lock) {
226 + spin_unlock(devp->dma_interrupt_handlers[channel].lock);
232 +/* eDMA error interrupt handler */
233 +static int dma_error_isr(int irq, void* dev_id)
238 + err = MCF_EDMA_ERR;
239 + for (i=0;i<EDMA_CHANNELS;i++) {
240 + if (err & (1<<i)) {
241 + if (devp!=NULL && devp->dma_interrupt_handlers[i].error_handler) {
242 + devp->dma_interrupt_handlers[i].error_handler(i, devp->dma_interrupt_handlers[i].dev);
244 + printk(KERN_WARNING EDMA_DRIVER_NAME ": DMA error on channel %d\n", i);
249 + MCF_EDMA_CERR = MCF_EDMA_CERR_CAER;
250 + return IRQ_HANDLED;
253 +/* sets channel parameters */
254 +void set_edma_params(int channel, u32 source, u32 dest,
255 + u32 attr, u32 soff, u32 nbytes, u32 slast,
256 + u32 citer, u32 biter, u32 doff, u32 dlast_sga,
257 + int major_int, int disable_req)
260 + if (channel<0 || channel>EDMA_CHANNELS)
263 + MCF_EDMA_TCD_SADDR(channel) = source;
264 + MCF_EDMA_TCD_DADDR(channel) = dest;
265 + MCF_EDMA_TCD_ATTR(channel) = attr;
266 + MCF_EDMA_TCD_SOFF(channel) = MCF_EDMA_TCD_SOFF_SOFF(soff);
267 + MCF_EDMA_TCD_NBYTES(channel) = MCF_EDMA_TCD_NBYTES_NBYTES(nbytes);
268 + MCF_EDMA_TCD_SLAST(channel) = MCF_EDMA_TCD_SLAST_SLAST(slast);
269 + MCF_EDMA_TCD_CITER(channel) = MCF_EDMA_TCD_CITER_CITER(citer);
270 + MCF_EDMA_TCD_BITER(channel)=MCF_EDMA_TCD_BITER_BITER(biter);
271 + MCF_EDMA_TCD_DOFF(channel) = MCF_EDMA_TCD_DOFF_DOFF(doff);
272 + MCF_EDMA_TCD_DLAST_SGA(channel) = MCF_EDMA_TCD_DLAST_SGA_DLAST_SGA(dlast_sga);
273 + /* interrupt at the end of major loop */
275 + MCF_EDMA_TCD_CSR(channel) |= MCF_EDMA_TCD_CSR_INT_MAJOR;
277 + MCF_EDMA_TCD_CSR(channel) &= ~MCF_EDMA_TCD_CSR_INT_MAJOR;
279 + /* disable request at the end of major loop of transfer or not*/
281 + MCF_EDMA_TCD_CSR(channel) |= MCF_EDMA_TCD_CSR_D_REQ;
283 + MCF_EDMA_TCD_CSR(channel) &= ~MCF_EDMA_TCD_CSR_D_REQ;
287 +EXPORT_SYMBOL(set_edma_params);
289 +/* init eDMA controller */
290 +void init_edma(void)
294 +EXPORT_SYMBOL(init_edma);
296 +/* request eDMA channel */
297 +int request_edma_channel(int channel,
298 + edma_irq_handler handler,
299 + edma_error_handler error_handler,
302 + const char* device_id )
304 + if (devp!=NULL && channel>=0 && channel<=EDMA_CHANNELS) {
305 + if (devp->dma_interrupt_handlers[channel].allocated) {
308 + devp->dma_interrupt_handlers[channel].allocated = 1;
309 + devp->dma_interrupt_handlers[channel].irq_handler = handler;
310 + devp->dma_interrupt_handlers[channel].error_handler = error_handler;
311 + devp->dma_interrupt_handlers[channel].dev = dev;
312 + devp->dma_interrupt_handlers[channel].lock = lock;
313 + devp->dma_interrupt_handlers[channel].device_id = device_id;
318 +EXPORT_SYMBOL(request_edma_channel);
320 +/* free eDMA channel */
321 +int free_edma_channel(int channel, void* dev)
323 + if (devp!=NULL && channel>=0 && channel<=EDMA_CHANNELS) {
324 + if (devp->dma_interrupt_handlers[channel].allocated) {
325 + if (devp->dma_interrupt_handlers[channel].dev != dev) {
328 + devp->dma_interrupt_handlers[channel].allocated = 0;
329 + devp->dma_interrupt_handlers[channel].dev = NULL;
330 + devp->dma_interrupt_handlers[channel].irq_handler = NULL;
331 + devp->dma_interrupt_handlers[channel].error_handler = NULL;
332 + devp->dma_interrupt_handlers[channel].lock = NULL;
338 +EXPORT_SYMBOL(free_edma_channel);
340 +/* clean-up device driver allocated resources */
341 +static void coldfire_edma_cleanup(void)
346 + /* free interrupts/memory */
348 + for (i=0;i<EDMA_CHANNELS;i++)
350 + MCF_INTC0_SIMR = EDMA_INT_CHANNEL_BASE+i;
351 + free_irq(EDMA_INT_CHANNEL_BASE+EDMA_INT_CONTROLLER_BASE+i, devp);
353 + MCF_INTC0_SIMR = EDMA_INT_CHANNEL_BASE+EDMA_CHANNELS;
354 + free_irq(EDMA_INT_CHANNEL_BASE+EDMA_INT_CONTROLLER_BASE+EDMA_CHANNELS, devp);
355 + cdev_del(&devp->cdev);
359 + /* unregister character device */
360 + devno = MKDEV(coldfire_dma_major, 0);
361 + unregister_chrdev_region(devno, 1);
364 +#ifdef CONFIG_PROC_FS
365 +/* proc file system support */
367 +#define FREE_CHANNEL "free"
368 +#define DEVICE_UNKNOWN "device unknown"
370 +static int proc_edma_show(struct seq_file *m, void *v)
374 + if (devp==NULL) return 0;
376 + for (i = 0 ; i < EDMA_CHANNELS ; i++) {
377 + if (devp->dma_interrupt_handlers[i].allocated) {
378 + if (devp->dma_interrupt_handlers[i].device_id)
379 + seq_printf(m, "%2d: %s\n", i, devp->dma_interrupt_handlers[i].device_id);
381 + seq_printf(m, "%2d: %s\n", i, DEVICE_UNKNOWN);
383 + seq_printf(m, "%2d: %s\n", i, FREE_CHANNEL);
389 +static int proc_edma_open(struct inode *inode, struct file *file)
391 + return single_open(file, proc_edma_show, NULL);
394 +static const struct file_operations proc_edma_operations = {
395 + .open = proc_edma_open,
397 + .llseek = seq_lseek,
398 + .release = single_release,
401 +static int __init proc_edma_init(void)
403 + struct proc_dir_entry *e;
405 + e = create_proc_entry("edma", 0, NULL);
407 + e->proc_fops = &proc_edma_operations;
414 +/* initializes device driver */
415 +static int __init coldfire_edma_init(void)
421 + /* allocate free major number */
422 + result = alloc_chrdev_region(&dev, DMA_DEV_MINOR, 1, EDMA_DRIVER_NAME);
424 + printk(KERN_WARNING EDMA_DRIVER_NAME": can't get major %d\n", result);
427 + coldfire_dma_major = MAJOR(dev);
429 + /* allocate device driver structure */
430 + devp = kmalloc(sizeof(struct coldfire_edma_dev), GFP_KERNEL);
436 + /* init handlers (no handlers for beggining) */
437 + for (i=0;i<EDMA_CHANNELS;i++) {
438 + devp->dma_interrupt_handlers[i].irq_handler = NULL;
439 + devp->dma_interrupt_handlers[i].error_handler = NULL;
440 + devp->dma_interrupt_handlers[i].dev = NULL;
441 + devp->dma_interrupt_handlers[i].allocated = 0;
442 + devp->dma_interrupt_handlers[i].lock = NULL;
443 + devp->dma_interrupt_handlers[i].device_id = NULL;
446 + /* register char device */
447 + cdev_init(&devp->cdev, &coldfire_edma_fops);
448 + devp->cdev.owner = THIS_MODULE;
449 + devp->cdev.ops = &coldfire_edma_fops;
450 + result = cdev_add(&devp->cdev, dev, 1);
452 + printk(KERN_NOTICE EDMA_DRIVER_NAME": Error %d adding coldfire-dma device\n", result);
457 + /* request/enable irq for each eDMA channel */
458 + for (i=0;i<EDMA_CHANNELS;i++)
460 + result = request_irq(EDMA_INT_CHANNEL_BASE+EDMA_INT_CONTROLLER_BASE+i,
461 + dmaisr, SA_INTERRUPT, EDMA_DRIVER_NAME, devp);
463 + printk(KERN_WARNING EDMA_DRIVER_NAME": Cannot request irq %d\n",
464 + EDMA_INT_CHANNEL_BASE+EDMA_INT_CONTROLLER_BASE+i);
469 + MCF_INTC0_ICR(EDMA_INT_CHANNEL_BASE+i) = EDMA_IRQ_LEVEL;
470 + MCF_INTC0_CIMR = EDMA_INT_CHANNEL_BASE+i;
474 + /* request error interrupt */
475 + result = request_irq(EDMA_INT_CHANNEL_BASE + EDMA_INT_CONTROLLER_BASE + EDMA_CHANNELS,
476 + dma_error_isr, SA_INTERRUPT, EDMA_DRIVER_NAME, devp);
478 + printk(KERN_WARNING EDMA_DRIVER_NAME": Cannot request irq %d\n",
479 + EDMA_INT_CHANNEL_BASE+EDMA_INT_CONTROLLER_BASE+EDMA_CHANNELS);
484 + /* enable error interrupt in interrupt controller */
485 + MCF_INTC0_ICR(EDMA_INT_CHANNEL_BASE+EDMA_CHANNELS) = EDMA_IRQ_LEVEL;
486 + MCF_INTC0_CIMR = EDMA_INT_CHANNEL_BASE+EDMA_CHANNELS;
488 +#ifdef CONFIG_PROC_FS
492 + printk(EDMA_DRIVER_NAME ": initialized successfully\n");
496 + coldfire_edma_cleanup();
501 +static void __exit coldfire_edma_exit(void)
503 + coldfire_edma_cleanup();
506 +module_init(coldfire_edma_init);
507 +module_exit(coldfire_edma_exit);
509 +MODULE_LICENSE("GPL");
510 +MODULE_AUTHOR("Yaroslav Vinogradov, Freescale Inc.");
511 +MODULE_DESCRIPTION("eDMA library for Coldfire 5445x");
513 +++ b/drivers/spi/spi-m5445x.c
515 +/***************************************************************************/
517 + * linux/arch/m68k/coldfire/spi-m5445x.c
519 + * Sub-architcture dependant initialization code for the Freescale
522 + * Yaroslav Vinogradov yaroslav.vinogradov@freescale.com
523 + * Copyright Freescale Semiconductor, Inc 2007
525 + * This program is free software; you can redistribute it and/or modify
526 + * it under the terms of the GNU General Public License as published by
527 + * the Free Software Foundation; either version 2 of the License, or
528 + * (at your option) any later version.
530 +/***************************************************************************/
533 +#include <linux/kernel.h>
534 +#include <linux/sched.h>
535 +#include <linux/param.h>
536 +#include <linux/init.h>
537 +#include <linux/interrupt.h>
538 +#include <linux/device.h>
539 +#include <linux/platform_device.h>
540 +#include <linux/spi/spi.h>
542 +#include <asm/dma.h>
543 +#include <asm/traps.h>
544 +#include <asm/machdep.h>
545 +#include <asm/coldfire.h>
546 +#include <asm/mcfsim.h>
547 +#include <asm/mcfqspi.h>
548 +#include <asm/mcf5445x_gpio.h>
550 +#define SPI_NUM_CHIPSELECTS 0x10
551 +#define SPI_PAR_VAL (0 | MCF_GPIO_PAR_DSPI_PCS5_PCS5 | MCF_GPIO_PAR_DSPI_PCS2_PCS2 \
552 + | MCF_GPIO_PAR_DSPI_PCS1_PCS1 | MCF_GPIO_PAR_DSPI_PCS0_PCS0 | MCF_GPIO_PAR_DSPI_SIN_SIN \
553 + | MCF_GPIO_PAR_DSPI_SOUT_SOUT | MCF_GPIO_PAR_DSPI_SCK_SCK)
555 +#define MCF5445x_DSPI_IRQ_SOURCE (31)
556 +#define MCF5445x_DSPI_IRQ_VECTOR (64 + MCF5445x_DSPI_IRQ_SOURCE)
558 +#define MCF5445x_DSPI_PAR (0xFC0A4063)
559 +#define MCF5445x_DSPI_MCR (0xFC05C000)
560 +#define MCF5445x_INTC0_ICR (0xFC048040)
561 +#define MCF5445x_INTC0_IMRL (0xFC04800C)
564 +#define M5445x_AUDIO_IRQ_SOURCE 49
565 +#define M5445x_AUDIO_IRQ_VECTOR (128+M5445x_AUDIO_IRQ_SOURCE)
566 +#define M5445x_AUDIO_IRQ_LEVEL 4
568 +void coldfire_qspi_cs_control(u8 cs, u8 command)
572 +#if defined(CONFIG_SPI_COLDFIRE_SSI_AUDIO)
573 +static struct coldfire_spi_chip ssi_audio_chip_info = {
574 + .mode = SPI_MODE_0,
575 + .bits_per_word = 16,
576 + .del_cs_to_clk = 16,
577 + .del_after_trans = 16,
578 + .void_write_data = 0
583 +static struct spi_board_info spi_board_info[] = {
585 +#if defined(CONFIG_SPI_COLDFIRE_SSI_AUDIO)
587 + .modalias = "ssi_audio",
588 + .max_speed_hz = 300000,
591 + .irq = M5445x_AUDIO_IRQ_VECTOR,
592 + .platform_data = NULL,
593 + .controller_data = &ssi_audio_chip_info
599 +static struct coldfire_spi_master coldfire_master_info = {
601 + .num_chipselect = SPI_NUM_CHIPSELECTS,
602 + .irq_source = MCF5445x_DSPI_IRQ_SOURCE,
603 + .irq_vector = MCF5445x_DSPI_IRQ_VECTOR,
604 + .irq_mask = (0x01 << MCF5445x_DSPI_IRQ_SOURCE),
605 + .irq_lp = 0x2, /* Level */
606 + .par_val = SPI_PAR_VAL,
607 +// .par_val16 = SPI_PAR_VAL,
608 + .cs_control = coldfire_qspi_cs_control,
611 +static struct resource coldfire_spi_resources[] = {
613 + .name = "qspi-par",
614 + .start = MCF5445x_DSPI_PAR,
615 + .end = MCF5445x_DSPI_PAR,
616 + .flags = IORESOURCE_MEM
620 + .name = "qspi-module",
621 + .start = MCF5445x_DSPI_MCR,
622 + .end = MCF5445x_DSPI_MCR + 0xB8,
623 + .flags = IORESOURCE_MEM
627 + .name = "qspi-int-level",
628 + .start = MCF5445x_INTC0_ICR + MCF5445x_DSPI_IRQ_SOURCE,
629 + .end = MCF5445x_INTC0_ICR + MCF5445x_DSPI_IRQ_SOURCE,
630 + .flags = IORESOURCE_MEM
634 + .name = "qspi-int-mask",
635 + .start = MCF5445x_INTC0_IMRL,
636 + .end = MCF5445x_INTC0_IMRL,
637 + .flags = IORESOURCE_MEM
641 +static struct platform_device coldfire_spi = {
642 + .name = "spi_coldfire", //"coldfire-qspi",
644 + .resource = coldfire_spi_resources,
645 + .num_resources = ARRAY_SIZE(coldfire_spi_resources),
647 + .platform_data = &coldfire_master_info,
651 +static int __init spi_dev_init(void)
655 + retval = platform_device_register(&coldfire_spi);
658 + printk(KERN_ERR "SPI-m5445x: platform_device_register failed with code=%d\n", retval);
662 + if (ARRAY_SIZE(spi_board_info))
663 + retval = spi_register_board_info(spi_board_info, ARRAY_SIZE(spi_board_info));
670 +arch_initcall(spi_dev_init);
672 +++ b/drivers/spi/spi_coldfire.c
674 +/****************************************************************************/
677 + * spi_coldfire.c - Master QSPI/DSPI controller for the ColdFire processors
679 + * (C) Copyright 2005, Intec Automation,
680 + * Mike Lavender (mike@steroidmicros)
682 + * (C) Copyright 2007, Freescale Inc,
683 + * Yaroslav Vinogradov (yaroslav.vinogradov@freescale.com)
686 + This program is free software; you can redistribute it and/or modify
687 + it under the terms of the GNU General Public License as published by
688 + the Free Software Foundation; either version 2 of the License, or
689 + (at your option) any later version.
691 + This program is distributed in the hope that it will be useful,
692 + but WITHOUT ANY WARRANTY; without even the implied warranty of
693 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
694 + GNU General Public License for more details.
696 + You should have received a copy of the GNU General Public License
697 + along with this program; if not, write to the Free Software
698 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
699 +/* ------------------------------------------------------------------------- */
702 +/****************************************************************************/
708 +#include <linux/autoconf.h>
709 +#include <linux/init.h>
710 +#include <linux/module.h>
711 +#include <linux/device.h>
712 +#include <linux/interrupt.h>
713 +#include <linux/platform_device.h>
714 +#include <linux/spi/spi.h>
715 +#include <linux/workqueue.h>
716 +#include <linux/delay.h>
718 +#include <asm/delay.h>
719 +#include <asm/mcfsim.h>
720 +#include <asm/mcfqspi.h>
721 +#include <asm/coldfire.h>
722 +#include <asm/virtconvert.h>
724 +#if defined(CONFIG_M54455)
726 + #if defined(CONFIG_SPI_COLDFIRE_DSPI_EDMA)
727 + #define SPI_DSPI_EDMA
729 + #define SPI_USE_MMU
735 +#include <asm/mcf5445x_dspi.h>
740 +#if defined(SPI_DSPI_EDMA)
742 +/* edma buffer size in transfer units (32bits) */
743 +#define EDMA_BUFFER_SIZE (PAGE_SIZE/4)
744 +#define EDMA_BUFSIZE_KMALLOC (EDMA_BUFFER_SIZE*4)
746 +#define DSPI_DMA_RX_TCD 12
747 +#define DSPI_DMA_TX_TCD 13
750 +#include <asm/coldfire_edma.h>
751 +#include <asm/mcf5445x_edma.h>
755 +MODULE_AUTHOR("Mike Lavender");
756 +MODULE_DESCRIPTION("ColdFire QSPI Contoller");
757 +MODULE_LICENSE("GPL");
759 +#define DRIVER_NAME "Coldfire QSPI/DSPI"
761 +/****************************************************************************/
764 + * Local constants and macros
767 +#define QSPI_RAM_SIZE 0x10 /* 16 word table */
769 +#define QSPI_TRANSMIT_RAM 0x00
770 +#define QSPI_RECEIVE_RAM 0x10
771 +#define QSPI_COMMAND_RAM 0x20
773 +#define QSPI_COMMAND 0x7000 /* 15: X = Continuous CS
774 + * 14: 1 = Get BITSE from QMR[BITS]
775 + * 13: 1 = Get DT from QDLYR[DTL]
776 + * 12: 1 = Get DSK from QDLYR[QCD]
777 + * 8-11: XXXX = next 4 bytes for CS
778 + * 0-7: 0000 0000 Reserved
781 +#define QIR_WCEF 0x0008 /* write collison */
782 +#define QIR_ABRT 0x0004 /* abort */
783 +#define QIR_SPIF 0x0001 /* finished */
785 +#define QIR_WCEFE 0x0800
786 +#define QIR_ABRTE 0x0400
787 +#define QIR_SPIFE 0x0100
789 +#define QIR_WCEFB 0x8000
790 +#define QIR_ABRTB 0x4000
791 +#define QIR_ABRTL 0x1000
793 +#define QMR_BITS 0x3C00
794 +#define QMR_BITS_8 0x2000
796 +#define QCR_CONT 0x8000
798 +#define QDLYR_SPE 0x8000
800 +#define QWR_ENDQP_MASK 0x0F00
801 +#define QWR_CSIV 0x1000 /* 1 = active low chip selects */
804 +#define START_STATE ((void*)0)
805 +#define RUNNING_STATE ((void*)1)
806 +#define DONE_STATE ((void*)2)
807 +#define ERROR_STATE ((void*)-1)
809 +#define QUEUE_RUNNING 0
810 +#define QUEUE_STOPPED 1
812 +/****************************************************************************/
815 + * Local Data Structures
818 +struct transfer_state {
826 +#define TRAN_STATE_RX_VOID 0x01
827 +#define TRAN_STATE_TX_VOID 0x02
828 +#define TRAN_STATE_WORD_ODD_NUM 0x04
830 + u16 void_write_data;
831 + unsigned cs_change:1;
862 + unsigned cont_scke:1;
869 + unsigned reserved15:1;
872 + unsigned dis_rxf:1;
874 + unsigned clr_rxf:1;
875 + unsigned smpl_pt:2;
876 + unsigned reserved71:7;
897 +#if defined(SPI_DSPI)
922 + u16 void_write_data;
926 +struct driver_data {
927 + /* Driver model hookup */
928 + struct platform_device *pdev;
930 + /* SPI framework hookup */
931 + struct spi_master *master;
933 + /* Driver message queue */
934 + struct workqueue_struct *workqueue;
935 + struct work_struct pump_messages;
937 + struct list_head queue;
941 + /* Message Transfer pump */
942 + struct tasklet_struct pump_transfers;
944 + /* Current message transfer state info */
945 + struct spi_message* cur_msg;
946 + struct spi_transfer* cur_transfer;
947 + struct chip_data *cur_chip;
954 +#define TRAN_STATE_RX_VOID 0x01
955 +#define TRAN_STATE_TX_VOID 0x02
956 +#define TRAN_STATE_WORD_ODD_NUM 0x04
958 + u16 void_write_data;
959 + unsigned cs_change:1;
964 +#if defined(SPI_DSPI)
965 + u32 *mcr; /* DSPI MCR register */
966 + u32 *ctar; /* DSPI CTAR register */
967 + u32 *dspi_dtfr; /* DSPI DTFR register */
968 + u32 *dspi_drfr; /* DSPI DRFR register */
969 + u32 *dspi_rser; /* DSPI RSER register */
970 + u32 *dspi_sr; /* DSPI status register */
971 + u8 dspi_ctas; /* DSPI CTAS value*/
973 +#if defined(SPI_DSPI_EDMA)
980 + u16 *qmr; /* QSPI mode register */
981 + u16 *qdlyr; /* QSPI delay register */
982 + u16 *qwr; /* QSPI wrap register */
983 + u16 *qir; /* QSPI interrupt register */
984 + u16 *qar; /* QSPI address register */
985 + u16 *qdr; /* QSPI data register */
986 + u16 *qcr; /* QSPI command register */
988 + u8 *par; /* Pin assignment register */
989 + u8 *int_icr; /* Interrupt level and priority register */
990 + u32 *int_mr; /* Interrupt mask register */
991 + void (*cs_control)(u8 cs, u8 command);
994 +#define DSPI_CS(cs) ((1<<(cs))<<16)
997 +/****************************************************************************/
1000 + * SPI local functions
1003 +//#define SPI_COLDFIRE_DEBUG
1005 +static void *next_transfer(struct driver_data *drv_data)
1007 + struct spi_message *msg = drv_data->cur_msg;
1008 + struct spi_transfer *trans = drv_data->cur_transfer;
1010 + /* Move to next transfer */
1011 + if (trans->transfer_list.next != &msg->transfers) {
1012 + drv_data->cur_transfer =
1013 + list_entry(trans->transfer_list.next,
1014 + struct spi_transfer,
1016 + return RUNNING_STATE;
1018 + return DONE_STATE;
1022 +#define DSPI_BITS MCF_DSPI_DCTAR_FMSZ(15)
1023 +#define DSPI_BITS_16 MCF_DSPI_DCTAR_FMSZ(15)
1024 +#define DSPI_BITS_8 MCF_DSPI_DCTAR_FMSZ(7)
1025 +#define DSPI_FIFO_SIZE 16
1027 +static inline int is_word_transfer(struct driver_data *drv_data)
1029 +#if defined(SPI_DSPI)
1030 + return ((*drv_data->ctar & DSPI_BITS_16) == DSPI_BITS_8) ? 0 : 1;
1032 + return ((*drv_data->qmr & QMR_BITS) == QMR_BITS_8) ? 0 : 1;
1036 +static void inline set_8bit_transfer_mode(struct driver_data *drv_data)
1038 +#if defined(SPI_DSPI)
1039 + *drv_data->ctar |= (*drv_data->ctar & ~DSPI_BITS) | DSPI_BITS_8;
1041 + *drv_data->qmr |= (*drv_data->qmr & ~QMR_BITS) | QMR_BITS_8;
1045 +static void inline set_16bit_transfer_mode(struct driver_data *drv_data)
1047 +#if defined(SPI_DSPI)
1048 + *drv_data->ctar |= (*drv_data->ctar & ~DSPI_BITS) | DSPI_BITS_16;
1050 + *drv_data->qmr |= (*drv_data->qmr & ~QMR_BITS);
1054 +static int write(struct driver_data *drv_data)
1058 + int cmd_count = 0;
1062 +#if defined(SPI_DSPI)
1064 +#if defined(SPI_DSPI_EDMA)
1074 + tx_word = is_word_transfer(drv_data);
1076 + // If we are in word mode, but only have a single byte to transfer
1077 + // then switch to byte mode temporarily. Will switch back at the
1078 + // end of the transfer.
1079 + if (tx_word && ((drv_data->tx_end - drv_data->tx) == 1)) {
1080 + drv_data->flags |= TRAN_STATE_WORD_ODD_NUM;
1081 + set_8bit_transfer_mode(drv_data);
1086 +#if defined(SPI_DSPI)
1088 +#if defined(SPI_DSPI_EDMA)
1089 + edma_wr = (u32*)(drv_data->edma_tx_buf);
1093 +#if defined(SPI_DSPI_EDMA)
1094 + while ((drv_data->tx < drv_data->tx_end) && (tx_count < EDMA_BUFFER_SIZE)) {
1096 + while ((drv_data->tx < drv_data->tx_end) && (tx_count < DSPI_FIFO_SIZE)) {
1099 + if ((drv_data->tx_end - drv_data->tx) == 1)
1101 + if (!(drv_data->flags & TRAN_STATE_TX_VOID)) {
1102 + d16 = *(u16 *)drv_data->tx;
1104 + d16 = drv_data->void_write_data;
1107 + dspi_pushr = MCF_DSPI_DTFR_TXDATA(d16)
1108 + | DSPI_CS(drv_data->cs)
1109 + | MCF_DSPI_DTFR_CTAS(drv_data->dspi_ctas)
1110 + //| MCF_DSPI_DTFR_CONT
1113 + drv_data->tx += 2;
1115 +#if defined(SPI_DSPI_EDMA)
1116 + if (drv_data->tx == drv_data->tx_end || tx_count==EDMA_BUFFER_SIZE-1) {
1118 + if (drv_data->tx == drv_data->tx_end || tx_count==DSPI_FIFO_SIZE-1) {
1120 + // last transfer in queue
1121 + dspi_pushr |= MCF_DSPI_DTFR_EOQ;
1122 + if (drv_data->cs_change) {
1123 + dspi_pushr &= ~MCF_DSPI_DTFR_CONT;
1129 + dspi_pushr |= MCF_DSPI_DTFR_CTCNT; // clear counter
1131 +#if defined(SPI_DSPI_EDMA)
1132 + *edma_wr = dspi_pushr;
1135 + *drv_data->dspi_dtfr = dspi_pushr;
1136 + //MCF_DSPI_DTFR = dspi_pushr;
1141 + if (!(drv_data->flags & TRAN_STATE_TX_VOID)) {
1142 + d8 = *(u8 *)drv_data->tx;
1144 + d8 = *(u8 *)&drv_data->void_write_data;
1147 + dspi_pushr = MCF_DSPI_DTFR_TXDATA(d8)
1148 + | DSPI_CS(drv_data->cs)
1149 + /* | MCF_DSPI_DTFR_PCS5 | */
1150 + | MCF_DSPI_DTFR_CTAS(drv_data->dspi_ctas)
1151 + | MCF_DSPI_DTFR_CONT;
1155 + if (drv_data->tx == drv_data->tx_end || tx_count==DSPI_FIFO_SIZE-1) {
1156 + // last transfer in queue
1157 + dspi_pushr |= MCF_DSPI_DTFR_EOQ;
1158 + if (drv_data->cs_change) {
1159 + dspi_pushr &= ~MCF_DSPI_DTFR_CONT;
1165 + dspi_pushr |= MCF_DSPI_DTFR_CTCNT; // clear counter
1168 +#if defined(SPI_DSPI_EDMA)
1169 + *edma_wr = dspi_pushr;
1172 + *drv_data->dspi_dtfr = dspi_pushr;
1173 + //MCF_DSPI_DTFR = dspi_pushr;
1180 +#if defined(SPI_DSPI_EDMA)
1184 + // TODO: initiate eDMA transfer
1185 + set_edma_params(DSPI_DMA_TX_TCD,
1187 + virt_to_phys(drv_data->edma_tx_buf),
1189 + drv_data->edma_tx_buf,
1191 + (u32)drv_data->dspi_dtfr,
1192 + MCF_EDMA_TCD_ATTR_SSIZE_32BIT | MCF_EDMA_TCD_ATTR_DSIZE_32BIT,
1196 + tx_count, // citer
1197 + tx_count, // biter
1204 + set_edma_params(DSPI_DMA_RX_TCD,
1205 + (u32)drv_data->dspi_drfr,
1207 + virt_to_phys(drv_data->edma_rx_buf),
1209 + drv_data->edma_rx_buf,
1211 + MCF_EDMA_TCD_ATTR_SSIZE_32BIT | MCF_EDMA_TCD_ATTR_DSIZE_32BIT,
1215 + tx_count, // citer
1216 + tx_count, // biter
1224 + start_edma_transfer(DSPI_DMA_TX_TCD); // transmit SPI data
1225 + start_edma_transfer(DSPI_DMA_RX_TCD); // receive SPI data
1231 + *drv_data->qar = QSPI_TRANSMIT_RAM;
1232 + while ((drv_data->tx < drv_data->tx_end) && (tx_count < QSPI_RAM_SIZE)) {
1234 + if ((drv_data->tx_end - drv_data->tx) == 1)
1237 + if (!(drv_data->flags & TRAN_STATE_TX_VOID))
1238 + *drv_data->qdr = *(u16 *)drv_data->tx;
1240 + *drv_data->qdr = drv_data->void_write_data;
1241 + drv_data->tx += 2;
1243 + if (!(drv_data->flags & TRAN_STATE_TX_VOID))
1244 + *drv_data->qdr = *(u8 *)drv_data->tx;
1246 + *drv_data->qdr = *(u8 *)&drv_data->void_write_data;
1253 + *drv_data->qar = QSPI_COMMAND_RAM;
1254 + while (cmd_count < tx_count) {
1255 + u16 qcr = QSPI_COMMAND
1257 + | (~((0x01 << drv_data->cs) << 8) & 0x0F00);
1259 + if ( (cmd_count == tx_count - 1)
1260 + && (drv_data->tx == drv_data->tx_end)
1261 + && (drv_data->cs_change) ) {
1264 + *drv_data->qcr = qcr;
1268 + *drv_data->qwr = (*drv_data->qwr & ~QWR_ENDQP_MASK) | ((cmd_count - 1) << 8);
1271 + *drv_data->qdlyr |= QDLYR_SPE;
1278 +static int read(struct driver_data *drv_data)
1282 +#if defined(SPI_DSPI_EDMA)
1286 + rx_word = is_word_transfer(drv_data);
1288 +#if defined(SPI_DSPI)
1290 +#if defined(SPI_DSPI_EDMA)
1291 + rx_edma = (u32*) drv_data->edma_tx_buf;
1292 + while ((drv_data->rx < drv_data->rx_end) && (rx_count < EDMA_BUFFER_SIZE)) {
1294 + while ((drv_data->rx < drv_data->rx_end) && (rx_count < DSPI_FIFO_SIZE)) {
1297 + if ((drv_data->rx_end - drv_data->rx) == 1)
1299 +#if defined(SPI_DSPI_EDMA)
1300 + d = MCF_DSPI_DRFR_RXDATA(*rx_edma);
1303 + d = MCF_DSPI_DRFR_RXDATA(*drv_data->dspi_drfr);
1306 + if (!(drv_data->flags & TRAN_STATE_RX_VOID))
1307 + *(u16 *)drv_data->rx = d;
1308 + drv_data->rx += 2;
1310 +#if defined(SPI_DSPI_EDMA)
1311 + d = MCF_DSPI_DRFR_RXDATA(*rx_edma);
1314 + d = MCF_DSPI_DRFR_RXDATA(*drv_data->dspi_drfr);
1316 + if (!(drv_data->flags & TRAN_STATE_RX_VOID))
1317 + *(u8 *)drv_data->rx = d;
1326 + *drv_data->qar = QSPI_RECEIVE_RAM;
1327 + while ((drv_data->rx < drv_data->rx_end) && (rx_count < QSPI_RAM_SIZE)) {
1329 + if ((drv_data->rx_end - drv_data->rx) == 1)
1332 + if (!(drv_data->flags & TRAN_STATE_RX_VOID))
1333 + *(u16 *)drv_data->rx = *drv_data->qdr;
1334 + drv_data->rx += 2;
1336 + if (!(drv_data->flags & TRAN_STATE_RX_VOID))
1337 + *(u8 *)drv_data->rx = *drv_data->qdr;
1348 +static inline void qspi_setup_chip(struct driver_data *drv_data)
1350 + struct chip_data *chip = drv_data->cur_chip;
1352 +#if defined(SPI_DSPI)
1354 + *drv_data->mcr = chip->mcr_val;
1356 + // TODO: remove later
1357 + chip->ctar_val = 0x78560118;
1359 + *drv_data->ctar = chip->ctar_val;
1360 + *drv_data->dspi_rser = 0
1361 + | MCF_DSPI_DRSER_EOQFE
1362 +#if defined(SPI_DSPI_EDMA)
1363 + | MCF_DSPI_DRSER_TFFFE
1364 + | MCF_DSPI_DRSER_TFFFS
1370 + *drv_data->qmr = chip->qmr_val;
1371 + *drv_data->qdlyr = chip->qdlyr_val;
1372 + *drv_data->qwr = chip->qwr_val;
1375 + * Enable all the interrupts and clear all the flags
1377 + *drv_data->qir = (QIR_SPIFE | QIR_ABRTE | QIR_WCEFE)
1378 + | (QIR_WCEFB | QIR_ABRTB | QIR_ABRTL)
1379 + | (QIR_SPIF | QIR_ABRT | QIR_WCEF);
1383 +#if defined(SPI_DSPI_EDMA)
1384 +static int edma_tx_handler(int channel, void* dev)
1386 + if (channel == DSPI_DMA_TX_TCD) {
1387 + stop_edma_transfer(DSPI_DMA_TX_TCD);
1389 + return IRQ_HANDLED;
1392 +static int edma_rx_handler(int channel, void* dev)
1394 + if (channel == DSPI_DMA_RX_TCD) {
1395 + stop_edma_transfer(DSPI_DMA_RX_TCD);
1398 + return IRQ_HANDLED;
1402 +static irqreturn_t qspi_interrupt(int irq, void *dev_id)
1404 + struct driver_data *drv_data = (struct driver_data *)dev_id;
1405 + struct spi_message *msg = drv_data->cur_msg;
1406 +#if defined(SPI_DSPI)
1407 +#if !defined(SPI_DSPI_EDMA)
1408 + u32 irq_status = *drv_data->dspi_sr;
1411 + u16 irq_status = *drv_data->qir;
1414 + /* Clear all flags immediately */
1415 +#if defined(SPI_DSPI)
1416 + *drv_data->dspi_sr = MCF_DSPI_DSR_EOQF;
1418 + *drv_data->qir |= (QIR_SPIF | QIR_ABRT | QIR_WCEF);
1421 + if (!drv_data->cur_msg || !drv_data->cur_msg->state) {
1422 +#if !defined(SPI_DSPI_EDMA)
1423 + /* if eDMA is used it happens some time (at least once)*/
1424 + printk(KERN_ERR "coldfire-qspi: bad message or transfer "
1425 + "state in interrupt handler. IRQ status=%x\n", irq_status);
1430 +#if !defined(SPI_DSPI)
1431 + if (irq_status & QIR_SPIF) {
1434 + * Read the data into the buffer and reload and start
1435 + * queue with new data if not finished. If finished
1436 + * then setup the next transfer
1440 + if (drv_data->rx == drv_data->rx_end) {
1442 + * Finished now - fall through and schedule next
1443 + * transfer tasklet
1445 + if (drv_data->flags & TRAN_STATE_WORD_ODD_NUM) {
1446 + //*drv_data->qmr &= ~QMR_BITS;
1447 + set_16bit_transfer_mode(drv_data);
1450 + msg->state = next_transfer(drv_data);
1451 + msg->actual_length += drv_data->len;
1453 + /* not finished yet - keep going */
1455 + return IRQ_HANDLED;
1457 +#if !defined(SPI_DSPI)
1459 + if (irq_status & QIR_WCEF)
1460 + drv_data->wce_cnt++;
1462 + if (irq_status & QIR_ABRT)
1463 + drv_data->abrt_cnt++;
1465 + msg->state = ERROR_STATE;
1469 + tasklet_schedule(&drv_data->pump_transfers);
1471 + return IRQ_HANDLED;
1474 +/* caller already set message->status; dma and pio irqs are blocked */
1475 +static void giveback(struct driver_data *drv_data)
1477 + struct spi_transfer* last_transfer;
1478 + unsigned long flags;
1479 + struct spi_message *msg;
1481 + spin_lock_irqsave(&drv_data->lock, flags);
1482 + msg = drv_data->cur_msg;
1483 + drv_data->cur_msg = NULL;
1484 + drv_data->cur_transfer = NULL;
1485 + drv_data->cur_chip = NULL;
1486 + queue_work(drv_data->workqueue, &drv_data->pump_messages);
1487 + spin_unlock_irqrestore(&drv_data->lock, flags);
1489 + last_transfer = list_entry(msg->transfers.prev,
1490 + struct spi_transfer,
1493 + if (!last_transfer->cs_change)
1494 + drv_data->cs_control(drv_data->cs, QSPI_CS_DROP);
1496 + msg->state = NULL;
1497 + if (msg->complete)
1498 + msg->complete(msg->context);
1502 +static void pump_transfers(unsigned long data)
1504 + struct driver_data *drv_data = (struct driver_data *)data;
1505 + struct spi_message *message = NULL;
1506 + struct spi_transfer *transfer = NULL;
1507 + struct spi_transfer *previous = NULL;
1508 + struct chip_data *chip = NULL;
1509 + unsigned long flags;
1511 + /* Get current state information */
1512 + message = drv_data->cur_msg;
1513 + transfer = drv_data->cur_transfer;
1514 + chip = drv_data->cur_chip;
1516 + /* Handle for abort */
1517 + if (message->state == ERROR_STATE) {
1518 + message->status = -EIO;
1519 + giveback(drv_data);
1523 + /* Handle end of message */
1524 + if (message->state == DONE_STATE) {
1525 + message->status = 0;
1526 + giveback(drv_data);
1530 + if (message->state == START_STATE) {
1531 + qspi_setup_chip(drv_data);
1533 + if (drv_data->cs_control) {
1534 + //printk( "m s\n" );
1535 + drv_data->cs_control(message->spi->chip_select, QSPI_CS_ASSERT);
1539 + /* Delay if requested at end of transfer*/
1540 + if (message->state == RUNNING_STATE) {
1541 + previous = list_entry(transfer->transfer_list.prev,
1542 + struct spi_transfer,
1545 + if (drv_data->cs_control && transfer->cs_change)
1546 + drv_data->cs_control(message->spi->chip_select, QSPI_CS_DROP);
1548 + if (previous->delay_usecs)
1549 + udelay(previous->delay_usecs);
1551 + if (drv_data->cs_control && transfer->cs_change)
1552 + drv_data->cs_control(message->spi->chip_select, QSPI_CS_ASSERT);
1555 + drv_data->flags = 0;
1556 + drv_data->tx = (void *)transfer->tx_buf;
1557 + drv_data->tx_end = drv_data->tx + transfer->len;
1558 + drv_data->rx = transfer->rx_buf;
1559 + drv_data->rx_end = drv_data->rx + transfer->len;
1560 + drv_data->len = transfer->len;
1561 + if (!drv_data->rx)
1562 + drv_data->flags |= TRAN_STATE_RX_VOID;
1563 + if (!drv_data->tx)
1564 + drv_data->flags |= TRAN_STATE_TX_VOID;
1565 + drv_data->cs = message->spi->chip_select;
1566 + drv_data->cs_change = transfer->cs_change;
1567 + drv_data->void_write_data = chip->void_write_data;
1569 + message->state = RUNNING_STATE;
1572 + local_irq_save(flags);
1574 + local_irq_restore(flags);
1578 +static void pump_messages(struct work_struct * work)
1580 + struct driver_data *drv_data;
1581 + unsigned long flags;
1583 + drv_data = container_of(work, struct driver_data, pump_messages);
1585 + /* Lock queue and check for queue work */
1586 + spin_lock_irqsave(&drv_data->lock, flags);
1587 + if (list_empty(&drv_data->queue) || drv_data->run == QUEUE_STOPPED) {
1588 + drv_data->busy = 0;
1589 + spin_unlock_irqrestore(&drv_data->lock, flags);
1593 + /* Make sure we are not already running a message */
1594 + if (drv_data->cur_msg) {
1595 + spin_unlock_irqrestore(&drv_data->lock, flags);
1599 + /* Extract head of queue */
1600 + drv_data->cur_msg = list_entry(drv_data->queue.next,
1601 + struct spi_message, queue);
1602 + list_del_init(&drv_data->cur_msg->queue);
1604 + /* Initial message state*/
1605 + drv_data->cur_msg->state = START_STATE;
1606 + drv_data->cur_transfer = list_entry(drv_data->cur_msg->transfers.next,
1607 + struct spi_transfer,
1610 + /* Setup the SPI Registers using the per chip configuration */
1611 + drv_data->cur_chip = spi_get_ctldata(drv_data->cur_msg->spi);
1613 + /* Mark as busy and launch transfers */
1614 + tasklet_schedule(&drv_data->pump_transfers);
1616 + drv_data->busy = 1;
1617 + spin_unlock_irqrestore(&drv_data->lock, flags);
1620 +/****************************************************************************/
1623 + * SPI master implementation
1626 +static int transfer(struct spi_device *spi, struct spi_message *msg)
1628 + struct driver_data *drv_data = spi_master_get_devdata(spi->master);
1629 + unsigned long flags;
1631 + spin_lock_irqsave(&drv_data->lock, flags);
1633 + if (drv_data->run == QUEUE_STOPPED) {
1634 + spin_unlock_irqrestore(&drv_data->lock, flags);
1635 + return -ESHUTDOWN;
1638 + msg->actual_length = 0;
1639 + msg->status = -EINPROGRESS;
1640 + msg->state = START_STATE;
1642 + list_add_tail(&msg->queue, &drv_data->queue);
1644 + if (drv_data->run == QUEUE_RUNNING && !drv_data->busy)
1645 + queue_work(drv_data->workqueue, &drv_data->pump_messages);
1647 + spin_unlock_irqrestore(&drv_data->lock, flags);
1653 +static int setup(struct spi_device *spi)
1655 + struct coldfire_spi_chip *chip_info;
1656 + struct chip_data *chip;
1658 + u32 baud_divisor = 255;
1661 + chip_info = (struct coldfire_spi_chip *)spi->controller_data;
1663 + /* Only alloc on first setup */
1664 + chip = spi_get_ctldata(spi);
1665 + if (chip == NULL) {
1666 + chip = kcalloc(1, sizeof(struct chip_data), GFP_KERNEL);
1669 + spi->mode = chip_info->mode;
1670 + spi->bits_per_word = chip_info->bits_per_word;
1673 +#if defined(SPI_DSPI)
1674 + chip->mcr.master = 1;
1675 + chip->mcr.cont_scke = 0;
1676 + chip->mcr.dconf = 0;
1677 + chip->mcr.frz = 0;
1678 + chip->mcr.mtfe = 1;
1679 + chip->mcr.pcsse = 0;
1680 + chip->mcr.rooe = 0;
1681 + chip->mcr.pcsis = 0xFF;
1682 + chip->mcr.reserved15 = 0;
1683 + chip->mcr.mdis = 0;
1684 + chip->mcr.dis_tx = 0;
1685 + chip->mcr.dis_rxf = 0;
1686 + chip->mcr.clr_tx = 1;
1687 + chip->mcr.clr_rxf = 1;
1688 + chip->mcr.smpl_pt = 0;
1689 + chip->mcr.reserved71 = 0;
1690 + chip->mcr.halt = 0;
1692 + if ((spi->bits_per_word >= 4) && (spi->bits_per_word <= 16)) {
1693 + chip->ctar.fmsz = spi->bits_per_word-1;
1695 + printk(KERN_ERR "coldfire-qspi: invalid wordsize\n");
1700 + if (spi->mode & SPI_CPHA)
1701 + chip->ctar.cpha = 1;
1703 + chip->ctar.cpha = 0;
1705 + if (spi->mode & SPI_CPOL)
1706 + chip->ctar.cpol = 1;
1708 + chip->ctar.cpol = 0;
1710 + if (spi->mode & SPI_LSB_FIRST)
1711 + chip->ctar.lsbfe = 1;
1713 + chip->ctar.lsbfe = 0;
1715 + /* This values are default for audio device */
1716 + chip->ctar.dbr = 0;
1717 + chip->ctar.pbr = 2;
1718 + chip->ctar.br = 8;
1720 + /* This values are default for audio device */
1721 + chip->ctar.pcssck = 1;
1722 + chip->ctar.pasc = 1;
1723 + chip->ctar.pdt = 1;
1724 + chip->ctar.cssck = 0;
1725 + chip->ctar.asc = 1;
1726 + chip->ctar.dt = 1;
1728 + chip->void_write_data = chip_info->void_write_data;
1732 + chip->qwr.csiv = 1; // Chip selects are active low
1733 + chip->qmr.master = 1; // Must set to master mode
1734 + chip->qmr.dohie = 1; // Data output high impediance enabled
1735 + chip->void_write_data = chip_info->void_write_data;
1737 + chip->qdlyr.qcd = chip_info->del_cs_to_clk;
1738 + chip->qdlyr.dtl = chip_info->del_after_trans;
1740 + if (spi->max_speed_hz != 0)
1741 + baud_divisor = (MCF_CLK/(2*spi->max_speed_hz));
1743 + if (baud_divisor < 2)
1746 + if (baud_divisor > 255)
1747 + baud_divisor = 255;
1749 + chip->qmr.baud = baud_divisor;
1751 + //printk( "QSPI: spi->max_speed_hz %d\n", spi->max_speed_hz );
1752 + //printk( "QSPI: Baud set to %d\n", chip->qmr.baud );
1754 + if (spi->mode & SPI_CPHA)
1755 + chip->qmr.cpha = 1;
1757 + if (spi->mode & SPI_CPOL)
1758 + chip->qmr.cpol = 1;
1760 + if (spi->bits_per_word == 16) {
1761 + chip->qmr.bits = 0;
1762 + } else if ((spi->bits_per_word >= 8) && (spi->bits_per_word <= 15)) {
1763 + chip->qmr.bits = spi->bits_per_word;
1765 + printk(KERN_ERR "coldfire-qspi: invalid wordsize\n");
1772 + spi_set_ctldata(spi, chip);
1777 +static int init_queue(struct driver_data *drv_data)
1779 + INIT_LIST_HEAD(&drv_data->queue);
1780 + spin_lock_init(&drv_data->lock);
1782 + drv_data->run = QUEUE_STOPPED;
1783 + drv_data->busy = 0;
1785 + tasklet_init(&drv_data->pump_transfers,
1786 + pump_transfers, (unsigned long)drv_data);
1788 + INIT_WORK(&drv_data->pump_messages, pump_messages/*, drv_data*/);
1790 + drv_data->workqueue = create_singlethread_workqueue(
1791 + drv_data->master->cdev.dev->bus_id);
1792 + if (drv_data->workqueue == NULL)
1798 +static int start_queue(struct driver_data *drv_data)
1800 + unsigned long flags;
1802 + spin_lock_irqsave(&drv_data->lock, flags);
1804 + if (drv_data->run == QUEUE_RUNNING || drv_data->busy) {
1805 + spin_unlock_irqrestore(&drv_data->lock, flags);
1809 + drv_data->run = QUEUE_RUNNING;
1810 + drv_data->cur_msg = NULL;
1811 + drv_data->cur_transfer = NULL;
1812 + drv_data->cur_chip = NULL;
1813 + spin_unlock_irqrestore(&drv_data->lock, flags);
1815 + queue_work(drv_data->workqueue, &drv_data->pump_messages);
1820 +static int stop_queue(struct driver_data *drv_data)
1822 + unsigned long flags;
1823 + unsigned limit = 500;
1826 + spin_lock_irqsave(&drv_data->lock, flags);
1828 + /* This is a bit lame, but is optimized for the common execution path.
1829 + * A wait_queue on the drv_data->busy could be used, but then the common
1830 + * execution path (pump_messages) would be required to call wake_up or
1831 + * friends on every SPI message. Do this instead */
1832 + drv_data->run = QUEUE_STOPPED;
1833 + while (!list_empty(&drv_data->queue) && drv_data->busy && limit--) {
1834 + spin_unlock_irqrestore(&drv_data->lock, flags);
1836 + spin_lock_irqsave(&drv_data->lock, flags);
1839 + if (!list_empty(&drv_data->queue) || drv_data->busy)
1842 + spin_unlock_irqrestore(&drv_data->lock, flags);
1847 +static int destroy_queue(struct driver_data *drv_data)
1851 + status = stop_queue(drv_data);
1855 + destroy_workqueue(drv_data->workqueue);
1861 +static void cleanup(const struct spi_device *spi)
1863 + struct chip_data *chip = spi_get_ctldata((struct spi_device *)spi);
1865 + dev_dbg(&spi->dev, "spi_device %u.%u cleanup\n",
1866 + spi->master->bus_num, spi->chip_select);
1872 +/****************************************************************************/
1875 + * Generic Device driver routines and interface implementation
1878 +static int coldfire_spi_probe(struct platform_device *pdev)
1880 + struct device *dev = &pdev->dev;
1881 + struct coldfire_spi_master *platform_info;
1882 + struct spi_master *master;
1883 + struct driver_data *drv_data = 0;
1884 + struct resource *memory_resource;
1889 +#if defined(SPI_DSPI_EDMA)
1893 + platform_info = (struct coldfire_spi_master *)pdev->dev.platform_data;
1895 + master = spi_alloc_master(dev, sizeof(struct driver_data));
1899 + drv_data = class_get_devdata(&master->cdev);
1900 + drv_data->master = master;
1902 + INIT_LIST_HEAD(&drv_data->queue);
1903 + spin_lock_init(&drv_data->lock);
1905 + master->bus_num = platform_info->bus_num;
1906 + master->num_chipselect = platform_info->num_chipselect;
1907 + master->cleanup = cleanup;
1908 + master->setup = setup;
1909 + master->transfer = transfer;
1911 + drv_data->cs_control = platform_info->cs_control;
1912 + if (drv_data->cs_control)
1913 + for(i = 0; i < master->num_chipselect; i++)
1914 + drv_data->cs_control(i, QSPI_CS_INIT | QSPI_CS_DROP);
1916 + /* Setup register addresses */
1917 + memory_resource = platform_get_resource_byname(pdev, IORESOURCE_MEM, "qspi-module");
1918 + if (!memory_resource) {
1919 + dev_dbg(dev, "can not find platform module memory\n");
1920 + goto out_error_master_alloc;
1923 +#if defined(SPI_DSPI_EDMA)
1924 + drv_data->edma_tx_buf = kmalloc(EDMA_BUFSIZE_KMALLOC, GFP_DMA);
1925 + if (!drv_data->edma_tx_buf) {
1926 + dev_dbg(dev, "cannot allocate eDMA TX memory\n");
1927 + goto out_error_master_alloc;
1929 + drv_data->edma_rx_buf = kmalloc(EDMA_BUFSIZE_KMALLOC, GFP_DMA);
1930 + if (!drv_data->edma_rx_buf) {
1931 + kfree(drv_data->edma_tx_buf);
1932 + dev_dbg(dev, "cannot allocate eDMA RX memory\n");
1933 + goto out_error_master_alloc;
1937 +#if defined(SPI_DSPI)
1939 + drv_data->mcr = (void *)(memory_resource->start + 0x00000000);
1940 + drv_data->ctar = (void *)(memory_resource->start + 0x0000000C);
1941 + drv_data->dspi_sr = (void *)(memory_resource->start + 0x0000002C);
1942 + drv_data->dspi_rser = (void *)(memory_resource->start + 0x00000030);
1943 + drv_data->dspi_dtfr = (void *)(memory_resource->start + 0x00000034);
1944 + drv_data->dspi_drfr = (void *)(memory_resource->start + 0x00000038);
1948 + drv_data->qmr = (void *)(memory_resource->start + 0x00000000);
1949 + drv_data->qdlyr = (void *)(memory_resource->start + 0x00000004);
1950 + drv_data->qwr = (void *)(memory_resource->start + 0x00000008);
1951 + drv_data->qir = (void *)(memory_resource->start + 0x0000000c);
1952 + drv_data->qar = (void *)(memory_resource->start + 0x00000010);
1953 + drv_data->qdr = (void *)(memory_resource->start + 0x00000014);
1954 + drv_data->qcr = (void *)(memory_resource->start + 0x00000014);
1958 + /* Setup register addresses */
1959 + memory_resource = platform_get_resource_byname(pdev, IORESOURCE_MEM, "qspi-par");
1960 + if (!memory_resource) {
1961 + dev_dbg(dev, "can not find platform par memory\n");
1962 + goto out_error_master_alloc;
1965 + drv_data->par = (void *)memory_resource->start;
1967 + /* Setup register addresses */
1968 + memory_resource = platform_get_resource_byname(pdev, IORESOURCE_MEM, "qspi-int-level");
1969 + if (!memory_resource) {
1970 + dev_dbg(dev, "can not find platform par memory\n");
1971 + goto out_error_master_alloc;
1974 + drv_data->int_icr = (void *)memory_resource->start;
1976 + /* Setup register addresses */
1977 + memory_resource = platform_get_resource_byname(pdev, IORESOURCE_MEM, "qspi-int-mask");
1978 + if (!memory_resource) {
1979 + dev_dbg(dev, "can not find platform par memory\n");
1980 + goto out_error_master_alloc;
1983 + drv_data->int_mr = (void *)memory_resource->start;
1985 + irq = platform_info->irq_vector;
1987 + status = request_irq(platform_info->irq_vector, qspi_interrupt, SA_INTERRUPT, dev->bus_id, drv_data);
1989 + dev_err(&pdev->dev, "unable to attach ColdFire QSPI interrupt\n");
1990 + goto out_error_master_alloc;
1993 + /* Now that we have all the addresses etc. Let's set it up */
1995 + //*drv_data->par = platform_info->par_val;
1997 + MCF_GPIO_PAR_DSPI = 0
1998 + | MCF_GPIO_PAR_DSPI_PCS5_PCS5
1999 + | MCF_GPIO_PAR_DSPI_PCS2_PCS2
2000 + | MCF_GPIO_PAR_DSPI_PCS1_PCS1
2001 + | MCF_GPIO_PAR_DSPI_PCS0_PCS0
2002 + | MCF_GPIO_PAR_DSPI_SIN_SIN
2003 + | MCF_GPIO_PAR_DSPI_SOUT_SOUT
2004 + | MCF_GPIO_PAR_DSPI_SCK_SCK;
2006 + *drv_data->int_icr = platform_info->irq_lp;
2007 + *drv_data->int_mr &= ~platform_info->irq_mask;
2010 + drv_data->dspi_ctas = 0; // TODO: change later
2013 + /* Initial and start queue */
2014 + status = init_queue(drv_data);
2015 + if (status != 0) {
2016 + dev_err(&pdev->dev, "problem initializing queue\n");
2017 + goto out_error_irq_alloc;
2019 + status = start_queue(drv_data);
2020 + if (status != 0) {
2021 + dev_err(&pdev->dev, "problem starting queue\n");
2022 + goto out_error_irq_alloc;
2025 + /* Register with the SPI framework */
2026 + platform_set_drvdata(pdev, drv_data);
2027 + status = spi_register_master(master);
2028 + if (status != 0) {
2029 + dev_err(&pdev->dev, "problem registering spi master\n");
2031 + goto out_error_queue_alloc;
2034 +#if defined(SPI_DSPI_EDMA)
2035 + if (request_edma_channel(DSPI_DMA_TX_TCD,
2039 + NULL, /* spinlock */
2043 + dev_err(&pdev->dev, "problem requesting edma transmit channel\n");
2045 + goto out_error_queue_alloc;
2048 + if (request_edma_channel(DSPI_DMA_RX_TCD,
2052 + NULL, /* spinlock */
2056 + dev_err(&pdev->dev, "problem requesting edma receive channel\n");
2058 + goto out_edma_transmit;
2062 + printk( "SPI: Coldfire master initialized\n" );
2063 + //dev_info(&pdev->dev, "driver initialized\n");
2066 +#if defined(SPI_DSPI_EDMA)
2068 + free_edma_channel(DSPI_DMA_TX_TCD, pdev);
2071 +out_error_queue_alloc:
2072 + destroy_queue(drv_data);
2074 +out_error_irq_alloc:
2075 + free_irq(irq, drv_data);
2077 +out_error_master_alloc:
2078 + spi_master_put(master);
2083 +static int coldfire_spi_remove(struct platform_device *pdev)
2085 + struct driver_data *drv_data = platform_get_drvdata(pdev);
2092 +#if defined(SPI_DSPI_EDMA)
2093 + free_edma_channel(DSPI_DMA_TX_TCD, pdev);
2094 + free_edma_channel(DSPI_DMA_RX_TCD, pdev);
2097 + /* Remove the queue */
2098 + status = destroy_queue(drv_data);
2102 + /* Disable the SSP at the peripheral and SOC level */
2103 + /*write_SSCR0(0, drv_data->ioaddr);
2104 + pxa_set_cken(drv_data->master_info->clock_enable, 0);*/
2107 + /*if (drv_data->master_info->enable_dma) {
2108 + if (drv_data->ioaddr == SSP1_VIRT) {
2111 + } else if (drv_data->ioaddr == SSP2_VIRT) {
2114 + } else if (drv_data->ioaddr == SSP3_VIRT) {
2118 + pxa_free_dma(drv_data->tx_channel);
2119 + pxa_free_dma(drv_data->rx_channel);
2123 + irq = platform_get_irq(pdev, 0);
2125 + free_irq(irq, drv_data);
2127 + /* Disconnect from the SPI framework */
2128 + spi_unregister_master(drv_data->master);
2130 + /* Prevent double remove */
2131 + platform_set_drvdata(pdev, NULL);
2136 +static void coldfire_spi_shutdown(struct platform_device *pdev)
2140 + if ((status = coldfire_spi_remove(pdev)) != 0)
2141 + dev_err(&pdev->dev, "shutdown failed with %d\n", status);
2146 +static int suspend_devices(struct device *dev, void *pm_message)
2148 + pm_message_t *state = pm_message;
2150 + if (dev->power.power_state.event != state->event) {
2151 + dev_warn(dev, "pm state does not match request\n");
2158 +static int coldfire_spi_suspend(struct platform_device *pdev, pm_message_t state)
2160 + struct driver_data *drv_data = platform_get_drvdata(pdev);
2163 + /* Check all childern for current power state */
2164 + if (device_for_each_child(&pdev->dev, &state, suspend_devices) != 0) {
2165 + dev_warn(&pdev->dev, "suspend aborted\n");
2169 + status = stop_queue(drv_data);
2172 + /*write_SSCR0(0, drv_data->ioaddr);
2173 + pxa_set_cken(drv_data->master_info->clock_enable, 0);*/
2178 +static int coldfire_spi_resume(struct platform_device *pdev)
2180 + struct driver_data *drv_data = platform_get_drvdata(pdev);
2183 + /* Enable the SSP clock */
2184 + /*pxa_set_cken(drv_data->master_info->clock_enable, 1);*/
2186 + /* Start the queue running */
2187 + status = start_queue(drv_data);
2188 + if (status != 0) {
2189 + dev_err(&pdev->dev, "problem starting queue (%d)\n", status);
2196 +#define coldfire_spi_suspend NULL
2197 +#define coldfire_spi_resume NULL
2198 +#endif /* CONFIG_PM */
2200 +static struct platform_driver driver = {
2202 + .name = "spi_coldfire",
2203 + .bus = &platform_bus_type,
2204 + .owner = THIS_MODULE,
2206 + .probe = coldfire_spi_probe,
2207 + .remove = __devexit_p(coldfire_spi_remove),
2208 + .shutdown = coldfire_spi_shutdown,
2209 + .suspend = coldfire_spi_suspend,
2210 + .resume = coldfire_spi_resume,
2213 +static int __init coldfire_spi_init(void)
2215 + platform_driver_register(&driver);
2219 +module_init(coldfire_spi_init);
2221 +static void __exit coldfire_spi_exit(void)
2223 + platform_driver_unregister(&driver);
2225 +module_exit(coldfire_spi_exit);
2227 +++ b/drivers/spi/ssi_audio.c
2230 + * MCF5445x audio driver.
2232 + * Yaroslav Vinogradov yaroslav.vinogradov@freescale.com
2233 + * Copyright Freescale Semiconductor, Inc. 2006
2235 + * This program is free software; you can redistribute it and/or modify
2236 + * it under the terms of the GNU General Public License as published by
2237 + * the Free Software Foundation; either version 2 of the License, or
2238 + * (at your option) any later version.
2241 +#include <linux/device.h>
2242 +#include <linux/init.h>
2243 +#include <linux/delay.h>
2244 +#include <linux/spi/spi.h>
2245 +#include <linux/fs.h>
2246 +#include <linux/kernel.h>
2247 +#include <linux/major.h>
2248 +#include <asm/mcfsim.h>
2249 +#include <linux/interrupt.h>
2250 +#include <linux/soundcard.h>
2251 +#include <asm/uaccess.h>
2252 +#include <asm/virtconvert.h>
2254 +#include <asm/coldfire.h>
2255 +#include <asm/coldfire_edma.h>
2256 +#include <asm/mcf5445x_ssi.h>
2257 +#include <asm/mcf5445x_ccm.h>
2258 +#include <asm/mcf5445x_gpio.h>
2260 +#define SOUND_DEVICE_NAME "sound"
2261 +#define DRIVER_NAME "ssi_audio"
2264 +/* #define AUDIO_DEBUG */
2270 +#define MAX_SPEED_HZ 12000000
2272 +#define M5445x_AUDIO_IRQ_SOURCE 49
2273 +#define M5445x_AUDIO_IRQ_VECTOR (128+M5445x_AUDIO_IRQ_SOURCE)
2274 +#define M5445x_AUDIO_IRQ_LEVEL 5
2276 +/* TLV320DAC23 audio chip registers */
2278 +#define CODEC_LEFT_IN_REG (0x00)
2279 +#define CODEC_RIGHT_IN_REG (0x01)
2280 +#define CODEC_LEFT_HP_VOL_REG (0x02)
2281 +#define CODEC_RIGHT_HP_VOL_REG (0x03)
2282 +#define CODEC_ANALOG_APATH_REG (0x04)
2283 +#define CODEC_DIGITAL_APATH_REG (0x05)
2284 +#define CODEC_POWER_DOWN_REG (0x06)
2285 +#define CODEC_DIGITAL_IF_FMT_REG (0x07)
2286 +#define CODEC_SAMPLE_RATE_REG (0x08)
2287 +#define CODEC_DIGITAL_IF_ACT_REG (0x09)
2288 +#define CODEC_RESET_REG (0x0f)
2290 +#define CODEC_SAMPLE_8KHZ (0x0C)
2291 +#define CODEC_SAMPLE_16KHZ (0x58)
2292 +#define CODEC_SAMPLE_22KHZ (0x62)
2293 +#define CODEC_SAMPLE_32KHZ (0x18)
2294 +#define CODEC_SAMPLE_44KHZ (0x22)
2295 +#define CODEC_SAMPLE_48KHZ (0x00)
2297 +/* Audio buffer data size */
2298 +#define BUFSIZE (64*1024)
2299 +/* DMA transfer size */
2300 +#define DMASIZE (16*1024)
2302 +/* transmit eDMA channel for SSI channel 0 */
2304 +/* transmit eDMA channel for SSI channel 1 */
2305 +#define DMA_TCD2 11
2308 + struct spi_device *spi;
2321 +static struct ssi_audio* audio_device = NULL;
2322 +volatile u32 audio_start;
2323 +volatile u32 audio_count;
2324 +volatile u32 audio_append;
2325 +volatile u32 audio_appstart;
2326 +volatile u32 audio_txbusy;
2328 +struct ssi_audio_format {
2329 + unsigned int format;
2330 + unsigned int bits;
2331 +} ssi_audio_formattable[] = {
2332 + { AFMT_MU_LAW, 8 },
2333 + { AFMT_A_LAW, 8 },
2334 + { AFMT_IMA_ADPCM, 8 },
2336 + { AFMT_S16_LE, 16 },
2337 + { AFMT_S16_BE, 16 },
2339 + { AFMT_U16_LE, 16 },
2340 + { AFMT_U16_BE, 16 },
2343 +#define FORMATSIZE (sizeof(ssi_audio_formattable) / sizeof(struct ssi_audio_format))
2345 +static void ssi_audio_setsamplesize(int val)
2349 + if (audio_device == NULL) return;
2351 + for (i = 0; (i < FORMATSIZE); i++) {
2352 + if (ssi_audio_formattable[i].format == val) {
2353 + audio_device->format = ssi_audio_formattable[i].format;
2354 + audio_device->bits = ssi_audio_formattable[i].bits;
2360 + printk(DRIVER_NAME ":ssi_audio_setsamplesize %d %d\n", audio_device->format, audio_device->bits);
2364 +static void ssi_audio_txdrain(void)
2367 + printk(DRIVER_NAME ":ssi_audio_txdrain()\n");
2370 + if (audio_device == NULL) return;
2372 + while (!signal_pending(current)) {
2373 + if (audio_txbusy == 0)
2375 + current->state = TASK_INTERRUPTIBLE;
2376 + schedule_timeout(1);
2380 +#ifdef CONFIG_SSIAUDIO_USE_EDMA
2382 + * Configure and start DMA engine.
2384 +void __inline__ ssi_audio_dmarun(void)
2386 + set_edma_params(DMA_TCD,
2388 + virt_to_phys(&(audio_device->audio_buf[audio_start])),
2390 + (u32)&(audio_device->audio_buf[audio_start]),
2392 + (u32)&MCF_SSI_TX0,
2393 + MCF_EDMA_TCD_ATTR_SSIZE_32BIT | MCF_EDMA_TCD_ATTR_DSIZE_32BIT,
2405 + set_edma_params(DMA_TCD2,
2407 + virt_to_phys(&(audio_device->audio_buf[audio_start+4])),
2409 + (u32)&(audio_device->audio_buf[audio_start+4]),
2411 + (u32)&MCF_SSI_TX1,
2412 + MCF_EDMA_TCD_ATTR_SSIZE_32BIT | MCF_EDMA_TCD_ATTR_DSIZE_32BIT,
2424 + audio_device->dmaing = 1;
2427 + start_edma_transfer(DMA_TCD);
2428 + start_edma_transfer(DMA_TCD2);
2430 + MCF_EDMA_ERQ |= (1<<DMA_TCD) | (1<<DMA_TCD2);
2431 + MCF_EDMA_SSRT = DMA_TCD;
2432 + MCF_EDMA_SSRT = DMA_TCD2;
2438 + * Start DMA'ing a new buffer of data if any available.
2440 +static void ssi_audio_dmabuf(void)
2443 + printk(DRIVER_NAME ":ssi_audio_dmabuf(): append=%x start=%x\n", audio_append, audio_appstart);
2446 + /* If already running then nothing to do... */
2447 + if (audio_device->dmaing)
2450 + /* Set DMA buffer size */
2451 + audio_count = (audio_append >= audio_appstart) ?
2452 + (audio_append - audio_appstart) :
2453 + (BUFSIZE - audio_appstart);
2454 + if (audio_count > DMASIZE)
2455 + audio_count = DMASIZE;
2457 + /* Adjust pointers and counters accordingly */
2458 + audio_appstart += audio_count;
2459 + if (audio_appstart >= BUFSIZE)
2460 + audio_appstart = 0;
2462 + if (audio_count > 0)
2463 + ssi_audio_dmarun();
2467 + printk(DRIVER_NAME ":DMA buffer is empty!\n");
2472 +void __inline__ stop_dma(void) {
2473 + stop_edma_transfer(DMA_TCD);
2474 + stop_edma_transfer(DMA_TCD2);
2477 +static int ssi_audio_dma_handler_empty(int channel, void *dev_id)
2479 + return IRQ_HANDLED;
2482 +static int ssi_audio_dma_handler(int channel, void *dev_id)
2485 + printk(DRIVER_NAME ":ssi_audio_dma_handler(channel=%d)\n", channel);
2488 + /* Clear DMA interrupt */
2491 + audio_device->dmaing = 0;
2493 + /* Update data pointers and counts */
2494 + audio_start += audio_count;
2495 + if (audio_start >= BUFSIZE)
2499 + /* Start new DMA buffer if we can */
2500 + ssi_audio_dmabuf();
2502 + return IRQ_HANDLED;
2505 +static void init_dma(void)
2507 + /* SSI DMA Signals mapped to DMA request */
2508 + MCF_CCM_MISCCR &= ~MCF_CCM_MISCCR_TIMDMA;
2512 +#endif /* CONFIG_SSIAUDIO_USE_EDMA */
2515 +/* Write CODEC register using SPI
2516 + * address - CODEC register address
2517 + * data - data to be written into register
2519 +static int codec_write(u8 addr, u16 data)
2523 + if (audio_device==NULL || audio_device->spi==NULL)
2526 + spi_word = ((addr & 0x7F)<<9)|(data & 0x1FF);
2527 + return spi_write(audio_device->spi, (const u8*)&spi_word, sizeof(spi_word));
2530 +static inline void enable_ssi(void)
2532 + if (audio_device==NULL || audio_device->ssi_enabled) return;
2533 + audio_device->ssi_enabled = 1;
2534 + MCF_SSI_CR |= MCF_SSI_CR_SSI_EN; /* enable SSI module */
2535 + MCF_SSI_CR |= MCF_SSI_CR_TE; /* enable tranmitter */
2538 +static inline void disable_ssi(void)
2540 + if (audio_device==NULL || audio_device->ssi_enabled==0) return;
2541 + MCF_SSI_CR &= ~MCF_SSI_CR_TE; /* disable transmitter */
2542 + MCF_SSI_CR &= ~MCF_SSI_CR_SSI_EN; /* disable SSI module */
2543 + audio_device->ssi_enabled = 0;
2546 +/* Audio CODEC initialization */
2547 +/* TODO: also the SSI frequency/dividers must be adjusted */
2548 +static void adjust_codec_speed(void) {
2550 + printk(DRIVER_NAME ":adjust_codec_speed: %d\n", audio_device->speed);
2553 + if (audio_device->speed == 8000) {
2554 + codec_write(CODEC_SAMPLE_RATE_REG,CODEC_SAMPLE_8KHZ);
2555 + } else if (audio_device->speed == 16000) {
2556 + codec_write(CODEC_SAMPLE_RATE_REG,CODEC_SAMPLE_16KHZ);
2557 + } else if (audio_device->speed == 22000) {
2558 + codec_write(CODEC_SAMPLE_RATE_REG,CODEC_SAMPLE_22KHZ);
2559 + } else if (audio_device->speed == 44000 || audio_device->speed == 44100) {
2560 + codec_write(CODEC_SAMPLE_RATE_REG,CODEC_SAMPLE_44KHZ);
2561 + } else if (audio_device->speed == 48000) {
2562 + codec_write(CODEC_SAMPLE_RATE_REG,CODEC_SAMPLE_48KHZ);
2564 + /* default 44KHz */
2565 + codec_write(CODEC_SAMPLE_RATE_REG,CODEC_SAMPLE_44KHZ);
2569 +static void codec_reset(void)
2571 + codec_write(CODEC_RESET_REG, 0); /* reset the audio chip */
2572 + udelay(1500); /* wait for reset */
2575 +static void init_audio_codec(void)
2578 + printk(DRIVER_NAME ":init_audio_codec()\n");
2582 + codec_write(CODEC_LEFT_IN_REG, 0x017);
2583 + codec_write(CODEC_RIGHT_IN_REG, 0x017);
2584 + codec_write(CODEC_POWER_DOWN_REG, 0x000); /* Turn off line input */
2585 + codec_write(CODEC_DIGITAL_IF_FMT_REG, 0x00A); /* I2S slave mode */
2586 + /* codec_write(CODEC_DIGITAL_IF_FMT_REG, 0x042); // I2S master mode */
2587 + codec_write(CODEC_DIGITAL_APATH_REG, 0x007); /* Set A path */
2589 + /* set sample rate */
2590 + adjust_codec_speed();
2592 + codec_write(CODEC_LEFT_HP_VOL_REG, 0x075); /* set volume */
2593 + codec_write(CODEC_RIGHT_HP_VOL_REG, 0x075); /* set volume */
2594 + codec_write(CODEC_DIGITAL_IF_ACT_REG, 1); /* Activate digital interface */
2595 + codec_write(CODEC_ANALOG_APATH_REG, 0x0F2);
2599 +static void chip_init(void)
2601 +#ifdef CONFIG_SSIAUDIO_USE_EDMA
2605 + /* Enable the SSI pins */
2606 + MCF_GPIO_PAR_SSI = ( 0
2607 + | MCF_GPIO_PAR_SSI_MCLK
2608 + | MCF_GPIO_PAR_SSI_STXD(3)
2609 + | MCF_GPIO_PAR_SSI_SRXD(3)
2610 + | MCF_GPIO_PAR_SSI_FS(3)
2611 + | MCF_GPIO_PAR_SSI_BCLK(3) );
2615 +static void init_ssi(void)
2618 + printk(DRIVER_NAME ":init_ssi()\n");
2621 + /* Dividers are for MCF54445 on 266Mhz, the output is 44.1Khz*/
2622 + /* Enable SSI clock in CCM */
2623 + MCF_CCM_CDR = MCF_CCM_CDR_SSIDIV(47);
2625 + /* Issue a SSI reset */
2626 + MCF_SSI_CR &= ~MCF_SSI_CR_SSI_EN; /* disable SSI module */
2628 + /* SSI module uses internal CPU clock */
2629 + MCF_CCM_MISCCR |= MCF_CCM_MISCCR_SSISRC;
2631 + MCF_CCM_MISCCR |= MCF_CCM_MISCCR_SSIPUE;
2632 + MCF_CCM_MISCCR |= MCF_CCM_MISCCR_SSIPUS_UP;
2636 + | MCF_SSI_CR_TCH /* Enable two channel mode */
2637 + | MCF_SSI_CR_MCE /* Set clock out on SSI_MCLK pin */
2638 + | MCF_SSI_CR_I2S_MASTER /* Set I2S master mode */
2639 + | MCF_SSI_CR_SYN /* Enable synchronous mode */
2644 + | MCF_SSI_TCR_TXDIR /* internally generated bit clock */
2645 + | MCF_SSI_TCR_TFDIR /* internally generated frame sync */
2646 + | MCF_SSI_TCR_TSCKP /* Clock data on falling edge of bit clock */
2647 + | MCF_SSI_TCR_TFSI /* Frame sync active low */
2648 + | MCF_SSI_TCR_TEFS /* TX frame sync 1 bit before data */
2649 + | MCF_SSI_TCR_TFEN0 /* TX FIFO 0 enabled */
2650 + | MCF_SSI_TCR_TFEN1 /* TX FIFO 1 enabled */
2651 + | MCF_SSI_TCR_TXBIT0
2654 + MCF_SSI_CCR = MCF_SSI_CCR_WL(7) /* 16 bit word length */
2655 + | MCF_SSI_CCR_DC(1) /* Frame rate divider */
2656 + | MCF_SSI_CCR_PM(0)
2657 + | MCF_SSI_CCR_DIV2
2661 + | MCF_SSI_FCSR_TFWM0(0)
2662 + | MCF_SSI_FCSR_TFWM1(0)
2665 + MCF_SSI_IER = 0 // interrupts
2666 +#ifndef CONFIG_SSIAUDIO_USE_EDMA
2667 + | MCF_SSI_IER_TIE /* transmit interrupts */
2668 + | MCF_SSI_IER_TFE0 /* transmit FIFO 0 empty */
2669 + | MCF_SSI_IER_TFE1 /* transmit FIFO 1 empty */
2671 + | MCF_SSI_IER_TDMAE /* DMA request enabled */
2672 + | MCF_SSI_IER_TFE0 /* transmit FIFO 0 empty */
2673 + | MCF_SSI_IER_TFE1 /* transmit FIFO 1 empty */
2677 +#ifndef CONFIG_SSIAUDIO_USE_EDMA
2678 + /* enable IRQ: SSI interrupt */
2679 + MCF_INTC1_ICR(M5445x_AUDIO_IRQ_SOURCE) = M5445x_AUDIO_IRQ_LEVEL;
2680 + MCF_INTC1_CIMR = M5445x_AUDIO_IRQ_SOURCE;
2684 +#ifndef CONFIG_SSIAUDIO_USE_EDMA
2685 +/* interrupt for SSI */
2686 +static int ssi_audio_isr(int irq, void *dev_id)
2688 + unsigned long *bp;
2690 + if (audio_txbusy==0) {
2691 + return IRQ_HANDLED;
2694 + spin_lock(&(audio_device->lock));
2696 + if (audio_start == audio_append) {
2700 + if (MCF_SSI_ISR & (MCF_SSI_ISR_TFE0|MCF_SSI_ISR_TFE1)) {
2701 + bp = (unsigned long *) &audio_device->audio_buf[audio_start];
2702 + if (audio_device->channel) {
2703 + MCF_SSI_TX1 = *bp;
2704 + audio_device->channel = 0;
2706 + MCF_SSI_TX0 = *bp;
2707 + audio_device->channel = 1;
2710 + if (audio_start >= BUFSIZE)
2715 + spin_unlock(&(audio_device->lock));
2717 + return IRQ_HANDLED;
2721 +/* Set initial driver playback defaults. */
2722 +static void init_driver_variables(void)
2724 + audio_device->speed = 44100;
2725 + audio_device->format = AFMT_S16_LE;
2726 + audio_device->bits = 16;
2727 + audio_device->stereo = 1;
2728 + audio_device->ssi_enabled = 0;
2733 + audio_appstart = 0;
2735 + audio_device->dmaing = 0;
2738 +/* open audio device */
2739 +static int ssi_audio_open(struct inode *inode, struct file *filp)
2742 + printk(DRIVER_NAME ":ssi_audio_open()\n");
2745 + if (audio_device==NULL) return (-ENODEV);
2747 + if (audio_device->isopen)
2750 + spin_lock(&(audio_device->lock));
2752 + audio_device->isopen = 1;
2754 + init_driver_variables();
2756 + init_audio_codec();
2758 + spin_unlock(&(audio_device->lock));
2765 +/* close audio device */
2766 +static int ssi_audio_close(struct inode *inode, struct file *filp)
2769 + printk(DRIVER_NAME ":ssi_audio_close()\n");
2772 + if (audio_device==NULL) return (-ENODEV);
2774 + ssi_audio_txdrain();
2776 + spin_lock(&(audio_device->lock));
2778 +#ifdef CONFIG_SSIAUDIO_USE_EDMA
2783 + init_driver_variables();
2784 + audio_device->isopen = 0;
2786 + spin_unlock(&(audio_device->lock));
2790 +/* write to audio device */
2791 +static ssize_t ssi_audio_write(struct file *filp, const char *buf, size_t count, loff_t *ppos)
2793 + unsigned long *dp, *buflp;
2794 + unsigned short *bufwp;
2795 + unsigned char *bufbp;
2796 + unsigned int slen, bufcnt, i, s, e;
2799 + printk(DRIVER_NAME ":ssi_audio_write(buf=%x,count=%d)\n", (int) buf, count);
2802 + if (audio_device==NULL) return (-ENODEV);
2807 + spin_lock(&(audio_device->lock));
2809 + buflp = (unsigned long *) buf;
2810 + bufwp = (unsigned short *) buf;
2811 + bufbp = (unsigned char *) buf;
2813 + bufcnt = count & ~0x3;
2816 + if (audio_device->stereo == 0)
2818 + if (audio_device->bits == 8)
2823 + * Get a snapshot of buffer, so we can figure out how
2824 + * much data we can fit in...
2828 + dp = (unsigned long *) &(audio_device->audio_buf[e]);
2830 + slen = ((s > e) ? (s - e) : (BUFSIZE - (e - s))) - 4;
2831 + if (slen > bufcnt)
2833 + if ((BUFSIZE - e) < slen)
2834 + slen = BUFSIZE - e;
2837 + if (signal_pending(current))
2838 + return(-ERESTARTSYS);
2839 + set_current_state(TASK_INTERRUPTIBLE);
2840 + schedule_timeout(1);
2844 + /* For DMA we need to have data as 32 bit
2845 + values (since SSI TX register is 32 bit).
2846 + So, the incomming 16 bit data must be put to buffer as 32 bit values.
2847 + Also, the endianess is converted if needed
2849 + if (audio_device->stereo) {
2850 + if (audio_device->bits == 16) {
2851 + if (audio_device->format==AFMT_S16_LE) {
2852 + /*- convert endianess, probably could be done by SSI also */
2853 + for (i = 0; (i < slen); i += 4) {
2854 + unsigned short val = le16_to_cpu((*bufwp++));
2858 + for (i = 0; (i < slen); i += 4) {
2863 + for (i = 0; (i < slen); i += 4) {
2864 + *dp = (((unsigned long) *bufbp++) << 24);
2865 + *dp++ |= (((unsigned long) *bufbp++) << 8);
2869 + if (audio_device->bits == 16) {
2870 + for (i = 0; (i < slen); i += 4) {
2871 + *dp++ = (((unsigned long)*bufwp)<<16) | *bufwp;
2875 + for (i = 0; (i < slen); i += 4) {
2876 + *dp++ = (((unsigned long) *bufbp) << 24) |
2877 + (((unsigned long) *bufbp) << 8);
2888 + /* If not outputing audio, then start now */
2889 + if (audio_txbusy == 0) {
2891 + audio_device->channel = 0;
2893 +#ifdef CONFIG_SSIAUDIO_USE_EDMA
2894 + ssi_audio_dmabuf(); /* start first DMA transfer */
2903 + spin_unlock(&(audio_device->lock));
2908 +/* ioctl: control the driver */
2909 +static int ssi_audio_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg)
2915 + printk(DRIVER_NAME ":ssi_audio_ioctl(cmd=%x,arg=%x)\n", (int) cmd, (int) arg);
2918 + if (audio_device==NULL) return (-ENODEV);
2922 + case SNDCTL_DSP_SPEED:
2923 + if (access_ok(VERIFY_READ, (void *) arg, sizeof(val))) {
2924 + get_user(val, (unsigned long *) arg);
2926 + printk(DRIVER_NAME ":ssi_audio_ioctl: SNDCTL_DSP_SPEED: %ld\n", val);
2928 + ssi_audio_txdrain();
2929 + audio_device->speed = val;
2930 + init_audio_codec();
2936 + case SNDCTL_DSP_SAMPLESIZE:
2937 + if (access_ok(VERIFY_READ, (void *) arg, sizeof(val))) {
2938 + get_user(val, (unsigned long *) arg);
2939 + ssi_audio_txdrain();
2940 + ssi_audio_setsamplesize(val);
2946 + case SNDCTL_DSP_STEREO:
2947 + if (access_ok(VERIFY_READ, (void *) arg, sizeof(val))) {
2948 + get_user(val, (unsigned long *) arg);
2949 + ssi_audio_txdrain();
2950 + audio_device->stereo = val;
2956 + case SNDCTL_DSP_GETBLKSIZE:
2957 + if (access_ok(VERIFY_WRITE, (void *) arg, sizeof(long)))
2958 + put_user(BUFSIZE, (long *) arg);
2963 + case SNDCTL_DSP_SYNC:
2964 + ssi_audio_txdrain();
2975 +/****************************************************************************/
2977 +struct file_operations ssi_audio_fops = {
2978 + open: ssi_audio_open, /* open */
2979 + release: ssi_audio_close, /* close */
2980 + write: ssi_audio_write, /* write */
2981 + ioctl: ssi_audio_ioctl, /* ioctl */
2984 +/* initialize audio driver */
2985 +static int __devinit ssi_audio_probe(struct spi_device *spi)
2987 + struct ssi_audio *audio;
2991 + printk(DRIVER_NAME": probe\n");
2995 + dev_dbg(&spi->dev, "no IRQ?\n");
2999 + /* don't exceed max specified sample rate */
3000 + if (spi->max_speed_hz > MAX_SPEED_HZ) {
3001 + dev_dbg(&spi->dev, "f(sample) %d KHz?\n",
3002 + (spi->max_speed_hz)/1000);
3006 + /* register charcter device */
3007 + if (register_chrdev(SOUND_MAJOR, SOUND_DEVICE_NAME, &ssi_audio_fops) < 0) {
3008 + printk(KERN_WARNING DRIVER_NAME ": failed to register major %d\n", SOUND_MAJOR);
3009 + dev_dbg(&spi->dev, DRIVER_NAME ": failed to register major %d\n", SOUND_MAJOR);
3013 + audio = kzalloc(sizeof(struct ssi_audio), GFP_KERNEL);
3019 + /* DMA buffer must be from GFP_DMA zone, so it will not be cached */
3020 + audio->audio_buf = kmalloc(BUFSIZE, GFP_DMA);
3021 + if (audio->audio_buf == NULL) {
3022 + dev_dbg(&spi->dev, DRIVER_NAME ": failed to allocate DMA[%d] buffer\n", BUFSIZE);
3024 + goto err_free_mem;
3027 + audio_device = audio;
3029 + dev_set_drvdata(&spi->dev, audio);
3030 + spi->dev.power.power_state = PMSG_ON;
3034 +#ifndef CONFIG_SSIAUDIO_USE_EDMA
3035 + if (request_irq(spi->irq, ssi_audio_isr, SA_INTERRUPT, spi->dev.bus_id, audio)) {
3036 + dev_dbg(&spi->dev, "irq %d busy?\n", spi->irq);
3038 + goto err_free_mem;
3042 + /* request 2 eDMA channels since two channel output mode is used */
3043 + if (request_edma_channel(DMA_TCD,
3044 + ssi_audio_dma_handler_empty,
3047 + &(audio_device->lock),
3051 + dev_dbg(&spi->dev, "DMA channel %d busy?\n", DMA_TCD);
3053 + goto err_free_mem;
3055 + if (request_edma_channel(DMA_TCD2,
3056 + ssi_audio_dma_handler,
3059 + &(audio_device->lock),
3063 + dev_dbg(&spi->dev, "DMA channel %d busy?\n", DMA_TCD2);
3065 + goto err_free_mem;
3070 + printk(DRIVER_NAME ": Probed successfully\n");
3076 + audio_device = NULL;
3078 + unregister_chrdev(SOUND_MAJOR, SOUND_DEVICE_NAME);
3082 +static int __devexit ssi_audio_remove(struct spi_device *spi)
3084 + struct ssi_audio *audio = dev_get_drvdata(&spi->dev);
3086 + ssi_audio_txdrain();
3087 +#ifndef CONFIG_SSIAUDIO_USE_EDMA
3088 + free_irq(spi->irq, audio);
3090 + free_edma_channel(DMA_TCD, audio);
3091 + free_edma_channel(DMA_TCD2, audio);
3093 + kfree(audio->audio_buf);
3095 + audio_device = NULL;
3096 + unregister_chrdev(SOUND_MAJOR, SOUND_DEVICE_NAME);
3097 + dev_dbg(&spi->dev, "unregistered audio\n");
3101 +static int ssi_audio_suspend(struct spi_device *spi, pm_message_t message) {
3105 +static int ssi_audio_resume(struct spi_device *spi) {
3109 +static struct spi_driver ssi_audio_driver = {
3111 + .name = DRIVER_NAME,
3112 + .bus = &spi_bus_type,
3113 + .owner = THIS_MODULE,
3115 + .probe = ssi_audio_probe,
3116 + .remove = __devexit_p(ssi_audio_remove),
3117 + .suspend = ssi_audio_suspend,
3118 + .resume = ssi_audio_resume,
3121 +static int __init ssi_audio_init(void)
3123 + return spi_register_driver(&ssi_audio_driver);
3125 +module_init(ssi_audio_init);
3127 +static void __exit ssi_audio_exit(void)
3129 + spi_unregister_driver(&ssi_audio_driver);
3131 +module_exit(ssi_audio_exit);
3133 +MODULE_DESCRIPTION("SSI/I2S Audio Driver");
3134 +MODULE_LICENSE("GPL");
3135 --- a/include/asm-m68k/coldfire_edma.h
3136 +++ b/include/asm-m68k/coldfire_edma.h
3139 + * coldfire_edma.h - eDMA driver for Coldfire MCF5445x
3141 + * Yaroslav Vinogradov yaroslav.vinogradov@freescale.com
3143 + * Copyright Freescale Semiconductor, Inc. 2007
3145 + * This program is free software; you can redistribute it and/or modify it
3146 + * under the terms of the GNU General Public License as published by the
3147 + * Free Software Foundation; either version 2 of the License, or (at your
3148 + * option) any later version.
3151 #ifndef _LINUX_COLDFIRE_DMA_H
3152 #define _LINUX_COLDFIRE_DMA_H
3154 #include <linux/interrupt.h>
3155 +#include <asm/mcf5445x_edma.h>
3157 -#define EDMA_DRIVER_NAME "ColdFire-eDMA"
3158 -#define DMA_DEV_MINOR 1
3159 +#define EDMA_DRIVER_NAME "ColdFire-eDMA"
3160 +#define DMA_DEV_MINOR 1
3162 #define EDMA_INT_CHANNEL_BASE 8
3163 #define EDMA_INT_CONTROLLER_BASE 64
3164 #define EDMA_CHANNELS 16
3167 #define EDMA_IRQ_LEVEL 5
3170 typedef irqreturn_t (*edma_irq_handler)(int, void *);
3171 typedef void (*edma_error_handler)(int, void *);
3174 +/* Setup transfer control descriptor (TCD)
3175 + * channel - descriptor number
3176 + * source - source address
3177 + * dest - destination address
3178 + * attr - attributes
3179 + * soff - source offset
3180 + * nbytes - number of bytes to be transfered in minor loop
3181 + * slast - last source address adjustment
3182 + * citer - major loop count
3183 + * biter - beggining minor loop count
3184 + * doff - destination offset
3185 + * dlast_sga - last destination address adjustment
3186 + * major_int - generate interrupt after each major loop
3187 + * disable_req - disable DMA request after major loop
3189 void set_edma_params(int channel, u32 source, u32 dest,
3190 - u32 attr, u32 soff, u32 nbytes, u32 slast,
3191 - u32 citer, u32 biter, u32 doff, u32 dlast_sga);
3193 -void start_edma_transfer(int channel, int major_int);
3195 -void stop_edma_transfer(int channel);
3197 -void confirm_edma_interrupt_handled(int channel);
3199 + u32 attr, u32 soff, u32 nbytes, u32 slast,
3200 + u32 citer, u32 biter, u32 doff, u32 dlast_sga,
3201 + int major_int, int disable_req);
3203 +/* Starts eDMA transfer on specified channel
3204 + * channel - eDMA TCD number
3206 +static inline void start_edma_transfer(int channel)
3208 + MCF_EDMA_SERQ = channel;
3209 + MCF_EDMA_SSRT = channel;
3212 +/* Stops eDMA transfer
3213 + * channel - eDMA TCD number
3215 +static inline void stop_edma_transfer(int channel)
3217 + MCF_EDMA_CINT = channel;
3218 + MCF_EDMA_CERQ = channel;
3222 +/* Confirm that interrupt has been handled
3223 + * channel - eDMA TCD number
3225 +static inline void confirm_edma_interrupt_handled(int channel)
3227 + MCF_EDMA_CINT = channel;
3230 +/* Initialize eDMA controller */
3231 void init_edma(void);
3233 -int request_edma_channel(int channel,
3234 - edma_irq_handler handler,
3235 - edma_error_handler error_handler,
3238 - const char *device_id);
3241 +/* Request eDMA channel:
3242 + * channel - eDMA TCD number
3243 + * handler - channel IRQ callback
3244 + * error_handler - error interrupt handler callback for channel
3246 + * lock - spinlock to be locked (can be NULL)
3247 + * device_id - device driver name for proc file system output
3249 +int request_edma_channel(int channel,
3250 + edma_irq_handler handler,
3251 + edma_error_handler error_handler,
3254 + const char *device_id);
3256 +/* Free eDMA channel
3257 + * channel - eDMA TCD number
3260 int free_edma_channel(int channel, void *dev);
3264 +++ b/include/linux/spi/mcfqspi.h
3266 +/****************************************************************************/
3269 + * mcfqspi.c - Master QSPI controller for the ColdFire processors
3271 + * (C) Copyright 2005, Intec Automation,
3272 + * Mike Lavender (mike@steroidmicros)
3275 + This program is free software; you can redistribute it and/or modify
3276 + it under the terms of the GNU General Public License as published by
3277 + the Free Software Foundation; either version 2 of the License, or
3278 + (at your option) any later version.
3280 + This program is distributed in the hope that it will be useful,
3281 + but WITHOUT ANY WARRANTY; without even the implied warranty of
3282 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3283 + GNU General Public License for more details.
3285 + You should have received a copy of the GNU General Public License
3286 + along with this program; if not, write to the Free Software
3287 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
3288 +/* ------------------------------------------------------------------------- */
3293 +#define QSPI_CS_INIT 0x01
3294 +#define QSPI_CS_ASSERT 0x02
3295 +#define QSPI_CS_DROP 0x04
3297 +#define QSPIIOCS_DOUT_HIZ 1 /* QMR[DOHIE] set hi-z dout between transfers */
3298 +#define QSPIIOCS_BITS 2 /* QMR[BITS] set transfer size */
3299 +#define QSPIIOCG_BITS 3 /* QMR[BITS] get transfer size */
3300 +#define QSPIIOCS_CPOL 4 /* QMR[CPOL] set SCK inactive state */
3301 +#define QSPIIOCS_CPHA 5 /* QMR[CPHA] set SCK phase, 1=rising edge */
3302 +#define QSPIIOCS_BAUD 6 /* QMR[BAUD] set SCK baud rate divider */
3303 +#define QSPIIOCS_QCD 7 /* QDLYR[QCD] set start delay */
3304 +#define QSPIIOCS_DTL 8 /* QDLYR[DTL] set after delay */
3305 +#define QSPIIOCS_CONT 9 /* continuous CS asserted during transfer */
3306 +#define QSPIIOCS_READDATA 10 /* set data send during read */
3307 +#define QSPIIOCS_ODD_MOD 11 /* if length of buffer is a odd number, 16-bit transfers */
3308 + /* are finalized with a 8-bit transfer */
3309 +#define QSPIIOCS_DSP_MOD 12 /* transfers are bounded to 15/30 bytes (a multiple of 3 bytes = 1 DSPword) */
3310 +#define QSPIIOCS_POLL_MOD 13 /* driver uses polling instead of interrupts */
3312 +#define QSPIIOCS_SET_CSIV 14 /* sets CSIV flag (cs inactive level) */
3314 +#ifdef CONFIG_M520x
3315 +#undef MCF_GPIO_PAR_QSPI
3316 +#define MCF_GPIO_PAR_QSPI (0xA4034)
3319 +struct coldfire_spi_master {
3321 + u16 num_chipselect;
3328 + void (*cs_control)(u8 cs, u8 command);
3332 +struct coldfire_spi_chip {
3336 + u8 del_after_trans;
3337 + u16 void_write_data;
3340 +typedef struct qspi_read_data {
3342 + __u8 *buf; /* data to send during read */
3343 + unsigned int loop : 1;
3345 +#endif /*MCFQSPI_H_*/