linux 内核gpio驱动,Linux下GPIO驱动模型

struct gpio_desc {

struct gpio_chip *chip;

unsigned long flags;

#define FLAG_REQUESTED 0

#define FLAG_IS_OUT 1

#define FLAG_RESERVED 2

#define FLAG_EXPORT 3

#define FLAG_SYSFS 4

#ifdef CONFIG_DEBUG_FS

const char *label;

#endif

};

**

* struct gpio_chip

- abstract a GPIO controller

* @label: for

diagnostics

* @dev: optional

device providing the GPIOs

* @owner: helps

prevent removal of modules exporting active GPIOs

* @request:

optional hook for chip-specific activation, such as

* enabling module

power and clock; may sleep

* @free: optional

hook for chip-specific deactivation, such as

* disabling module

power and clock; may sleep

*

@direction_input: configures signal "offset" as input, or returns

error

* @get: returns

value for signal "offset"; for output signals this

* returns either

the value actually sensed, or zero

*

@direction_output: configures signal "offset" as output, or returns

error

* @set: assigns

output value for signal "offset"

* @to_irq:

optional hook supporting non-static gpio_to_irq() mappings;

* implementation

may not sleep

* @dbg_show:

optional routine to show contents in debugfs; default code

* will be used

when this is omitted, but custom code can show extra

* state (such as

pullup/pulldown configuration).

* @base:

identifies the first GPIO number handled by this chip; or, if

* negative during

registration, requests dynamic ID allocation.

* @ngpio: the

number of GPIOs handled by this controller; the last GPIO

* handled is (base

+ ngpio - 1).

* @can_sleep: flag

must be set iff get()/set() methods sleep, as they

* must while

accessing GPIO expander chips over I2C or SPI

*

* A gpio_chip can

help platforms abstract various sources of GPIOs so

* they can all be

accessed through a common programing interface.

* Example sources

would be SOC controllers, FPGAs, multifunction

* chips, dedicated

GPIO expanders, and so on.

*

* Each chip

controls a number of signals, identified in method calls

* by "offset"

values in the range 0..(@ngpio - 1).  When those

signals

* are referenced

through calls like gpio_get_value(gpio), the offset

* is calculated by

subtracting @base from the gpio number.

*

struct gpio_chip {

const char *label;

struct device *dev;

struct module *owner;

int (*request)(struct gpio_chip

*chip,

unsigned offset);

void (*free)(struct gpio_chip

*chip,

unsigned offset);

int (*direction_input)(struct

gpio_chip *chip,

unsigned offset);

int (*get)(struct gpio_chip

*chip,

unsigned offset);

int (*direction_output)(struct

gpio_chip *chip,

unsigned offset, int value);

void (*set)(struct gpio_chip

*chip,

unsigned offset, int value);

int (*to_irq)(struct gpio_chip

*chip,

unsigned offset);

void (*dbg_show)(struct seq_file

*s,

struct gpio_chip *chip);

int base;

u16 ngpio;

unsigned can_sleep:1;

unsigned exported:1;

};

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值