Commit 05b1b986 authored by Laurent Pinchart's avatar Laurent Pinchart Committed by Mauro Carvalho Chehab

[media] omap4iss: Use a common macro for all sleep-based poll loops

Instead of implementing usleep_range-based poll loops manually (and
slightly differently), create a generic iss_poll_wait_timeout() macro
and use it through the driver.
Signed-off-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarMauro Carvalho Chehab <m.chehab@samsung.com>
parent 47a963f1
...@@ -734,18 +734,17 @@ static int iss_pipeline_is_last(struct media_entity *me) ...@@ -734,18 +734,17 @@ static int iss_pipeline_is_last(struct media_entity *me)
static int iss_reset(struct iss_device *iss) static int iss_reset(struct iss_device *iss)
{ {
unsigned long timeout = 0; unsigned int timeout;
iss_reg_set(iss, OMAP4_ISS_MEM_TOP, ISS_HL_SYSCONFIG, iss_reg_set(iss, OMAP4_ISS_MEM_TOP, ISS_HL_SYSCONFIG,
ISS_HL_SYSCONFIG_SOFTRESET); ISS_HL_SYSCONFIG_SOFTRESET);
while (iss_reg_read(iss, OMAP4_ISS_MEM_TOP, ISS_HL_SYSCONFIG) & timeout = iss_poll_condition_timeout(
ISS_HL_SYSCONFIG_SOFTRESET) { !(iss_reg_read(iss, OMAP4_ISS_MEM_TOP, ISS_HL_SYSCONFIG) &
if (timeout++ > 100) { ISS_HL_SYSCONFIG_SOFTRESET), 1000, 10, 10);
dev_alert(iss->dev, "cannot reset ISS\n"); if (timeout) {
return -ETIMEDOUT; dev_err(iss->dev, "ISS reset timeout\n");
} return -ETIMEDOUT;
usleep_range(10, 10);
} }
iss->crashed = 0; iss->crashed = 0;
...@@ -754,7 +753,7 @@ static int iss_reset(struct iss_device *iss) ...@@ -754,7 +753,7 @@ static int iss_reset(struct iss_device *iss)
static int iss_isp_reset(struct iss_device *iss) static int iss_isp_reset(struct iss_device *iss)
{ {
unsigned long timeout = 0; unsigned int timeout;
/* Fist, ensure that the ISP is IDLE (no transactions happening) */ /* Fist, ensure that the ISP is IDLE (no transactions happening) */
iss_reg_update(iss, OMAP4_ISS_MEM_ISP_SYS1, ISP5_SYSCONFIG, iss_reg_update(iss, OMAP4_ISS_MEM_ISP_SYS1, ISP5_SYSCONFIG,
...@@ -763,29 +762,24 @@ static int iss_isp_reset(struct iss_device *iss) ...@@ -763,29 +762,24 @@ static int iss_isp_reset(struct iss_device *iss)
iss_reg_set(iss, OMAP4_ISS_MEM_ISP_SYS1, ISP5_CTRL, ISP5_CTRL_MSTANDBY); iss_reg_set(iss, OMAP4_ISS_MEM_ISP_SYS1, ISP5_CTRL, ISP5_CTRL_MSTANDBY);
for (;;) { timeout = iss_poll_condition_timeout(
if (iss_reg_read(iss, OMAP4_ISS_MEM_ISP_SYS1, ISP5_CTRL) & iss_reg_read(iss, OMAP4_ISS_MEM_ISP_SYS1, ISP5_CTRL) &
ISP5_CTRL_MSTANDBY_WAIT) ISP5_CTRL_MSTANDBY_WAIT, 1000000, 1000, 1500);
break; if (timeout) {
if (timeout++ > 1000) { dev_err(iss->dev, "ISP5 standby timeout\n");
dev_alert(iss->dev, "cannot set ISP5 to standby\n"); return -ETIMEDOUT;
return -ETIMEDOUT;
}
usleep_range(1000, 1500);
} }
/* Now finally, do the reset */ /* Now finally, do the reset */
iss_reg_set(iss, OMAP4_ISS_MEM_ISP_SYS1, ISP5_SYSCONFIG, iss_reg_set(iss, OMAP4_ISS_MEM_ISP_SYS1, ISP5_SYSCONFIG,
ISP5_SYSCONFIG_SOFTRESET); ISP5_SYSCONFIG_SOFTRESET);
timeout = 0; timeout = iss_poll_condition_timeout(
while (iss_reg_read(iss, OMAP4_ISS_MEM_ISP_SYS1, ISP5_SYSCONFIG) & !(iss_reg_read(iss, OMAP4_ISS_MEM_ISP_SYS1, ISP5_SYSCONFIG) &
ISP5_SYSCONFIG_SOFTRESET) { ISP5_SYSCONFIG_SOFTRESET), 1000000, 1000, 1500);
if (timeout++ > 1000) { if (timeout) {
dev_alert(iss->dev, "cannot reset ISP5\n"); dev_err(iss->dev, "ISP5 reset timeout\n");
return -ETIMEDOUT; return -ETIMEDOUT;
}
usleep_range(1000, 1500);
} }
return 0; return 0;
......
...@@ -233,4 +233,18 @@ void iss_reg_update(struct iss_device *iss, enum iss_mem_resources res, ...@@ -233,4 +233,18 @@ void iss_reg_update(struct iss_device *iss, enum iss_mem_resources res,
iss_reg_write(iss, res, offset, (v & ~clr) | set); iss_reg_write(iss, res, offset, (v & ~clr) | set);
} }
#define iss_poll_condition_timeout(cond, timeout, min_ival, max_ival) \
({ \
unsigned long __timeout = jiffies + usecs_to_jiffies(timeout); \
unsigned int __min_ival = (min_ival); \
unsigned int __max_ival = (max_ival); \
bool __cond; \
while (!(__cond = (cond))) { \
if (time_after(jiffies, __timeout)) \
break; \
usleep_range(__min_ival, __max_ival); \
} \
!__cond; \
})
#endif /* _OMAP4_ISS_H_ */ #endif /* _OMAP4_ISS_H_ */
...@@ -487,9 +487,7 @@ static void csi2_irq_status_set(struct iss_csi2_device *csi2, int enable) ...@@ -487,9 +487,7 @@ static void csi2_irq_status_set(struct iss_csi2_device *csi2, int enable)
*/ */
int omap4iss_csi2_reset(struct iss_csi2_device *csi2) int omap4iss_csi2_reset(struct iss_csi2_device *csi2)
{ {
u8 soft_reset_retries = 0; unsigned int timeout;
u32 reg;
int i;
if (!csi2->available) if (!csi2->available)
return -ENODEV; return -ENODEV;
...@@ -500,37 +498,22 @@ int omap4iss_csi2_reset(struct iss_csi2_device *csi2) ...@@ -500,37 +498,22 @@ int omap4iss_csi2_reset(struct iss_csi2_device *csi2)
iss_reg_set(csi2->iss, csi2->regs1, CSI2_SYSCONFIG, iss_reg_set(csi2->iss, csi2->regs1, CSI2_SYSCONFIG,
CSI2_SYSCONFIG_SOFT_RESET); CSI2_SYSCONFIG_SOFT_RESET);
do { timeout = iss_poll_condition_timeout(
reg = iss_reg_read(csi2->iss, csi2->regs1, CSI2_SYSSTATUS) iss_reg_read(csi2->iss, csi2->regs1, CSI2_SYSSTATUS) &
& CSI2_SYSSTATUS_RESET_DONE; CSI2_SYSSTATUS_RESET_DONE, 500, 100, 100);
if (reg == CSI2_SYSSTATUS_RESET_DONE) if (timeout) {
break; dev_err(csi2->iss->dev, "CSI2: Soft reset timeout!\n");
soft_reset_retries++;
if (soft_reset_retries < 5)
usleep_range(100, 100);
} while (soft_reset_retries < 5);
if (soft_reset_retries == 5) {
dev_err(csi2->iss->dev,
"CSI2: Soft reset try count exceeded!\n");
return -EBUSY; return -EBUSY;
} }
iss_reg_set(csi2->iss, csi2->regs1, CSI2_COMPLEXIO_CFG, iss_reg_set(csi2->iss, csi2->regs1, CSI2_COMPLEXIO_CFG,
CSI2_COMPLEXIO_CFG_RESET_CTRL); CSI2_COMPLEXIO_CFG_RESET_CTRL);
i = 100; timeout = iss_poll_condition_timeout(
do { iss_reg_read(csi2->iss, csi2->phy->phy_regs, REGISTER1) &
reg = iss_reg_read(csi2->iss, csi2->phy->phy_regs, REGISTER1) REGISTER1_RESET_DONE_CTRLCLK, 10000, 100, 100);
& REGISTER1_RESET_DONE_CTRLCLK; if (timeout) {
if (reg == REGISTER1_RESET_DONE_CTRLCLK) dev_err(csi2->iss->dev, "CSI2: CSI2_96M_FCLK reset timeout!\n");
break;
usleep_range(100, 100);
} while (--i > 0);
if (i == 0) {
dev_err(csi2->iss->dev,
"CSI2: Reset for CSI2_96M_FCLK domain Failed!\n");
return -EBUSY; return -EBUSY;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment