通過platform data 管理gpio資源--dev
阿新 • • 發佈:2019-01-10
#include <linux/gpio/machine.h> #include <linux/platform_device.h> #include "board.h" #include "head.h" struct gpiod_lookup_table gpios_table = { .dev_id = "mydev_gpio", .table = { GPIO_LOOKUP_IDX("gpio.0", 15, "led", 0, GPIO_ACTIVE_HIGH), GPIO_LOOKUP_IDX("gpio.0", 16, "led", 1, GPIO_ACTIVE_HIGH), GPIO_LOOKUP_IDX("gpio.0", 17, "led", 2, GPIO_ACTIVE_HIGH), GPIO_LOOKUP("gpio.0", 1, "power", GPIO_ACTIVE_LOW), { }, }, }; static struct mydev_gpio_platform_data mydev_platform_data = { .name = "mydev", .type = MYDEV_TYPE_FIRST, }; static struct platform_device mydev_device = { .name = "mydev_gpio", .id = -1, .dev = { .platform_data = &mydev_platform_data, }, }; int __init mydev_init(void) { gpiod_add_lookup_table(&gpios_table); platform_device_register(&mydev_device); }