~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/m68k/q40/q40ints.c

Version: ~ [ linux-5.8 ] ~ [ linux-5.7.12 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.55 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.136 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.191 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.232 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.232 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * arch/m68k/q40/q40ints.c
  3  *
  4  * Copyright (C) 1999,2001 Richard Zidlicky
  5  *
  6  * This file is subject to the terms and conditions of the GNU General Public
  7  * License.  See the file COPYING in the main directory of this archive
  8  * for more details.
  9  *
 10  * .. used to be loosely based on bvme6000ints.c
 11  *
 12  */
 13 
 14 #include <linux/config.h>
 15 #include <linux/types.h>
 16 #include <linux/kernel.h>
 17 #include <linux/errno.h>
 18 #include <linux/string.h>
 19 #include <linux/sched.h>
 20 #include <linux/seq_file.h>
 21 #include <linux/interrupt.h>
 22 
 23 #include <asm/rtc.h>
 24 #include <asm/ptrace.h>
 25 #include <asm/system.h>
 26 #include <asm/irq.h>
 27 #include <asm/hardirq.h>
 28 #include <asm/traps.h>
 29 
 30 #include <asm/q40_master.h>
 31 #include <asm/q40ints.h>
 32 
 33 /* 
 34  * Q40 IRQs are defined as follows: 
 35  *            3,4,5,6,7,10,11,14,15 : ISA dev IRQs
 36  *            16-31: reserved
 37  *            32   : keyboard int
 38  *            33   : frame int (50/200 Hz periodic timer)
 39  *            34   : sample int (10/20 KHz periodic timer)
 40  *          
 41 */
 42 
 43 extern int ints_inited;
 44 
 45 
 46 irqreturn_t q40_irq2_handler (int, void *, struct pt_regs *fp);
 47 
 48 
 49 extern irqreturn_t (*q40_sys_default_handler[]) (int, void *, struct pt_regs *);
 50 
 51 static irqreturn_t q40_defhand (int irq, void *dev_id, struct pt_regs *fp);
 52 static irqreturn_t sys_default_handler(int lev, void *dev_id, struct pt_regs *regs);
 53 
 54 
 55 #define DEVNAME_SIZE 24
 56 
 57 static struct q40_irq_node {
 58         irqreturn_t     (*handler)(int, void *, struct pt_regs *);
 59         unsigned long   flags;
 60         void            *dev_id;
 61   /*        struct q40_irq_node *next;*/
 62         char            devname[DEVNAME_SIZE];
 63         unsigned        count;
 64         unsigned short  state;
 65 } irq_tab[Q40_IRQ_MAX+1];
 66 
 67 short unsigned q40_ablecount[Q40_IRQ_MAX+1];
 68 
 69 /*
 70  * void q40_init_IRQ (void)
 71  *
 72  * Parameters:  None
 73  *
 74  * Returns:     Nothing
 75  *
 76  * This function is called during kernel startup to initialize
 77  * the q40 IRQ handling routines.
 78  */
 79 
 80 static int disabled=0;
 81 
 82 void q40_init_IRQ (void)
 83 {
 84         int i;
 85 
 86         disabled=0;
 87         for (i = 0; i <= Q40_IRQ_MAX; i++) {
 88                 irq_tab[i].handler = q40_defhand;
 89                 irq_tab[i].flags = 0;
 90                 irq_tab[i].dev_id = NULL;
 91                 /*              irq_tab[i].next = NULL;*/
 92                 irq_tab[i].devname[0] = 0;
 93                 irq_tab[i].count = 0;
 94                 irq_tab[i].state =0;
 95                 q40_ablecount[i]=0;   /* all enabled */
 96         }
 97 
 98         /* setup handler for ISA ints */
 99         sys_request_irq(IRQ2,q40_irq2_handler, 0, "q40 ISA and master chip", NULL);
100 
101         /* now enable some ints.. */
102         master_outb(1,EXT_ENABLE_REG);  /* ISA IRQ 5-15 */
103 
104         /* make sure keyboard IRQ is disabled */
105         master_outb(0,KEY_IRQ_ENABLE_REG);
106 }
107 
108 int q40_request_irq(unsigned int irq,
109                 irqreturn_t (*handler)(int, void *, struct pt_regs *),
110                 unsigned long flags, const char *devname, void *dev_id)
111 {
112   /*printk("q40_request_irq %d, %s\n",irq,devname);*/
113 
114         if (irq > Q40_IRQ_MAX || (irq>15 && irq<32)) {
115                 printk("%s: Incorrect IRQ %d from %s\n", __FUNCTION__, irq, devname);
116                 return -ENXIO;
117         }
118 
119         /* test for ISA ints not implemented by HW */
120         switch (irq)
121           {
122           case 1: case 2: case 8: case 9:
123           case 12: case 13:
124             printk("%s: ISA IRQ %d from %s not implemented by HW\n", __FUNCTION__, irq, devname);
125             return -ENXIO;
126           case 11:            
127             printk("warning IRQ 10 and 11 not distinguishable\n");
128             irq=10;
129           default:
130             ;
131           }
132 
133         if (irq<Q40_IRQ_SAMPLE)
134           {
135             if (irq_tab[irq].dev_id != NULL) 
136                   {
137                     printk("%s: IRQ %d from %s is not replaceable\n",
138                            __FUNCTION__, irq, irq_tab[irq].devname);
139                     return -EBUSY;
140                   }
141             /*printk("IRQ %d set to handler %p\n",irq,handler);*/
142             if (dev_id==NULL)
143                   {
144                 printk("WARNING: dev_id == NULL in request_irq\n");
145                 dev_id=(void*)1;
146               }
147             irq_tab[irq].handler = handler;
148             irq_tab[irq].flags   = flags;
149             irq_tab[irq].dev_id  = dev_id;
150             strlcpy(irq_tab[irq].devname,devname,sizeof(irq_tab[irq].devname));
151             irq_tab[irq].state = 0;
152             return 0;
153           }
154         else {
155           /* Q40_IRQ_SAMPLE :somewhat special actions required here ..*/
156           sys_request_irq(4,handler,flags,devname,dev_id);
157           sys_request_irq(6,handler,flags,devname,dev_id);
158           return 0;
159         }
160 }
161 
162 void q40_free_irq(unsigned int irq, void *dev_id)
163 {
164         if (irq > Q40_IRQ_MAX || (irq>15 && irq<32)) {
165                 printk("%s: Incorrect IRQ %d, dev_id %x \n", __FUNCTION__, irq, (unsigned)dev_id);
166                 return;
167         }
168 
169         /* test for ISA ints not implemented by HW */
170         switch (irq)
171           {
172           case 1: case 2: case 8: case 9:
173           case 12: case 13:
174             printk("%s: ISA IRQ %d from %x invalid\n", __FUNCTION__, irq, (unsigned)dev_id);
175             return;
176           case 11: irq=10;
177           default:
178             ;
179           }
180         
181         if (irq<Q40_IRQ_SAMPLE)
182           {
183             if (irq_tab[irq].dev_id != dev_id)
184               printk("%s: Removing probably wrong IRQ %d from %s\n",
185                      __FUNCTION__, irq, irq_tab[irq].devname);
186             
187             irq_tab[irq].handler = q40_defhand;
188             irq_tab[irq].flags   = 0;
189             irq_tab[irq].dev_id  = NULL;
190             /* irq_tab[irq].devname = NULL; */
191             /* do not reset state !! */
192           }
193         else
194           { /* == Q40_IRQ_SAMPLE */
195             sys_free_irq(4,dev_id);
196             sys_free_irq(6,dev_id);
197           }
198 }
199 
200 
201 irqreturn_t q40_process_int (int level, struct pt_regs *fp)
202 {
203   printk("unexpected interrupt vec=%x, pc=%lx, d0=%lx, d0_orig=%lx, d1=%lx, d2=%lx\n",
204           level, fp->pc, fp->d0, fp->orig_d0, fp->d1, fp->d2);
205   printk("\tIIRQ_REG = %x, EIRQ_REG = %x\n",master_inb(IIRQ_REG),master_inb(EIRQ_REG));
206   return IRQ_HANDLED;
207 }
208 
209 /* 
210  * this stuff doesn't really belong here..
211 */
212 
213 int ql_ticks;              /* 200Hz ticks since last jiffie */
214 static int sound_ticks;
215 
216 #define SVOL 45
217 
218 void q40_mksound(unsigned int hz, unsigned int ticks)
219 {
220   /* for now ignore hz, except that hz==0 switches off sound */
221   /* simply alternate the ampl (128-SVOL)-(128+SVOL)-..-.. at 200Hz */
222   if (hz==0)
223     {
224       if (sound_ticks)
225         sound_ticks=1;
226 
227       *DAC_LEFT=128;
228       *DAC_RIGHT=128;
229 
230       return;
231     }
232   /* sound itself is done in q40_timer_int */
233   if (sound_ticks == 0) sound_ticks=1000; /* pretty long beep */
234   sound_ticks=ticks<<1;
235 }
236 
237 static irqreturn_t (*q40_timer_routine)(int, void *, struct pt_regs *);
238 
239 static irqreturn_t q40_timer_int (int irq, void * dev, struct pt_regs * regs)
240 {
241     ql_ticks = ql_ticks ? 0 : 1;
242     if (sound_ticks)
243       {
244         unsigned char sval=(sound_ticks & 1) ? 128-SVOL : 128+SVOL;
245         sound_ticks--;
246         *DAC_LEFT=sval;
247         *DAC_RIGHT=sval;
248       }
249 
250     if (!ql_ticks)
251         q40_timer_routine(irq, dev, regs);
252     return IRQ_HANDLED;
253 }
254 
255 void q40_sched_init (irqreturn_t (*timer_routine)(int, void *, struct pt_regs *))
256 {
257     int timer_irq;
258 
259     q40_timer_routine = timer_routine;
260     timer_irq=Q40_IRQ_FRAME;
261 
262     if (request_irq(timer_irq, q40_timer_int, 0,
263                                 "timer", q40_timer_int))
264         panic ("Couldn't register timer int");
265 
266     master_outb(-1,FRAME_CLEAR_REG);
267     master_outb( 1,FRAME_RATE_REG);
268 }
269 
270 
271 /* 
272  * tables to translate bits into IRQ numbers 
273  * it is a good idea to order the entries by priority
274  * 
275 */
276 
277 struct IRQ_TABLE{ unsigned mask; int irq ;};
278 #if 0
279 static struct IRQ_TABLE iirqs[]={
280   {Q40_IRQ_FRAME_MASK,Q40_IRQ_FRAME},
281   {Q40_IRQ_KEYB_MASK,Q40_IRQ_KEYBOARD},
282   {0,0}};
283 #endif
284 static struct IRQ_TABLE eirqs[]={
285   {Q40_IRQ3_MASK,3},                   /* ser 1 */
286   {Q40_IRQ4_MASK,4},                   /* ser 2 */
287   {Q40_IRQ14_MASK,14},                 /* IDE 1 */
288   {Q40_IRQ15_MASK,15},                 /* IDE 2 */
289   {Q40_IRQ6_MASK,6},                   /* floppy, handled elsewhere */
290   {Q40_IRQ7_MASK,7},                   /* par */
291 
292   {Q40_IRQ5_MASK,5},
293   {Q40_IRQ10_MASK,10},
294 
295 
296 
297 
298   {0,0}};
299 
300 /* complain only this many times about spurious ints : */
301 static int ccleirq=60;    /* ISA dev IRQ's*/
302 /*static int cclirq=60;*/     /* internal */
303 
304 /* FIXME: add shared ints,mask,unmask,probing.... */
305 
306 #define IRQ_INPROGRESS 1
307 /*static unsigned short saved_mask;*/
308 //static int do_tint=0;
309 
310 #define DEBUG_Q40INT
311 /*#define IP_USE_DISABLE *//* would be nice, but crashes ???? */
312 
313 static int mext_disabled=0;  /* ext irq disabled by master chip? */
314 static int aliased_irq=0;  /* how many times inside handler ?*/
315 
316 
317 /* got level 2 interrupt, dispatch to ISA or keyboard/timer IRQs */
318 irqreturn_t q40_irq2_handler (int vec, void *devname, struct pt_regs *fp)
319 {
320   unsigned mir, mer;
321   int irq,i;
322 
323 //repeat:
324   mir=master_inb(IIRQ_REG);
325   if (mir&Q40_IRQ_FRAME_MASK) {
326           irq_tab[Q40_IRQ_FRAME].count++;
327           irq_tab[Q40_IRQ_FRAME].handler(Q40_IRQ_FRAME,irq_tab[Q40_IRQ_FRAME].dev_id,fp);   
328           master_outb(-1,FRAME_CLEAR_REG);
329   }
330   if ((mir&Q40_IRQ_SER_MASK) || (mir&Q40_IRQ_EXT_MASK)) {
331           mer=master_inb(EIRQ_REG);
332           for (i=0; eirqs[i].mask; i++) {
333                   if (mer&(eirqs[i].mask)) {
334                           irq=eirqs[i].irq;
335 /*
336  * There is a little mess wrt which IRQ really caused this irq request. The
337  * main problem is that IIRQ_REG and EIRQ_REG reflect the state when they
338  * are read - which is long after the request came in. In theory IRQs should
339  * not just go away but they occassionally do
340  */
341                           if (irq>4 && irq<=15 && mext_disabled) {
342                                   /*aliased_irq++;*/
343                                   goto iirq;
344                           }
345                           if (irq_tab[irq].handler == q40_defhand ) {
346                                   printk("handler for IRQ %d not defined\n",irq);
347                                   continue; /* ignore uninited INTs :-( */
348                           }
349                           if ( irq_tab[irq].state & IRQ_INPROGRESS ) {
350                                   /* some handlers do local_irq_enable() for irq latency reasons, */
351                                   /* however reentering an active irq handler is not permitted */
352 #ifdef IP_USE_DISABLE
353                                   /* in theory this is the better way to do it because it still */
354                                   /* lets through eg the serial irqs, unfortunately it crashes */
355                                   disable_irq(irq);
356                                   disabled=1;
357 #else
358                                   /*printk("IRQ_INPROGRESS detected for irq %d, disabling - %s disabled\n",irq,disabled ? "already" : "not yet"); */
359                                   fp->sr = (((fp->sr) & (~0x700))+0x200);
360                                   disabled=1;
361 #endif
362                                   goto iirq;
363                           }
364                           irq_tab[irq].count++; 
365                           irq_tab[irq].state |= IRQ_INPROGRESS;
366                           irq_tab[irq].handler(irq,irq_tab[irq].dev_id,fp);
367                           irq_tab[irq].state &= ~IRQ_INPROGRESS;
368                           
369                           /* naively enable everything, if that fails than    */
370                           /* this function will be reentered immediately thus */
371                           /* getting another chance to disable the IRQ        */
372                           
373                           if ( disabled ) {
374 #ifdef IP_USE_DISABLE
375                                   if (irq>4){
376                                           disabled=0;
377                                           enable_irq(irq);}
378 #else
379                                   disabled=0;
380                                   /*printk("reenabling irq %d\n",irq); */
381 #endif
382                           }
383 // used to do 'goto repeat;' here, this delayed bh processing too long
384                           return IRQ_HANDLED;
385                   }
386           }
387           if (mer && ccleirq>0 && !aliased_irq) 
388                   printk("ISA interrupt from unknown source? EIRQ_REG = %x\n",mer),ccleirq--;
389   } 
390  iirq:
391   mir=master_inb(IIRQ_REG);
392   /* should test whether keyboard irq is really enabled, doing it in defhand */
393   if (mir&Q40_IRQ_KEYB_MASK) {
394           irq_tab[Q40_IRQ_KEYBOARD].count++;
395           irq_tab[Q40_IRQ_KEYBOARD].handler(Q40_IRQ_KEYBOARD,irq_tab[Q40_IRQ_KEYBOARD].dev_id,fp);
396   }
397   return IRQ_HANDLED;
398 }
399 
400 int show_q40_interrupts (struct seq_file *p, void *v)
401 {
402         int i;
403 
404         for (i = 0; i <= Q40_IRQ_MAX; i++) {
405                 if (irq_tab[i].count)
406                       seq_printf(p, "%sIRQ %02d: %8d  %s%s\n",
407                               (i<=15) ? "ISA-" : "    " ,               
408                             i, irq_tab[i].count,
409                             irq_tab[i].devname[0] ? irq_tab[i].devname : "?",
410                             irq_tab[i].handler == q40_defhand ? 
411                                         " (now unassigned)" : "");
412         }
413         return 0;
414 }
415 
416 
417 static irqreturn_t q40_defhand (int irq, void *dev_id, struct pt_regs *fp)
418 {
419         if (irq!=Q40_IRQ_KEYBOARD)
420              printk ("Unknown q40 interrupt %d\n", irq);
421         else master_outb(-1,KEYBOARD_UNLOCK_REG);
422         return IRQ_NONE;
423 }
424 static irqreturn_t sys_default_handler(int lev, void *dev_id, struct pt_regs *regs)
425 {
426         printk ("Uninitialised interrupt level %d\n", lev);
427         return IRQ_NONE;
428 }
429 
430  irqreturn_t (*q40_sys_default_handler[SYS_IRQS]) (int, void *, struct pt_regs *) = {
431          sys_default_handler,sys_default_handler,sys_default_handler,sys_default_handler,
432          sys_default_handler,sys_default_handler,sys_default_handler,sys_default_handler
433  };
434 
435 
436 void q40_enable_irq (unsigned int irq)
437 {
438   if ( irq>=5 && irq<=15 )
439   {
440     mext_disabled--;
441     if (mext_disabled>0)
442           printk("q40_enable_irq : nested disable/enable\n"); 
443     if (mext_disabled==0)
444     master_outb(1,EXT_ENABLE_REG);
445     }
446 }
447 
448 
449 void q40_disable_irq (unsigned int irq)
450 {
451   /* disable ISA iqs : only do something if the driver has been
452    * verified to be Q40 "compatible" - right now IDE, NE2K
453    * Any driver should not attempt to sleep across disable_irq !!
454    */
455 
456   if ( irq>=5 && irq<=15 ) {
457     master_outb(0,EXT_ENABLE_REG);
458     mext_disabled++;
459     if (mext_disabled>1) printk("disable_irq nesting count %d\n",mext_disabled);
460   }
461 }
462 
463 unsigned long q40_probe_irq_on (void)
464 {
465   printk("irq probing not working - reconfigure the driver to avoid this\n");
466   return -1;
467 }
468 int q40_probe_irq_off (unsigned long irqs)
469 {
470   return -1;
471 }
472 /*
473  * Local variables:
474  * compile-command: "m68k-linux-gcc -D__KERNEL__ -I/home/rz/lx/linux-2.2.6/include -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -pipe -fno-strength-reduce -ffixed-a2 -m68040   -c -o q40ints.o q40ints.c"
475  * End:
476  */
477 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp