Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3366932ybb; Tue, 31 Mar 2020 03:55:27 -0700 (PDT) X-Google-Smtp-Source: ADFU+vv3GvTu1O4mAfXHZtEZJkEH0QGPjAqptN2xxvnR9zF6YvgIa6YGCzp7VMBjsZzA2+KzsJU5 X-Received: by 2002:aca:3983:: with SMTP id g125mr1640291oia.13.1585652127254; Tue, 31 Mar 2020 03:55:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585652127; cv=none; d=google.com; s=arc-20160816; b=DOXYlJKutnKY59TFdTUNYg6wAvn+xkBSG9bApmFy+L95KkXqWUyc11K+gTgOAvodg9 cqv/RK8qrHGOZ4xKnGSY2PKWZY4hkm7uCOsNiF+NnEqU/dCpIpWaPmzHdKXWAGvbQE78 e9+Ls78VfU333XT1e74eaqvnYC9n+vx5q8AZhck0aLp5r887D3Yl5OAJ4/U/kFUq0Jz5 5vewLkYUNtRyfmnIH0uzZme15Vqx1ZOngUBFBSQhMUMScoGNKpmrtWqIrb9/naqXYaCQ gnCNDDKc51C8kCGZURu7DJ6bAJAWbriP/4J/pCmJPZMBhzUiAHO001P6/tHD70GIWkR9 lQqw== 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=+U4txAau88AU8oVvZIwvFhvgwskoLD9TnYvgvBzpHg0=; b=cpi8UhTwi5cCBlOSMsgjNEsjFZwv1nOq0FQEmrniDOVodsg6CbGnEUxCgRuQCZ+pWk twjD6T5qoN/AmcYyHPPe6Qo9/PxHvLSNVHHgNLt+g/nC50Q/tC2Es2Z0BgrZKVzyjop8 J2zQAOwyA0WXB3BTQcQaJfdj6yfi7CWfc7pnbjrHVSMg86F853xxfMWXcR5jymj8gKCf CvndGIgtrOXUHg5OWrF6bySO9ICSJANltCXrRzwZVPPiyDOqmFWyZiXROOJDqYs8VyvR gb9jP3oHPtIOYemIfy7QQWwrp2/WKBrYMBcKWb0hngKsrE5/vesLrXWwlEyc75Tcja0a o6/w== 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 d13si6781712oij.140.2020.03.31.03.55.15; Tue, 31 Mar 2020 03:55:27 -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 S1730466AbgCaKxw (ORCPT + 99 others); Tue, 31 Mar 2020 06:53:52 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:43597 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730442AbgCaKxu (ORCPT ); Tue, 31 Mar 2020 06:53:50 -0400 IronPort-SDR: SSFl0qJwqO+AbHaEmZa5DTVOGlFh97f7Q7eReDAnscd2boUFkigb9oh20omrq941CbJCDIel3T K5OhvwiqwUXmb7Vr97uoZ+/QCaeTYUfbUSrqpQCJ9UfzQ3A7EYdDjRjB0tfNgX6EpiJ2iw5GuJ au9sijOMGwcqUelkejYYWj7+o/kjRPZe6A79BX9+dZTPzoe2IK//W6mHJgmqK+2EoOksut5+Ut AGJzSZG2p2FBYnBxDTMEmqxvQMAv0k4Zn/7L1eUpAf8guONAeu1YC/zrD9NpJBnVBoMSzJstdh jpE= X-IronPort-AV: E=Sophos;i="5.72,327,1580803200"; d="scan'208";a="47330842" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 31 Mar 2020 02:53:50 -0800 IronPort-SDR: kauWWYYMfgeOWRryf6wVPxzi03A7Wy1c553H2DUA/4YMHuOJFiK6hPM6uqJbUzd7d7qxaR2IpD Z0aVu1KZ9JnilC4ib+05caxR1GXoSgawZoNQofpuDHziZ+kXWV0VIgOEKFv5feNTJ/h+5kgy6L zXXgcg+0eac6EqRhIk10OJiJAb7StiYso5gAPsD86oUxBmXpvHotpYnj8TK066B/gkYf9ApN1T Q28ZaIaiU3xAYPwK5OOqsLuIDmohVWV/YZIYv+VIy3aKPUxeZ2hxqXS/MKyAtcdJoDhyjwgq/+ Big= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v10 46/55] Input: Atmel: improve error handling in mxt_initialize() Date: Tue, 31 Mar 2020 03:50:42 -0700 Message-ID: <20200331105051.58896-47-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: Deepak Das Currently mxt_initialize() tries to probe bootloader mode even if valid bootloader address is not specified. This commit modifies mxt_initialize() to return error if Device is not in appmode and bootloader address is not specified. This commit also returns error code from mxt_send_bootloader_cmd() in mxt_initialize(). Signed-off-by: Deepak Das Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 58 +++++++++++++++++------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 0f7ee987a9c5..258dcd8a68e5 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -716,17 +716,13 @@ static int mxt_lookup_bootloader_address(struct mxt_data *data, bool retry) return 0; } -static int mxt_probe_bootloader(struct mxt_data *data, bool alt_address) +static int mxt_probe_bootloader(struct mxt_data *data) { struct device *dev = &data->client->dev; int error; u8 buf[3]; bool crc_failure, extended_id; - error = mxt_lookup_bootloader_address(data, alt_address); - if (error) - return error; - /* Check bootloader status and version information */ error = mxt_bootloader_read(data, buf, sizeof(buf)); if (error) @@ -2922,6 +2918,32 @@ static void mxt_config_cb(const struct firmware *cfg, void *ctx) release_firmware(cfg); } +static int mxt_bootloader_status(struct mxt_data *data) +{ + struct i2c_client *client = data->client; + int error; + + error = mxt_lookup_bootloader_address(data, false); + if (error) { + dev_info(&client->dev, + "Bootloader address is not specified\n"); + return error; + } + /* Check bootloader state */ + error = mxt_probe_bootloader(data); + if (error) { + dev_info(&client->dev, "Trying alternate bootloader address\n"); + mxt_lookup_bootloader_address(data, true); + error = mxt_probe_bootloader(data); + if (error) { + dev_err(&client->dev, + "Chip is not in appmode or bootloader mode\n"); + return error; + } + } + return 0; +} + static int mxt_initialize(struct mxt_data *data) { struct i2c_client *client = data->client; @@ -2933,16 +2955,13 @@ static int mxt_initialize(struct mxt_data *data) if (!error) break; - /* Check bootloader state */ - error = mxt_probe_bootloader(data, false); - if (error) { - dev_info(&client->dev, "Trying alternate bootloader address\n"); - error = mxt_probe_bootloader(data, true); - if (error) { - /* Chip is not in appmode or bootloader mode */ - return error; - } - } + dev_info(&client->dev, + "info block read failed (%d), so try bootloader method\n", + error); + + error = mxt_bootloader_status(data); + if (error) + return error; /* OK, we are in bootloader, see if we can recover */ if (++recovery_attempts > 1) { @@ -2956,7 +2975,9 @@ static int mxt_initialize(struct mxt_data *data) } /* Attempt to exit bootloader into app mode */ - mxt_send_bootloader_cmd(data, false); + error = mxt_send_bootloader_cmd(data, false); + if (error) + return error; msleep(MXT_FW_RESET_TIME); } @@ -3648,8 +3669,11 @@ static int mxt_enter_bootloader(struct mxt_data *data) msleep(MXT_RESET_TIME); + ret = mxt_lookup_bootloader_address(data, false); + if (ret) + return ret; /* Do not need to scan since we know family ID */ - ret = mxt_probe_bootloader(data, 0); + ret = mxt_probe_bootloader(data); if (ret) return ret; -- 2.17.1