~ubuntu-branches/ubuntu/trusty/apex/trusty

« back to all changes in this revision

Viewing changes to include/asm-generic/gpio.h

  • Committer: Bazaar Package Importer
  • Author(s): Oliver Grawert
  • Date: 2009-11-10 11:55:15 UTC
  • mfrom: (2.2.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091110115515-6jjsf6rc8py35awe
Tags: 1.6.10ubuntu1
* Merge from debian testing, remaining changes:
  - Move apex VMA address to 4MiB to leave enough space for the ubuntu
  kernel and not overwrite apex in ram when loading.
  - nslu2 configuration: set CONFIG_RAMDISK_SIZE=0x0055FFF0 instead of
  0x005FFFF0 to make enough room for ubuntu initramfs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef _ASM_GENERIC_GPIO_H
 
2
#define _ASM_GENERIC_GPIO_H
 
3
 
 
4
#include <linux/types.h>
 
5
 
 
6
#ifdef CONFIG_HAVE_GPIO_LIB
 
7
 
 
8
#include <linux/compiler.h>
 
9
 
 
10
/* Platforms may implement their GPIO interface with library code,
 
11
 * at a small performance cost for non-inlined operations and some
 
12
 * extra memory (for code and for per-GPIO table entries).
 
13
 *
 
14
 * While the GPIO programming interface defines valid GPIO numbers
 
15
 * to be in the range 0..MAX_INT, this library restricts them to the
 
16
 * smaller range 0..ARCH_NR_GPIOS.
 
17
 */
 
18
 
 
19
#ifndef ARCH_NR_GPIOS
 
20
#define ARCH_NR_GPIOS           256
 
21
#endif
 
22
 
 
23
static inline int gpio_is_valid(int number)
 
24
{
 
25
        /* only some non-negative numbers are valid */
 
26
        return ((unsigned)number) < ARCH_NR_GPIOS;
 
27
}
 
28
 
 
29
struct seq_file;
 
30
struct module;
 
31
 
 
32
/**
 
33
 * struct gpio_chip - abstract a GPIO controller
 
34
 * @label: for diagnostics
 
35
 * @direction_input: configures signal "offset" as input, or returns error
 
36
 * @get: returns value for signal "offset"; for output signals this
 
37
 *      returns either the value actually sensed, or zero
 
38
 * @direction_output: configures signal "offset" as output, or returns error
 
39
 * @set: assigns output value for signal "offset"
 
40
 * @dbg_show: optional routine to show contents in debugfs; default code
 
41
 *      will be used when this is omitted, but custom code can show extra
 
42
 *      state (such as pullup/pulldown configuration).
 
43
 * @base: identifies the first GPIO number handled by this chip; or, if
 
44
 *      negative during registration, requests dynamic ID allocation.
 
45
 * @ngpio: the number of GPIOs handled by this controller; the last GPIO
 
46
 *      handled is (base + ngpio - 1).
 
47
 * @can_sleep: flag must be set iff get()/set() methods sleep, as they
 
48
 *      must while accessing GPIO expander chips over I2C or SPI
 
49
 *
 
50
 * A gpio_chip can help platforms abstract various sources of GPIOs so
 
51
 * they can all be accessed through a common programing interface.
 
52
 * Example sources would be SOC controllers, FPGAs, multifunction
 
53
 * chips, dedicated GPIO expanders, and so on.
 
54
 *
 
55
 * Each chip controls a number of signals, identified in method calls
 
56
 * by "offset" values in the range 0..(@ngpio - 1).  When those signals
 
57
 * are referenced through calls like gpio_get_value(gpio), the offset
 
58
 * is calculated by subtracting @base from the gpio number.
 
59
 */
 
60
struct gpio_chip {
 
61
        char                    *label;
 
62
        struct module           *owner;
 
63
 
 
64
        int                     (*direction_input)(struct gpio_chip *chip,
 
65
                                                unsigned offset);
 
66
        int                     (*get)(struct gpio_chip *chip,
 
67
                                                unsigned offset);
 
68
        int                     (*direction_output)(struct gpio_chip *chip,
 
69
                                                unsigned offset, int value);
 
70
        void                    (*set)(struct gpio_chip *chip,
 
71
                                                unsigned offset, int value);
 
72
        void                    (*dbg_show)(struct seq_file *s,
 
73
                                                struct gpio_chip *chip);
 
74
        int                     base;
 
75
        u16                     ngpio;
 
76
        unsigned                can_sleep:1;
 
77
};
 
78
 
 
79
extern const char *gpiochip_is_requested(struct gpio_chip *chip,
 
80
                        unsigned offset);
 
81
extern int __must_check gpiochip_reserve(int start, int ngpio);
 
82
 
 
83
/* add/remove chips */
 
84
extern int gpiochip_add(struct gpio_chip *chip);
 
85
extern int __must_check gpiochip_remove(struct gpio_chip *chip);
 
86
 
 
87
 
 
88
/* Always use the library code for GPIO management calls,
 
89
 * or when sleeping may be involved.
 
90
 */
 
91
extern int gpio_request(unsigned gpio, const char *label);
 
92
extern void gpio_free(unsigned gpio);
 
93
 
 
94
extern int gpio_direction_input(unsigned gpio);
 
95
extern int gpio_direction_output(unsigned gpio, int value);
 
96
 
 
97
extern int gpio_get_value_cansleep(unsigned gpio);
 
98
extern void gpio_set_value_cansleep(unsigned gpio, int value);
 
99
 
 
100
 
 
101
/* A platform's <asm/gpio.h> code may want to inline the I/O calls when
 
102
 * the GPIO is constant and refers to some always-present controller,
 
103
 * giving direct access to chip registers and tight bitbanging loops.
 
104
 */
 
105
extern int __gpio_get_value(unsigned gpio);
 
106
extern void __gpio_set_value(unsigned gpio, int value);
 
107
 
 
108
extern int __gpio_cansleep(unsigned gpio);
 
109
 
 
110
 
 
111
#else
 
112
 
 
113
static inline int gpio_is_valid(int number)
 
114
{
 
115
        /* only non-negative numbers are valid */
 
116
        return number >= 0;
 
117
}
 
118
 
 
119
/* platforms that don't directly support access to GPIOs through I2C, SPI,
 
120
 * or other blocking infrastructure can use these wrappers.
 
121
 */
 
122
 
 
123
static inline int gpio_cansleep(unsigned gpio)
 
124
{
 
125
        return 0;
 
126
}
 
127
 
 
128
static inline int gpio_get_value_cansleep(unsigned gpio)
 
129
{
 
130
        might_sleep();
 
131
        return gpio_get_value(gpio);
 
132
}
 
133
 
 
134
static inline void gpio_set_value_cansleep(unsigned gpio, int value)
 
135
{
 
136
        might_sleep();
 
137
        gpio_set_value(gpio, value);
 
138
}
 
139
 
 
140
#endif
 
141
 
 
142
#endif /* _ASM_GENERIC_GPIO_H */