#!/bin/bash
# GPU OC Script for BC-250
# Tests all performance levels and applies max OC

SYSFS="/sys/class/drm/card0/device"

echo "=== Current GPU State ==="
echo "Performance level: $(cat $SYSFS/power_dpm_force_performance_level)"
echo "Temp: $(cat $SYSFS/hwmon/hwmon*/temp1_input 2>/dev/null)m°C"
echo ""
cat $SYSFS/pp_od_clk_voltage
echo ""
echo "DPM SCLK:"
cat $SYSFS/pp_dpm_sclk
echo ""

echo "=== Testing Performance Levels ==="
for level in low high auto profile_standard profile_min_sclk profile_min_mclk profile_peak manual; do
    echo -n "  $level: "
    echo "$level" > $SYSFS/power_dpm_force_performance_level 2>/dev/null
    if [ $? -eq 0 ]; then
        echo "OK"
    else
        echo "FAIL"
    fi
done
echo "Current level: $(cat $SYSFS/power_dpm_force_performance_level)"
echo ""

echo "=== Attempting OC ==="
# Try setting to manual first
echo "manual" > $SYSFS/power_dpm_force_performance_level 2>/dev/null
if [ $? -ne 0 ]; then
    echo "manual mode FAILED, trying profile_peak..."
    echo "profile_peak" > $SYSFS/power_dpm_force_performance_level 2>/dev/null
fi
echo "Level now: $(cat $SYSFS/power_dpm_force_performance_level)"

# Try to set higher SCLK via pp_od_clk_voltage
echo "Attempting SCLK 2000MHz 1100mV..."
echo "s 0 2000 1100" > $SYSFS/pp_od_clk_voltage 2>&1
echo "c" > $SYSFS/pp_od_clk_voltage 2>&1

echo ""
echo "=== After OC Attempt ==="
cat $SYSFS/pp_od_clk_voltage
echo ""
echo "DPM SCLK:"
cat $SYSFS/pp_dpm_sclk
echo ""

# Force highest DPM level
echo "2" > $SYSFS/pp_dpm_sclk 2>/dev/null
echo "DPM after force:"
cat $SYSFS/pp_dpm_sclk

echo ""
echo "=== amdgpu module params ==="
cat /sys/module/amdgpu/parameters/ppfeaturemask 2>/dev/null
echo ""
echo "GPU busy: $(cat $SYSFS/gpu_busy_percent 2>/dev/null)%"
echo "Temp: $(cat $SYSFS/hwmon/hwmon*/temp1_input 2>/dev/null)m°C"
