]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - include/mxc_keyb.h
applied patches from Freescale and Ka-Ro
[karo-tx-uboot.git] / include / mxc_keyb.h
1 /*
2  * Copyright 2004-2009 Freescale Semiconductor, Inc. All Rights Reserved.
3  */
4
5 /*
6  * The code contained herein is licensed under the GNU General Public
7  * License. You may obtain a copy of the GNU General Public License
8  * Version 2 or later at the following locations:
9  *
10  * http://www.opensource.org/licenses/gpl-license.html
11  * http://www.gnu.org/copyleft/gpl.html
12  */
13
14 /*!
15  * @defgroup keypad Keypad Driver
16  */
17
18 /*!
19  * @file mxc_keyb.h
20  *
21  * @brief MXC keypad header file.
22  *
23  * @ingroup keypad
24  */
25 #ifndef __MXC_KEYB_H__
26 #define __MXC_KEYB_H__
27
28 /*!
29  * Keypad Module Name
30  */
31 #define MOD_NAME  "mxckpd"
32
33 /*!
34  * Keypad irq number
35  */
36 #define KPP_IRQ  MXC_INT_KPP
37
38 /*!
39  * XLATE mode selection
40  */
41 #define KEYPAD_XLATE        0
42
43 /*!
44  * RAW mode selection
45  */
46 #define KEYPAD_RAW          1
47
48 /*!
49  * Maximum number of keys.
50  */
51 #define MAXROW                  8
52 #define MAXCOL                  8
53 #define MXC_MAXKEY              (MAXROW * MAXCOL)
54
55 /*!
56  * This define indicates break scancode for every key release. A constant
57  * of 128 is added to the key press scancode.
58  */
59 #define  MXC_KEYRELEASE   128
60
61 /*
62  * _reg_KPP_KPCR   _reg_KPP_KPSR _reg_KPP_KDDR _reg_KPP_KPDR
63  * Keypad Control Register Address
64  */
65 #define KPCR    (KPP_BASE_ADDR + 0x00)
66
67 /*
68  * Keypad Status Register Address
69  */
70 #define KPSR    (KPP_BASE_ADDR + 0x02)
71
72 /*
73  * Keypad Data Direction Address
74  */
75 #define KDDR    (KPP_BASE_ADDR + 0x04)
76
77 /*
78  * Keypad Data Register
79  */
80 #define KPDR    (KPP_BASE_ADDR + 0x06)
81
82 /*
83  * Key Press Interrupt Status bit
84  */
85 #define KBD_STAT_KPKD        0x01
86
87 /*
88  * Key Release Interrupt Status bit
89  */
90 #define KBD_STAT_KPKR        0x02
91
92 /*
93  * Key Depress Synchronizer Chain Status bit
94  */
95 #define KBD_STAT_KDSC        0x04
96
97 /*
98  * Key Release Synchronizer Status bit
99  */
100 #define KBD_STAT_KRSS        0x08
101
102 /*
103  * Key Depress Interrupt Enable Status bit
104  */
105 #define KBD_STAT_KDIE        0x100
106
107 /*
108  * Key Release Interrupt Enable
109  */
110 #define KBD_STAT_KRIE        0x200
111
112 /*
113  * Keypad Clock Enable
114  */
115 #define KBD_STAT_KPPEN       0x400
116
117 /*!
118  * Buffer size of keypad queue. Should be a power of 2.
119  */
120 #define KPP_BUF_SIZE    128
121
122 /*!
123  * Test whether bit is set for integer c
124  */
125 #define TEST_BIT(c, n) ((c) & (0x1 << (n)))
126
127 /*!
128  * Set nth bit in the integer c
129  */
130 #define BITSET(c, n)   ((c) | (1 << (n)))
131
132 /*!
133  * Reset nth bit in the integer c
134  */
135 #define BITRESET(c, n) ((c) & ~(1 << (n)))
136
137 enum KeyEvent {
138         KDepress,
139         KRelease
140 };
141
142 /*!
143  * This enum represents the keypad state machine to maintain debounce logic
144  * for key press/release.
145  */
146 enum KeyState {
147
148         /*!
149          * Key press state.
150          */
151         KStateUp,
152
153         /*!
154          * Key press debounce state.
155          */
156         KStateFirstDown,
157
158         /*!
159          * Key release state.
160          */
161         KStateDown,
162
163         /*!
164          * Key release debounce state.
165          */
166         KStateFirstUp
167 };
168
169 /*!
170  * Keypad Private Data Structure
171  */
172 typedef struct keypad_priv {
173
174         /*!
175          * Keypad state machine.
176          */
177         enum KeyState iKeyState;
178
179         /*!
180          * Number of rows configured in the keypad matrix
181          */
182         unsigned long kpp_rows;
183
184         /*!
185          * Number of Columns configured in the keypad matrix
186          */
187         unsigned long kpp_cols;
188 } keypad_priv;
189
190 /*!
191  * Keypad Data Structure
192  * */
193 struct kpp_key_info {
194         enum KeyEvent evt;
195         unsigned short val;
196 };
197
198 int mxc_kpp_init(void);
199 int mxc_kpp_getc(struct kpp_key_info *);
200
201 #endif                          /* __MXC_KEYB_H__ */