linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Enric Balletbo i Serra <enric.balletbo@collabora.com>
To: myungjoo.ham@samsung.com, kyungmin.park@samsung.com, robh+dt@kernel.org
Cc: devicetree@vger.kernel.org, heiko@sntech.de,
	linux-pm@vger.kernel.org, dbasehore@chromium.org,
	linux-kernel@vger.kernel.org, dianders@google.com,
	groek@google.com, kernel@collabora.com,
	Lin Huang <hl@rock-chips.com>,
	Elaine Zhang <zhangqing@rock-chips.com>,
	Chanwoo Choi <cw00.choi@samsung.com>,
	linux-rockchip@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org,
	Geert Uytterhoeven <geert+renesas@glider.be>,
	Jeffy Chen <jeffy.chen@rock-chips.com>,
	Ulf Hansson <ulf.hansson@linaro.org>
Subject: [PATCH 6/6] devfreq: rk3399_dmc: register devfreq notification to dmc driver.
Date: Thu, 19 Apr 2018 12:40:19 +0200	[thread overview]
Message-ID: <20180419104019.24406-7-enric.balletbo@collabora.com> (raw)
In-Reply-To: <20180419104019.24406-1-enric.balletbo@collabora.com>

From: Lin Huang <hl@rock-chips.com>

Because dmc may also access the PMU_BUS_IDLE_REQ register, we need to
ensure that the pd driver and the dmc driver will not access at this
register at the same time.

Signed-off-by: Lin Huang <hl@rock-chips.com>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
---

 drivers/devfreq/rk3399_dmc.c      | 47 +----------------------
 drivers/soc/rockchip/pm_domains.c | 31 +++++++++++++++
 include/soc/rockchip/rk3399_dmc.h | 63 +++++++++++++++++++++++++++++++
 3 files changed, 96 insertions(+), 45 deletions(-)
 create mode 100644 include/soc/rockchip/rk3399_dmc.h

diff --git a/drivers/devfreq/rk3399_dmc.c b/drivers/devfreq/rk3399_dmc.c
index 5bfca028eaaf..a1f320634d69 100644
--- a/drivers/devfreq/rk3399_dmc.c
+++ b/drivers/devfreq/rk3399_dmc.c
@@ -27,51 +27,7 @@
 #include <linux/suspend.h>
 
 #include <soc/rockchip/rockchip_sip.h>
-
-struct dram_timing {
-	unsigned int ddr3_speed_bin;
-	unsigned int pd_idle;
-	unsigned int sr_idle;
-	unsigned int sr_mc_gate_idle;
-	unsigned int srpd_lite_idle;
-	unsigned int standby_idle;
-	unsigned int auto_pd_dis_freq;
-	unsigned int dram_dll_dis_freq;
-	unsigned int phy_dll_dis_freq;
-	unsigned int ddr3_odt_dis_freq;
-	unsigned int ddr3_drv;
-	unsigned int ddr3_odt;
-	unsigned int phy_ddr3_ca_drv;
-	unsigned int phy_ddr3_dq_drv;
-	unsigned int phy_ddr3_odt;
-	unsigned int lpddr3_odt_dis_freq;
-	unsigned int lpddr3_drv;
-	unsigned int lpddr3_odt;
-	unsigned int phy_lpddr3_ca_drv;
-	unsigned int phy_lpddr3_dq_drv;
-	unsigned int phy_lpddr3_odt;
-	unsigned int lpddr4_odt_dis_freq;
-	unsigned int lpddr4_drv;
-	unsigned int lpddr4_dq_odt;
-	unsigned int lpddr4_ca_odt;
-	unsigned int phy_lpddr4_ca_drv;
-	unsigned int phy_lpddr4_ck_cs_drv;
-	unsigned int phy_lpddr4_dq_drv;
-	unsigned int phy_lpddr4_odt;
-};
-
-struct rk3399_dmcfreq {
-	struct device *dev;
-	struct devfreq *devfreq;
-	struct devfreq_simple_ondemand_data ondemand_data;
-	struct clk *dmc_clk;
-	struct devfreq_event_dev *edev;
-	struct mutex lock;
-	struct dram_timing timing;
-	struct regulator *vdd_center;
-	unsigned long rate, target_rate;
-	unsigned long volt, target_volt;
-};
+#include <soc/rockchip/rk3399_dmc.h>
 
 static int rk3399_dmcfreq_target(struct device *dev, unsigned long *freq,
 				 u32 flags)
@@ -394,6 +350,7 @@ static int rk3399_dmcfreq_probe(struct platform_device *pdev)
 
 	data->dev = dev;
 	platform_set_drvdata(pdev, data);
+	pd_register_notify_to_dmc(data->devfreq);
 
 	return 0;
 }
diff --git a/drivers/soc/rockchip/pm_domains.c b/drivers/soc/rockchip/pm_domains.c
index 53efc386b1ad..7acc836e7eb7 100644
--- a/drivers/soc/rockchip/pm_domains.c
+++ b/drivers/soc/rockchip/pm_domains.c
@@ -8,6 +8,7 @@
  * published by the Free Software Foundation.
  */
 
+#include <linux/devfreq.h>
 #include <linux/io.h>
 #include <linux/iopoll.h>
 #include <linux/err.h>
@@ -76,9 +77,13 @@ struct rockchip_pmu {
 	const struct rockchip_pmu_info *info;
 	struct mutex mutex; /* mutex lock for pmu */
 	struct genpd_onecell_data genpd_data;
+	struct devfreq *devfreq;
+	struct notifier_block dmc_nb;
 	struct generic_pm_domain *domains[];
 };
 
+static struct rockchip_pmu *dmc_pmu;
+
 #define to_rockchip_pd(gpd) container_of(gpd, struct rockchip_pm_domain, genpd)
 
 #define DOMAIN(pwr, status, req, idle, ack, wakeup)	\
@@ -601,6 +606,30 @@ static int rockchip_pm_add_subdomain(struct rockchip_pmu *pmu,
 	return error;
 }
 
+static int dmc_notify(struct notifier_block *nb, unsigned long event,
+		      void *data)
+{
+	if (event == DEVFREQ_PRECHANGE)
+		mutex_lock(&dmc_pmu->mutex);
+	else if (event == DEVFREQ_POSTCHANGE)
+		mutex_unlock(&dmc_pmu->mutex);
+
+	return NOTIFY_OK;
+}
+
+int pd_register_notify_to_dmc(struct devfreq *devfreq)
+{
+	if (!dmc_pmu)
+		return -EPROBE_DEFER;
+
+	dmc_pmu->devfreq = devfreq;
+	dmc_pmu->dmc_nb.notifier_call = dmc_notify;
+	devfreq_register_notifier(dmc_pmu->devfreq, &dmc_pmu->dmc_nb,
+				  DEVFREQ_TRANSITION_NOTIFIER);
+	return 0;
+}
+EXPORT_SYMBOL(pd_register_notify_to_dmc);
+
 static int rockchip_pm_domain_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -694,6 +723,8 @@ static int rockchip_pm_domain_probe(struct platform_device *pdev)
 		goto err_out;
 	}
 
+	dmc_pmu = pmu;
+
 	return 0;
 
 err_out:
diff --git a/include/soc/rockchip/rk3399_dmc.h b/include/soc/rockchip/rk3399_dmc.h
new file mode 100644
index 000000000000..7ccdfff1a154
--- /dev/null
+++ b/include/soc/rockchip/rk3399_dmc.h
@@ -0,0 +1,63 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * DMC (Dynamic Memory Controller) for RK3399 - Definitions
+ *
+ * Copyright (c) 2016, Fuzhou Rockchip Electronics Co., Ltd
+ *
+ * Author: Lin Huang <hl@rock-chips.com>
+ */
+
+#ifndef __SOC_RK3399_DMC_H
+#define __SOC_RK3399_DMC_H
+
+#include <linux/devfreq.h>
+
+struct dram_timing {
+	unsigned int ddr3_speed_bin;
+	unsigned int pd_idle;
+	unsigned int sr_idle;
+	unsigned int sr_mc_gate_idle;
+	unsigned int srpd_lite_idle;
+	unsigned int standby_idle;
+	unsigned int auto_pd_dis_freq;
+	unsigned int dram_dll_dis_freq;
+	unsigned int phy_dll_dis_freq;
+	unsigned int ddr3_odt_dis_freq;
+	unsigned int ddr3_drv;
+	unsigned int ddr3_odt;
+	unsigned int phy_ddr3_ca_drv;
+	unsigned int phy_ddr3_dq_drv;
+	unsigned int phy_ddr3_odt;
+	unsigned int lpddr3_odt_dis_freq;
+	unsigned int lpddr3_drv;
+	unsigned int lpddr3_odt;
+	unsigned int phy_lpddr3_ca_drv;
+	unsigned int phy_lpddr3_dq_drv;
+	unsigned int phy_lpddr3_odt;
+	unsigned int lpddr4_odt_dis_freq;
+	unsigned int lpddr4_drv;
+	unsigned int lpddr4_dq_odt;
+	unsigned int lpddr4_ca_odt;
+	unsigned int phy_lpddr4_ca_drv;
+	unsigned int phy_lpddr4_ck_cs_drv;
+	unsigned int phy_lpddr4_dq_drv;
+	unsigned int phy_lpddr4_odt;
+};
+
+struct rk3399_dmcfreq {
+	struct device *dev;
+	struct devfreq *devfreq;
+	struct devfreq_simple_ondemand_data ondemand_data;
+	struct clk *dmc_clk;
+	struct devfreq_event_dev *edev;
+	struct mutex lock;
+	struct dram_timing timing;
+	struct regulator *vdd_center;
+	unsigned long rate, target_rate;
+	unsigned long volt, target_volt;
+	struct dev_pm_opp *curr_opp;
+};
+
+int pd_register_notify_to_dmc(struct devfreq *devfreq);
+
+#endif
-- 
2.17.0

  parent reply	other threads:[~2018-04-19 10:41 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-19 10:40 [PATCH 0/6] devfreq: rk3399_dmc: improve rk3399_dmc driver and it's documentation Enric Balletbo i Serra
2018-04-19 10:40 ` [PATCH 1/6] dt-bindings: devfreq: rk3399_dmc: improve binding documentation Enric Balletbo i Serra
2018-04-19 10:40 ` [PATCH 2/6] dt-bindings: clock: add DDR3 standard speed bins Enric Balletbo i Serra
2018-04-19 11:10   ` Heiko Stuebner
2018-04-19 11:30     ` Enric Balletbo i Serra
2018-04-20 10:58       ` Heiko Stuebner
2018-04-19 10:40 ` [PATCH 3/6] devfreq: rk3399_dmc: remove wait for dcf irq event Enric Balletbo i Serra
2018-04-24  3:55   ` Chanwoo Choi
2018-04-19 10:40 ` [PATCH 4/6] dt-bindings: devfreq: rk3399_dmc: remove interrupts as is not required Enric Balletbo i Serra
2018-04-24  3:56   ` Chanwoo Choi
2018-04-19 10:40 ` [PATCH 5/6] devfreq: rk3399_dmc: do not print error when get supply and clk defer Enric Balletbo i Serra
2018-04-23 10:44   ` Ulf Hansson
2018-04-23 13:37     ` Ezequiel Garcia
2018-04-24  3:55   ` Chanwoo Choi
2018-04-19 10:40 ` Enric Balletbo i Serra [this message]
2018-04-24  4:08   ` [PATCH 6/6] devfreq: rk3399_dmc: register devfreq notification to dmc driver Chanwoo Choi
2018-04-23 10:53 ` [PATCH 0/6] devfreq: rk3399_dmc: improve rk3399_dmc driver and it's documentation Ulf Hansson
     [not found] ` <CGME20180419104054epcas5p49612174afb26493bcd937a0232b9b1df@epcms1p3>
2018-04-24  1:53   ` [PATCH 1/6] dt-bindings: devfreq: rk3399_dmc: improve binding documentation MyungJoo Ham
     [not found] ` <CGME20180419104056epcas2p29c74949b650fea596900e395dec662e8@epcms1p7>
2018-04-24  2:31   ` [PATCH 3/6] devfreq: rk3399_dmc: remove wait for dcf irq event MyungJoo Ham
     [not found] ` <CGME20180419104057epcas5p311ecfdeb6cb535cd7100232d282ac323@epcms1p4>
2018-04-24  2:33   ` [PATCH 5/6] devfreq: rk3399_dmc: do not print error when get supply and clk defer MyungJoo Ham
     [not found] ` <CGME20180419104059epcas2p3fe5aba95859e02307556200a42bc1ac2@epcms1p7>
2018-04-24  4:22   ` [PATCH 6/6] devfreq: rk3399_dmc: register devfreq notification to dmc driver MyungJoo Ham
2018-04-24  8:01     ` Enric Balletbo i Serra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180419104019.24406-7-enric.balletbo@collabora.com \
    --to=enric.balletbo@collabora.com \
    --cc=cw00.choi@samsung.com \
    --cc=dbasehore@chromium.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dianders@google.com \
    --cc=geert+renesas@glider.be \
    --cc=groek@google.com \
    --cc=heiko@sntech.de \
    --cc=hl@rock-chips.com \
    --cc=jeffy.chen@rock-chips.com \
    --cc=kernel@collabora.com \
    --cc=kyungmin.park@samsung.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=myungjoo.ham@samsung.com \
    --cc=robh+dt@kernel.org \
    --cc=ulf.hansson@linaro.org \
    --cc=zhangqing@rock-chips.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).