adb_kbd.c (224126) | adb_kbd.c (226449) |
---|---|
1/*- 2 * Copyright (C) 2008 Nathan Whitehorn 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 --- 8 unchanged lines hidden (view full) --- 17 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 18 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 20 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 21 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 22 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 23 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * | 1/*- 2 * Copyright (C) 2008 Nathan Whitehorn 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 --- 8 unchanged lines hidden (view full) --- 17 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 18 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 20 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 21 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 22 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 23 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * |
25 * $FreeBSD: head/sys/dev/adb/adb_kbd.c 224126 2011-07-17 08:19:19Z ed $ | 25 * $FreeBSD: head/sys/dev/adb/adb_kbd.c 226449 2011-10-16 21:01:42Z nwhitehorn $ |
26 */ 27 28#include <sys/cdefs.h> 29#include <sys/param.h> 30#include <sys/systm.h> 31#include <sys/module.h> 32#include <sys/bus.h> 33#include <sys/conf.h> 34#include <sys/kbio.h> 35#include <sys/condvar.h> 36#include <sys/callout.h> 37#include <sys/kernel.h> | 26 */ 27 28#include <sys/cdefs.h> 29#include <sys/param.h> 30#include <sys/systm.h> 31#include <sys/module.h> 32#include <sys/bus.h> 33#include <sys/conf.h> 34#include <sys/kbio.h> 35#include <sys/condvar.h> 36#include <sys/callout.h> 37#include <sys/kernel.h> |
38#include <sys/sysctl.h> |
|
38 39#include <machine/bus.h> 40 41#include "opt_kbd.h" 42#include <dev/kbd/kbdreg.h> 43#include <dev/kbd/kbdtables.h> | 39 40#include <machine/bus.h> 41 42#include "opt_kbd.h" 43#include <dev/kbd/kbdreg.h> 44#include <dev/kbd/kbdtables.h> |
45#include <dev/ofw/openfirm.h> 46#include <dev/ofw/ofw_bus.h> |
|
44 45#include <vm/vm.h> 46#include <vm/pmap.h> 47 48#include "adb.h" 49 50#define KBD_DRIVER_NAME "akbd" 51 52#define AKBD_EMULATE_ATKBD 1 53 54static int adb_kbd_probe(device_t dev); 55static int adb_kbd_attach(device_t dev); 56static int adb_kbd_detach(device_t dev); 57static void akbd_repeat(void *xsc); | 47 48#include <vm/vm.h> 49#include <vm/pmap.h> 50 51#include "adb.h" 52 53#define KBD_DRIVER_NAME "akbd" 54 55#define AKBD_EMULATE_ATKBD 1 56 57static int adb_kbd_probe(device_t dev); 58static int adb_kbd_attach(device_t dev); 59static int adb_kbd_detach(device_t dev); 60static void akbd_repeat(void *xsc); |
61static int adb_fn_keys(SYSCTL_HANDLER_ARGS); |
|
58 59static u_int adb_kbd_receive_packet(device_t dev, u_char status, 60 u_char command, u_char reg, int len, u_char *data); 61 62struct adb_kbd_softc { 63 keyboard_t sc_kbd; 64 65 device_t sc_dev; --- 211 unchanged lines hidden (view full) --- 277 return ms/(1000/hz); 278} 279 280static int 281adb_kbd_attach(device_t dev) 282{ 283 struct adb_kbd_softc *sc; 284 keyboard_switch_t *sw; | 62 63static u_int adb_kbd_receive_packet(device_t dev, u_char status, 64 u_char command, u_char reg, int len, u_char *data); 65 66struct adb_kbd_softc { 67 keyboard_t sc_kbd; 68 69 device_t sc_dev; --- 211 unchanged lines hidden (view full) --- 281 return ms/(1000/hz); 282} 283 284static int 285adb_kbd_attach(device_t dev) 286{ 287 struct adb_kbd_softc *sc; 288 keyboard_switch_t *sw; |
289 uint32_t fkeys; 290 phandle_t handle; |
|
285 286 sw = kbd_get_switch(KBD_DRIVER_NAME); 287 if (sw == NULL) { 288 return ENXIO; 289 } 290 291 sc = device_get_softc(dev); 292 sc->sc_dev = dev; --- 35 unchanged lines hidden (view full) --- 328 329 /* Check if we can read out the LED state from 330 this keyboard by reading the key state register */ 331 if (adb_read_register(dev, 2, NULL) == 2) 332 sc->have_led_control = 1; 333 334 adb_set_autopoll(dev,1); 335 | 291 292 sw = kbd_get_switch(KBD_DRIVER_NAME); 293 if (sw == NULL) { 294 return ENXIO; 295 } 296 297 sc = device_get_softc(dev); 298 sc->sc_dev = dev; --- 35 unchanged lines hidden (view full) --- 334 335 /* Check if we can read out the LED state from 336 this keyboard by reading the key state register */ 337 if (adb_read_register(dev, 2, NULL) == 2) 338 sc->have_led_control = 1; 339 340 adb_set_autopoll(dev,1); 341 |
342 handle = OF_finddevice("mac-io/via-pmu/adb/keyboard"); 343 if (handle != -1 && OF_getprop(handle, "AAPL,has-embedded-fn-keys", 344 &fkeys, sizeof(fkeys)) != -1) { 345 static const char *key_names[] = {"F1", "F2", "F3", "F4", "F5", 346 "F6", "F7", "F8", "F9", "F10", "F11", "F12"}; 347 struct sysctl_ctx_list *ctx; 348 struct sysctl_oid *tree; 349 int i; 350 351 if (bootverbose) 352 device_printf(dev, "Keyboard has embedded Fn keys\n"); 353 354 for (i = 0; i < 12; i++) { 355 uint32_t keyval; 356 char buf[3]; 357 if (OF_getprop(handle, key_names[i], &keyval, 358 sizeof(keyval)) < 0) 359 continue; 360 buf[0] = 1; 361 buf[1] = i+1; 362 buf[2] = keyval; 363 adb_write_register(dev, 0, 3, buf); 364 } 365 adb_write_register(dev, 1, 2, &(uint16_t){0}); 366 367 ctx = device_get_sysctl_ctx(dev); 368 tree = device_get_sysctl_tree(dev); 369 370 SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, 371 "fn_keys_function_as_primary", CTLTYPE_INT | CTLFLAG_RW, sc, 372 0, adb_fn_keys, "I", 373 "Set the Fn keys to be their F-key type as default"); 374 } 375 |
|
336 return (0); 337} 338 339static int 340adb_kbd_detach(device_t dev) 341{ 342 struct adb_kbd_softc *sc; 343 keyboard_t *kbd; --- 34 unchanged lines hidden (view full) --- 378 379 if (command != ADB_COMMAND_TALK) 380 return 0; 381 382 if (reg != 0 || len != 2) 383 return (0); 384 385 mtx_lock(&sc->sc_mutex); | 376 return (0); 377} 378 379static int 380adb_kbd_detach(device_t dev) 381{ 382 struct adb_kbd_softc *sc; 383 keyboard_t *kbd; --- 34 unchanged lines hidden (view full) --- 418 419 if (command != ADB_COMMAND_TALK) 420 return 0; 421 422 if (reg != 0 || len != 2) 423 return (0); 424 425 mtx_lock(&sc->sc_mutex); |
426 /* 0x7f is always the power button */ 427 if (data[0] == 0x7f && devctl_process_running()) { 428 devctl_notify("PMU", "Button", "pressed", NULL); 429 return (0); 430 } else if (data[0] == 0xff) { 431 return (0); /* Ignore power button release. */ 432 } |
|
386 if ((data[0] & 0x7f) == 57 && sc->buffers < 7) { 387 /* Fake the down/up cycle for caps lock */ 388 sc->buffer[sc->buffers++] = data[0] & 0x7f; 389 sc->buffer[sc->buffers++] = (data[0] & 0x7f) | (1 << 7); 390 } else { 391 sc->buffer[sc->buffers++] = data[0]; 392 } | 433 if ((data[0] & 0x7f) == 57 && sc->buffers < 7) { 434 /* Fake the down/up cycle for caps lock */ 435 sc->buffer[sc->buffers++] = data[0] & 0x7f; 436 sc->buffer[sc->buffers++] = (data[0] & 0x7f) | (1 << 7); 437 } else { 438 sc->buffer[sc->buffers++] = data[0]; 439 } |
393 | |
394 if (sc->buffer[sc->buffers-1] < 0xff) 395 sc->last_press = sc->buffer[sc->buffers-1]; 396 397 if ((data[1] & 0x7f) == 57 && sc->buffers < 7) { 398 /* Fake the down/up cycle for caps lock */ 399 sc->buffer[sc->buffers++] = data[1] & 0x7f; 400 sc->buffer[sc->buffers++] = (data[1] & 0x7f) | (1 << 7); 401 } else { --- 407 unchanged lines hidden (view full) --- 809 810 default: 811 return (EOPNOTSUPP); 812 } 813 814 return (0); 815} 816 | 440 if (sc->buffer[sc->buffers-1] < 0xff) 441 sc->last_press = sc->buffer[sc->buffers-1]; 442 443 if ((data[1] & 0x7f) == 57 && sc->buffers < 7) { 444 /* Fake the down/up cycle for caps lock */ 445 sc->buffer[sc->buffers++] = data[1] & 0x7f; 446 sc->buffer[sc->buffers++] = (data[1] & 0x7f) | (1 << 7); 447 } else { --- 407 unchanged lines hidden (view full) --- 855 856 default: 857 return (EOPNOTSUPP); 858 } 859 860 return (0); 861} 862 |
863static int 864adb_fn_keys(SYSCTL_HANDLER_ARGS) 865{ 866 struct adb_kbd_softc *sc = arg1; 867 int error; 868 uint16_t is_fn_enabled; 869 unsigned int is_fn_enabled_sysctl; 870 871 adb_read_register(sc->sc_dev, 1, &is_fn_enabled); 872 is_fn_enabled &= 1; 873 is_fn_enabled_sysctl = is_fn_enabled; 874 error = sysctl_handle_int(oidp, &is_fn_enabled_sysctl, 0, req); 875 876 if (error || !req->newptr) 877 return (error); 878 879 is_fn_enabled = is_fn_enabled_sysctl; 880 if (is_fn_enabled != 1 && is_fn_enabled != 0) 881 return (EINVAL); 882 883 adb_write_register(sc->sc_dev, 1, 2, &is_fn_enabled); 884 return (0); 885} 886 |
|
817DEV_MODULE(akbd, akbd_modevent, NULL); 818 | 887DEV_MODULE(akbd, akbd_modevent, NULL); 888 |