xref: /rk3399_rockchip-uboot/drivers/video/drm/rockchip_phy.c (revision 9ac6f4797ca1f9a9c5c1f4bdb8414fefa85f8bd3)
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 <errno.h>
10 #include <malloc.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 static const struct rockchip_phy g_phy[] = {
22 #ifdef CONFIG_ROCKCHIP_DW_MIPI_DSI
23 	{
24 	 .compatible = "rockchip,rk3366-mipi-dphy",
25 	 .funcs = &inno_mipi_dphy_funcs,
26 	},
27 	{
28 	 .compatible = "rockchip,rk3368-mipi-dphy",
29 	 .funcs = &inno_mipi_dphy_funcs,
30 	},
31 #endif
32 };
33 
34 const struct rockchip_phy *rockchip_get_phy(const void *blob, int phy_node)
35 {
36 	const char *name;
37 	int i;
38 
39 	name = fdt_stringlist_get(blob, phy_node, "compatible", 0, NULL);
40 
41 	for (i = 0; i < ARRAY_SIZE(g_phy); i++) {
42 		if (!strcmp(name, g_phy[i].compatible))
43 			break;
44 	}
45 	if (i >= ARRAY_SIZE(g_phy))
46 		return NULL;
47 
48 	return &g_phy[i];
49 }
50 
51 int rockchip_phy_power_on(struct display_state *state)
52 {
53 	struct connector_state *conn_state = &state->conn_state;
54 	const struct rockchip_phy *phy = conn_state->phy;
55 
56 	if (!phy || !phy->funcs || !phy->funcs->power_on) {
57 		printf("%s: failed to find phy power on funcs\n", __func__);
58 		return -ENODEV;
59 	}
60 
61 	return phy->funcs->power_on(state);
62 }
63 
64 int rockchip_phy_power_off(struct display_state *state)
65 {
66 	struct connector_state *conn_state = &state->conn_state;
67 	const struct rockchip_phy *phy = conn_state->phy;
68 
69 	if (!phy || !phy->funcs || !phy->funcs->power_off) {
70 		printf("%s: failed to find phy power_off funcs\n", __func__);
71 		return -ENODEV;
72 	}
73 
74 	return phy->funcs->power_off(state);
75 }
76 
77 unsigned long rockchip_phy_set_pll(struct display_state *state,
78 				   unsigned long rate)
79 {
80 	struct connector_state *conn_state = &state->conn_state;
81 	const struct rockchip_phy *phy = conn_state->phy;
82 
83 	if (!phy || !phy->funcs || !phy->funcs->set_pll) {
84 		printf("%s: failed to find phy set_pll funcs\n", __func__);
85 		return -ENODEV;
86 	}
87 
88 	return phy->funcs->set_pll(state, rate);
89 }
90