xref: /freebsd/sys/dev/gpio/gpiokeys_codes.c (revision 1719886f6d08408b834d270c59ffcfd821c8f63a)
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/param.h>
28 #include <sys/systm.h>
29 
30 #include <dev/gpio/gpiokeys.h>
31 #include <contrib/device-tree/include/dt-bindings/input/linux-event-codes.h>
32 
33 struct gpiokeys_codemap_entry {
34 	uint32_t	linux_code;
35 	uint32_t	bsd_code;
36 };
37 
38 static struct gpiokeys_codemap_entry gpiokeys_codes_map[] = {
39 	{ KEY_ESC,		1},
40 	{ KEY_1,		2},
41 	{ KEY_2,		3},
42 	{ KEY_3,		4},
43 	{ KEY_4,		5},
44 	{ KEY_5,		6},
45 	{ KEY_6,		7},
46 	{ KEY_7,		8},
47 	{ KEY_8,		9},
48 	{ KEY_9,		10},
49 	{ KEY_0,		11},
50 	{ KEY_MINUS,		12},
51 	{ KEY_EQUAL,		13},
52 	{ KEY_BACKSPACE,	14},
53 
54 	{ KEY_TAB,		15},
55 	{ KEY_Q,		16},
56 	{ KEY_W,		17},
57 	{ KEY_E,		18},
58 	{ KEY_R,		19},
59 	{ KEY_T,		20},
60 	{ KEY_Y,		21},
61 	{ KEY_U,		22},
62 	{ KEY_I,		23},
63 	{ KEY_O,		24},
64 	{ KEY_P,		25},
65 	{ KEY_LEFTBRACE,	26},
66 	{ KEY_RIGHTBRACE,	27},
67 
68 	{ KEY_ENTER,		28},
69 	{ KEY_LEFTCTRL,		29},
70 	{ KEY_A,		30},
71 	{ KEY_S,		31},
72 	{ KEY_D,		32},
73 	{ KEY_F,		33},
74 	{ KEY_G,		34},
75 	{ KEY_H,		35},
76 	{ KEY_J,		36},
77 	{ KEY_K,		37},
78 	{ KEY_L,		38},
79 	{ KEY_SEMICOLON,	39},
80 	{ KEY_APOSTROPHE,	40},
81 	{ KEY_GRAVE,		41},
82 
83 	{ KEY_LEFTSHIFT,	42},
84 	{ KEY_BACKSLASH,	43},
85 	{ KEY_Z,		44},
86 	{ KEY_X,		45},
87 	{ KEY_C,		46},
88 	{ KEY_V,		47},
89 	{ KEY_B,		48},
90 	{ KEY_N,		49},
91 	{ KEY_M,		50},
92 	{ KEY_COMMA,		51},
93 	{ KEY_DOT,		52},
94 	{ KEY_SLASH,		53},
95 	{ KEY_RIGHTSHIFT,	54},
96 
97 	{ KEY_LEFTALT,		56},
98 	{ KEY_SPACE,		57},
99 	{ KEY_CAPSLOCK,		58},
100 
101 	{ KEY_F1,		59},
102 	{ KEY_F2,		60},
103 	{ KEY_F3,		61},
104 	{ KEY_F4,		62},
105 	{ KEY_F5,		63},
106 	{ KEY_F6,		64},
107 	{ KEY_F7,		65},
108 	{ KEY_F8,		66},
109 	{ KEY_F9,		67},
110 	{ KEY_F10,		68},
111 	{ KEY_F11,		87},
112 	{ KEY_F12,		88},
113 
114 	{ KEY_RIGHTCTRL,	90},
115 	{ KEY_SYSRQ,		92},
116 	{ KEY_RIGHTALT,		93},
117 
118 	{ KEY_HOME,		GPIOKEY_E0(71)},
119 	{ KEY_UP,		GPIOKEY_E0(72)},
120 	{ KEY_PAGEUP,		GPIOKEY_E0(73)},
121 	{ KEY_LEFT,		GPIOKEY_E0(75)},
122 	{ KEY_RIGHT,		GPIOKEY_E0(77)},
123 	{ KEY_END,		GPIOKEY_E0(79)},
124 	{ KEY_DOWN,		GPIOKEY_E0(80)},
125 	{ KEY_PAGEDOWN,		GPIOKEY_E0(81)},
126 	{ KEY_INSERT,		GPIOKEY_E0(82)},
127 	{ KEY_DELETE,		GPIOKEY_E0(83)},
128 
129 	{ GPIOKEY_NONE,	GPIOKEY_NONE}
130 };
131 
132 uint32_t
133 gpiokey_map_linux_code(uint32_t linux_code)
134 {
135 	int i;
136 
137 	for (i = 0; gpiokeys_codes_map[i].linux_code != GPIOKEY_NONE; i++) {
138 		if (gpiokeys_codes_map[i].linux_code == linux_code)
139 			return (gpiokeys_codes_map[i].bsd_code);
140 	}
141 
142 	return (GPIOKEY_NONE);
143 }
144