brintos

brintos / linux-shallow public Read only

0
0
Text · 9.4 KiB · 38550c1 Raw
167 lines · python
1#!/bin/env python32# SPDX-License-Identifier: GPL-2.03# -*- coding: utf-8 -*-4#5# Copyright (c) 2020 Benjamin Tissoires <benjamin.tissoires@gmail.com>6# Copyright (c) 2020 Red Hat, Inc.7#8 9from .test_keyboard import ArrayKeyboard, TestArrayKeyboard10from hidtools.util import BusType11 12import libevdev13import logging14 15logger = logging.getLogger("hidtools.test.ite-keyboard")16 17KERNEL_MODULE = ("itetech", "hid_ite")18 19 20class KbdData(object):21    pass22 23 24# The ITE keyboards have an issue regarding the Wifi key:25# nothing comes in when pressing the key, but we get a null26# event on the key release.27# This test covers this case.28class ITEKeyboard(ArrayKeyboard):29    # fmt: off30    report_descriptor = [31        0x06, 0x85, 0xff,              # Usage Page (Vendor Usage Page 0xff85)32        0x09, 0x95,                    # Usage (Vendor Usage 0x95)           333        0xa1, 0x01,                    # Collection (Application)            534        0x85, 0x5a,                    # .Report ID (90)                     735        0x09, 0x01,                    # .Usage (Vendor Usage 0x01)          936        0x15, 0x00,                    # .Logical Minimum (0)                1137        0x26, 0xff, 0x00,              # .Logical Maximum (255)              1338        0x75, 0x08,                    # .Report Size (8)                    1639        0x95, 0x10,                    # .Report Count (16)                  1840        0xb1, 0x00,                    # .Feature (Data,Arr,Abs)             2041        0xc0,                          # End Collection                      2242        0x05, 0x01,                    # Usage Page (Generic Desktop)        2343        0x09, 0x06,                    # Usage (Keyboard)                    2544        0xa1, 0x01,                    # Collection (Application)            2745        0x85, 0x01,                    # .Report ID (1)                      2946        0x75, 0x01,                    # .Report Size (1)                    3147        0x95, 0x08,                    # .Report Count (8)                   3348        0x05, 0x07,                    # .Usage Page (Keyboard)              3549        0x19, 0xe0,                    # .Usage Minimum (224)                3750        0x29, 0xe7,                    # .Usage Maximum (231)                3951        0x15, 0x00,                    # .Logical Minimum (0)                4152        0x25, 0x01,                    # .Logical Maximum (1)                4353        0x81, 0x02,                    # .Input (Data,Var,Abs)               4554        0x95, 0x01,                    # .Report Count (1)                   4755        0x75, 0x08,                    # .Report Size (8)                    4956        0x81, 0x03,                    # .Input (Cnst,Var,Abs)               5157        0x95, 0x05,                    # .Report Count (5)                   5358        0x75, 0x01,                    # .Report Size (1)                    5559        0x05, 0x08,                    # .Usage Page (LEDs)                  5760        0x19, 0x01,                    # .Usage Minimum (1)                  5961        0x29, 0x05,                    # .Usage Maximum (5)                  6162        0x91, 0x02,                    # .Output (Data,Var,Abs)              6363        0x95, 0x01,                    # .Report Count (1)                   6564        0x75, 0x03,                    # .Report Size (3)                    6765        0x91, 0x03,                    # .Output (Cnst,Var,Abs)              6966        0x95, 0x06,                    # .Report Count (6)                   7167        0x75, 0x08,                    # .Report Size (8)                    7368        0x15, 0x00,                    # .Logical Minimum (0)                7569        0x26, 0xff, 0x00,              # .Logical Maximum (255)              7770        0x05, 0x07,                    # .Usage Page (Keyboard)              8071        0x19, 0x00,                    # .Usage Minimum (0)                  8272        0x2a, 0xff, 0x00,              # .Usage Maximum (255)                8473        0x81, 0x00,                    # .Input (Data,Arr,Abs)               8774        0xc0,                          # End Collection                      8975        0x05, 0x0c,                    # Usage Page (Consumer Devices)       9076        0x09, 0x01,                    # Usage (Consumer Control)            9277        0xa1, 0x01,                    # Collection (Application)            9478        0x85, 0x02,                    # .Report ID (2)                      9679        0x19, 0x00,                    # .Usage Minimum (0)                  9880        0x2a, 0x3c, 0x02,              # .Usage Maximum (572)                10081        0x15, 0x00,                    # .Logical Minimum (0)                10382        0x26, 0x3c, 0x02,              # .Logical Maximum (572)              10583        0x75, 0x10,                    # .Report Size (16)                   10884        0x95, 0x01,                    # .Report Count (1)                   11085        0x81, 0x00,                    # .Input (Data,Arr,Abs)               11286        0xc0,                          # End Collection                      11487        0x05, 0x01,                    # Usage Page (Generic Desktop)        11588        0x09, 0x0c,                    # Usage (Wireless Radio Controls)     11789        0xa1, 0x01,                    # Collection (Application)            11990        0x85, 0x03,                    # .Report ID (3)                      12191        0x15, 0x00,                    # .Logical Minimum (0)                12392        0x25, 0x01,                    # .Logical Maximum (1)                12593        0x09, 0xc6,                    # .Usage (Wireless Radio Button)      12794        0x95, 0x01,                    # .Report Count (1)                   12995        0x75, 0x01,                    # .Report Size (1)                    13196        0x81, 0x06,                    # .Input (Data,Var,Rel)               13397        0x75, 0x07,                    # .Report Size (7)                    13598        0x81, 0x03,                    # .Input (Cnst,Var,Abs)               13799        0xc0,                          # End Collection                      139100        0x05, 0x88,                    # Usage Page (Vendor Usage Page 0x88) 140101        0x09, 0x01,                    # Usage (Vendor Usage 0x01)           142102        0xa1, 0x01,                    # Collection (Application)            144103        0x85, 0x04,                    # .Report ID (4)                      146104        0x19, 0x00,                    # .Usage Minimum (0)                  148105        0x2a, 0xff, 0xff,              # .Usage Maximum (65535)              150106        0x15, 0x00,                    # .Logical Minimum (0)                153107        0x26, 0xff, 0xff,              # .Logical Maximum (65535)            155108        0x75, 0x08,                    # .Report Size (8)                    158109        0x95, 0x02,                    # .Report Count (2)                   160110        0x81, 0x02,                    # .Input (Data,Var,Abs)               162111        0xc0,                          # End Collection                      164112        0x05, 0x01,                    # Usage Page (Generic Desktop)        165113        0x09, 0x80,                    # Usage (System Control)              167114        0xa1, 0x01,                    # Collection (Application)            169115        0x85, 0x05,                    # .Report ID (5)                      171116        0x19, 0x81,                    # .Usage Minimum (129)                173117        0x29, 0x83,                    # .Usage Maximum (131)                175118        0x15, 0x00,                    # .Logical Minimum (0)                177119        0x25, 0x01,                    # .Logical Maximum (1)                179120        0x95, 0x08,                    # .Report Count (8)                   181121        0x75, 0x01,                    # .Report Size (1)                    183122        0x81, 0x02,                    # .Input (Data,Var,Abs)               185123        0xc0,                          # End Collection                      187124    ]125    # fmt: on126 127    def __init__(128        self,129        rdesc=report_descriptor,130        name=None,131        input_info=(BusType.USB, 0x06CB, 0x2968),132    ):133        super().__init__(rdesc, name, input_info)134 135    def event(self, keys, reportID=None, application=None):136        application = application or "Keyboard"137        return super().event(keys, reportID, application)138 139 140class TestITEKeyboard(TestArrayKeyboard):141    kernel_modules = [KERNEL_MODULE]142 143    def create_device(self):144        return ITEKeyboard()145 146    def test_wifi_key(self):147        uhdev = self.uhdev148        syn_event = self.syn_event149 150        # the following sends a 'release' event on the Wifi key.151        # the kernel is supposed to translate this into Wifi key152        # down and up153        r = [0x03, 0x00]154        uhdev.call_input_event(r)155        expected = [syn_event]156        expected.append(libevdev.InputEvent(libevdev.EV_KEY.KEY_RFKILL, 1))157        events = uhdev.next_sync_events()158        self.debug_reports([r], uhdev, events)159        self.assertInputEventsIn(expected, events)160 161        expected = [syn_event]162        expected.append(libevdev.InputEvent(libevdev.EV_KEY.KEY_RFKILL, 0))163        # the kernel sends the two down/up key events in a batch, no need to164        # call events = uhdev.next_sync_events()165        self.debug_reports([], uhdev, events)166        self.assertInputEventsIn(expected, events)167