Lines Matching +full:reg +full:- +full:rc
4 * SPDX-License-Identifier: Apache-2.0
28 /** Run-time data used by the emulator */
33 static int emul_sbs_charger_reg_write(const struct emul *target, int reg, int val) in emul_sbs_charger_reg_write() argument
35 struct sbs_charger_emul_data *data = target->data; in emul_sbs_charger_reg_write()
37 LOG_INF("write %x = %x", reg, val); in emul_sbs_charger_reg_write()
38 switch (reg) { in emul_sbs_charger_reg_write()
40 data->reg_charger_mode = val; in emul_sbs_charger_reg_write()
43 LOG_ERR("Unknown write %x", reg); in emul_sbs_charger_reg_write()
44 return -EIO; in emul_sbs_charger_reg_write()
50 static int emul_sbs_charger_reg_read(const struct emul *target, int reg, int *val) in emul_sbs_charger_reg_read() argument
52 switch (reg) { in emul_sbs_charger_reg_read()
61 LOG_ERR("Unknown register 0x%x read", reg); in emul_sbs_charger_reg_read()
62 return -EIO; in emul_sbs_charger_reg_read()
64 LOG_INF("read 0x%x = 0x%x", reg, *val); in emul_sbs_charger_reg_read()
75 int reg; in sbs_charger_emul_transfer_i2c() local
76 int rc; in sbs_charger_emul_transfer_i2c() local
78 data = target->data; in sbs_charger_emul_transfer_i2c()
80 i2c_dump_msgs_rw(target->dev, msgs, num_msgs, addr, false); in sbs_charger_emul_transfer_i2c()
83 if (msgs->flags & I2C_MSG_READ) { in sbs_charger_emul_transfer_i2c()
85 return -EIO; in sbs_charger_emul_transfer_i2c()
87 if (msgs->len != 1) { in sbs_charger_emul_transfer_i2c()
88 LOG_ERR("Unexpected msg0 length %d", msgs->len); in sbs_charger_emul_transfer_i2c()
89 return -EIO; in sbs_charger_emul_transfer_i2c()
91 reg = msgs->buf[0]; in sbs_charger_emul_transfer_i2c()
95 if (msgs->flags & I2C_MSG_READ) { in sbs_charger_emul_transfer_i2c()
96 switch (msgs->len - 1) { in sbs_charger_emul_transfer_i2c()
98 rc = emul_sbs_charger_reg_read(target, reg, &val); in sbs_charger_emul_transfer_i2c()
99 if (rc) { in sbs_charger_emul_transfer_i2c()
101 return rc; in sbs_charger_emul_transfer_i2c()
104 /* SBS uses SMBus, which sends data in little-endian format. */ in sbs_charger_emul_transfer_i2c()
105 sys_put_le16(val, msgs->buf); in sbs_charger_emul_transfer_i2c()
108 LOG_ERR("Unexpected msg1 length %d", msgs->len); in sbs_charger_emul_transfer_i2c()
109 return -EIO; in sbs_charger_emul_transfer_i2c()
113 if (msgs->len != 2) { in sbs_charger_emul_transfer_i2c()
114 LOG_ERR("Unexpected msg1 length %d", msgs->len); in sbs_charger_emul_transfer_i2c()
116 uint16_t value = sys_get_le16(msgs->buf); in sbs_charger_emul_transfer_i2c()
118 rc = emul_sbs_charger_reg_write(target, reg, value); in sbs_charger_emul_transfer_i2c()
123 return -EIO; in sbs_charger_emul_transfer_i2c()
126 return rc; in sbs_charger_emul_transfer_i2c()