Skip to contentSkip to conversation

drm/tiny: Add driver for Solomon SSD1307 OLED displays

PATCH Superseded Javier Martinez Canillas 8 participants 34 messages Feb 4, 2022 – Feb 10, 2022

Subsystems (6)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Javier Martinez Canillas

author maintainer
#0 lore raw

v2 cover drm/tiny: Add driver for Solomon SSD1307 OLED displays

This patch series adds a DRM driver for the Solomon OLED SSD1305, SSD1306, SSD1307 and SSD1309 displays. It is a port of the ssd1307fb fbdev driver.

Using the DRM fb emulation, all the tests from Geert Uytterhoeven's fbtest
(https://git.kernel.org/pub/scm/linux/kernel/git/geert/fbtest.git) passes:

    ./fbtest -f /dev/fb1
    Using drawops cfb32 (32 bpp packed pixels)
    Available visuals:
      Monochrome
      Grayscale 256
      Truecolor 8:8:8:0
    Using visops truecolor
    Running all tests
    test001: PASSED
    test002: PASSED
    test003: PASSED
    test004: PASSED
    test005: PASSED
    test006: PASSED
    test008: PASSED
    Screen size too small for this test
    test010: PASSED
    Benchmarking... 10x10 squares: 414.41 Mpixels/s
    Benchmarking... 20x20 squares: 858.31 Mpixels/s
    Benchmarking... 50x50 squares: 1586.33 Mpixels/s
    test012: PASSED
    Benchmarking... R5 circles: 234.68 Mpixels/s
    Benchmarking... R10 circles: 498.24 Mpixels/s
    Benchmarking... R25 circles: 942.34 Mpixels/s
    test013: PASSED

This is a v2 that addresses all the issues pointed in v1, thanks a lot to everyone that gave me feedback and reviews. I tried to not miss any comment, but there were a lot so forgive me if something is not there.

Patch #1 adds two new helpers, drm_fb_gray8_to_mono_reversed() to convert from grayscale to monochrome and a drm_fb_xrgb8888_to_mono_reversed() to convert from XR24 to monochrome. The latter internally use thes former.

Patch #2 adds the driver. The name ssd130x was used instead of ssd1307fb to denote that this driver is not only for SSD1307, but also for other displays from the same chip family.

Patch #3 just adds a MAINTAINERS entry for the DRM driver and patch #4 adds myself as a co-maintainer of the existing Device Tree binding for ssd1307fb, since the same is shared between the fbdev and DRM drivers.

Best regards,
Javier

Changes in v2:
- Drop patch that was adding a DRM_MODE_CONNECTOR_I2C type.
- Invert order of backlight {en,dis}able and display {on,off} (Sam Ravnborg)
- Don't clear the screen and turn on display on probe (Sam Ravnborg)
- Use backlight_get_brightness() macro to get BL brightness (Sam Ravnborg)
- Use dev managed version of devm_backlight_device_register() (Sam Ravnborg)
- Use dev_name(dev) for backlight name instead of an array (Sam Ravnborg)
- Drop the .get_brightness callback since isn't needed (Sam Ravnborg)
- Add myself as co-maintainer of the ssd1370fb DT binding (Sam Ravnborg)
- Add Sam Ravnborg's acked-by tag to patch 3/4.
- Rename driver to ssd130x since supports a display family (Thomas Zimmermann)
- Drop the TINY prefix from the Kconfig symbol (Thomas Zimmermann)
- Sort the Kconfig symbol dependencies alphabetically (Thomas Zimmermann)
- Rename struct ssd130x_array to struct ssd130x_i2c_msg (Thomas Zimmermann)
- Rename struct ssd130x_i2c_msg .type member to .cmd (Thomas Zimmermann)
- Use sizeof(*foo) instead of sizeof(struct foo) (Thomas Zimmermann)
- Use struct_size() macro to calculate sizeof(*foo) + len (Thomas Zimmermann)
- Use kcalloc() instead of kmalloc_array() + memset() (Thomas Zimmermann)
- Use shadow plane helpers virtual screen support (Thomas Zimmermann)
- Remove unused goto label in ssd1307_fb_blit_rect() (Thomas Zimmermann)
- Use drm_set_preferred_mode() inset of manually set (Thomas Zimmermann)
- Use shadow plane helpers virtual screen support (Thomas Zimmermann)
- Remove unused goto label in ssd1307_fb_blit_rect() (Thomas Zimmermann)
- Use drm_set_preferred_mode() inset of manually set (Thomas Zimmermann)
- Reorganize code in probe to make it more legible (Thomas Zimmermann)
- ssd130x_write_cmd() uses varargs to simplify I2C code (Thomas Zimmermann)
- Move regulator/pwm init logic to display pipe enable callback.
- Also add a drm_fb_xrgb8888_to_mono_reversed() helper (Thomas Zimmermann)
- Add a drm_fb_gray8_to_mono_reversed_line() helper (Thomas Zimmermann)

Javier Martinez Canillas (4):
drm/format-helper: Add drm_fb_{xrgb8888,gray8}_to_mono_reversed() drm/tiny: Add driver for Solomon SSD130X OLED displays
MAINTAINERS: Add entry for Solomon SSD130X OLED displays DRM driver
dt-bindings: display: ssd1307fb: Add myself as binding co-maintainer

 .../bindings/display/solomon,ssd1307fb.yaml   |   1 +
 MAINTAINERS                                   |   7 +
 drivers/gpu/drm/drm_format_helper.c           |  80 ++
 drivers/gpu/drm/tiny/Kconfig                  |  12 +
 drivers/gpu/drm/tiny/Makefile                 |   1 +
 drivers/gpu/drm/tiny/ssd130x.c                | 971 ++++++++++++++++++
 include/drm/drm_format_helper.h               |   7 +
 7 files changed, 1079 insertions(+)
 create mode 100644 drivers/gpu/drm/tiny/ssd130x.c
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH v2 1/4 drm/format-helper: Add drm_fb_{xrgb8888,gray8}_to_mono_reversed()

Add support to convert XR24 and 8-bit grayscale to reversed monochrome for drivers that control monochromatic panels, that only have 1 bit per pixel.

The drm_fb_gray8_to_mono_reversed() helper was based on the function that does the same in the drivers/gpu/drm/tiny/repaper.c driver.

---

(no changes since v1)

 drivers/gpu/drm/drm_format_helper.c | 80 +++++++++++++++++++++++++++++
 include/drm/drm_format_helper.h     |  7 +++
 2 files changed, 87 insertions(+)
drivers/gpu/drm/drm_format_helper.c +80 -0
index 0f28dd2bdd72..cdce4b7c25d9 100644
@@ -584,3 +584,83 @@ int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for
 	return -EINVAL;
 }
 EXPORT_SYMBOL(drm_fb_blit_toio);
+
+static void drm_fb_gray8_to_mono_reversed_line(u8 *dst, const u8 *src, size_t pixels)
+{
+	unsigned int xb, i;
+
+	for (xb = 0; xb < pixels / 8; xb++) {
+		u8 byte = 0x00;
+
+		for (i = 0; i < 8; i++) {
+			int x = xb * 8 + i;
+
+			byte >>= 1;
+			if (src[x] >> 7)
+				byte |= BIT(7);
+		}
+		*dst++ = byte;
+	}
+}
+
+/**
+ * drm_fb_gray8_to_mono_reversed - Convert grayscale to reversed monochrome
+ * @dst: reversed monochrome destination buffer
+ * @dst_pitch: Number of bytes between two consecutive scanlines within dst
+ * @src: 8-bit grayscale source buffer
+ * @clip: Clip rectangle area to copy
+ *
+ * DRM doesn't have native monochrome or grayscale support.
+ * Such drivers can announce the commonly supported XR24 format to userspace
+ * and use drm_fb_xrgb8888_to_gray8() to convert to grayscale and then this
+ * helper function to convert to the native format.
+ */
+void drm_fb_gray8_to_mono_reversed(void *dst, unsigned int dst_pitch, const void *src,
+				   const struct drm_rect *clip)
+{
+
+	size_t height = drm_rect_height(clip);
+	size_t width = drm_rect_width(clip);
+	unsigned int y;
+	const u8 *gray8 = src;
+	u8 *mono = dst;
+
+	if (!dst_pitch)
+		dst_pitch = width;
+
+	for (y = 0; y < height; y++) {
+		drm_fb_gray8_to_mono_reversed_line(mono, gray8, dst_pitch);
+		mono += (dst_pitch / 8);
+		gray8 += dst_pitch;
+	}
+}
+
+/**
+ * drm_fb_xrgb8888_to_mono_reversed - Convert XRGB8888 to reversed monochrome
+ * @dst: reversed monochrome destination buffer
+ * @dst_pitch: Number of bytes between two consecutive scanlines within dst
+ * @src: XRGB8888 source buffer
+ * @fb: DRM framebuffer
+ * @clip: Clip rectangle area to copy
+ *
+ * DRM doesn't have native monochrome support.
+ * Such drivers can announce the commonly supported XR24 format to userspace
+ * and use this function to convert to the native format.
+ *
+ * This function uses drm_fb_xrgb8888_to_gray8() to convert to grayscale and
+ * then the result is converted from grayscale to reversed monohrome.
+ */
+void drm_fb_xrgb8888_to_mono_reversed(void *dst, unsigned int dst_pitch, const void *src,
+				      const struct drm_framebuffer *fb,
+				      const struct drm_rect *clip)
+{
+	if (WARN_ON(fb->format->format != DRM_FORMAT_XRGB8888))
+		return;
+
+	if (!dst_pitch)
+		dst_pitch = drm_rect_width(clip);
+
+	drm_fb_xrgb8888_to_gray8(dst, dst_pitch, src, fb, clip);
+	drm_fb_gray8_to_mono_reversed(dst, dst_pitch, dst, fb, clip);
+}
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_mono_reversed);
include/drm/drm_format_helper.h +7 -0
index b30ed5de0a33..85e551a5cbe6 100644
@@ -43,4 +43,11 @@ int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for
 		     const void *vmap, const struct drm_framebuffer *fb,
 		     const struct drm_rect *rect);
 
+void drm_fb_gray8_to_mono_reversed(void *dst, unsigned int dst_pitch, const void *src,
+				   const struct drm_rect *clip);
+
+void drm_fb_xrgb8888_to_mono_reversed(void *dst, unsigned int dst_pitch, const void *src,
+				      const struct drm_framebuffer *fb,
+				      const struct drm_rect *clip);
+
 #endif /* __LINUX_DRM_FORMAT_HELPER_H */
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v2 1/4] drm/format-helper: Add drm_fb_{xrgb8888,gray8}_to_mono_reversed()

Hi

Am 04.02.22 um 14:43 schrieb Javier Martinez Canillas:

Quoted 20 lines

Add support to convert XR24 and 8-bit grayscale to reversed monochrome for drivers that control monochromatic panels, that only have 1 bit per pixel.

The drm_fb_gray8_to_mono_reversed() helper was based on the function that does the same in the drivers/gpu/drm/tiny/repaper.c driver.

---

(no changes since v1)

  drivers/gpu/drm/drm_format_helper.c | 80 +++++++++++++++++++++++++++++
  include/drm/drm_format_helper.h     |  7 +++
  2 files changed, 87 insertions(+)
drivers/gpu/drm/drm_format_helper.c +0 -0
index 0f28dd2bdd72..cdce4b7c25d9 100644

drivers/gpu/drm/drm_format_helper.c int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for · line 592

Quoted 9 lines
drivers/gpu/drm/drm_format_helper.c +6 -0
@@ -584,3 +584,83 @@ int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for
  	return -EINVAL;
  }
  EXPORT_SYMBOL(drm_fb_blit_toio);
+
+static void drm_fb_gray8_to_mono_reversed_line(u8 *dst, const u8 *src, size_t pixels)
+{
+	unsigned int xb, i;
+
+	for (xb = 0; xb < pixels / 8; xb++) {

In practice, all mode widths are multiples of 8 because VGA mandated it. So it's ok-ish to assume this here. You should probably at least print a warning somewhere if (pixels % 8 != 0)

Quoted 17 lines
drivers/gpu/drm/drm_format_helper.c +17 -0
+		u8 byte = 0x00;
+
+		for (i = 0; i < 8; i++) {
+			int x = xb * 8 + i;
+
+			byte >>= 1;
+			if (src[x] >> 7)
+				byte |= BIT(7);
+		}
+		*dst++ = byte;
+	}
+}
+
+/**
+ * drm_fb_gray8_to_mono_reversed - Convert grayscale to reversed monochrome
+ * @dst: reversed monochrome destination buffer
+ * @dst_pitch: Number of bytes between two consecutive scanlines within dst

drivers/gpu/drm/drm_format_helper.c int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for · line 619

Quoted 10 lines
drivers/gpu/drm/drm_format_helper.c +10 -0
+ * @src: 8-bit grayscale source buffer
+ * @clip: Clip rectangle area to copy
+ *
+ * DRM doesn't have native monochrome or grayscale support.
+ * Such drivers can announce the commonly supported XR24 format to userspace
+ * and use drm_fb_xrgb8888_to_gray8() to convert to grayscale and then this
+ * helper function to convert to the native format.
+ */
+void drm_fb_gray8_to_mono_reversed(void *dst, unsigned int dst_pitch, const void *src,
+				   const struct drm_rect *clip)

There's a bug here. You want to pass in a drm_framebuffer as fourth argument.

drivers/gpu/drm/drm_format_helper.c int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for · line 629

Quoted 10 lines
drivers/gpu/drm/drm_format_helper.c +10 -0
+{
+
+	size_t height = drm_rect_height(clip);
+	size_t width = drm_rect_width(clip);
+	unsigned int y;
+	const u8 *gray8 = src;
+	u8 *mono = dst;
+
+	if (!dst_pitch)
+		dst_pitch = width;

The dst_pitch is given in bytes. You have to device by 8. Here would be a good place to warn if (width % 8 != 0).

drivers/gpu/drm/drm_format_helper.c int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for · line 633

Quoted 4 lines
drivers/gpu/drm/drm_format_helper.c +4 -0
+
+	for (y = 0; y < height; y++) {
+		drm_fb_gray8_to_mono_reversed_line(mono, gray8, dst_pitch);
+		mono += (dst_pitch / 8);

The dst_pitch is already given in bytes.

drivers/gpu/drm/drm_format_helper.c int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for · line 634

Quoted 1 line
drivers/gpu/drm/drm_format_helper.c +1 -0
+		gray8 += dst_pitch;

'gray8 += fb->pitches[0]' would be correct.

Quoted 20 lines
drivers/gpu/drm/drm_format_helper.c +20 -0
+	}
+}
+
+/**
+ * drm_fb_xrgb8888_to_mono_reversed - Convert XRGB8888 to reversed monochrome
+ * @dst: reversed monochrome destination buffer
+ * @dst_pitch: Number of bytes between two consecutive scanlines within dst
+ * @src: XRGB8888 source buffer
+ * @fb: DRM framebuffer
+ * @clip: Clip rectangle area to copy
+ *
+ * DRM doesn't have native monochrome support.
+ * Such drivers can announce the commonly supported XR24 format to userspace
+ * and use this function to convert to the native format.
+ *
+ * This function uses drm_fb_xrgb8888_to_gray8() to convert to grayscale and
+ * then the result is converted from grayscale to reversed monohrome.
+ */
+void drm_fb_xrgb8888_to_mono_reversed(void *dst, unsigned int dst_pitch, const void *src,
+				      const struct drm_framebuffer *fb,

drivers/gpu/drm/drm_format_helper.c int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for · line 664

Quoted 10 lines
drivers/gpu/drm/drm_format_helper.c +10 -0
+				      const struct drm_rect *clip)
+{
+	if (WARN_ON(fb->format->format != DRM_FORMAT_XRGB8888))
+		return;
+
+	if (!dst_pitch)
+		dst_pitch = drm_rect_width(clip);
+
+	drm_fb_xrgb8888_to_gray8(dst, dst_pitch, src, fb, clip);
+	drm_fb_gray8_to_mono_reversed(dst, dst_pitch, dst, fb, clip);

Converting from dst into dst can give incorrect results. At some point we probably want to add restrict qualifiers to these pointers, to help the compiler with optimizing.

A better approach here is to pull the per-line conversion from drm_fb_xrgb8888_to_gray8() into a separate helper and implement a line-by-line conversion here. something like this:

drm_fb_xrgb8888_to_mono_reversed()

  {
    char *tmp = kmalloc(size of a single line of gray8)

    for (heigth) {
       drm_fb_xrgb8888_to_gray8_line(tmp, ..., src, ...);
       drm_fb_gray8_to_mono_reversed(dst, ..., tmp, ...);

       src += fb->pitches[0]
       dst += dst_pitch;
    }

    kfree(tmp);

}

Best regards
Thomas

Quoted 18 lines
drivers/gpu/drm/drm_format_helper.c +2 -0
+}
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_mono_reversed);
include/drm/drm_format_helper.h +7 -0
index b30ed5de0a33..85e551a5cbe6 100644
@@ -43,4 +43,11 @@ int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for
  		     const void *vmap, const struct drm_framebuffer *fb,
  		     const struct drm_rect *rect);
 
+void drm_fb_gray8_to_mono_reversed(void *dst, unsigned int dst_pitch, const void *src,
+				   const struct drm_rect *clip);
+
+void drm_fb_xrgb8888_to_mono_reversed(void *dst, unsigned int dst_pitch, const void *src,
+				      const struct drm_framebuffer *fb,
+				      const struct drm_rect *clip);
+
  #endif /* __LINUX_DRM_FORMAT_HELPER_H */
Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev
#3 lore raw

Re: [PATCH v2 1/4] drm/format-helper: Add drm_fb_{xrgb8888,gray8}_to_mono_reversed()

Am 04.02.22 um 16:52 schrieb Thomas Zimmermann:
[...]

Quoted 37 lines
Quoted 23 lines

+/**
+ * drm_fb_xrgb8888_to_mono_reversed - Convert XRGB8888 to reversed monochrome
+ * @dst: reversed monochrome destination buffer
+ * @dst_pitch: Number of bytes between two consecutive scanlines within dst
+ * @src: XRGB8888 source buffer
+ * @fb: DRM framebuffer
+ * @clip: Clip rectangle area to copy
+ *
+ * DRM doesn't have native monochrome support.
+ * Such drivers can announce the commonly supported XR24 format to userspace
+ * and use this function to convert to the native format.
+ *
+ * This function uses drm_fb_xrgb8888_to_gray8() to convert to grayscale and
+ * then the result is converted from grayscale to reversed monohrome.
+ */
+void drm_fb_xrgb8888_to_mono_reversed(void *dst, unsigned int dst_pitch, const void *src,
+                      const struct drm_framebuffer *fb,
+                      const struct drm_rect *clip)

drivers/gpu/drm/drm_format_helper.c int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for · line 664

Quoted 9 lines
drivers/gpu/drm/drm_format_helper.c +9 -0
+{
+    if (WARN_ON(fb->format->format != DRM_FORMAT_XRGB8888))
+        return;
+
+    if (!dst_pitch)
+        dst_pitch = drm_rect_width(clip);
+
+    drm_fb_xrgb8888_to_gray8(dst, dst_pitch, src, fb, clip);
+    drm_fb_gray8_to_mono_reversed(dst, dst_pitch, dst, fb, clip);

Converting from dst into dst can give incorrect results. At some point we probably want to add restrict qualifiers to these pointers, to help the compiler with optimizing.

A better approach here is to pull the per-line conversion from drm_fb_xrgb8888_to_gray8() into a separate helper and implement a line-by-line conversion here. something like this:

Quoted 7 lines

  drm_fb_xrgb8888_to_mono_reversed()
  {
    char *tmp = kmalloc(size of a single line of gray8)

    for (heigth) { drm_fb_xrgb8888_to_gray8_line(tmp, ..., src, ...); drm_fb_gray8_to_mono_reversed(dst, ..., tmp, ...);

Here, I meant 'drm_fb_gray8_to_mono_reversed_line()'

Quoted 7 lines

       src += fb->pitches[0]
       dst += dst_pitch;
    }

    kfree(tmp);
  }

To elaborate, this is an example of what I meant by composable. In the future, we can generalize this function and hand-in 2 function pointers the do the conversion with tmp as intermediate buffer. That would work for any combination of formats that have a common intermediate format.

Quoted 25 lines

Best regards
Thomas

Quoted 20 lines
(quoted diff) +2 -0
+}
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_mono_reversed);
include/drm/drm_format_helper.h +0 -0
index b30ed5de0a33..85e551a5cbe6 100644
@@ -43,4 +43,11 @@ int drm_fb_blit_toio(void __iomem *dst, unsigned 

int dst_pitch, uint32_t dst_for
               const void *vmap, const struct drm_framebuffer *fb, const struct drm_rect *rect);
+void drm_fb_gray8_to_mono_reversed(void *dst, unsigned int dst_pitch, const void *src,
+                   const struct drm_rect *clip);

include/drm/drm_format_helper.h +2 -0
+
+void drm_fb_xrgb8888_to_mono_reversed(void *dst, unsigned int 

dst_pitch, const void *src,
+                      const struct drm_framebuffer *fb, +                      const struct drm_rect *clip); +
  #endif /* __LINUX_DRM_FORMAT_HELPER_H */

Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev
author maintainer
#4 lore raw

Re: [PATCH v2 1/4] drm/format-helper: Add drm_fb_{xrgb8888,gray8}_to_mono_reversed()

In reply to Thomas Zimmermann

Hello Thomas,

Thanks a lot for your feedback.

On 2/4/22 16:52, Thomas Zimmermann wrote:

[snip]

Quoted 10 lines

drivers/gpu/drm/drm_format_helper.c int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for · line 592

Quoted 5 lines
drivers/gpu/drm/drm_format_helper.c +5 -0
+static void drm_fb_gray8_to_mono_reversed_line(u8 *dst, const u8 *src, size_t pixels)
+{
+	unsigned int xb, i;
+
+	for (xb = 0; xb < pixels / 8; xb++) {

In practice, all mode widths are multiples of 8 because VGA mandated it. So it's ok-ish to assume this here. You should probably at least print a warning somewhere if (pixels % 8 != 0)

Agreed.

[snip]

Quoted 11 lines

Review

Quoted 7 lines

+ * DRM doesn't have native monochrome or grayscale support.
+ * Such drivers can announce the commonly supported XR24 format to userspace
+ * and use drm_fb_xrgb8888_to_gray8() to convert to grayscale and then this
+ * helper function to convert to the native format.
+ */

(quoted diff) +2 -0
+void drm_fb_gray8_to_mono_reversed(void *dst, unsigned int dst_pitch, const void *src,
+				   const struct drm_rect *clip)

There's a bug here. You want to pass in a drm_framebuffer as fourth argument.

Quoted 14 lines

drivers/gpu/drm/drm_format_helper.c int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for · line 629

Quoted 10 lines
drivers/gpu/drm/drm_format_helper.c +10 -0
+{
+
+	size_t height = drm_rect_height(clip);
+	size_t width = drm_rect_width(clip);
+	unsigned int y;
+	const u8 *gray8 = src;
+	u8 *mono = dst;
+
+	if (!dst_pitch)
+		dst_pitch = width;

The dst_pitch is given in bytes. You have to device by 8. Here would be a good place to warn if (width % 8 != 0).

Ok.

Quoted 7 lines

drivers/gpu/drm/drm_format_helper.c int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for · line 633

Quoted 4 lines
drivers/gpu/drm/drm_format_helper.c +4 -0
+
+	for (y = 0; y < height; y++) {
+		drm_fb_gray8_to_mono_reversed_line(mono, gray8, dst_pitch);
+		mono += (dst_pitch / 8);

The dst_pitch is already given in bytes.

Yes, I know but for reversed mono we want only 1/8 of the width since we are converting from 8 bits per pixel greyscale to 1 bit per pixel mono.

Or am I misunderstanding what you meant ?

Quoted 4 lines

drivers/gpu/drm/drm_format_helper.c int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for · line 634

Quoted 1 line
drivers/gpu/drm/drm_format_helper.c +1 -0
+		gray8 += dst_pitch;

'gray8 += fb->pitches[0]' would be correct.

Ok.

[snip]

Quoted 22 lines

drivers/gpu/drm/drm_format_helper.c int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for · line 664

Quoted 13 lines

+ */

drivers/gpu/drm/drm_format_helper.c +12 -0
+void drm_fb_xrgb8888_to_mono_reversed(void *dst, unsigned int dst_pitch, const void *src,
+				      const struct drm_framebuffer *fb,
+				      const struct drm_rect *clip)
+{
+	if (WARN_ON(fb->format->format != DRM_FORMAT_XRGB8888))
+		return;
+
+	if (!dst_pitch)
+		dst_pitch = drm_rect_width(clip);
+
+	drm_fb_xrgb8888_to_gray8(dst, dst_pitch, src, fb, clip);
+	drm_fb_gray8_to_mono_reversed(dst, dst_pitch, dst, fb, clip);

Converting from dst into dst can give incorrect results. At some point we probably want to add restrict qualifiers to these pointers, to help the compiler with optimizing.

A better approach here is to pull the per-line conversion from drm_fb_xrgb8888_to_gray8() into a separate helper and implement a line-by-line conversion here. something like this:

Quoted 15 lines
   drm_fb_xrgb8888_to_mono_reversed()
   {
     char *tmp = kmalloc(size of a single line of gray8)

     for (heigth) {
        drm_fb_xrgb8888_to_gray8_line(tmp, ..., src, ...);
        drm_fb_gray8_to_mono_reversed(dst, ..., tmp, ...);

        src += fb->pitches[0]
        dst += dst_pitch;
     }

     kfree(tmp);
   }

I see. Yes, that sounds a much better approach. I'll change it in v3.

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Linux Engineering
Red Hat
#5 lore raw

Re: [PATCH v2 1/4] drm/format-helper: Add drm_fb_{xrgb8888,gray8}_to_mono_reversed()

Hi

Am 04.02.22 um 20:31 schrieb Javier Martinez Canillas:

Quoted 19 lines

Hello Thomas,

Thanks a lot for your feedback.

On 2/4/22 16:52, Thomas Zimmermann wrote:

[snip]

Quoted 10 lines

drivers/gpu/drm/drm_format_helper.c int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for · line 592

Quoted 5 lines
drivers/gpu/drm/drm_format_helper.c +5 -0
+static void drm_fb_gray8_to_mono_reversed_line(u8 *dst, const u8 *src, size_t pixels)
+{
+	unsigned int xb, i;
+
+	for (xb = 0; xb < pixels / 8; xb++) {

In practice, all mode widths are multiples of 8 because VGA mandated it. So it's ok-ish to assume this here. You should probably at least print a warning somewhere if (pixels % 8 != 0)

Quoted 1 line

Agreed.

After sending the mail, I realized that some code copies only parts of the source around; specifically for damage handling. None of this is aligned to multiple of 8. So the copying could start and end in the middle of bytes. You'd need a pixel-offset value of some sort.

If you don't want to handle this now, maybe at least detect this case and put a warning somewhere.

Quoted 39 lines

[snip]

Quoted 11 lines

Review

Quoted 7 lines

+ * DRM doesn't have native monochrome or grayscale support.
+ * Such drivers can announce the commonly supported XR24 format to userspace
+ * and use drm_fb_xrgb8888_to_gray8() to convert to grayscale and then this
+ * helper function to convert to the native format.
+ */

(quoted diff) +2 -0
+void drm_fb_gray8_to_mono_reversed(void *dst, unsigned int dst_pitch, const void *src,
+				   const struct drm_rect *clip)

There's a bug here. You want to pass in a drm_framebuffer as fourth argument.

Quoted 14 lines

drivers/gpu/drm/drm_format_helper.c int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for · line 629

Quoted 10 lines
drivers/gpu/drm/drm_format_helper.c +10 -0
+{
+
+	size_t height = drm_rect_height(clip);
+	size_t width = drm_rect_width(clip);
+	unsigned int y;
+	const u8 *gray8 = src;
+	u8 *mono = dst;
+
+	if (!dst_pitch)
+		dst_pitch = width;

The dst_pitch is given in bytes. You have to device by 8. Here would be a good place to warn if (width % 8 != 0).

Ok.

Quoted 7 lines

drivers/gpu/drm/drm_format_helper.c int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for · line 633

Quoted 4 lines
drivers/gpu/drm/drm_format_helper.c +4 -0
+
+	for (y = 0; y < height; y++) {
+		drm_fb_gray8_to_mono_reversed_line(mono, gray8, dst_pitch);
+		mono += (dst_pitch / 8);

The dst_pitch is already given in bytes.

Quoted 4 lines

Yes, I know but for reversed mono we want only 1/8 of the width since we are converting from 8 bits per pixel greyscale to 1 bit per pixel mono.

Or am I misunderstanding what you meant ?

I mean that if there are 80 pixel on a scanline, the value of dst_pitch is already 10. These pitch values are always given in bytes.

Best regards
Thomas

Quoted 51 lines
Quoted 5 lines

drivers/gpu/drm/drm_format_helper.c int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for · line 634

Quoted 2 lines
drivers/gpu/drm/drm_format_helper.c +1 -0
+		gray8 += dst_pitch;

'gray8 += fb->pitches[0]' would be correct.

Ok.

[snip]

Quoted 22 lines

drivers/gpu/drm/drm_format_helper.c int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for · line 664

Quoted 13 lines

+ */

drivers/gpu/drm/drm_format_helper.c +12 -0
+void drm_fb_xrgb8888_to_mono_reversed(void *dst, unsigned int dst_pitch, const void *src,
+				      const struct drm_framebuffer *fb,
+				      const struct drm_rect *clip)
+{
+	if (WARN_ON(fb->format->format != DRM_FORMAT_XRGB8888))
+		return;
+
+	if (!dst_pitch)
+		dst_pitch = drm_rect_width(clip);
+
+	drm_fb_xrgb8888_to_gray8(dst, dst_pitch, src, fb, clip);
+	drm_fb_gray8_to_mono_reversed(dst, dst_pitch, dst, fb, clip);

Converting from dst into dst can give incorrect results. At some point we probably want to add restrict qualifiers to these pointers, to help the compiler with optimizing.

A better approach here is to pull the per-line conversion from drm_fb_xrgb8888_to_gray8() into a separate helper and implement a line-by-line conversion here. something like this:

Quoted 15 lines
    drm_fb_xrgb8888_to_mono_reversed()
    {
      char *tmp = kmalloc(size of a single line of gray8)

      for (heigth) {
         drm_fb_xrgb8888_to_gray8_line(tmp, ..., src, ...);
         drm_fb_gray8_to_mono_reversed(dst, ..., tmp, ...);

         src += fb->pitches[0]
         dst += dst_pitch;
      }

      kfree(tmp);
    }

I see. Yes, that sounds a much better approach. I'll change it in v3.

Best regards,

Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev
#6 lore raw

Re: [PATCH v2 1/4] drm/format-helper: Add drm_fb_{xrgb8888,gray8}_to_mono_reversed()

In reply to Thomas Zimmermann
Quoted 29 lines · Thomas Zimmermann

Hi

Am 04.02.22 um 14:43 schrieb Javier Martinez Canillas:

Quoted 25 lines

Add support to convert XR24 and 8-bit grayscale to reversed monochrome for drivers that control monochromatic panels, that only have 1 bit per pixel.

The drm_fb_gray8_to_mono_reversed() helper was based on the function that does the same in the drivers/gpu/drm/tiny/repaper.c driver.

---

(no changes since v1)

  drivers/gpu/drm/drm_format_helper.c | 80 +++++++++++++++++++++++++++++
  include/drm/drm_format_helper.h     |  7 +++
  2 files changed, 87 insertions(+)
drivers/gpu/drm/drm_format_helper.c +2 -0
index 0f28dd2bdd72..cdce4b7c25d9 100644
@@ -584,3 +584,83 @@ int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for
      return -EINVAL;
  }
  EXPORT_SYMBOL(drm_fb_blit_toio);
+
+static void drm_fb_gray8_to_mono_reversed_line(u8 *dst, const u8 *src, size_t pixels)
Quoted 8 lines

drivers/gpu/drm/drm_format_helper.c int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for · line 592

Quoted 4 lines
drivers/gpu/drm/drm_format_helper.c +4 -0
+{
+     unsigned int xb, i;
+
+     for (xb = 0; xb < pixels / 8; xb++) {

In practice, all mode widths are multiples of 8 because VGA mandated it. So it's ok-ish to assume this here. You should probably at least print a warning somewhere if (pixels % 8 != 0)

Not sure if it's relevant, but 1366x768 was a fairly popular laptop resolution. There's even a dedicated drm_mode_fixup_1366x768 in drm_edid.c. (Would it have killed them to add 2 more horizontal pixels? Apparently.)

Cheers,

-ilia

#7 lore raw

Re: [PATCH v2 1/4] drm/format-helper: Add drm_fb_{xrgb8888, gray8}_to_mono_reversed()

Hi

Am 04.02.22 um 22:02 schrieb Ilia Mirkin:

Quoted 39 lines · Thomas Zimmermann
Quoted 29 lines

Hi

Am 04.02.22 um 14:43 schrieb Javier Martinez Canillas:

Quoted 25 lines

Add support to convert XR24 and 8-bit grayscale to reversed monochrome for drivers that control monochromatic panels, that only have 1 bit per pixel.

The drm_fb_gray8_to_mono_reversed() helper was based on the function that does the same in the drivers/gpu/drm/tiny/repaper.c driver.

---

(no changes since v1)

   drivers/gpu/drm/drm_format_helper.c | 80 +++++++++++++++++++++++++++++
   include/drm/drm_format_helper.h     |  7 +++
   2 files changed, 87 insertions(+)
drivers/gpu/drm/drm_format_helper.c +2 -0
index 0f28dd2bdd72..cdce4b7c25d9 100644
@@ -584,3 +584,83 @@ int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for
       return -EINVAL;
   }
   EXPORT_SYMBOL(drm_fb_blit_toio);
+
+static void drm_fb_gray8_to_mono_reversed_line(u8 *dst, const u8 *src, size_t pixels)
Quoted 8 lines

drivers/gpu/drm/drm_format_helper.c int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for · line 592

Quoted 4 lines
drivers/gpu/drm/drm_format_helper.c +4 -0
+{
+     unsigned int xb, i;
+
+     for (xb = 0; xb < pixels / 8; xb++) {

In practice, all mode widths are multiples of 8 because VGA mandated it. So it's ok-ish to assume this here. You should probably at least print a warning somewhere if (pixels % 8 != 0)

Quoted 4 lines

Not sure if it's relevant, but 1366x768 was a fairly popular laptop resolution. There's even a dedicated drm_mode_fixup_1366x768 in drm_edid.c. (Would it have killed them to add 2 more horizontal pixels? Apparently.)

D'oh!

Do you know how the text console looks in this mode? Fonts still expect a multiple of 8.

Best regards
Thomas

Quoted 4 lines

Cheers,

-ilia

Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev
author maintainer
#8 lore raw

PATCH v2 2/4 drm/tiny: Add driver for Solomon SSD130X OLED displays

In reply to Javier Martinez Canillas

Add a DRM driver for SSD1305, SSD1306, SSD1307 and SSD1309 Solomon OLED controllers that can be programmed via an I2C interface. This is a port of the ssd1307fb driver that already supports these devices.

A Device Tree binding is not added because the DRM driver is compatible with the existing binding for the ssd1307fb driver.

---

(no changes since v1)

 drivers/gpu/drm/tiny/Kconfig   |  12 +
 drivers/gpu/drm/tiny/Makefile  |   1 +
 drivers/gpu/drm/tiny/ssd130x.c | 971 +++++++++++++++++++++++++++++++++
 3 files changed, 984 insertions(+)
 create mode 100644 drivers/gpu/drm/tiny/ssd130x.c
drivers/gpu/drm/tiny/Kconfig +12 -0
index 712e0004e96e..1b6f5aa41d69 100644
@@ -67,6 +67,18 @@ config DRM_SIMPLEDRM
 	  On x86 BIOS or UEFI systems, you should also select SYSFB_SIMPLEFB
 	  to use UEFI and VESA framebuffers.
 
+config DRM_SSD130X
+	tristate "DRM support for Solomon SSD130X OLED displays"
+	depends on DRM && I2C
+	select BACKLIGHT_CLASS_DEVICE
+	select DRM_GEM_SHMEM_HELPER
+	select DRM_KMS_HELPER
+	help
+	  DRM driver for the SSD1305, SSD1306, SSD1307 and SSD1309 Solomon
+	  OLED controllers that can be programmed via an I2C interface.
+
+	  If M is selected the module will be called ssd130x.
+
 config TINYDRM_HX8357D
 	tristate "DRM support for HX8357D display panels"
 	depends on DRM && SPI
drivers/gpu/drm/tiny/Makefile +1 -0
index 5d5505d40e7b..18c3557dcb71 100644
@@ -5,6 +5,7 @@ obj-$(CONFIG_DRM_BOCHS)			+= bochs.o
 obj-$(CONFIG_DRM_CIRRUS_QEMU)		+= cirrus.o
 obj-$(CONFIG_DRM_GM12U320)		+= gm12u320.o
 obj-$(CONFIG_DRM_SIMPLEDRM)		+= simpledrm.o
+obj-$(CONFIG_DRM_SSD130X)		+= ssd130x.o
 obj-$(CONFIG_TINYDRM_HX8357D)		+= hx8357d.o
 obj-$(CONFIG_TINYDRM_ILI9163)		+= ili9163.o
 obj-$(CONFIG_TINYDRM_ILI9225)		+= ili9225.o
drivers/gpu/drm/tiny/ssd130x.c new file +971 -0

971 lines not on this page · raw message

Signature · 1 line
2.34.1
#9 lore raw

Re: [PATCH v2 2/4] drm/tiny: Add driver for Solomon SSD130X OLED displays

Quoted 6 lines · Javier Martinez Canillas

Add a DRM driver for SSD1305, SSD1306, SSD1307 and SSD1309 Solomon OLED controllers that can be programmed via an I2C interface. This is a port of the ssd1307fb driver that already supports these devices.

A Device Tree binding is not added because the DRM driver is compatible with the existing binding for the ssd1307fb driver.

...

Quoted 9 lines

+/*
+ * DRM driver for Solomon SSD130X OLED displays
+ *
+ * Copyright 2022 Red Hat Inc.
+ *
+ * Based on drivers/video/fbdev/ssd1307fb.c
+ * Copyright 2012 Free Electrons

+ *

No need for this blank line.

Quoted 1 line

+ */

...

drivers/gpu/drm/tiny/ssd130x.c line 81

Quoted 8 lines
drivers/gpu/drm/tiny/ssd130x.c new file +6 -0
+struct ssd130x_device {
+	struct drm_device drm;
+	struct drm_simple_display_pipe pipe;
+	struct drm_display_mode mode;
+	struct drm_connector connector;
 
 
+	struct i2c_client *client;

Can we logically separate hw protocol vs hw interface from day 1, please? This will allow to add SPI support for this panel much easier.

Technically I would like to see here

	struct device *dev;

and probably (I haven't looked into design)

	struct ssd130x_ops *ops;

or something alike.

Quoted 32 lines
drivers/gpu/drm/tiny/ssd130x.c new file +32 -0
+	const struct ssd130x_deviceinfo *device_info;
+
+	unsigned area_color_enable : 1;
+	unsigned com_invdir : 1;
+	unsigned com_lrremap : 1;
+	unsigned com_seq : 1;
+	unsigned lookup_table_set : 1;
+	unsigned low_power : 1;
+	unsigned seg_remap : 1;
+	u32 com_offset;
+	u32 contrast;
+	u32 dclk_div;
+	u32 dclk_frq;
+	u32 height;
+	u8 lookup_table[4];
+	u32 page_offset;
+	u32 col_offset;
+	u32 prechargep1;
+	u32 prechargep2;
+
+	struct backlight_device *bl_dev;
+	struct pwm_device *pwm;
+	struct gpio_desc *reset;
+	struct regulator *vbat_reg;
+	u32 vcomh;
+	u32 width;
+	/* Cached address ranges */
+	u8 col_start;
+	u8 col_end;
+	u8 page_start;
+	u8 page_end;
+};

...

Quoted 1 line

+static inline int ssd130x_write_value(struct i2c_client *client, u8 value)

Not sure inline does anything useful here.
Ditto for the rest similar cases.

...

Quoted 5 lines
drivers/gpu/drm/tiny/ssd130x.c new file +5 -0
+static inline int ssd130x_write_cmd(struct i2c_client *client, int count,
+				    /* u8 cmd, u8 value, ... */...)
+{
+	va_list ap;
+	u8 value;

drivers/gpu/drm/tiny/ssd130x.c line 186

Quoted 10 lines
drivers/gpu/drm/tiny/ssd130x.c new file +9 -0
+	int ret;
+
+	va_start(ap, count);
 
+	while (count--) {
+		value = va_arg(ap, int);
+		ret = ssd130x_write_value(client, (u8)value);
+		if (ret)
+			goto out_end;
+	}

I'm wondering if this can be written in a form

	do {
		...
	} while (--count);

In this case it will give a hint that count can't be 0.

Quoted 5 lines
drivers/gpu/drm/tiny/ssd130x.c new file +5 -0
+out_end:
+	va_end(ap);
+
+	return ret;
+}

...

drivers/gpu/drm/tiny/ssd130x.c line 239

Quoted 3 lines
drivers/gpu/drm/tiny/ssd130x.c new file +3 -0
+	ssd130x->pwm = pwm_get(dev, NULL);
+	if (IS_ERR(ssd130x->pwm)) {
+		dev_err(dev, "Could not get PWM from device tree!\n");

"device tree" is a bit confusing here if I run this on ACPI. Maybe something like "firmware description"?

Quoted 2 lines
(quoted diff) +2 -0
+		return PTR_ERR(ssd130x->pwm);
+	}

...

drivers/gpu/drm/tiny/ssd130x.c line 311

Quoted 2 lines
drivers/gpu/drm/tiny/ssd130x.c new file +2 -0
+	/* Set initial contrast */
+	ret = ssd130x_write_cmd(ssd130x->client, 2, SSD130X_CONTRAST, ssd130x->contrast);

Creating a local variable for client allows to:
- make lines shorter and might even be less LOCs
- allow to convert struct device to client in one place (as per my above comment)

Ditto for other similar cases.

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

...

drivers/gpu/drm/tiny/ssd130x.c line 388

Quoted 1 line
drivers/gpu/drm/tiny/ssd130x.c new file +1 -0
+		for (i = 0; i < ARRAY_SIZE(ssd130x->lookup_table); ++i) {

i++ should work same way.

Quoted 1 line
(quoted diff) +1 -0
+		}

...

drivers/gpu/drm/tiny/ssd130x.c line 407

Quoted 7 lines
drivers/gpu/drm/tiny/ssd130x.c new file +7 -0
+	/* Switch to horizontal addressing mode */
+	ret = ssd130x_write_cmd(ssd130x->client, 2, SSD130X_SET_ADDRESS_MODE,
+				SSD130X_SET_ADDRESS_MODE_HORIZONTAL);
+	if (ret < 0)
+		return ret;
+
+	return 0;

Can it be

	return ssd130x_write_cmd(...);

?

...

drivers/gpu/drm/tiny/ssd130x.c line 415

Quoted 2 lines
drivers/gpu/drm/tiny/ssd130x.c new file +2 -0
+	unsigned int line_length = DIV_ROUND_UP(width, 8);
+	unsigned int pages = DIV_ROUND_UP(height, 8);

For power of two there are more efficient roundup()/rounddown() (or with _ in the names, I don't remember by heart).

...

drivers/gpu/drm/tiny/ssd130x.c line 471

Quoted 4 lines
drivers/gpu/drm/tiny/ssd130x.c new file +3 -0
+			for (k = 0; k < m; k++) {
 
+				u8 byte = buf[(8 * i + k) * line_length +
+					       j / 8];

One line?

Quoted 4 lines
drivers/gpu/drm/tiny/ssd130x.c new file +4 -0
+				u8 bit = (byte >> (j % 8)) & 1;
+
+				data |= bit << k;
+			}

...

drivers/gpu/drm/tiny/ssd130x.c line 532

Quoted 13 lines
drivers/gpu/drm/tiny/ssd130x.c new file +12 -0
+static int ssd130x_display_pipe_mode_valid(struct drm_simple_display_pipe *pipe,
+					   const struct drm_display_mode *mode)
+{
+	struct ssd130x_device *ssd130x = drm_to_ssd130x(pipe->crtc.dev);
+
+	if (mode->hdisplay != ssd130x->mode.hdisplay &&
+	    mode->vdisplay != ssd130x->mode.vdisplay)
+		return MODE_ONE_SIZE;
 
+	else if (mode->hdisplay != ssd130x->mode.hdisplay)
+		return MODE_ONE_WIDTH;
+	else if (mode->vdisplay != ssd130x->mode.vdisplay)
+		return MODE_ONE_HEIGHT;

'else' in both cases is redundant.

Quoted 2 lines
(quoted diff) +2 -0
+	return MODE_OK;
+}

...

Quoted 1 line

+poweroff:

out_power_off: ?

...

Review

Quoted 2 lines
(quoted diff) +2 -0
+	if (!fb)
+		return;

Can it happen?

...

drivers/gpu/drm/tiny/ssd130x.c line 644

Quoted 4 lines
drivers/gpu/drm/tiny/ssd130x.c new file +4 -0
+	drm_mode_probed_add(connector, mode);
+	drm_set_preferred_mode(connector, mode->hdisplay, mode->vdisplay);
+
+	return 1;

Positive code, what is the meaning of it?

...

drivers/gpu/drm/tiny/ssd130x.c line 728

Quoted 2 lines
drivers/gpu/drm/tiny/ssd130x.c new file +2 -0
+	if (device_property_read_u32(dev, "solomon,prechargep2", &ssd130x->prechargep2))
+		ssd130x->prechargep2 = 2;

You can drop conditionals for the optional properties

	ssd130x->prechargep2 = 2;
	device_property_read_u32(dev, "solomon,prechargep2", &ssd130x->prechargep2);

and so on for the similar.

...

drivers/gpu/drm/tiny/ssd130x.c line 819

Quoted 6 lines
drivers/gpu/drm/tiny/ssd130x.c new file +5 -0
+	ssd130x->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
+	if (IS_ERR(ssd130x->reset)) {
 
+		ret = PTR_ERR(ssd130x->reset);
+		dev_err(dev, "Failed to get reset gpio: %d\n", ret);
+		return ret;

Why not

return dev_err_probe()?

Each time you call it for deferred probe, it will spam logs.

drivers/gpu/drm/tiny/ssd130x.c line 830

Quoted 12 lines
drivers/gpu/drm/tiny/ssd130x.c new file +11 -0
+	}
+
+	ssd130x->vbat_reg = devm_regulator_get_optional(dev, "vbat");
+	if (IS_ERR(ssd130x->vbat_reg)) {
+		ret = PTR_ERR(ssd130x->vbat_reg);
+		if (ret == -ENODEV) {
+			ssd130x->vbat_reg = NULL;
 
+		} else {
+			dev_err(dev, "Failed to get VBAT regulator: %d\n", ret);
+			return ret;
+		}

Ditto ?

Quoted 1 line
(quoted diff) +1 -0
+	}

...

drivers/gpu/drm/tiny/ssd130x.c line 850

Quoted 5 lines
drivers/gpu/drm/tiny/ssd130x.c new file +5 -0
+	if (IS_ERR(ssd130x)) {
+		ret = PTR_ERR(ssd130x);
+		dev_err(dev, "Failed to allocate DRM device: %d\n", ret);
+		return ret;
+	}

Ditto.

...

drivers/gpu/drm/tiny/ssd130x.c line 852

Quoted 1 line
drivers/gpu/drm/tiny/ssd130x.c new file +1 -0
+	i2c_set_clientdata(client, ssd130x);

Wondering if you can split i2c part from the core part and perhaps use regmap to access the device.

...

drivers/gpu/drm/tiny/ssd130x.c line 871

Quoted 4 lines
drivers/gpu/drm/tiny/ssd130x.c new file +4 -0
+	if (IS_ERR(bl)) {
+		ret = PTR_ERR(bl);
+		dev_err(dev, "Unable to register backlight device: %d\n", ret);
+		return ret;
	return dev_err_probe();
Quoted 1 line
(quoted diff) +1 -0
+	}

...

drivers/gpu/drm/tiny/ssd130x.c line 886

Quoted 5 lines
drivers/gpu/drm/tiny/ssd130x.c new file +5 -0
+	ret = drm_dev_register(drm, 0);
+	if (ret) {
+		dev_err(dev, "DRM device register failed: %d\n", ret);
+		return ret;
+	}

Ditto.

...

drivers/gpu/drm/tiny/ssd130x.c line 952

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

Comma is not needed in terminator entry.

...

drivers/gpu/drm/tiny/ssd130x.c line 966

Quoted 11 lines
drivers/gpu/drm/tiny/ssd130x.c new file +10 -0
+static struct i2c_driver ssd130x_i2c_driver = {
+	.driver = {
+		.name = DRIVER_NAME,
+		.of_match_table = ssd130x_of_match,
+	},
+	.probe_new = ssd130x_probe,
+	.remove = ssd130x_remove,
+	.shutdown = ssd130x_shutdown,
+};
 
+

Redundant blank line.

Quoted 1 line

+module_i2c_driver(ssd130x_i2c_driver);

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#10 lore raw

Re: [PATCH v2 2/4] drm/tiny: Add driver for Solomon SSD130X OLED displays

Hello Andy,

Thanks for your feedback.

Quoted 18 lines · Andy Shevchenko
Quoted 6 lines · Javier Martinez Canillas

Add a DRM driver for SSD1305, SSD1306, SSD1307 and SSD1309 Solomon OLED controllers that can be programmed via an I2C interface. This is a port of the ssd1307fb driver that already supports these devices.

A Device Tree binding is not added because the DRM driver is compatible with the existing binding for the ssd1307fb driver.

...

Quoted 7 lines

+/*
+ * DRM driver for Solomon SSD130X OLED displays
+ *
+ * Copyright 2022 Red Hat Inc.
+ *
+ * Based on drivers/video/fbdev/ssd1307fb.c
+ * Copyright 2012 Free Electrons

Quoted 4 lines
Quoted 1 line

+ *

No need for this blank line.

Ok.

Quoted 18 lines
Quoted 1 line

+ */

...

drivers/gpu/drm/tiny/ssd130x.c line 81

Quoted 8 lines
drivers/gpu/drm/tiny/ssd130x.c new file +6 -0
+struct ssd130x_device {
+	struct drm_device drm;
+	struct drm_simple_display_pipe pipe;
+	struct drm_display_mode mode;
+	struct drm_connector connector;
 
 
+	struct i2c_client *client;

Can we logically separate hw protocol vs hw interface from day 1, please? This will allow to add SPI support for this panel much easier.

Technically I would like to see here

Quoted 8 lines
	struct device *dev;

and probably (I haven't looked into design)

	struct ssd130x_ops *ops;

or something alike.

Sure. I wanted to keep the driver simple, making the writes bus agnostic and adding a level of indirection would make it more complex. But I agree that it will also make easier to add more buses later. I will do that for v3.

[snip]

Quoted 6 lines
Quoted 2 lines

+static inline int ssd130x_write_value(struct i2c_client *client, u8 value)

Not sure inline does anything useful here.
Ditto for the rest similar cases.

Ok, I'll drop them.

Quoted 20 lines

...

Quoted 5 lines
drivers/gpu/drm/tiny/ssd130x.c new file +5 -0
+static inline int ssd130x_write_cmd(struct i2c_client *client, int count,
+				    /* u8 cmd, u8 value, ... */...)
+{
+	va_list ap;
+	u8 value;

drivers/gpu/drm/tiny/ssd130x.c line 186

Quoted 10 lines
drivers/gpu/drm/tiny/ssd130x.c new file +9 -0
+	int ret;
+
+	va_start(ap, count);
 
+	while (count--) {
+		value = va_arg(ap, int);
+		ret = ssd130x_write_value(client, (u8)value);
+		if (ret)
+			goto out_end;
+	}

I'm wondering if this can be written in a form

Quoted 6 lines
	do {
		...
	} while (--count);

In this case it will give a hint that count can't be 0.

Sure, I don't have a strong preference. I will change it.

[snip]

Quoted 7 lines

drivers/gpu/drm/tiny/ssd130x.c line 239

Quoted 3 lines
drivers/gpu/drm/tiny/ssd130x.c new file +3 -0
+	ssd130x->pwm = pwm_get(dev, NULL);
+	if (IS_ERR(ssd130x->pwm)) {
+		dev_err(dev, "Could not get PWM from device tree!\n");

"device tree" is a bit confusing here if I run this on ACPI. Maybe something like "firmware description"?

Indeed.

Quoted 13 lines
Quoted 2 lines
(quoted diff) +2 -0
+		return PTR_ERR(ssd130x->pwm);
+	}

...

drivers/gpu/drm/tiny/ssd130x.c line 311

Quoted 2 lines
drivers/gpu/drm/tiny/ssd130x.c new file +2 -0
+	/* Set initial contrast */
+	ret = ssd130x_write_cmd(ssd130x->client, 2, SSD130X_CONTRAST, ssd130x->contrast);

Creating a local variable for client allows to:
- make lines shorter and might even be less LOCs
- allow to convert struct device to client in one place (as per my above comment)

Quoted 2 lines

Ditto for other similar cases.

Ok.

[snip]

Quoted 10 lines

drivers/gpu/drm/tiny/ssd130x.c line 407

Quoted 7 lines
drivers/gpu/drm/tiny/ssd130x.c new file +7 -0
+	/* Switch to horizontal addressing mode */
+	ret = ssd130x_write_cmd(ssd130x->client, 2, SSD130X_SET_ADDRESS_MODE,
+				SSD130X_SET_ADDRESS_MODE_HORIZONTAL);
+	if (ret < 0)
+		return ret;
+
+	return 0;

Can it be

Quoted 6 lines
	return ssd130x_write_cmd(...);

?

...

Yes.

Quoted 6 lines

drivers/gpu/drm/tiny/ssd130x.c line 415

Quoted 2 lines
drivers/gpu/drm/tiny/ssd130x.c new file +2 -0
+	unsigned int line_length = DIV_ROUND_UP(width, 8);
+	unsigned int pages = DIV_ROUND_UP(height, 8);

For power of two there are more efficient roundup()/rounddown() (or with _ in the names, I don't remember by heart).

Oh, I didn't know about round_{up,down}(). Thanks a lot for the pointer.

Quoted 9 lines

...

drivers/gpu/drm/tiny/ssd130x.c line 471

Quoted 4 lines
drivers/gpu/drm/tiny/ssd130x.c new file +3 -0
+			for (k = 0; k < m; k++) {
 
+				u8 byte = buf[(8 * i + k) * line_length +
+					       j / 8];

One line?

Yes.

Quoted 16 lines
Quoted 4 lines
drivers/gpu/drm/tiny/ssd130x.c new file +4 -0
+				u8 bit = (byte >> (j % 8)) & 1;
+
+				data |= bit << k;
+			}

...

Quoted 8 lines
drivers/gpu/drm/tiny/ssd130x.c new file +8 -0
+static int ssd130x_display_pipe_mode_valid(struct drm_simple_display_pipe *pipe,
+					   const struct drm_display_mode *mode)
+{
+	struct ssd130x_device *ssd130x = drm_to_ssd130x(pipe->crtc.dev);
+
+	if (mode->hdisplay != ssd130x->mode.hdisplay &&
+	    mode->vdisplay != ssd130x->mode.vdisplay)
+		return MODE_ONE_SIZE;
Quoted 7 lines

drivers/gpu/drm/tiny/ssd130x.c line 532

Quoted 4 lines
drivers/gpu/drm/tiny/ssd130x.c new file +4 -0
+	else if (mode->hdisplay != ssd130x->mode.hdisplay)
+		return MODE_ONE_WIDTH;
+	else if (mode->vdisplay != ssd130x->mode.vdisplay)
+		return MODE_ONE_HEIGHT;

'else' in both cases is redundant.

Indeed.

Quoted 9 lines
Quoted 2 lines
(quoted diff) +2 -0
+	return MODE_OK;
+}

...

Quoted 1 line

+poweroff:

out_power_off: ?

Ok.

Quoted 7 lines

...

Review

Quoted 2 lines
(quoted diff) +2 -0
+	if (!fb)
+		return;

Can it happen?

I don't know, but saw that the handler of other drivers checked for this so preferred to play safe and do the same.

Quoted 9 lines

...

drivers/gpu/drm/tiny/ssd130x.c line 644

Quoted 4 lines
drivers/gpu/drm/tiny/ssd130x.c new file +4 -0
+	drm_mode_probed_add(connector, mode);
+	drm_set_preferred_mode(connector, mode->hdisplay, mode->vdisplay);
+
+	return 1;

Positive code, what is the meaning of it?

It's the number of connector modes. The driver only supports 1.

Quoted 10 lines

...

drivers/gpu/drm/tiny/ssd130x.c line 728

Quoted 2 lines
drivers/gpu/drm/tiny/ssd130x.c new file +2 -0
+	if (device_property_read_u32(dev, "solomon,prechargep2", &ssd130x->prechargep2))
+		ssd130x->prechargep2 = 2;

You can drop conditionals for the optional properties

Quoted 5 lines
	ssd130x->prechargep2 = 2;
	device_property_read_u32(dev, "solomon,prechargep2", &ssd130x->prechargep2);

and so on for the similar.

Ok.

Quoted 11 lines

...

drivers/gpu/drm/tiny/ssd130x.c line 819

Quoted 6 lines
drivers/gpu/drm/tiny/ssd130x.c new file +5 -0
+	ssd130x->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
+	if (IS_ERR(ssd130x->reset)) {
 
+		ret = PTR_ERR(ssd130x->reset);
+		dev_err(dev, "Failed to get reset gpio: %d\n", ret);
+		return ret;

Why not

Quoted 4 lines

return dev_err_probe()?

Each time you call it for deferred probe, it will spam logs.

Right. I'll change in all the places you pointed out.

[snip]

Quoted 6 lines

...

drivers/gpu/drm/tiny/ssd130x.c line 952

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

Comma is not needed in terminator entry.

Right.

Quoted 12 lines

...

Quoted 9 lines
drivers/gpu/drm/tiny/ssd130x.c new file +9 -0
+static struct i2c_driver ssd130x_i2c_driver = {
+	.driver = {
+		.name = DRIVER_NAME,
+		.of_match_table = ssd130x_of_match,
+	},
+	.probe_new = ssd130x_probe,
+	.remove = ssd130x_remove,
+	.shutdown = ssd130x_shutdown,
+};
Quoted 4 lines
Quoted 1 line

+

Redundant blank line.

Ok.

Quoted 2 lines
Quoted 1 line

+module_i2c_driver(ssd130x_i2c_driver);

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Linux Engineering
Red Hat
#11 lore raw

Re: [PATCH v2 2/4] drm/tiny: Add driver for Solomon SSD130X OLED displays

Quoted 2 lines · Javier Martinez Canillas
Quoted 1 line · Andy Shevchenko

On Fri, Feb 04, 2022 at 02:43:45PM +0100, Javier Martinez Canillas wrote:

...

Quoted 18 lines
Quoted 18 lines

drivers/gpu/drm/tiny/ssd130x.c line 81

Quoted 8 lines
drivers/gpu/drm/tiny/ssd130x.c new file +6 -0
+struct ssd130x_device {
+	struct drm_device drm;
+	struct drm_simple_display_pipe pipe;
+	struct drm_display_mode mode;
+	struct drm_connector connector;
 
 
+	struct i2c_client *client;

Can we logically separate hw protocol vs hw interface from day 1, please? This will allow to add SPI support for this panel much easier.

Technically I would like to see here

	struct device *dev;

and probably (I haven't looked into design)

Quoted 7 lines
Quoted 3 lines
	struct ssd130x_ops *ops;

or something alike.

Sure. I wanted to keep the driver simple, making the writes bus agnostic and adding a level of indirection would make it more complex. But I agree that it will also make easier to add more buses later. I will do that for v3.

I have SSD1306 display with SPI interface and I'm not able to test your series. With the above it at least gives me a point to consider helping (coding and testing) with SPI one.

...

Quoted 7 lines
Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	if (!fb)
+		return;

Can it happen?

I don't know, but saw that the handler of other drivers checked for this so preferred to play safe and do the same.

So, either cargo-cult or indeed it may happen. Somebody may conduct a research on this...

...

Quoted 8 lines
Quoted 6 lines

drivers/gpu/drm/tiny/ssd130x.c line 644

Quoted 4 lines
drivers/gpu/drm/tiny/ssd130x.c new file +4 -0
+	drm_mode_probed_add(connector, mode);
+	drm_set_preferred_mode(connector, mode->hdisplay, mode->vdisplay);
+
+	return 1;

Positive code, what is the meaning of it?

It's the number of connector modes. The driver only supports 1.

A comment then?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#12 lore raw

Re: [PATCH v2 2/4] drm/tiny: Add driver for Solomon SSD130X OLED displays

Quoted 28 lines · Andy Shevchenko
Quoted 2 lines · Javier Martinez Canillas
Quoted 1 line · Andy Shevchenko

On Fri, Feb 04, 2022 at 02:43:45PM +0100, Javier Martinez Canillas wrote:

...

Quoted 22 lines
Quoted 21 lines

drivers/gpu/drm/tiny/ssd130x.c line 81

Quoted 8 lines
drivers/gpu/drm/tiny/ssd130x.c new file +6 -0
+struct ssd130x_device {
+	struct drm_device drm;
+	struct drm_simple_display_pipe pipe;
+	struct drm_display_mode mode;
+	struct drm_connector connector;
 
 
+	struct i2c_client *client;

Can we logically separate hw protocol vs hw interface from day 1, please? This will allow to add SPI support for this panel much easier.

Technically I would like to see here

	struct device *dev;

and probably (I haven't looked into design)

	struct ssd130x_ops *ops;

or something alike.

Quoted 8 lines
Quoted 3 lines

Sure. I wanted to keep the driver simple, making the writes bus agnostic and adding a level of indirection would make it more complex. But I agree that it will also make easier to add more buses later. I will do that for v3.

I have SSD1306 display with SPI interface and I'm not able to test your series. With the above it at least gives me a point to consider helping (coding and testing) with SPI one.

Yes, I understand that. On the other hand, I only have a SSD1306 with an I2C interface so I'm interested in supporting that. Then someone could extend to support other buses :)

But I agree with you that making the driver easier to extend and using regmap would be desirable. In fact, since I will add the level of indirection I can got ahead and attempt to add the SPI support as well.

I won't be able to test but I can use drivers/staging/fbtft/fb_ssd1306.c as a reference for this.

Quoted 7 lines

...

Quoted 5 lines
Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	if (!fb)
+		return;

Can it happen?

Quoted 6 lines
Quoted 2 lines

I don't know, but saw that the handler of other drivers checked for this so preferred to play safe and do the same.

So, either cargo-cult or indeed it may happen. Somebody may conduct a research on this...

Someone familiar with the simple display pipe helpers should chime in, I tried to grep around but couldn't figure out whether it was safe or not to assume the struct drm_framebuffer won't ever be NULL in a struct drm_shadow_plane_state.

As mentioned other drivers were doing and I preferred to be defensive rather than leading to a possible NULL pointer dereference.

Quoted 9 lines

...

Quoted 7 lines
Quoted 6 lines

drivers/gpu/drm/tiny/ssd130x.c line 644

Quoted 4 lines
drivers/gpu/drm/tiny/ssd130x.c new file +4 -0
+	drm_mode_probed_add(connector, mode);
+	drm_set_preferred_mode(connector, mode->hdisplay, mode->vdisplay);
+
+	return 1;

Positive code, what is the meaning of it?

Quoted 4 lines
Quoted 1 line

It's the number of connector modes. The driver only supports 1.

A comment then?

Yes, that makes sense.

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Linux Engineering
Red Hat
author maintainer
#13 lore raw

PATCH v2 3/4 MAINTAINERS: Add entry for Solomon SSD130X OLED displays DRM driver

In reply to Javier Martinez Canillas

To make sure that tools like the get_maintainer.pl script will suggest to Cc me if patches are posted for this driver.

Also include the Device Tree binding for the old ssd1307fb fbdev driver since the new DRM driver was made compatible with the existing binding.

---

(no changes since v1)

 MAINTAINERS                         | 7 +++++++
 drivers/gpu/drm/drm_format_helper.c | 2 +-
 2 files changed, 8 insertions(+), 1 deletion(-)
MAINTAINERS +7 -0
index d03ad8da1f36..9061488a4113 100644
@@ -6102,6 +6102,13 @@ T:	git git://anongit.freedesktop.org/drm/drm-misc
 F:	Documentation/devicetree/bindings/display/repaper.txt
 F:	drivers/gpu/drm/tiny/repaper.c
 
+DRM DRIVER FOR SOLOMON SSD130X OLED DISPLAYS
+M:	Javier Martinez Canillas <[email protected]>
+S:	Maintained
+T:	git git://anongit.freedesktop.org/drm/drm-misc
+F:	Documentation/devicetree/bindings/display/solomon,ssd1307fb.yaml
+F:	drivers/gpu/drm/tiny/ssd130x.c
+
 DRM DRIVER FOR QEMU'S CIRRUS DEVICE
 M:	Dave Airlie <[email protected]>
 M:	Gerd Hoffmann <[email protected]>
drivers/gpu/drm/drm_format_helper.c +1 -1
index cdce4b7c25d9..c3c1372fb771 100644
@@ -661,6 +661,6 @@ void drm_fb_xrgb8888_to_mono_reversed(void *dst, unsigned int dst_pitch, const v
 		dst_pitch = drm_rect_width(clip);
 
 	drm_fb_xrgb8888_to_gray8(dst, dst_pitch, src, fb, clip);
-	drm_fb_gray8_to_mono_reversed(dst, dst_pitch, dst, fb, clip);
+	drm_fb_gray8_to_mono_reversed(dst, dst_pitch, dst, clip);
 }
 EXPORT_SYMBOL(drm_fb_xrgb8888_to_mono_reversed);
Signature · 1 line
2.34.1
#14 lore raw

Re: [PATCH v2 3/4] MAINTAINERS: Add entry for Solomon SSD130X OLED displays DRM driver

Quoted 5 lines · Javier Martinez Canillas

To make sure that tools like the get_maintainer.pl script will suggest to Cc me if patches are posted for this driver.

Also include the Device Tree binding for the old ssd1307fb fbdev driver since the new DRM driver was made compatible with the existing binding.

...

Quoted 1 line
 drivers/gpu/drm/drm_format_helper.c | 2 +-

Nothing about this in the commit message...

Stray change?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#15 lore raw

Re: [PATCH v2 3/4] MAINTAINERS: Add entry for Solomon SSD130X OLED displays DRM driver

Hello Andy,

Quoted 7 lines · Andy Shevchenko
Quoted 5 lines · Javier Martinez Canillas

To make sure that tools like the get_maintainer.pl script will suggest to Cc me if patches are posted for this driver.

Also include the Device Tree binding for the old ssd1307fb fbdev driver since the new DRM driver was made compatible with the existing binding.

Quoted 8 lines

...

Quoted 1 line
 drivers/gpu/drm/drm_format_helper.c | 2 +-

Nothing about this in the commit message...

Stray change?

Sigh, I'm not sure how added that change. Just ignore it, I'll fix it on v3 or when applying if there isn't another revision of this series.

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Linux Engineering
Red Hat
#16 lore raw

Re: [PATCH v2 3/4] MAINTAINERS: Add entry for Solomon SSD130X OLED displays DRM driver

Quoted 2 lines · Javier Martinez Canillas
Quoted 1 line · Andy Shevchenko

On Fri, Feb 04, 2022 at 02:43:46PM +0100, Javier Martinez Canillas wrote:

...

Quoted 4 lines
Quoted 1 line

Stray change?

Sigh, I'm not sure how added that change. Just ignore it, I'll fix it on v3 or when applying if there isn't another revision of this series.

I believe v3 is warranted due to the other patch review.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#17 lore raw

Re: [PATCH v2 3/4] MAINTAINERS: Add entry for Solomon SSD130X OLED displays DRM driver

Quoted 4 lines · Andy Shevchenko
Quoted 2 lines · Javier Martinez Canillas
Quoted 1 line · Andy Shevchenko

On Fri, Feb 04, 2022 at 02:43:46PM +0100, Javier Martinez Canillas wrote:

Quoted 9 lines

...

Quoted 4 lines
Quoted 1 line

Stray change?

Sigh, I'm not sure how added that change. Just ignore it, I'll fix it on v3 or when applying if there isn't another revision of this series.

I believe v3 is warranted due to the other patch review.

Agreed. Thanks a lot for your feedback and comments.

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Linux Engineering
Red Hat
author maintainer
#18 lore raw

PATCH v2 4/4 dt-bindings: display: ssd1307fb: Add myself as binding co-maintainer

In reply to Javier Martinez Canillas

The ssd130x DRM driver also makes use of this Device Tree binding to allow existing users of the fbdev driver to migrate without the need to change their Device Trees.

Add myself as another maintainer of the binding, to make sure that I will be on Cc when patches are proposed for it.

---

(no changes since v1)

 Documentation/devicetree/bindings/display/solomon,ssd1307fb.yaml | 1 +
 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/display/solomon,ssd1307fb.yaml +1 -0
index 2ed2a7d0ca2f..9baafd0c42dd 100644
@@ -8,6 +8,7 @@ title: Solomon SSD1307 OLED Controller Framebuffer
 
 maintainers:
   - Maxime Ripard <[email protected]>
+  - Javier Martinez Canillas <[email protected]>
 
 properties:
   compatible:
Signature · 1 line
2.34.1
maintainer Acked-by on v2 4/4
#19 lore raw

Re: [PATCH v2 4/4] dt-bindings: display: ssd1307fb: Add myself as binding co-maintainer

Quoted 7 lines · Javier Martinez Canillas

The ssd130x DRM driver also makes use of this Device Tree binding to allow existing users of the fbdev driver to migrate without the need to change their Device Trees.

Add myself as another maintainer of the binding, to make sure that I will be on Cc when patches are proposed for it.

Quoted 9 lines

---

(no changes since v1)

 Documentation/devicetree/bindings/display/solomon,ssd1307fb.yaml | 1 +
 1 file changed, 1 insertion(+)
#20 lore raw
In reply to Javier Martinez Canillas

Hi Javier,

Quoted 2 lines · Javier Martinez Canillas

This patch series adds a DRM driver for the Solomon OLED SSD1305, SSD1306, SSD1307 and SSD1309 displays. It is a port of the ssd1307fb fbdev driver.

[...]

Quoted 3 lines

This is a v2 that addresses all the issues pointed in v1, thanks a lot to everyone that gave me feedback and reviews. I tried to not miss any comment, but there were a lot so forgive me if something is not there.

Thanks for the update!

Quoted 1 line

Changes in v2:

[...]

Note that the individual patches say "(no changes since v1)"?

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

author maintainer
#21 lore raw

Hello Geert,

Quoted 7 lines · Geert Uytterhoeven

Hi Javier,

Quoted 2 lines · Javier Martinez Canillas

This patch series adds a DRM driver for the Solomon OLED SSD1305, SSD1306, SSD1307 and SSD1309 displays. It is a port of the ssd1307fb fbdev driver.

Quoted 8 lines

[...]

Quoted 3 lines

This is a v2 that addresses all the issues pointed in v1, thanks a lot to everyone that gave me feedback and reviews. I tried to not miss any comment, but there were a lot so forgive me if something is not there.

Thanks for the update!

You are welcome!

Quoted 6 lines
Quoted 1 line

Changes in v2:

[...]

Note that the individual patches say "(no changes since v1)"?

That's due patman (the tool I use to post patches) not being that smart.

I only added the v2 changelog in the cover letter and not the individual patches to avoid adding noise, since there are a lot of changes since v1.

But patman then thought that means individual patches had no changes...

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Linux Engineering
Red Hat
#22 lore raw
In reply to Javier Martinez Canillas

Hi Javier,

Quoted 2 lines · Javier Martinez Canillas

This patch series adds a DRM driver for the Solomon OLED SSD1305, SSD1306, SSD1307 and SSD1309 displays. It is a port of the ssd1307fb fbdev driver.

I gave it a try on an Adafruit FeatherWing 128x32 OLED, connected to an OrangeCrab ECP5 FPGA board running a 64 MHz VexRiscv RISC-V softcore.

Findings:
- Kernel size increased by 349 KiB,
- The "Memory:" line reports 412 KiB less memory,
- On top of that, "free" shows ca. 92 KiB more memory in use after bootup.
- The logo (I have a custom monochrome logo enabled) is no longer shown.
- The screen is empty, with a (very very slow) flashing cursor in the middle of the screen, with a bogus long line next to it, which I can see being redrawn.
- Writing text (e.g. hello) to /dev/tty0, I first see the text, followed by an enlargement of some of the characters.
- "time ls" on the serial console (no files in the current directory, so nothing to print) increases from 0.86s to 1.92s, so the system is more loaded. As ssd1307fb relied on deferred I/O too, the slowdown might be (partly) due to redrawing of the visual artefacts mentioned above.

So while the displays seems to be initialized correctly, it looks like there are some serious bugs in the conversion from xrgb8888 to monochrome.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

author maintainer
#23 lore raw

Hello Geert,

Thanks a lot for testing!

Quoted 10 lines · Geert Uytterhoeven

Hi Javier,

Quoted 2 lines · Javier Martinez Canillas

This patch series adds a DRM driver for the Solomon OLED SSD1305, SSD1306, SSD1307 and SSD1309 displays. It is a port of the ssd1307fb fbdev driver.

I gave it a try on an Adafruit FeatherWing 128x32 OLED, connected to an OrangeCrab ECP5 FPGA board running a 64 MHz VexRiscv RISC-V softcore.

Quoted 6 lines

Findings:
- Kernel size increased by 349 KiB,
- The "Memory:" line reports 412 KiB less memory,
- On top of that, "free" shows ca. 92 KiB more memory in use after bootup.
- The logo (I have a custom monochrome logo enabled) is no longer shown.

I was able to display your tux monochrome with ./fbtest -f /dev/fb1 test004

Quoted 5 lines

- The screen is empty, with a (very very slow) flashing cursor in the middle of the screen, with a bogus long line next to it, which I can see being redrawn.
- Writing text (e.g. hello) to /dev/tty0, I first see the text, followed by an enlargement of some of the characters.

So far I was mostly testing using your fbtest repo tests and all of them (modulo test009 that says "Screen size too small for this test").

But I've tried now using as a VT and I see the same visual artifacts. I wonder what's the difference between fbcon and the way your tests use the fbdev API.

Quoted 6 lines

- "time ls" on the serial console (no files in the current directory, so nothing to print) increases from 0.86s to 1.92s, so the system is more loaded. As ssd1307fb relied on deferred I/O too, the slowdown might be (partly) due to redrawing of the visual artefacts mentioned above.

I was trying to first have the driver and then figure out how to optimize it. For v3 I'm using regmap to access instead of the I2C layer directly.

I noticed that this is even slower but it makes the driver more clean and allows to support both I2C and SPI (untested but will include it as a WIP).

Quoted 4 lines

So while the displays seems to be initialized correctly, it looks like there are some serious bugs in the conversion from xrgb8888 to monochrome.

Yes, that's possible. I haven't tried to use it as a console before because the display resolution is just too small. But will include now in my tests.

Quoted 2 lines

Gr{oetje,eeting}s,

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Linux Engineering
Red Hat
#24 lore raw
Quoted 8 lines · Javier Martinez Canillas
Quoted 5 lines · Geert Uytterhoeven

- "time ls" on the serial console (no files in the current directory, so nothing to print) increases from 0.86s to 1.92s, so the system is more loaded. As ssd1307fb relied on deferred I/O too, the slowdown might be (partly) due to redrawing of the visual artefacts mentioned above.

Quoted 5 lines

I was trying to first have the driver and then figure out how to optimize it. For v3 I'm using regmap to access instead of the I2C layer directly.

I noticed that this is even slower but it makes the driver more clean and allows to support both I2C and SPI (untested but will include it as a WIP).

I wouldn't have expected regmap to add huge overhead relative to I2C, partly predicated on I2C being rather slow itself. There will be some overhead for concurrency protection and data marshalling but for I2C clocked at normal speeds it's surprising.

author maintainer
#25 lore raw

Hello Mark,

Quoted 12 lines · Mark Brown
Quoted 10 lines · Javier Martinez Canillas
Quoted 5 lines · Geert Uytterhoeven

- "time ls" on the serial console (no files in the current directory, so nothing to print) increases from 0.86s to 1.92s, so the system is more loaded. As ssd1307fb relied on deferred I/O too, the slowdown might be (partly) due to redrawing of the visual artefacts mentioned above.

I was trying to first have the driver and then figure out how to optimize it. For v3 I'm using regmap to access instead of the I2C layer directly.

Quoted 7 lines
Quoted 2 lines

I noticed that this is even slower but it makes the driver more clean and allows to support both I2C and SPI (untested but will include it as a WIP).

I wouldn't have expected regmap to add huge overhead relative to I2C, partly predicated on I2C being rather slow itself. There will be some overhead for concurrency protection and data marshalling but for I2C clocked at normal speeds it's surprising.

Thanks for chiming in. That's good to know, I'll investigate more then.

Probably I was wrongly blaming regmap while it was another change that is causing the display to be refreshed at a slower rate than before.

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Linux Engineering
Red Hat
#26 lore raw
In reply to Javier Martinez Canillas

Hi Javier,

Quoted 9 lines · Javier Martinez Canillas
Quoted 8 lines · Geert Uytterhoeven
Quoted 2 lines · Javier Martinez Canillas

This patch series adds a DRM driver for the Solomon OLED SSD1305, SSD1306, SSD1307 and SSD1309 displays. It is a port of the ssd1307fb fbdev driver.

I gave it a try on an Adafruit FeatherWing 128x32 OLED, connected to an OrangeCrab ECP5 FPGA board running a 64 MHz VexRiscv RISC-V softcore.

Quoted 8 lines
Quoted 6 lines

Findings:
- Kernel size increased by 349 KiB,
- The "Memory:" line reports 412 KiB less memory,
- On top of that, "free" shows ca. 92 KiB more memory in use after bootup.
- The logo (I have a custom monochrome logo enabled) is no longer shown.

I was able to display your tux monochrome with ./fbtest -f /dev/fb1 test004

I meant the kernel's logo (FB_LOGO_*),. Obviously you need to enable a smaller one, as the default 80x80 logo is too large, and thus can't be drawn on your 128x64 or my 128x32 display.

Quoted 6 lines
Quoted 5 lines

- The screen is empty, with a (very very slow) flashing cursor in the middle of the screen, with a bogus long line next to it, which I can see being redrawn.
- Writing text (e.g. hello) to /dev/tty0, I first see the text, followed by an enlargement of some of the characters.

Quoted 6 lines

So far I was mostly testing using your fbtest repo tests and all of them (modulo test009 that says "Screen size too small for this test").

But I've tried now using as a VT and I see the same visual artifacts. I wonder what's the difference between fbcon and the way your tests use the fbdev API.

Fbcon does small writes to the shadow frame buffer, while fbtest writes to the mmap()ed /dev/fbX, causing a full page to be updated.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

author maintainer
#27 lore raw

On 2/8/22 16:23, Geert Uytterhoeven wrote:

[snip]

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

- The logo (I have a custom monochrome logo enabled) is no longer shown.

I was able to display your tux monochrome with ./fbtest -f /dev/fb1 test004

I meant the kernel's logo (FB_LOGO_*),. Obviously you need to enable a smaller one, as the default 80x80 logo is too large, and thus can't be drawn on your 128x64 or my 128x32 display.

That makes sense.

Quoted 9 lines
Quoted 9 lines
Quoted 5 lines

- The screen is empty, with a (very very slow) flashing cursor in the middle of the screen, with a bogus long line next to it, which I can see being redrawn.
- Writing text (e.g. hello) to /dev/tty0, I first see the text, followed by an enlargement of some of the characters.

So far I was mostly testing using your fbtest repo tests and all of them (modulo test009 that says "Screen size too small for this test").

Quoted 7 lines
Quoted 3 lines

But I've tried now using as a VT and I see the same visual artifacts. I wonder what's the difference between fbcon and the way your tests use the fbdev API.

Fbcon does small writes to the shadow frame buffer, while fbtest writes to the mmap()ed /dev/fbX, causing a full page to be updated.

I see. Thanks for the information.

Best regards, --
Javier Martinez Canillas
Linux Engineering
Red Hat

author maintainer
#28 lore raw
Quoted 1 line · Javier Martinez Canillas

On 2/8/22 16:23, Geert Uytterhoeven wrote:

[snip]

Quoted 7 lines
Quoted 4 lines

Fbcon does small writes to the shadow frame buffer, while fbtest writes to the mmap()ed /dev/fbX, causing a full page to be updated.

I see. Thanks for the information.

I found the bug. Partial updates where indeed broken and only a full screen update was working. I didn't notice because where using your fbtests that mmap and do a full update.

Thanks a lot for reporting this, the issue should be fixed in v3.

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Linux Engineering
Red Hat
#29 lore raw
In reply to Javier Martinez Canillas
Quoted 8 lines · Javier Martinez Canillas
Quoted 7 lines · Geert Uytterhoeven

On Fri, Feb 4, 2022 at 2:43 PM Javier Martinez Canillas <[email protected]> wrote:

- Kernel size increased by 349 KiB,
- The "Memory:" line reports 412 KiB less memory,
- On top of that, "free" shows ca. 92 KiB more memory in use after bootup.

The memory consumption should really be taken seriously, because these kind of displays are for embedded platforms with limited amount of resources.

Thanks, Geert, for testing and reporting this issue in particular.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#30 lore raw

Hi Andy,

Quoted 11 lines · Andy Shevchenko
Quoted 7 lines · Javier Martinez Canillas
Quoted 6 lines · Geert Uytterhoeven

On Fri, Feb 4, 2022 at 2:43 PM Javier Martinez Canillas <[email protected]> wrote:
- Kernel size increased by 349 KiB,
- The "Memory:" line reports 412 KiB less memory,
- On top of that, "free" shows ca. 92 KiB more memory in use after bootup.

The memory consumption should really be taken seriously, because these kind of displays are for embedded platforms with limited amount of resources.

Thanks for your concern!

Looking at the options that are auto-enabled, a few stand out that look like they're not needed on systems witch such small displays, or on legacy systems predating DDC:

menuconfig DRM
tristate "Direct Rendering Manager (XFree86 4.1.0 and
higher DRI support)"

            depends on (AGP || AGP=n) && !EMULATED_CMPXCHG && HAS_DMA
            select DRM_NOMODESET
            select DRM_PANEL_ORIENTATION_QUIRKS
            select HDMI

Not everyone pays HDMI royalties ;-)

select FB_CMDLINE
select I2C
select I2C_ALGOBIT

I do need I2C, as it's the transport for my SSD1306 display, but not everyone needs it.

select DMA_SHARED_BUFFER
select SYNC_FILE
# gallium uses SYS_kcmp for os_same_file_description() to de-duplicate # device and dmabuf fd. Let's make sure that is available for our userspace.
select KCMP

And:

config DRM_BRIDGE
def_bool y
depends on DRM
help
Bridge registration and lookup framework.

config DRM_PANEL_BRIDGE
def_bool y

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

author maintainer
#31 lore raw

Hello Geert,

Quoted 13 lines · Geert Uytterhoeven

Hi Andy,

Quoted 9 lines · Andy Shevchenko
Quoted 7 lines · Javier Martinez Canillas
Quoted 6 lines · Geert Uytterhoeven

On Fri, Feb 4, 2022 at 2:43 PM Javier Martinez Canillas <[email protected]> wrote:
- Kernel size increased by 349 KiB,
- The "Memory:" line reports 412 KiB less memory,
- On top of that, "free" shows ca. 92 KiB more memory in use after bootup.

Quoted 8 lines
Quoted 2 lines

The memory consumption should really be taken seriously, because these kind of displays are for embedded platforms with limited amount of resources.

Thanks for your concern!

Looking at the options that are auto-enabled, a few stand out that look like they're not needed on systems witch such small displays, or on legacy systems predating DDC:

Thanks for your analysis.

Since drivers are replacing the {simple,efi}fb drivers and others with the simpledrm driver, the DRM subsystem is now built into the kernel and no longer a loadable module.

So there has been some effort to make it more modular and smaller, as an example the following patch-set from Thomas:

https://www.spinics.net/lists/dri-devel/msg329120.html

But there are still a lot of room to reduce this and certainly enabling CONFIG_DRM will be noticeable for such memory constrainted systems.

This is outside the scope of this patch series though, that is only about adding a new DRM driver :)

Now, this is a reason why I mentioned that the old fbdev driver shouldn't be removed yet.

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Linux Engineering
Red Hat
#32 lore raw
Quoted 1 line · Javier Martinez Canillas

On 2/9/22 15:27, Geert Uytterhoeven wrote:

...

Quoted 2 lines

Now, this is a reason why I mentioned that the old fbdev driver shouldn't be removed yet.

I agree on this conclusion.

I think based on the fbtft resurrection discussion I can send a new version to unorphan it, route via fbdev, and leave under staging, so it will be a compromise between all stakeholders.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#33 lore raw
Quoted 5 lines · Andy Shevchenko
Quoted 1 line · Javier Martinez Canillas

On 2/9/22 15:27, Geert Uytterhoeven wrote:

...

Quoted 8 lines
Quoted 2 lines

Now, this is a reason why I mentioned that the old fbdev driver shouldn't be removed yet.

I agree on this conclusion.

I think based on the fbtft resurrection discussion I can send a new version to unorphan it, route via fbdev, and leave under staging, so it will be a compromise between all stakeholders.

The DT bindings still don't belong anywhere in the main tree.

Maxime