From patchwork Wed Jul 15 08:29:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudip Mukherjee X-Patchwork-Id: 6794541 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 06F60C05AD for ; Wed, 15 Jul 2015 08:31:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 08C4E205B9 for ; Wed, 15 Jul 2015 08:31:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3445F205F4 for ; Wed, 15 Jul 2015 08:30:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752279AbbGOIaA (ORCPT ); Wed, 15 Jul 2015 04:30:00 -0400 Received: from mail-pd0-f170.google.com ([209.85.192.170]:34800 "EHLO mail-pd0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751843AbbGOI34 (ORCPT ); Wed, 15 Jul 2015 04:29:56 -0400 Received: by pdbep18 with SMTP id ep18so21862862pdb.1; Wed, 15 Jul 2015 01:29:56 -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; bh=7SzSI+fnIzg8AumJ/A6/T87zJOiz64FmYpa9UA281+M=; b=POAxTUt/9sQDgjoTb/C10pjjPE2eslcRe/uLhrtx/FaDuUzBmSfmPTlTj1vLdXazz9 Jaz6BG28sVeBZDjfYsLkNkNAo1KvGLFn3KV2wR1Kt1sQhc1D24a/nWPQqy7ZCtvRZz65 NV1UT56w7QyJtaKtHo7B4PHyg4vyqLOqlNa2S8GvCVXhtxZKcEKPFyOzsFo6VqjGVGBp 9lHp2Q5oOMcbfeo1CGzE4/L4g9YpV8JhOJL4U8S0VAQOcfVu+B+M62Bn3w0LLHGLaBbB H7S6PtqDAD+LgHzG77yN6c7kwuVPhdQ9HbsR8YgFzZopbq7GJKalJCdCMU9+qN0yMbHV lHZg== X-Received: by 10.70.123.37 with SMTP id lx5mr5698248pdb.83.1436948995987; Wed, 15 Jul 2015 01:29:55 -0700 (PDT) Received: from localhost.localdomain ([49.206.246.192]) by smtp.gmail.com with ESMTPSA id to5sm3780058pac.33.2015.07.15.01.29.53 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 15 Jul 2015 01:29:54 -0700 (PDT) From: Sudip Mukherjee To: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-fbdev@vger.kernel.org, devel@driverdev.osuosl.org, Sudip Mukherjee Subject: [PATCH v2 1/2] staging: sm7xxfb: define new macros Date: Wed, 15 Jul 2015 13:59:45 +0530 Message-Id: <1436948986-29664-1-git-send-email-sudipm.mukherjee@gmail.com> X-Mailer: git-send-email 1.8.1.2 Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org X-Spam-Status: No, score=-8.2 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 --- v2: fixed empty macro 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..de134b0 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() do { } while (0) +#define big_pixel_depth(p, d) do { } while (0) +#define big_swap(p) p +#endif diff --git a/drivers/staging/sm7xxfb/sm7xxfb.c b/drivers/staging/sm7xxfb/sm7xxfb.c index 4dc9d5f..106465c 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);