From patchwork Fri Mar 22 14:16:29 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Heiko_St=C3=BCbner?= X-Patchwork-Id: 2320491 Return-Path: X-Original-To: patchwork-linux-fbdev@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 0283B400E6 for ; Fri, 22 Mar 2013 14:16:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932792Ab3CVOQc (ORCPT ); Fri, 22 Mar 2013 10:16:32 -0400 Received: from gloria.sntech.de ([95.129.55.99]:40387 "EHLO gloria.sntech.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932116Ab3CVOQc (ORCPT ); Fri, 22 Mar 2013 10:16:32 -0400 Received: from 146-52-57-5-dynip.superkabel.de ([146.52.57.5] helo=marty.localnet) by gloria.sntech.de with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.72) (envelope-from ) id 1UJ2lj-00082S-8O; Fri, 22 Mar 2013 15:16:31 +0100 From: Heiko =?utf-8?q?St=C3=BCbner?= To: Florian Tobias Schandinat Subject: [PATCH 7/9] AUO-K190x: add a 16bit truecolor mode Date: Fri, 22 Mar 2013 15:16:29 +0100 User-Agent: KMail/1.13.7 (Linux/3.2.0-3-686-pae; KDE/4.8.4; i686; ; ) Cc: Tomi Valkeinen , "linux-fbdev" References: <201303221512.28604.heiko@sntech.de> In-Reply-To: <201303221512.28604.heiko@sntech.de> MIME-Version: 1.0 Message-Id: <201303221516.29815.heiko@sntech.de> Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org Some applications seem to have problems using the 8bit grayscale mode. Therefore provide a 16bit truecolor mode which also gets converted to the 4bit grayscale the display uses, when updating a region. Signed-off-by: Heiko Stübner --- drivers/video/auo_k190x.c | 71 +++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 69 insertions(+), 2 deletions(-) diff --git a/drivers/video/auo_k190x.c b/drivers/video/auo_k190x.c index 848cfe9..69abb9c 100644 --- a/drivers/video/auo_k190x.c +++ b/drivers/video/auo_k190x.c @@ -59,6 +59,46 @@ static void auok190x_issue_cmd(struct auok190xfb_par *par, u16 data) par->board->set_ctl(par, AUOK190X_I80_DC, 1); } +/** + * Conversion of 16bit color to 4bit grayscale + * does roughly (0.3 * R + 0.6 G + 0.1 B) / 2 + */ +static inline int rgb565_to_gray4(u16 data, struct fb_var_screeninfo *var) +{ + return ((((data & 0xF800) >> var->red.offset) * 77 + + ((data & 0x07E0) >> (var->green.offset + 1)) * 151 + + ((data & 0x1F) >> var->blue.offset) * 28) >> 8 >> 1); +} + +static int auok190x_issue_pixels_rgb565(struct auok190xfb_par *par, int size, + u16 *data) +{ + struct fb_var_screeninfo *var = &par->info->var; + struct device *dev = par->info->device; + int i; + u16 tmp; + + if (size & 7) { + dev_err(dev, "issue_pixels: size %d must be a multiple of 8\n", + size); + return -EINVAL; + } + + for (i = 0; i < (size >> 2); i++) { + par->board->set_ctl(par, AUOK190X_I80_WR, 0); + + tmp = (rgb565_to_gray4(data[4*i], var) & 0x000F); + tmp |= (rgb565_to_gray4(data[4*i+1], var) << 4) & 0x00F0; + tmp |= (rgb565_to_gray4(data[4*i+2], var) << 8) & 0x0F00; + tmp |= (rgb565_to_gray4(data[4*i+3], var) << 12) & 0xF000; + + par->board->set_hdb(par, tmp); + par->board->set_ctl(par, AUOK190X_I80_WR, 1); + } + + return 0; +} + static int auok190x_issue_pixels_gray8(struct auok190xfb_par *par, int size, u16 *data) { @@ -98,6 +138,8 @@ static int auok190x_issue_pixels(struct auok190xfb_par *par, int size, if (info->var.bits_per_pixel == 8 && info->var.grayscale) auok190x_issue_pixels_gray8(par, size, data); + else if (info->var.bits_per_pixel == 16) + auok190x_issue_pixels_rgb565(par, size, data); else dev_err(dev, "unsupported color mode (bits: %d, gray: %d)\n", info->var.bits_per_pixel, info->var.grayscale); @@ -418,6 +460,22 @@ static int auok190xfb_check_var(struct fb_var_screeninfo *var, var->transp.length = 0; var->transp.offset = 0; var->transp.msb_right = 0; + } else if (var->bits_per_pixel == 16) { + var->red.length = 5; + var->red.offset = 11; + var->red.msb_right = 0; + + var->green.length = 6; + var->green.offset = 5; + var->green.msb_right = 0; + + var->blue.length = 5; + var->blue.offset = 0; + var->blue.msb_right = 0; + + var->transp.length = 0; + var->transp.offset = 0; + var->transp.msb_right = 0; } else { dev_warn(dev, "unsupported color mode (bits: %d, grayscale: %d)\n", info->var.bits_per_pixel, info->var.grayscale); @@ -471,6 +529,15 @@ static int auok190xfb_set_fix(struct fb_info *info) return 0; } +static int auok190xfb_set_par(struct fb_info *info) +{ + struct auok190xfb_par *par = info->par; + + auok190xfb_set_fix(info); + + return 0; +} + static struct fb_ops auok190xfb_ops = { .owner = THIS_MODULE, .fb_read = fb_sys_read, @@ -479,6 +546,7 @@ static struct fb_ops auok190xfb_ops = { .fb_copyarea = auok190xfb_copyarea, .fb_imageblit = auok190xfb_imageblit, .fb_check_var = auok190xfb_check_var, + .fb_set_par = auok190xfb_set_par, }; /* @@ -965,8 +1033,7 @@ int __devinit auok190x_common_probe(struct platform_device *pdev, /* videomemory handling */ - videomemorysize = roundup((panel->w * panel->h) * - info->var.bits_per_pixel / 8, PAGE_SIZE); + videomemorysize = roundup((panel->w * panel->h) * 2, PAGE_SIZE); videomemory = vmalloc(videomemorysize); if (!videomemory) { ret = -ENOMEM;