Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp814019imm; Fri, 11 May 2018 06:51:16 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr6Huw9zNs5cmw5mUnq3TONU4gwq6lR4uG5tHHNzMpU9Eh8HGUUEGrDRp03sOqRK7qh8nyS X-Received: by 2002:a65:654a:: with SMTP id a10-v6mr4494259pgw.107.1526046676436; Fri, 11 May 2018 06:51:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526046676; cv=none; d=google.com; s=arc-20160816; b=GYZ6ETwKvNGgpaINNp+lNS3eGzrZudtQXQ1dpeSYHWKcIc/YHnhPdVnmlstjHz2U6N s3oj329NlipGwVuHx7iqiGHG/PrOjj0sLdqcI7t3kfFUdvN+cz6dPWgwhmqH5xtc4Sjt +4Hk1rCx3o8DLqLQosVP6GfxedujyIPc8QhZwhkrxhFAiEbqSGHNDzNBIqZxyCh4qHvX 8TjI2dy3y3cfsz8LNbMzDfQKOH7PAZikGQzrsT6wcBZa2ZJvGovClIxj06mebUmmsspe xbY42mFdGMIdkR9eM/LEdjhskRXcSBn3ce9/h4A65CLswQefVqSHjUvZHgvNu9xXS5v2 NoQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:arc-authentication-results; bh=Bx9UL+B+p7ia4MbhEsOyyUmBoneC2PLGwYOZ+ASK1fo=; b=nFW7+uz4NbUhWQU39/7nxcYd7OHMQzlpzqVD1T6xJGhZay54lgIISdW+khXcXlFzCw C1ZobaIk4TPQpeAuD4JZL38eATGs/67EKCjVxUsMAppWRS7ZRzbj8d95LjFZSHVtdd4y 4MDbe0KU7ao5JVMcjg2gK2VwpMcqq102Pnu1jI89AUyM+gAmroRQbextVIO0mbVdgJMR Md1ZXIsgTL5a5svRovapAmOwSRrI2G9KE5cI3dghoKSNadgW36OUc+leC4krF0tqjcz3 k1zWFyjwds/eH9tW3+dEZoHrcRq9FaP9SxMtB3FLl2VHIPnwmH73aNE/avQ9yF5nRe5C 75lg== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cirrus.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 88-v6si3131369pla.315.2018.05.11.06.51.02; Fri, 11 May 2018 06:51:16 -0700 (PDT) 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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cirrus.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753158AbeEKNuf (ORCPT + 99 others); Fri, 11 May 2018 09:50:35 -0400 Received: from mx0b-001ae601.pphosted.com ([67.231.152.168]:57872 "EHLO mx0b-001ae601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753002AbeEKNue (ORCPT ); Fri, 11 May 2018 09:50:34 -0400 Received: from pps.filterd (m0077474.ppops.net [127.0.0.1]) by mx0b-001ae601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w4BDjFof018458; Fri, 11 May 2018 08:50:31 -0500 Authentication-Results: ppops.net; spf=none smtp.mailfrom=ckeepax@opensource.cirrus.com Received: from mail3.cirrus.com ([87.246.76.56]) by mx0b-001ae601.pphosted.com with ESMTP id 2hs91q2h65-1; Fri, 11 May 2018 08:50:31 -0500 Received: from EX17.ad.cirrus.com (ex17.ad.cirrus.com [172.20.9.81]) by mail3.cirrus.com (Postfix) with ESMTP id E4B24611CE60; Fri, 11 May 2018 08:50:45 -0500 (CDT) Received: from imbe.wolfsonmicro.main (198.61.95.81) by EX17.ad.cirrus.com (172.20.9.81) with Microsoft SMTP Server id 14.3.301.0; Fri, 11 May 2018 14:50:31 +0100 Received: from algalon.ad.cirrus.com (algalon.ad.cirrus.com [198.90.251.122]) by imbe.wolfsonmicro.main (8.14.4/8.14.4) with ESMTP id w4BDoUFE017652; Fri, 11 May 2018 14:50:30 +0100 From: Charles Keepax To: CC: , Subject: [PATCH] mfd: arizona: Don't use regmap_read_poll_timeout Date: Fri, 11 May 2018 14:50:30 +0100 Message-ID: <20180511135030.14590-1-ckeepax@opensource.cirrus.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=765 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1805110131 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some Arizona CODECs have a small timing window where they will NAK an I2C transaction if it happens before the boot done bit is set. This can cause the read of the register containing the boot done bit to fail until it is set. Since regmap_read_poll_timeout will abort polling if a read fails it can't be reliably used to poll the boot done bit over I2C. Do a partial revert of ef84f885e037 ("mfd: arizona: Refactor arizona_poll_reg"), removing the regmap_read_poll_timeout but leaving the refactoring to make the arizona_poll_reg take more sensible arguments. Fixes: ef84f885e037 ("mfd: arizona: Refactor arizona_poll_reg") Signed-off-by: Charles Keepax --- drivers/mfd/arizona-core.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/drivers/mfd/arizona-core.c b/drivers/mfd/arizona-core.c index 83f1c5a516d9..2ed29ce08dac 100644 --- a/drivers/mfd/arizona-core.c +++ b/drivers/mfd/arizona-core.c @@ -240,18 +240,31 @@ static int arizona_poll_reg(struct arizona *arizona, int timeout_ms, unsigned int reg, unsigned int mask, unsigned int target) { + ktime_t timeout = ktime_add_us(ktime_get(), timeout_ms * 1000); unsigned int val = 0; int ret; - ret = regmap_read_poll_timeout(arizona->regmap, - reg, val, ((val & mask) == target), - ARIZONA_REG_POLL_DELAY_US, - timeout_ms * 1000); - if (ret) - dev_err(arizona->dev, "Polling reg 0x%x timed out: %x\n", - reg, val); + while (true) { + ret = regmap_read(arizona->regmap, reg, &val); - return ret; + if ((val & mask) == target) + return 0; + + if (ktime_compare(ktime_get(), timeout) > 0) + break; + + usleep_range(ARIZONA_REG_POLL_DELAY_US / 2, + ARIZONA_REG_POLL_DELAY_US); + } + + if (ret) { + dev_err(arizona->dev, "Failed polling reg 0x%x: %d\n", + reg, ret); + return ret; + } + + dev_err(arizona->dev, "Polling reg 0x%x timed out: %x\n", reg, val); + return -ETIMEDOUT; } static int arizona_wait_for_boot(struct arizona *arizona) -- 2.11.0