Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Sakari Ailus <sakari.ailus@linux.intel.com>
Tested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> # on Beagleboard-xM + MPT9P031
Acked-by: Pavel Machek <pavel@ucw.cz>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>

authored by

Sakari Ailus and committed by
Mauro Carvalho Chehab
7e1db599 19be9fd6

+27 -30
+1 -1
drivers/media/platform/omap3isp/ispccp2.c
··· 841 841 switch (enable) { 842 842 case ISP_PIPELINE_STREAM_CONTINUOUS: 843 843 if (ccp2->phy) { 844 - ret = omap3isp_csiphy_acquire(ccp2->phy); 844 + ret = omap3isp_csiphy_acquire(ccp2->phy, &sd->entity); 845 845 if (ret < 0) 846 846 return ret; 847 847 }
+2 -2
drivers/media/platform/omap3isp/ispcsi2.c
··· 490 490 if (!csi2->available) 491 491 return -ENODEV; 492 492 493 - if (csi2->phy->phy_in_use) 493 + if (csi2->phy->entity) 494 494 return -EBUSY; 495 495 496 496 isp_reg_set(isp, csi2->regs1, ISPCSI2_SYSCONFIG, ··· 1053 1053 1054 1054 switch (enable) { 1055 1055 case ISP_PIPELINE_STREAM_CONTINUOUS: 1056 - if (omap3isp_csiphy_acquire(csi2->phy) < 0) 1056 + if (omap3isp_csiphy_acquire(csi2->phy, &sd->entity) < 0) 1057 1057 return -ENODEV; 1058 1058 if (csi2->output & CSI2_OUTPUT_MEMORY) 1059 1059 omap3isp_sbl_enable(isp, OMAP3_ISP_SBL_CSI2A_WRITE);
+20 -25
drivers/media/platform/omap3isp/ispcsiphy.c
··· 164 164 165 165 static int omap3isp_csiphy_config(struct isp_csiphy *phy) 166 166 { 167 - struct isp_csi2_device *csi2 = phy->csi2; 168 - struct isp_pipeline *pipe = to_isp_pipeline(&csi2->subdev.entity); 169 - struct isp_bus_cfg *buscfg = pipe->external->host_priv; 167 + struct isp_pipeline *pipe = to_isp_pipeline(phy->entity); 168 + struct isp_async_subdev *isd = 169 + container_of(pipe->external->asd, struct isp_async_subdev, asd); 170 + struct isp_bus_cfg *buscfg = pipe->external->host_priv ? 171 + pipe->external->host_priv : &isd->bus; 170 172 struct isp_csiphy_lanes_cfg *lanes; 171 173 int csi2_ddrclk_khz; 172 174 unsigned int num_data_lanes, used_lanes = 0; 173 175 unsigned int i; 174 176 u32 reg; 175 - 176 - if (!buscfg) { 177 - struct isp_async_subdev *isd = 178 - container_of(pipe->external->asd, 179 - struct isp_async_subdev, asd); 180 - buscfg = &isd->bus; 181 - } 182 177 183 178 if (buscfg->interface == ISP_INTERFACE_CCP2B_PHY1 184 179 || buscfg->interface == ISP_INTERFACE_CCP2B_PHY2) { ··· 217 222 csi2_ddrclk_khz = pipe->external_rate / 1000 218 223 / (2 * hweight32(used_lanes)) * pipe->external_width; 219 224 220 - reg = isp_reg_readl(csi2->isp, phy->phy_regs, ISPCSIPHY_REG0); 225 + reg = isp_reg_readl(phy->isp, phy->phy_regs, ISPCSIPHY_REG0); 221 226 222 227 reg &= ~(ISPCSIPHY_REG0_THS_TERM_MASK | 223 228 ISPCSIPHY_REG0_THS_SETTLE_MASK); ··· 228 233 reg |= (DIV_ROUND_UP(90 * csi2_ddrclk_khz, 1000000) + 3) 229 234 << ISPCSIPHY_REG0_THS_SETTLE_SHIFT; 230 235 231 - isp_reg_writel(csi2->isp, reg, phy->phy_regs, ISPCSIPHY_REG0); 236 + isp_reg_writel(phy->isp, reg, phy->phy_regs, ISPCSIPHY_REG0); 232 237 233 - reg = isp_reg_readl(csi2->isp, phy->phy_regs, ISPCSIPHY_REG1); 238 + reg = isp_reg_readl(phy->isp, phy->phy_regs, ISPCSIPHY_REG1); 234 239 235 240 reg &= ~(ISPCSIPHY_REG1_TCLK_TERM_MASK | 236 241 ISPCSIPHY_REG1_TCLK_MISS_MASK | ··· 239 244 reg |= TCLK_MISS << ISPCSIPHY_REG1_TCLK_MISS_SHIFT; 240 245 reg |= TCLK_SETTLE << ISPCSIPHY_REG1_TCLK_SETTLE_SHIFT; 241 246 242 - isp_reg_writel(csi2->isp, reg, phy->phy_regs, ISPCSIPHY_REG1); 247 + isp_reg_writel(phy->isp, reg, phy->phy_regs, ISPCSIPHY_REG1); 243 248 244 249 /* DPHY lane configuration */ 245 - reg = isp_reg_readl(csi2->isp, phy->cfg_regs, ISPCSI2_PHY_CFG); 250 + reg = isp_reg_readl(phy->isp, phy->cfg_regs, ISPCSI2_PHY_CFG); 246 251 247 252 for (i = 0; i < num_data_lanes; i++) { 248 253 reg &= ~(ISPCSI2_PHY_CFG_DATA_POL_MASK(i + 1) | ··· 258 263 reg |= lanes->clk.pol << ISPCSI2_PHY_CFG_CLOCK_POL_SHIFT; 259 264 reg |= lanes->clk.pos << ISPCSI2_PHY_CFG_CLOCK_POSITION_SHIFT; 260 265 261 - isp_reg_writel(csi2->isp, reg, phy->cfg_regs, ISPCSI2_PHY_CFG); 266 + isp_reg_writel(phy->isp, reg, phy->cfg_regs, ISPCSI2_PHY_CFG); 262 267 263 268 return 0; 264 269 } 265 270 266 - int omap3isp_csiphy_acquire(struct isp_csiphy *phy) 271 + int omap3isp_csiphy_acquire(struct isp_csiphy *phy, struct media_entity *entity) 267 272 { 268 273 int rval; 269 274 ··· 283 288 if (rval < 0) 284 289 goto done; 285 290 291 + phy->entity = entity; 292 + 286 293 rval = omap3isp_csiphy_config(phy); 287 294 if (rval < 0) 288 295 goto done; ··· 298 301 299 302 csiphy_power_autoswitch_enable(phy, true); 300 303 } 301 - 302 - phy->phy_in_use = 1; 303 - 304 304 done: 305 + if (rval < 0) 306 + phy->entity = NULL; 307 + 305 308 mutex_unlock(&phy->mutex); 306 309 return rval; 307 310 } ··· 309 312 void omap3isp_csiphy_release(struct isp_csiphy *phy) 310 313 { 311 314 mutex_lock(&phy->mutex); 312 - if (phy->phy_in_use) { 313 - struct isp_csi2_device *csi2 = phy->csi2; 314 - struct isp_pipeline *pipe = 315 - to_isp_pipeline(&csi2->subdev.entity); 315 + if (phy->entity) { 316 + struct isp_pipeline *pipe = to_isp_pipeline(phy->entity); 316 317 struct isp_bus_cfg *buscfg = pipe->external->host_priv; 317 318 318 319 csiphy_routing_cfg(phy, buscfg->interface, false, ··· 320 325 csiphy_set_power(phy, ISPCSI2_PHY_CFG_PWR_CMD_OFF); 321 326 } 322 327 regulator_disable(phy->vdd); 323 - phy->phy_in_use = 0; 328 + phy->entity = NULL; 324 329 } 325 330 mutex_unlock(&phy->mutex); 326 331 }
+4 -2
drivers/media/platform/omap3isp/ispcsiphy.h
··· 25 25 struct isp_csiphy { 26 26 struct isp_device *isp; 27 27 struct mutex mutex; /* serialize csiphy configuration */ 28 - u8 phy_in_use; 29 28 struct isp_csi2_device *csi2; 30 29 struct regulator *vdd; 30 + /* the entity that acquired the phy */ 31 + struct media_entity *entity; 31 32 32 33 /* mem resources - enums as defined in enum isp_mem_resources */ 33 34 unsigned int cfg_regs; ··· 37 36 u8 num_data_lanes; /* number of CSI2 Data Lanes supported */ 38 37 }; 39 38 40 - int omap3isp_csiphy_acquire(struct isp_csiphy *phy); 39 + int omap3isp_csiphy_acquire(struct isp_csiphy *phy, 40 + struct media_entity *entity); 41 41 void omap3isp_csiphy_release(struct isp_csiphy *phy); 42 42 int omap3isp_csiphy_init(struct isp_device *isp); 43 43 void omap3isp_csiphy_cleanup(struct isp_device *isp);