Skip to content
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

[Deepin-Kernel-SIG] [linux 6.6-y] [CIX] Apply syscon, gpio and phy suppors for CIX #642

Closed

Conversation

Avenger-285714
Copy link
Collaborator

@Avenger-285714 Avenger-285714 commented Mar 5, 2025

Summary by Sourcery

Adds support for CIXtech devices, including syscon, GPIO, and PHY drivers. This includes adding ACPI IDs for syscon and GPIO, and introducing new PHY drivers for USBDP, USB3, and USB2.

New Features:

  • Adds a new syscon regmap lookup function for devices with ACPI companions.
  • Introduces new PHY drivers for CIXtech USBDP, USB3 and USB2 devices.

Guomin.Chen and others added 3 commits March 5, 2025 14:10
Add ACPI support for syscon subsystem.

Signed-off-by: Lihua Liu <[email protected]>
Signed-off-by: Guomin.Chen <[email protected]>
Add acpi support for cadence gpio driver.

Signed-off-by: Zichar.Zhang <[email protected]>
Add usb2,usb3 and combo phy driver for cix.

Signed-off-by: Guomin.Chen <[email protected]>
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from avenger-285714. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

We failed to fetch the diff for pull request #642

You can try again by commenting this pull request with @sourcery-ai review, or contact us for help.

@Avenger-285714
Copy link
Collaborator Author

@sourcery-ai review

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

We failed to fetch the diff for pull request #642

You can try again by commenting this pull request with @sourcery-ai review, or contact us for help.

@opsiff
Copy link
Member

opsiff commented Mar 5, 2025

@sourcery-ai review

@opsiff
Copy link
Member

opsiff commented Mar 5, 2025

I suggest to splict the pull request to many small pull request to review, instead of many commits in one request in the situation :(.

@Avenger-285714 Avenger-285714 changed the title [Deepin-Kernel-SIG] [linux 6.6-y] [CIX] Apply suppors from CIXtech [WIP] [Deepin-Kernel-SIG] [linux 6.6-y] [CIX] Apply suppors from CIXtech Mar 5, 2025
@Avenger-285714 Avenger-285714 changed the title [WIP] [Deepin-Kernel-SIG] [linux 6.6-y] [CIX] Apply suppors from CIXtech [Deepin-Kernel-SIG] [linux 6.6-y] [CIX] Apply suppors from CIXtech Mar 5, 2025
@Avenger-285714 Avenger-285714 changed the title [Deepin-Kernel-SIG] [linux 6.6-y] [CIX] Apply suppors from CIXtech [Deepin-Kernel-SIG] [linux 6.6-y] [CIX] Apply suppors from CIXtech ( part of syscon, gpio and phy) Mar 5, 2025
@Avenger-285714
Copy link
Collaborator Author

@sourcery-ai review

Copy link

sourcery-ai bot commented Mar 5, 2025

Reviewer's Guide by Sourcery

This pull request adds support for CIX hardware, including syscon, GPIO, and PHY drivers. It introduces ACPI support for existing drivers and adds new drivers for USB, USBDP, and USB2 PHYs.

Sequence diagram for udphy_orien_sw_set

sequenceDiagram
  participant User
  participant typec_switch_dev
  participant cix_udphy

  User->>+typec_switch_dev: udphy_orien_sw_set(sw, orien)
  typec_switch_dev->>+cix_udphy: mutex_lock(&udphy->mutex)
  cix_udphy->>cix_udphy: udphy->flip = (orien == TYPEC_ORIENTATION_REVERSE)
  cix_udphy->>-typec_switch_dev: mutex_unlock(&udphy->mutex)
  typec_switch_dev-->>User: return 0
Loading

Sequence diagram for usbdp_typec_mux_set

sequenceDiagram
  participant User
  participant typec_mux_dev
  participant cix_udphy

  User->>+typec_mux_dev: usbdp_typec_mux_set(mux, state)
  typec_mux_dev->>+cix_udphy: mutex_lock(&udphy->mutex)
  cix_udphy->>cix_udphy: switch (state->mode)
  cix_udphy->>cix_udphy: udphy->next_mode = ...
  cix_udphy->>cix_udphy: usbdp_set_dpphy_mode(udphy)
  cix_udphy->>-typec_mux_dev: mutex_unlock(&udphy->mutex)
  typec_mux_dev-->>User: return 0
Loading

Class diagram for cix_u3phy

classDiagram
  class cix_u3phy {
    struct device *dev
    void __iomem *base
    struct regmap *phy_regmap
    struct regmap *usbphy_syscon
    struct reset_control *preset
    struct reset_control *reset
    struct clk *apb_clk
    struct clk *ref_clk
    struct mutex mutex
    bool init
    int init_count
    int id
    const struct cix_u3phy_cfg *cfg
  }
  class cix_u3phy_cfg {
    int (*u3phy_init)(struct cix_u3phy *u3phy)
    int (*u3phy_exit)(struct cix_u3phy *u3phy)
  }
  cix_u3phy -- cix_u3phy_cfg : has a
Loading

File-Level Changes

Change Details Files
Added a function to look up a syscon regmap by a device property, supporting both device tree and ACPI.
  • Added device_syscon_regmap_lookup_by_property function to look up a syscon regmap by a device property.
  • The function checks for an ACPI companion device and uses fwnode_find_reference to locate the regmap.
  • Added export for the function.
drivers/mfd/syscon.c
include/linux/mfd/syscon.h
Added ACPI support to the syscon driver.
  • Added an ACPI device ID table for the syscon driver.
  • Added the ACPI match table to the syscon platform driver.
drivers/mfd/syscon.c
Added ACPI support to the cadence GPIO driver.
  • Added an ACPI device ID table for the cadence GPIO driver.
  • Added the ACPI match table to the cadence GPIO platform driver.
drivers/gpio/gpio-cadence.c
Added a new directory for CIX PHY drivers.
  • Created a new directory drivers/phy/cix/.
  • Added phy-cix-usbdp.c, phy-cix-usb3.c, phy-cix-usb2.c, Makefile, and Kconfig files to the new directory.
drivers/phy/Makefile
drivers/phy/Kconfig
drivers/phy/cix/phy-cix-usbdp.c
drivers/phy/cix/phy-cix-usb3.c
drivers/phy/cix/phy-cix-usb2.c
drivers/phy/cix/Makefile
drivers/phy/cix/Kconfig

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @Avenger-285714 - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding a Kconfig option for the CIX syscon driver to allow it to be disabled if necessary.
  • The phy driver adds a lot of code - can it be split into multiple commits?
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

assert_phy:
reset_control_assert(udphy->reset);

assert_apb:
Copy link

Choose a reason for hiding this comment

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

suggestion (bug_risk): Return error code instead of 0 on failure in sky1_udphy_init.

In the error-handling paths (after "assert_phy:" and "assert_apb:"), the function unconditionally returns 0 even when an error has occurred (e.g. if regmap_multi_reg_write fails or udphy_status_check returns an error). This behavior might hide failures and lead the caller to incorrectly assume success. Consider propagating the appropriate error code instead.

Suggested implementation:

	assert_phy:
		reset_control_assert(udphy->reset);


		return ret;
	assert_apb:
		reset_control_assert(udphy->preset);
		clk_disable_unprepare(udphy->apb_clk);

		return ret;

Ensure that 'ret' is correctly set to a valid error code before branching to these error-handling labels. If additional clean-up is needed before returning the error code, consider that in the function design.

Comment on lines +31 to +38
preset = devm_reset_control_get(dev, "preset");

if (IS_ERR(preset))
dev_err(dev, "%s: failed to get preset\n", __func__);
else
reset_control_deassert(preset);

return 0;
Copy link

Choose a reason for hiding this comment

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

suggestion (bug_risk): Revisit error handling for missing reset control.

Currently, if obtaining the reset control fails, an error is logged but the probe continues and returns success. If the reset control is critical to proper operation, consider returning the error code (e.g., PTR_ERR(preset)) to prevent initializing in an invalid state.

Suggested change
preset = devm_reset_control_get(dev, "preset");
if (IS_ERR(preset))
dev_err(dev, "%s: failed to get preset\n", __func__);
else
reset_control_deassert(preset);
return 0;
preset = devm_reset_control_get(dev, "preset");
if (IS_ERR(preset)) {
dev_err(dev, "%s: failed to get preset\n", __func__);
return PTR_ERR(preset);
}
reset_control_deassert(preset);
return 0;

}
return 0;
}
static int sky1_u3phy_init(struct cix_u3phy *u3phy)
Copy link

Choose a reason for hiding this comment

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

issue (complexity): Consider using helper functions to consolidate error cleanup and initialization steps, reducing nested gotos and improving readability in the init function

Consider consolidating the error‐cleanup and initialization steps into helper functions to reduce the nested goto/if structure. For example, you can extract the cleanup work in the init function:

```c
static void cleanup_clocks_and_reset(struct cix_u3phy *u3phy)
{
	clk_disable_unprepare(u3phy->ref_clk);
	clk_disable_unprepare(u3phy->apb_clk);
	reset_control_deassert(u3phy->preset);
	reset_control_deassert(u3phy->reset);
	u3phy->init = false;
}

Then simplify your init function as follows:

static int sky1_u3phy_init(struct cix_u3phy *u3phy)
{
	int ret;

	if (!u3phy->init) {
		reset_control_assert(u3phy->reset);
		reset_control_assert(u3phy->preset);

		ret = clk_prepare_enable(u3phy->apb_clk);
		if (ret) {
			dev_err(u3phy->dev, "Failed to enable apb clock\n");
			goto err;
		}

		ret = clk_prepare_enable(u3phy->ref_clk);
		if (ret) {
			dev_err(u3phy->dev, "Failed to enable ref clock\n");
			goto disable_apb;
		}

		reset_control_deassert(u3phy->preset);
		ret = regmap_multi_reg_write(u3phy->phy_regmap, sky1_u3phy_conf,
					     ARRAY_SIZE(sky1_u3phy_conf));
		if (ret) {
			dev_err(u3phy->dev, "Failed to write the reg sequence\n");
			goto disable_ref;
		}

		u3phy->init = true;
		reset_control_deassert(u3phy->reset);
	}
	u3phy->init_count++;
	return 0;

disable_ref:
	clk_disable_unprepare(u3phy->ref_clk);
disable_apb:
	clk_disable_unprepare(u3phy->apb_clk);
err:
	cleanup_clocks_and_reset(u3phy);
	return ret;
}

This refactoring removes multiple nested goto labels and duplicate cleanup calls while keeping all functionality intact.

@Avenger-285714 Avenger-285714 changed the title [Deepin-Kernel-SIG] [linux 6.6-y] [CIX] Apply suppors from CIXtech ( part of syscon, gpio and phy) [Deepin-Kernel-SIG] [linux 6.6-y] [CIX] Apply syscon, gpio and phy suppors f CIX Mar 5, 2025
@Avenger-285714 Avenger-285714 changed the title [Deepin-Kernel-SIG] [linux 6.6-y] [CIX] Apply syscon, gpio and phy suppors f CIX [Deepin-Kernel-SIG] [linux 6.6-y] [CIX] Apply syscon, gpio and phy suppors for CIX Mar 5, 2025
@Avenger-285714
Copy link
Collaborator Author

I suggest to splict the pull request to many small pull request to review, instead of many commits in one request in the situation :(.

没用。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants