xref: /freebsd/sys/dev/gpio/gpiokeys_codes.c (revision 63d1fd5970ec814904aa0f4580b10a0d302d08b2)
1 /*-
2  * Copyright (c) 2015 Oleksandr Tymoshenko <gonzo@freebsd.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26 
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
29 
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 
33 #include <dev/gpio/gpiokeys.h>
34 #include <gnu/dts/include/dt-bindings/input/linux-event-codes.h>
35 
36 struct gpiokeys_codemap_entry {
37 	uint32_t	linux_code;
38 	uint32_t	bsd_code;
39 };
40 
41 static struct gpiokeys_codemap_entry gpiokeys_codes_map[] = {
42 	{ KEY_ESC,		1},
43 	{ KEY_1,		2},
44 	{ KEY_2,		3},
45 	{ KEY_3,		4},
46 	{ KEY_4,		5},
47 	{ KEY_5,		6},
48 	{ KEY_6,		7},
49 	{ KEY_7,		8},
50 	{ KEY_8,		9},
51 	{ KEY_9,		10},
52 	{ KEY_0,		11},
53 	{ KEY_MINUS,		12},
54 	{ KEY_EQUAL,		13},
55 	{ KEY_BACKSPACE,	14},
56 
57 	{ KEY_TAB,		15},
58 	{ KEY_Q,		16},
59 	{ KEY_W,		17},
60 	{ KEY_E,		18},
61 	{ KEY_R,		19},
62 	{ KEY_T,		20},
63 	{ KEY_Y,		21},
64 	{ KEY_U,		22},
65 	{ KEY_I,		23},
66 	{ KEY_O,		24},
67 	{ KEY_P,		25},
68 	{ KEY_LEFTBRACE,	26},
69 	{ KEY_RIGHTBRACE,	27},
70 
71 	{ KEY_ENTER,		28},
72 	{ KEY_LEFTCTRL,		29},
73 	{ KEY_A,		30},
74 	{ KEY_S,		31},
75 	{ KEY_D,		32},
76 	{ KEY_F,		33},
77 	{ KEY_G,		34},
78 	{ KEY_H,		35},
79 	{ KEY_J,		36},
80 	{ KEY_K,		37},
81 	{ KEY_L,		38},
82 	{ KEY_SEMICOLON,	39},
83 	{ KEY_APOSTROPHE,	40},
84 	{ KEY_GRAVE,		41},
85 
86 	{ KEY_LEFTSHIFT,	42},
87 	{ KEY_BACKSLASH,	43},
88 	{ KEY_Z,		44},
89 	{ KEY_X,		45},
90 	{ KEY_C,		46},
91 	{ KEY_V,		47},
92 	{ KEY_B,		48},
93 	{ KEY_N,		49},
94 	{ KEY_M,		50},
95 	{ KEY_COMMA,		51},
96 	{ KEY_DOT,		52},
97 	{ KEY_SLASH,		53},
98 	{ KEY_RIGHTSHIFT,	54},
99 
100 	{ KEY_LEFTALT,		56},
101 	{ KEY_SPACE,		57},
102 	{ KEY_CAPSLOCK,		58},
103 
104 	{ KEY_F1,		59},
105 	{ KEY_F2,		60},
106 	{ KEY_F3,		61},
107 	{ KEY_F4,		62},
108 	{ KEY_F5,		63},
109 	{ KEY_F6,		64},
110 	{ KEY_F7,		65},
111 	{ KEY_F8,		66},
112 	{ KEY_F9,		67},
113 	{ KEY_F10,		68},
114 	{ KEY_F11,		87},
115 	{ KEY_F12,		88},
116 
117 	{ KEY_RIGHTCTRL,	90},
118 	{ KEY_SYSRQ,		92},
119 	{ KEY_RIGHTALT,		93},
120 
121 	{ KEY_HOME,		GPIOKEY_E0(71)},
122 	{ KEY_UP,		GPIOKEY_E0(72)},
123 	{ KEY_PAGEUP,		GPIOKEY_E0(73)},
124 	{ KEY_LEFT,		GPIOKEY_E0(75)},
125 	{ KEY_RIGHT,		GPIOKEY_E0(77)},
126 	{ KEY_END,		GPIOKEY_E0(79)},
127 	{ KEY_DOWN,		GPIOKEY_E0(80)},
128 	{ KEY_PAGEDOWN,		GPIOKEY_E0(81)},
129 	{ KEY_INSERT,		GPIOKEY_E0(82)},
130 	{ KEY_DELETE,		GPIOKEY_E0(83)},
131 
132 	{ GPIOKEY_NONE,	GPIOKEY_NONE}
133 };
134 
135 uint32_t
136 gpiokey_map_linux_code(uint32_t linux_code)
137 {
138 	int i;
139 
140 	for (i = 0; gpiokeys_codes_map[i].linux_code != GPIOKEY_NONE; i++) {
141 		if (gpiokeys_codes_map[i].linux_code == linux_code)
142 			return (gpiokeys_codes_map[i].bsd_code);
143 	}
144 
145 	return (GPIOKEY_NONE);
146 }
147