1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (c) 2017 Theobroma Systems Design und Consulting GmbH
4  */
5 
6 #include <common.h>
7 #include <clk.h>
8 #include <display.h>
9 #include <dm.h>
10 #include <dw_hdmi.h>
11 #include <edid.h>
12 #include <regmap.h>
13 #include <syscon.h>
14 #include <asm/gpio.h>
15 #include <asm/io.h>
16 #include <asm/arch/clock.h>
17 #include <asm/arch/hardware.h>
18 #include <asm/arch/grf_rk3399.h>
19 #include <power/regulator.h>
20 #include "rk_hdmi.h"
21 
rk3399_hdmi_enable(struct udevice * dev,int panel_bpp,const struct display_timing * edid)22 static int rk3399_hdmi_enable(struct udevice *dev, int panel_bpp,
23 			      const struct display_timing *edid)
24 {
25 	struct rk_hdmi_priv *priv = dev_get_priv(dev);
26 	struct display_plat *uc_plat = dev_get_uclass_platdata(dev);
27 	int vop_id = uc_plat->source_id;
28 	struct rk3399_grf_regs *grf = priv->grf;
29 
30 	/* select the hdmi encoder input data from our source_id */
31 	rk_clrsetreg(&grf->soc_con20, GRF_RK3399_HDMI_VOP_SEL_MASK,
32 		     (vop_id == 1) ? GRF_RK3399_HDMI_VOP_SEL_L : 0);
33 
34 	return dw_hdmi_enable(&priv->hdmi, edid);
35 }
36 
rk3399_hdmi_ofdata_to_platdata(struct udevice * dev)37 static int rk3399_hdmi_ofdata_to_platdata(struct udevice *dev)
38 {
39 	struct rk_hdmi_priv *priv = dev_get_priv(dev);
40 	struct dw_hdmi *hdmi = &priv->hdmi;
41 
42 	hdmi->i2c_clk_high = 0x7a;
43 	hdmi->i2c_clk_low = 0x8d;
44 
45 	return rk_hdmi_ofdata_to_platdata(dev);
46 }
47 
48 static const char * const rk3399_regulator_names[] = {
49 	"vcc1v8_hdmi",
50 	"vcc0v9_hdmi"
51 };
52 
rk3399_hdmi_probe(struct udevice * dev)53 static int rk3399_hdmi_probe(struct udevice *dev)
54 {
55 	/* Enable regulators required for HDMI */
56 	rk_hdmi_probe_regulators(dev, rk3399_regulator_names,
57 				 ARRAY_SIZE(rk3399_regulator_names));
58 
59 	return rk_hdmi_probe(dev);
60 }
61 
62 static const struct dm_display_ops rk3399_hdmi_ops = {
63 	.read_edid = rk_hdmi_read_edid,
64 	.enable = rk3399_hdmi_enable,
65 };
66 
67 static const struct udevice_id rk3399_hdmi_ids[] = {
68 	{ .compatible = "rockchip,rk3399-dw-hdmi" },
69 	{ }
70 };
71 
72 U_BOOT_DRIVER(rk3399_hdmi_rockchip) = {
73 	.name = "rk3399_hdmi_rockchip",
74 	.id = UCLASS_DISPLAY,
75 	.of_match = rk3399_hdmi_ids,
76 	.ops = &rk3399_hdmi_ops,
77 	.ofdata_to_platdata = rk3399_hdmi_ofdata_to_platdata,
78 	.probe = rk3399_hdmi_probe,
79 	.priv_auto_alloc_size = sizeof(struct rk_hdmi_priv),
80 };
81