xref: /rk3399_rockchip-uboot/drivers/video/drm/rockchip_phy.c (revision 5821df21ae36d9ef252d346a5abb76be773c5d69)
1 /*
2  * (C) Copyright 2008-2017 Fuzhou Rockchip Electronics Co., Ltd
3  *
4  * SPDX-License-Identifier:	GPL-2.0+
5  */
6 
7 #include <config.h>
8 #include <common.h>
9 #include <dm/device.h>
10 #include <errno.h>
11 #include <fdtdec.h>
12 #include <fdt_support.h>
13 #include <asm/unaligned.h>
14 #include <linux/list.h>
15 
16 #include "rockchip_display.h"
17 #include "rockchip_crtc.h"
18 #include "rockchip_connector.h"
19 #include "rockchip_phy.h"
20 
21 #ifdef CONFIG_DRM_ROCKCHIP_DW_MIPI_DSI
22 static const struct rockchip_phy rockchip_rk3366_mipi_dphy_data = {
23 	 .funcs = &inno_mipi_dphy_funcs,
24 };
25 
26 static const struct rockchip_phy rockchip_rk3368_mipi_dphy_data = {
27 	 .funcs = &inno_mipi_dphy_funcs,
28 };
29 
30 static const struct rockchip_phy rockchip_rk312x_mipi_dphy_data = {
31 	 .funcs = &inno_mipi_dphy_funcs,
32 };
33 #endif
34 
35 static const struct udevice_id rockchip_phy_ids[] = {
36 #ifdef CONFIG_DRM_ROCKCHIP_DW_MIPI_DSI
37 	{
38 	 .compatible = "rockchip,rk3366-mipi-dphy",
39 	 .data = (ulong)&rockchip_rk3366_mipi_dphy_data,
40 	},
41 	{
42 	 .compatible = "rockchip,rk3368-mipi-dphy",
43 	 .data = (ulong)&rockchip_rk3368_mipi_dphy_data,
44 	},
45 	{
46 	 .compatible = "rockchip,rk312x-mipi-dphy",
47 	 .data = (ulong)&rockchip_rk312x_mipi_dphy_data,
48 	},
49 #endif
50 	{}
51 };
52 
53 static int rockchip_phy_probe(struct udevice *dev)
54 {
55 	return 0;
56 }
57 
58 static int rockchip_phy_bind(struct udevice *dev)
59 {
60 	return 0;
61 }
62 
63 U_BOOT_DRIVER(rockchip_phy) = {
64 	.name = "rockchip_phy",
65 	.id = UCLASS_PHY,
66 	.of_match = rockchip_phy_ids,
67 	.bind	= rockchip_phy_bind,
68 	.probe	= rockchip_phy_probe,
69 };
70 
71 int rockchip_phy_power_on(struct display_state *state)
72 {
73 	struct connector_state *conn_state = &state->conn_state;
74 	const struct rockchip_phy *phy = conn_state->phy;
75 
76 	if (!phy || !phy->funcs || !phy->funcs->power_on) {
77 		printf("%s: failed to find phy power on funcs\n", __func__);
78 		return -ENODEV;
79 	}
80 
81 	return phy->funcs->power_on(state);
82 }
83 
84 int rockchip_phy_power_off(struct display_state *state)
85 {
86 	struct connector_state *conn_state = &state->conn_state;
87 	const struct rockchip_phy *phy = conn_state->phy;
88 
89 	if (!phy || !phy->funcs || !phy->funcs->power_off) {
90 		printf("%s: failed to find phy power_off funcs\n", __func__);
91 		return -ENODEV;
92 	}
93 
94 	return phy->funcs->power_off(state);
95 }
96 
97 unsigned long rockchip_phy_set_pll(struct display_state *state,
98 				   unsigned long rate)
99 {
100 	struct connector_state *conn_state = &state->conn_state;
101 	const struct rockchip_phy *phy = conn_state->phy;
102 
103 	if (!phy || !phy->funcs || !phy->funcs->set_pll) {
104 		printf("%s: failed to find phy set_pll funcs\n", __func__);
105 		return -ENODEV;
106 	}
107 
108 	return phy->funcs->set_pll(state, rate);
109 }
110