Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3367253ybb; Tue, 31 Mar 2020 03:55:56 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuyuxEJv7AUlJ0o4vHNETyCUmbUX4QmN6EvFuv5iMWOLWoQ7yo2l9bBkgZ355+SQ3esCxR+ X-Received: by 2002:aca:cf48:: with SMTP id f69mr1482642oig.122.1585652155880; Tue, 31 Mar 2020 03:55:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585652155; cv=none; d=google.com; s=arc-20160816; b=nCwFu+37QVBuXDBqcUbHXCtH0r+OAzAI1BGMcjep5vygxeulQESk7AvVWQNQsidgen HWZlKI3ZUoQ62tkByCxsYu6dpb45RjpiV3N9oEXUS12f1dtAT6t0BeRtU3qOyx7TPNiC 4xv1TX63odrzEOvPlC8PjLb6GnTONEvQojm21mjNkNRa6IAjKlYMlOlk0g+JuGdNiUAH a3g3/pdAxiHgo0j3aRtjp5vFFC6YW+Che51yT8Q/WKHm/ReJK8oFzvIfW39v+EW43+h5 B7uPnBBqdKztNceKFdG3LJkicOCeVVOn9KhFZnCzfdnhIPyEeSIZsF1YyuSovK+6Y1nC WQ+g== 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=O5j5FUyBXSr7C56PfO26xFp4HSh5lNiHubFJtMMQSFs=; b=02hB1ZE/VJKrYbpUZcLoMiggM6GLLPbXDkvWmYju+5reOj5XlkGrO4RR7z2rRg8Th5 lQqdCYc+gBR7qF27x4Mhp/jtUK5UA4qlIPErKItPMGyVi3kZZ6KXNVSG2x1WG16k1CkG ObFhsMmFhZ9y8DnnX6/ZmzTdDbOu9VMmzytb2UgFSNsOK15l2cbiKFMTa0yCAY75rrtp GwIyfvffGP9ghkHZiUDHVE8axJflCnRSb1PQkbAN6SUNYtLR6JvQRTyQkUkeXWAtBU9y 6aLfY95D+h4rC6evOTqy7A/DxXPN2waxnDr1SzdlGek771W6cZZsBp1823TG1c5XmJJq DaEQ== 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 d8si3449961oti.106.2020.03.31.03.55.44; Tue, 31 Mar 2020 03:55:55 -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 S1730830AbgCaKyj (ORCPT + 99 others); Tue, 31 Mar 2020 06:54:39 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:43589 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730533AbgCaKwl (ORCPT ); Tue, 31 Mar 2020 06:52:41 -0400 IronPort-SDR: Jjfj1x3GLGu+OQoz8Otq97fQMTfka2E8LBBGP7RDfOlH996AmqMMRoFtzKYQ0rd/g+q8DwcrSL RROHHkbZip2f7wbjHehCfaAicY9oTrWscTDihi5EeVZVlPeMMwyle5nzYPjZC1W31+wpWNscrO MW00d5fcI0bf1MkqC/K0wID52H86xQrly7krDDU+W0Exi3S4Lj29EsdRKp8VuMG2Qn65eiXz4U 5etBn8Bzl3N87hybZXRc2Tw4KRj+H1qQB/fHMWYwSC2dgWn5CR8TPVsbjiMoyd1zUWZu5BeKSI bjs= X-IronPort-AV: E=Sophos;i="5.72,327,1580803200"; d="scan'208";a="47330784" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 31 Mar 2020 02:52:31 -0800 IronPort-SDR: j/Kk1Nw1R3lZu8YgXxlXawA/OD1F2sSEVx4lCUfHw6nzLg117J81hgMySnG8goUhf29wfN4b+W 93zhcddnIFwsnbqYfD5rt7X77Frf0cB1fO3I9ul5NRcWCcZVqSe0tDzcBoPudUuBupe0Q/9zw5 XeMRBgnb3dX2VP5q5bofSpD9SEhAtoevr1xfPNQA37128kY/tkNguwJ1Ayf64yWqIvK11mI0Qy LJDSz2sjs6JqcifzVAZ9AOKukH1Mfc1Mg7JrEKhh6rFrWfLqhHapvfaUd88XA4/eQMx2T1lg6b ZhE= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v10 25/55] Input: atmel_mxt_ts - refactor firmware flash to extract context into struct Date: Tue, 31 Mar 2020 03:50:21 -0700 Message-ID: <20200331105051.58896-26-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200331105051.58896-1-jiada_wang@mentor.com> References: <20200331105051.58896-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 67931cf64629..2c4b68802bc3 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