From patchwork Mon Nov 27 20:34:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 841863 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="mns6kYNm"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ylz7B6gbdz9s1h for ; Tue, 28 Nov 2017 07:34:46 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752707AbdK0Uep (ORCPT ); Mon, 27 Nov 2017 15:34:45 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:42484 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752626AbdK0Uep (ORCPT ); Mon, 27 Nov 2017 15:34:45 -0500 Received: by mail-wm0-f67.google.com with SMTP id 124so19945983wmv.1 for ; Mon, 27 Nov 2017 12:34:44 -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=pBW5EAqfdeDLSpzzDRlzf6iHCT9s+reyTxbb13jRYTY=; b=mns6kYNmtoJOOo5EZqGO9cweImITO/ApOs6k44FY8dLRDgAbjAQYcdrfzYGtIn74l9 xHRu7S6Gv1U0IqJbqpqyfKNoPEfWCghCk7n53Y13l7oVTvOafB0aQliQBbgpBlHAGDgB Gn6ySmN1daJLbC3CHa6teiEht3kEKdU1k5GNjXuvICL0qenLKESYUCqfCsLQMH0rxz2O kSNiD2z/D25X/PWJ6/LIAh02mmeDD2ANM5Kz538sp8c5PYV+3wEdok2YnApV7BZrgkKo jhCr0MnTz/FxItLEQkuLaenszSR+IVtXJmqMq3+FmFBHgHCMXz2I6JL0QxIKyKt/1nXM n58g== 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=pBW5EAqfdeDLSpzzDRlzf6iHCT9s+reyTxbb13jRYTY=; b=LFBJt24dYehA9VJ7RBxQaDtD0gjIysyCYWseGzHrq0E/bnJHFeoJju5Wq6WZP5W30o 3mTps2ZiBXykgoyGJIeo8xeQ1S6oqW/aKAGRPQYHid/dAtCWpZgUTlmaQeB11DclMlAr zGafb5A8v1hhJMDkQs6VExb9nzZR3PWccnjNvJBthk9iz4bjZhsZ71qPOjeWI/vSuiy0 y6q7OK80WzC77B6MjS3FT+FEervj5pKRxoMyHwXkWwEKgr5pRbV76XM2VBFWkLkhluNf HPmL0q4no/K5+wktWggXLrgj3UX5wi+2I5p8gmkffxiRAoDpnlC3aFU2iB66X3h1tML5 jglw== X-Gm-Message-State: AJaThX7ol4A42sxWTMMkTZMkYznhkL1pZHt1CKecYNYs0sJ03xWHyCfM dazuXdg2gLlI8od0dJ0t9aDr7A== X-Google-Smtp-Source: AGs4zMafX6hG6ba5fH1hFn7gKN521x+9OM+ciXkwoHn5yE8yyJWkUFuOGKT40GSr0jfN/OmmUHpnWg== X-Received: by 10.28.127.22 with SMTP id a22mr16588223wmd.12.1511814883304; Mon, 27 Nov 2017 12:34:43 -0800 (PST) Received: from ?IPv6:2003:ea:8bc0:e400:cdd0:4154:8262:d8bc? (p200300EA8BC0E400CDD041548262D8BC.dip0.t-ipconnect.de. [2003:ea:8bc0:e400:cdd0:4154:8262:d8bc]) by smtp.googlemail.com with ESMTPSA id d71sm11807031wma.7.2017.11.27.12.34.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Nov 2017 12:34:42 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v5 1/7] eeprom: at24: add basic regmap_i2c support To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: <2c379f45-d5e3-71af-eb20-ca51e09d9257@gmail.com> Message-ID: <3246477f-2e93-9e84-d13c-1e2e63ecfea3@gmail.com> Date: Mon, 27 Nov 2017 21:34:14 +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: <2c379f45-d5e3-71af-eb20-ca51e09d9257@gmail.com> Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org This patch adds basic regmap support to be used by subsequent patches of this series. Signed-off-by: Heiner Kallweit --- v2: - rebased v3: - no changes v4: - no changes v5: - no changes --- drivers/misc/eeprom/Kconfig | 1 + drivers/misc/eeprom/at24.c | 53 +++++++++++++++++++++++++++++++++++---------- 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/drivers/misc/eeprom/Kconfig b/drivers/misc/eeprom/Kconfig index de5876209..68a1ac929 100644 --- a/drivers/misc/eeprom/Kconfig +++ b/drivers/misc/eeprom/Kconfig @@ -4,6 +4,7 @@ config EEPROM_AT24 tristate "I2C EEPROMs / RAMs / ROMs from most vendors" depends on I2C && SYSFS select NVMEM + select REGMAP_I2C help Enable this driver to get read/write support to most I2C EEPROMs and compatible devices like FRAMs, SRAMs, ROMs etc. After you diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 75537a6fd..3700b0383 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -55,6 +56,11 @@ * which won't work on pure SMBus systems. */ +struct at24_client { + struct i2c_client *client; + struct regmap *regmap; +}; + struct at24_data { struct at24_platform_data chip; int use_smbus; @@ -81,7 +87,7 @@ struct at24_data { * Some chips tie up multiple I2C addresses; dummy devices reserve * them for us, and we'll use them with SMBus calls. */ - struct i2c_client *client[]; + struct at24_client client[]; }; /* @@ -274,7 +280,7 @@ static struct i2c_client *at24_translate_offset(struct at24_data *at24, *offset &= 0xff; } - return at24->client[i]; + return at24->client[i].client; } static ssize_t at24_eeprom_read_smbus(struct at24_data *at24, char *buf, @@ -679,6 +685,16 @@ static void at24_get_pdata(struct device *dev, struct at24_platform_data *chip) } } +static const struct regmap_config regmap_config_8 = { + .reg_bits = 8, + .val_bits = 8, +}; + +static const struct regmap_config regmap_config_16 = { + .reg_bits = 16, + .val_bits = 8, +}; + static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct at24_platform_data chip; @@ -689,6 +705,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) struct at24_data *at24; int err; unsigned i, num_addresses; + const struct regmap_config *config; u8 test_byte; if (client->dev.platform_data) { @@ -770,8 +787,13 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) num_addresses = DIV_ROUND_UP(chip.byte_len, (chip.flags & AT24_FLAG_ADDR16) ? 65536 : 256); + if (chip.flags & AT24_FLAG_ADDR16) + config = ®map_config_16; + else + config = ®map_config_8; + at24 = devm_kzalloc(&client->dev, sizeof(struct at24_data) + - num_addresses * sizeof(struct i2c_client *), GFP_KERNEL); + num_addresses * sizeof(struct at24_client), GFP_KERNEL); if (!at24) return -ENOMEM; @@ -781,6 +803,11 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) at24->chip = chip; at24->num_addresses = num_addresses; + at24->client[0].client = client; + at24->client[0].regmap = devm_regmap_init_i2c(client, config); + if (IS_ERR(at24->client[0].regmap)) + return PTR_ERR(at24->client[0].regmap); + if ((chip.flags & AT24_FLAG_SERIAL) && (chip.flags & AT24_FLAG_MAC)) { dev_err(&client->dev, "invalid device data - cannot have both AT24_FLAG_SERIAL & AT24_FLAG_MAC."); @@ -828,18 +855,22 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) } } - at24->client[0] = client; - /* use dummy devices for multiple-address chips */ for (i = 1; i < num_addresses; i++) { - at24->client[i] = i2c_new_dummy(client->adapter, - client->addr + i); - if (!at24->client[i]) { + at24->client[i].client = i2c_new_dummy(client->adapter, + client->addr + i); + if (!at24->client[i].client) { dev_err(&client->dev, "address 0x%02x unavailable\n", client->addr + i); err = -EADDRINUSE; goto err_clients; } + at24->client[i].regmap = devm_regmap_init_i2c( + at24->client[i].client, config); + if (IS_ERR(at24->client[i].regmap)) { + err = PTR_ERR(at24->client[i].regmap); + goto err_clients; + } } i2c_set_clientdata(client, at24); @@ -898,8 +929,8 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) err_clients: for (i = 1; i < num_addresses; i++) - if (at24->client[i]) - i2c_unregister_device(at24->client[i]); + if (at24->client[i].client) + i2c_unregister_device(at24->client[i].client); pm_runtime_disable(&client->dev); @@ -916,7 +947,7 @@ static int at24_remove(struct i2c_client *client) nvmem_unregister(at24->nvmem); for (i = 1; i < at24->num_addresses; i++) - i2c_unregister_device(at24->client[i]); + i2c_unregister_device(at24->client[i].client); pm_runtime_disable(&client->dev); pm_runtime_set_suspended(&client->dev); From patchwork Mon Nov 27 20:34:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 841864 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="lC4I+sAz"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ylz7C5jC4z9s4s for ; Tue, 28 Nov 2017 07:34:47 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752626AbdK0Ueq (ORCPT ); Mon, 27 Nov 2017 15:34:46 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:41652 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752779AbdK0Ueq (ORCPT ); Mon, 27 Nov 2017 15:34:46 -0500 Received: by mail-wm0-f68.google.com with SMTP id b189so36667806wmd.0 for ; Mon, 27 Nov 2017 12:34:45 -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=dM72aO05ZRKb/rVgUTvXskCuSfa8eCRgbW/mPDpBIPU=; b=lC4I+sAzPmwH0f37AC1fQpzK2pweagnFvxwATSb2mY3S5WZLZphJ4wATOCSYTRgkWz nD8zn1f9n6/i47E0VCOU1HdNIfpC3mgwNWXfd9gwKPOT2FxnZlgoE40B14L8FwKIC2Sa KRzLuRvEnS9JYoPRRyhjcc/IKy8UvYsMWEE4D/O0hw5Cxry5naH7gRlSbxkzVhNS8S1d J3zIZEM5vs7iRniXQ4/eM77Cno8F9VkdCxJevNGC40brJkA65WzcnbIZvelAq29ekIpQ uhOvPqcMp6FnqfXKjJ6wmzAURcnX64onJuAfK5V5HLiXyqz9jp9NzImRSPv5wJMSRgtR mLTg== 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=dM72aO05ZRKb/rVgUTvXskCuSfa8eCRgbW/mPDpBIPU=; b=ioTW/iGLpKI2devhhYRhGuE38I2FQvDkdP0K5NHe9/Lr8s180KZVqzumKYToA7Jlby fqn79ZVri7OMv3/fYyBrBIOdQJ+6oJXV18TA+yi93nAgVau63Cac12mEWvcDOGXRMqrY bwgBIKmXLuHp4So6BWvjM23/o0/OsP3W00iEUqurZbRGbvcFrGMh4B3xc8rOVP57RJj0 RFawhkjYYnHNFIP0DZVudgZZDE1Kj+sJ7kdardJuvyM8q6bILEE4LDJLMRFxveQ4rq0b 5f7cAvhy9MFUpZuS/b7bjNwKNouAFkLEbqeXnNREaGRyqt8zyEsK9fXP3AYB/iefgQko n9SQ== X-Gm-Message-State: AJaThX7rEpNgql/A1lo8vh/p59PL+w/TLgwbEtdBEDqIuBrgt7m72B28 9Me/KvGcoUebO5CsoxAHk4PNTg== X-Google-Smtp-Source: AGs4zMY4mdXtJuxx9vCH6mOpDHVzFPZOtRA8OTn6xf8vNqsMNwxaDIuwWHIBm8aoLEEdkpdTk367/Q== X-Received: by 10.28.88.65 with SMTP id m62mr17571359wmb.111.1511814884744; Mon, 27 Nov 2017 12:34:44 -0800 (PST) Received: from ?IPv6:2003:ea:8bc0:e400:cdd0:4154:8262:d8bc? (p200300EA8BC0E400CDD041548262D8BC.dip0.t-ipconnect.de. [2003:ea:8bc0:e400:cdd0:4154:8262:d8bc]) by smtp.googlemail.com with ESMTPSA id t200sm15434016wmd.45.2017.11.27.12.34.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Nov 2017 12:34:44 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v5 2/7] eeprom: at24: change at24_translate_offset return type To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: <2c379f45-d5e3-71af-eb20-ca51e09d9257@gmail.com> Message-ID: Date: Mon, 27 Nov 2017 21:34:19 +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: <2c379f45-d5e3-71af-eb20-ca51e09d9257@gmail.com> Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Change return type of at24_translate_offset to *at24_client to make member regmap accessible for subsequent patches of this series. Signed-off-by: Heiner Kallweit --- v2: - rebased v3: - improve readability v4: - no changes v5: - no changes --- drivers/misc/eeprom/at24.c | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 3700b0383..e4bace389 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -267,8 +267,8 @@ MODULE_DEVICE_TABLE(acpi, at24_acpi_ids); * one "eeprom" file not four, but larger reads would fail when * they crossed certain pages. */ -static struct i2c_client *at24_translate_offset(struct at24_data *at24, - unsigned int *offset) +static struct at24_client *at24_translate_offset(struct at24_data *at24, + unsigned int *offset) { unsigned i; @@ -280,17 +280,19 @@ static struct i2c_client *at24_translate_offset(struct at24_data *at24, *offset &= 0xff; } - return at24->client[i].client; + return &at24->client[i]; } static ssize_t at24_eeprom_read_smbus(struct at24_data *at24, char *buf, unsigned int offset, size_t count) { unsigned long timeout, read_time; + struct at24_client *at24_client; struct i2c_client *client; int status; - client = at24_translate_offset(at24, &offset); + at24_client = at24_translate_offset(at24, &offset); + client = at24_client->client; if (count > io_limit) count = io_limit; @@ -318,13 +320,15 @@ static ssize_t at24_eeprom_read_i2c(struct at24_data *at24, char *buf, unsigned int offset, size_t count) { unsigned long timeout, read_time; + struct at24_client *at24_client; struct i2c_client *client; struct i2c_msg msg[2]; int status, i; u8 msgbuf[2]; memset(msg, 0, sizeof(msg)); - client = at24_translate_offset(at24, &offset); + at24_client = at24_translate_offset(at24, &offset); + client = at24_client->client; if (count > io_limit) count = io_limit; @@ -368,12 +372,14 @@ static ssize_t at24_eeprom_read_serial(struct at24_data *at24, char *buf, unsigned int offset, size_t count) { unsigned long timeout, read_time; + struct at24_client *at24_client; struct i2c_client *client; struct i2c_msg msg[2]; u8 addrbuf[2]; int status; - client = at24_translate_offset(at24, &offset); + at24_client = at24_translate_offset(at24, &offset); + client = at24_client->client; memset(msg, 0, sizeof(msg)); msg[0].addr = client->addr; @@ -421,12 +427,14 @@ static ssize_t at24_eeprom_read_mac(struct at24_data *at24, char *buf, unsigned int offset, size_t count) { unsigned long timeout, read_time; + struct at24_client *at24_client; struct i2c_client *client; struct i2c_msg msg[2]; u8 addrbuf[2]; int status; - client = at24_translate_offset(at24, &offset); + at24_client = at24_translate_offset(at24, &offset); + client = at24_client->client; memset(msg, 0, sizeof(msg)); msg[0].addr = client->addr; @@ -478,10 +486,12 @@ static ssize_t at24_eeprom_write_smbus_block(struct at24_data *at24, unsigned int offset, size_t count) { unsigned long timeout, write_time; + struct at24_client *at24_client; struct i2c_client *client; ssize_t status = 0; - client = at24_translate_offset(at24, &offset); + at24_client = at24_translate_offset(at24, &offset); + client = at24_client->client; count = at24_adjust_write_count(at24, offset, count); loop_until_timeout(timeout, write_time) { @@ -505,10 +515,12 @@ static ssize_t at24_eeprom_write_smbus_byte(struct at24_data *at24, unsigned int offset, size_t count) { unsigned long timeout, write_time; + struct at24_client *at24_client; struct i2c_client *client; ssize_t status = 0; - client = at24_translate_offset(at24, &offset); + at24_client = at24_translate_offset(at24, &offset); + client = at24_client->client; loop_until_timeout(timeout, write_time) { status = i2c_smbus_write_byte_data(client, offset, buf[0]); @@ -529,12 +541,14 @@ static ssize_t at24_eeprom_write_i2c(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 i2c_msg msg; ssize_t status = 0; int i = 0; - client = at24_translate_offset(at24, &offset); + at24_client = at24_translate_offset(at24, &offset); + client = at24_client->client; count = at24_adjust_write_count(at24, offset, count); msg.addr = client->addr; @@ -567,6 +581,7 @@ static ssize_t at24_eeprom_write_i2c(struct at24_data *at24, const char *buf, static int at24_read(void *priv, unsigned int off, void *val, size_t count) { struct at24_data *at24 = priv; + struct at24_client *at24_client; struct i2c_client *client; char *buf = val; int ret; @@ -577,7 +592,8 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count) if (off + count > at24->chip.byte_len) return -EINVAL; - client = at24_translate_offset(at24, &off); + at24_client = at24_translate_offset(at24, &off); + client = at24_client->client; ret = pm_runtime_get_sync(&client->dev); if (ret < 0) { @@ -615,6 +631,7 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count) static int at24_write(void *priv, unsigned int off, void *val, size_t count) { struct at24_data *at24 = priv; + struct at24_client *at24_client; struct i2c_client *client; char *buf = val; int ret; @@ -625,7 +642,8 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count) if (off + count > at24->chip.byte_len) return -EINVAL; - client = at24_translate_offset(at24, &off); + at24_client = at24_translate_offset(at24, &off); + client = at24_client->client; ret = pm_runtime_get_sync(&client->dev); if (ret < 0) { From patchwork Mon Nov 27 20:34:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 841865 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="QnF6stov"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ylz7D6HVLz9s7C for ; Tue, 28 Nov 2017 07:34:48 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752779AbdK0Ues (ORCPT ); Mon, 27 Nov 2017 15:34:48 -0500 Received: from mail-wr0-f193.google.com ([209.85.128.193]:37555 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752706AbdK0Uer (ORCPT ); Mon, 27 Nov 2017 15:34:47 -0500 Received: by mail-wr0-f193.google.com with SMTP id k61so27721000wrc.4 for ; Mon, 27 Nov 2017 12:34:47 -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=pMEE68S1PEs3rogQKMXYsj9QKfw+Ro6quj9yDVi8A+w=; b=QnF6stovJOnGHIFTOJ+9fq04H9kaXunxtbWzoCFnbDw8rF4gAcIUezEyIEvL0iYV3B pLhbKDyJG6ioDmNpwIxZatSWfUalJTKsW0V9z/1EmofpkHqe0r9aU0bVo5iK6bQaIDcx fLX32xKxC9G6Vj+6sJqIaIj0NanWngTs8pIPJrHpYJC6EAPvGYsoqcySF1D/Bp8EuBCZ /s43oWHGFRjPlxdnbBhR/aL3umEne+i0qdRuR4WYf3qjPKYyA6ynJxRwCqPP9ukVbmPK 3JmIAmbpecMv7JffJJces4/vDFhX3Q62gpL09Bjv/dmVBkJuvltz9LX3HQSCyjVEh81H QCtw== 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=pMEE68S1PEs3rogQKMXYsj9QKfw+Ro6quj9yDVi8A+w=; b=JmqwNYkueNtmojqW2EEXgQL41ICpYwSNxTE6mKxmr+VCQT+E5mZ7fuBsu+4QyT1iLt YmfjJnkepvGAUv0QpctFj5GG42GIeY5BAC4X0QUqHnop/Ubmf2w6uDKirr4MNrFefNv4 Qehz3uQilPyLZYvH+/70j2CkbcZoDvFTf5YNEwkJaY0ULLNYUDa+ZwUy8A/Kwsa90D6K UhMOKnfDsIYQdDpqpoOzU+BrqLeF3PrAVNLjLg24gr0WtLazGDJwS2Wqt2DL1T7rCLgS Ofjin8pxKZ/Q4JgohKKmgkMf0y/rIlwA1CzMz8e44KUkjE8FNNq7G+8Nf+o66Bywbl8H QjOQ== X-Gm-Message-State: AJaThX5fG8r6eGjoI4h7NTQmg54IQsG6epwWLjft5nmI4watFXwJc7aF N0EpTDFq5waY5fmRYEd+OI2Kmw== X-Google-Smtp-Source: AGs4zMZ4FTSQQCHVtOJc/kb7GM1j5lMioKX3g58CuL8Vv1oHq0iZqTfJ8sSOCQDysopTIS4YYQURAA== X-Received: by 10.223.134.25 with SMTP id 25mr34644266wrv.186.1511814886051; Mon, 27 Nov 2017 12:34:46 -0800 (PST) Received: from ?IPv6:2003:ea:8bc0:e400:cdd0:4154:8262:d8bc? (p200300EA8BC0E400CDD041548262D8BC.dip0.t-ipconnect.de. [2003:ea:8bc0:e400:cdd0:4154:8262:d8bc]) by smtp.googlemail.com with ESMTPSA id c2sm18747085wrg.57.2017.11.27.12.34.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Nov 2017 12:34:45 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v5 3/7] eeprom: at24: add regmap-based write function To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: <2c379f45-d5e3-71af-eb20-ca51e09d9257@gmail.com> Message-ID: <6a415fde-8452-7f98-885a-bfac9ba97798@gmail.com> Date: Mon, 27 Nov 2017 21:34:22 +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: <2c379f45-d5e3-71af-eb20-ca51e09d9257@gmail.com> 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 v4: - no changes v5: - no changes --- 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 e4bace389..ca80424f3 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) { @@ -660,7 +685,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); From patchwork Mon Nov 27 20:34:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 841866 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="rNP6wvaR"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ylz7G1q5jz9s1h for ; Tue, 28 Nov 2017 07:34:50 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752794AbdK0Uet (ORCPT ); Mon, 27 Nov 2017 15:34:49 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:36144 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752706AbdK0Ues (ORCPT ); Mon, 27 Nov 2017 15:34:48 -0500 Received: by mail-wm0-f67.google.com with SMTP id r68so37777489wmr.1 for ; Mon, 27 Nov 2017 12:34:48 -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=cBPiUi76jtVqRXUs0DUxAj27k31EmxE+ftDx3W/yhH0=; b=rNP6wvaR3tYrqiX7krSxht8R/HW/7qMnfg9narwTsCiaxZAv2DFQu63+QtpCc7cCI9 cDnn28rIABSBJZYGnnJbqAN4JiMgPDYEXvJy66sXC4c9LHk/GtEWToXNq0rCt59nIry+ xuJGyPfxCqcOC4ThR5Hm8yf7Oa4LBvt8aSO6OI3D69h2VDA9E3exQ35uv18yOn4tcEIr cf0a7L5NPb08LUzpGG1mQwqinIKSPdvIM0B7dQlI73plIQ6uAnYkLQEYOZZh42Cze5Xv 216ZcXNwox9s0Q303Ux8PJNwQPYpRPh0rpkKlfMxBwje32Ee2JX6jn0myam5irBYw5jM WJbw== 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=cBPiUi76jtVqRXUs0DUxAj27k31EmxE+ftDx3W/yhH0=; b=eSGX4eySxFPbTqsHG1hYk2c8mth6ePynPZSwTfUUu3r9UiVQNvUbzaNRJKj0LqahKp E0+przYo3ixygpgENZS/kri4E8r2N56mDlMcxR/uxu+SI5hOcWAaNLMDXq3CqfqNJ2sM 6C/m0eJmPxnaaRUP8mRb39swUfATdiCO6F/ULQvXJ3iFE9rIadJayalKdlKzq344r99p MYgN5Prx58syZHto6YpqXh6N4OHsW+EjI+Yh94q6eD693LUwM0wm66O6xo92YXGJbSTS PfkimWNty5b3u9JIPul8zS2ZRkn9T3wSAyTsx6zdiHNUZkyg/ll3sGp5qTxvbEwENyLp wnEQ== X-Gm-Message-State: AJaThX7rhGytv5rXb/x9Rl3f61dfTprrfAZSXLcyUoFgsvtQBHYiofs0 yQdEzB9lCHDdIYZw2IwdZAfVNg== X-Google-Smtp-Source: AGs4zMYiDtw8Wg9ahib8RqOevcA9zrfFE6vSoV/rorVmEoZHMcg38e0r/l0DQ2PMifxbCFIBeT/CAg== X-Received: by 10.28.184.130 with SMTP id i124mr17749627wmf.85.1511814887427; Mon, 27 Nov 2017 12:34:47 -0800 (PST) Received: from ?IPv6:2003:ea:8bc0:e400:cdd0:4154:8262:d8bc? (p200300EA8BC0E400CDD041548262D8BC.dip0.t-ipconnect.de. [2003:ea:8bc0:e400:cdd0:4154:8262:d8bc]) by smtp.googlemail.com with ESMTPSA id p200sm11653220wmd.9.2017.11.27.12.34.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Nov 2017 12:34:46 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v5 4/7] eeprom: at24: remove old write functions To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: <2c379f45-d5e3-71af-eb20-ca51e09d9257@gmail.com> Message-ID: <8b47f81e-ad98-626c-cb96-8f2a325b1ce6@gmail.com> Date: Mon, 27 Nov 2017 21:34:24 +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: <2c379f45-d5e3-71af-eb20-ca51e09d9257@gmail.com> Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Remove the old and now unused write functions. Signed-off-by: Heiner Kallweit --- v2: - rebased v3: - rebased v4: - no changes v5: - no changes --- drivers/misc/eeprom/at24.c | 117 --------------------------------------------- 1 file changed, 117 deletions(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index ca80424f3..3df2301a9 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -64,11 +64,8 @@ struct at24_client { struct at24_data { struct at24_platform_data chip; int use_smbus; - int use_smbus_write; ssize_t (*read_func)(struct at24_data *, char *, unsigned int, size_t); - ssize_t (*write_func)(struct at24_data *, - const char *, unsigned int, size_t); /* * Lock protects against activities from other Linux tasks, @@ -76,7 +73,6 @@ struct at24_data { */ struct mutex lock; - u8 *writebuf; unsigned write_max; unsigned num_addresses; @@ -481,62 +477,6 @@ static size_t at24_adjust_write_count(struct at24_data *at24, return count; } -static ssize_t at24_eeprom_write_smbus_block(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; - ssize_t status = 0; - - at24_client = at24_translate_offset(at24, &offset); - client = at24_client->client; - count = at24_adjust_write_count(at24, offset, count); - - loop_until_timeout(timeout, write_time) { - status = i2c_smbus_write_i2c_block_data(client, - offset, count, buf); - if (status == 0) - status = count; - - dev_dbg(&client->dev, "write %zu@%d --> %zd (%ld)\n", - count, offset, status, jiffies); - - if (status == count) - return count; - } - - return -ETIMEDOUT; -} - -static ssize_t at24_eeprom_write_smbus_byte(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; - ssize_t status = 0; - - at24_client = at24_translate_offset(at24, &offset); - client = at24_client->client; - - loop_until_timeout(timeout, write_time) { - status = i2c_smbus_write_byte_data(client, offset, buf[0]); - if (status == 0) - status = count; - - dev_dbg(&client->dev, "write %zu@%d --> %zd (%ld)\n", - count, offset, status, jiffies); - - if (status == count) - return count; - } - - return -ETIMEDOUT; -} - static ssize_t at24_regmap_write(struct at24_data *at24, const char *buf, unsigned int offset, size_t count) { @@ -562,47 +502,6 @@ static ssize_t at24_regmap_write(struct at24_data *at24, const char *buf, return -ETIMEDOUT; } -static ssize_t at24_eeprom_write_i2c(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 i2c_msg msg; - ssize_t status = 0; - int i = 0; - - at24_client = at24_translate_offset(at24, &offset); - client = at24_client->client; - count = at24_adjust_write_count(at24, offset, count); - - msg.addr = client->addr; - msg.flags = 0; - - /* msg.buf is u8 and casts will mask the values */ - msg.buf = at24->writebuf; - if (at24->chip.flags & AT24_FLAG_ADDR16) - msg.buf[i++] = offset >> 8; - - msg.buf[i++] = offset; - memcpy(&msg.buf[i], buf, count); - msg.len = i + count; - - loop_until_timeout(timeout, write_time) { - status = i2c_transfer(client->adapter, &msg, 1); - if (status == 1) - status = count; - - dev_dbg(&client->dev, "write %zu@%d --> %zd (%ld)\n", - count, offset, status, jiffies); - - if (status == count) - return count; - } - - return -ETIMEDOUT; -} - static int at24_read(void *priv, unsigned int off, void *val, size_t count) { struct at24_data *at24 = priv; @@ -842,7 +741,6 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) mutex_init(&at24->lock); at24->use_smbus = use_smbus; - at24->use_smbus_write = use_smbus_write; at24->chip = chip; at24->num_addresses = num_addresses; @@ -866,15 +764,6 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) : at24_eeprom_read_i2c; } - if (at24->use_smbus) { - if (at24->use_smbus_write == I2C_SMBUS_I2C_BLOCK_DATA) - at24->write_func = at24_eeprom_write_smbus_block; - else - at24->write_func = at24_eeprom_write_smbus_byte; - } else { - at24->write_func = at24_eeprom_write_i2c; - } - writable = !(chip.flags & AT24_FLAG_READONLY); if (writable) { if (!use_smbus || use_smbus_write) { @@ -886,12 +775,6 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) if (use_smbus && write_max > I2C_SMBUS_BLOCK_MAX) write_max = I2C_SMBUS_BLOCK_MAX; at24->write_max = write_max; - - /* buffer (data + address at the beginning) */ - at24->writebuf = devm_kzalloc(&client->dev, - write_max + 2, GFP_KERNEL); - if (!at24->writebuf) - return -ENOMEM; } else { dev_warn(&client->dev, "cannot write due to controller restrictions."); From patchwork Mon Nov 27 20:34:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 841867 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="mn1d5vnf"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ylz7H57tZz9s1h for ; Tue, 28 Nov 2017 07:34:51 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752813AbdK0Uev (ORCPT ); Mon, 27 Nov 2017 15:34:51 -0500 Received: from mail-wr0-f196.google.com ([209.85.128.196]:33157 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752706AbdK0Ueu (ORCPT ); Mon, 27 Nov 2017 15:34:50 -0500 Received: by mail-wr0-f196.google.com with SMTP id 55so11426403wrx.0 for ; Mon, 27 Nov 2017 12:34:49 -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=dFxtUQeMevCq23wbXnDSKJk1l/vjKJwx0+6y2Ex1TCo=; b=mn1d5vnfUuq7gOxZd4VV8Tk4tiW9weYGh+cJ/WiRGCnvuKvl7M2VlOSpTqCt4OUbT6 BoGCOfqNMftCNF51D9UyNDsoKqOgjhiaCFc8i+yCAM+ODDKiitVn3EcrbFRZdpwmiMg2 D2anNxWxn+xqGVxwmfAVMcl5pV9T2luM/VlZxypiRVneR4pYIxTTTWOl/SnUzq6dnUE4 KDG5SbsjuLOOPLZYcLCrxdf0MJ7wMqsSXOeX/N7cc2CilrvSE4N98Fak/i/OWDH5yw1/ gtwcsLGpLBZA1XzBuBptixgljdPWstFSbKRaOu279yCOUdfgyUs6Wk2ZCr+At67u7iwk K7dA== 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=dFxtUQeMevCq23wbXnDSKJk1l/vjKJwx0+6y2Ex1TCo=; b=JhFx36c0dO1t+XnYmdS1cefMgvPCwOwfVYjEq/FfZHH5zFqD3u8rNRGl+bnUtNBohL 0puTX0TRVH2+4aTrX9YklQGlk81q/vIsEw5CmX1G99OQg9pdEuIIKaLDtThfnJMD4ZHR 5jpEbmon0+yW6aKHnTrBqtD/i7RT8HI9G0kwhhR6p6hciQAEX41SvaKnV1yPgSJq5lg/ y4pfT/ZpggLsSfh+bSUtE45yAaz/AtaHWuwKRdnkc4aApSKbBOhOD0es6cN6/O0sUT0Y NuHU5RaUBPxYgiR8mxADg9uVerK/E/4s/hSLISNQTKLLjsqUW/6TZ+VdpapDvCt14pLk 4iHA== X-Gm-Message-State: AJaThX5OQvTJ0m7sUYtfAxEFXN/Gd4ViFctYHc1a22NrlH25n1Y46o2P ZUWosBl3CEvEhmSMsH5FXxOUbQ== X-Google-Smtp-Source: AGs4zMYIFo+0URM0r0ANFDs72SGg2YcvSU15GiBJNmDtBZ8fasYF8JqSzxSlRcnqKiUHCetkCeW5RQ== X-Received: by 10.223.154.244 with SMTP id a107mr32288408wrc.8.1511814888747; Mon, 27 Nov 2017 12:34:48 -0800 (PST) Received: from ?IPv6:2003:ea:8bc0:e400:cdd0:4154:8262:d8bc? (p200300EA8BC0E400CDD041548262D8BC.dip0.t-ipconnect.de. [2003:ea:8bc0:e400:cdd0:4154:8262:d8bc]) by smtp.googlemail.com with ESMTPSA id y89sm10317296wmh.0.2017.11.27.12.34.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Nov 2017 12:34:48 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v5 5/7] eeprom: at24: add regmap-based read function To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: <2c379f45-d5e3-71af-eb20-ca51e09d9257@gmail.com> Message-ID: <1b91f67d-2a5f-9120-09fa-d27439862ab2@gmail.com> Date: Mon, 27 Nov 2017 21:34:34 +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: <2c379f45-d5e3-71af-eb20-ca51e09d9257@gmail.com> Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Add regmap-based read function and instead of using three different read functions (standard, mac, serial) use just one and factor out the read offset adjustment for mac and serial to at24_adjust_read_offset. Signed-off-by: Heiner Kallweit --- v2: - rebased v3: - improve readability - re-introduce debug message - introduce at24_adjust_read_offset v4: - move offset adjustment calculation to probe function v5: - small style improvements to at24_get_offset_adj --- drivers/misc/eeprom/at24.c | 56 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 3df2301a9..87ab2746d 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -75,6 +75,7 @@ struct at24_data { unsigned write_max; unsigned num_addresses; + unsigned int offset_adj; struct nvmem_config nvmem_config; struct nvmem_device *nvmem; @@ -312,6 +313,36 @@ static ssize_t at24_eeprom_read_smbus(struct at24_data *at24, char *buf, return -ETIMEDOUT; } +static ssize_t at24_regmap_read(struct at24_data *at24, char *buf, + unsigned int offset, size_t count) +{ + unsigned long timeout, read_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; + + if (count > io_limit) + count = io_limit; + + /* adjust offset for mac and serial read ops */ + offset += at24->offset_adj; + + loop_until_timeout(timeout, read_time) { + ret = regmap_bulk_read(regmap, offset, buf, count); + dev_dbg(&client->dev, "read %zu@%d --> %d (%ld)\n", + count, offset, ret, jiffies); + if (!ret) + return count; + } + + return -ETIMEDOUT; +} + static ssize_t at24_eeprom_read_i2c(struct at24_data *at24, char *buf, unsigned int offset, size_t count) { @@ -534,7 +565,7 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count) while (count) { int status; - status = at24->read_func(at24, buf, off, count); + status = at24_regmap_read(at24, buf, off, count); if (status < 0) { mutex_unlock(&at24->lock); pm_runtime_put(&client->dev); @@ -627,6 +658,28 @@ static void at24_get_pdata(struct device *dev, struct at24_platform_data *chip) } } +static unsigned int at24_get_offset_adj(u8 flags) +{ + if (flags & AT24_FLAG_MAC) { + return 0x0090; + } else if (flags & AT24_FLAG_SERIAL && flags & AT24_FLAG_ADDR16) { + /* + * For 16 bit address pointers, the word address must contain + * a '10' sequence in bits 11 and 10 regardless of the + * intended position of the address pointer. + */ + return 0x0800; + } else if (flags & AT24_FLAG_SERIAL) { + /* + * Otherwise the word address must begin with a '10' sequence, + * regardless of the intended address. + */ + return 0x0080; + } else { + return 0; + } +} + static const struct regmap_config regmap_config_8 = { .reg_bits = 8, .val_bits = 8, @@ -743,6 +796,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) at24->use_smbus = use_smbus; at24->chip = chip; at24->num_addresses = num_addresses; + at24->offset_adj = at24_get_offset_adj(chip.flags); at24->client[0].client = client; at24->client[0].regmap = devm_regmap_init_i2c(client, config); From patchwork Mon Nov 27 20:34:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 841868 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="bV9pqjC6"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ylz7J6cG1z9s1h for ; Tue, 28 Nov 2017 07:34:52 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752706AbdK0Uew (ORCPT ); Mon, 27 Nov 2017 15:34:52 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:46978 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752812AbdK0Uev (ORCPT ); Mon, 27 Nov 2017 15:34:51 -0500 Received: by mail-wm0-f65.google.com with SMTP id u83so36877431wmb.5 for ; Mon, 27 Nov 2017 12:34:50 -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=+nNYjfpm0vX2dSPPmzhZxwx3fjEpEglHX4/S17bWPj8=; b=bV9pqjC6aAcDh21KMu+EeXFF/TXHCWj2toiyZb6y+VVCSzKJMyOpzflkenw0xorqyU RDUX8SbSv9Wa26VXG2xBSvCO7xdUe+R/ppXYdmH9dJQbJsTNLP9+HgCXurKktgg+jHDk bbJGxEA3tzcZP2cAbqUitmlpSVMx6lSYG/FF33/pXKZOlLHaETljLP5ffFOym5YMFeN/ XHlypn8XO/9q1xTKEii3OXQLxtRbGREPemMtG/Sla7Gslhyy5IQ06YKy33cKtiPed25H OaqlfCwm6PPbXkMWeYmQJGVNFzNe8PIdORYkjcsxhHXRYgQ1ZbxQc7vR8bKjMjK+y/bD uLjw== 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=+nNYjfpm0vX2dSPPmzhZxwx3fjEpEglHX4/S17bWPj8=; b=P/Y7mhFvcqLvTCWiolSleyK37Ip+BQTPof9bLGreSpUGcN8NUhTIgNykSf+1eFWwA1 aoH0fUKJx0Mxt2ko7D0eURQmksHqMuUckjV3/BOlsDnm6RBfSa5RR+lT9hNXuyn0t5Yn 8EXGlQZ0Dr17OY8NRRHid+PDVAkMP0Dw5rHgt/bAfXRH+yHbbwPhfpN5GRWDYhCGsl/A +qRhD6lew1LdbHsmRyVjuJumiYVQSiwm70u8ysLi3v8ohV0XdJ2AGIcByssou/zih8X3 GsTcDd8HzUCAR9eqXpIAiRW7akHa89sJbvjTpNi4hfT8BNyfLkLwhM+uYjNCJ+1M8FCU pd6A== X-Gm-Message-State: AJaThX4/MfbCUp8rT7TLH7MnuWE3duwSSbQMsmVYlRZ4ldL1fTXJE0gW yZP13npzLr3h8BqBPNIFzoxGVQ== X-Google-Smtp-Source: AGs4zMZGwYUZRQU7lsQXVy0S38y1Sdlb0ls3cozAUOckrLKLMAgZWr6qI6aYmXADDjdb0tVR8gUbVA== X-Received: by 10.28.29.207 with SMTP id d198mr16314244wmd.106.1511814889975; Mon, 27 Nov 2017 12:34:49 -0800 (PST) Received: from ?IPv6:2003:ea:8bc0:e400:cdd0:4154:8262:d8bc? (p200300EA8BC0E400CDD041548262D8BC.dip0.t-ipconnect.de. [2003:ea:8bc0:e400:cdd0:4154:8262:d8bc]) by smtp.googlemail.com with ESMTPSA id s195sm22171634wmb.33.2017.11.27.12.34.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Nov 2017 12:34:49 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v5 6/7] eeprom: at24: remove old read functions To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: <2c379f45-d5e3-71af-eb20-ca51e09d9257@gmail.com> Message-ID: <385264f4-8934-67a6-972f-781ec4e8f31a@gmail.com> Date: Mon, 27 Nov 2017 21:34:37 +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: <2c379f45-d5e3-71af-eb20-ca51e09d9257@gmail.com> Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Remove the old and now unused read functions. Signed-off-by: Heiner Kallweit --- v2: - rebased v3: - rebased v4: - rebased v5: - no changes --- drivers/misc/eeprom/at24.c | 185 --------------------------------------------- 1 file changed, 185 deletions(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 87ab2746d..9b3652ec9 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -63,9 +63,6 @@ struct at24_client { struct at24_data { struct at24_platform_data chip; - int use_smbus; - - ssize_t (*read_func)(struct at24_data *, char *, unsigned int, size_t); /* * Lock protects against activities from other Linux tasks, @@ -280,39 +277,6 @@ static struct at24_client *at24_translate_offset(struct at24_data *at24, return &at24->client[i]; } -static ssize_t at24_eeprom_read_smbus(struct at24_data *at24, char *buf, - unsigned int offset, size_t count) -{ - unsigned long timeout, read_time; - struct at24_client *at24_client; - struct i2c_client *client; - int status; - - at24_client = at24_translate_offset(at24, &offset); - client = at24_client->client; - - if (count > io_limit) - count = io_limit; - - /* Smaller eeproms can work given some SMBus extension calls */ - if (count > I2C_SMBUS_BLOCK_MAX) - count = I2C_SMBUS_BLOCK_MAX; - - loop_until_timeout(timeout, read_time) { - status = i2c_smbus_read_i2c_block_data_or_emulated(client, - offset, - count, buf); - - dev_dbg(&client->dev, "read %zu@%d --> %d (%ld)\n", - count, offset, status, jiffies); - - if (status == count) - return count; - } - - return -ETIMEDOUT; -} - static ssize_t at24_regmap_read(struct at24_data *at24, char *buf, unsigned int offset, size_t count) { @@ -343,145 +307,6 @@ static ssize_t at24_regmap_read(struct at24_data *at24, char *buf, return -ETIMEDOUT; } -static ssize_t at24_eeprom_read_i2c(struct at24_data *at24, char *buf, - unsigned int offset, size_t count) -{ - unsigned long timeout, read_time; - struct at24_client *at24_client; - struct i2c_client *client; - struct i2c_msg msg[2]; - int status, i; - u8 msgbuf[2]; - - memset(msg, 0, sizeof(msg)); - at24_client = at24_translate_offset(at24, &offset); - client = at24_client->client; - - if (count > io_limit) - count = io_limit; - - /* - * When we have a better choice than SMBus calls, use a combined I2C - * message. Write address; then read up to io_limit data bytes. Note - * that read page rollover helps us here (unlike writes). msgbuf is - * u8 and will cast to our needs. - */ - i = 0; - if (at24->chip.flags & AT24_FLAG_ADDR16) - msgbuf[i++] = offset >> 8; - msgbuf[i++] = offset; - - msg[0].addr = client->addr; - msg[0].buf = msgbuf; - msg[0].len = i; - - msg[1].addr = client->addr; - msg[1].flags = I2C_M_RD; - msg[1].buf = buf; - msg[1].len = count; - - loop_until_timeout(timeout, read_time) { - status = i2c_transfer(client->adapter, msg, 2); - if (status == 2) - status = count; - - dev_dbg(&client->dev, "read %zu@%d --> %d (%ld)\n", - count, offset, status, jiffies); - - if (status == count) - return count; - } - - return -ETIMEDOUT; -} - -static ssize_t at24_eeprom_read_serial(struct at24_data *at24, char *buf, - unsigned int offset, size_t count) -{ - unsigned long timeout, read_time; - struct at24_client *at24_client; - struct i2c_client *client; - struct i2c_msg msg[2]; - u8 addrbuf[2]; - int status; - - at24_client = at24_translate_offset(at24, &offset); - client = at24_client->client; - - memset(msg, 0, sizeof(msg)); - msg[0].addr = client->addr; - msg[0].buf = addrbuf; - - /* - * The address pointer of the device is shared between the regular - * EEPROM array and the serial number block. The dummy write (part of - * the sequential read protocol) ensures the address pointer is reset - * to the desired position. - */ - if (at24->chip.flags & AT24_FLAG_ADDR16) { - /* - * For 16 bit address pointers, the word address must contain - * a '10' sequence in bits 11 and 10 regardless of the - * intended position of the address pointer. - */ - addrbuf[0] = 0x08; - addrbuf[1] = offset; - msg[0].len = 2; - } else { - /* - * Otherwise the word address must begin with a '10' sequence, - * regardless of the intended address. - */ - addrbuf[0] = 0x80 + offset; - msg[0].len = 1; - } - - msg[1].addr = client->addr; - msg[1].flags = I2C_M_RD; - msg[1].buf = buf; - msg[1].len = count; - - loop_until_timeout(timeout, read_time) { - status = i2c_transfer(client->adapter, msg, 2); - if (status == 2) - return count; - } - - return -ETIMEDOUT; -} - -static ssize_t at24_eeprom_read_mac(struct at24_data *at24, char *buf, - unsigned int offset, size_t count) -{ - unsigned long timeout, read_time; - struct at24_client *at24_client; - struct i2c_client *client; - struct i2c_msg msg[2]; - u8 addrbuf[2]; - int status; - - at24_client = at24_translate_offset(at24, &offset); - client = at24_client->client; - - memset(msg, 0, sizeof(msg)); - msg[0].addr = client->addr; - msg[0].buf = addrbuf; - addrbuf[0] = 0x90 + offset; - msg[0].len = 1; - msg[1].addr = client->addr; - msg[1].flags = I2C_M_RD; - msg[1].buf = buf; - msg[1].len = count; - - loop_until_timeout(timeout, read_time) { - status = i2c_transfer(client->adapter, msg, 2); - if (status == 2) - return count; - } - - return -ETIMEDOUT; -} - /* * Note that if the hardware write-protect pin is pulled high, the whole * chip is normally write protected. But there are plenty of product @@ -793,7 +618,6 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) return -ENOMEM; mutex_init(&at24->lock); - at24->use_smbus = use_smbus; at24->chip = chip; at24->num_addresses = num_addresses; at24->offset_adj = at24_get_offset_adj(chip.flags); @@ -809,15 +633,6 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) return -EINVAL; } - if (chip.flags & AT24_FLAG_SERIAL) { - at24->read_func = at24_eeprom_read_serial; - } else if (chip.flags & AT24_FLAG_MAC) { - at24->read_func = at24_eeprom_read_mac; - } else { - at24->read_func = at24->use_smbus ? at24_eeprom_read_smbus - : at24_eeprom_read_i2c; - } - writable = !(chip.flags & AT24_FLAG_READONLY); if (writable) { if (!use_smbus || use_smbus_write) { From patchwork Mon Nov 27 20:34:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 841869 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="nT4VJEpW"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ylz7L1hD6z9s1h for ; Tue, 28 Nov 2017 07:34:54 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752952AbdK0Uex (ORCPT ); Mon, 27 Nov 2017 15:34:53 -0500 Received: from mail-wr0-f195.google.com ([209.85.128.195]:43071 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752812AbdK0Uew (ORCPT ); Mon, 27 Nov 2017 15:34:52 -0500 Received: by mail-wr0-f195.google.com with SMTP id z34so4458798wrz.10 for ; Mon, 27 Nov 2017 12:34:52 -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=MrHGwN+FsZ7a8/+WcqXS4CARizuHB2qXgTwgugJPMqE=; b=nT4VJEpWc3Z0Ffome6/eBlNOubQ/ttYRL5swMh+ItrLeA+VgZc/Dc4XwoyZFqkOSSV xPLM4pww9fzh/FtyEKl6+Da7OPR2q/bpMqcQYUabnRJ8slQ04DUNyIo1EMXZrQ9RE1Ib jxlXCZeYtLFZmGFVVlSgAtgcK4X7I7GMUoNclf2b01/npcgG2maQmSHSHCk/T0cD+u3A RTCtCTXIqrBE8szKmekHtY//t0LEST7jIebN9NS677cZUFlIolRSBRPq1AJUZWDLRCtB VYzJwvhO/KhY6DKAn8mgAQoCzmuFFNS2kHmYEkodGh93/KjG2FF7eleWRai+3v29Yv9k v0Vw== 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=MrHGwN+FsZ7a8/+WcqXS4CARizuHB2qXgTwgugJPMqE=; b=LfZDvdektUINIlz54Vi6eczVu5lQXuwgnYff8nraxDSpmRQqAoc92lQ87xb1jHEkWs uAynAixeDcxiJP5yDpm1h3DKvLjH4Wqnm0BXHvCO7Z+ZFXmoHGPWdyegnr2tTcUQ5DmU kKVrtmntx3YEMchiY2pQgCYXf2vh65PMthlgUs/RM7QMNEnm2FOmI6V3w4Wxe7idiaQ0 kdssELE3kz3XiR+Q/Nn/kfmmJYKeQEqO323YyhzRtTDpbe7MxLiVj0BZbMBqlBax+iLm yK3M1g6sgXPbKoomMDSHnnB/e8sAbROkaUWL4GE5Vb7GdnjDFCVSyZlQ0FX7fcZjT/6Y zM7Q== X-Gm-Message-State: AJaThX5IxydTwxisfcVOEk06tPt8peLrOVCOa34HrORnfWbZ8Wj8V9n3 zhQBw+F+31I8+DydzUMKuGfFRg== X-Google-Smtp-Source: AGs4zMb/I6R79NMUvjQ5hmLocz2paHn7mgS47iO7B9muaaxosSQim5thdTzp7Tj7bkqhRS8SF6ROhg== X-Received: by 10.223.134.157 with SMTP id 29mr31958897wrx.72.1511814891388; Mon, 27 Nov 2017 12:34:51 -0800 (PST) Received: from ?IPv6:2003:ea:8bc0:e400:cdd0:4154:8262:d8bc? (p200300EA8BC0E400CDD041548262D8BC.dip0.t-ipconnect.de. [2003:ea:8bc0:e400:cdd0:4154:8262:d8bc]) by smtp.googlemail.com with ESMTPSA id x142sm13637717wme.34.2017.11.27.12.34.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Nov 2017 12:34:50 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v5 7/7] eeprom: at24: remove now unneeded smbus-related code To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: <2c379f45-d5e3-71af-eb20-ca51e09d9257@gmail.com> Message-ID: <0c8e9a5f-c066-5661-1b3b-316e3641bc61@gmail.com> Date: Mon, 27 Nov 2017 21:34:39 +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: <2c379f45-d5e3-71af-eb20-ca51e09d9257@gmail.com> Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Remove remaining now unneeded code dealing with SMBUS details. Signed-off-by: Heiner Kallweit --- v2: - rebased v3: - rebased v4: - rebased v5: - rebased --- drivers/misc/eeprom/at24.c | 58 +++++++--------------------------------------- 1 file changed, 8 insertions(+), 50 deletions(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 9b3652ec9..5768d983e 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -520,8 +520,6 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) struct at24_platform_data chip; kernel_ulong_t magic = 0; bool writable; - int use_smbus = 0; - int use_smbus_write = 0; struct at24_data *at24; int err; unsigned i, num_addresses; @@ -573,33 +571,12 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) dev_warn(&client->dev, "page_size looks suspicious (no power of 2)!\n"); - /* Use I2C operations unless we're stuck with SMBus extensions. */ - if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { - if (chip.flags & AT24_FLAG_ADDR16) - return -EPFNOSUPPORT; - - if (i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { - use_smbus = I2C_SMBUS_I2C_BLOCK_DATA; - } else if (i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_READ_WORD_DATA)) { - use_smbus = I2C_SMBUS_WORD_DATA; - } else if (i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_READ_BYTE_DATA)) { - use_smbus = I2C_SMBUS_BYTE_DATA; - } else { - return -EPFNOSUPPORT; - } - - if (i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) { - use_smbus_write = I2C_SMBUS_I2C_BLOCK_DATA; - } else if (i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) { - use_smbus_write = I2C_SMBUS_BYTE_DATA; - chip.page_size = 1; - } - } + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C) && + !i2c_check_functionality(client->adapter, + I2C_FUNC_SMBUS_WRITE_I2C_BLOCK) && + i2c_check_functionality(client->adapter, + I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) + chip.page_size = 1; if (chip.flags & AT24_FLAG_TAKE8ADDR) num_addresses = 8; @@ -634,21 +611,8 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) } writable = !(chip.flags & AT24_FLAG_READONLY); - if (writable) { - if (!use_smbus || use_smbus_write) { - - unsigned write_max = chip.page_size; - - if (write_max > io_limit) - write_max = io_limit; - if (use_smbus && write_max > I2C_SMBUS_BLOCK_MAX) - write_max = I2C_SMBUS_BLOCK_MAX; - at24->write_max = write_max; - } else { - dev_warn(&client->dev, - "cannot write due to controller restrictions."); - } - } + if (writable) + at24->write_max = min_t(unsigned int, chip.page_size, io_limit); /* use dummy devices for multiple-address chips */ for (i = 1; i < num_addresses; i++) { @@ -709,12 +673,6 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) dev_info(&client->dev, "%u byte %s EEPROM, %s, %u bytes/write\n", chip.byte_len, client->name, writable ? "writable" : "read-only", at24->write_max); - if (use_smbus == I2C_SMBUS_WORD_DATA || - use_smbus == I2C_SMBUS_BYTE_DATA) { - dev_notice(&client->dev, "Falling back to %s reads, " - "performance will suffer\n", use_smbus == - I2C_SMBUS_WORD_DATA ? "word" : "byte"); - } /* export data to kernel code */ if (chip.setup)