1*32002227SRobert Mustacchi /* 2*32002227SRobert Mustacchi * This file and its contents are supplied under the terms of the 3*32002227SRobert Mustacchi * Common Development and Distribution License ("CDDL"), version 1.0. 4*32002227SRobert Mustacchi * You may only use this file in accordance with the terms of version 5*32002227SRobert Mustacchi * 1.0 of the CDDL. 6*32002227SRobert Mustacchi * 7*32002227SRobert Mustacchi * A full copy of the text of the CDDL should have accompanied this 8*32002227SRobert Mustacchi * source. A copy of the CDDL is also available via the Internet at 9*32002227SRobert Mustacchi * http://www.illumos.org/license/CDDL. 10*32002227SRobert Mustacchi */ 11*32002227SRobert Mustacchi 12*32002227SRobert Mustacchi /* 13*32002227SRobert Mustacchi * Copyright 2025 Oxide Computer Company 14*32002227SRobert Mustacchi */ 15*32002227SRobert Mustacchi 16*32002227SRobert Mustacchi #ifndef _SYS_I2C_CONTROLLER_H 17*32002227SRobert Mustacchi #define _SYS_I2C_CONTROLLER_H 18*32002227SRobert Mustacchi 19*32002227SRobert Mustacchi /* 20*32002227SRobert Mustacchi * This file contains the definitions that I2C, I3C, and SMBus controller 21*32002227SRobert Mustacchi * drivers should use to interface with the system's i2c stack. 22*32002227SRobert Mustacchi */ 23*32002227SRobert Mustacchi 24*32002227SRobert Mustacchi #include <sys/devops.h> 25*32002227SRobert Mustacchi #include <sys/i2c/i2c.h> 26*32002227SRobert Mustacchi 27*32002227SRobert Mustacchi #ifdef __cplusplus 28*32002227SRobert Mustacchi extern "C" { 29*32002227SRobert Mustacchi #endif 30*32002227SRobert Mustacchi 31*32002227SRobert Mustacchi /* 32*32002227SRobert Mustacchi * Current version of the interface expected by the i2c controller provider. 33*32002227SRobert Mustacchi */ 34*32002227SRobert Mustacchi #define I2C_CTRL_PROVIDER_V0 0 35*32002227SRobert Mustacchi #define I2C_CTRL_PROVIDER I2C_CTRL_PROVIDER_V0 36*32002227SRobert Mustacchi 37*32002227SRobert Mustacchi typedef struct i2c_prop_info i2c_prop_info_t; 38*32002227SRobert Mustacchi 39*32002227SRobert Mustacchi typedef struct i2c_ctrl_ops { 40*32002227SRobert Mustacchi bool (*i2c_port_name_f)(void *, uint32_t, char *, size_t); 41*32002227SRobert Mustacchi void (*i2c_io_smbus_f)(void *, uint32_t, smbus_req_t *); 42*32002227SRobert Mustacchi void (*i2c_io_i2c_f)(void *, uint32_t, i2c_req_t *); 43*32002227SRobert Mustacchi i2c_errno_t (*i2c_prop_info_f)(void *, i2c_prop_t, i2c_prop_info_t *); 44*32002227SRobert Mustacchi i2c_errno_t (*i2c_prop_get_f)(void *, i2c_prop_t, void *, size_t); 45*32002227SRobert Mustacchi i2c_errno_t (*i2c_prop_set_f)(void *, i2c_prop_t, const void *, size_t); 46*32002227SRobert Mustacchi } i2c_ctrl_ops_t; 47*32002227SRobert Mustacchi 48*32002227SRobert Mustacchi typedef struct i2c_ctrl_register { 49*32002227SRobert Mustacchi uint32_t ic_vers; 50*32002227SRobert Mustacchi i2c_ctrl_type_t ic_type; 51*32002227SRobert Mustacchi const char *ic_name; 52*32002227SRobert Mustacchi uint32_t ic_nports; 53*32002227SRobert Mustacchi dev_info_t *ic_dip; 54*32002227SRobert Mustacchi void *ic_drv; 55*32002227SRobert Mustacchi const i2c_ctrl_ops_t *ic_ops; 56*32002227SRobert Mustacchi } i2c_ctrl_register_t; 57*32002227SRobert Mustacchi 58*32002227SRobert Mustacchi /* 59*32002227SRobert Mustacchi * Opaque structures for registration handles. 60*32002227SRobert Mustacchi */ 61*32002227SRobert Mustacchi typedef struct i2c_ctrl_hdl i2c_ctrl_hdl_t; 62*32002227SRobert Mustacchi 63*32002227SRobert Mustacchi typedef enum { 64*32002227SRobert Mustacchi I2C_CTRL_REG_E_OK = 0, 65*32002227SRobert Mustacchi I2C_CTRL_REG_E_BAD_VERS, 66*32002227SRobert Mustacchi I2C_CTRL_REG_E_NULL_ARG, 67*32002227SRobert Mustacchi I2C_CTRL_REG_E_BAD_OPS, 68*32002227SRobert Mustacchi I2C_CTRL_REG_E_NEED_PORT_NAME_FUNC, 69*32002227SRobert Mustacchi I2C_CTRL_REG_E_NEED_PROP_GET_FUNC, 70*32002227SRobert Mustacchi I2C_CTRL_REG_E_NEED_PROP_INFO_FUNC, 71*32002227SRobert Mustacchi I2C_CTRL_REG_E_BAD_CTRL_TYPE, 72*32002227SRobert Mustacchi I2C_CTRL_REG_E_UNSUP_CTRL_TYPE, 73*32002227SRobert Mustacchi I2C_CTRL_REG_E_BAD_DIP, 74*32002227SRobert Mustacchi I2C_CTRL_REG_E_BAD_NPORTS, 75*32002227SRobert Mustacchi I2C_CTRL_REG_E_BAD_NAME, 76*32002227SRobert Mustacchi I2C_CTRL_REG_E_INTERNAL, 77*32002227SRobert Mustacchi I2C_CTRL_REG_E_BAD_MOD_TYPE, 78*32002227SRobert Mustacchi I2C_CTRL_REG_E_NEXUS, 79*32002227SRobert Mustacchi I2C_CTRL_REG_E_NOT_UNIQUE, 80*32002227SRobert Mustacchi I2C_CTRL_REG_E_REQ_PROP, 81*32002227SRobert Mustacchi I2C_CTLR_REG_E_BAD_PROP_VAL 82*32002227SRobert Mustacchi } i2c_ctrl_reg_error_t; 83*32002227SRobert Mustacchi 84*32002227SRobert Mustacchi extern void i2c_ctrl_mod_init(struct dev_ops *); 85*32002227SRobert Mustacchi extern void i2c_ctrl_mod_fini(struct dev_ops *); 86*32002227SRobert Mustacchi extern i2c_ctrl_reg_error_t i2c_ctrl_register_alloc(uint32_t, 87*32002227SRobert Mustacchi i2c_ctrl_register_t **); 88*32002227SRobert Mustacchi extern void i2c_ctrl_register_free(i2c_ctrl_register_t *); 89*32002227SRobert Mustacchi 90*32002227SRobert Mustacchi extern i2c_ctrl_reg_error_t i2c_ctrl_register(const i2c_ctrl_register_t *, 91*32002227SRobert Mustacchi i2c_ctrl_hdl_t **); 92*32002227SRobert Mustacchi extern i2c_ctrl_reg_error_t i2c_ctrl_unregister(i2c_ctrl_hdl_t *); 93*32002227SRobert Mustacchi 94*32002227SRobert Mustacchi /* 95*32002227SRobert Mustacchi * The i2c_ctrl_port_name_portno() function is the default controller port 96*32002227SRobert Mustacchi * naming function that names the port after the controller. For systems where 97*32002227SRobert Mustacchi * ther isn't a complex I/O Mux element or some other naming case, this should 98*32002227SRobert Mustacchi * be what they use. 99*32002227SRobert Mustacchi */ 100*32002227SRobert Mustacchi extern bool i2c_ctrl_port_name_portno(void *, uint32_t, char *, size_t); 101*32002227SRobert Mustacchi 102*32002227SRobert Mustacchi /* 103*32002227SRobert Mustacchi * Various functions that can be called to set the results of I/O commands. 104*32002227SRobert Mustacchi */ 105*32002227SRobert Mustacchi extern void i2c_ctrl_io_success(i2c_error_t *); 106*32002227SRobert Mustacchi extern void i2c_ctrl_io_error(i2c_error_t *, i2c_errno_t, i2c_ctrl_error_t); 107*32002227SRobert Mustacchi 108*32002227SRobert Mustacchi /* 109*32002227SRobert Mustacchi * Property information interfaces. 110*32002227SRobert Mustacchi */ 111*32002227SRobert Mustacchi extern void i2c_prop_info_set_perm(i2c_prop_info_t *, i2c_prop_perm_t); 112*32002227SRobert Mustacchi extern void i2c_prop_info_set_def_u32(i2c_prop_info_t *, uint32_t); 113*32002227SRobert Mustacchi extern void i2c_prop_info_set_range_u32(i2c_prop_info_t *, uint32_t, uint32_t); 114*32002227SRobert Mustacchi extern void i2c_prop_info_set_pos_bit32(i2c_prop_info_t *, uint32_t); 115*32002227SRobert Mustacchi 116*32002227SRobert Mustacchi /* 117*32002227SRobert Mustacchi * Ways for a driver to discover timeout parameters to use. 118*32002227SRobert Mustacchi */ 119*32002227SRobert Mustacchi typedef enum { 120*32002227SRobert Mustacchi /* 121*32002227SRobert Mustacchi * This is the amount of time that a given I/O command should take 122*32002227SRobert Mustacchi * before the request is timed out. 123*32002227SRobert Mustacchi */ 124*32002227SRobert Mustacchi I2C_CTRL_TO_IO, 125*32002227SRobert Mustacchi /* 126*32002227SRobert Mustacchi * This is the amount of time to busy-wait while polling the controller 127*32002227SRobert Mustacchi * for I/O to advance. 128*32002227SRobert Mustacchi */ 129*32002227SRobert Mustacchi I2C_CTRL_TO_POLL_CTRL, 130*32002227SRobert Mustacchi /* 131*32002227SRobert Mustacchi * This is the amount of time to wait for the bus to be clear for use 132*32002227SRobert Mustacchi * before beginning a transaction. 133*32002227SRobert Mustacchi */ 134*32002227SRobert Mustacchi I2C_CTRL_TO_BUS_ACT, 135*32002227SRobert Mustacchi /* 136*32002227SRobert Mustacchi * This is the amount of time to wait for an abort to complete. 137*32002227SRobert Mustacchi */ 138*32002227SRobert Mustacchi I2C_CTRL_TO_ABORT 139*32002227SRobert Mustacchi } i2c_ctrl_timeout_t; 140*32002227SRobert Mustacchi extern uint32_t i2c_ctrl_timeout_count(i2c_ctrl_hdl_t *, i2c_ctrl_timeout_t); 141*32002227SRobert Mustacchi extern uint32_t i2c_ctrl_timeout_delay_us(i2c_ctrl_hdl_t *, i2c_ctrl_timeout_t); 142*32002227SRobert Mustacchi 143*32002227SRobert Mustacchi #ifdef __cplusplus 144*32002227SRobert Mustacchi } 145*32002227SRobert Mustacchi #endif 146*32002227SRobert Mustacchi 147*32002227SRobert Mustacchi #endif /* _SYS_I2C_CONTROLLER_H */ 148