Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2732711pxv; Mon, 12 Jul 2021 00:10:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzv8H/MRwyWZGpv6rXwTuLz0Z/OkCC1KHGTpaZ+/biaFpaRz2lwPh7DxtLPqZ3R53dIHPgW X-Received: by 2002:a92:7a02:: with SMTP id v2mr14067060ilc.232.1626073814347; Mon, 12 Jul 2021 00:10:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626073814; cv=none; d=google.com; s=arc-20160816; b=eO59Z1WIAiFov4W1FscR2l8KwzWp+mMkFZMwuVCaHMQ0GiatTUaITP7q/F60H024yM rn57Em0l8FSjeC7IjhOxS04tHXMbGRfzw6pj/KeRrB6R0CruO452EO0QE0vZkfFh05g9 RmAcrpY7h0yrtywITc6x/pJoY4Na54JqbfbaWhIRtMDaIejOvtAXb/oowbBzmDHapoxg ndYh//MlxLHPyYyVzqwBP24ztZkNPxTv7xx+Q5jYx72dL6cROIEx+eTG+c5Ea89q7Z8h Q11lhfwASeHRaL+5WiL7en3vuG8Ft3yc5rC4pZsYIipKXgj1PDvc/wl1WU9AVKBUJ/AG CTCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FpFP1Fu4uiLTbHiYjasOjafkNpZUIK272ZfPyOIzzWc=; b=Uxx6UM+9fmS5fIeEgGvMmx5cEJbXbp5wycDy0UaXa2joATwIteBcGYYPM5rUCD5Pxo 32/pBpldh4VXjGtObM4PAq53vW+EPp4wj2Yta27Qn29DTv5mk5qEqeE2mfVDO5UTOYSl H5oqYr0CaUB+D6JA+CVUwBvV+74Akqgr1NXaJTfJtMRb7pr8i9Kl1sgvph8iDqMlShcU u1VHjLUJ+SPQ3ICkGqv8E+8verWc546NFJqTxy6iMd40rTX0dQ9H4qGN7oR1Oa10g29c Sb+8OtVKWff+q/POOV3ueLrXhdfjbG1M3Nt8PWH/Kae8Xv41XKv/EieuYHwr+7i7wWnU dz6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lvkAi2e+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m4si16823824ioy.95.2021.07.12.00.10.02; Mon, 12 Jul 2021 00:10:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lvkAi2e+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244320AbhGLHKh (ORCPT + 99 others); Mon, 12 Jul 2021 03:10:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:48266 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238197AbhGLGsf (ORCPT ); Mon, 12 Jul 2021 02:48:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 12D2F6115A; Mon, 12 Jul 2021 06:44:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626072264; bh=OCif2ZsNIOhHAWJltQSZzdH7Ucun+7oFwwXTFZNaHWo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lvkAi2e+lZmW8lj8IVRdAo8oUZ3MpwlNwPaluAHEEq/PPgASa7JEsbTG1LiDxbnSL dl/BU/GfAQApIrSKmmgJWBYcgFKYR3wVnyi7CaoFWhZVGbk5ooiKl35wVY8B94jf1y 20zgulQgH48XGfUPCmAawa3Vypsw2sZawzo2WSnM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Robert Hancock , Stephen Boyd , Sasha Levin Subject: [PATCH 5.10 422/593] clk: si5341: Wait for DEVICE_READY on startup Date: Mon, 12 Jul 2021 08:09:42 +0200 Message-Id: <20210712060934.679964885@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060843.180606720@linuxfoundation.org> References: <20210712060843.180606720@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Robert Hancock [ Upstream commit 6e7d2de1e000d36990923ed80d2e78dfcb545cee ] The Si5341 datasheet warns that before accessing any other registers, including the PAGE register, we need to wait for the DEVICE_READY register to indicate the device is ready, or the process of the device loading its state from NVM can be corrupted. Wait for DEVICE_READY on startup before continuing initialization. This is done using a raw I2C register read prior to setting up regmap to avoid any potential unwanted automatic PAGE register accesses from regmap at this stage. Fixes: 3044a860fd ("clk: Add Si5341/Si5340 driver") Signed-off-by: Robert Hancock Link: https://lore.kernel.org/r/20210325192643.2190069-3-robert.hancock@calian.com Signed-off-by: Stephen Boyd Signed-off-by: Sasha Levin --- drivers/clk/clk-si5341.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/drivers/clk/clk-si5341.c b/drivers/clk/clk-si5341.c index e0446e66fa64..b8a960e927bc 100644 --- a/drivers/clk/clk-si5341.c +++ b/drivers/clk/clk-si5341.c @@ -94,6 +94,7 @@ struct clk_si5341_output_config { #define SI5341_STATUS 0x000C #define SI5341_SOFT_RST 0x001C #define SI5341_IN_SEL 0x0021 +#define SI5341_DEVICE_READY 0x00FE #define SI5341_XAXB_CFG 0x090E #define SI5341_IN_EN 0x0949 #define SI5341_INX_TO_PFD_EN 0x094A @@ -1189,6 +1190,32 @@ static const struct regmap_range_cfg si5341_regmap_ranges[] = { }, }; +static int si5341_wait_device_ready(struct i2c_client *client) +{ + int count; + + /* Datasheet warns: Any attempt to read or write any register other + * than DEVICE_READY before DEVICE_READY reads as 0x0F may corrupt the + * NVM programming and may corrupt the register contents, as they are + * read from NVM. Note that this includes accesses to the PAGE register. + * Also: DEVICE_READY is available on every register page, so no page + * change is needed to read it. + * Do this outside regmap to avoid automatic PAGE register access. + * May take up to 300ms to complete. + */ + for (count = 0; count < 15; ++count) { + s32 result = i2c_smbus_read_byte_data(client, + SI5341_DEVICE_READY); + if (result < 0) + return result; + if (result == 0x0F) + return 0; + msleep(20); + } + dev_err(&client->dev, "timeout waiting for DEVICE_READY\n"); + return -EIO; +} + static const struct regmap_config si5341_regmap_config = { .reg_bits = 8, .val_bits = 8, @@ -1385,6 +1412,11 @@ static int si5341_probe(struct i2c_client *client, data->i2c_client = client; + /* Must be done before otherwise touching hardware */ + err = si5341_wait_device_ready(client); + if (err) + return err; + for (i = 0; i < SI5341_NUM_INPUTS; ++i) { input = devm_clk_get(&client->dev, si5341_input_clock_names[i]); if (IS_ERR(input)) { -- 2.30.2