Received: by 2002:a17:90a:1609:0:0:0:0 with SMTP id n9csp595570pja; Thu, 19 Mar 2020 08:03:46 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtheT21WFRqXVQDPgKe4z2N+MWPV/Xmysp6slCqR8bBFuFVq8nxwZUq0tcQ+gvwNnYtpO+s X-Received: by 2002:a05:6830:239b:: with SMTP id l27mr2815855ots.278.1584630225895; Thu, 19 Mar 2020 08:03:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584630225; cv=none; d=google.com; s=arc-20160816; b=lmQf3Kxf7ms07n/Dmlh7sEfHIyFv0OYUgd5Irs3Oo+jSqlBA8XMBLHlk3F/M4fPkDy jM79+91VEv8yyE8U6XM1R4YkWhjizcHyFg3bfS581iOIPNqUmTkimZEf9OndTUreCVQA BbjFDJUWm/WuiwAR3zjidU1hKn5LUdEZ285GQUZC7jYHNV3f9uWWS95eLkYV+xaDR4sZ /V+AcID94XSu1acVW9GC6fhoz0MmHzBeJCLsqpD66nO6NDB+EchdBtxWdc5PDnUjR9an bmMcxm1GNbpFyC6Lmyowe+SLrkQvkzC26cFL8LWV7KVwGqRmokC9QTu4OZJ5lb7GVDKK n9QA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:ironport-sdr:ironport-sdr; bh=6pjXTq0kJjL1G67bBzt1QEIFhnW+HF4Vec/trCWeZXM=; b=bPr/zBQWm0v6JvzkA0phD+0JDk7hi9lYRIIapWr4+lcBKb+UMBbw4Dyck+fC4hAFb+ 2VlOdZ4iJ4P4lNq/suVHYPY+ZH3FpIYQzmJ13TSVK5gj/cjXAGXT1Qw1BohW0/o9QhX8 6DGAjnswhZ8ctDIAbnruxYLPemVnhFQkaysOjLlGa/UEEibuewyK8FlCzb55JpBzsquL aZT15jFGV9HmvVQFOksMF+PSSF7tFdaB9av2DiclGGdBytg6P6cckw8nkQUz3CqrQow5 CA/OjGSmJnegtaQID76tXPFH0qxKz1glKyM4GRiVoNaiFFnsi9JuuOO4X+04aE+UOh9n 1K5A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j192si1087997oih.233.2020.03.19.08.03.12; Thu, 19 Mar 2020 08:03:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728040AbgCSPBz (ORCPT + 99 others); Thu, 19 Mar 2020 11:01:55 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:16057 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727587AbgCSPBy (ORCPT ); Thu, 19 Mar 2020 11:01:54 -0400 IronPort-SDR: 620UCLGBEiSmZSvZyW6HnxYUJdaC35/EZ2gYPlkDc3sd+Bz/mS3ucBSPKix37lyR4N0fp60y3v QMfZnhUsSo4gtmgMUkuXDEaT/v19rmURNOKV6GiC/Js0t4hWFUxenFg7dV3qstk7gVC2JLBJ29 MO9HW9qQAH3MXFEqH7+vE9PVDfZADNAcX/WId0TNpkYuo/9sL4u7GM2ALFFLJvEE3452VOy1yQ o6GEqcfL5wZZX3dJUKmcjDcr8H5otCe3Bm09SQpuYQ6zhCns3zbjVvMLCPTXF77nghksH9goUB B5E= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="48850283" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:01:48 -0800 IronPort-SDR: zIMX+jzSTn0o3WVvrJPe1U41yNdyIcMbBtZrXiRstJh8fcDlkBisxrXv8zeLW1WBUzpcJPk6UZ jci47mG9NfXifxh0z+z9cGd1ldtrLiAIL9bXTJRaNXJU6f8wvi/CV0Hij1Zlmz6qn4ra1O88HN yDbPiLz2oGdj07VPOtVea7yxo6UVAE+kY8U85TYuPBtNQ5d6H1UNV91QrgoFf3XeAOkNRyn+s8 dWR57WkaZ0hgy1z/UOJTSCiVkL8RfnPYIm7iJL/7haQTd1RU4lFvtiEKLKaqfwGE+q0AK+j2fU meM= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 22/52] Input: atmel_mxt_ts - refactor firmware flash to extract context into struct Date: Thu, 19 Mar 2020 07:59:46 -0700 Message-ID: <20200319150016.61398-23-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-1-jiada_wang@mentor.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nick Dyer Refactor firmware flash to extract context into struct Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit 1bbe20ff3dcd6612e7942c495929eae5c138ece2) Signed-off-by: George G. Davis [jiada: Add commit description] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 59 +++++++++++++++--------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 7441dc71bbab..e5dc554a0845 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -291,6 +291,22 @@ struct mxt_cfg { struct mxt_info info; }; +/* Firmware frame structure */ +struct mxt_fw_frame { + __be16 size; + u8 data[]; +}; + +/* Firmware update context */ +struct mxt_flash { + const struct firmware *fw; + struct mxt_fw_frame *frame; + loff_t pos; + size_t frame_size; + unsigned int count; + unsigned int retry; +}; + /* Each client has this additional data */ struct mxt_data { struct i2c_client *client; @@ -3244,21 +3260,17 @@ static int mxt_check_firmware_format(struct device *dev, static int mxt_load_fw(struct device *dev) { struct mxt_data *data = dev_get_drvdata(dev); - const struct firmware *fw = NULL; - unsigned int frame_size; - unsigned int pos = 0; - unsigned int retry = 0; - unsigned int frame = 0; + struct mxt_flash f = { 0, }; int ret; - ret = request_firmware(&fw, data->fw_name, dev); + ret = request_firmware(&f.fw, data->fw_name, dev); if (ret) { dev_err(dev, "Unable to open firmware %s\n", data->fw_name); return ret; } /* Check for incorrect enc file */ - ret = mxt_check_firmware_format(dev, fw); + ret = mxt_check_firmware_format(dev, f.fw); if (ret) goto release_firmware; @@ -3312,41 +3324,42 @@ static int mxt_load_fw(struct device *dev) goto disable_irq; } - while (pos < fw->size) { + while (f.pos < f.fw->size) { + f.frame = (struct mxt_fw_frame *)(f.fw->data + f.pos); + ret = mxt_check_bootloader(data, MXT_WAITING_FRAME_DATA, true); if (ret) goto disable_irq; - frame_size = ((*(fw->data + pos) << 8) | *(fw->data + pos + 1)); - /* Take account of CRC bytes */ - frame_size += 2; + f.frame_size = __be16_to_cpu(f.frame->size) + 2U; /* Write one frame to device */ - ret = mxt_bootloader_write(data, fw->data + pos, frame_size); + ret = mxt_bootloader_write(data, f.fw->data + f.pos, + f.frame_size); if (ret) goto disable_irq; ret = mxt_check_bootloader(data, MXT_FRAME_CRC_PASS, true); if (ret) { - retry++; + f.retry++; /* Back off by 20ms per retry */ - msleep(retry * 20); + msleep(f.retry * 20); - if (retry > 20) { + if (f.retry > 20) { dev_err(dev, "Retry count exceeded\n"); goto disable_irq; } } else { - retry = 0; - pos += frame_size; - frame++; + f.retry = 0; + f.pos += f.frame_size; + f.count++; } - if (frame % 50 == 0) - dev_dbg(dev, "Sent %d frames, %d/%zd bytes\n", - frame, pos, fw->size); + if (f.count % 50 == 0) + dev_dbg(dev, "Sent %u frames, %lld/%zu bytes\n", + f.count, f.pos, f.fw->size); } /* Wait for flash. */ @@ -3355,7 +3368,7 @@ static int mxt_load_fw(struct device *dev) if (ret) goto disable_irq; - dev_dbg(dev, "Sent %d frames, %d bytes\n", frame, pos); + dev_dbg(dev, "Sent %u frames, %lld bytes\n", f.count, f.pos); /* * Wait for device to reset. Some bootloader versions do not assert @@ -3369,7 +3382,7 @@ static int mxt_load_fw(struct device *dev) disable_irq: disable_irq(data->irq); release_firmware: - release_firmware(fw); + release_firmware(f.fw); return ret; } -- 2.17.1