1299475Sgonzo/*- 2299475Sgonzo * Copyright (c) 2015 Oleksandr Tymoshenko <gonzo@freebsd.org> 3299475Sgonzo * All rights reserved. 4299475Sgonzo * 5299475Sgonzo * Redistribution and use in source and binary forms, with or without 6299475Sgonzo * modification, are permitted provided that the following conditions 7299475Sgonzo * are met: 8299475Sgonzo * 1. Redistributions of source code must retain the above copyright 9299475Sgonzo * notice, this list of conditions and the following disclaimer. 10299475Sgonzo * 2. Redistributions in binary form must reproduce the above copyright 11299475Sgonzo * notice, this list of conditions and the following disclaimer in the 12299475Sgonzo * documentation and/or other materials provided with the distribution. 13299475Sgonzo * 14299475Sgonzo * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15299475Sgonzo * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16299475Sgonzo * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17299475Sgonzo * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18299475Sgonzo * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19299475Sgonzo * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20299475Sgonzo * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21299475Sgonzo * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22299475Sgonzo * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23299475Sgonzo * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24299475Sgonzo * SUCH DAMAGE. 25299475Sgonzo */ 26299475Sgonzo 27299475Sgonzo#include <sys/cdefs.h> 28299475Sgonzo__FBSDID("$FreeBSD: releng/11.0/sys/dev/gpio/gpiokeys_codes.c 299475 2016-05-11 17:57:26Z gonzo $"); 29299475Sgonzo 30299475Sgonzo#include <sys/param.h> 31299475Sgonzo#include <sys/systm.h> 32299475Sgonzo 33299475Sgonzo#include <dev/gpio/gpiokeys.h> 34299475Sgonzo#include <gnu/dts/include/dt-bindings/input/linux-event-codes.h> 35299475Sgonzo 36299475Sgonzostruct gpiokeys_codemap_entry { 37299475Sgonzo uint32_t linux_code; 38299475Sgonzo uint32_t bsd_code; 39299475Sgonzo}; 40299475Sgonzo 41299475Sgonzostatic struct gpiokeys_codemap_entry gpiokeys_codes_map[] = { 42299475Sgonzo { KEY_ESC, 1}, 43299475Sgonzo { KEY_1, 2}, 44299475Sgonzo { KEY_2, 3}, 45299475Sgonzo { KEY_3, 4}, 46299475Sgonzo { KEY_4, 5}, 47299475Sgonzo { KEY_5, 6}, 48299475Sgonzo { KEY_6, 7}, 49299475Sgonzo { KEY_7, 8}, 50299475Sgonzo { KEY_8, 9}, 51299475Sgonzo { KEY_9, 10}, 52299475Sgonzo { KEY_0, 11}, 53299475Sgonzo { KEY_MINUS, 12}, 54299475Sgonzo { KEY_EQUAL, 13}, 55299475Sgonzo { KEY_BACKSPACE, 14}, 56299475Sgonzo 57299475Sgonzo { KEY_TAB, 15}, 58299475Sgonzo { KEY_Q, 16}, 59299475Sgonzo { KEY_W, 17}, 60299475Sgonzo { KEY_E, 18}, 61299475Sgonzo { KEY_R, 19}, 62299475Sgonzo { KEY_T, 20}, 63299475Sgonzo { KEY_Y, 21}, 64299475Sgonzo { KEY_U, 22}, 65299475Sgonzo { KEY_I, 23}, 66299475Sgonzo { KEY_O, 24}, 67299475Sgonzo { KEY_P, 25}, 68299475Sgonzo { KEY_LEFTBRACE, 26}, 69299475Sgonzo { KEY_RIGHTBRACE, 27}, 70299475Sgonzo 71299475Sgonzo { KEY_ENTER, 28}, 72299475Sgonzo { KEY_LEFTCTRL, 29}, 73299475Sgonzo { KEY_A, 30}, 74299475Sgonzo { KEY_S, 31}, 75299475Sgonzo { KEY_D, 32}, 76299475Sgonzo { KEY_F, 33}, 77299475Sgonzo { KEY_G, 34}, 78299475Sgonzo { KEY_H, 35}, 79299475Sgonzo { KEY_J, 36}, 80299475Sgonzo { KEY_K, 37}, 81299475Sgonzo { KEY_L, 38}, 82299475Sgonzo { KEY_SEMICOLON, 39}, 83299475Sgonzo { KEY_APOSTROPHE, 40}, 84299475Sgonzo { KEY_GRAVE, 41}, 85299475Sgonzo 86299475Sgonzo { KEY_LEFTSHIFT, 42}, 87299475Sgonzo { KEY_BACKSLASH, 43}, 88299475Sgonzo { KEY_Z, 44}, 89299475Sgonzo { KEY_X, 45}, 90299475Sgonzo { KEY_C, 46}, 91299475Sgonzo { KEY_V, 47}, 92299475Sgonzo { KEY_B, 48}, 93299475Sgonzo { KEY_N, 49}, 94299475Sgonzo { KEY_M, 50}, 95299475Sgonzo { KEY_COMMA, 51}, 96299475Sgonzo { KEY_DOT, 52}, 97299475Sgonzo { KEY_SLASH, 53}, 98299475Sgonzo { KEY_RIGHTSHIFT, 54}, 99299475Sgonzo 100299475Sgonzo { KEY_LEFTALT, 56}, 101299475Sgonzo { KEY_SPACE, 57}, 102299475Sgonzo { KEY_CAPSLOCK, 58}, 103299475Sgonzo 104299475Sgonzo { KEY_F1, 59}, 105299475Sgonzo { KEY_F2, 60}, 106299475Sgonzo { KEY_F3, 61}, 107299475Sgonzo { KEY_F4, 62}, 108299475Sgonzo { KEY_F5, 63}, 109299475Sgonzo { KEY_F6, 64}, 110299475Sgonzo { KEY_F7, 65}, 111299475Sgonzo { KEY_F8, 66}, 112299475Sgonzo { KEY_F9, 67}, 113299475Sgonzo { KEY_F10, 68}, 114299475Sgonzo { KEY_F11, 87}, 115299475Sgonzo { KEY_F12, 88}, 116299475Sgonzo 117299475Sgonzo { KEY_RIGHTCTRL, 90}, 118299475Sgonzo { KEY_SYSRQ, 92}, 119299475Sgonzo { KEY_RIGHTALT, 93}, 120299475Sgonzo 121299475Sgonzo { KEY_HOME, GPIOKEY_E0(71)}, 122299475Sgonzo { KEY_UP, GPIOKEY_E0(72)}, 123299475Sgonzo { KEY_PAGEUP, GPIOKEY_E0(73)}, 124299475Sgonzo { KEY_LEFT, GPIOKEY_E0(75)}, 125299475Sgonzo { KEY_RIGHT, GPIOKEY_E0(77)}, 126299475Sgonzo { KEY_END, GPIOKEY_E0(79)}, 127299475Sgonzo { KEY_DOWN, GPIOKEY_E0(80)}, 128299475Sgonzo { KEY_PAGEDOWN, GPIOKEY_E0(81)}, 129299475Sgonzo { KEY_INSERT, GPIOKEY_E0(82)}, 130299475Sgonzo { KEY_DELETE, GPIOKEY_E0(83)}, 131299475Sgonzo 132299475Sgonzo { GPIOKEY_NONE, GPIOKEY_NONE} 133299475Sgonzo}; 134299475Sgonzo 135299475Sgonzouint32_t 136299475Sgonzogpiokey_map_linux_code(uint32_t linux_code) 137299475Sgonzo{ 138299475Sgonzo int i; 139299475Sgonzo 140299475Sgonzo for (i = 0; gpiokeys_codes_map[i].linux_code != GPIOKEY_NONE; i++) { 141299475Sgonzo if (gpiokeys_codes_map[i].linux_code == linux_code) 142299475Sgonzo return (gpiokeys_codes_map[i].bsd_code); 143299475Sgonzo } 144299475Sgonzo 145299475Sgonzo return (GPIOKEY_NONE); 146299475Sgonzo} 147