[PATCH v2 08/19] PM / devfreq: exynos: Add support of bus frequency of sub-blocks using passive governor

2015-12-08 Thread Chanwoo Choi
This patch adds the support of bus frequency feature for sub-blocks which share
the one power line. If each bus depends on the power line, each bus is not able
to change the voltage by oneself. To optimize the power-consumption on runtime,
some buses using the same power line should change the source clock and
regulator at the same time. So, this patch uses the passive governor to support
the bus frequency for all buses which sharing the one power line.

For example,

Exynos3250 include the two power line for AXI buses as following:
: VDD_MIF : MIF (Memory Interface) provide the DMC (Dynamic Memory Controller)
  with the power (regulator).
: VDD_INT : INT (Internal) provide the various sub-blocks with the power
  (regulator).

Each bus is included in as follwoing block. In the case of VDD_MIF, only DMC bus
use the power line. So, there is no any depencency between buese. But, in the
case of VDD_INT, various buses share the one power line of VDD_INT. We need to
make the depenency between buses. When using passive governor, there is no
problem to support the bus frequency as DVFS for all buses. One bus should be
operated as the parent bus device which gathering the current load of INT block
and then decides the new frequency with some governors except of passive
governor. After deciding the new frequency by the parent bus device, the rest
bus devices will change the each source clock according to new frequency of the
parent bus device.

- MIF (Memory Interface) block
: VDD_MIF |--- DMC

- INT (Internal) block
: VDD_INT |--- LEFTBUS (parent)
  |--- PERIL
  |--- MFC
  |--- G3D
  |--- RIGHTBUS
  |--- FSYS
  |--- LCD0
  |--- PERIR
  |--- ISP
  |--- CAM

Signed-off-by: Chanwoo Choi 
---
 drivers/devfreq/Kconfig |   1 +
 drivers/devfreq/exynos/exynos-bus.c | 170 
 2 files changed, 136 insertions(+), 35 deletions(-)

diff --git a/drivers/devfreq/Kconfig b/drivers/devfreq/Kconfig
index d03f635a93e1..88f7cc4539b8 100644
--- a/drivers/devfreq/Kconfig
+++ b/drivers/devfreq/Kconfig
@@ -79,6 +79,7 @@ config ARM_EXYNOS_BUS_DEVFREQ
bool "ARM EXYNOS Generic Memory Bus DEVFREQ Driver"
depends on ARCH_EXYNOS
select DEVFREQ_GOV_SIMPLE_ONDEMAND
+   select DEVFREQ_GOV_PASSIVE
select DEVFREQ_EVENT_EXYNOS_PPMU
select PM_DEVFREQ_EVENT
select PM_OPP
diff --git a/drivers/devfreq/exynos/exynos-bus.c 
b/drivers/devfreq/exynos/exynos-bus.c
index f1bc20839650..2efc2bba757e 100644
--- a/drivers/devfreq/exynos/exynos-bus.c
+++ b/drivers/devfreq/exynos/exynos-bus.c
@@ -91,7 +91,7 @@ static int exynos_bus_get_event(struct exynos_bus *bus,
 }
 
 /*
- * Must necessary function for devfreq governor
+ * Must necessary function for devfreq simple-ondemand governor
  */
 static int exynos_bus_target(struct device *dev, unsigned long *freq, u32 
flags)
 {
@@ -205,57 +205,74 @@ static void exynos_bus_exit(struct device *dev)
dev_pm_opp_of_remove_table(dev);
 }
 
-static int exynos_bus_parse_of(struct device_node *np,
- struct exynos_bus *bus)
+/*
+ * Must necessary function for devfreq passive governor
+ */
+static int exynos_bus_passive_target(struct device *dev, unsigned long *freq,
+   u32 flags)
 {
-   struct device *dev = bus->dev;
-   unsigned long rate;
-   int i, ret, count, size;
+   struct exynos_bus *bus = dev_get_drvdata(dev);
+   struct dev_pm_opp *new_opp;
+   unsigned long old_freq, new_freq;
+   int ret = 0;
 
-   /* Get the clock to provide each bus with source clock */
-   bus->clk = devm_clk_get(dev, "bus");
-   if (IS_ERR(bus->clk)) {
-   dev_err(dev, "failed to get bus clock\n");
-   return PTR_ERR(bus->clk);
+   /* Get new opp-bus instance according to new bus clock */
+   rcu_read_lock();
+   new_opp = devfreq_recommended_opp(dev, freq, flags);
+   if (IS_ERR_OR_NULL(new_opp)) {
+   dev_err(dev, "failed to get recommed opp instance\n");
+   rcu_read_unlock();
+   return PTR_ERR(new_opp);
}
 
-   ret = clk_prepare_enable(bus->clk);
-   if (ret < 0) {
-   dev_err(dev, "failed to get enable clock\n");
-   return ret;
-   }
+   new_freq = dev_pm_opp_get_freq(new_opp);
+   old_freq = dev_pm_opp_get_freq(bus->curr_opp);
+   rcu_read_unlock();
 
-   /* Get the freq/voltage OPP table to scale the bus frequency */
-   rcu_read_lock();
-   ret = dev_pm_opp_of_add_table(dev);
+   if (old_freq == new_freq)
+   return 0;
+
+   /* Change the frequency according to new OPP level */
+   mutex_lock(>lock);
+
+   ret = clk_set_rate(bus->clk, new_freq);
if (ret < 0) {
-   dev_err(dev, "failed to get OPP table\n");
-   rcu_read_unlock();
-   return ret;
+ 

[PATCH v2 08/19] PM / devfreq: exynos: Add support of bus frequency of sub-blocks using passive governor

2015-12-08 Thread Chanwoo Choi
This patch adds the support of bus frequency feature for sub-blocks which share
the one power line. If each bus depends on the power line, each bus is not able
to change the voltage by oneself. To optimize the power-consumption on runtime,
some buses using the same power line should change the source clock and
regulator at the same time. So, this patch uses the passive governor to support
the bus frequency for all buses which sharing the one power line.

For example,

Exynos3250 include the two power line for AXI buses as following:
: VDD_MIF : MIF (Memory Interface) provide the DMC (Dynamic Memory Controller)
  with the power (regulator).
: VDD_INT : INT (Internal) provide the various sub-blocks with the power
  (regulator).

Each bus is included in as follwoing block. In the case of VDD_MIF, only DMC bus
use the power line. So, there is no any depencency between buese. But, in the
case of VDD_INT, various buses share the one power line of VDD_INT. We need to
make the depenency between buses. When using passive governor, there is no
problem to support the bus frequency as DVFS for all buses. One bus should be
operated as the parent bus device which gathering the current load of INT block
and then decides the new frequency with some governors except of passive
governor. After deciding the new frequency by the parent bus device, the rest
bus devices will change the each source clock according to new frequency of the
parent bus device.

- MIF (Memory Interface) block
: VDD_MIF |--- DMC

- INT (Internal) block
: VDD_INT |--- LEFTBUS (parent)
  |--- PERIL
  |--- MFC
  |--- G3D
  |--- RIGHTBUS
  |--- FSYS
  |--- LCD0
  |--- PERIR
  |--- ISP
  |--- CAM

Signed-off-by: Chanwoo Choi 
---
 drivers/devfreq/Kconfig |   1 +
 drivers/devfreq/exynos/exynos-bus.c | 170 
 2 files changed, 136 insertions(+), 35 deletions(-)

diff --git a/drivers/devfreq/Kconfig b/drivers/devfreq/Kconfig
index d03f635a93e1..88f7cc4539b8 100644
--- a/drivers/devfreq/Kconfig
+++ b/drivers/devfreq/Kconfig
@@ -79,6 +79,7 @@ config ARM_EXYNOS_BUS_DEVFREQ
bool "ARM EXYNOS Generic Memory Bus DEVFREQ Driver"
depends on ARCH_EXYNOS
select DEVFREQ_GOV_SIMPLE_ONDEMAND
+   select DEVFREQ_GOV_PASSIVE
select DEVFREQ_EVENT_EXYNOS_PPMU
select PM_DEVFREQ_EVENT
select PM_OPP
diff --git a/drivers/devfreq/exynos/exynos-bus.c 
b/drivers/devfreq/exynos/exynos-bus.c
index f1bc20839650..2efc2bba757e 100644
--- a/drivers/devfreq/exynos/exynos-bus.c
+++ b/drivers/devfreq/exynos/exynos-bus.c
@@ -91,7 +91,7 @@ static int exynos_bus_get_event(struct exynos_bus *bus,
 }
 
 /*
- * Must necessary function for devfreq governor
+ * Must necessary function for devfreq simple-ondemand governor
  */
 static int exynos_bus_target(struct device *dev, unsigned long *freq, u32 
flags)
 {
@@ -205,57 +205,74 @@ static void exynos_bus_exit(struct device *dev)
dev_pm_opp_of_remove_table(dev);
 }
 
-static int exynos_bus_parse_of(struct device_node *np,
- struct exynos_bus *bus)
+/*
+ * Must necessary function for devfreq passive governor
+ */
+static int exynos_bus_passive_target(struct device *dev, unsigned long *freq,
+   u32 flags)
 {
-   struct device *dev = bus->dev;
-   unsigned long rate;
-   int i, ret, count, size;
+   struct exynos_bus *bus = dev_get_drvdata(dev);
+   struct dev_pm_opp *new_opp;
+   unsigned long old_freq, new_freq;
+   int ret = 0;
 
-   /* Get the clock to provide each bus with source clock */
-   bus->clk = devm_clk_get(dev, "bus");
-   if (IS_ERR(bus->clk)) {
-   dev_err(dev, "failed to get bus clock\n");
-   return PTR_ERR(bus->clk);
+   /* Get new opp-bus instance according to new bus clock */
+   rcu_read_lock();
+   new_opp = devfreq_recommended_opp(dev, freq, flags);
+   if (IS_ERR_OR_NULL(new_opp)) {
+   dev_err(dev, "failed to get recommed opp instance\n");
+   rcu_read_unlock();
+   return PTR_ERR(new_opp);
}
 
-   ret = clk_prepare_enable(bus->clk);
-   if (ret < 0) {
-   dev_err(dev, "failed to get enable clock\n");
-   return ret;
-   }
+   new_freq = dev_pm_opp_get_freq(new_opp);
+   old_freq = dev_pm_opp_get_freq(bus->curr_opp);
+   rcu_read_unlock();
 
-   /* Get the freq/voltage OPP table to scale the bus frequency */
-   rcu_read_lock();
-   ret = dev_pm_opp_of_add_table(dev);
+   if (old_freq == new_freq)
+   return 0;
+
+   /* Change the frequency according to new OPP level */
+   mutex_lock(>lock);
+
+   ret = clk_set_rate(bus->clk, new_freq);
if (ret < 0) {
-   dev_err(dev, "failed to get OPP table\n");
-   rcu_read_unlock();
-