2 * linux/arch/arm26/kernel/dma.c
4 * Copyright (C) 1998-1999 Dave Gilbert / Russell King
5 * Copyright (C) 2003 Ian Molton
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * DMA functions specific to Archimedes and A5000 architecture
13 #include <linux/sched.h>
14 #include <linux/init.h>
20 #include <asm/hardware.h>
21 #include <asm/mach-types.h>
23 #define DPRINTK(x...) printk(KERN_DEBUG x)
25 #if defined(CONFIG_BLK_DEV_FD1772) || defined(CONFIG_BLK_DEV_FD1772_MODULE)
27 extern unsigned char fdc1772_dma_read, fdc1772_dma_read_end;
28 extern unsigned char fdc1772_dma_write, fdc1772_dma_write_end;
29 extern void fdc1772_setupdma(unsigned int count,unsigned int addr);
31 static void arc_floppy_data_enable_dma(dmach_t channel, dma_t *dma)
33 DPRINTK("arc_floppy_data_enable_dma\n");
38 switch (dma->dma_mode) {
39 case DMA_MODE_READ: { /* read */
41 DPRINTK("enable_dma fdc1772 data read\n");
42 local_save_flags_cli(flags);
45 memcpy ((void *)0x1c, (void *)&fdc1772_dma_read,
46 &fdc1772_dma_read_end - &fdc1772_dma_read);
47 fdc1772_setupdma(dma->buf.length, dma->buf.__address); /* Sets data pointer up */
48 enable_fiq(FIQ_FLOPPYDATA);
49 local_irq_restore(flags);
53 case DMA_MODE_WRITE: { /* write */
55 DPRINTK("enable_dma fdc1772 data write\n");
56 local_save_flags_cli(flags);
58 memcpy ((void *)0x1c, (void *)&fdc1772_dma_write,
59 &fdc1772_dma_write_end - &fdc1772_dma_write);
60 fdc1772_setupdma(dma->buf.length, dma->buf.__address); /* Sets data pointer up */
61 enable_fiq(FIQ_FLOPPYDATA);
63 local_irq_restore(flags);
67 printk ("enable_dma: dma%d not initialised\n", channel);
71 static int arc_floppy_data_get_dma_residue(dmach_t channel, dma_t *dma)
73 extern unsigned int fdc1772_bytestogo;
75 /* 10/1/1999 DAG - I presume its the number of bytes left? */
76 return fdc1772_bytestogo;
79 static void arc_floppy_cmdend_enable_dma(dmach_t channel, dma_t *dma)
81 /* Need to build a branch at the FIQ address */
82 extern void fdc1772_comendhandler(void);
85 DPRINTK("arc_floppy_cmdend_enable_dma\n");
86 /*printk("enable_dma fdc1772 command end FIQ\n");*/
90 /* B fdc1772_comendhandler */
91 *((unsigned int *)0x1c)=0xea000000 |
92 (((unsigned int)fdc1772_comendhandler-(0x1c+8))/4);
94 local_irq_restore(flags);
97 static int arc_floppy_cmdend_get_dma_residue(dmach_t channel, dma_t *dma)
99 /* 10/1/1999 DAG - Presume whether there is an outstanding command? */
100 extern unsigned int fdc1772_fdc_int_done;
102 /* Explicit! If the int done is 0 then 1 int to go */
103 return (fdc1772_fdc_int_done==0)?1:0;
106 static void arc_disable_dma(dmach_t channel, dma_t *dma)
108 disable_fiq(dma->dma_irq);
111 static struct dma_ops arc_floppy_data_dma_ops = {
113 .enable = arc_floppy_data_enable_dma,
114 .disable = arc_disable_dma,
115 .residue = arc_floppy_data_get_dma_residue,
118 static struct dma_ops arc_floppy_cmdend_dma_ops = {
120 .enable = arc_floppy_cmdend_enable_dma,
121 .disable = arc_disable_dma,
122 .residue = arc_floppy_cmdend_get_dma_residue,
126 #ifdef CONFIG_ARCH_A5K
127 static struct fiq_handler fh = {
131 static int a5k_floppy_get_dma_residue(dmach_t channel, dma_t *dma)
138 static void a5k_floppy_enable_dma(dmach_t channel, dma_t *dma)
141 void *fiqhandler_start;
142 unsigned int fiqhandler_length;
143 extern void floppy_fiqsetup(unsigned long len, unsigned long addr,
149 if (dma->dma_mode == DMA_MODE_READ) {
150 extern unsigned char floppy_fiqin_start, floppy_fiqin_end;
151 fiqhandler_start = &floppy_fiqin_start;
152 fiqhandler_length = &floppy_fiqin_end - &floppy_fiqin_start;
154 extern unsigned char floppy_fiqout_start, floppy_fiqout_end;
155 fiqhandler_start = &floppy_fiqout_start;
156 fiqhandler_length = &floppy_fiqout_end - &floppy_fiqout_start;
158 if (claim_fiq(&fh)) {
159 printk("floppydma: couldn't claim FIQ.\n");
162 memcpy((void *)0x1c, fiqhandler_start, fiqhandler_length);
163 regs.ARM_r9 = dma->buf.length;
164 regs.ARM_r10 = (unsigned long)dma->buf.__address;
165 regs.ARM_fp = FLOPPYDMA_BASE;
167 enable_fiq(dma->dma_irq);
170 static void a5k_floppy_disable_dma(dmach_t channel, dma_t *dma)
172 disable_fiq(dma->dma_irq);
176 static struct dma_ops a5k_floppy_dma_ops = {
178 .enable = a5k_floppy_enable_dma,
179 .disable = a5k_floppy_disable_dma,
180 .residue = a5k_floppy_get_dma_residue,
185 * This is virtual DMA - we don't need anything here
187 static void sound_enable_disable_dma(dmach_t channel, dma_t *dma)
191 static struct dma_ops sound_dma_ops = {
193 .enable = sound_enable_disable_dma,
194 .disable = sound_enable_disable_dma,
197 void __init arch_dma_init(dma_t *dma)
199 #if defined(CONFIG_BLK_DEV_FD1772) || defined(CONFIG_BLK_DEV_FD1772_MODULE)
200 if (machine_is_archimedes()) {
201 dma[DMA_VIRTUAL_FLOPPY0].dma_irq = FIQ_FLOPPYDATA;
202 dma[DMA_VIRTUAL_FLOPPY0].d_ops = &arc_floppy_data_dma_ops;
203 dma[DMA_VIRTUAL_FLOPPY1].dma_irq = 1;
204 dma[DMA_VIRTUAL_FLOPPY1].d_ops = &arc_floppy_cmdend_dma_ops;
207 #ifdef CONFIG_ARCH_A5K
208 if (machine_is_a5k()) {
209 dma[DMA_VIRTUAL_FLOPPY0].dma_irq = FIQ_FLOPPYDATA;
210 dma[DMA_VIRTUAL_FLOPPY0].d_ops = &a5k_floppy_dma_ops;
213 dma[DMA_VIRTUAL_SOUND].d_ops = &sound_dma_ops;