Lines Matching +full:charging +full:- +full:mode

4  * SPDX-License-Identifier: Apache-2.0
6 * Emulator for Diodes PI3USB9201 Dual-Role USB Charging-Type Detector.
38 /** Run-time data used by the emulator */
46 /** The current charging partner type requested by the test */
52 /** Pointer to run-time data */
62 struct pi3usb9201_emul_data *data = target->data; in pi3usb9201_emul_interrupt_is_pending()
64 if (data->reg[PI3USB9201_REG_CTRL_1] & PI3USB9201_REG_CTRL_1_INT_MASK) { in pi3usb9201_emul_interrupt_is_pending()
69 if ((data->reg[PI3USB9201_REG_CTRL_2] & PI3USB9201_REG_CTRL_2_START_DET) && in pi3usb9201_emul_interrupt_is_pending()
70 data->reg[PI3USB9201_REG_CLIENT_STS]) { in pi3usb9201_emul_interrupt_is_pending()
77 if (data->reg[PI3USB9201_REG_HOST_STS]) { in pi3usb9201_emul_interrupt_is_pending()
87 struct pi3usb9201_emul_data *data = target->data; in pi3usb9201_emul_set_reg()
88 const struct pi3usb9201_emul_cfg *cfg = target->cfg; in pi3usb9201_emul_set_reg()
91 return -EIO; in pi3usb9201_emul_set_reg()
94 data->reg[reg] = val; in pi3usb9201_emul_set_reg()
96 /* Once the driver sets the operating mode to client, update the in pi3usb9201_emul_set_reg()
97 * client status register with tests requested charging partner type in pi3usb9201_emul_set_reg()
100 enum pi3usb9201_mode mode = val >> PI3USB9201_REG_CTRL_1_MODE_SHIFT; in pi3usb9201_emul_set_reg() local
102 mode &= PI3USB9201_REG_CTRL_1_MODE_MASK; in pi3usb9201_emul_set_reg()
103 if (mode == PI3USB9201_CLIENT_MODE) { in pi3usb9201_emul_set_reg()
104 data->reg[PI3USB9201_REG_CLIENT_STS] = data->test_client_status; in pi3usb9201_emul_set_reg()
110 gpio_emul_input_set(cfg->intb_gpio.port, cfg->intb_gpio.pin, 0); in pi3usb9201_emul_set_reg()
118 struct pi3usb9201_emul_data *data = target->data; in pi3usb9201_emul_get_reg()
119 const struct pi3usb9201_emul_cfg *cfg = target->cfg; in pi3usb9201_emul_get_reg()
122 return -EIO; in pi3usb9201_emul_get_reg()
125 *val = data->reg[reg]; in pi3usb9201_emul_get_reg()
129 data->reg[reg] = 0; in pi3usb9201_emul_get_reg()
132 if (data->reg[PI3USB9201_REG_CLIENT_STS] == 0 && in pi3usb9201_emul_get_reg()
133 data->reg[PI3USB9201_REG_HOST_STS] == 0) { in pi3usb9201_emul_get_reg()
134 gpio_emul_input_set(cfg->intb_gpio.port, cfg->intb_gpio.pin, 1); in pi3usb9201_emul_get_reg()
143 struct pi3usb9201_emul_data *data = target->data; in pi3usb9201_emul_reset()
144 const struct pi3usb9201_emul_cfg *cfg = target->cfg; in pi3usb9201_emul_reset()
146 data->reg[PI3USB9201_REG_CTRL_1] = 0; in pi3usb9201_emul_reset()
147 data->reg[PI3USB9201_REG_CTRL_2] = 0; in pi3usb9201_emul_reset()
148 data->reg[PI3USB9201_REG_CLIENT_STS] = 0; in pi3usb9201_emul_reset()
149 data->reg[PI3USB9201_REG_HOST_STS] = 0; in pi3usb9201_emul_reset()
151 data->test_client_status = 0; in pi3usb9201_emul_reset()
153 gpio_emul_input_set(cfg->intb_gpio.port, cfg->intb_gpio.pin, 1); in pi3usb9201_emul_reset()
179 * @retval -EIO General input / output error
187 data = target->data; in pi3usb9201_emul_transfer()
188 cfg = data->cfg; in pi3usb9201_emul_transfer()
190 if (cfg->addr != addr) { in pi3usb9201_emul_transfer()
191 LOG_ERR("Address mismatch, expected %02x, got %02x", cfg->addr, addr); in pi3usb9201_emul_transfer()
192 return -EIO; in pi3usb9201_emul_transfer()
195 i2c_dump_msgs(target->dev, msgs, num_msgs, addr); in pi3usb9201_emul_transfer()
205 return -EIO; in pi3usb9201_emul_transfer()
212 return -EIO; in pi3usb9201_emul_transfer()
218 return -EIO; in pi3usb9201_emul_transfer()
223 struct pi3usb9201_emul_data *data = target->data; in pi3usb9201_emul_set_charging_partner()
228 data->test_client_status = 0; in pi3usb9201_emul_set_charging_partner()
231 data->test_client_status = SDP_DETECTED; in pi3usb9201_emul_set_charging_partner()
234 data->test_client_status = DCP_DETECTED; in pi3usb9201_emul_set_charging_partner()
237 data->test_client_status = CDP_DETECTED; in pi3usb9201_emul_set_charging_partner()
240 data->test_client_status = PROPRIETARY_1A_DETECTED; in pi3usb9201_emul_set_charging_partner()
243 LOG_ERR("Unsupported partner mode"); in pi3usb9201_emul_set_charging_partner()
244 return -EINVAL; in pi3usb9201_emul_set_charging_partner()
252 struct pi3usb9201_emul_data *data = target->data; in pi3usb9201_emul_set_pd_partner_state()
253 const struct pi3usb9201_emul_cfg *cfg = target->cfg; in pi3usb9201_emul_set_pd_partner_state()
254 uint8_t mode; in pi3usb9201_emul_set_pd_partner_state() local
256 mode = data->reg[PI3USB9201_REG_CTRL_1]; in pi3usb9201_emul_set_pd_partner_state()
257 mode >>= PI3USB9201_REG_CTRL_1_MODE_SHIFT; in pi3usb9201_emul_set_pd_partner_state()
258 mode &= PI3USB9201_REG_CTRL_1_MODE_MASK; in pi3usb9201_emul_set_pd_partner_state()
260 /* Driver must be configured for host mode SDP/CDP */ in pi3usb9201_emul_set_pd_partner_state()
261 if (mode != PI3USB9201_SDP_HOST_MODE && mode != PI3USB9201_CDP_HOST_MODE) { in pi3usb9201_emul_set_pd_partner_state()
262 return -EACCES; in pi3usb9201_emul_set_pd_partner_state()
266 data->reg[PI3USB9201_REG_HOST_STS] |= PI3USB9201_REG_HOST_STS_DEV_PLUG; in pi3usb9201_emul_set_pd_partner_state()
268 data->reg[PI3USB9201_REG_HOST_STS] |= PI3USB9201_REG_HOST_STS_DEV_UNPLUG; in pi3usb9201_emul_set_pd_partner_state()
271 /* Interrupt are enabled - assert the interrupt */ in pi3usb9201_emul_set_pd_partner_state()
272 if (!(data->reg[PI3USB9201_REG_CTRL_1] & PI3USB9201_REG_CTRL_1_INT_MASK)) { in pi3usb9201_emul_set_pd_partner_state()
273 gpio_emul_input_set(cfg->intb_gpio.port, cfg->intb_gpio.pin, 0); in pi3usb9201_emul_set_pd_partner_state()
303 const struct pi3usb9201_emul_cfg *cfg = target->cfg; in pi3usb9201_emul_init()
304 struct pi3usb9201_emul_data *data = cfg->data; in pi3usb9201_emul_init()
306 data->i2c = parent; in pi3usb9201_emul_init()
307 data->cfg = cfg; in pi3usb9201_emul_init()