1 // SPDX-License-Identifier: GPL-2.0+
3 * Amlogic AXG MIPI + PCIE analog PHY driver
6 * Copyright (C) 2020 BayLibre, SAS
17 #include <generic-phy.h>
20 #include <linux/delay.h>
21 #include <power/regulator.h>
24 #include <phy-mipi-dphy.h>
26 #include <linux/bitops.h>
27 #include <linux/compat.h>
28 #include <linux/bitfield.h>
30 #define HHI_MIPI_CNTL0 0x00
31 #define HHI_MIPI_CNTL0_COMMON_BLOCK GENMASK(31, 28)
32 #define HHI_MIPI_CNTL0_ENABLE BIT(29)
33 #define HHI_MIPI_CNTL0_BANDGAP BIT(26)
34 #define HHI_MIPI_CNTL0_DIF_REF_CTL1 GENMASK(25, 16)
35 #define HHI_MIPI_CNTL0_DIF_REF_CTL0 GENMASK(15, 0)
37 #define HHI_MIPI_CNTL1 0x04
38 #define HHI_MIPI_CNTL1_CH0_CML_PDR_EN BIT(12)
39 #define HHI_MIPI_CNTL1_LP_ABILITY GENMASK(5, 4)
40 #define HHI_MIPI_CNTL1_LP_RESISTER BIT(3)
41 #define HHI_MIPI_CNTL1_INPUT_SETTING BIT(2)
42 #define HHI_MIPI_CNTL1_INPUT_SEL BIT(1)
43 #define HHI_MIPI_CNTL1_PRBS7_EN BIT(0)
45 #define HHI_MIPI_CNTL2 0x08
46 #define HHI_MIPI_CNTL2_CH_PU GENMASK(31, 25)
47 #define HHI_MIPI_CNTL2_CH_CTL GENMASK(24, 19)
48 #define HHI_MIPI_CNTL2_CH0_DIGDR_EN BIT(18)
49 #define HHI_MIPI_CNTL2_CH_DIGDR_EN BIT(17)
50 #define HHI_MIPI_CNTL2_LPULPS_EN BIT(16)
51 #define HHI_MIPI_CNTL2_CH_EN GENMASK(15, 11)
52 #define HHI_MIPI_CNTL2_CH0_LP_CTL GENMASK(10, 1)
54 #define DSI_LANE_0 (1 << 4)
55 #define DSI_LANE_1 (1 << 3)
56 #define DSI_LANE_CLK (1 << 2)
57 #define DSI_LANE_2 (1 << 1)
58 #define DSI_LANE_3 (1 << 0)
59 #define DSI_LANE_MASK (0x1F)
61 struct phy_meson_axg_mipi_pcie_analog_priv {
62 struct regmap *regmap;
63 struct phy_configure_opts_mipi_dphy config;
69 static void phy_bandgap_enable(struct phy_meson_axg_mipi_pcie_analog_priv *priv)
71 regmap_update_bits(priv->regmap, HHI_MIPI_CNTL0,
72 HHI_MIPI_CNTL0_BANDGAP, HHI_MIPI_CNTL0_BANDGAP);
74 regmap_update_bits(priv->regmap, HHI_MIPI_CNTL0,
75 HHI_MIPI_CNTL0_ENABLE, HHI_MIPI_CNTL0_ENABLE);
78 static void phy_bandgap_disable(struct phy_meson_axg_mipi_pcie_analog_priv *priv)
80 regmap_update_bits(priv->regmap, HHI_MIPI_CNTL0,
81 HHI_MIPI_CNTL0_BANDGAP, 0);
82 regmap_update_bits(priv->regmap, HHI_MIPI_CNTL0,
83 HHI_MIPI_CNTL0_ENABLE, 0);
86 static void phy_dsi_analog_enable(struct phy_meson_axg_mipi_pcie_analog_priv *priv)
90 regmap_update_bits(priv->regmap, HHI_MIPI_CNTL0,
91 HHI_MIPI_CNTL0_DIF_REF_CTL1,
92 FIELD_PREP(HHI_MIPI_CNTL0_DIF_REF_CTL1, 0x1b8));
93 regmap_update_bits(priv->regmap, HHI_MIPI_CNTL0,
95 regmap_update_bits(priv->regmap, HHI_MIPI_CNTL0,
96 HHI_MIPI_CNTL0_DIF_REF_CTL0,
97 FIELD_PREP(HHI_MIPI_CNTL0_DIF_REF_CTL0, 0x8));
99 regmap_write(priv->regmap, HHI_MIPI_CNTL1, 0x001e);
101 regmap_write(priv->regmap, HHI_MIPI_CNTL2,
102 (0x26e0 << 16) | (0x459 << 0));
105 switch (priv->config.lanes) {
122 regmap_update_bits(priv->regmap, HHI_MIPI_CNTL2,
123 HHI_MIPI_CNTL2_CH_EN,
124 FIELD_PREP(HHI_MIPI_CNTL2_CH_EN, reg));
126 priv->dsi_enabled = true;
129 static void phy_dsi_analog_disable(struct phy_meson_axg_mipi_pcie_analog_priv *priv)
131 regmap_update_bits(priv->regmap, HHI_MIPI_CNTL0,
132 HHI_MIPI_CNTL0_DIF_REF_CTL1,
133 FIELD_PREP(HHI_MIPI_CNTL0_DIF_REF_CTL1, 0));
134 regmap_update_bits(priv->regmap, HHI_MIPI_CNTL0, BIT(31), 0);
135 regmap_update_bits(priv->regmap, HHI_MIPI_CNTL0,
136 HHI_MIPI_CNTL0_DIF_REF_CTL1, 0);
138 regmap_write(priv->regmap, HHI_MIPI_CNTL1, 0x6);
140 regmap_write(priv->regmap, HHI_MIPI_CNTL2, 0x00200000);
142 priv->dsi_enabled = false;
145 static int phy_meson_axg_mipi_pcie_analog_configure(struct phy *phy, void *params)
147 struct udevice *dev = phy->dev;
148 struct phy_meson_axg_mipi_pcie_analog_priv *priv = dev_get_priv(dev);
149 struct phy_configure_opts_mipi_dphy *config = params;
152 ret = phy_mipi_dphy_config_validate(config);
156 memcpy(&priv->config, config, sizeof(priv->config));
158 priv->dsi_configured = true;
160 /* If PHY was already powered on, setup the DSI analog part */
162 /* If reconfiguring, disable & reconfigure */
163 if (priv->dsi_enabled)
164 phy_dsi_analog_disable(priv);
168 phy_dsi_analog_enable(priv);
174 static int phy_meson_axg_mipi_pcie_analog_power_on(struct phy *phy)
176 struct udevice *dev = phy->dev;
177 struct phy_meson_axg_mipi_pcie_analog_priv *priv = dev_get_priv(dev);
179 phy_bandgap_enable(priv);
181 if (priv->dsi_configured)
182 phy_dsi_analog_enable(priv);
184 priv->powered = true;
189 static int phy_meson_axg_mipi_pcie_analog_power_off(struct phy *phy)
191 struct udevice *dev = phy->dev;
192 struct phy_meson_axg_mipi_pcie_analog_priv *priv = dev_get_priv(dev);
194 phy_bandgap_disable(priv);
196 if (priv->dsi_enabled)
197 phy_dsi_analog_disable(priv);
199 priv->powered = false;
204 struct phy_ops meson_axg_mipi_pcie_analog_ops = {
205 .power_on = phy_meson_axg_mipi_pcie_analog_power_on,
206 .power_off = phy_meson_axg_mipi_pcie_analog_power_off,
207 .configure = phy_meson_axg_mipi_pcie_analog_configure,
210 int meson_axg_mipi_pcie_analog_probe(struct udevice *dev)
212 struct phy_meson_axg_mipi_pcie_analog_priv *priv = dev_get_priv(dev);
214 priv->regmap = syscon_node_to_regmap(dev_ofnode(dev_get_parent(dev)));
215 if (IS_ERR(priv->regmap))
216 return PTR_ERR(priv->regmap);
221 static const struct udevice_id meson_axg_mipi_pcie_analog_ids[] = {
222 { .compatible = "amlogic,axg-mipi-pcie-analog-phy" },
226 U_BOOT_DRIVER(meson_axg_mipi_pcie_analog) = {
227 .name = "meson_axg_mipi_pcie_analog",
229 .of_match = meson_axg_mipi_pcie_analog_ids,
230 .probe = meson_axg_mipi_pcie_analog_probe,
231 .ops = &meson_axg_mipi_pcie_analog_ops,
232 .priv_auto = sizeof(struct phy_meson_axg_mipi_pcie_analog_priv),