Skip to contentSkip to conversation

Add DRM for stih4xx platforms

PATCH Superseded Benjamin Gaignard 3 participants 23 messages May 20, 2014 – May 21, 2014

Subsystems (3)

v3 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v3 cover Add DRM for stih4xx platforms

This series of patches add the support of DRM/KMS drivers for STMicroelectronics chipsets stih416 and stih407.

patcheset version 3:
- Correctly split code between probe and bind funtions
- Squash some commits
- remove HQ-VDP device code to have a smaller patcheset, we will introduce it later.

patches could be found here: git://git.linaro.org/people/benjamin.gaignard/kernel.git
on branch: drm_kms_for_next-v3

patcheset version 2:
- Use componentized device instead of register sub-devices in master driver probe function
- Fix Makefile and Kconfig to only allow built-in compilation

patches could be found here: git://git.linaro.org/people/benjamin.gaignard/kernel.git
on branch: drm_kms_for_next-v2

patcheset version 1:
- First path submission

Hardware is split in two main blocks: Compositor and TVout. Each of them includes specific hardware IPs and the display timing are controlled by a specific Video Timing Generator hardware IP (VTG).

Compositor is made of the follow hardware IPs:
- GDP (Generic Display Pipeline) which is an entry point for graphic (RGB) buffers
- VDP (Video Diplay Pipeline) which is an entry point for video (YUV) buffers
- HQVDP (High Quality Video Display Processor) that supports scaling, deinterlacing and some miscellaneous image quality improvements. It fetches the Video decoded buffers from memory, processes them and pushes them to the Compositor through a HW dedicated bus.
- Mixer is responsible of mixing all the entries depending of their respective z-order and layout

TVout is divided in 3 parts:
- HDMI to generate HDMI signals, depending of chipset version HDMI phy can change.
- HDA to generate signals for HD analog TV
- VIP to control/switch data path coming from Compositor

On stih416 compositor and Tvout are on different dies so a Video Trafic Advance inter-die Communication mechanism (VTAC) is needed.

+---------------------------------------------+   +----------------------------------------+
| +-------------------------------+   +----+  |   |  +----+   +--------------------------+ |
| |                               |   |    |  |   |  |    |   |  +---------+     +----+  | |
| | +----+              +------+  |   |    |  |   |  |    |   |  | VIP     |---->|HDMI|  | |
| | |GPD +------------->|      |  |   |    |  |   |  |    |   |  |         |     +----+  | |
| | +----+              |Mixer |--|-->|    |  |   |  |    |---|->| switcher|             | |
| |                     |      |  |   |    |  |   |  |    |   |  |         |     +----+  | |
| |                     |      |  |   |    |  |   |  |    |   |  |         |---->|HDA |  | |
| |                     +------+  |   |VTAC|========>|VTAC|   |  +---------+     +----+  | |
| |                               |   |    |  |   |  |    |   |                          | |
| |         Compositor            |   |    |  |   |  |    |   |           TVout          | |
| +-------------------------------+   |    |  |   |  |    |   +--------------------------+ |
|                      ^              |    |  |   |  |    |             ^                  |
|                      |              |    |  |   |  |    |             |                  |
|               +--------------+      |    |  |   |  |    |      +-------------+           |
|               | VTG (master) |----->|    |  |   |  |    |----->| VTG (slave) |           |
|               +--------------+      +----+  |   |  +----+      +-------------+           |
|Digital die                                  |   |                              Analog Die|
+---------------------------------------------+   +----------------------------------------+

On stih407 Compositor and Tvout are on the same die

+-----------------------------------------------------------------+
| +-------------------------------+  +--------------------------+ |
| |                               |  |  +---------+     +----+  | |
| | +----+              +------+  |  |  | VIP     |---->|HDMI|  | |
| | |GPD +------------->|      |  |  |  |         |     +----+  | |
| | +----+              |Mixer |--|--|->| switcher|             | |
| | +----+   +-----+    |      |  |  |  |         |     +----+  | |
| | |VDP +-->+HQVDP+--->|      |  |  |  |         |---->|HDA |  | |
| | +----+   +-----+    +------+  |  |  +---------+     +----+  | |
| |                               |  |                          | |
| |         Compositor            |  |           TVout          | |
| +-------------------------------+  +--------------------------+ |
|                              ^        ^                         |
|                              |        |                         |
|                           +--------------+                      |
|                           |     VTG      |                      |
|                           +--------------+                      |
|Digital die                                                      |
+-----------------------------------------------------------------+

In addition of the drivers for the IPs listed before a thin I2C driver (hdmiddc) is used by HDMI driver to retrieve EDID for monitor.

To unify interfaces of GDP and VDP we create a "layer" interface called by compositor to control both GPD and VDP.

Hardware have memory contraints (alignment, contiguous) so we use CMA drm helpers functions to allocate frame buffer.

File naming convention is:
- sti_* for IPs drivers
- sti_drm_* for drm functions implementation.

Benjamin Gaignard (16):
drm: sti: add VTG driver
drm: sti: add VTAC drivers
drm: sti: add HDMI driver
drm: sti: add I2C client driver for HDMI
drm: sti: add HDA driver
drm: sti: add TVOut driver
drm: sti: add sti layer interface definition
drm: sti: add GDP layer
drm: sti: add VID layer
drm: sti: add Mixer
drm: sti: add Compositor
drm: sti: add debug to GDP
drm: sti: add debug to VID
drm: sti: add debug to TVout
drm: sti: add debug to mixer
drm: sti: Add DRM driver itself

 drivers/gpu/drm/Kconfig                    |    2 +
 drivers/gpu/drm/Makefile                   |    1 +
 drivers/gpu/drm/sti/Kconfig                |   26 +
 drivers/gpu/drm/sti/Makefile               |   22 +
 drivers/gpu/drm/sti/sti_compositor.c       |  267 +++++++
 drivers/gpu/drm/sti/sti_compositor.h       |   84 +++
 drivers/gpu/drm/sti/sti_ddc.c              |   56 ++
 drivers/gpu/drm/sti/sti_drm_connector.c    |  195 +++++
 drivers/gpu/drm/sti/sti_drm_connector.h    |   16 +
 drivers/gpu/drm/sti/sti_drm_crtc.c         |  440 ++++++++++++
 drivers/gpu/drm/sti/sti_drm_crtc.h         |   21 +
 drivers/gpu/drm/sti/sti_drm_drv.c          |  338 +++++++++
 drivers/gpu/drm/sti/sti_drm_drv.h          |   36 +
 drivers/gpu/drm/sti/sti_drm_encoder.c      |  201 ++++++
 drivers/gpu/drm/sti/sti_drm_encoder.h      |   16 +
 drivers/gpu/drm/sti/sti_drm_plane.c        |  195 +++++
 drivers/gpu/drm/sti/sti_drm_plane.h        |   16 +
 drivers/gpu/drm/sti/sti_gdp.c              |  726 +++++++++++++++++++
 drivers/gpu/drm/sti/sti_gdp.h              |   75 ++
 drivers/gpu/drm/sti/sti_hda.c              |  852 ++++++++++++++++++++++
 drivers/gpu/drm/sti/sti_hda.h              |   14 +
 drivers/gpu/drm/sti/sti_hdmi.c             | 1071 ++++++++++++++++++++++++++++
 drivers/gpu/drm/sti/sti_hdmi.h             |  198 +++++
 drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c |  398 +++++++++++
 drivers/gpu/drm/sti/sti_hdmi_tx3g4c28phy.c |  224 ++++++
 drivers/gpu/drm/sti/sti_layer.c            |  309 ++++++++
 drivers/gpu/drm/sti/sti_layer.h            |  113 +++
 drivers/gpu/drm/sti/sti_mixer.c            |  405 +++++++++++
 drivers/gpu/drm/sti/sti_mixer.h            |   54 ++
 drivers/gpu/drm/sti/sti_tvout.c            |  904 +++++++++++++++++++++++
 drivers/gpu/drm/sti/sti_tvout.h            |  105 +++
 drivers/gpu/drm/sti/sti_vid.c              |  259 +++++++
 drivers/gpu/drm/sti/sti_vid.h              |   34 +
 drivers/gpu/drm/sti/sti_vtac_rx.c          |  169 +++++
 drivers/gpu/drm/sti/sti_vtac_tx.c          |  182 +++++
 drivers/gpu/drm/sti/sti_vtac_utils.h       |   52 ++
 drivers/gpu/drm/sti/sti_vtg.c              |  468 ++++++++++++
 drivers/gpu/drm/sti/sti_vtg.h              |   20 +
 drivers/gpu/drm/sti/sti_vtg_utils.c        |   99 +++
 drivers/gpu/drm/sti/sti_vtg_utils.h        |   29 +
 40 files changed, 8692 insertions(+)
 create mode 100644 drivers/gpu/drm/sti/Kconfig
 create mode 100644 drivers/gpu/drm/sti/Makefile
 create mode 100644 drivers/gpu/drm/sti/sti_compositor.c
 create mode 100644 drivers/gpu/drm/sti/sti_compositor.h
 create mode 100644 drivers/gpu/drm/sti/sti_ddc.c
 create mode 100644 drivers/gpu/drm/sti/sti_drm_connector.c
 create mode 100644 drivers/gpu/drm/sti/sti_drm_connector.h
 create mode 100644 drivers/gpu/drm/sti/sti_drm_crtc.c
 create mode 100644 drivers/gpu/drm/sti/sti_drm_crtc.h
 create mode 100644 drivers/gpu/drm/sti/sti_drm_drv.c
 create mode 100644 drivers/gpu/drm/sti/sti_drm_drv.h
 create mode 100644 drivers/gpu/drm/sti/sti_drm_encoder.c
 create mode 100644 drivers/gpu/drm/sti/sti_drm_encoder.h
 create mode 100644 drivers/gpu/drm/sti/sti_drm_plane.c
 create mode 100644 drivers/gpu/drm/sti/sti_drm_plane.h
 create mode 100644 drivers/gpu/drm/sti/sti_gdp.c
 create mode 100644 drivers/gpu/drm/sti/sti_gdp.h
 create mode 100644 drivers/gpu/drm/sti/sti_hda.c
 create mode 100644 drivers/gpu/drm/sti/sti_hda.h
 create mode 100644 drivers/gpu/drm/sti/sti_hdmi.c
 create mode 100644 drivers/gpu/drm/sti/sti_hdmi.h
 create mode 100644 drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c
 create mode 100644 drivers/gpu/drm/sti/sti_hdmi_tx3g4c28phy.c
 create mode 100644 drivers/gpu/drm/sti/sti_layer.c
 create mode 100644 drivers/gpu/drm/sti/sti_layer.h
 create mode 100644 drivers/gpu/drm/sti/sti_mixer.c
 create mode 100644 drivers/gpu/drm/sti/sti_mixer.h
 create mode 100644 drivers/gpu/drm/sti/sti_tvout.c
 create mode 100644 drivers/gpu/drm/sti/sti_tvout.h
 create mode 100644 drivers/gpu/drm/sti/sti_vid.c
 create mode 100644 drivers/gpu/drm/sti/sti_vid.h
 create mode 100644 drivers/gpu/drm/sti/sti_vtac_rx.c
 create mode 100644 drivers/gpu/drm/sti/sti_vtac_tx.c
 create mode 100644 drivers/gpu/drm/sti/sti_vtac_utils.h
 create mode 100644 drivers/gpu/drm/sti/sti_vtg.c
 create mode 100644 drivers/gpu/drm/sti/sti_vtg.h
 create mode 100644 drivers/gpu/drm/sti/sti_vtg_utils.c
 create mode 100644 drivers/gpu/drm/sti/sti_vtg_utils.h
Signature · 1 line
1.9.1
#1 lore raw

PATCH v3 1/16 drm: sti: add VTG driver

Video Time Generator drivers are used to synchronize the compositor
and tvout hardware IPs by providing line count, sample count,
synchronization signals (HSYNC, VSYNC) and top and bottom fields indication. VTG are used by pair for each data path (main or auxiliary): one for master and one for slave.

---
 drivers/gpu/drm/Kconfig             |   2 +
 drivers/gpu/drm/Makefile            |   1 +
 drivers/gpu/drm/sti/Kconfig         |  11 +
 drivers/gpu/drm/sti/Makefile        |   3 +
 drivers/gpu/drm/sti/sti_vtg.c       | 468 ++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/sti/sti_vtg.h       |  20 ++
 drivers/gpu/drm/sti/sti_vtg_utils.c |  99 ++++++++
 drivers/gpu/drm/sti/sti_vtg_utils.h |  29 +++
 8 files changed, 633 insertions(+)
 create mode 100644 drivers/gpu/drm/sti/Kconfig
 create mode 100644 drivers/gpu/drm/sti/Makefile
 create mode 100644 drivers/gpu/drm/sti/sti_vtg.c
 create mode 100644 drivers/gpu/drm/sti/sti_vtg.h
 create mode 100644 drivers/gpu/drm/sti/sti_vtg_utils.c
 create mode 100644 drivers/gpu/drm/sti/sti_vtg_utils.h
drivers/gpu/drm/Kconfig +2 -0
index d1cc2f6..0e30029 100644
@@ -201,3 +201,5 @@ source "drivers/gpu/drm/tegra/Kconfig"
 source "drivers/gpu/drm/panel/Kconfig"
 
 source "drivers/gpu/drm/bridge/Kconfig"
+
+source "drivers/gpu/drm/sti/Kconfig"
drivers/gpu/drm/Makefile +1 -0
index 5e792b0..44f7b17 100644
@@ -61,6 +61,7 @@ obj-$(CONFIG_DRM_QXL) += qxl/
 obj-$(CONFIG_DRM_BOCHS) += bochs/
 obj-$(CONFIG_DRM_MSM) += msm/
 obj-$(CONFIG_DRM_TEGRA) += tegra/
+obj-$(CONFIG_DRM_STI) += sti/
 obj-y			+= i2c/
 obj-y			+= panel/
 obj-y			+= bridge/
drivers/gpu/drm/sti/Kconfig new file +11 -0
new file mode 100644
index 0000000..3fff278
@@ -0,0 +1,11 @@
+config DRM_STI
+	bool "DRM Support for STMicroelectronics SoC stiH41x Series"
+	depends on DRM && (SOC_STIH415 || SOC_STIH416 || ARCH_MULTIPLATFORM)
+	help
+	  Choose this option to enable DRM on STM stiH41x chipset
+
+config VTG_STI
+	bool "Video Timing Generator for STMicroelectronics SoC stiH41x Series"
+	depends on DRM_STI
+	help
+	  Choose this option to enable VTG on STM stiH41x chipset
drivers/gpu/drm/sti/Makefile new file +3 -0
new file mode 100644
index 0000000..33216e1
@@ -0,0 +1,3 @@
+ccflags-y := -Iinclude/drm
+
+obj-$(CONFIG_VTG_STI) += sti_vtg.o sti_vtg_utils.o
drivers/gpu/drm/sti/sti_vtg.c new file +468 -0

468 lines not on this page · raw message

drivers/gpu/drm/sti/sti_vtg.h new file +20 -0
new file mode 100644
index 0000000..da67eb3
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) STMicroelectronics SA 2013
+ * Author: Benjamin Gaignard <[email protected]> for STMicroelectronics.
+ * License terms:  GNU General Public License (GPL), version 2
+ */
+
+#ifndef _STI_VTG_H_
+#define _STI_VTG_H_
+
+#include <linux/platform_device.h>
+#include <drm/drmP.h>
+
+extern struct device *vtg_main;
+extern struct device *vtg_aux;
+
+int vtg_set_config(struct device *dev, const struct drm_display_mode *mode);
+int vtg_register_client(struct device *dev, struct notifier_block *nb);
+int vtg_unregister_client(struct device *dev, struct notifier_block *nb);
+
+#endif
drivers/gpu/drm/sti/sti_vtg_utils.c new file +99 -0

99 lines not on this page · raw message

drivers/gpu/drm/sti/sti_vtg_utils.h new file +29 -0
new file mode 100644
index 0000000..fea2852
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) STMicroelectronics SA 2013
+ * Authors: Benjamin Gaignard <[email protected]>
+ *          Fabien Dessenne <[email protected]>
+ *          for STMicroelectronics.
+ * License terms:  GNU General Public License (GPL), version 2
+ */
+
+#ifndef _STI_VTG_UTILS_H_
+#define _STI_VTG_UTILS_H_
+
+#include <drm/drmP.h>
+
+#define WAIT_NEXT_VSYNC_MS      50 /*ms*/
+
+#define VTG_MAIN                0
+#define VTG_AUX                 1
+
+#define VTG_TOP_FIELD_EVENT     1
+#define VTG_BOTTOM_FIELD_EVENT  2
+
+int sti_vtg_setconfig(int main_aux, const struct drm_display_mode *mode);
+int sti_vtg_register_client(int main_aux, struct notifier_block *nb);
+int sti_vtg_unregister_client(int main_aux, struct notifier_block *nb);
+
+u32 sti_vtg_get_line_number(struct drm_display_mode mode, int y);
+u32 sti_vtg_get_pixel_number(struct drm_display_mode mode, int x);
+
+#endif
Signature · 1 line
1.9.1
#2 lore raw

Re: [PATCH v3 01/16] drm: sti: add VTG driver

Quoted 4 lines · Benjamin Gaignard

Video Time Generator drivers are used to synchronize the compositor
and tvout hardware IPs by providing line count, sample count,
synchronization signals (HSYNC, VSYNC) and top and bottom fields indication. VTG are used by pair for each data path (main or auxiliary): one for master and one for slave.

Please wrap commit messages at 72 characters.

Quoted 1 line
drivers/gpu/drm/sti/Makefile +0 -0

[...]

drivers/gpu/drm/sti/Makefile line 1

Quoted 6 lines

new file mode 100644
index 0000000..33216e1

drivers/gpu/drm/sti/Makefile new file +1 -0
@@ -0,0 +1,3 @@
+ccflags-y := -Iinclude/drm

I don't think you need this. If you include DRM headers you should be prefixing them with drm/ anyway.

Quoted 1 line
drivers/gpu/drm/sti/sti_vtg.c +0 -0

[...]

drivers/gpu/drm/sti/sti_vtg.c line 13

Quoted 4 lines
drivers/gpu/drm/sti/sti_vtg.c +4 -0
+#include <linux/component.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/notifier.h>

I prefer these to be sorted alphabetically.

drivers/gpu/drm/sti/sti_vtg.c line 19

Quoted 5 lines
drivers/gpu/drm/sti/sti_vtg.c +5 -0
+#include "sti_vtg_utils.h"
+#include "sti_vtg.h"
+
+#define VTG_TYPE_MASTER         0
+#define VTG_TYPE_SLAVE_BY_EXT0  1

This is somewhat odd. I'll try to make some suggestions later on on how to possibly improve on this.

Quoted 24 lines
drivers/gpu/drm/sti/sti_vtg.c +24 -0
+/* registers offset */
+#define VTG_MODE		0x0000
+#define VTG_CLKLN		0x0008
+#define VTG_HLFLN		0x000C
+#define VTG_DRST_AUTOC		0x0010
+#define VTG_VID_TFO		0x0040
+#define VTG_VID_TFS		0x0044
+#define VTG_VID_BFO		0x0048
+#define VTG_VID_BFS		0x004C
+
+#define VTG_HOST_ITS		0x0078
+#define VTG_HOST_ITS_BCLR	0x007C
+#define VTG_HOST_ITM_BCLR	0x0088
+#define VTG_HOST_ITM_BSET	0x008C
+
+#define VTG_H_HD_1		0x00C0
+#define VTG_TOP_V_VD_1		0x00C4
+#define VTG_BOT_V_VD_1		0x00C8
+#define VTG_TOP_V_HD_1		0x00CC
+#define VTG_BOT_V_HD_1		0x00D0
+
+#define VTG_H_HD_2		0x00E0
+#define VTG_TOP_V_VD_2		0x00E4
+#define VTG_BOT_V_VD_2		0x00E8

drivers/gpu/drm/sti/sti_vtg.c line 54

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtg.c +10 -0
+#define VTG_TOP_V_HD_2		0x00EC
+#define VTG_BOT_V_HD_2		0x00F0
+
+#define VTG_H_HD_3		0x0100
+#define VTG_TOP_V_VD_3		0x0104
+#define VTG_BOT_V_VD_3		0x0108
+#define VTG_TOP_V_HD_3		0x010C
+#define VTG_BOT_V_HD_3		0x0110
+
+/* IRQ mask */

These bits are also mirrored in the status register, so "mask" isn't entirely accurate.

drivers/gpu/drm/sti/sti_vtg.c line 56

Quoted 2 lines
drivers/gpu/drm/sti/sti_vtg.c +2 -0
+#define VTG_IRQ_TOP_FIELD_MASK     (1L << 1)
+#define VTG_IRQ_BOTTOM_FIELD_MASK  (1L << 0)

I think for these it's safe to leave out the _MASK suffix since they are really just individual bits in the interrupt registers.

drivers/gpu/drm/sti/sti_vtg.c line 58

Quoted 2 lines
drivers/gpu/drm/sti/sti_vtg.c +2 -0
+#define VTG_IRQ_MASK		   (VTG_IRQ_TOP_FIELD_MASK | \
+				    VTG_IRQ_BOTTOM_FIELD_MASK)

You should be using tabs and spaces more consistently. The general rule of thumb is to indent using tabs and use spaces only to pad and align.

drivers/gpu/drm/sti/sti_vtg.c

Quoted 2 lines
drivers/gpu/drm/sti/sti_vtg.c +2 -0
+
+/* Delay introduced by the AWG in nb of pixels */

What's an AWG?

drivers/gpu/drm/sti/sti_vtg.c line 65

Quoted 5 lines
drivers/gpu/drm/sti/sti_vtg.c +5 -0
+#define AWG_DELAY_HD            (-9)
+#define AWG_DELAY_ED            (-8)
+#define AWG_DELAY_SD            (-7)
+
+static const struct of_device_id vtg_match_types[];

It's more typical to avoid this kind of forward declaration. Instead you can move the vtg_match_types table right before the first reference (i.e. vtg_compositor_probe()). Also _types is an odd suffix. Maybe vtg_of_match?

Quoted 5 lines
drivers/gpu/drm/sti/sti_vtg.c +5 -0
+/*
+ * STI VTG data structure
+ *
+ * @nb_reg: number of memory resources to register
+ * @reg_names: names of the memory resources to register

drivers/gpu/drm/sti/sti_vtg.c line 81

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtg.c +10 -0
+ * @regs: ioremapped registers
+ */
+#define MAX_MEM_REGION 2
+#define VTG_MASTER  0
+#define VTG_SLAVE   1
+struct sti_vtg_data {
+	int nb_reg;
+	char *reg_names[MAX_MEM_REGION];
+	void __iomem *regs[MAX_MEM_REGION];
+};

The primary reason why I dislike this is that it requires you to clutter your code with conditionals as to the type of VTG. On the other hand, if you can expose both master and slave VTGs as separate devices you can handle them more uniformly.

Quoted 14 lines
drivers/gpu/drm/sti/sti_vtg.c +14 -0
+/*
+ * STI VTG structure
+ *
+ * @dev: pointer to device driver
+ * @data: data associated to the device
+ * @irq: VTG irq
+ * @type: VTG type (main or aux)
+ * @notifier_list: notifier callback
+ */
+struct sti_vtg {
+	struct device *dev;
+	struct sti_vtg_data data;
+	int irq;
+	int type;

drivers/gpu/drm/sti/sti_vtg.c line 106

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtg.c +10 -0
+	struct raw_notifier_head notifier_list;
+};
+
+/*
+ * STiH416:
+ * --------
+ * VTG slave is connected to the VTG master by the ext0 input (ext1 input is
+ * left unconnected).
+ *
+ *                  MPE               !   !             SAS

What are MPE and SAS?

Quoted 11 lines
+ *    ________                        !   !                        ________
+ *   |        |                       !   !                  ext0 |        |
+ *   |        |              _________!   !_________        ----->|        |
+ *   |  VTG   |    hsync    |         !   !         | hsync |     |  VTG   |
+ *   |        |------------>| VTAC Tx !==>! VTAC Rx |--------     |        |
+ *   | master |    vsync    |_________!   !_________| vsync       | slave  |
+ *   |        |                       !   !                  ---->|        |
+ *   |________|                       !   !                  ext1 |________|
+ *                                    !   !                            |
+ *                                    !   !                       synchro_irq

+ * */

drivers/gpu/drm/sti/sti_vtg.c line 121

Quoted 4 lines
drivers/gpu/drm/sti/sti_vtg.c +4 -0
+struct sti_vtg_data stih416_vtg_data = {
+	.nb_reg = 2,
+	.reg_names = {"master", "slave"},
+};

It seems to me like a better representation might be to split this into two separate devices, one being the master, the other the slave. That only works if the register spaces are reasonably well separated.

Quoted 17 lines
drivers/gpu/drm/sti/sti_vtg.c +17 -0
+/*
+ * STiH407:
+ * --------
+ * Only VTG master is used. There is no MPE and SAS domain => only one domain.
+ *
+ *                  MPE
+ *    ________
+ *   |        |
+ *   |        |
+ *   |  VTG   |    hsync
+ *   |        |------------>
+ *   | master |    vsync
+ *   |        |
+ *   |________|
+ *        |
+ *  synchro_irq
+ * */

drivers/gpu/drm/sti/sti_vtg.c line 149

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtg.c +10 -0
+struct sti_vtg_data stih407_vtg_data = {
+	.nb_reg = 1,
+	.reg_names = {"master"},
+};
+
+static int vtg_reset(void __iomem *regs)
+{
+	writel(1, regs + VTG_DRST_AUTOC);
+	return 0;
+}

This can't fail, so no need to make it return an int. Also I think this would be more consistent if it took a struct sti_vtg * instead of a pointer to the registers.

Quoted 17 lines
drivers/gpu/drm/sti/sti_vtg.c +17 -0
+static int vtg_reg_dump(struct device *dev, void __iomem *regs)
+{
+	dev_dbg(dev, "regs %p\n", regs);
+	dev_dbg(dev, "VTG_MODE 0x%x\n", readl(regs + VTG_MODE));
+	dev_dbg(dev, "VTG_CLKLN 0x%x\n", readl(regs + VTG_CLKLN));
+	dev_dbg(dev, "VTG_HLFLN 0x%x\n", readl(regs + VTG_HLFLN));
+	dev_dbg(dev, "VTG_VID_TFO 0x%x\n", readl(regs + VTG_VID_TFO));
+	dev_dbg(dev, "VTG_VID_BFO 0x%x\n", readl(regs + VTG_VID_BFO));
+	dev_dbg(dev, "VTG_VID_TFS 0x%x\n", readl(regs + VTG_VID_TFS));
+	dev_dbg(dev, "VTG_VID_BFS 0x%x\n", readl(regs + VTG_VID_BFS));
+	dev_dbg(dev, "VTG_H_HD_1 0x%x\n", readl(regs + VTG_H_HD_1));
+	dev_dbg(dev, "VTG_TOP_V_VD_1 0x%x\n", readl(regs + VTG_TOP_V_VD_1));
+	dev_dbg(dev, "VTG_BOT_V_VD_1 0x%x\n", readl(regs + VTG_BOT_V_VD_1));
+	dev_dbg(dev, "VTG_TOP_V_HD_1 0x%x\n", readl(regs + VTG_TOP_V_HD_1));
+	dev_dbg(dev, "VTG_BOT_V_HD_1 0x%x\n", readl(regs + VTG_BOT_V_HD_1));
+	dev_dbg(dev, "VTG_H_HD_2 0x%x\n", readl(regs + VTG_H_HD_2));
+	dev_dbg(dev, "VTG_TOP_V_VD_2 0x%x\n", readl(regs + VTG_TOP_V_VD_2));

drivers/gpu/drm/sti/sti_vtg.c line 177

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtg.c +10 -0
+	dev_dbg(dev, "VTG_BOT_V_VD_2 0x%x\n", readl(regs + VTG_BOT_V_VD_2));
+	dev_dbg(dev, "VTG_TOP_V_HD_2 0x%x\n", readl(regs + VTG_TOP_V_HD_2));
+	dev_dbg(dev, "VTG_BOT_V_HD_2 0x%x\n", readl(regs + VTG_BOT_V_HD_2));
+	dev_dbg(dev, "VTG_H_HD_3 0x%x\n", readl(regs + VTG_H_HD_3));
+	dev_dbg(dev, "VTG_TOP_V_VD_3 0x%x\n", readl(regs + VTG_TOP_V_VD_3));
+	dev_dbg(dev, "VTG_BOT_V_VD_3 0x%x\n", readl(regs + VTG_BOT_V_VD_3));
+	dev_dbg(dev, "VTG_TOP_V_HD_3 0x%x\n", readl(regs + VTG_TOP_V_HD_3));
+	dev_dbg(dev, "VTG_BOT_V_HD_3 0x%x\n", readl(regs + VTG_BOT_V_HD_3));
+	return 0;
+}

Maybe this should be exposed via debugfs?

drivers/gpu/drm/sti/sti_vtg.c line 180

Quoted 2 lines
drivers/gpu/drm/sti/sti_vtg.c +2 -0
+static int vtg_write_reg(void __iomem *regs,
+			 int type, const struct drm_display_mode *mode)

Perhaps this should be called something like vtg_set_mode() since it's evidently doing a whole lot more than just writing a register. Also it should take a struct sti_vtg *, in which case you can leave drop the type parameter as well.

drivers/gpu/drm/sti/sti_vtg.c

Quoted 2 lines
drivers/gpu/drm/sti/sti_vtg.c +2 -0
+{
+	int fo, fs, h_hd, v_vd, v_hd;

These should be u32. And you can probably get away with just a single one.

Quoted 21 lines
drivers/gpu/drm/sti/sti_vtg.c +21 -0
+
+	writel(mode->htotal, regs + VTG_CLKLN);
+	writel(mode->vtotal * 2, regs + VTG_HLFLN);
+
+	fo = (mode->vtotal - mode->vsync_start + 1) << 16;
+	fo |= mode->htotal - mode->hsync_start;
+	writel(fo, regs + VTG_VID_TFO);
+	writel(fo, regs + VTG_VID_BFO);
+
+	fs = (mode->vdisplay + mode->vtotal - mode->vsync_start + 1) << 16;
+	fs |= mode->hdisplay + mode->htotal - mode->hsync_start;
+	writel(fs, regs + VTG_VID_TFS);
+	writel(fs, regs + VTG_VID_BFS);
+
+	/* Prepare VTG set 1 for HDMI and VTG set 3 for HD DAC */
+	h_hd = (mode->hsync_end - mode->hsync_start) << 16;
+	writel(h_hd, regs + VTG_H_HD_1);
+
+	v_vd = (mode->vsync_end - mode->vsync_start + 1) << 16;
+	v_vd |= 1;
+	writel(v_vd, regs + VTG_TOP_V_VD_1);

drivers/gpu/drm/sti/sti_vtg.c line 213

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtg.c +10 -0
+	writel(v_vd, regs + VTG_BOT_V_VD_1);
+	writel(0, regs + VTG_TOP_V_HD_1);
+	writel(0, regs + VTG_BOT_V_HD_1);
+
+	/* Prepare VTG set 2 for for HD DCS */
+	writel(h_hd, regs + VTG_H_HD_2);
+	writel(v_vd, regs + VTG_TOP_V_VD_2);
+	writel(v_vd, regs + VTG_BOT_V_VD_2);
+	writel(0, regs + VTG_TOP_V_HD_2);
+	writel(0, regs + VTG_BOT_V_HD_2);

Does the ordering matter here? Otherwise the writes of the same value could be moved together and save a register.

Quoted 4 lines
drivers/gpu/drm/sti/sti_vtg.c +4 -0
+	/* Prepare VTG set 3 for HD Analog in HD mode */
+	h_hd = (mode->hsync_end - mode->hsync_start + AWG_DELAY_HD) << 16;
+	h_hd |= mode->htotal + AWG_DELAY_HD;
+	writel(h_hd, regs + VTG_H_HD_3);

drivers/gpu/drm/sti/sti_vtg.c line 228

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtg.c +10 -0
+
+	v_vd = (mode->vsync_end - mode->vsync_start) << 16;
+	v_vd |= mode->vtotal;
+	writel(v_vd, regs + VTG_TOP_V_VD_3);
+	writel(v_vd, regs + VTG_BOT_V_VD_3);
+
+	v_hd = (mode->htotal + AWG_DELAY_HD) << 16;
+	v_hd |= mode->htotal + AWG_DELAY_HD;
+	writel(v_hd, regs + VTG_TOP_V_HD_3);
+	writel(v_hd, regs + VTG_BOT_V_HD_3);

It's somewhat odd that many of these TOP/BOT pairs are written with the same values, but since I have no idea what each of them is supposed to do I can't really say if that's intentional or might be wrong. I assume that you've tested this code and therefore it works as expected, but it is still odd to write the same value into so many different registers.

drivers/gpu/drm/sti/sti_vtg.c line 239

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtg.c +10 -0
+	/* Mode */
+	writel(type, regs + VTG_MODE);
+	return 0;
+}
+
+static int vtg_disable_irq(void __iomem *regs)
+{
+	/* Clear interrupt status and mask */
+	writel(0xFFFF, regs + VTG_HOST_ITS_BCLR);
+	writel(0xFFFF, regs + VTG_HOST_ITM_BCLR);

I think typically "disabling an interrupt" only means clearing (or setting, depending on the hardware) the mask. If you clear the interrupt status at the same time you're also dropping any pending interrupts.

Also I think a more common pattern would be to disable interrupts first to make sure that clearing them won't immediately trigger a new interrupt.

This should also take a struct sti_vtg * and not return anything since it will never fail.

drivers/gpu/drm/sti/sti_vtg.c line 248

Quoted 9 lines
drivers/gpu/drm/sti/sti_vtg.c +9 -0
+	return 0;
+}
+
+static int vtg_enable_irq(void __iomem *regs)
+{
+	vtg_disable_irq(regs);
+	writel(VTG_IRQ_MASK, regs + VTG_HOST_ITM_BSET);
+	return 0;
+}

I think in this case it would probably be useful to open-code this rather than reuse vtg_disable_irq(). For instance when interrupts are to be enabled, why do they need to disable them first? It sounds like if that's what you really want, then you should do it using something explicit like this:

	vtg_disable_irq(...);
	vtg_enable_irq(...);

drivers/gpu/drm/sti/sti_vtg.c line 252

Quoted 3 lines
drivers/gpu/drm/sti/sti_vtg.c +3 -0
+int vtg_set_config(struct device *dev, const struct drm_display_mode *mode)
+{
+	struct sti_vtg *vtg = dev_get_drvdata(dev);

This seems somewhat brittle. I'd recommend you turn this into something more robust. Just to illustrate, and I haven't looked at any other patches yet, so I may be completely wrong here, here's what I'd imagine the device tree for this to look like:

	/ {
		/* master VTG */
		vtg@00000000 {
			reg = <0x00000000 0x1000>;

			st,slave = <&slave>;
		};

		/* slave VTG */
		slave: vtg@00001000 {
			reg = <0x00001000 0x1000>;
		};

		...
	};

Then the VTG driver could register each of the devices as VTG and the master could look the slave up using something like:

	struct platform_device *pdev; /* from .probe() */
	struct sti_vtg *vtg; /* allocated earlier */
	struct device_node *np;
	int err;

	np = of_parse_phandle(pdev->dev.of_node, "st,slave", 0);
	if (np) {
		/* VTG is a master, lookup slave */
		vtg->slave = of_vtg_find(np);
		/*
		 * This could be -EPROBE_DEFER if the slave hasn't been
		 * registered yet.
		 */
		if (IS_ERR(vtg->slave))
			return PTR_ERR(vtg->slave);
	} else {
		/* VTG is a slave */
	}

	...

	err = vtg_register(vtg);
	if (err < 0) {
		...
	}

vtg_register() could simply add a VTG into a global list, which of_vtg_find() could traverse to find a VTG matching the device node parsed from the phandle.

drivers/gpu/drm/sti/sti_vtg.c line 259

Quoted 7 lines
drivers/gpu/drm/sti/sti_vtg.c +7 -0
+	struct sti_vtg_data *data = &vtg->data;
+
+	if (!vtg)
+		return 1;
+
+	if (!data->regs[VTG_MASTER])
+		return 1;

With the above these additional checks become mostly unnecessary.

drivers/gpu/drm/sti/sti_vtg.c line 266

Quoted 7 lines
drivers/gpu/drm/sti/sti_vtg.c +7 -0
+
+	/* write slave / master configuration */
+	if (data->regs[VTG_SLAVE])
+		vtg_write_reg(data->regs[VTG_SLAVE],
+			      VTG_TYPE_SLAVE_BY_EXT0, mode);
+
+	vtg_write_reg(data->regs[VTG_MASTER], VTG_TYPE_MASTER, mode);

And this would become something like:

	if (vtg->slave)
		vtg_set_mode(vtg->slave, mode);

	vtg_set_mode(vtg, mode);

drivers/gpu/drm/sti/sti_vtg.c line 272

Quoted 5 lines
drivers/gpu/drm/sti/sti_vtg.c +5 -0
+	/* reset slave and then master */
+	if (data->regs[VTG_SLAVE])
+		vtg_reset(data->regs[VTG_SLAVE]);
+
+	vtg_reset(data->regs[VTG_MASTER]);
	if (vtg->slave)
		vtg_reset(vtg->slave);

	vtg_reset(vtg);

drivers/gpu/drm/sti/sti_vtg.c line 278

Quoted 5 lines
drivers/gpu/drm/sti/sti_vtg.c +5 -0
+	/* Enable irq for the vtg vblank synchro */
+	if (data->regs[VTG_SLAVE])
+		vtg_enable_irq(data->regs[VTG_SLAVE]);
+	else
+		vtg_enable_irq(data->regs[VTG_MASTER]);
	if (vtg->slave)
		vtg_enable_irq(vtg->slave);
	else
		vtg_enable_irq(vtg);

drivers/gpu/drm/sti/sti_vtg.c line 283

Quoted 4 lines
drivers/gpu/drm/sti/sti_vtg.c +4 -0
+	if (data->regs[VTG_SLAVE])
+		vtg_reg_dump(dev, data->regs[VTG_SLAVE]);
+
+	vtg_reg_dump(dev, data->regs[VTG_MASTER]);
	if (vtg->slave)
		vtg_reg_dump(vtg);

	vtg_reg_dump(vtg);

Of course this in particular wouldn't be present in the final driver but rather exposed via each VTG's debugfs tree.

drivers/gpu/drm/sti/sti_vtg.c line 298

Quoted 11 lines
drivers/gpu/drm/sti/sti_vtg.c +11 -0
+int vtg_register_client(struct device *dev, struct notifier_block *nb)
+{
+	struct sti_vtg *vtg = dev_get_drvdata(dev);
+	return raw_notifier_chain_register(&vtg->notifier_list, nb);
+}
+
+int vtg_unregister_client(struct device *dev, struct notifier_block *nb)
+{
+	struct sti_vtg *vtg = dev_get_drvdata(dev);
+	return raw_notifier_chain_unregister(&vtg->notifier_list, nb);
+}

Can you explain what you need the notifier for? I suppose I'll see in some later patch, but at this rate it'll take me a while to get there. =) My gut tells me that we won't be needing it though.

Quoted 11 lines
drivers/gpu/drm/sti/sti_vtg.c +11 -0
+static irqreturn_t vtg_irq_thread(int irq, void *arg)
+{
+	struct sti_vtg *vtg = arg;
+	struct sti_vtg_data *data = &vtg->data;
+	void __iomem *regs;
+	u32 status;
+
+	if (data->regs[VTG_SLAVE])
+		regs = data->regs[VTG_SLAVE];
+	else
+		regs = data->regs[VTG_MASTER];

drivers/gpu/drm/sti/sti_vtg.c line 320

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtg.c +10 -0
+
+	status = readl(regs + VTG_HOST_ITS);
+
+	writel(status, regs + VTG_HOST_ITS_BCLR);
+	/* TODO: check why this sync bus write solves the problem which
+	 * is that without this line, the handler is sometimes called twice,
+	 * first with status = 1 or 2, and immediately after with status=0
+	 */
+	/* sync bus write */
+	readl(regs + VTG_HOST_ITS);

I suspect this could be caused by wrongly writing the interrupt mask and status registers.

drivers/gpu/drm/sti/sti_vtg.c line 353

Quoted 11 lines
drivers/gpu/drm/sti/sti_vtg.c +11 -0
+static int vtg_compositor_bind(struct device *dev, struct device *master,
+	void *d)
+{
+	return 0;
+}
+
+static void vtg_compositor_unbind(struct device *dev, struct device *master,
+	void *data)
+{
+	/* do nothing */
+}

Why do you even need these if they're no-ops? How are you going to get at them from other drivers if you don't hook them up with something here? Perhaps that will be added in some subsequent patch, though.

Quoted 4 lines
drivers/gpu/drm/sti/sti_vtg.c +4 -0
+static const struct component_ops vtg_compositor_ops = {
+	.bind	= vtg_compositor_bind,
+	.unbind	= vtg_compositor_unbind,
+};

drivers/gpu/drm/sti/sti_vtg.c line 368

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtg.c +10 -0
+
+static int vtg_compositor_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct device_node *np = dev->of_node;
+	struct sti_vtg *vtg;
+	struct resource *res;
+	char irq_name[32];
+	struct sti_vtg_data *data;
+	int i;

This can be unsigned.

drivers/gpu/drm/sti/sti_vtg.c line 371

Quoted 3 lines
drivers/gpu/drm/sti/sti_vtg.c +3 -0
+	int ret;
+
+	DRM_INFO("%s\n", __func__);

I don't think DRM_INFO is the loglevel you want here.

drivers/gpu/drm/sti/sti_vtg.c line 374

Quoted 3 lines
drivers/gpu/drm/sti/sti_vtg.c +3 -0
+
+	if (!np)
+		return -ENXIO;

If the driver doesn't support non-OF configurations it's safe to assume that this will never be NULL.

drivers/gpu/drm/sti/sti_vtg.c line 380

Quoted 6 lines
drivers/gpu/drm/sti/sti_vtg.c +6 -0
+
+	vtg = devm_kzalloc(dev, sizeof(*vtg), GFP_KERNEL);
+	if (!vtg) {
+		DRM_ERROR("Failed to allocate VTG context\n");
+		return -ENOMEM;
+	}

There's no need for the error message, since allocation failures will already be noisily reported by the allocator.

drivers/gpu/drm/sti/sti_vtg.c line 385

Quoted 5 lines
drivers/gpu/drm/sti/sti_vtg.c +5 -0
+
+	vtg->dev = dev;
+
+	/* populate data structure depending on compatibility */
+	BUG_ON(!of_match_node(vtg_match_types, np)->data);

This is kind of pointless since the memcpy() below will oops equally well if ->data == NULL. I don't think you need to check this at all. If the device can't be matched in the table this function won't be called. And if .data has been set for the matching entry in the table this won't be NULL. Leaving the .data field unset doesn't make any sense for this driver.

drivers/gpu/drm/sti/sti_vtg.c line 388

Quoted 3 lines
drivers/gpu/drm/sti/sti_vtg.c +3 -0
+
+	memcpy(&vtg->data, of_match_node(vtg_match_types, np)->data,
+	       sizeof(struct sti_vtg_data));

Also maybe a good idea would be to store the result of of_match_node() in a temporary variable to help with readability.

Why copy memory here in the first place? This kind of data is supposed to be static configuration data, which is why it's typically static const. I've suggested some changes above to make the design somewhat more straightforward.

Quoted 4 lines
drivers/gpu/drm/sti/sti_vtg.c +4 -0
+
+	data = &vtg->data;
+
+	/* Get resources */

drivers/gpu/drm/sti/sti_vtg.c line 402

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtg.c +10 -0
+	for (i = 0; i < data->nb_reg; i++) {
+		res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
+						   data->reg_names[i]);
+		if (!res) {
+			DRM_ERROR("Invalid resource\n");
+			return -ENOMEM;
+		}
+		data->regs[i] = devm_ioremap_nocache(dev,
+						     res->start,
+						     resource_size(res));

You're supposed to also request regions to make them for exclusive use by this driver (to avoid other drivers to access the same registers without proper synchronization).

Also the canonical way to do this is using devm_ioremap_resource().

drivers/gpu/drm/sti/sti_vtg.c line 408

Quoted 6 lines
drivers/gpu/drm/sti/sti_vtg.c +6 -0
+		if (IS_ERR(data->regs[i]))
+			return PTR_ERR(data->regs[i]);
+	}
+
+	vtg->irq = platform_get_irq_byname(pdev, "synchro_irq");
+	if (IS_ERR_VALUE(vtg->irq)) {

That's an odd way to write this. if (vtg->irq < 0) should be good enough.

drivers/gpu/drm/sti/sti_vtg.c line 413

Quoted 5 lines
drivers/gpu/drm/sti/sti_vtg.c +5 -0
+		DRM_ERROR("Failed to get VTG interrupt\n");
+		return vtg->irq;
+	}
+
+	snprintf(irq_name, sizeof(irq_name), "vsync-%s", vtg_get_name(vtg));

I think it would be just fine to use dev_name(vtg->dev) instead of generating this name, but meh.

Quoted 6 lines
drivers/gpu/drm/sti/sti_vtg.c +6 -0
+	RAW_INIT_NOTIFIER_HEAD(&vtg->notifier_list);
+
+	ret = devm_request_threaded_irq(dev, vtg->irq, NULL, vtg_irq_thread,
+					IRQF_ONESHOT, irq_name, vtg);
+	if (IS_ERR_VALUE(ret)) {
+		DRM_ERROR("Failed to register VTG interrupt\n");

drivers/gpu/drm/sti/sti_vtg.c line 430

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtg.c +10 -0
+		return ret;
+	}
+
+	if (of_property_read_bool(np, "vtg-aux")) {
+		vtg->type = VTG_AUX;
+		vtg_aux = dev;
+	} else {
+		vtg->type = VTG_MAIN;
+		vtg_main = dev;
+	}

I wonder if these couldn't be made dyna

drivers/gpu/drm/sti/sti_vtg.c line 434

Quoted 4 lines
drivers/gpu/drm/sti/sti_vtg.c +4 -0
+
+	platform_set_drvdata(pdev, vtg);
+
+	DRM_INFO("%s VTG %s\n", __func__, vtg_get_name(vtg));

This also looks like a leftover debug message.

Quoted 9 lines
drivers/gpu/drm/sti/sti_vtg.c +9 -0
+	return component_add(&pdev->dev, &vtg_compositor_ops);
+}
+
+static int vtg_compositor_remove(struct platform_device *pdev)
+{
+	component_del(&pdev->dev, &vtg_compositor_ops);
+	return 0;
+}
+

drivers/gpu/drm/sti/sti_vtg.c line 454

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtg.c +10 -0
+static const struct of_device_id vtg_match_types[] = {
+	{
+	 .compatible = "st,stih416-vtg",
+	 .data = &stih416_vtg_data,
+	 },
+	{
+	 .compatible = "st,stih407-vtg",
+	 .data = &stih407_vtg_data,
+	 },
+	{ /* end node */ }

There's some funky indentation here.

drivers/gpu/drm/sti/sti_vtg.c line 463

Quoted 9 lines
drivers/gpu/drm/sti/sti_vtg.c +9 -0
+};
+MODULE_DEVICE_TABLE(of, vtg_match_types);
+
+struct platform_driver sti_vtg_driver = {
+	.driver = {
+		   .name = "sti-vtg",
+		   .owner = THIS_MODULE,
+		   .of_match_table = vtg_match_types,
+		   },

Indentation is odd here again.

Quoted 11 lines
drivers/gpu/drm/sti/sti_vtg.c +5 -0
+	.probe = vtg_compositor_probe,
+	.remove = vtg_compositor_remove,
+};
+
+module_platform_driver(sti_vtg_driver);
drivers/gpu/drm/sti/sti_vtg.h new file +0 -0
new file mode 100644
index 0000000..da67eb3

drivers/gpu/drm/sti/sti_vtg.h line 10

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtg.h new file +10 -0
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) STMicroelectronics SA 2013
+ * Author: Benjamin Gaignard <[email protected]> for STMicroelectronics.
+ * License terms:  GNU General Public License (GPL), version 2
+ */
+
+#ifndef _STI_VTG_H_
+#define _STI_VTG_H_
+
+#include <linux/platform_device.h>

Why do you need this include? I don't see anything in this file that's defined in platform_device.h.

drivers/gpu/drm/sti/sti_vtg.h line 11

Quoted 1 line
drivers/gpu/drm/sti/sti_vtg.h new file +1 -0
+#include <drm/drmP.h>

You don't actually need to include these here. You can simply forward declare the structures (which works because you only pass around pointers to them) like so:

	struct drm_display_mode;
	struct notifier_block;
Quoted 18 lines
drivers/gpu/drm/sti/sti_vtg.h new file +9 -0
+
+extern struct device *vtg_main;
+extern struct device *vtg_aux;
+
+int vtg_set_config(struct device *dev, const struct drm_display_mode *mode);
+int vtg_register_client(struct device *dev, struct notifier_block *nb);
+int vtg_unregister_client(struct device *dev, struct notifier_block *nb);
+
+#endif
drivers/gpu/drm/sti/sti_vtg_utils.c new file +3 -0
new file mode 100644
index 0000000..06bb4b4
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) STMicroelectronics SA 2013
+ * Author: Benjamin Gaignard <[email protected]> for STMicroelectronics.

drivers/gpu/drm/sti/sti_vtg_utils.c line 13

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtg_utils.c new file +10 -0
+ * License terms:  GNU General Public License (GPL), version 2
+ */
+
+#include <linux/platform_device.h>
+
+#include "sti_vtg_utils.h"
+#include "sti_vtg.h"
+
+struct device *vtg_main;
+struct device *vtg_aux;

I don't think these should be here. There is always a better way than globals.

Quoted 75 lines
drivers/gpu/drm/sti/sti_vtg_utils.c new file +75 -0
+int sti_vtg_setconfig(int main_aux, const struct drm_display_mode *mode)
+{
+	if (main_aux == VTG_MAIN && vtg_main)
+		return vtg_set_config(vtg_main, mode);
+
+	if (main_aux == VTG_AUX && vtg_aux)
+		return vtg_set_config(vtg_aux, mode);
+
+	return 1;
+}
+
+int sti_vtg_register_client(int main_aux, struct notifier_block *nb)
+{
+	if (main_aux == VTG_MAIN && vtg_main)
+		return vtg_register_client(vtg_main, nb);
+
+	if (main_aux == VTG_AUX && vtg_aux)
+		return vtg_register_client(vtg_aux, nb);
+
+	return 1;
+}
+
+int sti_vtg_unregister_client(int main_aux, struct notifier_block *nb)
+{
+	if (main_aux == VTG_MAIN && vtg_main)
+		return vtg_unregister_client(vtg_main, nb);
+
+	if (main_aux == VTG_AUX && vtg_aux)
+		return vtg_unregister_client(vtg_aux, nb);
+
+	return 1;
+}
+
+/*
+ *       Active        Front        Sync       Back          Active
+ *       Region        Porch                  Porch          Region
+ * <---------------><-------->0<---------><--------><----------------->
+ *
+ *   ///////////////|                               |  ///////////////|
+ *  /////////////// |                               | /////////////// |
+ * ///////////////  |.........            ..........|///////////////  |
+ *                            0___________      x/ymin           x/ymax
+ *
+ * <--[hv]display-->                                 <--[hv]display-->
+ * <--[hv]sync_start--------->                       <--[hv]sync_start-
+ * <--[hv]sync_end----------------------->           <--[hv]sync_end---
+ * <--[hv]total------------------------------------> <--[hv]total------
+ */
+
+/*
+ * sti_vtg_get_line_number
+ *
+ * @mode: display mode to be used
+ * @y:    line
+ *
+ * Return the line number according to the display mode taking
+ * into account the Sync and Back Porch information.
+ * Video frame line numbers start at 1, y starts at 0.
+ * In interlaced modes the start line is the field line number of the odd
+ * field, but y is still defined as a progressive frame.
+ */
+u32 sti_vtg_get_line_number(struct drm_display_mode mode, int y)
+{
+	int start_line = mode.vtotal - mode.vsync_start + 1;
+
+	if (mode.flags & DRM_MODE_FLAG_INTERLACE)
+		start_line *= 2;
+
+	return start_line + y;
+}
+
+/*
+ * sti_vtg_get_pixel_number
+ *
+ * @mode: display mode to be used

drivers/gpu/drm/sti/sti_vtg_utils.c line 99

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtg_utils.c new file +10 -0
+ * @x:    row
+ *
+ * Return the pixel number according to the display mode taking
+ * into account the Sync and Back Porch information.
+ * Pixels are counted from 0.
+ */
+u32 sti_vtg_get_pixel_number(struct drm_display_mode mode, int x)
+{
+	return mode.htotal - mode.hsync_start + x;
+}

It's somewhat unclear as to what the purpose is of these. Perhaps it will become clearer when I see them used in a subsequent patch.

Also it looks like the comments are supposed to be kernel-doc, but they aren't really.

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtg_utils.h new file +4 -0
new file mode 100644
index 0000000..fea2852
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) STMicroelectronics SA 2013
+ * Authors: Benjamin Gaignard <[email protected]>
+ *          Fabien Dessenne <[email protected]>

drivers/gpu/drm/sti/sti_vtg_utils.h line 14

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtg_utils.h new file +10 -0
+ *          for STMicroelectronics.
+ * License terms:  GNU General Public License (GPL), version 2
+ */
+
+#ifndef _STI_VTG_UTILS_H_
+#define _STI_VTG_UTILS_H_
+
+#include <drm/drmP.h>
+
+#define WAIT_NEXT_VSYNC_MS      50 /*ms*/

What is this used for?

drivers/gpu/drm/sti/sti_vtg_utils.h line 20

Quoted 5 lines
drivers/gpu/drm/sti/sti_vtg_utils.h new file +5 -0
+#define VTG_MAIN                0
+#define VTG_AUX                 1
+
+#define VTG_TOP_FIELD_EVENT     1
+#define VTG_BOTTOM_FIELD_EVENT  2

I would hope that we can get rid of these somehow.

drivers/gpu/drm/sti/sti_vtg_utils.h line 24

Quoted 3 lines
drivers/gpu/drm/sti/sti_vtg_utils.h new file +3 -0
+int sti_vtg_setconfig(int main_aux, const struct drm_display_mode *mode);
+int sti_vtg_register_client(int main_aux, struct notifier_block *nb);
+int sti_vtg_unregister_client(int main_aux, struct notifier_block *nb);

And these.

It's intriguing hardware I must say, and certainly a challenge since it's so different from other DRM drivers. And it's taken quite some time to go through this one file, so I won't be able to review all patches in one go.

Thierry

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

#3 lore raw

Re: [PATCH v3 01/16] drm: sti: add VTG driver

In reply to Benjamin Gaignard
Quoted 68 lines

Video Time Generator drivers are used to synchronize the compositor
and tvout hardware IPs by providing line count, sample count,
synchronization signals (HSYNC, VSYNC) and top and bottom fields indication. VTG are used by pair for each data path (main or auxiliary): one for master and one for slave.

---
 drivers/gpu/drm/Kconfig             |   2 +
 drivers/gpu/drm/Makefile            |   1 +
 drivers/gpu/drm/sti/Kconfig         |  11 +
 drivers/gpu/drm/sti/Makefile        |   3 +
 drivers/gpu/drm/sti/sti_vtg.c       | 468 ++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/sti/sti_vtg.h       |  20 ++
 drivers/gpu/drm/sti/sti_vtg_utils.c |  99 ++++++++
 drivers/gpu/drm/sti/sti_vtg_utils.h |  29 +++
 8 files changed, 633 insertions(+)
 create mode 100644 drivers/gpu/drm/sti/Kconfig
 create mode 100644 drivers/gpu/drm/sti/Makefile
 create mode 100644 drivers/gpu/drm/sti/sti_vtg.c
 create mode 100644 drivers/gpu/drm/sti/sti_vtg.h
 create mode 100644 drivers/gpu/drm/sti/sti_vtg_utils.c
 create mode 100644 drivers/gpu/drm/sti/sti_vtg_utils.h
drivers/gpu/drm/Kconfig +2 -0
index d1cc2f6..0e30029 100644
@@ -201,3 +201,5 @@ source "drivers/gpu/drm/tegra/Kconfig"
 source "drivers/gpu/drm/panel/Kconfig"
 
 source "drivers/gpu/drm/bridge/Kconfig"
+
+source "drivers/gpu/drm/sti/Kconfig"
drivers/gpu/drm/Makefile +1 -0
index 5e792b0..44f7b17 100644
@@ -61,6 +61,7 @@ obj-$(CONFIG_DRM_QXL) += qxl/
 obj-$(CONFIG_DRM_BOCHS) += bochs/
 obj-$(CONFIG_DRM_MSM) += msm/
 obj-$(CONFIG_DRM_TEGRA) += tegra/
+obj-$(CONFIG_DRM_STI) += sti/
 obj-y			+= i2c/
 obj-y			+= panel/
 obj-y			+= bridge/
drivers/gpu/drm/sti/Kconfig new file +11 -0
new file mode 100644
index 0000000..3fff278
@@ -0,0 +1,11 @@
+config DRM_STI
+	bool "DRM Support for STMicroelectronics SoC stiH41x Series"
+	depends on DRM && (SOC_STIH415 || SOC_STIH416 || ARCH_MULTIPLATFORM)
+	help
+	  Choose this option to enable DRM on STM stiH41x chipset
+
+config VTG_STI
+	bool "Video Timing Generator for STMicroelectronics SoC stiH41x Series"
+	depends on DRM_STI
+	help
+	  Choose this option to enable VTG on STM stiH41x chipset
drivers/gpu/drm/sti/Makefile new file +0 -0
new file mode 100644
index 0000000..33216e1

drivers/gpu/drm/sti/Makefile line 1

Quoted 1 line
drivers/gpu/drm/sti/Makefile new file +1 -0
@@ -0,0 +1,3 @@
+ccflags-y := -Iinclude/drm

Why is this required?

drivers/gpu/drm/sti/sti_vtg.c line 2

Quoted 9 lines
drivers/gpu/drm/sti/Makefile new file +1 -0
+obj-$(CONFIG_VTG_STI) += sti_vtg.o sti_vtg_utils.o
drivers/gpu/drm/sti/sti_vtg.c new file +2 -0
new file mode 100644
index 0000000..75d7125
@@ -0,0 +1,468 @@
+/*
+ * Copyright (C) STMicroelectronics SA 2013

2014

Quoted 44 lines
drivers/gpu/drm/sti/sti_vtg.c new file +44 -0
+ * Authors: Benjamin Gaignard <[email protected]>
+ *          Fabien Dessenne <[email protected]>
+ *          Vincent Abriou <[email protected]>
+ *          for STMicroelectronics.
+ * License terms:  GNU General Public License (GPL), version 2
+ */
+
+#include <linux/component.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/notifier.h>
+
+#include "sti_vtg_utils.h"
+#include "sti_vtg.h"
+
+#define VTG_TYPE_MASTER         0
+#define VTG_TYPE_SLAVE_BY_EXT0  1
+
+/* registers offset */
+#define VTG_MODE		0x0000
+#define VTG_CLKLN		0x0008
+#define VTG_HLFLN		0x000C
+#define VTG_DRST_AUTOC		0x0010
+#define VTG_VID_TFO		0x0040
+#define VTG_VID_TFS		0x0044
+#define VTG_VID_BFO		0x0048
+#define VTG_VID_BFS		0x004C
+
+#define VTG_HOST_ITS		0x0078
+#define VTG_HOST_ITS_BCLR	0x007C
+#define VTG_HOST_ITM_BCLR	0x0088
+#define VTG_HOST_ITM_BSET	0x008C
+
+#define VTG_H_HD_1		0x00C0
+#define VTG_TOP_V_VD_1		0x00C4
+#define VTG_BOT_V_VD_1		0x00C8
+#define VTG_TOP_V_HD_1		0x00CC
+#define VTG_BOT_V_HD_1		0x00D0
+
+#define VTG_H_HD_2		0x00E0
+#define VTG_TOP_V_VD_2		0x00E4
+#define VTG_BOT_V_VD_2		0x00E8
+#define VTG_TOP_V_HD_2		0x00EC
+#define VTG_BOT_V_HD_2		0x00F0

drivers/gpu/drm/sti/sti_vtg.c line 56

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtg.c new file +10 -0
+
+#define VTG_H_HD_3		0x0100
+#define VTG_TOP_V_VD_3		0x0104
+#define VTG_BOT_V_VD_3		0x0108
+#define VTG_TOP_V_HD_3		0x010C
+#define VTG_BOT_V_HD_3		0x0110
+
+/* IRQ mask */
+#define VTG_IRQ_TOP_FIELD_MASK     (1L << 1)
+#define VTG_IRQ_BOTTOM_FIELD_MASK  (1L << 0)

BIT()

drivers/gpu/drm/sti/sti_vtg.c line 67

Quoted 11 lines
drivers/gpu/drm/sti/sti_vtg.c new file +11 -0
+#define VTG_IRQ_MASK		   (VTG_IRQ_TOP_FIELD_MASK | \
+				    VTG_IRQ_BOTTOM_FIELD_MASK)
+
+/* Delay introduced by the AWG in nb of pixels */
+#define AWG_DELAY_HD            (-9)
+#define AWG_DELAY_ED            (-8)
+#define AWG_DELAY_SD            (-7)
+
+static const struct of_device_id vtg_match_types[];
+
+/*

Kernel doc style comments start with /**

drivers/gpu/drm/sti/sti_vtg.c line 76

Quoted 9 lines
drivers/gpu/drm/sti/sti_vtg.c new file +9 -0
+ * STI VTG data structure
+ *
+ * @nb_reg: number of memory resources to register
+ * @reg_names: names of the memory resources to register
+ * @regs: ioremapped registers
+ */
+#define MAX_MEM_REGION 2
+#define VTG_MASTER  0
+#define VTG_SLAVE   1

I'd place these above the header.

drivers/gpu/drm/sti/sti_vtg.c line 83

Quoted 7 lines
drivers/gpu/drm/sti/sti_vtg.c new file +7 -0
+struct sti_vtg_data {
+	int nb_reg;
+	char *reg_names[MAX_MEM_REGION];
+	void __iomem *regs[MAX_MEM_REGION];
+};
+
+/*

Kernel doc notation please - /**

I won't comment on this again from here.

Quoted 46 lines
drivers/gpu/drm/sti/sti_vtg.c new file +46 -0
+ * STI VTG structure
+ *
+ * @dev: pointer to device driver
+ * @data: data associated to the device
+ * @irq: VTG irq
+ * @type: VTG type (main or aux)
+ * @notifier_list: notifier callback
+ */
+struct sti_vtg {
+	struct device *dev;
+	struct sti_vtg_data data;
+	int irq;
+	int type;
+	struct raw_notifier_head notifier_list;
+};
+
+/*
+ * STiH416:
+ * --------
+ * VTG slave is connected to the VTG master by the ext0 input (ext1 input is
+ * left unconnected).
+ *
+ *                  MPE               !   !             SAS
+ *    ________                        !   !                        ________
+ *   |        |                       !   !                  ext0 |        |
+ *   |        |              _________!   !_________        ----->|        |
+ *   |  VTG   |    hsync    |         !   !         | hsync |     |  VTG   |
+ *   |        |------------>| VTAC Tx !==>! VTAC Rx |--------     |        |
+ *   | master |    vsync    |_________!   !_________| vsync       | slave  |
+ *   |        |                       !   !                  ---->|        |
+ *   |________|                       !   !                  ext1 |________|
+ *                                    !   !                            |
+ *                                    !   !                       synchro_irq
+ * */
+struct sti_vtg_data stih416_vtg_data = {
+	.nb_reg = 2,
+	.reg_names = {"master", "slave"},
+};
+
+/*
+ * STiH407:
+ * --------
+ * Only VTG master is used. There is no MPE and SAS domain => only one domain.
+ *
+ *                  MPE
+ *    ________

drivers/gpu/drm/sti/sti_vtg.c line 139

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtg.c new file +10 -0
+ *   |        |
+ *   |        |
+ *   |  VTG   |    hsync
+ *   |        |------------>
+ *   | master |    vsync
+ *   |        |
+ *   |________|
+ *        |
+ *  synchro_irq
+ * */

Odd comment tail.

drivers/gpu/drm/sti/sti_vtg.c line 149

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtg.c new file +10 -0
+struct sti_vtg_data stih407_vtg_data = {
+	.nb_reg = 1,
+	.reg_names = {"master"},
+};
+
+static int vtg_reset(void __iomem *regs)
+{
+	writel(1, regs + VTG_DRST_AUTOC);
+	return 0;
+}

The return value of this is never checked. Make it an inline void.

Quoted 35 lines
drivers/gpu/drm/sti/sti_vtg.c new file +35 -0
+static int vtg_reg_dump(struct device *dev, void __iomem *regs)
+{
+	dev_dbg(dev, "regs %p\n", regs);
+	dev_dbg(dev, "VTG_MODE 0x%x\n", readl(regs + VTG_MODE));
+	dev_dbg(dev, "VTG_CLKLN 0x%x\n", readl(regs + VTG_CLKLN));
+	dev_dbg(dev, "VTG_HLFLN 0x%x\n", readl(regs + VTG_HLFLN));
+	dev_dbg(dev, "VTG_VID_TFO 0x%x\n", readl(regs + VTG_VID_TFO));
+	dev_dbg(dev, "VTG_VID_BFO 0x%x\n", readl(regs + VTG_VID_BFO));
+	dev_dbg(dev, "VTG_VID_TFS 0x%x\n", readl(regs + VTG_VID_TFS));
+	dev_dbg(dev, "VTG_VID_BFS 0x%x\n", readl(regs + VTG_VID_BFS));
+	dev_dbg(dev, "VTG_H_HD_1 0x%x\n", readl(regs + VTG_H_HD_1));
+	dev_dbg(dev, "VTG_TOP_V_VD_1 0x%x\n", readl(regs + VTG_TOP_V_VD_1));
+	dev_dbg(dev, "VTG_BOT_V_VD_1 0x%x\n", readl(regs + VTG_BOT_V_VD_1));
+	dev_dbg(dev, "VTG_TOP_V_HD_1 0x%x\n", readl(regs + VTG_TOP_V_HD_1));
+	dev_dbg(dev, "VTG_BOT_V_HD_1 0x%x\n", readl(regs + VTG_BOT_V_HD_1));
+	dev_dbg(dev, "VTG_H_HD_2 0x%x\n", readl(regs + VTG_H_HD_2));
+	dev_dbg(dev, "VTG_TOP_V_VD_2 0x%x\n", readl(regs + VTG_TOP_V_VD_2));
+	dev_dbg(dev, "VTG_BOT_V_VD_2 0x%x\n", readl(regs + VTG_BOT_V_VD_2));
+	dev_dbg(dev, "VTG_TOP_V_HD_2 0x%x\n", readl(regs + VTG_TOP_V_HD_2));
+	dev_dbg(dev, "VTG_BOT_V_HD_2 0x%x\n", readl(regs + VTG_BOT_V_HD_2));
+	dev_dbg(dev, "VTG_H_HD_3 0x%x\n", readl(regs + VTG_H_HD_3));
+	dev_dbg(dev, "VTG_TOP_V_VD_3 0x%x\n", readl(regs + VTG_TOP_V_VD_3));
+	dev_dbg(dev, "VTG_BOT_V_VD_3 0x%x\n", readl(regs + VTG_BOT_V_VD_3));
+	dev_dbg(dev, "VTG_TOP_V_HD_3 0x%x\n", readl(regs + VTG_TOP_V_HD_3));
+	dev_dbg(dev, "VTG_BOT_V_HD_3 0x%x\n", readl(regs + VTG_BOT_V_HD_3));
+	return 0;
+}
+
+static int vtg_write_reg(void __iomem *regs,
+			 int type, const struct drm_display_mode *mode)
+{
+	int fo, fs, h_hd, v_vd, v_hd;
+
+	writel(mode->htotal, regs + VTG_CLKLN);
+	writel(mode->vtotal * 2, regs + VTG_HLFLN);

drivers/gpu/drm/sti/sti_vtg.c line 195

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtg.c new file +10 -0
+
+	fo = (mode->vtotal - mode->vsync_start + 1) << 16;
+	fo |= mode->htotal - mode->hsync_start;
+	writel(fo, regs + VTG_VID_TFO);
+	writel(fo, regs + VTG_VID_BFO);
+
+	fs = (mode->vdisplay + mode->vtotal - mode->vsync_start + 1) << 16;
+	fs |= mode->hdisplay + mode->htotal - mode->hsync_start;
+	writel(fs, regs + VTG_VID_TFS);
+	writel(fs, regs + VTG_VID_BFS);

This is all hieroglyphics to people who don't know what 'fo' and 'fs' is. Can you supplement my ignorance with some nice comments please? The same should apply to any code which isn't doing anything obvious.

Quoted 35 lines
drivers/gpu/drm/sti/sti_vtg.c new file +35 -0
+	/* Prepare VTG set 1 for HDMI and VTG set 3 for HD DAC */
+	h_hd = (mode->hsync_end - mode->hsync_start) << 16;
+	writel(h_hd, regs + VTG_H_HD_1);
+
+	v_vd = (mode->vsync_end - mode->vsync_start + 1) << 16;
+	v_vd |= 1;
+	writel(v_vd, regs + VTG_TOP_V_VD_1);
+	writel(v_vd, regs + VTG_BOT_V_VD_1);
+	writel(0, regs + VTG_TOP_V_HD_1);
+	writel(0, regs + VTG_BOT_V_HD_1);
+
+	/* Prepare VTG set 2 for for HD DCS */
+	writel(h_hd, regs + VTG_H_HD_2);
+	writel(v_vd, regs + VTG_TOP_V_VD_2);
+	writel(v_vd, regs + VTG_BOT_V_VD_2);
+	writel(0, regs + VTG_TOP_V_HD_2);
+	writel(0, regs + VTG_BOT_V_HD_2);
+
+	/* Prepare VTG set 3 for HD Analog in HD mode */
+	h_hd = (mode->hsync_end - mode->hsync_start + AWG_DELAY_HD) << 16;
+	h_hd |= mode->htotal + AWG_DELAY_HD;
+	writel(h_hd, regs + VTG_H_HD_3);
+
+	v_vd = (mode->vsync_end - mode->vsync_start) << 16;
+	v_vd |= mode->vtotal;
+	writel(v_vd, regs + VTG_TOP_V_VD_3);
+	writel(v_vd, regs + VTG_BOT_V_VD_3);
+
+	v_hd = (mode->htotal + AWG_DELAY_HD) << 16;
+	v_hd |= mode->htotal + AWG_DELAY_HD;
+	writel(v_hd, regs + VTG_TOP_V_HD_3);
+	writel(v_hd, regs + VTG_BOT_V_HD_3);
+
+	/* Mode */
+	writel(type, regs + VTG_MODE);

drivers/gpu/drm/sti/sti_vtg.c line 241

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtg.c new file +10 -0
+	return 0;
+}
+
+static int vtg_disable_irq(void __iomem *regs)
+{
+	/* Clear interrupt status and mask */
+	writel(0xFFFF, regs + VTG_HOST_ITS_BCLR);
+	writel(0xFFFF, regs + VTG_HOST_ITM_BCLR);
+	return 0;
+}

What's the point in returning a value if a) it's always the same and
b) it's never checked?

drivers/gpu/drm/sti/sti_vtg.c line 248

Quoted 6 lines
drivers/gpu/drm/sti/sti_vtg.c new file +6 -0
+static int vtg_enable_irq(void __iomem *regs)
+{
+	vtg_disable_irq(regs);
+	writel(VTG_IRQ_MASK, regs + VTG_HOST_ITM_BSET);
+	return 0;
+}

Same here and for every other int returning function which is never checked.

drivers/gpu/drm/sti/sti_vtg.c line 256

Quoted 7 lines
drivers/gpu/drm/sti/sti_vtg.c new file +7 -0
+int vtg_set_config(struct device *dev, const struct drm_display_mode *mode)
+{
+	struct sti_vtg *vtg = dev_get_drvdata(dev);
+	struct sti_vtg_data *data = &vtg->data;
+
+	if (!vtg)
+		return 1;

What does '1 mean? Please return a valid error code.

drivers/gpu/drm/sti/sti_vtg.c line 259

Quoted 2 lines
drivers/gpu/drm/sti/sti_vtg.c new file +2 -0
+	if (!data->regs[VTG_MASTER])
+		return 1;

Same here and anywhere else in the patch-set which does this.

drivers/gpu/drm/sti/sti_vtg.c line 266

Quoted 6 lines
drivers/gpu/drm/sti/sti_vtg.c new file +6 -0
+	/* write slave / master configuration */
+	if (data->regs[VTG_SLAVE])
+		vtg_write_reg(data->regs[VTG_SLAVE],
+			      VTG_TYPE_SLAVE_BY_EXT0, mode);
+
+	vtg_write_reg(data->regs[VTG_MASTER], VTG_TYPE_MASTER, mode);

Any chance in this driver using Regmap?

drivers/gpu/drm/sti/sti_vtg.c line 278

Quoted 11 lines
drivers/gpu/drm/sti/sti_vtg.c new file +11 -0
+	/* reset slave and then master */
+	if (data->regs[VTG_SLAVE])
+		vtg_reset(data->regs[VTG_SLAVE]);
+
+	vtg_reset(data->regs[VTG_MASTER]);
+
+	/* Enable irq for the vtg vblank synchro */
+	if (data->regs[VTG_SLAVE])
+		vtg_enable_irq(data->regs[VTG_SLAVE]);
+	else
+		vtg_enable_irq(data->regs[VTG_MASTER]);

When you write slave/master configuration and reset a few lines up from here you write to master regardless and only conditionally write to slave. Why is that different here.

drivers/gpu/drm/sti/sti_vtg.c line 283

Quoted 4 lines
drivers/gpu/drm/sti/sti_vtg.c new file +4 -0
+	if (data->regs[VTG_SLAVE])
+		vtg_reg_dump(dev, data->regs[VTG_SLAVE]);
+
+	vtg_reg_dump(dev, data->regs[VTG_MASTER]);

Same here?

Why don't you bind all of these up into one if() instead of having 4 in a row that are exactly the same?

drivers/gpu/drm/sti/sti_vtg.c line 292

Quoted 8 lines
drivers/gpu/drm/sti/sti_vtg.c new file +8 -0
+	return 0;
+}
+
+int vtg_register_client(struct device *dev, struct notifier_block *nb)
+{
+	struct sti_vtg *vtg = dev_get_drvdata(dev);
+	return raw_notifier_chain_register(&vtg->notifier_list, nb);
+}

Do these need to be exported?

Quoted 7 lines
drivers/gpu/drm/sti/sti_vtg.c new file +7 -0
+int vtg_unregister_client(struct device *dev, struct notifier_block *nb)
+{
+	struct sti_vtg *vtg = dev_get_drvdata(dev);
+	return raw_notifier_chain_unregister(&vtg->notifier_list, nb);
+}
+
+static irqreturn_t vtg_irq_thread(int irq, void *arg)

drivers/gpu/drm/sti/sti_vtg.c line 310

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtg.c new file +10 -0
+{
+	struct sti_vtg *vtg = arg;
+	struct sti_vtg_data *data = &vtg->data;
+	void __iomem *regs;
+	u32 status;
+
+	if (data->regs[VTG_SLAVE])
+		regs = data->regs[VTG_SLAVE];
+	else
+		regs = data->regs[VTG_MASTER];

So if slave is present master will never be serviced?

drivers/gpu/drm/sti/sti_vtg.c line 318

Quoted 7 lines
drivers/gpu/drm/sti/sti_vtg.c new file +7 -0
+	status = readl(regs + VTG_HOST_ITS);
+
+	writel(status, regs + VTG_HOST_ITS_BCLR);
+	/* TODO: check why this sync bus write solves the problem which
+	 * is that without this line, the handler is sometimes called twice,
+	 * first with status = 1 or 2, and immediately after with status=0
+	 */

Fix this before upstreaming it.

drivers/gpu/drm/sti/sti_vtg.c line 328

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtg.c new file +10 -0
+	/* sync bus write */
+	readl(regs + VTG_HOST_ITS);
+
+	if (status & VTG_IRQ_TOP_FIELD_MASK) {
+		raw_notifier_call_chain(&vtg->notifier_list,
+					VTG_TOP_FIELD_EVENT, &vtg->type);
+	} else {
+		raw_notifier_call_chain(&vtg->notifier_list,
+					VTG_BOTTOM_FIELD_EVENT, &vtg->type);
+	}

event = (status & VTG_IRQ_TOP_FIELD_MASK) ?
VTG_TOP_FIELD_EVENT : VTG_BOTTOM_FIELD_EVENT,

Then you only have to have one call.

Quoted 19 lines
drivers/gpu/drm/sti/sti_vtg.c new file +19 -0
+	return IRQ_HANDLED;
+}
+
+static const char *vtg_get_name(struct sti_vtg *vtg)
+{
+	if (vtg->type == VTG_MAIN)
+		return "main";
+	else if (vtg->type == VTG_AUX)
+		return "aux";
+	else
+		return "?";
+}
+
+static int vtg_compositor_bind(struct device *dev, struct device *master,
+	void *d)
+{
+	return 0;
+}
+

drivers/gpu/drm/sti/sti_vtg.c line 358

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtg.c new file +10 -0
+static void vtg_compositor_unbind(struct device *dev, struct device *master,
+	void *data)
+{
+	/* do nothing */
+}
+
+static const struct component_ops vtg_compositor_ops = {
+	.bind	= vtg_compositor_bind,
+	.unbind	= vtg_compositor_unbind,
+};

If they're pointless, why supply them? Does the framework insist on it?

drivers/gpu/drm/sti/sti_vtg.c line 371

Quoted 12 lines
drivers/gpu/drm/sti/sti_vtg.c new file +12 -0
+static int vtg_compositor_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct device_node *np = dev->of_node;
+	struct sti_vtg *vtg;
+	struct resource *res;
+	char irq_name[32];
+	struct sti_vtg_data *data;
+	int i;
+	int ret;
+
+	DRM_INFO("%s\n", __func__);

Pointless debug - keep it out of the Mainlined driver.

drivers/gpu/drm/sti/sti_vtg.c line 374

Quoted 2 lines
drivers/gpu/drm/sti/sti_vtg.c new file +2 -0
+	if (!np)
+		return -ENXIO;

Not seen this before; -EINVAL or -ENODEV is common.

drivers/gpu/drm/sti/sti_vtg.c line 378

Quoted 3 lines
drivers/gpu/drm/sti/sti_vtg.c new file +3 -0
+	vtg = devm_kzalloc(dev, sizeof(*vtg), GFP_KERNEL);
+	if (!vtg) {
+		DRM_ERROR("Failed to allocate VTG context\n");

No need for OOM errors, just return -ENOMEM.

drivers/gpu/drm/sti/sti_vtg.c line 385

Quoted 7 lines
drivers/gpu/drm/sti/sti_vtg.c new file +7 -0
+		return -ENOMEM;
+	}
+
+	vtg->dev = dev;
+
+	/* populate data structure depending on compatibility */
+	BUG_ON(!of_match_node(vtg_match_types, np)->data);

I'm not sure killing the kernel over this is the correct thing to do.

Just return an error.

drivers/gpu/drm/sti/sti_vtg.c line 388

Quoted 2 lines
drivers/gpu/drm/sti/sti_vtg.c new file +2 -0
+	memcpy(&vtg->data, of_match_node(vtg_match_types, np)->data,
+	       sizeof(struct sti_vtg_data));

This is pretty ugly. Why aren't you just using pointers? At the very least, break these lines out.

drivers/gpu/drm/sti/sti_vtg.c line 399

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtg.c new file +10 -0
+	data = &vtg->data;
+
+	/* Get resources */
+	for (i = 0; i < data->nb_reg; i++) {
+		res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
+						   data->reg_names[i]);
+		if (!res) {
+			DRM_ERROR("Invalid resource\n");
+			return -ENOMEM;
+		}

No memory? Are you sure that's what it means?

Quoted 25 lines
drivers/gpu/drm/sti/sti_vtg.c new file +25 -0
+		data->regs[i] = devm_ioremap_nocache(dev,
+						     res->start,
+						     resource_size(res));
+		if (IS_ERR(data->regs[i]))
+			return PTR_ERR(data->regs[i]);
+	}
+
+	vtg->irq = platform_get_irq_byname(pdev, "synchro_irq");
+	if (IS_ERR_VALUE(vtg->irq)) {
+		DRM_ERROR("Failed to get VTG interrupt\n");
+		return vtg->irq;
+	}
+
+	snprintf(irq_name, sizeof(irq_name), "vsync-%s", vtg_get_name(vtg));
+
+	RAW_INIT_NOTIFIER_HEAD(&vtg->notifier_list);
+
+	ret = devm_request_threaded_irq(dev, vtg->irq, NULL, vtg_irq_thread,
+					IRQF_ONESHOT, irq_name, vtg);
+	if (IS_ERR_VALUE(ret)) {
+		DRM_ERROR("Failed to register VTG interrupt\n");
+		return ret;
+	}
+
+	if (of_property_read_bool(np, "vtg-aux")) {

drivers/gpu/drm/sti/sti_vtg.c line 434

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtg.c new file +10 -0
+		vtg->type = VTG_AUX;
+		vtg_aux = dev;
+	} else {
+		vtg->type = VTG_MAIN;
+		vtg_main = dev;
+	}
+
+	platform_set_drvdata(pdev, vtg);
+
+	DRM_INFO("%s VTG %s\n", __func__, vtg_get_name(vtg));

Again, no need for this.

drivers/gpu/drm/sti/sti_vtg.c line 448

Quoted 13 lines
drivers/gpu/drm/sti/sti_vtg.c new file +13 -0
+	return component_add(&pdev->dev, &vtg_compositor_ops);
+}
+
+static int vtg_compositor_remove(struct platform_device *pdev)
+{
+	component_del(&pdev->dev, &vtg_compositor_ops);
+	return 0;
+}
+
+static const struct of_device_id vtg_match_types[] = {
+	{
+	 .compatible = "st,stih416-vtg",
+	 .data = &stih416_vtg_data,

These need one more tab.

drivers/gpu/drm/sti/sti_vtg.c line 453

Quoted 6 lines
drivers/gpu/drm/sti/sti_vtg.c new file +5 -0
+	 },
+	{
+	 .compatible = "st,stih407-vtg",
+	 .data = &stih407_vtg_data,
 
+	 },

In fact, this is all a little messy, use tabs throughout.

drivers/gpu/drm/sti/sti_vtg.c line 463

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtg.c new file +10 -0
+	{ /* end node */ }
+};
+MODULE_DEVICE_TABLE(of, vtg_match_types);
+
+struct platform_driver sti_vtg_driver = {
+	.driver = {
+		   .name = "sti-vtg",
+		   .owner = THIS_MODULE,
+		   .of_match_table = vtg_match_types,
+		   },

These tabs are not correct either. Did you run checkpatch.pl?

drivers/gpu/drm/sti/sti_vtg.h line 2

Quoted 13 lines
drivers/gpu/drm/sti/sti_vtg.c new file +5 -0
+	.probe = vtg_compositor_probe,
+	.remove = vtg_compositor_remove,
+};
+
+module_platform_driver(sti_vtg_driver);
drivers/gpu/drm/sti/sti_vtg.h new file +2 -0
new file mode 100644
index 0000000..da67eb3
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) STMicroelectronics SA 2013

It's 2014

drivers/gpu/drm/sti/sti_vtg.h line 8

Quoted 6 lines
drivers/gpu/drm/sti/sti_vtg.h new file +6 -0
+ * Author: Benjamin Gaignard <[email protected]> for STMicroelectronics.
+ * License terms:  GNU General Public License (GPL), version 2
+ */
+
+#ifndef _STI_VTG_H_
+#define _STI_VTG_H_

DRM_STI...?

Quoted 28 lines
drivers/gpu/drm/sti/sti_vtg.h new file +11 -0
+#include <linux/platform_device.h>
+#include <drm/drmP.h>
+
+extern struct device *vtg_main;
+extern struct device *vtg_aux;
+
+int vtg_set_config(struct device *dev, const struct drm_display_mode *mode);
+int vtg_register_client(struct device *dev, struct notifier_block *nb);
+int vtg_unregister_client(struct device *dev, struct notifier_block *nb);
+
+#endif
drivers/gpu/drm/sti/sti_vtg_utils.c new file +11 -0
new file mode 100644
index 0000000..06bb4b4
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) STMicroelectronics SA 2013
+ * Author: Benjamin Gaignard <[email protected]> for STMicroelectronics.
+ * License terms:  GNU General Public License (GPL), version 2
+ */
+
+#include <linux/platform_device.h>
+
+#include "sti_vtg_utils.h"
+#include "sti_vtg.h"
+

drivers/gpu/drm/sti/sti_vtg_utils.c line 21

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtg_utils.c new file +10 -0
+struct device *vtg_main;
+struct device *vtg_aux;
+
+int sti_vtg_setconfig(int main_aux, const struct drm_display_mode *mode)
+{
+	if (main_aux == VTG_MAIN && vtg_main)
+		return vtg_set_config(vtg_main, mode);
+
+	if (main_aux == VTG_AUX && vtg_aux)
+		return vtg_set_config(vtg_aux, mode);

Any reason for the 'setconfig' and 'set_config' inconsistency?

drivers/gpu/drm/sti/sti_vtg_utils.c line 22

Quoted 1 line
drivers/gpu/drm/sti/sti_vtg_utils.c new file +1 -0
+	return 1;

Use proper return values.

drivers/gpu/drm/sti/sti_vtg_utils.c line 23

Quoted 1 line
drivers/gpu/drm/sti/sti_vtg_utils.c new file +1 -0
+}

Do these need to be in a seperate file? Still looks VTG related?

Quoted 27 lines
drivers/gpu/drm/sti/sti_vtg_utils.c new file +27 -0
+int sti_vtg_register_client(int main_aux, struct notifier_block *nb)
+{
+	if (main_aux == VTG_MAIN && vtg_main)
+		return vtg_register_client(vtg_main, nb);
+
+	if (main_aux == VTG_AUX && vtg_aux)
+		return vtg_register_client(vtg_aux, nb);
+
+	return 1;
+}
+
+int sti_vtg_unregister_client(int main_aux, struct notifier_block *nb)
+{
+	if (main_aux == VTG_MAIN && vtg_main)
+		return vtg_unregister_client(vtg_main, nb);
+
+	if (main_aux == VTG_AUX && vtg_aux)
+		return vtg_unregister_client(vtg_aux, nb);
+
+	return 1;
+}
+
+/*
+ *       Active        Front        Sync       Back          Active
+ *       Region        Porch                  Porch          Region
+ * <---------------><-------->0<---------><--------><----------------->
+ *

drivers/gpu/drm/sti/sti_vtg_utils.c line 62

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtg_utils.c new file +10 -0
+ *   ///////////////|                               |  ///////////////|
+ *  /////////////// |                               | /////////////// |
+ * ///////////////  |.........            ..........|///////////////  |
+ *                            0___________      x/ymin           x/ymax
+ *
+ * <--[hv]display-->                                 <--[hv]display-->
+ * <--[hv]sync_start--------->                       <--[hv]sync_start-
+ * <--[hv]sync_end----------------------->           <--[hv]sync_end---
+ * <--[hv]total------------------------------------> <--[hv]total------
+ */

I'm not sure if I'm any more enlightened by this?

drivers/gpu/drm/sti/sti_vtg_utils.c line 61

Quoted 1 line
drivers/gpu/drm/sti/sti_vtg_utils.c new file +1 -0
+/*

/**

Quoted 70 lines
drivers/gpu/drm/sti/sti_vtg_utils.c new file +35 -0
+ * sti_vtg_get_line_number
+ *
+ * @mode: display mode to be used
+ * @y:    line
+ *
+ * Return the line number according to the display mode taking
+ * into account the Sync and Back Porch information.
+ * Video frame line numbers start at 1, y starts at 0.
+ * In interlaced modes the start line is the field line number of the odd
+ * field, but y is still defined as a progressive frame.
+ */
+u32 sti_vtg_get_line_number(struct drm_display_mode mode, int y)
+{
+	int start_line = mode.vtotal - mode.vsync_start + 1;
+
+	if (mode.flags & DRM_MODE_FLAG_INTERLACE)
+		start_line *= 2;
+
+	return start_line + y;
+}
+
+/*
+ * sti_vtg_get_pixel_number
+ *
+ * @mode: display mode to be used
+ * @x:    row
+ *
+ * Return the pixel number according to the display mode taking
+ * into account the Sync and Back Porch information.
+ * Pixels are counted from 0.
+ */
+u32 sti_vtg_get_pixel_number(struct drm_display_mode mode, int x)
+{
+	return mode.htotal - mode.hsync_start + x;
+}
drivers/gpu/drm/sti/sti_vtg_utils.h new file +29 -0
new file mode 100644
index 0000000..fea2852
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) STMicroelectronics SA 2013
+ * Authors: Benjamin Gaignard <[email protected]>
+ *          Fabien Dessenne <[email protected]>
+ *          for STMicroelectronics.
+ * License terms:  GNU General Public License (GPL), version 2
+ */
+
+#ifndef _STI_VTG_UTILS_H_
+#define _STI_VTG_UTILS_H_
+
+#include <drm/drmP.h>
+
+#define WAIT_NEXT_VSYNC_MS      50 /*ms*/
+
+#define VTG_MAIN                0
+#define VTG_AUX                 1
+
+#define VTG_TOP_FIELD_EVENT     1
+#define VTG_BOTTOM_FIELD_EVENT  2
+
+int sti_vtg_setconfig(int main_aux, const struct drm_display_mode *mode);
+int sti_vtg_register_client(int main_aux, struct notifier_block *nb);
+int sti_vtg_unregister_client(int main_aux, struct notifier_block *nb);
+
+u32 sti_vtg_get_line_number(struct drm_display_mode mode, int y);
+u32 sti_vtg_get_pixel_number(struct drm_display_mode mode, int x);
+
+#endif
Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#4 lore raw

PATCH v3 2/16 drm: sti: add VTAC drivers

In reply to Benjamin Gaignard

Video Trafic Advance Communication Rx and Tx drivers are designed for inter-die communication.

Both Tx and Rx must share the same configuration to communicate that is why vtac_mode[] is shared in sti_vtac_utils.h.

---
 drivers/gpu/drm/sti/Kconfig          |   6 ++
 drivers/gpu/drm/sti/Makefile         |   1 +
 drivers/gpu/drm/sti/sti_vtac_rx.c    | 169 ++++++++++++++++++++++++++++++++
 drivers/gpu/drm/sti/sti_vtac_tx.c    | 182 +++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/sti/sti_vtac_utils.h |  52 ++++++++++
 5 files changed, 410 insertions(+)
 create mode 100644 drivers/gpu/drm/sti/sti_vtac_rx.c
 create mode 100644 drivers/gpu/drm/sti/sti_vtac_tx.c
 create mode 100644 drivers/gpu/drm/sti/sti_vtac_utils.h
drivers/gpu/drm/sti/Kconfig +6 -0
index 3fff278..87e6128 100644
@@ -4,6 +4,12 @@ config DRM_STI
 	help
 	  Choose this option to enable DRM on STM stiH41x chipset
 
+config VTAC_STI
+	bool "Video Trafic Advance Communication Rx and Tx for STMicroelectronics SoC stiH41x Series"
+	depends on DRM_STI
+	help
+	  Choose this option to enable VTAC on STM stiH41x chipset
+
 config VTG_STI
 	bool "Video Timing Generator for STMicroelectronics SoC stiH41x Series"
 	depends on DRM_STI
drivers/gpu/drm/sti/Makefile +1 -0
index 33216e1..79fdcb6 100644
@@ -1,3 +1,4 @@
 ccflags-y := -Iinclude/drm
 
+obj-$(CONFIG_VTAC_STI) += sti_vtac_tx.o sti_vtac_rx.o
 obj-$(CONFIG_VTG_STI) += sti_vtg.o sti_vtg_utils.o
drivers/gpu/drm/sti/sti_vtac_rx.c new file +169 -0

169 lines not on this page · raw message

drivers/gpu/drm/sti/sti_vtac_tx.c new file +182 -0

182 lines not on this page · raw message

drivers/gpu/drm/sti/sti_vtac_utils.h new file +52 -0

52 lines not on this page · raw message

Signature · 1 line
1.9.1
#5 lore raw

Re: [PATCH v3 02/16] drm: sti: add VTAC drivers

First off: a lot of the general style comments from my review of patch 01/16 also apply here.

Quoted 1 line · Benjamin Gaignard

Video Trafic Advance Communication Rx and Tx drivers are designed

s/Trafic/Traffic/?

Quoted 1 line
drivers/gpu/drm/sti/Kconfig +0 -0

[...]

drivers/gpu/drm/sti/Kconfig config DRM_STI · line 8

Quoted 6 lines
drivers/gpu/drm/sti/Kconfig +2 -0
@@ -4,6 +4,12 @@ config DRM_STI
 	help
 	  Choose this option to enable DRM on STM stiH41x chipset
 
+config VTAC_STI
+	bool "Video Trafic Advance Communication Rx and Tx for STMicroelectronics SoC stiH41x Series"

Here too.

drivers/gpu/drm/sti/Kconfig config DRM_STI · line 11

Quoted 3 lines
drivers/gpu/drm/sti/Kconfig +3 -0
+	depends on DRM_STI
+	help
+	  Choose this option to enable VTAC on STM stiH41x chipset

I wonder how useful it is to make all of these user-selectable (or even Kconfig symbols to begin with). It seems like VTG and VTAC (and the same is likely true for other subdrivers) are essential to make this driver do anything useful, so in my opinion these should all be built unconditionally.

Quoted 1 line
drivers/gpu/drm/sti/sti_vtac_rx.c +0 -0

[...]

drivers/gpu/drm/sti/sti_vtac_rx.c line 2

Quoted 3 lines
drivers/gpu/drm/sti/sti_vtac_rx.c +2 -0
@@ -0,0 +1,169 @@
+/*
+ * Copyright (C) STMicroelectronics SA 2013

Nit: this probably needs an update to include 2014.

drivers/gpu/drm/sti/sti_vtac_rx.c line 11

Quoted 6 lines
drivers/gpu/drm/sti/sti_vtac_rx.c +6 -0
+#include <linux/clk.h>
+#include <linux/component.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>

Should be sorted alphabetically.

Quoted 5 lines
drivers/gpu/drm/sti/sti_vtac_rx.c +5 -0
+#include <drm/drmP.h>
+
+#include "sti_vtac_utils.h"
+
+#define VTAC_RX_CONFIG		0x00

drivers/gpu/drm/sti/sti_vtac_rx.c line 27

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtac_rx.c +10 -0
+#define VTAC_RX_FIFO_CONFIG	0x04
+
+#define VTAC_SW_RST_AUTOC	0x02
+#define VTAC_FIFO_CONFIG_VAL	0x04
+
+/*
+ * VTAC RX structure
+ *
+ * @dev: pointer to device structure
+ * @regs: ioremapped regsiters

s/regsiters/registers/

drivers/gpu/drm/sti/sti_vtac_rx.c line 30

Quoted 3 lines
drivers/gpu/drm/sti/sti_vtac_rx.c +3 -0
+ * @clk: clock
+ * @type: main or aux device
+ */

Also it's typically not necessary to document these driver-internal data structures. The meaning of the fields is usually obvious. Also these aren't usually exported to any documentation (because driver-internal) and hence kernel-doc isn't such a good fit.

Quoted 5 lines
drivers/gpu/drm/sti/sti_vtac_rx.c +5 -0
+struct sti_vtac_rx {
+	struct device *dev;
+	void __iomem *regs;
+	struct clk *clk;
+	int type;

drivers/gpu/drm/sti/sti_vtac_rx.c line 45

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtac_rx.c +10 -0
+};
+
+static void sti_vtac_rx_reg_dump(struct sti_vtac_rx *vtac_rx)
+{
+	dev_dbg(vtac_rx->dev, "vtac_rx->regs %p\n", vtac_rx->regs);
+	dev_dbg(vtac_rx->dev, "VTAC_RX_CONFIG 0x%x\n",
+		readl(vtac_rx->regs + VTAC_RX_CONFIG));
+	dev_dbg(vtac_rx->dev, "VTAC_RX_FIFO_CONFIG 0x%x\n",
+		readl(vtac_rx->regs + VTAC_RX_FIFO_CONFIG));
+}

Similar as in the previous patch, this would be desirable to have in debugfs.

drivers/gpu/drm/sti/sti_vtac_rx.c line 50

Quoted 4 lines
drivers/gpu/drm/sti/sti_vtac_rx.c +4 -0
+static void sti_vtac_rx_set_config(struct sti_vtac_rx *vtac_rx)
+{
+	int i;
+	u32 rx_config = EVEN_PARITY | ODD_PARITY | SW_RST_AUTOC | ENABLE;

For readability I think it would make sense to move this closer to where the register is written.

drivers/gpu/drm/sti/sti_vtac_rx.c line 57

Quoted 7 lines
drivers/gpu/drm/sti/sti_vtac_rx.c +7 -0
+
+	/* Enable VTAC clock */
+	if (clk_prepare_enable(vtac_rx->clk))
+		DRM_ERROR("Failed to prepare/enable vtac_rx clock.\n");
+
+	for (i = 0; i < ARRAY_SIZE(vtac_modes); i++) {
+		if (vtac_modes[i].type == vtac_rx->type) {

Rather than try to lookup the mode by type in a global table, could you not simply pass in the specific mode that should be configured as a parameter. That way you can probably leave out the type field from the sti_vtac_rx structure and use this in a similar way than what I suggested from the

Quoted 36 lines
drivers/gpu/drm/sti/sti_vtac_rx.c +36 -0
+			writel(VTAC_FIFO_CONFIG_VAL,
+			       vtac_rx->regs + VTAC_RX_FIFO_CONFIG);
+			rx_config |= vtac_modes[i].vid_in_width << 4;
+			rx_config |= vtac_modes[i].phyts_width << 16;
+			rx_config |= vtac_modes[i].phyts_per_pixel << 23;
+			rx_config |= VTAC_SW_RST_AUTOC;
+			writel(rx_config, vtac_rx->regs + VTAC_RX_CONFIG);
+		}
+	}
+}
+
+static int vtac_rx_bind(struct device *dev, struct device *master, void *data)
+{
+	return 0;
+}
+
+static void vtac_rx_unbind(struct device *dev, struct device *master,
+	void *data)
+{
+	/* do nothing */
+}
+
+static const struct component_ops vtac_rx_ops = {
+	.bind	= vtac_rx_bind,
+	.unbind	= vtac_rx_unbind,
+};
+
+static int sti_vtac_rx_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct device_node *np = dev->of_node;
+	struct sti_vtac_rx *vtac_rx;
+	struct resource *res;
+
+	DRM_INFO("%s\n", __func__);
+

drivers/gpu/drm/sti/sti_vtac_rx.c line 103

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtac_rx.c +10 -0
+	vtac_rx = devm_kzalloc(dev, sizeof(*vtac_rx), GFP_KERNEL);
+	if (!vtac_rx) {
+		DRM_ERROR("Failed to allocate VTAC RX context\n");
+		return -ENOMEM;
+	}
+	vtac_rx->dev = dev;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		DRM_ERROR("Invalid resource\n");

No need for this. devm_ioremap_resource() already checks for that and outputs an error message.

drivers/gpu/drm/sti/sti_vtac_rx.c line 113

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtac_rx.c +10 -0
+		return -ENOMEM;
+	}
+	vtac_rx->regs = devm_ioremap_resource(dev, res);
+	if (IS_ERR(vtac_rx->regs))
+		return PTR_ERR(vtac_rx->regs);
+
+	vtac_rx->type = VTAC_MAIN;
+	if (np)
+		if (of_property_read_bool(np, "vtac-rx-aux"))
+			vtac_rx->type = VTAC_AUX;

What exactly is the difference between auxiliary and main here? It seems like the only reason why you separate things here is because you use different names for the clocks and devices.

drivers/gpu/drm/sti/sti_vtac_rx.c line 127

Quoted 13 lines
drivers/gpu/drm/sti/sti_vtac_rx.c +13 -0
+	if (vtac_rx->type == VTAC_MAIN) {
+		vtac_rx->clk = devm_clk_get(dev, "vtac_main_phy");
+		if (IS_ERR(vtac_rx->clk)) {
+			DRM_ERROR("Cannot get vtac_main_phy clock\n");
+			return PTR_ERR(vtac_rx->clk);
+		}
+	} else {
+		vtac_rx->clk = devm_clk_get(dev, "vtac_aux_phy");
+		if (IS_ERR(vtac_rx->clk)) {
+			DRM_ERROR("Cannot get vtac_aux_phy clock\n");
+			return PTR_ERR(vtac_rx->clk);
+		}
+	}

There should be no need to make the consumer name of the clock different for main or auxiliary types. From the above it seems like the clock is used to drive a PHY, in which case something like "phy" would be good enough. That way you don't have to conditionalize.

Quoted 7 lines
drivers/gpu/drm/sti/sti_vtac_rx.c +7 -0
+	sti_vtac_rx_set_config(vtac_rx);
+	sti_vtac_rx_reg_dump(vtac_rx);
+
+	platform_set_drvdata(pdev, vtac_rx);
+	DRM_INFO("%s VTAC RX %s\n", __func__,
+		 vtac_rx->type == VTAC_MAIN ? "main" : "aux");
+

drivers/gpu/drm/sti/sti_vtac_rx.c line 145

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtac_rx.c +10 -0
+	return component_add(&pdev->dev, &vtac_rx_ops);
+}
+
+static int sti_vtac_rx_remove(struct platform_device *pdev)
+{
+	component_del(&pdev->dev, &vtac_rx_ops);
+	return 0;
+}
+
+static struct of_device_id vtac_rx_match_types[] = {

Should be static const.

drivers/gpu/drm/sti/sti_vtac_rx.c line 150

Quoted 5 lines
drivers/gpu/drm/sti/sti_vtac_rx.c +5 -0
+	{
+	 .compatible = "st,stih416-vtac-rx",
+	 }, {
+	     /* end node */
+	     }

Funky indentation.

drivers/gpu/drm/sti/sti_vtac_rx.c line 153

Quoted 3 lines
drivers/gpu/drm/sti/sti_vtac_rx.c +3 -0
+};
+
+MODULE_DEVICE_TABLE(of, vtac_rx_match_types);

I think it's more common to not have a blank line between the }; and the MODULE_DEVICE_TABLE. I missed that for 01/12.

drivers/gpu/drm/sti/sti_vtac_rx.c line 165

Quoted 12 lines
drivers/gpu/drm/sti/sti_vtac_rx.c +12 -0
+
+struct platform_driver sti_vtac_rx_driver = {
+	.driver = {
+		   .name = "sti-vtac-rx",
+		   .owner = THIS_MODULE,
+		   .of_match_table = vtac_rx_match_types,
+		   },
+	.probe = sti_vtac_rx_probe,
+	.remove = sti_vtac_rx_remove,
+};
+
+module_platform_driver(sti_vtac_rx_driver);

Same here, and that also applies to 01/12.

drivers/gpu/drm/sti/sti_vtac_rx.c line 169

Quoted 4 lines
drivers/gpu/drm/sti/sti_vtac_rx.c +4 -0
+
+MODULE_AUTHOR("Benjamin Gaignard <[email protected]>");
+MODULE_DESCRIPTION("STMicroelectronics SoC VTAC_RX driver");
+MODULE_LICENSE("GPL");

This doesn't match the license in the file header. This is also wrong in patch 01/12.

Quoted 33 lines
drivers/gpu/drm/sti/sti_vtac_tx.c new file +27 -0
new file mode 100644
index 0000000..3c0a152
@@ -0,0 +1,182 @@
+/*
+ * Copyright (C) STMicroelectronics SA 2013
+ * Author: Benjamin Gaignard <[email protected]> for STMicroelectronics.
+ * License terms:  GNU General Public License (GPL), version 2
+ */
+#include <linux/clk.h>
+#include <linux/component.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <drm/drmP.h>
+
+#include "sti_vtac_utils.h"
+
+#define VTAC_TX_CONFIG		0x00
+
+#define VTAC_SW_RST_AUTOC	0x02
+
+#define VTAC_TX_PHY_ENABLE_CLK_PHY	(0x01 << 0)
+#define VTAC_TX_PHY_PROG_N3		(0x04 << 7)
+#define VTAC_TX_PHY_ENABLE_CLK_DLL	(0x01 << 1)
+#define VTAC_TX_PHY_RST_N_DLL_SWITCH	(0x01 << 4)
+#define VTAC_TX_PHY_PLL_NOT_OSC_MODE	(0x01 << 3)
+
+/*
+ * VTAC TX structure

drivers/gpu/drm/sti/sti_vtac_tx.c line 37

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtac_tx.c new file +10 -0
+ *
+ * @dev: pointer to device structure
+ * @regs: ioremapped regsiters
+ * @clk: clock
+ * @type: main or aux device
+ */
+struct sti_vtac_tx {
+	struct device *dev;
+	void __iomem *tx_regs;
+	void __iomem *phy_regs;

If these are separate register regions, perhaps the PHY part should be exposed using the generic PHY framework (see Documentation/phy.txt).

drivers/gpu/drm/sti/sti_vtac_tx.c line 46

Quoted 5 lines
drivers/gpu/drm/sti/sti_vtac_tx.c new file +5 -0
+static void sti_vtac_tx_set_config(struct sti_vtac_tx *vtac_tx)
+{
+	int i;
+	u32 phy_config;
+	u32 tx_config = EVEN_PARITY | ODD_PARITY | SW_RST_AUTOC | ENABLE;

Both of these are awfully long names. Perhaps you can use a single variable called value here.

drivers/gpu/drm/sti/sti_vtac_tx.c line 50

Quoted 4 lines
drivers/gpu/drm/sti/sti_vtac_tx.c new file +4 -0
+
+	/* Enable VTAC clock */
+	if (clk_prepare_enable(vtac_tx->clk))
+		DRM_ERROR("Failed to prepare/enable vtac_tx clock.\n");

This would typically be a fatal error, wouldn't it? So this should return (and probably return the error code as well).

Quoted 8 lines
drivers/gpu/drm/sti/sti_vtac_tx.c new file +8 -0
+
+	/* Configure vtac phy */
+	phy_config = 0x00000000;
+	writel(phy_config, vtac_tx->phy_regs + 0x828);	/* SYS_CFG8522 */
+	phy_config = VTAC_TX_PHY_ENABLE_CLK_PHY;
+	writel(phy_config, vtac_tx->phy_regs + 0x824);	/* SYS_CFG8521 */
+	phy_config = readl(vtac_tx->phy_regs + 0x824);
+	phy_config |= VTAC_TX_PHY_PROG_N3;

drivers/gpu/drm/sti/sti_vtac_tx.c line 68

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtac_tx.c new file +10 -0
+	writel(phy_config, vtac_tx->phy_regs + 0x824);	/* SYS_CFG8521 */
+	phy_config = readl(vtac_tx->phy_regs + 0x824);
+	phy_config |= VTAC_TX_PHY_ENABLE_CLK_DLL;
+	writel(phy_config, vtac_tx->phy_regs + 0x824);	/* SYS_CFG8521 */
+	phy_config = readl(vtac_tx->phy_regs + 0x824);
+	phy_config |= VTAC_TX_PHY_RST_N_DLL_SWITCH;
+	writel(phy_config, vtac_tx->phy_regs + 0x824);	/* SYS_CFG8521 */
+	phy_config = readl(vtac_tx->phy_regs + 0x824);
+	phy_config |= VTAC_TX_PHY_PLL_NOT_OSC_MODE;
+	writel(phy_config, vtac_tx->phy_regs + 0x824);	/* SYS_CFG8521 */

Can we have a symbolic name for registers 0x824 and 0x828 here, please?

drivers/gpu/drm/sti/sti_vtac_tx.c line 76

Quoted 8 lines
drivers/gpu/drm/sti/sti_vtac_tx.c new file +8 -0
+
+	/* Configure vtac tx */
+	for (i = 0; i < ARRAY_SIZE(vtac_modes); i++) {
+		if (vtac_modes[i].type == vtac_tx->type) {
+			tx_config |= vtac_modes[i].vid_in_width << 4;
+			tx_config |= vtac_modes[i].phyts_width << 16;
+			tx_config |= vtac_modes[i].phyts_per_pixel << 23;
+			tx_config |= VTAC_SW_RST_AUTOC;

You already set SW_RST_AUTOC in tx_config and it seems to be the same value as VTAC_SW_RST_AUTOC. Also please provide only one name for a given field, either VTAC_SW_RST_AUTOC *or* SW_RST_AUTOC, not both.

drivers/gpu/drm/sti/sti_vtac_tx.c line 77

Quoted 1 line
drivers/gpu/drm/sti/sti_vtac_tx.c new file +1 -0
+			writel(tx_config, vtac_tx->tx_regs + VTAC_TX_CONFIG);

Similarly to VTAC Rx I'd set the variable right before writing it to the register here to make it immediately obvious what value gets written.

Also this is the exact same programming sequence as for VTAC Rx, and the config register seems to be at the same offset as well, so I'm wondering if perhaps Rx and Tx VTACs are actually the same hardware. If so you can probably get away with deduplicating both drivers and parameterizing. If you move out the PHY register programming into a PHY driver, then most of that work is already done.

Quoted 24 lines
drivers/gpu/drm/sti/sti_vtac_tx.c new file +24 -0
+static int sti_vtac_tx_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct device_node *np = dev->of_node;
+	struct sti_vtac_tx *vtac_tx;
+	struct resource *res;
+
+	DRM_INFO("%s\n", __func__);
+
+	vtac_tx = devm_kzalloc(dev, sizeof(*vtac_tx), GFP_KERNEL);
+	if (!vtac_tx) {
+		DRM_ERROR("Failed to allocate VTAC TX context\n");
+		return -ENOMEM;
+	}
+	vtac_tx->dev = dev;
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "vtac-tx");
+	if (!res) {
+		DRM_ERROR("Invalid resource 'vtac-tx'\n");
+		return -ENOMEM;
+	}
+	vtac_tx->tx_regs = devm_ioremap_resource(dev, res);
+	if (IS_ERR(vtac_tx->tx_regs))
+		return PTR_ERR(vtac_tx->tx_regs);

drivers/gpu/drm/sti/sti_vtac_tx.c line 131

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtac_tx.c new file +10 -0
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "vtac-phy");
+	if (!res) {
+		DRM_ERROR("Invalid resource 'vtac-phy'\n");
+		return -ENOMEM;
+	}
+	vtac_tx->phy_regs = devm_ioremap_nocache(dev, res->start,
+						 resource_size(res));
+	if (IS_ERR(vtac_tx->phy_regs))
+		return PTR_ERR(vtac_tx->phy_regs);

Why is this not using devm_ioremap_resource() like the tx_regs resource? Also if you move this to a separate PHY driver your resource management becomes a whole lot simpler (no need to worry about the tx_ or phy_ prefixes, ...).

drivers/gpu/drm/sti/sti_vtac_tx.c line 159

Quoted 1 line
drivers/gpu/drm/sti/sti_vtac_tx.c new file +1 -0
+static struct of_device_id vtac_tx_match_types[] = {

vtac_tx_of_match? Or if you can unify both drivers: vtac_of_match. If some parameterization is required to make Tx and Rx work in one driver you could add different compatible strings here for each. More likely though I think that information could be derived from context.

drivers/gpu/drm/sti/sti_vtac_tx.c line 165

Quoted 6 lines
drivers/gpu/drm/sti/sti_vtac_tx.c new file +6 -0
+	{
+	 .compatible = "st,stih416-vtac-tx",
+	 }, {
+	     /* end node */
+	     }
+};

Strange indentation here.

drivers/gpu/drm/sti/sti_vtac_tx.c line 173

Quoted 8 lines
drivers/gpu/drm/sti/sti_vtac_tx.c new file +8 -0
+MODULE_DEVICE_TABLE(of, vtac_tx_match_types);
+
+struct platform_driver sti_vtac_tx_driver = {
+	.driver = {
+		   .name = "sti-vtac-tx",
+		   .owner = THIS_MODULE,
+		   .of_match_table = vtac_tx_match_types,
+		   },

And here.

Quoted 1 line
drivers/gpu/drm/sti/sti_vtac_utils.h +0 -0

[...]

Quoted 1 line

+/* Number of phyts per pixel */

What's a "phyt"?

Quoted 7 lines
drivers/gpu/drm/sti/sti_vtac_utils.h +7 -0
+#define VTAC_2_5_PPP	0x0005
+#define VTAC_3_PPP	0x0006
+#define VTAC_4_PPP	0x0008
+#define VTAC_5_PPP	0x000A
+#define VTAC_6_PPP	0x000C
+#define VTAC_13_PPP	0x001A
+#define VTAC_14_PPP	0x001C

drivers/gpu/drm/sti/sti_vtac_utils.h line 30

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtac_utils.h +10 -0
+#define VTAC_15_PPP	0x001E
+#define VTAC_16_PPP	0x0020
+#define VTAC_17_PPP	0x0022
+#define VTAC_18_PPP	0x0024
+
+/* enable bits */
+#define EVEN_PARITY	(1 << 13)
+#define ODD_PARITY	(1 << 12)
+#define SW_RST_AUTOC	(1 << 1)
+#define ENABLE		(1 << 0)

These could probably use a VTAC_ prefix for consistency.

drivers/gpu/drm/sti/sti_vtac_utils.h line 36

Quoted 6 lines
drivers/gpu/drm/sti/sti_vtac_utils.h +6 -0
+
+/*
+ * VTAC mode structure
+ *
+ * @type: main, aux or dvo device
+ * @vid_in_width: Video Data Resolution

These are probably obvious if you know the hardware or can look at the datasheet, but I have no idea what this field for example means. I had initially thought that it would contain some number of pixels, but the table of modes below taught me better. Having some explanation of the fields in this structure could be useful.

Quoted 4 lines

+ * @phyts_width: Width of phyt buses(phyt low and phyt high).
+ * @phyts_per_pixel: Number of phyts sent per pixel
+ */

drivers/gpu/drm/sti/sti_vtac_utils.h +1 -0
+struct sti_vtac_mode {

drivers/gpu/drm/sti/sti_vtac_utils.h line 50

Quoted 10 lines
drivers/gpu/drm/sti/sti_vtac_utils.h +10 -0
+	int type;
+	int vid_in_width;
+	int phyts_width;
+	int phyts_per_pixel;
+};
+
+static struct sti_vtac_mode vtac_modes[] = {
+	{VTAC_MAIN, 0x2, 0x2, VTAC_5_PPP}, /* Main RGB 12 */
+	{VTAC_AUX, 0x1, 0x0, VTAC_17_PPP}, /* Aux 10 */
+};

This doesn't really belong in a header. If you manage to unify both VTAC Tx and Rx you can simply move this into the VTAC driver source file and not expose it beyond that at all.

Thierry

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

#6 lore raw

PATCH v3 3/16 drm: sti: add HDMI driver

In reply to Benjamin Gaignard

Add driver for HDMI ouput

---
 drivers/gpu/drm/sti/Makefile               |   5 +
 drivers/gpu/drm/sti/sti_hdmi.c             | 529 +++++++++++++++++++++++++++++
 drivers/gpu/drm/sti/sti_hdmi.h             | 195 +++++++++++
 drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c | 398 ++++++++++++++++++++++
 drivers/gpu/drm/sti/sti_hdmi_tx3g4c28phy.c | 224 ++++++++++++
 5 files changed, 1351 insertions(+)
 create mode 100644 drivers/gpu/drm/sti/sti_hdmi.c
 create mode 100644 drivers/gpu/drm/sti/sti_hdmi.h
 create mode 100644 drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c
 create mode 100644 drivers/gpu/drm/sti/sti_hdmi_tx3g4c28phy.c
drivers/gpu/drm/sti/Makefile +5 -0
index 79fdcb6..5295fc7 100644
@@ -1,4 +1,9 @@
 ccflags-y := -Iinclude/drm
 
+stidrm-y := sti_hdmi.o \
+			sti_hdmi_tx3g0c55phy.o \
+			sti_hdmi_tx3g4c28phy.o
+
 obj-$(CONFIG_VTAC_STI) += sti_vtac_tx.o sti_vtac_rx.o
 obj-$(CONFIG_VTG_STI) += sti_vtg.o sti_vtg_utils.o
+obj-$(CONFIG_DRM_STI) += stidrm.o
\ No newline at end of file
drivers/gpu/drm/sti/sti_hdmi.c new file +529 -0

529 lines not on this page · raw message

drivers/gpu/drm/sti/sti_hdmi.h new file +195 -0

195 lines not on this page · raw message

drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c new file +398 -0

398 lines not on this page · raw message

drivers/gpu/drm/sti/sti_hdmi_tx3g4c28phy.c new file +224 -0

224 lines not on this page · raw message

Signature · 1 line
1.9.1
#7 lore raw

Re: [PATCH v3 03/16] drm: sti: add HDMI driver

On Tue, May 20, 2014 at 03:56:13PM +0200, Benjamin Gaignard wrote:
[...]

Quoted 1 line
drivers/gpu/drm/sti/sti_hdmi.c +0 -0

[...]

drivers/gpu/drm/sti/sti_hdmi.c line 23

Quoted 2 lines
drivers/gpu/drm/sti/sti_hdmi.c +2 -0
+/* Reference to the hdmi device */
+struct device *hdmi_dev;

No globals please.

drivers/gpu/drm/sti/sti_hdmi.c line 32

Quoted 8 lines
drivers/gpu/drm/sti/sti_hdmi.c +8 -0
+/*
+ * Helper to write bit field
+ *
+ * @addr: register to update
+ * @val: value to write
+ * @mask: bit field mask to use
+ */
+static inline void hdmi_reg_writemask(void __iomem *addr, u32 val, u32 mask)

Given the hdmi_ prefix I'd expect this to take a struct sti_hdmi * as first argument. Maybe you can also leave out the _reg in there since it should be pretty obvious what this writes.

Quoted 9 lines
drivers/gpu/drm/sti/sti_hdmi.c +9 -0
+/*
+ * HDMI interrupt handler
+ *
+ * @irq: irq number
+ * @arg: connector structure
+ */
+static irqreturn_t hdmi_irq_thread(int irq, void *arg)
+{
+	struct sti_hdmi *hdmi = arg;

drivers/gpu/drm/sti/sti_hdmi.c line 58

Quoted 10 lines
drivers/gpu/drm/sti/sti_hdmi.c +10 -0
+	u32 status;
+
+	/* read interrupt status */
+	status = readl(hdmi->regs + HDMI_INT_STA);
+
+	/* PLL lock interrupt */
+	if (status & HDMI_INT_DLL_LCK) {
+		hdmi->event_received = true;
+		wake_up_interruptible(&hdmi->wait_event);
+	}

I think a more common way to do this is using a struct completion.

drivers/gpu/drm/sti/sti_hdmi.c line 62

Quoted 3 lines
drivers/gpu/drm/sti/sti_hdmi.c +3 -0
+	/* Hot plug detection */
+	if (status & HDMI_INT_HOT_PLUG) {
+		hdmi->hpd = gpio_get_value(hdmi->hpd_gpio);

Hmm... that's odd. You get an interrupt from the HDMI controller but need to read a GPIO to find out what the status is?

drivers/gpu/drm/sti/sti_hdmi.c line 71

Quoted 9 lines
drivers/gpu/drm/sti/sti_hdmi.c +9 -0
+		if (hdmi->drm_dev)
+			drm_helper_hpd_irq_event(hdmi->drm_dev);
+	}
+
+	/* Sw reset completed */
+	if (status & HDMI_INT_SW_RST) {
+		hdmi->event_received = true;
+		wake_up_interruptible(&hdmi->wait_event);
+	}

There's no way to distinguish this from HDMI_INT_DLL_LCK.

drivers/gpu/drm/sti/sti_hdmi.c line 80

Quoted 8 lines
drivers/gpu/drm/sti/sti_hdmi.c +8 -0
+	/* clear interrupt status */
+	writel(status, hdmi->regs + HDMI_INT_CLR);
+
+	/* TODO: check why this sync bus write solves the problem which
+	 * is that without this line, the handler is sometimes called twice
+	 */
+	/* sync bus write */
+	readl(hdmi->regs + HDMI_INT_STA);

This seems to be something that you're systematically doing wrong.

Quoted 6 lines
drivers/gpu/drm/sti/sti_hdmi.c +6 -0
+/*
+ * Start hdmi phy interface
+ *
+ * @hdmi: pointer on the hdmi internal structure
+ *
+ * Return -1 if error occurs

drivers/gpu/drm/sti/sti_hdmi.c line 100

Quoted 10 lines
drivers/gpu/drm/sti/sti_hdmi.c +10 -0
+ */
+static int hdmi_phy_start(struct sti_hdmi *hdmi)
+{
+	DRM_DEBUG_DRIVER("\n");
+
+	if (hdmi->tx3g0c55phy)
+		return sti_hdmi_tx3g0c55phy_start(hdmi);
+
+	return sti_hdmi_tx3g4c28phy_start(hdmi);
+}

This looks like a prime candidate for the generic PHY framework. That will allow you to simply store a struct phy * and use the generic API rather than special case every possible type of PHY.

Quoted 4 lines
drivers/gpu/drm/sti/sti_hdmi.c +4 -0
+/*
+ * Stop hdmi phy interface
+ *
+ * @hdmi: pointer on the hdmi internal structure

drivers/gpu/drm/sti/sti_hdmi.c line 115

Quoted 10 lines
drivers/gpu/drm/sti/sti_hdmi.c +10 -0
+ */
+static void hdmi_phy_stop(struct sti_hdmi *hdmi)
+{
+	DRM_DEBUG_DRIVER("\n");
+
+	if (hdmi->tx3g0c55phy)
+		sti_hdmi_tx3g0c55phy_stop(hdmi);
+	else
+		sti_hdmi_tx3g4c28phy_stop(hdmi);
+}

Same here. The generic PHY equivalents for this would be phy_power_on() and phy_power_off().

Quoted 17 lines
drivers/gpu/drm/sti/sti_hdmi.c +17 -0
+/*
+ * Set hdmi active area depending on the drm display mode selected
+ *
+ * @hdmi: pointer on the hdmi internal structure
+ */
+static void hdmi_active_area(struct sti_hdmi *hdmi)
+{
+	u32 xmin, xmax;
+	u32 ymin, ymax;
+
+	DRM_DEBUG_DRIVER("\n");
+
+	/*
+	 *       Active        Front        Sync       Back          Active
+	 *       Region        Porch                  Porch          Region
+	 * <---------------><-------->0<---------><--------><----------------->
+	 *

drivers/gpu/drm/sti/sti_hdmi.c line 143

Quoted 10 lines
drivers/gpu/drm/sti/sti_hdmi.c +10 -0
+	 *   ///////////////|                               |  ///////////////|
+	 *  /////////////// |                               | /////////////// |
+	 * ///////////////  |.........            ..........|///////////////  |
+	 *                            0___________      x/ymin           x/ymax
+	 *
+	 * <--[hv]display-->                                 <--[hv]display-->
+	 * <--[hv]sync_start--------->                       <--[hv]sync_start-
+	 * <--[hv]sync_end----------------------->           <--[hv]sync_end---
+	 * <--[hv]total------------------------------------> <--[hv]total------
+	 */

There's an instance of this picture somewhere else already, no need to keep a copy in every subdriver. Also this is something that people are supposed to know. Perhaps it should be moved to a central place for reference?

Quoted 4 lines
drivers/gpu/drm/sti/sti_hdmi.c +4 -0
+
+	xmin = sti_vtg_get_pixel_number(hdmi->mode, 0);
+	xmax = sti_vtg_get_pixel_number(hdmi->mode, hdmi->mode.hdisplay - 1);
+	ymin = sti_vtg_get_line_number(hdmi->mode, 0);

drivers/gpu/drm/sti/sti_hdmi.c line 157

Quoted 10 lines
drivers/gpu/drm/sti/sti_hdmi.c +10 -0
+	ymax = sti_vtg_get_line_number(hdmi->mode, hdmi->mode.vdisplay - 1);
+
+	writel(xmin, hdmi->regs + HDMI_ACTIVE_VID_XMIN);
+	writel(xmax, hdmi->regs + HDMI_ACTIVE_VID_XMAX);
+	writel(ymin, hdmi->regs + HDMI_ACTIVE_VID_YMIN);
+	writel(ymax, hdmi->regs + HDMI_ACTIVE_VID_YMAX);
+
+	DRM_DEBUG_DRIVER("xmin=%d xmax=%d ymin=%d ymax=%d\n",
+			 xmin, xmax, ymin, ymax);
+}

I feel a midlayer coming up in subsequent patches. This looks like it should be more tightly coupled to DRM.

Quoted 16 lines
drivers/gpu/drm/sti/sti_hdmi.c +16 -0
+/*
+ * Overall hdmi configuration
+ *
+ * @hdmi: pointer on the hdmi internal structure
+ */
+static void hdmi_config(struct sti_hdmi *hdmi)
+{
+	u32 val;
+	u32 mask;
+
+	DRM_DEBUG_DRIVER("\n");
+
+	/* Clear overrun and underrun fifo */
+	mask = HDMI_CFG_FIFO_OVERRUN_CLR | HDMI_CFG_FIFO_UNDERRUN_CLR;
+	val = HDMI_CFG_FIFO_OVERRUN_CLR | HDMI_CFG_FIFO_UNDERRUN_CLR;
+

drivers/gpu/drm/sti/sti_hdmi.c line 184

Quoted 10 lines
drivers/gpu/drm/sti/sti_hdmi.c +10 -0
+	/* Enable HDMI mode not DVI */
+	mask |= HDMI_CFG_HDMI_NOT_DVI | HDMI_CFG_ESS_NOT_OESS;
+	val |= HDMI_CFG_HDMI_NOT_DVI | HDMI_CFG_ESS_NOT_OESS;
+
+	/* Enable sink term detection */
+	mask |= HDMI_CFG_SINK_TERM_DET_EN;
+	val |= HDMI_CFG_SINK_TERM_DET_EN;
+
+	/* Set Hsync polarity */
+	if ((hdmi->mode.flags && DRM_MODE_FLAG_NHSYNC)

s/&&/&/

Quoted 9 lines
drivers/gpu/drm/sti/sti_hdmi.c +9 -0
+	    == DRM_MODE_FLAG_NHSYNC) {
+		DRM_DEBUG_DRIVER("H Sync Negative\n");
+		mask |= HDMI_CFG_H_SYNC_POL_NEG;
+		val |= HDMI_CFG_H_SYNC_POL_NEG;
+	}
+
+	/* Set Vsync polarity */
+	if ((hdmi->mode.flags && DRM_MODE_FLAG_NVSYNC)
+	    == DRM_MODE_FLAG_NVSYNC) {

drivers/gpu/drm/sti/sti_hdmi.c line 203

Quoted 10 lines
drivers/gpu/drm/sti/sti_hdmi.c +10 -0
+		DRM_DEBUG_DRIVER("V Sync Negative\n");
+		mask |= HDMI_CFG_V_SYNC_POL_NEG;
+		val |= HDMI_CFG_V_SYNC_POL_NEG;
+	}
+
+	/* Enable HDMI */
+	mask |= HDMI_CFG_DEVICE_EN;
+	val |= HDMI_CFG_DEVICE_EN;
+
+	hdmi_reg_writemask(hdmi->regs + HDMI_CFG, val, mask);

Quite frankly I don't see how hdmi_reg_writemask() makes this any more readable. This is equally readable in my opinion:

	value = hdmi_read(hdmi, HDMI_CFG);
	value &= ~HDMI...;
	value |= HDMI...;
	...
	hdmi_write(hdmi, value, HDMI_CFG);

Of course since your mask and value are always the same in the above there's really no use in masking out and ORing back in the value in the first place, so all of these can simply be:

	value = HDMI... | HDMI... | HDMI... | ...;

	if (...)
		value |= HDMI...;

	hdmi_write(hdmi, value, HDMI_CFG);
Quoted 6 lines
drivers/gpu/drm/sti/sti_hdmi.c +6 -0
+/*
+ * Prepare and configure the AVI infoframe
+ *
+ * AVI infoframe are transmitted at least once per two video field and
+ * contains information about HDMI transmission mode such as color space,
+ * colorimetry, ...

drivers/gpu/drm/sti/sti_hdmi.c line 221

Quoted 10 lines
drivers/gpu/drm/sti/sti_hdmi.c +10 -0
+ *
+ * @hdmi: pointer on the hdmi internal structure
+ *
+ * Return negative value if error occurs
+ */
+static int hdmi_avi_infoframe_config(struct sti_hdmi *hdmi)
+{
+	struct drm_display_mode *mode = &hdmi->mode;
+	struct hdmi_avi_infoframe infoframe;
+	u8 buffer[HDMI_INFOFRAME_HEADER_SIZE + HDMI_AVI_INFOFRAME_SIZE];

I think you can use HDMI_INFOFRAME_SIZE(AVI) here.

drivers/gpu/drm/sti/sti_hdmi.c line 222

Quoted 1 line
drivers/gpu/drm/sti/sti_hdmi.c +1 -0
+	u8 *frame = buffer + HDMI_INFOFRAME_HEADER_SIZE - 1;

Why "- 1"? I think this warrants a comment.

Quoted 7 lines
drivers/gpu/drm/sti/sti_hdmi.c +7 -0
+	u32 val;
+	u32 mask;
+	int ret;
+
+	DRM_DEBUG_DRIVER("\n");
+
+	ret = drm_hdmi_avi_infoframe_from_display_mode(&infoframe, mode);

drivers/gpu/drm/sti/sti_hdmi.c line 239

Quoted 10 lines
drivers/gpu/drm/sti/sti_hdmi.c +10 -0
+	if (ret < 0) {
+		DRM_ERROR("failed to setup AVI infoframe: %d\n", ret);
+		return ret;
+	}
+
+	/* TODO: remove static infoframe configuration */
+	infoframe.colorspace = HDMI_COLORSPACE_RGB;
+	infoframe.quantization_range = HDMI_QUANTIZATION_RANGE_DEFAULT;
+	infoframe.colorimetry = HDMI_COLORIMETRY_NONE;
+	infoframe.pixel_repeat = 0;

Why is this even necessary in the first place? If it really is it's likely that the core is just missing something, in which case the drm_hdmi_avi_infoframe_from_display_mode() helper should be fixed.

drivers/gpu/drm/sti/sti_hdmi.c line 249

Quoted 9 lines
drivers/gpu/drm/sti/sti_hdmi.c +9 -0
+	ret = hdmi_avi_infoframe_pack(&infoframe, buffer, sizeof(buffer));
+	if (ret < 0) {
+		DRM_ERROR("failed to pack AVI infoframe: %d\n", ret);
+		return ret;
+	}
+
+	/* Disable transmission slot for AVI infoframe */
+	val = HDMI_IFRAME_DISABLED;
+	mask = HDMI_IFRAME_CFG_DI_N(HDMI_IFRAME_MASK, HDMI_IFRAME_SLOT_AVI);

This is really impossible to parse by a human. I'd rather see this open- coded than obfuscated by some magic macro.

drivers/gpu/drm/sti/sti_hdmi.c line 256

Quoted 7 lines
drivers/gpu/drm/sti/sti_hdmi.c +7 -0
+	hdmi_reg_writemask(hdmi->regs + HDMI_SW_DI_CFG, val, mask);
+
+	/* Infoframe header */
+	val = buffer[0x0];
+	val |= buffer[0x1] << 8;
+	val |= buffer[0x2] << 16;
+	writel(val, hdmi->regs + HDMI_SW_DI_N_HEAD_WORD(HDMI_IFRAME_SLOT_AVI));

I think a hdmi_writel() helper would be useful here. Also the registers below seem to be all successive in memory, so maybe some sort of look would make this easier to read.

Quoted 16 lines
drivers/gpu/drm/sti/sti_hdmi.c +16 -0
+	/* Infoframe packet bytes */
+	val = frame[0x0];
+	val |= frame[0x1] << 8;
+	val |= frame[0x2] << 16;
+	val |= frame[0x3] << 24;
+	writel(val, hdmi->regs + HDMI_SW_DI_N_PKT_WORD0(HDMI_IFRAME_SLOT_AVI));
+	val = frame[0x4];
+	val |= frame[0x5] << 8;
+	val |= frame[0x6] << 16;
+	val |= frame[0x7] << 24;
+	writel(val, hdmi->regs + HDMI_SW_DI_N_PKT_WORD1(HDMI_IFRAME_SLOT_AVI));
+	val = frame[0x8];
+	val |= frame[0x9] << 8;
+	val |= frame[0xA] << 16;
+	val |= frame[0xB] << 24;
+	writel(val, hdmi->regs + HDMI_SW_DI_N_PKT_WORD2(HDMI_IFRAME_SLOT_AVI));

drivers/gpu/drm/sti/sti_hdmi.c line 282

Quoted 10 lines
drivers/gpu/drm/sti/sti_hdmi.c +10 -0
+	val = frame[0xC];
+	val |= frame[0xD] << 8;
+	writel(val, hdmi->regs + HDMI_SW_DI_N_PKT_WORD3(HDMI_IFRAME_SLOT_AVI));
+
+	/* Enable transmission slot for AVI infoframe */
+	/* According to the hdmi specification, AVI infoframe should be
+	 * transmitted at least once per two video fields */
+	val = HDMI_IFRAME_CFG_DI_N(HDMI_IFRAME_FIELD, HDMI_IFRAME_SLOT_AVI);
+	mask = HDMI_IFRAME_CFG_DI_N(HDMI_IFRAME_MASK, HDMI_IFRAME_SLOT_AVI);
+	hdmi_reg_writemask(hdmi->regs + HDMI_SW_DI_CFG, val, mask);

Again, not much gain in the hdmi_reg_writemask() helper here.

Quoted 6 lines

+/*
+ * Software reset of the hdmi subsystem
+ *
+ * @hdmi: pointer on the hdmi internal structure
+ *
+ * Return -1 if error occurs

No, this function never fails and always returns 0. Ideally it would propagate errors from lower layers if they can't be handled here.

drivers/gpu/drm/sti/sti_hdmi.c line 304

Quoted 12 lines

+ */

drivers/gpu/drm/sti/sti_hdmi.c +11 -0
+#define HDMI_TIMEOUT_SWRESET  100	/*milliseconds */
+static int hdmi_swreset(struct sti_hdmi *hdmi)
+{
+	u32 val;
+	u32 mask;
+
+	DRM_DEBUG_DRIVER("\n");
+
+	/* Enable hdmi_audio clock only during hdmi reset */
+	if (clk_prepare_enable(hdmi->clk_audio))
+		DRM_INFO("Failed to prepare/enable hdmi_audio clk\n");

You should propagate this error. If the clock can't be enabled presumably the remainder of this function can't succeed, so there's no point continuing beyond this.

drivers/gpu/drm/sti/sti_hdmi.c line 306

Quoted 1 line
drivers/gpu/drm/sti/sti_hdmi.c +1 -0
+	/* Sw reset */

You should either spell this out ("software") or use all caps for abbreviations ("SW").

drivers/gpu/drm/sti/sti_hdmi.c line 317

Quoted 11 lines
drivers/gpu/drm/sti/sti_hdmi.c +11 -0
+	mask = HDMI_CFG_SW_RST_EN;
+	val = HDMI_CFG_SW_RST_EN;
+
+	hdmi->event_received = false;
+	hdmi_reg_writemask(hdmi->regs + HDMI_CFG, val, mask);
+
+	/* Wait reset completed */
+	wait_event_interruptible_timeout(hdmi->wait_event,
+					 hdmi->event_received == true,
+					 msecs_to_jiffies
+					 (HDMI_TIMEOUT_SWRESET));

I think a completion would be better here. Perhaps even that would be overkill. You could also simply use a loop with a timeout where you check for the reset complete bit to be flagged.

drivers/gpu/drm/sti/sti_hdmi.c line 324

Quoted 6 lines
drivers/gpu/drm/sti/sti_hdmi.c +6 -0
+	/*
+	 * HDMI_STA_SW_RST bit is set to '1' when SW_RST bit in HDMI_CFG is
+	 * set to '1' and clk_audio is running.
+	 */
+	if ((readl(hdmi->regs + HDMI_STA) & HDMI_STA_SW_RST) == 0)
+		DRM_INFO("Warning: HDMI sw reset timeout occurs\n");

If this times out there's something from and you should return an error here so that appropriate action can be taken at higher levels.

drivers/gpu/drm/sti/sti_hdmi.c line 348

Quoted 13 lines
drivers/gpu/drm/sti/sti_hdmi.c +13 -0
+/*
+ * Attach the I2C ddc client to allow hdmi i2c communication
+ *
+ * @ddc: i2c client
+ */
+static struct i2c_client *hdmi_ddc;
+void sti_hdmi_attach_ddc_client(struct i2c_client *ddc)
+{
+	DRM_DEBUG_DRIVER("\n");
+
+	if (ddc)
+		hdmi_ddc = ddc;
+}

This doesn't look right. All other drivers use an i2c_adapter directly, so this should do the same. Since this will be using device tree it can use the same mechanism that every other DT driver uses.

On that note, I haven't seen you post the device tree bindings for this yet. It would be good to get a look at that as well since it may help with understanding how this all fits together. Also it will need to be reviewed as well anyway and depending on the output the drivers may need significant rework.

Quoted 8 lines
drivers/gpu/drm/sti/sti_hdmi.c +8 -0
+/*
+ * Get modes from edid
+ *
+ * @drm_connector: pointer on the drm connector
+ */
+static int sti_hdmi_get_modes(struct drm_connector *drm_connector)
+{
+	struct edid *edid;

drivers/gpu/drm/sti/sti_hdmi.c line 367

Quoted 10 lines
drivers/gpu/drm/sti/sti_hdmi.c +10 -0
+	int count;
+
+	DRM_DEBUG_DRIVER("\n");
+
+	if ((!hdmi_ddc) || (!hdmi_ddc->adapter))
+		goto fail;
+
+	edid = drm_get_edid(drm_connector, hdmi_ddc->adapter);
+	if (!edid)
+		goto fail;

You need to call drm_mode_connector_update_edid_property() even in case of failure here, since otherwise the connector will keep carrying a stale copy of the EDID.

drivers/gpu/drm/sti/sti_hdmi.c line 373

Quoted 6 lines
drivers/gpu/drm/sti/sti_hdmi.c +6 -0
+
+	count = drm_add_edid_modes(drm_connector, edid);
+	if (count)
+		drm_mode_connector_update_edid_property(drm_connector, edid);
+	else
+		DRM_ERROR("Add edid modes failed\n");

s/edid/EDID/ or better yet, just drop this error message.

drivers/gpu/drm/sti/sti_hdmi.c line 380

Quoted 7 lines
drivers/gpu/drm/sti/sti_hdmi.c +7 -0
+
+	kfree(edid);
+	return count;
+
+fail:
+	DRM_ERROR("Can not read HDMI EDID\n");
+	return -1;

This function should return the number of modes probed, so 0 in case of failure.

Quoted 10 lines
drivers/gpu/drm/sti/sti_hdmi.c +10 -0
+static int sti_hdmi_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct sti_hdmi *hdmi;
+	struct device_node *np = dev->of_node;
+	struct resource *res;
+	int ret;
+
+	DRM_INFO("%s\n", __func__);
+

drivers/gpu/drm/sti/sti_hdmi.c line 418

Quoted 10 lines
drivers/gpu/drm/sti/sti_hdmi.c +10 -0
+	hdmi = devm_kzalloc(dev, sizeof(*hdmi), GFP_KERNEL);
+	if (!hdmi) {
+		DRM_ERROR("Failed to allocate memory for hdmi\n");
+		return -ENOMEM;
+	}
+
+	hdmi->dev = pdev->dev;
+
+	/* Get resources */
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "hdmi-reg");

If you move the PHY programming to a different driver then this becomes the only resource and you don't need a name. Regardless, though, I think something like "hdmi" or "regs" would be more appropriate here.

Quoted 12 lines
drivers/gpu/drm/sti/sti_hdmi.c +12 -0
+	if (!res) {
+		DRM_ERROR("Invalid hdmi resource\n");
+		return -ENOMEM;
+	}
+	hdmi->regs = devm_ioremap_nocache(dev, res->start, resource_size(res));
+	if (IS_ERR(hdmi->regs))
+		return PTR_ERR(hdmi->regs);
+
+	if (of_device_is_compatible(np, "st,stih416-hdmi")) {
+		res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
+						   "syscfg");
+		if (!res) {

drivers/gpu/drm/sti/sti_hdmi.c line 440

Quoted 10 lines
drivers/gpu/drm/sti/sti_hdmi.c +10 -0
+			DRM_ERROR("Invalid syscfg resource\n");
+			return -ENOMEM;
+		}
+		hdmi->syscfg = devm_ioremap_nocache(dev, res->start,
+						    resource_size(res));
+		if (IS_ERR(hdmi->syscfg))
+			return PTR_ERR(hdmi->syscfg);
+
+		hdmi->tx3g0c55phy = true;
+	}

Again this seems like it would be better exposed as a generic PHY. That way you can simply request the PHY and use it if present. Perhaps this isn't really a PHY but something else entirely. What is this syscfg register range? Does it belong to some other device? I suspect that since you're not requesting the region this may in fact already be used by some other driver. In that case doing this is unsafe and you should provide a way to call into that other driver from this one to apply the corresponding configuration.

Quoted 3 lines
drivers/gpu/drm/sti/sti_hdmi.c +3 -0
+
+	/* Get clock resources */
+	hdmi->clk_pix = devm_clk_get(dev, "hdmi_pix");

[...]

Quoted 1 line
drivers/gpu/drm/sti/sti_hdmi.c +1 -0
+	hdmi->clk_tmds = devm_clk_get(dev, "hdmi_tmds");

[...]

Quoted 1 line
drivers/gpu/drm/sti/sti_hdmi.c +1 -0
+	hdmi->clk_phy = devm_clk_get(dev, "hdmi_phy");

[...]

drivers/gpu/drm/sti/sti_hdmi.c line 461

Quoted 1 line
drivers/gpu/drm/sti/sti_hdmi.c +1 -0
+	hdmi->clk_audio = devm_clk_get(dev, "hdmi_audio");

You can drop the hdmi_ prefix on all of these clock names since they're relative to the HDMI device anyway.

drivers/gpu/drm/sti/sti_hdmi.c line 467

Quoted 2 lines
drivers/gpu/drm/sti/sti_hdmi.c +2 -0
+
+	hdmi->hpd_gpio = of_get_named_gpio(np, "hdmi,hpd-gpio", 0);

This should use the gpiod API if at all possible.

drivers/gpu/drm/sti/sti_hdmi.c line 473

Quoted 6 lines
drivers/gpu/drm/sti/sti_hdmi.c +6 -0
+	if (hdmi->hpd_gpio < 0) {
+		DRM_ERROR("Failed to get hdmi hpd-gpio\n");
+		return -EIO;
+	}
+
+	hdmi->hpd = gpio_get_value(hdmi->hpd_gpio);

Why do you cache this value here? Can't you simply read it directly when it's needed?

drivers/gpu/drm/sti/sti_hdmi.c line 478

Quoted 4 lines
drivers/gpu/drm/sti/sti_hdmi.c +4 -0
+	init_waitqueue_head(&hdmi->wait_event);
+
+	/* Get irq ressources */
+	hdmi->irq = platform_get_irq_byname(pdev, "hdmi_irq");

Again, no need for the hdmi_ prefix. In this case it would also be an option to just name it "hdmi" if it's the only interrupt that this device can raise.

drivers/gpu/drm/sti/sti_hdmi.c line 482

Quoted 3 lines
drivers/gpu/drm/sti/sti_hdmi.c +3 -0
+	ret = devm_request_threaded_irq(dev, hdmi->irq, NULL,
+					hdmi_irq_thread, IRQF_ONESHOT,
+					"hdmi_irq", hdmi);

Perhaps dev_name(dev) instead of "hdmi_irq". Also perhaps you should provide a hdmi_irq() to implement the hard IRQ handler (reading the interrupt status registers) and if you determine that you need to do something that may sleep (as in case of the hotplug detect) you can return IRQ_WAKE_THREAD to only run the threaded handler if necessary.

drivers/gpu/drm/sti/sti_hdmi.c line 484

Quoted 2 lines
drivers/gpu/drm/sti/sti_hdmi.c +2 -0
+	if (ret) {
+		DRM_ERROR("Failed to register hdmi interrupt\n");

s/hdmi/HDMI/

drivers/gpu/drm/sti/sti_hdmi.c line 488

Quoted 4 lines
drivers/gpu/drm/sti/sti_hdmi.c +4 -0
+		return ret;
+	}
+
+	/* Get reset resources */

This comment is superfluous.

drivers/gpu/drm/sti/sti_hdmi.c line 492

Quoted 4 lines
drivers/gpu/drm/sti/sti_hdmi.c +4 -0
+	hdmi->reset = devm_reset_control_get(dev, "hdmi");
+	/* Take hdmi out of reset */
+	if (!IS_ERR(hdmi->reset))
+		reset_control_deassert(hdmi->reset);

Shouldn't this rather be:

	if (IS_ERR(hdmi->reset))
		return PTR_ERR(hdmi->reset);

	err = reset_control_deassert(hdmi->reset);
	if (err < 0)
		return err;

?

Quoted 13 lines
drivers/gpu/drm/sti/sti_hdmi.c +13 -0
+	hdmi_dev = &hdmi->dev;
+
+	platform_set_drvdata(pdev, hdmi);
+
+	return component_add(&pdev->dev, &sti_hdmi_ops);
+}
+
+static int sti_hdmi_remove(struct platform_device *pdev)
+{
+	component_del(&pdev->dev, &sti_hdmi_ops);
+	return 0;
+}
+

drivers/gpu/drm/sti/sti_hdmi.c line 516

Quoted 10 lines
drivers/gpu/drm/sti/sti_hdmi.c +10 -0
+static struct of_device_id hdmi_match_types[] = {
+	{
+	 .compatible = "st,stih416-hdmi",
+	 },
+	{
+	 .compatible = "st,stih407-hdmi",
+	 },
+	{ /* end node */ }
+};
+MODULE_DEVICE_TABLE(of, hdmi_match_types);

Weird indentation again. And s/hdmi_match_types/hdmi_of_match/?

drivers/gpu/drm/sti/sti_hdmi.c line 529

Quoted 12 lines
drivers/gpu/drm/sti/sti_hdmi.c +12 -0
+struct platform_driver sti_hdmi_driver = {
+	.driver = {
+		   .name = "sti-hdmi",
+		   .owner = THIS_MODULE,
+		   .of_match_table = hdmi_match_types,
+		   },
+	.probe = sti_hdmi_probe,
+	.remove = sti_hdmi_remove,
+};
+module_platform_driver(sti_hdmi_driver);
+
+MODULE_LICENSE("GPL");

I don't think you need that in every file that's built into a one module with other files. Only use it in the main source file.

Also s/GPL/GPL v2/.

Quoted 1 line
drivers/gpu/drm/sti/sti_hdmi.h +0 -0

[...]

Quoted 1 line

+/* HDMI v2.9 macro cell */

What does that mean?

drivers/gpu/drm/sti/sti_hdmi.h line 194

Quoted 11 lines
drivers/gpu/drm/sti/sti_hdmi.h +11 -0
+void sti_hdmi_attach_ddc_client(struct i2c_client *ddc);
+
+int sti_hdmi_tx3g0c55phy_start(struct sti_hdmi *hdmi);
+void sti_hdmi_tx3g0c55phy_stop(struct sti_hdmi *hdmi);
+void sti_hdmi_tx3g0c55phy_show(struct sti_hdmi *hdmi, struct seq_file *m);
+
+int sti_hdmi_tx3g4c28phy_start(struct sti_hdmi *hdmi);
+void sti_hdmi_tx3g4c28phy_stop(struct sti_hdmi *hdmi);
+void sti_hdmi_tx3g4c28phy_show(struct sti_hdmi *hdmi, struct seq_file *m);
+
+extern struct i2c_driver ddc_driver;

You should be able to get rid of all of these.

Quoted 1 line
drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c +0 -0

[...]

Quoted 9 lines

+/*
+ * Enable the old BCH/rejection PLL is now reused to provide the CLKPXPLL
+ * clock input to the new PHY PLL that generates the serializer clock
+ * (TMDS*10) and the TMDS clock which is now fed back into the HDMI
+ * formatter instead of the TMDS clock line from ClockGenB.
+ *
+ * @hdmi: pointer on the hdmi internal structure
+ *
+ * Return -1 if error occurs

Should return a proper error code.

drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c line 128

Quoted 4 lines

+ */

drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c +3 -0
+static int enable_pll_rejection(struct sti_hdmi *hdmi)
+{
+	int inputclock;

unsigned?

drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c line 133

Quoted 5 lines
drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c +5 -0
+	u32 mdiv;
+	u32 ndiv;
+	u32 pdiv;
+	u32 mask;
+	u32 val;

Variables of the same type can be declared on a single line to make this shorter.

drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c

Quoted 1 line
drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c +1 -0
+	int i;

unsigned?

Quoted 10 lines
drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c +10 -0
+	inputclock = hdmi->mode.clock * 1000;
+
+	DRM_DEBUG_DRIVER("hdmi rejection pll input clock = %dHz\n", inputclock);
+
+	/* Force to power down the HDMI rejection PLL */
+	mask = REJECTION_PLL_HDMI_ENABLE_MASK;
+	val = 0x0 << REJECTION_PLL_HDMI_ENABLE_SHIFT;
+	reg_writemask(hdmi->syscfg + HDMI_REJECTION_PLL_CONFIGURATION,
+		      val, mask);
+

drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c line 157

Quoted 10 lines
drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c +10 -0
+	/* Check the HDMI rejection PLL is really down */
+	for (i = 0; i < HDMI_WAIT_PLL_REJECTION_STATUS; i++) {
+		val = readl(hdmi->syscfg + HDMI_REJECTION_PLL_STATUS);
+		if ((val & REJECTION_PLL_HDMI_REJ_PLL_LOCK) == 0)
+			break;
+	}
+	if (i == HDMI_WAIT_PLL_REJECTION_STATUS) {
+		DRM_ERROR("hdmi rejection pll is not well powered down\n");
+		return -1;
+	}

Should this perhaps be a timed loop rather than a busy loop?

Quoted 35 lines
drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c +35 -0
+	/* Power up the HDMI rejection PLL */
+	/*
+	 * Note: On this SoC (stiH416) we are forced to have the input clock
+	 * be equal to the HDMI pixel clock.
+	 *
+	 * The values here have been suggested by validation however they are
+	 * still provisional and subject to change.
+	 *
+	 * PLLout = (Fin*Mdiv) / ((2 * Ndiv) / 2^Pdiv)
+	 */
+	if (inputclock < 50000000) {
+		/*
+		 * For slower clocks we need to multiply more to keep the
+		 * internal VCO frequency within the physical specification
+		 * of the PLL.
+		 */
+		pdiv = 4;
+		ndiv = 240;
+		mdiv = 30;
+	} else {
+		pdiv = 2;
+		ndiv = 60;
+		mdiv = 30;
+	}
+
+	mask = REJECTION_PLL_HDMI_PDIV_MASK |
+	    REJECTION_PLL_HDMI_NDIV_MASK |
+	    REJECTION_PLL_HDMI_MDIV_MASK | REJECTION_PLL_HDMI_ENABLE_MASK;
+	val = (pdiv << REJECTION_PLL_HDMI_PDIV_SHIFT) |
+	    (ndiv << REJECTION_PLL_HDMI_NDIV_SHIFT) |
+	    (mdiv << REJECTION_PLL_HDMI_MDIV_SHIFT) |
+	    (0x1 << REJECTION_PLL_HDMI_ENABLE_SHIFT);
+	reg_writemask(hdmi->syscfg + HDMI_REJECTION_PLL_CONFIGURATION,
+		      val, mask);
+

drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c line 203

Quoted 10 lines
drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c +10 -0
+	/* Check the HDMI rejection PLL is really up */
+	for (i = 0; i < HDMI_WAIT_PLL_REJECTION_STATUS; i++) {
+		val = readl(hdmi->syscfg + HDMI_REJECTION_PLL_STATUS);
+		if ((val & REJECTION_PLL_HDMI_REJ_PLL_LOCK) != 0)
+			break;
+	}
+	if (i == HDMI_WAIT_PLL_REJECTION_STATUS) {
+		DRM_ERROR("hdmi rejection pll is not well powered up\n");
+		return -1;
+	}

Same here.

Quoted 24 lines
drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c +24 -0
+
+	DRM_DEBUG_DRIVER("hdmi rejection pll locked\n");
+
+	return 0;
+}
+
+/*
+ * Disable the pll rejection
+ *
+ * @hdmi: pointer on the hdmi internal structure
+ */
+static void disable_pll_rejection(struct sti_hdmi *hdmi)
+{
+	int i;
+	u32 val;
+	u32 mask;
+
+	DRM_DEBUG_DRIVER("\n");
+
+	mask = REJECTION_PLL_HDMI_ENABLE_MASK;
+	val = 0x0 << REJECTION_PLL_HDMI_ENABLE_SHIFT;
+	reg_writemask(hdmi->syscfg + HDMI_REJECTION_PLL_CONFIGURATION,
+		      val, mask);
+

drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c line 237

Quoted 10 lines
drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c +10 -0
+	/* Check the HDMI rejection PLL is really down */
+	for (i = 0; i < HDMI_WAIT_PLL_REJECTION_STATUS; i++) {
+		val = readl(hdmi->syscfg + HDMI_REJECTION_PLL_STATUS);
+		if ((val & REJECTION_PLL_HDMI_REJ_PLL_LOCK) == 0)
+			break;
+	}
+	if (i == HDMI_WAIT_PLL_REJECTION_STATUS)
+		DRM_ERROR("hdmi rejection pll is not well powered down\n");
+	else
+		DRM_DEBUG_DRIVER("hdmi rejection pll is powered down\n");

And here.

drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c line 245

Quoted 8 lines
drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c +8 -0
+}
+
+/*
+ * Start hdmi phy macro cell tx3g0c55
+ *
+ * @hdmi: pointer on the hdmi internal structure
+ *
+ * Return -1 if error occurs

Should return a proper error code.

drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c line 254

Quoted 9 lines

+ */

drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c +8 -0
+int sti_hdmi_tx3g0c55phy_start(struct sti_hdmi *hdmi)
+{
+	u32 ckpxpll = hdmi->mode.clock * 1000;
+	u32 tmdsck;
+	u32 freqvco;
+	u32 pllctrl = 0;
+	u32 val;
+	int i;

unsigned

drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c line 257

Quoted 3 lines
drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c +3 -0
+
+	if (enable_pll_rejection(hdmi))
+		return -1;
	err = enable_pll_rejection(hdmi);
	if (err < 0)
		return err;
Quoted 20 lines
drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c +20 -0
+	/* TODO: manage DeepColor (30, 36 and 48 bits) and pixel repetition */
+
+	/* Assuming no pixel repetition and 24bits color */
+	tmdsck = ckpxpll;
+	pllctrl = 2 << HDMI_SRZ_PLL_CFG_NDIV_SHIFT;
+
+	/*
+	 * Setup the PLL mode parameter based on the ckpxpll. If we haven't got
+	 * a clock frequency supported by one of the specific PLL modes then we
+	 * will end up using the generic mode (0) which only supports a 10x
+	 * multiplier, hence only 24bit color.
+	 */
+	for (i = 0; i < NB_PLL_MODE; i++) {
+		if (ckpxpll >= pllmodes[i].min && ckpxpll <= pllmodes[i].max)
+			pllctrl |= HDMI_SRZ_PLL_CFG_MODE(pllmodes[i].mode);
+	}
+
+	freqvco = tmdsck * 10;
+	if (freqvco <= 425000000UL)
+		pllctrl |= HDMI_SRZ_PLL_CFG_VCOR(HDMI_SRZ_PLL_CFG_VCOR_425MHZ);

drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c line 290

Quoted 10 lines
drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c +10 -0
+	else if (freqvco <= 850000000UL)
+		pllctrl |= HDMI_SRZ_PLL_CFG_VCOR(HDMI_SRZ_PLL_CFG_VCOR_850MHZ);
+	else if (freqvco <= 1700000000UL)
+		pllctrl |= HDMI_SRZ_PLL_CFG_VCOR(HDMI_SRZ_PLL_CFG_VCOR_1700MHZ);
+	else if (freqvco <= 2970000000UL)
+		pllctrl |= HDMI_SRZ_PLL_CFG_VCOR(HDMI_SRZ_PLL_CFG_VCOR_3000MHZ);
+	else {
+		DRM_ERROR("PHY serializer clock out of range\n");
+		goto err;
+	}

This could be a table.

Quoted 8 lines
drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c +8 -0
+
+	/*
+	 * Configure and power up the PHY PLL
+	 */
+	hdmi->event_received = false;
+	DRM_DEBUG_DRIVER("pllctrl = 0x%x\n", pllctrl);
+	writel(pllctrl, hdmi->regs + HDMI_SRZ_PLL_CFG);
+

drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c line 308

Quoted 10 lines
drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c +10 -0
+	/* wait PLL interrupt */
+	wait_event_interruptible_timeout(hdmi->wait_event,
+					 hdmi->event_received == true,
+					 msecs_to_jiffies
+					 (HDMI_TIMEOUT_PLL_LOCK));
+
+	if ((readl(hdmi->regs + HDMI_STA) & HDMI_STA_DLL_LCK) == 0) {
+		DRM_ERROR("hdmi phy pll not locked\n");
+		goto err;
+	}

There doesn't seem to be a need for this to be strictly interrupt driven. A simple timed loop would do equally well.

Quoted 24 lines
drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c +24 -0
+	DRM_DEBUG_DRIVER("got PHY PLL Lock\n");
+
+	/*
+	 * To configure the source termination and pre-emphasis appropriately
+	 * for different high speed TMDS clock frequencies a phy configuration
+	 * table must be provided, tailored to the SoC and board combination.
+	 */
+	for (i = 0; i < NB_HDMI_PHY_CONFIG; i++) {
+		if ((hdmiphy_config[i].min_tmds_freq <= tmdsck) &&
+		    (hdmiphy_config[i].max_tmds_freq >= tmdsck)) {
+			val = hdmiphy_config[i].config[0];
+			writel(val, hdmi->regs + HDMI_SRZ_TAP_1);
+			val = hdmiphy_config[i].config[1];
+			writel(val, hdmi->regs + HDMI_SRZ_TAP_2);
+			val = hdmiphy_config[i].config[2];
+			writel(val, hdmi->regs + HDMI_SRZ_TAP_3);
+			val = hdmiphy_config[i].config[3];
+			val |= HDMI_SRZ_CTRL_EXTERNAL_DATA_EN;
+			val &= ~HDMI_SRZ_CTRL_POWER_DOWN;
+			writel(val, hdmi->regs + HDMI_SRZ_CTRL);
+
+			DRM_DEBUG_DRIVER("serializer cfg 0x%x 0x%x 0x%x 0x%x\n",
+					 hdmiphy_config[i].config[0],
+					 hdmiphy_config[i].config[1],

drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c line 343

Quoted 10 lines
drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c +10 -0
+					 hdmiphy_config[i].config[2],
+					 hdmiphy_config[i].config[3]);
+			return 0;
+		}
+	}
+
+	/*
+	 * Default, power up the serializer with no pre-emphasis or source
+	 * termination.
+	 */

Should this case produce a warning?

Quoted 12 lines
drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c +12 -0
+	writel(0x0, hdmi->regs + HDMI_SRZ_TAP_1);
+	writel(0x0, hdmi->regs + HDMI_SRZ_TAP_2);
+	writel(0x0, hdmi->regs + HDMI_SRZ_TAP_3);
+	writel(HDMI_SRZ_CTRL_EXTERNAL_DATA_EN, hdmi->regs + HDMI_SRZ_CTRL);
+
+	return 0;
+
+err:
+	disable_pll_rejection(hdmi);
+
+	return -1;
+}

[...]

drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c line 397

Quoted 13 lines
drivers/gpu/drm/sti/sti_hdmi_tx3g0c55phy.c +13 -0
+/*
+ * Debugfs
+ */
+#define HDMI_DBG_DUMP(reg) seq_printf(m, "\n %-25s 0x%08X", #reg, \
+		readl(hdmi->regs + reg))
+void sti_hdmi_tx3g0c55phy_show(struct sti_hdmi *hdmi, struct seq_file *m)
+{
+	HDMI_DBG_DUMP(HDMI_SRZ_PLL_CFG);
+	HDMI_DBG_DUMP(HDMI_SRZ_TAP_1);
+	HDMI_DBG_DUMP(HDMI_SRZ_TAP_2);
+	HDMI_DBG_DUMP(HDMI_SRZ_TAP_3);
+	HDMI_DBG_DUMP(HDMI_SRZ_CTRL);
+	seq_puts(m, "\n");

Why the empty line? Is this supposed to be used as part of a larger file? I'd recommend against doing that and rather have one debugfs entry for each device's register file.

drivers/gpu/drm/sti/sti_hdmi_tx3g4c28phy.c

Quoted 1 line
drivers/gpu/drm/sti/sti_hdmi_tx3g4c28phy.c +0 -0

[...]

Mostly the same comments apply here as for the other PHY.

Thierry

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

#8 lore raw

PATCH v3 4/16 drm: sti: add I2C client driver for HDMI

In reply to Benjamin Gaignard

Add I2C client driver to retrieve EDID.

---
 drivers/gpu/drm/sti/Makefile  |  3 ++-
 drivers/gpu/drm/sti/sti_ddc.c | 56 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/sti/sti_ddc.c
drivers/gpu/drm/sti/Makefile +2 -1
index 5295fc7..6c474eb 100644
@@ -2,7 +2,8 @@ ccflags-y := -Iinclude/drm
 
 stidrm-y := sti_hdmi.o \
 			sti_hdmi_tx3g0c55phy.o \
-			sti_hdmi_tx3g4c28phy.o
+			sti_hdmi_tx3g4c28phy.o \
+			sti_ddc.o
 
 obj-$(CONFIG_VTAC_STI) += sti_vtac_tx.o sti_vtac_rx.o
 obj-$(CONFIG_VTG_STI) += sti_vtg.o sti_vtg_utils.o
drivers/gpu/drm/sti/sti_ddc.c new file +56 -0

56 lines not on this page · raw message

Signature · 1 line
1.9.1
#9 lore raw

Re: [PATCH v3 04/16] drm: sti: add I2C client driver for HDMI

Quoted 8 lines · Benjamin Gaignard

Add I2C client driver to retrieve EDID.

---
 drivers/gpu/drm/sti/Makefile  |  3 ++-
 drivers/gpu/drm/sti/sti_ddc.c | 56 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/sti/sti_ddc.c

With my comments about DDC in the previous patch addressed this can be completely dropped.

Thierry

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

#10 lore raw

PATCH v3 5/16 drm: sti: add HDA driver

In reply to Benjamin Gaignard

Add driver to support analog TV ouput.

---
 drivers/gpu/drm/sti/Makefile  |   1 +
 drivers/gpu/drm/sti/sti_hda.c | 480 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 481 insertions(+)
 create mode 100644 drivers/gpu/drm/sti/sti_hda.c
drivers/gpu/drm/sti/Makefile +1 -0
index 6c474eb..aa69ea0 100644
@@ -3,6 +3,7 @@ ccflags-y := -Iinclude/drm
 stidrm-y := sti_hdmi.o \
 			sti_hdmi_tx3g0c55phy.o \
 			sti_hdmi_tx3g4c28phy.o \
+			sti_hda.o \
 			sti_ddc.o
 
 obj-$(CONFIG_VTAC_STI) += sti_vtac_tx.o sti_vtac_rx.o
drivers/gpu/drm/sti/sti_hda.c new file +480 -0

480 lines not on this page · raw message

Signature · 1 line
1.9.1
#11 lore raw

Re: [PATCH v3 05/16] drm: sti: add HDA driver

Quoted 1 line · Benjamin Gaignard

Add driver to support analog TV ouput.

Unfortunate that this has the same abbreviation as High-Definition Audio...

Quoted 1 line
drivers/gpu/drm/sti/sti_hda.c +0 -0

[...]

drivers/gpu/drm/sti/sti_hda.c line 66

Quoted 6 lines
drivers/gpu/drm/sti/sti_hda.c +6 -0
+/* Video DACs control */
+#define VIDEO_DACS_CONTROL_MASK         0x0FFF
+#define VIDEO_DACS_CONTROL_SYSCFG2535   0x085C /* for stih416 */
+#define DAC_CFG_HD_OFF_SHIFT            5
+#define DAC_CFG_HD_OFF_MASK             (0x7 << DAC_CFG_HD_OFF_SHIFT)
+#define VIDEO_DACS_CONTROL_SYSCFG5072   0x0120 /* for stih407 */

syscfg is starting to look more and more like it could be a syscon driver or some other specialized, platform-specific driver.

drivers/gpu/drm/sti/sti_hda.c line 233

Quoted 2 lines
drivers/gpu/drm/sti/sti_hda.c +2 -0
+/* Index (in supported modes table) of the preferred video mode */
+#define HDA_PREF_MODE_IDX               0

I don't think this symbolic name is particularly useful.

drivers/gpu/drm/sti/sti_hda.c line 257

Quoted 2 lines
drivers/gpu/drm/sti/sti_hda.c +2 -0
+/* Reference to the hda device */
+struct device *hda_dev;

This shouldn't be needed.

drivers/gpu/drm/sti/sti_hda.c line 331

Quoted 3 lines
drivers/gpu/drm/sti/sti_hda.c +3 -0
+static void sti_hda_configure_awg(struct sti_hda *hda, u32 *awg_instr, int nb)
+{
+	int i;

unsigned

drivers/gpu/drm/sti/sti_hda.c line 352

Quoted 12 lines
drivers/gpu/drm/sti/sti_hda.c +12 -0
+/*
+ * Get modes
+ *
+ * @drm_connector: pointer on the drm connector
+ *
+ * Return number of modes
+ */
+static int sti_hda_get_modes(struct drm_connector *drm_connector)
+{
+	struct drm_device *dev = drm_connector->dev;
+	struct drm_display_mode *mode;
+	int i, count;

unsigned for i. count should probably stay signed since DRM uses that throughout.

drivers/gpu/drm/sti/sti_hda.c line 356

Quoted 4 lines
drivers/gpu/drm/sti/sti_hda.c +4 -0
+
+	DRM_DEBUG_DRIVER("\n");
+
+	for (i = 0, count = 0; i < ARRAY_SIZE(hda_supported_modes); i++) {

You can initialize count when it's declared to make the loop more idiomatic.

Quoted 9 lines
drivers/gpu/drm/sti/sti_hda.c +9 -0
+		mode = drm_mode_duplicate(dev, &hda_supported_modes[i].mode);
+		if (!mode)
+			continue;
+		mode->vrefresh = drm_mode_vrefresh(mode);
+
+		/* Set the preferred mode */
+		if (i == HDA_PREF_MODE_IDX)
+			mode->type |= DRM_MODE_TYPE_PREFERRED;
+

drivers/gpu/drm/sti/sti_hda.c line 375

Quoted 10 lines
drivers/gpu/drm/sti/sti_hda.c +10 -0
+		drm_mode_probed_add(drm_connector, mode);
+		count++;
+	}
+
+	drm_mode_sort(&drm_connector->modes);
+
+	return count;
+}
+
+

Gratuituous newline.

Quoted 2 lines
drivers/gpu/drm/sti/sti_hda.c +2 -0
+static int sti_hda_probe(struct platform_device *pdev)
+{

[...]

Quoted 4 lines
drivers/gpu/drm/sti/sti_hda.c +4 -0
+}
+
+static int sti_hda_remove(struct platform_device *pdev)
+{

[...]

Quoted 16 lines
drivers/gpu/drm/sti/sti_hda.c +16 -0
+}
+
+static struct of_device_id hda_match_types[] = {
+	{
+	 .compatible = "st,stih416-hda",
+	 },
+	{
+	 .compatible = "st,stih407-hda",
+	 },
+	{ /* end node */ }
+};
+MODULE_DEVICE_TABLE(of, hda_match_types);
+
+struct platform_driver sti_hda_driver = {
+	.driver = {
+		   .name = "sti-hda",

drivers/gpu/drm/sti/sti_hda.c line 480

Quoted 10 lines
drivers/gpu/drm/sti/sti_hda.c +10 -0
+		   .owner = THIS_MODULE,
+		   .of_match_table = hda_match_types,
+		   },
+	.probe = sti_hda_probe,
+	.remove = sti_hda_remove,
+};
+
+module_platform_driver(sti_hda_driver);
+
+MODULE_LICENSE("GPL");

Same comments here as for all previous patches.

Thierry

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

#12 lore raw

PATCH v3 6/16 drm: sti: add TVOut driver

In reply to Benjamin Gaignard

TVout hardware block is responsible to dispatch the data flow coming from compositor block to any of the output (HDMI or Analog TV). It control when output are start/stop and configure according the require flow path.

---
 drivers/gpu/drm/sti/Makefile    |   3 +-
 drivers/gpu/drm/sti/sti_hda.c   | 372 +++++++++++++++++++++
 drivers/gpu/drm/sti/sti_hda.h   |  14 +
 drivers/gpu/drm/sti/sti_hdmi.c  | 542 +++++++++++++++++++++++++++++++
 drivers/gpu/drm/sti/sti_hdmi.h  |   3 +
 drivers/gpu/drm/sti/sti_tvout.c | 702 ++++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/sti/sti_tvout.h | 105 ++++++
 7 files changed, 1740 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/sti/sti_hda.h
 create mode 100644 drivers/gpu/drm/sti/sti_tvout.c
 create mode 100644 drivers/gpu/drm/sti/sti_tvout.h
drivers/gpu/drm/sti/Makefile +2 -1
index aa69ea0..45536c3 100644
@@ -1,6 +1,7 @@
 ccflags-y := -Iinclude/drm
 
-stidrm-y := sti_hdmi.o \
+stidrm-y :=	sti_tvout.o \
+			sti_hdmi.o \
 			sti_hdmi_tx3g0c55phy.o \
 			sti_hdmi_tx3g4c28phy.o \
 			sti_hda.o \
drivers/gpu/drm/sti/sti_hda.c +372 -0

384 lines not on this page · raw message

drivers/gpu/drm/sti/sti_hda.h new file +14 -0
new file mode 100644
index 0000000..e88b30e
@@ -0,0 +1,14 @@
+/*
+ * Copyright (C) STMicroelectronics SA 2014
+ * Authors: Fabien Dessenne <[email protected]> for STMicroelectronics.
+ * License terms: GNU General Public License (GPL), version 2
+ */
+
+#ifndef _STI_HDA_H_
+#define _STI_HDA_H_
+
+#include "sti_tvout.h"
+
+struct sti_tvout_connector *sti_hda_create(struct sti_tvout *tvout);
+
+#endif
drivers/gpu/drm/sti/sti_hdmi.c +542 -0

548 lines not on this page · raw message

drivers/gpu/drm/sti/sti_hdmi.h +3 -0
index c14c683..ed90a2c 100644
@@ -11,6 +11,8 @@
 
 #include <drm/drmP.h>
 
+#include "sti_tvout.h"
+
 /* HDMI v2.9 macro cell */
 #define HDMI_CFG                        0x0000
 #define HDMI_INT_EN                     0x0004
@@ -181,6 +183,7 @@ struct hdmi_phy_config {
 	u32 config[4];
 };
 
+struct sti_tvout_connector *sti_hdmi_create(struct sti_tvout *tvout);
 void sti_hdmi_attach_ddc_client(struct i2c_client *ddc);
 
 int sti_hdmi_tx3g0c55phy_start(struct sti_hdmi *hdmi);
drivers/gpu/drm/sti/sti_tvout.c new file +702 -0

702 lines not on this page · raw message

drivers/gpu/drm/sti/sti_tvout.h new file +105 -0

105 lines not on this page · raw message

Signature · 1 line
1.9.1
#13 lore raw

PATCH v3 7/16 drm: sti: add sti layer interface definition

In reply to Benjamin Gaignard

STI hardware have various input sub-devices before mixing block. Each type of sub-device have different capabilities for scaling, filtering or accepted pixel format.
This layer interface abstract those differences and make the interaction with compositor more simple.

---
 drivers/gpu/drm/sti/sti_layer.h | 104 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 104 insertions(+)
 create mode 100644 drivers/gpu/drm/sti/sti_layer.h
drivers/gpu/drm/sti/sti_layer.h new file +104 -0
new file mode 100644
index 0000000..ed8386a
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) STMicroelectronics SA 2013
+ * Authors: Benjamin Gaignard <[email protected]>
+ *          Fabien Dessenne <[email protected]>
+ *          for STMicroelectronics.
+ * License terms:  GNU General Public License (GPL), version 2
+ */
+
+#ifndef _STI_LAYER_H_
+#define _STI_LAYER_H_
+
+#include <drm/drmP.h>
+
+#define to_sti_layer(x) container_of(x, struct sti_layer, plane)
+
+#define STI_LAYER_TYPE_SHIFT 8
+#define STI_LAYER_TYPE_MASK (~((1<<STI_LAYER_TYPE_SHIFT)-1))
+
+
+enum sti_layer_type {
+	STI_GDP = 1 << STI_LAYER_TYPE_SHIFT,
+	STI_VID = 2 << STI_LAYER_TYPE_SHIFT,
+	STI_CUR = 3 << STI_LAYER_TYPE_SHIFT,
+	STI_BCK = 4 << STI_LAYER_TYPE_SHIFT
+};
+
+enum sti_layer_id_of_type {
+	STI_ID_0 = 0,
+	STI_ID_1 = 1,
+	STI_ID_2 = 2,
+	STI_ID_3 = 3
+};
+
+enum sti_layer_desc {
+	STI_GDP_0	= STI_GDP | STI_ID_0,
+	STI_GDP_1	= STI_GDP | STI_ID_1,
+	STI_GDP_2	= STI_GDP | STI_ID_2,
+	STI_GDP_3	= STI_GDP | STI_ID_3,
+	STI_VID_0	= STI_VID | STI_ID_0,
+	STI_VID_1	= STI_VID | STI_ID_1,
+	STI_CURSOR	= STI_CUR,
+	STI_BACK	= STI_BCK
+};
+
+struct sti_fps_info {
+	bool output;
+	int curr_frame_counter;
+	int last_frame_counter;
+	struct timespec last_timestamp;
+};
+
+/*
+ * STI layer structure
+ *
+ * @plane:		drm plane it is bound to (if any)
+ * @fb:			drm fb it is bound to
+ * @mode:		display mode
+ * @desc:		layer type & id
+ * @zorder:		layer z-order
+ * @enabled:		to know if the layer is active or not
+ * @src_x src_y:	coordinates of the input (fb) area
+ * @src_w src_h:	size of the input (fb) area
+ * @dst_x dst_y:	coordinates of the output (crtc) area
+ * @dst_w dst_h:	size of the output (crtc) area
+ * @format:		format
+ * @pitches:		pitch of 'planes' (eg: Y, U, V)
+ * @offsets:		offset of 'planes'
+ * @paddr:		physical address of the input buffer
+ * @fps_info:		frame per second info
+ */
+struct sti_layer {
+	struct drm_plane plane;
+	struct drm_framebuffer *fb;
+	struct drm_display_mode *mode;
+	enum sti_layer_desc desc;
+	int zorder;
+	bool enabled;
+	int src_x, src_y;
+	int src_w, src_h;
+	int dst_x, dst_y;
+	int dst_w, dst_h;
+	uint32_t format;
+	int pitches[4];
+	int offsets[4];
+	dma_addr_t paddr;
+	struct sti_fps_info fps_info;
+};
+
+struct sti_layer *sti_layer_create(struct device *dev, int desc,
+			void __iomem *baseaddr);
+int sti_layer_prepare(struct sti_layer *layer, struct drm_framebuffer *fb,
+			struct drm_display_mode *mode,
+			int dest_x, int dest_y,
+			int dest_w, int dest_h,
+			int src_x, int src_y,
+			int src_w, int src_h);
+int sti_layer_commit(struct sti_layer *layer);
+int sti_layer_disable(struct sti_layer *layer);
+const uint32_t *sti_layer_get_formats(struct sti_layer *layer);
+int sti_layer_get_nb_formats(struct sti_layer *layer);
+struct sti_layer *sti_layer_find_layer(struct sti_layer *layer[],
+			enum sti_layer_desc desc);
+const char *sti_layer_to_str(struct sti_layer *layer);
+#endif
Signature · 1 line
1.9.1
#14 lore raw

PATCH v3 8/16 drm: sti: add GDP layer

In reply to Benjamin Gaignard

Generic Display Pipeline are one of the compositor input sub-devices. GDP are dedicated to graphic input like RGB plans.

---
 drivers/gpu/drm/sti/Makefile    |   3 +-
 drivers/gpu/drm/sti/sti_gdp.c   | 491 ++++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/sti/sti_gdp.h   |  73 ++++++
 drivers/gpu/drm/sti/sti_layer.h |   5 +
 4 files changed, 571 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/sti/sti_gdp.c
 create mode 100644 drivers/gpu/drm/sti/sti_gdp.h
drivers/gpu/drm/sti/Makefile +2 -1
index 45536c3..cc04475 100644
@@ -1,10 +1,11 @@
 ccflags-y := -Iinclude/drm
 
-stidrm-y :=	sti_tvout.o \
+stidrm-y := sti_tvout.o \
 			sti_hdmi.o \
 			sti_hdmi_tx3g0c55phy.o \
 			sti_hdmi_tx3g4c28phy.o \
 			sti_hda.o \
+			sti_gdp.o \
 			sti_ddc.o
 
 obj-$(CONFIG_VTAC_STI) += sti_vtac_tx.o sti_vtac_rx.o
drivers/gpu/drm/sti/sti_gdp.c new file +491 -0

491 lines not on this page · raw message

drivers/gpu/drm/sti/sti_gdp.h new file +73 -0

73 lines not on this page · raw message

drivers/gpu/drm/sti/sti_layer.h +5 -0
index ed8386a..45cd1ea 100644
@@ -10,6 +10,7 @@
 #define _STI_LAYER_H_
 
 #include <drm/drmP.h>
+#include "sti_gdp.h"
 
 #define to_sti_layer(x) container_of(x, struct sti_layer, plane)
 
@@ -67,6 +68,7 @@ struct sti_fps_info {
  * @offsets:		offset of 'planes'
  * @paddr:		physical address of the input buffer
  * @fps_info:		frame per second info
+ * @gdp:                related GDP (if the layer is a GDP)
  */
 struct sti_layer {
 	struct drm_plane plane;
@@ -74,6 +76,7 @@ struct sti_layer {
 	struct drm_display_mode *mode;
 	enum sti_layer_desc desc;
 	int zorder;
+	int mixer_id;
 	bool enabled;
 	int src_x, src_y;
 	int src_w, src_h;
@@ -84,12 +87,14 @@ struct sti_layer {
 	int offsets[4];
 	dma_addr_t paddr;
 	struct sti_fps_info fps_info;
+	struct sti_gdp *gdp;
 };
 
 struct sti_layer *sti_layer_create(struct device *dev, int desc,
 			void __iomem *baseaddr);
 int sti_layer_prepare(struct sti_layer *layer, struct drm_framebuffer *fb,
 			struct drm_display_mode *mode,
+			int mixer_id,
 			int dest_x, int dest_y,
 			int dest_w, int dest_h,
 			int src_x, int src_y,
Signature · 1 line
1.9.1
#15 lore raw

PATCH v3 9/16 drm: sti: add VID layer

In reply to Benjamin Gaignard

VIDeo plug are one of the compositor input sub-devices. VID are dedicated to video inputs like YUV plans.

---
 drivers/gpu/drm/sti/Makefile    |   1 +
 drivers/gpu/drm/sti/sti_layer.h |   4 ++
 drivers/gpu/drm/sti/sti_vid.c   | 138 ++++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/sti/sti_vid.h   |  33 ++++++++++
 4 files changed, 176 insertions(+)
 create mode 100644 drivers/gpu/drm/sti/sti_vid.c
 create mode 100644 drivers/gpu/drm/sti/sti_vid.h
drivers/gpu/drm/sti/Makefile +1 -0
index cc04475..b9a3b74 100644
@@ -6,6 +6,7 @@ stidrm-y := sti_tvout.o \
 			sti_hdmi_tx3g4c28phy.o \
 			sti_hda.o \
 			sti_gdp.o \
+			sti_vid.o \
 			sti_ddc.o
 
 obj-$(CONFIG_VTAC_STI) += sti_vtac_tx.o sti_vtac_rx.o
drivers/gpu/drm/sti/sti_layer.h +4 -0
index 45cd1ea..bf3a14f 100644
@@ -11,6 +11,7 @@
 
 #include <drm/drmP.h>
 #include "sti_gdp.h"
+#include "sti_vid.h"
 
 #define to_sti_layer(x) container_of(x, struct sti_layer, plane)
 
@@ -58,6 +59,7 @@ struct sti_fps_info {
  * @mode:		display mode
  * @desc:		layer type & id
  * @zorder:		layer z-order
+ * @mixer_id:           id of the mixer used to display the layer
  * @enabled:		to know if the layer is active or not
  * @src_x src_y:	coordinates of the input (fb) area
  * @src_w src_h:	size of the input (fb) area
@@ -69,6 +71,7 @@ struct sti_fps_info {
  * @paddr:		physical address of the input buffer
  * @fps_info:		frame per second info
  * @gdp:                related GDP (if the layer is a GDP)
+ * @vid:                related VID (if the layer is a VID/VDP)
  */
 struct sti_layer {
 	struct drm_plane plane;
@@ -88,6 +91,7 @@ struct sti_layer {
 	dma_addr_t paddr;
 	struct sti_fps_info fps_info;
 	struct sti_gdp *gdp;
+	struct sti_vid *vid;
 };
 
 struct sti_layer *sti_layer_create(struct device *dev, int desc,
drivers/gpu/drm/sti/sti_vid.c new file +138 -0

138 lines not on this page · raw message

drivers/gpu/drm/sti/sti_vid.h new file +33 -0
new file mode 100644
index 0000000..dd4fd95
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) STMicroelectronics SA 2013
+ * Author: Fabien Dessenne <[email protected]> for STMicroelectronics.
+ * License terms:  GNU General Public License (GPL), version 2
+ */
+
+#ifndef _STI_VID_H_
+#define _STI_VID_H_
+
+/*
+ * STI VID structure
+ *
+ * @device:		driver device
+ * @regs:               subdevice register
+ * @get_formats:	get VID supported formats
+ * @get_nb_formats:	get number of format supported
+ * @prepare:		prepare VID before rendering
+ * @commit:		set VID for rendering
+ * @disable:		disable VID
+ */
+struct sti_vid {
+	struct device *dev;
+	void __iomem *regs;
+	const uint32_t* (*get_formats)(void);
+	int (*get_nb_formats)(void);
+	int (*prepare)(void *layer, bool first_prepare);
+	int (*commit)(void *layer);
+	int (*disable)(void *layer);
+};
+
+struct sti_vid *sti_vid_create(struct device *dev, void __iomem *baseaddr);
+
+#endif
Signature · 1 line
1.9.1
#16 lore raw

PATCH v3 10/16 drm: sti: add Mixer

In reply to Benjamin Gaignard

Mixer hardware IP is responsible of mixing the different inputs layers. Z-order is managed by the mixer.
We could 2 mixers: one for main path and one for auxilary path

---
 drivers/gpu/drm/sti/Makefile    |   1 +
 drivers/gpu/drm/sti/sti_mixer.c | 241 ++++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/sti/sti_mixer.h |  52 +++++++++
 3 files changed, 294 insertions(+)
 create mode 100644 drivers/gpu/drm/sti/sti_mixer.c
 create mode 100644 drivers/gpu/drm/sti/sti_mixer.h
drivers/gpu/drm/sti/Makefile +1 -0
index b9a3b74..3d52d2a 100644
@@ -5,6 +5,7 @@ stidrm-y := sti_tvout.o \
 			sti_hdmi_tx3g0c55phy.o \
 			sti_hdmi_tx3g4c28phy.o \
 			sti_hda.o \
+			sti_mixer.o \
 			sti_gdp.o \
 			sti_vid.o \
 			sti_ddc.o
drivers/gpu/drm/sti/sti_mixer.c new file +241 -0

241 lines not on this page · raw message

drivers/gpu/drm/sti/sti_mixer.h new file +52 -0

52 lines not on this page · raw message

Signature · 1 line
1.9.1
#17 lore raw

PATCH v3 11/16 drm: sti: add Compositor

In reply to Benjamin Gaignard

Compositor control all the input sub-devices and the mixer. It is the main entry point for composition.
Layer interface is used to control the layer.

---
 drivers/gpu/drm/sti/Kconfig          |   1 +
 drivers/gpu/drm/sti/Makefile         |   2 +
 drivers/gpu/drm/sti/sti_compositor.c | 219 +++++++++++++++++++++++++
 drivers/gpu/drm/sti/sti_compositor.h |  84 ++++++++++
 drivers/gpu/drm/sti/sti_layer.c      | 309 +++++++++++++++++++++++++++++++++++
 5 files changed, 615 insertions(+)
 create mode 100644 drivers/gpu/drm/sti/sti_compositor.c
 create mode 100644 drivers/gpu/drm/sti/sti_compositor.h
 create mode 100644 drivers/gpu/drm/sti/sti_layer.c
drivers/gpu/drm/sti/Kconfig +1 -0
index 87e6128..76c2e4f 100644
@@ -1,6 +1,7 @@
 config DRM_STI
 	bool "DRM Support for STMicroelectronics SoC stiH41x Series"
 	depends on DRM && (SOC_STIH415 || SOC_STIH416 || ARCH_MULTIPLATFORM)
+	select DRM_KMS_CMA_HELPER
 	help
 	  Choose this option to enable DRM on STM stiH41x chipset
 
drivers/gpu/drm/sti/Makefile +2 -0
index 3d52d2a..3b804d4 100644
@@ -5,6 +5,8 @@ stidrm-y := sti_tvout.o \
 			sti_hdmi_tx3g0c55phy.o \
 			sti_hdmi_tx3g4c28phy.o \
 			sti_hda.o \
+			sti_compositor.o \
+			sti_layer.o \
 			sti_mixer.o \
 			sti_gdp.o \
 			sti_vid.o \
drivers/gpu/drm/sti/sti_compositor.c new file +219 -0

219 lines not on this page · raw message

drivers/gpu/drm/sti/sti_compositor.h new file +84 -0

84 lines not on this page · raw message

drivers/gpu/drm/sti/sti_layer.c new file +309 -0

309 lines not on this page · raw message

Signature · 1 line
1.9.1
#18 lore raw

PATCH v3 12/16 drm: sti: add debug to GDP

In reply to Benjamin Gaignard

Allow to get more detailed debug information on GDP

---
 drivers/gpu/drm/sti/sti_drm_drv.h |  36 ++++++
 drivers/gpu/drm/sti/sti_gdp.c     | 235 ++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/sti/sti_gdp.h     |   2 +
 3 files changed, 273 insertions(+)
 create mode 100644 drivers/gpu/drm/sti/sti_drm_drv.h
drivers/gpu/drm/sti/sti_drm_drv.h new file +36 -0
new file mode 100644
index 0000000..5660196
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) STMicroelectronics SA 2013
+ * Author: Benjamin Gaignard <[email protected]> for STMicroelectronics.
+ * License terms:  GNU General Public License (GPL), version 2
+ */
+
+#ifndef _STI_DRM_DRV_H_
+#define _STI_DRM_DRV_H_
+
+#include <linux/platform_device.h>
+
+#include <drm/drmP.h>
+
+#include "sti_compositor.h"
+#include "sti_tvout.h"
+
+/*
+ * STI drm private structure
+ * This structure is stored as private in the drm_device
+ *
+ * @compo:                 compositor
+ * @tvout:                 TV OUT
+ * @pageflip_evt_list:     list of pending page flip requests
+ * @plane_zorder_property: z-order property for CRTC planes
+ */
+struct sti_drm_private {
+	struct sti_compositor *compo;
+	struct sti_tvout *tvout;
+	struct list_head pageflip_evt_list;
+	struct drm_property *plane_zorder_property;
+};
+
+#define STI_MAX_FB_HEIGHT	4096
+#define STI_MAX_FB_WIDTH	4096
+
+#endif
drivers/gpu/drm/sti/sti_gdp.c +235 -0

289 lines not on this page · raw message

drivers/gpu/drm/sti/sti_gdp.h +2 -0
index 4f7f40b..84875ff 100644
@@ -69,5 +69,7 @@ struct sti_gdp {
 
 struct sti_gdp *sti_gdp_create(struct device *dev, int id,
 		void __iomem *baseaddr);
+int sti_gdp_dbg_show(struct seq_file *m, void *arg);
+int sti_gdp_node_dbg_show(struct seq_file *m, void *arg);
 
 #endif
Signature · 1 line
1.9.1
#19 lore raw

PATCH v3 13/16 drm: sti: add debug to VID

In reply to Benjamin Gaignard

Make VIdeo plug more verbose on what is on going

---
 drivers/gpu/drm/sti/sti_vid.c | 121 ++++++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/sti/sti_vid.h |   1 +
 2 files changed, 122 insertions(+)
drivers/gpu/drm/sti/sti_vid.c +121 -0
index 710665d..35f60d8 100644
@@ -8,6 +8,8 @@
 
 #include "sti_vid.h"
 #include "sti_layer.h"
+#include "sti_compositor.h"
+#include "sti_drm_drv.h"
 #include "sti_vtg_utils.h"
 
 /* Registers */
@@ -49,6 +51,8 @@ static int sti_vid_prepare_layer(void *lay, bool first_prepare)
 	struct sti_layer *layer = (struct sti_layer *)lay;
 	struct sti_vid *vid = layer->vid;
 
+	dev_dbg(vid->dev, "%s %s\n", __func__, sti_layer_to_str(layer));
+
 	/* Unmask */
 	val = readl(vid->regs + VID_CTL);
 	val &= ~VID_CTL_IGNORE;
@@ -64,6 +68,8 @@ static int sti_vid_commit_layer(void *lay)
 	struct drm_display_mode *mode = layer->mode;
 	u32 ydo, xdo, yds, xds;
 
+	dev_dbg(vid->dev, "%s %s\n", __func__, sti_layer_to_str(layer));
+
 	ydo = sti_vtg_get_line_number(*mode, layer->dst_y);
 	yds = sti_vtg_get_line_number(*mode, layer->dst_y + layer->dst_h - 1);
 	xdo = sti_vtg_get_pixel_number(*mode, layer->dst_x);
@@ -81,6 +87,8 @@ static int sti_vid_disable_layer(void *lay)
 	struct sti_layer *layer = (struct sti_layer *)lay;
 	struct sti_vid *vid = layer->vid;
 
+	DRM_DEBUG_DRIVER("%s\n", sti_layer_to_str(layer));
+
 	/* Mask */
 	val = readl(vid->regs + VID_CTL);
 	val |= VID_CTL_IGNORE;
@@ -136,3 +144,116 @@ struct sti_vid *sti_vid_create(struct device *dev, void __iomem *baseaddr)
 
 	return vid;
 }
+
+static void sti_vid_dbg_ctl(struct seq_file *m, int val)
+{
+	val = val >> 30;
+	seq_puts(m, "\t");
+
+	if (!(val & 1))
+		seq_puts(m, "NOT ");
+	seq_puts(m, "ignored on main mixer - ");
+
+	if (!(val & 2))
+		seq_puts(m, "NOT ");
+	seq_puts(m, "ignored on aux mixer");
+}
+
+static void sti_vid_dbg_vpo(struct seq_file *m, int val)
+{
+	seq_printf(m, "\txdo:%4d\tydo:%4d", val & 0x0FFF, (val >> 16) & 0x0FFF);
+}
+
+static void sti_vid_dbg_vps(struct seq_file *m, int val)
+{
+	seq_printf(m, "\txds:%4d\tyds:%4d", val & 0x0FFF, (val >> 16) & 0x0FFF);
+}
+
+static void sti_vid_dbg_mst(struct seq_file *m, int val)
+{
+	if (val & 1)
+		seq_puts(m, "\tBUFFER UNDERFLOW!");
+}
+
+#define DBG_DUMP(reg) \
+	seq_printf(m, "\n " #reg "\t 0x%08X", readl(vid->regs + reg))
+
+int sti_vid_dbg_show(struct seq_file *m, void *arg)
+{
+	struct drm_info_node *node = (struct drm_info_node *)m->private;
+	struct drm_device *dev = node->minor->dev;
+	struct sti_drm_private *dev_priv = dev->dev_private;
+	struct sti_compositor *compo = dev_priv->compo;
+	enum sti_layer_desc vid_id = *(enum sti_layer_desc *)arg;
+	struct sti_layer *layer;
+	struct sti_vid *vid;
+	struct drm_plane *plane;
+	struct drm_crtc *crtc;
+	struct drm_framebuffer *fb;
+
+	if (compo == NULL) {
+		seq_puts(m, "No compo available\n");
+		goto out;
+	}
+
+	layer = sti_layer_find_layer(compo->layer, vid_id);
+	if (!layer) {
+		seq_puts(m, "Cannot find video layer\n");
+		goto out;
+	}
+	vid = layer->vid;
+
+	seq_printf(m, "\n%s (associated with the mixer_id %d)",
+			sti_layer_to_str(layer), layer->mixer_id);
+	seq_printf(m, "\t %d frame updates",
+		   layer->fps_info.curr_frame_counter);
+
+	DBG_DUMP(VID_CTL);
+	sti_vid_dbg_ctl(m, readl(vid->regs + VID_CTL));
+	DBG_DUMP(VID_ALP);
+	DBG_DUMP(VID_CLF);
+	DBG_DUMP(VID_VPO);
+	sti_vid_dbg_vpo(m, readl(vid->regs + VID_VPO));
+	DBG_DUMP(VID_VPS);
+	sti_vid_dbg_vps(m, readl(vid->regs + VID_VPS));
+	DBG_DUMP(VID_KEY1);
+	DBG_DUMP(VID_KEY2);
+	DBG_DUMP(VID_MPR0);
+	DBG_DUMP(VID_MPR1);
+	DBG_DUMP(VID_MPR2);
+	DBG_DUMP(VID_MPR3);
+	DBG_DUMP(VID_MST);
+	sti_vid_dbg_mst(m, readl(vid->regs + VID_MST));
+	DBG_DUMP(VID_BC);
+	DBG_DUMP(VID_TINT);
+	DBG_DUMP(VID_CSAT);
+
+	seq_puts(m, "\n");
+
+	plane = &layer->plane;
+	if (!plane->base.id) {
+		seq_puts(m, " Not connected to any DRM PLANE\n");
+		goto out;
+	}
+	seq_printf(m, " Connected to DRM PLANE #%d which is:\n",
+		   plane->base.id);
+
+	crtc = plane->crtc;
+	if (!crtc) {
+		seq_puts(m, "\tNot connected to any DRM CRTC\n");
+		goto out;
+	}
+	seq_printf(m, "\tConnected to DRM CRTC #%d\n", crtc->base.id);
+
+	fb = crtc->fb;
+	if (!fb) {
+		seq_puts(m, "\tNot connected to any DRM FB\n");
+		goto out;
+	}
+	seq_printf(m, "\tConnected to DRM FB #%d, %dx%d, %.4s\n",
+		   fb->base.id,
+		   fb->width, fb->height, (char *)&fb->pixel_format);
+
+out:
+	return 0;
+}
drivers/gpu/drm/sti/sti_vid.h +1 -0
index dd4fd95..6261ade 100644
@@ -29,5 +29,6 @@ struct sti_vid {
 };
 
 struct sti_vid *sti_vid_create(struct device *dev, void __iomem *baseaddr);
+int sti_vid_dbg_show(struct seq_file *m, void *arg);
 
 #endif
Signature · 1 line
1.9.1
#20 lore raw

PATCH v3 14/16 drm: sti: add debug to TVout

In reply to Benjamin Gaignard

Use debugfs to dump information about TVout

---
 drivers/gpu/drm/sti/sti_tvout.c | 181 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 181 insertions(+)
drivers/gpu/drm/sti/sti_tvout.c +181 -0
index 3e679a0..fb199c4 100644
@@ -18,6 +18,7 @@
 #include "sti_tvout.h"
 #include "sti_hdmi.h"
 #include "sti_hda.h"
+#include "sti_drm_drv.h"
 
 /* glue regsiters */
 #define TVO_CSC_MAIN_M0                  0x000
@@ -605,6 +606,186 @@ void sti_tvout_disable(struct sti_tvout *tvout,
 			connector->stop(connector);
 }
 
+/*
+ * Debugfs
+ */
+#define TVOUT_DBG_DUMP(reg) seq_printf(m, "\n %-25s 0x%08X", #reg, \
+		readl(tvout->regs + reg))
+#define TVOUT_CONNECTOR_NAME_MAX_LENGHT 10
+#define MAX_STRING_LENGTH 55
+
+static int sti_tvout_dbg_type_to_connector_name(enum sti_tvout_connector_type
+						type, char *name)
+{
+	switch (type) {
+	case STI_TVOUT_CONNECTOR_HDMI:
+		snprintf(name, TVOUT_CONNECTOR_NAME_MAX_LENGHT, "HDMI");
+		break;
+	case STI_TVOUT_CONNECTOR_HDA:
+		snprintf(name, TVOUT_CONNECTOR_NAME_MAX_LENGHT, "HD Analog");
+		break;
+	default:
+		return -1;
+	}
+
+	return 0;
+}
+
+static void tvout_dbg_vip(struct seq_file *m, int val)
+{
+	int r, g, b, tmp, mask;
+	char str[MAX_STRING_LENGTH];
+	static const char *const reorder[] = { "Y_G", "Cb_B", "Cr_R" };
+	static const char *const clipping[] = { "No", "EAV/SAV",
+		"Limited range RGB/Y", "Limited range Cb/Cr",
+		"decided by register" };
+	static const char *const round[] = { "8-bit", "10-bit", "12-bit" };
+	static const char *const input_sel[] = { "Main (color matrix enabled)",
+		"Main (color matrix by-passed)", "", "", "", "", "", "",
+		"Aux (color matrix enabled)", "Aux (color matrix by-passed)",
+		"", "", "", "", "", "Force value"
+	};
+
+	seq_puts(m, "\t");
+
+	mask = TVO_VIP_REORDER_MASK << TVO_VIP_REORDER_R_SHIFT;
+	r = (val & mask) >> TVO_VIP_REORDER_R_SHIFT;
+	mask = TVO_VIP_REORDER_MASK << TVO_VIP_REORDER_G_SHIFT;
+	g = (val & mask) >> TVO_VIP_REORDER_G_SHIFT;
+	mask = TVO_VIP_REORDER_MASK << TVO_VIP_REORDER_B_SHIFT;
+	b = (val & mask) >> TVO_VIP_REORDER_B_SHIFT;
+	snprintf(str, MAX_STRING_LENGTH, "Reorder: %s->%s %s->%s %s->%s",
+		 reorder[r], reorder[TVO_VIP_REORDER_CR_R_SEL],
+		 reorder[g], reorder[TVO_VIP_REORDER_Y_G_SEL],
+		 reorder[b], reorder[TVO_VIP_REORDER_CB_B_SEL]);
+	seq_printf(m, "%-55s", str);
+
+	mask = TVO_VIP_CLIP_MASK << TVO_VIP_CLIP_SHIFT;
+	tmp = (val & mask) >> TVO_VIP_CLIP_SHIFT;
+	snprintf(str, MAX_STRING_LENGTH, "Clipping: %s", clipping[tmp]);
+	seq_printf(m, "%-55s", str);
+
+	seq_printf(m, "\n%-40s", "");
+
+	mask = TVO_VIP_RND_MASK << TVO_VIP_RND_SHIFT;
+	tmp = (val & mask) >> TVO_VIP_RND_SHIFT;
+	snprintf(str, MAX_STRING_LENGTH,
+		 "Round: input data rounded to %s per component", round[tmp]);
+	seq_printf(m, "%-55s", str);
+
+	tmp = (val & TVO_VIP_SEL_INPUT_MASK);
+	snprintf(str, MAX_STRING_LENGTH, "Input selection: %s", input_sel[tmp]);
+	seq_printf(m, "%-55s", str);
+}
+
+static void tvout_dbg_hd_dac_cfg(struct seq_file *m, int val)
+{
+	seq_puts(m, "\t HD DAC ");
+	seq_puts(m, val & 1 ? "disabled" : "enabled");
+}
+
+static int tvout_dbg_show(struct seq_file *m,
+			  enum sti_tvout_connector_type type)
+{
+	struct drm_info_node *node = (struct drm_info_node *)m->private;
+	struct drm_device *dev = node->minor->dev;
+	struct sti_drm_private *dev_priv = dev->dev_private;
+	struct sti_tvout *tvout = dev_priv->tvout;
+	struct sti_tvout_connector *connector = tvout->connector[type];
+	char name[TVOUT_CONNECTOR_NAME_MAX_LENGHT];
+	int ret;
+
+	if (!connector)
+		return -1;
+
+	if (!connector->is_enabled)
+		return -1;
+
+	ret = mutex_lock_interruptible(&dev->struct_mutex);
+	if (ret)
+		return ret;
+
+	if (tvout == NULL) {
+		seq_puts(m, "No tvout available");
+		goto out;
+	}
+
+	ret = sti_tvout_dbg_type_to_connector_name(type, name);
+	if (ret) {
+		seq_puts(m, "No connector!");
+		goto out;
+	}
+
+	seq_printf(m, "\n%s connector: ", name);
+	seq_printf(m, "\nTVOUT: (virt base addr = 0x%p)", tvout->regs);
+	if (connector->is_enabled(connector)) {
+		if (connector->main_path) {
+			seq_puts(m, "\n Connected to the main path");
+			TVOUT_DBG_DUMP(TVO_CSC_MAIN_M0);
+			TVOUT_DBG_DUMP(TVO_CSC_MAIN_M1);
+			TVOUT_DBG_DUMP(TVO_CSC_MAIN_M2);
+			TVOUT_DBG_DUMP(TVO_CSC_MAIN_M3);
+			TVOUT_DBG_DUMP(TVO_CSC_MAIN_M4);
+			TVOUT_DBG_DUMP(TVO_CSC_MAIN_M5);
+			TVOUT_DBG_DUMP(TVO_CSC_MAIN_M6);
+			TVOUT_DBG_DUMP(TVO_CSC_MAIN_M7);
+			TVOUT_DBG_DUMP(TVO_MAIN_IN_VID_FORMAT);
+		} else {
+			seq_puts(m, "\n Connected to the auxiliary path");
+			TVOUT_DBG_DUMP(TVO_CSC_AUX_M0);
+			TVOUT_DBG_DUMP(TVO_CSC_AUX_M2);
+			TVOUT_DBG_DUMP(TVO_CSC_AUX_M3);
+			TVOUT_DBG_DUMP(TVO_CSC_AUX_M4);
+			TVOUT_DBG_DUMP(TVO_CSC_AUX_M5);
+			TVOUT_DBG_DUMP(TVO_CSC_AUX_M6);
+			TVOUT_DBG_DUMP(TVO_CSC_AUX_M7);
+			TVOUT_DBG_DUMP(TVO_AUX_IN_VID_FORMAT);
+		}
+	} else
+		seq_puts(m, " Disabled");
+
+	switch (type) {
+	case STI_TVOUT_CONNECTOR_HDMI:
+		TVOUT_DBG_DUMP(TVO_VIP_HDMI);
+		tvout_dbg_vip(m, readl(tvout->regs + TVO_VIP_HDMI));
+		TVOUT_DBG_DUMP(TVO_HDMI_FORCE_COLOR_0);
+		TVOUT_DBG_DUMP(TVO_HDMI_FORCE_COLOR_1);
+		TVOUT_DBG_DUMP(TVO_HDMI_CLIP_VALUE_B_CB);
+		TVOUT_DBG_DUMP(TVO_HDMI_CLIP_VALUE_Y_G);
+		TVOUT_DBG_DUMP(TVO_HDMI_CLIP_VALUE_R_CR);
+		TVOUT_DBG_DUMP(TVO_HDMI_SYNC_SEL);
+		TVOUT_DBG_DUMP(TVO_HDMI_DFV_OBS);
+		break;
+	case STI_TVOUT_CONNECTOR_HDA:
+		TVOUT_DBG_DUMP(TVO_VIP_HDF);
+		tvout_dbg_vip(m, readl(tvout->regs + TVO_VIP_HDF));
+		TVOUT_DBG_DUMP(TVO_HD_SYNC_SEL);
+		TVOUT_DBG_DUMP(TVO_HD_DAC_CFG_OFF);
+		tvout_dbg_hd_dac_cfg(m,
+				     readl(tvout->regs + TVO_HD_DAC_CFG_OFF));
+		break;
+	default:
+		goto out;
+	}
+
+	if (connector->dbg_show)
+		connector->dbg_show(connector, m);
+out:
+	seq_puts(m, "\n\n");
+	mutex_unlock(&dev->struct_mutex);
+	return 0;
+}
+
+int sti_tvout_hdmi_dbg_show(struct seq_file *m, void *arg)
+{
+	return tvout_dbg_show(m, STI_TVOUT_CONNECTOR_HDMI);
+}
+
+int sti_tvout_hda_dbg_show(struct seq_file *m, void *arg)
+{
+	return tvout_dbg_show(m, STI_TVOUT_CONNECTOR_HDA);
+}
+
 static int sti_tvout_bind(struct device *dev, struct device *master, void *data)
 {
 	return 0;
Signature · 1 line
1.9.1
#21 lore raw

PATCH v3 15/16 drm: sti: add debug to mixer

In reply to Benjamin Gaignard

Make mixer driver more verbose

---
 drivers/gpu/drm/sti/sti_mixer.c | 164 ++++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/sti/sti_mixer.h |   2 +
 2 files changed, 166 insertions(+)
drivers/gpu/drm/sti/sti_mixer.c +164 -0
index b6c8214..73d5405 100644
@@ -6,7 +6,9 @@
  * License terms:  GNU General Public License (GPL), version 2
  */
 
+#include "sti_drm_drv.h"
 #include "sti_mixer.h"
+#include "sti_compositor.h"
 #include "sti_vtg_utils.h"
 
 /* Identity: G=Y , B=Cb , R=Cr */
@@ -139,6 +141,8 @@ int sti_mixer_set_layer_depth(struct sti_mixer *mixer, struct sti_layer *layer)
 	mask = GAM_DEPTH_MASK_ID << (3 * depth);
 	layer_id = layer_id << (3 * depth);
 
+	DRM_DEBUG_DRIVER("%s %s depth=%d\n", sti_mixer_to_str(mixer),
+			 sti_layer_to_str(layer), depth);
 	dev_dbg(mixer->dev, "GAM_MIXER_CRB val 0x%x mask 0x%x\n",
 		layer_id, mask);
 	sti_mixer_reg_writemask(mixer, GAM_MIXER_CRB, layer_id, mask);
@@ -197,6 +201,9 @@ int sti_mixer_set_layer_status(struct sti_mixer *mixer,
 {
 	u32 mask, val;
 
+	DRM_DEBUG_DRIVER("%s %s %s\n", status ? "enable" : "disable",
+			 sti_mixer_to_str(mixer), sti_layer_to_str(layer));
+
 	mask = sti_mixer_get_layer_mask(layer);
 	if (!mask) {
 		DRM_ERROR("Can not find layer mask\n");
@@ -239,3 +246,160 @@ struct sti_mixer *sti_mixer_create(struct device *dev, int id,
 
 	return mixer;
 }
+
+static void sti_mixer_dbg_ctl(struct seq_file *m, int val)
+{
+	int count = 0;
+
+	seq_puts(m, "\tEnabled: ");
+	if (val & 1) {
+		seq_puts(m, "BKG ");
+		count++;
+	}
+	val = val >> 1;
+
+	if (val & 1) {
+		seq_puts(m, "VID0 ");
+		count++;
+	}
+	val = val >> 1;
+	if (val & 1) {
+		seq_puts(m, "VID1 ");
+		count++;
+	}
+	val = val >> 1;
+	if (val & 1) {
+		seq_puts(m, "GDP0 ");
+		count++;
+	}
+	val = val >> 1;
+	if (val & 1) {
+		seq_puts(m, "GDP1 ");
+		count++;
+	}
+	val = val >> 1;
+	if (val & 1) {
+		seq_puts(m, "GDP2 ");
+		count++;
+	}
+	val = val >> 1;
+	if (val & 1) {
+		seq_puts(m, "GDP3 ");
+		count++;
+	}
+	if (!count)
+		seq_puts(m, "Nothing");
+}
+
+static void sti_mixer_dbg_crb(struct seq_file *m, int val)
+{
+	int i;
+
+	seq_puts(m, "\tDepth: ");
+	for (i = 0; i < GAM_MIXER_NB_DEPTH_LEVEL; i++) {
+		switch (val & GAM_DEPTH_MASK_ID) {
+		case GAM_DEPTH_VID0_ID:
+			seq_puts(m, "VID0");
+			break;
+		case GAM_DEPTH_VID1_ID:
+			seq_puts(m, "VID1");
+			break;
+		case GAM_DEPTH_GDP0_ID:
+			seq_puts(m, "GDP0");
+			break;
+		case GAM_DEPTH_GDP1_ID:
+			seq_puts(m, "GDP1");
+			break;
+		case GAM_DEPTH_GDP2_ID:
+			seq_puts(m, "GDP2");
+			break;
+		case GAM_DEPTH_GDP3_ID:
+			seq_puts(m, "GDP3");
+			break;
+		default:
+			seq_puts(m, "---");
+		}
+		if (i < GAM_MIXER_NB_DEPTH_LEVEL - 1)
+			seq_puts(m, " < ");
+		val = val >> 3;
+	}
+}
+
+static void sti_mixer_dbg_mxn(struct seq_file *m, void *addr)
+{
+	int i;
+
+	for (i = 1; i < 8; i++)
+		seq_printf(m, "-0x%08X", (int)readl(addr + i * 4));
+}
+
+#define MIXER_DBG_DUMP(reg) seq_printf(m, "\n " #reg "\t 0x%08X", \
+		sti_mixer_reg_read(mixer, reg))
+
+int sti_mixer_dbg_show(struct seq_file *m, void *arg)
+{
+	struct drm_info_node *node = (struct drm_info_node *)m->private;
+	struct drm_device *dev = node->minor->dev;
+	struct sti_drm_private *dev_priv = dev->dev_private;
+	struct sti_compositor *compo = dev_priv->compo;
+	int i, ret;
+
+	ret = mutex_lock_interruptible(&dev->struct_mutex);
+	if (ret)
+		return ret;
+
+	if (compo == NULL) {
+		seq_puts(m, "No compositor available\n");
+		goto out;
+	}
+
+	for (i = 0; i < compo->nb_mixers; i++) {
+		struct drm_crtc *crtc;
+		struct drm_framebuffer *fb;
+		struct sti_mixer *mixer = compo->mixer[i];
+
+		seq_printf(m, "\n%s", sti_mixer_to_str(mixer));
+		MIXER_DBG_DUMP(GAM_MIXER_CTL);
+		sti_mixer_dbg_ctl(m,
+				  sti_mixer_reg_read(mixer,
+						     GAM_MIXER_CTL));
+		MIXER_DBG_DUMP(GAM_MIXER_BKC);
+		MIXER_DBG_DUMP(GAM_MIXER_BCO);
+		MIXER_DBG_DUMP(GAM_MIXER_BCS);
+		MIXER_DBG_DUMP(GAM_MIXER_AVO);
+		MIXER_DBG_DUMP(GAM_MIXER_AVS);
+		MIXER_DBG_DUMP(GAM_MIXER_CRB);
+		sti_mixer_dbg_crb(m,
+				  sti_mixer_reg_read(mixer,
+						     GAM_MIXER_CRB));
+		MIXER_DBG_DUMP(GAM_MIXER_ACT);
+		MIXER_DBG_DUMP(GAM_MIXER_MBP);
+		MIXER_DBG_DUMP(GAM_MIXER_MX0);
+		sti_mixer_dbg_mxn(m, mixer->regs + GAM_MIXER_MX0);
+		seq_puts(m, "\n");
+
+		crtc = &mixer->drm_crtc;
+		if (!crtc) {
+			seq_puts(m, " Not connected to any DRM CRTC\n");
+			continue;
+		}
+		seq_printf(m, " Connected to DRM CRTC #%d which is:\n",
+			   crtc->base.id);
+		seq_puts(m, crtc->enabled ? "\tEnabled\n" : "\tDisabled\n");
+		seq_printf(m, "\tMode: %s %dHz\n",
+			   crtc->mode.name, crtc->mode.vrefresh);
+		seq_printf(m, "\tat %d,%d\n", crtc->x, crtc->y);
+
+		fb = crtc->fb;
+		if (!fb) {
+			seq_puts(m, "\tNot connected to any DRM FB\n");
+			continue;
+		}
+		seq_printf(m, "\tConnected to DRM FB #%d, %dx%d, %.4s\n",
+			   fb->base.id,
+			   fb->width, fb->height, (char *)&fb->pixel_format);
+	}
+out:
+	mutex_unlock(&dev->struct_mutex);
+	return 0;
+}
drivers/gpu/drm/sti/sti_mixer.h +2 -0
index a05e21f..abdd1ad 100644
@@ -43,6 +43,8 @@ int sti_mixer_active_video_area(struct sti_mixer *mixer,
 
 void sti_mixer_set_background_status(struct sti_mixer *mixer, bool enable);
 
+int sti_mixer_dbg_show(struct seq_file *m, void *arg);
+
 /* depth in Cross-bar control = z order */
 #define GAM_MIXER_NB_DEPTH_LEVEL	7
 
Signature · 1 line
1.9.1
#22 lore raw

PATCH v3 16/16 drm: sti: Add DRM driver itself

In reply to Benjamin Gaignard

Make the link between all the hardware drivers and DRM/KMS interface. Create the driver itself and make it register all the sub-components. Use GEM CMA helpers for buffer allocation.

---
 drivers/gpu/drm/sti/Kconfig             |   8 +
 drivers/gpu/drm/sti/Makefile            |   7 +-
 drivers/gpu/drm/sti/sti_compositor.c    |  48 ++++
 drivers/gpu/drm/sti/sti_drm_connector.c | 195 ++++++++++++++
 drivers/gpu/drm/sti/sti_drm_connector.h |  16 ++
 drivers/gpu/drm/sti/sti_drm_crtc.c      | 440 ++++++++++++++++++++++++++++++++
 drivers/gpu/drm/sti/sti_drm_crtc.h      |  21 ++
 drivers/gpu/drm/sti/sti_drm_drv.c       | 338 ++++++++++++++++++++++++
 drivers/gpu/drm/sti/sti_drm_encoder.c   | 201 +++++++++++++++
 drivers/gpu/drm/sti/sti_drm_encoder.h   |  16 ++
 drivers/gpu/drm/sti/sti_drm_plane.c     | 195 ++++++++++++++
 drivers/gpu/drm/sti/sti_drm_plane.h     |  16 ++
 drivers/gpu/drm/sti/sti_tvout.c         |  21 ++
 13 files changed, 1521 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/sti/sti_drm_connector.c
 create mode 100644 drivers/gpu/drm/sti/sti_drm_connector.h
 create mode 100644 drivers/gpu/drm/sti/sti_drm_crtc.c
 create mode 100644 drivers/gpu/drm/sti/sti_drm_crtc.h
 create mode 100644 drivers/gpu/drm/sti/sti_drm_drv.c
 create mode 100644 drivers/gpu/drm/sti/sti_drm_encoder.c
 create mode 100644 drivers/gpu/drm/sti/sti_drm_encoder.h
 create mode 100644 drivers/gpu/drm/sti/sti_drm_plane.c
 create mode 100644 drivers/gpu/drm/sti/sti_drm_plane.h
drivers/gpu/drm/sti/Kconfig +8 -0
index 76c2e4f..2c80bcf 100644
@@ -1,10 +1,18 @@
 config DRM_STI
 	bool "DRM Support for STMicroelectronics SoC stiH41x Series"
 	depends on DRM && (SOC_STIH415 || SOC_STIH416 || ARCH_MULTIPLATFORM)
+	select DRM_KMS_HELPER
+	select DRM_GEM_CMA_HELPER
 	select DRM_KMS_CMA_HELPER
 	help
 	  Choose this option to enable DRM on STM stiH41x chipset
 
+config DRM_STI_FBDEV
+	bool "DRM frame buffer device for STMicroelectronics SoC stiH41x Serie"
+	depends on DRM_STI
+	help
+	  Choose this option to enable FBDEV on top of DRM for STM stiH41x chipset
+
 config VTAC_STI
 	bool "Video Trafic Advance Communication Rx and Tx for STMicroelectronics SoC stiH41x Series"
 	depends on DRM_STI
drivers/gpu/drm/sti/Makefile +6 -1
index 3b804d4..8eee160 100644
@@ -1,6 +1,11 @@
 ccflags-y := -Iinclude/drm
 
-stidrm-y := sti_tvout.o \
+stidrm-y := sti_drm_drv.o \
+			sti_drm_crtc.o \
+			sti_drm_plane.o \
+			sti_drm_connector.o \
+			sti_drm_encoder.o \
+			sti_tvout.o \
 			sti_hdmi.o \
 			sti_hdmi_tx3g0c55phy.o \
 			sti_hdmi_tx3g4c28phy.o \
drivers/gpu/drm/sti/sti_compositor.c +48 -0

67 lines not on this page · raw message

drivers/gpu/drm/sti/sti_drm_connector.c new file +195 -0

195 lines not on this page · raw message

drivers/gpu/drm/sti/sti_drm_connector.h new file +16 -0
new file mode 100644
index 0000000..068c674
@@ -0,0 +1,16 @@
+/*
+ * Copyright (C) STMicroelectronics SA 2013
+ * Author: Benjamin Gaignard <[email protected]> for STMicroelectronics.
+ * License terms:  GNU General Public License (GPL), version 2
+ */
+
+#ifndef _STI_DRM_CONNECTOR_H_
+#define _STI_DRM_CONNECTOR_H_
+
+#include "sti_tvout.h"
+
+struct drm_connector *sti_drm_connector_create(struct drm_device *dev,
+		struct sti_tvout *tvout, struct drm_encoder *encoder,
+		enum sti_tvout_connector_type type);
+
+#endif
drivers/gpu/drm/sti/sti_drm_crtc.c new file +440 -0

440 lines not on this page · raw message

drivers/gpu/drm/sti/sti_drm_crtc.h new file +21 -0
new file mode 100644
index 0000000..9d31e41
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) STMicroelectronics SA 2013
+ * Author: Benjamin Gaignard <[email protected]> for STMicroelectronics.
+ * License terms:  GNU General Public License (GPL), version 2
+ */
+
+#ifndef _STI_DRM_CRTC_H_
+#define _STI_DRM_CRTC_H_
+
+#include <drm/drmP.h>
+
+#include "sti_mixer.h"
+
+int sti_drm_crtc_init(struct drm_device *drm_dev, struct sti_mixer *mixer);
+int sti_drm_crtc_enable_vblank(struct drm_device *dev, int crtc);
+void sti_drm_crtc_disable_vblank(struct drm_device *dev, int crtc);
+int sti_drm_crtc_vblank_cb(struct notifier_block *nb,
+		unsigned long event, void *data);
+bool sti_drm_crtc_is_main(struct drm_crtc *drm_crtc);
+
+#endif
drivers/gpu/drm/sti/sti_drm_drv.c new file +338 -0

338 lines not on this page · raw message

drivers/gpu/drm/sti/sti_drm_encoder.c new file +201 -0

201 lines not on this page · raw message

drivers/gpu/drm/sti/sti_drm_encoder.h new file +16 -0
new file mode 100644
index 0000000..35d9945
@@ -0,0 +1,16 @@
+/*
+ * Copyright (C) STMicroelectronics SA 2013
+ * Author: Benjamin Gaignard <[email protected]> for STMicroelectronics.
+ * License terms:  GNU General Public License (GPL), version 2
+ */
+
+#ifndef _STI_DRM_ENCODER_H_
+#define _STI_DRM_ENCODER_H_
+
+#include "sti_tvout.h"
+
+struct drm_encoder *sti_drm_encoder_create(struct drm_device *dev,
+		struct sti_tvout *tvout, unsigned int possible_crtcs,
+		enum sti_tvout_connector_type type);
+
+#endif
drivers/gpu/drm/sti/sti_drm_plane.c new file +195 -0

195 lines not on this page · raw message

drivers/gpu/drm/sti/sti_drm_plane.h new file +16 -0
new file mode 100644
index 0000000..d182066
@@ -0,0 +1,16 @@
+/*
+ * Copyright (C) STMicroelectronics SA 2013
+ * Author: Benjamin Gaignard <[email protected]> for STMicroelectronics.
+ * License terms:  GNU General Public License (GPL), version 2
+ */
+
+#ifndef _STI_DRM_PLANE_H_
+#define _STI_DRM_PLANE_H_
+
+#include <drm/drmP.h>
+#include "sti_layer.h"
+
+struct drm_plane *sti_drm_plane_init(struct drm_device *dev,
+		struct sti_layer *layer, unsigned int possible_crtcs);
+
+#endif
drivers/gpu/drm/sti/sti_tvout.c +21 -0
index fb199c4..c25a104 100644
@@ -19,6 +19,8 @@
 #include "sti_hdmi.h"
 #include "sti_hda.h"
 #include "sti_drm_drv.h"
+#include "sti_drm_encoder.h"
+#include "sti_drm_connector.h"
 
 /* glue regsiters */
 #define TVO_CSC_MAIN_M0                  0x000
@@ -788,6 +790,25 @@ int sti_tvout_hda_dbg_show(struct seq_file *m, void *arg)
 
 static int sti_tvout_bind(struct device *dev, struct device *master, void *data)
 {
+	struct sti_tvout *tvout = dev_get_drvdata(dev);
+	struct drm_device *drm_dev = data;
+	struct drm_encoder *encoder;
+	int i;
+	struct sti_drm_private *dev_priv = drm_dev->dev_private;
+
+	dev_priv->tvout = tvout;
+
+	tvout->drm_dev = drm_dev;
+
+	/* Register all encoder/connector couples supported by tvout */
+	for (i = 0; i < STI_TVOUT_CONNECTOR_MAX; i++) {
+		if (tvout->connector_create[i] != NULL) {
+			encoder = sti_drm_encoder_create(drm_dev, tvout,
+							 1 << 0, i);
+			sti_drm_connector_create(drm_dev, tvout, encoder, i);
+		}
+	}
+
 	return 0;
 }
 
Signature · 1 line
1.9.1