Skip to contentSkip to conversation

MPC52xx simple GPIO support

DISCUSSION Stefan Strobl 5 participants 8 messages Jun 2, 2009 – Jun 12, 2009

lore
Share & tools
lore
#0 lore raw

Hi
I still don't quite understand how to use the Flattened Device Tree / Open Firmware. I see there's a driver (mpc52xx_gpt.c) that supports to use the Pins on the GPT as simple GPIOs. I activated it by adding these lines to my dts file:

gpt2: timer@620 {
	compatible = "fsl,mpc5200b-gpt-gpio","fsl,mpc5200-gpt-gpio";
	reg = <0x620 0x10>;
	interrupts = <1 11 0>;
	gpio-controller;
	#gpio-cells = <2>;
};

I can see the appropriate entries in sysfs (/sys/devices/f0000000.soc5200/f0000620.timer), but how can I actually use these GPIO's now?

Many thanks
Stefan.

#1 lore raw

Hi Stefan,

Quoted 14 lines · Stefan Strobl

Hi
I still don't quite understand how to use the Flattened Device Tree / Open Firmware. I see there's a driver (mpc52xx_gpt.c) that supports to use the Pins on the GPT as simple GPIOs. I activated it by adding these lines to my dts file:

gpt2: timer@620 {
	compatible = "fsl,mpc5200b-gpt-gpio","fsl,mpc5200-gpt-gpio";
	reg = <0x620 0x10>;
	interrupts = <1 11 0>;
	gpio-controller;
	#gpio-cells = <2>;
};
Quoted 3 lines

I can see the appropriate entries in sysfs (/sys/devices/f0000000.soc5200/f0000620.timer), but how can I actually use these GPIO's now?

For in-kernel usage example you can take a look at:
arch/powerpc/boot/dts/mpc836x_rdk.dts (upm node, notice gpios = <>) drivers/mtd/nand/fsl_upm.c (of_get_gpio() then gpio_request()).

For userland usage you need to enable CONFIG_GPIO_SYSFS, and then look into /sys/class/gpio/{gpiochip,export,gpioNNN}.

Signature · 3 lines
Anton Vorontsov
email: [email protected]
irc://irc.freenode.net/bd2
#2 lore raw
Quoted 12 lines · Anton Vorontsov

Hi Stefan,

Quoted 8 lines · Stefan Strobl

Hi
I still don't quite understand how to use the Flattened Device Tree / Open Firmware. I see there's a driver (mpc52xx_gpt.c) that supports to use the Pins on the GPT as simple GPIOs.

I can see the appropriate entries in sysfs (/sys/devices/f0000000.soc5200/f0000620.timer), but how can I actually use these GPIO's now?

Quoted 7 lines

For in-kernel usage example you can take a look at:
arch/powerpc/boot/dts/mpc836x_rdk.dts (upm node, notice gpios = <>) drivers/mtd/nand/fsl_upm.c (of_get_gpio() then gpio_request()).

For userland usage you need to enable CONFIG_GPIO_SYSFS, and then look into /sys/class/gpio/{gpiochip,export,gpioNNN}.

Thanks. With CONFIG_GPIO_SYSFS I can see the gpios as you mentioned, but cannot change its state there.

I've now also added CONFIG_LEDS_GPIO and was able to connect the GPIOs to LEDs like this:

gpt2: timer@620 {
	compatible = "fsl,mpc5200b-gpt-gpio","fsl,mpc5200-gpt-gpio";
	reg = <0x620 0x10>;
	interrupts = <1 11 0>;
	gpio-controller;
	#gpio-cells = <2>;
};
leds {
	compatible = "gpio-leds";
	dbg {
		label = "DbgLED";
		gpios = <&gpt2 0 1>; /* Active low */
		linux,default-trigger = "heartbeat";
	};
};

I can now manipulate the state of the LED in /sys/class/led/DbgLED/, which is cool.

The led class provides support for setting the brightness, which obviously the gpio driver doesn't support. The hardware (mpc52xx_gpt) would support it in PWM mode though. I'm now wandering how this could be best implemented.

1) - Create some PWM class similar to the GPIO class
- Add support for PWM mode in mpc52xx_gpt.c that uses that PWM class
- And add an interface for the LED to use the PWM class

2) - Create an LED driver that accesses the mpc52xx_gpt directly.

I think I would be overwhelmed trying to implement (1) but am confident to do (2). What do you think is the right approach?

Cheers, Stefan.

#3 lore raw

PWM class? (was: Re: MPC52xx simple GPIO support)

On Wed, Jun 03, 2009 at 02:42:26PM +0200, Stefan Strobl wrote:
[...]

Quoted 5 lines

The led class provides support for setting the brightness, which obviously the gpio driver doesn't support. The hardware (mpc52xx_gpt) would support it in PWM mode though. I'm now wandering how this could be best implemented.

Quoted 8 lines

1) - Create some PWM class similar to the GPIO class
- Add support for PWM mode in mpc52xx_gpt.c that uses that PWM class
- And add an interface for the LED to use the PWM class

2) - Create an LED driver that accesses the mpc52xx_gpt directly.

I think I would be overwhelmed trying to implement (1) but am confident to do (2). What do you think is the right approach?

I'd suggest creating a generic PWM class, i.e. PWMLIB, alike to GPIOLIB. (2) can be an acceptable approach for now, but for the long-term solution (1) is the way to go.

The non-lib PWM API is already there, see include/linux/pwm.h, and arch/arm/mach-pxa/pwm.c as an implementation example.

Note that PXA implementation is SOC-specific, which is not very good.

So I'd suggest creating drivers/pwm/pwmlib.c, borrowing ideas from gpiolib. And then we can reuse drivers/leds/leds-pwm.c driver (of course, after adding appropriate OF code into it).

Sure, as you've said, it could be quite boringly to implement, could take quite some time to pass all review cycles etc. But someday someone will have to do this. :-)

Signature · 3 lines
Anton Vorontsov
email: [email protected]
irc://irc.freenode.net/bd2
#4 lore raw

Re: PWM class? (was: Re: MPC52xx simple GPIO support)

Quoted 11 lines · Anton Vorontsov

On Wed, Jun 03, 2009 at 02:42:26PM +0200, Stefan Strobl wrote:
[...]

Quoted 9 lines

The led class provides support for setting the brightness, which obviously the gpio driver doesn't support. The hardware (mpc52xx_gpt) would support it in PWM mode though. I'm now wandering how this could be best implemented.

1) - Create some PWM class similar to the GPIO class
   - Add support for PWM mode in mpc52xx_gpt.c that uses that PWM class
   - And add an interface for the LED to use the PWM class

Quoted 8 lines
Quoted 4 lines

2) - Create an LED driver that accesses the mpc52xx_gpt directly.

I think I would be overwhelmed trying to implement (1) but am confident to do (2). What do you think is the right approach?

I'd suggest creating a generic PWM class, i.e. PWMLIB, alike to GPIOLIB. (2) can be an acceptable approach for now, but for the long-term solution (1) is the way to go.

What happened to this one?

http://ozlabs.org/pipermail/linuxppc-dev/2008-October/063562.html

Quoted 25 lines

The non-lib PWM API is already there, see include/linux/pwm.h, and arch/arm/mach-pxa/pwm.c as an implementation example.

Note that PXA implementation is SOC-specific, which is not very good.

So I'd suggest creating drivers/pwm/pwmlib.c, borrowing ideas from gpiolib. And then we can reuse drivers/leds/leds-pwm.c driver (of course, after adding appropriate OF code into it).

Sure, as you've said, it could be quite boringly to implement, could take quite some time to pass all review cycles etc. But someday someone will have to do this. :-)

--
Anton Vorontsov
email: [email protected]
irc://irc.freenode.net/bd2
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Signature · 2 lines
Jon Smirl
[email protected]
#5 lore raw

Re: PWM class? (was: Re: MPC52xx simple GPIO support)

Hi Jon,

Quoted 7 lines · Jon Smirl
Quoted 5 lines · Anton Vorontsov

On Wed, Jun 03, 2009 at 02:42:26PM +0200, Stefan Strobl wrote:
[...]

Quoted 3 lines

The led class provides support for setting the brightness, which obviously the gpio driver doesn't support. The hardware (mpc52xx_gpt) would support it in PWM mode though. I'm now wandering how this could b=

e

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

best implemented.

1) - Create some PWM class similar to the GPIO class
=A0 =A0- Add support for PWM mode in mpc52xx_gpt.c that uses that PWM c=

lass

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

=A0 =A0- And add an interface for the LED to use the PWM class

2) - Create an LED driver that accesses the mpc52xx_gpt directly.

I think I would be overwhelmed trying to implement (1) but am confident to do (2). What do you think is the right approach?

Quoted 8 lines
Quoted 3 lines

I'd suggest creating a generic PWM class, i.e. PWMLIB, alike to GPIOLIB. (2) can be an acceptable approach for now, but for the long-term solution (1) is the way to go.

What happened to this one?

http://ozlabs.org/pipermail/linuxppc-dev/2008-October/063562.html

Adding Bill to see if he has any updates.

--=20
---Trilok Soni
http://triloksoni.wordpress.com
http://www.linkedin.com/in/triloksoni

#6 lore raw

Re: PWM class? (was: Re: MPC52xx simple GPIO support)

In reply to Anton Vorontsov

On Wed, Jun 3, 2009 at 7:22 AM, Anton Vorontsov<[email protected]> w= rote:

Quoted 9 lines · Stefan Strobl

[...]

Quoted 7 lines

The led class provides support for setting the brightness, which obviously the gpio driver doesn't support. The hardware (mpc52xx_gpt) would support it in PWM mode though. I'm now wandering how this could be best implemented.

1) - Create some PWM class similar to the GPIO class
=A0 =A0- Add support for PWM mode in mpc52xx_gpt.c that uses that PWM cl=

ass

Quoted 14 lines
Quoted 6 lines

=A0 =A0- And add an interface for the LED to use the PWM class

2) - Create an LED driver that accesses the mpc52xx_gpt directly.

I think I would be overwhelmed trying to implement (1) but am confident to do (2). What do you think is the right approach?

I'd suggest creating a generic PWM class, i.e. PWMLIB, alike to GPIOLIB. (2) can be an acceptable approach for now, but for the long-term solution (1) is the way to go.

The non-lib PWM API is already there, see include/linux/pwm.h, and arch/arm/mach-pxa/pwm.c as an implementation example.

Quoted 6 lines

Note that PXA implementation is SOC-specific, which is not very good.

So I'd suggest creating drivers/pwm/pwmlib.c, borrowing ideas from gpiolib. And then we can reuse drivers/leds/leds-pwm.c driver (of course, after adding appropriate OF code into it).

Ugh. The referenced pwm api is about as trivial as it gets; it is an anonymous context pointer (anonymous struct pwm_device *) with a set of accessor functions. PWMs are also not nearly as common as GPIO pins, and I am not interested in gpiolib being duplicated for PWMs, at least not until there are more that just two examples of use to draw from.

If anything, I'd rather struct pwm_device be non-anonymous and contain a set of ops which call directly into the driver. That way is at least multiplatform friendly. I don't think the gpio API is the example to follow here. But even then I think it is premature to try and define a PWM api. Personally, I'd modify mpc52xx_gpt to export its own PWM interface for the time being using the existing GPIO infrastructure to find the appropriate pin.

If you do decide to do a generic PWM api, then I think the way to go is to build it as an extension to gpiolib.

Cheers,
g.

--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

#7 lore raw

Re: PWM class? (was: Re: MPC52xx simple GPIO support)

Quoted 31 lines · Grant Likely
Quoted 23 lines · Anton Vorontsov

On Wed, Jun 03, 2009 at 02:42:26PM +0200, Stefan Strobl wrote:
[...]

Quoted 5 lines

The led class provides support for setting the brightness, which obviously the gpio driver doesn't support. The hardware (mpc52xx_gpt) would support it in PWM mode though. I'm now wandering how this could be best implemented.

Quoted 8 lines

1) - Create some PWM class similar to the GPIO class
   - Add support for PWM mode in mpc52xx_gpt.c that uses that PWM class
   - And add an interface for the LED to use the PWM class

2) - Create an LED driver that accesses the mpc52xx_gpt directly.

I think I would be overwhelmed trying to implement (1) but am confident to do (2). What do you think is the right approach?

I'd suggest creating a generic PWM class, i.e. PWMLIB, alike to GPIOLIB. (2) can be an acceptable approach for now, but for the long-term solution (1) is the way to go.

The non-lib PWM API is already there, see include/linux/pwm.h, and arch/arm/mach-pxa/pwm.c as an implementation example.

Quoted 6 lines

Note that PXA implementation is SOC-specific, which is not very good.

So I'd suggest creating drivers/pwm/pwmlib.c, borrowing ideas from gpiolib. And then we can reuse drivers/leds/leds-pwm.c driver (of course, after adding appropriate OF code into it).

Quoted 6 lines

Ugh. The referenced pwm api is about as trivial as it gets; it is an anonymous context pointer (anonymous struct pwm_device *) with a set of accessor functions. PWMs are also not nearly as common as GPIO pins, and I am not interested in gpiolib being duplicated for PWMs, at least not until there are more that just two examples of use to draw from.

I didn't say that we should duplicate gpiolib. I said that we might borrow some ideas. ;-)

Quoted 7 lines

If anything, I'd rather struct pwm_device be non-anonymous and contain a set of ops which call directly into the driver. That way is at least multiplatform friendly. I don't think the gpio API is the example to follow here. But even then I think it is premature to try and define a PWM api. Personally, I'd modify mpc52xx_gpt to export its own PWM interface for the time being using the existing GPIO infrastructure to find the appropriate pin.

Jon Smirl found that there were already some efforts put into making generic PWM class:

http://thread.gmane.org/gmane.linux.kernel.embedded/1160

Briefly looking, the class is pretty cool. Somebody should just continue this work.

Quoted 2 lines

If you do decide to do a generic PWM api, then I think the way to go is to build it as an extension to gpiolib.

I don't think David Brownell will like this idea. But who knows... maybe.

Thanks,

Signature · 3 lines
Anton Vorontsov
email: [email protected]
irc://irc.freenode.net/bd2