Re: [PATCH 2/2] cpufreq: ti: Add cpufreq driver to determine available OPPs at runtime

2016-05-19 Thread Dave Gerlach

On 05/18/2016 11:39 PM, Viresh Kumar wrote:

On 18-05-16, 18:30, Dave Gerlach wrote:

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.

Signed-off-by: Dave Gerlach 
---
  drivers/cpufreq/Kconfig.arm  |  11 ++
  drivers/cpufreq/Makefile |   1 +
  drivers/cpufreq/ti-cpufreq.c | 254 +++
  3 files changed, 266 insertions(+)
  create mode 100644 drivers/cpufreq/ti-cpufreq.c

diff --git a/drivers/cpufreq/Kconfig.arm b/drivers/cpufreq/Kconfig.arm
index d89b8afe23b6..0dea6849ac3e 100644
--- a/drivers/cpufreq/Kconfig.arm
+++ b/drivers/cpufreq/Kconfig.arm
@@ -234,6 +234,17 @@ config ARM_TEGRA124_CPUFREQ
help
  This adds the CPUFreq driver support for Tegra124 SOCs.

+config ARM_TI_CPUFREQ
+   tristate "Texas Instruments CPUFreq support"


You sure you want to get it compiled as a module? And don't provide
module_exit() at all?


I thought about this for a while, and I was going to make it bool but 
decided to model it after what has already been accepted (sti-cpufreq). 
Wasn't sure what preferred path is, but I will go ahead and switch this 
to bool for this driver as I think that makes the most sense.





+   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 0a9b6a093646..5b1b6ec0a9f0 100644
--- a/drivers/cpufreq/Makefile
+++ b/drivers/cpufreq/Makefile
@@ -77,6 +77,7 @@ obj-$(CONFIG_ARM_SPEAR_CPUFREQ)   += 
spear-cpufreq.o
  obj-$(CONFIG_ARM_STI_CPUFREQ) += sti-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
  obj-$(CONFIG_MACH_MVEBU_V7)   += mvebu-cpufreq.o
diff --git a/drivers/cpufreq/ti-cpufreq.c b/drivers/cpufreq/ti-cpufreq.c
new file mode 100644
index ..e47b452aadd0
--- /dev/null
+++ b/drivers/cpufreq/ti-cpufreq.c
@@ -0,0 +1,254 @@
+/*
+ * TI CPUFreq/OPP hw-supported driver
+ *
+ * Copyright (C) 2016 Texas Instruments, Inc.
+ *  Dave Gerlach 
+ *
+ * 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 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define REVISION_MASK  (0xF << 28)


Use below shift-mask here ?


Yes, but this will change due to later change where this will actually 
be used.





+#define REVISION_SHIFT 28
+
+#define DRA7_EFUSE_HAS_OD_MPU_OPP  11
+#define DRA7_EFUSE_HAS_HIGH_MPU_OPP15
+#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_OPPBIT(2)
+
+#define VERSION_COUNT  2
+
+static struct ti_cpufreq_data {
+   struct device *cpu;
+   struct regmap *opp_efuse;
+   struct regmap *revision;
+} opp_data;
+
+static struct ti_cpufreq_soc_data {
+   unsigned 

Re: [PATCH 2/2] cpufreq: ti: Add cpufreq driver to determine available OPPs at runtime

2016-05-19 Thread Dave Gerlach

On 05/18/2016 11:39 PM, Viresh Kumar wrote:

On 18-05-16, 18:30, Dave Gerlach wrote:

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.

Signed-off-by: Dave Gerlach 
---
  drivers/cpufreq/Kconfig.arm  |  11 ++
  drivers/cpufreq/Makefile |   1 +
  drivers/cpufreq/ti-cpufreq.c | 254 +++
  3 files changed, 266 insertions(+)
  create mode 100644 drivers/cpufreq/ti-cpufreq.c

diff --git a/drivers/cpufreq/Kconfig.arm b/drivers/cpufreq/Kconfig.arm
index d89b8afe23b6..0dea6849ac3e 100644
--- a/drivers/cpufreq/Kconfig.arm
+++ b/drivers/cpufreq/Kconfig.arm
@@ -234,6 +234,17 @@ config ARM_TEGRA124_CPUFREQ
help
  This adds the CPUFreq driver support for Tegra124 SOCs.

+config ARM_TI_CPUFREQ
+   tristate "Texas Instruments CPUFreq support"


You sure you want to get it compiled as a module? And don't provide
module_exit() at all?


I thought about this for a while, and I was going to make it bool but 
decided to model it after what has already been accepted (sti-cpufreq). 
Wasn't sure what preferred path is, but I will go ahead and switch this 
to bool for this driver as I think that makes the most sense.





+   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 0a9b6a093646..5b1b6ec0a9f0 100644
--- a/drivers/cpufreq/Makefile
+++ b/drivers/cpufreq/Makefile
@@ -77,6 +77,7 @@ obj-$(CONFIG_ARM_SPEAR_CPUFREQ)   += 
spear-cpufreq.o
  obj-$(CONFIG_ARM_STI_CPUFREQ) += sti-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
  obj-$(CONFIG_MACH_MVEBU_V7)   += mvebu-cpufreq.o
diff --git a/drivers/cpufreq/ti-cpufreq.c b/drivers/cpufreq/ti-cpufreq.c
new file mode 100644
index ..e47b452aadd0
--- /dev/null
+++ b/drivers/cpufreq/ti-cpufreq.c
@@ -0,0 +1,254 @@
+/*
+ * TI CPUFreq/OPP hw-supported driver
+ *
+ * Copyright (C) 2016 Texas Instruments, Inc.
+ *  Dave Gerlach 
+ *
+ * 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 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define REVISION_MASK  (0xF << 28)


Use below shift-mask here ?


Yes, but this will change due to later change where this will actually 
be used.





+#define REVISION_SHIFT 28
+
+#define DRA7_EFUSE_HAS_OD_MPU_OPP  11
+#define DRA7_EFUSE_HAS_HIGH_MPU_OPP15
+#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_OPPBIT(2)
+
+#define VERSION_COUNT  2
+
+static struct ti_cpufreq_data {
+   struct device *cpu;
+   struct regmap *opp_efuse;
+   struct regmap *revision;
+} opp_data;
+
+static struct ti_cpufreq_soc_data {
+   unsigned long (*efuse_xlate)(unsigned long 

Re: [PATCH 2/2] cpufreq: ti: Add cpufreq driver to determine available OPPs at runtime

2016-05-18 Thread Viresh Kumar
On 18-05-16, 18:30, Dave Gerlach wrote:
> 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.
> 
> Signed-off-by: Dave Gerlach 
> ---
>  drivers/cpufreq/Kconfig.arm  |  11 ++
>  drivers/cpufreq/Makefile |   1 +
>  drivers/cpufreq/ti-cpufreq.c | 254 
> +++
>  3 files changed, 266 insertions(+)
>  create mode 100644 drivers/cpufreq/ti-cpufreq.c
> 
> diff --git a/drivers/cpufreq/Kconfig.arm b/drivers/cpufreq/Kconfig.arm
> index d89b8afe23b6..0dea6849ac3e 100644
> --- a/drivers/cpufreq/Kconfig.arm
> +++ b/drivers/cpufreq/Kconfig.arm
> @@ -234,6 +234,17 @@ config ARM_TEGRA124_CPUFREQ
>   help
> This adds the CPUFreq driver support for Tegra124 SOCs.
>  
> +config ARM_TI_CPUFREQ
> + tristate "Texas Instruments CPUFreq support"

You sure you want to get it compiled as a module? And don't provide
module_exit() at all?

> + 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 0a9b6a093646..5b1b6ec0a9f0 100644
> --- a/drivers/cpufreq/Makefile
> +++ b/drivers/cpufreq/Makefile
> @@ -77,6 +77,7 @@ obj-$(CONFIG_ARM_SPEAR_CPUFREQ) += 
> spear-cpufreq.o
>  obj-$(CONFIG_ARM_STI_CPUFREQ)+= sti-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
>  obj-$(CONFIG_MACH_MVEBU_V7)  += mvebu-cpufreq.o
> diff --git a/drivers/cpufreq/ti-cpufreq.c b/drivers/cpufreq/ti-cpufreq.c
> new file mode 100644
> index ..e47b452aadd0
> --- /dev/null
> +++ b/drivers/cpufreq/ti-cpufreq.c
> @@ -0,0 +1,254 @@
> +/*
> + * TI CPUFreq/OPP hw-supported driver
> + *
> + * Copyright (C) 2016 Texas Instruments, Inc.
> + *Dave Gerlach 
> + *
> + * 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 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define REVISION_MASK(0xF << 28)

Use below shift-mask here ?

> +#define REVISION_SHIFT   28
> +
> +#define DRA7_EFUSE_HAS_OD_MPU_OPP11
> +#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_OPPBIT(1)
> +#define DRA7_EFUSE_HIGH_MPU_OPP  BIT(2)
> +
> +#define VERSION_COUNT2
> +
> +static struct ti_cpufreq_data {
> + struct device *cpu;
> + struct regmap *opp_efuse;
> + struct regmap *revision;
> +} opp_data;
> +
> +static struct ti_cpufreq_soc_data {
> + unsigned long (*efuse_xlate)(unsigned long efuse);
> +} *soc_data;
> +
> +static unsigned long amx3_efuse_xlate(unsigned long efuse)
> +{
> + /* AM335x and AM437x use "OPP disable" bits, so invert */
> + return ~efuse;
> +}
> 

Re: [PATCH 2/2] cpufreq: ti: Add cpufreq driver to determine available OPPs at runtime

2016-05-18 Thread Viresh Kumar
On 18-05-16, 18:30, Dave Gerlach wrote:
> 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.
> 
> Signed-off-by: Dave Gerlach 
> ---
>  drivers/cpufreq/Kconfig.arm  |  11 ++
>  drivers/cpufreq/Makefile |   1 +
>  drivers/cpufreq/ti-cpufreq.c | 254 
> +++
>  3 files changed, 266 insertions(+)
>  create mode 100644 drivers/cpufreq/ti-cpufreq.c
> 
> diff --git a/drivers/cpufreq/Kconfig.arm b/drivers/cpufreq/Kconfig.arm
> index d89b8afe23b6..0dea6849ac3e 100644
> --- a/drivers/cpufreq/Kconfig.arm
> +++ b/drivers/cpufreq/Kconfig.arm
> @@ -234,6 +234,17 @@ config ARM_TEGRA124_CPUFREQ
>   help
> This adds the CPUFreq driver support for Tegra124 SOCs.
>  
> +config ARM_TI_CPUFREQ
> + tristate "Texas Instruments CPUFreq support"

You sure you want to get it compiled as a module? And don't provide
module_exit() at all?

> + 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 0a9b6a093646..5b1b6ec0a9f0 100644
> --- a/drivers/cpufreq/Makefile
> +++ b/drivers/cpufreq/Makefile
> @@ -77,6 +77,7 @@ obj-$(CONFIG_ARM_SPEAR_CPUFREQ) += 
> spear-cpufreq.o
>  obj-$(CONFIG_ARM_STI_CPUFREQ)+= sti-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
>  obj-$(CONFIG_MACH_MVEBU_V7)  += mvebu-cpufreq.o
> diff --git a/drivers/cpufreq/ti-cpufreq.c b/drivers/cpufreq/ti-cpufreq.c
> new file mode 100644
> index ..e47b452aadd0
> --- /dev/null
> +++ b/drivers/cpufreq/ti-cpufreq.c
> @@ -0,0 +1,254 @@
> +/*
> + * TI CPUFreq/OPP hw-supported driver
> + *
> + * Copyright (C) 2016 Texas Instruments, Inc.
> + *Dave Gerlach 
> + *
> + * 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 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define REVISION_MASK(0xF << 28)

Use below shift-mask here ?

> +#define REVISION_SHIFT   28
> +
> +#define DRA7_EFUSE_HAS_OD_MPU_OPP11
> +#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_OPPBIT(1)
> +#define DRA7_EFUSE_HIGH_MPU_OPP  BIT(2)
> +
> +#define VERSION_COUNT2
> +
> +static struct ti_cpufreq_data {
> + struct device *cpu;
> + struct regmap *opp_efuse;
> + struct regmap *revision;
> +} opp_data;
> +
> +static struct ti_cpufreq_soc_data {
> + unsigned long (*efuse_xlate)(unsigned long efuse);
> +} *soc_data;
> +
> +static unsigned long amx3_efuse_xlate(unsigned long efuse)
> +{
> + /* AM335x and AM437x use "OPP disable" bits, so invert */
> + return ~efuse;
> +}
> +
> +static unsigned long 

[PATCH 2/2] cpufreq: ti: Add cpufreq driver to determine available OPPs at runtime

2016-05-18 Thread Dave Gerlach
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.

Signed-off-by: Dave Gerlach 
---
 drivers/cpufreq/Kconfig.arm  |  11 ++
 drivers/cpufreq/Makefile |   1 +
 drivers/cpufreq/ti-cpufreq.c | 254 +++
 3 files changed, 266 insertions(+)
 create mode 100644 drivers/cpufreq/ti-cpufreq.c

diff --git a/drivers/cpufreq/Kconfig.arm b/drivers/cpufreq/Kconfig.arm
index d89b8afe23b6..0dea6849ac3e 100644
--- a/drivers/cpufreq/Kconfig.arm
+++ b/drivers/cpufreq/Kconfig.arm
@@ -234,6 +234,17 @@ config ARM_TEGRA124_CPUFREQ
help
  This adds the CPUFreq driver support for Tegra124 SOCs.
 
+config ARM_TI_CPUFREQ
+   tristate "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 0a9b6a093646..5b1b6ec0a9f0 100644
--- a/drivers/cpufreq/Makefile
+++ b/drivers/cpufreq/Makefile
@@ -77,6 +77,7 @@ obj-$(CONFIG_ARM_SPEAR_CPUFREQ)   += 
spear-cpufreq.o
 obj-$(CONFIG_ARM_STI_CPUFREQ)  += sti-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
 obj-$(CONFIG_MACH_MVEBU_V7)+= mvebu-cpufreq.o
diff --git a/drivers/cpufreq/ti-cpufreq.c b/drivers/cpufreq/ti-cpufreq.c
new file mode 100644
index ..e47b452aadd0
--- /dev/null
+++ b/drivers/cpufreq/ti-cpufreq.c
@@ -0,0 +1,254 @@
+/*
+ * TI CPUFreq/OPP hw-supported driver
+ *
+ * Copyright (C) 2016 Texas Instruments, Inc.
+ *  Dave Gerlach 
+ *
+ * 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 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define REVISION_MASK  (0xF << 28)
+#define REVISION_SHIFT 28
+
+#define DRA7_EFUSE_HAS_OD_MPU_OPP  11
+#define DRA7_EFUSE_HAS_HIGH_MPU_OPP15
+#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_OPPBIT(2)
+
+#define VERSION_COUNT  2
+
+static struct ti_cpufreq_data {
+   struct device *cpu;
+   struct regmap *opp_efuse;
+   struct regmap *revision;
+} opp_data;
+
+static struct ti_cpufreq_soc_data {
+   unsigned long (*efuse_xlate)(unsigned long efuse);
+} *soc_data;
+
+static unsigned long amx3_efuse_xlate(unsigned long efuse)
+{
+   /* AM335x and AM437x use "OPP disable" bits, so invert */
+   return ~efuse;
+}
+
+static unsigned long dra7_efuse_xlate(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:
+  

[PATCH 2/2] cpufreq: ti: Add cpufreq driver to determine available OPPs at runtime

2016-05-18 Thread Dave Gerlach
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.

Signed-off-by: Dave Gerlach 
---
 drivers/cpufreq/Kconfig.arm  |  11 ++
 drivers/cpufreq/Makefile |   1 +
 drivers/cpufreq/ti-cpufreq.c | 254 +++
 3 files changed, 266 insertions(+)
 create mode 100644 drivers/cpufreq/ti-cpufreq.c

diff --git a/drivers/cpufreq/Kconfig.arm b/drivers/cpufreq/Kconfig.arm
index d89b8afe23b6..0dea6849ac3e 100644
--- a/drivers/cpufreq/Kconfig.arm
+++ b/drivers/cpufreq/Kconfig.arm
@@ -234,6 +234,17 @@ config ARM_TEGRA124_CPUFREQ
help
  This adds the CPUFreq driver support for Tegra124 SOCs.
 
+config ARM_TI_CPUFREQ
+   tristate "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 0a9b6a093646..5b1b6ec0a9f0 100644
--- a/drivers/cpufreq/Makefile
+++ b/drivers/cpufreq/Makefile
@@ -77,6 +77,7 @@ obj-$(CONFIG_ARM_SPEAR_CPUFREQ)   += 
spear-cpufreq.o
 obj-$(CONFIG_ARM_STI_CPUFREQ)  += sti-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
 obj-$(CONFIG_MACH_MVEBU_V7)+= mvebu-cpufreq.o
diff --git a/drivers/cpufreq/ti-cpufreq.c b/drivers/cpufreq/ti-cpufreq.c
new file mode 100644
index ..e47b452aadd0
--- /dev/null
+++ b/drivers/cpufreq/ti-cpufreq.c
@@ -0,0 +1,254 @@
+/*
+ * TI CPUFreq/OPP hw-supported driver
+ *
+ * Copyright (C) 2016 Texas Instruments, Inc.
+ *  Dave Gerlach 
+ *
+ * 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 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define REVISION_MASK  (0xF << 28)
+#define REVISION_SHIFT 28
+
+#define DRA7_EFUSE_HAS_OD_MPU_OPP  11
+#define DRA7_EFUSE_HAS_HIGH_MPU_OPP15
+#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_OPPBIT(2)
+
+#define VERSION_COUNT  2
+
+static struct ti_cpufreq_data {
+   struct device *cpu;
+   struct regmap *opp_efuse;
+   struct regmap *revision;
+} opp_data;
+
+static struct ti_cpufreq_soc_data {
+   unsigned long (*efuse_xlate)(unsigned long efuse);
+} *soc_data;
+
+static unsigned long amx3_efuse_xlate(unsigned long efuse)
+{
+   /* AM335x and AM437x use "OPP disable" bits, so invert */
+   return ~efuse;
+}
+
+static unsigned long dra7_efuse_xlate(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 |=