Lines Matching full:dphy

17 #include <linux/phy/phy-mipi-dphy.h>
23 /* DPHY registers */
88 int (*probe)(struct cdns_dphy *dphy);
89 void (*remove)(struct cdns_dphy *dphy);
90 void (*set_psm_div)(struct cdns_dphy *dphy, u8 div);
91 void (*set_clk_lane_cfg)(struct cdns_dphy *dphy,
93 void (*set_pll_cfg)(struct cdns_dphy *dphy,
95 unsigned long (*get_wakeup_time_ns)(struct cdns_dphy *dphy);
96 int (*wait_for_pll_lock)(struct cdns_dphy *dphy);
97 int (*wait_for_cmn_ready)(struct cdns_dphy *dphy);
117 static int cdns_dphy_get_pll_cfg(struct cdns_dphy *dphy, in cdns_dphy_get_pll_cfg() argument
121 unsigned long pll_ref_hz = clk_get_rate(dphy->pll_ref_clk); in cdns_dphy_get_pll_cfg()
162 static int cdns_dphy_setup_psm(struct cdns_dphy *dphy) in cdns_dphy_setup_psm() argument
164 unsigned long psm_clk_hz = clk_get_rate(dphy->psm_clk); in cdns_dphy_setup_psm()
171 if (dphy->ops->set_psm_div) in cdns_dphy_setup_psm()
172 dphy->ops->set_psm_div(dphy, psm_div); in cdns_dphy_setup_psm()
177 static void cdns_dphy_set_clk_lane_cfg(struct cdns_dphy *dphy, in cdns_dphy_set_clk_lane_cfg() argument
180 if (dphy->ops->set_clk_lane_cfg) in cdns_dphy_set_clk_lane_cfg()
181 dphy->ops->set_clk_lane_cfg(dphy, cfg); in cdns_dphy_set_clk_lane_cfg()
184 static void cdns_dphy_set_pll_cfg(struct cdns_dphy *dphy, in cdns_dphy_set_pll_cfg() argument
187 if (dphy->ops->set_pll_cfg) in cdns_dphy_set_pll_cfg()
188 dphy->ops->set_pll_cfg(dphy, cfg); in cdns_dphy_set_pll_cfg()
191 static unsigned long cdns_dphy_get_wakeup_time_ns(struct cdns_dphy *dphy) in cdns_dphy_get_wakeup_time_ns() argument
193 return dphy->ops->get_wakeup_time_ns(dphy); in cdns_dphy_get_wakeup_time_ns()
196 static int cdns_dphy_wait_for_pll_lock(struct cdns_dphy *dphy) in cdns_dphy_wait_for_pll_lock() argument
198 return dphy->ops->wait_for_pll_lock ? dphy->ops->wait_for_pll_lock(dphy) : 0; in cdns_dphy_wait_for_pll_lock()
201 static int cdns_dphy_wait_for_cmn_ready(struct cdns_dphy *dphy) in cdns_dphy_wait_for_cmn_ready() argument
203 return dphy->ops->wait_for_cmn_ready ? dphy->ops->wait_for_cmn_ready(dphy) : 0; in cdns_dphy_wait_for_cmn_ready()
206 static unsigned long cdns_dphy_ref_get_wakeup_time_ns(struct cdns_dphy *dphy) in cdns_dphy_ref_get_wakeup_time_ns() argument
212 static void cdns_dphy_ref_set_pll_cfg(struct cdns_dphy *dphy, in cdns_dphy_ref_set_pll_cfg() argument
223 dphy->regs + DPHY_CMN_OPIPDIV); in cdns_dphy_ref_set_pll_cfg()
226 dphy->regs + DPHY_CMN_FBDIV); in cdns_dphy_ref_set_pll_cfg()
229 dphy->regs + DPHY_CMN_PWM); in cdns_dphy_ref_set_pll_cfg()
232 static void cdns_dphy_ref_set_psm_div(struct cdns_dphy *dphy, u8 div) in cdns_dphy_ref_set_psm_div() argument
235 dphy->regs + DPHY_PSM_CFG); in cdns_dphy_ref_set_psm_div()
238 static unsigned long cdns_dphy_j721e_get_wakeup_time_ns(struct cdns_dphy *dphy) in cdns_dphy_j721e_get_wakeup_time_ns() argument
244 static void cdns_dphy_j721e_set_pll_cfg(struct cdns_dphy *dphy, in cdns_dphy_j721e_set_pll_cfg() argument
254 dphy->regs + DPHY_CMN_PWM); in cdns_dphy_j721e_set_pll_cfg()
259 dphy->regs + DPHY_TX_J721E_WIZ_PLL_CTRL); in cdns_dphy_j721e_set_pll_cfg()
262 dphy->regs + DPHY_TX_J721E_WIZ_RST_CTRL); in cdns_dphy_j721e_set_pll_cfg()
265 static void cdns_dphy_j721e_set_psm_div(struct cdns_dphy *dphy, u8 div) in cdns_dphy_j721e_set_psm_div() argument
267 writel(div, dphy->regs + DPHY_TX_J721E_WIZ_PSM_FREQ); in cdns_dphy_j721e_set_psm_div()
270 static int cdns_dphy_j721e_wait_for_pll_lock(struct cdns_dphy *dphy) in cdns_dphy_j721e_wait_for_pll_lock() argument
274 return readl_poll_timeout(dphy->regs + DPHY_TX_J721E_WIZ_PLL_CTRL, status, in cdns_dphy_j721e_wait_for_pll_lock()
278 static int cdns_dphy_j721e_wait_for_cmn_ready(struct cdns_dphy *dphy) in cdns_dphy_j721e_wait_for_cmn_ready() argument
282 return readl_poll_timeout(dphy->regs + DPHY_TX_J721E_WIZ_STATUS, status, in cdns_dphy_j721e_wait_for_cmn_ready()
288 * This is the reference implementation of DPHY hooks. Specific integration of
310 struct cdns_dphy *dphy = phy_get_drvdata(phy); in cdns_dphy_config_from_opts() local
317 ret = cdns_dphy_get_pll_cfg(dphy, cfg, opts); in cdns_dphy_config_from_opts()
322 opts->wakeup = cdns_dphy_get_wakeup_time_ns(dphy) / 1000; in cdns_dphy_config_from_opts()
358 struct cdns_dphy *dphy = phy_get_drvdata(phy); in cdns_dphy_configure() local
361 ret = cdns_dphy_config_from_opts(phy, &opts->mipi_dphy, &dphy->cfg); in cdns_dphy_configure()
363 dphy->is_configured = true; in cdns_dphy_configure()
370 struct cdns_dphy *dphy = phy_get_drvdata(phy); in cdns_dphy_power_on() local
374 if (!dphy->is_configured || dphy->is_powered) in cdns_dphy_power_on()
377 clk_prepare_enable(dphy->psm_clk); in cdns_dphy_power_on()
378 clk_prepare_enable(dphy->pll_ref_clk); in cdns_dphy_power_on()
381 * Configure the internal PSM clk divider so that the DPHY has a in cdns_dphy_power_on()
384 ret = cdns_dphy_setup_psm(dphy); in cdns_dphy_power_on()
386 dev_err(&dphy->phy->dev, "Failed to setup PSM with error %d\n", ret); in cdns_dphy_power_on()
391 * Configure attach clk lanes to data lanes: the DPHY has 2 clk lanes in cdns_dphy_power_on()
397 cdns_dphy_set_clk_lane_cfg(dphy, DPHY_CLK_CFG_LEFT_DRIVES_LEFT); in cdns_dphy_power_on()
400 * Configure the DPHY PLL that will be used to generate the TX byte in cdns_dphy_power_on()
403 cdns_dphy_set_pll_cfg(dphy, &dphy->cfg); in cdns_dphy_power_on()
405 ret = cdns_dphy_tx_get_band_ctrl(dphy->cfg.hs_clk_rate); in cdns_dphy_power_on()
407 dev_err(&dphy->phy->dev, "Failed to get band control value with error %d\n", ret); in cdns_dphy_power_on()
413 writel(reg, dphy->regs + DPHY_BAND_CFG); in cdns_dphy_power_on()
416 reg = readl(dphy->regs + DPHY_CMN_SSM); in cdns_dphy_power_on()
418 dphy->regs + DPHY_CMN_SSM); in cdns_dphy_power_on()
420 ret = cdns_dphy_wait_for_pll_lock(dphy); in cdns_dphy_power_on()
422 dev_err(&dphy->phy->dev, "Failed to lock PLL with error %d\n", ret); in cdns_dphy_power_on()
426 ret = cdns_dphy_wait_for_cmn_ready(dphy); in cdns_dphy_power_on()
428 dev_err(&dphy->phy->dev, "O_CMN_READY signal failed to assert with error %d\n", in cdns_dphy_power_on()
433 dphy->is_powered = true; in cdns_dphy_power_on()
438 clk_disable_unprepare(dphy->pll_ref_clk); in cdns_dphy_power_on()
439 clk_disable_unprepare(dphy->psm_clk); in cdns_dphy_power_on()
446 struct cdns_dphy *dphy = phy_get_drvdata(phy); in cdns_dphy_power_off() local
449 clk_disable_unprepare(dphy->pll_ref_clk); in cdns_dphy_power_off()
450 clk_disable_unprepare(dphy->psm_clk); in cdns_dphy_power_off()
453 reg = readl(dphy->regs + DPHY_CMN_SSM); in cdns_dphy_power_off()
454 writel(reg & ~DPHY_CMN_SSM_EN, dphy->regs + DPHY_CMN_SSM); in cdns_dphy_power_off()
456 dphy->is_powered = false; in cdns_dphy_power_off()
471 struct cdns_dphy *dphy; in cdns_dphy_probe() local
474 dphy = devm_kzalloc(&pdev->dev, sizeof(*dphy), GFP_KERNEL); in cdns_dphy_probe()
475 if (!dphy) in cdns_dphy_probe()
477 dev_set_drvdata(&pdev->dev, dphy); in cdns_dphy_probe()
479 dphy->ops = of_device_get_match_data(&pdev->dev); in cdns_dphy_probe()
480 if (!dphy->ops) in cdns_dphy_probe()
483 dphy->regs = devm_platform_ioremap_resource(pdev, 0); in cdns_dphy_probe()
484 if (IS_ERR(dphy->regs)) in cdns_dphy_probe()
485 return PTR_ERR(dphy->regs); in cdns_dphy_probe()
487 dphy->psm_clk = devm_clk_get(&pdev->dev, "psm"); in cdns_dphy_probe()
488 if (IS_ERR(dphy->psm_clk)) in cdns_dphy_probe()
489 return PTR_ERR(dphy->psm_clk); in cdns_dphy_probe()
491 dphy->pll_ref_clk = devm_clk_get(&pdev->dev, "pll_ref"); in cdns_dphy_probe()
492 if (IS_ERR(dphy->pll_ref_clk)) in cdns_dphy_probe()
493 return PTR_ERR(dphy->pll_ref_clk); in cdns_dphy_probe()
495 if (dphy->ops->probe) { in cdns_dphy_probe()
496 ret = dphy->ops->probe(dphy); in cdns_dphy_probe()
501 dphy->phy = devm_phy_create(&pdev->dev, NULL, &cdns_dphy_ops); in cdns_dphy_probe()
502 if (IS_ERR(dphy->phy)) { in cdns_dphy_probe()
504 if (dphy->ops->remove) in cdns_dphy_probe()
505 dphy->ops->remove(dphy); in cdns_dphy_probe()
506 return PTR_ERR(dphy->phy); in cdns_dphy_probe()
509 phy_set_drvdata(dphy->phy, dphy); in cdns_dphy_probe()
518 struct cdns_dphy *dphy = dev_get_drvdata(&pdev->dev); in cdns_dphy_remove() local
520 if (dphy->ops->remove) in cdns_dphy_remove()
521 dphy->ops->remove(dphy); in cdns_dphy_remove()
525 { .compatible = "cdns,dphy", .data = &ref_dphy_ops },
526 { .compatible = "ti,j721e-dphy", .data = &j721e_dphy_ops },
535 .name = "cdns-mipi-dphy",