Using a spare TC 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

Using a spare TC on Linux

Thu Jun 22, 2017 10:41 pm

Hello all.

I will start by apologising myself as I think it is a newbie stupid question.

I have been struggling to understand all stuff from device tree passing through kernel source and trying to reach the processor specifics but I still see no connection between everything in the Linux kernel side and Atmel datasheet for SAM9G25, section 35 - Timer Counter (TC).

So, I will try to make some few objective questions hoping you can help to unstuck me.
  1. Is there an implementation of Atmel TC in Linux kernel?
  2. How can I (easily) tell which resources are being used by kernel and which are being spared?
  3. Finally, any guidances on how to use a spare TC channel for my own purposes?
Additional info:

I am currently developing on a custom board that was based in AT91SAM9x25-EK.
I succeeded to build Yocto and boot this board with minimal customization from the EK.
Now I need to develop a device driver that uses at least one TC channel to control a few stepper motors and it will probably take me to the FIQ in future, but I need to go one step at a time and I am not considering it now.

Any help will be greatly welcome.
blue_z
Location: USA
Posts: 1560
Joined: Thu Apr 19, 2007 10:15 pm

Re: Using a spare TC on Linux

Fri Jun 23, 2017 4:13 am

J4x wrote:I have been struggling to understand all stuff from device tree passing through kernel source and trying to reach the processor specifics but I still see no connection between everything in the Linux kernel side and Atmel datasheet for SAM9G25, section 35 - Timer Counter (TC).
Section 35 describes a single Timer Counter module which comprises three TC channels.

The memory map in Section 5 shows that the SoC has two TC modules, one at 0xF8008000 for channels TC0, TC1, & TC2, and a second module at 0xF800C000 for channels TC3, TC4, & TC5.

In the Device Tree source file at91sam9x5.dtsi, these two memory addresses are attached to the following device nodes:

Code: Select all

        tcb0: timer@f8008000 {
            compatible = "atmel,at91sam9x5-tcb";
            ...
        }
        tcb1: timer@f800c000 {
            compatible = "atmel,at91sam9x5-tcb";
            ...
        }
So clearly both TC modules (aka blocks) (and all six TC channels) are known to the kernel.
The compatible string associates a device driver to these device nodes.

In the kernel source the string "atmel,at91sam9x5-tcb" can be found in drivers/misc/atmel_tclib.c.
The Kconfig entry describes this driver as

Code: Select all

Atmel AT32/AT91 Timer/Counter Library

Select this if you want a library to allocate the Timer/Counter
blocks found on many Atmel processors. This facilitates using
these blocks by different drivers despite processor differences.
The default kernel configuration for AT91SAM9 devices enables this CONFIG_ATMEL_TCLIB.
So clearly this is the interface a driver should be using for managing a TC block/channel.
J4x wrote:Is there an implementation of Atmel TC in Linux kernel?
Sort of.
You probably also need to look into the "TC Block Clocksource", aka CONFIG_ATMEL_TCB_CLKSRC, and the tcb_clksrc.c driver,
and "Atmel TC Block PWM support", aka CONFIG_PWM_ATMEL_TCB, and the pwm-atmel.c driver
J4x wrote:How can I (easily) tell which resources are being used by kernel and which are being spared?
Finally, any guidances on how to use a spare TC channel for my own purposes?
Define "spare".
If you mean "not used or managed by the kernel", then there are no spare blocks/channels with the default DT and kernel configuration.
The programmable timers, ADC and PWM are possible consumers of a TC block/channel.

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

Re: Using a spare TC on Linux

Fri Jun 23, 2017 5:07 am

Hello blue_z.
Thank you very much. Your answer is gold.

A few minutes ago I was `grep`ing the compiled kernel source and could find `tcb0` and `tcb1`.
Strangely it only appeared in "kernel-source/.pc/at91sam9x5.dtsi.patch/arch/arm/boot/dts/at91sam9x5.dtsi".

The file in "kernel-source/arch/arm/boot/dts/at91sam9x5.dtsi" has no mention to tcb's at all (kernel 4.1).
blue_z wrote:
J4x wrote:How can I (easily) tell which resources are being used by kernel and which are being spared?
Finally, any guidances on how to use a spare TC channel for my own purposes?
Define "spare".
If you mean "not used or managed by the kernel", then there are no spare blocks/channels with the default DT and kernel configuration.
The ADC and PWM are possible consumers of a TC block/channel.
By "spare" I mean a resource (timer, to be more specific) that is not being used by the Linux kernel so I won't scramble everything putting my fatty fingers on it while the kernel is trying to do something serious.


I will now try to figure out how to use the functions in "atmel_tclib.c" and Google around.

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

Re: Using a spare TC on Linux

Fri Jun 23, 2017 11:04 pm

J4x wrote:The file in "kernel-source/arch/arm/boot/dts/at91sam9x5.dtsi" has no mention to tcb's at all (kernel 4.1).
Then you have a goofy custom version of the kernel source.
Mainline 4.1 has those tcb nodes, assuming that Free Electrons can be trusted to have an accurate copy.
Even the mainline 3.6 version has those tcb nodes.

FWIW it's bad practice to modify the low-level .dtsi file that represents the generic SoC.
Instead override the generic configuration by redefining the node in the top-level, board-level .dts file.

Regards

Return to “Linux”

Who is online

Users browsing this forum: No registered users and 1 guest