Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dt-binding for timers #20262

Closed
maxvankessel opened this issue Oct 31, 2019 · 5 comments
Closed

dt-binding for timers #20262

maxvankessel opened this issue Oct 31, 2019 · 5 comments
Assignees
Labels
area: Devicetree Enhancement Changes/Updates/Additions to existing features

Comments

@maxvankessel
Copy link
Contributor

I can' t wrap my head around the timer binding.

Currently I'm developing on a STM32F4 soc. And using the timer for multiple things.
So I've created an out-of-tree timer driver to support reading HALL sensors (which is a feature of the timer)
I've also supported the advanced timer functionality of the timer to drive a motor.

But every time I copy code from driver to driver to do the same thing, like get_cycles_per_sec to read absolute motor speed.

Normal procedure would be to ask the base what the tick rate is.
But the stm32 timer has no module.

I do not mind creating code out-of-tree, actually I find it liberating. But the extensibility of the timer-binding is a bit unnatural. Its not as natural as the spi-controller spi-device bindings, e.g.

&spi4 {
	status = "okay";
	cs-gpios = <&gpioe 4 0> , <&gpioe 3 0>;
	drv0: drv832x@0 {
		compatible = "ti,drv832x";
		reg = <0>;
		spi-max-frequency = <1000000>;
		label = "DRIVE";
		fault-gpios = <&gpioe 15 (GPIO_INT | GPIO_INT_EDGE)>;
		calibration-gpios = <&gpioe 14 GPIO_DIR_OUT>;
	};

	drv1: drv832x@1 {
		compatible = "ti,drv832x";
		reg = <1>;
		spi-max-frequency = <1000000>;
		label = "LEVEL";
		fault-gpios = <&gpioc 4 (GPIO_INT | GPIO_INT_EDGE)>;
		calibration-gpios = <&gpioc 5 GPIO_DIR_OUT>;
	};
};

This way, the (bridge-)driver does know on which bus its working.

So timer2 has 4 channels, and I'm using only three of the hall driver, but I would like to know what my who parent is and use parent specific functions. And use the instances instead of using the dts_fixups.h

&timers2 {
	status = "okay";
	hall {
		compatible = "st,stm32-hall";
		label = "DRIVE_HALL";
		interrupts = <28 0>;
		interrupt-names = "global";
		st,in-gpios = <&gpiob 10 GPIO_DIR_IN>, <&gpiob 9 GPIO_DIR_IN>, <&gpiob 8 GPIO_DIR_IN>;
		st,prescaler = <8>;
		st,filter = <0>;
		st,commutation = <0>;
		st,polarity = "both";
		status = "okay";
	};
};

Maybe throw in a #address-cells and size, to make a relative offset. Something like this

And eventually support something like this:

&timers2 {
	status = "okay";
	st,prescaler = <0>;

	pwm: pwm@0{
		compatible = "st,stm32-pwm";
		reg = <0 3>;
		status = "okay";
	};

	capture: cap@3 {
		compatible = "st,stm32-capture";
		reg = <3 1>;
		status = "okay";
	};
};

Side note: capture would then be part of the iio drivers.

My goal is to start a discussion, maybe it's already on the agenda, then I would like to know where I could find more information.

Thanks

@maxvankessel maxvankessel added the Enhancement Changes/Updates/Additions to existing features label Oct 31, 2019
@maxvankessel
Copy link
Contributor Author

This is what I've come up with so far:

&timers5 {
	status = "okay";

	timer {
		#address-cells = <1>;
		#size-cells = <0>;
		compatible = "st,stm32-cc-timer";
		label = "SYNC";
		st,master-slave-mode;
		st,slave-mode = <4>;			/* Reset timer */
		st,slave-trigger-in = <0>;		/* ITR0 */
		status = "okay";

		compare: cc1@0 {
			reg = <0>;			/* channel 1 */
			compatible = "st,stm32-compare";
			label = "TIM5_CC1";
			status = "okay";
		};
	};
};

It has a timer-controller.yaml and a timer-device.yaml But it still is a timer inside a timer which uses dts-fixups

@erwango
Copy link
Member

erwango commented Dec 16, 2020

@maxvankessel, I'd suggest to have a look to latest timers/pwm bindings. I think this should answer your querry.
I'm closing the point for now. Feel free to reopen if needed.

@erwango erwango closed this as completed Dec 16, 2020
@krebsbstn
Copy link

I wanted to use the functionality of master/slave modes on an stm32-h7a3zi-q.
I tougth I found the correct solution when i ran over this issue,
but I had to realize that the suggestions made by @maxvankessel have never been merged to zephyr master.
Even though this is needed to get two PWMs into sync.

@erwango
As your comment suggests, there is another way of synchronizing two timers to get aligned PWMs?

The Datasheet of STM32-H7A2ZI-Q tells there is the "Timer Link feature" avalible.
Could you please point out how to sync the PWMs via dts?

@erwango
Copy link
Member

erwango commented Nov 23, 2022

@krebsbstn This issue is 3 years old. Lot of things changed during this time. Please open a new issue describing your need.

@krebsbstn
Copy link

@krebsbstn This issue is 3 years old. Lot of things changed during this time. Please open a new issue describing your need.

Done, can be found here: #52490

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Devicetree Enhancement Changes/Updates/Additions to existing features
Projects
None yet
Development

No branches or pull requests

6 participants