Lines Matching +full:phy +full:- +full:mode

1 // SPDX-License-Identifier: GPL-2.0-only
5 * TI OMAP3 ISP - CSI PHY module
23 static void csiphy_routing_cfg_3630(struct isp_csiphy *phy, in csiphy_routing_cfg_3630() argument
28 u32 shift, mode; in csiphy_routing_cfg_3630() local
30 regmap_read(phy->isp->syscon, phy->isp->syscon_offset, &reg); in csiphy_routing_cfg_3630()
41 mode = OMAP3630_CONTROL_CAMERA_PHY_CTRL_CAMMODE_DPHY; in csiphy_routing_cfg_3630()
49 mode = OMAP3630_CONTROL_CAMERA_PHY_CTRL_CAMMODE_DPHY; in csiphy_routing_cfg_3630()
53 /* Select data/clock or data/strobe mode for CCP2 */ in csiphy_routing_cfg_3630()
57 mode = OMAP3630_CONTROL_CAMERA_PHY_CTRL_CAMMODE_CCP2_DATA_STROBE; in csiphy_routing_cfg_3630()
59 mode = OMAP3630_CONTROL_CAMERA_PHY_CTRL_CAMMODE_CCP2_DATA_CLOCK; in csiphy_routing_cfg_3630()
63 reg |= mode << shift; in csiphy_routing_cfg_3630()
65 regmap_write(phy->isp->syscon, phy->isp->syscon_offset, reg); in csiphy_routing_cfg_3630()
68 static void csiphy_routing_cfg_3430(struct isp_csiphy *phy, u32 iface, bool on, in csiphy_routing_cfg_3430() argument
79 regmap_write(phy->isp->syscon, phy->isp->syscon_offset, 0); in csiphy_routing_cfg_3430()
86 regmap_write(phy->isp->syscon, phy->isp->syscon_offset, csirxfe); in csiphy_routing_cfg_3430()
90 * Configure OMAP 3 CSI PHY routing.
91 * @phy: relevant phy device
98 * and 3630, so they will not hold their contents in off-mode. This isn't an
101 static void csiphy_routing_cfg(struct isp_csiphy *phy, in csiphy_routing_cfg() argument
105 if (phy->isp->phy_type == ISP_PHY_TYPE_3630 && on) in csiphy_routing_cfg()
106 return csiphy_routing_cfg_3630(phy, iface, ccp2_strobe); in csiphy_routing_cfg()
107 if (phy->isp->phy_type == ISP_PHY_TYPE_3430) in csiphy_routing_cfg()
108 return csiphy_routing_cfg_3430(phy, iface, on, ccp2_strobe); in csiphy_routing_cfg()
115 static void csiphy_power_autoswitch_enable(struct isp_csiphy *phy, bool enable) in csiphy_power_autoswitch_enable() argument
117 isp_reg_clr_set(phy->isp, phy->cfg_regs, ISPCSI2_PHY_CFG, in csiphy_power_autoswitch_enable()
126 * Returns 0 if successful, or -EBUSY if the retry count is exceeded.
128 static int csiphy_set_power(struct isp_csiphy *phy, u32 power) in csiphy_set_power() argument
133 isp_reg_clr_set(phy->isp, phy->cfg_regs, ISPCSI2_PHY_CFG, in csiphy_set_power()
139 reg = isp_reg_readl(phy->isp, phy->cfg_regs, ISPCSI2_PHY_CFG) & in csiphy_set_power()
148 dev_err(phy->isp->dev, "CSI2 CIO set power failed!\n"); in csiphy_set_power()
149 return -EBUSY; in csiphy_set_power()
162 static int omap3isp_csiphy_config(struct isp_csiphy *phy) in omap3isp_csiphy_config() argument
164 struct isp_pipeline *pipe = to_isp_pipeline(phy->entity); in omap3isp_csiphy_config()
165 struct isp_bus_cfg *buscfg = v4l2_subdev_to_bus_cfg(pipe->external); in omap3isp_csiphy_config()
172 if (buscfg->interface == ISP_INTERFACE_CCP2B_PHY1 in omap3isp_csiphy_config()
173 || buscfg->interface == ISP_INTERFACE_CCP2B_PHY2) { in omap3isp_csiphy_config()
174 lanes = &buscfg->bus.ccp2.lanecfg; in omap3isp_csiphy_config()
177 lanes = &buscfg->bus.csi2.lanecfg; in omap3isp_csiphy_config()
178 num_data_lanes = buscfg->bus.csi2.num_data_lanes; in omap3isp_csiphy_config()
181 if (num_data_lanes > phy->num_data_lanes) in omap3isp_csiphy_config()
182 return -EINVAL; in omap3isp_csiphy_config()
186 if (lanes->data[i].pol > 1 || lanes->data[i].pos > 3) in omap3isp_csiphy_config()
187 return -EINVAL; in omap3isp_csiphy_config()
189 if (used_lanes & (1 << lanes->data[i].pos)) in omap3isp_csiphy_config()
190 return -EINVAL; in omap3isp_csiphy_config()
192 used_lanes |= 1 << lanes->data[i].pos; in omap3isp_csiphy_config()
195 if (lanes->clk.pol > 1 || lanes->clk.pos > 3) in omap3isp_csiphy_config()
196 return -EINVAL; in omap3isp_csiphy_config()
198 if (lanes->clk.pos == 0 || used_lanes & (1 << lanes->clk.pos)) in omap3isp_csiphy_config()
199 return -EINVAL; in omap3isp_csiphy_config()
202 * The PHY configuration is lost in off mode, that's not an in omap3isp_csiphy_config()
206 csiphy_routing_cfg(phy, buscfg->interface, true, in omap3isp_csiphy_config()
207 buscfg->bus.ccp2.phy_layer); in omap3isp_csiphy_config()
210 /* CSI-2 is DDR and we only count used lanes. */ in omap3isp_csiphy_config()
211 csi2_ddrclk_khz = pipe->external_rate / 1000 in omap3isp_csiphy_config()
212 / (2 * hweight32(used_lanes)) * pipe->external_width; in omap3isp_csiphy_config()
214 reg = isp_reg_readl(phy->isp, phy->phy_regs, ISPCSIPHY_REG0); in omap3isp_csiphy_config()
218 /* THS_TERM: Programmed value = ceil(12.5 ns/DDRClk period) - 1. */ in omap3isp_csiphy_config()
219 reg |= (DIV_ROUND_UP(25 * csi2_ddrclk_khz, 2000000) - 1) in omap3isp_csiphy_config()
225 isp_reg_writel(phy->isp, reg, phy->phy_regs, ISPCSIPHY_REG0); in omap3isp_csiphy_config()
227 reg = isp_reg_readl(phy->isp, phy->phy_regs, ISPCSIPHY_REG1); in omap3isp_csiphy_config()
236 isp_reg_writel(phy->isp, reg, phy->phy_regs, ISPCSIPHY_REG1); in omap3isp_csiphy_config()
239 reg = isp_reg_readl(phy->isp, phy->cfg_regs, ISPCSI2_PHY_CFG); in omap3isp_csiphy_config()
244 reg |= (lanes->data[i].pol << in omap3isp_csiphy_config()
246 reg |= (lanes->data[i].pos << in omap3isp_csiphy_config()
252 reg |= lanes->clk.pol << ISPCSI2_PHY_CFG_CLOCK_POL_SHIFT; in omap3isp_csiphy_config()
253 reg |= lanes->clk.pos << ISPCSI2_PHY_CFG_CLOCK_POSITION_SHIFT; in omap3isp_csiphy_config()
255 isp_reg_writel(phy->isp, reg, phy->cfg_regs, ISPCSI2_PHY_CFG); in omap3isp_csiphy_config()
260 int omap3isp_csiphy_acquire(struct isp_csiphy *phy, struct media_entity *entity) in omap3isp_csiphy_acquire() argument
264 if (phy->vdd == NULL) { in omap3isp_csiphy_acquire()
265 dev_err(phy->isp->dev, in omap3isp_csiphy_acquire()
266 "Power regulator for CSI PHY not available\n"); in omap3isp_csiphy_acquire()
267 return -ENODEV; in omap3isp_csiphy_acquire()
270 mutex_lock(&phy->mutex); in omap3isp_csiphy_acquire()
272 rval = regulator_enable(phy->vdd); in omap3isp_csiphy_acquire()
276 rval = omap3isp_csi2_reset(phy->csi2); in omap3isp_csiphy_acquire()
280 phy->entity = entity; in omap3isp_csiphy_acquire()
282 rval = omap3isp_csiphy_config(phy); in omap3isp_csiphy_acquire()
286 if (phy->isp->revision == ISP_REVISION_15_0) { in omap3isp_csiphy_acquire()
287 rval = csiphy_set_power(phy, ISPCSI2_PHY_CFG_PWR_CMD_ON); in omap3isp_csiphy_acquire()
289 regulator_disable(phy->vdd); in omap3isp_csiphy_acquire()
293 csiphy_power_autoswitch_enable(phy, true); in omap3isp_csiphy_acquire()
297 phy->entity = NULL; in omap3isp_csiphy_acquire()
299 mutex_unlock(&phy->mutex); in omap3isp_csiphy_acquire()
303 void omap3isp_csiphy_release(struct isp_csiphy *phy) in omap3isp_csiphy_release() argument
305 mutex_lock(&phy->mutex); in omap3isp_csiphy_release()
306 if (phy->entity) { in omap3isp_csiphy_release()
307 struct isp_pipeline *pipe = to_isp_pipeline(phy->entity); in omap3isp_csiphy_release()
309 v4l2_subdev_to_bus_cfg(pipe->external); in omap3isp_csiphy_release()
311 csiphy_routing_cfg(phy, buscfg->interface, false, in omap3isp_csiphy_release()
312 buscfg->bus.ccp2.phy_layer); in omap3isp_csiphy_release()
313 if (phy->isp->revision == ISP_REVISION_15_0) { in omap3isp_csiphy_release()
314 csiphy_power_autoswitch_enable(phy, false); in omap3isp_csiphy_release()
315 csiphy_set_power(phy, ISPCSI2_PHY_CFG_PWR_CMD_OFF); in omap3isp_csiphy_release()
317 regulator_disable(phy->vdd); in omap3isp_csiphy_release()
318 phy->entity = NULL; in omap3isp_csiphy_release()
320 mutex_unlock(&phy->mutex); in omap3isp_csiphy_release()
324 * omap3isp_csiphy_init - Initialize the CSI PHY frontends
328 struct isp_csiphy *phy1 = &isp->isp_csiphy1; in omap3isp_csiphy_init()
329 struct isp_csiphy *phy2 = &isp->isp_csiphy2; in omap3isp_csiphy_init()
331 phy2->isp = isp; in omap3isp_csiphy_init()
332 phy2->csi2 = &isp->isp_csi2a; in omap3isp_csiphy_init()
333 phy2->num_data_lanes = ISP_CSIPHY2_NUM_DATA_LANES; in omap3isp_csiphy_init()
334 phy2->cfg_regs = OMAP3_ISP_IOMEM_CSI2A_REGS1; in omap3isp_csiphy_init()
335 phy2->phy_regs = OMAP3_ISP_IOMEM_CSIPHY2; in omap3isp_csiphy_init()
336 mutex_init(&phy2->mutex); in omap3isp_csiphy_init()
338 phy1->isp = isp; in omap3isp_csiphy_init()
339 mutex_init(&phy1->mutex); in omap3isp_csiphy_init()
341 if (isp->revision == ISP_REVISION_15_0) { in omap3isp_csiphy_init()
342 phy1->csi2 = &isp->isp_csi2c; in omap3isp_csiphy_init()
343 phy1->num_data_lanes = ISP_CSIPHY1_NUM_DATA_LANES; in omap3isp_csiphy_init()
344 phy1->cfg_regs = OMAP3_ISP_IOMEM_CSI2C_REGS1; in omap3isp_csiphy_init()
345 phy1->phy_regs = OMAP3_ISP_IOMEM_CSIPHY1; in omap3isp_csiphy_init()
353 mutex_destroy(&isp->isp_csiphy1.mutex); in omap3isp_csiphy_cleanup()
354 mutex_destroy(&isp->isp_csiphy2.mutex); in omap3isp_csiphy_cleanup()