From patchwork Wed Nov 22 07:02:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 840324 X-Patchwork-Delegate: bartekgola@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="S6PnsDf+"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yhYQh3nykz9s8J for ; Wed, 22 Nov 2017 18:06:20 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751148AbdKVHGT (ORCPT ); Wed, 22 Nov 2017 02:06:19 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:37872 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751216AbdKVHGS (ORCPT ); Wed, 22 Nov 2017 02:06:18 -0500 Received: by mail-wm0-f67.google.com with SMTP id v186so7936625wma.2 for ; Tue, 21 Nov 2017 23:06:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=tksBOi84IHbfCBNaMkElx26wHXi0CjLypBNSP7koDhw=; b=S6PnsDf+FzN+Q/Dv8XT5xy/Vi7LBq/txsqncsoTcrwFKo6n60csQEKCu8QVh6B/Ap6 HAQRP02cgsjfMTnyYlzP3JuIJEsBNK8dPoBy/0F7U/nzsn9L1hPE1mYfaYKapU9M0gBw Z+r7tGwjMQHiWXT87+xCXXWeExNqVPgIreFDh4UjyCnYgf+qf8NpL0gdcvYTr65pdGGO iHbFG+5ECdDudMhjH7atxMgHc736NDt/6MXlmIR8GUZTPPUGwCyeWspOczzvap9fa+dI EZXhPSYe8FsqIeSbk3EGnwBhpJJMGb/xSBpRPnoHQSVsfMhWufWbHd4BFAEW3X9hi7K5 ai8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=tksBOi84IHbfCBNaMkElx26wHXi0CjLypBNSP7koDhw=; b=kPT2H+/0+c43CCOxMY16rvTi9hmGgoPg+w3TSN1+rFe2GDuKzl5Ljdfl8oF+V0lENN KuBqNtM1TZ4487w6pTfcbMLxHocAuTIDgfKX87batTi2cnCRA5QC0+H3HTYHSOcGULFW ZYsBDC+I1HeFbm1IbwKNmuwBiq7gSXE41bDrWMNnhAIgysUXJr6dHcE/Eitao11W/Wum dPxngPGtUAFsl6tXWnfVzBudZwt2Eako8Wqtue29MWsbM3+ou+fSNccVUaRlCzHcPtJy sYyrC2yIq1fZSmKq/WoZJt2TeLvMvw6n7uBlp5880JfOpWQ6yJGjypfGAp/TL2KtgmoB JMeg== X-Gm-Message-State: AJaThX7BnN8huH39CBFWh846+UGBltXj8M8IJahQH8ImdEnKcpuE1dI6 5mxfL3f6ApYVL2leZM4voccCJDU2mCg= X-Google-Smtp-Source: AGs4zMYvwHdlx06jmal8iGWXYeUSoqva5wlC0RRs1Z1F2J2wSTRgBAA+KaudtcoqJnanSW13ffrsfw== X-Received: by 10.80.214.74 with SMTP id c10mr10215466edj.271.1511334377074; Tue, 21 Nov 2017 23:06:17 -0800 (PST) Received: from [192.168.178.85] (pD9F90FDA.dip0.t-ipconnect.de. [217.249.15.218]) by smtp.googlemail.com with ESMTPSA id p7sm10378285edj.5.2017.11.21.23.06.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Nov 2017 23:06:16 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v3 3/7] eeprom: at24: add regmap-based write function To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: Message-ID: Date: Wed, 22 Nov 2017 08:02:59 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Add a regmap-based write function. Signed-off-by: Heiner Kallweit --- v2: - rebased v3: - improve readability - re-introduce debug message --- drivers/misc/eeprom/at24.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index fe4393ad6..86a36482a 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -537,6 +537,31 @@ static ssize_t at24_eeprom_write_smbus_byte(struct at24_data *at24, return -ETIMEDOUT; } +static ssize_t at24_regmap_write(struct at24_data *at24, const char *buf, + unsigned int offset, size_t count) +{ + unsigned long timeout, write_time; + struct at24_client *at24_client; + struct i2c_client *client; + struct regmap *regmap; + int ret; + + at24_client = at24_translate_offset(at24, &offset); + regmap = at24_client->regmap; + client = at24_client->client; + count = at24_adjust_write_count(at24, offset, count); + + loop_until_timeout(timeout, write_time) { + ret = regmap_bulk_write(regmap, offset, buf, count); + dev_dbg(&client->dev, "write %zu@%d --> %d (%ld)\n", + count, offset, ret, jiffies); + if (!ret) + return count; + } + + return -ETIMEDOUT; +} + static ssize_t at24_eeprom_write_i2c(struct at24_data *at24, const char *buf, unsigned int offset, size_t count) { @@ -654,7 +679,7 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count) while (count) { int status; - status = at24->write_func(at24, buf, off, count); + status = at24_regmap_write(at24, buf, off, count); if (status < 0) { mutex_unlock(&at24->lock); pm_runtime_put(&client->dev);