of_gpio.h revision a19e3da5bc5fc6c10ab73f310bea80f3845b4531
1863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov/*
2863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov * OF helpers for the GPIO API
3863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov *
4863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov * Copyright (c) 2007-2008  MontaVista Software, Inc.
5863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov *
6863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
7863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov *
8863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov * This program is free software; you can redistribute it and/or modify
9863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov * it under the terms of the GNU General Public License as published by
10863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov * the Free Software Foundation; either version 2 of the License, or
11863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov * (at your option) any later version.
12863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov */
13863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov
14863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov#ifndef __LINUX_OF_GPIO_H
15863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov#define __LINUX_OF_GPIO_H
16863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov
17b908b53d580c3e9aba81ebe3339c5b7b4fa8031dAnton Vorontsov#include <linux/compiler.h>
18b908b53d580c3e9aba81ebe3339c5b7b4fa8031dAnton Vorontsov#include <linux/kernel.h>
19863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov#include <linux/errno.h>
2018ad7a61e1b700dfe177fabf1c350b4f5d4da8acWolfgang Grandegger#include <linux/gpio.h>
21863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov
22b908b53d580c3e9aba81ebe3339c5b7b4fa8031dAnton Vorontsovstruct device_node;
23b908b53d580c3e9aba81ebe3339c5b7b4fa8031dAnton Vorontsov
24b908b53d580c3e9aba81ebe3339c5b7b4fa8031dAnton Vorontsov/*
25b908b53d580c3e9aba81ebe3339c5b7b4fa8031dAnton Vorontsov * This is Linux-specific flags. By default controllers' and Linux' mapping
26b908b53d580c3e9aba81ebe3339c5b7b4fa8031dAnton Vorontsov * match, but GPIO controllers are free to translate their own flags to
27b908b53d580c3e9aba81ebe3339c5b7b4fa8031dAnton Vorontsov * Linux-specific in their .xlate callback. Though, 1:1 mapping is recommended.
28b908b53d580c3e9aba81ebe3339c5b7b4fa8031dAnton Vorontsov */
29b908b53d580c3e9aba81ebe3339c5b7b4fa8031dAnton Vorontsovenum of_gpio_flags {
30b908b53d580c3e9aba81ebe3339c5b7b4fa8031dAnton Vorontsov	OF_GPIO_ACTIVE_LOW = 0x1,
31b908b53d580c3e9aba81ebe3339c5b7b4fa8031dAnton Vorontsov};
32b908b53d580c3e9aba81ebe3339c5b7b4fa8031dAnton Vorontsov
33863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov#ifdef CONFIG_OF_GPIO
34863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov
35863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov/*
36863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov * OF GPIO chip for memory mapped banks
37863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov */
38863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsovstruct of_mm_gpio_chip {
39a19e3da5bc5fc6c10ab73f310bea80f3845b4531Anton Vorontsov	struct gpio_chip gc;
40863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov	void (*save_regs)(struct of_mm_gpio_chip *mm_gc);
41863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov	void __iomem *regs;
42863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov};
43863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov
44863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsovstatic inline struct of_mm_gpio_chip *to_of_mm_gpio_chip(struct gpio_chip *gc)
45863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov{
46a19e3da5bc5fc6c10ab73f310bea80f3845b4531Anton Vorontsov	return container_of(gc, struct of_mm_gpio_chip, gc);
47863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov}
48863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov
49b908b53d580c3e9aba81ebe3339c5b7b4fa8031dAnton Vorontsovextern int of_get_gpio_flags(struct device_node *np, int index,
50b908b53d580c3e9aba81ebe3339c5b7b4fa8031dAnton Vorontsov			     enum of_gpio_flags *flags);
51749820928a2fd47ff536773d869d2c3f8038b7d1Anton Vorontsovextern unsigned int of_gpio_count(struct device_node *np);
52b908b53d580c3e9aba81ebe3339c5b7b4fa8031dAnton Vorontsov
53863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsovextern int of_mm_gpiochip_add(struct device_node *np,
54863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov			      struct of_mm_gpio_chip *mm_gc);
55a19e3da5bc5fc6c10ab73f310bea80f3845b4531Anton Vorontsovextern int of_gpio_simple_xlate(struct gpio_chip *gc, struct device_node *np,
56a19e3da5bc5fc6c10ab73f310bea80f3845b4531Anton Vorontsov				const void *gpio_spec, u32 *flags);
57a19e3da5bc5fc6c10ab73f310bea80f3845b4531Anton Vorontsov#else /* CONFIG_OF_GPIO */
58863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov
59863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov/* Drivers may not strictly depend on the GPIO support, so let them link. */
60b908b53d580c3e9aba81ebe3339c5b7b4fa8031dAnton Vorontsovstatic inline int of_get_gpio_flags(struct device_node *np, int index,
61b908b53d580c3e9aba81ebe3339c5b7b4fa8031dAnton Vorontsov				    enum of_gpio_flags *flags)
62863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov{
63863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov	return -ENOSYS;
64863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov}
65863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov
66749820928a2fd47ff536773d869d2c3f8038b7d1Anton Vorontsovstatic inline unsigned int of_gpio_count(struct device_node *np)
67749820928a2fd47ff536773d869d2c3f8038b7d1Anton Vorontsov{
68749820928a2fd47ff536773d869d2c3f8038b7d1Anton Vorontsov	return 0;
69749820928a2fd47ff536773d869d2c3f8038b7d1Anton Vorontsov}
70749820928a2fd47ff536773d869d2c3f8038b7d1Anton Vorontsov
71863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov#endif /* CONFIG_OF_GPIO */
72863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov
73b908b53d580c3e9aba81ebe3339c5b7b4fa8031dAnton Vorontsov/**
74b908b53d580c3e9aba81ebe3339c5b7b4fa8031dAnton Vorontsov * of_get_gpio - Get a GPIO number to use with GPIO API
75b908b53d580c3e9aba81ebe3339c5b7b4fa8031dAnton Vorontsov * @np:		device node to get GPIO from
76b908b53d580c3e9aba81ebe3339c5b7b4fa8031dAnton Vorontsov * @index:	index of the GPIO
77b908b53d580c3e9aba81ebe3339c5b7b4fa8031dAnton Vorontsov *
78b908b53d580c3e9aba81ebe3339c5b7b4fa8031dAnton Vorontsov * Returns GPIO number to use with Linux generic GPIO API, or one of the errno
79b908b53d580c3e9aba81ebe3339c5b7b4fa8031dAnton Vorontsov * value on the error condition.
80b908b53d580c3e9aba81ebe3339c5b7b4fa8031dAnton Vorontsov */
81b908b53d580c3e9aba81ebe3339c5b7b4fa8031dAnton Vorontsovstatic inline int of_get_gpio(struct device_node *np, int index)
82b908b53d580c3e9aba81ebe3339c5b7b4fa8031dAnton Vorontsov{
83b908b53d580c3e9aba81ebe3339c5b7b4fa8031dAnton Vorontsov	return of_get_gpio_flags(np, index, NULL);
84b908b53d580c3e9aba81ebe3339c5b7b4fa8031dAnton Vorontsov}
85b908b53d580c3e9aba81ebe3339c5b7b4fa8031dAnton Vorontsov
86863fbf4966a7ac301a4077e4a04d73e8abfdd7b2Anton Vorontsov#endif /* __LINUX_OF_GPIO_H */
87