2021-01-15 10:01:21 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/*
|
|
|
|
* Rockchip PCIE3.0 phy driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2021 Rockchip Electronics Co., Ltd.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <clk.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <generic-phy.h>
|
|
|
|
#include <regmap.h>
|
|
|
|
#include <reset-uclass.h>
|
|
|
|
#include <syscon.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <dm/device_compat.h>
|
|
|
|
#include <dm/lists.h>
|
|
|
|
|
|
|
|
#define GRF_PCIE30PHY_CON1 0x4
|
|
|
|
#define GRF_PCIE30PHY_CON6 0x18
|
|
|
|
#define GRF_PCIE30PHY_CON9 0x24
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct rockchip_p3phy_priv - RK DW PCIe PHY state
|
|
|
|
*
|
|
|
|
* @mmio: The base address of PHY internal registers
|
|
|
|
* @phy_grf: The regmap for controlling pipe signal
|
|
|
|
* @p30phy: The reset signal for PHY
|
2023-08-02 19:04:29 +00:00
|
|
|
* @clks: The clocks for PHY
|
2021-01-15 10:01:21 +00:00
|
|
|
*/
|
|
|
|
struct rockchip_p3phy_priv {
|
|
|
|
void __iomem *mmio;
|
|
|
|
struct regmap *phy_grf;
|
|
|
|
struct reset_ctl p30phy;
|
2023-08-02 19:04:29 +00:00
|
|
|
struct clk_bulk clks;
|
2021-01-15 10:01:21 +00:00
|
|
|
};
|
|
|
|
|
2023-08-02 19:04:30 +00:00
|
|
|
struct rockchip_p3phy_ops {
|
|
|
|
int (*phy_init)(struct phy *phy);
|
|
|
|
};
|
|
|
|
|
|
|
|
static int rockchip_p3phy_rk3568_init(struct phy *phy)
|
|
|
|
{
|
|
|
|
struct rockchip_p3phy_priv *priv = dev_get_priv(phy->dev);
|
|
|
|
|
|
|
|
/* Deassert PCIe PMA output clamp mode */
|
|
|
|
regmap_write(priv->phy_grf, GRF_PCIE30PHY_CON9,
|
|
|
|
(0x1 << 15) | (0x1 << 31));
|
|
|
|
|
|
|
|
reset_deassert(&priv->p30phy);
|
|
|
|
udelay(1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct rockchip_p3phy_ops rk3568_ops = {
|
|
|
|
.phy_init = rockchip_p3phy_rk3568_init,
|
|
|
|
};
|
|
|
|
|
2021-01-15 10:01:21 +00:00
|
|
|
static int rochchip_p3phy_init(struct phy *phy)
|
|
|
|
{
|
2023-08-02 19:04:30 +00:00
|
|
|
struct rockchip_p3phy_ops *ops =
|
|
|
|
(struct rockchip_p3phy_ops *)dev_get_driver_data(phy->dev);
|
2021-01-15 10:01:21 +00:00
|
|
|
struct rockchip_p3phy_priv *priv = dev_get_priv(phy->dev);
|
|
|
|
int ret;
|
|
|
|
|
2023-08-02 19:04:29 +00:00
|
|
|
ret = clk_enable_bulk(&priv->clks);
|
|
|
|
if (ret)
|
2021-01-15 10:01:21 +00:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
reset_assert(&priv->p30phy);
|
|
|
|
udelay(1);
|
|
|
|
|
2023-08-02 19:04:30 +00:00
|
|
|
ret = ops->phy_init(phy);
|
|
|
|
if (ret)
|
|
|
|
clk_disable_bulk(&priv->clks);
|
2021-01-15 10:01:21 +00:00
|
|
|
|
2023-08-02 19:04:30 +00:00
|
|
|
return ret;
|
2021-01-15 10:01:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int rochchip_p3phy_exit(struct phy *phy)
|
|
|
|
{
|
|
|
|
struct rockchip_p3phy_priv *priv = dev_get_priv(phy->dev);
|
|
|
|
|
2023-08-02 19:04:29 +00:00
|
|
|
clk_disable_bulk(&priv->clks);
|
2021-01-15 10:01:21 +00:00
|
|
|
reset_assert(&priv->p30phy);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rockchip_p3phy_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct rockchip_p3phy_priv *priv = dev_get_priv(dev);
|
|
|
|
int ret;
|
|
|
|
|
2023-03-13 00:32:04 +00:00
|
|
|
priv->mmio = dev_read_addr_ptr(dev);
|
|
|
|
if (!priv->mmio)
|
2021-01-15 10:01:21 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
2023-08-02 19:04:29 +00:00
|
|
|
priv->phy_grf = syscon_regmap_lookup_by_phandle(dev, "rockchip,phy-grf");
|
2021-01-15 10:01:21 +00:00
|
|
|
if (IS_ERR(priv->phy_grf)) {
|
|
|
|
dev_err(dev, "failed to find rockchip,phy_grf regmap\n");
|
|
|
|
return PTR_ERR(priv->phy_grf);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = reset_get_by_name(dev, "phy", &priv->p30phy);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "no phy reset control specified\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-08-02 19:04:29 +00:00
|
|
|
ret = clk_get_bulk(dev, &priv->clks);
|
2021-01-15 10:01:21 +00:00
|
|
|
if (ret) {
|
2023-08-02 19:04:29 +00:00
|
|
|
dev_err(dev, "failed to get clocks\n");
|
|
|
|
return ret;
|
2021-01-15 10:01:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct phy_ops rochchip_p3phy_ops = {
|
|
|
|
.init = rochchip_p3phy_init,
|
|
|
|
.exit = rochchip_p3phy_exit,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct udevice_id rockchip_p3phy_of_match[] = {
|
2023-08-02 19:04:30 +00:00
|
|
|
{
|
|
|
|
.compatible = "rockchip,rk3568-pcie3-phy",
|
|
|
|
.data = (ulong)&rk3568_ops,
|
|
|
|
},
|
2021-01-15 10:01:21 +00:00
|
|
|
{ },
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(rockchip_pcie3phy) = {
|
|
|
|
.name = "rockchip_pcie3phy",
|
|
|
|
.id = UCLASS_PHY,
|
|
|
|
.of_match = rockchip_p3phy_of_match,
|
|
|
|
.ops = &rochchip_p3phy_ops,
|
|
|
|
.probe = rockchip_p3phy_probe,
|
|
|
|
.priv_auto = sizeof(struct rockchip_p3phy_priv),
|
|
|
|
};
|