Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
273 changes: 273 additions & 0 deletions README_LENOVO_LEGION_5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
# Lenovo Legion Pro 5 16IRX9 Setup Guide

This document provides a complete setup guide for the **Lenovo Legion Pro 5 16IRX9 (Model 83DF)** with the LenovoLegionLinux project, including fan control, temperature monitoring, and system optimization.

## 🖥️ Hardware Specifications

- **Model**: Lenovo Legion Pro 5 16IRX9 (83DF)
- **BIOS Version**: N0CN31WW (BIOS Prefix: N0CN)
- **OS**: Ubuntu 22.04
- **Embedded Controller ID**: 0x5507
- **Fan Configuration**: Dual fans with hardware maximum 10,000 RPM each

## 📋 Prerequisites

### System Dependencies

```bash
# Update system packages
sudo apt update && sudo apt upgrade -y

# Install required build tools and dependencies
sudo apt install -y make gcc linux-headers-$(uname -r) build-essential git lm-sensors wget dkms stress-ng

# Install Python development tools
sudo apt install -y python3-venv python3-pip python3-dev python3-setuptools python3-wheel
```

## 🚀 Installation Process

### Step 1: Clone and Setup Environment

```bash
# Clone the repository
cd ~/Downloads
git clone https://github.com/johnfanv2/LenovoLegionLinux.git
cd LenovoLegionLinux

# Install system dependencies
sudo ./deploy/dependencies/install_dependencies_ubuntu_22_04.sh
```

### Step 2: Configure Python Environment

```bash
# The system will automatically create a Python virtual environment
# Location: ~/Downloads/LenovoLegionLinux/.venv/
```

### Step 3: Install Python Packages

**Required Python packages that were installed:**
- `build` - For building Python packages
- `setuptools` - Python package development tools
- `wheel` - Python wheel package format
- `installer` - Python package installer
- `argcomplete` - Command line tab completion
- `pyyaml` - YAML parser and emitter
- `Pillow` - Python Imaging Library

```bash
# Install Python packages (done automatically during setup)
cd python/legion_linux
~/Downloads/LenovoLegionLinux/.venv/bin/python -m build --wheel --no-isolation
sudo ~/Downloads/LenovoLegionLinux/.venv/bin/python -m installer ~/Downloads/LenovoLegionLinux/python/legion_linux/dist/*.whl
```

### Step 4: Add Hardware Support

**⚠️ IMPORTANT**: The Legion Pro 5 16IRX9 (Model 83DF) is **NOT** in the default allowlist. We had to manually add support:

**File Modified**: `kernel_module/legion-laptop.c`
**Added Entry** (around line 1380):
```c
{
// e.g. Legion Pro 5 16IRX9 (83DF)
.ident = "N0CN",
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
DMI_MATCH(DMI_BIOS_VERSION, "N0CN"),
},
.driver_data = (void *)&model_g8cn
},
```

### Step 5: Compile and Install Kernel Module

```bash
cd kernel_module

# Clean and compile
make clean && make

# Install with DKMS (permanent installation)
sudo make dkms

# Make module load on boot
echo "legion_laptop" | sudo tee -a /etc/modules
```

## 🌡️ Fan Specifications and Investigation Results

### Hardware Limits Discovered

| Specification | Value | Notes |
|---------------|--------|-------|
| **Normal Operation** | ~2,300 RPM | Automatic temperature control |
| **High Performance Mode** | 3,100 RPM | 35% increase, safe sustained operation |
| **Attempted Maximum** | 4,500+ RPM | **FAILED** - Firmware limitations |
| **Hardware Theoretical Max** | 10,000 RPM | Manufacturer specification |
| **Safe Operating Range** | 2,300-3,500 RPM | Recommended for daily use |

### What Works ✅
- **Full Speed Mode**: Achieves 3,100 RPM safely
- **Power Mode Control**: 3 modes (1=Quiet, 2=Balanced, 3=Performance)
- **Temperature Monitoring**: CPU, GPU, IC temperatures
- **Fan Speed Reading**: Real-time RPM monitoring
- **Hardware Monitor Integration**: Works with `sensors` command

### What Doesn't Work ❌
- **Manual PWM Control**: System overrides manual settings
- **Custom Fan Curves**: Embedded controller ignores software curves
- **High-Speed Override**: Cannot exceed ~3,500 RPM safely
- **Direct Fan Control**: EC firmware limits prevent dangerous speeds

### Firmware Limitations
The Legion Pro 5 16IRX9 has **embedded controller (EC) firmware protection** that:
- Prevents dangerous fan speeds (>3,500 RPM in software control)
- Overrides aggressive manual fan curves
- Protects hardware from potential damage
- Maintains acoustic limits (noise control)

## 🛠️ Usage Commands

### Basic Fan Control

```bash
# Check current fan speeds and temperatures
sensors legion_hwmon-isa-0000

# Enable high-performance fan mode (3100 RPM)
echo 1 | sudo tee /sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/fan_fullspeed
echo 2 | sudo tee /sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/powermode
sudo ~/Downloads/LenovoLegionLinux/.venv/bin/legion_cli maximumfanspeed-enable

# Return to normal mode (2300 RPM)
echo 0 | sudo tee /sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/fan_fullspeed
echo 3 | sudo tee /sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/powermode
sudo ~/Downloads/LenovoLegionLinux/.venv/bin/legion_cli maximumfanspeed-disable
```

### Legion CLI Commands

```bash
# Monitor system (with 5-second interval)
~/Downloads/LenovoLegionLinux/.venv/bin/legion_cli monitor 5

# Check maximum fan speed status
~/Downloads/LenovoLegionLinux/.venv/bin/legion_cli maximumfanspeed-status

# Fan curve controls
~/Downloads/LenovoLegionLinux/.venv/bin/legion_cli fancurve-write-hw-to-file /tmp/current_curve.txt
~/Downloads/LenovoLegionLinux/.venv/bin/legion_cli fancurve-write-file-to-hw /tmp/custom_curve.txt

# Get help
~/Downloads/LenovoLegionLinux/.venv/bin/legion_cli --help
```

### Convenient Control Script

A control script was created at `~/Downloads/LenovoLegionLinux/fan_control.sh`:

```bash
# Enable high-performance mode
./fan_control.sh enable

# Disable high-performance mode
./fan_control.sh disable

# Check current status
./fan_control.sh status
```

## 📊 Performance Results

### Temperature Monitoring
```bash
# Example output:
legion_hwmon-isa-0000
Adapter: ISA adapter
Fan 1: 3100 RPM (max = 10000 RPM)
Fan 2: 3100 RPM (max = 10000 RPM)
CPU Temperature: +68.0°C
GPU Temperature: +49.0°C
IC Temperature: +80.0°C
```

### Available System Files

**Fan Control:**
- `/sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/fan_fullspeed`
- `/sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/fan_maxspeed`
- `/sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/powermode`

**Hardware Monitor:**
- `/sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/hwmon/hwmon6/fan1_input`
- `/sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/hwmon/hwmon6/fan2_input`
- `/sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/hwmon/hwmon6/temp1_input`

## ⚠️ Safety Considerations

### Safe Operating Guidelines
- ✅ **2,300-3,100 RPM**: Safe for continuous operation
- ⚠️ **3,100-4,000 RPM**: Use only during heavy workloads
- ❌ **4,000+ RPM**: Avoid - may cause hardware damage

### Signs of Problems
- Unusual fan noise (grinding, clicking)
- Inconsistent RPM readings
- Overheating despite high fan speeds
- System instability

## 🔧 Troubleshooting

### Module Not Loading
```bash
# Check if module is loaded
lsmod | grep legion

# Check dmesg for errors
sudo dmesg | grep -i legion

# Reload module manually
sudo rmmod legion-laptop
sudo modprobe legion_laptop
```

### Permission Errors
```bash
# Ensure proper permissions
sudo chmod 644 /sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/*
```

### Python Environment Issues
```bash
# Recreate virtual environment
cd ~/Downloads/LenovoLegionLinux
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt # if available
```

## 📚 Additional Resources

- **Main Project**: [LenovoLegionLinux GitHub](https://github.com/johnfanv2/LenovoLegionLinux)
- **Issues/Support**: [GitHub Issues](https://github.com/johnfanv2/LenovoLegionLinux/issues)
- **Documentation**: [Project Wiki](https://github.com/johnfanv2/LenovoLegionLinux/wiki)

## 🎯 Summary

The **Lenovo Legion Pro 5 16IRX9** is now fully supported with:
- ✅ **Fan monitoring** (real-time RPM)
- ✅ **Temperature sensors** (CPU/GPU/IC)
- ✅ **Performance boost** (35% fan speed increase)
- ✅ **Safe operation** (firmware-protected)
- ✅ **Easy controls** (CLI and scripts)

**Maximum achievable fan speed**: **3,100 RPM** (safe and effective cooling)

---

*Document created: September 24, 2025*
*Hardware: Lenovo Legion Pro 5 16IRX9 (83DF)*
*Software: LenovoLegionLinux with custom modifications*
49 changes: 49 additions & 0 deletions fan_control.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

# Legion Fan Control Script
# Usage: ./fan_control.sh [enable|disable|status]

case "$1" in
"enable")
echo "🔥 Enabling high-performance fan mode..."
echo 1 | sudo tee /sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/fan_fullspeed > /dev/null
echo 1 | sudo tee /sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/fan_maxspeed > /dev/null
echo 2 | sudo tee /sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/powermode > /dev/null
sudo /home/xuananh/Downloads/LenovoLegionLinux/.venv/bin/legion_cli maximumfanspeed-enable
echo "✅ High-performance fan mode enabled!"
echo "📊 Current fan speeds:"
sensors legion_hwmon-isa-0000
;;
"disable")
echo "🌡️ Disabling high-performance fan mode..."
echo 0 | sudo tee /sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/fan_fullspeed > /dev/null
echo 0 | sudo tee /sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/fan_maxspeed > /dev/null
echo 3 | sudo tee /sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/powermode > /dev/null
sudo /home/xuananh/Downloads/LenovoLegionLinux/.venv/bin/legion_cli maximumfanspeed-disable
echo "✅ Automatic fan mode restored!"
echo "📊 Current fan speeds:"
sensors legion_hwmon-isa-0000
;;
"status")
echo "📊 Current Legion Fan Status:"
echo "================================"
sensors legion_hwmon-isa-0000
echo ""
echo "🎛️ Current Settings:"
echo "Fan Full Speed: $(cat /sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/fan_fullspeed)"
echo "Fan Max Speed: $(cat /sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/fan_maxspeed)"
echo "Power Mode: $(cat /sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/powermode)"
;;
*)
echo "Legion Fan Control Script"
echo "========================"
echo "Usage: $0 [enable|disable|status]"
echo ""
echo "Commands:"
echo " enable - Enable high-performance fan mode (~2900 RPM)"
echo " disable - Return to automatic fan control (~2300 RPM)"
echo " status - Show current fan speeds and settings"
echo ""
echo "Note: Requires sudo privileges"
;;
esac
9 changes: 9 additions & 0 deletions kernel_module/legion-laptop.c
Original file line number Diff line number Diff line change
Expand Up @@ -1381,6 +1381,15 @@ static const struct dmi_system_id optimistic_allowlist[] = {
},
.driver_data = (void *)&model_nzcn
},
{
// e.g. Legion Pro 5 16IRX9 (83DF)
.ident = "N0CN",
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
DMI_MATCH(DMI_BIOS_VERSION, "N0CN"),
},
.driver_data = (void *)&model_g8cn
},
{}
};

Expand Down
2 changes: 1 addition & 1 deletion python/legion_linux/setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = legion_linux
version = _VERSION
version = 0.0.20
author = johnfan
author_email = johnfan@example.org
description = Control Lenovo Legion laptop
Expand Down
Loading