Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp6555814ybx; Mon, 11 Nov 2019 10:53:34 -0800 (PST) X-Google-Smtp-Source: APXvYqzPhJZ8np3mU9+xRh3wNF+LLUpB2DAkJsf8zlHPj31FQB+K/uV9G7jtTVi/lN8mouezCNr5 X-Received: by 2002:a50:fa8a:: with SMTP id w10mr28011145edr.179.1573498414632; Mon, 11 Nov 2019 10:53:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573498414; cv=none; d=google.com; s=arc-20160816; b=nNoTMcvS8BBJKXXTSB9KvpgRVpbT1Q4QzXWSGUjwfnwD3N9ab6QiTqHX3ZO+B/u2Ae R73G2DFJ+Uj4pDELqR+P6TulILdUHrxukRFyw2fEtx5ONA8NH39Ygot0H2m/U7AiMH5Z VH1GtEKffBrFGtqtX/hrAocmhnM+/Rj9moow+rRdjaxBMmwcWn5bViu1MCamnqYuTJ9e f3dH+8t+XG+/MlivDhKwc6ra2jK9dzbShssgurGfkv37H0hqxr+LQzu4X4EOGdTV5YLD c7WLY5n046m3j7VYJs2BnzGKG5UkmFSuWxznqQgVX7IBOl0aKwQWghs6Ail166DEtS6F dQNQ== 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=wKUDFclv96ya5v6JFpZid2ru20JqlCoJnQnFnmDIWH8=; b=S2/bPnASSBl0roAsALqiUoa0T6CQvg9Q/ueY3n0FEtqFGmwx2WveWS76vXrAB9sv58 iz4f/lKymuHKHXMQswY4+GDWRWVRVJmsj4kCxhmCPy74aEIGaCF0RtmTjtpqY4ow/o+T TIDwDjHtOcW8FqO4cOrwNB58RyFitd4sY/h5PIYhy7ZKwT+EoL0DwE2859asItV15zwH Z6C1CbRXGcPa+g2jfOhnRtF0Defx5UIoMmfcXWWUN0kx/M3UEwn5T4jIPM7zJ4lMGw0z wfvMHYMowSk05GAV5dzYLihPRwMNnUUy/JY5gfURIq+bQAvx8X74lYseB3847Jq5cGp3 3WDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yg5Hgu+F; 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 k20si3132061ejj.21.2019.11.11.10.53.10; Mon, 11 Nov 2019 10:53:34 -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=yg5Hgu+F; 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 S1730362AbfKKSu3 (ORCPT + 99 others); Mon, 11 Nov 2019 13:50:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:44160 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728461AbfKKSu1 (ORCPT ); Mon, 11 Nov 2019 13:50:27 -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 2AC90222C1; Mon, 11 Nov 2019 18:50:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573498226; bh=xgMeimPcvHOIArbrDbWkWWbd5mdHO0gP7skiv0N82S0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yg5Hgu+FrZ6zaSTvDDIwJ6RZtEjuTB/dOHCnp1zR6AE4DWApdWTN7GaA0zTjIQj0i AHifWnyhO5SqWi1PPMCW3mEwMKHzUWPk01CHk6kcqTdwLes5B2qj/hzpNWQKTY3LRV TK/iMD05gQpicjDQwJDuy5sJttS4JAAqxWzSDuMg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jean-Baptiste Maneyrol , Jonathan Cameron Subject: [PATCH 5.3 058/193] iio: imu: inv_mpu6050: fix no data on MPU6050 Date: Mon, 11 Nov 2019 19:27:20 +0100 Message-Id: <20191111181505.263610846@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191111181459.850623879@linuxfoundation.org> References: <20191111181459.850623879@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 commit 6e82ae6b8d11b948b74e71396efd8e074c415f44 upstream. 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: Greg Kroah-Hartman --- 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(-) --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -114,54 +114,63 @@ static const struct inv_mpu6050_hw hw_in .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, }, }; --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h @@ -100,12 +100,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; }; /* --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c @@ -180,9 +180,6 @@ irqreturn_t inv_mpu6050_read_fifo(int ir "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); @@ -211,6 +208,18 @@ irqreturn_t inv_mpu6050_read_fifo(int ir 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);