blob: 8b3026e2af7f7b517dad1898d8200ee5744b76a4 [file] [log] [blame]
Jingoo Han74988e82013-10-16 21:58:14 +05301/*
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 Kamatbbe21b22014-05-29 12:00:47 +053012#include <linux/err.h>
Jingoo Han74988e82013-10-16 21:58:14 +053013#include <linux/io.h>
14#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/of.h>
17#include <linux/of_address.h>
18#include <linux/phy/phy.h>
19#include <linux/platform_device.h>
20
21/* DPTX_PHY_CONTROL register */
22#define EXYNOS_DPTX_PHY_ENABLE (1 << 0)
23
24struct exynos_dp_video_phy {
25 void __iomem *regs;
26};
27
28static int __set_phy_state(struct exynos_dp_video_phy *state, unsigned int on)
29{
30 u32 reg;
31
32 reg = readl(state->regs);
33 if (on)
34 reg |= EXYNOS_DPTX_PHY_ENABLE;
35 else
36 reg &= ~EXYNOS_DPTX_PHY_ENABLE;
37 writel(reg, state->regs);
38
39 return 0;
40}
41
42static int exynos_dp_video_phy_power_on(struct phy *phy)
43{
44 struct exynos_dp_video_phy *state = phy_get_drvdata(phy);
45
46 return __set_phy_state(state, 1);
47}
48
49static int exynos_dp_video_phy_power_off(struct phy *phy)
50{
51 struct exynos_dp_video_phy *state = phy_get_drvdata(phy);
52
53 return __set_phy_state(state, 0);
54}
55
56static struct phy_ops exynos_dp_video_phy_ops = {
57 .power_on = exynos_dp_video_phy_power_on,
58 .power_off = exynos_dp_video_phy_power_off,
59 .owner = THIS_MODULE,
60};
61
62static int exynos_dp_video_phy_probe(struct platform_device *pdev)
63{
64 struct exynos_dp_video_phy *state;
65 struct device *dev = &pdev->dev;
66 struct resource *res;
67 struct phy_provider *phy_provider;
68 struct phy *phy;
69
70 state = devm_kzalloc(dev, sizeof(*state), GFP_KERNEL);
71 if (!state)
72 return -ENOMEM;
73
74 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
75
76 state->regs = devm_ioremap_resource(dev, res);
77 if (IS_ERR(state->regs))
78 return PTR_ERR(state->regs);
79
Kishon Vijay Abraham If0ed8172014-07-14 15:55:02 +053080 phy = devm_phy_create(dev, NULL, &exynos_dp_video_phy_ops, NULL);
Jingoo Han74988e82013-10-16 21:58:14 +053081 if (IS_ERR(phy)) {
82 dev_err(dev, "failed to create Display Port PHY\n");
83 return PTR_ERR(phy);
84 }
85 phy_set_drvdata(phy, state);
86
Kishon Vijay Abraham I64fe1892014-02-17 14:29:25 +053087 phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
Kishon Vijay Abraham I64fe1892014-02-17 14:29:25 +053088
Sachin Kamatbbe21b22014-05-29 12:00:47 +053089 return PTR_ERR_OR_ZERO(phy_provider);
Jingoo Han74988e82013-10-16 21:58:14 +053090}
91
92static const struct of_device_id exynos_dp_video_phy_of_match[] = {
93 { .compatible = "samsung,exynos5250-dp-video-phy" },
94 { },
95};
96MODULE_DEVICE_TABLE(of, exynos_dp_video_phy_of_match);
97
98static struct platform_driver exynos_dp_video_phy_driver = {
99 .probe = exynos_dp_video_phy_probe,
100 .driver = {
101 .name = "exynos-dp-video-phy",
102 .owner = THIS_MODULE,
103 .of_match_table = exynos_dp_video_phy_of_match,
104 }
105};
106module_platform_driver(exynos_dp_video_phy_driver);
107
108MODULE_AUTHOR("Jingoo Han <jg1.han@samsung.com>");
109MODULE_DESCRIPTION("Samsung EXYNOS SoC DP PHY driver");
110MODULE_LICENSE("GPL v2");