Skip to contentSkip to conversation

Exynos5: Add cpu freq and tmu throttling

PATCH New Akshay Saraswat 2 participants 6 messages May 13, 2013 – May 15, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover Exynos5: Add cpu freq and tmu throttling

This patch set adds cpu frequency scaling and tmu throttling for exynos5.

Changes since v1:
- Patch-1: Added comment for the set voltage API.
- Patch-2: Added "Acked-by: Simon Glass".
- Patch-3: Added "Acked-by: Simon Glass".
- Patch-4: Added "Acked-by: Simon Glass".

Akshay Saraswat (4):
PMIC: max77686: add pmic_set_voltage api for max77686
Exynos5: cpufreq: Implement frequency scaling for exynos5
smdk5250: enable support for tmu throttling
Exynos5: config: enable cpu freq

 arch/arm/include/asm/arch-exynos/cpufreq.h |   54 ++++++
 board/samsung/smdk5250/smdk5250.c          |   19 ++
 drivers/power/Makefile                     |    1 +
 drivers/power/exynos-cpufreq.c             |  282 ++++++++++++++++++++++++++++
 drivers/power/pmic/pmic_max77686.c         |   66 +++++++
 include/configs/exynos5250-dt.h            |    3 +
 include/power/max77686_pmic.h              |   12 ++
 include/power/pmic.h                       |    1 +
 8 files changed, 438 insertions(+)
 create mode 100644 arch/arm/include/asm/arch-exynos/cpufreq.h
 create mode 100644 drivers/power/exynos-cpufreq.c
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH v2 1/4 PMIC: max77686: add pmic_set_voltage api for max77686

This patch adds pmic_set_voltage api in max77686. As the name suggests, this api is required for switching voltage from one level to another. Unit for the new voltage value should be microvolts.

---
Changes since v1:
- Added comment for the set voltage API.

 drivers/power/pmic/pmic_max77686.c |   66 ++++++++++++++++++++++++++++++++++++
 include/power/max77686_pmic.h      |   12 +++++++
 include/power/pmic.h               |    1 +
 3 files changed, 79 insertions(+)
drivers/power/pmic/pmic_max77686.c +66 -0
index 7fcb4c0..9e1bfdb 100644
@@ -77,3 +77,69 @@ int pmic_init(unsigned char bus)
 
 	return 0;
 }
+/*
+ * Change voltage in BUCK2 to the new value given.
+ *
+ * @param new_voltage		new volatge value (unit - microvolts)
+ * @return			int value, 0 for success
+ */
+int pmic_set_voltage(u32 new_voltage)
+{
+	struct pmic *p;
+	u32 read_data, volt_level, ret;
+
+	p = pmic_get("MAX77686_PMIC");
+	if (!p)
+		return -ENODEV;
+
+	/* Read BUCK2 DVS1 value */
+	ret = pmic_reg_read(p, MAX77686_REG_PMIC_BUCK2DVS1, &read_data);
+	if (ret != 0) {
+		debug("CPUFREQ: max77686 BUCK2 DVS1 register read failed.\n");
+		return -1;
+	}
+
+	/* Calculate voltage level */
+	volt_level = new_voltage - MAX77686_BUCK2_VOL_MIN * 1000;
+
+	if (volt_level < 0) {
+		debug("CPUFREQ: Not a valid voltage level to set\n");
+		return -1;
+	}
+
+	volt_level /= MAX77686_BUCK2_VOL_DIV;
+
+	/* Update voltage level in BUCK2 DVS1 register value */
+	clrsetbits_8(&read_data,
+		     MAX77686_BUCK2_VOL_BITMASK << MAX77686_BUCK2_VOL_BITPOS,
+		     volt_level << MAX77686_BUCK2_VOL_BITPOS);
+
+	/* Write new value in BUCK2 DVS1 */
+	ret = pmic_reg_write(p, MAX77686_REG_PMIC_BUCK2DVS1, read_data);
+	if (ret != 0) {
+		debug("CPUFREQ: max77686 BUCK2 DVS1 register write failed.\n");
+		return -1;
+	}
+
+	/* Set ENABLE BUCK2 register bits */
+	read_data = 0;
+	ret = pmic_reg_read(p, MAX77686_BUCK2_VOL_ENADDR, &read_data);
+	if (ret != 0) {
+		debug("CPUFREQ: max77686 BUCK2 enable address read failed.\n");
+		return -1;
+	}
+
+	clrsetbits_8(&read_data,
+		     (MAX77686_BUCK2_VOL_ENBITMASK
+		     << MAX77686_BUCK2_VOL_ENBITPOS),
+		     (MAX77686_BUCK2_VOL_ENBITON
+		     << MAX77686_BUCK2_VOL_ENBITPOS));
+
+	ret = pmic_reg_write(p, MAX77686_BUCK2_VOL_ENADDR, read_data);
+	if (ret != 0) {
+		debug("CPUFREQ: max77686 BUCK2 enable address write failed.\n");
+		return -1;
+	}
+
+	return 0;
+}
include/power/max77686_pmic.h +12 -0
index fdc7ca9..2780f17 100644
@@ -175,6 +175,18 @@ enum {
 #define MAX77686_LD05CTRL1_1_8V	0x14
 /* LDO10 1.8 volt value */
 #define MAX77686_LD10CTRL1_1_8V	0x14
+
+/* BUCK2 voltage parameter values */
+#define MAX77686_BUCK2_VOL_BITPOS	0x0
+#define MAX77686_BUCK2_VOL_BITMASK	0xff
+#define MAX77686_BUCK2_VOL_ENBITPOS	0x4
+#define MAX77686_BUCK2_VOL_ENBITMASK	0x3
+#define MAX77686_BUCK2_VOL_ENADDR	0x12
+#define MAX77686_BUCK2_VOL_ENBITON	0x1
+#define MAX77686_BUCK2_VOL_ENBITOFF	0x0
+#define MAX77686_BUCK2_VOL_MIN		925
+#define MAX77686_BUCK2_VOL_DIV		12500
+
 /*
  * MAX77686_REG_PMIC_32KHZ set to 32KH CP
  * output is activated
include/power/pmic.h +1 -0
index 1ecfc05..02f6f11 100644
@@ -99,6 +99,7 @@ int pmic_probe(struct pmic *p);
 int pmic_reg_read(struct pmic *p, u32 reg, u32 *val);
 int pmic_reg_write(struct pmic *p, u32 reg, u32 val);
 int pmic_set_output(struct pmic *p, u32 reg, int ldo, int on);
+int pmic_set_voltage(u32 new_voltage);
 
 #define pmic_i2c_addr (p->hw.i2c.addr)
 #define pmic_i2c_tx_num (p->hw.i2c.tx_num)
Signature · 1 line
1.7.10.4
#3 lore raw

PATCH v2 2/4 Exynos5: cpufreq: Implement frequency scaling for exynos5

In reply to Akshay Saraswat

Exynos5 currently runs at full speed i.e. 1.7 GHz everytime. Scaling down the clock speed in certain situations, may help in reducing the ARM temperature and power consumption.

---
Changes since v1:
- Added "Acked-by: Simon Glass".

 arch/arm/include/asm/arch-exynos/cpufreq.h |   54 ++++++
 drivers/power/Makefile                     |    1 +
 drivers/power/exynos-cpufreq.c             |  282 ++++++++++++++++++++++++++++
 3 files changed, 337 insertions(+)
 create mode 100644 arch/arm/include/asm/arch-exynos/cpufreq.h
 create mode 100644 drivers/power/exynos-cpufreq.c
arch/arm/include/asm/arch-exynos/cpufreq.h new file +54 -0
new file mode 100644
index 0000000..173e804
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd.
+ *      http://www.samsung.com
+ *
+ * EXYNOS - CPU frequency scaling support
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+/* Define various levels of ARM frequency */
+enum cpufreq_level {
+	CPU_FREQ_L200,		/* 200 MHz */
+	CPU_FREQ_L300,		/* 300 MHz */
+	CPU_FREQ_L400,		/* 400 MHz */
+	CPU_FREQ_L500,		/* 500 MHz */
+	CPU_FREQ_L600,		/* 600 MHz */
+	CPU_FREQ_L700,		/* 700 MHz */
+	CPU_FREQ_L800,		/* 800 MHz */
+	CPU_FREQ_L900,		/* 900 MHz */
+	CPU_FREQ_L1000,		/* 1000 MHz */
+	CPU_FREQ_L1100,		/* 1100 MHz */
+	CPU_FREQ_L1200,		/* 1200 MHz */
+	CPU_FREQ_L1300,		/* 1300 MHz */
+	CPU_FREQ_L1400,		/* 1400 MHz */
+	CPU_FREQ_L1500,		/* 1500 MHz */
+	CPU_FREQ_L1600,		/* 1600 MHz */
+	CPU_FREQ_L1700,		/* 1700 MHz */
+	CPU_FREQ_LCOUNT,
+};
+
+/*
+ * Initialize ARM frequency scaling
+ *
+ * @param blob  FDT blob
+ * @return	int value, 0 for success
+ */
+int exynos_cpufreq_init(void);
+
+/*
+ * Switch ARM frequency to new level
+ *
+ * @param new_freq_level	enum cpufreq_level, states new frequency
+ * @return			int value, 0 for success
+ */
+int exynos_set_frequency(enum cpufreq_level new_freq_level);
drivers/power/Makefile +1 -0
index 1dac16a..4589d9b 100644
@@ -31,6 +31,7 @@ COBJS-$(CONFIG_TPS6586X_POWER)	+= tps6586x.o
 COBJS-$(CONFIG_TWL4030_POWER)	+= twl4030.o
 COBJS-$(CONFIG_TWL6030_POWER)	+= twl6030.o
 COBJS-$(CONFIG_TWL6035_POWER)	+= twl6035.o
+COBJS-$(CONFIG_EXYNOS_CPUFREQ)	+= exynos-cpufreq.o
 
 COBJS-$(CONFIG_POWER) += power_core.o
 COBJS-$(CONFIG_DIALOG_POWER) += power_dialog.o
drivers/power/exynos-cpufreq.c new file +282 -0

282 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#4 lore raw

PATCH v2 3/4 smdk5250: enable support for tmu throttling

In reply to Akshay Saraswat

Adding tmu throttling support to smdk5250.

---
Changes since v1:
- Added "Acked-by: Simon Glass".

 board/samsung/smdk5250/smdk5250.c |   19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
board/samsung/smdk5250/smdk5250.c +19 -0
index 8b09e1d..301dcf8 100644
@@ -38,6 +38,8 @@
 #include <power/pmic.h>
 #include <power/max77686_pmic.h>
 #include <tmu.h>
+#include <asm/arch/cpufreq.h>
+#include <asm/arch/clk.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -58,6 +60,15 @@ static void boot_temp_check(void)
 		break;
 	case TMU_STATUS_WARNING:
 		puts("EXYNOS_TMU: WARNING! Temperature very high\n");
+#ifdef CONFIG_EXYNOS_CPUFREQ
+		exynos_set_frequency(CPU_FREQ_L400);
+#endif
+		break;
+	case TMU_STATUS_NORMAL:
+#ifdef CONFIG_EXYNOS_CPUFREQ
+		if (get_pll_clk(APLL) != 1700000000)
+			exynos_set_frequency(CPU_FREQ_L1700);
+#endif
 		break;
 	/*
 	 * TMU_STATUS_INIT means something is wrong with temperature sensing
@@ -110,6 +121,13 @@ int board_init(void)
 	boot_temp_check();
 #endif
 
+#if defined CONFIG_EXYNOS_CPUFREQ
+	if (exynos_cpufreq_init()) {
+		debug("%s: Failed to init CPU frequency scaling\n", __func__);
+		return -1;
+	}
+#endif
+
 #ifdef CONFIG_EXYNOS_SPI
 	spi_init();
 #endif
@@ -119,6 +137,7 @@ int board_init(void)
 #ifdef CONFIG_SOUND_MAX98095
 	board_enable_audio_codec();
 #endif
+
 	return 0;
 }
 
Signature · 1 line
1.7.10.4
#5 lore raw

PATCH v2 4/4 Exynos5: config: enable cpu freq

In reply to Akshay Saraswat

This patch enables cpu freq support for exynos5 by adding config for it.

---
Changes since v1:
- Added "Acked-by: Simon Glass".

 include/configs/exynos5250-dt.h |    3 +++
 1 file changed, 3 insertions(+)
include/configs/exynos5250-dt.h +3 -0
index 4514e7a..2321614 100644
@@ -128,6 +128,9 @@
 #define CONFIG_CMD_DTT
 #define CONFIG_TMU_CMD_DTT
 
+/* CPU Frequency Scaling */
+#define CONFIG_EXYNOS_CPUFREQ
+
 /* USB */
 #define CONFIG_CMD_USB
 #define CONFIG_USB_EHCI
Signature · 1 line
1.7.10.4