单色 (1bpp) 简单帧缓冲区 (simplefb.c) format/depth

Monochromatic (1bpp) simple framebuffer (simplefb.c) format/depth

我按照下面建议的方式成功使用了简单的frambuffer驱动程序(https://github.com/torvalds/linux/blob/fcadab740480e0e0e9fa9bd272acd409884d431a/drivers/video/fbdev/simplefb.c) with 16bits per pixel encoding (r5g6b5) settings. Now, I would like to use a similar approach for a smaller monochromatic display using 1bit-per-pixel depth. According to the source code, the simple framebuffer doesn't seem to support this mode of operation. Is it possible to add this mode ("y1") into SIMPLEFB_FORMATS define (https://github.com/torvalds/linux/blob/fcadab740480e0e0e9fa9bd272acd409884d431a/include/linux/platform_data/simplefb.h)?然后在devicetree中使用这个模式?

#define SIMPLEFB_FORMATS \{ \ 
 { "r5g6b5", 16, {11, 5}, {5, 6}, {0, 5}, {0, 0}, DRM_FORMAT_RGB565 }, \
 ....
 { "y1", 1, {0, 1}, {0, 0}, {0, 0}, {0, 0}, DRM_FORMAT_MONO }, \
}

这个问题有通用的解决方案吗?我需要在每个像素深度为 1 位的给定物理地址上分配一个帧缓冲区...

提前致谢, 麦克

我以这种方式在简单的帧缓冲区中实现了 1bpp:

diff --git a/drivers/video/fbdev/simplefb.c b/drivers/video/fbdev/simplefb.c
index 533a047d07a2..9c654ff10ab7 100644
--- a/drivers/video/fbdev/simplefb.c
+++ b/drivers/video/fbdev/simplefb.c
@@ -25,7 +25,8 @@
 #include <linux/parser.h>
 #include <linux/regulator/consumer.h>
 
-static const struct fb_fix_screeninfo simplefb_fix = {
+// removed const
+static struct fb_fix_screeninfo simplefb_fix = {
        .id             = "simple",
        .type           = FB_TYPE_PACKED_PIXELS,
        .visual         = FB_VISUAL_TRUECOLOR,
@@ -432,6 +433,10 @@ static int simplefb_probe(struct platform_device *pdev)
 
        par = info->par;
 
+       if (params.format->bits_per_pixel == 1) {
+         simplefb_fix.visual = FB_VISUAL_MONO01;
+       }
+
        info->fix = simplefb_fix;
        info->fix.smem_start = mem->start;
        info->fix.smem_len = resource_size(mem);
@@ -480,10 +485,10 @@ static int simplefb_probe(struct platform_device *pdev)
        dev_info(&pdev->dev, "framebuffer at 0x%lx, 0x%x bytes, mapped to 0x%p\n",
                             info->fix.smem_start, info->fix.smem_len,
                             info->screen_base);
-       dev_info(&pdev->dev, "format=%s, mode=%dx%dx%d, linelength=%d\n",
+       dev_info(&pdev->dev, "format=%s, mode=%dx%dx%d, linelength=%d, visual=%d\n",
                             params.format->name,
                             info->var.xres, info->var.yres,
-                            info->var.bits_per_pixel, info->fix.line_length);
+                            info->var.bits_per_pixel, info->fix.line_length, simplefb_fix.visual);
 
        ret = register_framebuffer(info);
        if (ret < 0) {
diff --git a/include/linux/platform_data/simplefb.h b/include/linux/platform_data/simplefb.h
index ca8337695c2a..77714fc5f789 100644
--- a/include/linux/platform_data/simplefb.h
+++ b/include/linux/platform_data/simplefb.h
@@ -24,6 +24,7 @@
        { "a8b8g8r8", 32, {0, 8}, {8, 8}, {16, 8}, {24, 8}, DRM_FORMAT_ABGR8888 }, \
        { "x2r10g10b10", 32, {20, 10}, {10, 10}, {0, 10}, {0, 0}, DRM_FORMAT_XRGB2101010 }, \
        { "a2r10g10b10", 32, {20, 10}, {10, 10}, {0, 10}, {30, 2}, DRM_FORMAT_ARGB2101010 }, \
+       { "r1", 1, {0, 1}, {0, 0}, {0, 0}, {0, 0}, 0 }, \
 }
 
 /*

设备树记录然后以这种方式查找 256x128 单色显示:

fb0: framebuffer@43c40000 {
                compatible = "simple-framebuffer";
                reg = <0x43c40000 (32 * 16)>;
                width = <256>;
                height = <128>;
                stride = <32>;
                format = "r1";
                status = "okay";
            };