From patchwork Sat Mar 9 21:48:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dante Paz X-Patchwork-Id: 10846043 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 615D14B79 for ; Sat, 9 Mar 2019 21:49:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3838726E78 for ; Sat, 9 Mar 2019 21:49:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 26062289BE; Sat, 9 Mar 2019 21:49:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C31D626E78 for ; Sat, 9 Mar 2019 21:49:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726424AbfCIVtu (ORCPT ); Sat, 9 Mar 2019 16:49:50 -0500 Received: from mail-qk1-f194.google.com ([209.85.222.194]:37059 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726348AbfCIVtu (ORCPT ); Sat, 9 Mar 2019 16:49:50 -0500 Received: by mail-qk1-f194.google.com with SMTP id m9so661480qkl.4 for ; Sat, 09 Mar 2019 13:49:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=P3UjJOhMRVS8bcXLs7Od3rpPEusYn88sazfEWdi0fTM=; b=f1IY3TJezl7+hr9NW4UAVDK7Djb6IEdv9K6Z4l02hqCWNKAM2ewX8hvoYS7Lw+bwqn mkLmfNmW5MQiTVuKvFLtiq0qZ2nayQCv9SDBLTy/JmKcexxdpbigmQkyC/Ad3Sd0Mi+Q 82gWZB4p3fPmixp9iQe3wTIemDQTIgZkjyPKfkK/F14P79X5Dlmw2dEm3i9DzVIUcvQH 40AuqMDNXf8boFjiMSb6tJvNFlpEz7rOYA69MZS0mmo1TBPjAW4lU7QEWUQu3cSG1Qkn S/+vuEXW0rQwgA0T+PBTRO7yACn30xUJMeKzZ8+OJPg19rYuEXpu55LR3ov2J8wJrWXW 1Qbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=P3UjJOhMRVS8bcXLs7Od3rpPEusYn88sazfEWdi0fTM=; b=WBzPP2vmp+hkX8W/QjHKpZIvqv+eiI+MX9hVGiXpksHOSfI168xhZysEjHnro55Pt/ GrzRBVUUQbCudlDGv5p78u7OTBKQC4MN8f6evrT3VjO+9MUYlo95f57Xtv0hoVeru+i9 RaIAsbJNQaBSFe/OVpE0jJjRe5IFD3TsrfV6SF3+LWWNr+2cJmUFpxwBPcfTI4MlqcZk dq2LlO4nsuFn4y7ch3nMpjQKksU0PGxeIK7woN+BN7S7PGkZSMvA8NFoTZVgYskst0NI RK8bNmBSWOfOFi2xXKDvrFNEDtngVyuzzgFMUgjdkOuW9UP2NGKo7UPMXiHNAhtu3SEo AgYw== X-Gm-Message-State: APjAAAVp8EARwLwu2BUPIl0yUyTaBMbfPw2vQO7RkqM8SFh8NSSSykhe up12BTQTILgntE7x71XBeTk= X-Google-Smtp-Source: APXvYqzr1ZWJi0FsBkJXepPs0IXI03qWTtx/hjCXDFUFV65nyrNKWUogv6e0XMDRfF6m6S8EZPA+xw== X-Received: by 2002:a37:9d96:: with SMTP id g144mr19269837qke.192.1552168187713; Sat, 09 Mar 2019 13:49:47 -0800 (PST) Received: from localhost.localdomain ([181.167.60.233]) by smtp.gmail.com with ESMTPSA id n44sm911681qtc.6.2019.03.09.13.49.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 09 Mar 2019 13:49:47 -0800 (PST) From: Dante Paz To: gregkh@linuxfoundation.org Cc: linux-fbdev@vger.kernel.org, devel@driverdev.osuosl.org, leobras.c@gmail.com, nishadkamdar@gmail.com, renatoys08@gmail.com, dri-devel@lists.freedesktop.org, Dante Paz Subject: [PATCH] FBTFT: fbtft-bus: Fix code style problems Date: Sat, 9 Mar 2019 18:48:52 -0300 Message-Id: <20190309214852.12233-1-dante.paz@gmail.com> X-Mailer: git-send-email 2.17.2 Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Dante Paz Style and coding function issues were corrected, by avoiding macro functions with a conflicting coding style. Signed-off-by: Dante Paz --- drivers/staging/fbtft/fbtft-bus.c | 440 +++++++++++++++++------------- 1 file changed, 254 insertions(+), 186 deletions(-) diff --git a/drivers/staging/fbtft/fbtft-bus.c b/drivers/staging/fbtft/fbtft-bus.c index 2ea814d0dca5..6f49306cd162 100644 --- a/drivers/staging/fbtft/fbtft-bus.c +++ b/drivers/staging/fbtft/fbtft-bus.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include #include -#include +#include #include #include "fbtft.h" @@ -11,103 +11,171 @@ * *****************************************************************************/ -#define define_fbtft_write_reg(func, buffer_type, data_type, modifier) \ -void func(struct fbtft_par *par, int len, ...) \ -{ \ - va_list args; \ - int i, ret; \ - int offset = 0; \ - buffer_type *buf = (buffer_type *)par->buf; \ - \ - if (unlikely(par->debug & DEBUG_WRITE_REGISTER)) { \ - va_start(args, len); \ - for (i = 0; i < len; i++) { \ - buf[i] = modifier((data_type)va_arg(args, \ - unsigned int)); \ - } \ - va_end(args); \ - fbtft_par_dbg_hex(DEBUG_WRITE_REGISTER, par, \ - par->info->device, buffer_type, buf, len, \ - "%s: ", __func__); \ - } \ - \ - va_start(args, len); \ - \ - if (par->startbyte) { \ - *(u8 *)par->buf = par->startbyte; \ - buf = (buffer_type *)(par->buf + 1); \ - offset = 1; \ - } \ - \ - *buf = modifier((data_type)va_arg(args, unsigned int)); \ - ret = fbtft_write_buf_dc(par, par->buf, sizeof(data_type) + offset, \ - 0); \ - if (ret < 0) \ - goto out; \ - len--; \ - \ - if (par->startbyte) \ - *(u8 *)par->buf = par->startbyte | 0x2; \ - \ - if (len) { \ - i = len; \ - while (i--) \ - *buf++ = modifier((data_type)va_arg(args, \ - unsigned int)); \ - fbtft_write_buf_dc(par, par->buf, \ - len * (sizeof(data_type) + offset), 1); \ - } \ -out: \ - va_end(args); \ -} \ -EXPORT_SYMBOL(func); - -define_fbtft_write_reg(fbtft_write_reg8_bus8, u8, u8, ) -define_fbtft_write_reg(fbtft_write_reg16_bus8, __be16, u16, cpu_to_be16) -define_fbtft_write_reg(fbtft_write_reg16_bus16, u16, u16, ) +void fbtft_write_reg8_bus8(struct fbtft_par *par, int len, ...) +{ + va_list args; + int i, ret; + int offset = 0; + + u8 *buf = (u8 *)par->buf; + + if (unlikely(par->debug & DEBUG_WRITE_REGISTER)) { + va_start(args, len); + for (i = 0; i < len; i++) + buf[i] = ((u8)va_arg(args, unsigned int)); + + va_end(args); + fbtft_par_dbg_hex(DEBUG_WRITE_REGISTER, par, par->info->device, + u8, buf, len, "%s: ", __func__); + } + va_start(args, len); + if (par->startbyte) { + *(u8 *)par->buf = par->startbyte; + buf = (u8 *)(par->buf + 1); + offset = 1; + } + *buf = ((u8)va_arg(args, unsigned int)); + ret = fbtft_write_buf_dc(par, par->buf, sizeof(u8) + offset, 0); + if (ret < 0) + goto out; + len--; + if (par->startbyte) + *(u8 *)par->buf = par->startbyte | 0x2; + if (len) { + i = len; + while (i--) + *buf++ = ((u8)va_arg(args, unsigned int)); + fbtft_write_buf_dc(par, par->buf, + len*(sizeof(u8) + offset), 1); + } out: + va_end(args); +} +EXPORT_SYMBOL(fbtft_write_reg8_bus8); + +void fbtft_write_reg16_bus8(struct fbtft_par *par, int len, ...) +{ + va_list args; + int i, ret; + int offset = 0; + + __be16 *buf = (__be16 *)par->buf; + + if (unlikely(par->debug & DEBUG_WRITE_REGISTER)) { + va_start(args, len); + for (i = 0; i < len; i++) + buf[i] = cpu_to_be16((u16)va_arg(args, unsigned int)); + + va_end(args); + fbtft_par_dbg_hex(DEBUG_WRITE_REGISTER, par, par->info->device, + __be16, buf, len, "%s: ", __func__); + } + va_start(args, len); + if (par->startbyte) { + *(u8 *)par->buf = par->startbyte; + buf = (__be16 *)(par->buf + 1); + offset = 1; + } + *buf = cpu_to_be16((u16)va_arg(args, unsigned int)); + ret = fbtft_write_buf_dc(par, par->buf, sizeof(u16) + offset, 0); + if (ret < 0) + goto out; + len--; + if (par->startbyte) + *(u8 *)par->buf = par->startbyte | 0x2; + if (len) { + i = len; + while (i--) + *buf++ = cpu_to_be16((u16)va_arg(args, unsigned int)); + fbtft_write_buf_dc(par, par->buf, + len*(sizeof(u16) + offset), 1); + } out: + va_end(args); +} +EXPORT_SYMBOL(fbtft_write_reg16_bus8); + +void fbtft_write_reg16_bus16(struct fbtft_par *par, int len, ...) +{ + va_list args; + int i, ret; + int offset = 0; + u16 *buf = (u16 *)par->buf; + + if (unlikely(par->debug & DEBUG_WRITE_REGISTER)) { + va_start(args, len); + for (i = 0; i < len; i++) + buf[i] = ((u16)va_arg(args, unsigned int)); + + va_end(args); + fbtft_par_dbg_hex(DEBUG_WRITE_REGISTER, par, par->info->device, + u16, buf, len, "%s: ", __func__); + } + va_start(args, len); + + if (par->startbyte) { + *(u8 *)par->buf = par->startbyte; + buf = (u16 *)(par->buf + 1); + offset = 1; + } + *buf = ((u16)va_arg(args, unsigned int)); + ret = fbtft_write_buf_dc(par, par->buf, sizeof(u16) + offset, 0); + if (ret < 0) + goto out; + len--; + if (par->startbyte) + *(u8 *)par->buf = par->startbyte | 0x2; + if (len) { + i = len; + while (i--) + *buf++ = ((u16)va_arg(args, unsigned int)); + fbtft_write_buf_dc(par, par->buf, + len*(sizeof(u16) + offset), 1); + } out: + va_end(args); +} +EXPORT_SYMBOL(fbtft_write_reg16_bus16); void fbtft_write_reg8_bus9(struct fbtft_par *par, int len, ...) { - va_list args; - int i, ret; - int pad = 0; - u16 *buf = (u16 *)par->buf; - - if (unlikely(par->debug & DEBUG_WRITE_REGISTER)) { - va_start(args, len); - for (i = 0; i < len; i++) - *(((u8 *)buf) + i) = (u8)va_arg(args, unsigned int); - va_end(args); - fbtft_par_dbg_hex(DEBUG_WRITE_REGISTER, par, - par->info->device, u8, buf, len, "%s: ", - __func__); - } - if (len <= 0) - return; - - if (par->spi && (par->spi->bits_per_word == 8)) { - /* we're emulating 9-bit, pad start of buffer with no-ops - * (assuming here that zero is a no-op) - */ - pad = (len % 4) ? 4 - (len % 4) : 0; - for (i = 0; i < pad; i++) - *buf++ = 0x000; - } - - va_start(args, len); - *buf++ = (u8)va_arg(args, unsigned int); - i = len - 1; - while (i--) { - *buf = (u8)va_arg(args, unsigned int); - *buf++ |= 0x100; /* dc=1 */ - } - va_end(args); - ret = par->fbtftops.write(par, par->buf, (len + pad) * sizeof(u16)); - if (ret < 0) { - dev_err(par->info->device, - "write() failed and returned %d\n", ret); - return; - } + va_list args; + int i, ret; + int pad = 0; + u16 *buf = (u16 *)par->buf; + + if (unlikely(par->debug & DEBUG_WRITE_REGISTER)) { + va_start(args, len); + for (i = 0; i < len; i++) + *(((u8 *)buf) + i) = (u8)va_arg(args, unsigned int); + va_end(args); + fbtft_par_dbg_hex(DEBUG_WRITE_REGISTER, par, + par->info->device, u8, buf, len, "%s: ", + __func__); + } + if (len <= 0) + return; + + if (par->spi && (par->spi->bits_per_word == 8)) { + /* we're emulating 9-bit, pad start of buffer with no-ops + * (assuming here that zero is a no-op) + */ + pad = (len % 4) ? 4 - (len % 4) : 0; + for (i = 0; i < pad; i++) + *buf++ = 0x000; + } + + va_start(args, len); + *buf++ = (u8)va_arg(args, unsigned int); + i = len - 1; + while (i--) { + *buf = (u8)va_arg(args, unsigned int); + *buf++ |= 0x100; /* dc=1 */ + } + va_end(args); + ret = par->fbtftops.write(par, par->buf, (len + pad) * sizeof(u16)); + if (ret < 0) { + dev_err(par->info->device, + "write() failed and returned %d\n", ret); + return; + } } EXPORT_SYMBOL(fbtft_write_reg8_bus9); @@ -120,125 +188,125 @@ EXPORT_SYMBOL(fbtft_write_reg8_bus9); /* 16 bit pixel over 8-bit databus */ int fbtft_write_vmem16_bus8(struct fbtft_par *par, size_t offset, size_t len) { - u16 *vmem16; - __be16 *txbuf16 = par->txbuf.buf; - size_t remain; - size_t to_copy; - size_t tx_array_size; - int i; - int ret = 0; - size_t startbyte_size = 0; - - fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s(offset=%zu, len=%zu)\n", - __func__, offset, len); - - remain = len / 2; - vmem16 = (u16 *)(par->info->screen_buffer + offset); - - if (!par->gpio.dc) - gpiod_set_value(par->gpio.dc, 1); - - /* non buffered write */ - if (!par->txbuf.buf) - return par->fbtftops.write(par, vmem16, len); - - /* buffered write */ - tx_array_size = par->txbuf.len / 2; - - if (par->startbyte) { - txbuf16 = par->txbuf.buf + 1; - tx_array_size -= 2; - *(u8 *)(par->txbuf.buf) = par->startbyte | 0x2; - startbyte_size = 1; - } - - while (remain) { - to_copy = min(tx_array_size, remain); - dev_dbg(par->info->device, "to_copy=%zu, remain=%zu\n", - to_copy, remain - to_copy); - - for (i = 0; i < to_copy; i++) - txbuf16[i] = cpu_to_be16(vmem16[i]); - - vmem16 = vmem16 + to_copy; - ret = par->fbtftops.write(par, par->txbuf.buf, - startbyte_size + to_copy * 2); - if (ret < 0) - return ret; - remain -= to_copy; - } - - return ret; + u16 *vmem16; + __be16 *txbuf16 = par->txbuf.buf; + size_t remain; + size_t to_copy; + size_t tx_array_size; + int i; + int ret = 0; + size_t startbyte_size = 0; + + fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s(offset=%zu, len=%zu)\n", + __func__, offset, len); + + remain = len / 2; + vmem16 = (u16 *)(par->info->screen_buffer + offset); + + if (par->gpio.dc != -1) + gpio_set_value(par->gpio.dc, 1); + + /* non buffered write */ + if (!par->txbuf.buf) + return par->fbtftops.write(par, vmem16, len); + + /* buffered write */ + tx_array_size = par->txbuf.len / 2; + + if (par->startbyte) { + txbuf16 = par->txbuf.buf + 1; + tx_array_size -= 2; + *(u8 *)(par->txbuf.buf) = par->startbyte | 0x2; + startbyte_size = 1; + } + + while (remain) { + to_copy = min(tx_array_size, remain); + dev_dbg(par->info->device, "to_copy=%zu, remain=%zu\n", + to_copy, remain - to_copy); + + for (i = 0; i < to_copy; i++) + txbuf16[i] = cpu_to_be16(vmem16[i]); + + vmem16 = vmem16 + to_copy; + ret = par->fbtftops.write(par, par->txbuf.buf, + startbyte_size + to_copy * 2); + if (ret < 0) + return ret; + remain -= to_copy; + } + + return ret; } EXPORT_SYMBOL(fbtft_write_vmem16_bus8); /* 16 bit pixel over 9-bit SPI bus: dc + high byte, dc + low byte */ int fbtft_write_vmem16_bus9(struct fbtft_par *par, size_t offset, size_t len) { - u8 *vmem8; - u16 *txbuf16 = par->txbuf.buf; - size_t remain; - size_t to_copy; - size_t tx_array_size; - int i; - int ret = 0; + u8 *vmem8; + u16 *txbuf16 = par->txbuf.buf; + size_t remain; + size_t to_copy; + size_t tx_array_size; + int i; + int ret = 0; - fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s(offset=%zu, len=%zu)\n", - __func__, offset, len); + fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s(offset=%zu, len=%zu)\n", + __func__, offset, len); - if (!par->txbuf.buf) { - dev_err(par->info->device, "%s: txbuf.buf is NULL\n", __func__); - return -1; - } + if (!par->txbuf.buf) { + dev_err(par->info->device, "%s: txbuf.buf is NULL\n", __func__); + return -1; + } - remain = len; - vmem8 = par->info->screen_buffer + offset; + remain = len; + vmem8 = par->info->screen_buffer + offset; - tx_array_size = par->txbuf.len / 2; + tx_array_size = par->txbuf.len / 2; - while (remain) { - to_copy = min(tx_array_size, remain); - dev_dbg(par->info->device, "to_copy=%zu, remain=%zu\n", - to_copy, remain - to_copy); + while (remain) { + to_copy = min(tx_array_size, remain); + dev_dbg(par->info->device, "to_copy=%zu, remain=%zu\n", + to_copy, remain - to_copy); #ifdef __LITTLE_ENDIAN - for (i = 0; i < to_copy; i += 2) { - txbuf16[i] = 0x0100 | vmem8[i + 1]; - txbuf16[i + 1] = 0x0100 | vmem8[i]; - } + for (i = 0; i < to_copy; i += 2) { + txbuf16[i] = 0x0100 | vmem8[i + 1]; + txbuf16[i + 1] = 0x0100 | vmem8[i]; + } #else - for (i = 0; i < to_copy; i++) - txbuf16[i] = 0x0100 | vmem8[i]; + for (i = 0; i < to_copy; i++) + txbuf16[i] = 0x0100 | vmem8[i]; #endif - vmem8 = vmem8 + to_copy; - ret = par->fbtftops.write(par, par->txbuf.buf, to_copy * 2); - if (ret < 0) - return ret; - remain -= to_copy; - } - - return ret; + vmem8 = vmem8 + to_copy; + ret = par->fbtftops.write(par, par->txbuf.buf, to_copy * 2); + if (ret < 0) + return ret; + remain -= to_copy; + } + + return ret; } EXPORT_SYMBOL(fbtft_write_vmem16_bus9); int fbtft_write_vmem8_bus8(struct fbtft_par *par, size_t offset, size_t len) { - dev_err(par->info->device, "%s: function not implemented\n", __func__); - return -1; + dev_err(par->info->device, "%s: function not implemented\n", __func__); + return -1; } EXPORT_SYMBOL(fbtft_write_vmem8_bus8); /* 16 bit pixel over 16-bit databus */ int fbtft_write_vmem16_bus16(struct fbtft_par *par, size_t offset, size_t len) { - u16 *vmem16; + u16 *vmem16; - fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s(offset=%zu, len=%zu)\n", - __func__, offset, len); + fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s(offset=%zu, len=%zu)\n", + __func__, offset, len); - vmem16 = (u16 *)(par->info->screen_buffer + offset); + vmem16 = (u16 *)(par->info->screen_buffer + offset); - /* no need for buffered write with 16-bit bus */ - return fbtft_write_buf_dc(par, vmem16, len, 1); + /* no need for buffered write with 16-bit bus */ + return fbtft_write_buf_dc(par, vmem16, len, 1); } EXPORT_SYMBOL(fbtft_write_vmem16_bus16);