Received: by 10.213.65.68 with SMTP id h4csp832591imn; Tue, 27 Mar 2018 09:35:55 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+TtGpHsroHTVxXFE1e0Qks0jvstM5CYEr34Yt29aBAchjaKGqKsQ6zr7OcWdUQUEZCf6Zb X-Received: by 10.98.133.28 with SMTP id u28mr45552pfd.190.1522168555848; Tue, 27 Mar 2018 09:35:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522168555; cv=none; d=google.com; s=arc-20160816; b=Ob9zFEg1lBMjXv+9zKbN6JB50zab1XvzDRa/HaDh1pPJOKFYl3YXiD4XoMWfUSOYWj yK7dsb+T8yFDR70xwr9JFjnc/zwFgIRNIHINqMzhtw92R8BgGSY9LyKB5zM2MdYNvZmS cMx6OvV5cUXOkzfhOs7r3PRcWihdSEj2qPwnESI0DJIEC6mYOxV6M8vPBilxkGRV7vcV scIY+iB+6+3EosQgWCnHsH9MVv/zNV3H06vLRhjk9Qkf5xZtcS89hZLZNUiIm7O0Ywq0 oE7z9Fermr6r3AamAn5qg4Aj5bNdKZCsAY40DUU1npXkM4cgVDtV2yqKubvRLgzVJNvk O8wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=HJACQ8KPPa+UAS7E6m1/MVvCXQgc1XS5yKYx2b/NddM=; b=tH+r5eRAJK4e0tW8xJDlp8A9V9gXUL3afDbWW8UaMJjSbhOQk1JKKv8iAWkNUjGVTZ R/nYo0wOYTzCP/15Ue72fr6aVflxJkGwKzJqq0SpaJFJDRuQ9cT+DamZ/CFar7VC1FhE sQn/+j6PV5FIU/FXqIBz4u/Bnt9yWtS7IOAwEID+WSajS43TuFGw9F/8yFa4fv3vbuWs O48Y8fMDB28gmmcIQrYBf8UqHJtQgUOf0GQpejgVKXC7qyEnQc7IT3NsknVsep/YCqoX YzFx3UTQ5EXtKv+FTJFfHu9ewme9U04G0S1zIUbLHsuPSNlRJ6msN6rnUccU/iccqaTr eP1w== 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 s3si1261150pfj.50.2018.03.27.09.35.41; Tue, 27 Mar 2018 09:35: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 S1754269AbeC0Qee (ORCPT + 99 others); Tue, 27 Mar 2018 12:34:34 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:44430 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754254AbeC0Qeb (ORCPT ); Tue, 27 Mar 2018 12:34:31 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 72D24121F; Tue, 27 Mar 2018 16:34:30 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Richard Lai , Stable@vger.kernel.org, Jonathan Cameron Subject: [PATCH 4.14 006/101] iio: chemical: ccs811: Corrected firmware boot/application mode transition Date: Tue, 27 Mar 2018 18:26:38 +0200 Message-Id: <20180327162750.405377291@linuxfoundation.org> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180327162749.993880276@linuxfoundation.org> References: <20180327162749.993880276@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Richard Lai commit b91e146c38b003c899710ede6d05fc824675e386 upstream. CCS811 has different I2C register maps in boot and application mode. When CCS811 is in boot mode, register APP_START (0xF4) is used to transit the firmware state from boot to application mode. However, APP_START is not a valid register location when CCS811 is in application mode (refer to "CCS811 Bootloader Register Map" and "CCS811 Application Register Map" in CCS811 datasheet). The driver should not attempt to perform a write to APP_START while CCS811 is in application mode, as this is not a valid or documented register location. When prob function is being called, the driver assumes the CCS811 sensor is in boot mode, and attempts to perform a write to APP_START. Although CCS811 powers-up in boot mode, it may have already been transited to application mode by previous instances, e.g. unload and reload device driver by the system, or explicitly by user. Depending on the system design, CCS811 sensor may be permanently connected to system power source rather than power controlled by GPIO, hence it is possible that the sensor is never power reset, thus the firmware could be in either boot or application mode at any given time when driver prob function is being called. This patch checks the STATUS register before attempting to send a write to APP_START. Only if the firmware is not in application mode and has valid firmware application loaded, then it will continue to start transiting the firmware boot to application mode. Signed-off-by: Richard Lai Cc: Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- drivers/iio/chemical/ccs811.c | 3 +++ 1 file changed, 3 insertions(+) --- a/drivers/iio/chemical/ccs811.c +++ b/drivers/iio/chemical/ccs811.c @@ -128,6 +128,9 @@ static int ccs811_start_sensor_applicati if (ret < 0) return ret; + if ((ret & CCS811_STATUS_FW_MODE_APPLICATION)) + return 0; + if ((ret & CCS811_STATUS_APP_VALID_MASK) != CCS811_STATUS_APP_VALID_LOADED) return -EIO;