概述
#include /* DTS
myled{
compatible = "led";
/* led2-5: gpx2_7 gpx1_0 gpf3_4 gpf3_5 *//*
gpios = , , , ;
};
*/
MODULE_LICENSE("Dual BSD/GPL");
MODULE_DESCRIPTION("a simple driver example!");
//create a platform driver
struct resource *res;
int led_pin;
int led_probe(struct platform_device *pdev)
{
int i = 0;
char name_buf[10] = {0};
printk("probe !n");
// 获取DTS:gpios = , , , ;(正式)
for(i = 0; i < 4; i++) {
// 从DTB解析管脚
led_pin = of_get_gpio(pdev->dev.of_node, i);
printk("led-gpio: %dn", led_pin);
sprintf(name_buf, "led%d-pin", i);
devm_gpio_request(&pdev->dev, led_pin, name_buf);
// gpio_request(led_pin, name_buf);
gpio_direction_output(led_pin, 1);
gpio_set_value(led_pin, 1);
}
#if 0
// 获取DTS:reg = <0x11000c40 4>;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
printk("baseaddr: %#xn", res->start);
// 获取DTS:pin = <7>; (非正式)
res = platform_get_resource_byname(pdev, 0, "pin");
printk("pinnum: %#xn", res->start);
#endif
return 0;
}
int led_remove(struct platform_device *pdev)
{
printk("remove !n");
return 0;
}
struct of_device_id led_table[] = {
{.compatible = "led"},
{}
};
struct platform_driver led_driver = {
.probe = led_probe,
.remove = led_remove,
.driver = {
.name = "11000c40.led_node",
.of_match_table = led_table
}
};
static int led_init(void)
{
printk("module installn");
//add into platform bus
platform_driver_register(&led_driver);
return 0;
}
static void led_exit(void)
{
printk("module releasen");
//del from platform bus
platform_driver_unregister(&led_driver);
}
module_init(led_init);
module_exit(led_exit);
最后
以上就是尊敬冬瓜为你收集整理的Linux从设备树取gpio号,linux设备树之gpio的全部内容,希望文章能够帮你解决Linux从设备树取gpio号,linux设备树之gpio所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复