Skip to content

[Deepin-Kernel-SIG] [linux 6.12-y] [Upstream] pwm: Add Loongson PWM controller support#1718

Open
opsiff wants to merge 2 commits into
deepin-community:linux-6.12.yfrom
opsiff:linux-6.12.y-2026-05-15
Open

[Deepin-Kernel-SIG] [linux 6.12-y] [Upstream] pwm: Add Loongson PWM controller support#1718
opsiff wants to merge 2 commits into
deepin-community:linux-6.12.yfrom
opsiff:linux-6.12.y-2026-05-15

Conversation

@opsiff
Copy link
Copy Markdown
Member

@opsiff opsiff commented May 15, 2026

Summary by Sourcery

Add support for the Loongson PWM controller and integrate its driver into the LoongArch desktop configuration.

New Features:

  • Introduce a Loongson-specific PWM driver with DT and ACPI bindings for the LS7A PWM controller.

Enhancements:

  • Wire the new Loongson PWM driver into the PWM build system and LoongArch desktop defconfig.

AaronDot and others added 2 commits May 15, 2026 09:53
This commit adds a generic PWM framework driver for the PWM controller
found on Loongson family chips.

Acked-by: Huacai Chen <chenhuacai@loongson.cn>
Co-developed-by: Juxin Gao <gaojuxin@loongson.cn>
Signed-off-by: Juxin Gao <gaojuxin@loongson.cn>
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
Link: https://lore.kernel.org/r/76050a903a8015422fb9261ad88c7d9cc2edbbd8.1743403075.git.zhoubinbin@loongson.cn
Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>
(cherry picked from commit 2b62c89)
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
deepin inclusion
category: bugfix

users report LL300 Laptop works failed with new driver and kernel,
work around by builtin the pwm driver until loongson find a proper way.

Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
(cherry picked from commit eef9634)
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 15, 2026

Reviewer's Guide

Adds a new Loongson PWM controller driver and wires it into the PWM subsystem, including build, config, and power-management support for LoongArch/ACPI/DT platforms.

File-Level Changes

Change Details Files
Introduce a Loongson PWM controller driver and hook it into the kernel PWM subsystem.
  • Add pwm-loongson.c implementing a single-channel pwm_chip with .apply and .get_state based on Loongson PWM registers and control bits
  • Implement clock handling with optional ACPI fallback frequency, including overflow guard on clk_rate and suspend/resume PM callbacks that require PWM to be disabled before suspend
  • Register the driver as a platform_driver with OF and ACPI match tables and module metadata
  • Wire the new driver into the PWM Makefile, Kconfig, MAINTAINERS, and the LoongArch desktop defconfig to allow building and selection of the driver
drivers/pwm/pwm-loongson.c
drivers/pwm/Makefile
drivers/pwm/Kconfig
MAINTAINERS
arch/loongarch/configs/deepin_loongarch_desktop_defconfig

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!

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

@deepin-ci-robot deepin-ci-robot requested a review from huangbibo May 15, 2026 01:57
@deepin-ci-robot
Copy link
Copy Markdown

[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 opsiff. For more information see the Code Review Process.

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

Details 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
Copy Markdown

@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 - I've left some high level feedback:

  • In pwm_loongson_probe(), the error path after devm_clk_rate_exclusive_get() uses PTR_ERR(ddata->clk) instead of the local ret value, which will report an incorrect error code if clk retrieval succeeded but exclusive rate failed.
  • pwm_loongson_suspend()/resume() unconditionally call clk_disable_unprepare()/clk_prepare_enable() on ddata->clk even though the clock is optional and may be NULL (ACPI/default-frequency case); guard these calls with a ddata->clk check.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In pwm_loongson_probe(), the error path after devm_clk_rate_exclusive_get() uses PTR_ERR(ddata->clk) instead of the local ret value, which will report an incorrect error code if clk retrieval succeeded but exclusive rate failed.
- pwm_loongson_suspend()/resume() unconditionally call clk_disable_unprepare()/clk_prepare_enable() on ddata->clk even though the clock is optional and may be NULL (ACPI/default-frequency case); guard these calls with a ddata->clk check.

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.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a new PWM controller driver for Loongson (LS7A/Loongson family) and hooks it into the PWM subsystem build and the Deepin LoongArch desktop defconfig.

Changes:

  • Add a new pwm-loongson platform driver with DT + ACPI match tables.
  • Wire the driver into drivers/pwm/Makefile and add a CONFIG_PWM_LOONGSON Kconfig option.
  • Enable CONFIG_PWM_LOONGSON=y in deepin_loongarch_desktop_defconfig.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
MAINTAINERS Adds a maintainer entry and file patterns for the new Loongson PWM driver/binding.
drivers/pwm/pwm-loongson.c Introduces the Loongson PWM controller driver implementation.
drivers/pwm/Makefile Adds build rule for pwm-loongson.o under CONFIG_PWM_LOONGSON.
drivers/pwm/Kconfig Adds CONFIG_PWM_LOONGSON Kconfig entry.
arch/loongarch/configs/deepin_loongarch_desktop_defconfig Enables Loongson PWM driver in the Deepin LoongArch desktop configuration.
Comments suppressed due to low confidence (1)

drivers/pwm/pwm-loongson.c:133

  • Same truncation/clamping issue as duty_cycle: the u64 result of mul_u64_u64_div_u64() is assigned to a u32 before comparing against U32_MAX, so the clamp won't work for large period_ns values. Use a u64 temporary and only cast to u32 after clamping.
	/* period = period_ns * ddata->clk_rate / NSEC_PER_SEC */
	period = mul_u64_u64_div_u64(period_ns, ddata->clk_rate, NSEC_PER_SEC);
	if (period > U32_MAX)
		period = U32_MAX;


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +122 to +132
struct pwm_loongson_ddata *ddata = to_pwm_loongson_ddata(chip);

/* duty = duty_ns * ddata->clk_rate / NSEC_PER_SEC */
duty = mul_u64_u64_div_u64(duty_ns, ddata->clk_rate, NSEC_PER_SEC);
if (duty > U32_MAX)
duty = U32_MAX;

/* period = period_ns * ddata->clk_rate / NSEC_PER_SEC */
period = mul_u64_u64_div_u64(period_ns, ddata->clk_rate, NSEC_PER_SEC);
if (period > U32_MAX)
period = U32_MAX;
Comment on lines +79 to +83
u16 val;
struct pwm_loongson_ddata *ddata = to_pwm_loongson_ddata(chip);

val = pwm_loongson_readl(ddata, LOONGSON_PWM_REG_CTRL);

if (ddata->clk) {
ret = devm_clk_rate_exclusive_get(dev, ddata->clk);
if (ret)
return dev_err_probe(dev, PTR_ERR(ddata->clk),
Comment thread MAINTAINERS
Comment on lines +13384 to +13389
LOONGSON PWM DRIVER
M: Binbin Zhou <zhoubinbin@loongson.cn>
L: linux-pwm@vger.kernel.org
S: Maintained
F: Documentation/devicetree/bindings/pwm/loongson,ls7a-pwm.yaml
F: drivers/pwm/pwm-loongson.c
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.

4 participants