Home | History | Annotate | Line # | Download | only in usb
      1 /*	$NetBSD: umcpmio.h,v 1.2 2025/03/17 18:24:08 riastradh Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2024 Brad Spencer <brad (at) anduin.eldar.org>
      5  *
      6  * Permission to use, copy, modify, and distribute this software for any
      7  * purpose with or without fee is hereby granted, provided that the above
      8  * copyright notice and this permission notice appear in all copies.
      9  *
     10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     17  */
     18 
     19 #ifndef _UMCPMIO_H_
     20 #define _UMCPMIO_H_
     21 
     22 #include <sys/param.h>
     23 #include <sys/types.h>
     24 
     25 #include <sys/condvar.h>
     26 #include <sys/conf.h>
     27 #include <sys/device.h>
     28 #include <sys/file.h>
     29 #include <sys/gpio.h>
     30 #include <sys/kauth.h>
     31 #include <sys/kernel.h>
     32 #include <sys/kmem.h>
     33 #include <sys/lwp.h>
     34 #include <sys/mutex.h>
     35 #include <sys/sysctl.h>
     36 #include <sys/systm.h>
     37 #include <sys/tty.h>
     38 #include <sys/vnode.h>
     39 
     40 #include <dev/gpio/gpiovar.h>
     41 
     42 #include <dev/hid/hid.h>
     43 
     44 #include <dev/i2c/i2cvar.h>
     45 
     46 #include <dev/usb/uhidev.h>
     47 #include <dev/usb/usbdevs.h>
     48 #include <dev/usb/usbdi.h>
     49 #include <dev/usb/usbdi_util.h>
     50 
     51 #define UMCPMIO_VREF_NAME 7
     52 #define UMCPMIO_CD_NAME 7
     53 #define UMCPMIO_DC_NAME 4
     54 
     55 #define MCP2221_NPINS 4
     56 #define UMCPMIO_NUM_DEVS 4
     57 
     58 enum umcpmio_minor_devs {
     59 	CONTROL_DEV = 0,
     60 	GP1_DEV = 1,
     61 	GP2_DEV = 2,
     62 	GP3_DEV = 3,
     63 };
     64 
     65 struct umcpmio_irq {
     66 	int (*sc_gpio_irqfunc)(void *);
     67 	void *sc_gpio_irqarg;
     68 };
     69 
     70 struct umcpmio_softc {
     71 	device_t		sc_dev;
     72 	struct uhidev		*sc_hdev;
     73 	struct usbd_device	*sc_udev;
     74 
     75 	struct sysctllog	*sc_umcpmiolog;
     76 	bool			sc_dumpbuffer;
     77 
     78 	int			sc_cv_wait;
     79 	int			sc_response_errcnt;
     80 	int			sc_busy_delay;
     81 	int			sc_retry_busy_read;
     82 	int			sc_retry_busy_write;
     83 
     84 	kmutex_t		sc_action_mutex;
     85 
     86 	kcondvar_t		sc_res_cv;
     87 	kmutex_t		sc_res_mutex;
     88 	bool			sc_res_ready;
     89 	uint8_t			*sc_res_buffer;
     90 
     91 	device_t		sc_gpio_dev;
     92 	struct gpio_chipset_tag	sc_gpio_gc;
     93 	gpio_pin_t		sc_gpio_pins[MCP2221_NPINS];
     94         struct umcpmio_irq      sc_gpio_irqs[1];
     95 	int			sc_irq_poll;
     96 
     97 	struct i2c_controller	sc_i2c_tag;
     98 	device_t		sc_i2c_dev;
     99 	bool			sc_reportreadnostop;
    100 
    101 	bool			sc_dev_open[UMCPMIO_NUM_DEVS];
    102 
    103 	char			sc_dying;
    104 };
    105 
    106 struct umcpmio_sysctl_name {
    107 	const char	*text;
    108 };
    109 
    110 #endif	/* _UMCPMIO_H_ */
    111