Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3367289ybb; Tue, 31 Mar 2020 03:55:59 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuk1+TV4N9IuLrzwP1usjWnQI9dtaLwtFBtUCPnLywOqo2LcnBwPxCNjEZmU+Kzhplm+bm/ X-Received: by 2002:aca:7285:: with SMTP id p127mr1577996oic.32.1585652159552; Tue, 31 Mar 2020 03:55:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585652159; cv=none; d=google.com; s=arc-20160816; b=aOnmPCEMoy+E748QVGY+ABeVhYPCTg+VM8gsg6ecXgKwFxqjf9b0gsQltcS7vIDw8L Q6zgtl5gvvC5GsHWM22dz5Jhm4iTAab1FedSlfN63kUtdJfxgzzUagmk64/LFIzJ0Xct kVSvyBw1waOEEvbAlItsWpDu2Fhli2az0l5i3eBEcJ5H4sDEQ/jL/VXPII/bYn3pFdV1 g1SR0RmyIk6hRiCVk+6ZBw3t7DYOfXTh9rw8Don+iyDd+q/oN4uXVdAAP8394l/ttE5z g0AL4/UevUUxFkd8PQCr98E0JqWpqmxkoTrdbf7AAlmHyN73cyirwmDOPQiGSpA49Tlz L/tQ== 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=PI9b0Q0XgwBTheu0ShpkXuO597myxG8s1XrYoB+02a8=; b=F0WjKZh6/x5NvOWQHXKT5B865p+nxZE+u7JhdlE6KZwLCxweQwRnqgJqICZ+nG66Wh SnbpE43gnjMj6bM/y9ROZ3sHFJWMfLnOGc1syTrn2ApXVWzrFZ68OwdmyyR6HNCp/1Xc J86pX3NXXPCzQoRLeHp4nXGxQyhaSKTQtyyvOvxkL9WyBsFEwE+ICcggSkAew5k2ud2u EKPMXtw3ctKRLcEadq7tplxjt3LpYJ/3R0WfFr5kFbs1YX3Fi1rVPXGWlNNZ5chguo9g BDQEaeqp0OklzgtiKaZUmyRuG3DjYB1Zb+JVW3tEzFj4Pd8G+2Um2AcuDoYb9yocBESh TXMA== 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 f41si2442866otf.280.2020.03.31.03.55.47; Tue, 31 Mar 2020 03:55:59 -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 S1730708AbgCaKyh (ORCPT + 99 others); Tue, 31 Mar 2020 06:54:37 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:43593 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730542AbgCaKwm (ORCPT ); Tue, 31 Mar 2020 06:52:42 -0400 IronPort-SDR: S8NJUt8s581pvwq5kezZeh92ad3uWGAlPi4Hk3aB1SsbeTQO0UP1wZqrer1oN/UQtAHxvRgcmf vy5oW5PrVrna5KpklAI869xEsH91D3/60Kc4DKZj8OZyg08PqFqIwEZaFEAZ8vgdDR6QFxiOf1 RqXXN0MDFojcvoXalTxJsDXh4U5DwcSNg8dHW9Sko1IM7Uhrgf9Liu53Bwu7Zq0ihBycQ4hBD4 jKBGQvCJfAVeogOURWmJVvEpOu46hUdhnFzNd/SYeKhrEOYOuoiZSss0rQy9j2qrHP6KwSWLmm JQY= X-IronPort-AV: E=Sophos;i="5.72,327,1580803200"; d="scan'208";a="47330785" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 31 Mar 2020 02:52:35 -0800 IronPort-SDR: m7oDGqw6BZrIwhibDRC06KmwhLm6AVCl/CZ8dEfzuQMhJNROVXPe9v0u1M8oCCHE7E6/GxPQ/d r6phIWVjIzaMeUcuksoTPS/ooh3ckXLZFHuGsAVCTC7EMrojRK/341+Epivsj8DHtTZ69XFX++ EWNuGzcDrLNdnDA1fXpt5gSG+k0lM3BkHrhFvUoJF0Uh3oN4wgedgLDOpU+bXn3Eoh56VfILN1 ZDtDmoqGP3ziZfoElk1oJD4uVXENxfzEkszFD6mGRSkT4r71LKAYr2acpERsVJkRaZxnIl2jh3 YRg= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v10 26/55] Input: atmel_mxt_ts - refactor code to enter bootloader into separate func Date: Tue, 31 Mar 2020 03:50:22 -0700 Message-ID: <20200331105051.58896-27-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 code to enter bootloader into separate func Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit bedd706a32522b946467e15f4f4f24de86a1b4d7) [gdavis: Resolve forward port conflicts due to applying upstream commit 96a938aa214e ("Input: atmel_mxt_ts - remove platform data support").] Signed-off-by: George G. Davis [jiada: Squash change from ndyer/linux/for-upstream commit d691d3ee6c6de84b38464a42 3207b3e23cb9dc3a - Input: atmel_mxt_ts - check firmware format before entering bootloader Add commit description] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 43 +++++++++++++++--------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 2c4b68802bc3..11b2f133e6be 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -3257,23 +3257,10 @@ static int mxt_check_firmware_format(struct device *dev, return -EINVAL; } -static int mxt_load_fw(struct device *dev) +static int mxt_enter_bootloader(struct mxt_data *data) { - struct mxt_data *data = dev_get_drvdata(dev); - struct mxt_flash f = { 0, }; int ret; - 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, f.fw); - if (ret) - goto release_firmware; - if (data->suspended) { if (data->suspend_mode == MXT_SUSPEND_REGULATOR) mxt_regulator_enable(data); @@ -3291,14 +3278,14 @@ static int mxt_load_fw(struct device *dev) ret = mxt_t6_command(data, MXT_COMMAND_RESET, MXT_BOOT_VALUE, false); if (ret) - goto release_firmware; + return ret; msleep(MXT_RESET_TIME); /* Do not need to scan since we know family ID */ ret = mxt_lookup_bootloader_address(data, 0); if (ret) - goto release_firmware; + return ret; mxt_sysfs_remove(data); mxt_free_input_device(data); @@ -3309,6 +3296,30 @@ static int mxt_load_fw(struct device *dev) reinit_completion(&data->bl_completion); + return 0; +} + +static int mxt_load_fw(struct device *dev) +{ + struct mxt_data *data = dev_get_drvdata(dev); + struct mxt_flash f = { 0, }; + int ret; + + 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, f.fw); + if (ret) + goto release_firmware; + + ret = mxt_enter_bootloader(data); + if (ret) + goto release_firmware; + ret = mxt_check_bootloader(data, MXT_WAITING_BOOTLOAD_CMD, false); if (ret) { /* Bootloader may still be unlocked from previous attempt */ -- 2.17.1