Confirming this on a SpacemiT K3 Pico-ITX (Milk-V Jupiter 2), with some analysis
and a working proof of concept.

Setup
-----
- Ubuntu 26.10, linux-image 7.3.0-9-generic and 7.3.0-10-generic.
- Firmware from ppa:ubuntu-risc-v-team/k3 (flash-k3-firmware.sh): edk2-spacemit
  0.0.9-6, u-boot-spacemit 1.0.5-5, opensbi-spacemit 1.0.5+fix1-5, esos-spacemit
  1.0.5-1, spacemit-ec-firmware 0.0.31.

What happens on the generic 7.3 kernel
--------------------------------------
- No thermal zones (/sys/class/thermal has only a PCIe link-speed cooling
  device), no SoC temperature at all, no cpufreq, no fan control.
- The fan spins fast at power-on, then settles at the EC's boot-time duty and
  never ramps, whatever the load.
- After several hours of sustained full load the system became unstable (a
  kswapd0 oops followed by user-space segfaults at corrupted-looking
  addresses). With no SoC temperature visible I can't prove the cause was
  heat, but the board was hot to the touch.

Why: fan control on this board is host-driven
---------------------------------------------
In SpacemiT's vendor kernel (github.com/spacemit-com/linux-6.18, branch
k3-br-v1.0.y; k3-pico.dtsi / k3.dtsi) the fan is a pwm-fan whose PWM is provided
by the Chrome EC (google,cros-ec-pwm). The EC sits on the SoC's eSPI controller
(spacemit,k3-espi @ 0xcac8c000, EC child google,cros-ec-espi). The fan is driven
by thermal zones fed from the SoC tsensor (spacemit,k3-tsensor @ 0xd4018000),
with trips at 55-75C mapped to fan cooling states (full duty at 75C).

On the Ubuntu 7.3 riscv64 kernel every link of that chain is missing:
1. Config: CONFIG_CHROME_PLATFORMS is not set, so there is no CROS_EC,
   CROS_EC_PROTO or PWM_CROS_EC. (SENSORS_PWM_FAN, THERMAL_OF, THERMAL_HWMON
   and THERMAL_GOV_STEP_WISE are enabled.)
2. Drivers: mainline (checked v7.4-rc2) has no K3 eSPI host driver, no
   cros_ec_espi transport and no K3 tsensor driver. The existing K1 tsensor
   driver has a different register map.
3. Device tree: the upstream k3-pico-itx.dts has no eSPI/EC/fan/tsensor/
   thermal-zone nodes.
4. Since 7.3.0-10 the kernel image carries embedded DTBs (.dtbauto sections).
   The stub selects its built-in k3-pico-itx DTB and ignores a DTB supplied by
   GRUB "devicetree", so a locally fixed DTB is not used either.

Workaround that works today
---------------------------
linux-image-k3-6.18 (6.18.3-10.3) from ppa:ubuntu-risc-v-team/k3 gives 7 thermal
zones, pwm-fan and /dev/cros_ec, and the fan follows load. Two things were
needed on this board with the PPA firmware:
- initcall_blacklist=spacemit_rproc_driver_init. Without it, every boot oopses
  at ~2s: "Oops - load access fault" in spacemit_rproc_probe -> rproc_add ->
  rproc_boot (__memcpy), then "Kernel panic - not syncing: Fatal exception in
  interrupt".
- panic=10 is a good idea. Without it, a panic leaves the board hung with the
  fan at its default duty.
With the vendor kernel, a 10-minute all-core stress-ng run holds the SoC
at ~73C with the fan at cooling state 4 (~3.75k rpm).

Proof of concept on the Ubuntu 7.3.0-10 kernel
----------------------------------------------
To check that the missing pieces are self-contained, I built them as
out-of-tree modules against linux-headers-7.3.0-10-generic, with no kernel
rebuild:
- from upstream v7.3: drivers/platform/chrome/cros_ec.c, cros_ec_proto.c
  (+ cros_ec_trace.c), drivers/pwm/pwm-cros-ec.c
- from the vendor tree (k3-br-v1.0.y): drivers/bus/spacemit-k3-espi.c,
  drivers/platform/chrome/cros_ec_espi.c, drivers/thermal/k3-thermal.c
The only source change needed for 7.3 was in k3-thermal.c: replacing the
tz->devdata access with thermal_zone_device_priv(tz), so the private
thermal_core.h include can go, and adding MODULE_LICENSE. The other drivers
built unchanged.

I appended the vendor nodes to the upstream k3-pico-itx.dtb. Upstream already
defines every clock/reset ID they need, with identical names:
CLK_APMU_ESPI_SCLK_SRC/SCLK/MCLK, RESET_APMU_ESPI_MCLK/SCLK,
CLK_APBC_TSEN/TSEN_BUS, RESET_APBC_TSEN. The nodes were espi + ec + pwm, 
pwm-fan,
tsensor, and all seven thermal zones. k3-thermal fails the whole probe unless
every sensor in tsensor_map has a zone. I booted the bare kernel extracted from
the .linux section, because of the .dtbauto behaviour above.

Result on 7.3.0-10:
  cros_ec_espi 84000000.ec: Chrome EC device registered
This worked with no pinctrl and no EC interrupt, relying on the firmware's pin
setup. All 7 zones registered, and the fan steps 0 -> 1 at the 55C trip under
load and back afterwards. With no zones registered, pwm-fan holds the fan at
full speed, which is a safe failure mode.

Calibration caveat
------------------
The tsensor readings depend on a vref constant. The PPA 6.18 kernel
(k3-br-v1.0.2) hard-codes CALIB_VREF_DEFAULT 0x9A. The current vendor branch
reads a per-chip trim from efuse (soc_rtemp_trim, bank7 @0x0A; fallback
soc_rtemp_trim1, bank0 @0x1C) and otherwise uses 0xD8. Under identical load, the
two constants differ by ~15C (0x9A reads higher). On this board the bank7 trim
is unprogrammed (00 00). So correct readings on mainline also need a K3
efuse/nvmem driver, or at least a conservative default.

Suggestions
-----------
- Enable CHROME_PLATFORMS, CROS_EC, CROS_EC_PROTO, PWM_CROS_EC (=m) in the
  riscv64 config. This costs nothing on other boards and is a prerequisite here.
- Carry or upstream the three K3 drivers (eSPI host, cros_ec_espi, k3 tsensor)
  plus the DT nodes in k3-pico-itx.dts. Since the kernel now selects its own
  embedded DTB, the nodes have to be in the kernel's DT.
- Until then, document on the K3 install page that the generic kernel has no
  fan control and that sustained load can overheat the board,
  and point at linux-k3-6.18 with the rproc workaround.

I'm happy to share the PoC module build (Kbuild + patch) and the DT
fragment.

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2173918

Title:
  Spacemit K3 running hot (missing thermal management)

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/linux-riscv/+bug/2173918/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to