xref: /openbmc/linux/drivers/phy/samsung/phy-exynos-dp-video.c (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
20b56e9a7SVivek Gautam /*
3c233a2edSKrzysztof Kozlowski  * Samsung Exynos SoC series Display Port PHY driver
40b56e9a7SVivek Gautam  *
50b56e9a7SVivek Gautam  * Copyright (C) 2013 Samsung Electronics Co., Ltd.
60b56e9a7SVivek Gautam  * Author: Jingoo Han <jg1.han@samsung.com>
70b56e9a7SVivek Gautam  */
80b56e9a7SVivek Gautam 
90b56e9a7SVivek Gautam #include <linux/err.h>
100b56e9a7SVivek Gautam #include <linux/io.h>
110b56e9a7SVivek Gautam #include <linux/kernel.h>
120b56e9a7SVivek Gautam #include <linux/module.h>
130b56e9a7SVivek Gautam #include <linux/mfd/syscon.h>
140b56e9a7SVivek Gautam #include <linux/of.h>
150b56e9a7SVivek Gautam #include <linux/phy/phy.h>
160b56e9a7SVivek Gautam #include <linux/platform_device.h>
170b56e9a7SVivek Gautam #include <linux/regmap.h>
180b56e9a7SVivek Gautam #include <linux/soc/samsung/exynos-regs-pmu.h>
190b56e9a7SVivek Gautam 
200b56e9a7SVivek Gautam struct exynos_dp_video_phy_drvdata {
210b56e9a7SVivek Gautam 	u32 phy_ctrl_offset;
220b56e9a7SVivek Gautam };
230b56e9a7SVivek Gautam 
240b56e9a7SVivek Gautam struct exynos_dp_video_phy {
250b56e9a7SVivek Gautam 	struct regmap *regs;
260b56e9a7SVivek Gautam 	const struct exynos_dp_video_phy_drvdata *drvdata;
270b56e9a7SVivek Gautam };
280b56e9a7SVivek Gautam 
exynos_dp_video_phy_power_on(struct phy * phy)290b56e9a7SVivek Gautam static int exynos_dp_video_phy_power_on(struct phy *phy)
300b56e9a7SVivek Gautam {
310b56e9a7SVivek Gautam 	struct exynos_dp_video_phy *state = phy_get_drvdata(phy);
320b56e9a7SVivek Gautam 
330b56e9a7SVivek Gautam 	/* Disable power isolation on DP-PHY */
340b56e9a7SVivek Gautam 	return regmap_update_bits(state->regs, state->drvdata->phy_ctrl_offset,
350b56e9a7SVivek Gautam 				  EXYNOS4_PHY_ENABLE, EXYNOS4_PHY_ENABLE);
360b56e9a7SVivek Gautam }
370b56e9a7SVivek Gautam 
exynos_dp_video_phy_power_off(struct phy * phy)380b56e9a7SVivek Gautam static int exynos_dp_video_phy_power_off(struct phy *phy)
390b56e9a7SVivek Gautam {
400b56e9a7SVivek Gautam 	struct exynos_dp_video_phy *state = phy_get_drvdata(phy);
410b56e9a7SVivek Gautam 
420b56e9a7SVivek Gautam 	/* Enable power isolation on DP-PHY */
430b56e9a7SVivek Gautam 	return regmap_update_bits(state->regs, state->drvdata->phy_ctrl_offset,
440b56e9a7SVivek Gautam 				  EXYNOS4_PHY_ENABLE, 0);
450b56e9a7SVivek Gautam }
460b56e9a7SVivek Gautam 
470b56e9a7SVivek Gautam static const struct phy_ops exynos_dp_video_phy_ops = {
480b56e9a7SVivek Gautam 	.power_on	= exynos_dp_video_phy_power_on,
490b56e9a7SVivek Gautam 	.power_off	= exynos_dp_video_phy_power_off,
500b56e9a7SVivek Gautam 	.owner		= THIS_MODULE,
510b56e9a7SVivek Gautam };
520b56e9a7SVivek Gautam 
530b56e9a7SVivek Gautam static const struct exynos_dp_video_phy_drvdata exynos5250_dp_video_phy = {
540b56e9a7SVivek Gautam 	.phy_ctrl_offset	= EXYNOS5_DPTX_PHY_CONTROL,
550b56e9a7SVivek Gautam };
560b56e9a7SVivek Gautam 
570b56e9a7SVivek Gautam static const struct exynos_dp_video_phy_drvdata exynos5420_dp_video_phy = {
580b56e9a7SVivek Gautam 	.phy_ctrl_offset	= EXYNOS5420_DPTX_PHY_CONTROL,
590b56e9a7SVivek Gautam };
600b56e9a7SVivek Gautam 
610b56e9a7SVivek Gautam static const struct of_device_id exynos_dp_video_phy_of_match[] = {
620b56e9a7SVivek Gautam 	{
630b56e9a7SVivek Gautam 		.compatible = "samsung,exynos5250-dp-video-phy",
640b56e9a7SVivek Gautam 		.data = &exynos5250_dp_video_phy,
650b56e9a7SVivek Gautam 	}, {
660b56e9a7SVivek Gautam 		.compatible = "samsung,exynos5420-dp-video-phy",
670b56e9a7SVivek Gautam 		.data = &exynos5420_dp_video_phy,
680b56e9a7SVivek Gautam 	},
690b56e9a7SVivek Gautam 	{ },
700b56e9a7SVivek Gautam };
710b56e9a7SVivek Gautam MODULE_DEVICE_TABLE(of, exynos_dp_video_phy_of_match);
720b56e9a7SVivek Gautam 
exynos_dp_video_phy_probe(struct platform_device * pdev)730b56e9a7SVivek Gautam static int exynos_dp_video_phy_probe(struct platform_device *pdev)
740b56e9a7SVivek Gautam {
750b56e9a7SVivek Gautam 	struct exynos_dp_video_phy *state;
760b56e9a7SVivek Gautam 	struct device *dev = &pdev->dev;
770b56e9a7SVivek Gautam 	struct phy_provider *phy_provider;
780b56e9a7SVivek Gautam 	struct phy *phy;
790b56e9a7SVivek Gautam 
800b56e9a7SVivek Gautam 	state = devm_kzalloc(dev, sizeof(*state), GFP_KERNEL);
810b56e9a7SVivek Gautam 	if (!state)
820b56e9a7SVivek Gautam 		return -ENOMEM;
830b56e9a7SVivek Gautam 
84*220fc398SKrzysztof Kozlowski 	state->regs = syscon_node_to_regmap(dev->parent->of_node);
85*220fc398SKrzysztof Kozlowski 	if (IS_ERR(state->regs))
86*220fc398SKrzysztof Kozlowski 		/* Backwards compatible way */
870b56e9a7SVivek Gautam 		state->regs = syscon_regmap_lookup_by_phandle(dev->of_node,
880b56e9a7SVivek Gautam 							      "samsung,pmu-syscon");
890b56e9a7SVivek Gautam 	if (IS_ERR(state->regs)) {
900b56e9a7SVivek Gautam 		dev_err(dev, "Failed to lookup PMU regmap\n");
910b56e9a7SVivek Gautam 		return PTR_ERR(state->regs);
920b56e9a7SVivek Gautam 	}
930b56e9a7SVivek Gautam 
94e0ed4082SChunfeng Yun 	state->drvdata = of_device_get_match_data(dev);
950b56e9a7SVivek Gautam 
960b56e9a7SVivek Gautam 	phy = devm_phy_create(dev, NULL, &exynos_dp_video_phy_ops);
970b56e9a7SVivek Gautam 	if (IS_ERR(phy)) {
980b56e9a7SVivek Gautam 		dev_err(dev, "failed to create Display Port PHY\n");
990b56e9a7SVivek Gautam 		return PTR_ERR(phy);
1000b56e9a7SVivek Gautam 	}
1010b56e9a7SVivek Gautam 	phy_set_drvdata(phy, state);
1020b56e9a7SVivek Gautam 
1030b56e9a7SVivek Gautam 	phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
1040b56e9a7SVivek Gautam 
1050b56e9a7SVivek Gautam 	return PTR_ERR_OR_ZERO(phy_provider);
1060b56e9a7SVivek Gautam }
1070b56e9a7SVivek Gautam 
1080b56e9a7SVivek Gautam static struct platform_driver exynos_dp_video_phy_driver = {
1090b56e9a7SVivek Gautam 	.probe	= exynos_dp_video_phy_probe,
1100b56e9a7SVivek Gautam 	.driver = {
1110b56e9a7SVivek Gautam 		.name	= "exynos-dp-video-phy",
1120b56e9a7SVivek Gautam 		.of_match_table	= exynos_dp_video_phy_of_match,
1136aeec986SMarek Szyprowski 		.suppress_bind_attrs = true,
1140b56e9a7SVivek Gautam 	}
1150b56e9a7SVivek Gautam };
1160b56e9a7SVivek Gautam module_platform_driver(exynos_dp_video_phy_driver);
1170b56e9a7SVivek Gautam 
1180b56e9a7SVivek Gautam MODULE_AUTHOR("Jingoo Han <jg1.han@samsung.com>");
119c233a2edSKrzysztof Kozlowski MODULE_DESCRIPTION("Samsung Exynos SoC DP PHY driver");
1200b56e9a7SVivek Gautam MODULE_LICENSE("GPL v2");
121