Skip to contentSkip to conversation

Add a display driver to the Allwinner H3

RFC PATCH Superseded Jean-Francois Moine 5 participants 18 messages Jan 5, 2016 – Feb 2, 2016

Subsystems (5)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#1 lore raw

RFC PATCH 1/2 clk: sunxi: Add sun8i display support

In reply to Jean-Francois Moine

Add the clock types which are used by the sun8i family for video.

---
 drivers/clk/sunxi/Makefile            |   1 +
 drivers/clk/sunxi/clk-sun8i-display.c | 247 ++++++++++++++++++++++++++++++++++
 2 files changed, 258 insertions(+)
 create mode 100644 drivers/clk/sunxi/clk-sun8i-display.c
drivers/clk/sunxi/Makefile +1 -0
index cb4c299..145c078 100644
@@ -10,6 +10,7 @@ obj-y += clk-a10-pll2.o
 obj-y += clk-a20-gmac.o
 obj-y += clk-mod0.o
 obj-y += clk-simple-gates.o
+obj-y += clk-sun8i-display.o
 obj-y += clk-sun8i-mbus.o
 obj-y += clk-sun9i-core.o
 obj-y += clk-sun9i-mmc.o
drivers/clk/sunxi/clk-sun8i-display.c new file +247 -0

247 lines not on this page · raw message

Signature · 1 line
2.6.4
#8 lore raw

RFC PATCH 2/2 drm: sunxi: Add a basic DRM driver for Allwinner DE2

In reply to Jean-Francois Moine

In recent SoCs, as the H3, Allwinner uses a new display interface, DE2. This patch adds a DRM video driver for this interface,
and also a driver for the HDMI connector found in the H3.

---
 drivers/gpu/drm/Kconfig             |   2 +
 drivers/gpu/drm/Makefile            |   1 +
 drivers/gpu/drm/sunxi/Kconfig       |  21 ++
 drivers/gpu/drm/sunxi/Makefile      |   8 +
 drivers/gpu/drm/sunxi/de2_crtc.c    | 409 ++++++++++++++++++++++++++++++
 drivers/gpu/drm/sunxi/de2_crtc.h    |  42 ++++
 drivers/gpu/drm/sunxi/de2_de.c      | 467 +++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/sunxi/de2_drm.h     |  51 ++++
 drivers/gpu/drm/sunxi/de2_drv.c     | 376 ++++++++++++++++++++++++++++
 drivers/gpu/drm/sunxi/de2_hdmi.c    | 381 ++++++++++++++++++++++++++++
 drivers/gpu/drm/sunxi/de2_hdmi.h    |  34 +++
 drivers/gpu/drm/sunxi/de2_hdmi_h3.c | 478 ++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/sunxi/de2_hdmi_h3.h |  14 ++
 drivers/gpu/drm/sunxi/de2_plane.c   | 102 ++++++++
 14 files changed, 2386 insertions(+)
 create mode 100644 drivers/gpu/drm/sunxi/Kconfig
 create mode 100644 drivers/gpu/drm/sunxi/Makefile
 create mode 100644 drivers/gpu/drm/sunxi/de2_crtc.c
 create mode 100644 drivers/gpu/drm/sunxi/de2_crtc.h
 create mode 100644 drivers/gpu/drm/sunxi/de2_de.c
 create mode 100644 drivers/gpu/drm/sunxi/de2_drm.h
 create mode 100644 drivers/gpu/drm/sunxi/de2_drv.c
 create mode 100644 drivers/gpu/drm/sunxi/de2_hdmi.c
 create mode 100644 drivers/gpu/drm/sunxi/de2_hdmi.h
 create mode 100644 drivers/gpu/drm/sunxi/de2_hdmi_h3.c
 create mode 100644 drivers/gpu/drm/sunxi/de2_hdmi_h3.h
 create mode 100644 drivers/gpu/drm/sunxi/de2_plane.c
drivers/gpu/drm/Kconfig +2 -0
index c4bf9a1..edef0c8 100644
@@ -266,3 +266,5 @@ source "drivers/gpu/drm/amd/amdkfd/Kconfig"
 source "drivers/gpu/drm/imx/Kconfig"
 
 source "drivers/gpu/drm/vc4/Kconfig"
+
+source "drivers/gpu/drm/sunxi/Kconfig"
drivers/gpu/drm/Makefile +1 -0
index 1e9ff4c..597c246 100644
@@ -75,3 +75,4 @@ obj-y			+= i2c/
 obj-y			+= panel/
 obj-y			+= bridge/
 obj-$(CONFIG_DRM_FSL_DCU) += fsl-dcu/
+obj-$(CONFIG_DRM_SUNXI) += sunxi/
drivers/gpu/drm/sunxi/Kconfig new file +21 -0
new file mode 100644
index 0000000..9b4d414
@@ -0,0 +1,21 @@
+#
+# Allwinner Video configuration
+#
+
+config DRM_SUNXI
+	tristate "DRM Support for Allwinner Video"
+	depends on DRM && ARCH_SUNXI
+	depends on OF
+	select DRM_KMS_HELPER
+	select DRM_KMS_CMA_HELPER
+	select DRM_GEM_CMA_HELPER
+	help
+	  Choose this option if you have a Allwinner chipset.
+
+config DRM_SUNXI_DE2
+	tristate "Support for Allwinner Video with DE2 interface"
+	depends on DRM_SUNXI && MACH_SUN8I
+	select REGMAP_MMIO
+	help
+	  Choose this option if your Allwinner chipset has the DE2 interface
+	  as the H3.
drivers/gpu/drm/sunxi/Makefile new file +8 -0
new file mode 100644
index 0000000..8bb533f
@@ -0,0 +1,8 @@
+#
+# Makefile for Allwinner's DRM device driver
+#
+
+sunxi-de2-drm-objs := de2_drv.o de2_de.o de2_crtc.o de2_plane.o
+sunxi-de2-hdmi-objs := de2_hdmi.o de2_hdmi_h3.o
+
+obj-$(CONFIG_DRM_SUNXI_DE2) += sunxi-de2-drm.o sunxi-de2-hdmi.o
drivers/gpu/drm/sunxi/de2_crtc.c new file +409 -0

409 lines not on this page · raw message

drivers/gpu/drm/sunxi/de2_crtc.h new file +42 -0

42 lines not on this page · raw message

drivers/gpu/drm/sunxi/de2_de.c new file +467 -0

467 lines not on this page · raw message

drivers/gpu/drm/sunxi/de2_drm.h new file +51 -0

51 lines not on this page · raw message

drivers/gpu/drm/sunxi/de2_drv.c new file +376 -0

376 lines not on this page · raw message

drivers/gpu/drm/sunxi/de2_hdmi.c new file +381 -0

381 lines not on this page · raw message

drivers/gpu/drm/sunxi/de2_hdmi.h new file +34 -0
new file mode 100644
index 0000000..840a4c8
@@ -0,0 +1,34 @@
+#ifndef __DE2_HDMI_H__
+#define __DE2_HDMI_H__
+/*
+ * Copyright (C) 2015 Jean-Fran??ois Moine
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ */
+
+#include <linux/clk.h>
+#include <linux/reset.h>
+#include <drm/drmP.h>
+
+struct de2_hdmi_priv {
+	struct device *dev;
+	void __iomem *mmio;
+
+	struct drm_encoder encoder;
+	struct drm_connector connector;
+
+	struct clk *clk;
+	struct clk *clk_ddc;
+	struct clk *gate;
+	struct reset_control *rstc0;
+	struct reset_control *rstc1;
+
+	struct mutex mutex;
+	u8 cea_mode;
+	bool is_hdmi_sink;
+	bool is_yuv;
+};
+
+#endif /* __DE2_HDMI_H__ */
drivers/gpu/drm/sunxi/de2_hdmi_h3.c new file +478 -0

478 lines not on this page · raw message

drivers/gpu/drm/sunxi/de2_hdmi_h3.h new file +14 -0
new file mode 100644
index 0000000..59fb6ca
@@ -0,0 +1,14 @@
+#ifndef __DE2_HDMI_H3_H__
+#define __DE2_HDMI_H3_H__
+
+void bsp_hdmi_set_video_en(struct de2_hdmi_priv *priv,
+			unsigned char enable);
+int bsp_hdmi_video(struct de2_hdmi_priv *priv);
+int bsp_hdmi_ddc_read(struct de2_hdmi_priv *priv,
+			char cmd, char pointer, char offset,
+			int nbyte, char *pbuf);
+int bsp_hdmi_get_hpd(struct de2_hdmi_priv *priv);
+void bsp_hdmi_init(struct de2_hdmi_priv *priv);
+void bsp_hdmi_hrst(struct de2_hdmi_priv *priv);
+
+#endif /* __DE2_HDMI_H3_H__ */
drivers/gpu/drm/sunxi/de2_plane.c new file +102 -0

102 lines not on this page · raw message

Signature · 1 line
2.6.4
#0 lore raw

cover Add a display driver to the Allwinner H3

The proposed DRM driver works on a Orange PI 2 with a kernel 4.4-rc1 and the H3 patches found in Hans de Goede's GIT repository.

As there is no documentation about the DE2 nor about the HDMI which are found in the H3, this driver has been built from Allwiiner's sources.

So, there may be license problems, especially for the file de2_hdmi_h3.c which contains a lot of magic values.

The associated DT and documentation will be submitted when the H3 DTs will be in the kernel.

Jean-Francois Moine (2):
clk: sunxi: Add sun8i display support
drm: sunxi: Add a basic DRM driver for Allwinner DE2

 drivers/clk/sunxi/Makefile            |   1 +
 drivers/clk/sunxi/clk-sun8i-display.c | 257 ++++++++++++++++++
 drivers/gpu/drm/Kconfig               |   2 +
 drivers/gpu/drm/Makefile              |   1 +
 drivers/gpu/drm/sunxi/Kconfig         |  21 ++
 drivers/gpu/drm/sunxi/Makefile        |   8 +
 drivers/gpu/drm/sunxi/de2_crtc.c      | 409 +++++++++++++++++++++++++++++
 drivers/gpu/drm/sunxi/de2_crtc.h      |  42 +++
 drivers/gpu/drm/sunxi/de2_de.c        | 467 +++++++++++++++++++++++++++++++++
 drivers/gpu/drm/sunxi/de2_drm.h       |  51 ++++
 drivers/gpu/drm/sunxi/de2_drv.c       | 376 ++++++++++++++++++++++++++
 drivers/gpu/drm/sunxi/de2_hdmi.c      | 381 +++++++++++++++++++++++++++
 drivers/gpu/drm/sunxi/de2_hdmi.h      |  34 +++
 drivers/gpu/drm/sunxi/de2_hdmi_h3.c   | 478 ++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/sunxi/de2_hdmi_h3.h   |  14 +
 drivers/gpu/drm/sunxi/de2_plane.c     | 102 ++++++++
 16 files changed, 2644 insertions(+)
 create mode 100644 drivers/clk/sunxi/clk-sun8i-display.c
 create mode 100644 drivers/gpu/drm/sunxi/Kconfig
 create mode 100644 drivers/gpu/drm/sunxi/Makefile
 create mode 100644 drivers/gpu/drm/sunxi/de2_crtc.c
 create mode 100644 drivers/gpu/drm/sunxi/de2_crtc.h
 create mode 100644 drivers/gpu/drm/sunxi/de2_de.c
 create mode 100644 drivers/gpu/drm/sunxi/de2_drm.h
 create mode 100644 drivers/gpu/drm/sunxi/de2_drv.c
 create mode 100644 drivers/gpu/drm/sunxi/de2_hdmi.c
 create mode 100644 drivers/gpu/drm/sunxi/de2_hdmi.h
 create mode 100644 drivers/gpu/drm/sunxi/de2_hdmi_h3.c
 create mode 100644 drivers/gpu/drm/sunxi/de2_hdmi_h3.h
 create mode 100644 drivers/gpu/drm/sunxi/de2_plane.c
Signature · 1 line
2.6.4
#9 lore raw

Re: [PATCH RFC 2/2] drm: sunxi: Add a basic DRM driver for Allwinner DE2

In reply to Jean-Francois Moine

Some comments from an ARM architecture point of view. I haven't reviewed it from a DRM point of view yet.

Quoted 52 lines · Jean-Francois Moine
drivers/gpu/drm/sunxi/de2_crtc.c new file +52 -0
+struct tcon {
+	u32 gctl;
+#define		TCON_GCTL_TCON_En 0x80000000
+	u32 gint0;
+#define		TCON_GINT0_TCON1_Vb_Int_En 0x40000000
+#define		TCON_GINT0_TCON1_Vb_Int_Flag 0x00001000
+	u32 gint1;
+	u32 dum0[13];
+	u32 tcon0_ctl;
+#define		TCON0_CTL_TCON_En 0x80000000
+	u32 dum1[19];
+	u32 tcon1_ctl;
+#define		TCON1_CTL_TCON_En 0x80000000
+#define		TCON1_CTL_Interlace_En 0x00100000
+#define		TCON1_CTL_Start_Delay_SHIFT 4
+#define		TCON1_CTL_Start_Delay_MASK 0x000001f0
+	u32 basic0;			/* XI/YI */
+	u32 basic1;			/* LS_XO/LS_YO */
+	u32 basic2;			/* XO/YO */
+	u32 basic3;			/* HT/HBP */
+	u32 basic4;			/* VT/VBP */
+	u32 basic5;			/* HSPW/VSPW */
+	u32 dum2;
+	u32 ps_sync;
+	u32 dum3[15];
+	u32 io_pol;
+#define		TCON1_IO_POL_IO0_inv 0x01000000
+#define		TCON1_IO_POL_IO1_inv 0x02000000
+#define		TCON1_IO_POL_IO2_inv 0x04000000
+	u32 io_tri;
+	u32 dum4[2];
+
+	u32 ceu_ctl;			/* 100 */
+#define     TCON_CEU_CTL_ceu_en 0x80000000
+	u32 dum5[3];
+	u32 ceu_rr;
+	u32 ceu_rg;
+	u32 ceu_rb;
+	u32 ceu_rc;
+	u32 ceu_gr;
+	u32 ceu_gg;
+	u32 ceu_gb;
+	u32 ceu_gc;
+	u32 ceu_br;
+	u32 ceu_bg;
+	u32 ceu_bb;
+	u32 ceu_bc;
+	u32 ceu_rv;
+	u32 ceu_gv;
+	u32 ceu_bv;
+	u32 dum6[45];
+

drivers/gpu/drm/sunxi/de2_crtc.c line 82

Quoted 10 lines
drivers/gpu/drm/sunxi/de2_crtc.c new file +10 -0
+	u32 mux_ctl;			/* 200 */
+#define		TCON_MUX_CTL_HDMI_SRC_SHIFT 8
+#define		TCON_MUX_CTL_HDMI_SRC_MASK 0x00000300
+	u32 dum7[63];
+
+	u32 fill_ctl;			/* 300 */
+	u32 fill_start0;
+	u32 fill_end0;
+	u32 fill_data0;
+};

This sets off warnings bells for me...

Quoted 38 lines
drivers/gpu/drm/sunxi/de2_crtc.c new file +38 -0
+static void de2_set_frame_timings(struct lcd *lcd)
+{
+	struct drm_crtc *crtc = &lcd->crtc;
+	const struct drm_display_mode *mode = &crtc->mode;
+	struct tcon *p_tcon = lcd->mmio;
+	int interlace = mode->flags & DRM_MODE_FLAG_INTERLACE ? 2 : 1;
+	int start_delay;
+	u32 data;
+
+	DRM_DEBUG_DRIVER("\n");
+
+	data = XY(mode->hdisplay - 1, mode->vdisplay / interlace - 1);
+	p_tcon->basic0 = data;
+	p_tcon->basic1 = data;
+	p_tcon->basic2 = data;
+	p_tcon->basic3 = XY(mode->htotal - 1,
+				mode->htotal - mode->hsync_start - 1);
+	p_tcon->basic4 = XY(mode->vtotal * (3 - interlace),
+				mode->vtotal - mode->vsync_start - 1);
+	p_tcon->basic5 = XY(mode->hsync_end - mode->hsync_start - 1,
+				mode->vsync_end - mode->vsync_start - 1);
+
+	p_tcon->ps_sync = XY(1, 1);
+
+	data = TCON1_IO_POL_IO2_inv;
+	if (mode->flags & DRM_MODE_FLAG_PVSYNC)
+		data |= TCON1_IO_POL_IO0_inv;
+	if (mode->flags & DRM_MODE_FLAG_PHSYNC)
+		data |= TCON1_IO_POL_IO1_inv;
+	p_tcon->io_pol = data;
+
+	p_tcon->ceu_ctl &= ~TCON_CEU_CTL_ceu_en;
+
+	if (interlace == 2)
+		p_tcon->tcon1_ctl |= TCON1_CTL_Interlace_En;
+	else
+		p_tcon->tcon1_ctl &= ~TCON1_CTL_Interlace_En;
+

drivers/gpu/drm/sunxi/de2_crtc.c line 145

Quoted 10 lines
drivers/gpu/drm/sunxi/de2_crtc.c new file +10 -0
+	p_tcon->fill_ctl = 0;
+	p_tcon->fill_start0 = mode->vtotal + 1;
+	p_tcon->fill_end0 = mode->vtotal;
+	p_tcon->fill_data0 = 0;
+
+	start_delay = (mode->vtotal - mode->vdisplay) / interlace - 5;
+	if (start_delay > 31)
+		start_delay = 31;
+	p_tcon->tcon1_ctl &= ~TCON1_CTL_Start_Delay_MASK;
+	p_tcon->tcon1_ctl |= start_delay << TCON1_CTL_Start_Delay_SHIFT;

Here, the compiler might read tcon1_ctl, clear the bits, merge the new bits in, and write them back. Or it might decide to read, clear bits, write back, set the new bits, and write back again. What happens if start_delay were written as zero?

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+	p_tcon->io_tri = 0x0fffffff;

This whole thing even more so - the compiler is free to reorder these accesses, merge them together, etc. If the compiler decides to inline this into callers, then it can merge these accesses with accesses in the caller functions too.

This is why we have IO accessors; they prevent the compiler doing these kinds of optimisations, and to ensure correctness, we have sparse, and we mark MMIO memory with __iomem to prevent this kind of programming mistake.

Please use sparse to check your work, and also use the IO accessors.

The same comments apply elsewhere.

Quoted 4 lines
drivers/gpu/drm/sunxi/de2_crtc.c new file +4 -0
+}
+
+static void de2_crtc_enable(struct drm_crtc *crtc)
+{

drivers/gpu/drm/sunxi/de2_crtc.c line 161

Quoted 10 lines
drivers/gpu/drm/sunxi/de2_crtc.c new file +10 -0
+	struct lcd *lcd = crtc_to_lcd(crtc);
+	struct drm_display_mode *mode = &crtc->mode;
+	struct tcon *p_tcon = lcd->mmio;
+
+	DRM_DEBUG_DRIVER("clock %d\n", mode->clock);
+
+	if (mode->clock == 0) {
+		dev_err(lcd->dev, "crtc_start: no clock!\n");
+		return;
+	}

Why do you need to check this here?

drivers/gpu/drm/sunxi/de2_crtc.c line 165

Quoted 4 lines
drivers/gpu/drm/sunxi/de2_crtc.c new file +4 -0
+
+	de2_set_frame_timings(lcd);
+
+	clk_set_rate(lcd->clk, mode->clock * 1000);

What if the clock can't support the rate?

...

drivers/gpu/drm/sunxi/de2_de.c line 234

Quoted 9 lines
drivers/gpu/drm/sunxi/de2_de.c new file +9 -0
+	/* set the VI/UIs channels */
+	for (chan = 0; chan < 4; chan++) {
+		int chan_o = mux_o + DE_MUX_CHAN_REGS +
+				DE_MUX_CHAN_SZ * chan;
+
+		if (chan == 0)
+			memset(priv->mmio + chan_o, 0, sizeof(struct de_vi));
+		else
+			memset(priv->mmio + chan_o, 0, sizeof(struct de_ui));

The compiler is allowed to optimise memset() any way it chooses; it makes no guarantees what so ever, and the compiler is allowed to assume that it is accessing memory which has no side effects. It's even allowed to use unaligned accesses if it so pleases, which are illegal for MMIO memory on ARM. memset_io() must be used instead. Sparse would have found this as well.

...

drivers/gpu/drm/sunxi/de2_hdmi.c line 98

Quoted 5 lines
drivers/gpu/drm/sunxi/de2_hdmi.c new file +5 -0
+static int de2_hdmi_connector_mode_valid(struct drm_connector *connector,
+					struct drm_display_mode *mode)
+{
+	if (!drm_match_cea_mode(mode))
+		return MODE_NOMODE;

Maybe detect modes with a zero clock here instead?

Quoted 2 lines
drivers/gpu/drm/sunxi/de2_hdmi.c new file +2 -0
+	return MODE_OK;
+}

...

drivers/gpu/drm/sunxi/de2_hdmi_h3.c line 82

Quoted 8 lines
drivers/gpu/drm/sunxi/de2_hdmi_h3.c new file +8 -0
+static void hdmi_phy_init(struct de2_hdmi_priv *priv)
+{
+	int to_cnt;
+	u32 tmp;
+
+	hdmi_writel(priv, 0x10020, 0);
+	hdmi_writel(priv, 0x10020, 1 << 0);
+	udelay(5);

udelay() does not delay precisely; it may return slightly short of the requested delay. I hope you've made allowance for that.

Signature · 3 lines
RMK's Patch system: http://www.arm.linux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
#2 lore raw

Re: [PATCH RFC 1/2] clk: sunxi: Add sun8i display support

In reply to Jean-Francois Moine

Hi,

First of all, please include the clk subsystem maintainers and the linux-clk mailing list for all clk related patches.

Quoted 1 line · Jean-Francois Moine

Add the clock types which are used by the sun8i family for video.

These clocks first appeared in the A31.

Quoted 4 lines
---
 drivers/clk/sunxi/Makefile            |   1 +
 drivers/clk/sunxi/clk-sun8i-display.c | 247 ++++++++++++++++++++++++++++++++++

Please split this into 2 patches, and 2 files: one for PLL3, named clk-sun6i-pll3.c, and one for the display mod clocks, named clk-sun6i-display.c

Quoted 40 lines
 2 files changed, 258 insertions(+)
 create mode 100644 drivers/clk/sunxi/clk-sun8i-display.c
drivers/clk/sunxi/Makefile +1 -0
index cb4c299..145c078 100644
@@ -10,6 +10,7 @@ obj-y += clk-a10-pll2.o
 obj-y += clk-a20-gmac.o
 obj-y += clk-mod0.o
 obj-y += clk-simple-gates.o
+obj-y += clk-sun8i-display.o
 obj-y += clk-sun8i-mbus.o
 obj-y += clk-sun9i-core.o
 obj-y += clk-sun9i-mmc.o
drivers/clk/sunxi/clk-sun8i-display.c new file +19 -0
new file mode 100644
index 0000000..eded572
@@ -0,0 +1,247 @@
+/*
+ * Copyright 2015 Jean-Francois Moine <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/clk-provider.h>
+#include <linux/of_address.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+#include <linux/rational.h>

drivers/clk/sunxi/clk-sun8i-display.c line 29

Quoted 10 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +10 -0
+#include <linux/delay.h>
+
+static DEFINE_SPINLOCK(sun8i_display_lock);
+
+/* PLL3 (video) and PLL10 (de) */
+struct clk_fact {
+       struct clk_hw hw;
+       void __iomem *reg;
+};
+#define to_clk_fact(_hw) container_of(_hw, struct clk_fact, hw)

What does fact stand for?

drivers/clk/sunxi/clk-sun8i-display.c line 32

Quoted 3 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +3 -0
+
+#define SUN8I_PLL3_MSHIFT      0
+#define SUN8I_PLL3_MMASK       0x0f

You can use GENMASK for these. Note that GENMASK is inclusive on both ends.

drivers/clk/sunxi/clk-sun8i-display.c line 36

Quoted 4 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +4 -0
+#define SUN8I_PLL3_NSHIFT      8
+#define SUN8I_PLL3_NMASK       0x7f
+#define SUN8I_PLL3_MODE_SEL    0x01000000
+#define SUN8I_PLL3_FRAC_CLK    0x02000000

Please use the BIT() macros.

Quoted 35 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +35 -0
+
+static int sun8i_pll3_get_fact(unsigned long rate,
+                       unsigned long parent_rate,
+                       unsigned long *n, unsigned long *m)
+{
+       if (rate == 297000000)
+               return 1;
+       if (rate == 270000000)
+               return 0;
+       rational_best_approximation(rate, parent_rate,
+                               SUN8I_PLL3_NMASK + 1, SUN8I_PLL3_MMASK + 1,
+                               n, m);
+       return -1;
+}
+
+static unsigned long sun8i_pll3_recalc_rate(struct clk_hw *hw,
+                                       unsigned long parent_rate)
+{
+       struct clk_fact *fact = to_clk_fact(hw);
+       u32 reg;
+       u32 n, m;
+
+       reg = readl(fact->reg);
+       if (reg & SUN8I_PLL3_MODE_SEL) {
+               n = (reg >> SUN8I_PLL3_NSHIFT) & SUN8I_PLL3_NMASK;
+               m = (reg >> SUN8I_PLL3_MSHIFT) & SUN8I_PLL3_MMASK;
+               return parent_rate / (m + 1) * (n + 1);
+       }
+       if (reg & SUN8I_PLL3_FRAC_CLK)
+               return 297000000;
+       return 270000000;
+}
+
+static long sun8i_pll3_round_rate(struct clk_hw *hw, unsigned long rate,
+                               unsigned long *parent_rate)

drivers/clk/sunxi/clk-sun8i-display.c line 81

Quoted 10 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +10 -0
+{
+       int frac;
+       unsigned long n, m;
+
+       frac = sun8i_pll3_get_fact(rate, *parent_rate, &n, &m);
+       if (frac == 1)
+               return 297000000;
+       if (frac == 0)
+               return 270000000;
+       return (*parent_rate * n) / m;

The ordering is different from the one in recalc_rate. Considering integer rounding, would the results be different?

Quoted 20 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +20 -0
+}
+
+static int sun8i_pll3_set_rate(struct clk_hw *hw, unsigned long rate,
+                       unsigned long parent_rate)
+{
+       struct clk_fact *fact = to_clk_fact(hw);
+       u32 reg;
+       int frac;
+       unsigned long n, m;
+
+       reg = readl(fact->reg) &
+                       ~(SUN8I_PLL3_MODE_SEL |
+                         SUN8I_PLL3_FRAC_CLK |
+                         (SUN8I_PLL3_NMASK << SUN8I_PLL3_NSHIFT) |
+                         (SUN8I_PLL3_MMASK << SUN8I_PLL3_MSHIFT));
+
+       frac = sun8i_pll3_get_fact(rate, parent_rate, &n, &m);
+       if (frac == 1)
+               reg |= SUN8I_PLL3_FRAC_CLK;     /* 297MHz */
+       else if (frac == 0)

drivers/clk/sunxi/clk-sun8i-display.c line 111

Quoted 10 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +10 -0
+               ;                               /* 270MHz */
+       else
+               reg |= SUN8I_PLL3_MODE_SEL |
+                       ((n - 1) << SUN8I_PLL3_NSHIFT) |
+                       ((m - 1) << SUN8I_PLL3_MSHIFT);
+
+       writel(reg, fact->reg);
+
+       /* delay 500us so pll stabilizes */
+       __delay(500);

Bit 28 indicates PLL lock, please use readl_poll_timeout() to check it.

Quoted 20 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +20 -0
+
+       return 0;
+}
+
+static const struct clk_ops clk_sun8i_pll3_fact_ops = {
+       .recalc_rate = sun8i_pll3_recalc_rate,
+       .round_rate = sun8i_pll3_round_rate,
+       .set_rate = sun8i_pll3_set_rate,
+};
+
+static void __init sun8i_pll3_setup(struct device_node *node)
+{
+       const char *clk_name = node->name, *parent;
+       struct clk_fact *fact;
+       struct clk_gate *gate;
+       void __iomem *reg;
+       struct clk *clk;
+
+       of_property_read_string(node, "clock-output-names", &clk_name);
+       parent = of_clk_get_parent_name(node, 0);

drivers/clk/sunxi/clk-sun8i-display.c line 141

Quoted 10 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +10 -0
+
+       reg = of_io_request_and_map(node, 0, of_node_full_name(node));
+       if (IS_ERR(reg)) {
+               pr_err("%s: Could not map the clock registers\n", clk_name);
+               return;
+       }
+
+       gate = kzalloc(sizeof(*gate), GFP_KERNEL);
+       if (!gate)
+               return;

You should call release_mem_region() to release the iomem region you requested with of_io_request_and_map().

Quoted 13 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +13 -0
+
+       gate->reg = reg;
+       gate->bit_idx = 31;
+       gate->lock = &sun8i_display_lock;
+
+       fact = kzalloc(sizeof(*fact), GFP_KERNEL);
+       if (!fact)
+               goto free_gate;
+
+       fact->reg = reg;
+
+       clk = clk_register_composite(NULL, clk_name,
+                                    &parent, 1,

drivers/clk/sunxi/clk-sun8i-display.c line 164

Quoted 10 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +10 -0
+                                    NULL, NULL,
+                                    &fact->hw, &clk_sun8i_pll3_fact_ops,
+                                    &gate->hw, &clk_gate_ops,
+                                    0);
+       if (IS_ERR(clk)) {
+               pr_err("%s: Couldn't register the clock\n", clk_name);
+               goto free_fact;
+       }
+
+       of_clk_add_provider(node, of_clk_src_simple_get, clk);

Would this fail?

Quoted 6 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +6 -0
+
+       return;
+
+free_fact:
+       kfree(fact);
+free_gate:

drivers/clk/sunxi/clk-sun8i-display.c line 180

Quoted 10 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +10 -0
+       kfree(gate);
+}
+
+CLK_OF_DECLARE(sun8i_pll3, "allwinner,sun8i-pll3-clk", sun8i_pll3_setup);
+
+/* DE, TCON0, TVE, HDMI, DEINTERLACE  */
+static void __init sun8i_display_setup(struct device_node *node)
+{
+       const char *clk_name = node->name;
+       const char *parents[2];

There are as many as six parents for display mod clocks on A31. A23/A33 mod clocks have holes in there parent array, as some PLLs are missing. We may need a different driver to deal with that.

Quoted 11 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +11 -0
+       struct clk_mux *mux = NULL;
+       struct clk_divider *div;
+       struct clk_gate *gate;
+       void __iomem *reg;
+       struct clk *clk;
+       int n;
+
+       of_property_read_string(node, "clock-output-names", &clk_name);
+
+       reg = of_io_request_and_map(node, 0, of_node_full_name(node));
+       if (IS_ERR(reg)) {

drivers/clk/sunxi/clk-sun8i-display.c line 201

Quoted 10 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +10 -0
+               pr_err("%s: Could not map the clock registers\n", clk_name);
+               return;
+       }
+
+       n = of_clk_parent_fill(node, parents, ARRAY_SIZE(parents));
+
+       if (n > 1) {                            /* many possible sources */
+               mux = kzalloc(sizeof(*mux), GFP_KERNEL);
+               if (!mux)
+                       return;

release_mem_region().

drivers/clk/sunxi/clk-sun8i-display.c line 204

Quoted 3 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +3 -0
+               mux->reg = reg;
+               mux->shift = 24;
+               mux->mask = 0x07;

Macros for these, please.

drivers/clk/sunxi/clk-sun8i-display.c line 210

Quoted 6 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +6 -0
+               mux->lock = &sun8i_display_lock;
+       }
+
+       gate = kzalloc(sizeof(*gate), GFP_KERNEL);
+       if (!gate)
+               goto free_gate;

Label name is confusing. Another "free_mux" wouldn't harm.

drivers/clk/sunxi/clk-sun8i-display.c line 222

Quoted 12 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +12 -0
+
+       gate->reg = reg;
+       gate->bit_idx = 31;
+       gate->lock = &sun8i_display_lock;
+
+       div = kzalloc(sizeof(*div), GFP_KERNEL);
+       if (!div)
+               goto free_gate;
+
+       div->reg = reg;
+       div->shift = 0;
+       div->width = 4;

Macros, please.

Quoted 4 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +4 -0
+       div->lock = &sun8i_display_lock;
+
+       clk = clk_register_composite(NULL, clk_name,
+                                    parents, n,

drivers/clk/sunxi/clk-sun8i-display.c line 236

Quoted 10 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +10 -0
+                                    mux ? &mux->hw : NULL, &clk_mux_ops,
+                                    &div->hw, &clk_divider_ops,
+                                    &gate->hw, &clk_gate_ops,
+                                    0);
+       if (IS_ERR(clk)) {
+               pr_err("%s: Couldn't register the clock\n", clk_name);
+               goto free_div;
+       }
+
+       of_clk_add_provider(node, of_clk_src_simple_get, clk);

Would this fail?

Quoted 12 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +11 -1
+
+       return;
+
+free_div:
+       kfree(div);
+free_gate:
+       kfree(gate);
+       kfree(mux);
+}
+
+CLK_OF_DECLARE(sun8i_display, "allwinner,sun8i-display-clk", sun8i_display_setup);
--
Quoted 1 line

2.6.4

Regards
ChenYu

#11 lore raw

Re: [PATCH RFC 2/2] drm: sunxi: Add a basic DRM driver for Allwinner DE2

In reply to Jean-Francois Moine

On 05/01/16 19:40, Jean-Francois Moine wrote:
[snip]

Quoted 45 lines
drivers/gpu/drm/sunxi/de2_hdmi_h3.c new file +39 -0
new file mode 100644
index 0000000..c54b090
@@ -0,0 +1,478 @@
+/*
+ * Allwinner H3 HDMI lowlevel functions
+ *
+ * Copyright (C) 2016 Jean-Francois Moine <[email protected]>
+ *
+ * Adapted from the file
+ *	lichee/linux-3.4/drivers/video/sunxi/disp2/hdmi/aw/hdmi_bsp_sun8iw7.c
+ * with no license nor copyright.
+ */
+
+#include <drm/drmP.h>
+
+#include "de2_hdmi.h"
+#include "de2_hdmi_h3.h"
+
+struct para_tab {
+	u32 para[19];
+};
+
+struct pcm_sf {
+	u32 	sf;
+	unsigned char	cs_sf;
+};
+
+/*
+ * [0] = vic (cea Video ID)
+ * [1] used in hdmi_phy_set / bsp_hdmi_audio
+ * [2..17] used in bsp_hdmi_video
+ */
+static const struct para_tab ptbl[] = {
+	{{  6,  1, 1,  1,  5,  3, 0, 1, 4, 0, 0, 160,  20,  38, 124, 240, 22, 0, 0}},
+	{{ 21, 11, 1,  1,  5,  3, 1, 1, 2, 0, 0, 160,  32,  24, 126,  32, 24, 0, 0}},
+	{{  2, 11, 0,  0,  2,  6, 1, 0, 9, 0, 0, 208, 138,  16,  62, 224, 45, 0, 0}},
+	{{ 17, 11, 0,  0,  2,  5, 2, 0, 5, 0, 0, 208, 144,  12,  64,  64, 49, 0, 0}},
+	{{ 19,  4, 0, 96,  5,  5, 2, 2, 5, 1, 0,   0, 188, 184,  40, 208, 30, 1, 1}},
+	{{  4,  4, 0, 96,  5,  5, 2, 1, 5, 0, 0,   0, 114, 110,  40, 208, 30, 1, 1}},
+	{{ 20,  4, 0, 97,  7,  5, 4, 2, 2, 2, 0, 128, 208,  16,  44,  56, 22, 1, 1}},
+	{{  5,  4, 0, 97,  7,  5, 4, 1, 2, 0, 0, 128,  24,  88,  44,  56, 22, 1, 1}},
+	{{ 31,  2, 0, 96,  7,  5, 4, 2, 4, 2, 0, 128, 208,  16,  44,  56, 45, 1, 1}},

drivers/gpu/drm/sunxi/de2_hdmi_h3.c line 49

Quoted 10 lines
drivers/gpu/drm/sunxi/de2_hdmi_h3.c new file +10 -0
+	{{ 16,  2, 0, 96,  7,  5, 4, 1, 4, 0, 0, 128,  24,  88,  44,  56, 45, 1, 1}},
+	{{ 32,  4, 0, 96,  7,  5, 4, 3, 4, 2, 0, 128,  62, 126,  44,  56, 45, 1, 1}},
+	{{ 33,  4, 0,  0,  7,  5, 4, 2, 4, 2, 0, 128, 208,  16,  44,  56, 45, 1, 1}},
+	{{ 34,  4, 0,  0,  7,  5, 4, 1, 4, 0, 0, 128,  24,  88,  44,  56, 45, 1, 1}},
+	{{160,  2, 0, 96,  7,  5, 8, 3, 4, 2, 0, 128,  62, 126,  44, 157, 45, 1, 1}},
+	{{147,  2, 0, 96,  5,  5, 5, 2, 5, 1, 0,   0, 188, 184,  40, 190, 30, 1, 1}},
+	{{132,  2, 0, 96,  5,  5, 5, 1, 5, 0, 0,   0, 114, 110,  40, 160, 30, 1, 1}},
+	{{257,  1, 0, 96, 15, 10, 8, 2, 8, 0, 0,   0,  48, 176,  88, 112, 90, 1, 1}},
+	{{258,  1, 0, 96, 15, 10, 8, 5, 8, 4, 0,   0, 160,  32,  88, 112, 90, 1, 1}},
+};

Hi,

did you try to figure out what the values in this table actually mean?

I tried it some time ago because I wanted to add some more resolutions to 3.4, but never got further than what I'll add below. But it might be useful now, to get rid of at least some of the magic constants. With some more work (what does [1] mean?) we might be able to drop the entire table and use the values from drm_display_mode directly instead.

unsure (hard to verify):
[2] = pixel repetition (1 = 2x)
[3] = bit0: interlaced (no idea about the 96/0x60 yet)
[17] = something csc related
[18] = unused

pretty sure (verified by comparing with timings):
[4] = horizontal active (high byte)
[5] = vsync width
[6] = vertical active (high byte)
[7] = horizontal blanking (high byte)
[8] = vertical front porch
[9] = horizontal front porch (high byte)
[10] = hsync width (high byte)
[11] = horizontal active (low byte)
[12] = horizontal blanking (low byte)
[13] = horizontal front porch (low byte)
[14] = hsync width (low byte)
[15] = vertical active (low byte)
[16] = vertical blanking

Generally, nice work. I only skimmed over it by now, but I hope to test and review the hardware related parts more intensively sometime.

Regards,
Jens

#13 lore raw
In reply to Jean-Francois Moine

Hi,

Thanks a lot for your work!

Quoted 6 lines · Jean-Francois Moine

The proposed DRM driver works on a Orange PI 2 with a kernel 4.4-rc1 and the H3 patches found in Hans de Goede's GIT repository.

As there is no documentation about the DE2 nor about the HDMI which are found in the H3, this driver has been built from Allwiiner's sources.

That's unfortunate :/

Have you checked in the A64 BSP if there was some useful information?

Quoted 2 lines

So, there may be license problems, especially for the file de2_hdmi_h3.c which contains a lot of magic values.

I guess it's the biggest issue with your code right now. What licenses issues are we talking about here?

Remember that having your Signed-off-by tag on a commit means that you certify that you have the right to submit the patch under the license you indicate in the files added and / or modified.

If you don't have such right, for example because you don't have the right and / or authorization from the initial author to re-license that code, you cannot put your SoB.

Quoted 2 lines

The associated DT and documentation will be submitted when the H3 DTs will be in the kernel.

Having the DT binding documentation would really help in the review.

Thanks!
Maxime

Signature · 3 lines
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

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

#14 lore raw
Quoted 7 lines · On Wed, 6 Jan 2016 22:20:46 +0100 Maxime Ripard…
Quoted 3 lines

As there is no documentation about the DE2 nor about the HDMI which are found in the H3, this driver has been built from Allwiiner's sources.

That's unfortunate :/

Have you checked in the A64 BSP if there was some useful information?

Same as the H3: no more information about the display system.

Quoted 5 lines
Quoted 2 lines

So, there may be license problems, especially for the file de2_hdmi_h3.c which contains a lot of magic values.

I guess it's the biggest issue with your code right now. What licenses issues are we talking about here?

The documentation about the H3, as the other Allwinner documentations, starts with:

This documentation is the original work and copyrighted property of Allwinner Technology ("Allwinner"). Reproduction in whole or in part must obtain the written approval of Allwinner and give clear acknowledgement to the copyright owner.

Then, the DE2 sources contain only:

All Winner Tech, All Right Reserved. 2014-2015 Copyright (c)

Eventually, there is no copyright/author/history in the HDMI sources.

Quoted 7 lines

Remember that having your Signed-off-by tag on a commit means that you certify that you have the right to submit the patch under the license you indicate in the files added and / or modified.

If you don't have such right, for example because you don't have the right and / or authorization from the initial author to re-license that code, you cannot put your SoB.

OK, sorry. So, please, ignore the whole patch series.

Quoted 4 lines
Quoted 2 lines

The associated DT and documentation will be submitted when the H3 DTs will be in the kernel.

Having the DT binding documentation would really help in the review.

Here it is, as a sunxi specific documentation, but it could be generic.

devicetree/bindings/display/sunxi.txt new file +107 -0
@@ -0,0 +1,107 @@
+Allwinner sunxi display subsystem
+=================================
+
+The sunxi display subsystems contain a display controller (DE),
+one or two LCD controllers (TCON) and their external interfaces.
+
+Display controller
+==================
+
+Required properties:
+
+- compatible: value should be one of the following
+		"allwinner,sun8i-h3-display-engine"
+
+- clocks: must include clock specifiers corresponding to entries in the
+		clock-names property.
+
+- clock-names: must contain
+		gate: for DE activation
+		clock: DE clock
+
+- resets: phandle to the reset of the device
+
+- ports: phandle's to the LCD ports
+
+LCD controller
+==============
+
+Required properties:
+
+- compatible: value should be one of the following
+		"allwinner,sun8i-h3-lcd"
+
+- clocks: must include clock specifiers corresponding to entries in the
+		clock-names property.
+
+- clock-names: must contain
+		gate: for LCD activation
+		clock: pixel clock
+
+- resets: phandle to the reset of the device
+
+- port: port node with endpoint definitions as defined in
+	Documentation/devicetree/bindings/media/video-interfaces.txt
+
+HDMI support
+============
+
+Required properties:
+
+- compatible: value should be one of the following
+		"allwinner,sun8i-h3-hdmi"
+
+- clocks: must include clock specifiers corresponding to entries in the
+		clock-names property.
+
+- clock-names: must contain
+		gate: for HDMI activation
+		clock: pixel clock
+		ddc-clock: for the HDMI protocol
+
+- resets: one or two phandle's to the reset of the device
+
+- port: port node with endpoint definitions as defined in
+	Documentation/devicetree/bindings/media/video-interfaces.txt
+
+Example:
+
+	de: de-controller at 01000000 {
+		compatible = "allwinner,sun8i-h3-display-engine";
+		...
+		clocks = <&bus_gates 44>, <&de_clk>;
+		clock-names = "gate", "clock";
+		resets = <&bus_rst 44>;
+		ports = <&lcd0_p>;
+	};
+
+	lcd0: lcd-controller at 01c0c000 {
+		compatible = "allwinner,sun8i-h3-lcd";
+		...
+		clocks = <&bus_gates 35>, <&tcon0_clk>;
+		clock-names = "gate", "clock";
+		resets = <&bus_rst 35>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+		lcd0_p: port {
+			lcd0_ep: endpoint {
+				remote-endpoint = <&hdmi_ep>;
+			};
+		};
+	};
+
+	hdmi: hdmi at 01ee0000 {
+		compatible = "allwinner,sun8i-h3-hdmi";
+		...
+		clocks = <&bus_gates 43>, <&hdmi_clk>,
+			 <&hdmi_slow_clk 31>;
+		clock-names = "gate", "clock", "ddc-clock";
+		resets = <&bus_rst 42>, <&bus_rst 43>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+		port {
+			hdmi_ep: endpoint {
+				remote-endpoint = <&lcd0_ep>;
+			};
+		};
+	};
Signature · 2 lines
Ken ar c'henta?	|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/
#3 lore raw

Re: [PATCH RFC 1/2] clk: sunxi: Add sun8i display support

In reply to Chen-Yu Tsai
Quoted 2 lines · On Wed, 6 Jan 2016 10:39:51 +0800 Chen-Yu Tsai <[email protected]> wrote:

First of all, please include the clk subsystem maintainers and the linux-clk mailing list for all clk related patches.

OK.

Quoted 4 lines · Jean-Francois Moine
Quoted 1 line

Add the clock types which are used by the sun8i family for video.

These clocks first appeared in the A31.

Sorry, I have the documentation of only some sun8i SoCs.

Quoted 8 lines
Quoted 4 lines
---
 drivers/clk/sunxi/Makefile            |   1 +
 drivers/clk/sunxi/clk-sun8i-display.c | 247 ++++++++++++++++++++++++++++++++++

Please split this into 2 patches, and 2 files: one for PLL3, named clk-sun6i-pll3.c, and one for the display mod clocks, named clk-sun6i-display.c

No problem.

	[snip]
Quoted 29 lines
Quoted 29 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +23 -0
new file mode 100644
index 0000000..eded572
@@ -0,0 +1,247 @@
+/*
+ * Copyright 2015 Jean-Francois Moine <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/clk-provider.h>
+#include <linux/of_address.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+#include <linux/rational.h>
+#include <linux/delay.h>
+
+static DEFINE_SPINLOCK(sun8i_display_lock);
+
Quoted 8 lines

drivers/clk/sunxi/clk-sun8i-display.c line 29

Quoted 6 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +6 -0
+/* PLL3 (video) and PLL10 (de) */
+struct clk_fact {
+       struct clk_hw hw;
+       void __iomem *reg;
+};
+#define to_clk_fact(_hw) container_of(_hw, struct clk_fact, hw)

What does fact stand for?

pre-divide plus factor. Have you a better name?

Quoted 6 lines

drivers/clk/sunxi/clk-sun8i-display.c line 32

Quoted 3 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +3 -0
+
+#define SUN8I_PLL3_MSHIFT      0
+#define SUN8I_PLL3_MMASK       0x0f

You can use GENMASK for these. Note that GENMASK is inclusive on both ends.

Quoted 6 lines

drivers/clk/sunxi/clk-sun8i-display.c line 36

Quoted 4 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +4 -0
+#define SUN8I_PLL3_NSHIFT      8
+#define SUN8I_PLL3_NMASK       0x7f
+#define SUN8I_PLL3_MODE_SEL    0x01000000
+#define SUN8I_PLL3_FRAC_CLK    0x02000000

Please use the BIT() macros.

OK.

Quoted 40 lines
Quoted 40 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +40 -0
+
+static int sun8i_pll3_get_fact(unsigned long rate,
+                       unsigned long parent_rate,
+                       unsigned long *n, unsigned long *m)
+{
+       if (rate == 297000000)
+               return 1;
+       if (rate == 270000000)
+               return 0;
+       rational_best_approximation(rate, parent_rate,
+                               SUN8I_PLL3_NMASK + 1, SUN8I_PLL3_MMASK + 1,
+                               n, m);
+       return -1;
+}
+
+static unsigned long sun8i_pll3_recalc_rate(struct clk_hw *hw,
+                                       unsigned long parent_rate)
+{
+       struct clk_fact *fact = to_clk_fact(hw);
+       u32 reg;
+       u32 n, m;
+
+       reg = readl(fact->reg);
+       if (reg & SUN8I_PLL3_MODE_SEL) {
+               n = (reg >> SUN8I_PLL3_NSHIFT) & SUN8I_PLL3_NMASK;
+               m = (reg >> SUN8I_PLL3_MSHIFT) & SUN8I_PLL3_MMASK;
+               return parent_rate / (m + 1) * (n + 1);
+       }
+       if (reg & SUN8I_PLL3_FRAC_CLK)
+               return 297000000;
+       return 270000000;
+}
+
+static long sun8i_pll3_round_rate(struct clk_hw *hw, unsigned long rate,
+                               unsigned long *parent_rate)
+{
+       int frac;
+       unsigned long n, m;
+
+       frac = sun8i_pll3_get_fact(rate, *parent_rate, &n, &m);
Quoted 8 lines

drivers/clk/sunxi/clk-sun8i-display.c line 81

Quoted 5 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +5 -0
+       if (frac == 1)
+               return 297000000;
+       if (frac == 0)
+               return 270000000;
+       return (*parent_rate * n) / m;

The ordering is different from the one in recalc_rate. Considering integer rounding, would the results be different?

Maybe. But, you are right, 'm', as a pre-divider, should be before 'n'.

Quoted 24 lines
Quoted 24 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +24 -0
+}
+
+static int sun8i_pll3_set_rate(struct clk_hw *hw, unsigned long rate,
+                       unsigned long parent_rate)
+{
+       struct clk_fact *fact = to_clk_fact(hw);
+       u32 reg;
+       int frac;
+       unsigned long n, m;
+
+       reg = readl(fact->reg) &
+                       ~(SUN8I_PLL3_MODE_SEL |
+                         SUN8I_PLL3_FRAC_CLK |
+                         (SUN8I_PLL3_NMASK << SUN8I_PLL3_NSHIFT) |
+                         (SUN8I_PLL3_MMASK << SUN8I_PLL3_MSHIFT));
+
+       frac = sun8i_pll3_get_fact(rate, parent_rate, &n, &m);
+       if (frac == 1)
+               reg |= SUN8I_PLL3_FRAC_CLK;     /* 297MHz */
+       else if (frac == 0)
+               ;                               /* 270MHz */
+       else
+               reg |= SUN8I_PLL3_MODE_SEL |
+                       ((n - 1) << SUN8I_PLL3_NSHIFT) |
Quoted 8 lines

drivers/clk/sunxi/clk-sun8i-display.c line 111

Quoted 6 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +6 -0
+                       ((m - 1) << SUN8I_PLL3_MSHIFT);
+
+       writel(reg, fact->reg);
+
+       /* delay 500us so pll stabilizes */
+       __delay(500);

Bit 28 indicates PLL lock, please use readl_poll_timeout() to check it.

I did not know about this useful macro.

Quoted 25 lines
Quoted 25 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +25 -0
+
+       return 0;
+}
+
+static const struct clk_ops clk_sun8i_pll3_fact_ops = {
+       .recalc_rate = sun8i_pll3_recalc_rate,
+       .round_rate = sun8i_pll3_round_rate,
+       .set_rate = sun8i_pll3_set_rate,
+};
+
+static void __init sun8i_pll3_setup(struct device_node *node)
+{
+       const char *clk_name = node->name, *parent;
+       struct clk_fact *fact;
+       struct clk_gate *gate;
+       void __iomem *reg;
+       struct clk *clk;
+
+       of_property_read_string(node, "clock-output-names", &clk_name);
+       parent = of_clk_get_parent_name(node, 0);
+
+       reg = of_io_request_and_map(node, 0, of_node_full_name(node));
+       if (IS_ERR(reg)) {
+               pr_err("%s: Could not map the clock registers\n", clk_name);
+               return;
Quoted 8 lines

drivers/clk/sunxi/clk-sun8i-display.c line 141

Quoted 5 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +5 -0
+       }
+
+       gate = kzalloc(sizeof(*gate), GFP_KERNEL);
+       if (!gate)
+               return;

You should call release_mem_region() to release the iomem region you requested with of_io_request_and_map().

Right.

Quoted 17 lines
Quoted 17 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +17 -0
+
+       gate->reg = reg;
+       gate->bit_idx = 31;
+       gate->lock = &sun8i_display_lock;
+
+       fact = kzalloc(sizeof(*fact), GFP_KERNEL);
+       if (!fact)
+               goto free_gate;
+
+       fact->reg = reg;
+
+       clk = clk_register_composite(NULL, clk_name,
+                                    &parent, 1,
+                                    NULL, NULL,
+                                    &fact->hw, &clk_sun8i_pll3_fact_ops,
+                                    &gate->hw, &clk_gate_ops,
+                                    0);
Quoted 8 lines

drivers/clk/sunxi/clk-sun8i-display.c line 164

Quoted 6 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +6 -0
+       if (IS_ERR(clk)) {
+               pr_err("%s: Couldn't register the clock\n", clk_name);
+               goto free_fact;
+       }
+
+       of_clk_add_provider(node, of_clk_src_simple_get, clk);

Would this fail?

Don't know. This is done this way in many other sunxi clocks.

Quoted 13 lines
Quoted 13 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +13 -0
+
+       return;
+
+free_fact:
+       kfree(fact);
+free_gate:
+       kfree(gate);
+}
+
+CLK_OF_DECLARE(sun8i_pll3, "allwinner,sun8i-pll3-clk", sun8i_pll3_setup);
+
+/* DE, TCON0, TVE, HDMI, DEINTERLACE  */
+static void __init sun8i_display_setup(struct device_node *node)
Quoted 8 lines

drivers/clk/sunxi/clk-sun8i-display.c line 180

Quoted 3 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +3 -0
+{
+       const char *clk_name = node->name;
+       const char *parents[2];

There are as many as six parents for display mod clocks on A31. A23/A33 mod clocks have holes in there parent array, as some PLLs are missing. We may need a different driver to deal with that.

I don't see why: the DT may contain dummy clocks in the parent list.

Otherwise, I agree the remaining remarks.

Thanks for the review.

Signature · 2 lines
Ken ar c'henta?	|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/
#10 lore raw

Re: [PATCH RFC 2/2] drm: sunxi: Add a basic DRM driver for Allwinner DE2

In reply to Russell King - ARM Linux
Quoted 2 lines · On Tue, 5 Jan 2016 20:38:17 +0000 Russell King - ARM Linux…

Some comments from an ARM architecture point of view. I haven't reviewed it from a DRM point of view yet.

Anyway, thanks for your explanations and remarks.

Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+static void de2_crtc_enable(struct drm_crtc *crtc)
+{
	...
Quoted 3 lines

drivers/gpu/drm/sunxi/de2_crtc.c line 165

Quoted 1 line
drivers/gpu/drm/sunxi/de2_crtc.c new file +1 -0
+	clk_set_rate(lcd->clk, mode->clock * 1000);

What if the clock can't support the rate?

The function enabling the CRTC has no return code, so the screen would be blurred. But this would not occur: the video PLL is in the range 30..600MHz.

Quoted 7 lines

drivers/gpu/drm/sunxi/de2_hdmi.c line 98

Quoted 5 lines
drivers/gpu/drm/sunxi/de2_hdmi.c new file +5 -0
+static int de2_hdmi_connector_mode_valid(struct drm_connector *connector,
+					struct drm_display_mode *mode)
+{
+	if (!drm_match_cea_mode(mode))
+		return MODE_NOMODE;

Maybe detect modes with a zero clock here instead?

We have no documentation about the HDMI hardware and only the CEA modes are handled in Allwinner's driver.

Signature · 2 lines
Ken ar c'henta?	|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/
#12 lore raw

Re: [PATCH RFC 2/2] drm: sunxi: Add a basic DRM driver for Allwinner DE2

In reply to Jens Kuske
Quoted 17 lines · On Wed, 6 Jan 2016 21:41:30 +0100 Jens Kuske <[email protected]> wrote:

On 05/01/16 19:40, Jean-Francois Moine wrote:
[snip]

Quoted 6 lines
drivers/gpu/drm/sunxi/de2_hdmi_h3.c new file +0 -0
new file mode 100644
index 0000000..c54b090

drivers/gpu/drm/sunxi/de2_hdmi_h3.c line 9

Quoted 9 lines
drivers/gpu/drm/sunxi/de2_hdmi_h3.c new file +9 -0
@@ -0,0 +1,478 @@
+/*
+ * Allwinner H3 HDMI lowlevel functions
+ *
+ * Copyright (C) 2016 Jean-Francois Moine <[email protected]>
+ *
+ * Adapted from the file
+ *	lichee/linux-3.4/drivers/video/sunxi/disp2/hdmi/aw/hdmi_bsp_sun8iw7.c
+ * with no license nor copyright.
+ */
	[snip]
Quoted 7 lines

drivers/gpu/drm/sunxi/de2_hdmi_h3.c line 31

Quoted 7 lines
drivers/gpu/drm/sunxi/de2_hdmi_h3.c new file +7 -0
+/*
+ * [0] = vic (cea Video ID)
+ * [1] used in hdmi_phy_set / bsp_hdmi_audio
+ * [2..17] used in bsp_hdmi_video
+ */
+static const struct para_tab ptbl[] = {
+	{{  6,  1, 1,  1,  5,  3, 0, 1, 4, 0, 0, 160,  20,  38, 124, 240, 22, 0, 0}},
	[snip]
Quoted 29 lines

did you try to figure out what the values in this table actually mean?

I tried it some time ago because I wanted to add some more resolutions to 3.4, but never got further than what I'll add below. But it might be useful now, to get rid of at least some of the magic constants. With some more work (what does [1] mean?) we might be able to drop the entire table and use the values from drm_display_mode directly instead.

unsure (hard to verify):
[2] = pixel repetition (1 = 2x)
[3] = bit0: interlaced (no idea about the 96/0x60 yet)
[17] = something csc related
[18] = unused

pretty sure (verified by comparing with timings):
[4] = horizontal active (high byte)
[5] = vsync width
[6] = vertical active (high byte)
[7] = horizontal blanking (high byte)
[8] = vertical front porch
[9] = horizontal front porch (high byte)
[10] = hsync width (high byte)
[11] = horizontal active (low byte)
[12] = horizontal blanking (low byte)
[13] = horizontal front porch (low byte)
[14] = hsync width (low byte)
[15] = vertical active (low byte)
[16] = vertical blanking

Quoted 2 lines

Generally, nice work. I only skimmed over it by now, but I hope to test and review the hardware related parts more intensively sometime.

Hi Jens,

Thanks for this information, but this table is only a very small part of the HDMI code.

I doubt that anyone could understand the other sequences of the functions of this BSP without documentation, or could do some reverse engineering and understand how the DE2 HDMI device works.

So, I think that we have to wait for some information and/or authorisation from Allwinner before putting a HDMI driver for the H3 (and A83T, A64...) into the mainline.

Signature · 2 lines
Ken ar c'henta?	|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/
#15 lore raw
In reply to Jean-Francois Moine

Hi,

Quoted 7 lines · Jean-Francois Moine
Quoted 4 lines · On Wed, 6 Jan 2016 22:20:46 +0100 Maxime Ripard…
Quoted 3 lines

As there is no documentation about the DE2 nor about the HDMI which are found in the H3, this driver has been built from Allwiiner's sources.

Quoted 5 lines
Quoted 3 lines

That's unfortunate :/

Have you checked in the A64 BSP if there was some useful information?

Same as the H3: no more information about the display system.

Too bad...

Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

So, there may be license problems, especially for the file de2_hdmi_h3.c which contains a lot of magic values.

I guess it's the biggest issue with your code right now. What licenses issues are we talking about here?

Quoted 7 lines

The documentation about the H3, as the other Allwinner documentations, starts with:

This documentation is the original work and copyrighted property of Allwinner Technology ("Allwinner"). Reproduction in whole or in part must obtain the written approval of Allwinner and give clear acknowledgement to the copyright owner.

I'm not sure this one is an issue. This datasheet is available publicly, and it's common to have a datasheet with restrictions (or even an NDA).

Quoted 5 lines

Then, the DE2 sources contain only:

All Winner Tech, All Right Reserved. 2014-2015 Copyright (c)

Eventually, there is no copyright/author/history in the HDMI sources.

That one is nasty though :/

It seems to be a GPL violation though, so we have two solutions:

A) have a clean room implementation
B) Ask allwinner to comply with the license

The former doesn't look likely to happen soon... Can you open an issue on this on their linux github repo?

Thanks!
Maxime

Signature · 3 lines
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

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

#4 lore raw

Re: [PATCH RFC 1/2] clk: sunxi: Add sun8i display support

In reply to Jean-Francois Moine

Hi,

Quoted 137 lines · Jean-Francois Moine

Add the clock types which are used by the sun8i family for video.

---
 drivers/clk/sunxi/Makefile            |   1 +
 drivers/clk/sunxi/clk-sun8i-display.c | 247 ++++++++++++++++++++++++++++++++++
 2 files changed, 258 insertions(+)
 create mode 100644 drivers/clk/sunxi/clk-sun8i-display.c
drivers/clk/sunxi/Makefile +1 -0
index cb4c299..145c078 100644
@@ -10,6 +10,7 @@ obj-y += clk-a10-pll2.o
 obj-y += clk-a20-gmac.o
 obj-y += clk-mod0.o
 obj-y += clk-simple-gates.o
+obj-y += clk-sun8i-display.o
 obj-y += clk-sun8i-mbus.o
 obj-y += clk-sun9i-core.o
 obj-y += clk-sun9i-mmc.o
drivers/clk/sunxi/clk-sun8i-display.c new file +110 -0
new file mode 100644
index 0000000..eded572
@@ -0,0 +1,247 @@
+/*
+ * Copyright 2015 Jean-Francois Moine <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/clk-provider.h>
+#include <linux/of_address.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+#include <linux/rational.h>
+#include <linux/delay.h>
+
+static DEFINE_SPINLOCK(sun8i_display_lock);
+
+/* PLL3 (video) and PLL10 (de) */
+struct clk_fact {
+	struct clk_hw hw;
+	void __iomem *reg;
+};
+#define to_clk_fact(_hw) container_of(_hw, struct clk_fact, hw)
+
+#define SUN8I_PLL3_MSHIFT	0
+#define SUN8I_PLL3_MMASK	0x0f
+#define SUN8I_PLL3_NSHIFT	8
+#define SUN8I_PLL3_NMASK	0x7f
+#define SUN8I_PLL3_MODE_SEL	0x01000000
+#define SUN8I_PLL3_FRAC_CLK	0x02000000
+
+static int sun8i_pll3_get_fact(unsigned long rate,
+			unsigned long parent_rate,
+			unsigned long *n, unsigned long *m)
+{
+	if (rate == 297000000)
+		return 1;
+	if (rate == 270000000)
+		return 0;
+	rational_best_approximation(rate, parent_rate,
+				SUN8I_PLL3_NMASK + 1, SUN8I_PLL3_MMASK + 1,
+				n, m);
+	return -1;
+}
+
+static unsigned long sun8i_pll3_recalc_rate(struct clk_hw *hw,
+					unsigned long parent_rate)
+{
+	struct clk_fact *fact = to_clk_fact(hw);
+	u32 reg;
+	u32 n, m;
+
+	reg = readl(fact->reg);
+	if (reg & SUN8I_PLL3_MODE_SEL) {
+		n = (reg >> SUN8I_PLL3_NSHIFT) & SUN8I_PLL3_NMASK;
+		m = (reg >> SUN8I_PLL3_MSHIFT) & SUN8I_PLL3_MMASK;
+		return parent_rate / (m + 1) * (n + 1);
+	}
+	if (reg & SUN8I_PLL3_FRAC_CLK)
+		return 297000000;
+	return 270000000;
+}
+
+static long sun8i_pll3_round_rate(struct clk_hw *hw, unsigned long rate,
+				unsigned long *parent_rate)
+{
+	int frac;
+	unsigned long n, m;
+
+	frac = sun8i_pll3_get_fact(rate, *parent_rate, &n, &m);
+	if (frac == 1)
+		return 297000000;
+	if (frac == 0)
+		return 270000000;
+	return (*parent_rate * n) / m;
+}
+
+static int sun8i_pll3_set_rate(struct clk_hw *hw, unsigned long rate,
+			unsigned long parent_rate)
+{
+	struct clk_fact *fact = to_clk_fact(hw);
+	u32 reg;
+	int frac;
+	unsigned long n, m;
+
+	reg = readl(fact->reg) &
+			~(SUN8I_PLL3_MODE_SEL |
+			  SUN8I_PLL3_FRAC_CLK |
+			  (SUN8I_PLL3_NMASK << SUN8I_PLL3_NSHIFT) |
+			  (SUN8I_PLL3_MMASK << SUN8I_PLL3_MSHIFT));
+
+	frac = sun8i_pll3_get_fact(rate, parent_rate, &n, &m);
+	if (frac == 1)
+		reg |= SUN8I_PLL3_FRAC_CLK;	/* 297MHz */
+	else if (frac == 0)
+		;				/* 270MHz */
+	else
+		reg |= SUN8I_PLL3_MODE_SEL |
+			((n - 1) << SUN8I_PLL3_NSHIFT) |
+			((m - 1) << SUN8I_PLL3_MSHIFT);
+
+	writel(reg, fact->reg);
+
+	/* delay 500us so pll stabilizes */

drivers/clk/sunxi/clk-sun8i-display.c line 120

Quoted 10 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +10 -0
+	__delay(500);
+
+	return 0;
+}
+
+static const struct clk_ops clk_sun8i_pll3_fact_ops = {
+	.recalc_rate = sun8i_pll3_recalc_rate,
+	.round_rate = sun8i_pll3_round_rate,
+	.set_rate = sun8i_pll3_set_rate,
+};

We have the clk-factors stuff to handle this easily, could you use that instead ?

Quoted 117 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +117 -0
+
+static void __init sun8i_pll3_setup(struct device_node *node)
+{
+	const char *clk_name = node->name, *parent;
+	struct clk_fact *fact;
+	struct clk_gate *gate;
+	void __iomem *reg;
+	struct clk *clk;
+
+	of_property_read_string(node, "clock-output-names", &clk_name);
+	parent = of_clk_get_parent_name(node, 0);
+
+	reg = of_io_request_and_map(node, 0, of_node_full_name(node));
+	if (IS_ERR(reg)) {
+		pr_err("%s: Could not map the clock registers\n", clk_name);
+		return;
+	}
+
+	gate = kzalloc(sizeof(*gate), GFP_KERNEL);
+	if (!gate)
+		return;
+
+	gate->reg = reg;
+	gate->bit_idx = 31;
+	gate->lock = &sun8i_display_lock;
+
+	fact = kzalloc(sizeof(*fact), GFP_KERNEL);
+	if (!fact)
+		goto free_gate;
+
+	fact->reg = reg;
+
+	clk = clk_register_composite(NULL, clk_name,
+				     &parent, 1,
+				     NULL, NULL,
+				     &fact->hw, &clk_sun8i_pll3_fact_ops,
+				     &gate->hw, &clk_gate_ops,
+				     0);
+	if (IS_ERR(clk)) {
+		pr_err("%s: Couldn't register the clock\n", clk_name);
+		goto free_fact;
+	}
+
+	of_clk_add_provider(node, of_clk_src_simple_get, clk);
+
+	return;
+
+free_fact:
+	kfree(fact);
+free_gate:
+	kfree(gate);
+}
+
+CLK_OF_DECLARE(sun8i_pll3, "allwinner,sun8i-pll3-clk", sun8i_pll3_setup);
+
+/* DE, TCON0, TVE, HDMI, DEINTERLACE  */
+static void __init sun8i_display_setup(struct device_node *node)
+{
+	const char *clk_name = node->name;
+	const char *parents[2];
+	struct clk_mux *mux = NULL;
+	struct clk_divider *div;
+	struct clk_gate *gate;
+	void __iomem *reg;
+	struct clk *clk;
+	int n;
+
+	of_property_read_string(node, "clock-output-names", &clk_name);
+
+	reg = of_io_request_and_map(node, 0, of_node_full_name(node));
+	if (IS_ERR(reg)) {
+		pr_err("%s: Could not map the clock registers\n", clk_name);
+		return;
+	}
+
+	n = of_clk_parent_fill(node, parents, ARRAY_SIZE(parents));
+
+	if (n > 1) {				/* many possible sources */
+		mux = kzalloc(sizeof(*mux), GFP_KERNEL);
+		if (!mux)
+			return;
+		mux->reg = reg;
+		mux->shift = 24;
+		mux->mask = 0x07;
+		mux->lock = &sun8i_display_lock;
+	}
+
+	gate = kzalloc(sizeof(*gate), GFP_KERNEL);
+	if (!gate)
+		goto free_gate;
+
+	gate->reg = reg;
+	gate->bit_idx = 31;
+	gate->lock = &sun8i_display_lock;
+
+	div = kzalloc(sizeof(*div), GFP_KERNEL);
+	if (!div)
+		goto free_gate;
+
+	div->reg = reg;
+	div->shift = 0;
+	div->width = 4;
+	div->lock = &sun8i_display_lock;
+
+	clk = clk_register_composite(NULL, clk_name,
+				     parents, n,
+				     mux ? &mux->hw : NULL, &clk_mux_ops,
+				     &div->hw, &clk_divider_ops,
+				     &gate->hw, &clk_gate_ops,
+				     0);
+	if (IS_ERR(clk)) {
+		pr_err("%s: Couldn't register the clock\n", clk_name);
+		goto free_div;
+	}
+
+	of_clk_add_provider(node, of_clk_src_simple_get, clk);
+

drivers/clk/sunxi/clk-sun8i-display.c line 247

Quoted 10 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +10 -0
+	return;
+
+free_div:
+	kfree(div);
+free_gate:
+	kfree(gate);
+	kfree(mux);
+}
+
+CLK_OF_DECLARE(sun8i_display, "allwinner,sun8i-display-clk", sun8i_display_setup);

As part of my DRM patches, I've added a clk-display clock that can handle that easily.

And actually, as part of bringing up the display engine on the A33, I already did it:
https://github.com/mripard/linux/commit/92b6843b5ee5b70cb2be3638df31d3eca28a4dba
https://github.com/mripard/linux/commit/81e8ea74be5e72124eb584432bb79ff75f90d9ed

Thanks!
Maxime

Signature · 10 lines
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160118/190d887b/attachment.sig>
#5 lore raw

Re: [PATCH RFC 1/2] clk: sunxi: Add sun8i display support

Quoted 8 lines · On Mon, 18 Jan 2016 20:09:04 +0100 Maxime Ripard…

drivers/clk/sunxi/clk-sun8i-display.c line 120

Quoted 5 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +5 -0
+static const struct clk_ops clk_sun8i_pll3_fact_ops = {
+	.recalc_rate = sun8i_pll3_recalc_rate,
+	.round_rate = sun8i_pll3_round_rate,
+	.set_rate = sun8i_pll3_set_rate,
+};

We have the clk-factors stuff to handle this easily, could you use that instead ?

No, the sun6i/8i pll3 offers direct 297MHz and 270MHz.

Quoted 7 lines

As part of my DRM patches, I've added a clk-display clock that can handle that easily.

And actually, as part of bringing up the display engine on the A33, I already did it:
https://github.com/mripard/linux/commit/92b6843b5ee5b70cb2be3638df31d3eca28a4dba
https://github.com/mripard/linux/commit/81e8ea74be5e72124eb584432bb79ff75f90d9ed

I don't remember any patch request from yours in the Linux mailing-lists about these developments.

Otherwise, about this old RFC, Chen-Yu Tsai replied:

Quoted 4 lines
Quoted 1 line

Add the clock types which are used by the sun8i family for video.

These clocks first appeared in the A31.

Quoted 8 lines
Quoted 4 lines
---
 drivers/clk/sunxi/Makefile            |   1 +
 drivers/clk/sunxi/clk-sun8i-display.c | 247 ++++++++++++++++++++++++++++++++++

Please split this into 2 patches, and 2 files: one for PLL3, named clk-sun6i-pll3.c, and one for the display mod clocks, named clk-sun6i-display.c

My new patch series about the H3 display was sent 4 days ago (but not sure it reached the list linux-clk at vger.kernel.org because of some non-ASCII characters).

Signature · 2 lines
A galon		|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/
#16 lore raw
In reply to Maxime Ripard
Quoted 8 lines · On Mon, 18 Jan 2016 11:18:27 +0100 Maxime Ripard…
Quoted 5 lines

Then, the DE2 sources contain only:

All Winner Tech, All Right Reserved. 2014-2015 Copyright (c)

Eventually, there is no copyright/author/history in the HDMI sources.

That one is nasty though :/

Quoted 7 lines

It seems to be a GPL violation though, so we have two solutions:

A) have a clean room implementation
B) Ask allwinner to comply with the license

The former doesn't look likely to happen soon... Can you open an issue on this on their linux github repo?

Do you really think that I could have more luck than people of the linux-sunxi or pine64 teams?

Signature · 2 lines
A galon		|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/
#6 lore raw

Re: [PATCH RFC 1/2] clk: sunxi: Add sun8i display support

In reply to Jean-Francois Moine

Hi,

Quoted 12 lines · Jean-Francois Moine
Quoted 8 lines · On Mon, 18 Jan 2016 20:09:04 +0100 Maxime Ripard…

drivers/clk/sunxi/clk-sun8i-display.c line 120

Quoted 5 lines
drivers/clk/sunxi/clk-sun8i-display.c new file +5 -0
+static const struct clk_ops clk_sun8i_pll3_fact_ops = {
+	.recalc_rate = sun8i_pll3_recalc_rate,
+	.round_rate = sun8i_pll3_round_rate,
+	.set_rate = sun8i_pll3_set_rate,
+};

We have the clk-factors stuff to handle this easily, could you use that instead ?

Quoted 1 line

No, the sun6i/8i pll3 offers direct 297MHz and 270MHz.

That's true, but so far it's something that never has been really needed. This PLL is not the same one using the fractional mode, so I guess we could extend the clk-factors to be able to deal with that. The video pll in the A10 (pll3) is also in this case, so does the A31 PLL3 and PLL4.

Also note that all these clocks can reach those frequencies through what allwinner calls the integer mode, so apart from the hardware readout, we don't really need it anyway.

Quoted 10 lines
Quoted 7 lines

As part of my DRM patches, I've added a clk-display clock that can handle that easily.

And actually, as part of bringing up the display engine on the A33, I already did it:
https://github.com/mripard/linux/commit/92b6843b5ee5b70cb2be3638df31d3eca28a4dba
https://github.com/mripard/linux/commit/81e8ea74be5e72124eb584432bb79ff75f90d9ed

I don't remember any patch request from yours in the Linux mailing-lists about these developments.

Indeed, I was waiting for the first DRM developments to get in before sending those for review.

Quoted 6 lines

Otherwise, about this old RFC, Chen-Yu Tsai replied:

Quoted 3 lines
Quoted 1 line

Add the clock types which are used by the sun8i family for video.

These clocks first appeared in the A31.

The video PLL is, the display engine and tcon clocks are a bit different (mostly because of their weird parent configuration that need a muxing table). Note that I'm talking about the A23 / A33. I haven't checked for the H3.

Thanks!
Maxime

Signature · 10 lines
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160127/0cf1a529/attachment.sig>
#7 lore raw

Re: [PATCH RFC 1/2] clk: sunxi: Add sun8i display support

Quoted 5 lines · On Wed, 27 Jan 2016 22:50:51 +0100 Maxime Ripard…

Hi,

Quoted 2 lines · Jean-Francois Moine

On Mon, 18 Jan 2016 20:09:04 +0100
Maxime Ripard <[email protected]> wrote:

	[snip]
Quoted 11 lines
Quoted 4 lines
Quoted 2 lines

We have the clk-factors stuff to handle this easily, could you use that instead ?

No, the sun6i/8i pll3 offers direct 297MHz and 270MHz.

That's true, but so far it's something that never has been really needed. This PLL is not the same one using the fractional mode, so I guess we could extend the clk-factors to be able to deal with that. The video pll in the A10 (pll3) is also in this case, so does the A31 PLL3 and PLL4.

Quoted 3 lines

Also note that all these clocks can reach those frequencies through what allwinner calls the integer mode, so apart from the hardware readout, we don't really need it anyway.

Maybe it is too simple! 297MHz is the PLL3 frequency which can be used for most video modes. And, so, as it is the default value, in my tests, I never saw the PLL3 set_rate function being called.

	[snip]
Quoted 10 lines
Quoted 5 lines

Otherwise, about this old RFC, Chen-Yu Tsai replied:

Quoted 3 lines
Quoted 1 line

Add the clock types which are used by the sun8i family for video.

These clocks first appeared in the A31.

The video PLL is, the display engine and tcon clocks are a bit different (mostly because of their weird parent configuration that need a muxing table). Note that I'm talking about the A23 / A33. I haven't checked for the H3.

The TCONs of the A23/A33 and H3 SoCs are quite the same. The display engines 2 of the H3/A64/A83T are the same and they ask for a fixed clock (432MHz).

Signature · 2 lines
Ken ar c'henta?	|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/
#17 lore raw
In reply to Jean-Francois Moine
Quoted 13 lines · Jean-Francois Moine
Quoted 10 lines · On Mon, 18 Jan 2016 11:18:27 +0100 Maxime Ripard…
Quoted 5 lines

Then, the DE2 sources contain only:

All Winner Tech, All Right Reserved. 2014-2015 Copyright (c)

Eventually, there is no copyright/author/history in the HDMI sources.

That one is nasty though :/

It seems to be a GPL violation though, so we have two solutions:

Quoted 8 lines
Quoted 5 lines

A) have a clean room implementation
B) Ask allwinner to comply with the license

The former doesn't look likely to happen soon... Can you open an issue on this on their linux github repo?

Do you really think that I could have more luck than people of the linux-sunxi or pine64 teams?

It did work for a few issues in the past...

Maxime

Signature · 10 lines
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160202/549266c0/attachment.sig>