Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1406157pxb; Fri, 21 Jan 2022 17:55:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJy+WWjNeWyPwHmQUEhMVLYHJFG3XTq9x5dM2H7y9wD4BpDq6iN/oIfp73cYNPUbSGlvpjFI X-Received: by 2002:a17:90a:e454:: with SMTP id jp20mr3345533pjb.53.1642816509224; Fri, 21 Jan 2022 17:55:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642816509; cv=none; d=google.com; s=arc-20160816; b=MG1uWhYY2OH4krz1kyD/Gwjsa9vI7KKAK0tLgpIRTPJtpAUZPgsfqFhHsoDR23FlN5 ZkY4FLAoRyAwQGU6XhKL/sWFjNKk6+EYV8cC9wkdEcXM8bplyzioz8cnKApZ6HREivW1 ib3LOrGUJdQs3Am5ta7g1CYRQX0ExdNw2DDble8frCr0qxNuhdiSSXrXu1cHN+HFmsEo E1B3V/TPnhTsLyo3M3eVRXvs44IlqmI8f7kLwiTqmYCYNcctNXzBrK33am0EhAI58pJv Pl/MJbP94XobwltTmEs5dQMV1VV1rZmppHLM4KlwmxhKi2jUK5eHeTjUE0eHMaULpuGS ZkKQ== 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=lMmX9lvxgOkwEfxVhw4HRiF04tV/7JNOl7Clfm/ZaPMOWG7oVi2dXtr6rdTSDE/10+ 64c1PFt8VKYeExprX1ZFVAQjobh3E6o+b2LrH+pJHnw55FDtmXJgw0biVuNFog+GYZ5w W3MkcIaWQpJtfrvGq2sbv8Ex3PyA5eXICNAr6eKebFDYE9Cc5T+qYk6MmKZPUWykps28 P46AAkPCUACeIgRRzGg/x4UebyLp0vD467cl4pk5ET7MbwpmER7OnhjFsL+a+ik6NWoV z4F2kr1OHlJSEmj2gS4wouokLNeb6mYjdgk/Tt5Mcq9Gq53Dv95qq2sevTje1doVtd6M Xt3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=kmbb5e3q; 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 oj10si15481991pjb.39.2022.01.21.17.54.57; Fri, 21 Jan 2022 17:55:09 -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=kmbb5e3q; 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 S1381596AbiAUPV4 (ORCPT + 99 others); Fri, 21 Jan 2022 10:21:56 -0500 Received: from bhuna.collabora.co.uk ([46.235.227.227]:47860 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381510AbiAUPVf (ORCPT ); Fri, 21 Jan 2022 10:21:35 -0500 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: detlev) with ESMTPSA id 8BEBD1F4620F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1642778494; bh=2mB2P4wQOPq9kSLMyvSy9LaY6Q067M0W9yvzSk3DLlM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kmbb5e3qEsxmWG6cBbBUEN8rAxqpUBtJbUtt8ef1TJ2wriBuLgayzlVYjC8s2qQFs C4IzTdk93dIe4cZJ/48G+doZd1RklQ0Sp/aPkDasJXBM4Nm/tJmwJCR7DDb2tIex3z OBWi4hm2FIYIOoNtZ/o1GBFptDoZBYi4SXySuxqMApGOcdl4n9P6u7Ac6VvEdgyCjn WlLaz7bL9eQ3jbTFYqQRekTkd0DzNzDG9zix7jrfVrxhzNtLI0jKtNz1LmPoWMzHHl k89lS9ySGlUkMiSVFCRbaBhDS5SPGOSF27W5UFxb/DLDI66moh1Ij/dDYFcCMcU0Uj 5mdVO341/5Nlg== From: Detlev Casanova To: linux-kernel@vger.kernel.org Cc: Dave Stevenson , Liam Girdwood , Mark Brown Subject: [PATCH v2 9/9] regulator/rpi-panel-attiny: Use two transactions for I2C read Date: Fri, 21 Jan 2022 10:20:56 -0500 Message-Id: <20220121152056.2044551-10-detlev.casanova@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220121152056.2044551-1-detlev.casanova@collabora.com> References: <20220121152056.2044551-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