[POWERPC] Split initrd logic out of early_init_dt_scan_chosen() to fix warning
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / arm26 / machine / dma.c
blob4402a5a1b78fbe2d9efc8fb294f5915a8269c130
1 /*
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>
16 #include <asm/dma.h>
17 #include <asm/fiq.h>
18 #include <asm/irq.h>
19 #include <asm/io.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");
35 if (dma->using_sg)
36 BUG();
38 switch (dma->dma_mode) {
39 case DMA_MODE_READ: { /* read */
40 unsigned long flags;
41 DPRINTK("enable_dma fdc1772 data read\n");
42 local_save_flags_cli(flags);
43 clf();
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);
51 break;
53 case DMA_MODE_WRITE: { /* write */
54 unsigned long flags;
55 DPRINTK("enable_dma fdc1772 data write\n");
56 local_save_flags_cli(flags);
57 clf();
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);
65 break;
66 default:
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);
83 unsigned long flags;
85 DPRINTK("arc_floppy_cmdend_enable_dma\n");
86 /*printk("enable_dma fdc1772 command end FIQ\n");*/
87 save_flags(flags);
88 clf();
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 = {
112 .type = "FIQDMA",
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 = {
119 .type = "FIQCMD",
120 .enable = arc_floppy_cmdend_enable_dma,
121 .disable = arc_disable_dma,
122 .residue = arc_floppy_cmdend_get_dma_residue,
124 #endif
126 #ifdef CONFIG_ARCH_A5K
127 static struct fiq_handler fh = {
128 .name = "floppydata"
131 static int a5k_floppy_get_dma_residue(dmach_t channel, dma_t *dma)
133 struct pt_regs regs;
134 get_fiq_regs(&regs);
135 return regs.ARM_r9;
138 static void a5k_floppy_enable_dma(dmach_t channel, dma_t *dma)
140 struct pt_regs regs;
141 void *fiqhandler_start;
142 unsigned int fiqhandler_length;
143 extern void floppy_fiqsetup(unsigned long len, unsigned long addr,
144 unsigned long port);
146 if (dma->using_sg)
147 BUG();
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;
153 } else {
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");
160 return;
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;
166 set_fiq_regs(&regs);
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);
173 release_fiq(&fh);
176 static struct dma_ops a5k_floppy_dma_ops = {
177 .type = "FIQDMA",
178 .enable = a5k_floppy_enable_dma,
179 .disable = a5k_floppy_disable_dma,
180 .residue = a5k_floppy_get_dma_residue,
182 #endif
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 = {
192 .type = "VIRTUAL",
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;
206 #endif
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;
212 #endif
213 dma[DMA_VIRTUAL_SOUND].d_ops = &sound_dma_ops;