1 1.8 thorpej /* $NetBSD: ihidev.h,v 1.8 2025/09/17 13:51:47 thorpej Exp $ */ 2 1.1 bouyer /* $OpenBSD ihidev.h,v 1.4 2016/01/31 18:24:35 jcs Exp $ */ 3 1.1 bouyer 4 1.1 bouyer /*- 5 1.1 bouyer * Copyright (c) 2017 The NetBSD Foundation, Inc. 6 1.1 bouyer * All rights reserved. 7 1.1 bouyer * 8 1.1 bouyer * This code is derived from software contributed to The NetBSD Foundation 9 1.1 bouyer * by Manuel Bouyer. 10 1.1 bouyer * 11 1.1 bouyer * Redistribution and use in source and binary forms, with or without 12 1.1 bouyer * modification, are permitted provided that the following conditions 13 1.1 bouyer * are met: 14 1.1 bouyer * 1. Redistributions of source code must retain the above copyright 15 1.1 bouyer * notice, this list of conditions and the following disclaimer. 16 1.1 bouyer * 2. Redistributions in binary form must reproduce the above copyright 17 1.1 bouyer * notice, this list of conditions and the following disclaimer in the 18 1.1 bouyer * documentation and/or other materials provided with the distribution. 19 1.1 bouyer * 20 1.1 bouyer * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 1.1 bouyer * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 1.1 bouyer * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 1.1 bouyer * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 1.1 bouyer * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 1.1 bouyer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 1.1 bouyer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 1.1 bouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 1.1 bouyer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 1.1 bouyer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 1.1 bouyer * POSSIBILITY OF SUCH DAMAGE. 31 1.1 bouyer */ 32 1.1 bouyer 33 1.5 riastrad #ifndef _DEV_I2C_IHIDEV_H_ 34 1.5 riastrad #define _DEV_I2C_IHIDEV_H_ 35 1.5 riastrad 36 1.5 riastrad /* ihidevreg.h */ 37 1.5 riastrad 38 1.1 bouyer /* 39 1.1 bouyer * HID-over-i2c driver 40 1.1 bouyer * 41 1.1 bouyer * Copyright (c) 2015, 2016 joshua stein <jcs (at) openbsd.org> 42 1.1 bouyer * 43 1.1 bouyer * Permission to use, copy, modify, and distribute this software for any 44 1.1 bouyer * purpose with or without fee is hereby granted, provided that the above 45 1.1 bouyer * copyright notice and this permission notice appear in all copies. 46 1.1 bouyer * 47 1.1 bouyer * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 48 1.1 bouyer * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 49 1.1 bouyer * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 50 1.1 bouyer * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 51 1.1 bouyer * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 52 1.1 bouyer * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 53 1.1 bouyer * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 54 1.1 bouyer */ 55 1.1 bouyer 56 1.5 riastrad #include <sys/types.h> 57 1.5 riastrad 58 1.1 bouyer /* from usbdi.h: Match codes. */ 59 1.1 bouyer /* First five codes is for a whole device. */ 60 1.1 bouyer #define IMATCH_VENDOR_PRODUCT_REV 14 61 1.1 bouyer #define IMATCH_VENDOR_PRODUCT 13 62 1.1 bouyer #define IMATCH_VENDOR_DEVCLASS_DEVPROTO 12 63 1.1 bouyer #define IMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO 11 64 1.1 bouyer #define IMATCH_DEVCLASS_DEVSUBCLASS 10 65 1.1 bouyer /* Next six codes are for interfaces. */ 66 1.1 bouyer #define IMATCH_VENDOR_PRODUCT_REV_CONF_IFACE 9 67 1.1 bouyer #define IMATCH_VENDOR_PRODUCT_CONF_IFACE 8 68 1.1 bouyer #define IMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO 7 69 1.1 bouyer #define IMATCH_VENDOR_IFACESUBCLASS 6 70 1.1 bouyer #define IMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO 5 71 1.1 bouyer #define IMATCH_IFACECLASS_IFACESUBCLASS 4 72 1.1 bouyer #define IMATCH_IFACECLASS 3 73 1.1 bouyer #define IMATCH_IFACECLASS_GENERIC 2 74 1.1 bouyer /* Generic driver */ 75 1.1 bouyer #define IMATCH_GENERIC 1 76 1.1 bouyer /* No match */ 77 1.1 bouyer #define IMATCH_NONE 0 78 1.1 bouyer 79 1.1 bouyer #define IHIDBUSCF_REPORTID 0 80 1.1 bouyer #define IHIDBUSCF_REPORTID_DEFAULT -1 81 1.1 bouyer 82 1.1 bouyer #define ihidevcf_reportid cf_loc[IHIDBUSCF_REPORTID] 83 1.1 bouyer #define IHIDEV_UNK_REPORTID IHIDBUSCF_REPORTID_DEFAULT 84 1.1 bouyer 85 1.1 bouyer /* 5.1.1 - HID Descriptor Format */ 86 1.1 bouyer struct i2c_hid_desc { 87 1.1 bouyer uint16_t wHIDDescLength; 88 1.1 bouyer uint16_t bcdVersion; 89 1.1 bouyer uint16_t wReportDescLength; 90 1.1 bouyer uint16_t wReportDescRegister; 91 1.1 bouyer uint16_t wInputRegister; 92 1.1 bouyer uint16_t wMaxInputLength; 93 1.1 bouyer uint16_t wOutputRegister; 94 1.1 bouyer uint16_t wMaxOutputLength; 95 1.1 bouyer uint16_t wCommandRegister; 96 1.1 bouyer uint16_t wDataRegister; 97 1.1 bouyer uint16_t wVendorID; 98 1.1 bouyer uint16_t wProductID; 99 1.1 bouyer uint16_t wVersionID; 100 1.1 bouyer uint32_t reserved; 101 1.1 bouyer } __packed; 102 1.1 bouyer 103 1.5 riastrad /* ihidevvar.h */ 104 1.5 riastrad 105 1.5 riastrad #include <sys/types.h> 106 1.5 riastrad 107 1.5 riastrad #include <sys/device.h> 108 1.5 riastrad #include <sys/mutex.h> 109 1.6 riastrad #include <sys/workqueue.h> 110 1.7 jmcneill #include <sys/gpio.h> 111 1.5 riastrad 112 1.5 riastrad #include <dev/i2c/i2cvar.h> 113 1.7 jmcneill #include <dev/gpio/gpiovar.h> 114 1.5 riastrad 115 1.1 bouyer struct ihidev_softc { 116 1.1 bouyer device_t sc_dev; 117 1.1 bouyer i2c_tag_t sc_tag; 118 1.1 bouyer i2c_addr_t sc_addr; 119 1.6 riastrad kmutex_t sc_lock; 120 1.1 bouyer 121 1.1 bouyer void * sc_ih; 122 1.7 jmcneill void * sc_ih_gpio; 123 1.7 jmcneill struct gpio_pinmap sc_ih_gpiomap; 124 1.7 jmcneill int sc_ih_gpiopins[1]; 125 1.6 riastrad struct workqueue *sc_wq; 126 1.6 riastrad struct work sc_work; 127 1.6 riastrad volatile unsigned sc_work_pending; 128 1.4 thorpej int sc_intr_type; 129 1.1 bouyer 130 1.1 bouyer u_int sc_hid_desc_addr; 131 1.1 bouyer union { 132 1.1 bouyer uint8_t hid_desc_buf[sizeof(struct i2c_hid_desc)]; 133 1.1 bouyer struct i2c_hid_desc hid_desc; 134 1.1 bouyer }; 135 1.1 bouyer 136 1.1 bouyer uint8_t *sc_report; 137 1.1 bouyer int sc_reportlen; 138 1.1 bouyer 139 1.1 bouyer int sc_nrepid; 140 1.1 bouyer struct ihidev **sc_subdevs; 141 1.1 bouyer 142 1.1 bouyer u_int sc_isize; 143 1.1 bouyer u_char *sc_ibuf; 144 1.1 bouyer 145 1.1 bouyer int sc_refcnt; 146 1.1 bouyer }; 147 1.1 bouyer 148 1.1 bouyer struct ihidev { 149 1.1 bouyer device_t sc_idev; 150 1.1 bouyer struct ihidev_softc *sc_parent; 151 1.1 bouyer uint8_t sc_report_id; 152 1.1 bouyer uint8_t sc_state; 153 1.1 bouyer #define IHIDEV_OPEN 0x01 /* device is open */ 154 1.1 bouyer void (*sc_intr)(struct ihidev *, void *, u_int); 155 1.1 bouyer 156 1.1 bouyer int sc_isize; 157 1.1 bouyer int sc_osize; 158 1.1 bouyer int sc_fsize; 159 1.1 bouyer }; 160 1.1 bouyer 161 1.1 bouyer struct ihidev_attach_arg { 162 1.1 bouyer struct i2c_attach_args *iaa; 163 1.1 bouyer struct ihidev_softc *parent; 164 1.1 bouyer uint8_t reportid; 165 1.1 bouyer #define IHIDEV_CLAIM_ALLREPORTID 255 166 1.1 bouyer }; 167 1.1 bouyer 168 1.1 bouyer struct i2c_hid_report_request { 169 1.1 bouyer u_int id; 170 1.1 bouyer u_int type; 171 1.1 bouyer #define I2C_HID_REPORT_TYPE_INPUT 0x1 172 1.1 bouyer #define I2C_HID_REPORT_TYPE_OUTPUT 0x2 173 1.1 bouyer #define I2C_HID_REPORT_TYPE_FEATURE 0x3 174 1.1 bouyer void *data; 175 1.1 bouyer u_int len; 176 1.1 bouyer }; 177 1.1 bouyer 178 1.1 bouyer void ihidev_get_report_desc(struct ihidev_softc *, void **, int *); 179 1.1 bouyer int ihidev_open(struct ihidev *); 180 1.1 bouyer void ihidev_close(struct ihidev *); 181 1.1 bouyer 182 1.1 bouyer int ihidev_set_report(device_t, int, int, void *, int); 183 1.1 bouyer int ihidev_get_report(device_t, int, int, void *, int); 184 1.1 bouyer int ihidev_report_type_conv(int); 185 1.1 bouyer 186 1.5 riastrad #endif /* _DEV_I2C_IHIDEV_H_ */ 187