Skip to contentSkip to conversation

cpufreq: tegra: Re-model Tegra20 cpufreq driver

PATCH Superseded Bill Huang 2 participants 5 messages Dec 12, 2013 – Dec 17, 2013

Subsystems (4)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Bill Huang

author
#0 lore raw

PATCH v4 1/1 cpufreq: tegra: Re-model Tegra20 cpufreq driver

Re-model Tegra20 cpufreq driver as below.

* Rename tegra-cpufreq.c to tegra20-cpufreq.c since this file supports only Tegra20.
* Add probe function so defer probe can be used when we're going to support DVFS.
* Create a fake cpufreq platform device with its name being "${root_compatible}-cpufreq" so SoC cpufreq driver can bind to it accordingly.

---

This patch remodel Tegra cpufreq driver to make it more easy to add new SoC support, in addition to that, adding probe function in the driver to let probe defer can be used to control init sequence when we are going to support DVFS.

Changes since v3:

- Create separate driver for each SoCs instead of a central driver indirect call to different SoC functions.

Changes since v2:

- Fix Kconfig.
- Rebase on top of branch 'cpufreq-next' on git://git.linaro.org/people/vireshk/linux.git.

Changes since v1:

- Split up patches.
- Split configuration-time data out of structure "tegra_cpufreq_data".
- Bug fixes.

---
 arch/arm/mach-tegra/tegra.c       |    2 +
 drivers/cpufreq/Kconfig.arm       |   12 +++
 drivers/cpufreq/Makefile          |    1 +
 drivers/cpufreq/tegra-cpufreq.c   |  214 ++++++-------------------------------
 drivers/cpufreq/tegra20-cpufreq.c |  192 +++++++++++++++++++++++++++++++++
 include/linux/tegra-cpufreq.h     |   24 +++++
 6 files changed, 265 insertions(+), 180 deletions(-)
 create mode 100644 drivers/cpufreq/tegra20-cpufreq.c
 create mode 100644 include/linux/tegra-cpufreq.h
arch/arm/mach-tegra/tegra.c +2 -0
index 7336817..a9b23e9 100644
@@ -34,6 +34,7 @@
 #include <linux/usb/tegra_usb_phy.h>
 #include <linux/clk/tegra.h>
 #include <linux/irqchip.h>
+#include <linux/tegra-cpufreq.h>
 
 #include <asm/hardware/cache-l2x0.h>
 #include <asm/mach-types.h>
@@ -160,6 +161,7 @@ static void __init tegra_dt_init_late(void)
 {
 	int i;
 
+	tegra_cpufreq_init();
 	tegra_init_suspend();
 	tegra_cpuidle_init();
 	tegra_powergate_debugfs_init();
drivers/cpufreq/Kconfig.arm +12 -0
index ce52ed9..1cc9213 100644
@@ -225,6 +225,18 @@ config ARM_TEGRA_CPUFREQ
 	help
 	  This adds the CPUFreq driver support for TEGRA SOCs.
 
+config ARM_TEGRA20_CPUFREQ
+	bool "NVIDIA TEGRA20"
+	depends on ARM_TEGRA_CPUFREQ && ARCH_TEGRA_2x_SOC
+	default y
+	help
+	  This enables Tegra20 cpufreq functionality, it adds
+	  Tegra20 CPU frequency ladder and the call back functions
+	  to set CPU rate. All the non-SoC dependant codes are
+	  controlled by the config ARM_TEGRA20_CPUFREQ.
+
+	  If in doubt, say N.
+
 config ARM_VEXPRESS_SPC_CPUFREQ
         tristate "Versatile Express SPC based CPUfreq driver"
         select ARM_BIG_LITTLE_CPUFREQ
drivers/cpufreq/Makefile +1 -0
index 7494565..331964b 100644
@@ -74,6 +74,7 @@ obj-$(CONFIG_ARM_SA1100_CPUFREQ)	+= sa1100-cpufreq.o
 obj-$(CONFIG_ARM_SA1110_CPUFREQ)	+= sa1110-cpufreq.o
 obj-$(CONFIG_ARM_SPEAR_CPUFREQ)		+= spear-cpufreq.o
 obj-$(CONFIG_ARM_TEGRA_CPUFREQ)		+= tegra-cpufreq.o
+obj-$(CONFIG_ARM_TEGRA20_CPUFREQ)	+= tegra20-cpufreq.o
 obj-$(CONFIG_ARM_VEXPRESS_SPC_CPUFREQ)	+= vexpress-spc-cpufreq.o
 
 ##################################################################################
drivers/cpufreq/tegra-cpufreq.c +34 -180

227 lines not on this page · raw message

drivers/cpufreq/tegra20-cpufreq.c new file +192 -0

192 lines not on this page · raw message

include/linux/tegra-cpufreq.h new file +24 -0
new file mode 100644
index 0000000..d7643e0
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2013, NVIDIA Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ */
+
+#ifndef __LINUX_TEGRA_CPUFREQ_H
+#define __LINUX_TEGRA_CPUFREQ_H
+
+#ifdef CONFIG_ARM_TEGRA_CPUFREQ
+int tegra_cpufreq_init(void);
+#else
+static inline int tegra_cpufreq_init(void)
+{ return; }
+#endif
+
+#endif /* __LINUX_TEGRA_CPUFREQ_H_ */
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 11 lines · Bill Huang

Re-model Tegra20 cpufreq driver as below.

* Rename tegra-cpufreq.c to tegra20-cpufreq.c since this file supports only Tegra20.
* Add probe function so defer probe can be used when we're going to support DVFS.
* Create a fake cpufreq platform device with its name being "${root_compatible}-cpufreq" so SoC cpufreq driver can bind to it accordingly.

drivers/cpufreq/Kconfig.arm config ARM_TEGRA_CPUFREQ · line 236

Quoted 10 lines
drivers/cpufreq/Kconfig.arm +9 -0
 
+config ARM_TEGRA20_CPUFREQ
+	bool "NVIDIA TEGRA20"
+	depends on ARM_TEGRA_CPUFREQ && ARCH_TEGRA_2x_SOC
+	default y
+	help
+	  This enables Tegra20 cpufreq functionality, it adds
+	  Tegra20 CPU frequency ladder and the call back functions
+	  to set CPU rate. All the non-SoC dependant codes are
+	  controlled by the config ARM_TEGRA20_CPUFREQ.

I think that last sentence is no longer true in this patch version. Or, did you mean to write ARM_TEGRA_CPUFREQ rather than ARM_TEGRA20_CPUFREQ?

drivers/cpufreq/tegra-cpufreq.c line 25

Quoted 9 lines
drivers/cpufreq/tegra-cpufreq.c +6 -0
 
+static const char * const tegra_soc_compat[] = {
+	"nvidia,tegra124",
+	"nvidia,tegra114",
+	"nvidia,tegra30",
+	"nvidia,tegra20",
+	NULL
 };

That table will need editing for each chip. I wonder if you can do something like always use the very last entry in /compatible. That would assume a particular ordering of the compatible entries, but they should be in the order $board, $soc anyway...

drivers/cpufreq/tegra-cpufreq.c line 38

Quoted 11 lines
drivers/cpufreq/tegra-cpufreq.c +11 -0
+int __init tegra_cpufreq_init(void)
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(tegra_soc_compat); i++) {
+		if (of_machine_is_compatible(tegra_soc_compat[i])) {
+			struct platform_device_info devinfo;
+			char buf[40];
+
+			memset(&devinfo, 0, sizeof(devinfo));
+			strcpy(buf, tegra_soc_compat[i]);
+			strcat(buf, "-cpufreq");

kasprintf() might be simpler, and would avoid the arbitrary 39-character string limit and possibility of overflow.

drivers/cpufreq/tegra-cpufreq.c line 40

Quoted 2 lines
drivers/cpufreq/tegra-cpufreq.c +2 -0
+			devinfo.name = buf;
+			platform_device_register_full(&devinfo);

Does the devinfo struct need to stick around, i.e. does platform_device_register_full keep the pointer, or take a copy of the struct? If it keeps the pointer, it'd be best to make devinfo a static global variable.

drivers/cpufreq/tegra20-cpufreq.c

Quoted 1 line
drivers/cpufreq/tegra20-cpufreq.c +0 -0

Please pass the "-C" option to "git format-patch"; I assume that almost all the code in this file is simply cut/paste verbatim from tegra-cpufreq.c where it was deleted.

Quoted 1 line

+ * Copyright (C) 2010 Google, Inc.

It's worth adding NV (c) here too.

drivers/cpufreq/tegra20-cpufreq.c line 178

Quoted 5 lines
drivers/cpufreq/tegra20-cpufreq.c +5 -0
+static int tegra20_cpufreq_remove(struct platform_device *pdev)
+{
+	cpufreq_unregister_driver(&tegra20_cpufreq_driver);
+	return 0;
+}

That leaks all the clk_get_sys() calls. Does building this as a module work OK?

Quoted 1 line

+MODULE_LICENSE("GPL");

That should be "GPL v2".

include/linux/tegra-cpufreq.h line 22

Quoted 8 lines
include/linux/tegra-cpufreq.h +6 -0
 
+#ifdef CONFIG_ARM_TEGRA_CPUFREQ
+int tegra_cpufreq_init(void);
+#else
+static inline int tegra_cpufreq_init(void)
+{ return; }
+#endif

If you're going to wrap the { } onto one line, then I think it'd be best to wrap the whole thing (prototype and body) onto one line. Otherwise, write:

{
	return;
}

Oh, and you need "return 0" not just "return".

author
#2 lore raw
Quoted 13 lines · Stephen Warren
Quoted 11 lines · Bill Huang

Re-model Tegra20 cpufreq driver as below.

* Rename tegra-cpufreq.c to tegra20-cpufreq.c since this file supports only Tegra20.
* Add probe function so defer probe can be used when we're going to support DVFS.
* Create a fake cpufreq platform device with its name being "${root_compatible}-cpufreq" so SoC cpufreq driver can bind to it accordingly.

drivers/cpufreq/Kconfig.arm +0 -0
Quoted 12 lines

drivers/cpufreq/Kconfig.arm config ARM_TEGRA_CPUFREQ · line 236

Quoted 9 lines
drivers/cpufreq/Kconfig.arm +9 -0
+config ARM_TEGRA20_CPUFREQ
+	bool "NVIDIA TEGRA20"
+	depends on ARM_TEGRA_CPUFREQ && ARCH_TEGRA_2x_SOC
+	default y
+	help
+	  This enables Tegra20 cpufreq functionality, it adds
+	  Tegra20 CPU frequency ladder and the call back functions
+	  to set CPU rate. All the non-SoC dependant codes are
+	  controlled by the config ARM_TEGRA20_CPUFREQ.

I think that last sentence is no longer true in this patch version. Or, did you mean to write ARM_TEGRA_CPUFREQ rather than ARM_TEGRA20_CPUFREQ?

Right, should be ARM_TEGRA_CPUFREQ, thanks for catching this.

Quoted 15 lines

drivers/cpufreq/tegra-cpufreq.c line 25

Quoted 10 lines
drivers/cpufreq/tegra-cpufreq.c +6 -0
 
+static const char * const tegra_soc_compat[] = {
+	"nvidia,tegra124",
+	"nvidia,tegra114",
+	"nvidia,tegra30",
+	"nvidia,tegra20",
+	NULL
  };

That table will need editing for each chip. I wonder if you can do something like always use the very last entry in /compatible. That would assume a particular ordering of the compatible entries, but they should be in the order $board, $soc anyway...

How do we get subset of a string and making sure it is the last? There must be some assumptions here (though they will possibly be true) I guess, for example, they should be in the order $board, $soc... and the last "nvidia" should be the start of the last compatible id we would like to get.

Quoted 15 lines

drivers/cpufreq/tegra-cpufreq.c line 38

Quoted 12 lines
drivers/cpufreq/tegra-cpufreq.c +11 -0
+int __init tegra_cpufreq_init(void)
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(tegra_soc_compat); i++) {
+		if (of_machine_is_compatible(tegra_soc_compat[i])) {
+			struct platform_device_info devinfo;
+			char buf[40];
+
+			memset(&devinfo, 0, sizeof(devinfo));
+			strcpy(buf, tegra_soc_compat[i]);
+			strcat(buf, "-cpufreq");

kasprintf() might be simpler, and would avoid the arbitrary 39-character string limit and possibility of overflow.

Ah yeah, thanks.

Quoted 8 lines

drivers/cpufreq/tegra-cpufreq.c line 40

Quoted 3 lines
drivers/cpufreq/tegra-cpufreq.c +2 -0
+			devinfo.name = buf;
+			platform_device_register_full(&devinfo);

Does the devinfo struct need to stick around, i.e. does platform_device_register_full keep the pointer, or take a copy of the struct? If it keeps the pointer, it'd be best to make devinfo a static global variable.

devinfo is used to provide dev info to create platform device structure, so I think it is OK here.

Quoted 6 lines

drivers/cpufreq/tegra20-cpufreq.c

Quoted 2 lines
drivers/cpufreq/tegra20-cpufreq.c +0 -0

Please pass the "-C" option to "git format-patch"; I assume that almost all the code in this file is simply cut/paste verbatim from tegra-cpufreq.c where it was deleted.

OK, thanks.

Quoted 4 lines
Quoted 2 lines

+ * Copyright (C) 2010 Google, Inc.

It's worth adding NV (c) here too.

OK.

Quoted 9 lines

drivers/cpufreq/tegra20-cpufreq.c line 178

Quoted 6 lines
drivers/cpufreq/tegra20-cpufreq.c +5 -0
+static int tegra20_cpufreq_remove(struct platform_device *pdev)
+{
+	cpufreq_unregister_driver(&tegra20_cpufreq_driver);
+	return 0;
+}

That leaks all the clk_get_sys() calls. Does building this as a module work OK?

I should add back those clk_put here.

Quoted 4 lines
Quoted 2 lines

+MODULE_LICENSE("GPL");

That should be "GPL v2".

OK.

Quoted 14 lines

include/linux/tegra-cpufreq.h line 22

Quoted 9 lines
include/linux/tegra-cpufreq.h +6 -0
 
+#ifdef CONFIG_ARM_TEGRA_CPUFREQ
+int tegra_cpufreq_init(void);
+#else
+static inline int tegra_cpufreq_init(void)
+{ return; }
+#endif

If you're going to wrap the { } onto one line, then I think it'd be best to wrap the whole thing (prototype and body) onto one line. Otherwise, write:

Quoted 5 lines
{
	return;
}

Oh, and you need "return 0" not just "return".

Thanks for catching.

Quoted 1 line
#3 lore raw
Quoted 45 lines · bilhuang
Quoted 23 lines · Stephen Warren
Quoted 11 lines · Bill Huang

Re-model Tegra20 cpufreq driver as below.

* Rename tegra-cpufreq.c to tegra20-cpufreq.c since this file supports only Tegra20.
* Add probe function so defer probe can be used when we're going to support DVFS.
* Create a fake cpufreq platform device with its name being "${root_compatible}-cpufreq" so SoC cpufreq driver can bind to it accordingly.

drivers/cpufreq/Kconfig.arm config ARM_TEGRA_CPUFREQ · line 236

Quoted 10 lines
drivers/cpufreq/Kconfig.arm +9 -0
 
+config ARM_TEGRA20_CPUFREQ
+    bool "NVIDIA TEGRA20"
+    depends on ARM_TEGRA_CPUFREQ && ARCH_TEGRA_2x_SOC
+    default y
+    help
+      This enables Tegra20 cpufreq functionality, it adds
+      Tegra20 CPU frequency ladder and the call back functions
+      to set CPU rate. All the non-SoC dependant codes are
+      controlled by the config ARM_TEGRA20_CPUFREQ.
Quoted 2 lines

I think that last sentence is no longer true in this patch version. Or, did you mean to write ARM_TEGRA_CPUFREQ rather than ARM_TEGRA20_CPUFREQ?

Right, should be ARM_TEGRA_CPUFREQ, thanks for catching this.

Quoted 12 lines

drivers/cpufreq/tegra-cpufreq.c line 25

Quoted 11 lines
drivers/cpufreq/tegra-cpufreq.c +6 -0
 
+static const char * const tegra_soc_compat[] = {
+    "nvidia,tegra124",
+    "nvidia,tegra114",
+    "nvidia,tegra30",
+    "nvidia,tegra20",
+    NULL
  };
Quoted 4 lines

That table will need editing for each chip. I wonder if you can do something like always use the very last entry in /compatible. That would assume a particular ordering of the compatible entries, but they should be in the order $board, $soc anyway...

Quoted 5 lines

How do we get subset of a string and making sure it is the last? There must be some assumptions here (though they will possibly be true) I guess, for example, they should be in the order $board, $soc... and the last "nvidia" should be the start of the last compatible id we would like to get.

The compatible property is an array of strings, rather than one big string, so you can just keep getting index 0, 1, 2, ... until you find there aren't any more entries. I think it's reasonable to assume that the SoC compatible value must be last, and it should be in practice, although perhaps that is fragile. If you want, we can leave this as-is for now, and modify it later if it becomes a problem.

author
#4 lore raw
Quoted 52 lines · Stephen Warren
Quoted 45 lines · bilhuang
Quoted 23 lines · Stephen Warren
Quoted 11 lines · Bill Huang

Re-model Tegra20 cpufreq driver as below.

* Rename tegra-cpufreq.c to tegra20-cpufreq.c since this file supports only Tegra20.
* Add probe function so defer probe can be used when we're going to support DVFS.
* Create a fake cpufreq platform device with its name being

    "${root_compatible}-cpufreq" so SoC cpufreq driver can bind to it
    accordingly.

drivers/cpufreq/Kconfig.arm config ARM_TEGRA_CPUFREQ · line 236

Quoted 10 lines
drivers/cpufreq/Kconfig.arm +9 -0
 
+config ARM_TEGRA20_CPUFREQ
+    bool "NVIDIA TEGRA20"
+    depends on ARM_TEGRA_CPUFREQ && ARCH_TEGRA_2x_SOC
+    default y
+    help
+      This enables Tegra20 cpufreq functionality, it adds
+      Tegra20 CPU frequency ladder and the call back functions
+      to set CPU rate. All the non-SoC dependant codes are
+      controlled by the config ARM_TEGRA20_CPUFREQ.
Quoted 2 lines

I think that last sentence is no longer true in this patch version. Or, did you mean to write ARM_TEGRA_CPUFREQ rather than ARM_TEGRA20_CPUFREQ?

Right, should be ARM_TEGRA_CPUFREQ, thanks for catching this.

Quoted 12 lines

drivers/cpufreq/tegra-cpufreq.c line 25

Quoted 11 lines
drivers/cpufreq/tegra-cpufreq.c +6 -0
 
+static const char * const tegra_soc_compat[] = {
+    "nvidia,tegra124",
+    "nvidia,tegra114",
+    "nvidia,tegra30",
+    "nvidia,tegra20",
+    NULL
   };
Quoted 4 lines

That table will need editing for each chip. I wonder if you can do something like always use the very last entry in /compatible. That would assume a particular ordering of the compatible entries, but they should be in the order $board, $soc anyway...

Quoted 5 lines

How do we get subset of a string and making sure it is the last? There must be some assumptions here (though they will possibly be true) I guess, for example, they should be in the order $board, $soc... and the last "nvidia" should be the start of the last compatible id we would like to get.

Quoted 7 lines

The compatible property is an array of strings, rather than one big string, so you can just keep getting index 0, 1, 2, ... until you find there aren't any more entries. I think it's reasonable to assume that the SoC compatible value must be last, and it should be in practice, although perhaps that is fragile. If you want, we can leave this as-is for now, and modify it later if it becomes a problem.

Right, thanks.