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> |
| 17 | #include <linux/mfd/syscon/exynos5-pmu.h> |
Jingoo Han | 74988e8 | 2013-10-16 21:58:14 +0530 | [diff] [blame] | 18 | #include <linux/of.h> |
| 19 | #include <linux/of_address.h> |
| 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> |
Jingoo Han | 74988e8 | 2013-10-16 21:58:14 +0530 | [diff] [blame] | 23 | |
Vivek Gautam | a5ec598 | 2014-09-16 10:32:06 +0530 | [diff] [blame] | 24 | struct exynos_dp_video_phy_drvdata { |
| 25 | u32 phy_ctrl_offset; |
Jingoo Han | 74988e8 | 2013-10-16 21:58:14 +0530 | [diff] [blame] | 26 | }; |
| 27 | |
Vivek Gautam | a5ec598 | 2014-09-16 10:32:06 +0530 | [diff] [blame] | 28 | struct exynos_dp_video_phy { |
| 29 | struct regmap *regs; |
| 30 | const struct exynos_dp_video_phy_drvdata *drvdata; |
| 31 | }; |
| 32 | |
| 33 | static void exynos_dp_video_phy_pwr_isol(struct exynos_dp_video_phy *state, |
| 34 | unsigned int on) |
Jingoo Han | 74988e8 | 2013-10-16 21:58:14 +0530 | [diff] [blame] | 35 | { |
Vivek Gautam | a5ec598 | 2014-09-16 10:32:06 +0530 | [diff] [blame] | 36 | unsigned int val; |
Jingoo Han | 74988e8 | 2013-10-16 21:58:14 +0530 | [diff] [blame] | 37 | |
Vivek Gautam | a5ec598 | 2014-09-16 10:32:06 +0530 | [diff] [blame] | 38 | if (IS_ERR(state->regs)) |
| 39 | return; |
Jingoo Han | 74988e8 | 2013-10-16 21:58:14 +0530 | [diff] [blame] | 40 | |
Vivek Gautam | a5ec598 | 2014-09-16 10:32:06 +0530 | [diff] [blame] | 41 | val = on ? 0 : EXYNOS5_PHY_ENABLE; |
| 42 | |
| 43 | regmap_update_bits(state->regs, state->drvdata->phy_ctrl_offset, |
| 44 | EXYNOS5_PHY_ENABLE, val); |
Jingoo Han | 74988e8 | 2013-10-16 21:58:14 +0530 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | static int exynos_dp_video_phy_power_on(struct phy *phy) |
| 48 | { |
| 49 | struct exynos_dp_video_phy *state = phy_get_drvdata(phy); |
| 50 | |
Vivek Gautam | a5ec598 | 2014-09-16 10:32:06 +0530 | [diff] [blame] | 51 | /* Disable power isolation on DP-PHY */ |
| 52 | exynos_dp_video_phy_pwr_isol(state, 0); |
| 53 | |
| 54 | return 0; |
Jingoo Han | 74988e8 | 2013-10-16 21:58:14 +0530 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | static int exynos_dp_video_phy_power_off(struct phy *phy) |
| 58 | { |
| 59 | struct exynos_dp_video_phy *state = phy_get_drvdata(phy); |
| 60 | |
Vivek Gautam | a5ec598 | 2014-09-16 10:32:06 +0530 | [diff] [blame] | 61 | /* Enable power isolation on DP-PHY */ |
| 62 | exynos_dp_video_phy_pwr_isol(state, 1); |
| 63 | |
| 64 | return 0; |
Jingoo Han | 74988e8 | 2013-10-16 21:58:14 +0530 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | static struct phy_ops exynos_dp_video_phy_ops = { |
| 68 | .power_on = exynos_dp_video_phy_power_on, |
| 69 | .power_off = exynos_dp_video_phy_power_off, |
| 70 | .owner = THIS_MODULE, |
| 71 | }; |
| 72 | |
Vivek Gautam | a5ec598 | 2014-09-16 10:32:06 +0530 | [diff] [blame] | 73 | static const struct exynos_dp_video_phy_drvdata exynos5250_dp_video_phy = { |
| 74 | .phy_ctrl_offset = EXYNOS5_DPTX_PHY_CONTROL, |
| 75 | }; |
| 76 | |
| 77 | static const struct exynos_dp_video_phy_drvdata exynos5420_dp_video_phy = { |
| 78 | .phy_ctrl_offset = EXYNOS5420_DPTX_PHY_CONTROL, |
| 79 | }; |
| 80 | |
| 81 | static const struct of_device_id exynos_dp_video_phy_of_match[] = { |
| 82 | { |
| 83 | .compatible = "samsung,exynos5250-dp-video-phy", |
| 84 | .data = &exynos5250_dp_video_phy, |
| 85 | }, { |
| 86 | .compatible = "samsung,exynos5420-dp-video-phy", |
| 87 | .data = &exynos5420_dp_video_phy, |
| 88 | }, |
| 89 | { }, |
| 90 | }; |
| 91 | MODULE_DEVICE_TABLE(of, exynos_dp_video_phy_of_match); |
| 92 | |
Jingoo Han | 74988e8 | 2013-10-16 21:58:14 +0530 | [diff] [blame] | 93 | static int exynos_dp_video_phy_probe(struct platform_device *pdev) |
| 94 | { |
| 95 | struct exynos_dp_video_phy *state; |
| 96 | struct device *dev = &pdev->dev; |
Vivek Gautam | a5ec598 | 2014-09-16 10:32:06 +0530 | [diff] [blame] | 97 | const struct of_device_id *match; |
Jingoo Han | 74988e8 | 2013-10-16 21:58:14 +0530 | [diff] [blame] | 98 | struct phy_provider *phy_provider; |
| 99 | struct phy *phy; |
| 100 | |
| 101 | state = devm_kzalloc(dev, sizeof(*state), GFP_KERNEL); |
| 102 | if (!state) |
| 103 | return -ENOMEM; |
| 104 | |
Vivek Gautam | a5ec598 | 2014-09-16 10:32:06 +0530 | [diff] [blame] | 105 | state->regs = syscon_regmap_lookup_by_phandle(dev->of_node, |
| 106 | "samsung,pmu-syscon"); |
| 107 | if (IS_ERR(state->regs)) { |
| 108 | dev_err(dev, "Failed to lookup PMU regmap\n"); |
Jingoo Han | 74988e8 | 2013-10-16 21:58:14 +0530 | [diff] [blame] | 109 | return PTR_ERR(state->regs); |
Vivek Gautam | a5ec598 | 2014-09-16 10:32:06 +0530 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | match = of_match_node(exynos_dp_video_phy_of_match, dev->of_node); |
| 113 | state->drvdata = match->data; |
Jingoo Han | 74988e8 | 2013-10-16 21:58:14 +0530 | [diff] [blame] | 114 | |
Heikki Krogerus | dbc9863 | 2014-11-19 17:28:21 +0200 | [diff] [blame] | 115 | phy = devm_phy_create(dev, NULL, &exynos_dp_video_phy_ops); |
Jingoo Han | 74988e8 | 2013-10-16 21:58:14 +0530 | [diff] [blame] | 116 | if (IS_ERR(phy)) { |
| 117 | dev_err(dev, "failed to create Display Port PHY\n"); |
| 118 | return PTR_ERR(phy); |
| 119 | } |
| 120 | phy_set_drvdata(phy, state); |
| 121 | |
Kishon Vijay Abraham I | 64fe189 | 2014-02-17 14:29:25 +0530 | [diff] [blame] | 122 | 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] | 123 | |
Sachin Kamat | bbe21b2 | 2014-05-29 12:00:47 +0530 | [diff] [blame] | 124 | return PTR_ERR_OR_ZERO(phy_provider); |
Jingoo Han | 74988e8 | 2013-10-16 21:58:14 +0530 | [diff] [blame] | 125 | } |
| 126 | |
Jingoo Han | 74988e8 | 2013-10-16 21:58:14 +0530 | [diff] [blame] | 127 | static struct platform_driver exynos_dp_video_phy_driver = { |
| 128 | .probe = exynos_dp_video_phy_probe, |
| 129 | .driver = { |
| 130 | .name = "exynos-dp-video-phy", |
Jingoo Han | 74988e8 | 2013-10-16 21:58:14 +0530 | [diff] [blame] | 131 | .of_match_table = exynos_dp_video_phy_of_match, |
| 132 | } |
| 133 | }; |
| 134 | module_platform_driver(exynos_dp_video_phy_driver); |
| 135 | |
| 136 | MODULE_AUTHOR("Jingoo Han <jg1.han@samsung.com>"); |
| 137 | MODULE_DESCRIPTION("Samsung EXYNOS SoC DP PHY driver"); |
| 138 | MODULE_LICENSE("GPL v2"); |