From patchwork Sat Feb 17 16:28:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Lai X-Patchwork-Id: 10226249 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 64919602CB for ; Sat, 17 Feb 2018 16:31:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F0FA28ABE for ; Sat, 17 Feb 2018 16:31:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 43BB428AC9; Sat, 17 Feb 2018 16:31:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B3A9B28ABE for ; Sat, 17 Feb 2018 16:31:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751082AbeBQQbD (ORCPT ); Sat, 17 Feb 2018 11:31:03 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:56212 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751029AbeBQQbC (ORCPT ); Sat, 17 Feb 2018 11:31:02 -0500 Received: by mail-wm0-f65.google.com with SMTP id h74so8160919wme.5 for ; Sat, 17 Feb 2018 08:31:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=richardman-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xk+dCayuUGQyRGEdfLrqFdhV3DPaF/sIZ98mnWcy2sU=; b=fYTwTI11pQuSOBhqPJD0hmXvZpfhXUswQfTYkdmwhIqImrmukvHTeooHgKXAe6aNo4 bWfpySnH80TOsec4nXgn6YMFfjuqKTlRl6Dxi2bb55cL1TjMgXrDdDjCifSppasxiCIm KT4sGFEMP5nxXbuiSzG0jKsjf1HPPQ2T0hF8vUigqCNzDlOLGyGOJ8v8QbTAikuGclCS L2kd1DfXOx06zY7OVlHq8f/Vtg7Ns2HoFXsyREyWFClQDs3lzEtqD4ar4B7gLRfwzwuD oq+Gsjkhf5WOFvVK99y1ZQT1EhsmQQPVo0Axi0IYbBTu9Bh8C1yxjgjlpeR829WwLSh6 GKyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xk+dCayuUGQyRGEdfLrqFdhV3DPaF/sIZ98mnWcy2sU=; b=Bg25wcITkKGZMC59WL+gFAr77Aawzz+CKxdGLSz47BYx+tVXx4yukL7XnLeJAGXB6a bMzZNsGQD6DgEfQeymNgIqgZ8tmKYRcNgVntnmTGRbzdgF/O4gy8HpZ0IwUACuBwT8X7 4wDlxiYm2cu0q2PtkuOv+Bc45ajkg8A9wzG4mC5exRFMck3+Sn7ZN7Km2zfVw68KWkL4 5OeVsZTedRQb5VjlETwriPVtbAyPn5EKsYLCSqsbaOtvsU8CoULMKtaQp6VDEWKt257t dvpYikBL4ZmqbeMffpaYVA1LBMV01HJPVDZ2xH8AGuYd6Ny6QbC3TrTVy8KPlSjhQ/p2 L3Qg== X-Gm-Message-State: APf1xPCPtl9oPYz4x+Qv0TzJBbfjR5iDfI+8docftmpI33cv+qZcFwSA TzvpgbazuEq7QXfEVK7VeXPGdA== X-Google-Smtp-Source: AH8x224qqdARyVpXfoP+2qlbzPat5jsMAJ+EIUulJMfXoLWfIt81Un8oq9Zd23Ji85MdLzLlstVqmg== X-Received: by 10.28.124.4 with SMTP id x4mr7273910wmc.84.1518885061331; Sat, 17 Feb 2018 08:31:01 -0800 (PST) Received: from RICHARDMAN.localdomain (cpc91232-cmbg18-2-0-cust493.5-4.cable.virginm.net. [82.2.125.238]) by smtp.gmail.com with ESMTPSA id e127sm15660964wmg.10.2018.02.17.08.31.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 17 Feb 2018 08:31:00 -0800 (PST) From: Richard Lai Cc: Richard Lai , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] iio: chemical: ccs811: Corrected firmware boot/application mode transition Date: Sat, 17 Feb 2018 16:28:24 +0000 Message-Id: <1518885013-1852-1-git-send-email-richard@richardman.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <20180217142513.323bbe82@archlinux> References: <20180217142513.323bbe82@archlinux> To: unlisted-recipients:; (no To-header on input) Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- Changes in v2: - Removed unnecessary macros introduced in previous patch drivers/iio/chemical/ccs811.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/iio/chemical/ccs811.c b/drivers/iio/chemical/ccs811.c index 840a6cb..6ad8a42 100644 --- a/drivers/iio/chemical/ccs811.c +++ b/drivers/iio/chemical/ccs811.c @@ -129,6 +129,9 @@ static int ccs811_start_sensor_application(struct i2c_client *client) 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;