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