Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp6553378ybx; Mon, 11 Nov 2019 10:51:06 -0800 (PST) X-Google-Smtp-Source: APXvYqy6OL+Z1aSRktX8Lc0L4HxMqbOvNV+qTlvuA/F2tUJWyeSB4o8LZnOzJ01Zz2JAQbcq3sTK X-Received: by 2002:a50:ab01:: with SMTP id s1mr28798739edc.192.1573498266259; Mon, 11 Nov 2019 10:51:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573498266; cv=none; d=google.com; s=arc-20160816; b=Jty5s6x8ka8oQZQ/QHdUcRKJuAyiKdMJ5t35K2K02L4tluBiGb9ojK4jsksz58N55r Ls/FFZ2ykHUyzTmapGiwBMwlmISZwHdaGk5M7HaVROfimXadlEuZuuzNBoa5lqGOtqdV cdyyyeMhM2GgiuZaku58ueXZHTC/crhREA8NIpRgY9560Erwhst8p+2I2kNEG1YF5H04 rZs/nYCxxis+2Vayg3gHN88r5r4SyCqDjslLPr6Pkh8VYYadT+IKdikacZM4enbxAksn OLF/foUvO/4agPWzu1b3jSOtpZhUh9hYWzODjDhUx6yjPGYZmQvihLML80GAuyO/jjhK n8kA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wz/Aa7kVw4GAkXB6ZT7rf9uj21xU5zF5V+xCMJAe9Fk=; b=o1RpMj+kixH81aHXeNgF/ETUOvptZ6DiK3danWeeQBrEGWSjNM4t8TEP+2BvmnBsx/ DLB+62Q+bIFbGlEssEOxK/uGPU9vcMN5Zzmeyz7VSUHk/jp8PG2dALSw3xMKBV/nKqhT VMMqUThYD/pWB6RqTdv9mp0h5RndfhMF6oroXkaU/95n2sya+4TEZOPEm2TKrIi89aPs qD6e7y+CQ/Tk1VXhD4m5GekapNqFprZnFVFq3n+imZwZRdESHmJobQBhMMFQPaIEkU8l EqjAHp1KLsif75iAPJRxh0omTFi0B7yyIYMA1aIYGcV//tBKju1I3MR5h5CwVooOM3Wn 0V0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=eUJ8PNZw; 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 17si9720195ejt.431.2019.11.11.10.50.42; Mon, 11 Nov 2019 10:51:06 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=eUJ8PNZw; 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 S1730105AbfKKSrW (ORCPT + 99 others); Mon, 11 Nov 2019 13:47:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:40082 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730072AbfKKSrT (ORCPT ); Mon, 11 Nov 2019 13:47:19 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1E52221655; Mon, 11 Nov 2019 18:47:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573498038; bh=Qx6rEvYfQ/vz4Rbc+dIQHrZu8mzVfOmIM+BjA2Ep5dc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eUJ8PNZwqdfKrJfNQAH8j2JkHW7B7UrKTDPTmECKQN9DEPAiPVGbaO/N3QYHyQGa/ LWzaeqR1p2LqM+yM+sO2RLacuRTJcly34JZ+PDJisyzd/QpaCRilNdi6PUfWXwUpX8 nw4lSbA6JuBXNnU7kqen0xT8VojBv247NsH9FviE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jean-Baptiste Maneyrol , Jonathan Cameron , Sasha Levin Subject: [PATCH 4.19 123/125] iio: imu: inv_mpu6050: fix no data on MPU6050 Date: Mon, 11 Nov 2019 19:29:22 +0100 Message-Id: <20191111181456.142299857@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191111181438.945353076@linuxfoundation.org> References: <20191111181438.945353076@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jean-Baptiste Maneyrol [ Upstream commit 6e82ae6b8d11b948b74e71396efd8e074c415f44 ] Some chips have a fifo overflow bit issue where the bit is always set. The result is that every data is dropped. Change fifo overflow management by checking fifo count against a maximum value. Add fifo size in chip hardware set of values. Fixes: f5057e7b2dba ("iio: imu: inv_mpu6050: better fifo overflow handling") Cc: stable@vger.kernel.org Signed-off-by: Jean-Baptiste Maneyrol Signed-off-by: Jonathan Cameron Signed-off-by: Sasha Levin --- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 9 +++++++++ drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 2 ++ drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c | 15 ++++++++++++--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c index cb80c9e49fc7b..ea099523e0355 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -121,54 +121,63 @@ static const struct inv_mpu6050_hw hw_info[] = { .name = "MPU6050", .reg = ®_set_6050, .config = &chip_config_6050, + .fifo_size = 1024, }, { .whoami = INV_MPU6500_WHOAMI_VALUE, .name = "MPU6500", .reg = ®_set_6500, .config = &chip_config_6050, + .fifo_size = 512, }, { .whoami = INV_MPU6515_WHOAMI_VALUE, .name = "MPU6515", .reg = ®_set_6500, .config = &chip_config_6050, + .fifo_size = 512, }, { .whoami = INV_MPU6000_WHOAMI_VALUE, .name = "MPU6000", .reg = ®_set_6050, .config = &chip_config_6050, + .fifo_size = 1024, }, { .whoami = INV_MPU9150_WHOAMI_VALUE, .name = "MPU9150", .reg = ®_set_6050, .config = &chip_config_6050, + .fifo_size = 1024, }, { .whoami = INV_MPU9250_WHOAMI_VALUE, .name = "MPU9250", .reg = ®_set_6500, .config = &chip_config_6050, + .fifo_size = 512, }, { .whoami = INV_MPU9255_WHOAMI_VALUE, .name = "MPU9255", .reg = ®_set_6500, .config = &chip_config_6050, + .fifo_size = 512, }, { .whoami = INV_ICM20608_WHOAMI_VALUE, .name = "ICM20608", .reg = ®_set_6500, .config = &chip_config_6050, + .fifo_size = 512, }, { .whoami = INV_ICM20602_WHOAMI_VALUE, .name = "ICM20602", .reg = ®_set_icm20602, .config = &chip_config_6050, + .fifo_size = 1008, }, }; diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h index bdbaf6e01ce3e..e56c1d191ae46 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h @@ -108,12 +108,14 @@ struct inv_mpu6050_chip_config { * @name: name of the chip. * @reg: register map of the chip. * @config: configuration of the chip. + * @fifo_size: size of the FIFO in bytes. */ struct inv_mpu6050_hw { u8 whoami; u8 *name; const struct inv_mpu6050_reg_map *reg; const struct inv_mpu6050_chip_config *config; + size_t fifo_size; }; /* diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c index 548e042f7b5bd..4f9c2765aa23f 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c @@ -188,9 +188,6 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p) "failed to ack interrupt\n"); goto flush_fifo; } - /* handle fifo overflow by reseting fifo */ - if (int_status & INV_MPU6050_BIT_FIFO_OVERFLOW_INT) - goto flush_fifo; if (!(int_status & INV_MPU6050_BIT_RAW_DATA_RDY_INT)) { dev_warn(regmap_get_device(st->map), "spurious interrupt with status 0x%x\n", int_status); @@ -216,6 +213,18 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p) if (result) goto end_session; fifo_count = get_unaligned_be16(&data[0]); + + /* + * Handle fifo overflow by resetting fifo. + * Reset if there is only 3 data set free remaining to mitigate + * possible delay between reading fifo count and fifo data. + */ + nb = 3 * bytes_per_datum; + if (fifo_count >= st->hw->fifo_size - nb) { + dev_warn(regmap_get_device(st->map), "fifo overflow reset\n"); + goto flush_fifo; + } + /* compute and process all complete datum */ nb = fifo_count / bytes_per_datum; inv_mpu6050_update_period(st, pf->timestamp, nb); -- 2.20.1