Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 8 Feb 2017 03:00:07 +0800
From:      Jia-Shiun Li <jiashiun@gmail.com>
To:        "freebsd-arm@freebsd.org" <freebsd-arm@freebsd.org>
Subject:   patching cpufreq for rpi3
Message-ID:  <CAHNYxxOFFeSUQ_8%2BR7RsPn_acoexRNjn%2B51hz6q=GPgz6FYaEg@mail.gmail.com>

index | next in thread | raw e-mail

[-- Attachment #1 --]
I was figuring out why frequency scaling does not work
on rpi3, and found that bcm2837 was not caught in some
cases. Thus the attached patch.

The patch corrects voltage reporting for rpi3.
Frequency scaling still does not work though.
Any ideas?


--- dmesg.orig.txt    2017-02-07 20:00:46.587450000 +0800
+++ dmesg.new3.txt    2017-02-08 00:44:23.609649000 +0800
@@ -5,13 +5,13 @@
 Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
     The Regents of the University of California. All rights reserved.
 FreeBSD is a registered trademark of The FreeBSD Foundation.
-FreeBSD 12.0-CURRENT #1 r313043: Sun Feb  5 01:01:06 CST 2017
+FreeBSD 12.0-CURRENT #3 r313043M: Wed Feb  8 00:24:00 CST 2017
     jsli@4cbsd:/personal/freebsd/obj/x64/arm64.aarch64/
personal/freebsd/fbsdsrc/sys/GENERIC arm64
 FreeBSD clang version 3.9.1 (tags/RELEASE_391/final 289601) (based on LLVM
3.9.1)
 WARNING: WITNESS option enabled, expect reduced performance.
 VT: init without driver.
-Preloaded elf kernel "/boot/kernel/kernel" at 0xffff000000e27000.
-Preloaded /boot/entropy "/boot/entropy" at 0xffff000000e27de0.
+Preloaded elf kernel "/boot/kernel.cpufreq/kernel" at 0xffff000000e27000.
+Preloaded /boot/entropy "/boot/entropy" at 0xffff000000e27de8.
 Starting CPU 1 (1)
 Starting CPU 2 (2)
 Starting CPU 3 (3)
@@ -236,8 +236,8 @@
 bcm2835_cpufreq0: Boot settings:
 bcm2835_cpufreq0: current ARM 600MHz, Core 250MHz, SDRAM 400MHz, Turbo OFF
 bcm2835_cpufreq0: max/min ARM 1200/600MHz, Core 400/250MHz, SDRAM
450/400MHz
-bcm2835_cpufreq0: current Core 30001200mV, SDRAM_C 30001200mV, SDRAM_I
30001200mV, SDRAM_P 30001200mV
-bcm2835_cpufreq0: max/min Core 32344950/30001200mV, SDRAM_C
30001200/30001200mV, SDRAM_I 30001200/30001200mV, SDRAM_P
30001200/30001200mV
+bcm2835_cpufreq0: current Core 1200mV, SDRAM_C 1200mV, SDRAM_I 1200mV,
SDRAM_P 1200mV
+bcm2835_cpufreq0: max/min Core 1293/1200mV, SDRAM_C 1200/1200mV, SDRAM_I
1200/1200mV, SDRAM_P 1200/1200mV
 bcm2835_cpufreq0: Temperature 51.5C
 Release APs
 mmc0: setting bus width to 4 bits


-Jia-Shiun.

[-- Attachment #2 --]
Index: sys/arm/broadcom/bcm2835/bcm2835_cpufreq.c
===================================================================
--- sys/arm/broadcom/bcm2835/bcm2835_cpufreq.c	(revision 313043)
+++ sys/arm/broadcom/bcm2835/bcm2835_cpufreq.c	(working copy)
@@ -66,16 +66,16 @@
 #define	HZ2MHZ(freq) ((freq) / (1000 * 1000))
 #define	MHZ2HZ(freq) ((freq) * (1000 * 1000))
 
-#ifdef SOC_BCM2836
+#ifdef SOC_BCM2835
+#define	OFFSET2MVOLT(val) (1200 + ((val) * 25))
+#define	MVOLT2OFFSET(val) (((val) - 1200) / 25)
+#define	DEFAULT_ARM_FREQUENCY	 700
+#define	DEFAULT_LOWEST_FREQ	 300
+#else
 #define	OFFSET2MVOLT(val) (((val) / 1000))
 #define	MVOLT2OFFSET(val) (((val) * 1000))
 #define	DEFAULT_ARM_FREQUENCY	 600
 #define	DEFAULT_LOWEST_FREQ	 600
-#else
-#define	OFFSET2MVOLT(val) (1200 + ((val) * 25))
-#define	MVOLT2OFFSET(val) (((val) - 1200) / 25)
-#define	DEFAULT_ARM_FREQUENCY	 700
-#define	DEFAULT_LOWEST_FREQ	 300
 #endif
 #define	DEFAULT_CORE_FREQUENCY	 250
 #define	DEFAULT_SDRAM_FREQUENCY	 400
@@ -1544,7 +1544,20 @@
 		if (min_freq > cpufreq_lowest_freq)
 			min_freq = cpufreq_lowest_freq;
 
-#ifdef SOC_BCM2836
+#ifdef SOC_BCM2835
+	/* from freq to min_freq */
+	for (idx = 0; idx < *count && freq >= min_freq; idx++) {
+		if (freq > sc->arm_min_freq)
+			volts = sc->max_voltage_core;
+		else
+			volts = sc->min_voltage_core;
+		sets[idx].freq = freq;
+		sets[idx].volts = volts;
+		sets[idx].lat = TRANSITION_LATENCY;
+		sets[idx].dev = dev;
+		freq -= MHZSTEP;
+	}
+#else
 	/* XXX RPi2 have only 900/600MHz */
 	idx = 0;
 	volts = sc->min_voltage_core;
@@ -1560,19 +1573,6 @@
 		sets[idx].dev = dev;
 		idx++;
 	}
-#else
-	/* from freq to min_freq */
-	for (idx = 0; idx < *count && freq >= min_freq; idx++) {
-		if (freq > sc->arm_min_freq)
-			volts = sc->max_voltage_core;
-		else
-			volts = sc->min_voltage_core;
-		sets[idx].freq = freq;
-		sets[idx].volts = volts;
-		sets[idx].lat = TRANSITION_LATENCY;
-		sets[idx].dev = dev;
-		freq -= MHZSTEP;
-	}
 #endif
 	*count = idx;
 
help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAHNYxxOFFeSUQ_8%2BR7RsPn_acoexRNjn%2B51hz6q=GPgz6FYaEg>