// SPDX-License-Identifier: GPL-2.0+ /* * This is a driver for the keyboard, touchpad and USB port of the * keyboard dock for the Asus TF103C 2-in-1 tablet. * * This keyboard dock has its own I2C attached embedded controller * and the keyboard and touchpad are also connected over I2C, * instead of using the usual USB connection. This means that the * keyboard dock requires this special driver to function. * * Copyright (C) 2021 Hans de Goede <hdegoede@redhat.com>
*/
staticbool fnlock;
module_param(fnlock, bool, 0644);
MODULE_PARM_DESC(fnlock, "By default the kbd toprow sends multimedia key presses. AltGr " "can be pressed to change this to F1-F12. Set this to 1 to " "change the default. Press AltGr + Esc to toggle at runtime.");
/* * Stop AltGr reports from getting reported on the "Asus TF103C Dock * Keyboard" input_dev, since this gets used as "Fn" key for the toprow * keys. Instead we report this on the "Asus TF103C Dock Top Row Keys" * input_dev, when not used to modify the toprow keys.
*/
dock->altgr_pressed = buf[TF103C_DOCK_KBD_DATA_MODIFIERS] & 0x40;
buf[TF103C_DOCK_KBD_DATA_MODIFIERS] &= ~0x40;
staticvoid tf103c_dock_toprow_press(struct tf103c_dock_data *dock, int key_code)
{ /* * Release AltGr before reporting the toprow key, so that userspace * sees e.g. just KEY_SUSPEND and not AltGr + KEY_SUSPEND.
*/ if (dock->altgr_pressed) {
input_report_key(dock->input, KEY_RIGHTALT, false);
input_sync(dock->input);
}
if (last_press)
*last_press = key_code; else
tf103c_dock_toprow_release(dock, key_code);
}
/* * The keyboard sends what appears to be standard I2C-HID input-reports, * except that a 16 bit register address of where the I2C-HID format * input-reports are stored must be send before reading it in a single * (I2C repeated-start) I2C transaction. * * Its unknown how to get the HID descriptors but they are easy to reconstruct: * * Input report id 0x11 is 8 bytes long and contain standard USB HID intf-class, * Boot Interface Subclass reports. * Input report id 0x13 is 2 bytes long and sends Consumer Control events * Input report id 0x14 is 1 byte long and sends System Control events * * However the top row keys (where a normal keyboard has F1-F12 + Print-Screen) * are a mess, using a mix of the 0x13 and 0x14 input reports as well as EC SCI * events; and these need special handling to allow actually sending F1-F12, * since the Fn key on the keyboard only works on the cursor keys and the top * row keys always send their special "Multimedia hotkey" codes. * * So only forward the 0x11 reports to HID and handle the top-row keys here.
*/ staticvoid tf103c_dock_kbd_interrupt(struct tf103c_dock_data *dock)
{ struct device *dev = &dock->ec_client->dev;
u8 *buf = dock->kbd_buf; int size;
if (tf103c_dock_kbd_read(dock)) return;
size = buf[0] | buf[1] << 8; if (size < TF103C_DOCK_KBD_DATA_MIN_LENGTH ||
size > TF103C_DOCK_KBD_DATA_MAX_LENGTH) {
dev_err(dev, "error reported kbd pkt size %d is out of range %d-%d\n", size,
TF103C_DOCK_KBD_DATA_MIN_LENGTH,
TF103C_DOCK_KBD_DATA_MAX_LENGTH); return;
}
switch (buf[2]) { case 0x11: if (size != 11) break;
tf103c_dock_report_toprow_kbd_hook(dock);
if (test_bit(TF103C_DOCK_FLAG_HID_OPEN, &dock->flags))
hid_input_report(dock->hid, HID_INPUT_REPORT, buf + 2, size - 2, 1); return; case 0x13: if (size != 5) break;
switch (buf[3] | buf[4] << 8) { case 0:
tf103c_dock_toprow_event(dock, -1, &dock->last_press_0x13); return; case 0x70:
tf103c_dock_toprow_event(dock, 3, &dock->last_press_0x13); return; case 0x6f:
tf103c_dock_toprow_event(dock, 4, &dock->last_press_0x13); return; case 0xb6:
tf103c_dock_toprow_event(dock, 7, &dock->last_press_0x13); return; case 0xcd:
tf103c_dock_toprow_event(dock, 8, &dock->last_press_0x13); return; case 0xb5:
tf103c_dock_toprow_event(dock, 9, &dock->last_press_0x13); return; case 0xe2:
tf103c_dock_toprow_event(dock, 10, &dock->last_press_0x13); return; case 0xea:
tf103c_dock_toprow_event(dock, 11, &dock->last_press_0x13); return; case 0xe9:
tf103c_dock_toprow_event(dock, 12, &dock->last_press_0x13); return;
} break; case 0x14: if (size != 4) break;
switch (buf[3]) { case 0:
tf103c_dock_toprow_event(dock, -1, &dock->last_press_0x14); return; case 1:
tf103c_dock_toprow_event(dock, 0, &dock->last_press_0x14); return;
} break;
}
/* * tf103c_enable_touchpad() is only called from the threaded interrupt handler * and tf103c_disable_touchpad() is only called after the irq is disabled, * so no locking is necessary.
*/ staticvoid tf103c_dock_enable_touchpad(struct tf103c_dock_data *dock)
{ struct i2c_board_info board_info = { }; struct device *dev = &dock->ec_client->dev; int ret;
if (dock->tp_enabled) { /* Happens after resume, the tp needs to be reinitialized */
ret = device_reprobe(&dock->tp_client->dev); if (ret)
dev_err_probe(dev, ret, "reprobing tp-client\n"); return;
}
switch (val) { case TF103C_DOCK_SMI_EC_WAKEUP:
tf103c_dock_ec_cmd(dock, tf103c_dock_enable_cmd);
tf103c_dock_ec_cmd(dock, tf103c_dock_usb_enable_cmd);
tf103c_dock_kbd_write(dock, TF103C_DOCK_KBD_CMD_ENABLE); break; case TF103C_DOCK_SMI_PAD_BL_CHANGE: /* There is no backlight, but the EC still sends this */ break; case TF103C_DOCK_SMI_HID_STATUS_CHANGED:
tf103c_dock_enable_touchpad(dock); break; default:
dev_warn(dev, "warning unknown SMI value: 0x%02x\n", val); break;
}
}
if (!(intr_data[1] & TF103C_DOCK_INTR_DATA1_OBF_MASK)) return IRQ_NONE;
/* intr_data[0] is the length of the rest of the packet */ if (intr_data[0] == 3 && intr_data[1] == TF103C_DOCK_INTR_DATA1_OOB_VALUE &&
intr_data[2] == TF103C_DOCK_INTR_DATA2_OOB_VALUE) { /* intr_data[3] seems to contain a HID input report id */ switch (intr_data[3]) { case 0x01:
handle_nested_irq(dock->tp_irq); break; case 0x11: case 0x13: case 0x14:
tf103c_dock_kbd_interrupt(dock); break; default:
dev_warn(dev, "warning unknown intr_data[3]: 0x%02x\n", intr_data[3]); break;
} return IRQ_HANDLED;
}
if (intr_data[1] & TF103C_DOCK_INTR_DATA1_SCI_MASK) {
tf103c_dock_sci(dock, intr_data[2]); return IRQ_HANDLED;
}
if (intr_data[1] & TF103C_DOCK_INTR_DATA1_SMI_MASK) {
tf103c_dock_smi(dock, intr_data[2]); return IRQ_HANDLED;
}
/* * tf103c_dock_[dis|en]able only run from hpd_work or at times when * hpd_work cannot run (hpd_irq disabled), so no locking is necessary.
*/ staticvoid tf103c_dock_enable(struct tf103c_dock_data *dock)
{ if (dock->enabled) return;
if (dock->board_rev != 2)
gpiod_set_value(dock->pwr_en, 1);
msleep(500);
enable_irq(dock->irq);
dock->enabled = true;
}
staticvoid tf103c_dock_disable(struct tf103c_dock_data *dock)
{ if (!dock->enabled) return;
disable_irq(dock->irq);
tf103c_dock_disable_touchpad(dock); if (dock->board_rev != 2)
gpiod_set_value(dock->pwr_en, 0);
/* 1. Get GPIOs and their IRQs */
gpiod_add_lookup_table(&tf103c_dock_gpios);
ret = devm_add_action_or_reset(dev, tf103c_dock_non_devm_cleanup, dock); if (ret) return ret;
/* * The pin is configured as input by default, use ASIS because otherwise * the gpio-crystalcove.c switches off the internal pull-down replacing * it with a pull-up.
*/
board_rev_gpio = gpiod_get(dev, "board_rev", GPIOD_ASIS); if (IS_ERR(board_rev_gpio)) return dev_err_probe(dev, PTR_ERR(board_rev_gpio), "requesting board_rev GPIO\n");
dock->board_rev = gpiod_get_value_cansleep(board_rev_gpio) + 1;
gpiod_put(board_rev_gpio);
/* * The Android driver drives the dock-pwr-en pin high at probe for * revision 2 boards and then never touches it again? * This code has only been tested on a revision 1 board, so for now * just mimick what Android does on revision 2 boards.
*/
flags = (dock->board_rev == 2) ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW;
dock->pwr_en = devm_gpiod_get(dev, "dock_pwr_en", flags); if (IS_ERR(dock->pwr_en)) return dev_err_probe(dev, PTR_ERR(dock->pwr_en), "requesting pwr_en GPIO\n");
ret = devm_request_irq(dev, dock->hpd_irq, tf103c_dock_hpd_irq,
IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_NO_AUTOEN, "dock_hpd", dock); if (ret) return ret;
/* * 2. Create I2C clients. The dock uses 4 different i2c addresses, * the ACPI NPCE69A node being probed points to the EC address.
*/
dock->ec_client = client;
if (dock->enabled) { if (device_may_wakeup(dev))
disable_irq_wake(dock->irq);
/* Don't try to resume if the dock was unplugged during suspend */ if (gpiod_get_value(dock->hpd_gpio))
tf103c_dock_ec_cmd(dock, tf103c_dock_enable_cmd);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.