Skip to contentSkip to conversation

Lager HDMI support

RFC In review Ulrich Hecht 3 participants 11 messages Aug 30, 2013 – Sep 11, 2013

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover Lager HDMI support

Hi!

This is an attempt to enable the HDMI output on the Lager board. It is not likely to work as is because I do not have physical access to such a board yet, but it builds and runs, and the devices involved (i2c controller, DU, HDMI encoder) respond as expected.

This work depends on two unmerged drivers (r8a7790 i2c controller and ADV7511 HDMI encoder) that I have included in this patch set.

It appears that the DRM i2c slave code assumes that video encoders are always connected to a local dedicated i2c controller that is instantiated by the GPU driver. This is not so on the Lager board which has the HDMI encoder on a general-purpose i2c bus together with other devices. This makes it difficult for the DU driver to get an i2c_client handle to the encoder. I have solved this by forwarding the handle from the adv7511 driver to the DU driver via their platform_data structures. I'd like to hear if there is a more elegant/correct way to deal with this. (There is for DT, but this is the best C version I could come up with.)

The other question I have is what would be a viable strategy to get this whole mess upstream, particularly the adv7511 driver which requires changes to common DRM code...

CU
Uli

Lars-Peter Clausen (1):
ASoC: Add SPDIF DAI format

Nguyen Viet Dung (3):
i2c: rcar: modify I2C driver
ARM: shmobile: r8a7790: add I2C setup
ARM: shmobile: r8a7790: add I2C clock

Ulrich Hecht (6):
drm: ADV7511 i2c HDMI encoder driver
drm: Decouple edid parsing from i2c adapter
ARM: shmobile: r8a7790: i2c pinmux
ARM: shmobile: r8a7790: lager: i2c support
drm: rcar-du: support for i2c HDMI encoders
ARM: shmobile: r8a7790: lager: HDMI output via DU and ADV7511

 arch/arm/mach-shmobile/board-lager.c          |  56 ++
 arch/arm/mach-shmobile/clock-r8a7790.c        |  11 +
 arch/arm/mach-shmobile/include/mach/r8a7790.h |   3 +
 arch/arm/mach-shmobile/setup-r8a7790.c        |  28 +
 drivers/gpu/drm/Kconfig                       |   6 +
 drivers/gpu/drm/drm_edid.c                    |  18 +-
 drivers/gpu/drm/i2c/Makefile                  |   3 +
 drivers/gpu/drm/i2c/adv7511.h                 | 455 ++++++++++++
 drivers/gpu/drm/i2c/adv7511_audio.c           | 304 ++++++++
 drivers/gpu/drm/i2c/adv7511_core.c            | 981 ++++++++++++++++++++++++++
 drivers/gpu/drm/rcar-du/Makefile              |   1 +
 drivers/gpu/drm/rcar-du/rcar_du_drv.c         |   7 +
 drivers/gpu/drm/rcar-du/rcar_du_drv.h         |   2 +
 drivers/gpu/drm/rcar-du/rcar_du_encoder.c     |  56 +-
 drivers/gpu/drm/rcar-du/rcar_du_encoder.h     |   6 +-
 drivers/gpu/drm/rcar-du/rcar_du_hdmicon.c     | 165 +++++
 drivers/gpu/drm/rcar-du/rcar_du_hdmicon.h     |  28 +
 drivers/i2c/busses/i2c-rcar.c                 |  17 +-
 drivers/pinctrl/sh-pfc/pfc-r8a7790.c          |  90 +++
 include/drm/drm_edid.h                        |   3 +
 include/linux/i2c/i2c-rcar.h                  |   4 +
 include/linux/platform_data/rcar-du.h         |   4 +
 include/sound/soc-dai.h                       |   1 +
 23 files changed, 2236 insertions(+), 13 deletions(-)
 create mode 100644 drivers/gpu/drm/i2c/adv7511.h
 create mode 100644 drivers/gpu/drm/i2c/adv7511_audio.c
 create mode 100644 drivers/gpu/drm/i2c/adv7511_core.c
 create mode 100644 drivers/gpu/drm/rcar-du/rcar_du_hdmicon.c
 create mode 100644 drivers/gpu/drm/rcar-du/rcar_du_hdmicon.h
Signature · 1 line
1.8.1.4
#1 lore raw

RFC 1/10 drm: ADV7511 i2c HDMI encoder driver

ADV7511 driver snapshot taken from commit f416e32 of xcomm_zynq_3_10 branch at
https://github.com/analogdevicesinc/linux.git

Changed to export its i2c_client handle via platform_data, which is the only way I could come up with to use a DRM encoder that is not attached to a dedicated on-GPU i2c bus.

---
 drivers/gpu/drm/Kconfig             |   6 +
 drivers/gpu/drm/i2c/Makefile        |   3 +
 drivers/gpu/drm/i2c/adv7511.h       | 455 +++++++++++++++++
 drivers/gpu/drm/i2c/adv7511_audio.c | 304 +++++++++++
 drivers/gpu/drm/i2c/adv7511_core.c  | 981 ++++++++++++++++++++++++++++++++++++
 5 files changed, 1749 insertions(+)
 create mode 100644 drivers/gpu/drm/i2c/adv7511.h
 create mode 100644 drivers/gpu/drm/i2c/adv7511_audio.c
 create mode 100644 drivers/gpu/drm/i2c/adv7511_core.c
drivers/gpu/drm/Kconfig +6 -0
index a7c54c8..7cd1c29 100644
@@ -200,6 +200,12 @@ config DRM_SAVAGE
 	  Choose this option if you have a Savage3D/4/SuperSavage/Pro/Twister
 	  chipset. If M is selected the module will be called savage.
 
+config DRM_ENCODER_ADV7511
+	tristate "AV7511 encoder"
+	depends on DRM && I2C
+	select REGMAP_I2C
+	select HDMI
+
 source "drivers/gpu/drm/exynos/Kconfig"
 
 source "drivers/gpu/drm/vmwgfx/Kconfig"
drivers/gpu/drm/i2c/Makefile +3 -0
index 43aa33b..ef3a76a 100644
@@ -6,5 +6,8 @@ obj-$(CONFIG_DRM_I2C_CH7006) += ch7006.o
 sil164-y := sil164_drv.o
 obj-$(CONFIG_DRM_I2C_SIL164) += sil164.o
 
+adv7511-y := adv7511_core.o adv7511_audio.o
+obj-$(CONFIG_DRM_ENCODER_ADV7511) += adv7511.o
+
 tda998x-y := tda998x_drv.o
 obj-$(CONFIG_DRM_I2C_NXP_TDA998X) += tda998x.o
drivers/gpu/drm/i2c/adv7511.h new file +455 -0

455 lines not on this page · raw message

drivers/gpu/drm/i2c/adv7511_audio.c new file +304 -0

304 lines not on this page · raw message

drivers/gpu/drm/i2c/adv7511_core.c new file +981 -0

981 lines not on this page · raw message

Signature · 1 line
1.8.1.4
#2 lore raw

Re: [RFC 01/10] drm: ADV7511 i2c HDMI encoder driver

Hi Ulrich,

Thank you for the patch.

Quoted 2 lines · On Friday 30 August 2013 14:37:35 Ulrich Hecht wrote:

ADV7511 driver snapshot taken from commit f416e32 of xcomm_zynq_3_10 branch at https://github.com/analogdevicesinc/linux.git

I believe Lars-Peter (CC'ed) was planning to upstream the driver. Lars-Peter, could you please share your plans ?

Quoted 15 lines

Changed to export its i2c_client handle via platform_data, which is the only way I could come up with to use a DRM encoder that is not attached to a dedicated on-GPU i2c bus.

---
 drivers/gpu/drm/Kconfig             |   6 +
 drivers/gpu/drm/i2c/Makefile        |   3 +
 drivers/gpu/drm/i2c/adv7511.h       | 455 +++++++++++++++++
 drivers/gpu/drm/i2c/adv7511_audio.c | 304 +++++++++++
 drivers/gpu/drm/i2c/adv7511_core.c  | 981 +++++++++++++++++++++++++++++++++
 5 files changed, 1749 insertions(+)
 create mode 100644 drivers/gpu/drm/i2c/adv7511.h
 create mode 100644 drivers/gpu/drm/i2c/adv7511_audio.c
 create mode 100644 drivers/gpu/drm/i2c/adv7511_core.c
Signature · 3 lines
Regards,

Laurent Pinchart
#3 lore raw

Re: [RFC 01/10] drm: ADV7511 i2c HDMI encoder driver

In reply to Ulrich Hecht
Quoted 10 lines · Laurent Pinchart

Hi Ulrich,

Thank you for the patch.

Quoted 2 lines · On Friday 30 August 2013 14:37:35 Ulrich Hecht wrote:

ADV7511 driver snapshot taken from commit f416e32 of xcomm_zynq_3_10 branch at https://github.com/analogdevicesinc/linux.git

I believe Lars-Peter (CC'ed) was planning to upstream the driver. Lars-Peter, could you please share your plans ?

My plan was to have all this upstream long time ago ;)

As I said in that other thread, I don't think it is a good idea to have two drivers for the same device. But if nobody else sees a problem with this and as long as the v4l driver doesn't have devicetree support I guess we could get away with it for now. Even if it will probably haunt us later on.

There are still a few minor bits and pieces to iron out, but lets try to aim for 2.6.13.

- Lars

Quoted 17 lines
Quoted 16 lines

Changed to export its i2c_client handle via platform_data, which is the only way I could come up with to use a DRM encoder that is not attached to a dedicated on-GPU i2c bus.

---
 drivers/gpu/drm/Kconfig             |   6 +
 drivers/gpu/drm/i2c/Makefile        |   3 +
 drivers/gpu/drm/i2c/adv7511.h       | 455 +++++++++++++++++
 drivers/gpu/drm/i2c/adv7511_audio.c | 304 +++++++++++
 drivers/gpu/drm/i2c/adv7511_core.c  | 981 +++++++++++++++++++++++++++++++++
 5 files changed, 1749 insertions(+)
 create mode 100644 drivers/gpu/drm/i2c/adv7511.h
 create mode 100644 drivers/gpu/drm/i2c/adv7511_audio.c
 create mode 100644 drivers/gpu/drm/i2c/adv7511_core.c
#4 lore raw

Re: [RFC 01/10] drm: ADV7511 i2c HDMI encoder driver

In reply to Ulrich Hecht

Hi Lars-Peter,

Quoted 11 lines · On Monday 02 September 2013 15:40:22 Lars-Peter Clausen wrote:
Quoted 7 lines · Laurent Pinchart
Quoted 3 lines · On Friday 30 August 2013 14:37:35 Ulrich Hecht wrote:

ADV7511 driver snapshot taken from commit f416e32 of xcomm_zynq_3_10 branch at https://github.com/analogdevicesinc/linux.git

I believe Lars-Peter (CC'ed) was planning to upstream the driver. Lars-Peter, could you please share your plans ?

My plan was to have all this upstream long time ago ;)

Quoted 7 lines

As I said in that other thread, I don't think it is a good idea to have two drivers for the same device. But if nobody else sees a problem with this and as long as the v4l driver doesn't have devicetree support I guess we could get away with it for now. Even if it will probably haunt us later on.

There are still a few minor bits and pieces to iron out, but lets try to aim for 2.6.13.

If you can make it for 2.6.13 I will be extremely impressed :-)

Do you plan to push the driver yourself ? If so, I would appreciate if you could CC me. If there's just a few minor bits to iron out I can already review your latest version if that can help.

Signature · 3 lines
Regards,

Laurent Pinchart
#5 lore raw

Re: [RFC 01/10] drm: ADV7511 i2c HDMI encoder driver

In reply to Ulrich Hecht
Quoted 19 lines · Laurent Pinchart

Hi Lars-Peter,

Quoted 16 lines · On Monday 02 September 2013 15:40:22 Lars-Peter Clausen wrote:
Quoted 7 lines · Laurent Pinchart
Quoted 3 lines · On Friday 30 August 2013 14:37:35 Ulrich Hecht wrote:

ADV7511 driver snapshot taken from commit f416e32 of xcomm_zynq_3_10 branch at https://github.com/analogdevicesinc/linux.git

I believe Lars-Peter (CC'ed) was planning to upstream the driver. Lars-Peter, could you please share your plans ?

My plan was to have all this upstream long time ago ;)

As I said in that other thread, I don't think it is a good idea to have two drivers for the same device. But if nobody else sees a problem with this and as long as the v4l driver doesn't have devicetree support I guess we could get away with it for now. Even if it will probably haunt us later on.

Quoted 4 lines
Quoted 2 lines

There are still a few minor bits and pieces to iron out, but lets try to aim for 2.6.13.

If you can make it for 2.6.13 I will be extremely impressed :-)

Yea, I know DRM always takes a bit longer...

Quoted 5 lines

Do you plan to push the driver yourself ? If so, I would appreciate if you could CC me. If there's just a few minor bits to iron out I can already review your latest version if that can help.

There are a couple of style issues, so if you review the driver ignore these for now, but otherwise feedback is welcome, thanks. And I'm not also quite happy with the ASoC integration yet.

- Lars

#6 lore raw

Re: [RFC 01/10] drm: ADV7511 i2c HDMI encoder driver

In reply to Ulrich Hecht

Hi Lars-Peter,

Quoted 18 lines · On Monday 02 September 2013 16:43:25 Lars-Peter Clausen wrote:
Quoted 17 lines · Laurent Pinchart
Quoted 16 lines · On Monday 02 September 2013 15:40:22 Lars-Peter Clausen wrote:
Quoted 6 lines · Laurent Pinchart
Quoted 2 lines · On Friday 30 August 2013 14:37:35 Ulrich Hecht wrote:

ADV7511 driver snapshot taken from commit f416e32 of xcomm_zynq_3_10 branch at https://github.com/analogdevicesinc/linux.git

I believe Lars-Peter (CC'ed) was planning to upstream the driver. Lars-Peter, could you please share your plans ?

My plan was to have all this upstream long time ago ;)

As I said in that other thread, I don't think it is a good idea to have two drivers for the same device. But if nobody else sees a problem with this and as long as the v4l driver doesn't have devicetree support I guess we could get away with it for now. Even if it will probably haunt us later on.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

There are still a few minor bits and pieces to iron out, but lets try to aim for 2.6.13.

If you can make it for 2.6.13 I will be extremely impressed :-)

Yea, I know DRM always takes a bit longer...

I think you meant 3.13 ;-)

Quoted 7 lines
Quoted 3 lines

Do you plan to push the driver yourself ? If so, I would appreciate if you could CC me. If there's just a few minor bits to iron out I can already review your latest version if that can help.

There are a couple of style issues, so if you review the driver ignore these for now, but otherwise feedback is welcome, thanks. And I'm not also quite happy with the ASoC integration yet.

Sure. Is the version available from the above branch the latest version ?

Signature · 3 lines
Regards,

Laurent Pinchart
#7 lore raw

Re: [RFC 01/10] drm: ADV7511 i2c HDMI encoder driver

In reply to Ulrich Hecht
Quoted 34 lines · Laurent Pinchart

Hi Lars-Peter,

Quoted 18 lines · On Monday 02 September 2013 16:43:25 Lars-Peter Clausen wrote:
Quoted 17 lines · Laurent Pinchart
Quoted 16 lines · On Monday 02 September 2013 15:40:22 Lars-Peter Clausen wrote:
Quoted 6 lines · Laurent Pinchart
Quoted 2 lines · On Friday 30 August 2013 14:37:35 Ulrich Hecht wrote:

ADV7511 driver snapshot taken from commit f416e32 of xcomm_zynq_3_10 branch at https://github.com/analogdevicesinc/linux.git

I believe Lars-Peter (CC'ed) was planning to upstream the driver. Lars-Peter, could you please share your plans ?

My plan was to have all this upstream long time ago ;)

As I said in that other thread, I don't think it is a good idea to have two drivers for the same device. But if nobody else sees a problem with this and as long as the v4l driver doesn't have devicetree support I guess we could get away with it for now. Even if it will probably haunt us later on.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

There are still a few minor bits and pieces to iron out, but lets try to aim for 2.6.13.

If you can make it for 2.6.13 I will be extremely impressed :-)

Yea, I know DRM always takes a bit longer...

I think you meant 3.13 ;-)

Quoted 4 lines
Quoted 3 lines

Do you plan to push the driver yourself ? If so, I would appreciate if you could CC me. If there's just a few minor bits to iron out I can already review your latest version if that can help.

Quoted 5 lines
Quoted 3 lines

There are a couple of style issues, so if you review the driver ignore these for now, but otherwise feedback is welcome, thanks. And I'm not also quite happy with the ASoC integration yet.

Sure. Is the version available from the above branch the latest version ?

Yes, you can find it here:
https://github.com/analogdevicesinc/linux/tree/xcomm_zynq/drivers/gpu/drm/i2c

Oh and the DT bindings also still need proper documentation.

- Lars

#8 lore raw

Re: [RFC 01/10] drm: ADV7511 i2c HDMI encoder driver

Hi Lars-Peter,

(CC'ing Hans Verkuil and the dri-devel and linux-media mailing lists)

Quoted 29 lines · On Monday 02 September 2013 17:09:11 Lars-Peter Clausen wrote:
Quoted 28 lines · Laurent Pinchart
Quoted 18 lines · On Monday 02 September 2013 16:43:25 Lars-Peter Clausen wrote:
Quoted 17 lines · Laurent Pinchart
Quoted 16 lines · On Monday 02 September 2013 15:40:22 Lars-Peter Clausen wrote:
Quoted 6 lines · Laurent Pinchart
Quoted 2 lines · On Friday 30 August 2013 14:37:35 Ulrich Hecht wrote:

ADV7511 driver snapshot taken from commit f416e32 of xcomm_zynq_3_10 branch at https://github.com/analogdevicesinc/linux.git

I believe Lars-Peter (CC'ed) was planning to upstream the driver. Lars-Peter, could you please share your plans ?

My plan was to have all this upstream long time ago ;)

As I said in that other thread, I don't think it is a good idea to have two drivers for the same device. But if nobody else sees a problem with this and as long as the v4l driver doesn't have devicetree support I guess we could get away with it for now. Even if it will probably haunt us later on.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

There are still a few minor bits and pieces to iron out, but lets try to aim for 2.6.13.

If you can make it for 2.6.13 I will be extremely impressed :-)

Yea, I know DRM always takes a bit longer...

I think you meant 3.13 ;-)

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

Do you plan to push the driver yourself ? If so, I would appreciate if you could CC me. If there's just a few minor bits to iron out I can already review your latest version if that can help.

There are a couple of style issues, so if you review the driver ignore these for now, but otherwise feedback is welcome, thanks. And I'm not also quite happy with the ASoC integration yet.

I'll thus concentrate on the video part in the review. Any chance to get the video portion to mainline first and then add audio support ?

Quoted 5 lines
Quoted 1 line

Sure. Is the version available from the above branch the latest version ?

Yes, you can find it here:
https://github.com/analogdevicesinc/linux/tree/xcomm_zynq/drivers/gpu/drm/
i2c

Thank you.

Quoted 1 line

Oh and the DT bindings also still need proper documentation.

I've squashed all the patches together and have copied the result below.

Quoted 10 lines

From f7c27f204cab3d7dcaa128880c0d9ef1ae0e2fc6 Mon Sep 17 00:00:00 2001
From: Lars-Peter Clausen <[email protected]>
Date: Mon, 5 Mar 2012 16:30:57 +0100
Subject: [PATCH] DRM: Add adv7511 encoder driver

This patch adds a driver for the Analog Devices adv7511. The adv7511 is a standalone HDMI transmitter chip. It features a HDMI output interface on one end and video and audio input interfaces on the other.

Quoted 10 lines
---
 drivers/gpu/drm/Kconfig             |   6 +
 drivers/gpu/drm/i2c/Makefile        |   3 +
 drivers/gpu/drm/i2c/adv7511.h       | 454 +++++++++++++++++
 drivers/gpu/drm/i2c/adv7511_audio.c | 304 +++++++++++
 drivers/gpu/drm/i2c/adv7511_core.c  | 979 +++++++++++++++++++++++++++++++++
 5 files changed, 1746 insertions(+)
 create mode 100644 drivers/gpu/drm/i2c/adv7511.h
 create mode 100644 drivers/gpu/drm/i2c/adv7511_audio.c
 create mode 100644 drivers/gpu/drm/i2c/adv7511_core.c

First of all, please run checkpatch.pl on the code :-)

drivers/gpu/drm/Kconfig config DRM_SAVAGE · line 207

Quoted 13 lines
drivers/gpu/drm/Kconfig +5 -0
index 626bc0c..d8862a4 100644
@@ -200,6 +200,12 @@ config DRM_SAVAGE
 	  Choose this option if you have a Savage3D/4/SuperSavage/Pro/Twister
 	  chipset. If M is selected the module will be called savage.
 
+config DRM_ENCODER_ADV7511
+	tristate "AV7511 encoder"
+	depends on DRM && I2C
+	select REGMAP_I2C
+	select HDMI

Beside adding a help text, you should also depend on and/or select SND_SOC.

Quoted 4 lines
drivers/gpu/drm/Kconfig +1 -0
+
 source "drivers/gpu/drm/exynos/Kconfig"
 
 source "drivers/gpu/drm/vmwgfx/Kconfig"

[snip]

Quoted 8 lines
drivers/gpu/drm/i2c/adv7511.h new file +2 -0
new file mode 100644
index 0000000..4631fcd6
@@ -0,0 +1,454 @@
+/**
+ * Analog Devices ADV7511 HDMI transmitter driver

drivers/gpu/drm/i2c/adv7511.h line 12

Quoted 10 lines
drivers/gpu/drm/i2c/adv7511.h new file +10 -0
+ *
+ * Copyright 2012 Analog Devices Inc.
+ *
+ * Licensed under the GPL-2.
+ */
+
+#ifndef __ADV7511_H__
+#define __ADV7511_H__
+
+#include <linux/hdmi.h>

This file should be split in two headers, one with platform data that will go to include/linux/platform_data/, and another one that can stay here.

Quoted 10 lines
drivers/gpu/drm/i2c/adv7511.h new file +10 -0
+#define ADV7511_REG_CHIP_REVISION		0x00
+#define ADV7511_REG_N0				0x01
+#define ADV7511_REG_N1				0x02
+#define ADV7511_REG_N2				0x03
+#define ADV7511_REG_SPDIF_FREQ			0x04
+#define ADV7511_REG_CTS_AUTOMATIC1		0x05
+#define ADV7511_REG_CTS_AUTOMATIC2		0x06
+#define ADV7511_REG_CTS_MANUAL0			0x07
+#define ADV7511_REG_CTS_MANUAL1			0x08
+#define ADV7511_REG_CTS_MANUAL2			0x09

[snip]

drivers/gpu/drm/i2c/adv7511.h line 91

Quoted 2 lines
drivers/gpu/drm/i2c/adv7511.h new file +2 -0
+#define ADV7511_CSC_ENABLE			BIT(7)
+#define ADV7511_CSC_UPDATE_MODE			BIT(5)

I would have added the bits right after the register they refer to, but that's up to you.

[snip]

Quoted 1 line

+#include <drm/drmP.h>

You can move the include at the beginning of the file.

drivers/gpu/drm/i2c/adv7511.h line 192

Quoted 3 lines
drivers/gpu/drm/i2c/adv7511.h new file +3 -0
+struct i2c_client;
+struct regmap;
+struct adv7511;

Nitpicking, you could sort the structures alphabetically.

Quoted 29 lines
drivers/gpu/drm/i2c/adv7511.h new file +29 -0
+int adv7511_packet_enable(struct adv7511 *adv7511, unsigned int packet);
+int adv7511_packet_disable(struct adv7511 *adv7511, unsigned int packet);
+
+int adv7511_audio_init(struct device *dev);
+void adv7511_audio_exit(struct device *dev);
+
+/**
+ * enum adv7511_input_style - Selects the input format style
+ * ADV7511_INPUT_STYLE1: Use input style 1
+ * ADV7511_INPUT_STYLE2: Use input style 2
+ * ADV7511_INPUT_STYLE3: Use input style 3
+ **/
+enum adv7511_input_style {
+	ADV7511_INPUT_STYLE1 = 2,
+	ADV7511_INPUT_STYLE2 = 1,
+	ADV7511_INPUT_STYLE3 = 3,
+};
+
+/**
+ * enum adv7511_input_id - Selects the input format id
+ * @ADV7511_INPUT_ID_24BIT_RGB444_YCbCr444: Input pixel format is 24-bit
+ *					    444 RGB or 444 YCbCR with separate syncs
+ * @ADV7511_INPUT_ID_16_20_24BIT_YCbCr422_SEPARATE_SYNC:
+ * @ADV7511_INPUT_ID_16_20_24BIT_YCbCr422_EMBEDDED_SYNC:
+ * @ADV7511_INPUT_ID_8_10_12BIT_YCbCr422_SEPARATE_SYNC:
+ * @ADV7511_INPUT_ID_8_10_12BIT_YCbCr422_EMBEDDED_SYNC:
+ * @ADV7511_INPUT_ID_12_15_16BIT_RGB444_YCbCr444:
+ **/
+enum adv7511_input_id {

drivers/gpu/drm/i2c/adv7511.h

Quoted 10 lines
drivers/gpu/drm/i2c/adv7511.h new file +10 -0
+	ADV7511_INPUT_ID_24BIT_RGB444_YCbCr444 = 0,
+	ADV7511_INPUT_ID_16_20_24BIT_YCbCr422_SEPARATE_SYNC = 1,
+	ADV7511_INPUT_ID_16_20_24BIT_YCbCr422_EMBEDDED_SYNC = 2,
+	ADV7511_INPUT_ID_8_10_12BIT_YCbCr422_SEPARATE_SYNC = 3,
+	ADV7511_INPUT_ID_8_10_12BIT_YCbCr422_EMBEDDED_SYNC = 4,
+	ADV7511_INPUT_ID_12_15_16BIT_RGB444_YCbCr444 = 5,
+};
+
+/**
+ * enum adv7511_input_bit_justifiction - Selects the input format bit 

justifiction

Quoted 1 line

+ * ADV7511_INPUT_BIT_JUSTIFICATION_EVENLY: Input bits are evenly

distributed

Quoted 1 line

+ * ADV7511_INPUT_BIT_JUSTIFICATION_RIGHT: Input bit signals have right

justification

Quoted 1 line

+ * ADV7511_INPUT_BIT_JUSTIFICATION_LEFT: Input bit signals have left

justification

drivers/gpu/drm/i2c/adv7511.h

Quoted 10 lines

+ **/

drivers/gpu/drm/i2c/adv7511.h new file +9 -0
+enum adv7511_input_bit_justifiction {
+	ADV7511_INPUT_BIT_JUSTIFICATION_EVENLY = 0,
+	ADV7511_INPUT_BIT_JUSTIFICATION_RIGHT = 1,
+	ADV7511_INPUT_BIT_JUSTIFICATION_LEFT = 2,
+};
+
+/**
+ * enum adv7511_input_color_depth - Selects the input format color depth
+ * @ADV7511_INPUT_COLOR_DEPTH_8BIT: Input format color depth is 8 bits per 

channel

Quoted 1 line

+ * @ADV7511_INPUT_COLOR_DEPTH_10BIT: Input format color dpeth is 10 bits

per channel

Quoted 1 line

+ * @ADV7511_INPUT_COLOR_DEPTH_12BIT: Input format color depth is 12 bits

per channel

drivers/gpu/drm/i2c/adv7511.h line 253

Quoted 6 lines

+ **/

drivers/gpu/drm/i2c/adv7511.h new file +5 -0
+enum adv7511_input_color_depth {
+	ADV7511_INPUT_COLOR_DEPTH_8BIT = 3,
+	ADV7511_INPUT_COLOR_DEPTH_10BIT = 1,
+	ADV7511_INPUT_COLOR_DEPTH_12BIT = 2,
+};

Those enums describe the video format at the chip input. This can be configured statically from platform data or DT, but some platforms might need to setup formats dynamically at runtime. For instance the ADV7511 could be driven by a mux with two inputs using different formats.

For these reasons I would combine all those enums in a single one that lists all possible input formats. The formats should be standardized and moved to a separate header file. Get and set format operations will be needed (this is something CDF will address :-)).

Quoted 4 lines
drivers/gpu/drm/i2c/adv7511.h new file +4 -0
+
+/**
+ * enum adv7511_input_sync_pulse - Selects the sync pulse
+ * @ADV7511_INPUT_SYNC_PULSE_DE: Use the DE signal as sync pulse

drivers/gpu/drm/i2c/adv7511.h line 267

Quoted 10 lines
drivers/gpu/drm/i2c/adv7511.h new file +10 -0
+ * @ADV7511_INPUT_SYNC_PULSE_HSYNC: Use the HSYNC signal as sync pulse
+ * @ADV7511_INPUT_SYNC_PULSE_VSYNC: Use the VSYNC signal as sync pulse
+ * @ADV7511_INPUT_SYNC_PULSE_NONE: No external sync pulse signal
+ **/
+enum adv7511_input_sync_pulse {
+	ADV7511_INPUT_SYNC_PULSE_DE = 0,
+	ADV7511_INPUT_SYNC_PULSE_HSYNC = 1,
+	ADV7511_INPUT_SYNC_PULSE_VSYNC = 2,
+	ADV7511_INPUT_SYNC_PULSE_NONE = 3,
+};

This property should also be standardized. It might make sense to define new display flags (include/video/display_timing.h), but a separate enum is possible as well.

Quoted 32 lines
drivers/gpu/drm/i2c/adv7511.h new file +32 -0
+/**
+ * enum adv7511_input_clock_delay - Delay for the video data input clock
+ * @ADV7511_INPUT_CLOCK_DELAY_MINUS_1200PS: -1200 pico seconds delay
+ * @ADV7511_INPUT_CLOCK_DELAY_MINUS_800PS: -800 pico seconds delay
+ * @ADV7511_INPUT_CLOCK_DELAY_MINUS_400PS: -400 pico seconds delay
+ * @ADV7511_INPUT_CLOCK_DELAY_NONE: No delay
+ * @ADV7511_INPUT_CLOCK_DELAY_PLUS_400PS: 400 pico seconds delay
+ * @ADV7511_INPUT_CLOCK_DELAY_PLUS_800PS: 800 pico seconds delay
+ * @ADV7511_INPUT_CLOCK_DELAY_PLUS_1200PS: 1200 pico seconds delay
+ * @ADV7511_INPUT_CLOCK_DELAY_PLUS_1600PS: 1600 pico seconds delay
+ **/
+enum adv7511_input_clock_delay {
+	ADV7511_INPUT_CLOCK_DELAY_MINUS_1200PS = 0,
+	ADV7511_INPUT_CLOCK_DELAY_MINUS_800PS = 1,
+	ADV7511_INPUT_CLOCK_DELAY_MINUS_400PS = 2,
+	ADV7511_INPUT_CLOCK_DELAY_NONE = 3,
+	ADV7511_INPUT_CLOCK_DELAY_PLUS_400PS = 4,
+	ADV7511_INPUT_CLOCK_DELAY_PLUS_800PS = 5,
+	ADV7511_INPUT_CLOCK_DELAY_PLUS_1200PS = 6,
+	ADV7511_INPUT_CLOCK_DELAY_PLUS_1600PS = 7,
+};
+
+/**
+ * enum adv7511_sync_polarity - Polarity for the input sync signals
+ * ADV7511_SYNC_POLARITY_PASSTHROUGH:  Sync polarity matches that of the
+ *				    currently configured mode.
+ * ADV7511_SYNC_POLARITY_LOW:	    Sync polarity is low
+ * ADV7511_SYNC_POLARITY_HIGH:	    Sync polarity is high
+ *
+ * If the polarity is set to either ADV7511_SYNC_POLARITY_LOW or
+ * ADV7511_SYNC_POLARITY_HIGH the ADV7511 will internally invert the signal
+ * if it is required to match the sync polarity setting for the currently

drivers/gpu/drm/i2c/adv7511.h line 309

Quoted 10 lines
drivers/gpu/drm/i2c/adv7511.h new file +10 -0
+ * selected mode. If the polarity is set to
+ * ADV7511_SYNC_POLARITY_PASSTHROUGH, the ADV7511 will route the signal
+ * unchanged, this is useful if the upstream graphics core will already
+ * generate the sync singals with the correct polarity.
+ **/
+enum adv7511_sync_polarity {
+	ADV7511_SYNC_POLARITY_PASSTHROUGH,
+	ADV7511_SYNC_POLARITY_LOW,
+	ADV7511_SYNC_POLARITY_HIGH,
+};

This property should be standardized as well.

Quoted 2 lines

+/**
+ * enum adv7511_timing_gen_seq - Selects the order in which timing

adjustments are performed

Quoted 1 line

+ * @ADV7511_TIMING_GEN_SEQ_SYN_ADJ_FIRST: Sync adjustment first, then DE

generation

Quoted 1 line

+ * @ADV7511_TIMING_GEN_SEQ_DE_GEN_FIRST: DE generation first, then sync

adjustment

Quoted 2 lines

+ *
+ * This setting is only relevant if both DE generation and sync adjustment

are

Quoted 8 lines

+ * active.
+ **/

drivers/gpu/drm/i2c/adv7511.h new file +6 -0
+enum adv7511_timing_gen_seq {
+    ADV7511_TIMING_GEN_SEQ_SYN_ADJ_FIRST = 0,
+    ADV7511_TIMING_GEN_SEQ_DE_GEN_FIRST = 1,
+};
+
+/**

drivers/gpu/drm/i2c/adv7511.h line 334

Quoted 10 lines
drivers/gpu/drm/i2c/adv7511.h new file +10 -0
+ * enum adv7511_up_conversion - Selects the upscaling conversion method
+ * @ADV7511_UP_CONVERSION_ZERO_ORDER: Use zero order up conversion
+ * @ADV7511_UP_CONVERSION_FIRST_ORDER: Use first order up conversion
+ *
+ * This used when converting from a 4:2:2 format to a 4:4:4 format.
+ **/
+enum adv7511_up_conversion {
+    ADV7511_UP_CONVERSION_ZERO_ORDER = 0,
+    ADV7511_UP_CONVERSION_FIRST_ORDER = 1,
+};

How is the upscaling conversion method supposed to be selected ? What does it depend on ?

Quoted 68 lines
drivers/gpu/drm/i2c/adv7511.h new file +68 -0
+/**
+ * struct adv7511_link_config - Describes adv7511 hardware configuration
+ * @id:				Video input format id
+ * @input_style:		Video input format style
+ * @sync_pulse:			Select the sync pulse
+ * @clock_delay:		Clock delay for the input clock
+ * @reverse_bitorder:		Reverse video input signal bitorder
+ * @bit_justification:		Video input format bit justification
+ * @up_conversion:		Selects the upscaling conversion method
+ * @input_color_depth:		Input video format color depth
+ * @tmds_clock_inversion:	Whether to invert the TDMS clock
+ * @vsync_polartity:		vsync input signal configuration
+ * @hsync_polartity:		hsync input signal configuration
+ * @timing_gen_seq:		Selects the order in which sync DE generation
+ *				and sync adjustment are performt.
+ * @gpio_pd:			GPIO controlling the PD (powerdown) pin
+ **/
+struct adv7511_link_config {
+	enum adv7511_input_id id;
+	enum adv7511_input_style input_style;
+	enum adv7511_input_sync_pulse sync_pulse;
+	enum adv7511_input_clock_delay clock_delay;
+	bool reverse_bitorder;
+	enum adv7511_input_bit_justifiction bit_justification;
+	enum adv7511_up_conversion up_conversion;
+	enum adv7511_input_color_depth input_color_depth;
+	bool tmds_clock_inversion;
+	enum adv7511_timing_gen_seq timing_gen_seq;
+
+	enum adv7511_sync_polarity vsync_polarity;
+	enum adv7511_sync_polarity hsync_polarity;
+
+	int gpio_pd;
+};
+
+/**
+	adi,input-style = 1|2|3;
+	adi,input-id = 
+		"24-bit-rgb444-ycbcr444",
+		"16-20-24-bit-ycbcr422-separate-sync" |
+		"16-20-24-bit-ycbcr422-embedded-sync" |
+		"8-10-12-bit-ycbcr422-separate-sync" |
+		"8-10-12-bit-ycbcr422-embedded-sync" |
+		"12-15-16-bit-rgb444-ycbcr444"
+	adi,sync-pulse = "de","vsync","hsync","none"
+	adi,clock-delay = -1200|-800|-400|0|400|800|1200|1600
+	adi,reverse-bitorder
+	adi,bit-justification = "left"|"right"|"evently";
+	adi,up-conversion = "zero-order"|"first-order"
+	adi,input-color-depth = 8|10|12
+	adi,tdms-clock-inversion
+	adi,vsync-polarity = "low"|"high"|"passthrough"
+	adi,hsync-polarity = "low"|"high"|"passtrhough"
+	adi,timing-gen-seq = "sync-adjustment-first"|"de-generation-first"
+*/
+
+/**
+ * enum adv7511_csc_scaling - Scaling factor for the ADV7511 CSC
+ * @ADV7511_CSC_SCALING_1: CSC results are not scaled
+ * @ADV7511_CSC_SCALING_2: CSC results are scaled by a factor of two
+ * @ADV7511_CSC_SCALING_4: CSC results are scalled by a factor of four
+ **/
+enum adv7511_csc_scaling {
+	ADV7511_CSC_SCALING_1 = 0,
+	ADV7511_CSC_SCALING_2 = 1,
+	ADV7511_CSC_SCALING_4 = 2,
+};
+

drivers/gpu/drm/i2c/adv7511.h line 414

Quoted 10 lines
drivers/gpu/drm/i2c/adv7511.h new file +10 -0
+/**
+ * struct adv7511_video_config - Describes adv7511 hardware configuration
+ * @csc_enable:			Whether to enable color space conversion
+ * @csc_scaling_factor:		Color space conversion scaling factor
+ * @csc_coefficents:		Color space conversion coefficents
+ * @hdmi_mode:			Whether to use HDMI or DVI output mode
+ * @avi_infoframe:		HDMI infoframe
+ **/
+struct adv7511_video_config {
+	bool csc_enable;

Shouldn't this be automatically computed based on the input and output formats ?

drivers/gpu/drm/i2c/adv7511.h line 416

Quoted 2 lines
drivers/gpu/drm/i2c/adv7511.h new file +2 -0
+	enum adv7511_csc_scaling csc_scaling_factor;
+	const uint16_t *csc_coefficents;

Do the coefficients need to be configured freely, or could presets do ?

Review

Quoted 39 lines
drivers/gpu/drm/i2c/adv7511.h new file +38 -0
+	bool hdmi_mode;
+	struct hdmi_avi_infoframe avi_infoframe;
+};
+
+struct adv7511 {
+	struct i2c_client *i2c_main;
+	struct i2c_client *i2c_edid;
+	struct i2c_client *i2c_packet;
+	struct i2c_client *i2c_cec;
+
+	struct regmap *regmap;
+	struct regmap *packet_memory_regmap;
+	enum drm_connector_status status;
+	int dpms_mode;
+
+	unsigned int f_tmds;
+	unsigned int f_audio;
+
+	unsigned int audio_source;
+
+	unsigned int current_edid_segment;
+	uint8_t edid_buf[256];
+
+	wait_queue_head_t wq;
+	struct drm_encoder *encoder;
+
+	bool embedded_sync;
+	enum adv7511_sync_polarity vsync_polarity;
+	enum adv7511_sync_polarity hsync_polarity;
+
+	struct edid *edid;
+
+	int gpio_pd;
+};
+
+struct edid *adv7511_get_edid(struct drm_encoder *encoder);
+
+#endif
(quoted diff) +0 -0

b/drivers/gpu/drm/i2c/adv7511_audio.c

Quoted 10 lines

new file mode 100644
index 0000000..746f383

drivers/gpu/drm/i2c/adv7511_audio.c new file +5 -0
@@ -0,0 +1,304 @@
+/**
+ * Analog Devices ADV7511 HDMI transmitter driver
+ *
+ * Copyright 2012 Analog Devices Inc.
+ *

drivers/gpu/drm/i2c/adv7511_audio.c line 15

Quoted 10 lines
drivers/gpu/drm/i2c/adv7511_audio.c new file +10 -0
+ * Licensed under the GPL-2.
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/pm.h>
+#include <linux/i2c.h>
+#include <linux/spi/spi.h>

Is this header needed ?

drivers/gpu/drm/i2c/adv7511_audio.c line 22

Quoted 7 lines
drivers/gpu/drm/i2c/adv7511_audio.c new file +7 -0
+#include <linux/slab.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+#include <sound/initval.h>
+#include <sound/tlv.h>

What about sorting the headers alphabetically ? :-)

Quoted 2 lines
drivers/gpu/drm/i2c/adv7511_audio.c new file +2 -0
+
+#include "adv7511.h"

[snip]

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/gpu/drm/i2c/adv7511_core.c

Quoted 16 lines

new file mode 100644
index 0000000..f26151d

drivers/gpu/drm/i2c/adv7511_core.c new file +11 -0
@@ -0,0 +1,979 @@
+/**
+ * Analog Devices ADV7511 HDMI transmitter driver
+ *
+ * Copyright 2012 Analog Devices Inc.
+ *
+ * Licensed under the GPL-2.
+ */
+
+#include <linux/slab.h>
+#include <linux/module.h>
+#include <linux/i2c.h>

drivers/gpu/drm/i2c/adv7511_core.c line 21

Quoted 10 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +10 -0
+#include <linux/regmap.h>
+#include <linux/gpio.h>
+#include <linux/of_gpio.h>
+
+#include "adv7511.h"
+
+#include <drm/drmP.h>
+#include <drm/drm_crtc_helper.h>
+#include <drm/drm_encoder_slave.h>
+#include <drm/drm_edid.h>

Alphabetical order as well ?

Quoted 61 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +61 -0
+static const uint8_t adv7511_register_defaults[] = {
+	0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00 */
+	0x00, 0x00, 0x01, 0x0e, 0xbc, 0x18, 0x01, 0x13,
+	0x25, 0x37, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 10 */
+	0x46, 0x62, 0x04, 0xa8, 0x00, 0x00, 0x1c, 0x84,
+	0x1c, 0xbf, 0x04, 0xa8, 0x1e, 0x70, 0x02, 0x1e, /* 20 */
+	0x00, 0x00, 0x04, 0xa8, 0x08, 0x12, 0x1b, 0xac,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 30 */
+	0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0xb0,
+	0x00, 0x50, 0x90, 0x7e, 0x79, 0x70, 0x00, 0x00, /* 40 */
+	0x00, 0xa8, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x02, 0x0d, 0x00, 0x00, 0x00, 0x00, /* 50 */
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 60 */
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x01, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 70 */
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 80 */
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, /* 90 */
+	0x0b, 0x02, 0x00, 0x18, 0x5a, 0x60, 0x00, 0x00,
+	0x00, 0x00, 0x80, 0x80, 0x08, 0x04, 0x00, 0x00, /* a0 */
+	0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x40, 0x14,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* b0 */
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* c0 */
+	0x00, 0x03, 0x00, 0x00, 0x02, 0x00, 0x01, 0x04,
+	0x30, 0xff, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, /* d0 */
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x01,
+	0x80, 0x75, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, /* e0 */
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x75, 0x11, 0x00, /* f0 */
+	0x00, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+};
+
+/* ADI recommanded values for proper operation. */
+static const struct reg_default adv7511_fixed_registers[] = {
+	{ 0x98, 0x03 },
+	{ 0x9a, 0xe0 },
+	{ 0x9c, 0x30 },
+	{ 0x9d, 0x61 },
+	{ 0xa2, 0xa4 },
+	{ 0xa3, 0xa4 },
+	{ 0xe0, 0xd0 },
+	{ 0xf9, 0x00 },
+	{ 0x55, 0x02 },
+};
+
+static struct adv7511 *encoder_to_adv7511(struct drm_encoder *encoder)
+{
+	return to_encoder_slave(encoder)->slave_priv;
+}
+
+static void adv7511_set_colormap(struct adv7511 *adv7511, bool enable,
+	const uint16_t *coeff, unsigned int scaling_factor)
+{
+	unsigned int i;
+
+	regmap_update_bits(adv7511->regmap, ADV7511_REG_CSC_UPPER(1),
+		ADV7511_CSC_UPDATE_MODE, ADV7511_CSC_UPDATE_MODE);
+

drivers/gpu/drm/i2c/adv7511_core.c line 93

Quoted 10 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +10 -0
+	if (enable) {
+		for (i = 0; i < 12; ++i) {
+			regmap_update_bits(adv7511->regmap,
+				ADV7511_REG_CSC_UPPER(i),
+				0x1f, coeff[i] >> 8);
+			regmap_write(adv7511->regmap,
+				ADV7511_REG_CSC_LOWER(i),
+				coeff[i] & 0xff);
+		}
+	}

You could move this in the first branch of the following if.

drivers/gpu/drm/i2c/adv7511_core.c line 100

Quoted 7 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +7 -0
+
+	if (enable) {
+		regmap_update_bits(adv7511->regmap, ADV7511_REG_CSC_UPPER(0),
+			0xe0, 0x80 | (scaling_factor << 5));
+	} else {
+		regmap_update_bits(adv7511->regmap, ADV7511_REG_CSC_UPPER(0),
+			0x80, 0x00);

Could you add #defines for register fields instead of using numerical values (for values used here and below) ?

Quoted 12 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +12 -0
+	}
+
+	regmap_update_bits(adv7511->regmap, ADV7511_REG_CSC_UPPER(1),
+		ADV7511_CSC_UPDATE_MODE, 0);
+}
+
+#define ADV7511_HDMI_CFG_MODE_MASK 0x2
+#define ADV7511_HDMI_CFG_MODE_DVI 0x0
+#define ADV7511_HDMI_CFG_MODE_HDMI 0x2
+
+#define ADV7511_PACKET_MEM_SPD		0
+#define ADV7511_PACKET_MEM_MPEG		1

drivers/gpu/drm/i2c/adv7511_core.c line 122

Quoted 10 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +10 -0
+#define ADV7511_PACKET_MEM_ACP		2
+#define ADV7511_PACKET_MEM_ISRC1	3
+#define ADV7511_PACKET_MEM_ISRC2	4
+#define ADV7511_PACKET_MEM_GM		5
+#define ADV7511_PACKET_MEM_SPARE1	6
+#define ADV7511_PACKET_MEM_SPARE2	7
+
+#define ADV7511_PACKET_MEM_DATA_REG(x) ((x) * 0x20)
+#define ADV7511_PACKET_MEM_UPDATE_REG(x) ((x) * 0x20 + 0x1f)
+#define ADV7511_PACKET_MEM_UPDATE_ENABLE BIT(7)

Should this be moved to the adv7511.h header ?

drivers/gpu/drm/i2c/adv7511_core.c line 123

Quoted 1 line
drivers/gpu/drm/i2c/adv7511_core.c new file +1 -0
+#if 0

This should obviously be removed or used :-)

Quoted 33 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +33 -0
+static void adv7511_program_infoframe(struct adv7511 *adv7511,
+	const void *buffer, size_t size, unsigned int reg)
+{
+	unsigned int data_reg, update_reg;
+	unsigned int update_bit;
+
+	switch (type) {
+	case AVI:
+		regmap = adv7511->regmap;
+		data_reg = ADV7511_REG_AVI_INFOFRAME_VERSION;
+		update_reg = ADV7511_REG_INFOFRAME_UPDATE;
+		update_bit = BIT(6);
+		break;
+	case AUDIO:
+		regmap = adv7511->regmap;
+		data_reg = ADV7511_REG_AUDIO_INFOFRAME_VERSION;
+		update_reg = ADV7511_REG_INFOFRAME_UPDATE;
+		update_bit = BIT(5);
+		break;
+	case GC:
+		regmap = adv7511->regmap;
+		data_reg = ADV7511_REG_GC(0);
+		update_reg = ADV7511_REG_INFOFRAME_UPDATE;
+		update_bit = BIT(4);
+		break;
+	case SPD:
+		regmap = adv7511->packet_memory_regmap;
+		data_reg = ADV7511_PACKET_MEM_DATA_REG(ADV7511_PACKET_MEM_SPD);
+		data_reg = ADV7511_PACKET_MEM_UPDATE_REG(ADV7511_PACKET_MEM_SPD);
+		update_bit = ADV7511_PACKET_MEM_UPDATE_ENABLE;
+		break;
+	}
+

drivers/gpu/drm/i2c/adv7511_core.c line 166

Quoted 10 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +10 -0
+	regmap_update_bits(adv7511->regmap, update_reg, update_bit, update_bit);
+
+	regmap_bulk_write(adv7511->regmap, data_reg, buffer, size);
+
+	regmap_update_bits(adv7511->regmap, update_reg, update_bit, 0);
+}
+
+#endif
+
+static void adv7511_set_config(struct drm_encoder *encoder, void *c)

Now we're getting to the controversial point.

What bothers me about the DRM encoder slave API is that the display controller driver needs to be aware of the details of the slave encoder, as it needs to pass an encoder-specific configuration structure to the .set_config() operation. The question would thus be, what about using the Common Display Framework ?

Quoted 97 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +97 -0
+{
+	struct adv7511 *adv7511 = encoder_to_adv7511(encoder);
+	struct adv7511_video_config *config = c;
+	bool output_format_422, output_format_ycbcr;
+	unsigned int mode;
+	uint8_t infoframe[17];
+
+	if (config->hdmi_mode) {
+		mode = ADV7511_HDMI_CFG_MODE_HDMI;
+
+		switch (config->avi_infoframe.colorspace) {
+		case HDMI_COLORSPACE_YUV444:
+			output_format_422 = false;
+			output_format_ycbcr = true;
+			break;
+		case HDMI_COLORSPACE_YUV422:
+			output_format_422 = true;
+			output_format_ycbcr = true;
+			break;
+		default:
+			output_format_422 = false;
+			output_format_ycbcr = false;
+			break;
+		}
+	} else {
+		mode = ADV7511_HDMI_CFG_MODE_DVI;
+		output_format_422 = false;
+		output_format_ycbcr = false;
+	}
+
+	adv7511_packet_disable(adv7511, ADV7511_PACKET_ENABLE_AVI_INFOFRAME);
+
+	adv7511_set_colormap(adv7511, config->csc_enable,
+		config->csc_coefficents, config->csc_scaling_factor);
+
+	regmap_update_bits(adv7511->regmap, ADV7511_REG_VIDEO_INPUT_CFG1, 0x81,
+		(output_format_422 << 7) | output_format_ycbcr);
+
+	regmap_update_bits(adv7511->regmap, ADV7511_REG_HDCP_HDMI_CFG,
+		ADV7511_HDMI_CFG_MODE_MASK, mode);
+
+	hdmi_avi_infoframe_pack(&config->avi_infoframe, infoframe,
+		sizeof(infoframe));
+
+	/* The AVI infoframe id is not configurable */
+	regmap_bulk_write(adv7511->regmap, ADV7511_REG_AVI_INFOFRAME_VERSION,
+		infoframe + 1, sizeof(infoframe) - 1);
+
+	adv7511_packet_enable(adv7511, ADV7511_PACKET_ENABLE_AVI_INFOFRAME);
+}
+
+static void adv7511_set_link_config(struct adv7511 *adv7511,
+	const struct adv7511_link_config *config)
+{
+	enum adv7511_input_sync_pulse sync_pulse;
+
+	switch (config->id) {
+	case ADV7511_INPUT_ID_12_15_16BIT_RGB444_YCbCr444:
+		sync_pulse = ADV7511_INPUT_SYNC_PULSE_NONE;
+		break;
+	default:
+		sync_pulse = config->sync_pulse;
+		break;
+	}
+
+	switch (config->id) {
+	case ADV7511_INPUT_ID_16_20_24BIT_YCbCr422_EMBEDDED_SYNC:
+	case ADV7511_INPUT_ID_8_10_12BIT_YCbCr422_EMBEDDED_SYNC:
+		adv7511->embedded_sync = true;
+		break;
+	default:
+		adv7511->embedded_sync = false;
+		break;
+	}
+
+	regmap_update_bits(adv7511->regmap, ADV7511_REG_I2C_FREQ_ID_CFG,
+		0xf, config->id);
+	regmap_update_bits(adv7511->regmap, ADV7511_REG_VIDEO_INPUT_CFG1, 0x7e,
+		(config->input_color_depth << 4) | (config->input_style << 2));
+	regmap_write(adv7511->regmap, ADV7511_REG_VIDEO_INPUT_CFG2,
+		(config->reverse_bitorder << 6) |
+		(config->bit_justification << 3));
+	regmap_write(adv7511->regmap, ADV7511_REG_TIMING_GEN_SEQ,
+		(sync_pulse << 2) |
+		(config->timing_gen_seq << 1));
+	regmap_write(adv7511->regmap, 0xba,
+		(config->clock_delay << 5));
+
+	regmap_update_bits(adv7511->regmap, ADV7511_REG_TMDS_CLOCK_INV,
+		0x08, config->tmds_clock_inversion << 3);
+
+	adv7511->hsync_polarity = config->hsync_polarity;
+	adv7511->vsync_polarity = config->vsync_polarity;
+}
+
+int adv7511_packet_enable(struct adv7511 *adv7511, unsigned int packet)
+{

drivers/gpu/drm/i2c/adv7511_core.c line 273

Quoted 10 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +10 -0
+	if (packet & 0xff) {
+		regmap_update_bits(adv7511->regmap, ADV7511_REG_PACKET_ENABLE0,
+			 packet, 0xff);
+	}
+
+	if (packet & 0xff00) {
+		packet >>= 8;
+		regmap_update_bits(adv7511->regmap, ADV7511_REG_PACKET_ENABLE1,
+			packet, 0xff);
+	}

What about definings masks in adv7511.h ?

drivers/gpu/drm/i2c/adv7511_core.c line 274

Quoted 2 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +2 -0
+
+	return 0;

The function never returns an error, could it be made void ? Same for the disable function below.

Quoted 145 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +145 -0
+}
+
+int adv7511_packet_disable(struct adv7511 *adv7511, unsigned int packet)
+{
+	if (packet & 0xff) {
+		regmap_update_bits(adv7511->regmap, ADV7511_REG_PACKET_ENABLE0,
+			 packet, 0x00);
+	}
+
+	if (packet & 0xff00) {
+		packet >>= 8;
+		regmap_update_bits(adv7511->regmap, ADV7511_REG_PACKET_ENABLE1,
+			packet, 0x00);
+	}
+
+	return 0;
+}
+
+static bool adv7511_register_volatile(struct device *dev, unsigned int reg)
+{
+	switch (reg) {
+	case ADV7511_REG_SPDIF_FREQ:
+	case ADV7511_REG_CTS_AUTOMATIC1:
+	case ADV7511_REG_CTS_AUTOMATIC2:
+	case ADV7511_REG_VIC_DETECTED:
+	case ADV7511_REG_VIC_SEND:
+	case ADV7511_REG_AUX_VIC_DETECTED:
+	case ADV7511_REG_STATUS:
+	case ADV7511_REG_GC(1):
+	case ADV7511_REG_INT(0):
+	case ADV7511_REG_INT(1):
+	case ADV7511_REG_PLL_STATUS:
+	case ADV7511_REG_AN(0):
+	case ADV7511_REG_AN(1):
+	case ADV7511_REG_AN(2):
+	case ADV7511_REG_AN(3):
+	case ADV7511_REG_AN(4):
+	case ADV7511_REG_AN(5):
+	case ADV7511_REG_AN(6):
+	case ADV7511_REG_AN(7):
+	case ADV7511_REG_HDCP_STATUS:
+	case ADV7511_REG_BCAPS:
+	case ADV7511_REG_BKSV(0):
+	case ADV7511_REG_BKSV(1):
+	case ADV7511_REG_BKSV(2):
+	case ADV7511_REG_BKSV(3):
+	case ADV7511_REG_BKSV(4):
+	case ADV7511_REG_DDC_STATUS:
+	case ADV7511_REG_BSTATUS(0):
+	case ADV7511_REG_BSTATUS(1):
+	case ADV7511_REG_CHIP_ID_HIGH:
+	case ADV7511_REG_CHIP_ID_LOW:
+		return true;
+	}
+
+	return false;
+}
+
+static bool adv7511_hpd(struct adv7511 *adv7511)
+{
+	unsigned int irq0;
+	int ret;
+
+	ret = regmap_read(adv7511->regmap, ADV7511_REG_INT(0), &irq0);
+	if (ret < 0)
+		return false;
+
+	if (irq0 & ADV7511_INT0_HDP) {
+		regmap_write(adv7511->regmap, ADV7511_REG_INT(0), ADV7511_INT0_HDP);
+		return true;
+	}
+
+	return false;
+}
+
+static irqreturn_t adv7511_irq_handler(int irq, void *devid)
+{
+	struct adv7511 *adv7511 = devid;
+
+	if (adv7511_hpd(adv7511))
+		drm_helper_hpd_irq_event(adv7511->encoder->dev);
+
+	wake_up_all(&adv7511->wq);
+
+	return IRQ_HANDLED;
+}
+
+static unsigned int adv7511_is_interrupt_pending(struct adv7511 *adv7511,
+	unsigned int irq)
+{
+	unsigned int irq0, irq1;
+	unsigned int pending;
+	int ret;
+
+	ret = regmap_read(adv7511->regmap, ADV7511_REG_INT(0), &irq0);
+	if (ret < 0)
+		return 0;
+	ret = regmap_read(adv7511->regmap, ADV7511_REG_INT(1), &irq1);
+	if (ret < 0)
+		return 0;
+
+	pending = (irq1 << 8) | irq0;
+
+	return pending & irq;
+}
+
+static int adv7511_wait_for_interrupt(struct adv7511 *adv7511, int irq,
+	int timeout)
+{
+	unsigned int pending = 0;
+	int ret;
+
+	if (adv7511->i2c_main->irq) {
+		ret = wait_event_interruptible_timeout(adv7511->wq,
+				adv7511_is_interrupt_pending(adv7511, irq),
+				msecs_to_jiffies(timeout));
+		if (ret <= 0)
+			return 0;
+		pending = adv7511_is_interrupt_pending(adv7511, irq);
+	} else {
+		if (timeout < 25)
+			timeout = 25;
+		do {
+			pending = adv7511_is_interrupt_pending(adv7511, irq);
+			if (pending)
+				break;
+			msleep(25);
+			timeout -= 25;
+		} while (timeout >= 25);
+	}
+
+	return pending;
+}
+
+static int adv7511_get_edid_block(void *data, unsigned char *buf,
+	int block, int len)
+{
+	struct drm_encoder *encoder = data;
+	struct adv7511 *adv7511 = encoder_to_adv7511(encoder);
+	struct i2c_msg xfer[2];
+	uint8_t offset;
+	int i;
+	int ret;
+
+	if (len > 128)

drivers/gpu/drm/i2c/adv7511_core.c line 430

Quoted 10 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +10 -0
+		return -EINVAL;
+
+	if (adv7511->current_edid_segment != block / 2) {
+		unsigned int status;
+
+		ret = regmap_read(adv7511->regmap, ADV7511_REG_DDC_STATUS, &status);
+		if (ret < 0)
+			return ret;
+
+		if (status != 2) {

#define as well ?

drivers/gpu/drm/i2c/adv7511_core.c line 431

Quoted 2 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +2 -0
+			regmap_write(adv7511->regmap, ADV7511_REG_EDID_SEGMENT, block);
+			ret = adv7511_wait_for_interrupt(adv7511, ADV7511_INT0_EDID_READY 

|

Quoted 15 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +15 -0
+					ADV7511_INT1_DDC_ERROR, 200);
+
+			if (!(ret & ADV7511_INT0_EDID_READY))
+				return -EIO;
+		}
+
+		regmap_write(adv7511->regmap, ADV7511_REG_INT(0),
+			ADV7511_INT0_EDID_READY | ADV7511_INT1_DDC_ERROR);
+
+		/* Break this apart, hopefully more I2C controllers will support 64
+		 * byte transfers than 256 byte transfers */
+
+		xfer[0].addr = adv7511->i2c_edid->addr;
+		xfer[0].flags = 0;
+		xfer[0].len = 1;

drivers/gpu/drm/i2c/adv7511_core.c

Quoted 10 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +10 -0
+		xfer[0].buf = &offset;
+		xfer[1].addr = adv7511->i2c_edid->addr;
+		xfer[1].flags = I2C_M_RD;
+		xfer[1].len = 64;
+		xfer[1].buf = adv7511->edid_buf;
+
+		offset = 0;
+
+		for (i = 0; i < 4; ++i) {
+			ret = i2c_transfer(adv7511->i2c_edid->adapter, xfer, 

ARRAY_SIZE(xfer));

drivers/gpu/drm/i2c/adv7511_core.c line 465

Quoted 8 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +8 -0
+			if (ret < 0)
+				return ret;
+			else if (ret != 2)
+				return -EIO;
+
+			xfer[1].buf += 64;
+			offset += 64;
+		}

Shouldn't you read two times 64 bytes per block, not four times ?

Quoted 32 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +32 -0
+
+		adv7511->current_edid_segment = block / 2;
+	}
+
+	if (block % 2 == 0)
+		memcpy(buf, adv7511->edid_buf, len);
+	else
+		memcpy(buf, adv7511->edid_buf + 128, len);
+
+	return 0;
+}
+
+static int adv7511_get_modes(struct drm_encoder *encoder,
+	struct drm_connector *connector)
+{
+	struct adv7511 *adv7511 = encoder_to_adv7511(encoder);
+	struct edid *edid;
+	unsigned int count;
+
+	/* Reading the EDID only works if the device is powered */
+	if (adv7511->dpms_mode != DRM_MODE_DPMS_ON) {
+		regmap_write(adv7511->regmap, ADV7511_REG_INT(0),
+			ADV7511_INT0_EDID_READY | ADV7511_INT1_DDC_ERROR);
+		regmap_update_bits(adv7511->regmap, ADV7511_REG_POWER,
+				ADV7511_POWER_POWER_DOWN, 0);
+		adv7511->current_edid_segment = -1;
+	}
+
+	edid = drm_do_get_edid(connector, adv7511_get_edid_block, encoder);
+
+	if (adv7511->dpms_mode != DRM_MODE_DPMS_ON)
+		regmap_update_bits(adv7511->regmap, ADV7511_REG_POWER,

drivers/gpu/drm/i2c/adv7511_core.c line 507

Quoted 10 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +10 -0
+				ADV7511_POWER_POWER_DOWN, ADV7511_POWER_POWER_DOWN);
+
+	adv7511->edid = edid;
+	if (!edid)
+		return 0;
+
+	drm_mode_connector_update_edid_property(connector, edid);
+	count = drm_add_edid_modes(connector, edid);
+
+	kfree(adv7511->edid);

Really ? Shouldn't you then move the adv7511->edid = edid; line below ?

Quoted 5 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +5 -0
+
+	return count;
+}
+
+struct edid *adv7511_get_edid(struct drm_encoder *encoder)

drivers/gpu/drm/i2c/adv7511_core.c line 522

Quoted 10 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +10 -0
+{
+	struct adv7511 *adv7511 = encoder_to_adv7511(encoder);
+
+	if (!adv7511->edid)
+		return NULL;
+
+	return kmemdup(adv7511->edid, sizeof(*adv7511->edid) +
+		adv7511->edid->extensions * 128, GFP_KERNEL);
+}
+EXPORT_SYMBOL_GPL(adv7511_get_edid);

Why do you need to export this function, who will use it ?

Quoted 10 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +10 -0
+static void adv7511_encoder_dpms(struct drm_encoder *encoder, int mode)
+{
+	struct adv7511 *adv7511 = encoder_to_adv7511(encoder);
+
+	switch (mode) {
+	case DRM_MODE_DPMS_ON:
+		adv7511->current_edid_segment = -1;
+
+		regmap_write(adv7511->regmap, ADV7511_REG_INT(0),
+			ADV7511_INT0_EDID_READY | ADV7511_INT1_DDC_ERROR);

drivers/gpu/drm/i2c/adv7511_core.c line 543

Quoted 10 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +10 -0
+		regmap_update_bits(adv7511->regmap, ADV7511_REG_POWER,
+				ADV7511_POWER_POWER_DOWN, 0);
+		/*
+		 * Per spec it is allowed to pulse the HDP signal to indicate
+		 * that the EDID information has changed. Some monitors do this
+		 * when they wakeup from standby or are enabled. When the HDP
+		 * goes low the adv7511 is reset and the outputs are disabled
+		 * which might cause the monitor to go to standby again. To
+		 * avoid this we ignore the HDP pin for the first few seconds
+		 * after enabeling the output.

s/enabeling/enabling/

drivers/gpu/drm/i2c/adv7511_core.c

Quoted 5 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +5 -0
+		 */
+		regmap_update_bits(adv7511->regmap, ADV7511_REG_POWER2,
+				ADV7511_REG_POWER2_HDP_SRC_MASK,
+				ADV7511_REG_POWER2_HDP_SRC_NONE);
+		/* Most of the registers are reset during power down or when HPD is 

low */

Quoted 4 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +4 -0
+		regcache_sync(adv7511->regmap);
+		break;
+	default:
+		/* TODO: setup additional power down modes */

drivers/gpu/drm/i2c/adv7511_core.c

Quoted 10 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +10 -0
+		regmap_update_bits(adv7511->regmap, ADV7511_REG_POWER,
+				ADV7511_POWER_POWER_DOWN, ADV7511_POWER_POWER_DOWN);
+		regcache_mark_dirty(adv7511->regmap);
+		break;
+	}
+
+	adv7511->dpms_mode = mode;
+}
+
+static enum drm_connector_status adv7511_encoder_detect(struct drm_encoder 

*encoder,

Quoted 174 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +174 -0
+	struct drm_connector *connector)
+{
+	struct adv7511 *adv7511 = encoder_to_adv7511(encoder);
+	enum drm_connector_status status;
+	unsigned int val;
+	bool hpd;
+	int ret;
+
+	ret = regmap_read(adv7511->regmap, ADV7511_REG_STATUS, &val);
+	if (ret < 0)
+		return connector_status_disconnected;
+
+	if (val & ADV7511_STATUS_HPD)
+		status = connector_status_connected;
+	else
+		status = connector_status_disconnected;
+
+	hpd = adv7511_hpd(adv7511);
+
+	/* The chip resets itself when the cable is disconnected, so in case
+	 * there is a pending HPD interrupt and the cable is connected there was
+	 * at least on transition from disconnected to connected and the chip
+	 * has to be reinitialized. */
+	if (status == connector_status_connected && hpd &&
+		adv7511->dpms_mode == DRM_MODE_DPMS_ON) {
+		regcache_mark_dirty(adv7511->regmap);
+		adv7511_encoder_dpms(encoder, adv7511->dpms_mode);
+		adv7511_get_modes(encoder, connector);
+		status = connector_status_disconnected;
+	} else {
+		/* Renable HDP sensing */
+		regmap_update_bits(adv7511->regmap, ADV7511_REG_POWER2,
+				ADV7511_REG_POWER2_HDP_SRC_MASK,
+				ADV7511_REG_POWER2_HDP_SRC_BOTH);
+	}
+
+	adv7511->status = status;
+	return status;
+}
+
+static void adv7511_encoder_mode_set(struct drm_encoder *encoder,
+	struct drm_display_mode *mode,
+	struct drm_display_mode *adj_mode)
+{
+	struct adv7511 *adv7511 = encoder_to_adv7511(encoder);
+	unsigned int low_refresh_rate;
+	unsigned int hsync_polarity = 0;
+	unsigned int vsync_polarity = 0;
+
+	if (adv7511->embedded_sync) {
+		unsigned int hsync_offset, hsync_len;
+		unsigned int vsync_offset, vsync_len;
+
+		hsync_offset = adj_mode->crtc_hsync_start - adj_mode->crtc_hdisplay;
+		vsync_offset = adj_mode->crtc_vsync_start - adj_mode->crtc_vdisplay;
+		hsync_len = adj_mode->crtc_hsync_end - adj_mode->crtc_hsync_start;
+		vsync_len = adj_mode->crtc_vsync_end - adj_mode->crtc_vsync_start;
+
+		/* The hardware vsync generator has a off-by-one bug */
+		vsync_offset += 1;
+
+		regmap_write(adv7511->regmap, ADV7511_REG_HSYNC_PLACEMENT_MSB,
+			((hsync_offset >> 10) & 0x7) << 5);
+		regmap_write(adv7511->regmap, ADV7511_REG_SYNC_DECODER(0),
+			(hsync_offset >> 2) & 0xff);
+		regmap_write(adv7511->regmap, ADV7511_REG_SYNC_DECODER(1),
+			((hsync_offset & 0x3) << 6) | ((hsync_len >> 4) & 0x3f));
+		regmap_write(adv7511->regmap, ADV7511_REG_SYNC_DECODER(2),
+			((hsync_len & 0xf) << 4) | ((vsync_offset >> 6) & 0xf));
+		regmap_write(adv7511->regmap, ADV7511_REG_SYNC_DECODER(3),
+			((vsync_offset & 0x3f) << 2) | ((vsync_len >> 8) & 0x3));
+		regmap_write(adv7511->regmap, ADV7511_REG_SYNC_DECODER(4),
+			vsync_len & 0xff);
+
+		hsync_polarity = !(adj_mode->flags & DRM_MODE_FLAG_PHSYNC);
+		vsync_polarity = !(adj_mode->flags & DRM_MODE_FLAG_PVSYNC);
+	} else {
+		enum adv7511_sync_polarity mode_hsync_polarity;
+		enum adv7511_sync_polarity mode_vsync_polarity;
+
+		/**
+		 * If the input signal is always low or always high we want to
+		 * invert or let it passthrough depending on the polarity of the
+		 * current mode.
+		 **/
+		if (adj_mode->flags & DRM_MODE_FLAG_NHSYNC)
+			mode_hsync_polarity = ADV7511_SYNC_POLARITY_LOW;
+		else
+			mode_hsync_polarity = ADV7511_SYNC_POLARITY_HIGH;
+
+		if (adj_mode->flags & DRM_MODE_FLAG_NVSYNC)
+			mode_vsync_polarity = ADV7511_SYNC_POLARITY_LOW;
+		else
+			mode_vsync_polarity = ADV7511_SYNC_POLARITY_HIGH;
+
+		if (adv7511->hsync_polarity != mode_hsync_polarity &&
+		    adv7511->hsync_polarity != ADV7511_SYNC_POLARITY_PASSTHROUGH)
+			hsync_polarity = 1;
+
+		if (adv7511->vsync_polarity != mode_vsync_polarity &&
+		    adv7511->vsync_polarity != ADV7511_SYNC_POLARITY_PASSTHROUGH)
+			vsync_polarity = 1;
+	}
+
+	if (mode->vrefresh <= 24000)
+		low_refresh_rate = ADV7511_LOW_REFRESH_RATE_24HZ;
+	else if (mode->vrefresh <= 25000)
+		low_refresh_rate = ADV7511_LOW_REFRESH_RATE_25HZ;
+	else if (mode->vrefresh <= 30000)
+		low_refresh_rate = ADV7511_LOW_REFRESH_RATE_30HZ;
+	else
+		low_refresh_rate = ADV7511_LOW_REFRESH_RATE_NONE;
+
+	regmap_update_bits(adv7511->regmap, 0xfb,
+		0x6, low_refresh_rate << 1);
+	regmap_update_bits(adv7511->regmap, 0x17,
+		0x60, (vsync_polarity << 6) | (hsync_polarity << 5));
+
+	adv7511->f_tmds = mode->clock;
+}
+
+static struct drm_encoder_slave_funcs adv7511_encoder_funcs = {
+	.set_config = adv7511_set_config,
+	.dpms = adv7511_encoder_dpms,
+	/* .destroy = adv7511_encoder_destroy,*/
+	.mode_set = adv7511_encoder_mode_set,
+	.detect = adv7511_encoder_detect,
+	.get_modes = adv7511_get_modes,
+};
+
+static const struct regmap_config adv7511_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+
+	.max_register = 0xff,
+	.cache_type = REGCACHE_RBTREE,
+	.reg_defaults_raw = adv7511_register_defaults,
+	.num_reg_defaults_raw = ARRAY_SIZE(adv7511_register_defaults),
+
+	.volatile_reg = adv7511_register_volatile,
+};
+
+/*
+	adi,input-id - 
+		0x00: 
+		0x01:
+		0x02:
+		0x03:
+		0x04:
+		0x05:
+	adi,sync-pulse - Selects the sync pulse
+		0x00: Use the DE signal as sync pulse
+		0x01: Use the HSYNC signal as sync pulse
+		0x02: Use the VSYNC signal as sync pulse
+		0x03: No external sync pulse
+	adi,bit-justification -
+		0x00: Evently
+		0x01: Right
+		0x02: Left
+	adi,up-conversion - 
+		0x00: zero-order up conversion
+		0x01: first-order up conversion
+	adi,timing-generation-sequence -
+		0x00: Sync adjustment first, then DE generation
+		0x01: DE generation first then sync adjustment
+	adi,vsync-polarity - Polarity of the vsync signal
+		0x00: Passthrough
+		0x01: Active low
+		0x02: Active high
+	adi,hsync-polarity - Polarity of the hsync signal
+		0x00: Passthrough
+		0x01: Active low
+		0x02: Active high
+	adi,reverse-bitorder - If set the bitorder is reveresed

drivers/gpu/drm/i2c/adv7511_core.c line 746

Quoted 10 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +10 -0
+	adi,tmds-clock-inversion - If set use tdms clock inversion
+	adi,clock-delay - Clock delay for the video data clock
+		0x00: -1200 ps
+		0x01:  -800 ps
+		0x02:  -400 ps
+		0x03: no dealy
+		0x04:   400 ps
+		0x05:   800 ps
+		0x06:  1200 ps
+		0x07:  1600 ps

The value should be expressed directly in ps in the DT.

drivers/gpu/drm/i2c/adv7511_core.c line 754

Quoted 8 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +8 -0
+	adi,input-style - Specifies the input style used
+		0x02: Use input style 1
+		0x01: Use input style 2
+		0x03: Use Input style 3
+	adi,input-color-depth - Selects the input format color depth 
+		0x03: 8-bit per channel
+		0x01: 10-bit per channel
+		0x02: 12-bit per channel

The properties related to the input format should be grouped in a single input format property, as discussed above for the input format enums.

drivers/gpu/drm/i2c/adv7511_core.c line 756

Quoted 4 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +4 -0
+*/
+
+
+static int adv7511_parse_dt(struct device_node *np, struct 

adv7511_link_config *config)

Quoted 61 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +61 -0
+{
+	int ret;
+	u32 val;
+
+	ret = of_property_read_u32(np, "adi,input-id", &val);
+	if (ret < 0)
+		return ret;
+	config->id = val;
+
+	ret = of_property_read_u32(np, "adi,sync-pulse", &val);
+	if (ret < 0)
+		config->sync_pulse = ADV7511_INPUT_SYNC_PULSE_NONE;
+	else
+		config->sync_pulse = val;
+
+	ret = of_property_read_u32(np, "adi,bit-justification", &val);
+	if (ret < 0)
+		return ret;
+	config->bit_justification = val;
+
+	ret = of_property_read_u32(np, "adi,up-conversion", &val);
+	if (ret < 0)
+		config->up_conversion = ADV7511_UP_CONVERSION_ZERO_ORDER;
+	else
+		config->up_conversion = val;
+
+	ret = of_property_read_u32(np, "adi,timing-generation-sequence", &val);
+	if (ret < 0)
+		return ret;
+	config->timing_gen_seq = val;
+
+	ret = of_property_read_u32(np, "adi,vsync-polarity", &val);
+	if (ret < 0)
+		return ret;
+	config->vsync_polarity = val;
+
+	ret = of_property_read_u32(np, "adi,hsync-polarity", &val);
+	if (ret < 0)
+		return ret;
+	config->hsync_polarity = val;
+
+	config->reverse_bitorder = of_property_read_bool(np,
+		"adi,reverse-bitorder");
+	config->tmds_clock_inversion = of_property_read_bool(np,
+		"adi,tmds-clock-inversion");
+
+	ret = of_property_read_u32(np, "adi,clock-delay", &val);
+	if (ret)
+		return ret;
+	config->clock_delay = val;
+
+	ret = of_property_read_u32(np, "adi,input-style", &val);
+	if (ret)
+		return ret;
+	config->input_style = val;
+
+	ret = of_property_read_u32(np, "adi,input-color-depth", &val);
+	if (ret)
+		return ret;
+	config->input_color_depth = val;
+

drivers/gpu/drm/i2c/adv7511_core.c line 829

Quoted 10 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +10 -0
+	config->gpio_pd = of_get_gpio(np, 0);
+	if (config->gpio_pd == -EPROBE_DEFER)
+		return -EPROBE_DEFER;
+
+	return 0;
+}
+
+static const int edid_i2c_addr = 0x7e;
+static const int packet_i2c_addr = 0x70;
+static const int cec_i2c_addr = 0x78;

What about #defines instead of static const ints ?

Quoted 20 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +20 -0
+static int adv7511_probe(struct i2c_client *i2c,
+	const struct i2c_device_id *id)
+{
+	struct adv7511_link_config link_config;
+	struct adv7511 *adv7511;
+	unsigned int val;
+	int ret;
+
+	if (i2c->dev.of_node) {
+		ret = adv7511_parse_dt(i2c->dev.of_node, &link_config);
+		if (ret)
+			return ret;
+	} else {
+		if (!i2c->dev.platform_data)
+			return -EINVAL;
+		link_config = *(struct adv7511_link_config *)i2c->dev.platform_data;
+	}
+
+	adv7511 = devm_kzalloc(&i2c->dev, sizeof(*adv7511), GFP_KERNEL);
+	if (!adv7511)

drivers/gpu/drm/i2c/adv7511_core.c line 860

Quoted 10 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +10 -0
+		return -ENOMEM;
+
+	adv7511->gpio_pd = link_config.gpio_pd;
+
+	if (gpio_is_valid(adv7511->gpio_pd)) {
+		ret = devm_gpio_request_one(&i2c->dev, adv7511->gpio_pd,
+				GPIOF_OUT_INIT_HIGH, "PD");
+		if (ret)
+			return ret;
+		mdelay(5);

msleep() or usleep_range() ?

Quoted 9 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +9 -0
+		gpio_set_value_cansleep(adv7511->gpio_pd, 0);
+	}
+
+	adv7511->regmap = devm_regmap_init_i2c(i2c, &adv7511_regmap_config);
+	if (IS_ERR(adv7511->regmap))
+		return PTR_ERR(adv7511->regmap);
+
+	ret = regmap_read(adv7511->regmap, ADV7511_REG_CHIP_REVISION, &val);
+	if (ret)

drivers/gpu/drm/i2c/adv7511_core.c

Quoted 10 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +10 -0
+		return ret;
+	dev_dbg(&i2c->dev, "Rev. %d\n", val);
+
+	ret = regmap_register_patch(adv7511->regmap, adv7511_fixed_registers,
+		ARRAY_SIZE(adv7511_fixed_registers));
+	if (ret)
+		return ret;
+
+	regmap_write(adv7511->regmap, ADV7511_REG_EDID_I2C_ADDR, edid_i2c_addr);
+	regmap_write(adv7511->regmap, ADV7511_REG_PACKET_I2C_ADDR, 

packet_i2c_addr);

drivers/gpu/drm/i2c/adv7511_core.c line 887

Quoted 8 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +8 -0
+	regmap_write(adv7511->regmap, ADV7511_REG_CEC_I2C_ADDR, cec_i2c_addr);
+	adv7511_packet_disable(adv7511, 0xffff);
+
+	adv7511->i2c_main = i2c;
+	adv7511->i2c_edid = i2c_new_dummy(i2c->adapter, edid_i2c_addr >> 1);
+	adv7511->i2c_packet = i2c_new_dummy(i2c->adapter, packet_i2c_addr >> 1);
+	if (!adv7511->i2c_edid)
+		return -ENOMEM;

Wouldn't this leak i2c_packet ?

drivers/gpu/drm/i2c/adv7511_core.c line 891

Quoted 4 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +4 -0
+
+	if (i2c->irq) {
+		ret = request_threaded_irq(i2c->irq, NULL, adv7511_irq_handler,
+				IRQF_ONESHOT, dev_name(&i2c->dev), adv7511);

You can use the devm_ version and get rid of the free_irq() in the remove() handler.

Quoted 14 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +14 -0
+		if (ret)
+			goto err_i2c_unregister_device;
+
+		init_waitqueue_head(&adv7511->wq);
+	}
+
+	/* CEC is unused for now */
+	regmap_write(adv7511->regmap, ADV7511_REG_CEC_CTRL,
+		ADV7511_CEC_CTRL_POWER_DOWN);
+
+	regmap_update_bits(adv7511->regmap, ADV7511_REG_POWER,
+			ADV7511_POWER_POWER_DOWN, ADV7511_POWER_POWER_DOWN);
+
+	adv7511->current_edid_segment = -1;

drivers/gpu/drm/i2c/adv7511_core.c line 917

Quoted 10 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +10 -0
+
+	i2c_set_clientdata(i2c, adv7511);
+	adv7511_audio_init(&i2c->dev);
+
+	adv7511_set_link_config(adv7511, &link_config);
+
+	return 0;
+
+err_i2c_unregister_device:
+	i2c_unregister_device(adv7511->i2c_edid);

Shouldn't you also unregister i2c_packet ?

drivers/gpu/drm/i2c/adv7511_core.c line 926

Quoted 9 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +9 -0
+
+	return ret;
+}
+
+static int adv7511_remove(struct i2c_client *i2c)
+{
+	struct adv7511 *adv7511 = i2c_get_clientdata(i2c);
+
+	i2c_unregister_device(adv7511->i2c_edid);

Shouldn't you also unregister i2c_packet ?

Quoted 55 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +55 -0
+
+	if (i2c->irq)
+		free_irq(i2c->irq, adv7511);
+	kfree(adv7511->edid);
+
+	return 0;
+}
+
+static int adv7511_encoder_init(struct i2c_client *i2c,
+	struct drm_device *dev, struct drm_encoder_slave *encoder)
+{
+
+	struct adv7511 *adv7511 = i2c_get_clientdata(i2c);
+
+	encoder->slave_priv = adv7511;
+	encoder->slave_funcs = &adv7511_encoder_funcs;
+
+	adv7511->encoder = &encoder->base;
+
+	return 0;
+}
+
+static const struct i2c_device_id adv7511_ids[] = {
+	{ "adv7511", 0 },
+	{}
+};
+
+static struct drm_i2c_encoder_driver adv7511_driver = {
+	.i2c_driver = {
+		.driver = {
+			.name = "adv7511",
+		},
+		.id_table = adv7511_ids,
+		.probe = adv7511_probe,
+		.remove = adv7511_remove,
+	},
+
+	.encoder_init = adv7511_encoder_init,
+};
+
+static int __init adv7511_init(void)
+{
+	return drm_i2c_encoder_register(THIS_MODULE, &adv7511_driver);
+}
+module_init(adv7511_init);
+
+static void __exit adv7511_exit(void)
+{
+	drm_i2c_encoder_unregister(&adv7511_driver);
+}
+module_exit(adv7511_exit);
+
+MODULE_AUTHOR("Lars-Peter Clausen <[email protected]>");
+MODULE_DESCRIPTION("ADV7511 HDMI transmitter driver");
+MODULE_LICENSE("GPL");
Signature · 3 lines
Regards,

Laurent Pinchart
#9 lore raw

Re: [RFC 01/10] drm: ADV7511 i2c HDMI encoder driver

[...]

Quoted 21 lines

drivers/gpu/drm/i2c/adv7511.h

Quoted 4 lines
drivers/gpu/drm/i2c/adv7511.h new file +4 -0
+
+/**
+ * enum adv7511_input_color_depth - Selects the input format color depth
+ * @ADV7511_INPUT_COLOR_DEPTH_8BIT: Input format color depth is 8 bits per 

channel

Quoted 1 line

+ * @ADV7511_INPUT_COLOR_DEPTH_10BIT: Input format color dpeth is 10 bits

per channel

Quoted 1 line

+ * @ADV7511_INPUT_COLOR_DEPTH_12BIT: Input format color depth is 12 bits

per channel

drivers/gpu/drm/i2c/adv7511.h line 253

Quoted 6 lines

+ **/

drivers/gpu/drm/i2c/adv7511.h new file +5 -0
+enum adv7511_input_color_depth {
+	ADV7511_INPUT_COLOR_DEPTH_8BIT = 3,
+	ADV7511_INPUT_COLOR_DEPTH_10BIT = 1,
+	ADV7511_INPUT_COLOR_DEPTH_12BIT = 2,
+};

Those enums describe the video format at the chip input. This can be configured statically from platform data or DT, but some platforms might need to setup formats dynamically at runtime. For instance the ADV7511 could be driven by a mux with two inputs using different formats.

Quoted 4 lines

For these reasons I would combine all those enums in a single one that lists all possible input formats. The formats should be standardized and moved to a separate header file. Get and set format operations will be needed (this is something CDF will address :-)).

Since most these settings are orthogonal to each other putting them in one enum gives you 3 * 3 * 6 * 3 = 162 entries. These enums configure to which pins of the ADV7511 what signal is connected. Standardizing this would require that other chips use the same layouts for connecting the pins.

[...]

Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/i2c/adv7511.h new file +7 -0
+
+/**
+ * enum adv7511_up_conversion - Selects the upscaling conversion method
+ * @ADV7511_UP_CONVERSION_ZERO_ORDER: Use zero order up conversion
+ * @ADV7511_UP_CONVERSION_FIRST_ORDER: Use first order up conversion
+ *
+ * This used when converting from a 4:2:2 format to a 4:4:4 format.
Quoted 9 lines

drivers/gpu/drm/i2c/adv7511.h line 334

Quoted 5 lines

+ **/

drivers/gpu/drm/i2c/adv7511.h new file +4 -0
+enum adv7511_up_conversion {
+    ADV7511_UP_CONVERSION_ZERO_ORDER = 0,
+    ADV7511_UP_CONVERSION_FIRST_ORDER = 1,
+};

How is the upscaling conversion method supposed to be selected ? What does it depend on ?

It's probably up to the system designer to say which method yields better results for their system.

[...]

Quoted 5 lines
Quoted 5 lines

+/**
+ * struct adv7511_video_config - Describes adv7511 hardware configuration
+ * @csc_enable: Whether to enable color space conversion
+ * @csc_scaling_factor: Color space conversion scaling factor
+ * @csc_coefficents: Color space conversion coefficents

Quoted 8 lines

drivers/gpu/drm/i2c/adv7511.h line 414

Quoted 5 lines

+ * @hdmi_mode: Whether to use HDMI or DVI output mode
+ * @avi_infoframe: HDMI infoframe
+ **/

drivers/gpu/drm/i2c/adv7511.h new file +2 -0
+struct adv7511_video_config {
+	bool csc_enable;

Shouldn't this be automatically computed based on the input and output formats ?

If the driver knew the input and output colorspaces and had coefficient tables for all possible combinations built in that could be done. This is maybe something that could be done in the framework.

Quoted 9 lines

drivers/gpu/drm/i2c/adv7511.h line 416

Quoted 3 lines
drivers/gpu/drm/i2c/adv7511.h new file +2 -0
+	enum adv7511_csc_scaling csc_scaling_factor;
+	const uint16_t *csc_coefficents;

Do the coefficients need to be configured freely, or could presets do ?

Quoted 3 lines
drivers/gpu/drm/i2c/adv7511.h new file +3 -0
+	bool hdmi_mode;
+	struct hdmi_avi_infoframe avi_infoframe;
+};

[...]

Quoted 9 lines
Quoted 1 line

+static void adv7511_set_config(struct drm_encoder *encoder, void *c)

Now we're getting to the controversial point.

What bothers me about the DRM encoder slave API is that the display controller driver needs to be aware of the details of the slave encoder, as it needs to pass an encoder-specific configuration structure to the .set_config() operation. The question would thus be, what about using the Common Display Framework ?

Well, as I said I'd prefer using the CDF for this driver. But even then the display controller driver might need to know about the details of the encoder. I think we talked about this during the FOSDEM meeting. The graphics fabric on the board can easily get complex enough to require a board custom driver, similar to what we have in ASoC. I think this drm_bridge patchset[1] tries to address a similar issue.

[1] http://lists.freedesktop.org/archives/dri-devel/2013-August/043237.html
[...]

Quoted 4 lines

drivers/gpu/drm/i2c/adv7511_core.c

Quoted 3 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +3 -0
+
+		for (i = 0; i < 4; ++i) {
+			ret = i2c_transfer(adv7511->i2c_edid->adapter, xfer, 

ARRAY_SIZE(xfer));

Quoted 10 lines

drivers/gpu/drm/i2c/adv7511_core.c line 465

Quoted 8 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +8 -0
+			if (ret < 0)
+				return ret;
+			else if (ret != 2)
+				return -EIO;
+
+			xfer[1].buf += 64;
+			offset += 64;
+		}

Shouldn't you read two times 64 bytes per block, not four times ?

The controller on the ADV7511 always reads two blocks at once, so it is 256 bytes.

Quoted 13 lines
Quoted 13 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +12 -0
+
+		adv7511->current_edid_segment = block / 2;
+	}
+
+	if (block % 2 == 0)
+		memcpy(buf, adv7511->edid_buf, len);
+	else
+		memcpy(buf, adv7511->edid_buf + 128, len);
+
+	return 0;
+}
+

[...]

Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +6 -0
+
+struct edid *adv7511_get_edid(struct drm_encoder *encoder)
+{
+	struct adv7511 *adv7511 = encoder_to_adv7511(encoder);
+
+	if (!adv7511->edid)
Quoted 8 lines

drivers/gpu/drm/i2c/adv7511_core.c line 522

Quoted 6 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +6 -0
+		return NULL;
+
+	return kmemdup(adv7511->edid, sizeof(*adv7511->edid) +
+		adv7511->edid->extensions * 128, GFP_KERNEL);
+}
+EXPORT_SYMBOL_GPL(adv7511_get_edid);

Why do you need to export this function, who will use it ?

The drm driver using the encoder that wants to know the EDID. E.g. to know if the monitor supports HDMI or not. But exporting this function is really just a quick hack to compensate for the removal of 'raw_edid', this probably wants proper abstraction in the framework.

[...]

Quoted 36 lines
Quoted 36 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +36 -0
+/*
+	adi,input-id - 
+		0x00: 
+		0x01:
+		0x02:
+		0x03:
+		0x04:
+		0x05:
+	adi,sync-pulse - Selects the sync pulse
+		0x00: Use the DE signal as sync pulse
+		0x01: Use the HSYNC signal as sync pulse
+		0x02: Use the VSYNC signal as sync pulse
+		0x03: No external sync pulse
+	adi,bit-justification -
+		0x00: Evently
+		0x01: Right
+		0x02: Left
+	adi,up-conversion - 
+		0x00: zero-order up conversion
+		0x01: first-order up conversion
+	adi,timing-generation-sequence -
+		0x00: Sync adjustment first, then DE generation
+		0x01: DE generation first then sync adjustment
+	adi,vsync-polarity - Polarity of the vsync signal
+		0x00: Passthrough
+		0x01: Active low
+		0x02: Active high
+	adi,hsync-polarity - Polarity of the hsync signal
+		0x00: Passthrough
+		0x01: Active low
+		0x02: Active high
+	adi,reverse-bitorder - If set the bitorder is reveresed
+	adi,tmds-clock-inversion - If set use tdms clock inversion
+	adi,clock-delay - Clock delay for the video data clock
+		0x00: -1200 ps
+		0x01:  -800 ps
Quoted 8 lines

drivers/gpu/drm/i2c/adv7511_core.c line 746

Quoted 6 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +6 -0
+		0x02:  -400 ps
+		0x03: no dealy
+		0x04:   400 ps
+		0x05:   800 ps
+		0x06:  1200 ps
+		0x07:  1600 ps

The value should be expressed directly in ps in the DT.

DT doesn't allow negative values.

Thanks for the review,
- Lars

#10 lore raw

Re: [RFC 01/10] drm: ADV7511 i2c HDMI encoder driver

Hi Lars-Peter,

Quoted 28 lines · On Wednesday 04 September 2013 13:34:30 Lars-Peter Clausen wrote:

[...]

Quoted 21 lines
Quoted 10 lines
drivers/gpu/drm/i2c/adv7511.h new file +4 -0
+
+/**
+ * enum adv7511_input_color_depth - Selects the input format color depth
+ * @ADV7511_INPUT_COLOR_DEPTH_8BIT: Input format color depth is 8 bits

per channel
+ * @ADV7511_INPUT_COLOR_DEPTH_10BIT: Input format color dpeth is 10 bits per channel
+ * @ADV7511_INPUT_COLOR_DEPTH_12BIT: Input format color depth is 12 bits per channel
+ **/

drivers/gpu/drm/i2c/adv7511.h line 253

Quoted 5 lines
drivers/gpu/drm/i2c/adv7511.h new file +5 -0
+enum adv7511_input_color_depth {
+	ADV7511_INPUT_COLOR_DEPTH_8BIT = 3,
+	ADV7511_INPUT_COLOR_DEPTH_10BIT = 1,
+	ADV7511_INPUT_COLOR_DEPTH_12BIT = 2,
+};

Those enums describe the video format at the chip input. This can be configured statically from platform data or DT, but some platforms might need to setup formats dynamically at runtime. For instance the ADV7511 could be driven by a mux with two inputs using different formats.

Quoted 4 lines

For these reasons I would combine all those enums in a single one that lists all possible input formats. The formats should be standardized and moved to a separate header file. Get and set format operations will be needed (this is something CDF will address :-)).

Quoted 4 lines

Since most these settings are orthogonal to each other putting them in one enum gives you 3 * 3 * 6 * 3 = 162 entries. These enums configure to which pins of the ADV7511 what signal is connected. Standardizing this would require that other chips use the same layouts for connecting the pins.

The problem is, this information needs to be shared between devices. Formats on the bus could very well be dynamic, the ADV7511 video source could be able to generate multiple formats that would be runtime configurable. To support this, platform data and DT bindings should describe how signals are connected (which would thus filter the list of supported formats), and a runtime API will be needed to get and set formats. The formats thus need to be standardized

We had a similar issue in V4L2 and have introduced a media bus format enumeration to solve it (see include/uapi/linux/v4l2-mediabus.h). I believe something similar is needed here.

Of course this won't solve the issue of how to select a format on the bus when both endpoints support multiple formats. This should probably be selected by userspace somehow, but we're missing an API to do so at the moment. A default value would thus need to be computed somehow, and possibly given by platform data and DT bindings (although it doesn't describe the hardware as such, and should thus not be part of the DT bindings).

Quoted 15 lines
Quoted 6 lines
Quoted 6 lines

+/**
+ * enum adv7511_up_conversion - Selects the upscaling conversion method
+ * @ADV7511_UP_CONVERSION_ZERO_ORDER: Use zero order up conversion
+ * @ADV7511_UP_CONVERSION_FIRST_ORDER: Use first order up conversion
+ *
+ * This used when converting from a 4:2:2 format to a 4:4:4 format.

Quoted 8 lines

drivers/gpu/drm/i2c/adv7511.h line 334

Quoted 5 lines

+ **/

drivers/gpu/drm/i2c/adv7511.h new file +4 -0
+enum adv7511_up_conversion {
+    ADV7511_UP_CONVERSION_ZERO_ORDER = 0,
+    ADV7511_UP_CONVERSION_FIRST_ORDER = 1,
+};

How is the upscaling conversion method supposed to be selected ? What does it depend on ?

Quoted 2 lines

It's probably up to the system designer to say which method yields better results for their system.

And what would a system designer base his/her decision on ? :-)

Quoted 65 lines
Quoted 6 lines
Quoted 6 lines

+/**
+ * struct adv7511_video_config - Describes adv7511 hardware configuration
+ * @csc_enable: Whether to enable color space conversion
+ * @csc_scaling_factor: Color space conversion scaling factor
+ * @csc_coefficents: Color space conversion coefficents

Quoted 8 lines

drivers/gpu/drm/i2c/adv7511.h line 414

Quoted 5 lines

+ * @hdmi_mode: Whether to use HDMI or DVI output mode
+ * @avi_infoframe: HDMI infoframe
+ **/

drivers/gpu/drm/i2c/adv7511.h new file +2 -0
+struct adv7511_video_config {
+	bool csc_enable;

Shouldn't this be automatically computed based on the input and output formats ?

If the driver knew the input and output colorspaces and had coefficient tables for all possible combinations built in that could be done. This is maybe something that could be done in the framework.

Quoted 8 lines

drivers/gpu/drm/i2c/adv7511.h line 416

Quoted 2 lines
drivers/gpu/drm/i2c/adv7511.h new file +2 -0
+	enum adv7511_csc_scaling csc_scaling_factor;
+	const uint16_t *csc_coefficents;

Do the coefficients need to be configured freely, or could presets do ?

Quoted 3 lines
drivers/gpu/drm/i2c/adv7511.h new file +3 -0
+	bool hdmi_mode;
+	struct hdmi_avi_infoframe avi_infoframe;
+};

[...]

Quoted 9 lines
Quoted 1 line

+static void adv7511_set_config(struct drm_encoder *encoder, void *c)

Now we're getting to the controversial point.

What bothers me about the DRM encoder slave API is that the display controller driver needs to be aware of the details of the slave encoder, as it needs to pass an encoder-specific configuration structure to the .set_config() operation. The question would thus be, what about using the Common Display Framework ?

Well, as I said I'd prefer using the CDF for this driver. But even then the display controller driver might need to know about the details of the encoder. I think we talked about this during the FOSDEM meeting. The graphics fabric on the board can easily get complex enough to require a board custom driver, similar to what we have in ASoC. I think this drm_bridge patchset[1] tries to address a similar issue.

[1] http://lists.freedesktop.org/archives/dri-devel/2013-August/043237.html
[...]

Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +3 -0
+
+		for (i = 0; i < 4; ++i) {
+			ret = i2c_transfer(adv7511->i2c_edid->adapter, xfer,

ARRAY_SIZE(xfer));

(quoted diff) +2 -0
+			if (ret < 0)
+				return ret;
Quoted 8 lines

drivers/gpu/drm/i2c/adv7511_core.c line 465

Quoted 6 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +6 -0
+			else if (ret != 2)
+				return -EIO;
+
+			xfer[1].buf += 64;
+			offset += 64;
+		}

Shouldn't you read two times 64 bytes per block, not four times ?

Quoted 2 lines

The controller on the ADV7511 always reads two blocks at once, so it is 256 bytes.

But this function return 128 bytes to the called. Can't you optimize this by reading 128 bytes only from the ADV7511 instead of throwing away 128 bytes every time ?

Quoted 30 lines
Quoted 12 lines
Quoted 12 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +12 -0
+
+		adv7511->current_edid_segment = block / 2;
+	}
+
+	if (block % 2 == 0)
+		memcpy(buf, adv7511->edid_buf, len);
+	else
+		memcpy(buf, adv7511->edid_buf + 128, len);
+
+	return 0;
+}
+

[...]

Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +6 -0
+
+struct edid *adv7511_get_edid(struct drm_encoder *encoder)
+{
+	struct adv7511 *adv7511 = encoder_to_adv7511(encoder);
+
+	if (!adv7511->edid)
Quoted 8 lines

drivers/gpu/drm/i2c/adv7511_core.c line 522

Quoted 6 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +6 -0
+		return NULL;
+
+	return kmemdup(adv7511->edid, sizeof(*adv7511->edid) +
+		adv7511->edid->extensions * 128, GFP_KERNEL);
+}
+EXPORT_SYMBOL_GPL(adv7511_get_edid);

Why do you need to export this function, who will use it ?

Quoted 4 lines

The drm driver using the encoder that wants to know the EDID. E.g. to know if the monitor supports HDMI or not. But exporting this function is really just a quick hack to compensate for the removal of 'raw_edid', this probably wants proper abstraction in the framework.

Yes, we do want a proper abstraction :-)

Quoted 45 lines
Quoted 36 lines
Quoted 36 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +36 -0
+/*
+	adi,input-id -
+		0x00:
+		0x01:
+		0x02:
+		0x03:
+		0x04:
+		0x05:
+	adi,sync-pulse - Selects the sync pulse
+		0x00: Use the DE signal as sync pulse
+		0x01: Use the HSYNC signal as sync pulse
+		0x02: Use the VSYNC signal as sync pulse
+		0x03: No external sync pulse
+	adi,bit-justification -
+		0x00: Evently
+		0x01: Right
+		0x02: Left
+	adi,up-conversion -
+		0x00: zero-order up conversion
+		0x01: first-order up conversion
+	adi,timing-generation-sequence -
+		0x00: Sync adjustment first, then DE generation
+		0x01: DE generation first then sync adjustment
+	adi,vsync-polarity - Polarity of the vsync signal
+		0x00: Passthrough
+		0x01: Active low
+		0x02: Active high
+	adi,hsync-polarity - Polarity of the hsync signal
+		0x00: Passthrough
+		0x01: Active low
+		0x02: Active high
+	adi,reverse-bitorder - If set the bitorder is reveresed
+	adi,tmds-clock-inversion - If set use tdms clock inversion
+	adi,clock-delay - Clock delay for the video data clock
+		0x00: -1200 ps
+		0x01:  -800 ps
Quoted 8 lines

drivers/gpu/drm/i2c/adv7511_core.c line 746

Quoted 6 lines
drivers/gpu/drm/i2c/adv7511_core.c new file +6 -0
+		0x02:  -400 ps
+		0x03: no dealy
+		0x04:   400 ps
+		0x05:   800 ps
+		0x06:  1200 ps
+		0x07:  1600 ps

The value should be expressed directly in ps in the DT.

Quoted 1 line

DT doesn't allow negative values.

Doesn't it ? DT carries values a packed bits, but doesn't really specify how the value is to be interpreted. That's the job of the DT bindings. We could just tell that the clock-delay should be a 32-bit 2-complement signed value.

Signature · 3 lines
Regards,

Laurent Pinchart