Skip to content

Add TCPC driver for FUSB307 #85831

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 27, 2025
Merged

Conversation

recalci
Copy link
Contributor

@recalci recalci commented Feb 16, 2025

This PR adds the TCPC driver for the FUSB307 and includes several related fixes.

Copy link
Collaborator

@keith-zephyr keith-zephyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first commits on this PR are bug fixes and could be merged into the 4.1 release if you split them out into a separate PR.

@recalci
Copy link
Contributor Author

recalci commented Feb 21, 2025

The first commits on this PR are bug fixes and could be merged into the 4.1 release if you split them out into a separate PR.

Thank you for your review. I've created a new PR #86143

Corrected macro definitions.

Signed-off-by: Jianxiong Gu <[email protected]>
@recalci recalci force-pushed the usbc_tcpc_fusb307 branch 2 times, most recently from de601ac to fa4feea Compare March 4, 2025 16:30
@recalci recalci force-pushed the usbc_tcpc_fusb307 branch from fa4feea to 7a4ee45 Compare March 6, 2025 18:00
keith-zephyr
keith-zephyr previously approved these changes Mar 12, 2025
tmon-nordic
tmon-nordic previously approved these changes Mar 14, 2025

ret = tcpci_tcpm_get_status_register(bus, TCPC_REG_POWER_STATUS, &reg);
if (ret == 0) {
*sinking = !!(reg & TCPC_REG_POWER_STATUS_SINKING_VBUS);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be just *sinking = reg & TCPC_REG_POWER_STATUS_SINKING_VBUS;, see C STD scalar value conversion to bool.


ret = tcpci_tcpm_get_status_register(bus, TCPC_REG_POWER_STATUS, &reg);
if (ret == 0) {
*sourcing = !!(reg & TCPC_REG_POWER_STATUS_SOURCING_VBUS);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above

Comment on lines 625 to 628
if (enable) {
/* Set Look4Connection command */
return tcpci_write_reg8(bus, TCPC_REG_COMMAND, TCPC_REG_COMMAND_LOOK4CONNECTION);
} else {
return 0;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

	if (enable) {
		/* Set Look4Connection command */
		return tcpci_write_reg8(bus, TCPC_REG_COMMAND, TCPC_REG_COMMAND_LOOK4CONNECTION);
	}

	return 0;

IIRC, there should be checkpatch warning for this kind of constructs.

#define DT_DRV_COMPAT onnn_fusb307_tcpc
LOG_MODULE_REGISTER(tcpc_fusb307, CONFIG_USBC_LOG_LEVEL);

/** Data structure for device instances */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment style must be /* */, it is documented.
Also, there is no need to comment obvious things like /* Data structure for device instances */, Delayable work, Boolean valu, State of CC1...

VCONN_DISC_GPIO(node), \
}

#define FUSB307_DRIVER_INIT(inst) \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#define FUSB307_INSTANCE_DEFINE(inst)

static struct fusb307_data drv_data_fusb307##inst = \
FUSB307_DRIVER_DATA_INIT(DT_DRV_INST(inst)); \
static struct fusb307_cfg drv_cfg_fusb307##inst = \
FUSB307_DRIVER_CFG_INIT(DT_DRV_INST(inst)); \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just

	static struct fusb307_cfg fusb307_cfg_##inst = {
		.bus = I2C_DT_SPEC_GET(node),                                                      \
		.alert_gpio = GPIO_DT_SPEC_GET(node, irq_gpios),                                   \
		.transmit_retries = DT_PROP(node, transmit_retries),                               \
		VCONN_DISC_GPIO(node),                                                             \
	};

and the same for the data

recalci added 3 commits March 16, 2025 20:55
Add generic functions that will be common to TCPCI compliant drivers.

Signed-off-by: Jianxiong Gu <[email protected]>
Update set_snk_ctrl, set_src_ctrl, and set_low_power_mode
to use the generic TCPCI function.

Signed-off-by: Jianxiong Gu <[email protected]>
Updated set_drp_toggle to handle differences in TCPCI revisions.
Added a macro for TCPCI revision and read it from the chip register
during initialization.

Signed-off-by: Jianxiong Gu <[email protected]>
@recalci recalci dismissed stale reviews from tmon-nordic and keith-zephyr via 9fe0c8d March 16, 2025 17:36
@recalci recalci force-pushed the usbc_tcpc_fusb307 branch from 7a4ee45 to 9fe0c8d Compare March 16, 2025 17:36
@recalci
Copy link
Contributor Author

recalci commented Mar 16, 2025

@jfischer-no thanks for the review.
Requested changes implemented

@recalci recalci closed this Mar 17, 2025
@recalci recalci deleted the usbc_tcpc_fusb307 branch March 17, 2025 15:48
@recalci recalci restored the usbc_tcpc_fusb307 branch March 17, 2025 15:57
@recalci
Copy link
Contributor Author

recalci commented Mar 17, 2025

Sorry,I closed this PR by mistake. Reopen

@recalci recalci reopened this Mar 17, 2025
keith-zephyr
keith-zephyr previously approved these changes Mar 17, 2025
recalci added 3 commits March 27, 2025 02:35
Add support for FUSB307.

Signed-off-by: Jianxiong Gu <[email protected]>
Enable VBUS measurement before checking the VBUS level and
disable it when unattached.

Signed-off-by: Jianxiong Gu <[email protected]>
Add a build test to verify fusb307 driver builds correctly.

Signed-off-by: Jianxiong Gu <[email protected]>
Copy link
Collaborator

@jfischer-no jfischer-no left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@craigpeacock
Copy link

What is the status on this one? @sambhurst

@kartben kartben merged commit a505a43 into zephyrproject-rtos:main May 27, 2025
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: USB Universal Serial Bus area: USB-C
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants