Continuing story of SAM9x5 TC driver on Linux

This forum is for users of Microchip MPUs and who are interested in using Linux OS.

Moderator: nferre

J4x
Posts: 11
Joined: Thu Jun 22, 2017 8:00 pm

Continuing story of SAM9x5 TC driver on Linux

Wed Jun 28, 2017 6:45 am

Well, I am still a newbie and can't get my simple driver to use a Timer-Counter.

My kernel menuconfig shows:

Code: Select all

> Device Drivers > Misc devices
 [*] Atmel AT32/AT91 Timer/Counter Library
 [*]   TC Block Clocksource
Device tree has:

Code: Select all

			tcb0: timer@f8008000 {
				compatible = "atmel,at91sam9x5-tcb";
				reg = <0xf8008000 0x100>;
				interrupts = <17 IRQ_TYPE_LEVEL_HIGH 0>;
				clocks = <&tcb0_clk>, <&clk32k>;
				clock-names = "t0_clk", "slow_clk";
			};

			tcb1: timer@f800c000 {
				compatible = "atmel,at91sam9x5-tcb";
				reg = <0xf800c000 0x100>;
				interrupts = <17 IRQ_TYPE_LEVEL_HIGH 0>;
				clocks = <&tcb0_clk>, <&clk32k>;
				clock-names = "t0_clk", "slow_clk";
			};
If I search my board for "tcb" that's what I get:

Code: Select all

# find /sys/ -iname "*tcb*"
/sys/bus/platform/drivers/atmel-tcb-pwm
/sys/firmware/devicetree/base/ahb/apb/pmc@fffffc00/periphck/tcb0_clk
/sys/kernel/debug/clk/tcb0_clk
But my driver code always dies at the same point with the message "Could not find TCB node":

Code: Select all

	struct device_node *np;

	np = of_find_compatible_node( NULL, NULL, "atmel,at91sam9x5-tcb" );

	if ( !np )
		np = of_find_compatible_node( NULL, NULL, "tcb0_clk" );

	if ( !np )
	{
		printk ( KERN_ALERT "Could not find TCB node" );
		return -ENODEV;
	}
I have tried to skip completely the device tree lookup and allocate the timer directly either specifying "0" or "1" as "tcblock":

Code: Select all

tcb = atmel_tc_alloc( tcblock );
No better luck, though.

I am using the nothing new Linux kernel 4.1.0 from Yocto grabbed from https://github.com/linux4sam/meta-atmel - linux4sam_5.3.

Could anyone please give me any suggestions, guidelines, examples or anything else that might be of help?

Thanks in advance.
blue_z
Location: USA
Posts: 1560
Joined: Thu Apr 19, 2007 10:15 pm

Re: Continuing story of SAM9x5 TC driver on Linux

Wed Jun 28, 2017 9:04 pm

Read my response in your previous thread, or how to get periodic timer callback in linux kernel

BTW if you're going to write kernel code, then use kernel coding style.

Regards
J4x
Posts: 11
Joined: Thu Jun 22, 2017 8:00 pm

[SOLVED] Re: Continuing story of SAM9x5 TC driver on Linux

Thu Jun 29, 2017 2:06 pm

Thanks for your reply, blue_z.
blue_z wrote:Read my response in your previous thread, or how to get periodic timer callback in linux kernel
Are you sure you have such post?
Neither at91 search neither Google can find it. And believe me, I always start by searching before asking.
Furthermore, what Google points me to is not really what I need. I need to have a very fine control of SAM9 TC.

I finally spot my error and my timer is now working as should.
My problem is that I was not looking at the right device tree files.
A previous patch was whipping away `tcb0` and `tcb1` and I didn' t notice that until yesterday.

Now `atmel_tc_alloc( tcblock )` works out of the box and I don't even need to query DT with `of_find_compatible_node(...)`.

I also needed to remove from my kernel

Code: Select all

 [*]   TC Block Clocksource
otherwise the IRQ I needed wouldn't be available.

I hope this post be of help for other people in this forum.

blue_z wrote:BTW if you're going to write kernel code, then use kernel coding style.
Thanks for noting.
To be honest, I am not worried about it now. KDevelop will format the code for me following all the kernel rules with a single button click.

Right now, I really need to understand my code and the extra spaces and so help me a lot to spot details. I am not that young anymore...

Thank you again.
blue_z
Location: USA
Posts: 1560
Joined: Thu Apr 19, 2007 10:15 pm

Re: [SOLVED] Re: Continuing story of SAM9x5 TC driver on Lin

Thu Jun 29, 2017 11:27 pm

J4x wrote:Are you sure you have such post?
Neither at91 search neither Google can find it.
So you think I'm so absent minded that I lost track of what I had posted four minutes prior?
You have a grand total of two other threads, and you need to use search engines to try to find a post "in your previous thread"?
J4x
Posts: 11
Joined: Thu Jun 22, 2017 8:00 pm

Re: [SOLVED] Re: Continuing story of SAM9x5 TC driver on Lin

Mon Jul 03, 2017 4:31 pm

blue_z wrote:So you think I'm so absent minded that I lost track of what I had posted four minutes prior?
You have a grand total of two other threads, and you need to use search engines to try to find a post "in your previous thread"?
Hey friend, take it easy.
Thank you very much for your (free) help and I sincerely apologise if I am making stupid questions or if I cannot easily correlate answers that you gave in this other thread.

I took me some time to understand that my copy retrieved from "linux4sam" repository had been tainted behind my back while I was still trying to learn how things worked.

This way I could not associate the more general questions in my first thread with a specific TC question of this post.

Nevertheless, as I told you before, Googling "periodic timer callback in linux kernel" wouldn't take me where I needed.

My apologies again.

Return to “Linux”

Who is online

Users browsing this forum: Google [Bot] and 1 guest