Lines Matching +full:t +full:- +full:phy

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Rockchip emmc PHY driver
5 * Copyright (C) 2016 Shawn Lin <shawn.lin@rock-chips.com>
15 #include <linux/phy/phy.h>
20 * The higher 16-bit of this register is used for write protection
93 static int rockchip_emmc_phy_power(struct phy *phy, bool on_off) in rockchip_emmc_phy_power() argument
95 struct rockchip_emmc_phy *rk_phy = phy_get_drvdata(phy); in rockchip_emmc_phy_power()
106 regmap_write(rk_phy->reg_base, in rockchip_emmc_phy_power()
107 rk_phy->reg_offset + GRF_EMMCPHY_CON6, in rockchip_emmc_phy_power()
111 regmap_write(rk_phy->reg_base, in rockchip_emmc_phy_power()
112 rk_phy->reg_offset + GRF_EMMCPHY_CON6, in rockchip_emmc_phy_power()
121 rate = clk_get_rate(rk_phy->emmcclk); in rockchip_emmc_phy_power()
146 rate - ideal_rate : ideal_rate - rate; in rockchip_emmc_phy_power()
151 * far off. Also warn if we're above the 200 MHz max. Don't in rockchip_emmc_phy_power()
152 * warn for really slow rates since we won't be tuning then. in rockchip_emmc_phy_power()
155 dev_warn(&phy->dev, "Unsupported rate: %lu\n", rate); in rockchip_emmc_phy_power()
164 regmap_write(rk_phy->reg_base, in rockchip_emmc_phy_power()
165 rk_phy->reg_offset + GRF_EMMCPHY_CON6, in rockchip_emmc_phy_power()
177 ret = regmap_read_poll_timeout(rk_phy->reg_base, in rockchip_emmc_phy_power()
178 rk_phy->reg_offset + GRF_EMMCPHY_STATUS, in rockchip_emmc_phy_power()
187 regmap_write(rk_phy->reg_base, in rockchip_emmc_phy_power()
188 rk_phy->reg_offset + GRF_EMMCPHY_CON0, in rockchip_emmc_phy_power()
193 regmap_write(rk_phy->reg_base, in rockchip_emmc_phy_power()
194 rk_phy->reg_offset + GRF_EMMCPHY_CON6, in rockchip_emmc_phy_power()
201 * clock might be turned on later. ...but we can't wait for the DLL in rockchip_emmc_phy_power()
206 * is turned on, but for now we won't. in rockchip_emmc_phy_power()
214 * with clock speed. If we are powering on the PHY and the card clock in rockchip_emmc_phy_power()
217 * Hopefully we won't be running at 100 kHz, but we should still make in rockchip_emmc_phy_power()
221 * extra long to lock for reasons that aren't understood. In some in rockchip_emmc_phy_power()
225 ret = regmap_read_poll_timeout(rk_phy->reg_base, in rockchip_emmc_phy_power()
226 rk_phy->reg_offset + GRF_EMMCPHY_STATUS, in rockchip_emmc_phy_power()
237 static int rockchip_emmc_phy_init(struct phy *phy) in rockchip_emmc_phy_init() argument
239 struct rockchip_emmc_phy *rk_phy = phy_get_drvdata(phy); in rockchip_emmc_phy_init()
245 * - PHY driver to probe in rockchip_emmc_phy_init()
246 * - SDHCI driver to start probe in rockchip_emmc_phy_init()
247 * - SDHCI driver to register it's clock in rockchip_emmc_phy_init()
248 * - SDHCI driver to get the PHY in rockchip_emmc_phy_init()
249 * - SDHCI driver to init the PHY in rockchip_emmc_phy_init()
254 * NOTE: we don't do anything special for EPROBE_DEFER here. Given the in rockchip_emmc_phy_init()
255 * above expected use case, EPROBE_DEFER isn't sensible to expect, so in rockchip_emmc_phy_init()
258 rk_phy->emmcclk = clk_get_optional(&phy->dev, "emmcclk"); in rockchip_emmc_phy_init()
259 if (IS_ERR(rk_phy->emmcclk)) { in rockchip_emmc_phy_init()
260 ret = PTR_ERR(rk_phy->emmcclk); in rockchip_emmc_phy_init()
261 dev_err(&phy->dev, "Error getting emmcclk: %d\n", ret); in rockchip_emmc_phy_init()
262 rk_phy->emmcclk = NULL; in rockchip_emmc_phy_init()
268 static int rockchip_emmc_phy_exit(struct phy *phy) in rockchip_emmc_phy_exit() argument
270 struct rockchip_emmc_phy *rk_phy = phy_get_drvdata(phy); in rockchip_emmc_phy_exit()
272 clk_put(rk_phy->emmcclk); in rockchip_emmc_phy_exit()
277 static int rockchip_emmc_phy_power_off(struct phy *phy) in rockchip_emmc_phy_power_off() argument
279 /* Power down emmc phy analog blocks */ in rockchip_emmc_phy_power_off()
280 return rockchip_emmc_phy_power(phy, PHYCTRL_PDB_PWR_OFF); in rockchip_emmc_phy_power_off()
283 static int rockchip_emmc_phy_power_on(struct phy *phy) in rockchip_emmc_phy_power_on() argument
285 struct rockchip_emmc_phy *rk_phy = phy_get_drvdata(phy); in rockchip_emmc_phy_power_on()
288 regmap_write(rk_phy->reg_base, in rockchip_emmc_phy_power_on()
289 rk_phy->reg_offset + GRF_EMMCPHY_CON6, in rockchip_emmc_phy_power_on()
290 HIWORD_UPDATE(rk_phy->drive_impedance, in rockchip_emmc_phy_power_on()
295 regmap_write(rk_phy->reg_base, in rockchip_emmc_phy_power_on()
296 rk_phy->reg_offset + GRF_EMMCPHY_CON0, in rockchip_emmc_phy_power_on()
302 regmap_write(rk_phy->reg_base, in rockchip_emmc_phy_power_on()
303 rk_phy->reg_offset + GRF_EMMCPHY_CON0, in rockchip_emmc_phy_power_on()
304 HIWORD_UPDATE(rk_phy->output_tapdelay_select, in rockchip_emmc_phy_power_on()
308 /* Internal pull-down for strobe line */ in rockchip_emmc_phy_power_on()
309 regmap_write(rk_phy->reg_base, in rockchip_emmc_phy_power_on()
310 rk_phy->reg_offset + GRF_EMMCPHY_CON2, in rockchip_emmc_phy_power_on()
311 HIWORD_UPDATE(rk_phy->enable_strobe_pulldown, in rockchip_emmc_phy_power_on()
315 /* Power up emmc phy analog blocks */ in rockchip_emmc_phy_power_on()
316 return rockchip_emmc_phy_power(phy, PHYCTRL_PDB_PWR_ON); in rockchip_emmc_phy_power_on()
342 dev_warn(&pdev->dev, "Invalid value %u for drive-impedance-ohm.\n", in convert_drive_impedance_ohm()
349 struct device *dev = &pdev->dev; in rockchip_emmc_phy_probe()
351 struct phy *generic_phy; in rockchip_emmc_phy_probe()
357 if (!dev->parent || !dev->parent->of_node) in rockchip_emmc_phy_probe()
358 return -ENODEV; in rockchip_emmc_phy_probe()
360 grf = syscon_node_to_regmap(dev->parent->of_node); in rockchip_emmc_phy_probe()
368 return -ENOMEM; in rockchip_emmc_phy_probe()
370 if (of_property_read_u32(dev->of_node, "reg", &reg_offset)) { in rockchip_emmc_phy_probe()
372 dev->of_node); in rockchip_emmc_phy_probe()
373 return -EINVAL; in rockchip_emmc_phy_probe()
376 rk_phy->reg_offset = reg_offset; in rockchip_emmc_phy_probe()
377 rk_phy->reg_base = grf; in rockchip_emmc_phy_probe()
378 rk_phy->drive_impedance = PHYCTRL_DR_50OHM; in rockchip_emmc_phy_probe()
379 rk_phy->enable_strobe_pulldown = PHYCTRL_REN_STRB_DISABLE; in rockchip_emmc_phy_probe()
380 rk_phy->output_tapdelay_select = PHYCTRL_OTAPDLYSEL_DEFAULT; in rockchip_emmc_phy_probe()
382 if (!of_property_read_u32(dev->of_node, "drive-impedance-ohm", &val)) in rockchip_emmc_phy_probe()
383 rk_phy->drive_impedance = convert_drive_impedance_ohm(pdev, val); in rockchip_emmc_phy_probe()
385 if (of_property_read_bool(dev->of_node, "rockchip,enable-strobe-pulldown")) in rockchip_emmc_phy_probe()
386 rk_phy->enable_strobe_pulldown = PHYCTRL_REN_STRB_ENABLE; in rockchip_emmc_phy_probe()
388 if (!of_property_read_u32(dev->of_node, "rockchip,output-tapdelay-select", &val)) { in rockchip_emmc_phy_probe()
390 rk_phy->output_tapdelay_select = val; in rockchip_emmc_phy_probe()
392 dev_err(dev, "output-tapdelay-select exceeds limit, apply default\n"); in rockchip_emmc_phy_probe()
395 generic_phy = devm_phy_create(dev, dev->of_node, &ops); in rockchip_emmc_phy_probe()
397 dev_err(dev, "failed to create PHY\n"); in rockchip_emmc_phy_probe()
408 { .compatible = "rockchip,rk3399-emmc-phy" },
417 .name = "rockchip-emmc-phy",
424 MODULE_AUTHOR("Shawn Lin <shawn.lin@rock-chips.com>");
425 MODULE_DESCRIPTION("Rockchip EMMC PHY driver");