All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* Using gpio from device tree on platform devices.
@ 2015-08-20 20:53 Daniel.
  2015-08-21  6:59 ` victorascroft at gmail.com
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel. @ 2015-08-20 20:53 UTC (permalink / raw
  To: kernelnewbies

Hi all,

I'm trying to migrate a driver from board files to device tree. I've
added the gpios to device tree. My device is loaded automatically,
this is nice, but I'm facing problems while getting gpio from device
tree using of_get_property().


Here is the device tree node:
        powerfailure {
                compatible = "powerfailure";
                poff_pfail  = <&gpio5 12 GPIO_ACTIVE_LOW>;
                irq_pfail   = <&gpio5 17 GPIO_ACTIVE_LOW>;
        };


Here is my driver: http://pastebin.com/4DsRaXMS

A simple description of it. There is a circuit that triggers the
irq_pfail at failure of power supply. The irq handler then start a
clean shutdown. At the end of shutdown pf_power_off to cut the energy
from the device. The logic works fine, but I'm having problems on
pf_probe function. I got this dump:
http://pastebin.com/paTBWwcE

So I think I'm doing something wrong with of_get_property returned
value. I'm using the kernel 3.14.28 from freescale (iMX6 quad core
cpu).

What is the right way to get gpio values from device tree? Is that
of_get_property() lines right?

Thanks in advance,
Cheers

-- dhs


-- 
"Do or do not. There is no try"
  Yoda Master

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Using gpio from device tree on platform devices.
  2015-08-20 20:53 Using gpio from device tree on platform devices Daniel.
@ 2015-08-21  6:59 ` victorascroft at gmail.com
  2015-08-21  7:10   ` victorascroft at gmail.com
  0 siblings, 1 reply; 4+ messages in thread
From: victorascroft at gmail.com @ 2015-08-21  6:59 UTC (permalink / raw
  To: kernelnewbies

On 15-08-20 17:53:27, Daniel. wrote:
> Hi all,
> 
> I'm trying to migrate a driver from board files to device tree. I've
> added the gpios to device tree. My device is loaded automatically,
> this is nice, but I'm facing problems while getting gpio from device
> tree using of_get_property().
> 
> 
> Here is the device tree node:
>         powerfailure {
>                 compatible = "powerfailure";
>                 poff_pfail  = <&gpio5 12 GPIO_ACTIVE_LOW>;
>                 irq_pfail   = <&gpio5 17 GPIO_ACTIVE_LOW>;
>         };

Why reinvent the wheel? May be the below is what you want?
http://lxr.free-electrons.com/source/Documentation/devicetree/bindings/gpio/gpio-poweroff.txt

I would recommend checking first if this works for you. Don't know
what kernel you are using though.

Now coming to what you are trying to do. If you have something like below

poff-pfail-gpios = <&gpio5 12 GPIO_ACTIVE_LOW>;

struct gpio_desc *gpiod;
*gpiod = devm_gpiod_get(&pdev->dev, "poff-pail")

You can then use gpio descriptors in your call gpiod_* calls. Note that

http://lxr.free-electrons.com/source/Documentation/gpio/gpio.txt#L11

the gpio descriptor based interface is recommended and the legacy gpio
number based interface is not recommend to use anymore.

If you still want to stick to extracting information using of_* based
calls I would recommend looking at gpio specific ones.

For example, of_get_named_gpio and such....grep/vgrep for them...

-- Sanchayan.

> 
> 
> Here is my driver: http://pastebin.com/4DsRaXMS
> 
> A simple description of it. There is a circuit that triggers the
> irq_pfail at failure of power supply. The irq handler then start a
> clean shutdown. At the end of shutdown pf_power_off to cut the energy
> from the device. The logic works fine, but I'm having problems on
> pf_probe function. I got this dump:
> http://pastebin.com/paTBWwcE
> 
> So I think I'm doing something wrong with of_get_property returned
> value. I'm using the kernel 3.14.28 from freescale (iMX6 quad core
> cpu).
> 
> What is the right way to get gpio values from device tree? Is that
> of_get_property() lines right?
> 
> Thanks in advance,
> Cheers
> 
> -- dhs
> 
> 
> -- 
> "Do or do not. There is no try"
>   Yoda Master
> 
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Using gpio from device tree on platform devices.
  2015-08-21  6:59 ` victorascroft at gmail.com
@ 2015-08-21  7:10   ` victorascroft at gmail.com
  2015-08-21 14:55     ` Daniel.
  0 siblings, 1 reply; 4+ messages in thread
From: victorascroft at gmail.com @ 2015-08-21  7:10 UTC (permalink / raw
  To: kernelnewbies

On 15-08-21 12:29:49, victorascroft at gmail.com wrote:
> On 15-08-20 17:53:27, Daniel. wrote:
> > Hi all,
> > 
> > I'm trying to migrate a driver from board files to device tree. I've
> > added the gpios to device tree. My device is loaded automatically,
> > this is nice, but I'm facing problems while getting gpio from device
> > tree using of_get_property().
> > 
> > 
> > Here is the device tree node:
> >         powerfailure {
> >                 compatible = "powerfailure";
> >                 poff_pfail  = <&gpio5 12 GPIO_ACTIVE_LOW>;
> >                 irq_pfail   = <&gpio5 17 GPIO_ACTIVE_LOW>;
> >         };
> 
> Why reinvent the wheel? May be the below is what you want?
> http://lxr.free-electrons.com/source/Documentation/devicetree/bindings/gpio/gpio-poweroff.txt
> 
> I would recommend checking first if this works for you. Don't know
> what kernel you are using though.
> 
> Now coming to what you are trying to do. If you have something like below
> 
> poff-pfail-gpios = <&gpio5 12 GPIO_ACTIVE_LOW>;
> 
> struct gpio_desc *gpiod;
> *gpiod = devm_gpiod_get(&pdev->dev, "poff-pail")
> 
> You can then use gpio descriptors in your call gpiod_* calls. Note that
> 
> http://lxr.free-electrons.com/source/Documentation/gpio/gpio.txt#L11
> 
> the gpio descriptor based interface is recommended and the legacy gpio
> number based interface is not recommend to use anymore.
> 
> If you still want to stick to extracting information using of_* based
> calls I would recommend looking at gpio specific ones.
> 
> For example, of_get_named_gpio and such....grep/vgrep for them...
> 
> -- Sanchayan.
> 
> > 
> > 
> > Here is my driver: http://pastebin.com/4DsRaXMS
> > 
> > A simple description of it. There is a circuit that triggers the
> > irq_pfail at failure of power supply. The irq handler then start a
> > clean shutdown. At the end of shutdown pf_power_off to cut the energy
> > from the device. The logic works fine, but I'm having problems on
> > pf_probe function. I got this dump:
> > http://pastebin.com/paTBWwcE
> > 
> > So I think I'm doing something wrong with of_get_property returned
> > value. I'm using the kernel 3.14.28 from freescale (iMX6 quad core
> > cpu).

Sorry my bad I did not come down to this. Did you check the function
prototype of the functions you are calling? I would recommend checking
that.

> > 
> > What is the right way to get gpio values from device tree? Is that
> > of_get_property() lines right?

Use the gpio specific of_* ones?

> > 
> > Thanks in advance,
> > Cheers
> > 
> > -- dhs
> > 
> > 
> > -- 
> > "Do or do not. There is no try"
> >   Yoda Master
> > 
> > _______________________________________________
> > Kernelnewbies mailing list
> > Kernelnewbies at kernelnewbies.org
> > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Using gpio from device tree on platform devices.
  2015-08-21  7:10   ` victorascroft at gmail.com
@ 2015-08-21 14:55     ` Daniel.
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel. @ 2015-08-21 14:55 UTC (permalink / raw
  To: kernelnewbies

Hi Victor, the of_get_named_gpio works fine. Thank you so much!

I'll take a look at gpio-poweroff, this should cut my code by half :)

Best regards,
- dhs

2015-08-21 4:10 GMT-03:00  <victorascroft@gmail.com>:
> On 15-08-21 12:29:49, victorascroft at gmail.com wrote:
>> On 15-08-20 17:53:27, Daniel. wrote:
>> > Hi all,
>> >
>> > I'm trying to migrate a driver from board files to device tree. I've
>> > added the gpios to device tree. My device is loaded automatically,
>> > this is nice, but I'm facing problems while getting gpio from device
>> > tree using of_get_property().
>> >
>> >
>> > Here is the device tree node:
>> >         powerfailure {
>> >                 compatible = "powerfailure";
>> >                 poff_pfail  = <&gpio5 12 GPIO_ACTIVE_LOW>;
>> >                 irq_pfail   = <&gpio5 17 GPIO_ACTIVE_LOW>;
>> >         };
>>
>> Why reinvent the wheel? May be the below is what you want?
>> http://lxr.free-electrons.com/source/Documentation/devicetree/bindings/gpio/gpio-poweroff.txt
>>
>> I would recommend checking first if this works for you. Don't know
>> what kernel you are using though.
>>
>> Now coming to what you are trying to do. If you have something like below
>>
>> poff-pfail-gpios = <&gpio5 12 GPIO_ACTIVE_LOW>;
>>
>> struct gpio_desc *gpiod;
>> *gpiod = devm_gpiod_get(&pdev->dev, "poff-pail")
>>
>> You can then use gpio descriptors in your call gpiod_* calls. Note that
>>
>> http://lxr.free-electrons.com/source/Documentation/gpio/gpio.txt#L11
>>
>> the gpio descriptor based interface is recommended and the legacy gpio
>> number based interface is not recommend to use anymore.
>>
>> If you still want to stick to extracting information using of_* based
>> calls I would recommend looking at gpio specific ones.
>>
>> For example, of_get_named_gpio and such....grep/vgrep for them...
>>
>> -- Sanchayan.
>>
>> >
>> >
>> > Here is my driver: http://pastebin.com/4DsRaXMS
>> >
>> > A simple description of it. There is a circuit that triggers the
>> > irq_pfail at failure of power supply. The irq handler then start a
>> > clean shutdown. At the end of shutdown pf_power_off to cut the energy
>> > from the device. The logic works fine, but I'm having problems on
>> > pf_probe function. I got this dump:
>> > http://pastebin.com/paTBWwcE
>> >
>> > So I think I'm doing something wrong with of_get_property returned
>> > value. I'm using the kernel 3.14.28 from freescale (iMX6 quad core
>> > cpu).
>
> Sorry my bad I did not come down to this. Did you check the function
> prototype of the functions you are calling? I would recommend checking
> that.
>
>> >
>> > What is the right way to get gpio values from device tree? Is that
>> > of_get_property() lines right?
>
> Use the gpio specific of_* ones?
>
>> >
>> > Thanks in advance,
>> > Cheers
>> >
>> > -- dhs
>> >
>> >
>> > --
>> > "Do or do not. There is no try"
>> >   Yoda Master
>> >
>> > _______________________________________________
>> > Kernelnewbies mailing list
>> > Kernelnewbies at kernelnewbies.org
>> > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies



-- 
"Do or do not. There is no try"
  Yoda Master

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-08-21 14:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-20 20:53 Using gpio from device tree on platform devices Daniel.
2015-08-21  6:59 ` victorascroft at gmail.com
2015-08-21  7:10   ` victorascroft at gmail.com
2015-08-21 14:55     ` Daniel.

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.