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