All of lore.kernel.org
 help / color / mirror / Atom feed
* How to use FIQ on rpi zero? (second try)
@ 2020-06-05  9:32 Sietse Achterop
  0 siblings, 0 replies; only message in thread
From: Sietse Achterop @ 2020-06-05  9:32 UTC (permalink / raw)
  To: linux-arm-kernel


Hello List,

I'm having trouble with using FIQ interrupts with the ARM timer on raspberypi zero, (BCM2835 chip).
I created a kernel module, and the test version of this driver can be found in

   https://github.com/SietseAchterop/Batradio/blob/master/batradio_module/fiqtest_4.c

I made sure that FIQ is not used by USB by adding
    dwc_otg.fiq_fsm_enable=0 dwc_otg.fiq_enable=0 dwc_otg.nak_holdoff=0
to cmdline.txt in /boot

I first tried to use the regular sequence of functions to use.
In the init function:
   claim_fiq, set_fiq_regs, enable_fiq
In the exit function
   disable_fiq, release_fiq.

But I cannot find which iqr number to use, e.g. using irq_of_parse_and_map
I tried several values. 0, 64, but nothing works.
So instead of enable/disable I directly set the timer interrupt via the IRQFIQ register.

This works, a bit.
The fiq_handler only resets the ARM timer, increments a timer and toggles a LED.
I see the timer counting, the fiq being called.
But the rpi fairly quickly crashes.
In the, sometimes, 10 seconds that it runs I see the led flashing very irregular.

What is wrong here?
Has the irregularity something to do with suspend/resume?
Please find below the relevant snippets from the init and exit function of the driver.
And also the fiq_handler.

    Thanks in advance,
        Sietse

====== init_bat
       .....
   // directly set ARM timer registers
   TIMCNTR = 0x0000000;   // stop timer
   TIMLOAD = 100000-1;    // load value
   TIMCINT = 0;           // clear interrupt

   ret = claim_fiq(&bat_fh);
   if (ret) {
     printk("batradio: claim_fiq failed.\n");
     return ret;
   }
   
   set_fiq_handler(&batradio_handler, &batradio_handler_end - &batradio_handler);

   regs.ARM_r8  = (long)gpiospi;
   regs.ARM_r9  = (long)irqtimer;
   regs.ARM_r10 = (long)0;
   set_fiq_regs(&regs);

   TIMCNTR = 0x000000A2;   // start timer with interrupt, 23 bit counter
   IRQFIQ = 0xC0;         // timer interrupt to fiq directly via register
   //enable_fiq(64);
       ....

======  exit_bat
	....
   IRQFIQ  = 0x00;
   TIMCNTR = 0x003E0000;
   //disable_fiq(64);
         ....
	
======  batradio fiq handler
	.text
	.global batradio_handler
	.global batradio_handler_end

batradio_handler:
	stmdb sp!, {r6-r7}
	mov  r6, #0
	str r6, [r9, #0x40C]	// TIMCINT = 0 // clear interrupt

	mov r7, #0x2000		// 1 << CNVST
	add r10, r10, #1
	ands r6, r10, #0x0001	// set toggle speed
	bne off
	str r7, [r8, #40]	// led on
	ldmia sp!, {r6-r7}
	subs pc, lr, #4
off:	str r7, [r8, #28]	// led off
	ldmia sp!, {r6-r7}
	subs pc, lr, #4
batradio_handler_end:

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-06-05  9:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-05  9:32 How to use FIQ on rpi zero? (second try) Sietse Achterop

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.