From patchwork Sun Nov 11 14:15:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10677661 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2F926139B for ; Sun, 11 Nov 2018 14:15:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E07F2AA5A for ; Sun, 11 Nov 2018 14:15:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 125CB2AA61; Sun, 11 Nov 2018 14:15:53 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham 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 A78BB2AA5A for ; Sun, 11 Nov 2018 14:15:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728213AbeKLAEd (ORCPT ); Sun, 11 Nov 2018 19:04:33 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:32949 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728196AbeKLAEc (ORCPT ); Sun, 11 Nov 2018 19:04:32 -0500 Received: by mail-wm1-f65.google.com with SMTP id f19-v6so7040347wmb.0 for ; Sun, 11 Nov 2018 06:15:50 -0800 (PST) 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:mime-version:content-transfer-encoding; bh=RaJ110oMzrI8TqqlDCrF22ItgAp9REwCFp+H8cB/KAg=; b=IrK21RvKdaB+LojtnLpr9AGHXWPmlnBWLBcqrgfwXbWeUm2mPrxscklzqMMzAJhE4F 2IYNIluaaXHCuKiOjGuR9A3g1CMXtulNEW6/48Bo40j3fcZwQva9vx3duigbWiRKhrnr JvyiUY4MzlJky/AhIi3q2jqiSv8NEiEXsVkaDmydjzPRqJarurgKHC4iEKZBxh4047DZ DDkVeNdY1Phedk6+PgN0U2vPMIS0Fs/y6HGtIGEnEiMSsILMQZ3bQqQi44JIUaxMlceC hMn6X7M0C1gD9OwljtilnPzLUvfo9/uTPHD8rC9lgtF73pKZnPnHBfKQONAIRrIoK9nT lMNQ== X-Gm-Message-State: AGRZ1gKY1t2DC53Dw5Tbja2wc5ol1FCK/zlE8etUwyexJlMAqWjGPfWY 47lFBVnTRk2+afJeIXM5R/IjJg== X-Google-Smtp-Source: AJdET5fhgPxqYmstC16g37rJh20YQQXdG5hfLFmQTFO6DsvzIDDXWbS5TRYpwgSmAGQK0F9W7qxidw== X-Received: by 2002:a1c:605:: with SMTP id 5-v6mr4867091wmg.94.1541945750024; Sun, 11 Nov 2018 06:15:50 -0800 (PST) Received: from localhost.localdomain ([151.66.8.224]) by smtp.gmail.com with ESMTPSA id w11-v6sm15861685wrr.96.2018.11.11.06.15.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Nov 2018 06:15:49 -0800 (PST) From: Lorenzo Bianconi To: jic23@kernel.org Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v2 2/9] iio: imu: st_lsm6dsx: reload trimming parameter at bootstrap Date: Sun, 11 Nov 2018 15:15:29 +0100 Message-Id: <9b47f1429ddec5144d52605ef0ccf1f15a310db4.1541945612.git.lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 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 Perform a complete device reset at bootstrap reloading trimming parameter after sw reset is completed. Device sw reset/boot is explained here: https://www.st.com/resource/en/application_note/dm00517282.pdf, section 5.7 Signed-off-by: Lorenzo Bianconi --- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c index c8b993bea757..961ce9d65d82 100644 --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c @@ -56,6 +56,7 @@ #define ST_LSM6DSX_REG_WHOAMI_ADDR 0x0f #define ST_LSM6DSX_REG_RESET_ADDR 0x12 #define ST_LSM6DSX_REG_RESET_MASK BIT(0) +#define ST_LSM6DSX_REG_BOOT_MASK BIT(7) #define ST_LSM6DSX_REG_BDU_ADDR 0x12 #define ST_LSM6DSX_REG_BDU_MASK BIT(6) #define ST_LSM6DSX_REG_INT2_ON_INT1_ADDR 0x13 @@ -778,12 +779,23 @@ static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw) u8 drdy_int_reg; int err; - err = regmap_write(hw->regmap, ST_LSM6DSX_REG_RESET_ADDR, - ST_LSM6DSX_REG_RESET_MASK); + /* device sw reset */ + err = regmap_update_bits(hw->regmap, ST_LSM6DSX_REG_RESET_ADDR, + ST_LSM6DSX_REG_RESET_MASK, + FIELD_PREP(ST_LSM6DSX_REG_RESET_MASK, 1)); if (err < 0) return err; - msleep(200); + msleep(50); + + /* reload trimming parameter */ + err = regmap_update_bits(hw->regmap, ST_LSM6DSX_REG_RESET_ADDR, + ST_LSM6DSX_REG_BOOT_MASK, + FIELD_PREP(ST_LSM6DSX_REG_BOOT_MASK, 1)); + if (err < 0) + return err; + + msleep(50); /* enable Block Data Update */ err = regmap_update_bits(hw->regmap, ST_LSM6DSX_REG_BDU_ADDR,