Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1284673pxb; Fri, 21 Jan 2022 14:20:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJzpQHp/iKhBkepRxKdUsky0ylgXoMGLHQqKw7C37bDtZjw34P6VbcGBln3Doqd+IC8AujEA X-Received: by 2002:a05:6a00:2313:b0:4c6:fd5c:118a with SMTP id h19-20020a056a00231300b004c6fd5c118amr5293193pfh.74.1642803628973; Fri, 21 Jan 2022 14:20:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642803628; cv=none; d=google.com; s=arc-20160816; b=fxAKfOB8XeLHrUaKWxCN8zQJepPOo6y3iOV7njEe5e4lkNUKbshNeeAEHt20O2q9uW 6J9mnIKFfbyFZxfr5B7D9IL41wL+FP4VXlFuMIRl21Q1pf+gNIC4QJw0ITS8kH1truQw 6CfqW6EGgEdM3lqN2S+CKmwB8XEEHuxzsfJj6vWBRYqVNsFT7ZVYVI92hhRmRXCVC5T+ NM7bm0cFBG87sjMhyTS5LKzj390u7QcEbtjX+YM0IZHtdhgA5pG08iJear5v3FIcGC9Y 6Y8Y49zpSwakcqkXZp0cHWFKziKjkyfTAgPoyBS/v8VMTPZF7zjD2dS518YP+bdU81do z63A== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0VeueS0G60pc1cICW7gwpNjWkIJgn7D6ZzcaRgxSFjs=; b=KbJatwCChlVXGxUYAItJ0A+MdaPH5Af1YpAviOIqvg/clbtGnqcn88ZVlKeSjgeNbI hVQ6NgVcRGcGliYwWqusdRfIOIVdkUQ93G1+LwnGQ+yw/6S3rprlmsWoCHFmzKkAF09I s16Tv+Mk8cgPWU3WK9oGDER/K1sK6/lDAVAPlgnRmcGrk5J8A4yfOWl1jSJlCDR9oMGP wK2hUrZX9MOlra8uX+GqhTBBmh0NYt0zZJXXRODJTwdan04r4f7D2zhQiaPgW1xBcJ2Y 8lynxbcEkgEcIpzgfsQbtL3YXLdh/MmtHrZwkq+hXG/CsSc3mgtvRn77t2UaiUo0dmab V0cA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=ZMCIyAPk; 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=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b9si6661229plm.324.2022.01.21.14.20.13; Fri, 21 Jan 2022 14:20:28 -0800 (PST) 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=@collabora.com header.s=mail header.b=ZMCIyAPk; 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=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376675AbiATPX0 (ORCPT + 99 others); Thu, 20 Jan 2022 10:23:26 -0500 Received: from bhuna.collabora.co.uk ([46.235.227.227]:35502 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376622AbiATPWm (ORCPT ); Thu, 20 Jan 2022 10:22:42 -0500 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: detlev) with ESMTPSA id A6A8E1F45344 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1642692161; bh=2mB2P4wQOPq9kSLMyvSy9LaY6Q067M0W9yvzSk3DLlM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZMCIyAPkzsbattDVeeURkKSN9tQXId/AoEpzX+AIRWjWMHmrorWgkZRTMqlZHN22A hBxjvD6hOgdKh/CzmAYZaZQcxxt+I9UeiIiVrNp7SzKwS47OkfmojwNqeqWjIi6Yvg bwVCZgNJd5Tw+/bdzaKVldUj693RvMcl9PszlRaWXr0D359OaO9mjDVZZfA6X2y23G omWnbOq4FaQB1yhWhvJ3T+aMMuN5HaOyQzOfh/eqHjcULKX5rjg+dWHPBodLrhyraM /hO0O8X/1RY/tvLR0JHIPm9dBJ8jGFJHKmtjwANuBxrgM82a3CRtpsXDWTV5xxbu0U yDc2ijHAM9gzA== From: Detlev Casanova To: linux-kernel@vger.kernel.org Cc: Dave Stevenson , Liam Girdwood , Mark Brown Subject: [PATCH 9/9] regulator/rpi-panel-attiny: Use two transactions for I2C read Date: Thu, 20 Jan 2022 10:21:50 -0500 Message-Id: <20220120152150.1952568-10-detlev.casanova@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220120152150.1952568-1-detlev.casanova@collabora.com> References: <20220120152150.1952568-1-detlev.casanova@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dave Stevenson The I2C to the Atmel is very fussy, and locks up easily on Pi0-3 particularly on reads. If running at 100kHz on Pi3, reading the ID register generally locks up the Atmel, but splitting the register select write and read into two transactions is reliable. Signed-off-by: Dave Stevenson --- .../regulator/rpi-panel-attiny-regulator.c | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/drivers/regulator/rpi-panel-attiny-regulator.c b/drivers/regulator/rpi-panel-attiny-regulator.c index 8b80c0de1022..e3decc419814 100644 --- a/drivers/regulator/rpi-panel-attiny-regulator.c +++ b/drivers/regulator/rpi-panel-attiny-regulator.c @@ -234,6 +234,39 @@ static void attiny_gpio_set(struct gpio_chip *gc, unsigned int off, int val) mutex_unlock(&state->lock); } +static int attiny_i2c_read(struct i2c_client *client, u8 reg, unsigned int *buf) +{ + struct i2c_msg msgs[1]; + u8 addr_buf[1] = { reg }; + u8 data_buf[1] = { 0, }; + int ret; + + /* Write register address */ + msgs[0].addr = client->addr; + msgs[0].flags = 0; + msgs[0].len = ARRAY_SIZE(addr_buf); + msgs[0].buf = addr_buf; + + ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); + if (ret != ARRAY_SIZE(msgs)) + return -EIO; + + usleep_range(5000, 10000); + + /* Read data from register */ + msgs[0].addr = client->addr; + msgs[0].flags = I2C_M_RD; + msgs[0].len = 1; + msgs[0].buf = data_buf; + + ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); + if (ret != ARRAY_SIZE(msgs)) + return -EIO; + + *buf = data_buf[0]; + return 0; +} + /* * I2C driver interface functions */ @@ -264,7 +297,7 @@ static int attiny_i2c_probe(struct i2c_client *i2c, goto error; } - ret = regmap_read(regmap, REG_ID, &data); + ret = attiny_i2c_read(i2c, REG_ID, &data); if (ret < 0) { dev_err(&i2c->dev, "Failed to read REG_ID reg: %d\n", ret); goto error; -- 2.34.1