Home | History | Annotate | Line # | Download | only in i2c
ihidev.h revision 1.6.10.1
      1  1.6.10.1  perseant /* $NetBSD: ihidev.h,v 1.6.10.1 2025/08/02 05:56:39 perseant 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.6.10.1  perseant #include <sys/gpio.h>
    111       1.5  riastrad 
    112       1.5  riastrad #include <dev/i2c/i2cvar.h>
    113  1.6.10.1  perseant #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.1    bouyer 	uint64_t	sc_phandle;
    120       1.6  riastrad 	kmutex_t	sc_lock;
    121       1.1    bouyer 
    122       1.1    bouyer 	void *		sc_ih;
    123  1.6.10.1  perseant 	void *		sc_ih_gpio;
    124  1.6.10.1  perseant 	struct gpio_pinmap sc_ih_gpiomap;
    125  1.6.10.1  perseant 	int		sc_ih_gpiopins[1];
    126       1.6  riastrad 	struct workqueue *sc_wq;
    127       1.6  riastrad 	struct work	sc_work;
    128       1.6  riastrad 	volatile unsigned sc_work_pending;
    129       1.4   thorpej 	int		sc_intr_type;
    130       1.1    bouyer 
    131       1.1    bouyer 	u_int		sc_hid_desc_addr;
    132       1.1    bouyer 	union {
    133       1.1    bouyer 		uint8_t	hid_desc_buf[sizeof(struct i2c_hid_desc)];
    134       1.1    bouyer 		struct i2c_hid_desc hid_desc;
    135       1.1    bouyer 	};
    136       1.1    bouyer 
    137       1.1    bouyer 	uint8_t		*sc_report;
    138       1.1    bouyer 	int		sc_reportlen;
    139       1.1    bouyer 
    140       1.1    bouyer 	int		sc_nrepid;
    141       1.1    bouyer 	struct		ihidev **sc_subdevs;
    142       1.1    bouyer 
    143       1.1    bouyer 	u_int		sc_isize;
    144       1.1    bouyer 	u_char		*sc_ibuf;
    145       1.1    bouyer 
    146       1.1    bouyer 	int		sc_refcnt;
    147       1.1    bouyer };
    148       1.1    bouyer 
    149       1.1    bouyer struct ihidev {
    150       1.1    bouyer 	device_t	sc_idev;
    151       1.1    bouyer 	struct ihidev_softc *sc_parent;
    152       1.1    bouyer 	uint8_t		sc_report_id;
    153       1.1    bouyer 	uint8_t		sc_state;
    154       1.1    bouyer #define	IHIDEV_OPEN	0x01	/* device is open */
    155       1.1    bouyer 	void		(*sc_intr)(struct ihidev *, void *, u_int);
    156       1.1    bouyer 
    157       1.1    bouyer 	int		sc_isize;
    158       1.1    bouyer 	int		sc_osize;
    159       1.1    bouyer 	int		sc_fsize;
    160       1.1    bouyer };
    161       1.1    bouyer 
    162       1.1    bouyer struct ihidev_attach_arg {
    163       1.1    bouyer 	struct i2c_attach_args	*iaa;
    164       1.1    bouyer 	struct ihidev_softc	*parent;
    165       1.1    bouyer 	uint8_t			 reportid;
    166       1.1    bouyer #define	IHIDEV_CLAIM_ALLREPORTID	255
    167       1.1    bouyer };
    168       1.1    bouyer 
    169       1.1    bouyer struct i2c_hid_report_request {
    170       1.1    bouyer 	u_int id;
    171       1.1    bouyer 	u_int type;
    172       1.1    bouyer #define I2C_HID_REPORT_TYPE_INPUT	0x1
    173       1.1    bouyer #define I2C_HID_REPORT_TYPE_OUTPUT	0x2
    174       1.1    bouyer #define I2C_HID_REPORT_TYPE_FEATURE	0x3
    175       1.1    bouyer 	void *data;
    176       1.1    bouyer 	u_int len;
    177       1.1    bouyer };
    178       1.1    bouyer 
    179       1.1    bouyer void ihidev_get_report_desc(struct ihidev_softc *, void **, int *);
    180       1.1    bouyer int ihidev_open(struct ihidev *);
    181       1.1    bouyer void ihidev_close(struct ihidev *);
    182       1.1    bouyer 
    183       1.1    bouyer int ihidev_set_report(device_t, int, int, void *, int);
    184       1.1    bouyer int ihidev_get_report(device_t, int, int, void *, int);
    185       1.1    bouyer int ihidev_report_type_conv(int);
    186       1.1    bouyer 
    187       1.5  riastrad #endif	/* _DEV_I2C_IHIDEV_H_ */
    188