| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Rockchip DP PHY driver |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2016 FuZhou Rockchip Co., Ltd. |
|---|
| 5 | 6 | * Author: Yakir Yang <ykk@@rock-chips.com> |
|---|
| 6 | | - * |
|---|
| 7 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 8 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 9 | | - * the Free Software Foundation; either version 2 of the License. |
|---|
| 10 | 7 | */ |
|---|
| 11 | 8 | |
|---|
| 12 | 9 | #include <linux/clk.h> |
|---|
| 13 | | -#include <linux/clk-provider.h> |
|---|
| 14 | 10 | #include <linux/mfd/syscon.h> |
|---|
| 15 | 11 | #include <linux/module.h> |
|---|
| 16 | 12 | #include <linux/of.h> |
|---|
| 17 | | -#include <linux/of_device.h> |
|---|
| 18 | 13 | #include <linux/phy/phy.h> |
|---|
| 19 | 14 | #include <linux/platform_device.h> |
|---|
| 20 | 15 | #include <linux/regmap.h> |
|---|
| 21 | | -#include <linux/reset.h> |
|---|
| 22 | 16 | |
|---|
| 23 | | -struct rockchip_dp_phy_data { |
|---|
| 24 | | - u32 grf_reg_offset; |
|---|
| 25 | | - u8 ref_clk_sel_shift; |
|---|
| 26 | | - u8 iddq_shift; |
|---|
| 27 | | -}; |
|---|
| 17 | +#define GRF_SOC_CON12 0x0274 |
|---|
| 18 | + |
|---|
| 19 | +#define GRF_EDP_REF_CLK_SEL_INTER_HIWORD_MASK BIT(20) |
|---|
| 20 | +#define GRF_EDP_REF_CLK_SEL_INTER BIT(4) |
|---|
| 21 | + |
|---|
| 22 | +#define GRF_EDP_PHY_SIDDQ_HIWORD_MASK BIT(21) |
|---|
| 23 | +#define GRF_EDP_PHY_SIDDQ_ON 0 |
|---|
| 24 | +#define GRF_EDP_PHY_SIDDQ_OFF BIT(5) |
|---|
| 28 | 25 | |
|---|
| 29 | 26 | struct rockchip_dp_phy { |
|---|
| 30 | 27 | struct device *dev; |
|---|
| 31 | 28 | struct regmap *grf; |
|---|
| 32 | 29 | struct clk *phy_24m; |
|---|
| 33 | | - struct reset_control *rst; |
|---|
| 34 | | - const struct rockchip_dp_phy_data *data; |
|---|
| 35 | 30 | }; |
|---|
| 31 | + |
|---|
| 32 | +static int rockchip_set_phy_state(struct phy *phy, bool enable) |
|---|
| 33 | +{ |
|---|
| 34 | + struct rockchip_dp_phy *dp = phy_get_drvdata(phy); |
|---|
| 35 | + int ret; |
|---|
| 36 | + |
|---|
| 37 | + if (enable) { |
|---|
| 38 | + ret = regmap_write(dp->grf, GRF_SOC_CON12, |
|---|
| 39 | + GRF_EDP_PHY_SIDDQ_HIWORD_MASK | |
|---|
| 40 | + GRF_EDP_PHY_SIDDQ_ON); |
|---|
| 41 | + if (ret < 0) { |
|---|
| 42 | + dev_err(dp->dev, "Can't enable PHY power %d\n", ret); |
|---|
| 43 | + return ret; |
|---|
| 44 | + } |
|---|
| 45 | + |
|---|
| 46 | + ret = clk_prepare_enable(dp->phy_24m); |
|---|
| 47 | + } else { |
|---|
| 48 | + clk_disable_unprepare(dp->phy_24m); |
|---|
| 49 | + |
|---|
| 50 | + ret = regmap_write(dp->grf, GRF_SOC_CON12, |
|---|
| 51 | + GRF_EDP_PHY_SIDDQ_HIWORD_MASK | |
|---|
| 52 | + GRF_EDP_PHY_SIDDQ_OFF); |
|---|
| 53 | + } |
|---|
| 54 | + |
|---|
| 55 | + return ret; |
|---|
| 56 | +} |
|---|
| 36 | 57 | |
|---|
| 37 | 58 | static int rockchip_dp_phy_power_on(struct phy *phy) |
|---|
| 38 | 59 | { |
|---|
| 39 | | - struct rockchip_dp_phy *dp = phy_get_drvdata(phy); |
|---|
| 40 | | - const struct rockchip_dp_phy_data *data = dp->data; |
|---|
| 41 | | - |
|---|
| 42 | | - if (!__clk_is_enabled(dp->phy_24m)) |
|---|
| 43 | | - clk_prepare_enable(dp->phy_24m); |
|---|
| 44 | | - |
|---|
| 45 | | - if (dp->rst) { |
|---|
| 46 | | - /* EDP 24m clock domain software reset */ |
|---|
| 47 | | - reset_control_assert(dp->rst); |
|---|
| 48 | | - usleep_range(20, 40); |
|---|
| 49 | | - reset_control_deassert(dp->rst); |
|---|
| 50 | | - } |
|---|
| 51 | | - |
|---|
| 52 | | - regmap_write(dp->grf, data->grf_reg_offset, |
|---|
| 53 | | - 0 | BIT(16 + data->iddq_shift)); |
|---|
| 54 | | - |
|---|
| 55 | | - return 0; |
|---|
| 60 | + return rockchip_set_phy_state(phy, true); |
|---|
| 56 | 61 | } |
|---|
| 57 | 62 | |
|---|
| 58 | 63 | static int rockchip_dp_phy_power_off(struct phy *phy) |
|---|
| 59 | 64 | { |
|---|
| 60 | | - struct rockchip_dp_phy *dp = phy_get_drvdata(phy); |
|---|
| 61 | | - const struct rockchip_dp_phy_data *data = dp->data; |
|---|
| 62 | | - |
|---|
| 63 | | - regmap_write(dp->grf, data->grf_reg_offset, |
|---|
| 64 | | - BIT(data->iddq_shift) | BIT(16 + data->iddq_shift)); |
|---|
| 65 | | - |
|---|
| 66 | | - if (__clk_is_enabled(dp->phy_24m)) |
|---|
| 67 | | - clk_disable_unprepare(dp->phy_24m); |
|---|
| 68 | | - |
|---|
| 69 | | - return 0; |
|---|
| 65 | + return rockchip_set_phy_state(phy, false); |
|---|
| 70 | 66 | } |
|---|
| 71 | 67 | |
|---|
| 72 | 68 | static const struct phy_ops rockchip_dp_phy_ops = { |
|---|
| .. | .. |
|---|
| 81 | 77 | struct device_node *np = dev->of_node; |
|---|
| 82 | 78 | struct phy_provider *phy_provider; |
|---|
| 83 | 79 | struct rockchip_dp_phy *dp; |
|---|
| 84 | | - const struct rockchip_dp_phy_data *data = of_device_get_match_data(dev); |
|---|
| 85 | 80 | struct phy *phy; |
|---|
| 86 | 81 | int ret; |
|---|
| 87 | 82 | |
|---|
| .. | .. |
|---|
| 96 | 91 | return -ENOMEM; |
|---|
| 97 | 92 | |
|---|
| 98 | 93 | dp->dev = dev; |
|---|
| 99 | | - dp->data = data; |
|---|
| 100 | 94 | |
|---|
| 101 | 95 | dp->phy_24m = devm_clk_get(dev, "24m"); |
|---|
| 102 | 96 | if (IS_ERR(dp->phy_24m)) { |
|---|
| .. | .. |
|---|
| 110 | 104 | return ret; |
|---|
| 111 | 105 | } |
|---|
| 112 | 106 | |
|---|
| 113 | | - ret = clk_prepare_enable(dp->phy_24m); |
|---|
| 114 | | - if (ret) { |
|---|
| 115 | | - dev_err(dev, "failed to enable phy 24m clock: %d\n", ret); |
|---|
| 116 | | - return ret; |
|---|
| 117 | | - } |
|---|
| 118 | | - |
|---|
| 119 | | - dp->rst = devm_reset_control_get_optional(dev, "edp_24m"); |
|---|
| 120 | | - if (IS_ERR(dp->rst)) { |
|---|
| 121 | | - ret = PTR_ERR(dp->rst); |
|---|
| 122 | | - dev_err(dev, "failed to get reset control: %d\n", ret); |
|---|
| 123 | | - return ret; |
|---|
| 124 | | - } |
|---|
| 125 | | - |
|---|
| 126 | 107 | dp->grf = syscon_node_to_regmap(dev->parent->of_node); |
|---|
| 127 | 108 | if (IS_ERR(dp->grf)) { |
|---|
| 128 | 109 | dev_err(dev, "rk3288-dp needs the General Register Files syscon\n"); |
|---|
| 129 | 110 | return PTR_ERR(dp->grf); |
|---|
| 130 | 111 | } |
|---|
| 131 | 112 | |
|---|
| 132 | | - /* eDP PHY reference clock source from internal clock */ |
|---|
| 133 | | - ret = regmap_write(dp->grf, data->grf_reg_offset, |
|---|
| 134 | | - BIT(data->ref_clk_sel_shift) | |
|---|
| 135 | | - BIT(16 + data->ref_clk_sel_shift)); |
|---|
| 136 | | - if (ret) { |
|---|
| 113 | + ret = regmap_write(dp->grf, GRF_SOC_CON12, GRF_EDP_REF_CLK_SEL_INTER | |
|---|
| 114 | + GRF_EDP_REF_CLK_SEL_INTER_HIWORD_MASK); |
|---|
| 115 | + if (ret != 0) { |
|---|
| 137 | 116 | dev_err(dp->dev, "Could not config GRF edp ref clk: %d\n", ret); |
|---|
| 138 | 117 | return ret; |
|---|
| 139 | 118 | } |
|---|
| .. | .. |
|---|
| 150 | 129 | return PTR_ERR_OR_ZERO(phy_provider); |
|---|
| 151 | 130 | } |
|---|
| 152 | 131 | |
|---|
| 153 | | -static const struct rockchip_dp_phy_data rk3288_dp_phy_data = { |
|---|
| 154 | | - .grf_reg_offset = 0x274, |
|---|
| 155 | | - .ref_clk_sel_shift = 4, |
|---|
| 156 | | - .iddq_shift = 5, |
|---|
| 157 | | -}; |
|---|
| 158 | | - |
|---|
| 159 | | -static const struct rockchip_dp_phy_data rk3368_dp_phy_data = { |
|---|
| 160 | | - .grf_reg_offset = 0x410, |
|---|
| 161 | | - .ref_clk_sel_shift = 0, |
|---|
| 162 | | - .iddq_shift = 1, |
|---|
| 163 | | -}; |
|---|
| 164 | | - |
|---|
| 165 | 132 | static const struct of_device_id rockchip_dp_phy_dt_ids[] = { |
|---|
| 166 | | - { .compatible = "rockchip,rk3288-dp-phy", .data = &rk3288_dp_phy_data }, |
|---|
| 167 | | - { .compatible = "rockchip,rk3368-dp-phy", .data = &rk3368_dp_phy_data }, |
|---|
| 133 | + { .compatible = "rockchip,rk3288-dp-phy" }, |
|---|
| 168 | 134 | {} |
|---|
| 169 | 135 | }; |
|---|
| 170 | 136 | |
|---|