spi-topcliff-pch: add recovery processing in case wait-event timeout
[zen-stable.git] / arch / m68k / atari / stdma.c
blobddbf43ca8858012470d7f20665e89e85f5a045f3
1 /*
2 * linux/arch/m68k/atari/stmda.c
4 * Copyright (C) 1994 Roman Hodek
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file COPYING in the main directory of this archive
9 * for more details.
13 /* This file contains some function for controlling the access to the */
14 /* ST-DMA chip that may be shared between devices. Currently we have: */
15 /* TT: Floppy and ACSI bus */
16 /* Falcon: Floppy and SCSI */
17 /* */
18 /* The controlling functions set up a wait queue for access to the */
19 /* ST-DMA chip. Callers to stdma_lock() that cannot granted access are */
20 /* put onto a queue and waked up later if the owner calls */
21 /* stdma_release(). Additionally, the caller gives his interrupt */
22 /* service routine to stdma_lock(). */
23 /* */
24 /* On the Falcon, the IDE bus uses just the ACSI/Floppy interrupt, but */
25 /* not the ST-DMA chip itself. So falhd.c needs not to lock the */
26 /* chip. The interrupt is routed to falhd.c if IDE is configured, the */
27 /* model is a Falcon and the interrupt was caused by the HD controller */
28 /* (can be determined by looking at its status register). */
31 #include <linux/types.h>
32 #include <linux/kdev_t.h>
33 #include <linux/genhd.h>
34 #include <linux/sched.h>
35 #include <linux/init.h>
36 #include <linux/interrupt.h>
37 #include <linux/wait.h>
38 #include <linux/module.h>
40 #include <asm/atari_stdma.h>
41 #include <asm/atariints.h>
42 #include <asm/atarihw.h>
43 #include <asm/io.h>
44 #include <asm/irq.h>
46 static int stdma_locked; /* the semaphore */
47 /* int func to be called */
48 static irq_handler_t stdma_isr;
49 static void *stdma_isr_data; /* data passed to isr */
50 static DECLARE_WAIT_QUEUE_HEAD(stdma_wait); /* wait queue for ST-DMA */
55 /***************************** Prototypes *****************************/
57 static irqreturn_t stdma_int (int irq, void *dummy);
59 /************************* End of Prototypes **************************/
64 * Function: void stdma_lock( isrfunc isr, void *data )
66 * Purpose: Tries to get a lock on the ST-DMA chip that is used by more
67 * then one device driver. Waits on stdma_wait until lock is free.
68 * stdma_lock() may not be called from an interrupt! You have to
69 * get the lock in your main routine and release it when your
70 * request is finished.
72 * Inputs: A interrupt function that is called until the lock is
73 * released.
75 * Returns: nothing
79 void stdma_lock(irq_handler_t handler, void *data)
81 unsigned long flags;
83 local_irq_save(flags); /* protect lock */
85 /* Since the DMA is used for file system purposes, we
86 have to sleep uninterruptible (there may be locked
87 buffers) */
88 wait_event(stdma_wait, !stdma_locked);
90 stdma_locked = 1;
91 stdma_isr = handler;
92 stdma_isr_data = data;
93 local_irq_restore(flags);
95 EXPORT_SYMBOL(stdma_lock);
99 * Function: void stdma_release( void )
101 * Purpose: Releases the lock on the ST-DMA chip.
103 * Inputs: none
105 * Returns: nothing
109 void stdma_release(void)
111 unsigned long flags;
113 local_irq_save(flags);
115 stdma_locked = 0;
116 stdma_isr = NULL;
117 stdma_isr_data = NULL;
118 wake_up(&stdma_wait);
120 local_irq_restore(flags);
122 EXPORT_SYMBOL(stdma_release);
126 * Function: int stdma_others_waiting( void )
128 * Purpose: Check if someone waits for the ST-DMA lock.
130 * Inputs: none
132 * Returns: 0 if no one is waiting, != 0 otherwise
136 int stdma_others_waiting(void)
138 return waitqueue_active(&stdma_wait);
140 EXPORT_SYMBOL(stdma_others_waiting);
144 * Function: int stdma_islocked( void )
146 * Purpose: Check if the ST-DMA is currently locked.
147 * Note: Returned status is only valid if ints are disabled while calling and
148 * as long as they remain disabled.
149 * If called with ints enabled, status can change only from locked to
150 * unlocked, because ints may not lock the ST-DMA.
152 * Inputs: none
154 * Returns: != 0 if locked, 0 otherwise
158 int stdma_islocked(void)
160 return stdma_locked;
162 EXPORT_SYMBOL(stdma_islocked);
166 * Function: void stdma_init( void )
168 * Purpose: Initialize the ST-DMA chip access controlling.
169 * It sets up the interrupt and its service routine. The int is registered
170 * as slow int, client devices have to live with that (no problem
171 * currently).
173 * Inputs: none
175 * Return: nothing
179 void __init stdma_init(void)
181 stdma_isr = NULL;
182 if (request_irq(IRQ_MFP_FDC, stdma_int, IRQ_TYPE_SLOW | IRQF_SHARED,
183 "ST-DMA floppy,ACSI,IDE,Falcon-SCSI", stdma_int))
184 pr_err("Couldn't register ST-DMA interrupt\n");
189 * Function: void stdma_int()
191 * Purpose: The interrupt routine for the ST-DMA. It calls the isr
192 * registered by stdma_lock().
196 static irqreturn_t stdma_int(int irq, void *dummy)
198 if (stdma_isr)
199 (*stdma_isr)(irq, stdma_isr_data);
200 return IRQ_HANDLED;