18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * P2U (PIPE to UPHY) driver for Tegra T194 SoC 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2019 NVIDIA Corporation. 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Author: Vidya Sagar <vidyas@nvidia.com> 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <linux/err.h> 118c2ecf20Sopenharmony_ci#include <linux/io.h> 128c2ecf20Sopenharmony_ci#include <linux/module.h> 138c2ecf20Sopenharmony_ci#include <linux/of.h> 148c2ecf20Sopenharmony_ci#include <linux/of_platform.h> 158c2ecf20Sopenharmony_ci#include <linux/phy/phy.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#define P2U_PERIODIC_EQ_CTRL_GEN3 0xc0 188c2ecf20Sopenharmony_ci#define P2U_PERIODIC_EQ_CTRL_GEN3_PERIODIC_EQ_EN BIT(0) 198c2ecf20Sopenharmony_ci#define P2U_PERIODIC_EQ_CTRL_GEN3_INIT_PRESET_EQ_TRAIN_EN BIT(1) 208c2ecf20Sopenharmony_ci#define P2U_PERIODIC_EQ_CTRL_GEN4 0xc4 218c2ecf20Sopenharmony_ci#define P2U_PERIODIC_EQ_CTRL_GEN4_INIT_PRESET_EQ_TRAIN_EN BIT(1) 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#define P2U_RX_DEBOUNCE_TIME 0xa4 248c2ecf20Sopenharmony_ci#define P2U_RX_DEBOUNCE_TIME_DEBOUNCE_TIMER_MASK 0xffff 258c2ecf20Sopenharmony_ci#define P2U_RX_DEBOUNCE_TIME_DEBOUNCE_TIMER_VAL 160 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_cistruct tegra_p2u { 288c2ecf20Sopenharmony_ci void __iomem *base; 298c2ecf20Sopenharmony_ci}; 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_cistatic inline void p2u_writel(struct tegra_p2u *phy, const u32 value, 328c2ecf20Sopenharmony_ci const u32 reg) 338c2ecf20Sopenharmony_ci{ 348c2ecf20Sopenharmony_ci writel_relaxed(value, phy->base + reg); 358c2ecf20Sopenharmony_ci} 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_cistatic inline u32 p2u_readl(struct tegra_p2u *phy, const u32 reg) 388c2ecf20Sopenharmony_ci{ 398c2ecf20Sopenharmony_ci return readl_relaxed(phy->base + reg); 408c2ecf20Sopenharmony_ci} 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_cistatic int tegra_p2u_power_on(struct phy *x) 438c2ecf20Sopenharmony_ci{ 448c2ecf20Sopenharmony_ci struct tegra_p2u *phy = phy_get_drvdata(x); 458c2ecf20Sopenharmony_ci u32 val; 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci val = p2u_readl(phy, P2U_PERIODIC_EQ_CTRL_GEN3); 488c2ecf20Sopenharmony_ci val &= ~P2U_PERIODIC_EQ_CTRL_GEN3_PERIODIC_EQ_EN; 498c2ecf20Sopenharmony_ci val |= P2U_PERIODIC_EQ_CTRL_GEN3_INIT_PRESET_EQ_TRAIN_EN; 508c2ecf20Sopenharmony_ci p2u_writel(phy, val, P2U_PERIODIC_EQ_CTRL_GEN3); 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci val = p2u_readl(phy, P2U_PERIODIC_EQ_CTRL_GEN4); 538c2ecf20Sopenharmony_ci val |= P2U_PERIODIC_EQ_CTRL_GEN4_INIT_PRESET_EQ_TRAIN_EN; 548c2ecf20Sopenharmony_ci p2u_writel(phy, val, P2U_PERIODIC_EQ_CTRL_GEN4); 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci val = p2u_readl(phy, P2U_RX_DEBOUNCE_TIME); 578c2ecf20Sopenharmony_ci val &= ~P2U_RX_DEBOUNCE_TIME_DEBOUNCE_TIMER_MASK; 588c2ecf20Sopenharmony_ci val |= P2U_RX_DEBOUNCE_TIME_DEBOUNCE_TIMER_VAL; 598c2ecf20Sopenharmony_ci p2u_writel(phy, val, P2U_RX_DEBOUNCE_TIME); 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci return 0; 628c2ecf20Sopenharmony_ci} 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_cistatic const struct phy_ops ops = { 658c2ecf20Sopenharmony_ci .power_on = tegra_p2u_power_on, 668c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 678c2ecf20Sopenharmony_ci}; 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_cistatic int tegra_p2u_probe(struct platform_device *pdev) 708c2ecf20Sopenharmony_ci{ 718c2ecf20Sopenharmony_ci struct phy_provider *phy_provider; 728c2ecf20Sopenharmony_ci struct device *dev = &pdev->dev; 738c2ecf20Sopenharmony_ci struct phy *generic_phy; 748c2ecf20Sopenharmony_ci struct tegra_p2u *phy; 758c2ecf20Sopenharmony_ci struct resource *res; 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); 788c2ecf20Sopenharmony_ci if (!phy) 798c2ecf20Sopenharmony_ci return -ENOMEM; 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ctl"); 828c2ecf20Sopenharmony_ci phy->base = devm_ioremap_resource(dev, res); 838c2ecf20Sopenharmony_ci if (IS_ERR(phy->base)) 848c2ecf20Sopenharmony_ci return PTR_ERR(phy->base); 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci platform_set_drvdata(pdev, phy); 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci generic_phy = devm_phy_create(dev, NULL, &ops); 898c2ecf20Sopenharmony_ci if (IS_ERR(generic_phy)) 908c2ecf20Sopenharmony_ci return PTR_ERR(generic_phy); 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci phy_set_drvdata(generic_phy, phy); 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); 958c2ecf20Sopenharmony_ci if (IS_ERR(phy_provider)) 968c2ecf20Sopenharmony_ci return PTR_ERR(phy_provider); 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci return 0; 998c2ecf20Sopenharmony_ci} 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_cistatic const struct of_device_id tegra_p2u_id_table[] = { 1028c2ecf20Sopenharmony_ci { 1038c2ecf20Sopenharmony_ci .compatible = "nvidia,tegra194-p2u", 1048c2ecf20Sopenharmony_ci }, 1058c2ecf20Sopenharmony_ci {} 1068c2ecf20Sopenharmony_ci}; 1078c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, tegra_p2u_id_table); 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_cistatic struct platform_driver tegra_p2u_driver = { 1108c2ecf20Sopenharmony_ci .probe = tegra_p2u_probe, 1118c2ecf20Sopenharmony_ci .driver = { 1128c2ecf20Sopenharmony_ci .name = "tegra194-p2u", 1138c2ecf20Sopenharmony_ci .of_match_table = tegra_p2u_id_table, 1148c2ecf20Sopenharmony_ci }, 1158c2ecf20Sopenharmony_ci}; 1168c2ecf20Sopenharmony_cimodule_platform_driver(tegra_p2u_driver); 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ciMODULE_AUTHOR("Vidya Sagar <vidyas@nvidia.com>"); 1198c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("NVIDIA Tegra194 PIPE2UPHY PHY driver"); 1208c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 121