Skip to contentSkip to conversation

Enable rk3066 VOP and HDMI for MK808

PATCH Superseded Johan Jonker 3 participants 9 messages Mar 6, 2019 – Mar 28, 2019

Subsystems (5)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v4 cover Enable rk3066 VOP and HDMI for MK808

For testing only.

Version: V4

Title: Enable rk3066 VOP and HDMI for MK808.

This patch serie only works in combination with a MK808 TV stick and a rk3066 processor. Other boxes and tablets with a rk3066 need extra software for power management and lcd's.

What does it do:

With these kernel patches a MK808 can show 2 penguins and a console on a DVI-D monitor in combination with a framebuffer.

Not tested:

HDMI TV
HDCP
DRM
Xorg
Display managers
Android
etc.

Problems:

DRM functions keep changing every rc.
With v5.0-rc8 the monitor doesn't blank on poweroff, it freezes. Fixed screen size for DVI-D.
HDMI sound not included.
etc.

///////////////////////////////////////////
Changes V3 > V4:

rockchip,rk3066-hdmi.txt
change document name

rk3066_hdmi.c
add more info in commit message
replace deprecated drmP.h include
small text style changes
explain vic variable
remove enc_in_format
change lock name
change regmap name
change cmp name
replace hdmi->dev by dev
use sentinel
use HDMI_VIDEO_VSYNC_OFFSET_SHIFT define
remove unused module macros
change driver name for dmesg

///////////////////////////////////////////
Changes V2 > V3:

updated to v5.0-rc8
removed patches that are already added to linux-next

rk3066_hdmi.c
removed gpl text
small style changes
removed unused includes
add include for:
drm_helper_hpd_irq_event drm_helper_probe_single_connector_modes
update drm_hdmi_avi_infoframe_from_display_mode function call

rk3066_hdmi.h
removed gpl text

rk3066a.dtsi
add extra port for hdmi connector node

rk3066a-mk808.dts
add hdmi connector node
connect hdmi_out with hdmi_con_in

rk3066-hdmi.txt
add extra port for hdmi connector node

///////////////////////////////////////////

# How to make rkfs.cpio

find . | cpio -o --format=newc > ../rkfs.cpio

# How to compile/flash

make menuconfig ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- make -j4 ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi-

cp ./arch/arm/boot/zImage ../zImage-dtb
cat ./arch/arm/boot/dts/rk3066a-mk808.dtb >> ../zImage-dtb ../tools/rkcrc -k ../zImage-dtb ../mk808.img
sudo ../tools/rkflashtool w 0x4000 0x8000 < ../mk808.img sudo ../tools/rkflashtool b

///////////////////////////////////////////

Johan Jonker (2):
ARM: dts: rockchip: rk3066a-mk808: enable vop0 and hdmi nodes
dt-bindings: display: rockchip: add document for rk3066 hdmi

Zheng Yang (2):
drm: rockchip: introduce rk3066 hdmi
ARM: dts: rockchip: add rk3066 hdmi nodes

 .../display/rockchip/rockchip,rk3066-hdmi.txt      |  72 ++
 arch/arm/boot/dts/rk3066a-mk808.dts                |  29 +
 arch/arm/boot/dts/rk3066a.dtsi                     |  52 ++
 drivers/gpu/drm/rockchip/Kconfig                   |   8 +
 drivers/gpu/drm/rockchip/Makefile                  |   1 +
 drivers/gpu/drm/rockchip/rk3066_hdmi.c             | 901 +++++++++++++++++++++
 drivers/gpu/drm/rockchip/rk3066_hdmi.h             | 226 ++++++
 drivers/gpu/drm/rockchip/rockchip_drm_drv.c        |   2 +
 drivers/gpu/drm/rockchip/rockchip_drm_drv.h        |   1 +
 9 files changed, 1292 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/display/rockchip/rockchip,rk3066-hdmi.txt
 create mode 100644 drivers/gpu/drm/rockchip/rk3066_hdmi.c
 create mode 100644 drivers/gpu/drm/rockchip/rk3066_hdmi.h
Signature · 1 line
2.11.0
#1 lore raw

PATCH v4 1/4 drm: rockchip: introduce rk3066 hdmi

From: Zheng Yang <[email protected]>

The RK3066 HDMI TX serves as interface between a LCD Controller and a HDMI bus. A HDMI TX consists of one HDMI transmitter controller and one HDMI transmitter PHY. The interface has three (3) 8-bit data channels which can be configured for a number of bus widths (8/10/12/16/20/24-bit) and different video formats (RGB, YCbCr).

Features:
HDMI version 1.4a, HDCP revision 1.4 and
DVI version 1.0 compliant transmitter. Supports DTV resolutions from 480i to 1080i/p HD. Master I2C interface for a DDC connection. HDMI TX supports multiple power save modes. The HDMI TX input can switch between LCDC0 and LCDC1. (Sound support is not included in this patch)

---
 drivers/gpu/drm/rockchip/Kconfig            |   8 +
 drivers/gpu/drm/rockchip/Makefile           |   1 +
 drivers/gpu/drm/rockchip/rk3066_hdmi.c      | 901 ++++++++++++++++++++++++++++
 drivers/gpu/drm/rockchip/rk3066_hdmi.h      | 226 +++++++
 drivers/gpu/drm/rockchip/rockchip_drm_drv.c |   2 +
 drivers/gpu/drm/rockchip/rockchip_drm_drv.h |   1 +
 6 files changed, 1139 insertions(+)
 create mode 100644 drivers/gpu/drm/rockchip/rk3066_hdmi.c
 create mode 100644 drivers/gpu/drm/rockchip/rk3066_hdmi.h
drivers/gpu/drm/rockchip/Kconfig +8 -0
index 1e75196f9..2cdf3b62d 100644
@@ -77,4 +77,12 @@ config ROCKCHIP_RGB
 	  Some Rockchip CRTCs, like rv1108, can directly output parallel
 	  and serial RGB format to panel or connect to a conversion chip.
 	  say Y to enable its driver.
+
+config ROCKCHIP_RK3066_HDMI
+	bool "Rockchip specific extensions for RK3066 HDMI"
+	depends on DRM_ROCKCHIP
+	help
+	  This selects support for Rockchip SoC specific extensions
+	  for the RK3066 HDMI driver. If you want to enable
+	  HDMI on RK3066 based SoC, you should select this option.
 endif
drivers/gpu/drm/rockchip/Makefile +1 -0
index f6fc9d5dd..524684ba7 100644
@@ -15,5 +15,6 @@ rockchipdrm-$(CONFIG_ROCKCHIP_DW_MIPI_DSI) += dw-mipi-dsi-rockchip.o
 rockchipdrm-$(CONFIG_ROCKCHIP_INNO_HDMI) += inno_hdmi.o
 rockchipdrm-$(CONFIG_ROCKCHIP_LVDS) += rockchip_lvds.o
 rockchipdrm-$(CONFIG_ROCKCHIP_RGB) += rockchip_rgb.o
+rockchipdrm-$(CONFIG_ROCKCHIP_RK3066_HDMI) += rk3066_hdmi.o
 
 obj-$(CONFIG_DRM_ROCKCHIP) += rockchipdrm.o
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +901 -0

901 lines not on this page · raw message

drivers/gpu/drm/rockchip/rk3066_hdmi.h new file +226 -0

226 lines not on this page · raw message

drivers/gpu/drm/rockchip/rockchip_drm_drv.c +2 -0
index d7fa17f12..8d7a634c1 100644
@@ -486,6 +486,8 @@ static int __init rockchip_drm_init(void)
 	ADD_ROCKCHIP_SUB_DRIVER(dw_mipi_dsi_rockchip_driver,
 				CONFIG_ROCKCHIP_DW_MIPI_DSI);
 	ADD_ROCKCHIP_SUB_DRIVER(inno_hdmi_driver, CONFIG_ROCKCHIP_INNO_HDMI);
+	ADD_ROCKCHIP_SUB_DRIVER(rk3066_hdmi_driver,
+				CONFIG_ROCKCHIP_RK3066_HDMI);
 
 	ret = platform_register_drivers(rockchip_sub_drivers,
 					num_rockchip_sub_drivers);
drivers/gpu/drm/rockchip/rockchip_drm_drv.h +1 -0
index ce48568ec..e4bc4322b 100644
@@ -73,4 +73,5 @@ extern struct platform_driver inno_hdmi_driver;
 extern struct platform_driver rockchip_dp_driver;
 extern struct platform_driver rockchip_lvds_driver;
 extern struct platform_driver vop_platform_driver;
+extern struct platform_driver rk3066_hdmi_driver;
 #endif /* _ROCKCHIP_DRM_DRV_H_ */
Signature · 1 line
2.11.0
#2 lore raw

Re: [PATCH v4 1/4] drm: rockchip: introduce rk3066 hdmi

Hi,

Would like to add some "Tested-by:" tags.
Is Rockchip or someone with RK3066 hardware able to test this patch with a HDMI TV or DVI monitor and give a report?

Power domain doesn't seem to turn off the vop and hdmi in v5.0-rc8. The bug is due to a patch revert earlier this year.
To shutdown MK808 one can continue to use the patch at the link below until this issue is fixed by them.

drm/rockchip: shutdown drm subsystem on shutdown
https://patchwork.kernel.org/patch/10556151/

[for-4.20] Revert "drm/rockchip: Allow driver to be shutdown on reboot/kexec"
https://patchwork.kernel.org/patch/10714725/

maintainer
#3 lore raw

Re: [PATCH v4 1/4] drm: rockchip: introduce rk3066 hdmi

In reply to Johan Jonker

Hi Johan,

Am Mittwoch, 6. März 2019, 23:41:10 CET schrieb Johan Jonker:

Quoted 17 lines

From: Zheng Yang <[email protected]>

The RK3066 HDMI TX serves as interface between a LCD Controller and a HDMI bus. A HDMI TX consists of one HDMI transmitter controller and one HDMI transmitter PHY. The interface has three (3) 8-bit data channels which can be configured for a number of bus widths (8/10/12/16/20/24-bit) and different video formats (RGB, YCbCr).

Features:
HDMI version 1.4a, HDCP revision 1.4 and
DVI version 1.0 compliant transmitter. Supports DTV resolutions from 480i to 1080i/p HD. Master I2C interface for a DDC connection. HDMI TX supports multiple power save modes. The HDMI TX input can switch between LCDC0 and LCDC1. (Sound support is not included in this patch)

Quoted 2 lines

Looks good in general, but there are some minor things to improve yet, please see below for specifics.

[...]

drivers/gpu/drm/rockchip/rk3066_hdmi.c line 274

Quoted 4 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +4 -0
+static void rk3066_hdmi_config_phy(struct rk3066_hdmi *hdmi)
+{
+	/* TMDS uses the same frequency as dclk. */
+	hdmi_writeb(hdmi, HDMI_DEEP_COLOR_MODE, 0x22);

These magic values below are no fault of yours, but in any case this could use a comment that the semi-public documentation does not describe hdmi-registers at all, so we're stuck with these magic-values for now.

Quoted 35 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +34 -0
+	if (hdmi->tmdsclk > 100000000) {
+		rk3066_hdmi_phy_write(hdmi, 0x158, 0x0E);
+		rk3066_hdmi_phy_write(hdmi, 0x15c, 0x00);
+		rk3066_hdmi_phy_write(hdmi, 0x160, 0x60);
+		rk3066_hdmi_phy_write(hdmi, 0x164, 0x00);
+		rk3066_hdmi_phy_write(hdmi, 0x168, 0xDA);
+		rk3066_hdmi_phy_write(hdmi, 0x16c, 0xA1);
+		rk3066_hdmi_phy_write(hdmi, 0x170, 0x0e);
+		rk3066_hdmi_phy_write(hdmi, 0x174, 0x22);
+		rk3066_hdmi_phy_write(hdmi, 0x178, 0x00);
+	} else if (hdmi->tmdsclk > 50000000) {
+		rk3066_hdmi_phy_write(hdmi, 0x158, 0x06);
+		rk3066_hdmi_phy_write(hdmi, 0x15c, 0x00);
+		rk3066_hdmi_phy_write(hdmi, 0x160, 0x60);
+		rk3066_hdmi_phy_write(hdmi, 0x164, 0x00);
+		rk3066_hdmi_phy_write(hdmi, 0x168, 0xCA);
+		rk3066_hdmi_phy_write(hdmi, 0x16c, 0xA3);
+		rk3066_hdmi_phy_write(hdmi, 0x170, 0x0e);
+		rk3066_hdmi_phy_write(hdmi, 0x174, 0x20);
+		rk3066_hdmi_phy_write(hdmi, 0x178, 0x00);
+	} else {
+		rk3066_hdmi_phy_write(hdmi, 0x158, 0x02);
+		rk3066_hdmi_phy_write(hdmi, 0x15c, 0x00);
+		rk3066_hdmi_phy_write(hdmi, 0x160, 0x60);
+		rk3066_hdmi_phy_write(hdmi, 0x164, 0x00);
+		rk3066_hdmi_phy_write(hdmi, 0x168, 0xC2);
+		rk3066_hdmi_phy_write(hdmi, 0x16c, 0xA2);
+		rk3066_hdmi_phy_write(hdmi, 0x170, 0x0e);
+		rk3066_hdmi_phy_write(hdmi, 0x174, 0x20);
+		rk3066_hdmi_phy_write(hdmi, 0x178, 0x00);
+	}
+}
 
+static void rk3066_hdmi_encoder_enable(struct drm_encoder *encoder)
+{

drivers/gpu/drm/rockchip/rk3066_hdmi.c

Quoted 10 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +10 -0
+	struct rk3066_hdmi *hdmi = to_rk3066_hdmi(encoder);
+	int mux, val;
+
+	mux = drm_of_encoder_active_endpoint_id(hdmi->dev->of_node, encoder);
+	if (mux)
+		val = BIT(30) | BIT(14);
+	else
+		val = BIT(30);
+
+	regmap_write(hdmi->grf, 0x150, val);

Please define constants for both BIT(14) and the 0x150 GRF register, which is GRF_SOC_CON0, so in the header

#define GRF_SOC_CON0 0x150
#define HDMI_VIDEO_SEL BIT(14)

and then do

	if (mux)
		val = (HDMI_VIDEO_SEL << 16) | HDMI_VIDEO_SEL;
	else
		val = HDMI_VIDEO_SEL << 16;

	regmap_write(hdmi->grf, GRF_SOC_CON0, val);
Quoted 6 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +6 -0
+
+	dev_dbg(hdmi->dev, "hdmi encoder enable select: vop%s\n",
+		(mux) ? "1" : "0");
+
+	rk3066_hdmi_setup(hdmi, &hdmi->previous_mode);
+}

drivers/gpu/drm/rockchip/rk3066_hdmi.c line 467

Quoted 10 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +8 -0
+
 
 
+static const struct drm_display_mode edid_cea_modes[] = {
+	/* 4 - 1280x720@60Hz 16:9 */
+	{ DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
+		   1430, 1650, 0, 720, 725, 730, 750, 0,
+		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
+	  .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
+};

please drop that, see below

Quoted 26 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +26 -0
+static int rk3066_hdmi_connector_get_modes(struct drm_connector *connector)
+{
+	struct rk3066_hdmi *hdmi = to_rk3066_hdmi(connector);
+	struct drm_display_mode *mode = NULL;
+	struct edid *edid;
+	int ret = 0;
+
+	if (!hdmi->ddc)
+		return 0;
+
+	hdmi->hdmi_data.sink_is_hdmi = false;
+
+	edid = drm_get_edid(connector, hdmi->ddc);
+	if (edid) {
+		hdmi->hdmi_data.sink_is_hdmi = drm_detect_hdmi_monitor(edid);
+
+		dev_info(hdmi->dev, "monitor type : %s : %dx%d cm\n",
+			(hdmi->hdmi_data.sink_is_hdmi ? "HDMI" : "DVI"),
+			edid->width_cm, edid->height_cm);
+
+		drm_connector_update_edid_property(connector, edid);
+		ret = drm_add_edid_modes(connector, edid);
+		kfree(edid);
+	}
+
+	if ((ret == 0) || (hdmi->hdmi_data.sink_is_hdmi == false)) {

drivers/gpu/drm/rockchip/rk3066_hdmi.c line 504

Quoted 10 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +10 -0
+		hdmi->hdmi_data.sink_is_hdmi = false;
+
+		mode = drm_mode_duplicate(hdmi->drm_dev, &edid_cea_modes[0]);
+		if (!mode)
+			return ret;
+		mode->type |= DRM_MODE_TYPE_PREFERRED;
+		drm_mode_probed_add(connector, mode);
+		ret++;
+
+		dev_info(hdmi->dev, "no CEA mode found, use default\n");

This is a hack from the vendor-kernel.

If EDID reading fails, it is some sort of issue with the driver, so we shouldn't assume any specific mode at all. See the somewhat similar inno_hdmi driver for comparison.

Quoted 17 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +14 -0
+	}
+
+	return ret;
+}
+
 
 
 
+static int
+rk3066_hdmi_register(struct drm_device *drm, struct rk3066_hdmi *hdmi)
+{
+	struct drm_encoder *encoder = &hdmi->encoder;
+	struct device *dev = hdmi->dev;
+
+	encoder->possible_crtcs =
+		drm_of_find_possible_crtcs(drm, dev->of_node);
+

drivers/gpu/drm/rockchip/rk3066_hdmi.c line 577

Quoted 10 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +10 -0
+	/*
+	 * If we failed to find the VOP(s) which this encoder is
+	 * supposed to be connected to, it's because the VOP has
+	 * not been registered yet.  Defer probing, and hope that
+	 * the required VOP is added later.
+	 */
+	if (encoder->possible_crtcs == 0)
+		return -EPROBE_DEFER;
+
+	dev_info(hdmi->dev, "VOP found\n");

unnecessary output which will clutter up the kernel log, please drop.

Quoted 37 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +37 -0
+
+	drm_encoder_helper_add(encoder, &rk3066_hdmi_encoder_helper_funcs);
+	drm_encoder_init(drm, encoder, &rk3066_hdmi_encoder_funcs,
+			 DRM_MODE_ENCODER_TMDS, NULL);
+
+	hdmi->connector.polled = DRM_CONNECTOR_POLL_HPD;
+
+	drm_connector_helper_add(&hdmi->connector,
+				 &rk3066_hdmi_connector_helper_funcs);
+	drm_connector_init(drm, &hdmi->connector,
+			   &rk3066_hdmi_connector_funcs,
+			   DRM_MODE_CONNECTOR_HDMIA);
+
+	drm_connector_attach_encoder(&hdmi->connector, encoder);
+
+	return 0;
+}
+
+static irqreturn_t rk3066_hdmi_i2c_irq(struct rk3066_hdmi *hdmi, u8 stat)
+{
+	struct rk3066_hdmi_i2c *i2c = hdmi->i2c;
+
+	if (!(stat & HDMI_INTR_EDID_MASK))
+		return IRQ_NONE;
+
+	i2c->stat = stat;
+
+	complete(&i2c->compl);
+
+	return IRQ_HANDLED;
+}
+
+static irqreturn_t rk3066_hdmi_hardirq(int irq, void *dev_id)
+{
+	struct rk3066_hdmi *hdmi = dev_id;
+	irqreturn_t ret = IRQ_NONE;
+	u8 interrupt;

drivers/gpu/drm/rockchip/rk3066_hdmi.c line 624

Quoted 10 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +10 -0
+
+	if (rk3066_hdmi_get_power_mode(hdmi) == HDMI_SYS_POWER_MODE_A)
+		hdmi_writeb(hdmi, HDMI_SYS_CTRL, HDMI_SYS_POWER_MODE_B);
+
+	interrupt = hdmi_readb(hdmi, HDMI_INTR_STATUS1);
+	if (interrupt)
+		hdmi_writeb(hdmi, HDMI_INTR_STATUS1, interrupt);
+
+	if (hdmi->i2c)
+		ret = rk3066_hdmi_i2c_irq(hdmi, interrupt);

I think you don't really need that rk3066_hdmi_i2c_irq function above, this can just become

	if (interrupt & HDMI_INTR_EDID_MASK) {
		hdmi->i2c->stat = stat;
		complete(&hdmi->i2c->compl);
	}

hdmi->i2c is set through rk3066_hdmi_i2c_adapter() which is always called and needs to be sucessful before registering the interrupt, so there is no need to check for hdmi->i2c here at all.

Quoted 34 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +29 -0
+
+	if (interrupt & (HDMI_INTR_HOTPLUG | HDMI_INTR_MSENS))
+		ret = IRQ_WAKE_THREAD;
+
+	return ret;
+}
+
 
 
 
 
 
+static struct i2c_adapter *rk3066_hdmi_i2c_adapter(struct rk3066_hdmi *hdmi)
+{
+	struct i2c_adapter *adap;
+	struct rk3066_hdmi_i2c *i2c;
+	int ret;
+
+	i2c = devm_kzalloc(hdmi->dev, sizeof(*i2c), GFP_KERNEL);
+	if (!i2c)
+		return ERR_PTR(-ENOMEM);
+
+	mutex_init(&i2c->i2c_lock);
+	init_completion(&i2c->compl);
+
+	adap = &i2c->adap;
+	adap->class = I2C_CLASS_DDC;
+	adap->owner = THIS_MODULE;
+	adap->dev.parent = hdmi->dev;
+	adap->dev.of_node = hdmi->dev->of_node;
+	adap->algo = &rk3066_hdmi_algorithm;
+	strlcpy(adap->name, "RK3066 HDMI", sizeof(adap->name));
+	i2c_set_adapdata(adap, hdmi);
+

drivers/gpu/drm/rockchip/rk3066_hdmi.c line 765

Quoted 10 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +10 -0
+	ret = i2c_add_adapter(adap);
+	if (ret) {
+		dev_warn(hdmi->dev, "cannot add %s I2C adapter\n", adap->name);
+		devm_kfree(hdmi->dev, i2c);
+		return ERR_PTR(ret);
+	}
+
+	hdmi->i2c = i2c;
+
+	dev_info(hdmi->dev, "registered %s I2C bus driver\n", adap->name);

Please drop or make it a DRM_DEV_DEBUG. Also, please convert all the general dev_foobar calls to their DRM_* equivalents, so dev_warn becomes DRM_DEV_ERROR, dev_info DRM_DEV_INFO and so on.

Quoted 63 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +63 -0
+	return adap;
+}
+
+static int rk3066_hdmi_bind(struct device *dev, struct device *master,
+			    void *data)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct drm_device *drm = data;
+	struct rk3066_hdmi *hdmi;
+	struct resource *iores;
+	int irq;
+	int ret;
+
+	hdmi = devm_kzalloc(dev, sizeof(*hdmi), GFP_KERNEL);
+	if (!hdmi)
+		return -ENOMEM;
+
+	hdmi->dev = dev;
+	hdmi->drm_dev = drm;
+
+	iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!iores)
+		return -ENXIO;
+
+	hdmi->regs = devm_ioremap_resource(dev, iores);
+	if (IS_ERR(hdmi->regs))
+		return PTR_ERR(hdmi->regs);
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0)
+		return irq;
+
+	hdmi->hclk = devm_clk_get(dev, "hclk");
+	if (IS_ERR(hdmi->hclk)) {
+		dev_err(dev, "unable to get HDMI hclk clock\n");
+		return PTR_ERR(hdmi->hclk);
+	}
+
+	ret = clk_prepare_enable(hdmi->hclk);
+	if (ret) {
+		dev_err(dev, "cannot enable HDMI hclk clock: %d\n", ret);
+		return ret;
+	}
+
+	hdmi->grf = syscon_regmap_lookup_by_phandle(dev->of_node,
+						    "rockchip,grf");
+	if (IS_ERR(hdmi->grf)) {
+		dev_err(dev, "unable to get rockchip,grf\n");
+		ret = PTR_ERR(hdmi->grf);
+		goto err_disable_hclk;
+	}
+
+	/* internal hclk = hdmi_hclk / 25 */
+	hdmi_writeb(hdmi, HDMI_INTERNAL_CLK_DIVIDER, 25);
+
+	hdmi->ddc = rk3066_hdmi_i2c_adapter(hdmi);
+	if (IS_ERR(hdmi->ddc)) {
+		ret = PTR_ERR(hdmi->ddc);
+		hdmi->ddc = NULL;
+		goto err_disable_hclk;
+	}
+
+	rk3066_hdmi_set_power_mode(hdmi, HDMI_SYS_POWER_MODE_B);

drivers/gpu/drm/rockchip/rk3066_hdmi.c line 839

Quoted 10 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +10 -0
+	usleep_range(999, 1000);
+	hdmi_writeb(hdmi, HDMI_INTR_MASK1, HDMI_INTR_HOTPLUG);
+	hdmi_writeb(hdmi, HDMI_INTR_MASK2, 0);
+	hdmi_writeb(hdmi, HDMI_INTR_MASK3, 0);
+	hdmi_writeb(hdmi, HDMI_INTR_MASK4, 0);
+	rk3066_hdmi_set_power_mode(hdmi, HDMI_SYS_POWER_MODE_A);
+
+	ret = rk3066_hdmi_register(drm, hdmi);
+	if (ret)
+		goto err_disable_hclk;

goto err_disable_i2c;

So that the i2c-adapter also gets disabled on error.

drivers/gpu/drm/rockchip/rk3066_hdmi.c line 848

Quoted 8 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +8 -0
+	dev_set_drvdata(dev, hdmi);
+
+	ret = devm_request_threaded_irq(dev, irq, rk3066_hdmi_hardirq,
+					rk3066_hdmi_irq, IRQF_SHARED,
+					dev_name(dev), hdmi);
+	if (ret) {
+		dev_err(dev, "failed to request hdmi irq: %d\n", ret);
+		goto err_disable_hclk;

goto err_disable_i2c;

drivers/gpu/drm/rockchip/rk3066_hdmi.c line 259

Quoted 4 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +4 -0
+	}
+
+	return 0;
+

err_disable_i2c:

	i2c_put_adapter(hdmi->ddc);
Quoted 6 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +6 -0
+err_disable_hclk:
+	clk_disable_unprepare(hdmi->hclk);
+
+	return ret;
+}
+

drivers/gpu/drm/rockchip/rk3066_hdmi.c line 868

Quoted 10 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +10 -0
+static void rk3066_hdmi_unbind(struct device *dev, struct device *master,
+			       void *data)
+{
+	struct rk3066_hdmi *hdmi = dev_get_drvdata(dev);
+
+	hdmi->connector.funcs->destroy(&hdmi->connector);
+	hdmi->encoder.funcs->destroy(&hdmi->encoder);
+
+	clk_disable_unprepare(hdmi->hclk);
+	i2c_put_adapter(hdmi->ddc);

you should probably invert the calling order here, first remove the i2c adapter and only then disable the clock.

Thanks
Heiko

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#4 lore raw

Re: [PATCH v4 1/4] drm: rockchip: introduce rk3066 hdmi

Hi,

Question for Heiko cs. See below.
Let me know if there's a need for V6?

Quoted 8 lines · Heiko Stübner

Am Mittwoch, 6. März 2019, 23:41:10 CET schrieb Johan Jonker:

drivers/gpu/drm/rockchip/rk3066_hdmi.c line 475

Quoted 6 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +6 -0
+static int rk3066_hdmi_connector_get_modes(struct drm_connector *connector)
+{
+	struct rk3066_hdmi *hdmi = to_rk3066_hdmi(connector);
+	struct edid *edid;
+	int ret = 0;
+

Is this OK or drop it?

	hdmi->hdmi_data.sink_is_hdmi = false;
Quoted 77 lines
Quoted 77 lines
(quoted diff) +73 -0
+	if (!hdmi->ddc)
+		return 0;
+
+	edid = drm_get_edid(connector, hdmi->ddc);
+	if (edid) {
+		hdmi->hdmi_data.sink_is_hdmi = drm_detect_hdmi_monitor(edid);
+		drm_connector_update_edid_property(connector, edid);
+		ret = drm_add_edid_modes(connector, edid);
+		kfree(edid);
+	}
+
 
+
+	return ret;
+}
 
 
 
+static int rk3066_hdmi_bind(struct device *dev, struct device *master,
+			    void *data)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct drm_device *drm = data;
+	struct rk3066_hdmi *hdmi;
+	struct resource *iores;
+	int irq;
+	int ret;
+
+	hdmi = devm_kzalloc(dev, sizeof(*hdmi), GFP_KERNEL);
+	if (!hdmi)
+		return -ENOMEM;
+
+	hdmi->dev = dev;
+	hdmi->drm_dev = drm;
+
+	iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!iores)
+		return -ENXIO;
+
+	hdmi->regs = devm_ioremap_resource(dev, iores);
+	if (IS_ERR(hdmi->regs))
+		return PTR_ERR(hdmi->regs);
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0)
+		return irq;
+
+	hdmi->hclk = devm_clk_get(dev, "hclk");
+	if (IS_ERR(hdmi->hclk)) {
+		dev_err(dev, "unable to get HDMI hclk clock\n");
+		return PTR_ERR(hdmi->hclk);
+	}
+
+	ret = clk_prepare_enable(hdmi->hclk);
+	if (ret) {
+		dev_err(dev, "cannot enable HDMI hclk clock: %d\n", ret);
+		return ret;
+	}
+
+	hdmi->grf = syscon_regmap_lookup_by_phandle(dev->of_node,
+						    "rockchip,grf");
+	if (IS_ERR(hdmi->grf)) {
+		dev_err(dev, "unable to get rockchip,grf\n");
+		ret = PTR_ERR(hdmi->grf);
+		goto err_disable_hclk;
+	}
+
+	/* internal hclk = hdmi_hclk / 25 */
+	hdmi_writeb(hdmi, HDMI_INTERNAL_CLK_DIVIDER, 25);
+
+	hdmi->ddc = rk3066_hdmi_i2c_adapter(hdmi);
+	if (IS_ERR(hdmi->ddc)) {
+		ret = PTR_ERR(hdmi->ddc);
+		hdmi->ddc = NULL;
+		goto err_disable_hclk;
+	}
+
Quoted 8 lines

drivers/gpu/drm/rockchip/rk3066_hdmi.c line 836

Quoted 8 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +8 -0
+	rk3066_hdmi_set_power_mode(hdmi, HDMI_SYS_POWER_MODE_B);
+	usleep_range(999, 1000);
+	hdmi_writeb(hdmi, HDMI_INTR_MASK1, HDMI_INTR_HOTPLUG);
+	hdmi_writeb(hdmi, HDMI_INTR_MASK2, 0);
+	hdmi_writeb(hdmi, HDMI_INTR_MASK3, 0);
+	hdmi_writeb(hdmi, HDMI_INTR_MASK4, 0);
+	rk3066_hdmi_set_power_mode(hdmi, HDMI_SYS_POWER_MODE_A);
+

The function rk3066_hdmi_register() inits an encoder and connector.

Quoted 8 lines

drivers/gpu/drm/rockchip/rk3066_hdmi.c line 839

Quoted 3 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +3 -0
+	ret = rk3066_hdmi_register(drm, hdmi);
+	if (ret)
+		goto err_disable_hclk;

goto err_disable_i2c;

So that the i2c-adapter also gets disabled on error.

Quoted 9 lines

drivers/gpu/drm/rockchip/rk3066_hdmi.c line 848

Quoted 8 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +8 -0
+	dev_set_drvdata(dev, hdmi);
+
+	ret = devm_request_threaded_irq(dev, irq, rk3066_hdmi_hardirq,
+					rk3066_hdmi_irq, IRQF_SHARED,
+					dev_name(dev), hdmi);
+	if (ret) {
+		dev_err(dev, "failed to request hdmi irq: %d\n", ret);
+		goto err_disable_hclk;

If an error happens here the encoder and connector also have to be removed like in the inno driver. Is that correct? Change this to:

goto err_cleanup_hdmi;

Quoted 7 lines

goto err_disable_i2c;

drivers/gpu/drm/rockchip/rk3066_hdmi.c line 259

Quoted 4 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +4 -0
+	}
+
+	return 0;
+

What goto name would you like to have here?

err_cleanup_hdmi:

	hdmi->connector.funcs->destroy(&hdmi->connector);
	hdmi->encoder.funcs->destroy(&hdmi->encoder);
Quoted 9 lines

err_disable_i2c:

	i2c_put_adapter(hdmi->ddc);

drivers/gpu/drm/rockchip/rk3066_hdmi.c line 858

Quoted 6 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +6 -0
+err_disable_hclk:
+	clk_disable_unprepare(hdmi->hclk);
+
+	return ret;
+}
+

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

#5 lore raw

PATCH v4 2/4 ARM: dts: rockchip: add rk3066 hdmi nodes

In reply to Johan Jonker

From: Zheng Yang <[email protected]>

This patch adds the hdmi nodes to rk3066.

---
 arch/arm/boot/dts/rk3066a.dtsi | 52 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)
arch/arm/boot/dts/rk3066a.dtsi +52 -0
index 653127a37..9c43b985a 100644
@@ -80,6 +80,10 @@
 		vop0_out: port {
 			#address-cells = <1>;
 			#size-cells = <0>;
+			vop0_out_hdmi: endpoint@0 {
+				reg = <0>;
+				remote-endpoint = <&hdmi_in_vop0>;
+			};
 		};
 	};
 
@@ -101,6 +105,44 @@
 		vop1_out: port {
 			#address-cells = <1>;
 			#size-cells = <0>;
+			vop1_out_hdmi: endpoint@0 {
+				reg = <0>;
+				remote-endpoint = <&hdmi_in_vop1>;
+			};
+		};
+	};
+
+	hdmi: hdmi@10116000 {
+		compatible = "rockchip,rk3066-hdmi";
+		reg = <0x10116000 0x2000>;
+		interrupts = <GIC_SPI 64 IRQ_TYPE_LEVEL_HIGH>;
+		clocks = <&cru HCLK_HDMI>;
+		clock-names = "hclk";
+		power-domains = <&power RK3066_PD_VIO>;
+		rockchip,grf = <&grf>;
+		pinctrl-names = "default";
+		pinctrl-0 = <&hdmii2c_xfer>, <&hdmi_hpd>;
+		status = "disabled";
+
+		ports {
+			#address-cells = <1>;
+			#size-cells = <0>;
+			hdmi_in: port@0 {
+				reg = <0>;
+				#address-cells = <1>;
+				#size-cells = <0>;
+				hdmi_in_vop0: endpoint@0 {
+					reg = <0>;
+					remote-endpoint = <&vop0_out_hdmi>;
+				};
+				hdmi_in_vop1: endpoint@1 {
+					reg = <1>;
+					remote-endpoint = <&vop1_out_hdmi>;
+				};
+			};
+			hdmi_out: port@1 {
+				reg = <1>;
+			};
 		};
 	};
 
@@ -415,6 +457,16 @@
 			};
 		};
 
+		hdmi {
+			hdmi_hpd: hdmi-hpd {
+				rockchip,pins = <0 RK_PA0 1 &pcfg_pull_default>;
+			};
+			hdmii2c_xfer: hdmii2c-xfer {
+				rockchip,pins = <0 RK_PA1 1 &pcfg_pull_none>,
+						<0 RK_PA2 1 &pcfg_pull_none>;
+			};
+		};
+
 		pwm0 {
 			pwm0_out: pwm0-out {
 				rockchip,pins = <RK_GPIO0 3 RK_FUNC_1 &pcfg_pull_none>;
Signature · 1 line
2.11.0
#6 lore raw

PATCH v4 3/4 ARM: dts: rockchip: rk3066a-mk808: enable vop0 and hdmi nodes

In reply to Johan Jonker

This patch enables the vop0 and hdmi nodes
for a MK808 with rk3066 processor.

---
 arch/arm/boot/dts/rk3066a-mk808.dts | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
arch/arm/boot/dts/rk3066a-mk808.dts +29 -0
index 9d2216d71..8bc259d3e 100644
@@ -30,6 +30,17 @@
 		};
 	};
 
+	hdmi_con {
+		compatible = "hdmi-connector";
+		type = "c";
+
+		port {
+			hdmi_con_in: endpoint {
+				remote-endpoint = <&hdmi_out_con>;
+			};
+		};
+	};
+
 	vcc_io: vcc-io {
 		compatible = "regulator-fixed";
 		regulator-name = "vcc_io";
@@ -91,6 +102,20 @@
 	};
 };
 
+&hdmi {
+	status = "okay";
+};
+
+&hdmi_in_vop1 {
+	status = "disabled";
+};
+
+&hdmi_out {
+	hdmi_out_con: endpoint {
+		remote-endpoint = <&hdmi_con_in>;
+	};
+};
+
 &mmc0 {
 	bus-width = <4>;
 	cap-mmc-highspeed;
@@ -150,6 +175,10 @@
 	status = "okay";
 };
 
+&vop0 {
+	status = "okay";
+};
+
 &wdt {
 	status = "okay";
 };
Signature · 1 line
2.11.0
#7 lore raw

PATCH v4 4/4 dt-bindings: display: rockchip: add document for rk3066 hdmi

In reply to Johan Jonker

This patch adds a binding that describes the HDMI controller for rk3066.

---
 .../display/rockchip/rockchip,rk3066-hdmi.txt      | 72 ++++++++++++++++++++++
 1 file changed, 72 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/display/rockchip/rockchip,rk3066-hdmi.txt
Documentation/devicetree/bindings/display/rockchip/rockchip,rk3066-hdmi.txt new file +72 -0
new file mode 100644
index 000000000..d1ad31bca
@@ -0,0 +1,72 @@
+Rockchip specific extensions for rk3066 HDMI
+============================================
+
+Required properties:
+- compatible:
+	"rockchip,rk3066-hdmi";
+- reg:
+	Physical base address and length of the controller's registers.
+- clocks, clock-names:
+	Phandle to HDMI controller clock, name should be "hclk".
+- interrupts:
+	HDMI interrupt number.
+- power-domains:
+	Phandle to the RK3066_PD_VIO power domain.
+- rockchip,grf:
+	This soc uses GRF regs to switch the HDMI TX input between vop0 and vop1.
+- ports:
+	Contains one port node with two endpoints, numbered 0 and 1,
+	connected respectively to vop0 and vop1.
+	Contains one port node with one endpoint
+	connected to a hdmi-connector node.
+- pinctrl-0, pinctrl-name:
+	Switch the iomux for the HPD/I2C pins to HDMI function.
+
+Example:
+	hdmi: hdmi@10116000 {
+		compatible = "rockchip,rk3066-hdmi";
+		reg = <0x10116000 0x2000>;
+		interrupts = <GIC_SPI 64 IRQ_TYPE_LEVEL_HIGH>;
+		clocks = <&cru HCLK_HDMI>;
+		clock-names = "hclk";
+		power-domains = <&power RK3066_PD_VIO>;
+		rockchip,grf = <&grf>;
+		pinctrl-names = "default";
+		pinctrl-0 = <&hdmii2c_xfer>, <&hdmi_hpd>;
+
+		ports {
+			#address-cells = <1>;
+			#size-cells = <0>;
+			hdmi_in: port@0 {
+				reg = <0>;
+				#address-cells = <1>;
+				#size-cells = <0>;
+				hdmi_in_vop0: endpoint@0 {
+					reg = <0>;
+					remote-endpoint = <&vop0_out_hdmi>;
+				};
+				hdmi_in_vop1: endpoint@1 {
+					reg = <1>;
+					remote-endpoint = <&vop1_out_hdmi>;
+				};
+			};
+			hdmi_out: port@1 {
+				reg = <1>;
+				hdmi_out_con: endpoint {
+					remote-endpoint = <&hdmi_con_in>;
+				};
+			};
+		};
+	};
+
+&pinctrl {
+		hdmi {
+			hdmi_hpd: hdmi-hpd {
+				rockchip,pins = <0 RK_PA0 1 &pcfg_pull_default>;
+			};
+			hdmii2c_xfer: hdmii2c-xfer {
+				rockchip,pins = <0 RK_PA1 1 &pcfg_pull_none>,
+						<0 RK_PA2 1 &pcfg_pull_none>;
+			};
+		};
+};
Signature · 1 line
2.11.0
maintainer Reviewed-by on v4 4/4
#8 lore raw

Re: [PATCH v4 4/4] dt-bindings: display: rockchip: add document for rk3066 hdmi

Quoted 9 lines · Johan Jonker

This patch adds a binding that describes the HDMI controller for rk3066.

---
 .../display/rockchip/rockchip,rk3066-hdmi.txt      | 72 ++++++++++++++++++++++
 1 file changed, 72 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/display/rockchip/rockchip,rk3066-hdmi.txt