Skip to contentSkip to conversation

drm/tiny: Add driver for Solomon SSD1307 OLED displays

PATCH Superseded Javier Martinez Canillas 9 participants 56 messages Jan 31, 2022 – Mar 14, 2022

Subsystems (4)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#17 lore raw

PATCH 2/4 drm/format-helper: Add drm_fb_gray8_to_mono_reversed()

In reply to Javier Martinez Canillas

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

This helper function was based on repaper_gray8_to_mono_reversed() from the drivers/gpu/drm/tiny/repaper.c driver.

---

 drivers/gpu/drm/drm_format_helper.c | 35 +++++++++++++++++++++++++++++
 include/drm/drm_format_helper.h     |  2 ++
 2 files changed, 37 insertions(+)
drivers/gpu/drm/drm_format_helper.c +35 -0
index 0f28dd2bdd72..bf477c136082 100644
@@ -584,3 +584,38 @@ int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for
 	return -EINVAL;
 }
 EXPORT_SYMBOL(drm_fb_blit_toio);
+
+/**
+ * drm_fb_gray8_to_mono_reversed - Convert grayscale to reversed monochrome
+ * @dst: reversed monochrome destination buffer
+ * @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, void *src, const struct drm_rect *clip)
+{
+	size_t width = drm_rect_width(clip);
+	size_t height = drm_rect_width(clip);
+
+	u8 *mono = dst, *gray8 = src;
+	unsigned int y, xb, i;
+
+	for (y = 0; y < height; y++)
+		for (xb = 0; xb < width / 8; xb++) {
+			u8 byte = 0x00;
+
+			for (i = 0; i < 8; i++) {
+				int x = xb * 8 + i;
+
+				byte >>= 1;
+				if (gray8[y * width + x] >> 7)
+					byte |= BIT(7);
+			}
+			*mono++ = byte;
+		}
+}
+EXPORT_SYMBOL(drm_fb_gray8_to_mono_reversed);
include/drm/drm_format_helper.h +2 -0
index b30ed5de0a33..cd4c8b7c78de 100644
@@ -43,4 +43,6 @@ 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, void *vaddr, const struct drm_rect *clip);
+
 #endif /* __LINUX_DRM_FORMAT_HELPER_H */
Signature · 1 line
2.34.1
#0 lore raw

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
    test009: PASSED
    test010: PASSED
    Benchmarking... 10x10 squares: 412.99 Mpixels/s
    Benchmarking... 20x20 squares: 857.46 Mpixels/s
    Benchmarking... 50x50 squares: 1593.51 Mpixels/s
    test012: PASSED
    Benchmarking... R5 circles: 237.07 Mpixels/s
    Benchmarking... R10 circles: 501.24 Mpixels/s
    Benchmarking... R25 circles: 947.86 Mpixels/s
    test013: PASSED

Patch #1 adds an I2C connector type since currently there isn't one and I2C drivers use DRM_MODE_CONNECTOR_Unknown or DRM_MODE_CONNECTOR_VIRTUAL.

Patch #2 adds a drm_fb_gray8_to_mono_reversed() DRM format helper since most DRM/KMS user-space don't support bpp 1 displays, so drivers expose a common format that's converted to greyscale and then to monochrome.

Patch #3 adds the driver. The name ssd1307 was used instead of ssd130x (which would be more accurate) to avoid confusion for users who want to migrate from the existing ssd1307fb fbdev driver.

Patch #4 just adds a MAINTAINERS entry for this new DRM driver.

Best regards,
Javier

Javier Martinez Canillas (4):
drm: Add I2C connector type
drm/format-helper: Add drm_fb_gray8_to_mono_reversed() drm/tiny: Add driver for Solomon SSD1307 OLED displays
MAINTAINERS: Add entry for Solomon SSD1307 OLED displays DRM driver

 MAINTAINERS                         |   7 +
 drivers/gpu/drm/drm_connector.c     |   1 +
 drivers/gpu/drm/drm_format_helper.c |  35 +
 drivers/gpu/drm/tiny/Kconfig        |  12 +
 drivers/gpu/drm/tiny/Makefile       |   1 +
 drivers/gpu/drm/tiny/ssd1307.c      | 976 ++++++++++++++++++++++++++++
 include/drm/drm_format_helper.h     |   2 +
 include/uapi/drm/drm_mode.h         |   1 +
 8 files changed, 1035 insertions(+)
 create mode 100644 drivers/gpu/drm/tiny/ssd1307.c
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/4 drm: Add I2C connector type

There isn't a connector type for display controllers accesed through I2C, most drivers use DRM_MODE_CONNECTOR_Unknown or DRM_MODE_CONNECTOR_VIRTUAL.

Add an I2C connector type to match the actual connector.

As Noralf Trønnes mentions in commit fc06bf1d76d6 ("drm: Add SPI connector type"), user-space should be able to cope with a connector type that does not yet understand.

Tested with modetest -M ssd1307 -c and shows the connector as unknown-1.

---

 drivers/gpu/drm/drm_connector.c | 1 +
 include/uapi/drm/drm_mode.h     | 1 +
 2 files changed, 2 insertions(+)
drivers/gpu/drm/drm_connector.c +1 -0
index a50c82bc2b2f..975a7525a508 100644
@@ -105,6 +105,7 @@ static struct drm_conn_prop_enum_list drm_connector_enum_list[] = {
 	{ DRM_MODE_CONNECTOR_WRITEBACK, "Writeback" },
 	{ DRM_MODE_CONNECTOR_SPI, "SPI" },
 	{ DRM_MODE_CONNECTOR_USB, "USB" },
+	{ DRM_MODE_CONNECTOR_I2C, "I2C" },
 };
 
 void drm_connector_ida_init(void)
include/uapi/drm/drm_mode.h +1 -0
index e1e351682872..d6d6288242db 100644
@@ -421,6 +421,7 @@ enum drm_mode_subconnector {
 #define DRM_MODE_CONNECTOR_WRITEBACK	18
 #define DRM_MODE_CONNECTOR_SPI		19
 #define DRM_MODE_CONNECTOR_USB		20
+#define DRM_MODE_CONNECTOR_I2C		21
 
 /**
  * struct drm_mode_get_connector - Get connector metadata.
Signature · 1 line
2.34.1
#23 lore raw
In reply to Javier Martinez Canillas

This driver only advertises XRGB8888 in ssd1307_formats. It would be nice to expose R8 as well so that user-space can directly produce suitable buffers. It would also be nice to have some kind of preferred format, so that user-space knows R8 is preferred over XRGB8888.

#24 lore raw
Quoted 4 lines · Simon Ser

This driver only advertises XRGB8888 in ssd1307_formats. It would be nice to expose R8 as well so that user-space can directly produce suitable buffers. It would also be nice to have some kind of preferred format, so that user-space knows R8 is preferred over XRGB8888.

Hm, since the format used by the hw is actually R1, adding that to drm_fourcc.h would be even better.

Let me know if you want me to type up any of the user-space bits.

Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] drm: Add I2C connector type

In reply to Javier Martinez Canillas
Quoted 10 lines · Javier Martinez Canillas

There isn't a connector type for display controllers accesed through I2C, most drivers use DRM_MODE_CONNECTOR_Unknown or DRM_MODE_CONNECTOR_VIRTUAL.

Add an I2C connector type to match the actual connector.

As Noralf Trønnes mentions in commit fc06bf1d76d6 ("drm: Add SPI connector type"), user-space should be able to cope with a connector type that does not yet understand.

Tested with modetest -M ssd1307 -c and shows the connector as unknown-1.

I had expected unknown-21??

Quoted 2 lines
Quoted 32 lines

---

 drivers/gpu/drm/drm_connector.c | 1 +
 include/uapi/drm/drm_mode.h     | 1 +
 2 files changed, 2 insertions(+)
drivers/gpu/drm/drm_connector.c +1 -0
index a50c82bc2b2f..975a7525a508 100644
@@ -105,6 +105,7 @@ static struct drm_conn_prop_enum_list drm_connector_enum_list[] = {
 	{ DRM_MODE_CONNECTOR_WRITEBACK, "Writeback" },
 	{ DRM_MODE_CONNECTOR_SPI, "SPI" },
 	{ DRM_MODE_CONNECTOR_USB, "USB" },
+	{ DRM_MODE_CONNECTOR_I2C, "I2C" },
 };
 
 void drm_connector_ida_init(void)
include/uapi/drm/drm_mode.h +1 -0
index e1e351682872..d6d6288242db 100644
@@ -421,6 +421,7 @@ enum drm_mode_subconnector {
 #define DRM_MODE_CONNECTOR_WRITEBACK	18
 #define DRM_MODE_CONNECTOR_SPI		19
 #define DRM_MODE_CONNECTOR_USB		20
+#define DRM_MODE_CONNECTOR_I2C		21
 
 /**
  * struct drm_mode_get_connector - Get connector metadata.
Signature · 1 line
2.34.1
#38 lore raw
In reply to Javier Martinez Canillas

Hi Javier,

Quoted 5 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.

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:

Impressed how fast you did this!
Saw the picture you posted a link to on irc - nice.

Quoted 3 lines

Patch #3 adds the driver. The name ssd1307 was used instead of ssd130x (which would be more accurate) to avoid confusion for users who want to migrate from the existing ssd1307fb fbdev driver.

Looking forward the name ssd130x would make more sense. There is only so many existing users and a potential of much more new users. So in my color of the world the naming that benefits the most users wins.

Sam

#25 lore raw
In reply to Simon Ser

Hello Simon,

Thanks for your feedback.

Quoted 10 lines · Simon Ser
Quoted 4 lines · Simon Ser

This driver only advertises XRGB8888 in ssd1307_formats. It would be nice to expose R8 as well so that user-space can directly produce suitable buffers. It would also be nice to have some kind of preferred format, so that user-space knows R8 is preferred over XRGB8888.

Hm, since the format used by the hw is actually R1, adding that to drm_fourcc.h would be even better.

Yes, agreed that would be nice. We discussed this already with Thomas and my suggestion was to land the driver as is, advertising XRGB8888. Which is also what the other driver using monochrome does (drivers/gpu/drm/tiny/repaper.c):

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

As a follow-up we can wire up al the needed bits to have a DRM/KMS driver that could expose a R1 format.

Quoted 2 lines

Let me know if you want me to type up any of the user-space bits.

Thanks! I also could help to add the needed support in the user-space stack.

Best reagards,

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

Re: [PATCH 1/4] drm: Add I2C connector type

In reply to Sam Ravnborg
Quoted 4 lines · Sam Ravnborg
Quoted 3 lines · Javier Martinez Canillas

There isn't a connector type for display controllers accesed through I2C, most drivers use DRM_MODE_CONNECTOR_Unknown or DRM_MODE_CONNECTOR_VIRTUAL.

Quoted 9 lines
Quoted 7 lines

Add an I2C connector type to match the actual connector.

As Noralf Trønnes mentions in commit fc06bf1d76d6 ("drm: Add SPI connector type"), user-space should be able to cope with a connector type that does not yet understand.

Tested with modetest -M ssd1307 -c and shows the connector as unknown-1.

I had expected unknown-21??

As you pointed out in patch 3/4, I forgot to change DRM_MODE_CONNECTOR_Unknown to DRM_MODE_CONNECTOR_I2C after adding this patch...

Quoted 4 lines
Quoted 2 lines
Quoted 1 line

---

Thanks!

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Linux Engineering
Red Hat
#39 lore raw
In reply to Sam Ravnborg
Quoted 11 lines · Sam Ravnborg

Hi Javier,

Quoted 5 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.

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:

Impressed how fast you did this!
Saw the picture you posted a link to on irc - nice.

Thanks :)

What's impressive is how many helper functions the DRM core has, so typing a new DRM driver is something that could be achieved in a few hours. Which was one of my goals with this experiment, to understand how much effort would be for a developer with no prior experience with DRM to port a fbdev driver.

Quoted 8 lines
Quoted 3 lines

Patch #3 adds the driver. The name ssd1307 was used instead of ssd130x (which would be more accurate) to avoid confusion for users who want to migrate from the existing ssd1307fb fbdev driver.

Looking forward the name ssd130x would make more sense. There is only so many existing users and a potential of much more new users. So in my color of the world the naming that benefits the most users wins.

Agreed. That's also what Andy suggested and makes a lot of sense to me.

Quoted 2 lines

Sam

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Linux Engineering
Red Hat
#26 lore raw
In reply to Simon Ser
Quoted 9 lines · Simon Ser
Quoted 4 lines · Simon Ser

This driver only advertises XRGB8888 in ssd1307_formats. It would be nice to expose R8 as well so that user-space can directly produce suitable buffers. It would also be nice to have some kind of preferred format, so that user-space knows R8 is preferred over XRGB8888.

Hm, since the format used by the hw is actually R1, adding that to drm_fourcc.h would be even better.

What's the story with the Rn formats?
The comments say "n bpp Red", while this is a monochrome (even inverted) display?

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

#27 lore raw
Quoted 4 lines · Geert Uytterhoeven

What's the story with the Rn formats?

The comments say "n bpp Red", while this is a monochrome (even inverted) display?

I don't think the color matters that much. "Red" was picked just because it was an arbitrary color, to make the difference with e.g. C8. Or am I mistaken?

#28 lore raw

Hi Simon,

Quoted 8 lines · Simon Ser
Quoted 4 lines · Geert Uytterhoeven

What's the story with the Rn formats?

The comments say "n bpp Red", while this is a monochrome (even inverted) display?

I don't think the color matters that much. "Red" was picked just because it was an arbitrary color, to make the difference with e.g. C8. Or am I mistaken?

I'd expect 8-bit grayscale to be Y8 instead.

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

#32 lore raw
In reply to Simon Ser
Quoted 10 lines · Simon Ser
Quoted 4 lines · Geert Uytterhoeven

What's the story with the Rn formats?

The comments say "n bpp Red", while this is a monochrome (even inverted) display?

I don't think the color matters that much. "Red" was picked just because it was an arbitrary color, to make the difference with e.g. C8. Or am I mistaken?

The red comes from gl, where with shaders it really doesn't matter what meaning you attach to channels, but really just how many you have. So 2-channel formats are called RxGx, 3-channel RxGxBx, 4-channel RxGxBxAx and single-channel Rx. And we use drm_fourcc for interop in general, hence why these exist.

We should probably make a comment that this really isn't a red channel when used for display it's a greyscale/intensity format. Aside from that documentation gap I think reusing Rx formats for greyscale/intensity for display makes perfect sense. -Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#53 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.

Thanks for your series!

I'll give 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 9 lines

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

Oh, fake 32-bpp truecolor ;-)

Does it run modetest, too?

I'm trying to get modetest working on my atari DRM driver. Comparing to the cirrus driver doesn't help much, as modetest doesn't seem to work with the cirrus driver (modified to not do hardware access, as I don't have cirrus hardware):

    # modetest -M cirrus -s 31:1024x768-60Hz
    setting mode 1024x768-60.00Hz on connectors 31, crtc 34
    failed to set gamma: Function not implemented

Does there exist another simple test program for showing something using the DRM API?

Thanks!

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

#40 lore raw
In reply to Sam Ravnborg
Quoted 1 line · Sam Ravnborg

On Mon, Jan 31, 2022 at 09:12:20PM +0100, Javier Martinez Canillas wrote:

...

Quoted 7 lines
Quoted 3 lines

Patch #3 adds the driver. The name ssd1307 was used instead of ssd130x (which would be more accurate) to avoid confusion for users who want to migrate from the existing ssd1307fb fbdev driver.

Looking forward the name ssd130x would make more sense. There is only so many existing users and a potential of much more new users. So in my color of the world the naming that benefits the most users wins.

It depends if the binding is going to be preserved. Also this series doesn't answer to the question what to do with the old driver.

If you leave it, I would expect the backward compatibility, otherwise the series misses removal of the old driver.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#33 lore raw
In reply to Daniel Vetter
Quoted 18 lines · Daniel Vetter
Quoted 10 lines · Simon Ser
Quoted 4 lines · Geert Uytterhoeven

What's the story with the Rn formats?

The comments say "n bpp Red", while this is a monochrome (even inverted) display?

I don't think the color matters that much. "Red" was picked just because it was an arbitrary color, to make the difference with e.g. C8. Or am I mistaken?

The red comes from gl, where with shaders it really doesn't matter what meaning you attach to channels, but really just how many you have. So 2-channel formats are called RxGx, 3-channel RxGxBx, 4-channel RxGxBxAx and single-channel Rx. And we use drm_fourcc for interop in general, hence why these exist.

Quoted 5 lines

We should probably make a comment that this really isn't a red channel when used for display it's a greyscale/intensity format. Aside from that documentation gap I think reusing Rx formats for greyscale/intensity for display makes perfect sense. -Daniel

To sump up the conversation in the #dri-devel channel, these drivers should support the following formats:

1) Dx (Daniel suggested that for darkness, but inverted mono)
2) Rx (single-channel for grayscale)
3) RxGxBxAx (4-channel fake 32-bpp truecolor)

The format preference will be in that order, so if user-space is able to use Dx then there won't be a need for any conversion and just the native format will be used.

If using Rx then only a Rx -> Dx conversion will happen and the last format will require the less performant RxGxBxAx -> Rx -> Dx path.

But we still need RxGxBxAx as a fallback for compatibility with the existing user-space, so all this could be done as a follow-up as an optimization and shouldn't block monochromatic panel drivers IMO.

Best regards,

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

Re: [PATCH 2/4] drm/format-helper: Add drm_fb_gray8_to_mono_reversed()

In reply to Javier Martinez Canillas

Hi

Am 31.01.22 um 21:12 schrieb Javier Martinez Canillas:

Quoted 5 lines

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

This helper function was based on repaper_gray8_to_mono_reversed() from the drivers/gpu/drm/tiny/repaper.c driver.

You could convert repaper to the new helper.

Quoted 19 lines

---

  drivers/gpu/drm/drm_format_helper.c | 35 +++++++++++++++++++++++++++++
  include/drm/drm_format_helper.h     |  2 ++
  2 files changed, 37 insertions(+)
drivers/gpu/drm/drm_format_helper.c +3 -0
index 0f28dd2bdd72..bf477c136082 100644
@@ -584,3 +584,38 @@ int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for
  	return -EINVAL;
  }
  EXPORT_SYMBOL(drm_fb_blit_toio);
+
+/**
+ * drm_fb_gray8_to_mono_reversed - Convert grayscale to reversed monochrome

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

Quoted 10 lines
drivers/gpu/drm/drm_format_helper.c +10 -0
+ * @dst: reversed monochrome destination buffer
+ * @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, void *src, const struct drm_rect *clip)

IMHO it would be better to have a function that converts xrgb8888 to mono and let it handle the intermediate step of gray8.

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

Quoted 9 lines
drivers/gpu/drm/drm_format_helper.c +9 -0
+{
+	size_t width = drm_rect_width(clip);
+	size_t height = drm_rect_width(clip);
+
+	u8 *mono = dst, *gray8 = src;
+	unsigned int y, xb, i;
+
+	for (y = 0; y < height; y++)
+		for (xb = 0; xb < width / 8; xb++) {

The inner loop should probably go into a separate helper function. See the drm_fb_*_line() helpers in this file

At some point, we's want to have a single blit helper that takes source and destination formats/buffers. It would then pick the correct per-line helper for the conversion. So yeah, we'd want something composable.

Best regards
Thomas

Quoted 24 lines
drivers/gpu/drm/drm_format_helper.c +13 -0
+			u8 byte = 0x00;
+
+			for (i = 0; i < 8; i++) {
+				int x = xb * 8 + i;
+
+				byte >>= 1;
+				if (gray8[y * width + x] >> 7)
+					byte |= BIT(7);
+			}
+			*mono++ = byte;
+		}
+}
+EXPORT_SYMBOL(drm_fb_gray8_to_mono_reversed);
include/drm/drm_format_helper.h +2 -0
index b30ed5de0a33..cd4c8b7c78de 100644
@@ -43,4 +43,6 @@ 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, void *vaddr, 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
#29 lore raw
In reply to Geert Uytterhoeven

Hi

Am 01.02.22 um 09:36 schrieb Geert Uytterhoeven:

Quoted 6 lines

Hi Simon,

Quoted 3 lines · Simon Ser
Quoted 2 lines · Geert Uytterhoeven

What's the story with the Rn formats?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

The comments say "n bpp Red", while this is a monochrome (even inverted) display?

I don't think the color matters that much. "Red" was picked just because it was an arbitrary color, to make the difference with e.g. C8. Or am I mistaken?

I'd expect 8-bit grayscale to be Y8 instead.

I like this naming, but DRM_FORMAT_R8 is uapi already. :/ If anything, we could add Yn formats in addition to existing Rn formats.

Best regards
Thomas

Quoted 11 lines

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

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
#30 lore raw
Quoted 6 lines · Thomas Zimmermann

Am 01.02.22 um 09:36 schrieb Geert Uytterhoeven:

Quoted 1 line

I'd expect 8-bit grayscale to be Y8 instead.

I like this naming, but DRM_FORMAT_R8 is uapi already. :/ If anything, we could add Yn formats in addition to existing Rn formats.

Need to be a bit careful, e.g. Y210 exists and isn't a grayscale format. This could be confusing.

#31 lore raw

Hi

Am 01.02.22 um 11:11 schrieb Simon Ser:

Quoted 11 lines · Thomas Zimmermann
Quoted 7 lines

Am 01.02.22 um 09:36 schrieb Geert Uytterhoeven:

Quoted 1 line

I'd expect 8-bit grayscale to be Y8 instead.

I like this naming, but DRM_FORMAT_R8 is uapi already. :/ If anything, we could add Yn formats in addition to existing Rn formats.

Need to be a bit careful, e.g. Y210 exists and isn't a grayscale format. This could be confusing.

Well, ok. How about 'I' as in 'intensity'? There aren't too many drivers supporting this yet. So if we want to find a better name, now's the time.

Best regards
Thomas

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
#55 lore raw
In reply to Geert Uytterhoeven

Hello Geert,

Quoted 4 lines · Geert Uytterhoeven

Hi Javier,

On Mon, Jan 31, 2022 at 9:12 PM Javier Martinez Canillas <[email protected]> wrote:

Quoted 9 lines
Quoted 2 lines

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.

Thanks for your series!

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

Awesome! let me know if you have any issues. I keep an update-to-date version at https://github.com/martinezjavier/linux/tree/ssd1307

Quoted 12 lines
Quoted 9 lines

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

Oh, fake 32-bpp truecolor ;-)

Yes :) that's what the repaper drivers does to have maximum compatibility with existing user-space and I followed the same.

Quoted 2 lines

Does it run modetest, too?

It does, yes. And for example modetest -M ssd1307 will print all the info about encoders, connectors, CRTs, etc.

Quoted 9 lines

I'm trying to get modetest working on my atari DRM driver. Comparing to the cirrus driver doesn't help much, as modetest doesn't seem to work with the cirrus driver (modified to not do hardware access, as I don't have cirrus hardware):

    # modetest -M cirrus -s 31:1024x768-60Hz
    setting mode 1024x768-60.00Hz on connectors 31, crtc 34
    failed to set gamma: Function not implemented
# modetest -M ssd1307 -c -s 31:128x64-0.12Hz
...
setting mode 128x64-0.12Hz on connectors 31, crtc 33
failed to set gamma: Function not implemented

this seems to be a bug in modetest. I found a patch posted some time ago but never landed: https://www.spinics.net/lists/dri-devel/msg251356.html

Quoted 3 lines

Does there exist another simple test program for showing something using the DRM API?

I tested with plymouth and gdm that make use of the DRM API, they do start and I see something on the screen but don't really handle that well the fact that's a 128x64 resolution.

I didn't test with more DRM programs because was mostly interested in making sure that the fbdev emulation was working correctly.

Noticed that Simon shared some simple examples, I'll give them a try.

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Linux Engineering
Red Hat
#34 lore raw
In reply to Javier Martinez Canillas
Quoted 25 lines · On Tue, 1 Feb 2022 10:49:03 +0100 Javier Martinez Canillas…
Quoted 18 lines · Daniel Vetter
Quoted 10 lines · Simon Ser
Quoted 4 lines · Geert Uytterhoeven

What's the story with the Rn formats?

The comments say "n bpp Red", while this is a monochrome (even inverted) display?

I don't think the color matters that much. "Red" was picked just because it was an arbitrary color, to make the difference with e.g. C8. Or am I mistaken?

The red comes from gl, where with shaders it really doesn't matter what meaning you attach to channels, but really just how many you have. So 2-channel formats are called RxGx, 3-channel RxGxBx, 4-channel RxGxBxAx and single-channel Rx. And we use drm_fourcc for interop in general, hence why these exist.

Quoted 5 lines

We should probably make a comment that this really isn't a red channel when used for display it's a greyscale/intensity format. Aside from that documentation gap I think reusing Rx formats for greyscale/intensity for display makes perfect sense. -Daniel

Quoted 4 lines

To sump up the conversation in the #dri-devel channel, these drivers should support the following formats:

1) Dx (Daniel suggested that for darkness, but inverted mono)

Did you consider format C1 instead?

To my understanding, the C formats are paletted, which would also fit very nicely semantically. You have an enumerated list of pixel values and each of them produces some arbitrary color on screen. This would fit e.g. blue/white LCD panels nicely.

The little problem there is the palette.

C8 format is traditionally translated to RGB triplets through GAMMA LUT. Therefore the display itself is still three-channel, it's just the framebuffer format that is single-channel. But now, we are dealing with truly paletted displays. Furthermore, the palette is fixed, ingrained in the panel hardware.

So we would probably need a new KMS property for the fixed palette of the panel. What would it be called? Would it be a connector property?

The property would be a read-only blob, an array that maps Cx values to "colors". How do we represent "colors"? How do we accommodate C1, C2, C4 and C8 with the same blob?

Since the blob is a mapping from color index to "color", and the array in the blob has N entries, we could simply say that Cx integer value is the color index. If the Cx you use does not go up to N, then you miss some colors. If the Cx you use can go higher than N, then Cx values >= N will clamp to N-1, for example. Of course, if your panel palette has only 4 entries, you can expose C1 and C2 and have no reason to expose C4 or C8, avoiding the Cx >= N issue.

How do we define the array contents then, the "colors"... plain old RGB triplets do not mean much[1], but that would be better than nothing. I also suppose that people would not be keen on seeing something like CIE 1931 XYZ or Lab values, even though those would probably have the most useful definition. Coming up with those values properly would require a colorimeter. As a compromise, maybe we could use an RGB triplet, and assume sRGB SDR color space and transfer function, just like we do with all displays whether they are that or not. If someone needs to know better, then they can profile the display. sRGB triplets would likely give enough intuition to what color the indices result in, that it could be used in automated color conversions or quantizations from larger color spaces like sRGB with some rough degree of color similarity.

It is a lot of hassle, but it would have a clear benefit: userspace would know very well how the display behaves (what colors it shows, roughly), and you could use Cx formats to drive a panel in its "native" format.

Possible problems are around interactions with the old GAMMA property, which is traditionally used for the C8 palette. But if you have a fixed-palette panel, then maybe you wouldn't expose GAMMA property on the CRTC at all?

I have no idea how this would map to fbdev API though.

[1] https://gitlab.freedesktop.org/pq/color-and-hdr/-/blob/main/doc/pixels_color.md

Thanks,
pq

Quoted 15 lines

2) Rx (single-channel for grayscale)
3) RxGxBxAx (4-channel fake 32-bpp truecolor)

The format preference will be in that order, so if user-space is able to use Dx then there won't be a need for any conversion and just the native format will be used.

If using Rx then only a Rx -> Dx conversion will happen and the last format will require the less performant RxGxBxAx -> Rx -> Dx path.

But we still need RxGxBxAx as a fallback for compatibility with the existing user-space, so all this could be done as a follow-up as an optimization and shouldn't block monochromatic panel drivers IMO.

Best regards,

#35 lore raw

Hi Pekka,

Quoted 25 lines · Pekka Paalanen
Quoted 23 lines · On Tue, 1 Feb 2022 10:49:03 +0100 Javier Martinez Canillas…
Quoted 21 lines · Daniel Vetter
Quoted 8 lines · Simon Ser
Quoted 4 lines · Geert Uytterhoeven

What's the story with the Rn formats?

The comments say "n bpp Red", while this is a monochrome (even inverted) display?

I don't think the color matters that much. "Red" was picked just because it was an arbitrary color, to make the difference with e.g. C8. Or am I mistaken?

The red comes from gl, where with shaders it really doesn't matter what meaning you attach to channels, but really just how many you have. So 2-channel formats are called RxGx, 3-channel RxGxBx, 4-channel RxGxBxAx and single-channel Rx. And we use drm_fourcc for interop in general, hence why these exist.

We should probably make a comment that this really isn't a red channel when used for display it's a greyscale/intensity format. Aside from that documentation gap I think reusing Rx formats for greyscale/intensity for display makes perfect sense. -Daniel

Quoted 6 lines
Quoted 4 lines

To sump up the conversation in the #dri-devel channel, these drivers should support the following formats:

1) Dx (Daniel suggested that for darkness, but inverted mono)

Did you consider format C1 instead?

That would be a 2-color display, which is not necessarily black and white. Cfr. Amiga or Atari bit planes with bpp=1. That's why fbdev has separate visuals for monochrome.

Quoted 1 line

I have no idea how this would map to fbdev API though.

    #define FB_VISUAL_MONO01                0       /* Monochr.
1=Black 0=White */
    #define FB_VISUAL_MONO10                1       /* Monochr.
1=White 0=Black */
    #define FB_VISUAL_TRUECOLOR             2       /* True color   */

The above is RGB (or grayscale, see below).

    #define FB_VISUAL_PSEUDOCOLOR           3       /* Pseudo color

(like atari) */

Palette

    #define FB_VISUAL_DIRECTCOLOR           4       /* Direct color */

Usually used as RGB with gamma correction, but the actual hardware is more flexible.

    #define FB_VISUAL_STATIC_PSEUDOCOLOR    5       /* Pseudo color readonly */

Fixed palette

And:

    struct fb_var_screeninfo {
            ...
            __u32 grayscale;                /* 0 = color, 1 = grayscale,    */

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

#19 lore raw

Re: [PATCH 2/4] drm/format-helper: Add drm_fb_gray8_to_mono_reversed()

In reply to Thomas Zimmermann
Quoted 57 lines · On Tue, 1 Feb 2022 10:59:43 +0100 Thomas Zimmermann <[email protected]> wrote:

Hi

Am 31.01.22 um 21:12 schrieb Javier Martinez Canillas:

Quoted 5 lines

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

This helper function was based on repaper_gray8_to_mono_reversed() from the drivers/gpu/drm/tiny/repaper.c driver.

You could convert repaper to the new helper.

Quoted 19 lines

---

  drivers/gpu/drm/drm_format_helper.c | 35 +++++++++++++++++++++++++++++
  include/drm/drm_format_helper.h     |  2 ++
  2 files changed, 37 insertions(+)
drivers/gpu/drm/drm_format_helper.c +3 -0
index 0f28dd2bdd72..bf477c136082 100644
@@ -584,3 +584,38 @@ int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for
  	return -EINVAL;
  }
  EXPORT_SYMBOL(drm_fb_blit_toio);
+
+/**
+ * drm_fb_gray8_to_mono_reversed - Convert grayscale to reversed monochrome

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

Quoted 10 lines
drivers/gpu/drm/drm_format_helper.c +10 -0
+ * @dst: reversed monochrome destination buffer
+ * @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, void *src, const struct drm_rect *clip)  

IMHO it would be better to have a function that converts xrgb8888 to mono and let it handle the intermediate step of gray8.

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

Quoted 9 lines
drivers/gpu/drm/drm_format_helper.c +9 -0
+{
+	size_t width = drm_rect_width(clip);
+	size_t height = drm_rect_width(clip);
+
+	u8 *mono = dst, *gray8 = src;
+	unsigned int y, xb, i;
+
+	for (y = 0; y < height; y++)
+		for (xb = 0; xb < width / 8; xb++) {  

The inner loop should probably go into a separate helper function. See the drm_fb_*_line() helpers in this file

Quoted 3 lines

At some point, we's want to have a single blit helper that takes source and destination formats/buffers. It would then pick the correct per-line helper for the conversion. So yeah, we'd want something composable.

Btw. VKMS is going to do blending, and it needs to support various formats, so the latest patches from Igor probably do something similar.

Thanks,
pq

Quoted 17 lines

Best regards
Thomas

Quoted 13 lines
drivers/gpu/drm/drm_format_helper.c +13 -0
+			u8 byte = 0x00;
+
+			for (i = 0; i < 8; i++) {
+				int x = xb * 8 + i;
+
+				byte >>= 1;
+				if (gray8[y * width + x] >> 7)
+					byte |= BIT(7);
+			}
+			*mono++ = byte;
+		}
+}
+EXPORT_SYMBOL(drm_fb_gray8_to_mono_reversed);
#41 lore raw
In reply to Andy Shevchenko
Quoted 8 lines · Andy Shevchenko
Quoted 1 line · Sam Ravnborg

On Mon, Jan 31, 2022 at 09:12:20PM +0100, Javier Martinez Canillas wrote:

...

Quoted 3 lines
Quoted 3 lines

Patch #3 adds the driver. The name ssd1307 was used instead of ssd130x (which would be more accurate) to avoid confusion for users who want to migrate from the existing ssd1307fb fbdev driver.

Quoted 8 lines
Quoted 4 lines

Looking forward the name ssd130x would make more sense. There is only so many existing users and a potential of much more new users. So in my color of the world the naming that benefits the most users wins.

It depends if the binding is going to be preserved. Also this series doesn't answer to the question what to do with the old driver.

I don't plan to remove the old driver (yet). My goal here is to have an answer for Fedora users that might complain that we disabled all the fbdev drivers.

So I wanted to understand the effort involved in porting a fbdev driver to DRM.

Quoted 3 lines

If you leave it, I would expect the backward compatibility, otherwise the series misses removal of the old driver.

I don't see how those two are correlated. You just need different compatible strings to match the new and old drivers. That what was usually done for DRM drivers that were ported. To give an example, the "omapfb" vs "omapdrm".

Since the current binding has a compatible "ssd1305fb-i2c", we could make the new one "ssd1305drm-i2c" or better, just "ssd1305-i2c".

Best regards,

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

Hi Javier,

Quoted 27 lines · Javier Martinez Canillas
Quoted 8 lines · Andy Shevchenko
Quoted 1 line · Sam Ravnborg

On Mon, Jan 31, 2022 at 09:12:20PM +0100, Javier Martinez Canillas wrote:

...

Quoted 3 lines
Quoted 3 lines

Patch #3 adds the driver. The name ssd1307 was used instead of ssd130x (which would be more accurate) to avoid confusion for users who want to migrate from the existing ssd1307fb fbdev driver.

Quoted 8 lines
Quoted 4 lines

Looking forward the name ssd130x would make more sense. There is only so many existing users and a potential of much more new users. So in my color of the world the naming that benefits the most users wins.

It depends if the binding is going to be preserved. Also this series doesn't answer to the question what to do with the old driver.

I don't plan to remove the old driver (yet). My goal here is to have an answer for Fedora users that might complain that we disabled all the fbdev drivers.

So I wanted to understand the effort involved in porting a fbdev driver to DRM.

Quoted 3 lines

If you leave it, I would expect the backward compatibility, otherwise the series misses removal of the old driver.

Quoted 6 lines

I don't see how those two are correlated. You just need different compatible strings to match the new and old drivers. That what was usually done for DRM drivers that were ported. To give an example, the "omapfb" vs "omapdrm".

Since the current binding has a compatible "ssd1305fb-i2c", we could make the new one "ssd1305drm-i2c" or better, just "ssd1305-i2c".

DT describes hardware, not software policy.
If the hardware is the same, the DT bindings should stay the same.

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

#20 lore raw

Re: [PATCH 2/4] drm/format-helper: Add drm_fb_gray8_to_mono_reversed()

In reply to Thomas Zimmermann

Hello Thomas,

Thanks a lot for your feedback.

Quoted 11 lines · Thomas Zimmermann

Hi

Am 31.01.22 um 21:12 schrieb Javier Martinez Canillas:

Quoted 5 lines

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

This helper function was based on repaper_gray8_to_mono_reversed() from the drivers/gpu/drm/tiny/repaper.c driver.

You could convert repaper to the new helper.

Yes, I plan to do it but was out of scope for this patch series.

Quoted 24 lines
Quoted 24 lines

---

  drivers/gpu/drm/drm_format_helper.c | 35 +++++++++++++++++++++++++++++
  include/drm/drm_format_helper.h     |  2 ++
  2 files changed, 37 insertions(+)
drivers/gpu/drm/drm_format_helper.c +8 -0
index 0f28dd2bdd72..bf477c136082 100644
@@ -584,3 +584,38 @@ int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for
  	return -EINVAL;
  }
  EXPORT_SYMBOL(drm_fb_blit_toio);
+
+/**
+ * drm_fb_gray8_to_mono_reversed - Convert grayscale to reversed monochrome
+ * @dst: reversed monochrome destination buffer
+ * @src: 8-bit grayscale source buffer
+ * @clip: Clip rectangle area to copy
+ *
+ * DRM doesn't have native monochrome or grayscale support.
Quoted 9 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 599

Quoted 5 lines
drivers/gpu/drm/drm_format_helper.c +5 -0
+ * 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, void *src, const struct drm_rect *clip)

IMHO it would be better to have a function that converts xrgb8888 to mono and let it handle the intermediate step of gray8.

That's a good idea. I'll add that too.

Quoted 13 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 608

Quoted 9 lines
drivers/gpu/drm/drm_format_helper.c +9 -0
+{
+	size_t width = drm_rect_width(clip);
+	size_t height = drm_rect_width(clip);
+
+	u8 *mono = dst, *gray8 = src;
+	unsigned int y, xb, i;
+
+	for (y = 0; y < height; y++)
+		for (xb = 0; xb < width / 8; xb++) {

The inner loop should probably go into a separate helper function. See the drm_fb_*_line() helpers in this file

Quoted 4 lines

At some point, we's want to have a single blit helper that takes source and destination formats/buffers. It would then pick the correct per-line helper for the conversion. So yeah, we'd want something composable.

Agreed. I'll split that into a separate helper function.

Best regards,

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

Re: [PATCH 1/4] drm: Add I2C connector type

In reply to Sam Ravnborg

Den 31.01.2022 21.52, skrev Sam Ravnborg:

Quoted 10 lines · Javier Martinez Canillas
Quoted 9 lines

There isn't a connector type for display controllers accesed through I2C, most drivers use DRM_MODE_CONNECTOR_Unknown or DRM_MODE_CONNECTOR_VIRTUAL.

Add an I2C connector type to match the actual connector.

As Noralf Trønnes mentions in commit fc06bf1d76d6 ("drm: Add SPI connector type"), user-space should be able to cope with a connector type that does not yet understand.

It turned out that I wasn't entirely correct here, mpv didn't cope with unknown types. In the PR to add support Emil Velikov wondered if libdrm should handle these connector names:
https://github.com/mpv-player/mpv/pull/8989#issuecomment-879187711

Quoted 6 lines
Quoted 1 line

Tested with modetest -M ssd1307 -c and shows the connector as unknown-1.

I had expected unknown-21??

Quoted 2 lines

Sam, didn't you and Laurent discuss adding DRM_MODE_CONNECTOR_PANEL for such a use case?

If someone adds parallel bus support to the MIPI DBI helper, there will be one more connector type (I wonder what that one will be called).

Noralf.

Quoted 32 lines
Quoted 32 lines

---

 drivers/gpu/drm/drm_connector.c | 1 +
 include/uapi/drm/drm_mode.h     | 1 +
 2 files changed, 2 insertions(+)
drivers/gpu/drm/drm_connector.c +1 -0
index a50c82bc2b2f..975a7525a508 100644
@@ -105,6 +105,7 @@ static struct drm_conn_prop_enum_list drm_connector_enum_list[] = {
 	{ DRM_MODE_CONNECTOR_WRITEBACK, "Writeback" },
 	{ DRM_MODE_CONNECTOR_SPI, "SPI" },
 	{ DRM_MODE_CONNECTOR_USB, "USB" },
+	{ DRM_MODE_CONNECTOR_I2C, "I2C" },
 };
 
 void drm_connector_ida_init(void)
include/uapi/drm/drm_mode.h +1 -0
index e1e351682872..d6d6288242db 100644
@@ -421,6 +421,7 @@ enum drm_mode_subconnector {
 #define DRM_MODE_CONNECTOR_WRITEBACK	18
 #define DRM_MODE_CONNECTOR_SPI		19
 #define DRM_MODE_CONNECTOR_USB		20
+#define DRM_MODE_CONNECTOR_I2C		21
 
 /**
  * struct drm_mode_get_connector - Get connector metadata.
Signature · 1 line
2.34.1
#5 lore raw

Re: [PATCH 1/4] drm: Add I2C connector type

Hello Noralf,

Quoted 14 lines · Noralf Trønnes

Den 31.01.2022 21.52, skrev Sam Ravnborg:

Quoted 10 lines · Javier Martinez Canillas
Quoted 9 lines

There isn't a connector type for display controllers accesed through I2C, most drivers use DRM_MODE_CONNECTOR_Unknown or DRM_MODE_CONNECTOR_VIRTUAL.

Add an I2C connector type to match the actual connector.

As Noralf Trønnes mentions in commit fc06bf1d76d6 ("drm: Add SPI connector type"), user-space should be able to cope with a connector type that does not yet understand.

Quoted 5 lines

It turned out that I wasn't entirely correct here, mpv didn't cope with unknown types. In the PR to add support Emil Velikov wondered if libdrm should handle these connector names:
https://github.com/mpv-player/mpv/pull/8989#issuecomment-879187711

I see, thanks for the information. What should we do then, just use the type DRM_MODE_CONNECTOR_Unknown then ?

Best regards,

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

Hello Geert,

On 2/1/22 12:38, Geert Uytterhoeven wrote:

[snip]

Quoted 7 lines
Quoted 3 lines

Since the current binding has a compatible "ssd1305fb-i2c", we could make the new one "ssd1305drm-i2c" or better, just "ssd1305-i2c".

DT describes hardware, not software policy.
If the hardware is the same, the DT bindings should stay the same.

Yes I know that but the thing is that the current binding don't describe the hardware correctly. For instance, don't use a backlight DT node as a property of the panel and have this "fb" suffix in the compatible strings.

Having said that, my opinion is that we should just keep with the existing bindings and make compatible to that even if isn't completely correct.

Since that will ease adoption of the new DRM driver and allow users to use it without the need to update their DTBs.

Best regards,

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

Re: [PATCH 1/4] drm: Add I2C connector type

In reply to Javier Martinez Canillas

Den 01.02.2022 14.06, skrev Javier Martinez Canillas:

Quoted 17 lines

Hello Noralf,

Quoted 14 lines · Noralf Trønnes

Den 31.01.2022 21.52, skrev Sam Ravnborg:

Quoted 10 lines · Javier Martinez Canillas
Quoted 9 lines

There isn't a connector type for display controllers accesed through I2C, most drivers use DRM_MODE_CONNECTOR_Unknown or DRM_MODE_CONNECTOR_VIRTUAL.

Add an I2C connector type to match the actual connector.

As Noralf Trønnes mentions in commit fc06bf1d76d6 ("drm: Add SPI connector type"), user-space should be able to cope with a connector type that does not yet understand.

Quoted 9 lines
Quoted 5 lines

It turned out that I wasn't entirely correct here, mpv didn't cope with unknown types. In the PR to add support Emil Velikov wondered if libdrm should handle these connector names:
https://github.com/mpv-player/mpv/pull/8989#issuecomment-879187711

I see, thanks for the information. What should we do then, just use the type DRM_MODE_CONNECTOR_Unknown then ?

Not really, I just wanted to point out that it could be that not all userspace will handle an unknown connector type (I just checked the DE's at the time). I haven't seen any issues after adding the SPI type so it can't be that many apps that has problems. Adding to that a tiny monochrome display is limited in which applications it will encounter I guess :) It was after adding the USB type that I discovered that mpv didn't work.

Noralf.

#7 lore raw

Re: [PATCH 1/4] drm: Add I2C connector type

In reply to Noralf Trønnes
Quoted 30 lines · Noralf Trønnes

Den 01.02.2022 14.06, skrev Javier Martinez Canillas:

Quoted 17 lines

Hello Noralf,

Quoted 14 lines · Noralf Trønnes

Den 31.01.2022 21.52, skrev Sam Ravnborg:

Quoted 10 lines · Javier Martinez Canillas
Quoted 9 lines

There isn't a connector type for display controllers accesed through I2C, most drivers use DRM_MODE_CONNECTOR_Unknown or DRM_MODE_CONNECTOR_VIRTUAL.

Add an I2C connector type to match the actual connector.

As Noralf Trønnes mentions in commit fc06bf1d76d6 ("drm: Add SPI connector type"), user-space should be able to cope with a connector type that does not yet understand.

Quoted 9 lines
Quoted 5 lines

It turned out that I wasn't entirely correct here, mpv didn't cope with unknown types. In the PR to add support Emil Velikov wondered if libdrm should handle these connector names:
https://github.com/mpv-player/mpv/pull/8989#issuecomment-879187711

I see, thanks for the information. What should we do then, just use the type DRM_MODE_CONNECTOR_Unknown then ?

Quoted 8 lines

Not really, I just wanted to point out that it could be that not all userspace will handle an unknown connector type (I just checked the DE's at the time). I haven't seen any issues after adding the SPI type so it can't be that many apps that has problems. Adding to that a tiny monochrome display is limited in which applications it will encounter I guess :) It was after adding the USB type that I discovered that mpv didn't work.

Anything we do for this rather obscure hardware certainly won't be an issue for most applications :)

But I wasn't sure if your previous comment meant that you were nacking $subject. Glad that we can go ahead and describe the correct type then.

Best regards,

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

Hi Javier,

Quoted 12 lines · Javier Martinez Canillas
Quoted 6 lines · Geert Uytterhoeven
Quoted 2 lines

Since the current binding has a compatible "ssd1305fb-i2c", we could make the new one "ssd1305drm-i2c" or better, just "ssd1305-i2c".

DT describes hardware, not software policy.
If the hardware is the same, the DT bindings should stay the same.

Yes I know that but the thing is that the current binding don't describe the hardware correctly. For instance, don't use a backlight DT node as a property of the panel and have this "fb" suffix in the compatible strings.

Quoted 5 lines

Having said that, my opinion is that we should just keep with the existing bindings and make compatible to that even if isn't completely correct.

Since that will ease adoption of the new DRM driver and allow users to use it without the need to update their DTBs.

To me it looks like the pwms property is not related to the backlight at all, and only needed for some variants?

And the actual backlight code seems to be about internal contrast adjustment?

So if the pwms usage is OK, what other reasons are there to break DT compatibility? IMHO just the "fb" suffix is not a good reason.

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

#9 lore raw

Re: [PATCH 1/4] drm: Add I2C connector type

In reply to Simon Ser

Den 01.02.2022 14.38, skrev Simon Ser:

Quoted 9 lines · Noralf Trønnes
Quoted 4 lines

It turned out that I wasn't entirely correct here, mpv didn't cope with unknown types. In the PR to add support Emil Velikov wondered if libdrm should handle these connector names:

Opened this MR to try to make things easier for user-space:
https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/222

Thanks Simon!

#45 lore raw
In reply to Geert Uytterhoeven

Hello Geert,

Quoted 16 lines · Geert Uytterhoeven

Hi Javier,

Quoted 12 lines · Javier Martinez Canillas
Quoted 6 lines · Geert Uytterhoeven
Quoted 2 lines

Since the current binding has a compatible "ssd1305fb-i2c", we could make the new one "ssd1305drm-i2c" or better, just "ssd1305-i2c".

DT describes hardware, not software policy.
If the hardware is the same, the DT bindings should stay the same.

Yes I know that but the thing is that the current binding don't describe the hardware correctly. For instance, don't use a backlight DT node as a property of the panel and have this "fb" suffix in the compatible strings.

Quoted 9 lines
Quoted 5 lines

Having said that, my opinion is that we should just keep with the existing bindings and make compatible to that even if isn't completely correct.

Since that will ease adoption of the new DRM driver and allow users to use it without the need to update their DTBs.

To me it looks like the pwms property is not related to the backlight at all, and only needed for some variants?

I was reading the datasheets of the ssd1305, ssd1306 and ssd1307. Only the first one mentions anything about a PWM and says:

In phase 3, the OLED driver switches to use current source to drive the OLED pixels and this is the current drive stage. SSD1305 employs PWM (Pulse Width Modulation) method to control the brightness of area color A, B, C, D color individually. The longer the waveform in current drive stage is, the brighter is the pixel and vice versa.

After finishing phase 3, the driver IC will go back to phase 1 to display the next row image data. This threestep cycle is run continuously to refresh image display on OLED panel.

The way I understand this is that the PWM isn't used for the backlight but instead to power the IC and allow to display the actual pixels ?

And this matches what Maxime mentioned in this patch:

https://linux-arm-kernel.infradead.narkive.com/5i44FnQ8/patch-1-2-video-ssd1307fb-add-support-for-ssd1306-oled-controller

The Solomon SSD1306 OLED controller is very similar to the SSD1307, except for the fact that the power is given through an external PWM for the 1307, and while the 1306 can generate its own power without any PWM.

Quoted 6 lines

And the actual backlight code seems to be about internal contrast adjustment?

So if the pwms usage is OK, what other reasons are there to break DT compatibility? IMHO just the "fb" suffix is not a good reason.

Absolutely agreed with you on this. It seems we should just use the existing binding and make the driver compatible with that. The only value is that the drm_panel infrastructure could be used, but making it backward compatible is more worthy IMO.

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

#46 lore raw

Hi Javier,

Quoted 13 lines · Javier Martinez Canillas

Hello Geert,

Quoted 10 lines · Geert Uytterhoeven

Hi Javier,

Quoted 6 lines · Javier Martinez Canillas
Quoted 5 lines · Geert Uytterhoeven
Quoted 2 lines

Since the current binding has a compatible "ssd1305fb-i2c", we could make the new one "ssd1305drm-i2c" or better, just "ssd1305-i2c".

DT describes hardware, not software policy.
If the hardware is the same, the DT bindings should stay the same.

Only if the bindings describe the HW in a correct way that is.

Quoted 32 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line

Yes I know that but the thing is that the current binding don't describe the hardware correctly. For instance, don't use a backlight DT node as a property of the panel and have this "fb" suffix in the compatible strings.

Quoted 9 lines
Quoted 5 lines

Having said that, my opinion is that we should just keep with the existing bindings and make compatible to that even if isn't completely correct.

Since that will ease adoption of the new DRM driver and allow users to use it without the need to update their DTBs.

To me it looks like the pwms property is not related to the backlight at all, and only needed for some variants?

I was reading the datasheets of the ssd1305, ssd1306 and ssd1307. Only the first one mentions anything about a PWM and says:

In phase 3, the OLED driver switches to use current source to drive the OLED pixels and this is the current drive stage. SSD1305 employs PWM (Pulse Width Modulation) method to control the brightness of area color A, B, C, D color individually. The longer the waveform in current drive stage is, the brighter is the pixel and vice versa.

After finishing phase 3, the driver IC will go back to phase 1 to display the next row image data. This threestep cycle is run continuously to refresh image display on OLED panel.

The way I understand this is that the PWM isn't used for the backlight but instead to power the IC and allow to display the actual pixels ?

Quoted 7 lines

And this matches what Maxime mentioned in this patch:

https://linux-arm-kernel.infradead.narkive.com/5i44FnQ8/patch-1-2-video-ssd1307fb-add-support-for-ssd1306-oled-controller

The Solomon SSD1306 OLED controller is very similar to the SSD1307, except for the fact that the power is given through an external PWM for the 1307, and while the 1306 can generate its own power without any PWM.

I took a look at the datasheets - and all ssd1305, ssd1306 and ssd1307 are the same. They have timing constrains on the Vcc.
The random schematic I found on the net showed me that a PWM was used to control the Vcc voltage - which again is used to control the brightness.

All the above has nothing to do with backlight - I had this mixed up in my head.

So my current understanding:
- solomon,ssd1307fb.yaml should NOT include a backlight node - because the backlight is something included in the ssd130x device and not something separate.
- 1305, 1306, and 1307 (I did not check 1309) all requires a Vcc supply that shall be turned on/off according to the datasheet. This implies that we need a regulaator for Vcc - and the regulator could be a pwm based regulator or something else - the HW do not care.
- But I can see that several design connect Vcc to a fixed voltage, so I am not too sure about this part.

I think the correct binding would have

    ssd1307 => regulator => pwm

So the ssd1307 binding references a regulator, and the regulator may use an pwm or may use something else.

The current binding references a vbat supply - but the datasheet do not mention any vbat. It is most likely modelling the Vdd supply.

Right now my take is to go the simple route:
- Keep the binding as is and just use the pwm as already implemented
- Likewise keep the backlight as is

Last I recommend to drop the fbdev variant - if the drm driver has any regressions we can fix them. And I do not see any other way to move users over. Unless their setup breaks then they do not change.

Quoted 4 lines
Quoted 4 lines

And the actual backlight code seems to be about internal contrast adjustment?

Quoted 8 lines
Quoted 3 lines

So if the pwms usage is OK, what other reasons are there to break DT compatibility? IMHO just the "fb" suffix is not a good reason.

Absolutely agreed with you on this. It seems we should just use the existing binding and make the driver compatible with that. The only value is that the drm_panel infrastructure could be used, but making it backward compatible is more worthy IMO.

Using drm_panel here would IMO just complicate things - it is not that we will see many different panels (I think).

Sam

#10 lore raw

Re: [PATCH 1/4] drm: Add I2C connector type

In reply to Noralf Trønnes

Hi Noralf,

Quoted 20 lines · Noralf Trønnes

Den 31.01.2022 21.52, skrev Sam Ravnborg:

Quoted 10 lines · Javier Martinez Canillas
Quoted 9 lines

There isn't a connector type for display controllers accesed through I2C, most drivers use DRM_MODE_CONNECTOR_Unknown or DRM_MODE_CONNECTOR_VIRTUAL.

Add an I2C connector type to match the actual connector.

As Noralf Trønnes mentions in commit fc06bf1d76d6 ("drm: Add SPI connector type"), user-space should be able to cope with a connector type that does not yet understand.

It turned out that I wasn't entirely correct here, mpv didn't cope with unknown types. In the PR to add support Emil Velikov wondered if libdrm should handle these connector names:
https://github.com/mpv-player/mpv/pull/8989#issuecomment-879187711

Quoted 1 line
Quoted 1 line

Tested with modetest -M ssd1307 -c and shows the connector as unknown-1.

Quoted 8 lines
Quoted 5 lines

I had expected unknown-21??

Quoted 2 lines

Sam, didn't you and Laurent discuss adding DRM_MODE_CONNECTOR_PANEL for such a use case?

You have a splendid memory - yes we did. But no conclusions:
https://lore.kernel.org/dri-devel/?q=DRM_MODE_CONNECTOR_PANEL

As I wrote in another part of this thread(s) - typing the patch is easy. But I do not understand the userspace implications so I need someone else to say go.

Sam

#11 lore raw

Re: [PATCH 1/4] drm: Add I2C connector type

Quoted 3 lines · Sam Ravnborg

As I wrote in another part of this thread(s) - typing the patch is easy. But I do not understand the userspace implications so I need someone else to say go.

User-space shouldn't really use the connector for anything except making it easier for the user to understand where to plug the display cable. I think a generic "panel" connector type makes sense.

#47 lore raw
In reply to Sam Ravnborg

Hello Sam,

On 2/1/22 21:40, Sam Ravnborg wrote:

[snip]

Quoted 9 lines

I took a look at the datasheets - and all ssd1305, ssd1306 and ssd1307 are the same. They have timing constrains on the Vcc.
The random schematic I found on the net showed me that a PWM was used to control the Vcc voltage - which again is used to control the brightness.

All the above has nothing to do with backlight - I had this mixed up in my head.

Yes, same here. I was leaning towards fixing the DT binding but then due Geert comment and after reading the datasheets for ssd130{5,6,7} like you I had the same understanding.

Glad that you agree.

[snip]

Quoted 5 lines

Last I recommend to drop the fbdev variant - if the drm driver has any regressions we can fix them. And I do not see any other way to move users over. Unless their setup breaks then they do not change.

As I mentioned in this thread I wouldn't propose to drop the fbdev variant. I prefer to use the carrot and not the stick. Peter Robinson suggested to make the driver mutually exclusive and add !FB_SSD1307 in the config symbol.

I think that makes sense and will do it in v2.

Best regards,

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

Re: [PATCH 1/4] drm: Add I2C connector type

In reply to Simon Ser
Quoted 10 lines · Simon Ser
Quoted 3 lines · Sam Ravnborg

As I wrote in another part of this thread(s) - typing the patch is easy. But I do not understand the userspace implications so I need someone else to say go.

User-space shouldn't really use the connector for anything except making it easier for the user to understand where to plug the display cable. I think a generic "panel" connector type makes sense.

I'll drop this patch from the series. I didn't have all the context and thought that was an opportunity to add an I2C type, since there was a SPI type already.

But seems to be more controversial than I expected and shouldn't really matter for a tiny driver like this. I will just go ahead and use the Unknown type.

Best regards,

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

Re: [PATCH 1/4] drm: Add I2C connector type

In reply to Noralf Trønnes

Hi Noralf,

since you're here, I'll just hijack the discussion to ask something only semi-related.

IIRC the gud driver doesn't update the display immediately during atomic commits. Instead, it instructs a helper thread to do the update. What's the rational behind this design? Is that something we should adopt for other drivers that operate over slow buses (USB, I2C, etc)? Would this be relevant for the ssd1307 driver?

Best regards
Thomas

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
#36 lore raw
In reply to Geert Uytterhoeven
Quoted 31 lines · On Tue, 1 Feb 2022 12:07:07 +0100 Geert Uytterhoeven <[email protected]>…

Hi Pekka,

Quoted 28 lines · Pekka Paalanen
Quoted 26 lines · On Tue, 1 Feb 2022 10:49:03 +0100 Javier Martinez Canillas…
Quoted 16 lines · Daniel Vetter
Quoted 8 lines · Simon Ser
Quoted 4 lines · Geert Uytterhoeven

What's the story with the Rn formats?

The comments say "n bpp Red", while this is a monochrome (even inverted) display?

I don't think the color matters that much. "Red" was picked just because it was an arbitrary color, to make the difference with e.g. C8. Or am I mistaken?

The red comes from gl, where with shaders it really doesn't matter what meaning you attach to channels, but really just how many you have. So 2-channel formats are called RxGx, 3-channel RxGxBx, 4-channel RxGxBxAx and single-channel Rx. And we use drm_fourcc for interop in general, hence why these exist.

Quoted 5 lines

We should probably make a comment that this really isn't a red channel when used for display it's a greyscale/intensity format. Aside from that documentation gap I think reusing Rx formats for greyscale/intensity for display makes perfect sense. -Daniel

To sump up the conversation in the #dri-devel channel, these drivers should support the following formats:

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

1) Dx (Daniel suggested that for darkness, but inverted mono)

Did you consider format C1 instead?

That would be a 2-color display, which is not necessarily black and white. Cfr. Amiga or Atari bit planes with bpp=1. That's why fbdev has separate visuals for monochrome.

Yes, that is exactly what I was aiming at: to draft a plan for panels that have a fixed and arbitrary palette. From the discussions I understood that the panel in question here requires somehow reversed colors ("inverted mono"), which didn't really sound to be like "normal monochrome".

Quoted 22 lines
Quoted 1 line

I have no idea how this would map to fbdev API though.

    #define FB_VISUAL_MONO01                0       /* Monochr.
1=Black 0=White */
    #define FB_VISUAL_MONO10                1       /* Monochr.
1=White 0=Black */
    #define FB_VISUAL_TRUECOLOR             2       /* True color   */

The above is RGB (or grayscale, see below).

    #define FB_VISUAL_PSEUDOCOLOR           3       /* Pseudo color

(like atari) */

Palette

    #define FB_VISUAL_DIRECTCOLOR           4       /* Direct color */

Usually used as RGB with gamma correction, but the actual hardware is more flexible.

    #define FB_VISUAL_STATIC_PSEUDOCOLOR    5       /* Pseudo color readonly */
Quoted 7 lines

Fixed palette

And:

    struct fb_var_screeninfo {
            ...
            __u32 grayscale;                /* 0 = color, 1 = grayscale,    */

DRM has pixel formats, but no visuals so far. Maybe it needs to grow the concept of visuals in some form? However, care should be taken to not clash with existing colorimetry features. I would hope that the colorimetry feature set could be extended to cover the above as well. Well, only if there would be any users for it.

My silly attempt with Cx formats (e.g. DRM_FORMAT_C8) was a stab in that direction, but maybe not flexible enough for the above.

If on the other hand the panel is "grayscale" but with an arbitrary color (white, green, orange or other on black), the IRC consensus seems to be that one should use Rx formats (e.g. DRM_FORMAT_R8) for it, regardless of the actual color. That would convey that the pixel value has a monotonic (increasing) mapping to brightness, unlike with paletted formats. I agree with this, but wonder how reversed brightness should be dealt with - or just have the driver invert the pixel values before sending them to display?

Cx formats with a read-only palette could be used to represent "grayscale" and "reversed grayscale" too, but people seem to think that is too complicated to analyse and use for KMS userspace.

Other #dri-devel IRC mumblings were about maybe adding a DRM pixel format for grayscale or intensity or luminance so that one would not need to use "red" color channel for something that doesn't look red. That is, do not use Cx formats because those produce completely arbitrary colors, and do not use Rx formats because the display is not redscale. Personally I'd be fine with Rx formats.

Thanks,
pq

#14 lore raw

Re: [PATCH 1/4] drm: Add I2C connector type

In reply to Thomas Zimmermann

Den 02.02.2022 10.14, skrev Thomas Zimmermann:

Quoted 11 lines

Hi Noralf,

since you're here, I'll just hijack the discussion to ask something only semi-related.

IIRC the gud driver doesn't update the display immediately during atomic commits. Instead, it instructs a helper thread to do the update. What's the rational behind this design? Is that something we should adopt for other drivers that operate over slow buses (USB, I2C, etc)? Would this be relevant for the ssd1307 driver?

Async flushing is only necessary on multi display setups where there's only one rendering loop for all the displays. I saw what tiny/gm12u320.c did and Hans gave me the rationale. The SPI drivers run flushing inline. Info on the gud wiki:
https://github.com/notro/gud/wiki/Linux-Host-Driver#asynchronous-flushing

Noralf.

#37 lore raw
In reply to Pekka Paalanen

Hi Pekka,

Quoted 75 lines · Pekka Paalanen
Quoted 29 lines · On Tue, 1 Feb 2022 12:07:07 +0100 Geert Uytterhoeven <[email protected]>…
Quoted 28 lines · Pekka Paalanen
Quoted 26 lines · On Tue, 1 Feb 2022 10:49:03 +0100 Javier Martinez Canillas…
Quoted 16 lines · Daniel Vetter
Quoted 8 lines · Simon Ser
Quoted 4 lines · Geert Uytterhoeven

What's the story with the Rn formats?

The comments say "n bpp Red", while this is a monochrome (even inverted) display?

I don't think the color matters that much. "Red" was picked just because it was an arbitrary color, to make the difference with e.g. C8. Or am I mistaken?

The red comes from gl, where with shaders it really doesn't matter what meaning you attach to channels, but really just how many you have. So 2-channel formats are called RxGx, 3-channel RxGxBx, 4-channel RxGxBxAx and single-channel Rx. And we use drm_fourcc for interop in general, hence why these exist.

Quoted 5 lines

We should probably make a comment that this really isn't a red channel when used for display it's a greyscale/intensity format. Aside from that documentation gap I think reusing Rx formats for greyscale/intensity for display makes perfect sense. -Daniel

To sump up the conversation in the #dri-devel channel, these drivers should support the following formats:

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

1) Dx (Daniel suggested that for darkness, but inverted mono)

Did you consider format C1 instead?

That would be a 2-color display, which is not necessarily black and white. Cfr. Amiga or Atari bit planes with bpp=1. That's why fbdev has separate visuals for monochrome.

Yes, that is exactly what I was aiming at: to draft a plan for panels that have a fixed and arbitrary palette. From the discussions I understood that the panel in question here requires somehow reversed colors ("inverted mono"), which didn't really sound to be like "normal monochrome".

Quoted 22 lines
Quoted 1 line

I have no idea how this would map to fbdev API though.

    #define FB_VISUAL_MONO01                0       /* Monochr.
1=Black 0=White */
    #define FB_VISUAL_MONO10                1       /* Monochr.
1=White 0=Black */
    #define FB_VISUAL_TRUECOLOR             2       /* True color   */

The above is RGB (or grayscale, see below).

    #define FB_VISUAL_PSEUDOCOLOR           3       /* Pseudo color

(like atari) */

Palette

    #define FB_VISUAL_DIRECTCOLOR           4       /* Direct color */

Usually used as RGB with gamma correction, but the actual hardware is more flexible.

    #define FB_VISUAL_STATIC_PSEUDOCOLOR    5       /* Pseudo color readonly */
Quoted 7 lines

Fixed palette

And:

    struct fb_var_screeninfo {
            ...
            __u32 grayscale;                /* 0 = color, 1 = grayscale,    */
Quoted 5 lines

DRM has pixel formats, but no visuals so far. Maybe it needs to grow the concept of visuals in some form? However, care should be taken to not clash with existing colorimetry features. I would hope that the colorimetry feature set could be extended to cover the above as well. Well, only if there would be any users for it.

Fbdev has separate (orthogonal) settings for
1. Frame buffer layout (FB_TYPE_*),
2. Pixel format (depth and fb_bitfields),
3. Visual.
DRM combines all of the above in a fourcc value.

Nowadays most frame buffer layouts are packed, so using a shadow frame buffer to support other layouts is very helpful, as it means applications no longer have to care about legacy frame buffer layouts.

Quoted 9 lines

My silly attempt with Cx formats (e.g. DRM_FORMAT_C8) was a stab in that direction, but maybe not flexible enough for the above.

If on the other hand the panel is "grayscale" but with an arbitrary color (white, green, orange or other on black), the IRC consensus seems to be that one should use Rx formats (e.g. DRM_FORMAT_R8) for it, regardless of the actual color. That would convey that the pixel value has a monotonic (increasing) mapping to brightness, unlike with paletted formats. I agree with this, but wonder how reversed brightness

Agreed, the only thing that matters is a monotonic mapping, and whether it's increasing or decreasing.

Quoted 2 lines

should be dealt with - or just have the driver invert the pixel values before sending them to display?

That's an option. If the data has to be copied anyway, inversion is a cheap operation. Else I think you need new fourcc types.

Quoted 3 lines

Cx formats with a read-only palette could be used to represent "grayscale" and "reversed grayscale" too, but people seem to think that is too complicated to analyse and use for KMS userspace.

Yeah, it's complicated, but rather rare. Most desktop hardware (even from the nineties ;-) does support a programmable palette. Exceptions are CGA, the C64 (no Linux support yet ;-), and eInk displays that support e.g. white, black, and red.

If you do want to support it, perhaps introduce Fx (F = fixed) fourcc types?

Quoted 6 lines

Other #dri-devel IRC mumblings were about maybe adding a DRM pixel format for grayscale or intensity or luminance so that one would not need to use "red" color channel for something that doesn't look red. That is, do not use Cx formats because those produce completely arbitrary colors, and do not use Rx formats because the display is not redscale. Personally I'd be fine with Rx formats.

Fine, as said above, monotonic mapping is what matters.

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

#48 lore raw
In reply to Javier Martinez Canillas
Quoted 1 line · Javier Martinez Canillas

On 2/1/22 21:40, Sam Ravnborg wrote:

...

Quoted 2 lines

Peter Robinson suggested to
make the driver mutually exclusive and add !FB_SSD1307 in the config symbol.

And how will distros choose "the right" option in this case? What to do when I wan to see a regression and I want to change drivers w/o recompilation?

NAK from me to that proposal.

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

Hello Andy,

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

On 2/1/22 21:40, Sam Ravnborg wrote:

...

Quoted 2 lines

Peter Robinson suggested to
make the driver mutually exclusive and add !FB_SSD1307 in the config symbol.

And how will distros choose "the right" option in this case?

It depends on the distro. In Fedora we are disabling *all* the fbdev drivers.

Quoted 3 lines

What to do when I wan to see a regression and I want to change drivers w/o recompilation?

If you want to have the two drivers without recompilation (and same compatible to match) then how would kmod / udev choose which one to load ? It becomes a race condition between the two drivers which one probes first.

Quoted 2 lines

NAK from me to that proposal.

What's your suggestion then to solve the issue mentioned above ? With my distro maintainer hat I don't care that much, since the fbdev drivers will be disabled.

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Linux Engineering
Red Hat
#50 lore raw
Quoted 7 lines · Javier Martinez Canillas
Quoted 4 lines · Andy Shevchenko
Quoted 1 line · Javier Martinez Canillas

On 2/1/22 21:40, Sam Ravnborg wrote:

And how will distros choose "the right" option in this case?

It depends on the distro. In Fedora we are disabling *all* the fbdev drivers.

Yes, and Distro A will think about old driver (because they have customers and don't want to have a bad user experience) and Distro F will choose a new one.

Quoted 6 lines
Quoted 2 lines

What to do when I wan to see a regression and I want to change drivers w/o recompilation?

If you want to have the two drivers without recompilation (and same compatible to match) then how would kmod / udev choose which one to load ? It becomes a race condition between the two drivers which one probes first.

We have a long history in kernel where new drivers came and old faded. When two or more drivers of the same feature is enabled in the kernel we may use modprobe facilities to prioritize them (blacklisting).

Quoted 4 lines
Quoted 1 line

NAK from me to that proposal.

What's your suggestion then to solve the issue mentioned above ? With my distro maintainer hat I don't care that much, since the fbdev drivers will be disabled.

I think both of them can work together. If user doesn't care, the first one wins.

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

On 2/2/22 12:50, Andy Shevchenko wrote:

[snip]

Quoted 5 lines
Quoted 2 lines

What's your suggestion then to solve the issue mentioned above ? With my distro maintainer hat I don't care that much, since the fbdev drivers will be disabled.

I think both of them can work together. If user doesn't care, the first one wins.

I don't think this is a good idea but as mentioned I don't really care that much since we will disable all fbdev drivers anyway. So I'm happy to allow them both.

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Linux Engineering
Red Hat
#52 lore raw
Quoted 8 lines · Javier Martinez Canillas
Quoted 4 lines · Andy Shevchenko
Quoted 2 lines

What's your suggestion then to solve the issue mentioned above ? With my distro maintainer hat I don't care that much, since the fbdev drivers will be disabled.

I think both of them can work together. If user doesn't care, the first one wins.

I don't think this is a good idea but as mentioned I don't really care that much since we will disable all fbdev drivers anyway. So I'm happy to allow them both.

Thanks!

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

Re: [PATCH 1/4] drm: Add I2C connector type

In reply to Noralf Trønnes
Quoted 13 lines · On Wed, 2 Feb 2022 10:45:42 +0100 Noralf Trønnes <[email protected]> wrote:

Den 02.02.2022 10.14, skrev Thomas Zimmermann:

Quoted 11 lines

Hi Noralf,

since you're here, I'll just hijack the discussion to ask something only semi-related.

IIRC the gud driver doesn't update the display immediately during atomic commits. Instead, it instructs a helper thread to do the update. What's the rational behind this design? Is that something we should adopt for other drivers that operate over slow buses (USB, I2C, etc)? Would this be relevant for the ssd1307 driver?

Quoted 5 lines

Async flushing is only necessary on multi display setups where there's only one rendering loop for all the displays. I saw what tiny/gm12u320.c did and Hans gave me the rationale. The SPI drivers run flushing inline. Info on the gud wiki:
https://github.com/notro/gud/wiki/Linux-Host-Driver#asynchronous-flushing

Hi,

please also consider that userspace may throttle to the KMS pageflip events. If the pageflip event is immediate from submitting a flip, that could mean userspace will be repainting in a busy-loop, like 1 kHz. However, I remember something about virtual KMS drivers doing exactly this, and there being something that tells userspace to throttle itself instead of depending on pageflip completions. I just forget how that is supposed to work, and I'm fairly sure that e.g. Weston does not behave well there.

Unfortunately, the pageflip event is also what synchronises FB usage. Once flipping in a new FB completed, the old FB is free for re-use. But, if the kernel is still copying out from the old FB, userspace may partially overwrite the contents, temporarily leading to an incomplete or too new image on screen. Do you have anything to prevent that?

Thanks,
pq

#16 lore raw

Re: [PATCH 1/4] drm: Add I2C connector type

Den 02.02.2022 16.04, skrev Pekka Paalanen:

Quoted 33 lines
Quoted 13 lines · On Wed, 2 Feb 2022 10:45:42 +0100 Noralf Trønnes <[email protected]> wrote:

Den 02.02.2022 10.14, skrev Thomas Zimmermann:

Quoted 11 lines

Hi Noralf,

since you're here, I'll just hijack the discussion to ask something only semi-related.

IIRC the gud driver doesn't update the display immediately during atomic commits. Instead, it instructs a helper thread to do the update. What's the rational behind this design? Is that something we should adopt for other drivers that operate over slow buses (USB, I2C, etc)? Would this be relevant for the ssd1307 driver?

Quoted 5 lines

Async flushing is only necessary on multi display setups where there's only one rendering loop for all the displays. I saw what tiny/gm12u320.c did and Hans gave me the rationale. The SPI drivers run flushing inline. Info on the gud wiki:
https://github.com/notro/gud/wiki/Linux-Host-Driver#asynchronous-flushing

Hi,

please also consider that userspace may throttle to the KMS pageflip events. If the pageflip event is immediate from submitting a flip, that could mean userspace will be repainting in a busy-loop, like 1 kHz. However, I remember something about virtual KMS drivers doing exactly this, and there being something that tells userspace to throttle itself instead of depending on pageflip completions. I just forget how that is supposed to work, and I'm fairly sure that e.g. Weston does not behave well there.

Quoted 6 lines

Unfortunately, the pageflip event is also what synchronises FB usage. Once flipping in a new FB completed, the old FB is free for re-use. But, if the kernel is still copying out from the old FB, userspace may partially overwrite the contents, temporarily leading to an incomplete or too new image on screen. Do you have anything to prevent that?

Unfortunately not. One solution would be to make a buffer copy during the flip and do the USB transfer async but I haven't looked into that. My plan is to wait and see what problems users report back before trying to fix anything.

Noralf.

#21 lore raw

Re: [PATCH 2/4] drm/format-helper: Add drm_fb_gray8_to_mono_reversed()

In reply to Javier Martinez Canillas

Hi Javier,

Quoted 11 lines · Javier Martinez Canillas

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

This helper function was based on repaper_gray8_to_mono_reversed() from the drivers/gpu/drm/tiny/repaper.c driver.

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

Quoted 7 lines
drivers/gpu/drm/drm_format_helper.c +4 -0
@@ -584,3 +584,38 @@ int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for
        return -EINVAL;
 }
 EXPORT_SYMBOL(drm_fb_blit_toio);
+
+/**
+ * drm_fb_gray8_to_mono_reversed - Convert grayscale to reversed monochrome
+ * @dst: reversed monochrome destination buffer

What's the meaning of "reversed"?
During the last few days, I've been balancing between (a) "reverse video" and (b) "reverse bit order", but none of them seems to be true.

(a) The code maps 0-127 to 0 and 8-255 to 1, which just reduces from 256 to 2 grayscale levels, without inversion. The result is also white-on-black on my ssd130x OLED.
(b) On little-endian, the CFB drawops use little-endian bit order, which is what ends up in "byte" in the code below.

Quoted 20 lines
drivers/gpu/drm/drm_format_helper.c +20 -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, void *src, const struct drm_rect *clip)
+{
+       size_t width = drm_rect_width(clip);
+       size_t height = drm_rect_width(clip);
+
+       u8 *mono = dst, *gray8 = src;
+       unsigned int y, xb, i;
+
+       for (y = 0; y < height; y++)
+               for (xb = 0; xb < width / 8; xb++) {
+                       u8 byte = 0x00;
+

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

Quoted 10 lines
drivers/gpu/drm/drm_format_helper.c +10 -0
+                       for (i = 0; i < 8; i++) {
+                               int x = xb * 8 + i;
+
+                               byte >>= 1;
+                               if (gray8[y * width + x] >> 7)
+                                       byte |= BIT(7);
+                       }
+                       *mono++ = byte;
+               }
+}

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

#22 lore raw

Re: [PATCH 2/4] drm/format-helper: Add drm_fb_gray8_to_mono_reversed()

Hello Geert,

Quoted 12 lines · Geert Uytterhoeven

Hi Javier,

Quoted 7 lines · Javier Martinez Canillas

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

This helper function was based on repaper_gray8_to_mono_reversed() from the drivers/gpu/drm/tiny/repaper.c driver.

Quoted 12 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 590

Quoted 10 lines
drivers/gpu/drm/drm_format_helper.c +4 -0
@@ -584,3 +584,38 @@ int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for
        return -EINVAL;
 }
 EXPORT_SYMBOL(drm_fb_blit_toio);
+
+/**
+ * drm_fb_gray8_to_mono_reversed - Convert grayscale to reversed monochrome
+ * @dst: reversed monochrome destination buffer

What's the meaning of "reversed"?

Originally I took this helper from the repaper driver and it was called repaper_gray8_to_mono_reversed(), so the naming just got carried over.

Quoted 9 lines

During the last few days, I've been balancing between (a) "reverse video" and (b) "reverse bit order", but none of them seems to be true.

(a) The code maps 0-127 to 0 and 8-255 to 1, which just reduces from 256 to 2 grayscale levels, without inversion. The result is also white-on-black on my ssd130x OLED.
(b) On little-endian, the CFB drawops use little-endian bit order, which is what ends up in "byte" in the code below.

As far as I understand is (a) from the options since the repaper display uses black-on-white. But as you pointed out the ssd130x OLEDs instead do white-on-black.

I should had probably just name the helper drm_fb_gray8_to_monochrome() or maybe drm_fb_gray8_to_gray1() ?

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Linux Engineering
Red Hat