static inline uint8_t controller_read(int ctrl_num, uint8_t reg) { int val = 0; ctrl_num = ctrl_num % ARRAY_SIZE(i2c_addr); i2c_read8(I2C_PORT_LIGHTBAR, i2c_addr[ctrl_num], reg, &val); return val; }
static int test_i2c(void) { int res = EC_ERROR_UNKNOWN; int dummy_data; struct i2c_test_param_t *param; param = i2c_test_params + (prng_no_seed() % (sizeof(i2c_test_params) / sizeof(struct i2c_test_param_t))); if (param->width == 8 && param->data == -1) res = i2c_read8(param->port, param->addr, param->offset, &dummy_data); else if (param->width == 8 && param->data >= 0) res = i2c_write8(param->port, param->addr, param->offset, param->data); else if (param->width == 16 && param->data == -1) res = i2c_read16(param->port, param->addr, param->offset, &dummy_data); else if (param->width == 16 && param->data >= 0) res = i2c_write16(param->port, param->addr, param->offset, param->data); else if (param->width == 32 && param->data == -1) res = i2c_read32(param->port, param->addr, param->offset, &dummy_data); else if (param->width == 32 && param->data >= 0) res = i2c_write32(param->port, param->addr, param->offset, param->data); return res; }
static int anx7688_init(int port) { int rv = 0; int mask = 0; /* * 7688 POWER_STATUS[6] is not reliable for tcpci_tcpm_init() to poll * due to it is default 0 in HW, and we cannot write TCPC until it is * ready, or something goes wrong. (Issue 52772) * Instead we poll TCPC 0x50:0xe7 bit6 here to make sure bootdone is * ready(50ms). Then PD main flow can process cc debounce in 50ms ~ * 100ms to follow cts. */ while (1) { rv = i2c_read8(I2C_PORT_TCPC, ANX7688_USBC_ADDR, ANX7688_REG_RAMCTRL, &mask); if (rv == EC_SUCCESS && (mask & ANX7688_REG_RAMCTRL_BOOT_DONE)) break; msleep(10); } rv = tcpci_tcpm_drv.init(port); if (rv) return rv; rv = tcpc_read16(port, TCPC_REG_ALERT_MASK, &mask); if (rv) return rv; /* enable vendor specific alert */ mask |= ANX7688_VENDOR_ALERT; rv = tcpc_write16(port, TCPC_REG_ALERT_MASK, mask); return rv; }
static int pca9534_pin_read(int port, int addr, int reg, int pin, int *val) { int ret; ret = i2c_read8(port, addr, reg, val); *val = (*val & (1 << pin)) ? 1 : 0; return ret; }
int tcpm_get_cc(int port, int *cc1, int *cc2) { int status; int rv; rv = i2c_read8(I2C_PORT_TCPC, I2C_ADDR_TCPC(port), TCPC_REG_CC_STATUS, &status); /* If i2c read fails, return error */ if (rv) return rv; *cc1 = TCPC_REG_CC_STATUS_CC1(status); *cc2 = TCPC_REG_CC_STATUS_CC2(status); /* * If status is not open, then OR in termination to convert to * enum tcpc_cc_voltage_status. */ if (*cc1 != TYPEC_CC_VOLT_OPEN) *cc1 |= TCPC_REG_CC_STATUS_TERM(status) << 2; if (*cc2 != TYPEC_CC_VOLT_OPEN) *cc2 |= TCPC_REG_CC_STATUS_TERM(status) << 2; return rv; }
/** * Read the humidity register from the sensor. */ int16_t hts221_read_hum() { int16_t buffer = 0; if (i2c_read8(HTS221_ADDRESS_R, I2C_AAI(HTS221_HUMIDITY_OUT_L), (uint8_t*)&buffer, 2) != DEVICES_OK) { return INT16_MIN; } return buffer; }
/** * Read the WHO_AM_I register to detect the presence of the sensor. * The sensor should respond with HTS221_WHO_I_AM. */ uint8_t hts221_who_am_i() { uint8_t value; if (i2c_read8(HTS221_ADDRESS_R, HTS221_WHO_AM_I, &value, 1) != DEVICES_OK) { return 0; } return value; }
static int raw_read8(const int offset, int *data_ptr) { int ret; ret = i2c_read8(I2C_PORT_THERMAL, BD99992GW_I2C_ADDR, offset, data_ptr); if (ret != EC_SUCCESS) CPRINTS("bd99992gw read fail %d\n", ret); return ret; }
static int ps8740_read(int i2c_addr, uint8_t reg, uint8_t *val) { int read, res; res = i2c_read8(I2C_PORT_USB_MUX, i2c_addr, reg, &read); if (res) return res; *val = read; return EC_SUCCESS; }
static uint8_t ir357x_read(uint8_t reg) { int res; int val; res = i2c_read8(I2C_PORT_REGULATOR, IR357x_I2C_ADDR, reg, &val); if (res) return 0xee; return val; }
static int pca9534_pin_write(int port, int addr, int reg, int pin, int val) { int ret, v; ret = i2c_read8(port, addr, reg, &v); if (ret != EC_SUCCESS) return ret; v &= ~(1 << pin); if (val) v |= 1 << pin; return i2c_write8(port, addr, reg, v); }
static int anx7688_tcpm_get_vbus_level(int port) { int reg = 0; /* On ANX7688, POWER_STATUS.VBusPresent (bit 2) is averaged 16 times, so * its value may not be set to 1 quickly enough during power role swap. * Therefore, we use a proprietary register to read the unfiltered VBus * value. See crosbug.com/p/55221 . */ i2c_read8(I2C_PORT_TCPC, 0x50, 0x40, ®); return ((reg & 0x10) ? 1 : 0); }
int rcpod_I2CRead(rcpod_dev* rcpod, rcpod_i2c_dev* idev, unsigned char* read_buffer, int read_count) { if (!rcpod_HasAcceleratedI2C(rcpod)) return softi2c_read(rcpod, idev, read_buffer, read_count); if (i2c_set_dev(rcpod, idev) < 0) return 0; if (read_count <= 8 && read_count > 0) return i2c_read8(rcpod, read_buffer, read_count); return i2c_write_read(rcpod, NULL, 0, read_buffer, read_count); }
int charger_get_input_current(int *input_current) { int rv; int reg; rv = i2c_read8(I2C_PORT_CHARGER, BQ24773_ADDR, BQ24773_INPUT_CURRENT, ®); if (rv) return rv; *input_current = REG8_TO_CURRENT(reg, R_AC); return EC_SUCCESS; }
/* Read from lp8555 with automatic i2c retries */ static int lp8555_read_with_retry(int reg, int *data) { int i, rv; for (i = 0; i < I2C_RETRIES; i++) { rv = i2c_read8(I2C_PORT_BACKLIGHT, I2C_ADDR_BACKLIGHT, reg, data); if (rv == EC_SUCCESS) return EC_SUCCESS; usleep(I2C_RETRY_DELAY); } CPRINTS("Backlight read fail: reg 0x%02x", reg); return rv; }
uint8_t ov7670_get(uint8_t addr) { uint8_t retval; i2c_start(); i2c_write8(OV7670_ADDR); i2c_write8(addr); i2c_stop(); __delay_cycles(16 * 1000); i2c_start(); i2c_write8(OV7670_ADDR + 1); retval = i2c_read8(0xFF); i2c_stop(); return retval; }
/** * Retrieve the calibration data from the sensor. * This is required to interpolate the physical units from the sensor values. */ Devices_StatusTypeDef hts221_read_calib(HTS221_CalibTypeDef* calib) { /* The calibration registers are in order - read them all at once. */ uint8_t buffer[16] = { 0 }; if (i2c_read8(HTS221_ADDRESS_R, I2C_AAI(HTS221_H0_rH_x2), buffer, 16) != DEVICES_OK) { return DEVICES_ERROR; } calib->H0_rH = (float)buffer[0] / 2.0; calib->H1_rH = (float)buffer[1] / 2.0; calib->T0_degC = (float)(buffer[2] + ((buffer[5] & 0x3) << 8)) / 8.0; calib->T1_degC = (float)(buffer[3] + ((buffer[5] & 0xC) << 6)) / 8.0; calib->H0_T0_OUT = *(int16_t*)&buffer[6]; calib->H1_T0_OUT = *(int16_t*)&buffer[10]; calib->T0_OUT = *(int16_t*)&buffer[12]; calib->T1_OUT = *(int16_t*)&buffer[14]; return DEVICES_OK; }
void board_tcpc_init(void) { int port, reg; /* Only reset TCPC if not sysjump */ if (!system_jumped_to_this_image()) board_reset_pd_mcu(); /* * TODO: Remove when Reef is updated with PS8751 A3. * * Force PS8751 A2 to wake from low power mode. * If PS8751 remains in low power mode after sysjump, * TCPM_INIT will fail due to not able to access PS8751. * * NOTE: PS8751 A3 will wake on any I2C access. */ i2c_read8(NPCX_I2C_PORT0_1, 0x10, 0xA0, ®); /* Enable TCPC0 interrupt */ gpio_enable_interrupt(GPIO_USB_C0_PD_INT_ODL); /* Enable TCPC1 interrupt */ gpio_enable_interrupt(GPIO_USB_C1_PD_INT_ODL); #ifdef CONFIG_USB_PD_TCPC_LOW_POWER /* Enable CABLE_DET interrupt for ANX3429 wake from standby */ gpio_enable_interrupt(GPIO_USB_C0_CABLE_DET); #endif /* * Initialize HPD to low; after sysjump SOC needs to see * HPD pulse to enable video path */ for (port = 0; port < CONFIG_USB_PD_PORT_COUNT; port++) { const struct usb_mux *mux = &usb_muxes[port]; mux->hpd_update(port, 0, 0); } }
int tcpm_get_message(int port, uint32_t *payload, int *head) { int rv, cnt, reg = TCPC_REG_RX_DATA; rv = i2c_read8(I2C_PORT_TCPC, I2C_ADDR_TCPC(port), TCPC_REG_RX_BYTE_CNT, &cnt); rv |= i2c_read16(I2C_PORT_TCPC, I2C_ADDR_TCPC(port), TCPC_REG_RX_HDR, (int *)head); if (rv == EC_SUCCESS && cnt > 0) { i2c_lock(I2C_PORT_TCPC, 1); rv = i2c_xfer(I2C_PORT_TCPC, I2C_ADDR_TCPC(port), (uint8_t *)®, 1, (uint8_t *)payload, cnt, I2C_XFER_SINGLE); i2c_lock(I2C_PORT_TCPC, 0); } /* Read complete, clear RX status alert bit */ i2c_write16(I2C_PORT_TCPC, I2C_ADDR_TCPC(port), TCPC_REG_ALERT, TCPC_REG_ALERT_RX_STATUS); return rv; }
inline int lp5562_read(uint8_t reg, int *val) { return i2c_read8(I2C_PORT_MASTER, LP5562_I2C_ADDR, reg, val); }
int tcpm_get_power_status(int port, int *status) { return i2c_read8(I2C_PORT_TCPC, I2C_ADDR_TCPC(port), TCPC_REG_POWER_STATUS, status); }
/** * Read register from Gyrometer. */ static inline int raw_read8(const int port, const int addr, const int reg, int *data_ptr) { return i2c_read8(port, addr, reg, data_ptr); }
int charger_device_id(int *id) { return i2c_read8(I2C_PORT_CHARGER, BQ24773_ADDR, BQ24773_DEVICE_ADDRESS, id); }
/** * Read register from Gyrometer. */ static inline int raw_read8(const int addr, const int reg, int *data_ptr) { return i2c_read8(I2C_PORT_GYRO, addr, reg, data_ptr); }
static int raw_read8(const int offset, int *data_ptr) { return i2c_read8(I2C_PORT_THERMAL, TMP432_I2C_ADDR, offset, data_ptr); }