On Tue, Mar 26, 2019 at 10:17:40AM +0100, Thomas Zimmermann wrote: > Signed-off-by: Thomas Zimmermann <tzimmermann@xxxxxxx> > --- > drivers/gpu/drm/fbdevdrm/Makefile | 1 + > drivers/gpu/drm/fbdevdrm/fbdevdrm_format.c | 441 +++++++++++++++++++++ > drivers/gpu/drm/fbdevdrm/fbdevdrm_format.h | 26 ++ > 3 files changed, 468 insertions(+) > create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_format.c > create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_format.h > > diff --git a/drivers/gpu/drm/fbdevdrm/Makefile b/drivers/gpu/drm/fbdevdrm/Makefile > index b8fab9d52faa..aef60d0f4888 100644 > --- a/drivers/gpu/drm/fbdevdrm/Makefile > +++ b/drivers/gpu/drm/fbdevdrm/Makefile > @@ -2,6 +2,7 @@ ccflags-y = -Iinclude/drm > fbdevdrm-y := fbdevdrm_bo.o \ > fbdevdrm_device.o \ > fbdevdrm_drv.o \ > + fbdevdrm_format.o \ > fbdevdrm_modeset.o \ > fbdevdrm_ttm.o > > diff --git a/drivers/gpu/drm/fbdevdrm/fbdevdrm_format.c b/drivers/gpu/drm/fbdevdrm/fbdevdrm_format.c > new file mode 100644 > index 000000000000..208f7c60e525 > --- /dev/null > +++ b/drivers/gpu/drm/fbdevdrm/fbdevdrm_format.c > @@ -0,0 +1,441 @@ > +/* SPDX-License-Identifier: GPL-2.0-or-later > + * > + * One purpose of this driver is to allow for easy conversion of framebuffer > + * drivers to DRM. As a special exception to the GNU GPL, you are allowed to > + * relicense this file under the terms of a license of your choice if you're > + * porting a framebuffer driver. In order to do so, update the SPDX license > + * identifier to the new license and remove this exception. > + * > + * If you add code to this file, please ensure that it's compatible with the > + * stated exception. > + */ > + > +#include "fbdevdrm_format.h" > +#include <asm/byteorder.h> > +#include <linux/fb.h> > + > +#if defined __BIG_ENDIAN > +#define HOST_FUNC(_func) \ > + _func ## _be > +#elif defined __LITTLE_ENDIAN > +#define HOST_FUNC(_func) \ > + _func ## _le > +#else > +#error "Unsupported endianess" > +#endif > + > +static bool is_c8(const struct fb_info* fb_info) > +{ > + return fb_info->var.bits_per_pixel == 8; > +} > + > +static bool is_rgb565_be(const struct fb_info* fb_info) > +{ > + return (fb_info->var.bits_per_pixel == 16) && > + (fb_info->var.red.offset == 0) && > + (fb_info->var.red.length == 5) && > + (fb_info->var.green.offset == 5) && > + (fb_info->var.green.length == 6) && > + (fb_info->var.blue.offset == 11) && > + (fb_info->var.blue.length == 5); > +} You can't distinguish LE vs. BE like this. Maybe FBINFO_FOREIGN_ENDIAN is trustworthy? -- Ville Syrjälä Intel