cip-dev.lists.cip-project.org archive mirror
 help / color / mirror / Atom feed
* Re: [cip-dev] [PATCH 4.4.y-cip 3/3] cpufreq: ti: Add cpufreq driver to determine available OPPs at runtime
       [not found] <HK2PR01MB3281A0A027BAB0F4F036AC7AFAAA0@HK2PR01MB3281.apcprd01.prod.exchangelabs.com>
@ 2020-05-01  9:31 ` Pavel Machek
  2020-05-03 19:09   ` Nobuhiro Iwamatsu
  0 siblings, 1 reply; 4+ messages in thread
From: Pavel Machek @ 2020-05-01  9:31 UTC (permalink / raw)
  To: Johnson CH Chen (陳昭勳)
  Cc: cip-dev, nobuhiro1.iwamatsu, pavel


[-- Attachment #1.1: Type: text/plain, Size: 2725 bytes --]

Hi!

> From: Dave Gerlach <d-gerlach@ti.com>
>  
> commit e13cf046cd70894393a1085ca39da7ef751353fb upstream
> 
> Some TI SoCs, like those in the AM335x, AM437x, DRA7x, and AM57x families,
> have different OPPs available for the MPU depending on which specific
> variant of the SoC is in use. This can be determined through use of the
> revision and an eFuse register present in the silicon. Introduce a
> ti-cpufreq driver that can read the aformentioned values and provide
> them as version matching data to the opp framework. Through this the
> opp-supported-hw dt binding that is part of the operating-points-v2
> table can be used to indicate availability of OPPs for each device.
> 
> This driver also creates the "cpufreq-dt" platform_device after passing
> the version matching data to the OPP framework so that the cpufreq-dt
> handles the actual cpufreq implementation. Even without the necessary
> data to pass the version matching data the driver will still create this
> device to maintain backwards compatibility with operating-points v1
> tables.
> 
> index 000000000000..3dbf57164ded
> --- /dev/null
> +++ b/drivers/cpufreq/ti-cpufreq.c
> @@ -0,0 +1,272 @@
> +/*
> + * TI CPUFreq/OPP hw-supported driver
> + *
> + * Copyright (C) 2016-2017 Texas Instruments, Inc.
> + *	 Dave Gerlach <d-gerlach@ti.com>
> + *
> + * 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.

I guess SPDX would be better than this.

> +static int ti_cpufreq_init(void)
> +{
...
> +	/*
> +	 * OPPs determine whether or not they are supported based on
> +	 * two metrics:
> +	 *	0 - SoC Revision
> +	 *	1 - eFuse value
> +	 */
> +	ret = ti_cpufreq_get_rev(opp_data, &version[0]);
> +	if (ret)
> +		goto fail_put_node;
> +
> +	ret = ti_cpufreq_get_efuse(opp_data, &version[1]);
> +	if (ret)
> +		goto fail_put_node;
> +
> +	of_node_put(opp_data->opp_node);
> +
> +	ret = dev_pm_opp_set_supported_hw(opp_data->cpu_dev,
> +						version, VERSION_COUNT);
> +	if (ret) {
> +		dev_err(opp_data->cpu_dev,
> +			"Failed to set supported hardware\n");
> +		goto fail_put_node;
> +	}

This should be "return err", we have already put the node few lines
above.

> +register_cpufreq_dt:
> +	platform_device_register_simple("cpufreq-dt", -1, NULL, 0);
> +
> +	return 0;
> +
> +fail_put_node:
> +	of_node_put(opp_data->opp_node);
> +
> +	return ret;
> +}

Best regards,
								Pavel
-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

[-- Attachment #2: Type: text/plain, Size: 419 bytes --]

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#4612): https://lists.cip-project.org/g/cip-dev/message/4612
Mute This Topic: https://lists.cip-project.org/mt/73369237/4520388
Group Owner: cip-dev+owner@lists.cip-project.org
Unsubscribe: https://lists.cip-project.org/g/cip-dev/leave/8129055/727948398/xyzzy  [cip-dev@archiver.kernel.org]
-=-=-=-=-=-=-=-=-=-=-=-

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [cip-dev] [PATCH 4.4.y-cip 3/3] cpufreq: ti: Add cpufreq driver to determine available OPPs at runtime
  2020-05-01  9:31 ` [cip-dev] [PATCH 4.4.y-cip 3/3] cpufreq: ti: Add cpufreq driver to determine available OPPs at runtime Pavel Machek
@ 2020-05-03 19:09   ` Nobuhiro Iwamatsu
  2020-05-05 11:05     ` johnsonch.chen@moxa.com
  0 siblings, 1 reply; 4+ messages in thread
From: Nobuhiro Iwamatsu @ 2020-05-03 19:09 UTC (permalink / raw)
  To: pavel, JohnsonCH.Chen; +Cc: cip-dev

[-- Attachment #1: Type: text/plain, Size: 3569 bytes --]

Hi,

> -----Original Message-----
> From: Pavel Machek [mailto:pavel@denx.de]
> Sent: Friday, May 1, 2020 6:32 PM
> To: Johnson CH Chen (陳昭勳) <JohnsonCH.Chen@moxa.com>
> Cc: cip-dev@lists.cip-project.org; iwamatsu nobuhiro(岩松 信洋 □SWC◯ACT)
> <nobuhiro1.iwamatsu@toshiba.co.jp>; pavel@denx.de
> Subject: Re: [PATCH 4.4.y-cip 3/3] cpufreq: ti: Add cpufreq driver to determine available OPPs at runtime
> 
> Hi!
> 
> > From: Dave Gerlach <d-gerlach@ti.com>
> >
> > commit e13cf046cd70894393a1085ca39da7ef751353fb upstream
> >
> > Some TI SoCs, like those in the AM335x, AM437x, DRA7x, and AM57x families,
> > have different OPPs available for the MPU depending on which specific
> > variant of the SoC is in use. This can be determined through use of the
> > revision and an eFuse register present in the silicon. Introduce a
> > ti-cpufreq driver that can read the aformentioned values and provide
> > them as version matching data to the opp framework. Through this the
> > opp-supported-hw dt binding that is part of the operating-points-v2
> > table can be used to indicate availability of OPPs for each device.
> >
> > This driver also creates the "cpufreq-dt" platform_device after passing
> > the version matching data to the OPP framework so that the cpufreq-dt
> > handles the actual cpufreq implementation. Even without the necessary
> > data to pass the version matching data the driver will still create this
> > device to maintain backwards compatibility with operating-points v1
> > tables.
> >
> > index 000000000000..3dbf57164ded
> > --- /dev/null
> > +++ b/drivers/cpufreq/ti-cpufreq.c
> > @@ -0,0 +1,272 @@
> > +/*
> > + * TI CPUFreq/OPP hw-supported driver
> > + *
> > + * Copyright (C) 2016-2017 Texas Instruments, Inc.
> > + *	 Dave Gerlach <d-gerlach@ti.com>
> > + *
> > + * 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.
> 
> I guess SPDX would be better than this.
> 
> > +static int ti_cpufreq_init(void)
> > +{
> ...
> > +	/*
> > +	 * OPPs determine whether or not they are supported based on
> > +	 * two metrics:
> > +	 *	0 - SoC Revision
> > +	 *	1 - eFuse value
> > +	 */
> > +	ret = ti_cpufreq_get_rev(opp_data, &version[0]);
> > +	if (ret)
> > +		goto fail_put_node;
> > +
> > +	ret = ti_cpufreq_get_efuse(opp_data, &version[1]);
> > +	if (ret)
> > +		goto fail_put_node;
> > +
> > +	of_node_put(opp_data->opp_node);
> > +
> > +	ret = dev_pm_opp_set_supported_hw(opp_data->cpu_dev,
> > +						version, VERSION_COUNT);
> > +	if (ret) {
> > +		dev_err(opp_data->cpu_dev,
> > +			"Failed to set supported hardware\n");
> > +		goto fail_put_node;
> > +	}
> 
> This should be "return err", we have already put the node few lines
> above.

Oh, thanks for your pointing.
we also need to backport the following patche:
  9a6e91d08e7707baa2f824257342ca7efcb199bc

And there are other issues too, so I think the following patches are also needed.
05829d9431df1bf6de98679fbcfbad282c1c55a4
e5d295b06d69a1924665a16a4987be475addd00f
248aefdcc3a7e0cfbd014946b4dead63e750e71b

Please check these.

> 
> > +register_cpufreq_dt:
> > +	platform_device_register_simple("cpufreq-dt", -1, NULL, 0);
> > +
> > +	return 0;
> > +
> > +fail_put_node:
> > +	of_node_put(opp_data->opp_node);
> > +
> > +	return ret;
> > +}
> 
> Best regards,
> 								Pavel

Best regards,
  Nobuhiro


[-- Attachment #2: Type: text/plain, Size: 419 bytes --]

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#4610): https://lists.cip-project.org/g/cip-dev/message/4610
Mute This Topic: https://lists.cip-project.org/mt/73369237/4520388
Group Owner: cip-dev+owner@lists.cip-project.org
Unsubscribe: https://lists.cip-project.org/g/cip-dev/leave/8129055/727948398/xyzzy  [cip-dev@archiver.kernel.org]
-=-=-=-=-=-=-=-=-=-=-=-

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [cip-dev] [PATCH 4.4.y-cip 3/3] cpufreq: ti: Add cpufreq driver to determine available OPPs at runtime
  2020-05-03 19:09   ` Nobuhiro Iwamatsu
@ 2020-05-05 11:05     ` johnsonch.chen@moxa.com
  0 siblings, 0 replies; 4+ messages in thread
From: johnsonch.chen@moxa.com @ 2020-05-05 11:05 UTC (permalink / raw)
  To: nobuhiro1.iwamatsu, pavel; +Cc: cip-dev

[-- Attachment #1: Type: text/plain, Size: 4300 bytes --]

Hi,

>
> Hi,
>
> > -----Original Message-----
> > From: Pavel Machek [mailto:pavel@denx.de]
> > Sent: Friday, May 1, 2020 6:32 PM
> > To: Johnson CH Chen (陳昭勳) <JohnsonCH.Chen@moxa.com>
> > Cc: cip-dev@lists.cip-project.org; iwamatsu nobuhiro(岩松 信洋 □SWC◯ACT)
> > <nobuhiro1.iwamatsu@toshiba.co.jp>; pavel@denx.de
> > Subject: Re: [PATCH 4.4.y-cip 3/3] cpufreq: ti: Add cpufreq driver 
> > to determine available OPPs at runtime
> >
> > Hi!
> >
> > > From: Dave Gerlach <d-gerlach@ti.com>
> > >
> > > commit e13cf046cd70894393a1085ca39da7ef751353fb upstream
> > >
> > > Some TI SoCs, like those in the AM335x, AM437x, DRA7x, and AM57x 
> > > families, have different OPPs available for the MPU depending on 
> > > which specific variant of the SoC is in use. This can be 
> > > determined through use of the revision and an eFuse register 
> > > present in the silicon. Introduce a ti-cpufreq driver that can 
> > > read the aformentioned values and provide them as version matching 
> > > data to the opp framework. Through this the opp-supported-hw dt 
> > > binding that is part of the operating-points-v2 table can be used to indicate availability of OPPs for each device.
> > >
> > > This driver also creates the "cpufreq-dt" platform_device after 
> > > passing the version matching data to the OPP framework so that the 
> > > cpufreq-dt handles the actual cpufreq implementation. Even without 
> > > the necessary data to pass the version matching data the driver 
> > > will still create this device to maintain backwards compatibility 
> > > with operating-points v1 tables.
> > >
> > > index 000000000000..3dbf57164ded
> > > --- /dev/null
> > > +++ b/drivers/cpufreq/ti-cpufreq.c
> > > @@ -0,0 +1,272 @@
> > > +/*
> > > + * TI CPUFreq/OPP hw-supported driver
> > > + *
> > > + * Copyright (C) 2016-2017 Texas Instruments, Inc.
> > > + *  Dave Gerlach <d-gerlach@ti.com>
> > > + *
> > > + * 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.
> >
> > I guess SPDX would be better than this.
> >
> > > +static int ti_cpufreq_init(void)
> > > +{
> > ...
> > > +   /*
> > > +    * OPPs determine whether or not they are supported based on
> > > +    * two metrics:
> > > +    *      0 - SoC Revision
> > > +    *      1 - eFuse value
> > > +    */
> > > +   ret = ti_cpufreq_get_rev(opp_data, &version[0]);
> > > +   if (ret)
> > > +           goto fail_put_node;
> > > +
> > > +   ret = ti_cpufreq_get_efuse(opp_data, &version[1]);
> > > +   if (ret)
> > > +           goto fail_put_node;
> > > +
> > > +   of_node_put(opp_data->opp_node);
> > > +
> > > +   ret = dev_pm_opp_set_supported_hw(opp_data->cpu_dev,
> > > +                                           version, VERSION_COUNT);
> > > +   if (ret) {
> > > +           dev_err(opp_data->cpu_dev,
> > > +                   "Failed to set supported hardware\n");
> > > +           goto fail_put_node;
> > > +   }
> >
> > This should be "return err", we have already put the node few lines 
> > above.
>
> Oh, thanks for your pointing.
> we also need to backport the following patche:
>   9a6e91d08e7707baa2f824257342ca7efcb199bc
>
This patch can fix double-free issue, thanks your suggestion!

> And there are other issues too, so I think the following patches are also needed.
> 05829d9431df1bf6de98679fbcfbad282c1c55a4
> e5d295b06d69a1924665a16a4987be475addd00f
> 248aefdcc3a7e0cfbd014946b4dead63e750e71b
>
> Please check these.
>
These three patches can solve other issues for ti cpufreq driver.
Besides, ti cpufreq driver should be SPDX, and it seems no related patch in mainline kernel.
I will include above patches and SPDX in patch series v2.

> >
> > > +register_cpufreq_dt:
> > > +   platform_device_register_simple("cpufreq-dt", -1, NULL, 0);
> > > +
> > > +   return 0;
> > > +
> > > +fail_put_node:
> > > +   of_node_put(opp_data->opp_node);
> > > +
> > > +   return ret;
> > > +}
> >
> > Best regards,
> >                                                               Pavel
>
> Best regards,
>   Nobuhiro
>

Best regards,
Johnson

[-- Attachment #2: Type: text/plain, Size: 419 bytes --]

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#4614): https://lists.cip-project.org/g/cip-dev/message/4614
Mute This Topic: https://lists.cip-project.org/mt/73369237/4520388
Group Owner: cip-dev+owner@lists.cip-project.org
Unsubscribe: https://lists.cip-project.org/g/cip-dev/leave/8129055/727948398/xyzzy  [cip-dev@archiver.kernel.org]
-=-=-=-=-=-=-=-=-=-=-=-

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [cip-dev] [PATCH 4.4.y-cip 3/3] cpufreq: ti: Add cpufreq driver to determine available OPPs at runtime
@ 2020-04-30  3:34 Johnson CH Chen (陳昭勳)
  0 siblings, 0 replies; 4+ messages in thread
From: Johnson CH Chen (陳昭勳) @ 2020-04-30  3:34 UTC (permalink / raw)
  To: cip-dev, nobuhiro1.iwamatsu, pavel

From: Dave Gerlach <d-gerlach@ti.com>
 
commit e13cf046cd70894393a1085ca39da7ef751353fb upstream

Some TI SoCs, like those in the AM335x, AM437x, DRA7x, and AM57x families,
have different OPPs available for the MPU depending on which specific
variant of the SoC is in use. This can be determined through use of the
revision and an eFuse register present in the silicon. Introduce a
ti-cpufreq driver that can read the aformentioned values and provide
them as version matching data to the opp framework. Through this the
opp-supported-hw dt binding that is part of the operating-points-v2
table can be used to indicate availability of OPPs for each device.

This driver also creates the "cpufreq-dt" platform_device after passing
the version matching data to the OPP framework so that the cpufreq-dt
handles the actual cpufreq implementation. Even without the necessary
data to pass the version matching data the driver will still create this
device to maintain backwards compatibility with operating-points v1
tables.

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Dave Gerlach <d-gerlach@ti.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
[Johnson Chen: Use original api _of_get_opp_desc_node() and assign returned 
value of dev_pm_opp_set_supported_hw() to ret directly]
Signed-off-by: Johnson Chen <johnsonch.chen@moxa.com>
Signed-off-by: Victor Yu <victor.yu@moxa.com>
---
 drivers/base/power/opp/core.c |   1 +
 drivers/cpufreq/Kconfig.arm   |  11 ++
 drivers/cpufreq/Makefile      |   1 +
 drivers/cpufreq/ti-cpufreq.c  | 272 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/pm_opp.h        |   7 ++
 5 files changed, 292 insertions(+)
 create mode 100644 drivers/cpufreq/ti-cpufreq.c

diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c
index c53a3e261306..4035d282d6df 100644
--- a/drivers/base/power/opp/core.c
+++ b/drivers/base/power/opp/core.c
@@ -1325,6 +1325,7 @@ struct device_node *_of_get_opp_desc_node(struct device *dev)
 
 	return of_parse_phandle(dev->of_node, "operating-points-v2", 0);
 }
+EXPORT_SYMBOL_GPL(_of_get_opp_desc_node);
 
 /* Initializes OPP tables based on new bindings */
 static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np)
diff --git a/drivers/cpufreq/Kconfig.arm b/drivers/cpufreq/Kconfig.arm
index eed1e073d96d..6b834112d857 100644
--- a/drivers/cpufreq/Kconfig.arm
+++ b/drivers/cpufreq/Kconfig.arm
@@ -231,6 +231,17 @@ config ARM_TEGRA124_CPUFREQ
 	help
 	  This adds the CPUFreq driver support for Tegra124 SOCs.
 
+config ARM_TI_CPUFREQ
+	bool "Texas Instruments CPUFreq support"
+	depends on ARCH_OMAP2PLUS
+	help
+	  This driver enables valid OPPs on the running platform based on
+	  values contained within the SoC in use. Enable this in order to
+	  use the cpufreq-dt driver on all Texas Instruments platforms that
+	  provide dt based operating-points-v2 tables with opp-supported-hw
+	  data provided. Required for cpufreq support on AM335x, AM437x,
+	  DRA7x, and AM57x platforms.
+
 config ARM_PXA2xx_CPUFREQ
 	tristate "Intel PXA2xx CPUfreq driver"
 	depends on PXA27x || PXA25x
diff --git a/drivers/cpufreq/Makefile b/drivers/cpufreq/Makefile
index c0af1a1281c8..6e889596d9a1 100644
--- a/drivers/cpufreq/Makefile
+++ b/drivers/cpufreq/Makefile
@@ -75,6 +75,7 @@ obj-$(CONFIG_ARM_SCPI_CPUFREQ)		+= scpi-cpufreq.o
 obj-$(CONFIG_ARM_SPEAR_CPUFREQ)		+= spear-cpufreq.o
 obj-$(CONFIG_ARM_TEGRA20_CPUFREQ)	+= tegra20-cpufreq.o
 obj-$(CONFIG_ARM_TEGRA124_CPUFREQ)	+= tegra124-cpufreq.o
+obj-$(CONFIG_ARM_TI_CPUFREQ)		+= ti-cpufreq.o
 obj-$(CONFIG_ARM_VEXPRESS_SPC_CPUFREQ)	+= vexpress-spc-cpufreq.o
 obj-$(CONFIG_ACPI_CPPC_CPUFREQ) += cppc_cpufreq.o
 
diff --git a/drivers/cpufreq/ti-cpufreq.c b/drivers/cpufreq/ti-cpufreq.c
new file mode 100644
index 000000000000..3dbf57164ded
--- /dev/null
+++ b/drivers/cpufreq/ti-cpufreq.c
@@ -0,0 +1,272 @@
+/*
+ * TI CPUFreq/OPP hw-supported driver
+ *
+ * Copyright (C) 2016-2017 Texas Instruments, Inc.
+ *	 Dave Gerlach <d-gerlach@ti.com>
+ *
+ * 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 in the hope that 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.
+ */
+
+#include <linux/cpu.h>
+#include <linux/io.h>
+#include <linux/mfd/syscon.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_platform.h>
+#include <linux/pm_opp.h>
+#include <linux/regmap.h>
+#include <linux/slab.h>
+
+#define REVISION_MASK				0xF
+#define REVISION_SHIFT				28
+
+#define AM33XX_800M_ARM_MPU_MAX_FREQ		0x1E2F
+#define AM43XX_600M_ARM_MPU_MAX_FREQ		0xFFA
+
+#define DRA7_EFUSE_HAS_OD_MPU_OPP		11
+#define DRA7_EFUSE_HAS_HIGH_MPU_OPP		15
+#define DRA7_EFUSE_HAS_ALL_MPU_OPP		23
+
+#define DRA7_EFUSE_NOM_MPU_OPP			BIT(0)
+#define DRA7_EFUSE_OD_MPU_OPP			BIT(1)
+#define DRA7_EFUSE_HIGH_MPU_OPP			BIT(2)
+
+#define VERSION_COUNT				2
+
+struct ti_cpufreq_data;
+
+struct ti_cpufreq_soc_data {
+	unsigned long (*efuse_xlate)(struct ti_cpufreq_data *opp_data,
+				     unsigned long efuse);
+	unsigned long efuse_fallback;
+	unsigned long efuse_offset;
+	unsigned long efuse_mask;
+	unsigned long efuse_shift;
+	unsigned long rev_offset;
+};
+
+struct ti_cpufreq_data {
+	struct device *cpu_dev;
+	struct device_node *opp_node;
+	struct regmap *syscon;
+	const struct ti_cpufreq_soc_data *soc_data;
+};
+
+static unsigned long amx3_efuse_xlate(struct ti_cpufreq_data *opp_data,
+				      unsigned long efuse)
+{
+	if (!efuse)
+		efuse = opp_data->soc_data->efuse_fallback;
+	/* AM335x and AM437x use "OPP disable" bits, so invert */
+	return ~efuse;
+}
+
+static unsigned long dra7_efuse_xlate(struct ti_cpufreq_data *opp_data,
+				      unsigned long efuse)
+{
+	unsigned long calculated_efuse = DRA7_EFUSE_NOM_MPU_OPP;
+
+	/*
+	 * The efuse on dra7 and am57 parts contains a specific
+	 * value indicating the highest available OPP.
+	 */
+
+	switch (efuse) {
+	case DRA7_EFUSE_HAS_ALL_MPU_OPP:
+	case DRA7_EFUSE_HAS_HIGH_MPU_OPP:
+		calculated_efuse |= DRA7_EFUSE_HIGH_MPU_OPP;
+	case DRA7_EFUSE_HAS_OD_MPU_OPP:
+		calculated_efuse |= DRA7_EFUSE_OD_MPU_OPP;
+	}
+
+	return calculated_efuse;
+}
+
+static struct ti_cpufreq_soc_data am3x_soc_data = {
+	.efuse_xlate = amx3_efuse_xlate,
+	.efuse_fallback = AM33XX_800M_ARM_MPU_MAX_FREQ,
+	.efuse_offset = 0x07fc,
+	.efuse_mask = 0x1fff,
+	.rev_offset = 0x600,
+};
+
+static struct ti_cpufreq_soc_data am4x_soc_data = {
+	.efuse_xlate = amx3_efuse_xlate,
+	.efuse_fallback = AM43XX_600M_ARM_MPU_MAX_FREQ,
+	.efuse_offset = 0x0610,
+	.efuse_mask = 0x3f,
+	.rev_offset = 0x600,
+};
+
+static struct ti_cpufreq_soc_data dra7_soc_data = {
+	.efuse_xlate = dra7_efuse_xlate,
+	.efuse_offset = 0x020c,
+	.efuse_mask = 0xf80000,
+	.efuse_shift = 19,
+	.rev_offset = 0x204,
+};
+
+/**
+ * ti_cpufreq_get_efuse() - Parse and return efuse value present on SoC
+ * @opp_data: pointer to ti_cpufreq_data context
+ * @efuse_value: Set to the value parsed from efuse
+ *
+ * Returns error code if efuse not read properly.
+ */
+static int ti_cpufreq_get_efuse(struct ti_cpufreq_data *opp_data,
+				u32 *efuse_value)
+{
+	struct device *dev = opp_data->cpu_dev;
+	u32 efuse;
+	int ret;
+
+	ret = regmap_read(opp_data->syscon, opp_data->soc_data->efuse_offset,
+			  &efuse);
+	if (ret) {
+		dev_err(dev,
+			"Failed to read the efuse value from syscon: %d\n",
+			ret);
+		return ret;
+	}
+
+	efuse = (efuse & opp_data->soc_data->efuse_mask);
+	efuse >>= opp_data->soc_data->efuse_shift;
+
+	*efuse_value = opp_data->soc_data->efuse_xlate(opp_data, efuse);
+
+	return 0;
+}
+
+/**
+ * ti_cpufreq_get_rev() - Parse and return rev value present on SoC
+ * @opp_data: pointer to ti_cpufreq_data context
+ * @revision_value: Set to the value parsed from revision register
+ *
+ * Returns error code if revision not read properly.
+ */
+static int ti_cpufreq_get_rev(struct ti_cpufreq_data *opp_data,
+			      u32 *revision_value)
+{
+	struct device *dev = opp_data->cpu_dev;
+	u32 revision;
+	int ret;
+
+	ret = regmap_read(opp_data->syscon, opp_data->soc_data->rev_offset,
+			  &revision);
+	if (ret) {
+		dev_err(dev,
+			"Failed to read the revision number from syscon: %d\n",
+			ret);
+		return ret;
+	}
+
+	*revision_value = BIT((revision >> REVISION_SHIFT) & REVISION_MASK);
+
+	return 0;
+}
+
+static int ti_cpufreq_setup_syscon_register(struct ti_cpufreq_data *opp_data)
+{
+	struct device *dev = opp_data->cpu_dev;
+	struct device_node *np = opp_data->opp_node;
+
+	opp_data->syscon = syscon_regmap_lookup_by_phandle(np,
+							"syscon");
+	if (IS_ERR(opp_data->syscon)) {
+		dev_err(dev,
+			"\"syscon\" is missing, cannot use OPPv2 table.\n");
+		return PTR_ERR(opp_data->syscon);
+	}
+
+	return 0;
+}
+
+static const struct of_device_id ti_cpufreq_of_match[] = {
+	{ .compatible = "ti,am33xx", .data = &am3x_soc_data, },
+	{ .compatible = "ti,am4372", .data = &am4x_soc_data, },
+	{ .compatible = "ti,dra7", .data = &dra7_soc_data },
+	{},
+};
+
+static int ti_cpufreq_init(void)
+{
+	u32 version[VERSION_COUNT];
+	struct device_node *np;
+	const struct of_device_id *match;
+	struct ti_cpufreq_data *opp_data;
+	int ret;
+
+	np = of_find_node_by_path("/");
+	match = of_match_node(ti_cpufreq_of_match, np);
+	if (!match)
+		return -ENODEV;
+
+	opp_data = kzalloc(sizeof(*opp_data), GFP_KERNEL);
+	if (!opp_data)
+		return -ENOMEM;
+
+	opp_data->soc_data = match->data;
+
+	opp_data->cpu_dev = get_cpu_device(0);
+	if (!opp_data->cpu_dev) {
+		pr_err("%s: Failed to get device for CPU0\n", __func__);
+		return -ENODEV;
+	}
+
+	opp_data->opp_node = _of_get_opp_desc_node(opp_data->cpu_dev);
+	if (!opp_data->opp_node) {
+		dev_info(opp_data->cpu_dev,
+			 "OPP-v2 not supported, cpufreq-dt will attempt to use legacy tables.\n");
+		goto register_cpufreq_dt;
+	}
+
+	ret = ti_cpufreq_setup_syscon_register(opp_data);
+	if (ret)
+		goto fail_put_node;
+
+	/*
+	 * OPPs determine whether or not they are supported based on
+	 * two metrics:
+	 *	0 - SoC Revision
+	 *	1 - eFuse value
+	 */
+	ret = ti_cpufreq_get_rev(opp_data, &version[0]);
+	if (ret)
+		goto fail_put_node;
+
+	ret = ti_cpufreq_get_efuse(opp_data, &version[1]);
+	if (ret)
+		goto fail_put_node;
+
+	of_node_put(opp_data->opp_node);
+
+	ret = dev_pm_opp_set_supported_hw(opp_data->cpu_dev,
+						version, VERSION_COUNT);
+	if (ret) {
+		dev_err(opp_data->cpu_dev,
+			"Failed to set supported hardware\n");
+		goto fail_put_node;
+	}
+
+register_cpufreq_dt:
+	platform_device_register_simple("cpufreq-dt", -1, NULL, 0);
+
+	return 0;
+
+fail_put_node:
+	of_node_put(opp_data->opp_node);
+
+	return ret;
+}
+module_init(ti_cpufreq_init);
+
+MODULE_DESCRIPTION("TI CPUFreq/OPP hw-supported driver");
+MODULE_AUTHOR("Dave Gerlach <d-gerlach@ti.com>");
+MODULE_LICENSE("GPL v2");
diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h
index 3a85110242f0..6c6348692cd4 100644
--- a/include/linux/pm_opp.h
+++ b/include/linux/pm_opp.h
@@ -151,6 +151,8 @@ int dev_pm_opp_of_cpumask_add_table(cpumask_var_t cpumask);
 void dev_pm_opp_of_cpumask_remove_table(cpumask_var_t cpumask);
 int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, cpumask_var_t cpumask);
 int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, cpumask_var_t cpumask);
+struct device_node *_of_get_opp_desc_node(struct device *dev);
+
 #else
 static inline int dev_pm_opp_of_add_table(struct device *dev)
 {
@@ -179,6 +181,11 @@ static inline int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, cpumask_va
 {
 	return -ENOSYS;
 }
+static inline struct device_node *_of_get_opp_desc_node(struct device *dev)
+{
+	return NULL;
+}
+
 #endif
 
 #endif		/* __LINUX_OPP_H__ */
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-05-05 11:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <HK2PR01MB3281A0A027BAB0F4F036AC7AFAAA0@HK2PR01MB3281.apcprd01.prod.exchangelabs.com>
2020-05-01  9:31 ` [cip-dev] [PATCH 4.4.y-cip 3/3] cpufreq: ti: Add cpufreq driver to determine available OPPs at runtime Pavel Machek
2020-05-03 19:09   ` Nobuhiro Iwamatsu
2020-05-05 11:05     ` johnsonch.chen@moxa.com
2020-04-30  3:34 Johnson CH Chen (陳昭勳)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).