Using gpio from device tree on platform devices.

Daniel. danielhilst at gmail.com
Fri Aug 21 10:55:38 EDT 2015


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 at 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



More information about the Kernelnewbies mailing list