From patchwork Mon Apr 22 10:02:23 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 2471071 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) by patchwork2.kernel.org (Postfix) with ESMTP id 41DF3DF23A for ; Mon, 22 Apr 2013 10:09:27 +0000 (UTC) Received: from merlin.infradead.org ([205.233.59.134]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UUDeA-00032B-Uq; Mon, 22 Apr 2013 10:06:56 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UUDch-0003Qx-8S; Mon, 22 Apr 2013 10:05:24 +0000 Received: from mail.free-electrons.com ([94.23.35.102]) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UUDcF-0003Nb-BB for linux-arm-kernel@lists.infradead.org; Mon, 22 Apr 2013 10:04:57 +0000 Received: by mail.free-electrons.com (Postfix, from userid 106) id 033ADBED; Mon, 22 Apr 2013 12:04:54 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.3.2 Received: from localhost (per18-1-82-246-202-189.fbx.proxad.net [82.246.202.189]) by mail.free-electrons.com (Postfix) with ESMTPSA id 9EEDDC36; Mon, 22 Apr 2013 12:02:32 +0200 (CEST) From: Maxime Ripard To: Andrew Morton , Shawn Guo , Florian Tobias Schandinat Subject: [PATCH 2/4] ssd1307fb: Rework the communication functions Date: Mon, 22 Apr 2013 12:02:23 +0200 Message-Id: <1366624945-5708-3-git-send-email-maxime.ripard@free-electrons.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1366624945-5708-1-git-send-email-maxime.ripard@free-electrons.com> References: <1366624945-5708-1-git-send-email-maxime.ripard@free-electrons.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130422_060455_653057_A30043B0 X-CRM114-Status: GOOD ( 15.86 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: linux-fbdev@vger.kernel.org, Maxime Ripard , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org To efficiently send a whole page to the display, we need to be able to manipulate more easily the data arrays that has to be sent to the OLED controller. As such, this patch introduces a ssd1307fb_array structure that handles both the small header to be sent over i2c, which contains the type of information sent, and the raw bytes after that. Signed-off-by: Maxime Ripard --- drivers/video/ssd1307fb.c | 77 +++++++++++++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 27 deletions(-) diff --git a/drivers/video/ssd1307fb.c b/drivers/video/ssd1307fb.c index 5ab5281..35f5348 100644 --- a/drivers/video/ssd1307fb.c +++ b/drivers/video/ssd1307fb.c @@ -51,6 +51,11 @@ struct ssd1307fb_par { u32 width; }; +struct ssd1307fb_array { + u8 type; + u8 data[0]; +}; + static struct fb_fix_screeninfo ssd1307fb_fix = { .id = "Solomon SSD1307", .type = FB_TYPE_PACKED_PIXELS, @@ -65,49 +70,67 @@ static struct fb_var_screeninfo ssd1307fb_var = { .bits_per_pixel = 1, }; -static int ssd1307fb_write_array(struct i2c_client *client, u8 type, u8 *cmd, u32 len) +static struct ssd1307fb_array *ssd1307fb_alloc_array(u32 len, u8 type) { - u8 *buf; - int ret = 0; - - buf = kzalloc(len + 1, GFP_KERNEL); - if (!buf) { - dev_err(&client->dev, "Couldn't allocate sending buffer.\n"); - return -ENOMEM; - } + struct ssd1307fb_array *array; - buf[0] = type; - memcpy(buf + 1, cmd, len); + array = kzalloc(sizeof(struct ssd1307fb_array) + len, GFP_KERNEL); + if (!array) + return NULL; - ret = i2c_master_send(client, buf, len + 1); - if (ret != len + 1) { - dev_err(&client->dev, "Couldn't send I2C command.\n"); - goto error; - } + array->type = type; -error: - kfree(buf); - return ret; + return array; } -static inline int ssd1307fb_write_cmd_array(struct i2c_client *client, u8 *cmd, u32 len) +static int ssd1307fb_write_array(struct i2c_client *client, + struct ssd1307fb_array *array, u32 len) { - return ssd1307fb_write_array(client, SSD1307FB_COMMAND, cmd, len); + int ret; + + len += sizeof(struct ssd1307fb_array); + + ret = i2c_master_send(client, (u8 *)array, len); + if (ret != len) { + dev_err(&client->dev, "Couldn't send I2C command.\n"); + return ret; + } + + return 0; } static inline int ssd1307fb_write_cmd(struct i2c_client *client, u8 cmd) { - return ssd1307fb_write_cmd_array(client, &cmd, 1); -} + struct ssd1307fb_array *array; + int ret; -static inline int ssd1307fb_write_data_array(struct i2c_client *client, u8 *cmd, u32 len) -{ - return ssd1307fb_write_array(client, SSD1307FB_DATA, cmd, len); + array = ssd1307fb_alloc_array(1, SSD1307FB_COMMAND); + if (!array) + return -ENOMEM; + + array->data[0] = cmd; + + ret = ssd1307fb_write_array(client, array, 1); + kfree(array); + + return ret; } static inline int ssd1307fb_write_data(struct i2c_client *client, u8 data) { - return ssd1307fb_write_data_array(client, &data, 1); + struct ssd1307fb_array *array; + int ret; + + array = ssd1307fb_alloc_array(1, SSD1307FB_DATA); + if (!array) + return -ENOMEM; + + array->data[0] = data; + + ret = ssd1307fb_write_array(client, array, 1); + kfree(array); + + return ret; } static void ssd1307fb_update_display(struct ssd1307fb_par *par)