From: wenyou.yang@microchip.com (Wenyou Yang)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v5 2/5] media: atmel-isc: Add prepare and unprepare ops
Date: Fri, 27 Oct 2017 11:21:29 +0800 [thread overview]
Message-ID: <20171027032132.16418-3-wenyou.yang@microchip.com> (raw)
In-Reply-To: <20171027032132.16418-1-wenyou.yang@microchip.com>
A software write operation to the ISC_CLKEN or ISC_CLKDIS register
requires double clock domain synchronization and is not permitted
when the ISC_SR.SIP is asserted. So add the .prepare and .unprepare
ops to make sure the ISC_CLKSR.SIP is unasserted before the write
operation to the ISC_CLKEN or ISC_CLKDIS register.
Signed-off-by: Wenyou Yang <wenyou.yang@microchip.com>
---
Changes in v5:
- Fix the clock ID which enters the runtime suspend should be
ISC_ISPCK, instead of ISC_MCK for clk_prepare/clk_unprepare().
Changes in v4:
- Call pm_runtime_get_sync() and pm_runtime_put_sync() in ->prepare
and ->unprepare callback.
Changes in v3: None
Changes in v2: None
drivers/media/platform/atmel/atmel-isc-regs.h | 1 +
drivers/media/platform/atmel/atmel-isc.c | 40 +++++++++++++++++++++++++++
2 files changed, 41 insertions(+)
diff --git a/drivers/media/platform/atmel/atmel-isc-regs.h b/drivers/media/platform/atmel/atmel-isc-regs.h
index 6936ac467609..93e58fcf1d5f 100644
--- a/drivers/media/platform/atmel/atmel-isc-regs.h
+++ b/drivers/media/platform/atmel/atmel-isc-regs.h
@@ -42,6 +42,7 @@
/* ISC Clock Status Register */
#define ISC_CLKSR 0x00000020
+#define ISC_CLKSR_SIP BIT(31)
#define ISC_CLK(n) BIT(n)
diff --git a/drivers/media/platform/atmel/atmel-isc.c b/drivers/media/platform/atmel/atmel-isc.c
index 991f962b7023..329ee8f256bb 100644
--- a/drivers/media/platform/atmel/atmel-isc.c
+++ b/drivers/media/platform/atmel/atmel-isc.c
@@ -308,6 +308,44 @@ module_param(sensor_preferred, uint, 0644);
MODULE_PARM_DESC(sensor_preferred,
"Sensor is preferred to output the specified format (1-on 0-off), default 1");
+static int isc_wait_clk_stable(struct clk_hw *hw)
+{
+ struct isc_clk *isc_clk = to_isc_clk(hw);
+ struct regmap *regmap = isc_clk->regmap;
+ unsigned long timeout = jiffies + usecs_to_jiffies(1000);
+ unsigned int status;
+
+ while (time_before(jiffies, timeout)) {
+ regmap_read(regmap, ISC_CLKSR, &status);
+ if (!(status & ISC_CLKSR_SIP))
+ return 0;
+
+ usleep_range(10, 250);
+ }
+
+ return -ETIMEDOUT;
+}
+
+static int isc_clk_prepare(struct clk_hw *hw)
+{
+ struct isc_clk *isc_clk = to_isc_clk(hw);
+
+ if (isc_clk->id == ISC_ISPCK)
+ pm_runtime_get_sync(isc_clk->dev);
+
+ return isc_wait_clk_stable(hw);
+}
+
+static void isc_clk_unprepare(struct clk_hw *hw)
+{
+ struct isc_clk *isc_clk = to_isc_clk(hw);
+
+ isc_wait_clk_stable(hw);
+
+ if (isc_clk->id == ISC_ISPCK)
+ pm_runtime_put_sync(isc_clk->dev);
+}
+
static int isc_clk_enable(struct clk_hw *hw)
{
struct isc_clk *isc_clk = to_isc_clk(hw);
@@ -459,6 +497,8 @@ static int isc_clk_set_rate(struct clk_hw *hw,
}
static const struct clk_ops isc_clk_ops = {
+ .prepare = isc_clk_prepare,
+ .unprepare = isc_clk_unprepare,
.enable = isc_clk_enable,
.disable = isc_clk_disable,
.is_enabled = isc_clk_is_enabled,
--
2.13.0
next prev parent reply other threads:[~2017-10-27 3:21 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-27 3:21 [PATCH v5 0/5] media: atmel-isc: Rework the format list and clock provider Wenyou Yang
2017-10-27 3:21 ` [PATCH v5 1/5] media: atmel-isc: Add spin lock for clock enable ops Wenyou Yang
2017-10-27 3:21 ` Wenyou Yang [this message]
2017-10-27 3:21 ` [PATCH v5 3/5] media: atmel-isc: Enable the clocks during probe Wenyou Yang
2017-10-27 3:21 ` [PATCH v5 4/5] media: atmel-isc: Remove unnecessary member Wenyou Yang
2017-10-27 3:21 ` [PATCH v5 5/5] media: atmel-isc: Rework the format list Wenyou Yang
2017-10-27 12:41 ` [PATCH v5 0/5] media: atmel-isc: Rework the format list and clock provider Hans Verkuil
2017-10-30 0:25 ` Yang, Wenyou
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=20171027032132.16418-3-wenyou.yang@microchip.com \
--to=wenyou.yang@microchip.com \
--cc=linux-arm-kernel@lists.infradead.org \
/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).