Merge branch 'devel-gpio' into omap-for-linus
[pandora-kernel.git] / arch / arm / mach-omap2 / mux.h
1 /*
2  * Copyright (C) 2009 Nokia
3  * Copyright (C) 2009-2010 Texas Instruments
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation.
8  */
9
10 #include "mux2420.h"
11 #include "mux2430.h"
12 #include "mux34xx.h"
13 #include "mux44xx.h"
14
15 #define OMAP_MUX_TERMINATOR     0xffff
16
17 /* 34xx mux mode options for each pin. See TRM for options */
18 #define OMAP_MUX_MODE0      0
19 #define OMAP_MUX_MODE1      1
20 #define OMAP_MUX_MODE2      2
21 #define OMAP_MUX_MODE3      3
22 #define OMAP_MUX_MODE4      4
23 #define OMAP_MUX_MODE5      5
24 #define OMAP_MUX_MODE6      6
25 #define OMAP_MUX_MODE7      7
26
27 /* 24xx/34xx mux bit defines */
28 #define OMAP_PULL_ENA                   (1 << 3)
29 #define OMAP_PULL_UP                    (1 << 4)
30 #define OMAP_ALTELECTRICALSEL           (1 << 5)
31
32 /* 34xx specific mux bit defines */
33 #define OMAP_INPUT_EN                   (1 << 8)
34 #define OMAP_OFF_EN                     (1 << 9)
35 #define OMAP_OFFOUT_EN                  (1 << 10)
36 #define OMAP_OFFOUT_VAL                 (1 << 11)
37 #define OMAP_OFF_PULL_EN                (1 << 12)
38 #define OMAP_OFF_PULL_UP                (1 << 13)
39 #define OMAP_WAKEUP_EN                  (1 << 14)
40
41 /* 44xx specific mux bit defines */
42 #define OMAP_WAKEUP_EVENT               (1 << 15)
43
44 /* Active pin states */
45 #define OMAP_PIN_OUTPUT                 0
46 #define OMAP_PIN_INPUT                  OMAP_INPUT_EN
47 #define OMAP_PIN_INPUT_PULLUP           (OMAP_PULL_ENA | OMAP_INPUT_EN \
48                                                 | OMAP_PULL_UP)
49 #define OMAP_PIN_INPUT_PULLDOWN         (OMAP_PULL_ENA | OMAP_INPUT_EN)
50
51 /* Off mode states */
52 #define OMAP_PIN_OFF_NONE               0
53 #define OMAP_PIN_OFF_OUTPUT_HIGH        (OMAP_OFF_EN | OMAP_OFFOUT_EN \
54                                                 | OMAP_OFFOUT_VAL)
55 #define OMAP_PIN_OFF_OUTPUT_LOW         (OMAP_OFF_EN | OMAP_OFFOUT_EN)
56 #define OMAP_PIN_OFF_INPUT_PULLUP       (OMAP_OFF_EN | OMAP_OFF_PULL_EN \
57                                                 | OMAP_OFF_PULL_UP)
58 #define OMAP_PIN_OFF_INPUT_PULLDOWN     (OMAP_OFF_EN | OMAP_OFF_PULL_EN)
59 #define OMAP_PIN_OFF_WAKEUPENABLE       OMAP_WAKEUP_EN
60
61 #define OMAP_MODE_GPIO(x)       (((x) & OMAP_MUX_MODE7) == OMAP_MUX_MODE4)
62
63 /* Flags for omapX_mux_init */
64 #define OMAP_PACKAGE_MASK               0xffff
65 #define OMAP_PACKAGE_CBS                8               /* 547-pin 0.40 0.40 */
66 #define OMAP_PACKAGE_CBL                7               /* 547-pin 0.40 0.40 */
67 #define OMAP_PACKAGE_CBP                6               /* 515-pin 0.40 0.50 */
68 #define OMAP_PACKAGE_CUS                5               /* 423-pin 0.65 */
69 #define OMAP_PACKAGE_CBB                4               /* 515-pin 0.40 0.50 */
70 #define OMAP_PACKAGE_CBC                3               /* 515-pin 0.50 0.65 */
71 #define OMAP_PACKAGE_ZAC                2               /* 24xx 447-pin POP */
72 #define OMAP_PACKAGE_ZAF                1               /* 2420 447-pin SIP */
73
74
75 #define OMAP_MUX_NR_MODES               8               /* Available modes */
76 #define OMAP_MUX_NR_SIDES               2               /* Bottom & top */
77
78 /*
79  * omap_mux_init flags definition:
80  *
81  * OMAP_MUX_REG_8BIT: Ensure that access to padconf is done in 8 bits.
82  * The default value is 16 bits.
83  * OMAP_MUX_GPIO_IN_MODE3: The GPIO is selected in mode3.
84  * The default is mode4.
85  */
86 #define OMAP_MUX_REG_8BIT               (1 << 0)
87 #define OMAP_MUX_GPIO_IN_MODE3          (1 << 1)
88
89 /**
90  * struct mux_partition - contain partition related information
91  * @name: name of the current partition
92  * @flags: flags specific to this partition
93  * @phys: physical address
94  * @size: partition size
95  * @base: virtual address after ioremap
96  * @muxmodes: list of nodes that belong to a partition
97  * @node: list node for the partitions linked list
98  */
99 struct omap_mux_partition {
100         const char              *name;
101         u32                     flags;
102         u32                     phys;
103         u32                     size;
104         void __iomem            *base;
105         struct list_head        muxmodes;
106         struct list_head        node;
107 };
108
109 /**
110  * struct omap_mux - data for omap mux register offset and it's value
111  * @reg_offset: mux register offset from the mux base
112  * @gpio:       GPIO number
113  * @muxnames:   available signal modes for a ball
114  * @balls:      available balls on the package
115  * @partition:  mux partition
116  */
117 struct omap_mux {
118         u16     reg_offset;
119         u16     gpio;
120 #ifdef CONFIG_OMAP_MUX
121         char    *muxnames[OMAP_MUX_NR_MODES];
122 #ifdef CONFIG_DEBUG_FS
123         char    *balls[OMAP_MUX_NR_SIDES];
124 #endif
125 #endif
126 };
127
128 /**
129  * struct omap_ball - data for balls on omap package
130  * @reg_offset: mux register offset from the mux base
131  * @balls:      available balls on the package
132  */
133 struct omap_ball {
134         u16     reg_offset;
135         char    *balls[OMAP_MUX_NR_SIDES];
136 };
137
138 /**
139  * struct omap_board_mux - data for initializing mux registers
140  * @reg_offset: mux register offset from the mux base
141  * @mux_value:  desired mux value to set
142  */
143 struct omap_board_mux {
144         u16     reg_offset;
145         u16     value;
146 };
147
148 #if defined(CONFIG_OMAP_MUX)
149
150 /**
151  * omap_mux_init_gpio - initialize a signal based on the GPIO number
152  * @gpio:               GPIO number
153  * @val:                Options for the mux register value
154  */
155 int omap_mux_init_gpio(int gpio, int val);
156
157 /**
158  * omap_mux_init_signal - initialize a signal based on the signal name
159  * @muxname:            Mux name in mode0_name.signal_name format
160  * @val:                Options for the mux register value
161  */
162 int omap_mux_init_signal(const char *muxname, int val);
163
164 #else
165
166 static inline int omap_mux_init_gpio(int gpio, int val)
167 {
168         return 0;
169 }
170 static inline int omap_mux_init_signal(char *muxname, int val)
171 {
172         return 0;
173 }
174
175 static struct omap_board_mux *board_mux __initdata __maybe_unused;
176
177 #endif
178
179 /**
180  * omap_mux_get_gpio() - get mux register value based on GPIO number
181  * @gpio:               GPIO number
182  *
183  */
184 u16 omap_mux_get_gpio(int gpio);
185
186 /**
187  * omap_mux_set_gpio() - set mux register value based on GPIO number
188  * @val:                New mux register value
189  * @gpio:               GPIO number
190  *
191  */
192 void omap_mux_set_gpio(u16 val, int gpio);
193
194 /**
195  * omap_mux_get() - get a mux partition by name
196  * @name:               Name of the mux partition
197  *
198  */
199 struct omap_mux_partition *omap_mux_get(const char *name);
200
201 /**
202  * omap_mux_read() - read mux register
203  * @partition:          Mux partition
204  * @mux_offset:         Offset of the mux register
205  *
206  */
207 u16 omap_mux_read(struct omap_mux_partition *p, u16 mux_offset);
208
209 /**
210  * omap_mux_write() - write mux register
211  * @partition:          Mux partition
212  * @val:                New mux register value
213  * @mux_offset:         Offset of the mux register
214  *
215  * This should be only needed for dynamic remuxing of non-gpio signals.
216  */
217 void omap_mux_write(struct omap_mux_partition *p, u16 val, u16 mux_offset);
218
219 /**
220  * omap_mux_write_array() - write an array of mux registers
221  * @partition:          Mux partition
222  * @board_mux:          Array of mux registers terminated by MAP_MUX_TERMINATOR
223  *
224  * This should be only needed for dynamic remuxing of non-gpio signals.
225  */
226 void omap_mux_write_array(struct omap_mux_partition *p,
227                           struct omap_board_mux *board_mux);
228
229 /**
230  * omap2420_mux_init() - initialize mux system with board specific set
231  * @board_mux:          Board specific mux table
232  * @flags:              OMAP package type used for the board
233  */
234 int omap2420_mux_init(struct omap_board_mux *board_mux, int flags);
235
236 /**
237  * omap2430_mux_init() - initialize mux system with board specific set
238  * @board_mux:          Board specific mux table
239  * @flags:              OMAP package type used for the board
240  */
241 int omap2430_mux_init(struct omap_board_mux *board_mux, int flags);
242
243 /**
244  * omap3_mux_init() - initialize mux system with board specific set
245  * @board_mux:          Board specific mux table
246  * @flags:              OMAP package type used for the board
247  */
248 int omap3_mux_init(struct omap_board_mux *board_mux, int flags);
249
250 /**
251  * omap4_mux_init() - initialize mux system with board specific set
252  * @board_mux:          Board specific mux table
253  * @flags:              OMAP package type used for the board
254  */
255 int omap4_mux_init(struct omap_board_mux *board_mux, int flags);
256
257 /**
258  * omap_mux_init - private mux init function, do not call
259  */
260 int omap_mux_init(const char *name, u32 flags,
261                   u32 mux_pbase, u32 mux_size,
262                   struct omap_mux *superset,
263                   struct omap_mux *package_subset,
264                   struct omap_board_mux *board_mux,
265                   struct omap_ball *package_balls);
266