xref: /rk3399_rockchip-uboot/drivers/video/drm/rockchip_phy.c (revision 21016d27c500da4326bdc59cd3505fcd85d236db)
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 #endif
30 
31 static const struct udevice_id rockchip_phy_ids[] = {
32 #ifdef CONFIG_DRM_ROCKCHIP_DW_MIPI_DSI
33 	{
34 	 .compatible = "rockchip,rk3366-mipi-dphy",
35 	 .data = (ulong)&rockchip_rk3366_mipi_dphy_data,
36 	},
37 	{
38 	 .compatible = "rockchip,rk3368-mipi-dphy",
39 	 .data = (ulong)&rockchip_rk3368_mipi_dphy_data,
40 	},
41 #endif
42 	{}
43 };
44 
45 static int rockchip_phy_probe(struct udevice *dev)
46 {
47 	return 0;
48 }
49 
50 static int rockchip_phy_bind(struct udevice *dev)
51 {
52 	return 0;
53 }
54 
55 U_BOOT_DRIVER(rockchip_phy) = {
56 	.name = "rockchip_phy",
57 	.id = UCLASS_PHY,
58 	.of_match = rockchip_phy_ids,
59 	.bind	= rockchip_phy_bind,
60 	.probe	= rockchip_phy_probe,
61 };
62 
63 int rockchip_phy_power_on(struct display_state *state)
64 {
65 	struct connector_state *conn_state = &state->conn_state;
66 	const struct rockchip_phy *phy = conn_state->phy;
67 
68 	if (!phy || !phy->funcs || !phy->funcs->power_on) {
69 		printf("%s: failed to find phy power on funcs\n", __func__);
70 		return -ENODEV;
71 	}
72 
73 	return phy->funcs->power_on(state);
74 }
75 
76 int rockchip_phy_power_off(struct display_state *state)
77 {
78 	struct connector_state *conn_state = &state->conn_state;
79 	const struct rockchip_phy *phy = conn_state->phy;
80 
81 	if (!phy || !phy->funcs || !phy->funcs->power_off) {
82 		printf("%s: failed to find phy power_off funcs\n", __func__);
83 		return -ENODEV;
84 	}
85 
86 	return phy->funcs->power_off(state);
87 }
88 
89 unsigned long rockchip_phy_set_pll(struct display_state *state,
90 				   unsigned long rate)
91 {
92 	struct connector_state *conn_state = &state->conn_state;
93 	const struct rockchip_phy *phy = conn_state->phy;
94 
95 	if (!phy || !phy->funcs || !phy->funcs->set_pll) {
96 		printf("%s: failed to find phy set_pll funcs\n", __func__);
97 		return -ENODEV;
98 	}
99 
100 	return phy->funcs->set_pll(state, rate);
101 }
102