Blame view

include/linux/of_gpio.h 3.8 KB
863fbf496   Anton Vorontsov   [POWERPC] OF help...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  /*
   * OF helpers for the GPIO API
   *
   * Copyright (c) 2007-2008  MontaVista Software, Inc.
   *
   * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
   *
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation; either version 2 of the License, or
   * (at your option) any later version.
   */
  
  #ifndef __LINUX_OF_GPIO_H
  #define __LINUX_OF_GPIO_H
b908b53d5   Anton Vorontsov   of/gpio: Implemen...
16
17
  #include <linux/compiler.h>
  #include <linux/kernel.h>
863fbf496   Anton Vorontsov   [POWERPC] OF help...
18
  #include <linux/errno.h>
18ad7a61e   Wolfgang Grandegger   of_gpio: Should u...
19
  #include <linux/gpio.h>
15c9a0acc   Grant Likely   of: create of_pha...
20
  #include <linux/of.h>
863fbf496   Anton Vorontsov   [POWERPC] OF help...
21

b908b53d5   Anton Vorontsov   of/gpio: Implemen...
22
23
24
25
26
27
28
29
30
31
  struct device_node;
  
  /*
   * This is Linux-specific flags. By default controllers' and Linux' mapping
   * match, but GPIO controllers are free to translate their own flags to
   * Linux-specific in their .xlate callback. Though, 1:1 mapping is recommended.
   */
  enum of_gpio_flags {
  	OF_GPIO_ACTIVE_LOW = 0x1,
  };
863fbf496   Anton Vorontsov   [POWERPC] OF help...
32
33
34
  #ifdef CONFIG_OF_GPIO
  
  /*
863fbf496   Anton Vorontsov   [POWERPC] OF help...
35
36
37
   * OF GPIO chip for memory mapped banks
   */
  struct of_mm_gpio_chip {
a19e3da5b   Anton Vorontsov   of/gpio: Kill of_...
38
  	struct gpio_chip gc;
863fbf496   Anton Vorontsov   [POWERPC] OF help...
39
40
41
42
43
44
  	void (*save_regs)(struct of_mm_gpio_chip *mm_gc);
  	void __iomem *regs;
  };
  
  static inline struct of_mm_gpio_chip *to_of_mm_gpio_chip(struct gpio_chip *gc)
  {
a19e3da5b   Anton Vorontsov   of/gpio: Kill of_...
45
  	return container_of(gc, struct of_mm_gpio_chip, gc);
863fbf496   Anton Vorontsov   [POWERPC] OF help...
46
  }
a6b091914   John Bonesio   of/gpio: Add new ...
47
48
  extern int of_get_named_gpio_flags(struct device_node *np,
  		const char *list_name, int index, enum of_gpio_flags *flags);
749820928   Anton Vorontsov   of/gpio: Implemen...
49
  extern unsigned int of_gpio_count(struct device_node *np);
b908b53d5   Anton Vorontsov   of/gpio: Implemen...
50

863fbf496   Anton Vorontsov   [POWERPC] OF help...
51
52
  extern int of_mm_gpiochip_add(struct device_node *np,
  			      struct of_mm_gpio_chip *mm_gc);
594fa265e   Grant Likely   of/gpio: stop usi...
53

391c970c0   Anton Vorontsov   of/gpio: add defa...
54
55
  extern void of_gpiochip_add(struct gpio_chip *gc);
  extern void of_gpiochip_remove(struct gpio_chip *gc);
594fa265e   Grant Likely   of/gpio: stop usi...
56
  extern struct gpio_chip *of_node_to_gpiochip(struct device_node *np);
15c9a0acc   Grant Likely   of: create of_pha...
57
58
59
  extern int of_gpio_simple_xlate(struct gpio_chip *gc,
  				const struct of_phandle_args *gpiospec,
  				u32 *flags);
594fa265e   Grant Likely   of/gpio: stop usi...
60

a19e3da5b   Anton Vorontsov   of/gpio: Kill of_...
61
  #else /* CONFIG_OF_GPIO */
863fbf496   Anton Vorontsov   [POWERPC] OF help...
62
63
  
  /* Drivers may not strictly depend on the GPIO support, so let them link. */
a6b091914   John Bonesio   of/gpio: Add new ...
64
65
  static inline int of_get_named_gpio_flags(struct device_node *np,
  		const char *list_name, int index, enum of_gpio_flags *flags)
863fbf496   Anton Vorontsov   [POWERPC] OF help...
66
67
68
  {
  	return -ENOSYS;
  }
749820928   Anton Vorontsov   of/gpio: Implemen...
69
70
71
72
  static inline unsigned int of_gpio_count(struct device_node *np)
  {
  	return 0;
  }
3038bbdf7   Jamie Iles   of/gpio: export o...
73
  static inline int of_gpio_simple_xlate(struct gpio_chip *gc,
15c9a0acc   Grant Likely   of: create of_pha...
74
75
  				       const struct of_phandle_args *gpiospec,
  				       u32 *flags)
3038bbdf7   Jamie Iles   of/gpio: export o...
76
77
78
  {
  	return -ENOSYS;
  }
391c970c0   Anton Vorontsov   of/gpio: add defa...
79
80
  static inline void of_gpiochip_add(struct gpio_chip *gc) { }
  static inline void of_gpiochip_remove(struct gpio_chip *gc) { }
863fbf496   Anton Vorontsov   [POWERPC] OF help...
81
  #endif /* CONFIG_OF_GPIO */
b908b53d5   Anton Vorontsov   of/gpio: Implemen...
82
  /**
a6b091914   John Bonesio   of/gpio: Add new ...
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
   * of_get_gpio_flags() - Get a GPIO number and flags to use with GPIO API
   * @np:		device node to get GPIO from
   * @index:	index of the GPIO
   * @flags:	a flags pointer to fill in
   *
   * Returns GPIO number to use with Linux generic GPIO API, or one of the errno
   * value on the error condition. If @flags is not NULL the function also fills
   * in flags for the GPIO.
   */
  static inline int of_get_gpio_flags(struct device_node *np, int index,
  		      enum of_gpio_flags *flags)
  {
  	return of_get_named_gpio_flags(np, "gpios", index, flags);
  }
  
  /**
   * of_get_named_gpio() - Get a GPIO number to use with GPIO API
   * @np:		device node to get GPIO from
   * @propname:	Name of property containing gpio specifier(s)
   * @index:	index of the GPIO
   *
   * Returns GPIO number to use with Linux generic GPIO API, or one of the errno
   * value on the error condition.
   */
  static inline int of_get_named_gpio(struct device_node *np,
                                     const char *propname, int index)
  {
  	return of_get_named_gpio_flags(np, propname, index, NULL);
  }
  
  /**
   * of_get_gpio() - Get a GPIO number to use with GPIO API
b908b53d5   Anton Vorontsov   of/gpio: Implemen...
115
116
117
118
119
120
121
122
123
124
   * @np:		device node to get GPIO from
   * @index:	index of the GPIO
   *
   * Returns GPIO number to use with Linux generic GPIO API, or one of the errno
   * value on the error condition.
   */
  static inline int of_get_gpio(struct device_node *np, int index)
  {
  	return of_get_gpio_flags(np, index, NULL);
  }
863fbf496   Anton Vorontsov   [POWERPC] OF help...
125
  #endif /* __LINUX_OF_GPIO_H */