1863fbf49SAnton Vorontsov /* 2863fbf49SAnton Vorontsov * OF helpers for the GPIO API 3863fbf49SAnton Vorontsov * 4863fbf49SAnton Vorontsov * Copyright (c) 2007-2008 MontaVista Software, Inc. 5863fbf49SAnton Vorontsov * 6863fbf49SAnton Vorontsov * Author: Anton Vorontsov <avorontsov@ru.mvista.com> 7863fbf49SAnton Vorontsov * 8863fbf49SAnton Vorontsov * This program is free software; you can redistribute it and/or modify 9863fbf49SAnton Vorontsov * it under the terms of the GNU General Public License as published by 10863fbf49SAnton Vorontsov * the Free Software Foundation; either version 2 of the License, or 11863fbf49SAnton Vorontsov * (at your option) any later version. 12863fbf49SAnton Vorontsov */ 13863fbf49SAnton Vorontsov 14863fbf49SAnton Vorontsov #ifndef __LINUX_OF_GPIO_H 15863fbf49SAnton Vorontsov #define __LINUX_OF_GPIO_H 16863fbf49SAnton Vorontsov 17863fbf49SAnton Vorontsov #include <linux/errno.h> 18863fbf49SAnton Vorontsov #include <asm/gpio.h> 19863fbf49SAnton Vorontsov 20863fbf49SAnton Vorontsov #ifdef CONFIG_OF_GPIO 21863fbf49SAnton Vorontsov 22863fbf49SAnton Vorontsov /* 23863fbf49SAnton Vorontsov * Generic OF GPIO chip 24863fbf49SAnton Vorontsov */ 25863fbf49SAnton Vorontsov struct of_gpio_chip { 26863fbf49SAnton Vorontsov struct gpio_chip gc; 27863fbf49SAnton Vorontsov int gpio_cells; 28863fbf49SAnton Vorontsov int (*xlate)(struct of_gpio_chip *of_gc, struct device_node *np, 29863fbf49SAnton Vorontsov const void *gpio_spec); 30863fbf49SAnton Vorontsov }; 31863fbf49SAnton Vorontsov 32863fbf49SAnton Vorontsov static inline struct of_gpio_chip *to_of_gpio_chip(struct gpio_chip *gc) 33863fbf49SAnton Vorontsov { 34863fbf49SAnton Vorontsov return container_of(gc, struct of_gpio_chip, gc); 35863fbf49SAnton Vorontsov } 36863fbf49SAnton Vorontsov 37863fbf49SAnton Vorontsov /* 38863fbf49SAnton Vorontsov * OF GPIO chip for memory mapped banks 39863fbf49SAnton Vorontsov */ 40863fbf49SAnton Vorontsov struct of_mm_gpio_chip { 41863fbf49SAnton Vorontsov struct of_gpio_chip of_gc; 42863fbf49SAnton Vorontsov void (*save_regs)(struct of_mm_gpio_chip *mm_gc); 43863fbf49SAnton Vorontsov void __iomem *regs; 44863fbf49SAnton Vorontsov }; 45863fbf49SAnton Vorontsov 46863fbf49SAnton Vorontsov static inline struct of_mm_gpio_chip *to_of_mm_gpio_chip(struct gpio_chip *gc) 47863fbf49SAnton Vorontsov { 48863fbf49SAnton Vorontsov struct of_gpio_chip *of_gc = to_of_gpio_chip(gc); 49863fbf49SAnton Vorontsov 50863fbf49SAnton Vorontsov return container_of(of_gc, struct of_mm_gpio_chip, of_gc); 51863fbf49SAnton Vorontsov } 52863fbf49SAnton Vorontsov 53863fbf49SAnton Vorontsov extern int of_get_gpio(struct device_node *np, int index); 54863fbf49SAnton Vorontsov extern int of_mm_gpiochip_add(struct device_node *np, 55863fbf49SAnton Vorontsov struct of_mm_gpio_chip *mm_gc); 56863fbf49SAnton Vorontsov extern int of_gpio_simple_xlate(struct of_gpio_chip *of_gc, 57863fbf49SAnton Vorontsov struct device_node *np, 58863fbf49SAnton Vorontsov const void *gpio_spec); 59863fbf49SAnton Vorontsov #else 60863fbf49SAnton Vorontsov 61863fbf49SAnton Vorontsov /* Drivers may not strictly depend on the GPIO support, so let them link. */ 62863fbf49SAnton Vorontsov static inline int of_get_gpio(struct device_node *np, int index) 63863fbf49SAnton Vorontsov { 64863fbf49SAnton Vorontsov return -ENOSYS; 65863fbf49SAnton Vorontsov } 66863fbf49SAnton Vorontsov 67863fbf49SAnton Vorontsov #endif /* CONFIG_OF_GPIO */ 68863fbf49SAnton Vorontsov 69863fbf49SAnton Vorontsov #endif /* __LINUX_OF_GPIO_H */ 70