diff -uNr linux-3.3-4.0/linux/arch/mips/brcmstb/prom.c linux-3.3-4.0-simplefb/linux/arch/mips/brcmstb/prom.c --- linux-3.3-4.0/linux/arch/mips/brcmstb/prom.c 2016-08-10 15:10:32.000000000 +0800 +++ linux-3.3-4.0-simplefb/linux/arch/mips/brcmstb/prom.c 2016-11-17 17:51:41.608177768 +0800 @@ -229,6 +229,15 @@ FETCH("FLASH_SIZE", parse_ulong, &brcm_mtd_flash_size_mb); FETCH("FLASH_TYPE", parse_string, brcm_mtd_flash_type); +#ifdef CONFIG_FB_SIMPLE + FETCH("LCD_SURFACE_ADDR", parse_hex, &brcm_surface_start); + FETCH("LCD_SURFACE_SIZE", parse_hex, &brcm_surface_len); + FETCH("LCD_DISP_WIDTH", parse_ulong, &brcm_disp_width); + FETCH("LCD_DISP_HEIGHT", parse_ulong, &brcm_disp_heigth); + FETCH("LCD_DISP_STRIDE", parse_ulong, &brcm_disp_stride); + FETCH("LCD_DISP_FORMAT", parse_string, brcm_disp_format); +#endif + printk(KERN_CONT "found %d vars.\n", fetched); } diff -uNr linux-3.3-4.0/linux/drivers/brcmstb/setup.c linux-3.3-4.0-simplefb/linux/drivers/brcmstb/setup.c --- linux-3.3-4.0/linux/drivers/brcmstb/setup.c 2016-08-10 15:10:33.000000000 +0800 +++ linux-3.3-4.0-simplefb/linux/drivers/brcmstb/setup.c 2016-11-17 17:51:58.924750824 +0800 @@ -45,6 +45,10 @@ #include +#ifdef CONFIG_FB_SIMPLE +#include +#endif + #ifndef CONFIG_MTD /* squash MTD warning on IKOS builds */ #define CONFIG_MTD_MAP_BANK_WIDTH_1 1 @@ -161,6 +165,54 @@ }, }; +#ifdef CONFIG_FB_SIMPLE +/* Display/Framebuffer */ +unsigned long brcm_surface_start; +unsigned long brcm_surface_len; +unsigned long brcm_disp_width; +unsigned long brcm_disp_heigth; +unsigned long brcm_disp_stride; +char brcm_disp_format[CFE_STRING_SIZE]; + +static int __init brcm_register_simplefb(void) +{ + struct resource res; + struct platform_device *pdev; + struct simplefb_platform_data pdata; + + if (brcm_surface_len == 0) + return -ENODEV; + + memset(&res, 0, sizeof(res)); + res.start = brcm_surface_start; + res.end = res.start + brcm_surface_len - 1; + res.flags = IORESOURCE_MEM; + + memset(&pdata, 0, sizeof(pdata)); + pdata.width = brcm_disp_width; + pdata.height = brcm_disp_heigth; + pdata.stride = brcm_disp_stride; + pdata.format = brcm_disp_format; + + pdev = platform_device_alloc("simple-framebuffer", -1); + if (!pdev || + platform_device_add_resources(pdev, &res, 1) || + platform_device_add_data(pdev, &pdata, sizeof(pdata)) || + platform_device_add(pdev)) { + printk(KERN_WARNING + "%s: register simple-framebuffer device failed\n", __func__); + platform_device_put(pdev); + return -ENODEV; + } + else + { + printk(KERN_WARNING "Register simple-framebuffer device\n"); + } + + return 0; +} +#endif + static inline void brcm_bogus_release(struct device *dev) { } @@ -651,6 +703,10 @@ } #endif +#if defined(CONFIG_FB_SIMPLE) + brcm_register_simplefb(); +#endif + return 0; } diff -uNr linux-3.3-4.0/linux/drivers/video/Kconfig linux-3.3-4.0-simplefb/linux/drivers/video/Kconfig --- linux-3.3-4.0/linux/drivers/video/Kconfig 2016-08-10 15:10:34.000000000 +0800 +++ linux-3.3-4.0-simplefb/linux/drivers/video/Kconfig 2016-11-17 17:52:07.465794932 +0800 @@ -2409,6 +2409,22 @@ Choose this option if you want to use the Unigfx device as a framebuffer device. Without the support of PCI & AGP. +config FB_SIMPLE + bool "Simple framebuffer support" + depends on (FB = y) + select FB_CFB_FILLRECT + select FB_CFB_COPYAREA + select FB_CFB_IMAGEBLIT + help + Say Y if you want support for a simple frame-buffer. + + This driver assumes that the display hardware has been initialized + before the kernel boots, and the kernel will simply render to the + pre-allocated frame buffer surface. + + Configuration re: surface address, size, and format must be provided + through device tree, or plain old platform data. + source "drivers/video/omap/Kconfig" source "drivers/video/omap2/Kconfig" diff -uNr linux-3.3-4.0/linux/drivers/video/Makefile linux-3.3-4.0-simplefb/linux/drivers/video/Makefile --- linux-3.3-4.0/linux/drivers/video/Makefile 2016-08-10 15:10:34.000000000 +0800 +++ linux-3.3-4.0-simplefb/linux/drivers/video/Makefile 2016-11-17 17:52:15.511622613 +0800 @@ -158,6 +158,7 @@ obj-$(CONFIG_FB_MX3) += mx3fb.o obj-$(CONFIG_FB_DA8XX) += da8xx-fb.o obj-$(CONFIG_FB_MXS) += mxsfb.o +obj-$(CONFIG_FB_SIMPLE) += simplefb.o # the test framebuffer is last obj-$(CONFIG_FB_VIRTUAL) += vfb.o diff -uNr linux-3.3-4.0/linux/drivers/video/simplefb.c linux-3.3-4.0-simplefb/linux/drivers/video/simplefb.c --- linux-3.3-4.0/linux/drivers/video/simplefb.c 1970-01-01 08:00:00.000000000 +0800 +++ linux-3.3-4.0-simplefb/linux/drivers/video/simplefb.c 2016-11-02 13:16:51.456925300 +0800 @@ -0,0 +1,280 @@ +/* + * Simplest possible simple frame-buffer driver, as a platform device + * + * Copyright (c) 2013, Stephen Warren + * + * Based on q40fb.c, which was: + * Copyright (C) 2001 Richard Zidlicky + * + * Also based on offb.c, which was: + * Copyright (C) 1997 Geert Uytterhoeven + * Copyright (C) 1996 Paul Mackerras + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + */ + +#include +#include +#include +#include +#include +#include + +static struct fb_fix_screeninfo simplefb_fix = { + .id = "simple", + .type = FB_TYPE_PACKED_PIXELS, + .visual = FB_VISUAL_TRUECOLOR, + .accel = FB_ACCEL_NONE, +}; + +static struct fb_var_screeninfo simplefb_var = { + .height = -1, + .width = -1, + .activate = FB_ACTIVATE_NOW, + .vmode = FB_VMODE_NONINTERLACED, +}; + +static int simplefb_setcolreg(u_int regno, u_int red, u_int green, u_int blue, + u_int transp, struct fb_info *info) +{ + u32 *pal = info->pseudo_palette; + u32 cr = red >> (16 - info->var.red.length); + u32 cg = green >> (16 - info->var.green.length); + u32 cb = blue >> (16 - info->var.blue.length); + u32 value; + + if (regno >= 16) + return -EINVAL; + + value = (cr << info->var.red.offset) | + (cg << info->var.green.offset) | + (cb << info->var.blue.offset); + if (info->var.transp.length > 0) { + u32 mask = (1 << info->var.transp.length) - 1; + mask <<= info->var.transp.offset; + value |= mask; + } + pal[regno] = value; + + return 0; +} + +static void simplefb_destroy(struct fb_info *info) +{ + if (info->screen_base) + iounmap(info->screen_base); +} + +static struct fb_ops simplefb_ops = { + .owner = THIS_MODULE, + .fb_destroy = simplefb_destroy, + .fb_setcolreg = simplefb_setcolreg, + .fb_fillrect = cfb_fillrect, + .fb_copyarea = cfb_copyarea, + .fb_imageblit = cfb_imageblit, +}; + +static struct simplefb_format simplefb_formats[] = SIMPLEFB_FORMATS; + +struct simplefb_params { + u32 width; + u32 height; + u32 stride; + struct simplefb_format *format; +}; + +static int simplefb_parse_dt(struct platform_device *pdev, + struct simplefb_params *params) +{ + struct device_node *np = pdev->dev.of_node; + int ret; + const char *format; + int i; + + ret = of_property_read_u32(np, "width", ¶ms->width); + if (ret) { + dev_err(&pdev->dev, "Can't parse width property\n"); + return ret; + } + + ret = of_property_read_u32(np, "height", ¶ms->height); + if (ret) { + dev_err(&pdev->dev, "Can't parse height property\n"); + return ret; + } + + ret = of_property_read_u32(np, "stride", ¶ms->stride); + if (ret) { + dev_err(&pdev->dev, "Can't parse stride property\n"); + return ret; + } + + ret = of_property_read_string(np, "format", &format); + if (ret) { + dev_err(&pdev->dev, "Can't parse format property\n"); + return ret; + } + params->format = NULL; + for (i = 0; i < ARRAY_SIZE(simplefb_formats); i++) { + if (strcmp(format, simplefb_formats[i].name)) + continue; + params->format = &simplefb_formats[i]; + break; + } + if (!params->format) { + dev_err(&pdev->dev, "Invalid format value\n"); + return -EINVAL; + } + + return 0; +} + +static int simplefb_parse_pd(struct platform_device *pdev, + struct simplefb_params *params) +{ + struct simplefb_platform_data *pd = dev_get_platdata(&pdev->dev); + int i; + + params->width = pd->width; + params->height = pd->height; + params->stride = pd->stride; + + params->format = NULL; + for (i = 0; i < ARRAY_SIZE(simplefb_formats); i++) { + if (strcmp(pd->format, simplefb_formats[i].name)) + continue; + + params->format = &simplefb_formats[i]; + break; + } + + if (!params->format) { + dev_err(&pdev->dev, "Invalid format value\n"); + return -EINVAL; + } + + return 0; +} + +static int simplefb_probe(struct platform_device *pdev) +{ + int ret; + struct simplefb_params params; + struct fb_info *info; + struct resource *mem; + + if (fb_get_options("simplefb", NULL)) + return -ENODEV; + + ret = -ENODEV; + if (dev_get_platdata(&pdev->dev)) + ret = simplefb_parse_pd(pdev, ¶ms); + else if (pdev->dev.of_node) + ret = simplefb_parse_dt(pdev, ¶ms); + + if (ret) + return ret; + + mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!mem) { + dev_err(&pdev->dev, "No memory resource\n"); + return -EINVAL; + } + + info = framebuffer_alloc(sizeof(u32) * 16, &pdev->dev); + if (!info) + return -ENOMEM; + platform_set_drvdata(pdev, info); + + info->fix = simplefb_fix; + info->fix.smem_start = mem->start; + info->fix.smem_len = resource_size(mem); + info->fix.line_length = params.stride; + + info->var = simplefb_var; + info->var.xres = params.width; + info->var.yres = params.height; + info->var.xres_virtual = params.width; + info->var.yres_virtual = params.height; + info->var.bits_per_pixel = params.format->bits_per_pixel; + info->var.red = params.format->red; + info->var.green = params.format->green; + info->var.blue = params.format->blue; + info->var.transp = params.format->transp; + + info->apertures = alloc_apertures(1); + if (!info->apertures) { + framebuffer_release(info); + return -ENOMEM; + } + info->apertures->ranges[0].base = info->fix.smem_start; + info->apertures->ranges[0].size = info->fix.smem_len; + + info->fbops = &simplefb_ops; + info->flags = FBINFO_DEFAULT | FBINFO_MISC_FIRMWARE; + info->screen_base = ioremap_wc(info->fix.smem_start, + info->fix.smem_len); + if (!info->screen_base) { + framebuffer_release(info); + return -ENODEV; + } + info->pseudo_palette = (void *)(info + 1); + + 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", + params.format->name, + info->var.xres, info->var.yres, + info->var.bits_per_pixel, info->fix.line_length); + + ret = register_framebuffer(info); + if (ret < 0) { + dev_err(&pdev->dev, "Unable to register simplefb: %d\n", ret); + iounmap(info->screen_base); + framebuffer_release(info); + return ret; + } + + dev_info(&pdev->dev, "fb%d: simplefb registered!\n", info->node); + + return 0; +} + +static int simplefb_remove(struct platform_device *pdev) +{ + struct fb_info *info = platform_get_drvdata(pdev); + + unregister_framebuffer(info); + framebuffer_release(info); + + return 0; +} + +static const struct of_device_id simplefb_of_match[] = { + { .compatible = "simple-framebuffer", }, + { }, +}; +MODULE_DEVICE_TABLE(of, simplefb_of_match); + +static struct platform_driver simplefb_driver = { + .driver = { + .name = "simple-framebuffer", + .owner = THIS_MODULE, + .of_match_table = simplefb_of_match, + }, + .probe = simplefb_probe, + .remove = simplefb_remove, +}; +module_platform_driver(simplefb_driver); + +MODULE_AUTHOR("Stephen Warren "); +MODULE_DESCRIPTION("Simple framebuffer driver"); +MODULE_LICENSE("GPL v2"); diff -uNr linux-3.3-4.0/linux/include/linux/brcmstb/brcmstb.h linux-3.3-4.0-simplefb/linux/include/linux/brcmstb/brcmstb.h --- linux-3.3-4.0/linux/include/linux/brcmstb/brcmstb.h 2016-08-10 15:10:34.000000000 +0800 +++ linux-3.3-4.0-simplefb/linux/include/linux/brcmstb/brcmstb.h 2016-11-17 17:53:12.538779797 +0800 @@ -952,6 +952,16 @@ void brcm_pm_sata3(int enable); +#ifdef CONFIG_FB_SIMPLE +/* Display/Framebuffer */ +extern unsigned long brcm_surface_start; +extern unsigned long brcm_surface_len; +extern unsigned long brcm_disp_width; +extern unsigned long brcm_disp_heigth; +extern unsigned long brcm_disp_stride; +extern char brcm_disp_format[CFE_STRING_SIZE]; +#endif + extern unsigned long brcm_dram0_size_mb; extern unsigned long brcm_dram1_size_mb; extern unsigned long brcm_dram1_linux_mb; diff -uNr linux-3.3-4.0/linux/include/linux/platform_data/simplefb.h linux-3.3-4.0-simplefb/linux/include/linux/platform_data/simplefb.h --- linux-3.3-4.0/linux/include/linux/platform_data/simplefb.h 1970-01-01 08:00:00.000000000 +0800 +++ linux-3.3-4.0-simplefb/linux/include/linux/platform_data/simplefb.h 2015-10-31 06:20:23.000000000 +0800 @@ -0,0 +1,64 @@ +/* + * simplefb.h - Simple Framebuffer Device + * + * Copyright (C) 2013 David Herrmann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#ifndef __PLATFORM_DATA_SIMPLEFB_H__ +#define __PLATFORM_DATA_SIMPLEFB_H__ + +#include +#include +#include + +/* format array, use it to initialize a "struct simplefb_format" array */ +#define SIMPLEFB_FORMATS \ +{ \ + { "r5g6b5", 16, {11, 5}, {5, 6}, {0, 5}, {0, 0}, DRM_FORMAT_RGB565 }, \ + { "x1r5g5b5", 16, {10, 5}, {5, 5}, {0, 5}, {0, 0}, DRM_FORMAT_XRGB1555 }, \ + { "a1r5g5b5", 16, {10, 5}, {5, 5}, {0, 5}, {15, 1}, DRM_FORMAT_ARGB1555 }, \ + { "r8g8b8", 24, {16, 8}, {8, 8}, {0, 8}, {0, 0}, DRM_FORMAT_RGB888 }, \ + { "x8r8g8b8", 32, {16, 8}, {8, 8}, {0, 8}, {0, 0}, DRM_FORMAT_XRGB8888 }, \ + { "a8r8g8b8", 32, {16, 8}, {8, 8}, {0, 8}, {24, 8}, DRM_FORMAT_ARGB8888 }, \ + { "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 }, \ +} + +/* + * Data-Format for Simple-Framebuffers + * @name: unique 0-terminated name that can be used to identify the mode + * @red,green,blue: Offsets and sizes of the single RGB parts + * @transp: Offset and size of the alpha bits. length=0 means no alpha + * @fourcc: 32bit DRM four-CC code (see drm_fourcc.h) + */ +struct simplefb_format { + const char *name; + u32 bits_per_pixel; + struct fb_bitfield red; + struct fb_bitfield green; + struct fb_bitfield blue; + struct fb_bitfield transp; + u32 fourcc; +}; + +/* + * Simple-Framebuffer description + * If the arch-boot code creates simple-framebuffers without DT support, it + * can pass the width, height, stride and format via this platform-data object. + * The framebuffer location must be given as IORESOURCE_MEM resource. + * @format must be a format as described in "struct simplefb_format" above. + */ +struct simplefb_platform_data { + u32 width; + u32 height; + u32 stride; + const char *format; +}; + +#endif /* __PLATFORM_DATA_SIMPLEFB_H__ */