Lines Matching +full:sierra +full:- +full:phy +full:- +full:t0
1 // SPDX-License-Identifier: GPL-2.0
3 * Cadence Sierra PHY Driver
14 #include <linux/phy/phy.h>
22 #include <dt-bindings/phy/phy.h>
24 /* PHY register offsets */
155 struct phy *phy; member
211 u32 offset = reg << ctx->reg_offset_shift; in cdns_regmap_write()
213 writew(val, ctx->base + offset); in cdns_regmap_write()
221 u32 offset = reg << ctx->reg_offset_shift; in cdns_regmap_read()
223 *val = readw(ctx->base + offset); in cdns_regmap_read()
271 static int cdns_sierra_phy_init(struct phy *gphy) in cdns_sierra_phy_init()
274 struct cdns_sierra_phy *phy = dev_get_drvdata(gphy->dev.parent); in cdns_sierra_phy_init() local
280 /* Initialise the PHY registers, unless auto configured */ in cdns_sierra_phy_init()
281 if (phy->autoconf) in cdns_sierra_phy_init()
284 clk_set_rate(phy->cmn_refclk_dig_div, 25000000); in cdns_sierra_phy_init()
285 clk_set_rate(phy->cmn_refclk1_dig_div, 25000000); in cdns_sierra_phy_init()
286 if (ins->phy_type == PHY_TYPE_PCIE) { in cdns_sierra_phy_init()
287 num_cmn_regs = phy->init_data->pcie_cmn_regs; in cdns_sierra_phy_init()
288 num_ln_regs = phy->init_data->pcie_ln_regs; in cdns_sierra_phy_init()
289 cmn_vals = phy->init_data->pcie_cmn_vals; in cdns_sierra_phy_init()
290 ln_vals = phy->init_data->pcie_ln_vals; in cdns_sierra_phy_init()
291 } else if (ins->phy_type == PHY_TYPE_USB3) { in cdns_sierra_phy_init()
292 num_cmn_regs = phy->init_data->usb_cmn_regs; in cdns_sierra_phy_init()
293 num_ln_regs = phy->init_data->usb_ln_regs; in cdns_sierra_phy_init()
294 cmn_vals = phy->init_data->usb_cmn_vals; in cdns_sierra_phy_init()
295 ln_vals = phy->init_data->usb_ln_vals; in cdns_sierra_phy_init()
297 return -EINVAL; in cdns_sierra_phy_init()
300 regmap = phy->regmap_common_cdb; in cdns_sierra_phy_init()
304 for (i = 0; i < ins->num_lanes; i++) { in cdns_sierra_phy_init()
306 regmap = phy->regmap_lane_cdb[i + ins->mlane]; in cdns_sierra_phy_init()
314 static int cdns_sierra_phy_on(struct phy *gphy) in cdns_sierra_phy_on()
316 struct cdns_sierra_phy *sp = dev_get_drvdata(gphy->dev.parent); in cdns_sierra_phy_on()
318 struct device *dev = sp->dev; in cdns_sierra_phy_on()
322 /* Take the PHY lane group out of reset */ in cdns_sierra_phy_on()
323 ret = reset_control_deassert(ins->lnk_rst); in cdns_sierra_phy_on()
325 dev_err(dev, "Failed to take the PHY lane out of reset\n"); in cdns_sierra_phy_on()
329 ret = regmap_field_read_poll_timeout(sp->pllctrl_lock[ins->mlane], in cdns_sierra_phy_on()
337 static int cdns_sierra_phy_off(struct phy *gphy) in cdns_sierra_phy_off()
341 return reset_control_assert(ins->lnk_rst); in cdns_sierra_phy_off()
344 static int cdns_sierra_phy_reset(struct phy *gphy) in cdns_sierra_phy_reset()
346 struct cdns_sierra_phy *sp = dev_get_drvdata(gphy->dev.parent); in cdns_sierra_phy_reset()
348 reset_control_assert(sp->phy_rst); in cdns_sierra_phy_reset()
349 reset_control_deassert(sp->phy_rst); in cdns_sierra_phy_reset()
364 if (of_property_read_u32(child, "reg", &inst->mlane)) in cdns_sierra_get_optional()
365 return -EINVAL; in cdns_sierra_get_optional()
367 if (of_property_read_u32(child, "cdns,num-lanes", &inst->num_lanes)) in cdns_sierra_get_optional()
368 return -EINVAL; in cdns_sierra_get_optional()
370 if (of_property_read_u32(child, "cdns,phy-type", &inst->phy_type)) in cdns_sierra_get_optional()
371 return -EINVAL; in cdns_sierra_get_optional()
386 return ERR_PTR(-ENOMEM); in cdns_regmap_init()
388 ctx->dev = dev; in cdns_regmap_init()
389 ctx->base = base + block_offset; in cdns_regmap_init()
390 ctx->reg_offset_shift = reg_offset_shift; in cdns_regmap_init()
397 struct device *dev = sp->dev; in cdns_regfield_init()
402 regmap = sp->regmap_common_cdb; in cdns_regfield_init()
408 sp->macro_id_type = field; in cdns_regfield_init()
410 regmap = sp->regmap_phy_config_ctrl; in cdns_regfield_init()
416 sp->phy_pll_cfg_1 = field; in cdns_regfield_init()
419 regmap = sp->regmap_lane_cdb[i]; in cdns_regfield_init()
425 sp->pllctrl_lock[i] = field; in cdns_regfield_init()
435 struct device *dev = sp->dev; in cdns_regmap_init_blocks()
450 sp->regmap_lane_cdb[i] = regmap; in cdns_regmap_init_blocks()
460 sp->regmap_common_cdb = regmap; in cdns_regmap_init_blocks()
466 dev_err(dev, "Failed to init PHY config and control regmap\n"); in cdns_regmap_init_blocks()
469 sp->regmap_phy_config_ctrl = regmap; in cdns_regmap_init_blocks()
478 struct device *dev = &pdev->dev; in cdns_sierra_phy_probe()
486 struct device_node *dn = dev->of_node, *child; in cdns_sierra_phy_probe()
489 return -ENODEV; in cdns_sierra_phy_probe()
491 /* Get init data for this PHY */ in cdns_sierra_phy_probe()
494 return -EINVAL; in cdns_sierra_phy_probe()
496 data = (struct cdns_sierra_data *)match->data; in cdns_sierra_phy_probe()
500 return -ENOMEM; in cdns_sierra_phy_probe()
502 sp->dev = dev; in cdns_sierra_phy_probe()
503 sp->init_data = data; in cdns_sierra_phy_probe()
512 ret = cdns_regmap_init_blocks(sp, base, data->block_offset_shift, in cdns_sierra_phy_probe()
513 data->reg_offset_shift); in cdns_sierra_phy_probe()
523 sp->clk = devm_clk_get_optional(dev, "phy_clk"); in cdns_sierra_phy_probe()
524 if (IS_ERR(sp->clk)) { in cdns_sierra_phy_probe()
526 return PTR_ERR(sp->clk); in cdns_sierra_phy_probe()
529 sp->phy_rst = devm_reset_control_get(dev, "sierra_reset"); in cdns_sierra_phy_probe()
530 if (IS_ERR(sp->phy_rst)) { in cdns_sierra_phy_probe()
532 return PTR_ERR(sp->phy_rst); in cdns_sierra_phy_probe()
535 sp->apb_rst = devm_reset_control_get_optional(dev, "sierra_apb"); in cdns_sierra_phy_probe()
536 if (IS_ERR(sp->apb_rst)) { in cdns_sierra_phy_probe()
538 return PTR_ERR(sp->apb_rst); in cdns_sierra_phy_probe()
547 sp->cmn_refclk_dig_div = clk; in cdns_sierra_phy_probe()
555 sp->cmn_refclk1_dig_div = clk; in cdns_sierra_phy_probe()
557 ret = clk_prepare_enable(sp->clk); in cdns_sierra_phy_probe()
562 reset_control_deassert(sp->apb_rst); in cdns_sierra_phy_probe()
564 /* Check that PHY is present */ in cdns_sierra_phy_probe()
565 regmap_field_read(sp->macro_id_type, &id_value); in cdns_sierra_phy_probe()
566 if (sp->init_data->id_value != id_value) { in cdns_sierra_phy_probe()
567 ret = -EINVAL; in cdns_sierra_phy_probe()
571 sp->autoconf = of_property_read_bool(dn, "cdns,autoconf"); in cdns_sierra_phy_probe()
574 struct phy *gphy; in cdns_sierra_phy_probe()
576 sp->phys[node].lnk_rst = in cdns_sierra_phy_probe()
579 if (IS_ERR(sp->phys[node].lnk_rst)) { in cdns_sierra_phy_probe()
581 child->full_name); in cdns_sierra_phy_probe()
582 ret = PTR_ERR(sp->phys[node].lnk_rst); in cdns_sierra_phy_probe()
586 if (!sp->autoconf) { in cdns_sierra_phy_probe()
587 ret = cdns_sierra_get_optional(&sp->phys[node], child); in cdns_sierra_phy_probe()
590 child->name); in cdns_sierra_phy_probe()
595 sp->num_lanes += sp->phys[node].num_lanes; in cdns_sierra_phy_probe()
603 sp->phys[node].phy = gphy; in cdns_sierra_phy_probe()
604 phy_set_drvdata(gphy, &sp->phys[node]); in cdns_sierra_phy_probe()
608 sp->nsubnodes = node; in cdns_sierra_phy_probe()
610 if (sp->num_lanes > SIERRA_MAX_LANES) { in cdns_sierra_phy_probe()
615 /* If more than one subnode, configure the PHY as multilink */ in cdns_sierra_phy_probe()
616 if (!sp->autoconf && sp->nsubnodes > 1) in cdns_sierra_phy_probe()
617 regmap_field_write(sp->phy_pll_cfg_1, 0x1); in cdns_sierra_phy_probe()
621 reset_control_deassert(sp->phy_rst); in cdns_sierra_phy_probe()
628 reset_control_put(sp->phys[i].lnk_rst); in cdns_sierra_phy_probe()
631 clk_disable_unprepare(sp->clk); in cdns_sierra_phy_probe()
632 reset_control_assert(sp->apb_rst); in cdns_sierra_phy_probe()
638 struct cdns_sierra_phy *phy = platform_get_drvdata(pdev); in cdns_sierra_phy_remove() local
641 reset_control_assert(phy->phy_rst); in cdns_sierra_phy_remove()
642 reset_control_assert(phy->apb_rst); in cdns_sierra_phy_remove()
643 pm_runtime_disable(&pdev->dev); in cdns_sierra_phy_remove()
649 for (i = 0; i < phy->nsubnodes; i++) { in cdns_sierra_phy_remove()
650 reset_control_assert(phy->phys[i].lnk_rst); in cdns_sierra_phy_remove()
651 reset_control_put(phy->phys[i].lnk_rst); in cdns_sierra_phy_remove()
813 .compatible = "cdns,sierra-phy-t0",
817 .compatible = "ti,sierra-phy-t0",
828 .name = "cdns-sierra-phy",
836 MODULE_DESCRIPTION("CDNS sierra phy driver");