Skip to content

Commit 3d520fe

Browse files
Wenyou Yangehristev
authored andcommitted
media: atmel-isc: Add prepare and unprepare ops
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> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
1 parent f21d326 commit 3d520fe

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

drivers/media/platform/atmel/atmel-isc-regs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
/* ISC Clock Status Register */
4545
#define ISC_CLKSR 0x00000020
46+
#define ISC_CLKSR_SIP BIT(31)
4647

4748
#define ISC_CLK(n) BIT(n)
4849

drivers/media/platform/atmel/atmel-isc.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,44 @@ module_param(sensor_preferred, uint, 0644);
308308
MODULE_PARM_DESC(sensor_preferred,
309309
"Sensor is preferred to output the specified format (1-on 0-off), default 1");
310310

311+
static int isc_wait_clk_stable(struct clk_hw *hw)
312+
{
313+
struct isc_clk *isc_clk = to_isc_clk(hw);
314+
struct regmap *regmap = isc_clk->regmap;
315+
unsigned long timeout = jiffies + usecs_to_jiffies(1000);
316+
unsigned int status;
317+
318+
while (time_before(jiffies, timeout)) {
319+
regmap_read(regmap, ISC_CLKSR, &status);
320+
if (!(status & ISC_CLKSR_SIP))
321+
return 0;
322+
323+
usleep_range(10, 250);
324+
}
325+
326+
return -ETIMEDOUT;
327+
}
328+
329+
static int isc_clk_prepare(struct clk_hw *hw)
330+
{
331+
struct isc_clk *isc_clk = to_isc_clk(hw);
332+
333+
if (isc_clk->id == ISC_MCK)
334+
pm_runtime_get_sync(isc_clk->dev);
335+
336+
return isc_wait_clk_stable(hw);
337+
}
338+
339+
static void isc_clk_unprepare(struct clk_hw *hw)
340+
{
341+
struct isc_clk *isc_clk = to_isc_clk(hw);
342+
343+
isc_wait_clk_stable(hw);
344+
345+
if (isc_clk->id == ISC_MCK)
346+
pm_runtime_put_sync(isc_clk->dev);
347+
}
348+
311349
static int isc_clk_enable(struct clk_hw *hw)
312350
{
313351
struct isc_clk *isc_clk = to_isc_clk(hw);
@@ -459,6 +497,8 @@ static int isc_clk_set_rate(struct clk_hw *hw,
459497
}
460498

461499
static const struct clk_ops isc_clk_ops = {
500+
.prepare = isc_clk_prepare,
501+
.unprepare = isc_clk_unprepare,
462502
.enable = isc_clk_enable,
463503
.disable = isc_clk_disable,
464504
.is_enabled = isc_clk_is_enabled,

0 commit comments

Comments
 (0)