Skip to contentSkip to conversation

Enable rk3066 VOP and HDMI for MK808

PATCH Superseded Johan Jonker 2 participants 8 messages Mar 2, 2019 – Mar 12, 2019

Subsystems (5)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v3 cover Enable rk3066 VOP and HDMI for MK808

Version: V3

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
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 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

 .../bindings/display/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             | 911 +++++++++++++++++++++
 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, 1302 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/display/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 v3 1/4 drm: rockchip: introduce rk3066 hdmi

From: Zheng Yang <[email protected]>

Introduce rk3066 hdmi.

---
 drivers/gpu/drm/rockchip/Kconfig            |   8 +
 drivers/gpu/drm/rockchip/Makefile           |   1 +
 drivers/gpu/drm/rockchip/rk3066_hdmi.c      | 911 ++++++++++++++++++++++++++++
 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, 1149 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 +911 -0

911 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 v3 1/4] drm: rockchip: introduce rk3066 hdmi

Hi Johan.

Thanks for this nive driver.
A few review comments follows.

Sam

Quoted 3 lines · Johan Jonker

From: Zheng Yang <[email protected]>

Introduce rk3066 hdmi.

A little more info would be good here.
Do not assume all reader knows as much as you do.

Quoted 13 lines

---

drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +3 -0
new file mode 100644
index 000000000..3c5b702dc
@@ -0,0 +1,911 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) Fuzhou Rockchip Electronics Co.Ltd

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

Quoted 10 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +10 -0
+ *    Zheng Yang <[email protected]>
+ */
+
+#include <linux/clk.h>
+#include <linux/mfd/syscon.h>
+#include <linux/regmap.h>
+
+#include <drm/drm_of.h>
+#include <drm/drmP.h>
+#include <drm/drm_probe_helper.h>

Please do not use drmP.h in new files. The usage of drmP.h is deprecated. Also please sort the include files, but keep the nice grouping.

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

Quoted 10 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +10 -0
+
+#include "rockchip_drm_drv.h"
+#include "rockchip_drm_vop.h"
+
+#include "rk3066_hdmi.h"
+
+#define DEFAULT_PLLA_RATE 30000000
+
+struct hdmi_data_info {
+	int vic;

vic is used so much. It deserves an explanation.

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

Quoted 2 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +2 -0
+	bool sink_is_hdmi;
+	unsigned int enc_in_format;

enc_in_format is in this patch only assinged.
aybe drop it (if not used in later patches)

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

Quoted 9 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +9 -0
+	unsigned int enc_out_format;
+	unsigned int colorimetry;
+};
+
+struct rk3066_hdmi_i2c {
+	struct i2c_adapter adap;
+
+	u8 ddc_addr;
+	u8 segment_addr;

The two members above are only used in rk3066_hdmi_i2c_write() Maybe they can be made local variables?

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

Quoted 3 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +3 -0
+	u8 stat;
+
+	struct mutex lock; /*for i2c operation*/

Name the lock after what is protects, to avoid mis-use.

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

Quoted 1 line
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +1 -0
+	struct completion cmp;

cmp is shorthand for "compare" - as we have a command named so. Find a better name.

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

Quoted 5 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +5 -0
+};
+
+struct rk3066_hdmi {
+	struct device *dev;
+	struct drm_device *drm_dev;

The new way to do this is to embed the device.
See latest patches by Noralf in drm-misc-next, which include a nice example.

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

Quoted 1 line
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +1 -0
+	struct regmap *regmap;

+1 for using regmap.
But then there is still several readl_relaxed() writel_relaxed() calls? They are in hdmi_readb() and hdmi_writeb(). Should a regmap had been used here too?

Quoted 171 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +171 -0
+	int irq;
+	struct clk *hclk;
+	void __iomem *regs;
+
+	struct drm_connector connector;
+	struct drm_encoder encoder;
+
+	struct rk3066_hdmi_i2c *i2c;
+	struct i2c_adapter *ddc;
+
+	unsigned int tmdsclk;
+
+	struct hdmi_data_info hdmi_data;
+	struct drm_display_mode previous_mode;
+};
+
+#define to_rk3066_hdmi(x) container_of(x, struct rk3066_hdmi, x)
+
+static inline u8 hdmi_readb(struct rk3066_hdmi *hdmi, u16 offset)
+{
+	return readl_relaxed(hdmi->regs + offset);
+}
+
+static inline void hdmi_writeb(struct rk3066_hdmi *hdmi, u16 offset, u32 val)
+{
+	writel_relaxed(val, hdmi->regs + offset);
+}
+
+static inline void hdmi_modb(struct rk3066_hdmi *hdmi, u16 offset,
+			     u32 msk, u32 val)
+{
+	u8 temp = hdmi_readb(hdmi, offset) & ~msk;
+
+	temp |= val & msk;
+	hdmi_writeb(hdmi, offset, temp);
+}
+
+static void rk3066_hdmi_i2c_init(struct rk3066_hdmi *hdmi)
+{
+	int ddc_bus_freq;
+
+	ddc_bus_freq = (hdmi->tmdsclk >> 2) / HDMI_SCL_RATE;
+
+	hdmi_writeb(hdmi, HDMI_DDC_BUS_FREQ_L, ddc_bus_freq & 0xFF);
+	hdmi_writeb(hdmi, HDMI_DDC_BUS_FREQ_H, (ddc_bus_freq >> 8) & 0xFF);
+
+	/* Clear the EDID interrupt flag and mute the interrupt */
+	hdmi_modb(hdmi, HDMI_INTR_MASK1, HDMI_INTR_EDID_MASK, 0);
+	hdmi_writeb(hdmi, HDMI_INTR_STATUS1, HDMI_INTR_EDID_MASK);
+}
+
+static inline u8 rk3066_hdmi_get_power_mode(struct rk3066_hdmi *hdmi)
+{
+	return hdmi_readb(hdmi, HDMI_SYS_CTRL) & HDMI_SYS_POWER_MODE_MASK;
+}
+
+static void rk3066_hdmi_set_power_mode(struct rk3066_hdmi *hdmi, int mode)
+{
+	u8 current_mode, next_mode;
+	u8 i = 0;
+
+	current_mode = rk3066_hdmi_get_power_mode(hdmi);
+
+	dev_dbg(hdmi->dev, "mode         :%d\n", mode);
+	dev_dbg(hdmi->dev, "current_mode :%d\n", current_mode);
+
+	if (current_mode == mode)
+		return;
+
+	do {
+		if (current_mode > mode)
+			next_mode = current_mode / 2;
+		else {
+			if (current_mode < HDMI_SYS_POWER_MODE_A)
+				next_mode = HDMI_SYS_POWER_MODE_A;
+			else
+				next_mode = current_mode * 2;
+		}
+
+		dev_dbg(hdmi->dev, "%d: next_mode :%d\n", i, next_mode);
+
+		if (next_mode != HDMI_SYS_POWER_MODE_D) {
+			hdmi_modb(hdmi, HDMI_SYS_CTRL,
+				  HDMI_SYS_POWER_MODE_MASK, next_mode);
+		} else {
+			hdmi_writeb(hdmi, HDMI_SYS_CTRL,
+				    HDMI_SYS_POWER_MODE_D |
+				    HDMI_SYS_PLL_RESET_MASK);
+			usleep_range(90, 100);
+			hdmi_writeb(hdmi, HDMI_SYS_CTRL,
+				    HDMI_SYS_POWER_MODE_D |
+				    HDMI_SYS_PLLB_RESET);
+			usleep_range(90, 100);
+			hdmi_writeb(hdmi, HDMI_SYS_CTRL,
+				    HDMI_SYS_POWER_MODE_D);
+		}
+		current_mode = next_mode;
+		i = i + 1;
+	} while ((next_mode != mode) && (i < 5));
+
+	/*
+	 * When IP controller haven't configured to an accurate video
+	 * timing, DDC_CLK is equal to PLLA freq which is 30MHz,so we
+	 * need to init the TMDS rate to PCLK rate, and reconfigure
+	 * the DDC clock.
+	 */
+	if (mode < HDMI_SYS_POWER_MODE_D)
+		hdmi->tmdsclk = DEFAULT_PLLA_RATE;
+}
+
+static int
+rk3066_hdmi_upload_frame(struct rk3066_hdmi *hdmi, int setup_rc,
+			 union hdmi_infoframe *frame, u32 frame_index,
+			 u32 mask, u32 disable, u32 enable)
+{
+	if (mask)
+		hdmi_modb(hdmi, HDMI_CP_AUTO_SEND_CTRL, mask, disable);
+
+	hdmi_writeb(hdmi, HDMI_CP_BUF_INDEX, frame_index);
+
+	if (setup_rc >= 0) {
+		u8 packed_frame[HDMI_MAXIMUM_INFO_FRAME_SIZE];
+		ssize_t rc, i;
+
+		rc = hdmi_infoframe_pack(frame, packed_frame,
+					 sizeof(packed_frame));
+		if (rc < 0)
+			return rc;
+
+		for (i = 0; i < rc; i++)
+			hdmi_writeb(hdmi, HDMI_CP_BUF_ACC_HB0 + i * 4,
+				    packed_frame[i]);
+
+		if (mask)
+			hdmi_modb(hdmi, HDMI_CP_AUTO_SEND_CTRL, mask, enable);
+	}
+
+	return setup_rc;
+}
+
+static int rk3066_hdmi_config_avi(struct rk3066_hdmi *hdmi,
+				  struct drm_display_mode *mode)
+{
+	union hdmi_infoframe frame;
+	int rc;
+
+	rc = drm_hdmi_avi_infoframe_from_display_mode(&frame.avi,
+						      &hdmi->connector, mode);
+
+	if (hdmi->hdmi_data.enc_out_format == HDMI_COLORSPACE_YUV444)
+		frame.avi.colorspace = HDMI_COLORSPACE_YUV444;
+	else if (hdmi->hdmi_data.enc_out_format == HDMI_COLORSPACE_YUV422)
+		frame.avi.colorspace = HDMI_COLORSPACE_YUV422;
+	else
+		frame.avi.colorspace = HDMI_COLORSPACE_RGB;
+
+	frame.avi.colorimetry = hdmi->hdmi_data.colorimetry;
+	frame.avi.scan_mode = HDMI_SCAN_MODE_NONE;
+
+	return rk3066_hdmi_upload_frame(hdmi, rc, &frame,
+					HDMI_INFOFRAME_AVI, 0, 0, 0);
+}
+
+static int rk3066_hdmi_config_video_timing(struct rk3066_hdmi *hdmi,
+					   struct drm_display_mode *mode)
+{
+	int value, vsync_offset;
+
+	/* Set detail external video timing polarity and interlace mode */
+	value = HDMI_EXT_VIDEO_SET_EN;
+	value |= mode->flags & DRM_MODE_FLAG_PHSYNC ?

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

Quoted 10 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +10 -0
+		 HDMI_VIDEO_HSYNC_ACTIVE_HIGH : HDMI_VIDEO_HSYNC_ACTIVE_LOW;
+	value |= mode->flags & DRM_MODE_FLAG_PVSYNC ?
+		 HDMI_VIDEO_VSYNC_ACTIVE_HIGH : HDMI_VIDEO_VSYNC_ACTIVE_LOW;
+	value |= mode->flags & DRM_MODE_FLAG_INTERLACE ?
+		 HDMI_VIDEO_MODE_INTERLACE : HDMI_VIDEO_MODE_PROGRESSIVE;
+	if (hdmi->hdmi_data.vic == 2 || hdmi->hdmi_data.vic == 3)
+		vsync_offset = 6;
+	else
+		vsync_offset = 0;
+	value |= vsync_offset << 4; 

Replace 4 with HDMI_VIDEO_VSYNC_OFFSET_SHIFT??

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

Quoted 2 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +2 -0
+	hdmi_writeb(hdmi, HDMI_EXT_VIDEO_PARA, value);
+

+

Quoted 34 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +34 -0
+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(hdmi->dev, "hclk");
+	if (IS_ERR(hdmi->hclk)) {
+		dev_err(hdmi->dev, "unable to get HDMI hclk clock\n");
+		return PTR_ERR(hdmi->hclk);
+	}

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

Quoted 10 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +10 -0
+
+	ret = clk_prepare_enable(hdmi->hclk);
+	if (ret) {
+		dev_err(hdmi->dev, "cannot enable HDMI hclk clock: %d\n", ret);
+		return ret;
+	}
+
+	hdmi->regmap =
+		syscon_regmap_lookup_by_phandle(hdmi->dev->of_node,
+						"rockchip,grf");

dev->of_node would be fine here. No reason to go via hdmi->

Quoted 44 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +44 -0
+	if (IS_ERR(hdmi->regmap)) {
+		dev_err(hdmi->dev, "unable to get rockchip,grf\n");
+		ret = PTR_ERR(hdmi->regmap);
+		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);
+	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;
+
+	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(hdmi->dev,
+			"failed to request hdmi irq: %d\n", ret);
+		goto err_disable_hclk;
+	}
+
+	return 0;
+
+err_disable_hclk:
+	clk_disable_unprepare(hdmi->hclk);
+

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

Quoted 10 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +10 -0
+	return ret;
+}
+
+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);

I think the destroy() function should not be called directly.

Quoted 15 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +15 -0
+
+	clk_disable_unprepare(hdmi->hclk);
+	i2c_put_adapter(hdmi->ddc);
+}
+
+static const struct component_ops rk3066_hdmi_ops = {
+	.bind	= rk3066_hdmi_bind,
+	.unbind	= rk3066_hdmi_unbind,
+};
+
+static int rk3066_hdmi_probe(struct platform_device *pdev)
+{
+	return component_add(&pdev->dev, &rk3066_hdmi_ops);
+}
+

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

Quoted 10 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +10 -0
+static int rk3066_hdmi_remove(struct platform_device *pdev)
+{
+	component_del(&pdev->dev, &rk3066_hdmi_ops);
+
+	return 0;
+}
+
+static const struct of_device_id rk3066_hdmi_dt_ids[] = {
+	{ .compatible = "rockchip,rk3066-hdmi",
+	},

MAke this a one-liner.

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

Quoted 1 line
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +1 -0
+	{},

Us { /* sentinal */ }, like most other drivers.

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

Quoted 2 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +2 -0
+	.driver = {
+		.name = "rockchip-rk3066hdmi",

Different naming are used for the driver in this file. Coniser using a macro to align the naming.

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

Quoted 3 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +3 -0
+		.of_match_table = rk3066_hdmi_dt_ids,
+	},
+};

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

#3 lore raw

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

Thanks for the useful review comments.

With regard to the bugs something between rc1 and rc8 results in a freeze on poweroff. Power domain doesn't seem to turn off the vop and hdmi in rc8.
For testing only.

Forgot to ask rob+dt the prefered document name for "rockchip,rk3066-hdmi" Please advise if this is OK? "rockchip_rk3066-hdmi.txt"

On 3/3/19 9:23 PM, Sam Ravnborg wrote:> Hi Johan.

Quoted 4 lines

Thanks for this nive driver.
A few review comments follows.

Quoted 8 lines

Sam

Quoted 3 lines · Johan Jonker

From: Zheng Yang <[email protected]>

Introduce rk3066 hdmi.

A little more info would be good here.
Do not assume all reader knows as much as you do.

Will add more text in V4.

Quoted 9 lines

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

Quoted 7 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +7 -0
+#include <linux/clk.h>
+#include <linux/mfd/syscon.h>
+#include <linux/regmap.h>
+
+#include <drm/drm_of.h>
+#include <drm/drmP.h>
+#include <drm/drm_probe_helper.h>

Please do not use drmP.h in new files. The usage of drmP.h is deprecated. Also please sort the include files, but keep the nice grouping.

You try to get rid of it and now I add one more to it ... Thank you for letting me know.
The file drmP.h is used for:
to_platform_device, platform_get_resource, platform_get_irq Replaced <drm/drmP.h> by <linux/platform_device.h>

Quoted 2 lines

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

Quoted 1 line
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +1 -0
+	int vic;

vic is used so much. It deserves an explanation.

Is this OK?
int vic; // pointer to the current cea mode in the edid_cea_modes array

hdmi->hdmi_data.vic = drm_match_cea_mode(mode);

Quoted 4 lines

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

Quoted 1 line
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +1 -0
+	unsigned int enc_in_format;

enc_in_format is in this patch only assinged.
aybe drop it (if not used in later patches)

Will drop it. Possible leftover when they reused
the inno-hdmi driver as template?

Quoted 4 lines

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

Quoted 2 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +2 -0
+	u8 ddc_addr;
+	u8 segment_addr;

The two members above are only used in rk3066_hdmi_i2c_write() Maybe they can be made local variables?

ddc_addr and segment_addr only get a value in the condition below and are reused.
Should remain global.

	if (msgs->addr == DDC_SEGMENT_ADDR)
		hdmi->i2c->segment_addr = msgs->buf[0];
	if (msgs->addr == DDC_ADDR)
		hdmi->i2c->ddc_addr = msgs->buf[0];
Quoted 2 lines

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

Quoted 1 line
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +1 -0
+	struct mutex lock; /*for i2c operation*/

Name the lock after what is protects, to avoid mis-use.

Will change the name to i2c_lock.

Quoted 4 lines

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

Quoted 1 line
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +1 -0
+	struct completion cmp;

cmp is shorthand for "compare" - as we have a command named so. Find a better name.

Agree.

Quoted 3 lines

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

Quoted 1 line
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +1 -0
+	struct drm_device *drm_dev;

The new way to do this is to embed the device.
See latest patches by Noralf in drm-misc-next, which include a nice

example.

That sounds more like a job for the Rockchip maintainers and not for a individual. With this driver they have 8 more to go ...

	ADD_ROCKCHIP_SUB_DRIVER(vop_platform_driver, CONFIG_DRM_ROCKCHIP);
	ADD_ROCKCHIP_SUB_DRIVER(rockchip_lvds_driver,
				CONFIG_ROCKCHIP_LVDS);
	ADD_ROCKCHIP_SUB_DRIVER(rockchip_dp_driver,
				CONFIG_ROCKCHIP_ANALOGIX_DP);
	ADD_ROCKCHIP_SUB_DRIVER(cdn_dp_driver, CONFIG_ROCKCHIP_CDN_DP);
	ADD_ROCKCHIP_SUB_DRIVER(dw_hdmi_rockchip_pltfm_driver,
				CONFIG_ROCKCHIP_DW_HDMI);
	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);
Quoted 4 lines

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

Quoted 1 line
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +1 -0
+	struct regmap *regmap;

+1 for using regmap.
But then there is still several readl_relaxed() writel_relaxed() calls? They are in hdmi_readb() and hdmi_writeb(). Should a regmap had been

used here too?

Will rename hdmi->regmap to hdmi->grf_regmap to make it look more different between hdmi devm_ioremap and grf syscon_regmap.

Quoted 2 lines

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

Quoted 1 line
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +1 -0
+	value |= vsync_offset << 4;

Replace 4 with HDMI_VIDEO_VSYNC_OFFSET_SHIFT??

Looks like it. That's something only the author can tell.

Quoted 5 lines

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

Quoted 3 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +3 -0
+	hdmi->regmap =
+		syscon_regmap_lookup_by_phandle(hdmi->dev->of_node,
+						"rockchip,grf");

dev->of_node would be fine here. No reason to go via hdmi->

Will replace the other hdmi->dev in this function by dev as well.

Quoted 3 lines

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

Quoted 2 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +2 -0
+	hdmi->connector.funcs->destroy(&hdmi->connector);
+	hdmi->encoder.funcs->destroy(&hdmi->encoder);

I think the destroy() function should not be called directly.

Don't know what should be used instead. Please advise.

Quoted 7 lines

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

Quoted 3 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +3 -0
+static const struct of_device_id rk3066_hdmi_dt_ids[] = {
+	{ .compatible = "rockchip,rk3066-hdmi",
+	},

MAke this a one-liner.

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

Quoted 1 line
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +1 -0
+	{},

Us { /* sentinal */ }, like most other drivers.

Agree. But I prefere sentinel ...

{ .compatible = "rockchip,rk3066-hdmi"},
{ /* sentinel */ },

Quoted 4 lines

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

Quoted 2 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c new file +2 -0
+	.driver = {
+		.name = "rockchip-rk3066hdmi",

Different naming are used for the driver in this file. Coniser using a macro to align the naming.

"rockchip,rk3066-hdmi" is related to "rockchip,rk3066-vop"

"rockchip-rk3066hdmi" should remain in line with the other debug messages, else it gets a mess if you do a dmesg | grep ...

[    0.576237] rockchip-pm-domain 20004000.pmu:power-controller:
rockchip_pm_domain_probe
[    1.198354] rockchip-vop 1010c000.vop: attaching to power domain 'pd_vio'
[    1.437444] rockchip-drm display-subsystem: bound 10116000.hdmi (ops
0xc0842d38)
[    0.397567] rockchip-rk3066hdmi 10116000.hdmi: registered RK3066 HDMI

I2C bus driver

Not so good example.

[   12.726332] dwmmc_rockchip 10214000.dwmmc: Using external DMA controller.
#4 lore raw

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

Quoted 4 lines · Johan Jonker

With regard to the bugs something between rc1 and rc8 results in a freeze on poweroff. Power domain doesn't seem to turn off the vop and hdmi in 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 fix 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/

#5 lore raw

PATCH v3 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 v3 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 v3 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.

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