10a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij#ifndef __LINUX_GPIO_MACHINE_H 20a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij#define __LINUX_GPIO_MACHINE_H 30a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij 4b3ea074fd3c798bee861aa076dc2f873461ae26fAlexandre Courbot#include <linux/types.h> 5b3ea074fd3c798bee861aa076dc2f873461ae26fAlexandre Courbot#include <linux/list.h> 6b3ea074fd3c798bee861aa076dc2f873461ae26fAlexandre Courbot 70a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleijenum gpio_lookup_flags { 80a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij GPIO_ACTIVE_HIGH = (0 << 0), 90a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij GPIO_ACTIVE_LOW = (1 << 0), 100a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij GPIO_OPEN_DRAIN = (1 << 1), 110a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij GPIO_OPEN_SOURCE = (1 << 2), 120a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij}; 130a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij 140a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij/** 150a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij * struct gpiod_lookup - lookup table 160a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij * @chip_label: name of the chip the GPIO belongs to 170a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij * @chip_hwnum: hardware number (i.e. relative to the chip) of the GPIO 180a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij * @con_id: name of the GPIO from the device's point of view 190a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij * @idx: index of the GPIO in case several GPIOs share the same name 200a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij * @flags: mask of GPIO_* values 210a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij * 220a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij * gpiod_lookup is a lookup table for associating GPIOs to specific devices and 230a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij * functions using platform data. 240a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij */ 250a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleijstruct gpiod_lookup { 260a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij const char *chip_label; 270a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij u16 chip_hwnum; 280a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij const char *con_id; 290a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij unsigned int idx; 300a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij enum gpio_lookup_flags flags; 310a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij}; 320a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij 330a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleijstruct gpiod_lookup_table { 340a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij struct list_head list; 350a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij const char *dev_id; 360a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij struct gpiod_lookup table[]; 370a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij}; 380a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij 390a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij/* 400a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij * Simple definition of a single GPIO under a con_id 410a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij */ 420a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij#define GPIO_LOOKUP(_chip_label, _chip_hwnum, _con_id, _flags) \ 430a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij GPIO_LOOKUP_IDX(_chip_label, _chip_hwnum, _con_id, 0, _flags) 440a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij 450a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij/* 460a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij * Use this macro if you need to have several GPIOs under the same con_id. 470a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij * Each GPIO needs to use a different index and can be accessed using 480a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij * gpiod_get_index() 490a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij */ 500a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij#define GPIO_LOOKUP_IDX(_chip_label, _chip_hwnum, _con_id, _idx, _flags) \ 510a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij{ \ 520a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij .chip_label = _chip_label, \ 530a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij .chip_hwnum = _chip_hwnum, \ 540a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij .con_id = _con_id, \ 550a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij .idx = _idx, \ 560a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij .flags = _flags, \ 570a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij} 580a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij 590a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleijvoid gpiod_add_lookup_table(struct gpiod_lookup_table *table); 600a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij 610a6d315827eedc733d404ecff3cd4cc0e6437865Linus Walleij#endif /* __LINUX_GPIO_MACHINE_H */ 62