// SPDX-License-Identifier: GPL-2.0
/*
* drivers/macintosh/adbhid.c
*
* ADB HID driver for Power Macintosh computers.
*
* Adapted from drivers/macintosh/mac_keyb.c by Franz Sirl.
* drivers/macintosh/mac_keyb.c was Copyright (C) 1996 Paul Mackerras
* with considerable contributions from Ben Herrenschmidt and others.
*
* Copyright (C) 2000 Franz Sirl.
*
* Adapted to ADB changes and support for more devices by
* Benjamin Herrenschmidt. Adapted from code in MkLinux
* and reworked.
*
* Supported devices:
*
* - Standard 1 button mouse
* - All standard Apple Extended protocol (handler ID 4)
* - mouseman and trackman mice & trackballs
* - PowerBook Trackpad (default setup: enable tapping)
* - MicroSpeed mouse & trackball (needs testing)
* - CH Products Trackball Pro (needs testing)
* - Contour Design (Contour Mouse)
* - Hunter digital (NoHandsMouse)
* - Kensignton TurboMouse 5 (needs testing)
* - Mouse Systems A3 mice and trackballs <aidan@kublai.com>
* - MacAlly 2-buttons mouse (needs testing) <pochini@denise.shiny.it>
*
* To do:
*
* Improve Kensington support.
* Split mouse/kbd
* Move to syfs
*/
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/init.h>
#include <linux/notifier.h>
#include <linux/input.h>
#include <linux/adb.h>
#include <linux/cuda.h>
#include <linux/pmu.h>
#include <asm/machdep.h>
#ifdef CONFIG_PPC_PMAC
#include <asm/backlight.h>
#include <asm/pmac_feature.h>
#endif
MODULE_AUTHOR("Franz Sirl <Franz.Sirl-kernel@lauterbach.com>");
static int restore_capslock_events;
module_param(restore_capslock_events, int, 0644);
MODULE_PARM_DESC(restore_capslock_events,
"Produce keypress events for capslock on both keyup and keydown.");
#define KEYB_KEYREG 0 /* register # for key up/down data */
#define KEYB_LEDREG 2 /* register # for leds on ADB keyboard */
#define MOUSE_DATAREG 0 /* reg# for movement/button codes from mouse */
static int adb_message_handler(struct notifier_block *, unsigned long, void *);
static struct notifier_block adbhid_adb_notifier = {
.notifier_call = adb_message_handler,
};
/* Some special keys */
#define ADB_KEY_DEL 0x33
#define ADB_KEY_CMD 0x37
#define ADB_KEY_CAPSLOCK 0x39
#define ADB_KEY_FN 0x3f
#define ADB_KEY_FWDEL 0x75
#define ADB_KEY_POWER_OLD 0x7e
#define ADB_KEY_POWER 0x7f
static const u16 adb_to_linux_keycodes[128] = {
/* 0x00 */ KEY_A, /* 30 */
/* 0x01 */ KEY_S, /* 31 */
/* 0x02 */ KEY_D, /* 32 */
/* 0x03 */ KEY_F, /* 33 */
/* 0x04 */ KEY_H, /* 35 */
/* 0x05 */ KEY_G, /* 34 */
/* 0x06 */ KEY_Z, /* 44 */
/* 0x07 */ KEY_X, /* 45 */
/* 0x08 */ KEY_C, /* 46 */
/* 0x09 */ KEY_V, /* 47 */
/* 0x0a */ KEY_102ND, /* 86 */
/* 0x0b */ KEY_B, /* 48 */
/* 0x0c */ KEY_Q, /* 16 */
/* 0x0d */ KEY_W, /* 17 */
/* 0x0e */ KEY_E, /* 18 */
/* 0x0f */ KEY_R, /* 19 */
/* 0x10 */ KEY_Y, /* 21 */
/* 0x11 */ KEY_T, /* 20 */
/* 0x12 */ KEY_1, /* 2 */
/* 0x13 */ KEY_2, /* 3 */
/* 0x14 */ KEY_3, /* 4 */
/* 0x15 */ KEY_4, /* 5 */
/* 0x16 */ KEY_6, /* 7 */
/* 0x17 */ KEY_5, /* 6 */
/* 0x18 */ KEY_EQUAL, /* 13 */
/* 0x19 */ KEY_9, /* 10 */
/* 0x1a */ KEY_7, /* 8 */
/* 0x1b */ KEY_MINUS, /* 12 */
/* 0x1c */ KEY_8, /* 9 */
/* 0x1d