Home | History | Annotate | Line # | Download | only in usb
      1 /*	$NetBSD: umcpmio_io.h,v 1.3 2025/11/29 18:39:14 brad 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_IO_H_
     20 #define _UMCPMIO_IO_H_
     21 
     22 #include <sys/types.h>
     23 
     24 #include <sys/ioccom.h>
     25 
     26 #include <dev/usb/umcpmio_hid_reports.h>
     27 
     28 #define UMCPMIO_CHIP_TYPE_2210 0x01
     29 #define UMCPMIO_CHIP_TYPE_2221 0x02
     30 
     31 union umcpmio_ioctl_get_status {
     32 	struct mcp2210_status_res mcp2210_status_res;
     33 	struct mcp2221_status_res mcp2221_status_res;
     34 	uint8_t status_blob[UMCPMIO_RES_BUFFER_SIZE];
     35 };
     36 
     37 struct umcpmio_ioctl_get_flash {
     38 	uint8_t subcode;
     39 	union {
     40 		struct mcp2210_get_nvram_res mcp2210_get_nvram_res;
     41 		struct mcp2221_get_flash_res mcp2221_get_flash_res;
     42 		uint8_t get_blob[UMCPMIO_RES_BUFFER_SIZE];
     43 	} res;
     44 };
     45 
     46 struct umcpmio_ioctl_put_flash {
     47 	uint8_t subcode;
     48 	union {
     49 		struct mcp2210_set_nvram_req mcp2210_set_req;
     50 		struct mcp2221_put_flash_req mcp2221_put_req;
     51 		uint8_t put_req_blob[UMCPMIO_REQ_BUFFER_SIZE];
     52 	} req;
     53 	union {
     54 		struct mcp2210_set_nvram_res mcp2210_set_res;
     55 		struct mcp2221_put_flash_res mcp2221_put_res;
     56 		uint8_t put_res_blob[UMCPMIO_RES_BUFFER_SIZE];
     57 	} res;
     58 };
     59 
     60 struct mcp2210_ioctl_get_sram {
     61 	uint8_t cmd;
     62 	uint8_t res[UMCPMIO_RES_BUFFER_SIZE];
     63 };
     64 
     65 #define UMCPMIO_GET_STATUS	_IOR('m', 1, union umcpmio_ioctl_get_status)
     66 #define MCP2221_GET_SRAM	_IOR('m', 2, struct mcp2221_get_sram_res)
     67 #define MCP2221_GET_GP_CFG	_IOR('m', 3, struct mcp2221_get_gpio_cfg_res)
     68 #define UMCPMIO_GET_FLASH	_IOWR('m', 4, struct umcpmio_ioctl_get_flash)
     69 #define UMCPMIO_PUT_FLASH	_IOWR('m', 5, struct umcpmio_ioctl_put_flash)
     70 #define UMCPMIO_CHIP_TYPE	_IOR('m', 6, uint8_t)
     71 #define MCP2210_GET_SRAM	_IOWR('m', 7, struct mcp2210_ioctl_get_sram)
     72 #define MCP2210_CANCEL_SPI	_IOR('m', 8, struct mcp2210_cancel_spi_res)
     73 
     74 #endif	/* _UMCPMIO_IO_H_ */
     75