Lines Matching +full:dphy +full:- +full:cfg
1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright: 2017-2018 Cadence Design Systems, Inc.
17 #include <linux/phy/phy-mipi-dphy.h>
23 /* DPHY registers */
94 int (*probe)(struct cdns_dphy *dphy);
95 void (*remove)(struct cdns_dphy *dphy);
96 void (*set_psm_div)(struct cdns_dphy *dphy, u8 div);
97 void (*set_clk_lane_cfg)(struct cdns_dphy *dphy,
98 enum cdns_dphy_clk_lane_cfg cfg);
99 void (*set_pll_cfg)(struct cdns_dphy *dphy,
100 const struct cdns_dphy_cfg *cfg);
101 unsigned long (*get_wakeup_time_ns)(struct cdns_dphy *dphy);
105 struct cdns_dphy_cfg cfg; member
119 static int cdns_dsi_get_dphy_pll_cfg(struct cdns_dphy *dphy, in cdns_dsi_get_dphy_pll_cfg() argument
120 struct cdns_dphy_cfg *cfg, in cdns_dsi_get_dphy_pll_cfg() argument
124 unsigned long pll_ref_hz = clk_get_rate(dphy->pll_ref_clk); in cdns_dsi_get_dphy_pll_cfg()
127 memset(cfg, 0, sizeof(*cfg)); in cdns_dsi_get_dphy_pll_cfg()
130 return -EINVAL; in cdns_dsi_get_dphy_pll_cfg()
132 cfg->pll_ipdiv = 1; in cdns_dsi_get_dphy_pll_cfg()
134 cfg->pll_ipdiv = 2; in cdns_dsi_get_dphy_pll_cfg()
136 cfg->pll_ipdiv = 4; in cdns_dsi_get_dphy_pll_cfg()
138 cfg->pll_ipdiv = 8; in cdns_dsi_get_dphy_pll_cfg()
140 dlane_bps = opts->hs_clk_rate; in cdns_dsi_get_dphy_pll_cfg()
143 return -EINVAL; in cdns_dsi_get_dphy_pll_cfg()
145 cfg->pll_opdiv = 1; in cdns_dsi_get_dphy_pll_cfg()
147 cfg->pll_opdiv = 2; in cdns_dsi_get_dphy_pll_cfg()
149 cfg->pll_opdiv = 4; in cdns_dsi_get_dphy_pll_cfg()
151 cfg->pll_opdiv = 8; in cdns_dsi_get_dphy_pll_cfg()
153 cfg->pll_fbdiv = DIV_ROUND_UP_ULL(dlane_bps * 2 * cfg->pll_opdiv * in cdns_dsi_get_dphy_pll_cfg()
154 cfg->pll_ipdiv, in cdns_dsi_get_dphy_pll_cfg()
160 static int cdns_dphy_setup_psm(struct cdns_dphy *dphy) in cdns_dphy_setup_psm() argument
162 unsigned long psm_clk_hz = clk_get_rate(dphy->psm_clk); in cdns_dphy_setup_psm()
166 return -EINVAL; in cdns_dphy_setup_psm()
169 if (dphy->ops->set_psm_div) in cdns_dphy_setup_psm()
170 dphy->ops->set_psm_div(dphy, psm_div); in cdns_dphy_setup_psm()
175 static void cdns_dphy_set_clk_lane_cfg(struct cdns_dphy *dphy, in cdns_dphy_set_clk_lane_cfg() argument
176 enum cdns_dphy_clk_lane_cfg cfg) in cdns_dphy_set_clk_lane_cfg() argument
178 if (dphy->ops->set_clk_lane_cfg) in cdns_dphy_set_clk_lane_cfg()
179 dphy->ops->set_clk_lane_cfg(dphy, cfg); in cdns_dphy_set_clk_lane_cfg()
182 static void cdns_dphy_set_pll_cfg(struct cdns_dphy *dphy, in cdns_dphy_set_pll_cfg() argument
183 const struct cdns_dphy_cfg *cfg) in cdns_dphy_set_pll_cfg() argument
185 if (dphy->ops->set_pll_cfg) in cdns_dphy_set_pll_cfg()
186 dphy->ops->set_pll_cfg(dphy, cfg); in cdns_dphy_set_pll_cfg()
189 static unsigned long cdns_dphy_get_wakeup_time_ns(struct cdns_dphy *dphy) in cdns_dphy_get_wakeup_time_ns() argument
191 return dphy->ops->get_wakeup_time_ns(dphy); in cdns_dphy_get_wakeup_time_ns()
194 static unsigned long cdns_dphy_ref_get_wakeup_time_ns(struct cdns_dphy *dphy) in cdns_dphy_ref_get_wakeup_time_ns() argument
200 static void cdns_dphy_ref_set_pll_cfg(struct cdns_dphy *dphy, in cdns_dphy_ref_set_pll_cfg() argument
201 const struct cdns_dphy_cfg *cfg) in cdns_dphy_ref_set_pll_cfg() argument
205 fbdiv_low = (cfg->pll_fbdiv / 4) - 2; in cdns_dphy_ref_set_pll_cfg()
206 fbdiv_high = cfg->pll_fbdiv - fbdiv_low - 2; in cdns_dphy_ref_set_pll_cfg()
209 DPHY_CMN_IPDIV(cfg->pll_ipdiv) | in cdns_dphy_ref_set_pll_cfg()
210 DPHY_CMN_OPDIV(cfg->pll_opdiv), in cdns_dphy_ref_set_pll_cfg()
211 dphy->regs + DPHY_CMN_OPIPDIV); in cdns_dphy_ref_set_pll_cfg()
214 dphy->regs + DPHY_CMN_FBDIV); in cdns_dphy_ref_set_pll_cfg()
217 dphy->regs + DPHY_CMN_PWM); in cdns_dphy_ref_set_pll_cfg()
220 static void cdns_dphy_ref_set_psm_div(struct cdns_dphy *dphy, u8 div) in cdns_dphy_ref_set_psm_div() argument
223 dphy->regs + DPHY_PSM_CFG); in cdns_dphy_ref_set_psm_div()
226 static unsigned long cdns_dphy_j721e_get_wakeup_time_ns(struct cdns_dphy *dphy) in cdns_dphy_j721e_get_wakeup_time_ns() argument
228 /* Minimum wakeup time as per MIPI D-PHY spec v1.2 */ in cdns_dphy_j721e_get_wakeup_time_ns()
232 static void cdns_dphy_j721e_set_pll_cfg(struct cdns_dphy *dphy, in cdns_dphy_j721e_set_pll_cfg() argument
233 const struct cdns_dphy_cfg *cfg) in cdns_dphy_j721e_set_pll_cfg() argument
243 dphy->regs + DPHY_CMN_PWM); in cdns_dphy_j721e_set_pll_cfg()
245 writel((FIELD_PREP(DPHY_TX_J721E_WIZ_IPDIV, cfg->pll_ipdiv) | in cdns_dphy_j721e_set_pll_cfg()
246 FIELD_PREP(DPHY_TX_J721E_WIZ_OPDIV, cfg->pll_opdiv) | in cdns_dphy_j721e_set_pll_cfg()
247 FIELD_PREP(DPHY_TX_J721E_WIZ_FBDIV, cfg->pll_fbdiv)), in cdns_dphy_j721e_set_pll_cfg()
248 dphy->regs + DPHY_TX_J721E_WIZ_PLL_CTRL); in cdns_dphy_j721e_set_pll_cfg()
251 dphy->regs + DPHY_TX_J721E_WIZ_RST_CTRL); in cdns_dphy_j721e_set_pll_cfg()
253 readl_poll_timeout(dphy->regs + DPHY_TX_J721E_WIZ_PLL_CTRL, status, in cdns_dphy_j721e_set_pll_cfg()
256 readl_poll_timeout(dphy->regs + DPHY_TX_J721E_WIZ_STATUS, status, in cdns_dphy_j721e_set_pll_cfg()
261 static void cdns_dphy_j721e_set_psm_div(struct cdns_dphy *dphy, u8 div) in cdns_dphy_j721e_set_psm_div() argument
263 writel(div, dphy->regs + DPHY_TX_J721E_WIZ_PSM_FREQ); in cdns_dphy_j721e_set_psm_div()
267 * This is the reference implementation of DPHY hooks. Specific integration of
268 * this IP may have to re-implement some of them depending on how they decided
285 struct cdns_dphy_cfg *cfg) in cdns_dphy_config_from_opts() argument
287 struct cdns_dphy *dphy = phy_get_drvdata(phy); in cdns_dphy_config_from_opts() local
295 ret = cdns_dsi_get_dphy_pll_cfg(dphy, cfg, in cdns_dphy_config_from_opts()
300 opts->wakeup = cdns_dphy_get_wakeup_time_ns(dphy) / 1000; in cdns_dphy_config_from_opts()
313 return -EOPNOTSUPP; in cdns_dphy_tx_get_band_ctrl()
315 for (i = 0; i < ARRAY_SIZE(tx_bands) - 1; i++) { in cdns_dphy_tx_get_band_ctrl()
320 return -EOPNOTSUPP; in cdns_dphy_tx_get_band_ctrl()
326 struct cdns_dphy_cfg cfg = { 0 }; in cdns_dphy_validate() local
329 return -EINVAL; in cdns_dphy_validate()
331 return cdns_dphy_config_from_opts(phy, &opts->mipi_dphy, &cfg); in cdns_dphy_validate()
336 struct cdns_dphy *dphy = phy_get_drvdata(phy); in cdns_dphy_configure() local
337 struct cdns_dphy_cfg cfg = { 0 }; in cdns_dphy_configure() local
341 ret = cdns_dphy_config_from_opts(phy, &opts->mipi_dphy, &cfg); in cdns_dphy_configure()
346 * Configure the internal PSM clk divider so that the DPHY has a in cdns_dphy_configure()
349 ret = cdns_dphy_setup_psm(dphy); in cdns_dphy_configure()
354 * Configure attach clk lanes to data lanes: the DPHY has 2 clk lanes in cdns_dphy_configure()
360 cdns_dphy_set_clk_lane_cfg(dphy, DPHY_CLK_CFG_LEFT_DRIVES_LEFT); in cdns_dphy_configure()
363 * Configure the DPHY PLL that will be used to generate the TX byte in cdns_dphy_configure()
366 cdns_dphy_set_pll_cfg(dphy, &cfg); in cdns_dphy_configure()
368 band_ctrl = cdns_dphy_tx_get_band_ctrl(opts->mipi_dphy.hs_clk_rate); in cdns_dphy_configure()
374 writel(reg, dphy->regs + DPHY_BAND_CFG); in cdns_dphy_configure()
381 struct cdns_dphy *dphy = phy_get_drvdata(phy); in cdns_dphy_power_on() local
383 clk_prepare_enable(dphy->psm_clk); in cdns_dphy_power_on()
384 clk_prepare_enable(dphy->pll_ref_clk); in cdns_dphy_power_on()
388 dphy->regs + DPHY_CMN_SSM); in cdns_dphy_power_on()
395 struct cdns_dphy *dphy = phy_get_drvdata(phy); in cdns_dphy_power_off() local
397 clk_disable_unprepare(dphy->pll_ref_clk); in cdns_dphy_power_off()
398 clk_disable_unprepare(dphy->psm_clk); in cdns_dphy_power_off()
413 struct cdns_dphy *dphy; in cdns_dphy_probe() local
416 dphy = devm_kzalloc(&pdev->dev, sizeof(*dphy), GFP_KERNEL); in cdns_dphy_probe()
417 if (!dphy) in cdns_dphy_probe()
418 return -ENOMEM; in cdns_dphy_probe()
419 dev_set_drvdata(&pdev->dev, dphy); in cdns_dphy_probe()
421 dphy->ops = of_device_get_match_data(&pdev->dev); in cdns_dphy_probe()
422 if (!dphy->ops) in cdns_dphy_probe()
423 return -EINVAL; in cdns_dphy_probe()
425 dphy->regs = devm_platform_ioremap_resource(pdev, 0); in cdns_dphy_probe()
426 if (IS_ERR(dphy->regs)) in cdns_dphy_probe()
427 return PTR_ERR(dphy->regs); in cdns_dphy_probe()
429 dphy->psm_clk = devm_clk_get(&pdev->dev, "psm"); in cdns_dphy_probe()
430 if (IS_ERR(dphy->psm_clk)) in cdns_dphy_probe()
431 return PTR_ERR(dphy->psm_clk); in cdns_dphy_probe()
433 dphy->pll_ref_clk = devm_clk_get(&pdev->dev, "pll_ref"); in cdns_dphy_probe()
434 if (IS_ERR(dphy->pll_ref_clk)) in cdns_dphy_probe()
435 return PTR_ERR(dphy->pll_ref_clk); in cdns_dphy_probe()
437 if (dphy->ops->probe) { in cdns_dphy_probe()
438 ret = dphy->ops->probe(dphy); in cdns_dphy_probe()
443 dphy->phy = devm_phy_create(&pdev->dev, NULL, &cdns_dphy_ops); in cdns_dphy_probe()
444 if (IS_ERR(dphy->phy)) { in cdns_dphy_probe()
445 dev_err(&pdev->dev, "failed to create PHY\n"); in cdns_dphy_probe()
446 if (dphy->ops->remove) in cdns_dphy_probe()
447 dphy->ops->remove(dphy); in cdns_dphy_probe()
448 return PTR_ERR(dphy->phy); in cdns_dphy_probe()
451 phy_set_drvdata(dphy->phy, dphy); in cdns_dphy_probe()
452 phy_provider = devm_of_phy_provider_register(&pdev->dev, in cdns_dphy_probe()
460 struct cdns_dphy *dphy = dev_get_drvdata(&pdev->dev); in cdns_dphy_remove() local
462 if (dphy->ops->remove) in cdns_dphy_remove()
463 dphy->ops->remove(dphy); in cdns_dphy_remove()
467 { .compatible = "cdns,dphy", .data = &ref_dphy_ops },
468 { .compatible = "ti,j721e-dphy", .data = &j721e_dphy_ops },
477 .name = "cdns-mipi-dphy",
484 MODULE_DESCRIPTION("Cadence MIPI D-PHY Driver");