Lines Matching +full:vconn +full:- +full:enable +full:- +full:polarity
3 * SPDX-License-Identifier: Apache-2.0
37 /** Alert handler set by USB-C stack */
39 /** Alert handler data set by USB-C stack */
42 /** VCONN discharge callback set by USB-C stack */
44 /** VCONN discharge callback data set by USB-C stack */
46 /** Polarity of CC lines for PD and VCONN */
69 const struct ps8xxx_cfg *cfg = dev->config; in tcpci_init_alert_mask()
76 ret = tcpci_write_reg16(&cfg->bus, TCPC_REG_ALERT_MASK, mask); in tcpci_init_alert_mask()
86 struct ps8xxx_data *data = dev->data; in ps8xxx_tcpc_init()
88 if (!data->initialized) { in ps8xxx_tcpc_init()
89 if (data->init_retries > CONFIG_USBC_TCPC_PS8XXX_INIT_RETRIES) { in ps8xxx_tcpc_init()
91 return -EIO; in ps8xxx_tcpc_init()
94 return -EAGAIN; in ps8xxx_tcpc_init()
104 const struct ps8xxx_cfg *cfg = dev->config; in ps8xxx_tcpc_get_cc()
105 struct ps8xxx_data *data = dev->data; in ps8xxx_tcpc_get_cc()
108 if (!data->initialized) { in ps8xxx_tcpc_get_cc()
109 return -EIO; in ps8xxx_tcpc_get_cc()
112 if (IS_ENABLED(CONFIG_USBC_CSM_SINK_ONLY) && !data->cc_changed) { in ps8xxx_tcpc_get_cc()
113 *cc1 = data->cc1; in ps8xxx_tcpc_get_cc()
114 *cc2 = data->cc2; in ps8xxx_tcpc_get_cc()
119 data->cc_changed = false; in ps8xxx_tcpc_get_cc()
121 ret = tcpci_tcpm_get_cc(&cfg->bus, cc1, cc2); in ps8xxx_tcpc_get_cc()
123 if (IS_ENABLED(CONFIG_USBC_CSM_SINK_ONLY) || *cc1 != data->cc1 || *cc2 != data->cc2) { in ps8xxx_tcpc_get_cc()
124 LOG_DBG("CC changed values: %d->%d, %d->%d", data->cc1, *cc1, data->cc2, *cc2); in ps8xxx_tcpc_get_cc()
125 data->cc1 = *cc1; in ps8xxx_tcpc_get_cc()
126 data->cc2 = *cc2; in ps8xxx_tcpc_get_cc()
134 const struct ps8xxx_cfg *cfg = dev->config; in ps8xxx_tcpc_select_rp_value()
135 struct ps8xxx_data *data = dev->data; in ps8xxx_tcpc_select_rp_value()
137 data->cc_changed = true; in ps8xxx_tcpc_select_rp_value()
139 return tcpci_update_reg8(&cfg->bus, TCPC_REG_ROLE_CTRL, TCPC_REG_ROLE_CTRL_RP_MASK, in ps8xxx_tcpc_select_rp_value()
145 const struct ps8xxx_cfg *cfg = dev->config; in ps8xxx_tcpc_get_rp_value()
149 ret = tcpci_read_reg8(&cfg->bus, TCPC_REG_ROLE_CTRL, ®_value); in ps8xxx_tcpc_get_rp_value()
157 const struct ps8xxx_cfg *cfg = dev->config; in ps8xxx_tcpc_set_cc()
158 struct ps8xxx_data *data = dev->data; in ps8xxx_tcpc_set_cc()
160 if (!data->initialized) { in ps8xxx_tcpc_set_cc()
161 return -EIO; in ps8xxx_tcpc_set_cc()
164 data->cc_changed = true; in ps8xxx_tcpc_set_cc()
166 return tcpci_update_reg8(&cfg->bus, TCPC_REG_ROLE_CTRL, in ps8xxx_tcpc_set_cc()
173 struct ps8xxx_data *data = dev->data; in ps8xxx_tcpc_set_vconn_discharge_cb()
175 data->vconn_discharge_cb = cb; in ps8xxx_tcpc_set_vconn_discharge_cb()
180 struct ps8xxx_data *data = dev->data; in ps8xxx_tcpc_set_vconn_cb()
182 data->vconn_cb = vconn_cb; in ps8xxx_tcpc_set_vconn_cb()
185 int ps8xxx_tcpc_vconn_discharge(const struct device *dev, bool enable) in ps8xxx_tcpc_vconn_discharge() argument
187 const struct ps8xxx_cfg *cfg = dev->config; in ps8xxx_tcpc_vconn_discharge()
189 return tcpci_update_reg8(&cfg->bus, TCPC_REG_POWER_CTRL, in ps8xxx_tcpc_vconn_discharge()
191 (enable) ? TCPC_REG_POWER_CTRL_AUTO_DISCHARGE_DISCONNECT : 0); in ps8xxx_tcpc_vconn_discharge()
194 int ps8xxx_tcpc_set_vconn(const struct device *dev, bool enable) in ps8xxx_tcpc_set_vconn() argument
196 const struct ps8xxx_cfg *cfg = dev->config; in ps8xxx_tcpc_set_vconn()
197 struct ps8xxx_data *data = dev->data; in ps8xxx_tcpc_set_vconn()
200 if (!data->initialized) { in ps8xxx_tcpc_set_vconn()
201 return -EIO; in ps8xxx_tcpc_set_vconn()
204 data->cc_changed = true; in ps8xxx_tcpc_set_vconn()
205 ret = tcpci_update_reg8(&cfg->bus, TCPC_REG_POWER_CTRL, TCPC_REG_POWER_CTRL_VCONN_EN, in ps8xxx_tcpc_set_vconn()
206 enable ? TCPC_REG_POWER_CTRL_VCONN_EN : 0); in ps8xxx_tcpc_set_vconn()
212 if (data->vconn_cb != NULL) { in ps8xxx_tcpc_set_vconn()
213 ret = data->vconn_cb(dev, data->cc_polarity, enable); in ps8xxx_tcpc_set_vconn()
222 const struct ps8xxx_cfg *cfg = dev->config; in ps8xxx_tcpc_set_roles()
224 return tcpci_update_reg8(&cfg->bus, TCPC_REG_MSG_HDR_INFO, TCPC_REG_MSG_HDR_INFO_ROLES_MASK, in ps8xxx_tcpc_set_roles()
230 const struct ps8xxx_cfg *cfg = dev->config; in ps8xxx_tcpc_get_rx_pending_msg()
231 struct ps8xxx_data *data = dev->data; in ps8xxx_tcpc_get_rx_pending_msg()
239 if (!data->msg_pending) { in ps8xxx_tcpc_get_rx_pending_msg()
240 return -ENODATA; in ps8xxx_tcpc_get_rx_pending_msg()
247 data->msg_pending = false; in ps8xxx_tcpc_get_rx_pending_msg()
256 ret = i2c_transfer(cfg->bus.bus, buf, 2, cfg->bus.addr); in ps8xxx_tcpc_get_rx_pending_msg()
266 buf[2].buf = (uint8_t *)&msg->type; in ps8xxx_tcpc_get_rx_pending_msg()
270 msg->header.raw_value = 0; in ps8xxx_tcpc_get_rx_pending_msg()
271 buf[3].buf = (uint8_t *)&msg->header.raw_value; in ps8xxx_tcpc_get_rx_pending_msg()
276 buf[4].buf = msg->data; in ps8xxx_tcpc_get_rx_pending_msg()
277 buf[4].len = msg_len - 3; in ps8xxx_tcpc_get_rx_pending_msg()
288 ret = i2c_transfer(cfg->bus.bus, buf, buf_count, cfg->bus.addr); in ps8xxx_tcpc_get_rx_pending_msg()
292 msg->len = (msg_len > 3) ? msg_len - 3 : 0; in ps8xxx_tcpc_get_rx_pending_msg()
293 ret = sizeof(msg->header.raw_value) + msg->len; in ps8xxx_tcpc_get_rx_pending_msg()
296 tcpci_write_reg16(&cfg->bus, TCPC_REG_ALERT, TCPC_REG_ALERT_RX_STATUS); in ps8xxx_tcpc_get_rx_pending_msg()
300 int ps8xxx_tcpc_set_rx_enable(const struct device *dev, bool enable) in ps8xxx_tcpc_set_rx_enable() argument
302 const struct ps8xxx_cfg *cfg = dev->config; in ps8xxx_tcpc_set_rx_enable()
303 int detect_sop_en = enable ? TCPC_REG_RX_DETECT_SOP_HRST_MASK : 0; in ps8xxx_tcpc_set_rx_enable()
305 return tcpci_write_reg8(&cfg->bus, TCPC_REG_RX_DETECT, detect_sop_en); in ps8xxx_tcpc_set_rx_enable()
308 int ps8xxx_tcpc_set_cc_polarity(const struct device *dev, enum tc_cc_polarity polarity) in ps8xxx_tcpc_set_cc_polarity() argument
310 const struct ps8xxx_cfg *cfg = dev->config; in ps8xxx_tcpc_set_cc_polarity()
311 struct ps8xxx_data *data = dev->data; in ps8xxx_tcpc_set_cc_polarity()
314 if (!data->initialized) { in ps8xxx_tcpc_set_cc_polarity()
315 return -EIO; in ps8xxx_tcpc_set_cc_polarity()
319 &cfg->bus, TCPC_REG_TCPC_CTRL, TCPC_REG_TCPC_CTRL_PLUG_ORIENTATION, in ps8xxx_tcpc_set_cc_polarity()
320 (polarity == TC_POLARITY_CC1) ? 0 : TCPC_REG_TCPC_CTRL_PLUG_ORIENTATION); in ps8xxx_tcpc_set_cc_polarity()
326 data->cc_changed = true; in ps8xxx_tcpc_set_cc_polarity()
327 data->cc_polarity = polarity; in ps8xxx_tcpc_set_cc_polarity()
333 const struct ps8xxx_cfg *cfg = dev->config; in ps8xxx_tcpc_transmit_data()
337 int cnt = 4 * msg->header.number_of_data_objects; in ps8xxx_tcpc_transmit_data()
340 if (msg->header.message_type >= NUM_SOP_STAR_TYPES) { in ps8xxx_tcpc_transmit_data()
346 &cfg->bus, TCPC_REG_TRANSMIT, in ps8xxx_tcpc_transmit_data()
347 TCPC_REG_TRANSMIT_SET_WITHOUT_RETRY(msg->header.message_type)); in ps8xxx_tcpc_transmit_data()
353 cnt += sizeof(msg->header.raw_value); in ps8xxx_tcpc_transmit_data()
363 buf[1].buf = (uint8_t *)&msg->header.raw_value; in ps8xxx_tcpc_transmit_data()
364 buf[1].len = sizeof(msg->header.raw_value); in ps8xxx_tcpc_transmit_data()
367 buf[2].buf = (uint8_t *)msg->data; in ps8xxx_tcpc_transmit_data()
368 buf[2].len = msg->len; in ps8xxx_tcpc_transmit_data()
371 if (cnt > sizeof(msg->header.raw_value)) { in ps8xxx_tcpc_transmit_data()
372 rv = i2c_transfer(cfg->bus.bus, buf, 3, cfg->bus.addr); in ps8xxx_tcpc_transmit_data()
375 rv = i2c_transfer(cfg->bus.bus, buf, 2, cfg->bus.addr); in ps8xxx_tcpc_transmit_data()
391 rv = tcpci_write_reg8(&cfg->bus, TCPC_REG_TRANSMIT, in ps8xxx_tcpc_transmit_data()
392 TCPC_REG_TRANSMIT_SET_WITH_RETRY(cfg->transmit_retries, msg->type)); in ps8xxx_tcpc_transmit_data()
399 const struct ps8xxx_cfg *cfg = dev->config; in ps8xxx_tcpc_dump_std_reg()
402 LOG_INF("TCPC %s:%s registers:", cfg->bus.bus->name, dev->name); in ps8xxx_tcpc_dump_std_reg()
406 tcpci_read_reg8(&cfg->bus, tcpci_std_regs[a].addr, (uint8_t *)&value); in ps8xxx_tcpc_dump_std_reg()
407 LOG_INF("- %-30s(0x%02x) = 0x%02x", tcpci_std_regs[a].name, in ps8xxx_tcpc_dump_std_reg()
411 tcpci_read_reg16(&cfg->bus, tcpci_std_regs[a].addr, &value); in ps8xxx_tcpc_dump_std_reg()
412 LOG_INF("- %-30s(0x%02x) = 0x%04x", tcpci_std_regs[a].name, in ps8xxx_tcpc_dump_std_reg()
428 return -ENOSYS; in ps8xxx_tcpc_get_status_register()
434 return -ENOSYS; in ps8xxx_tcpc_clear_status_register()
440 return -ENOSYS; in ps8xxx_tcpc_mask_status_register()
443 int ps8xxx_tcpc_set_debug_accessory(const struct device *dev, bool enable) in ps8xxx_tcpc_set_debug_accessory() argument
445 return -ENOSYS; in ps8xxx_tcpc_set_debug_accessory()
450 return -ENOSYS; in ps8xxx_tcpc_set_debug_detach()
453 int ps8xxx_tcpc_set_drp_toggle(const struct device *dev, bool enable) in ps8xxx_tcpc_set_drp_toggle() argument
455 return -ENOSYS; in ps8xxx_tcpc_set_drp_toggle()
460 return -ENOSYS; in ps8xxx_tcpc_get_snk_ctrl()
463 int ps8xxx_tcpc_set_snk_ctrl(const struct device *dev, bool enable) in ps8xxx_tcpc_set_snk_ctrl() argument
465 const struct ps8xxx_cfg *cfg = dev->config; in ps8xxx_tcpc_set_snk_ctrl()
466 uint8_t cmd = (enable) ? TCPC_REG_COMMAND_SNK_CTRL_HIGH : TCPC_REG_COMMAND_SNK_CTRL_LOW; in ps8xxx_tcpc_set_snk_ctrl()
468 return tcpci_write_reg8(&cfg->bus, TCPC_REG_COMMAND, cmd); in ps8xxx_tcpc_set_snk_ctrl()
473 return -ENOSYS; in ps8xxx_tcpc_get_src_ctrl()
476 int ps8xxx_tcpc_set_src_ctrl(const struct device *dev, bool enable) in ps8xxx_tcpc_set_src_ctrl() argument
478 const struct ps8xxx_cfg *cfg = dev->config; in ps8xxx_tcpc_set_src_ctrl()
479 uint8_t cmd = (enable) ? TCPC_REG_COMMAND_SRC_CTRL_DEF : TCPC_REG_COMMAND_SRC_CTRL_LOW; in ps8xxx_tcpc_set_src_ctrl()
481 return tcpci_write_reg8(&cfg->bus, TCPC_REG_COMMAND, cmd); in ps8xxx_tcpc_set_src_ctrl()
486 const struct ps8xxx_cfg *cfg = dev->config; in ps8xxx_tcpc_get_chip_info()
490 return -EIO; in ps8xxx_tcpc_get_chip_info()
493 ret |= tcpci_read_reg16(&cfg->bus, TCPC_REG_VENDOR_ID, &chip_info->vendor_id); in ps8xxx_tcpc_get_chip_info()
494 ret |= tcpci_read_reg16(&cfg->bus, TCPC_REG_PRODUCT_ID, &chip_info->product_id); in ps8xxx_tcpc_get_chip_info()
495 ret |= tcpci_read_reg16(&cfg->bus, TCPC_REG_BCD_DEV, &chip_info->device_id); in ps8xxx_tcpc_get_chip_info()
498 if (chip_info->product_id == PS8815_PRODUCT_ID) { in ps8xxx_tcpc_get_chip_info()
501 ret |= tcpci_read_reg8(&cfg->bus, PS8815_REG_FW_VER, &fw_ver); in ps8xxx_tcpc_get_chip_info()
502 chip_info->fw_version_number = fw_ver; in ps8xxx_tcpc_get_chip_info()
504 chip_info->fw_version_number = 0; in ps8xxx_tcpc_get_chip_info()
507 chip_info->min_req_fw_version_number = 0; in ps8xxx_tcpc_get_chip_info()
512 int ps8xxx_tcpc_set_low_power_mode(const struct device *dev, bool enable) in ps8xxx_tcpc_set_low_power_mode() argument
514 const struct ps8xxx_cfg *cfg = dev->config; in ps8xxx_tcpc_set_low_power_mode()
516 return tcpci_write_reg8(&cfg->bus, TCPC_REG_COMMAND, TCPC_REG_COMMAND_I2CIDLE); in ps8xxx_tcpc_set_low_power_mode()
519 int ps8xxx_tcpc_sop_prime_enable(const struct device *dev, bool enable) in ps8xxx_tcpc_sop_prime_enable() argument
521 return -ENOSYS; in ps8xxx_tcpc_sop_prime_enable()
524 int ps8xxx_tcpc_set_bist_test_mode(const struct device *dev, bool enable) in ps8xxx_tcpc_set_bist_test_mode() argument
526 return -ENOSYS; in ps8xxx_tcpc_set_bist_test_mode()
532 struct ps8xxx_data *data = dev->data; in ps8xxx_tcpc_set_alert_handler_cb()
534 if (data->alert_handler == handler && data->alert_handler_data == handler_data) { in ps8xxx_tcpc_set_alert_handler_cb()
538 data->alert_handler = handler; in ps8xxx_tcpc_set_alert_handler_cb()
539 data->alert_handler_data = handler_data; in ps8xxx_tcpc_set_alert_handler_cb()
584 k_work_submit(&data->alert_work); in ps8xxx_alert_cb()
590 const struct device *dev = data->dev; in ps8xxx_alert_work_cb()
591 const struct ps8xxx_cfg *cfg = dev->config; in ps8xxx_alert_work_cb()
595 if (!data->initialized) { in ps8xxx_alert_work_cb()
599 tcpci_read_reg16(&cfg->bus, TCPC_REG_ALERT, &alert_reg); in ps8xxx_alert_work_cb()
607 data->cc_changed = true; in ps8xxx_alert_work_cb()
611 tcpci_read_reg8(&cfg->bus, TCPC_REG_FAULT_STATUS, &fault); in ps8xxx_alert_work_cb()
612 tcpci_write_reg8(&cfg->bus, TCPC_REG_FAULT_STATUS, fault); in ps8xxx_alert_work_cb()
618 tcpci_read_reg8(&cfg->bus, TCPC_REG_EXT_STATUS, &ext_status); in ps8xxx_alert_work_cb()
619 tcpci_write_reg8(&cfg->bus, TCPC_REG_EXT_STATUS, ext_status); in ps8xxx_alert_work_cb()
621 data->cc_changed = true; in ps8xxx_alert_work_cb()
626 tcpci_read_reg8(&cfg->bus, TCPC_REG_POWER_STATUS, &pwr_status); in ps8xxx_alert_work_cb()
627 tcpci_write_reg8(&cfg->bus, TCPC_REG_POWER_STATUS, pwr_status); in ps8xxx_alert_work_cb()
633 tcpci_read_reg8(&cfg->bus, TCPC_REG_ALERT_EXT, &alert_status); in ps8xxx_alert_work_cb()
634 tcpci_write_reg8(&cfg->bus, TCPC_REG_ALERT_EXT, alert_status); in ps8xxx_alert_work_cb()
638 data->msg_pending = true; in ps8xxx_alert_work_cb()
640 data->cc_changed = true; in ps8xxx_alert_work_cb()
643 if (data->alert_handler != NULL) { in ps8xxx_alert_work_cb()
644 data->alert_handler(data->dev, data->alert_handler_data, alert_type); in ps8xxx_alert_work_cb()
651 tcpci_write_reg16(&cfg->bus, TCPC_REG_ALERT, clear_flags); in ps8xxx_alert_work_cb()
653 tcpci_read_reg16(&cfg->bus, TCPC_REG_ALERT, &alert_reg); in ps8xxx_alert_work_cb()
664 const struct ps8xxx_cfg *cfg = data->dev->config; in ps8xxx_init_work_cb()
671 LOG_INF("Initializing PS8xxx chip: %s", data->dev->name); in ps8xxx_init_work_cb()
672 res = tcpci_read_reg8(&cfg->bus, TCPC_REG_POWER_STATUS, &power_reg); in ps8xxx_init_work_cb()
674 data->init_retries++; in ps8xxx_init_work_cb()
676 if (data->init_retries > CONFIG_USBC_TCPC_PS8XXX_INIT_RETRIES) { in ps8xxx_init_work_cb()
681 LOG_DBG("Postpone chip initialization %d", data->init_retries); in ps8xxx_init_work_cb()
682 k_work_schedule_for_queue(&k_sys_work_q, &data->init_dwork, in ps8xxx_init_work_cb()
688 tcpci_read_reg16(&cfg->bus, TCPC_REG_VENDOR_ID, &idVendor); in ps8xxx_init_work_cb()
689 tcpci_read_reg16(&cfg->bus, TCPC_REG_PRODUCT_ID, &idProduct); in ps8xxx_init_work_cb()
690 tcpci_read_reg16(&cfg->bus, TCPC_REG_BCD_DEV, &idDevice); in ps8xxx_init_work_cb()
694 gpio_pin_configure_dt(&cfg->alert_gpio, GPIO_INPUT); in ps8xxx_init_work_cb()
696 gpio_init_callback(&data->alert_cb, ps8xxx_alert_cb, BIT(cfg->alert_gpio.pin)); in ps8xxx_init_work_cb()
697 gpio_add_callback(cfg->alert_gpio.port, &data->alert_cb); in ps8xxx_init_work_cb()
698 gpio_pin_interrupt_configure_dt(&cfg->alert_gpio, GPIO_INT_EDGE_TO_ACTIVE); in ps8xxx_init_work_cb()
700 tcpci_init_alert_mask(data->dev); in ps8xxx_init_work_cb()
701 data->initialized = true; in ps8xxx_init_work_cb()
703 /* Disable the vconn and open CC lines to reinitialize the communication with partner */ in ps8xxx_init_work_cb()
704 ps8xxx_tcpc_set_vconn(data->dev, false); in ps8xxx_init_work_cb()
705 ps8xxx_tcpc_set_cc(data->dev, TC_CC_OPEN); in ps8xxx_init_work_cb()
708 k_work_submit(&data->alert_work); in ps8xxx_init_work_cb()
713 const struct ps8xxx_cfg *cfg = dev->config; in ps8xxx_dev_init()
714 struct ps8xxx_data *data = dev->data; in ps8xxx_dev_init()
716 if (!device_is_ready(cfg->bus.bus)) { in ps8xxx_dev_init()
717 return -EIO; in ps8xxx_dev_init()
720 k_work_init_delayable(&data->init_dwork, ps8xxx_init_work_cb); in ps8xxx_dev_init()
721 k_work_schedule_for_queue(&k_sys_work_q, &data->init_dwork, in ps8xxx_dev_init()
724 k_work_init(&data->alert_work, ps8xxx_alert_work_cb); in ps8xxx_dev_init()