在linux2.6.38中提供了统一管理外部io的模块。本文的内容是跟踪这些模块,是如何关联起来的。
环境:龙芯1b开发板
一、重点关注的相关的结构体:
gpiolib.c文件,被移植到driver/gpio/目录下。
structgpio_desc {
structgpio_chip *chip;
unsignedlong flags;
#defineFLAG_REQUESTED 0
#defineFLAG_IS_OUT 1
#defineFLAG_RESERVED 2
#defineFLAG_EXPORT 3
#defineFLAG_SYSFS 4
#defineFLAG_TRIG_FALL 5
#defineFLAG_TRIG_RISE 6
#defineFLAG_ACTIVE_LOW 7
#defineID_SHIFT 16
#defineGPIO_FLAGS_MASK ((1 << ID_SHIFT) - 1)
#defineGPIO_TRIGGER_MASK (BIT(FLAG_TRIG_FALL) | BIT(FLAG_TRIG_RISE))
#ifdefCONFIG_DEBUG_FS
constchar *label;
#endif
};
对于上面这个结构体,现在只关心structgpio_chip *chip;
structgpio_chip {
constchar *label;
structdevice *dev;
structmodule *owner;
int (*request)(struct gpio_chip *chip,
unsignedoffset);
void (*free)(struct gpio_chip *chip,
unsignedoffset);
int (*direction_input)(struct gpio_chip *chip,
unsignedoffset);
int (*get)(struct gpio_chip *chip,
unsignedoffset);
int (*direction_output)(struct gpio_chip *chip,
unsignedoffset, int value);
int (*set_debounce)(struct gpio_chip *chip,
unsignedoffset, unsigned debounce);
void (*set)(struct gpio_chip *chip,
unsignedoffset, int value);
int (*to_irq)(struct gpio_chip *chip,
unsignedoffset);