Skip to content

driver-power-meson64-reset.patch: adapt and re-enable for Linux 7.1#9780

Open
EvilOlaf wants to merge 1 commit into
armbian:mainfrom
EvilOlaf:fix-meson64-diver-power-reset
Open

driver-power-meson64-reset.patch: adapt and re-enable for Linux 7.1#9780
EvilOlaf wants to merge 1 commit into
armbian:mainfrom
EvilOlaf:fix-meson64-diver-power-reset

Conversation

@EvilOlaf
Copy link
Copy Markdown
Member

@EvilOlaf EvilOlaf commented May 7, 2026

Description

Fixes #9777
thx @pyavitz

How Has This Been Tested?

  • build meson64

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

Summary by CodeRabbit

  • New Features
    • Added Meson64 platform power/reset driver supporting native restart and power-off functionality for Amlogic G12A, G12B, and SM1 SoCs.
    • Integrated SD card power management during power operations.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 7, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This pull request disables a Meson64 power/reset driver patch that was added to support system restart and power-off on Amlogic G12A, G12B, and SM1 SoCs. The patch is disabled because it fails to compile on kernel 7.1 due to the upstream removal of the linux/of_gpio.h header. The disabled state prevents build failures while the driver implementation awaits refactoring to use the current GPIO API.

Changes

Meson64 Power/Reset Driver Disabling

Layer / File(s) Summary
Build Configuration
patch/kernel/archive/meson64-7.1/driver-power-meson64-reset.patch
Adds CONFIG_POWER_RESET_MESON64 Kconfig option for Meson64 devices and meson64-reboot.o build target when enabled.
Driver Globals & Helpers
patch/kernel/archive/meson64-7.1/driver-power-meson64-reset.patch
Defines GPIO descriptors for SD signals (sd-vqsw, sd-vmmc, sd-vqen), PSCI function IDs for restart/poweroff, GPIO error macros, and SMC call helper via arm_smccc_smc().
Card Reset Function
patch/kernel/archive/meson64-7.1/driver-power-meson64-reset.patch
Implements meson64_card_reset() that conditionally manipulates SD GPIOs via gpiod API with different sequences based on sd_vqen presence.
Restart & Poweroff Handlers
patch/kernel/archive/meson64-7.1/driver-power-meson64-reset.patch
Defines do_meson64_restart() notifier callback and do_meson64_poweroff() function; both invoke card reset then trigger PSCI SMC calls.
Device Tree Binding & Probe
patch/kernel/archive/meson64-7.1/driver-power-meson64-reset.patch
Implements meson64_restart_probe() to read PSCI IDs and GPIOs from device tree, register handlers, and acquire GPIO descriptors; defines meson64,reboot OF match and platform driver registration via device_initcall().
Patch Disabled
patch/kernel/archive/meson64-7.1/driver-power-meson64-reset.patch.disabled
Shows the same 236 lines of driver code being removed from the active build due to compilation failure from missing linux/of_gpio.h header on kernel 7.1.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes


Poem

🐰 A driver drafted with GPIO care,
PSCI calls floating through the air,
But of_gpio.h went away,
So we disable it today.
Awaits refactor, kernel's new way! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adapting and re-enabling the meson64 power reset driver patch for Linux 7.1 compatibility.
Linked Issues check ✅ Passed The pull request addresses issue #9777 by fixing the linux/of_gpio.h compilation error and adapting the driver to the new kernel API for Linux 7.1.
Out of Scope Changes check ✅ Passed All changes are scoped to adapting the meson64 power reset driver for Linux 7.1 compatibility; no unrelated modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added 05 Milestone: Second quarter release size/large PR with 250 lines or more Needs review Seeking for review Hardware Hardware related like kernel, U-Boot, ... Patches Patches related to kernel, U-Boot, ... labels May 7, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
patch/kernel/archive/meson64-7.1/driver-power-meson64-reset.patch (1)

177-180: ⚡ Quick win

Hardcoded magic number 0x82000042 needs a comment or named constant.

The value 0x82000042 is an undocumented bare hex literal with no explanation of what SiP/vendor service it invokes, what argument 1 means, or why it must be called before psci_function_id_poweroff. This will be completely opaque to anyone maintaining the driver later.

🔧 Suggested fix
+/* Amlogic SiP service: set shutdown reason before PSCI SYSTEM_OFF */
+#define MESON64_SIP_SET_POWEROFF_REASON   0x82000042
+#define MESON64_POWEROFF_REASON_NORMAL    1
+
 static void do_meson64_poweroff(void)
 {
     meson64_card_reset();
-    __invoke_psci_fn_smc(0x82000042, 1, 0, 0);
+    meson64_invoke_smc(MESON64_SIP_SET_POWEROFF_REASON,
+                       MESON64_POWEROFF_REASON_NORMAL, 0, 0);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@patch/kernel/archive/meson64-7.1/driver-power-meson64-reset.patch` around
lines 177 - 180, Replace the bare hex literal 0x82000042 with a well-named
constant and add a concise comment explaining the vendor/SiP SMC being invoked,
the meaning of the argument '1', and why it must be called before
__invoke_psci_fn_smc(psci_function_id_poweroff,...); specifically, define a
constant (e.g., MESON_SIP_PRE_POWEROFF_SMC or MESON_SIP_SYSTEM_CONTROL_SMC) and
use that constant in the call to __invoke_psci_fn_smc, and add a one- to
two-line comment above the call describing the SMC function ID, the vendor
providing it, the effect of the '1' parameter, and why it precedes
psci_function_id_poweroff.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@patch/kernel/archive/meson64-7.1/driver-power-meson64-reset.patch`:
- Around line 54-65: The driver source drivers/power/reset/meson64-reboot.c is
missing a MODULE_LICENSE declaration causing the kernel to be tainted; add a
MODULE_LICENSE("GPL") (or another appropriate SPDX-compatible license string)
near the top of the file (after includes or the header comment) so the kernel
recognizes the module license; you can also add optional MODULE_AUTHOR and
MODULE_DESCRIPTION for completeness, but ensure MODULE_LICENSE is present in
meson64-reboot.c.
- Around line 95-108: The functions __invoke_psci_fn_smc and meson64_card_reset
currently have external linkage; make both functions static to limit their
scope: rename __invoke_psci_fn_smc to meson64_invoke_smc (update all local call
sites to use meson64_invoke_smc) and change its signature to static noinline int
meson64_invoke_smc(...), and mark meson64_card_reset as static void
meson64_card_reset(void); ensure you update every reference in this file to the
new meson64_invoke_smc symbol so callers compile after the rename.
- Around line 196-213: Replace the immediate-drive acquisitions with preserving
acquisitions and proper error handling: acquire sd_vqsw_desc, sd_vmmc_desc and
sd_vqen_desc using gpiod_get_optional(&pdev->dev, "name", GPIOD_ASIS) (not
GPIOD_OUT_LOW) and if any gpiod_get_optional returns ERR_PTR(-EPROBE_DEFER)
return that error so the probe defers instead of silently dropping GPIO support;
treat other ERR_PTRs by setting the corresponding descriptor to NULL. Add a
platform remove callback (e.g., meson64_restart_remove) that calls gpiod_put()
for sd_vqen_desc, sd_vmmc_desc, sd_vqsw_desc if non-NULL and clears pm_power_off
if it equals do_meson64_poweroff, and wire that remove into the platform_driver
struct for meson64_restart_driver so resources are released on unload.

---

Nitpick comments:
In `@patch/kernel/archive/meson64-7.1/driver-power-meson64-reset.patch`:
- Around line 177-180: Replace the bare hex literal 0x82000042 with a well-named
constant and add a concise comment explaining the vendor/SiP SMC being invoked,
the meaning of the argument '1', and why it must be called before
__invoke_psci_fn_smc(psci_function_id_poweroff,...); specifically, define a
constant (e.g., MESON_SIP_PRE_POWEROFF_SMC or MESON_SIP_SYSTEM_CONTROL_SMC) and
use that constant in the call to __invoke_psci_fn_smc, and add a one- to
two-line comment above the call describing the SMC function ID, the vendor
providing it, the effect of the '1' parameter, and why it precedes
psci_function_id_poweroff.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6f01d145-dbed-414d-aaea-a8e65bd24faf

📥 Commits

Reviewing files that changed from the base of the PR and between 3ae6351 and db1cac7.

📒 Files selected for processing (2)
  • patch/kernel/archive/meson64-7.1/driver-power-meson64-reset.patch
  • patch/kernel/archive/meson64-7.1/driver-power-meson64-reset.patch.disabled
💤 Files with no reviewable changes (1)
  • patch/kernel/archive/meson64-7.1/driver-power-meson64-reset.patch.disabled

Comment on lines +54 to +65
+/*
+ * drivers/power/reset/meson64-reboot.c
+ *
+ * Copyright (C) 2017 Amlogic, Inc. All rights reserved.
+ * Updated for Linux 7.1
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ */
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Missing MODULE_LICENSE — will taint the kernel.

There is no MODULE_LICENSE declaration anywhere in the driver. Without it the kernel marks itself as tainted with TAINT_PROPRIETARY_MODULE at boot and emits a loud warning. Even built-in drivers (registered via device_initcall) must declare a license.

🔧 Proposed fix
 device_initcall(meson64_restart_init);
+
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("Meson64 reboot/power-off driver");
+MODULE_AUTHOR("Patrick Yavitz <pyavitz@gmail.com>");
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@patch/kernel/archive/meson64-7.1/driver-power-meson64-reset.patch` around
lines 54 - 65, The driver source drivers/power/reset/meson64-reboot.c is missing
a MODULE_LICENSE declaration causing the kernel to be tainted; add a
MODULE_LICENSE("GPL") (or another appropriate SPDX-compatible license string)
near the top of the file (after includes or the header comment) so the kernel
recognizes the module license; you can also add optional MODULE_AUTHOR and
MODULE_DESCRIPTION for completeness, but ensure MODULE_LICENSE is present in
meson64-reboot.c.

Comment on lines +95 to +108
+static noinline int __invoke_psci_fn_smc(u64 function_id, u64 arg0, u64 arg1,
+ u64 arg2)
+{
+ struct arm_smccc_res res;
+
+ arm_smccc_smc((unsigned long)function_id,
+ (unsigned long)arg0,
+ (unsigned long)arg1,
+ (unsigned long)arg2,
+ 0, 0, 0, 0, &res);
+ return res.a0;
+}
+
+void meson64_card_reset(void)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Both __invoke_psci_fn_smc and meson64_card_reset must be static.

Neither function is declared static, so both are exported into the kernel's global symbol namespace. __invoke_psci_fn_smc collides in name with the function in drivers/firmware/psci/psci.c (currently static __always_inline there, so no linker error today — but that could change). meson64_card_reset is called only within this file and has no EXPORT_SYMBOL, so there is no reason for external linkage.

🔧 Proposed fix
-static noinline int __invoke_psci_fn_smc(u64 function_id, u64 arg0, u64 arg1,
+static noinline int meson64_invoke_smc(u64 function_id, u64 arg0, u64 arg1,
                      u64 arg2)
 {
 ...
 }
 
-void meson64_card_reset(void)
+static void meson64_card_reset(void)
 {

Update all call sites of __invoke_psci_fn_smcmeson64_invoke_smc accordingly.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@patch/kernel/archive/meson64-7.1/driver-power-meson64-reset.patch` around
lines 95 - 108, The functions __invoke_psci_fn_smc and meson64_card_reset
currently have external linkage; make both functions static to limit their
scope: rename __invoke_psci_fn_smc to meson64_invoke_smc (update all local call
sites to use meson64_invoke_smc) and change its signature to static noinline int
meson64_invoke_smc(...), and mark meson64_card_reset as static void
meson64_card_reset(void); ensure you update every reference in this file to the
new meson64_invoke_smc symbol so callers compile after the rename.

Comment on lines +196 to +213
+ if (!of_property_read_u32(of_node, "sys_poweroff", &id)) {
+ psci_function_id_poweroff = id;
+ pm_power_off = do_meson64_poweroff;
+ }
+
+ sd_vqsw_desc = gpiod_get(&pdev->dev, "sd-vqsw", GPIOD_OUT_LOW);
+ if (IS_ERR(sd_vqsw_desc))
+ sd_vqsw_desc = NULL;
+
+ sd_vmmc_desc = gpiod_get(&pdev->dev, "sd-vmmc", GPIOD_OUT_LOW);
+ if (IS_ERR(sd_vmmc_desc))
+ sd_vmmc_desc = NULL;
+
+ sd_vqen_desc = gpiod_get(&pdev->dev, "sd-vqen", GPIOD_OUT_LOW);
+ if (IS_ERR(sd_vqen_desc))
+ sd_vqen_desc = NULL;
+
+ return 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | 🏗️ Heavy lift

GPIOD_OUT_LOW at probe drives SD power GPIOs low immediately, corrupting SD state.

gpiod_get(&pdev->dev, "sd-vmmc", GPIOD_OUT_LOW) and the other GPIOD_OUT_LOW acquisitions immediately configure and assert the GPIOs as driven-low at driver probe time. sd-vmmc is an SD card power rail and sd-vqsw is a voltage switch — pulling them low during normal operation will cut SD card power and break any mounted SD filesystem before the first reboot.

The GPIOs should be acquired with GPIOD_ASIS (preserve firmware-set state) and only toggled during the actual reset/poweroff path.

Additionally:

  • gpiod_get (not gpiod_get_optional) is used, then IS_ERR results are silently suppressed. This swallows -EPROBE_DEFER: if the GPIO controller has not yet probed, the driver silently continues with no GPIO support instead of deferring.
  • There is no platform_driver.remove callback, so gpiod_put is never called for any acquired GPIO, and pm_power_off is set but never cleared on unload/remove.
🔧 Proposed fix
-    sd_vqsw_desc = gpiod_get(&pdev->dev, "sd-vqsw", GPIOD_OUT_LOW);
-    if (IS_ERR(sd_vqsw_desc))
-        sd_vqsw_desc = NULL;
-
-    sd_vmmc_desc = gpiod_get(&pdev->dev, "sd-vmmc", GPIOD_OUT_LOW);
-    if (IS_ERR(sd_vmmc_desc))
-        sd_vmmc_desc = NULL;
-
-    sd_vqen_desc = gpiod_get(&pdev->dev, "sd-vqen", GPIOD_OUT_LOW);
-    if (IS_ERR(sd_vqen_desc))
-        sd_vqen_desc = NULL;
+    sd_vqsw_desc = gpiod_get_optional(&pdev->dev, "sd-vqsw", GPIOD_ASIS);
+    if (IS_ERR(sd_vqsw_desc))
+        return PTR_ERR(sd_vqsw_desc);
+
+    sd_vmmc_desc = gpiod_get_optional(&pdev->dev, "sd-vmmc", GPIOD_ASIS);
+    if (IS_ERR(sd_vmmc_desc)) {
+        ret = PTR_ERR(sd_vmmc_desc);
+        goto err_put_vqsw;
+    }
+
+    sd_vqen_desc = gpiod_get_optional(&pdev->dev, "sd-vqen", GPIOD_ASIS);
+    if (IS_ERR(sd_vqen_desc)) {
+        ret = PTR_ERR(sd_vqen_desc);
+        goto err_put_vmmc;
+    }
+
     return 0;
+
+err_put_vmmc:
+    gpiod_put(sd_vmmc_desc);
+err_put_vqsw:
+    gpiod_put(sd_vqsw_desc);
+    return ret;

Add a remove callback to meson64_restart_driver:

static int meson64_restart_remove(struct platform_device *pdev)
{
    if (sd_vqen_desc)  gpiod_put(sd_vqen_desc);
    if (sd_vmmc_desc)  gpiod_put(sd_vmmc_desc);
    if (sd_vqsw_desc)  gpiod_put(sd_vqsw_desc);
    if (pm_power_off == do_meson64_poweroff)
        pm_power_off = NULL;
    return 0;
}

And wire it in:

 static struct platform_driver meson64_restart_driver = {
     .probe  = meson64_restart_probe,
+    .remove = meson64_restart_remove,
     .driver = {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@patch/kernel/archive/meson64-7.1/driver-power-meson64-reset.patch` around
lines 196 - 213, Replace the immediate-drive acquisitions with preserving
acquisitions and proper error handling: acquire sd_vqsw_desc, sd_vmmc_desc and
sd_vqen_desc using gpiod_get_optional(&pdev->dev, "name", GPIOD_ASIS) (not
GPIOD_OUT_LOW) and if any gpiod_get_optional returns ERR_PTR(-EPROBE_DEFER)
return that error so the probe defers instead of silently dropping GPIO support;
treat other ERR_PTRs by setting the corresponding descriptor to NULL. Add a
platform remove callback (e.g., meson64_restart_remove) that calls gpiod_put()
for sd_vqen_desc, sd_vmmc_desc, sd_vqsw_desc if non-NULL and clears pm_power_off
if it equals do_meson64_poweroff, and wire that remove into the platform_driver
struct for meson64_restart_driver so resources are released on unload.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

05 Milestone: Second quarter release Hardware Hardware related like kernel, U-Boot, ... Needs review Seeking for review Patches Patches related to kernel, U-Boot, ... size/large PR with 250 lines or more

Development

Successfully merging this pull request may close these issues.

meson64: driver-power-meson64-reset.patch breaks compilation on kernel 7.1

1 participant