Commit 7e1db599 authored by Sakari Ailus's avatar Sakari Ailus Committed by Mauro Carvalho Chehab

media: omap3isp: csiphy: Don't assume the CSI receiver is a CSI2 module

The CSI PHY is associated with a CSI receiver. The code assumes this
receiver is a CSI2 module and relies on the CSI2 module object heavily to
access the ISP or pipeline objects. However, the receiver could also be a
CSI1/CCP2 module.

Pass a new CSI receiver entity pointer to the CSI PHY acquire function, and
replace all hardcoded usage of the CSI2 module with that CSI receiver
entity.
Signed-off-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
Tested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> # on Beagleboard-xM + MPT9P031
Acked-by: default avatarPavel Machek <pavel@ucw.cz>
Reviewed-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
parent 19be9fd6
...@@ -841,7 +841,7 @@ static int ccp2_s_stream(struct v4l2_subdev *sd, int enable) ...@@ -841,7 +841,7 @@ static int ccp2_s_stream(struct v4l2_subdev *sd, int enable)
switch (enable) { switch (enable) {
case ISP_PIPELINE_STREAM_CONTINUOUS: case ISP_PIPELINE_STREAM_CONTINUOUS:
if (ccp2->phy) { if (ccp2->phy) {
ret = omap3isp_csiphy_acquire(ccp2->phy); ret = omap3isp_csiphy_acquire(ccp2->phy, &sd->entity);
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
......
...@@ -490,7 +490,7 @@ int omap3isp_csi2_reset(struct isp_csi2_device *csi2) ...@@ -490,7 +490,7 @@ int omap3isp_csi2_reset(struct isp_csi2_device *csi2)
if (!csi2->available) if (!csi2->available)
return -ENODEV; return -ENODEV;
if (csi2->phy->phy_in_use) if (csi2->phy->entity)
return -EBUSY; return -EBUSY;
isp_reg_set(isp, csi2->regs1, ISPCSI2_SYSCONFIG, isp_reg_set(isp, csi2->regs1, ISPCSI2_SYSCONFIG,
...@@ -1053,7 +1053,7 @@ static int csi2_set_stream(struct v4l2_subdev *sd, int enable) ...@@ -1053,7 +1053,7 @@ static int csi2_set_stream(struct v4l2_subdev *sd, int enable)
switch (enable) { switch (enable) {
case ISP_PIPELINE_STREAM_CONTINUOUS: case ISP_PIPELINE_STREAM_CONTINUOUS:
if (omap3isp_csiphy_acquire(csi2->phy) < 0) if (omap3isp_csiphy_acquire(csi2->phy, &sd->entity) < 0)
return -ENODEV; return -ENODEV;
if (csi2->output & CSI2_OUTPUT_MEMORY) if (csi2->output & CSI2_OUTPUT_MEMORY)
omap3isp_sbl_enable(isp, OMAP3_ISP_SBL_CSI2A_WRITE); omap3isp_sbl_enable(isp, OMAP3_ISP_SBL_CSI2A_WRITE);
......
...@@ -164,22 +164,17 @@ static int csiphy_set_power(struct isp_csiphy *phy, u32 power) ...@@ -164,22 +164,17 @@ static int csiphy_set_power(struct isp_csiphy *phy, u32 power)
static int omap3isp_csiphy_config(struct isp_csiphy *phy) static int omap3isp_csiphy_config(struct isp_csiphy *phy)
{ {
struct isp_csi2_device *csi2 = phy->csi2; struct isp_pipeline *pipe = to_isp_pipeline(phy->entity);
struct isp_pipeline *pipe = to_isp_pipeline(&csi2->subdev.entity); struct isp_async_subdev *isd =
struct isp_bus_cfg *buscfg = pipe->external->host_priv; container_of(pipe->external->asd, struct isp_async_subdev, asd);
struct isp_bus_cfg *buscfg = pipe->external->host_priv ?
pipe->external->host_priv : &isd->bus;
struct isp_csiphy_lanes_cfg *lanes; struct isp_csiphy_lanes_cfg *lanes;
int csi2_ddrclk_khz; int csi2_ddrclk_khz;
unsigned int num_data_lanes, used_lanes = 0; unsigned int num_data_lanes, used_lanes = 0;
unsigned int i; unsigned int i;
u32 reg; u32 reg;
if (!buscfg) {
struct isp_async_subdev *isd =
container_of(pipe->external->asd,
struct isp_async_subdev, asd);
buscfg = &isd->bus;
}
if (buscfg->interface == ISP_INTERFACE_CCP2B_PHY1 if (buscfg->interface == ISP_INTERFACE_CCP2B_PHY1
|| buscfg->interface == ISP_INTERFACE_CCP2B_PHY2) { || buscfg->interface == ISP_INTERFACE_CCP2B_PHY2) {
lanes = &buscfg->bus.ccp2.lanecfg; lanes = &buscfg->bus.ccp2.lanecfg;
...@@ -222,7 +217,7 @@ static int omap3isp_csiphy_config(struct isp_csiphy *phy) ...@@ -222,7 +217,7 @@ static int omap3isp_csiphy_config(struct isp_csiphy *phy)
csi2_ddrclk_khz = pipe->external_rate / 1000 csi2_ddrclk_khz = pipe->external_rate / 1000
/ (2 * hweight32(used_lanes)) * pipe->external_width; / (2 * hweight32(used_lanes)) * pipe->external_width;
reg = isp_reg_readl(csi2->isp, phy->phy_regs, ISPCSIPHY_REG0); reg = isp_reg_readl(phy->isp, phy->phy_regs, ISPCSIPHY_REG0);
reg &= ~(ISPCSIPHY_REG0_THS_TERM_MASK | reg &= ~(ISPCSIPHY_REG0_THS_TERM_MASK |
ISPCSIPHY_REG0_THS_SETTLE_MASK); ISPCSIPHY_REG0_THS_SETTLE_MASK);
...@@ -233,9 +228,9 @@ static int omap3isp_csiphy_config(struct isp_csiphy *phy) ...@@ -233,9 +228,9 @@ static int omap3isp_csiphy_config(struct isp_csiphy *phy)
reg |= (DIV_ROUND_UP(90 * csi2_ddrclk_khz, 1000000) + 3) reg |= (DIV_ROUND_UP(90 * csi2_ddrclk_khz, 1000000) + 3)
<< ISPCSIPHY_REG0_THS_SETTLE_SHIFT; << ISPCSIPHY_REG0_THS_SETTLE_SHIFT;
isp_reg_writel(csi2->isp, reg, phy->phy_regs, ISPCSIPHY_REG0); isp_reg_writel(phy->isp, reg, phy->phy_regs, ISPCSIPHY_REG0);
reg = isp_reg_readl(csi2->isp, phy->phy_regs, ISPCSIPHY_REG1); reg = isp_reg_readl(phy->isp, phy->phy_regs, ISPCSIPHY_REG1);
reg &= ~(ISPCSIPHY_REG1_TCLK_TERM_MASK | reg &= ~(ISPCSIPHY_REG1_TCLK_TERM_MASK |
ISPCSIPHY_REG1_TCLK_MISS_MASK | ISPCSIPHY_REG1_TCLK_MISS_MASK |
...@@ -244,10 +239,10 @@ static int omap3isp_csiphy_config(struct isp_csiphy *phy) ...@@ -244,10 +239,10 @@ static int omap3isp_csiphy_config(struct isp_csiphy *phy)
reg |= TCLK_MISS << ISPCSIPHY_REG1_TCLK_MISS_SHIFT; reg |= TCLK_MISS << ISPCSIPHY_REG1_TCLK_MISS_SHIFT;
reg |= TCLK_SETTLE << ISPCSIPHY_REG1_TCLK_SETTLE_SHIFT; reg |= TCLK_SETTLE << ISPCSIPHY_REG1_TCLK_SETTLE_SHIFT;
isp_reg_writel(csi2->isp, reg, phy->phy_regs, ISPCSIPHY_REG1); isp_reg_writel(phy->isp, reg, phy->phy_regs, ISPCSIPHY_REG1);
/* DPHY lane configuration */ /* DPHY lane configuration */
reg = isp_reg_readl(csi2->isp, phy->cfg_regs, ISPCSI2_PHY_CFG); reg = isp_reg_readl(phy->isp, phy->cfg_regs, ISPCSI2_PHY_CFG);
for (i = 0; i < num_data_lanes; i++) { for (i = 0; i < num_data_lanes; i++) {
reg &= ~(ISPCSI2_PHY_CFG_DATA_POL_MASK(i + 1) | reg &= ~(ISPCSI2_PHY_CFG_DATA_POL_MASK(i + 1) |
...@@ -263,12 +258,12 @@ static int omap3isp_csiphy_config(struct isp_csiphy *phy) ...@@ -263,12 +258,12 @@ static int omap3isp_csiphy_config(struct isp_csiphy *phy)
reg |= lanes->clk.pol << ISPCSI2_PHY_CFG_CLOCK_POL_SHIFT; reg |= lanes->clk.pol << ISPCSI2_PHY_CFG_CLOCK_POL_SHIFT;
reg |= lanes->clk.pos << ISPCSI2_PHY_CFG_CLOCK_POSITION_SHIFT; reg |= lanes->clk.pos << ISPCSI2_PHY_CFG_CLOCK_POSITION_SHIFT;
isp_reg_writel(csi2->isp, reg, phy->cfg_regs, ISPCSI2_PHY_CFG); isp_reg_writel(phy->isp, reg, phy->cfg_regs, ISPCSI2_PHY_CFG);
return 0; return 0;
} }
int omap3isp_csiphy_acquire(struct isp_csiphy *phy) int omap3isp_csiphy_acquire(struct isp_csiphy *phy, struct media_entity *entity)
{ {
int rval; int rval;
...@@ -288,6 +283,8 @@ int omap3isp_csiphy_acquire(struct isp_csiphy *phy) ...@@ -288,6 +283,8 @@ int omap3isp_csiphy_acquire(struct isp_csiphy *phy)
if (rval < 0) if (rval < 0)
goto done; goto done;
phy->entity = entity;
rval = omap3isp_csiphy_config(phy); rval = omap3isp_csiphy_config(phy);
if (rval < 0) if (rval < 0)
goto done; goto done;
...@@ -301,10 +298,10 @@ int omap3isp_csiphy_acquire(struct isp_csiphy *phy) ...@@ -301,10 +298,10 @@ int omap3isp_csiphy_acquire(struct isp_csiphy *phy)
csiphy_power_autoswitch_enable(phy, true); csiphy_power_autoswitch_enable(phy, true);
} }
phy->phy_in_use = 1;
done: done:
if (rval < 0)
phy->entity = NULL;
mutex_unlock(&phy->mutex); mutex_unlock(&phy->mutex);
return rval; return rval;
} }
...@@ -312,10 +309,8 @@ int omap3isp_csiphy_acquire(struct isp_csiphy *phy) ...@@ -312,10 +309,8 @@ int omap3isp_csiphy_acquire(struct isp_csiphy *phy)
void omap3isp_csiphy_release(struct isp_csiphy *phy) void omap3isp_csiphy_release(struct isp_csiphy *phy)
{ {
mutex_lock(&phy->mutex); mutex_lock(&phy->mutex);
if (phy->phy_in_use) { if (phy->entity) {
struct isp_csi2_device *csi2 = phy->csi2; struct isp_pipeline *pipe = to_isp_pipeline(phy->entity);
struct isp_pipeline *pipe =
to_isp_pipeline(&csi2->subdev.entity);
struct isp_bus_cfg *buscfg = pipe->external->host_priv; struct isp_bus_cfg *buscfg = pipe->external->host_priv;
csiphy_routing_cfg(phy, buscfg->interface, false, csiphy_routing_cfg(phy, buscfg->interface, false,
...@@ -325,7 +320,7 @@ void omap3isp_csiphy_release(struct isp_csiphy *phy) ...@@ -325,7 +320,7 @@ void omap3isp_csiphy_release(struct isp_csiphy *phy)
csiphy_set_power(phy, ISPCSI2_PHY_CFG_PWR_CMD_OFF); csiphy_set_power(phy, ISPCSI2_PHY_CFG_PWR_CMD_OFF);
} }
regulator_disable(phy->vdd); regulator_disable(phy->vdd);
phy->phy_in_use = 0; phy->entity = NULL;
} }
mutex_unlock(&phy->mutex); mutex_unlock(&phy->mutex);
} }
......
...@@ -25,9 +25,10 @@ struct regulator; ...@@ -25,9 +25,10 @@ struct regulator;
struct isp_csiphy { struct isp_csiphy {
struct isp_device *isp; struct isp_device *isp;
struct mutex mutex; /* serialize csiphy configuration */ struct mutex mutex; /* serialize csiphy configuration */
u8 phy_in_use;
struct isp_csi2_device *csi2; struct isp_csi2_device *csi2;
struct regulator *vdd; struct regulator *vdd;
/* the entity that acquired the phy */
struct media_entity *entity;
/* mem resources - enums as defined in enum isp_mem_resources */ /* mem resources - enums as defined in enum isp_mem_resources */
unsigned int cfg_regs; unsigned int cfg_regs;
...@@ -36,7 +37,8 @@ struct isp_csiphy { ...@@ -36,7 +37,8 @@ struct isp_csiphy {
u8 num_data_lanes; /* number of CSI2 Data Lanes supported */ u8 num_data_lanes; /* number of CSI2 Data Lanes supported */
}; };
int omap3isp_csiphy_acquire(struct isp_csiphy *phy); int omap3isp_csiphy_acquire(struct isp_csiphy *phy,
struct media_entity *entity);
void omap3isp_csiphy_release(struct isp_csiphy *phy); void omap3isp_csiphy_release(struct isp_csiphy *phy);
int omap3isp_csiphy_init(struct isp_device *isp); int omap3isp_csiphy_init(struct isp_device *isp);
void omap3isp_csiphy_cleanup(struct isp_device *isp); void omap3isp_csiphy_cleanup(struct isp_device *isp);
......
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