Lines Matching +full:sata +full:- +full:phy
1 // SPDX-License-Identifier: GPL-2.0
3 * Marvell Berlin SATA PHY driver
7 * Antoine Ténart <antoine.tenart@free-electrons.com>
13 #include <linux/phy/phy.h>
52 struct phy *phy; member
81 static int phy_berlin_sata_power_on(struct phy *phy) in phy_berlin_sata_power_on() argument
83 struct phy_berlin_desc *desc = phy_get_drvdata(phy); in phy_berlin_sata_power_on()
84 struct phy_berlin_priv *priv = dev_get_drvdata(phy->dev.parent); in phy_berlin_sata_power_on()
85 void __iomem *ctrl_reg = priv->base + 0x60 + (desc->index * 0x80); in phy_berlin_sata_power_on()
88 clk_prepare_enable(priv->clk); in phy_berlin_sata_power_on()
90 spin_lock(&priv->lock); in phy_berlin_sata_power_on()
92 /* Power on PHY */ in phy_berlin_sata_power_on()
93 writel(CONTROL_REGISTER, priv->base + HOST_VSA_ADDR); in phy_berlin_sata_power_on()
94 regval = readl(priv->base + HOST_VSA_DATA); in phy_berlin_sata_power_on()
95 regval &= ~desc->power_bit; in phy_berlin_sata_power_on()
96 writel(regval, priv->base + HOST_VSA_DATA); in phy_berlin_sata_power_on()
99 writel(MBUS_SIZE_CONTROL, priv->base + HOST_VSA_ADDR); in phy_berlin_sata_power_on()
100 regval = readl(priv->base + HOST_VSA_DATA); in phy_berlin_sata_power_on()
102 writel(regval, priv->base + HOST_VSA_DATA); in phy_berlin_sata_power_on()
104 /* set PHY mode and ref freq to 25 MHz */ in phy_berlin_sata_power_on()
105 phy_berlin_sata_reg_setbits(ctrl_reg, priv->phy_base, 0x01, in phy_berlin_sata_power_on()
109 /* set PHY up to 6 Gbps */ in phy_berlin_sata_power_on()
110 phy_berlin_sata_reg_setbits(ctrl_reg, priv->phy_base, 0x25, in phy_berlin_sata_power_on()
114 phy_berlin_sata_reg_setbits(ctrl_reg, priv->phy_base, 0x23, in phy_berlin_sata_power_on()
118 phy_berlin_sata_reg_setbits(ctrl_reg, priv->phy_base, 0x02, in phy_berlin_sata_power_on()
127 spin_unlock(&priv->lock); in phy_berlin_sata_power_on()
129 clk_disable_unprepare(priv->clk); in phy_berlin_sata_power_on()
134 static int phy_berlin_sata_power_off(struct phy *phy) in phy_berlin_sata_power_off() argument
136 struct phy_berlin_desc *desc = phy_get_drvdata(phy); in phy_berlin_sata_power_off()
137 struct phy_berlin_priv *priv = dev_get_drvdata(phy->dev.parent); in phy_berlin_sata_power_off()
140 clk_prepare_enable(priv->clk); in phy_berlin_sata_power_off()
142 spin_lock(&priv->lock); in phy_berlin_sata_power_off()
144 /* Power down PHY */ in phy_berlin_sata_power_off()
145 writel(CONTROL_REGISTER, priv->base + HOST_VSA_ADDR); in phy_berlin_sata_power_off()
146 regval = readl(priv->base + HOST_VSA_DATA); in phy_berlin_sata_power_off()
147 regval |= desc->power_bit; in phy_berlin_sata_power_off()
148 writel(regval, priv->base + HOST_VSA_DATA); in phy_berlin_sata_power_off()
150 spin_unlock(&priv->lock); in phy_berlin_sata_power_off()
152 clk_disable_unprepare(priv->clk); in phy_berlin_sata_power_off()
157 static struct phy *phy_berlin_sata_phy_xlate(struct device *dev, in phy_berlin_sata_phy_xlate()
163 if (WARN_ON(args->args[0] >= priv->nphys)) in phy_berlin_sata_phy_xlate()
164 return ERR_PTR(-ENODEV); in phy_berlin_sata_phy_xlate()
166 for (i = 0; i < priv->nphys; i++) { in phy_berlin_sata_phy_xlate()
167 if (priv->phys[i]->index == args->args[0]) in phy_berlin_sata_phy_xlate()
171 if (i == priv->nphys) in phy_berlin_sata_phy_xlate()
172 return ERR_PTR(-ENODEV); in phy_berlin_sata_phy_xlate()
174 return priv->phys[i]->phy; in phy_berlin_sata_phy_xlate()
190 struct device *dev = &pdev->dev; in phy_berlin_sata_probe()
192 struct phy *phy; in phy_berlin_sata_probe() local
201 return -ENOMEM; in phy_berlin_sata_probe()
205 return -EINVAL; in phy_berlin_sata_probe()
207 priv->base = devm_ioremap(dev, res->start, resource_size(res)); in phy_berlin_sata_probe()
208 if (!priv->base) in phy_berlin_sata_probe()
209 return -ENOMEM; in phy_berlin_sata_probe()
211 priv->clk = devm_clk_get(dev, NULL); in phy_berlin_sata_probe()
212 if (IS_ERR(priv->clk)) in phy_berlin_sata_probe()
213 return PTR_ERR(priv->clk); in phy_berlin_sata_probe()
215 priv->nphys = of_get_child_count(dev->of_node); in phy_berlin_sata_probe()
216 if (priv->nphys == 0) in phy_berlin_sata_probe()
217 return -ENODEV; in phy_berlin_sata_probe()
219 priv->phys = devm_kcalloc(dev, priv->nphys, sizeof(*priv->phys), in phy_berlin_sata_probe()
221 if (!priv->phys) in phy_berlin_sata_probe()
222 return -ENOMEM; in phy_berlin_sata_probe()
224 if (of_device_is_compatible(dev->of_node, "marvell,berlin2-sata-phy")) in phy_berlin_sata_probe()
225 priv->phy_base = BG2_PHY_BASE; in phy_berlin_sata_probe()
227 priv->phy_base = BG2Q_PHY_BASE; in phy_berlin_sata_probe()
230 spin_lock_init(&priv->lock); in phy_berlin_sata_probe()
232 for_each_available_child_of_node(dev->of_node, child) { in phy_berlin_sata_probe()
238 ret = -EINVAL; in phy_berlin_sata_probe()
244 ret = -EINVAL; in phy_berlin_sata_probe()
250 ret = -ENOMEM; in phy_berlin_sata_probe()
254 phy = devm_phy_create(dev, NULL, &phy_berlin_sata_ops); in phy_berlin_sata_probe()
255 if (IS_ERR(phy)) { in phy_berlin_sata_probe()
256 dev_err(dev, "failed to create PHY %d\n", phy_id); in phy_berlin_sata_probe()
257 ret = PTR_ERR(phy); in phy_berlin_sata_probe()
261 phy_desc->phy = phy; in phy_berlin_sata_probe()
262 phy_desc->power_bit = phy_berlin_power_down_bits[phy_id]; in phy_berlin_sata_probe()
263 phy_desc->index = phy_id; in phy_berlin_sata_probe()
264 phy_set_drvdata(phy, phy_desc); in phy_berlin_sata_probe()
266 priv->phys[i++] = phy_desc; in phy_berlin_sata_probe()
268 /* Make sure the PHY is off */ in phy_berlin_sata_probe()
269 phy_berlin_sata_power_off(phy); in phy_berlin_sata_probe()
281 { .compatible = "marvell,berlin2-sata-phy" },
282 { .compatible = "marvell,berlin2q-sata-phy" },
290 .name = "phy-berlin-sata",
296 MODULE_DESCRIPTION("Marvell Berlin SATA PHY driver");
297 MODULE_AUTHOR("Antoine Ténart <antoine.tenart@free-electrons.com>");