The branch main has been updated by wulf:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=a9227954b0f01e950cc51d744af27585778ddf84

commit a9227954b0f01e950cc51d744af27585778ddf84
Author:     Vladimir Kondratyev <w...@freebsd.org>
AuthorDate: 2025-09-22 08:37:19 +0000
Commit:     Vladimir Kondratyev <w...@freebsd.org>
CommitDate: 2025-09-22 08:37:19 +0000

    ietp(4): Always overload HID report descriptor
    
    It is required since "iichid(4): Always use wMaxInputLength bytes
    as input report length" commit.
    
    MFC after:      1 week
---
 sys/dev/hid/ietp.c | 55 +++++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 40 insertions(+), 15 deletions(-)

diff --git a/sys/dev/hid/ietp.c b/sys/dev/hid/ietp.c
index 73a5cb7414d4..a9d0295fb121 100644
--- a/sys/dev/hid/ietp.c
+++ b/sys/dev/hid/ietp.c
@@ -199,17 +199,32 @@ static const struct hid_device_id ietp_iic_devs[] = {
        IETP_IIC_DEV("ELAN1000"),
 };
 
-static uint8_t const ietp_dummy_rdesc[] = {
+static uint8_t const ietp_dummy_rdesc_lo[] = {
        0x05, HUP_GENERIC_DESKTOP,      /* Usage Page (Generic Desktop Ctrls)   
*/
        0x09, HUG_MOUSE,                /* Usage (Mouse)                        
*/
        0xA1, 0x01,                     /* Collection (Application)             
*/
        0x09, 0x01,                     /*   Usage (0x01)                       
*/
+       0x15, 0x00,                     /*   Logical Minimum (0)                
*/
+       0x26, 0xFF, 0x00,               /*   Logical Maximum (255)              
*/
        0x95, IETP_REPORT_LEN_LO,       /*   Report Count (IETP_REPORT_LEN_LO)  
*/
        0x75, 0x08,                     /*   Report Size (8)                    
*/
        0x81, 0x02,                     /*   Input (Data,Var,Abs)               
*/
        0xC0,                           /* End Collection                       
*/
 };
 
+static uint8_t const ietp_dummy_rdesc_hi[] = {
+       0x05, HUP_GENERIC_DESKTOP,      /* Usage Page (Generic Desktop Ctrls)   
*/
+       0x09, HUG_MOUSE,                /* Usage (Mouse)                        
*/
+       0xA1, 0x01,                     /* Collection (Application)             
*/
+       0x09, 0x01,                     /*   Usage (0x01)                       
*/
+       0x15, 0x00,                     /*   Logical Minimum (0)                
*/
+       0x26, 0xFF, 0x00,               /*   Logical Maximum (255)              
*/
+       0x95, IETP_REPORT_LEN_HI,       /*   Report Count (IETP_REPORT_LEN_HI)  
*/
+       0x75, 0x08,                     /*   Report Size (8)                    
*/
+       0x81, 0x02,                     /*   Input (Data,Var,Abs)               
*/
+       0xC0,                           /* End Collection                       
*/
+};
+
 static const struct evdev_methods ietp_evdev_methods = {
        .ev_open = &ietp_ev_open,
        .ev_close = &ietp_ev_close,
@@ -433,28 +448,38 @@ ietp_res2dpmm(uint8_t res, bool hi_precision)
 static void
 ietp_iic_identify(driver_t *driver, device_t parent)
 {
-       void *d_ptr;
-       hid_size_t d_len;
-       int isize;
-       uint8_t iid;
+       device_t iichid = device_get_parent(parent);
+       static const uint16_t reg = IETP_PATTERN;
+       uint16_t addr = iicbus_get_addr(iichid) << 1;
+       uint8_t resp[2];
+       uint8_t cmd[2] = { reg & 0xff, (reg >> 8) & 0xff };
+       struct iic_msg msgs[2] = {
+           { addr, IIC_M_WR | IIC_M_NOSTOP,  sizeof(cmd), cmd },
+           { addr, IIC_M_RD, sizeof(resp), resp },
+       };
+       struct iic_rdwr_data ird = { msgs, nitems(msgs) };
+       uint8_t pattern;
 
        if (HIDBUS_LOOKUP_ID(parent, ietp_iic_devs) == NULL)
                return;
-       if (hid_get_report_descr(parent, &d_ptr, &d_len) != 0)
+
+       if (device_get_devclass(iichid) != devclass_find("iichid"))
                return;
 
-       /*
-        * Some Elantech trackpads have a mangled HID report descriptor, which
-        * reads as having an incorrect input size (i.e. < IETP_REPORT_LEN_LO).
-        * If the input size is incorrect, load a dummy report descriptor.
-        */
+       DPRINTF("Read reg 0x%04x with size %zu\n", reg, sizeof(resp));
 
-       isize = hid_report_size_max(d_ptr, d_len, hid_input, &iid);
-       if (isize >= IETP_REPORT_LEN_LO)
+       if (hid_ioctl(parent, I2CRDWR, (uintptr_t)&ird) != 0)
                return;
 
-       hid_set_report_descr(parent, ietp_dummy_rdesc,
-           sizeof(ietp_dummy_rdesc));
+       DPRINTF("Response: %*D\n", (int)size(resp), resp, " ");
+
+       pattern = (resp[0] == 0xFF && resp[1] == 0xFF) ? 0 : resp[1];
+       if (pattern >= 0x02)
+               hid_set_report_descr(parent, ietp_dummy_rdesc_hi,
+                   sizeof(ietp_dummy_rdesc_hi));
+       else
+               hid_set_report_descr(parent, ietp_dummy_rdesc_lo,
+                   sizeof(ietp_dummy_rdesc_lo));
 }
 
 static int

Reply via email to