Received: by 10.213.65.68 with SMTP id h4csp837487imn; Tue, 27 Mar 2018 09:41:47 -0700 (PDT) X-Google-Smtp-Source: AIpwx48F0wfiUIorFP28ShKnQs6nBo7bzNOVmaCqIRsGpdoFAMGUHdmPb9q4k3pPw5bOUeILhIT0 X-Received: by 10.167.129.90 with SMTP id d26mr66874pfn.108.1522168907025; Tue, 27 Mar 2018 09:41:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522168907; cv=none; d=google.com; s=arc-20160816; b=FDtJI13sej7vKQJ+bOw7YJcSAXdHzzuNtLxBu5AxcxRF9Z7HS82P1uWjaPrwCUZ1do Lh9m2aABrSDNcn0SUlgCzDkq07CktXaf2s1UswKMh7IPFcfUIYsgbZ8TZOD2fgoTaeju RMxG16Q8TOi0HNhd6bximFo7FZRmEkjlaVIjUpEAwU9bfNjEt0EduSjzbMY3bC++nvjA LIb6ecTlHEtSQXfSd3EYOuVRrhS6eqGsBzcz7Z4Gw5FHi/3O2z0teY0fyKej/w1TRke8 4VeO21oEcvZcTXevu11FMr2p5De1fyeDjJMuJsqzueX6DHkyiANMVToOPDffvPZ9iq26 uMMA== 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=eMgZ5j2QzaEVU43Ww03S+l6rp+A8ofVkO+RxPyir9v4=; b=zMsZNm7bpKcCsw9A9HHixkdorBRvcJkmmNGB3xUYYUXifsd8+yQaKztVxagQBJUxei nabW+BdeEeh8TUipnwEZ1BEE5ktglvPkYvOKs4w+Rjue++2c33VDsZUREHChBs3brHSD KarmU4AiaDn5cep0O8UUTdTnb4DemokWaASHImnQb/xMfMJTh+SIVUHNuTwvUZIBfELg mACzDOPAXSrflsFW82XVTR1u5mP0ZTzBtu4zlGj94+dALEEktgd05taPFpANheC+WgJp c0yCQZZkLXOV/DLZe7EhP7cX9HMrQU69js81c4irg5yxsMiTXbu3RRLfyW9rh1CW30CL gcrQ== 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 x9-v6si1711050plo.41.2018.03.27.09.41.32; Tue, 27 Mar 2018 09:41:46 -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 S1755363AbeC0QkG (ORCPT + 99 others); Tue, 27 Mar 2018 12:40:06 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:47524 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754639AbeC0QkD (ORCPT ); Tue, 27 Mar 2018 12:40:03 -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 1B1241130; Tue, 27 Mar 2018 16:40:02 +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.15 006/105] iio: chemical: ccs811: Corrected firmware boot/application mode transition Date: Tue, 27 Mar 2018 18:26:46 +0200 Message-Id: <20180327162758.111015515@linuxfoundation.org> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180327162757.813009222@linuxfoundation.org> References: <20180327162757.813009222@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.15-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 @@ -133,6 +133,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;