1 /* 2 * OF helpers for the GPIO API 3 * 4 * Copyright (c) 2007-2008 MontaVista Software, Inc. 5 * 6 * Author: Anton Vorontsov <avorontsov@ru.mvista.com> 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or 11 * (at your option) any later version. 12 */ 13 14 #ifndef __LINUX_OF_GPIO_H 15 #define __LINUX_OF_GPIO_H 16 17 #include <linux/errno.h> 18 #include <linux/gpio.h> 19 20 #ifdef CONFIG_OF_GPIO 21 22 /* 23 * Generic OF GPIO chip 24 */ 25 struct of_gpio_chip { 26 struct gpio_chip gc; 27 int gpio_cells; 28 int (*xlate)(struct of_gpio_chip *of_gc, struct device_node *np, 29 const void *gpio_spec); 30 }; 31 32 static inline struct of_gpio_chip *to_of_gpio_chip(struct gpio_chip *gc) 33 { 34 return container_of(gc, struct of_gpio_chip, gc); 35 } 36 37 /* 38 * OF GPIO chip for memory mapped banks 39 */ 40 struct of_mm_gpio_chip { 41 struct of_gpio_chip of_gc; 42 void (*save_regs)(struct of_mm_gpio_chip *mm_gc); 43 void __iomem *regs; 44 }; 45 46 static inline struct of_mm_gpio_chip *to_of_mm_gpio_chip(struct gpio_chip *gc) 47 { 48 struct of_gpio_chip *of_gc = to_of_gpio_chip(gc); 49 50 return container_of(of_gc, struct of_mm_gpio_chip, of_gc); 51 } 52 53 extern int of_get_gpio(struct device_node *np, int index); 54 extern int of_mm_gpiochip_add(struct device_node *np, 55 struct of_mm_gpio_chip *mm_gc); 56 extern int of_gpio_simple_xlate(struct of_gpio_chip *of_gc, 57 struct device_node *np, 58 const void *gpio_spec); 59 #else 60 61 /* Drivers may not strictly depend on the GPIO support, so let them link. */ 62 static inline int of_get_gpio(struct device_node *np, int index) 63 { 64 return -ENOSYS; 65 } 66 67 #endif /* CONFIG_OF_GPIO */ 68 69 #endif /* __LINUX_OF_GPIO_H */ 70