Jingoo Han | 74988e8 | 2013-10-16 21:58:14 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Samsung EXYNOS SoC series Display Port PHY driver |
| 3 | * |
| 4 | * Copyright (C) 2013 Samsung Electronics Co., Ltd. |
| 5 | * Author: Jingoo Han <jg1.han@samsung.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 version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | */ |
| 11 | |
Sachin Kamat | bbe21b2 | 2014-05-29 12:00:47 +0530 | [diff] [blame] | 12 | #include <linux/err.h> |
Jingoo Han | 74988e8 | 2013-10-16 21:58:14 +0530 | [diff] [blame] | 13 | #include <linux/io.h> |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/module.h> |
Vivek Gautam | a5ec598 | 2014-09-16 10:32:06 +0530 | [diff] [blame] | 16 | #include <linux/mfd/syscon.h> |
Jingoo Han | 74988e8 | 2013-10-16 21:58:14 +0530 | [diff] [blame] | 17 | #include <linux/of.h> |
| 18 | #include <linux/of_address.h> |
Chunfeng Yun | e0ed408 | 2017-08-09 17:17:58 +0800 | [diff] [blame] | 19 | #include <linux/of_device.h> |
Jingoo Han | 74988e8 | 2013-10-16 21:58:14 +0530 | [diff] [blame] | 20 | #include <linux/phy/phy.h> |
| 21 | #include <linux/platform_device.h> |
Vivek Gautam | a5ec598 | 2014-09-16 10:32:06 +0530 | [diff] [blame] | 22 | #include <linux/regmap.h> |
Krzysztof Kozlowski | 424c984 | 2017-03-14 18:46:50 +0200 | [diff] [blame] | 23 | #include <linux/soc/samsung/exynos-regs-pmu.h> |
Jingoo Han | 74988e8 | 2013-10-16 21:58:14 +0530 | [diff] [blame] | 24 | |
Vivek Gautam | a5ec598 | 2014-09-16 10:32:06 +0530 | [diff] [blame] | 25 | struct exynos_dp_video_phy_drvdata { |
| 26 | u32 phy_ctrl_offset; |
Jingoo Han | 74988e8 | 2013-10-16 21:58:14 +0530 | [diff] [blame] | 27 | }; |
| 28 | |
Vivek Gautam | a5ec598 | 2014-09-16 10:32:06 +0530 | [diff] [blame] | 29 | struct exynos_dp_video_phy { |
| 30 | struct regmap *regs; |
| 31 | const struct exynos_dp_video_phy_drvdata *drvdata; |
| 32 | }; |
| 33 | |
Jingoo Han | 74988e8 | 2013-10-16 21:58:14 +0530 | [diff] [blame] | 34 | static int exynos_dp_video_phy_power_on(struct phy *phy) |
| 35 | { |
| 36 | struct exynos_dp_video_phy *state = phy_get_drvdata(phy); |
| 37 | |
Vivek Gautam | a5ec598 | 2014-09-16 10:32:06 +0530 | [diff] [blame] | 38 | /* Disable power isolation on DP-PHY */ |
Axel Lin | 0f9722e | 2015-02-27 12:34:10 +0800 | [diff] [blame] | 39 | return regmap_update_bits(state->regs, state->drvdata->phy_ctrl_offset, |
Krzysztof Kozlowski | 7a66647 | 2017-03-29 13:59:57 +0530 | [diff] [blame] | 40 | EXYNOS4_PHY_ENABLE, EXYNOS4_PHY_ENABLE); |
Jingoo Han | 74988e8 | 2013-10-16 21:58:14 +0530 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | static int exynos_dp_video_phy_power_off(struct phy *phy) |
| 44 | { |
| 45 | struct exynos_dp_video_phy *state = phy_get_drvdata(phy); |
| 46 | |
Vivek Gautam | a5ec598 | 2014-09-16 10:32:06 +0530 | [diff] [blame] | 47 | /* Enable power isolation on DP-PHY */ |
Axel Lin | 0f9722e | 2015-02-27 12:34:10 +0800 | [diff] [blame] | 48 | return regmap_update_bits(state->regs, state->drvdata->phy_ctrl_offset, |
Krzysztof Kozlowski | 7a66647 | 2017-03-29 13:59:57 +0530 | [diff] [blame] | 49 | EXYNOS4_PHY_ENABLE, 0); |
Jingoo Han | 74988e8 | 2013-10-16 21:58:14 +0530 | [diff] [blame] | 50 | } |
| 51 | |
Axel Lin | 4a9e5ca | 2015-07-15 15:33:51 +0800 | [diff] [blame] | 52 | static const struct phy_ops exynos_dp_video_phy_ops = { |
Jingoo Han | 74988e8 | 2013-10-16 21:58:14 +0530 | [diff] [blame] | 53 | .power_on = exynos_dp_video_phy_power_on, |
| 54 | .power_off = exynos_dp_video_phy_power_off, |
| 55 | .owner = THIS_MODULE, |
| 56 | }; |
| 57 | |
Vivek Gautam | a5ec598 | 2014-09-16 10:32:06 +0530 | [diff] [blame] | 58 | static const struct exynos_dp_video_phy_drvdata exynos5250_dp_video_phy = { |
| 59 | .phy_ctrl_offset = EXYNOS5_DPTX_PHY_CONTROL, |
| 60 | }; |
| 61 | |
| 62 | static const struct exynos_dp_video_phy_drvdata exynos5420_dp_video_phy = { |
| 63 | .phy_ctrl_offset = EXYNOS5420_DPTX_PHY_CONTROL, |
| 64 | }; |
| 65 | |
| 66 | static const struct of_device_id exynos_dp_video_phy_of_match[] = { |
| 67 | { |
| 68 | .compatible = "samsung,exynos5250-dp-video-phy", |
| 69 | .data = &exynos5250_dp_video_phy, |
| 70 | }, { |
| 71 | .compatible = "samsung,exynos5420-dp-video-phy", |
| 72 | .data = &exynos5420_dp_video_phy, |
| 73 | }, |
| 74 | { }, |
| 75 | }; |
| 76 | MODULE_DEVICE_TABLE(of, exynos_dp_video_phy_of_match); |
| 77 | |
Jingoo Han | 74988e8 | 2013-10-16 21:58:14 +0530 | [diff] [blame] | 78 | static int exynos_dp_video_phy_probe(struct platform_device *pdev) |
| 79 | { |
| 80 | struct exynos_dp_video_phy *state; |
| 81 | struct device *dev = &pdev->dev; |
Jingoo Han | 74988e8 | 2013-10-16 21:58:14 +0530 | [diff] [blame] | 82 | struct phy_provider *phy_provider; |
| 83 | struct phy *phy; |
| 84 | |
| 85 | state = devm_kzalloc(dev, sizeof(*state), GFP_KERNEL); |
| 86 | if (!state) |
| 87 | return -ENOMEM; |
| 88 | |
Vivek Gautam | a5ec598 | 2014-09-16 10:32:06 +0530 | [diff] [blame] | 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"); |
Jingoo Han | 74988e8 | 2013-10-16 21:58:14 +0530 | [diff] [blame] | 93 | return PTR_ERR(state->regs); |
Vivek Gautam | a5ec598 | 2014-09-16 10:32:06 +0530 | [diff] [blame] | 94 | } |
| 95 | |
Chunfeng Yun | e0ed408 | 2017-08-09 17:17:58 +0800 | [diff] [blame] | 96 | state->drvdata = of_device_get_match_data(dev); |
Jingoo Han | 74988e8 | 2013-10-16 21:58:14 +0530 | [diff] [blame] | 97 | |
Heikki Krogerus | dbc9863 | 2014-11-19 17:28:21 +0200 | [diff] [blame] | 98 | phy = devm_phy_create(dev, NULL, &exynos_dp_video_phy_ops); |
Jingoo Han | 74988e8 | 2013-10-16 21:58:14 +0530 | [diff] [blame] | 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 | |
Kishon Vijay Abraham I | 64fe189 | 2014-02-17 14:29:25 +0530 | [diff] [blame] | 105 | phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); |
Kishon Vijay Abraham I | 64fe189 | 2014-02-17 14:29:25 +0530 | [diff] [blame] | 106 | |
Sachin Kamat | bbe21b2 | 2014-05-29 12:00:47 +0530 | [diff] [blame] | 107 | return PTR_ERR_OR_ZERO(phy_provider); |
Jingoo Han | 74988e8 | 2013-10-16 21:58:14 +0530 | [diff] [blame] | 108 | } |
| 109 | |
Jingoo Han | 74988e8 | 2013-10-16 21:58:14 +0530 | [diff] [blame] | 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", |
Jingoo Han | 74988e8 | 2013-10-16 21:58:14 +0530 | [diff] [blame] | 114 | .of_match_table = exynos_dp_video_phy_of_match, |
| 115 | } |
| 116 | }; |
| 117 | module_platform_driver(exynos_dp_video_phy_driver); |
| 118 | |
| 119 | MODULE_AUTHOR("Jingoo Han <jg1.han@samsung.com>"); |
| 120 | MODULE_DESCRIPTION("Samsung EXYNOS SoC DP PHY driver"); |
| 121 | MODULE_LICENSE("GPL v2"); |