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