Right way to get the gpio values from the device tree in the device driver

Raul Piper raulpblooper at gmail.com
Thu Aug 18 06:42:13 EDT 2016


Hello,

With reference to the example below what is the correct way to get the gpio
values from the device tree :

I modified the existing leds-ns2 device tree as below :



          blue-sata {

                   label = "ns2:blue:sata";

                   slow-gpio = <&gpio0 29 0>;

                   cmd-gpio = <&gpio0 30 0>;

+                 slow1-gpio=<&gpio 31 0>;

+                 cmd1-gpio=<&gpio 32 0>;

                   modes-map = <NS_V2_LED_OFF  0 1

                                NS_V2_LED_ON   1 0

                                NS_V2_LED_ON   0 0

                                NS_V2_LED_SATA 1 1>;

           };





And modified the driver by adding slow1 and cmd1 in all the structure (just
like slow and cmd)

But when I am trying to get the gpio number for slow1 and cmd1 I am getting
the below error(number gpio #31 and 32 are random numbers of gpio for
testing, does it matters?) :

error : leds-ns2:probe of ns2-leds failed with error -2.What does error
code -2 represents ?Is this a device tree parsing error?

ret = of_get_named_gpio(child, "slow1-gpio", 0);

                 if (ret < 0)

                         return ret;

same error if I try to get the cmd1-gpio


Thanks in advance !

Regards,

Rp

On Thu, Aug 4, 2016 at 9:23 AM, Raul Piper <raulpblooper at gmail.com> wrote:
> make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- <name of the dtb file>.dtb
>
> This compiles fine.
>
> On Thu, Aug 4, 2016 at 1:06 AM, Frank Rowand <frowand.list at gmail.com>
wrote:
>> On 07/25/16 04:17, Raul Piper wrote:
>>> Hi,
>>> Where can I find the example for the  dynamic Loading of the device
>>> tree and its corresponding device driver.
>>> How can I build the dts with or without the kernel source.
>>>
>>> I am getting this error whenever I am trying to build the below sample
>>> dts file using the dtc compiler.
>>>
>>> dtc -O dtb -o leds-ns2.dtb leds-ns2.dts
>>>
>>>
>>> Error: leds-ns2.dts:1.1-2 syntax error
>>
>> That is an error at line 1, columns 1-2. dtc does not understand cpp
>> directives, you need to process leds-ns2.dts with cpp. The Linux
>> build infrastructure does this for .dtb targets in makefiles.
>>
>>> FATAL ERROR: Unable to parse input tree
>>>
>>> Below is the content  of the leds-ns2.dts
>>>
>>> #include <dt-bindings/leds/leds-ns2.h>
>>>
>>>  ns2-leds {
>>>           compatible = "lacie,ns2-leds";
>>>
>>>           blue-sata {
>>>                   label = "ns2:blue:sata";
>>>                   slow-gpio = <&gpio0 29 0>;
>>>                   cmd-gpio = <&gpio0 30 0>;
>>>                   modes-map = <NS_V2_LED_OFF  0 1
>>>                                NS_V2_LED_ON   1 0
>>>                                NS_V2_LED_ON   0 0
>>>                                NS_V2_LED_SATA 1 1>;
>>>           };
>>>   };
>>>
>>> Thanks,
>>> R
>>> --
>>> To unsubscribe from this list: send the line "unsubscribe devicetree" in
>>> the body of a message to majordomo at vger.kernel.org
>>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20160818/357e24f7/attachment.html 


More information about the Kernelnewbies mailing list