2016-03-18 12:14:51

by Feng Xiao

[permalink] [raw]
Subject: [PATCH] cpufreq: rockchip: add driver

This driver will directly use cpufreq-dt driver as backend.

As there is not a generic devicetree board file(rockchip.c)
on ARM64 architecture, so remove platform_device_register_simple
in rockchip.c and add a new cpufreq driver to support for all
Rockchip SoCs.

Signed-off-by: Feng Xiao <[email protected]>
---
arch/arm/mach-rockchip/rockchip.c | 1 -
drivers/cpufreq/Kconfig.arm | 10 ++++++++++
drivers/cpufreq/Makefile | 1 +
drivers/cpufreq/rockchip-cpufreq.c | 36 ++++++++++++++++++++++++++++++++++++
4 files changed, 47 insertions(+), 1 deletion(-)
create mode 100644 drivers/cpufreq/rockchip-cpufreq.c

diff --git a/arch/arm/mach-rockchip/rockchip.c b/arch/arm/mach-rockchip/rockchip.c
index 3f07cc5..beb71da 100644
--- a/arch/arm/mach-rockchip/rockchip.c
+++ b/arch/arm/mach-rockchip/rockchip.c
@@ -74,7 +74,6 @@ static void __init rockchip_dt_init(void)
{
rockchip_suspend_init();
of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
- platform_device_register_simple("cpufreq-dt", 0, NULL, 0);
}

static const char * const rockchip_board_dt_compat[] = {
diff --git a/drivers/cpufreq/Kconfig.arm b/drivers/cpufreq/Kconfig.arm
index 14b1f93..1786315 100644
--- a/drivers/cpufreq/Kconfig.arm
+++ b/drivers/cpufreq/Kconfig.arm
@@ -97,6 +97,16 @@ config ARM_OMAP2PLUS_CPUFREQ
depends on ARCH_OMAP2PLUS
default ARCH_OMAP2PLUS

+config ARM_ROCKCHIP_CPUFREQ
+ tristate "Rockchip CPUfreq driver"
+ depends on ARCH_ROCKCHIP && CPUFREQ_DT
+ select PM_OPP
+ help
+ This adds the CPUFreq driver support for Rockchip SoCs.
+ The driver will directly use cpufreq-dt driver as backend.
+
+ If in doubt, say N.
+
config ARM_S3C_CPUFREQ
bool
help
diff --git a/drivers/cpufreq/Makefile b/drivers/cpufreq/Makefile
index 9e63fb1..91d8bb7 100644
--- a/drivers/cpufreq/Makefile
+++ b/drivers/cpufreq/Makefile
@@ -61,6 +61,7 @@ obj-$(CONFIG_ARM_MT8173_CPUFREQ) += mt8173-cpufreq.o
obj-$(CONFIG_ARM_OMAP2PLUS_CPUFREQ) += omap-cpufreq.o
obj-$(CONFIG_ARM_PXA2xx_CPUFREQ) += pxa2xx-cpufreq.o
obj-$(CONFIG_PXA3xx) += pxa3xx-cpufreq.o
+obj-$(CONFIG_ARM_ROCKCHIP_CPUFREQ) += rockchip-cpufreq.o
obj-$(CONFIG_ARM_S3C24XX_CPUFREQ) += s3c24xx-cpufreq.o
obj-$(CONFIG_ARM_S3C24XX_CPUFREQ_DEBUGFS) += s3c24xx-cpufreq-debugfs.o
obj-$(CONFIG_ARM_S3C2410_CPUFREQ) += s3c2410-cpufreq.o
diff --git a/drivers/cpufreq/rockchip-cpufreq.c b/drivers/cpufreq/rockchip-cpufreq.c
new file mode 100644
index 0000000..ecbadcd
--- /dev/null
+++ b/drivers/cpufreq/rockchip-cpufreq.c
@@ -0,0 +1,36 @@
+/*
+ * Rockchip Platforms CPUFreq Support
+ *
+ * Copyright (C) 2016 Fuzhou Rockchip Electronics Co., Ltd
+ *
+ * Feng Xiao <[email protected]>
+ *
+ * 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.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+
+static int __init rockchip_cpufreq_driver_init(void)
+{
+ struct platform_device *pdev;
+
+ pdev = platform_device_register_simple("cpufreq-dt", -1, NULL, 0);
+ return PTR_ERR_OR_ZERO(pdev);
+}
+module_init(rockchip_cpufreq_driver_init);
+
+MODULE_AUTHOR("Feng Xiao <[email protected]>");
+MODULE_DESCRIPTION("Rockchip cpufreq driver");
+MODULE_LICENSE("GPL v2");
--
1.9.1



2016-03-18 12:57:12

by Heiko Stübner

[permalink] [raw]
Subject: Re: [PATCH] cpufreq: rockchip: add driver

Hi Feng,

Am Freitag, 18. M?rz 2016, 20:10:04 schrieb Feng Xiao:
> This driver will directly use cpufreq-dt driver as backend.
>
> As there is not a generic devicetree board file(rockchip.c)
> on ARM64 architecture, so remove platform_device_register_simple
> in rockchip.c and add a new cpufreq driver to support for all
> Rockchip SoCs.
>
> Signed-off-by: Feng Xiao <[email protected]>

[...]

> diff --git a/drivers/cpufreq/rockchip-cpufreq.c
> b/drivers/cpufreq/rockchip-cpufreq.c new file mode 100644
> index 0000000..ecbadcd
> --- /dev/null
> +++ b/drivers/cpufreq/rockchip-cpufreq.c
> @@ -0,0 +1,36 @@
> +/*
> + * Rockchip Platforms CPUFreq Support
> + *
> + * Copyright (C) 2016 Fuzhou Rockchip Electronics Co., Ltd
> + *
> + * Feng Xiao <[email protected]>
> + *
> + * 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.
> + *
> + * This program is distributed "as is" WITHOUT ANY WARRANTY of any
> + * kind, whether express or implied; without even the implied warranty
> + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + */
> +
> +#include <linux/err.h>
> +#include <linux/init.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/platform_device.h>
> +
> +static int __init rockchip_cpufreq_driver_init(void)
> +{
> + struct platform_device *pdev;
> +
> + pdev = platform_device_register_simple("cpufreq-dt", -1, NULL, 0);
> + return PTR_ERR_OR_ZERO(pdev);

This would create that cpufreq-dt device on all non-Rockchip platforms
compiled into the same kernel image as well - we definitly don't want that.

Also, on both the rk3368 as well as the rk3399, you probably want the cluster-
handling of arm-bL-cpufreq-dt.
Contrary to its name it is _not_ limited to switching between clusters, but
can also control frequencies of multiple cpu-clusters running at the same
time.


Implementation-wise, I guess doing it similar to the scpi-implementation might
make more sense. Please take a look at drivers/clk/clk-scpi.c that registers
the virtual cpufreq device there.

So we could do something similar, move the cpufreq from mach-rockchip to the
clock drivers and register the appropriate cpufreq-driver for each soc.
cpufreq-dt for socs with a single cluster, the bL-thing for socs with multiple
clusters.


Heiko

2016-03-21 09:51:05

by Viresh Kumar

[permalink] [raw]
Subject: Re: [PATCH] cpufreq: rockchip: add driver

On 18-03-16, 13:56, Heiko St?bner wrote:
> Also, on both the rk3368 as well as the rk3399, you probably want the cluster-
> handling of arm-bL-cpufreq-dt.
> Contrary to its name it is _not_ limited to switching between clusters, but
> can also control frequencies of multiple cpu-clusters running at the same
> time.

We aren't adding any new users to bL driver, please use cpufreq-dt as that also
supports multiple clusters now.

--
viresh

2016-03-21 09:55:07

by Heiko Stübner

[permalink] [raw]
Subject: Re: [PATCH] cpufreq: rockchip: add driver

Am Montag, 21. M?rz 2016, 15:20:49 schrieb Viresh Kumar:
> On 18-03-16, 13:56, Heiko St?bner wrote:
> > Also, on both the rk3368 as well as the rk3399, you probably want the
> > cluster- handling of arm-bL-cpufreq-dt.
> > Contrary to its name it is _not_ limited to switching between clusters,
> > but
> > can also control frequencies of multiple cpu-clusters running at the same
> > time.
>
> We aren't adding any new users to bL driver, please use cpufreq-dt as that
> also supports multiple clusters now.

I hadn't seen that yet ... nice that cpufreq-dt now also supports clusters :-)

The other part still stands though, as we probably should register the
platform-device somewhere else and not in some new special module.

When everything is using cpufreq-dt now, I guess we could just add it to the
core rockchip clk-code. Or was there some agreement where this should be done
(obviously not the devicetree itself)?

2016-03-21 09:59:06

by Viresh Kumar

[permalink] [raw]
Subject: Re: [PATCH] cpufreq: rockchip: add driver

On 21-03-16, 10:54, Heiko St?bner wrote:
> I hadn't seen that yet ... nice that cpufreq-dt now also supports clusters :-)
>
> The other part still stands though, as we probably should register the
> platform-device somewhere else and not in some new special module.
>
> When everything is using cpufreq-dt now, I guess we could just add it to the
> core rockchip clk-code. Or was there some agreement where this should be done
> (obviously not the devicetree itself)?

Yeah, there was a discussion around creating a white or black list of platforms
that want to create a platform device for cpufreq-dt. That can be done in
cpufreq-dt.c or a new file, but I haven't worked out on that yet.

You can do it from clk-code or from the driver that was added in this thread.
Just that you need to match your platform's compatible string before doing that.

--
viresh

2016-03-21 13:24:24

by Feng Xiao

[permalink] [raw]
Subject: Re: [PATCH] cpufreq: rockchip: add driver



在 2016/3/21 17:58, Viresh Kumar 写道:
> On 21-03-16, 10:54, Heiko Stübner wrote:
>> I hadn't seen that yet ... nice that cpufreq-dt now also supports clusters :-)
>>
>> The other part still stands though, as we probably should register the
>> platform-device somewhere else and not in some new special module.
>>
>> When everything is using cpufreq-dt now, I guess we could just add it to the
>> core rockchip clk-code. Or was there some agreement where this should be done
>> (obviously not the devicetree itself)?
Of_clk_init is called early, and platform_device_register_simple should
be called after devices_init, it will be failed to do it from clk-code.
So we need add a new file or add module_init to each clock controller
driver(like clk-rk3368.c, clk-rk3399.c) ?
> Yeah, there was a discussion around creating a white or black list of platforms
> that want to create a platform device for cpufreq-dt. That can be done in
> cpufreq-dt.c or a new file, but I haven't worked out on that yet.
>
> You can do it from clk-code or from the driver that was added in this thread.
> Just that you need to match your platform's compatible string before doing that.
Rockchip-cpufreq.c depends on ARM_ROCKCHIP_CPUFREQ, it will not be
compiled on non-Rockchip platforms.
The driver can support all Rockchip SoCs up to now, add
of_machine_is_compatible may be redundant ?
>


2016-03-21 15:13:09

by Viresh Kumar

[permalink] [raw]
Subject: Re: [PATCH] cpufreq: rockchip: add driver

On 21-03-16, 21:24, Feng Xiao wrote:
> Rockchip-cpufreq.c depends on ARM_ROCKCHIP_CPUFREQ, it will not be compiled
> on non-Rockchip platforms.
> The driver can support all Rockchip SoCs up to now, add
> of_machine_is_compatible may be redundant ?

Heard of Multi-platform kernels ?

--
viresh

2016-03-21 15:13:58

by Heiko Stübner

[permalink] [raw]
Subject: Re: [PATCH] cpufreq: rockchip: add driver

Hi,

Am Montag, 21. März 2016, 21:24:32 schrieb Feng Xiao:
> 在 2016/3/21 17:58, Viresh Kumar 写道:
> > On 21-03-16, 10:54, Heiko Stübner wrote:
> >> I hadn't seen that yet ... nice that cpufreq-dt now also supports
> >> clusters :-)
> >>
> >> The other part still stands though, as we probably should register the
> >> platform-device somewhere else and not in some new special module.
> >>
> >> When everything is using cpufreq-dt now, I guess we could just add it to
> >> the core rockchip clk-code. Or was there some agreement where this
> >> should be done (obviously not the devicetree itself)?
>
> Of_clk_init is called early, and platform_device_register_simple should
> be called after devices_init, it will be failed to do it from clk-code.
> So we need add a new file or add module_init to each clock controller
> driver(like clk-rk3368.c, clk-rk3399.c) ?

as Viresh said, it should be ok to do it like your approach creating a module
in drivers/cpufreq. But the compatible check is necessary.

Doing it this way also makes it easier to have

> > Yeah, there was a discussion around creating a white or black list of
> > platforms that want to create a platform device for cpufreq-dt. That can
> > be done in cpufreq-dt.c or a new file, but I haven't worked out on that
> > yet.
> >
> > You can do it from clk-code or from the driver that was added in this
> > thread. Just that you need to match your platform's compatible string
> > before doing that.
> Rockchip-cpufreq.c depends on ARM_ROCKCHIP_CPUFREQ, it will not be
> compiled on non-Rockchip platforms.
> The driver can support all Rockchip SoCs up to now, add
> of_machine_is_compatible may be redundant ?

Please always keep multiplatform in mind. These days the kernel can be
compiled for multiple architectures at the same time, so you can have support
for Rockchip, Exynos, Qualcom and whatever in the same kernel image.

Therefore a compile-time check is not enough and you need to check the
actually running machine as well.


Heiko

2016-03-21 15:52:36

by Heiko Stübner

[permalink] [raw]
Subject: Re: [PATCH] cpufreq: rockchip: add driver

Am Montag, 21. März 2016, 16:13:40 schrieb Heiko Stübner:
> Hi,
>
> Am Montag, 21. März 2016, 21:24:32 schrieb Feng Xiao:
> > 在 2016/3/21 17:58, Viresh Kumar 写道:
> > > On 21-03-16, 10:54, Heiko Stübner wrote:
> > >> I hadn't seen that yet ... nice that cpufreq-dt now also supports
> > >> clusters :-)
> > >>
> > >> The other part still stands though, as we probably should register the
> > >> platform-device somewhere else and not in some new special module.
> > >>
> > >> When everything is using cpufreq-dt now, I guess we could just add it
> > >> to
> > >> the core rockchip clk-code. Or was there some agreement where this
> > >> should be done (obviously not the devicetree itself)?
> >
> > Of_clk_init is called early, and platform_device_register_simple should
> > be called after devices_init, it will be failed to do it from clk-code.
> > So we need add a new file or add module_init to each clock controller
> > driver(like clk-rk3368.c, clk-rk3399.c) ?
>
> as Viresh said, it should be ok to do it like your approach creating a
> module in drivers/cpufreq. But the compatible check is necessary.
>
> Doing it this way also makes it easier to have

Seem like I forgot the complete my sentence here. This should've been

Doing it this way also makes it easier to have everything go into cpufreq-dt
once that whitelist appears that Viresh wrote about. So this might be better
than to distribute this stuff around other subsystems, as I originally
suggested.

>
> > > Yeah, there was a discussion around creating a white or black list of
> > > platforms that want to create a platform device for cpufreq-dt. That can
> > > be done in cpufreq-dt.c or a new file, but I haven't worked out on that
> > > yet.
> > >
> > > You can do it from clk-code or from the driver that was added in this
> > > thread. Just that you need to match your platform's compatible string
> > > before doing that.
> >
> > Rockchip-cpufreq.c depends on ARM_ROCKCHIP_CPUFREQ, it will not be
> > compiled on non-Rockchip platforms.
> > The driver can support all Rockchip SoCs up to now, add
> > of_machine_is_compatible may be redundant ?
>
> Please always keep multiplatform in mind. These days the kernel can be
> compiled for multiple architectures at the same time, so you can have
> support for Rockchip, Exynos, Qualcom and whatever in the same kernel
> image.
>
> Therefore a compile-time check is not enough and you need to check the
> actually running machine as well.
>
>
> Heiko

2016-03-22 01:27:58

by Feng Xiao

[permalink] [raw]
Subject: Re: [PATCH] cpufreq: rockchip: add driver

I get it, thanks.

在 2016/3/21 23:52, Heiko Stübner 写道:
> Am Montag, 21. März 2016, 16:13:40 schrieb Heiko Stübner:
>> Hi,
>>
>> Am Montag, 21. März 2016, 21:24:32 schrieb Feng Xiao:
>>> 在 2016/3/21 17:58, Viresh Kumar 写道:
>>>> On 21-03-16, 10:54, Heiko Stübner wrote:
>>>>> I hadn't seen that yet ... nice that cpufreq-dt now also supports
>>>>> clusters :-)
>>>>>
>>>>> The other part still stands though, as we probably should register the
>>>>> platform-device somewhere else and not in some new special module.
>>>>>
>>>>> When everything is using cpufreq-dt now, I guess we could just add it
>>>>> to
>>>>> the core rockchip clk-code. Or was there some agreement where this
>>>>> should be done (obviously not the devicetree itself)?
>>> Of_clk_init is called early, and platform_device_register_simple should
>>> be called after devices_init, it will be failed to do it from clk-code.
>>> So we need add a new file or add module_init to each clock controller
>>> driver(like clk-rk3368.c, clk-rk3399.c) ?
>> as Viresh said, it should be ok to do it like your approach creating a
>> module in drivers/cpufreq. But the compatible check is necessary.
>>
>> Doing it this way also makes it easier to have
> Seem like I forgot the complete my sentence here. This should've been
>
> Doing it this way also makes it easier to have everything go into cpufreq-dt
> once that whitelist appears that Viresh wrote about. So this might be better
> than to distribute this stuff around other subsystems, as I originally
> suggested.
>
>>>> Yeah, there was a discussion around creating a white or black list of
>>>> platforms that want to create a platform device for cpufreq-dt. That can
>>>> be done in cpufreq-dt.c or a new file, but I haven't worked out on that
>>>> yet.
>>>>
>>>> You can do it from clk-code or from the driver that was added in this
>>>> thread. Just that you need to match your platform's compatible string
>>>> before doing that.
>>> Rockchip-cpufreq.c depends on ARM_ROCKCHIP_CPUFREQ, it will not be
>>> compiled on non-Rockchip platforms.
>>> The driver can support all Rockchip SoCs up to now, add
>>> of_machine_is_compatible may be redundant ?
>> Please always keep multiplatform in mind. These days the kernel can be
>> compiled for multiple architectures at the same time, so you can have
>> support for Rockchip, Exynos, Qualcom and whatever in the same kernel
>> image.
>>
>> Therefore a compile-time check is not enough and you need to check the
>> actually running machine as well.
>>
>>
>> Heiko
>
>
>


2016-03-22 11:59:45

by Feng Xiao

[permalink] [raw]
Subject: [PATCH v1] cpufreq: rockchip: add driver

This driver will directly use cpufreq-dt driver as backend.

As there is not a generic devicetree board file(rockchip.c)
on ARM64 architecture, so remove platform_device_register_simple
in rockchip.c and add a new cpufreq driver to support Rockchip
SoCs.

Signed-off-by: Feng Xiao <[email protected]>
---
change in v1:
- add compatible check

arch/arm/mach-rockchip/rockchip.c | 1 -
drivers/cpufreq/Kconfig.arm | 10 +++++++
drivers/cpufreq/Makefile | 1 +
drivers/cpufreq/rockchip-cpufreq.c | 55 ++++++++++++++++++++++++++++++++++++++
4 files changed, 66 insertions(+), 1 deletion(-)
create mode 100644 drivers/cpufreq/rockchip-cpufreq.c

diff --git a/arch/arm/mach-rockchip/rockchip.c b/arch/arm/mach-rockchip/rockchip.c
index 3f07cc5..beb71da 100644
--- a/arch/arm/mach-rockchip/rockchip.c
+++ b/arch/arm/mach-rockchip/rockchip.c
@@ -74,7 +74,6 @@ static void __init rockchip_dt_init(void)
{
rockchip_suspend_init();
of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
- platform_device_register_simple("cpufreq-dt", 0, NULL, 0);
}

static const char * const rockchip_board_dt_compat[] = {
diff --git a/drivers/cpufreq/Kconfig.arm b/drivers/cpufreq/Kconfig.arm
index 14b1f93..1786315 100644
--- a/drivers/cpufreq/Kconfig.arm
+++ b/drivers/cpufreq/Kconfig.arm
@@ -97,6 +97,16 @@ config ARM_OMAP2PLUS_CPUFREQ
depends on ARCH_OMAP2PLUS
default ARCH_OMAP2PLUS

+config ARM_ROCKCHIP_CPUFREQ
+ tristate "Rockchip CPUfreq driver"
+ depends on ARCH_ROCKCHIP && CPUFREQ_DT
+ select PM_OPP
+ help
+ This adds the CPUFreq driver support for Rockchip SoCs.
+ The driver will directly use cpufreq-dt driver as backend.
+
+ If in doubt, say N.
+
config ARM_S3C_CPUFREQ
bool
help
diff --git a/drivers/cpufreq/Makefile b/drivers/cpufreq/Makefile
index 9e63fb1..91d8bb7 100644
--- a/drivers/cpufreq/Makefile
+++ b/drivers/cpufreq/Makefile
@@ -61,6 +61,7 @@ obj-$(CONFIG_ARM_MT8173_CPUFREQ) += mt8173-cpufreq.o
obj-$(CONFIG_ARM_OMAP2PLUS_CPUFREQ) += omap-cpufreq.o
obj-$(CONFIG_ARM_PXA2xx_CPUFREQ) += pxa2xx-cpufreq.o
obj-$(CONFIG_PXA3xx) += pxa3xx-cpufreq.o
+obj-$(CONFIG_ARM_ROCKCHIP_CPUFREQ) += rockchip-cpufreq.o
obj-$(CONFIG_ARM_S3C24XX_CPUFREQ) += s3c24xx-cpufreq.o
obj-$(CONFIG_ARM_S3C24XX_CPUFREQ_DEBUGFS) += s3c24xx-cpufreq-debugfs.o
obj-$(CONFIG_ARM_S3C2410_CPUFREQ) += s3c2410-cpufreq.o
diff --git a/drivers/cpufreq/rockchip-cpufreq.c b/drivers/cpufreq/rockchip-cpufreq.c
new file mode 100644
index 0000000..65c1de9
--- /dev/null
+++ b/drivers/cpufreq/rockchip-cpufreq.c
@@ -0,0 +1,55 @@
+/*
+ * Rockchip Platforms CPUFreq Support
+ *
+ * Copyright (C) 2016 Fuzhou Rockchip Electronics Co., Ltd
+ *
+ * Feng Xiao <[email protected]>
+ *
+ * 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.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+
+static const char * const rockchip_compat[] = {
+ "rockchip,rk2928",
+ "rockchip,rk3066a",
+ "rockchip,rk3066b",
+ "rockchip,rk3188",
+ "rockchip,rk3288",
+ "rockchip,rk3366",
+ "rockchip,rk3368",
+ "rockchip,rk3399",
+};
+
+static int __init rockchip_cpufreq_driver_init(void)
+{
+ struct platform_device *pdev;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(rockchip_compat); i++) {
+ if (of_machine_is_compatible(rockchip_compat[i])) {
+ pdev = platform_device_register_simple("cpufreq-dt",
+ -1, NULL, 0);
+ return PTR_ERR_OR_ZERO(pdev);
+ }
+ }
+
+ return -ENODEV;
+}
+module_init(rockchip_cpufreq_driver_init);
+
+MODULE_AUTHOR("Feng Xiao <[email protected]>");
+MODULE_DESCRIPTION("Rockchip cpufreq driver");
+MODULE_LICENSE("GPL v2");
--
1.9.1


2016-03-22 16:07:57

by Heiko Stübner

[permalink] [raw]
Subject: Re: [PATCH v1] cpufreq: rockchip: add driver

Hi,

Am Dienstag, 22. M?rz 2016, 19:57:28 schrieb Feng Xiao:
> This driver will directly use cpufreq-dt driver as backend.
>
> As there is not a generic devicetree board file(rockchip.c)
> on ARM64 architecture, so remove platform_device_register_simple
> in rockchip.c and add a new cpufreq driver to support Rockchip
> SoCs.
>
> Signed-off-by: Feng Xiao <[email protected]>

some hints regarding the soc-selection below, otherwise this looks nice.

Reviewed-by: Heiko Stuebner <[email protected]>

[includes an Ack for the mach-rockchip change ;-) ]

[...]

> diff --git a/drivers/cpufreq/rockchip-cpufreq.c
> b/drivers/cpufreq/rockchip-cpufreq.c new file mode 100644
> index 0000000..65c1de9
> --- /dev/null
> +++ b/drivers/cpufreq/rockchip-cpufreq.c
> @@ -0,0 +1,55 @@
> +/*
> + * Rockchip Platforms CPUFreq Support
> + *
> + * Copyright (C) 2016 Fuzhou Rockchip Electronics Co., Ltd
> + *
> + * Feng Xiao <[email protected]>
> + *
> + * 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.
> + *
> + * This program is distributed "as is" WITHOUT ANY WARRANTY of any
> + * kind, whether express or implied; without even the implied warranty
> + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + */
> +
> +#include <linux/err.h>
> +#include <linux/init.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/platform_device.h>
> +
> +static const char * const rockchip_compat[] = {
> + "rockchip,rk2928",

+ "rockchip,rk3036",

> + "rockchip,rk3066a",
> + "rockchip,rk3066b",
> + "rockchip,rk3188",

+ "rockchip,rk3228",

> + "rockchip,rk3288",
> + "rockchip,rk3366",
> + "rockchip,rk3368",
> + "rockchip,rk3399",
> +};
> +
> +static int __init rockchip_cpufreq_driver_init(void)
> +{
> + struct platform_device *pdev;
> + int i;
> +
> + for (i = 0; i < ARRAY_SIZE(rockchip_compat); i++) {
> + if (of_machine_is_compatible(rockchip_compat[i])) {
> + pdev = platform_device_register_simple("cpufreq-dt",
> + -1, NULL, 0);
> + return PTR_ERR_OR_ZERO(pdev);
> + }
> + }
> +
> + return -ENODEV;
> +}
> +module_init(rockchip_cpufreq_driver_init);
> +
> +MODULE_AUTHOR("Feng Xiao <[email protected]>");
> +MODULE_DESCRIPTION("Rockchip cpufreq driver");
> +MODULE_LICENSE("GPL v2");

2016-03-23 02:20:05

by Feng Xiao

[permalink] [raw]
Subject: [PATCH v2] cpufreq: rockchip: add driver

This driver will directly use cpufreq-dt driver as backend.

As there is not a generic devicetree board file(rockchip.c)
on ARM64 architecture, so remove platform_device_register_simple
in rockchip.c and add a new cpufreq driver to support Rockchip
SoCs.

Signed-off-by: Feng Xiao <[email protected]>
Reviewed-by: Heiko Stuebner <[email protected]>
---
change in v2:
- add rockchip,rk3036 and rockchip,rk3228 to compatibility list

change in v1:
- add compatible check

arch/arm/mach-rockchip/rockchip.c | 1 -
drivers/cpufreq/Kconfig.arm | 10 +++++++
drivers/cpufreq/Makefile | 1 +
drivers/cpufreq/rockchip-cpufreq.c | 57 ++++++++++++++++++++++++++++++++++++++
4 files changed, 68 insertions(+), 1 deletion(-)
create mode 100644 drivers/cpufreq/rockchip-cpufreq.c

diff --git a/arch/arm/mach-rockchip/rockchip.c b/arch/arm/mach-rockchip/rockchip.c
index 3f07cc5..beb71da 100644
--- a/arch/arm/mach-rockchip/rockchip.c
+++ b/arch/arm/mach-rockchip/rockchip.c
@@ -74,7 +74,6 @@ static void __init rockchip_dt_init(void)
{
rockchip_suspend_init();
of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
- platform_device_register_simple("cpufreq-dt", 0, NULL, 0);
}

static const char * const rockchip_board_dt_compat[] = {
diff --git a/drivers/cpufreq/Kconfig.arm b/drivers/cpufreq/Kconfig.arm
index 14b1f93..1786315 100644
--- a/drivers/cpufreq/Kconfig.arm
+++ b/drivers/cpufreq/Kconfig.arm
@@ -97,6 +97,16 @@ config ARM_OMAP2PLUS_CPUFREQ
depends on ARCH_OMAP2PLUS
default ARCH_OMAP2PLUS

+config ARM_ROCKCHIP_CPUFREQ
+ tristate "Rockchip CPUfreq driver"
+ depends on ARCH_ROCKCHIP && CPUFREQ_DT
+ select PM_OPP
+ help
+ This adds the CPUFreq driver support for Rockchip SoCs.
+ The driver will directly use cpufreq-dt driver as backend.
+
+ If in doubt, say N.
+
config ARM_S3C_CPUFREQ
bool
help
diff --git a/drivers/cpufreq/Makefile b/drivers/cpufreq/Makefile
index 9e63fb1..91d8bb7 100644
--- a/drivers/cpufreq/Makefile
+++ b/drivers/cpufreq/Makefile
@@ -61,6 +61,7 @@ obj-$(CONFIG_ARM_MT8173_CPUFREQ) += mt8173-cpufreq.o
obj-$(CONFIG_ARM_OMAP2PLUS_CPUFREQ) += omap-cpufreq.o
obj-$(CONFIG_ARM_PXA2xx_CPUFREQ) += pxa2xx-cpufreq.o
obj-$(CONFIG_PXA3xx) += pxa3xx-cpufreq.o
+obj-$(CONFIG_ARM_ROCKCHIP_CPUFREQ) += rockchip-cpufreq.o
obj-$(CONFIG_ARM_S3C24XX_CPUFREQ) += s3c24xx-cpufreq.o
obj-$(CONFIG_ARM_S3C24XX_CPUFREQ_DEBUGFS) += s3c24xx-cpufreq-debugfs.o
obj-$(CONFIG_ARM_S3C2410_CPUFREQ) += s3c2410-cpufreq.o
diff --git a/drivers/cpufreq/rockchip-cpufreq.c b/drivers/cpufreq/rockchip-cpufreq.c
new file mode 100644
index 0000000..9266614
--- /dev/null
+++ b/drivers/cpufreq/rockchip-cpufreq.c
@@ -0,0 +1,57 @@
+/*
+ * Rockchip Platforms CPUFreq Support
+ *
+ * Copyright (C) 2016 Fuzhou Rockchip Electronics Co., Ltd
+ *
+ * Feng Xiao <[email protected]>
+ *
+ * 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.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+
+static const char * const rockchip_compat[] = {
+ "rockchip,rk2928",
+ "rockchip,rk3036",
+ "rockchip,rk3066a",
+ "rockchip,rk3066b",
+ "rockchip,rk3188",
+ "rockchip,rk3228",
+ "rockchip,rk3288",
+ "rockchip,rk3366",
+ "rockchip,rk3368",
+ "rockchip,rk3399",
+};
+
+static int __init rockchip_cpufreq_driver_init(void)
+{
+ struct platform_device *pdev;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(rockchip_compat); i++) {
+ if (of_machine_is_compatible(rockchip_compat[i])) {
+ pdev = platform_device_register_simple("cpufreq-dt",
+ -1, NULL, 0);
+ return PTR_ERR_OR_ZERO(pdev);
+ }
+ }
+
+ return -ENODEV;
+}
+module_init(rockchip_cpufreq_driver_init);
+
+MODULE_AUTHOR("Feng Xiao <[email protected]>");
+MODULE_DESCRIPTION("Rockchip cpufreq driver");
+MODULE_LICENSE("GPL v2");
--
1.9.1


2016-03-23 04:40:44

by Viresh Kumar

[permalink] [raw]
Subject: Re: [PATCH v2] cpufreq: rockchip: add driver

On 23-03-16, 10:18, Feng Xiao wrote:
> diff --git a/drivers/cpufreq/Kconfig.arm b/drivers/cpufreq/Kconfig.arm
> index 14b1f93..1786315 100644
> --- a/drivers/cpufreq/Kconfig.arm
> +++ b/drivers/cpufreq/Kconfig.arm
> @@ -97,6 +97,16 @@ config ARM_OMAP2PLUS_CPUFREQ
> depends on ARCH_OMAP2PLUS
> default ARCH_OMAP2PLUS
>
> +config ARM_ROCKCHIP_CPUFREQ
> + tristate "Rockchip CPUfreq driver"

Since you are allowing it to be built as a module ...

> + depends on ARCH_ROCKCHIP && CPUFREQ_DT
> + select PM_OPP
> + help
> + This adds the CPUFreq driver support for Rockchip SoCs.
> + The driver will directly use cpufreq-dt driver as backend.
> +
> + If in doubt, say N.

> +++ b/drivers/cpufreq/rockchip-cpufreq.c
> +static int __init rockchip_cpufreq_driver_init(void)
> +{
> + struct platform_device *pdev;
> + int i;
> +
> + for (i = 0; i < ARRAY_SIZE(rockchip_compat); i++) {
> + if (of_machine_is_compatible(rockchip_compat[i])) {
> + pdev = platform_device_register_simple("cpufreq-dt",
> + -1, NULL, 0);
> + return PTR_ERR_OR_ZERO(pdev);
> + }
> + }
> +
> + return -ENODEV;
> +}
> +module_init(rockchip_cpufreq_driver_init);

You need a module exit as well to remove the device. Otherwise following
sequence will give you errors:

insmod rockchip-cpufreq.ko
rmmod rockchip-cpufreq.ko
insmod rockchip-cpufreq.ko //Errors on this..

So, either don't allow it to be built as a module or fix the module-exit path.

--
viresh

2016-03-24 03:01:12

by Feng Xiao

[permalink] [raw]
Subject: Re: [PATCH v2] cpufreq: rockchip: add driver

hi all,
I found that it could match the cpufreq-dt driver succesfully only
with the following changes.
--- a/arch/arm64/boot/dts/rockchip/rk3366.dtsi
+++ b/arch/arm64/boot/dts/rockchip/rk3366.dtsi
@@ -139,6 +139,10 @@
};
};

+ cpufreq-dt { //the node name must be cpufreq-dt
+ compatible = "rockchip,cpufreq"; // the compatible
name is insignificant
+ };
+

This was supported by the commit 07e461cd7e73a84f0e3757932b93cc80976fd749

commit 07e461cd7e73a84f0e3757932b93cc80976fd749
Author: Grant Likely <[email protected]>
Date: Wed May 21 15:40:31 2014 +0900

of: Ensure unique names without sacrificing determinism

The way the driver core is implemented, every device using the same bus
type is required to have a unique name because a symlink to each device
is created in the appropriate /sys/bus/*/devices directory, and two
identical names causes a collision.

The current code handles the requirement by using an globally
incremented counter that is appended to the device name. It works, but
it means any change to device registration will change the assigned
numbers. Instead, if we build up the name by using information from the
parent nodes, then it can be guaranteed to be unique without adding a
random number to the end of it.

Signed-off-by: Grant Likely <[email protected]>
Cc: Ezequiel Garcia <[email protected]>
Cc: Rob Herring <[email protected]>

If so, do I need to continue to add the new cpufreq driver ?

在 2016/3/23 12:40, Viresh Kumar 写道:
> On 23-03-16, 10:18, Feng Xiao wrote:
>> diff --git a/drivers/cpufreq/Kconfig.arm b/drivers/cpufreq/Kconfig.arm
>> index 14b1f93..1786315 100644
>> --- a/drivers/cpufreq/Kconfig.arm
>> +++ b/drivers/cpufreq/Kconfig.arm
>> @@ -97,6 +97,16 @@ config ARM_OMAP2PLUS_CPUFREQ
>> depends on ARCH_OMAP2PLUS
>> default ARCH_OMAP2PLUS
>>
>> +config ARM_ROCKCHIP_CPUFREQ
>> + tristate "Rockchip CPUfreq driver"
> Since you are allowing it to be built as a module ...
>
>> + depends on ARCH_ROCKCHIP && CPUFREQ_DT
>> + select PM_OPP
>> + help
>> + This adds the CPUFreq driver support for Rockchip SoCs.
>> + The driver will directly use cpufreq-dt driver as backend.
>> +
>> + If in doubt, say N.
>> +++ b/drivers/cpufreq/rockchip-cpufreq.c
>> +static int __init rockchip_cpufreq_driver_init(void)
>> +{
>> + struct platform_device *pdev;
>> + int i;
>> +
>> + for (i = 0; i < ARRAY_SIZE(rockchip_compat); i++) {
>> + if (of_machine_is_compatible(rockchip_compat[i])) {
>> + pdev = platform_device_register_simple("cpufreq-dt",
>> + -1, NULL, 0);
>> + return PTR_ERR_OR_ZERO(pdev);
>> + }
>> + }
>> +
>> + return -ENODEV;
>> +}
>> +module_init(rockchip_cpufreq_driver_init);
> You need a module exit as well to remove the device. Otherwise following
> sequence will give you errors:
>
> insmod rockchip-cpufreq.ko
> rmmod rockchip-cpufreq.ko
> insmod rockchip-cpufreq.ko //Errors on this..
>
> So, either don't allow it to be built as a module or fix the module-exit path.
>


2016-03-24 06:43:56

by Viresh Kumar

[permalink] [raw]
Subject: Re: [PATCH v2] cpufreq: rockchip: add driver

On 24-03-16, 11:01, Feng Xiao wrote:
> hi all,
> I found that it could match the cpufreq-dt driver succesfully only with
> the following changes.
> --- a/arch/arm64/boot/dts/rockchip/rk3366.dtsi
> +++ b/arch/arm64/boot/dts/rockchip/rk3366.dtsi
> @@ -139,6 +139,10 @@
> };
> };
>
> + cpufreq-dt { //the node name must be cpufreq-dt
> + compatible = "rockchip,cpufreq"; // the compatible name is
> insignificant
> + };
> +

Its not allowed to create a DT node for a dummy device and so we never
followed this way.

I have just sent a patchset and cc'd you:
"[PATCH 0/3] cpufreq: dt: Create platform device from generic code"

and so this patch shall get replaced now.

--
viresh

2016-03-24 15:09:06

by Finley Xiao

[permalink] [raw]
Subject: Re: [PATCH v2] cpufreq: rockchip: add driver

Hi Viresh,

can we add a of_match_table with a common compatible name as follows ?

--- a/drivers/cpufreq/cpufreq-dt.c
+++ b/drivers/cpufreq/cpufreq-dt.c
@@ -470,10 +470,16 @@ static int dt_cpufreq_remove(struct
platform_device *pdev)
cpufreq_unregister_driver(&dt_cpufreq_driver);
return 0;
}
+static const struct of_device_id dt_cpufreq_of_match[] = {
+ { .compatible = "***,***", },
+ { }
+};
+MODULE_DEVICE_TABLE(of, dt_cpufreq_of_match);
static struct platform_driver dt_cpufreq_platdrv = {
.driver = {
.name = "cpufreq-dt",
+ .of_match_table = dt_cpufreq_of_match,
},

--- a/arch/arm64/boot/dts/rockchip/rk3366.dtsi
+++ b/arch/arm64/boot/dts/rockchip/rk3366.dtsi
+ cpufreq {
+ compatible = "***,***";
+ }

Does it create a DT node for a dummy device too ?


在 2016/3/24 14:43, Viresh Kumar 写道:
> On 24-03-16, 11:01, Feng Xiao wrote:
>> hi all,
>> I found that it could match the cpufreq-dt driver succesfully only with
>> the following changes.
>> --- a/arch/arm64/boot/dts/rockchip/rk3366.dtsi
>> +++ b/arch/arm64/boot/dts/rockchip/rk3366.dtsi
>> @@ -139,6 +139,10 @@
>> };
>> };
>>
>> + cpufreq-dt { //the node name must be cpufreq-dt
>> + compatible = "rockchip,cpufreq"; // the compatible name is
>> insignificant
>> + };
>> +
> Its not allowed to create a DT node for a dummy device and so we never
> followed this way.
>
> I have just sent a patchset and cc'd you:
> "[PATCH 0/3] cpufreq: dt: Create platform device from generic code"
>
> and so this patch shall get replaced now.
>

--
Finley


2016-03-25 04:42:09

by Viresh Kumar

[permalink] [raw]
Subject: Re: [PATCH v2] cpufreq: rockchip: add driver

On 24-03-16, 23:09, Finley Xiao wrote:
> --- a/arch/arm64/boot/dts/rockchip/rk3366.dtsi
> +++ b/arch/arm64/boot/dts/rockchip/rk3366.dtsi
> + cpufreq {
> + compatible = "***,***";
> + }
>
> Does it create a DT node for a dummy device too ?

Yes, its not allowed.

--
viresh