1 /* $NetBSD: umcpmio.h,v 1.1 2024/12/16 16:37:38 brad Exp $ */ 2 3 /* 4 * Copyright (c) 2024 Brad Spencer <brad@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 20 #ifndef _UMCPMIO_H_ 21 #define _UMCPMIO_H_ 22 23 #include <sys/param.h> 24 #include <sys/systm.h> 25 #include <sys/conf.h> 26 #include <sys/kernel.h> 27 #include <sys/kmem.h> 28 #include <sys/device.h> 29 #include <sys/sysctl.h> 30 #include <sys/tty.h> 31 #include <sys/file.h> 32 #include <sys/vnode.h> 33 #include <sys/kauth.h> 34 #include <sys/lwp.h> 35 36 #include <sys/gpio.h> 37 #include <dev/gpio/gpiovar.h> 38 39 #include <dev/i2c/i2cvar.h> 40 41 #include <dev/usb/usbdi.h> 42 #include <dev/usb/usbdi_util.h> 43 #include <dev/usb/usbdevs.h> 44 #include <dev/usb/uhidev.h> 45 #include <dev/hid/hid.h> 46 47 #define UMCPMIO_VREF_NAME 7 48 #define UMCPMIO_CD_NAME 7 49 #define UMCPMIO_DC_NAME 4 50 51 #define MCP2221_NPINS 4 52 #define UMCPMIO_NUM_DEVS 4 53 54 enum umcpmio_minor_devs { 55 CONTROL_DEV = 0, 56 GP1_DEV = 1, 57 GP2_DEV = 2, 58 GP3_DEV = 3, 59 }; 60 61 struct umcpmio_irq { 62 int (*sc_gpio_irqfunc)(void *); 63 void *sc_gpio_irqarg; 64 }; 65 66 struct umcpmio_softc { 67 device_t sc_dev; 68 struct uhidev *sc_hdev; 69 struct usbd_device *sc_udev; 70 71 struct sysctllog *sc_umcpmiolog; 72 bool sc_dumpbuffer; 73 74 int sc_cv_wait; 75 int sc_response_errcnt; 76 int sc_busy_delay; 77 int sc_retry_busy_read; 78 int sc_retry_busy_write; 79 80 kmutex_t sc_action_mutex; 81 82 kcondvar_t sc_res_cv; 83 kmutex_t sc_res_mutex; 84 bool sc_res_ready; 85 uint8_t *sc_res_buffer; 86 87 device_t sc_gpio_dev; 88 struct gpio_chipset_tag sc_gpio_gc; 89 gpio_pin_t sc_gpio_pins[MCP2221_NPINS]; 90 struct umcpmio_irq sc_gpio_irqs[1]; 91 int sc_irq_poll; 92 93 struct i2c_controller sc_i2c_tag; 94 device_t sc_i2c_dev; 95 bool sc_reportreadnostop; 96 97 bool sc_dev_open[UMCPMIO_NUM_DEVS]; 98 99 char sc_dying; 100 }; 101 102 struct umcpmio_sysctl_name { 103 const char *text; 104 }; 105 106 #endif 107