Reputation: 8136
Is this
of_get_named_gpio(child, "gpio-name", 0);
a correct way to get the GPIO number? Where the corresponding device tree is as below:
gpio-name = <&gpio0 21 0>;
I get this error:
probe of failed with error -2
What does error code -2
represents? Is this a device tree parsing error?
Upvotes: 2
Views: 7620
Reputation: 11
This snap-shot of the code shows how to get/set the particular GPIO. it is a tested code.
struct device_node *np = client->dev.of_node;
int gpio;
u8 buf[MAX_I2C_DATA_LEN];
int ret, tries = 0;
if (!np)
return -ENODEV;
gpio = of_get_named_gpio(np, "**gpio-name-used-in-dts-file**", 0);
if (!gpio_is_valid(gpio))
return -ENODEV;
ret = gpio_request(gpio, "egalax_irq");
if (ret < 0) {
dev_err(&client->dev,
"request gpio failed, cannot wake up controller: %d\n",ret);
return ret;
}
gpio_direction_output(gpio, 1);
ret = gpio_get_value(gpio);
""ret"" Will have gpio value.
Upvotes: 1