]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/phy/phy-exynos-dp-video.c
Merge branches 'acpi-video' and 'acpi-ec'
[mirror_ubuntu-artful-kernel.git] / drivers / phy / phy-exynos-dp-video.c
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
12 #include <linux/err.h>
13 #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
24 struct exynos_dp_video_phy {
25 void __iomem *regs;
26 };
27
28 static 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
42 static 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
49 static 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
56 static 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
62 static 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
80 phy = devm_phy_create(dev, NULL, &exynos_dp_video_phy_ops, NULL);
81 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
87 phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
88
89 return PTR_ERR_OR_ZERO(phy_provider);
90 }
91
92 static const struct of_device_id exynos_dp_video_phy_of_match[] = {
93 { .compatible = "samsung,exynos5250-dp-video-phy" },
94 { },
95 };
96 MODULE_DEVICE_TABLE(of, exynos_dp_video_phy_of_match);
97
98 static 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 };
106 module_platform_driver(exynos_dp_video_phy_driver);
107
108 MODULE_AUTHOR("Jingoo Han <jg1.han@samsung.com>");
109 MODULE_DESCRIPTION("Samsung EXYNOS SoC DP PHY driver");
110 MODULE_LICENSE("GPL v2");