From patchwork Tue Jul 7 08:14:36 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudip Mukherjee X-Patchwork-Id: 6731001 Return-Path: X-Original-To: patchwork-linux-fbdev@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 91B80C05AC for ; Tue, 7 Jul 2015 08:18:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A2E2720458 for ; Tue, 7 Jul 2015 08:18:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 842952045A for ; Tue, 7 Jul 2015 08:18:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756561AbbGGIPt (ORCPT ); Tue, 7 Jul 2015 04:15:49 -0400 Received: from mail-pa0-f45.google.com ([209.85.220.45]:34111 "EHLO mail-pa0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756350AbbGGIPD (ORCPT ); Tue, 7 Jul 2015 04:15:03 -0400 Received: by pabvl15 with SMTP id vl15so109456980pab.1; Tue, 07 Jul 2015 01:15:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=uJKA8dn69/JgqnOAncoCECr5v3iR+FUMtNrp//O8QSE=; b=qWoTR3Kap43nRCB6X0KYyH1Kb3Hm83II6qT2igYtzSjL1z1Z8YtOmRiWNAbuZBmRJf 6ZEFU0N6biqSJS4gl39X1aujPT+MkniWYgxrp/jCVNXkx3CSye1iLjiXrUEknfQ3j5Le Vu9WN5QvjuNQCrsz1KfsujW3qYM6EL2acf0lAzSn3OqVTkJo9nIuHyGxoN5KTBZHWIAW NOpVUo7LNVV6pHuBHfulJZ3sfIVYrcgGmZdH5XVPOYoBaT1TgCYwKbfe1H/3HYzSPQ4g kzyuSdgHRxA+FLZcBKorhSCpxPa0r2TYDSqSrNWzkoYU3+/7GBfJ/CEtQAdlkB1YTl3b y6WA== X-Received: by 10.70.89.199 with SMTP id bq7mr6297115pdb.168.1436256902830; Tue, 07 Jul 2015 01:15:02 -0700 (PDT) Received: from localhost.localdomain ([49.206.254.91]) by mx.google.com with ESMTPSA id wm8sm20823418pbc.19.2015.07.07.01.15.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 07 Jul 2015 01:15:02 -0700 (PDT) From: Sudip Mukherjee To: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-fbdev@vger.kernel.org, devel@driverdev.osuosl.org, Dan Carpenter , Sudip Mukherjee Subject: [PATCH 4/5] staging: sm7xxfb: define new macros Date: Tue, 7 Jul 2015 13:44:36 +0530 Message-Id: <1436256877-10754-5-git-send-email-sudipm.mukherjee@gmail.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1436256877-10754-1-git-send-email-sudipm.mukherjee@gmail.com> References: <1436256877-10754-1-git-send-email-sudipm.mukherjee@gmail.com> Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Define and use some new macros to work with different situations based on little-endian and big-endian. Signed-off-by: Sudip Mukherjee --- drivers/staging/sm7xxfb/sm7xx.h | 19 ++++++++++++++++ drivers/staging/sm7xxfb/sm7xxfb.c | 48 ++++++++------------------------------- 2 files changed, 29 insertions(+), 38 deletions(-) diff --git a/drivers/staging/sm7xxfb/sm7xx.h b/drivers/staging/sm7xxfb/sm7xx.h index 31a21bd..6905177 100644 --- a/drivers/staging/sm7xxfb/sm7xx.h +++ b/drivers/staging/sm7xxfb/sm7xx.h @@ -95,3 +95,22 @@ struct modeinit { unsigned char init_cr30_cr4d[SIZE_CR30_CR4D]; unsigned char init_cr90_cra7[SIZE_CR90_CRA7]; }; + +#ifdef __BIG_ENDIAN +#define pal_rgb(r, g, b, val) (((r & 0xf800) >> 8) | \ + ((g & 0xe000) >> 13) | \ + ((g & 0x1c00) << 3) | \ + ((b & 0xf800) >> 3)) +#define big_addr 0x800000 +#define mmio_addr 0x00800000 +#define seqw17 smtc_seqw(0x17, 0x30) +#define big_pixel_depth(p, d) {if (p == 24) {p = 32; d = 32; } } +#define big_swap(p) ((p & 0xff00ff00 >> 8) | (p & 0x00ff00ff << 8)) +#else +#define pal_rgb(r, g, b, val) val +#define big_addr 0 +#define mmio_addr 0x00c00000 +#define seqw17 +#define big_pixel_depth(p, d) +#define big_swap(p) p +#endif diff --git a/drivers/staging/sm7xxfb/sm7xxfb.c b/drivers/staging/sm7xxfb/sm7xxfb.c index 4dc9d5f..252f110a 100644 --- a/drivers/staging/sm7xxfb/sm7xxfb.c +++ b/drivers/staging/sm7xxfb/sm7xxfb.c @@ -923,25 +923,14 @@ static int smtc_setcolreg(unsigned regno, unsigned red, unsigned green, val = chan_to_field(red, &sfb->fb->var.red); val |= chan_to_field(green, &sfb->fb->var.green); val |= chan_to_field(blue, &sfb->fb->var.blue); -#ifdef __BIG_ENDIAN - pal[regno] = ((red & 0xf800) >> 8) | - ((green & 0xe000) >> 13) | - ((green & 0x1c00) << 3) | - ((blue & 0xf800) >> 3); -#else - pal[regno] = val; -#endif + pal[regno] = pal_rgb(red, green, blue, val); } else { u32 *pal = sfb->fb->pseudo_palette; val = chan_to_field(red, &sfb->fb->var.red); val |= chan_to_field(green, &sfb->fb->var.green); val |= chan_to_field(blue, &sfb->fb->var.blue); -#ifdef __BIG_ENDIAN - val = (val & 0xff00ff00 >> 8) | - (val & 0x00ff00ff << 8); -#endif - pal[regno] = val; + pal[regno] = big_swap(val); } break; @@ -1002,8 +991,7 @@ static ssize_t smtcfb_read(struct fb_info *info, char __user *buf, dst = buffer; for (i = c >> 2; i--;) { *dst = fb_readl(src++); - *dst = (*dst & 0xff00ff00 >> 8) | - (*dst & 0x00ff00ff << 8); + *dst = big_swap(*dst); dst++; } if (c & 3) { @@ -1091,8 +1079,7 @@ static ssize_t smtcfb_write(struct fb_info *info, const char __user *buf, } for (i = c >> 2; i--;) { - fb_writel((*src & 0xff00ff00 >> 8) | - (*src & 0x00ff00ff << 8), dst++); + fb_writel(big_swap(*src), dst++); src++; } if (c & 3) { @@ -1341,10 +1328,8 @@ static int smtc_map_smem(struct smtcfb_info *sfb, { sfb->fb->fix.smem_start = pci_resource_start(pdev, 0); -#ifdef __BIG_ENDIAN if (sfb->fb->var.bits_per_pixel == 32) - sfb->fb->fix.smem_start += 0x800000; -#endif + sfb->fb->fix.smem_start += big_addr; sfb->fb->fix.smem_len = smem_len; @@ -1437,10 +1422,7 @@ static int smtcfb_pci_probe(struct pci_dev *pdev, sfb->fb->var.bits_per_pixel = SCREEN_BPP; } -#ifdef __BIG_ENDIAN - if (sfb->fb->var.bits_per_pixel == 24) - sfb->fb->var.bits_per_pixel = (smtc_scr_info.lfb_depth = 32); -#endif + big_pixel_depth(sfb->fb->var.bits_per_pixel, smtc_scr_info.lfb_depth); /* Map address and memory detection */ mmio_base = pci_resource_start(pdev, 0); pci_read_config_byte(pdev, PCI_REVISION_ID, &sfb->chip_rev_id); @@ -1451,11 +1433,7 @@ static int smtcfb_pci_probe(struct pci_dev *pdev, sfb->fb->fix.mmio_start = mmio_base + 0x00400000; sfb->fb->fix.mmio_len = 0x00400000; smem_size = SM712_VIDEOMEMORYSIZE; -#ifdef __BIG_ENDIAN - sfb->lfb = ioremap(mmio_base, 0x00c00000); -#else - sfb->lfb = ioremap(mmio_base, 0x00800000); -#endif + sfb->lfb = ioremap(mmio_base, mmio_addr); if (!sfb->lfb) { dev_err(&pdev->dev, "%s: unable to map memory mapped IO!\n", @@ -1468,12 +1446,10 @@ static int smtcfb_pci_probe(struct pci_dev *pdev, sfb->lfb + 0x00700000); sfb->dp_regs = sfb->lfb + 0x00408000; sfb->vp_regs = sfb->lfb + 0x0040c000; -#ifdef __BIG_ENDIAN if (sfb->fb->var.bits_per_pixel == 32) { - sfb->lfb += 0x800000; + sfb->lfb += big_addr; dev_info(&pdev->dev, "sfb->lfb=%p\n", sfb->lfb); } -#endif /* set MCLK = 14.31818 * (0x16 / 0x2) */ smtc_seqw(0x6a, 0x16); @@ -1482,10 +1458,8 @@ static int smtcfb_pci_probe(struct pci_dev *pdev, /* enable PCI burst */ smtc_seqw(0x17, 0x20); /* enable word swap */ -#ifdef __BIG_ENDIAN if (sfb->fb->var.bits_per_pixel == 32) - smtc_seqw(0x17, 0x30); -#endif + seqw17; break; case 0x720: sfb->fb->fix.mmio_start = mmio_base; @@ -1617,10 +1591,8 @@ static int smtcfb_pci_resume(struct device *device) smtc_seqw(0x62, 0x3e); /* enable PCI burst */ smtc_seqw(0x17, 0x20); -#ifdef __BIG_ENDIAN if (sfb->fb->var.bits_per_pixel == 32) - smtc_seqw(0x17, 0x30); -#endif + seqw17; break; case 0x720: smtc_seqw(0x62, 0xff);