gpio-descriptor-based

 https://github.com/PacktPublishing/Linux-Device-Drivers-Development/blob/master/Chapter14/gpio-descriptor-module.c

https://www.embedded.com/linux-device-driver-development-the-descriptor-based-gpio-interface/




struct gpio_chip {

const char *label;

struct gpio_device *gpiodev;

struct device *parent;

struct fwnode_handle *fwnode;

struct module *owner;


int (*request)(struct gpio_chip *gc, unsigned int offset);

void (*free)(struct gpio_chip *gc, unsigned int offset);

int (*get_direction)(struct gpio_chip *gc, unsigned int offset);

int (*direction_input)(struct gpio_chip *gc, unsigned int offset);

int (*direction_output)(struct gpio_chip *gc,  unsigned int offset, int value);

int (*get)(struct gpio_chip *gc, unsigned int offset);

int (*get_multiple)(struct gpio_chip *gc, unsigned long *mask, unsigned long *bits);

void (*set)(struct gpio_chip *gc, unsigned int offset, int value);

void (*set_multiple)(struct gpio_chip *gc, unsigned long *mask, unsigned long *bits);

int (*set_config)(struct gpio_chip *gc, unsigned int offset, unsigned long config);

int (*to_irq)(struct gpio_chip *gc, unsigned int offset);


void (*dbg_show)(struct seq_file *s, struct gpio_chip *gc);


int (*init_valid_mask)(struct gpio_chip *gc,  unsigned long *valid_mask,  unsigned int ngpios);


int (*add_pin_ranges)(struct gpio_chip *gc);


int (*en_hw_timestamp)(struct gpio_chip *gc,  u32 offset, unsigned long flags);

int (*dis_hw_timestamp)(struct gpio_chip *gc, u32 offset, unsigned long flags);

int base;

u16 ngpio;

u16 offset;

const char *const *names;

    struct gpio_irq_chip irq;


* Number of cells used to form the GPIO specifier.

*/

unsigned int of_gpio_n_cells;


bool can_sleep;

.

.

.

};


struct gpio_desc {

struct gpio_chip *chip;

unsigned long flags;

const char *label;

};



gpiod_to_irq() can be used to get the IRQ number that corresponds to a GPIO descriptor mapped to IRQ, the resulting IRQ number can be used with the request_irq()



foo_device {

compatible = "packt,gpio-descriptor-sample";

led-gpios = <&gpio2 15 GPIO_ACTIVE_HIGH>, // red

<&gpio2 16 GPIO_ACTIVE_HIGH>, // green

btn1-gpios = <&gpio2 1 GPIO_ACTIVE_LOW>;

btn2-gpios = <&gpio2 31 GPIO_ACTIVE_LOW>;

};


static int my_pdrv_probe (struct platform_device *pdev)

{

int retval;

struct device *dev = &pdev->dev;

red = devm_gpiod_get_index(dev, "led", 0,GPIOD_OUT_LOW);

green = devm_gpiod_get_index(dev, "led", 1,GPIOD_OUT_LOW);


/* Configure GPIO Buttons as input */

btn1 = devm_gpiod_get(dev, "led", 0, GPIOD_IN);

btn2 = devm_gpiod_get(dev, "led", 1, GPIOD_IN);


irq = gpiod_to_irq(btn1);


retval = devm_request_threaded_irq(dev, irq, NULL,btn1_pushed_irq_handler,IRQF_TRIGGER_LOW | IRQF_ONESHOT,"gpio-descriptor-sample", NULL);


pr_info("Hello! device probed!\n");

return 0;

}

Comments

Popular posts from this blog

dev_get_platdata understanding

Getting started with pinctrl subsystem linux

How to take systrace in android