Commit Graph
57 Commits
Author SHA1 Message Date
maoxiaochuan 3004655ce5 loongarch: fix fpu panic bug
Changelog: 修复fpu的panic bug
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2026-08-24 14:52:18 +08:00
maoxiaochuan 17d323e4e2 watchdog: loongson2: fix .remove callback return type mismatch
Since Linux 6.11 (commit 0ed03dd1f63f), the platform_driver .remove
callback returns void instead of int. ls2x_wdt_remove still returns int,
triggering an -Werror=incompatible-pointer-types build error at the
.remove = ls2x_wdt_remove assignment.

Change ls2x_wdt_remove's return type to void and drop the return 0.
2026-08-24 12:13:23 +08:00
maoxiaochuan 3b5138a7fb loongarch:update CPUCFG2 define
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2026-08-24 10:58:16 +08:00
maoxiaochuan 54d39940be LoongArch: dts: loongson-2k1000: Sync from linux 7.0
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2026-08-24 10:58:16 +08:00
maoxiaochuan 0d305ad520 LoongArch: Add HOTPLUG_SMT implementation
For benchmarking or debugging purpose, we usually want to control SMT
via boot parameter and sysfs knobs. So add HOTPLUG_SMT implementation.

1. Boot parameters:

nosmt:		Disable SMT, can be enabled via sysfs knobs.
nosmt=force:	Disable SMT, cannot be enabled via sysfs knobs.

2. Runtime sysfs controls:

Write "on", "off", "forceoff" or the number of SMT threads (1, 2, ...)
to /sys/devices/system/cpu/smt/control.

Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2026-08-24 10:58:15 +08:00
maoxiaochuan 30535140db LoongArch: Wire up memfd_secret system call
LoongArch supports ARCH_HAS_SET_DIRECT_MAP, therefore wire up the
memfd_secret system call, which just depends on it.

Acked-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Acked-by: David Hildenbrand (Red Hat) <david@kernel.org>
Signed-off-by: Lain "Fearyncess" Yang <fearyncess@aosc.io>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2026-08-24 10:58:15 +08:00
maoxiaochuan 9a07c6c3b7 net: stmmac: dwmac-loongson: Set clk_csr_i to 100-150MHz
Current clk_csr_i setting of Loongson STMMAC (including LS7A1000/2000
and LS2K1000/2000/3000) are copy & paste from other drivers. In fact,
Loongson STMMAC use 125MHz clocks and need 62 freq division to within
2.5MHz, meeting most PHY MDC requirement. So fix by setting clk_csr_i
to 100-150MHz, otherwise some PHYs may link fail.

Cc: stable@vger.kernel.org
Fixes: 30bba69d7db40e7 ("stmmac: pci: Add dwmac support for Loongson")
Signed-off-by: Hongliang Wang <wanghongliang@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Link: https://patch.msgid.link/20260203062901.2158236-1-chenhuacai@loongson.cn
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2026-08-24 10:58:15 +08:00
maoxiaochuan be7f956fec rtc: loongson: Add Loongson-2K0300 support
The Loongson-2K0300's rtc hardware design is similar to that of the
Loongson-1B, but it does not support the alarm feature.

Introduce `LOONGSON_RTC_ALARM_WORKAROUND`, which indicates a chip that
does not support the alarm feature, and rewrite the related logic in
`loongson_rtc_alarm_setting()`.

Reviewed-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
Link: https://patch.msgid.link/abff68dda2fe6a6601a9e58b31e278d941297fce.1768616276.git.zhoubinbin@loongson.cn
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2026-08-24 10:58:14 +08:00
maoxiaochuan 55a9dbec94 dt-bindings: clock: loongson2: Add Loongson-2K0300 compatible
Document the clock controller shipped in Loongson-2K0300 SoC, which
generates various clock signals for SoC peripherals. Differing from
previous generations of SoCs, LS2K0300 requires a 120MHz external clock
input.

Signed-off-by: Yao Zi <ziyao@disroot.org>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: Yanteng Si <siyanteng@cqsoftware.com.cn>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
2026-02-04 19:14:59 +08:00
maoxiaochuan 99a10baa16 loongson_2k300_defconfig:Enable bh1750 and aht20 2026-02-04 19:14:59 +08:00
maoxiaochuan 5318de7663 LoongArch: dts: Describe PCI sideband IRQ through interrupt-extended
SoC integrated peripherals on LS2K1000 and LS2K2000 could be discovered
as PCI devices, but require sideband interrupts to function, which are
previously described by interrupts and interrupt-parent properties.

However, pci/pci-device.yaml allows interrupts property to only specify
PCI INTx interrupts, not sideband ones. Convert these devices to use
interrupt-extended property, which describes sideband interrupts used by
PCI devices since dt-schema commit e6ea659d2baa ("schemas: pci-device:
Allow interrupts-extended for sideband interrupts"), eliminating
dtbs_check warnings.

Cc: stable@vger.kernel.org
Fixes: 30a5532a3206 ("LoongArch: dts: DeviceTree for Loongson-2K1000")
Signed-off-by: Yao Zi <me@ziyao.cc>
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2026-02-04 16:39:59 +08:00
maoxiaochuan fe414e400e serial: 8250: Add Loongson uart driver support
Add the driver for on-chip UART used on Loongson family chips.

The hardware is similar to NS16550A, but there are the following
differences:
 - Some chips (such as Loongson-2K2000) have added a fractional division
   register to obtain the required baud rate accurately, so the
   {get,set}_divisor callback is overridden.
 - Due to hardware defects, quirk handling is required for
   UART_MCR/UART_MSR.

Co-developed-by: Haowei Zheng <zhenghaowei@loongson.cn>
Signed-off-by: Haowei Zheng <zhenghaowei@loongson.cn>
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
Reviewed-by: Huacai Chen <chenhuacai@loongson.cn>
Link: https://patch.msgid.link/2c2a01a276b9250efea0c7aa190efecdfd6fdf5a.1760166651.git.zhoubinbin@loongson.cn
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2026-02-04 16:39:56 +08:00
maoxiaochuan 139ba8bfee watchdog: loongson1: Add Loongson-2k0300 watchdog support
According to the manual, the Loongson-2K0300 watchdog is similar to the
Loongson-1, except for some register offsets and inconsistent register
bit definitions. Separate definitions via driver_data suffice.

Co-developed-by: Xiaochuang Mao <maoxiaochuan@loongson.cn>
Signed-off-by: Xiaochuang Mao <maoxiaochuan@loongson.cn>
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
Reviewed-by: Huacai Chen <chenhuacai@loongson.cn>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2026-02-04 16:39:55 +08:00
maoxiaochuan 1d096282e3 dt-bindings: mtd: loongson,ls1b-nand-controller: Document the Loongson-2K0500 NAND controller
Add new compatible for the Loongson-2K NAND controller used for
Loongson-2K0500 SoC.

Acked-by: Rob Herring (Arm) <robh@kernel.org>
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2026-02-04 16:39:23 +08:00
maoxiaochuan 5de7f99249 mtd: rawnand: loongson1: Rename the prefix from ls1x to loongson
I am going to introduce the NAND controllers of the Loongson-2K series
CPUs, which are similar to Loongson-1.

As preparation, rename all prefixes from Loongson1-specific to
Loongson-generic.

No functional change intended.

Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2026-02-04 16:39:22 +08:00
maoxiaochuan 4f26a03386 mtd: rawnand: Add Loongson-1 NAND Controller Driver
Add NAND controller driver for Loongson-1 SoCs.

Signed-off-by: Keguang Zhang <keguang.zhang@gmail.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2026-02-04 16:39:22 +08:00
maoxiaochuan dc9018a7d7 tpm: Add a driver for Loongson TPM device
Loongson Security Engine supports random number generation, hash,
symmetric encryption and asymmetric encryption. Based on these
encryption functions, TPM2 have been implemented in the Loongson
Security Engine firmware. This driver is responsible for copying data
into the memory visible to the firmware and receiving data from the
firmware.

Co-developed-by: Yinggang Gu <guyinggang@loongson.cn>
Signed-off-by: Yinggang Gu <guyinggang@loongson.cn>
Signed-off-by: Qunqin Zhao <zhaoqunqin@loongson.cn>
Reviewed-by: Huacai Chen <chenhuacai@loongson.cn>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Link: https://lore.kernel.org/r/20250705072045.1067-4-zhaoqunqin@loongson.cn
Signed-off-by: Lee Jones <lee@kernel.org>
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2026-02-04 16:39:20 +08:00
maoxiaochuan e3bb43ff99 mfd: Add support for Loongson Security Engine chip controller
Loongson Security Engine chip supports RNG, SM2, SM3 and SM4 accelerator
engines. This is the base driver for other specific engine drivers.

Co-developed-by: Yinggang Gu <guyinggang@loongson.cn>
Signed-off-by: Yinggang Gu <guyinggang@loongson.cn>
Signed-off-by: Qunqin Zhao <zhaoqunqin@loongson.cn>
Reviewed-by: Huacai Chen <chenhuacai@loongson.cn>
Link: https://lore.kernel.org/r/20250705072045.1067-2-zhaoqunqin@loongson.cn
Signed-off-by: Lee Jones <lee@kernel.org>
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2026-02-04 16:39:19 +08:00
maoxiaochuan d1e8fab20f ls2k300_Pi:dts:Add node for aht20
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2026-02-04 16:38:56 +08:00
maoxiaochuan 123845389c iio:humidity:Add aht20 support
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2026-02-04 16:38:56 +08:00
maoxiaochuan 28d1952150 ls2k300_pi:dts:update pin configuration
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2026-02-04 16:38:55 +08:00
maoxiaochuan 61f607d374 LoongArch: Use __pmd()/__pte() for swap entry conversions
The __pmd() and __pte() helper macros provide the correct initialization
syntax and abstraction for the pmd_t and pte_t types.

Use __pmd() to fix follow warning about __swp_entry_to_pmd() with gcc-15
under specific configs [1] :

  In file included from ./include/linux/pgtable.h:6,
                   from ./include/linux/mm.h:31,
                   from ./include/linux/pagemap.h:8,
                   from arch/loongarch/mm/init.c:14:
  ./include/linux/swapops.h: In function ‘swp_entry_to_pmd’:
  ./arch/loongarch/include/asm/pgtable.h:302:34: error: missing braces around initializer [-Werror=missing-braces]
    302 | #define __swp_entry_to_pmd(x)   ((pmd_t) { (x).val | _PAGE_HUGE })
        |                                  ^
  ./include/linux/swapops.h:559:16: note: in expansion of macro ‘__swp_entry_to_pmd’
    559 |         return __swp_entry_to_pmd(arch_entry);
        |                ^~~~~~~~~~~~~~~~~~
  cc1: all warnings being treated as errors

Also update __swp_entry_to_pte() to use __pte() for consistency.

[1]. https://download.01.org/0day-ci/archive/20251119/202511190316.luI90kAo-lkp@intel.com/config

Cc: stable@vger.kernel.org
Signed-off-by: Yuli Wang <wangyl5933@chinaunicom.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2026-02-04 16:38:20 +08:00
maoxiaochuan da3522f798 loongson_2k300_defconfig:Update defconfig for enable usbnet and usb_serial
4g module use usb or serial to transfer data

Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2026-02-04 16:38:19 +08:00
maoxiaochuan eb8a62958a Add EC200U_CN, EC200A_CN, EC200N_CN 4g module support.
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2026-02-04 16:38:19 +08:00
maoxiaochuan 75187a098c LoongArch: Consolidate CPU names in /proc/cpuinfo
Some processors have no IOCSR.VENDOR and IOCSR.CPUNAME, some processors
have these registers but there is no valid information.

Consolidate CPU names in /proc/cpuinfo:
1. Add "PRID" to display the PRID & Core-Name;
2. Let "Model Name" display "Unknown" if no valid name.

Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2025-11-24 15:13:11 +08:00
maoxiaochuan ed8ea729ee gpio:fix crash when irq map fail
[    1.112617] Warning: unable to open an initial console.
[    1.128648] Waiting for root device /dev/mmcblk0p1...
[   11.439784] gpio gpiochip0: Static allocation of GPIO base is deprecated, use dynamic allocation.
[   11.449431] gpio-lsirq 16104000.gpio: IRQ Pin Map fail
[   11.459605] gpio-lsirq 16104000.gpio: probe with driver gpio-lsirq failed with error -1
[   11.467761] Unhandled kernel unaligned access[#1]:
[   11.472606] CPU: 0 UID: 0 PID: 79 Comm: kworker/u4:2 Not tainted 6.12.0.lsgd #1
[   11.479994] Hardware name: Loongson LS2K300/LS2K300-PAI, BIOS 2022.04-v2.0.0-00572-gfaaca55a 04/01/2022
[   11.489483] Workqueue: events_unbound deferred_probe_work_func
[   11.495394] pc 90000000008683a8 ra 9000000000868398 tp 9000000006954000 sp 9000000006957b60
[   11.503832] a0 9000000001860338 a1 90000000066a0230 a2 9000000006957b98 a3 0000000000000004
[   11.512267] a4 00000000000000b4 a5 0000000000000040 a6 0000000000000000 a7 9000000006018410
[   11.520703] t0 0000000000000122 t1 9000000001860240 t2 90000000068b2f40 t3 0000000000000000
[   11.529137] t4 900000000618a658 t5 900000000618a658 t6 90000000009f0eb4 t7 90000000009f1154
[   11.537571] t8 0000000000000000 u0 006f6970672e3030 s9 90000000066ce500 s0 9000000006c1d440
[   11.546005] s1 9000000006c1e400 s2 9000000001860240 s3 9000000001860338 s4 0000000000000003
[   11.554440] s5 90000000013ea000 s6 90000000066ce4c0 s7 90000000013f2000 s8 90000000060e5e80
[   11.562874]    ra: 9000000000868398 gpiochip_remove+0x44/0xd4
[   11.568693]   ERA: 90000000008683a8 gpiochip_remove+0x54/0xd4
[   11.574504]  CRMD: 000000b0 (PLV0 -IE -DA +PG DACF=CC DACM=CC -WE)
[   11.580774]  PRMD: 00000004 (PPLV0 +PIE -PWE)
[   11.585182]  EUEN: 00000000 (-FPE -SXE -ASXE -BTE)
[   11.590033]  ECFG: 00071c1d (LIE=0,2-4,10-12 VS=7)
[   11.594882] ESTAT: 00090000 [ALE] (IS= ECode=9 EsubCode=0)
[   11.600428]  BADV: 0000000000000122
[   11.603946]  PRID: 0014a030 (Loongson-64bit, )
[   11.608431] Modules linked in:
[   11.611512] Process kworker/u4:2 (pid: 79, threadinfo=(____ptrval____), task=(____ptrval____))
[   11.620213] Stack : 9000000006196ca0 9000000006957b98 900000000618a410 90000000066d7b40
[   11.628313]         90000000066a0200 90000000009f276c 90000000013ea000 90000000066d7420
[   11.636412]         90000000066a0200 db47c55fde642c00 90000000013ea000 90000000009ec89c
[   11.644510]         90000000013ea000 0000000000000000 9000000001860e00 0000000000000001
[   11.652608]         900000000618a410 90000000009ebae8 900000000618a410 90000000009ec3e8
[   11.660707]         900000000618a410 0000000000000003 900000000618a410 9000000001860e00
[   11.668805]         900000000618a410 90000000009ec63c 900000000618a410 9000000001860e00
[   11.676904]         9000000001c91e18 90000000009ec7fc 9000000001860e00 900000000618a410
[   11.685002]         9000000006957d18 9000000001860e00 0000000000000001 90000000009ec968
[   11.693100]         90000000013ea000 9000000006957d18 900000000608f800 9000000006957cb8
[   11.701199]         ...
[   11.703668] Call Trace:
[   11.703675] [<90000000008683a8>] gpiochip_remove+0x54/0xd4
[   11.711688] [<90000000009f2768>] devres_release_all+0xb4/0x12c
[   11.717594] [<90000000009ebae4>] device_unbind_cleanup+0x10/0x5c
[   11.723667] [<90000000009ec3e4>] really_probe+0x1e0/0x3ac
[   11.729126] [<90000000009ec638>] __driver_probe_device+0x88/0x160
[   11.735285] [<90000000009ec7f8>] driver_probe_device+0x34/0xd8
[   11.741181] [<90000000009ec964>] __device_attach_driver+0xc8/0x178
[   11.747430] [<90000000009e9d7c>] bus_for_each_drv+0x8c/0xf0
[   11.753073] [<90000000009ecda8>] __device_attach+0xa4/0x1b4
[   11.758705] [<90000000009eaf60>] bus_probe_device+0xa8/0xd0
[   11.764339] [<90000000009eb5f4>] deferred_probe_work_func+0x9c/0xf0
[   11.770674] [<9000000000259084>] process_one_work+0x178/0x2f4
[   11.776492] [<9000000000259fa0>] worker_thread+0x390/0x4c8
[   11.782041] [<9000000000261028>] kthread+0x104/0x114
[   11.787066] [<9000000000f1c764>] ret_from_kernel_thread+0x28/0x48
[   11.793229] [<9000000000221024>] ret_from_kernel_thread_asm+0xc/0x88
[   11.799654]
[   11.801153] Code: 28cd630c  00150344  29c021ac <2700018d> 0284880c  29cd630c  5789441a  02c04324  56f96fe8
[   11.811031]
[   11.812564] ---[ end trace 0000000000000000 ]---
[  119.451577] random: crng init done
2025-11-20 16:56:46 +08:00
maoxiaochuan f9d47373c9 LoongArch: Consolidate max_pfn & max_low_pfn calculation
Now there 5 places which calculate max_pfn & max_low_pfn:
1. in fdt_setup() for FDT systems;
2. in memblock_init() for ACPI systems;
3. in init_numa_memory() for NUMA systems;
4. in arch_mem_init() to recalculate for "mem=" cmdline;
5. in paging_init() to recalculate for NUMA systems.

Since memblock_init() is called both for ACPI and FDT systems, move the
calculation out of the for_each_efi_memory_desc() loop can eliminate the
first case. The last case is very questionable (may be derived from the
MIPS/Loongson code) and breaks the "mem=" cmdline, so should be removed.
And then the NUMA version of paging_init() can be also eliminated.

After consolidation there are 3 places of calculation:
1. in memblock_init() for both ACPI and FDT systems;
2. in init_numa_memory() to recalculate for NUMA systems;
3. in arch_mem_init() to recalculate for the "mem=" cmdline.

For all cases the calculation is:
max_pfn = PFN_DOWN(memblock_end_of_DRAM());
max_low_pfn = min(PFN_DOWN(HIGHMEM_START), max_pfn);

Cc: stable@vger.kernel.org
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2025-11-20 16:55:52 +08:00
maoxiaochuan 8738a252e0 LoongArch: Consolidate early_ioremap()/ioremap_prot()
1. Use phys_addr_t instead of u64, which can work for both 32/64 bits.
2. Check whether the input physical address is above TO_PHYS_MASK (and
   return NULL if yes) for the DMW version.

Note: In theory early_ioremap() also need the TO_PHYS_MASK checking, but
the UEFI BIOS pass some DMW virtual addresses.

Cc: stable@vger.kernel.org
Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2025-11-20 16:55:50 +08:00
maoxiaochuan 2f99cde742 rust: Add -fno-isolate-erroneous-paths-dereference to bindgen_skip_c_flags
It's used to work around an objtool issue since commit abb2a5572264
("LoongArch: Add cflag -fno-isolate-erroneous-paths-dereference"), but
it's then passed to bindgen and cause an error because Clang does not
have this option.

Fixes: abb2a5572264 ("LoongArch: Add cflag -fno-isolate-erroneous-paths-dereference")
Acked-by: Miguel Ojeda <ojeda@kernel.org>
Tested-by: Mingcong Bai <jeffbai@aosc.io>
Signed-off-by: Xi Ruoyao <xry111@xry111.site>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2025-11-20 16:55:49 +08:00
maoxiaochuan fa7dc59488 LoongArch: Try VMA lock-based page fault handling first
Attempt VMA lock-based page fault handling first, and fall back to the
existing mmap_lock-based handling if that fails.

The "ebizzy -mTRp" test on Loongson-3A6000 shows that PER_VMA_LOCK can
improve the benchmark by about 17.9% (97837.7 to 115430.8).

This is the LoongArch variant of "x86/mm: try VMA lock-based page fault
handling first".

Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2025-11-10 08:55:44 +08:00
maoxiaochuan e2347c1e4a LoongArch: Add cflag -fno-isolate-erroneous-paths-dereference
Currently, when compiling with GCC, there is no "break 7" instruction
for zero division due to using the option -mno-check-zero-division, but
the compiler still generates "break 0" instruction for zero division.

Here is a simple example:

  $ cat test.c
  int div(int a)
  {
      return a / 0;
  }
  $ gcc -O2 -S test.c -o test.s

GCC generates "break 0" on LoongArch and "ud2" on x86, objtool decodes
"ud2" as INSN_BUG for x86, so decode "break 0" as INSN_BUG can fix the
objtool warnings for LoongArch, but this is not the intention.

When decoding "break 0" as INSN_TRAP in the previous commit, the aim is
to handle "break 0" as a trap. The generated "break 0" for zero division
by GCC is not proper, it should generate a break instruction with proper
bug type, so add the GCC option -fno-isolate-erroneous-paths-dereference
to avoid generating the unexpected "break 0" instruction for now.

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/r/202509200413.7uihAxJ5-lkp@intel.com/
Fixes: baad7830ee9a ("objtool/LoongArch: Mark types based on break immediate code")
Suggested-by: WANG Rui <wangrui@loongson.cn>
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2025-11-10 08:55:42 +08:00
maoxiaochuan e5c614adbe LoongArch: Handle jump tables options for RUST
When compiling with LLVM and CONFIG_RUST is set, there exist objtool
warnings in rust/core.o and rust/kernel.o, like this:

    rust/core.o: warning: objtool:
_RNvXs1_NtNtCs5QSdWC790r4_4core5ascii10ascii_charNtB5_9AsciiCharNtNtB9_3fmt5Debug3fmt+0x54:
sibling call from callable instruction with modified stack frame

For this special case, the related object file shows that there is no
generated relocation section '.rela.discard.tablejump_annotate' for the
table jump instruction jirl, thus objtool can not know that what is the
actual destination address.

If rustc has the option "-Cllvm-args=--loongarch-annotate-tablejump",
pass the option to enable jump tables for objtool, otherwise it should
pass "-Zno-jump-tables" to keep compatibility with older rustc.

How to test:

  $ rustup component add rust-src
  $ make LLVM=1 rustavailable
  $ make ARCH=loongarch LLVM=1 clean defconfig
  $ scripts/config -d MODVERSIONS \
    -e RUST -e SAMPLES -e SAMPLES_RUST \
    -e SAMPLE_RUST_CONFIGFS -e SAMPLE_RUST_MINIMAL \
    -e SAMPLE_RUST_MISC_DEVICE -e SAMPLE_RUST_PRINT \
    -e SAMPLE_RUST_DMA -e SAMPLE_RUST_DRIVER_PCI \
    -e SAMPLE_RUST_DRIVER_PLATFORM -e SAMPLE_RUST_DRIVER_FAUX \
    -e SAMPLE_RUST_DRIVER_AUXILIARY -e SAMPLE_RUST_HOSTPROGS
  $ make ARCH=loongarch LLVM=1 olddefconfig all

Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2025-11-10 08:55:40 +08:00
maoxiaochuan 940713b0a5 LoongArch: Pass annotate-tablejump option if LTO is enabled
When compiling with LLVM and CONFIG_LTO_CLANG is set, there exist many
objtool warnings "sibling call from callable instruction with modified
stack frame".

For this special case, the related object file shows that there is no
generated relocation section '.rela.discard.tablejump_annotate' for the
table jump instruction jirl, thus objtool can not know that what is the
actual destination address.

It needs to do something on the LLVM side to make sure that there is the
relocation section '.rela.discard.tablejump_annotate' if LTO is enabled,
but in order to maintain compatibility for the current LLVM compiler,
this can be done in the kernel Makefile for now. Ensure it is aware of
linker with LTO, '--loongarch-annotate-tablejump' needs to be passed via
'-mllvm' to ld.lld.

Note that it should also pass the compiler option -mannotate-tablejump
rather than only pass '-mllvm --loongarch-annotate-tablejump' to ld.lld
if LTO is enabled, otherwise there are no jump info for some table jump
instructions.

Fixes: e20ab7d454ee ("LoongArch: Enable jump table for objtool")
Closes: https://lore.kernel.org/loongarch/20250731175655.GA1455142@ax162/
Reported-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Co-developed-by: WANG Rui <wangrui@loongson.cn>
Signed-off-by: WANG Rui <wangrui@loongson.cn>
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2025-11-10 08:55:40 +08:00
maoxiaochuan 89906e82e1 Revert "irqchip/loongson-pch-msi.c: Switch to msi_create_parent_irq_domain()"
This reverts commit fbcfa60948.

Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2025-11-10 08:55:38 +08:00
maoxiaochuan f6c06f7167 2k300:add mcp3004 and w1 driver support
Changelog: NULL
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2025-11-10 08:55:30 +08:00
maoxiaochuan b5738df99f pwm: loongson: Add an error code in probe()
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2025-11-10 08:55:26 +08:00
maoxiaochuan e7044560bd pwm: loongson: Fix u32 overflow in waveform calculation
mul_u64_u64_div_u64() returns an u64 that might be bigger than U32_MAX.
To properly handle this case it must not be directly assigned to an u32
value.

Use a wider type for duty and period to make the idiom:

    duty = mul_u64_u64_div_u64(...)
    if (duty > U32_MAX)
        duty = U32_MAX;

actually work as intended.

Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Link: https://lore.kernel.org/r/44f3c764-8b65-49a9-b3ad-797e9fbb96f5@stanley.mountain
Fixes: 2b62c89448dd ("pwm: Add Loongson PWM controller support")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
Reviewed-by: Binbin Zhou <zhoubinbin@loongson.cn>
Link: https://lore.kernel.org/r/20250412122124.1636152-2-u.kleine-koenig@baylibre.com
Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2025-11-10 08:55:25 +08:00
maoxiaochuan 012dbfc9b1 dts:ls2k300:Unify model name
it can't get cpu-name by read iocsr, should fill it by FDT.
2025-05-12 09:40:07 +08:00
maoxiaochuan 043a7bf72c update to 68887137c5
1.Add 2K1000 support
2.Icrease the success rate of download wifi firmware(especially in alpine).
2025-05-09 10:50:39 +08:00
maoxiaochuan 4684882283 dts:Add spdx-license-identifier and copyright 2025-04-30 16:22:29 +08:00
maoxiaochuan 0f90d6eeff 2k300&2k300_rt:Enable spi_spidev
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2025-04-30 15:54:48 +08:00
maoxiaochuan 881dbd52e0 update to e7567cc18
1.Fix the issue of the SD card crashing due to repeated plugging and unplugging.
2.add init-polarity to support setup init pwm status
3.loongson2_thermal: update temperature formula
4.Fix alert/critical temperature to 75/105
5.Add alientek-2k300 support
2025-04-17 19:59:01 +08:00
maoxiaochuan 9bd4ef8edb i2c:fix bus broken after once xfer failed 2025-04-02 14:14:45 +08:00
maoxiaochuan ff60a514ff update to 9f12731260
1.dts:ls2k300:Correct label of spi
2.ls2k300:Add a defconfig for rt
3.fix SD-card CMD48 stuck
4.fix i2c hang  when touch for a long time
2025-03-26 13:04:16 +08:00
maoxiaochuan 6273342ddd update to 7d2033720
dts:Rename loongson2k300.dtsi -> loongson-2k0300.dtsi
dts:Add dts for ls2k1000_dp
can:lscanfd:update lscan_.o_shipped
2025-03-10 14:54:18 +08:00
maoxiaochuan b679601af6 hugetlb:fix build error
the error message is as follow:

../arch/loongarch/mm/mmap.c: In function ‘arch_get_unmapped_area_common’:
../arch/loongarch/mm/mmap.c:69:35: error: implicit declaration of function ‘huge_page_mask_align’; did you mean ‘huge_page_mask’? [-Werror=implicit-function-declaration]
   69 |                 info.align_mask = huge_page_mask_align(filp);
      |                                   ^~~~~~~~~~~~~~~~~~~~
      |                                   huge_page_mask
cc1: some warnings being treated as errors

code sync for linux-6.13

Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2025-03-10 14:43:33 +08:00
maoxiaochuan 766b45b0e9 LoongArch: Set max_pfn with the PFN of the last page
The current max_pfn equals to zero. In this case, it causes user cannot
get some page information through /proc filesystem such as kpagecount.
The following message is displayed by stress-ng test suite with command
"stress-ng --verbose --physpage 1 -t 1".

 # stress-ng --verbose --physpage 1 -t 1
 stress-ng: error: [1691] physpage: cannot read page count for address 0x134ac000 in /proc/kpagecount, errno=22 (Invalid argument)
 stress-ng: error: [1691] physpage: cannot read page count for address 0x7ffff207c3a8 in /proc/kpagecount, errno=22 (Invalid argument)
 stress-ng: error: [1691] physpage: cannot read page count for address 0x134b0000 in /proc/kpagecount, errno=22 (Invalid argument)
 ...

After applying this patch, the kernel can pass the test.

 # stress-ng --verbose --physpage 1 -t 1
 stress-ng: debug: [1701] physpage: [1701] started (instance 0 on CPU 3)
 stress-ng: debug: [1701] physpage: [1701] exited (instance 0 on CPU 3)
 stress-ng: debug: [1700] physpage: [1701] terminated (success)

Cc: stable@vger.kernel.org  # 6.8+
Fixes: ff6c3d81f2e8 ("NUMA: optimize detection of memory with no node id assigned by firmware")
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2025-03-10 14:43:08 +08:00
maoxiaochuan f544a64561 update to de782c8951a
ls2k300_mini_dp:enhance otg compatibility
2025-03-06 11:02:21 +08:00
maoxiaochuan 99f01b458e update to 19d7522c1
1.UTS_VERSION add git commit id
2.loongson_2k300_defconfig:Remove unused config
3.Code improvement
2025-03-04 11:56:15 +08:00
maoxiaochuan 9243940556 update to 4249c4342540b1
mmc:Remove unused code to avoid compile warning
loongson_2k300_defconfig:Don't builtin serio_xx
2025-02-21 10:22:11 +08:00
maoxiaochuan 1c67e978cf Update to 1ace04931c77df9
1. Add 2k300_gongkong board support
2025-02-20 10:02:07 +08:00
maoxiaochuan d405f3e1c1 PWM:Remove unused code 2025-02-16 18:09:45 +08:00
maoxiaochuan fc841ef35d Remove unused code 2025-02-14 23:25:39 +08:00
maoxiaochuan 7ffd18ab9d Update to 14fc3074cfe039
1. 添加带irq处理的gpio驱动
2. 龙芯2k系列添加mmc驱动支持
3. 添加看门狗驱动
4. dtb支持从command line中的board_name字段判断
5. 支持内存分布描述数据从固件传入的数据获取
6. 支持从bootcmdline获取ramdisk启动的地址和所用大小
7. 添加2k300的i2c总线驱动
8. 2k300使用新的spi 和 spi-io 驱动
9. CPU芯片温度传感器支持2k300的计算方式
10. 添加2k300的adc驱动
11. pwm: update default pwm freq to 50Mhz
12. loongson pwm 驱动支持dts使用clock-frequency形式声明频率
13. loongson pwm 确保disable时输出的电平为空闲电平
14. 2k300编译配置使能pwm leds功能
15. 2k300的gmac的phy-mode默认使用rgmii-id
16. 2k300先锋派设置YT8531的内部延迟
17. YT8531 phy 支持设置led的工作模式
18. LCD屏幕 支持cmdline的panel属性选择某一款板卡的dts配置,实现屏幕切换
19. 添加脚本用于快速选择板卡配置文件
20. 添加CAN驱动
21. 添加音频驱动
22. 优化OTG兼容性

Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2025-02-13 16:03:32 +08:00
maoxiaochuan f70d65c829 loongarch: add chip type select support
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2025-02-13 15:11:41 +08:00
maoxiaochuan 8305551cb5 loongarch: mach: add mach nedd header file
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2025-02-13 15:11:37 +08:00
maoxiaochuan 8b074cffbf init src (linux-6.12.0) 2025-02-13 14:11:16 +08:00