1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * Samsung Exynos SoC series Display Port PHY driver 4 * 5 * Copyright (C) 2013 Samsung Electronics Co., Ltd. 6 * Author: Jingoo Han <jg1.han@samsung.com> 7 */ 8 9 #include <linux/err.h> 10 #include <linux/io.h> 11 #include <linux/kernel.h> 12 #include <linux/module.h> 13 #include <linux/mfd/syscon.h> 14 #include <linux/of.h> 15 #include <linux/of_address.h> 16 #include <linux/of_device.h> 17 #include <linux/phy/phy.h> 18 #include <linux/platform_device.h> 19 #include <linux/regmap.h> 20 #include <linux/soc/samsung/exynos-regs-pmu.h> 21 22 struct exynos_dp_video_phy_drvdata { 23 u32 phy_ctrl_offset; 24 }; 25 26 struct exynos_dp_video_phy { 27 struct regmap *regs; 28 const struct exynos_dp_video_phy_drvdata *drvdata; 29 }; 30 31 static int exynos_dp_video_phy_power_on(struct phy *phy) 32 { 33 struct exynos_dp_video_phy *state = phy_get_drvdata(phy); 34 35 /* Disable power isolation on DP-PHY */ 36 return regmap_update_bits(state->regs, state->drvdata->phy_ctrl_offset, 37 EXYNOS4_PHY_ENABLE, EXYNOS4_PHY_ENABLE); 38 } 39 40 static int exynos_dp_video_phy_power_off(struct phy *phy) 41 { 42 struct exynos_dp_video_phy *state = phy_get_drvdata(phy); 43 44 /* Enable power isolation on DP-PHY */ 45 return regmap_update_bits(state->regs, state->drvdata->phy_ctrl_offset, 46 EXYNOS4_PHY_ENABLE, 0); 47 } 48 49 static const struct phy_ops exynos_dp_video_phy_ops = { 50 .power_on = exynos_dp_video_phy_power_on, 51 .power_off = exynos_dp_video_phy_power_off, 52 .owner = THIS_MODULE, 53 }; 54 55 static const struct exynos_dp_video_phy_drvdata exynos5250_dp_video_phy = { 56 .phy_ctrl_offset = EXYNOS5_DPTX_PHY_CONTROL, 57 }; 58 59 static const struct exynos_dp_video_phy_drvdata exynos5420_dp_video_phy = { 60 .phy_ctrl_offset = EXYNOS5420_DPTX_PHY_CONTROL, 61 }; 62 63 static const struct of_device_id exynos_dp_video_phy_of_match[] = { 64 { 65 .compatible = "samsung,exynos5250-dp-video-phy", 66 .data = &exynos5250_dp_video_phy, 67 }, { 68 .compatible = "samsung,exynos5420-dp-video-phy", 69 .data = &exynos5420_dp_video_phy, 70 }, 71 { }, 72 }; 73 MODULE_DEVICE_TABLE(of, exynos_dp_video_phy_of_match); 74 75 static int exynos_dp_video_phy_probe(struct platform_device *pdev) 76 { 77 struct exynos_dp_video_phy *state; 78 struct device *dev = &pdev->dev; 79 struct phy_provider *phy_provider; 80 struct phy *phy; 81 82 state = devm_kzalloc(dev, sizeof(*state), GFP_KERNEL); 83 if (!state) 84 return -ENOMEM; 85 86 state->regs = syscon_node_to_regmap(dev->parent->of_node); 87 if (IS_ERR(state->regs)) 88 /* Backwards compatible way */ 89 state->regs = syscon_regmap_lookup_by_phandle(dev->of_node, 90 "samsung,pmu-syscon"); 91 if (IS_ERR(state->regs)) { 92 dev_err(dev, "Failed to lookup PMU regmap\n"); 93 return PTR_ERR(state->regs); 94 } 95 96 state->drvdata = of_device_get_match_data(dev); 97 98 phy = devm_phy_create(dev, NULL, &exynos_dp_video_phy_ops); 99 if (IS_ERR(phy)) { 100 dev_err(dev, "failed to create Display Port PHY\n"); 101 return PTR_ERR(phy); 102 } 103 phy_set_drvdata(phy, state); 104 105 phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); 106 107 return PTR_ERR_OR_ZERO(phy_provider); 108 } 109 110 static struct platform_driver exynos_dp_video_phy_driver = { 111 .probe = exynos_dp_video_phy_probe, 112 .driver = { 113 .name = "exynos-dp-video-phy", 114 .of_match_table = exynos_dp_video_phy_of_match, 115 .suppress_bind_attrs = true, 116 } 117 }; 118 module_platform_driver(exynos_dp_video_phy_driver); 119 120 MODULE_AUTHOR("Jingoo Han <jg1.han@samsung.com>"); 121 MODULE_DESCRIPTION("Samsung Exynos SoC DP PHY driver"); 122 MODULE_LICENSE("GPL v2"); 123