git: 6b1da3d223a8 - main - iichid(4): Implement I2CRDWR command in hid_ioctl method

From: Vladimir Kondratyev <wulf_at_FreeBSD.org>
Date: Wed, 02 Mar 2022 23:36:40 UTC
The branch main has been updated by wulf:

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

commit 6b1da3d223a88d544439d1be4115714f0aee75be
Author:     Vladimir Kondratyev <wulf@FreeBSD.org>
AuthorDate: 2022-03-02 23:35:23 +0000
Commit:     Vladimir Kondratyev <wulf@FreeBSD.org>
CommitDate: 2022-03-02 23:35:23 +0000

    iichid(4): Implement I2CRDWR command in hid_ioctl method
    
    This command is intended to be compatible with I2CRDWR ioctl.
    It is required to perform arbitrary I2C transfers by device
    drivers which can switch between HID and native non-HID modes.
    
    MFC after:      2 month
---
 sys/dev/iicbus/iichid.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/sys/dev/iicbus/iichid.c b/sys/dev/iicbus/iichid.c
index a36ed9bb8538..271a71ccc50e 100644
--- a/sys/dev/iicbus/iichid.c
+++ b/sys/dev/iicbus/iichid.c
@@ -947,6 +947,24 @@ iichid_set_protocol(device_t dev, uint16_t protocol)
 	return (ENOTSUP);
 }
 
+static int
+iichid_ioctl(device_t dev, unsigned long cmd, uintptr_t data)
+{
+	int error;
+
+	switch (cmd) {
+	case I2CRDWR:
+		error = iic2errno(iicbus_transfer(dev,
+		    ((struct iic_rdwr_data *)data)->msgs,
+		    ((struct iic_rdwr_data *)data)->nmsgs));
+		break;
+	default:
+		error = EINVAL;
+	}
+
+	return (error);
+}
+
 static int
 iichid_fill_device_info(struct i2c_hid_desc *desc, ACPI_HANDLE handle,
     struct hid_device_info *hw)
@@ -1279,6 +1297,7 @@ static device_method_t iichid_methods[] = {
 	DEVMETHOD(hid_set_report,	iichid_set_report),
 	DEVMETHOD(hid_set_idle,		iichid_set_idle),
 	DEVMETHOD(hid_set_protocol,	iichid_set_protocol),
+	DEVMETHOD(hid_ioctl,		iichid_ioctl),
 
 	DEVMETHOD_END
 };