1*fd71220bSRobert Mustacchi /* 2*fd71220bSRobert Mustacchi * This file and its contents are supplied under the terms of the 3*fd71220bSRobert Mustacchi * Common Development and Distribution License ("CDDL"), version 1.0. 4*fd71220bSRobert Mustacchi * You may only use this file in accordance with the terms of version 5*fd71220bSRobert Mustacchi * 1.0 of the CDDL. 6*fd71220bSRobert Mustacchi * 7*fd71220bSRobert Mustacchi * A full copy of the text of the CDDL should have accompanied this 8*fd71220bSRobert Mustacchi * source. A copy of the CDDL is also available via the Internet at 9*fd71220bSRobert Mustacchi * http://www.illumos.org/license/CDDL. 10*fd71220bSRobert Mustacchi */ 11*fd71220bSRobert Mustacchi 12*fd71220bSRobert Mustacchi /* 13*fd71220bSRobert Mustacchi * Copyright 2022 Oxide Computer Company 14*fd71220bSRobert Mustacchi */ 15*fd71220bSRobert Mustacchi 16*fd71220bSRobert Mustacchi #ifndef _SYS_GPIO_DPIO_H 17*fd71220bSRobert Mustacchi #define _SYS_GPIO_DPIO_H 18*fd71220bSRobert Mustacchi 19*fd71220bSRobert Mustacchi /* 20*fd71220bSRobert Mustacchi * Definitions that consumers of DPIOs should likely know about. 21*fd71220bSRobert Mustacchi */ 22*fd71220bSRobert Mustacchi 23*fd71220bSRobert Mustacchi #ifdef __cplusplus 24*fd71220bSRobert Mustacchi extern "C" { 25*fd71220bSRobert Mustacchi #endif 26*fd71220bSRobert Mustacchi 27*fd71220bSRobert Mustacchi /* 28*fd71220bSRobert Mustacchi * This is the general size of names in the dpio structures. Actual name lengths 29*fd71220bSRobert Mustacchi * and limits are potentially less. 30*fd71220bSRobert Mustacchi */ 31*fd71220bSRobert Mustacchi #define DPIO_NAMELEN 64 32*fd71220bSRobert Mustacchi 33*fd71220bSRobert Mustacchi /* 34*fd71220bSRobert Mustacchi * Basic IOCTL information 35*fd71220bSRobert Mustacchi */ 36*fd71220bSRobert Mustacchi #define DPIO_IOC (('d' << 24) | ('p' << 16) | ('i' << 8)) 37*fd71220bSRobert Mustacchi 38*fd71220bSRobert Mustacchi /* 39*fd71220bSRobert Mustacchi * This is the set of values that are expected on a write(2) to a DPIO to set 40*fd71220bSRobert Mustacchi * the output state. Each write(2) must be a uint32_t (4 bytes) in size. 41*fd71220bSRobert Mustacchi */ 42*fd71220bSRobert Mustacchi typedef enum { 43*fd71220bSRobert Mustacchi DPIO_OUTPUT_LOW = 0, 44*fd71220bSRobert Mustacchi DPIO_OUTPUT_HIGH = 1, 45*fd71220bSRobert Mustacchi DPIO_OUTPUT_DISABLE = UINT32_MAX 46*fd71220bSRobert Mustacchi } dpio_output_t; 47*fd71220bSRobert Mustacchi 48*fd71220bSRobert Mustacchi /* 49*fd71220bSRobert Mustacchi * This is the set of values that are expected on a read(2) of a DPIO to get the 50*fd71220bSRobert Mustacchi * input state. Each read(2) must be a uint32_t (4 bytes) in size. 51*fd71220bSRobert Mustacchi */ 52*fd71220bSRobert Mustacchi typedef enum { 53*fd71220bSRobert Mustacchi DPIO_INPUT_LOW = 0, 54*fd71220bSRobert Mustacchi DPIO_INPUT_HIGH = 1 55*fd71220bSRobert Mustacchi } dpio_input_t; 56*fd71220bSRobert Mustacchi 57*fd71220bSRobert Mustacchi /* 58*fd71220bSRobert Mustacchi * This indicates features that the DPIO is set up for and supports. 59*fd71220bSRobert Mustacchi */ 60*fd71220bSRobert Mustacchi typedef enum { 61*fd71220bSRobert Mustacchi DPIO_C_READ = 1 << 0, 62*fd71220bSRobert Mustacchi DPIO_C_WRITE = 1 << 1, 63*fd71220bSRobert Mustacchi DPIO_C_POLL = 1 << 2 64*fd71220bSRobert Mustacchi } dpio_caps_t; 65*fd71220bSRobert Mustacchi 66*fd71220bSRobert Mustacchi typedef enum { 67*fd71220bSRobert Mustacchi DPIO_F_KERNEL = 1 << 0, 68*fd71220bSRobert Mustacchi } dpio_flags_t; 69*fd71220bSRobert Mustacchi 70*fd71220bSRobert Mustacchi /* 71*fd71220bSRobert Mustacchi * This is the basic information structure for a DPIO. It reports information 72*fd71220bSRobert Mustacchi * about what is supported and usable. This is accessible via the dpinfo 73*fd71220bSRobert Mustacchi * interface or via the dpio itself. If this is called directly on a dpio 74*fd71220bSRobert Mustacchi * itself, then the dpi_dpio field will be the DPIO's name. 75*fd71220bSRobert Mustacchi */ 76*fd71220bSRobert Mustacchi #define DPIO_IOC_INFO (DPIO_IOC | 1) 77*fd71220bSRobert Mustacchi typedef struct { 78*fd71220bSRobert Mustacchi char dpi_dpio[DPIO_NAMELEN]; 79*fd71220bSRobert Mustacchi char dpi_ctrl[DPIO_NAMELEN]; 80*fd71220bSRobert Mustacchi uint32_t dpi_gpio; 81*fd71220bSRobert Mustacchi dpio_caps_t dpi_caps; 82*fd71220bSRobert Mustacchi dpio_flags_t dpi_flags; 83*fd71220bSRobert Mustacchi uint32_t dpi_pad; 84*fd71220bSRobert Mustacchi } dpio_info_t; 85*fd71220bSRobert Mustacchi 86*fd71220bSRobert Mustacchi /* 87*fd71220bSRobert Mustacchi * This is used to get information about the current timing information. If the 88*fd71220bSRobert Mustacchi * system supports interrupts on changes and it has been enabled, then this will 89*fd71220bSRobert Mustacchi * be used to indicate the last time we received an update. 90*fd71220bSRobert Mustacchi */ 91*fd71220bSRobert Mustacchi #define DPIO_IOC_TIMING (DPIO_IOC | 2) 92*fd71220bSRobert Mustacchi typedef struct { 93*fd71220bSRobert Mustacchi hrtime_t dpt_last_input_intr; 94*fd71220bSRobert Mustacchi hrtime_t dpt_last_write; 95*fd71220bSRobert Mustacchi } dpio_timing_t; 96*fd71220bSRobert Mustacchi 97*fd71220bSRobert Mustacchi /* 98*fd71220bSRobert Mustacchi * This is used to get access to the current output state that has been set on 99*fd71220bSRobert Mustacchi * the DPIO. This is only available via the dpio itself, it is not available via 100*fd71220bSRobert Mustacchi * dpinfo as it is information specific to current consumers. 101*fd71220bSRobert Mustacchi */ 102*fd71220bSRobert Mustacchi #define DPIO_IOC_CUROUT (DPIO_IOC | 3) 103*fd71220bSRobert Mustacchi typedef struct { 104*fd71220bSRobert Mustacchi dpio_output_t dps_curout; 105*fd71220bSRobert Mustacchi uint32_t dps_pad; 106*fd71220bSRobert Mustacchi } dpio_curout_t; 107*fd71220bSRobert Mustacchi 108*fd71220bSRobert Mustacchi #ifdef __cplusplus 109*fd71220bSRobert Mustacchi } 110*fd71220bSRobert Mustacchi #endif 111*fd71220bSRobert Mustacchi 112*fd71220bSRobert Mustacchi #endif /* _SYS_GPIO_DPIO_H */ 113