From patchwork Wed Nov 22 21:12:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 840522 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="Pt1iQu42"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yhwCz0Vh5z9rxm for ; Thu, 23 Nov 2017 08:13:19 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751707AbdKVVNR (ORCPT ); Wed, 22 Nov 2017 16:13:17 -0500 Received: from mail-wr0-f196.google.com ([209.85.128.196]:33812 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751981AbdKVVNI (ORCPT ); Wed, 22 Nov 2017 16:13:08 -0500 Received: by mail-wr0-f196.google.com with SMTP id k18so10846551wre.1 for ; Wed, 22 Nov 2017 13:13:08 -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=wnwc+C0to8BEXK+LWgWa1rG9fKMtiSwY31ku4ddAsUo=; b=Pt1iQu42ZKvbw+MAZn8mvzfWUQPEvfZP+F7zDhT4Y8QKaSMa2WL+DCXPBwcVkmUopG qxeKf1OqnM0/VEfUwjOnTv8N41Vz6FVcBNRCmarO0uq9u4Q8qX2E42Mux/1z29QtnJGu CfRD75CU3Ispr1ou5pGktGR2WMWCOygokn1GQDMB9fDzA3ZPsRSQEPjnA10zzMFipGOv AuB747fur3AWhgo/4CScm/2iYDW+JajO8wj79KkyNObaGVGEafYKtm1sh82XQoEPRu2r kKoamyZeJWp2cARa5lZQAI9+M2No7TWrhbM1MIWopkukQIxZZXWTdvTWi0UYuyglP8ar nUmQ== 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=wnwc+C0to8BEXK+LWgWa1rG9fKMtiSwY31ku4ddAsUo=; b=cRctRaENrQFjiDGbzzyWMjEJ1FSVWPGCKScVoN2PuaTGg7WWhobbIChScbNovjIPuT hyXMvTHCjzseF1GhiAPrtCBLcU3vxUEYpWbY2E6tPbkSxKF7Be6uUUJqNIoTY10NE1Hl 7P7x6GT5zWyWyxkHIWZScFRDBBJMSxHbxmBP5WH0W4FMfselzZi5S6aOnmXylvoZHYKQ aLMgF24U8tqy3gLp8sViMzOnxkKPj++CTnow9K4Z7h7At6AmwYvrRo3FSoZkvK6SfN92 BG+ES33DB8cnqnOk/gfkoMrm2BRM3BnGzJHRsTnXOzdwXy4EvDWg7/JlKhc1QZMza58k lw1w== X-Gm-Message-State: AJaThX6qnnkUFjAB9eMGKjZBXPr7SMQGFb4ETmny05ej41WGm4zxEJsb PYmKYSZrCbmc0tBT7UrJOftYGg== X-Google-Smtp-Source: AGs4zMbs8zwj/5RVIfgL3TKZnr4gKb56vK/4ANzVYdui+S9QHaBwqrjfI/kZmFFcPvv5/1sq1rPMzw== X-Received: by 10.223.165.67 with SMTP id j3mr19992110wrb.181.1511385187085; Wed, 22 Nov 2017 13:13:07 -0800 (PST) Received: from ?IPv6:2003:ea:8bc0:e400:58ac:8788:9665:db13? (p200300EA8BC0E40058AC87889665DB13.dip0.t-ipconnect.de. [2003:ea:8bc0:e400:58ac:8788:9665:db13]) by smtp.googlemail.com with ESMTPSA id p42sm34648396wrb.28.2017.11.22.13.13.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Nov 2017 13:13:06 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v4 1/7] eeprom: at24: add basic regmap_i2c support To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: <0448eec2-7dfb-ca79-d03a-d5b7fcb5d76c@gmail.com> Message-ID: <7425c78c-0110-5ea1-f9b1-0263bd1aba2e@gmail.com> Date: Wed, 22 Nov 2017 22:12:46 +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: <0448eec2-7dfb-ca79-d03a-d5b7fcb5d76c@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 --- 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 e0b4b36ef..911cce8ec 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, @@ -673,6 +679,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; @@ -683,6 +699,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) { @@ -764,8 +781,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; @@ -775,6 +797,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."); @@ -822,18 +849,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); @@ -892,8 +923,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); @@ -910,7 +941,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 Wed Nov 22 21:12:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 840523 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="Ib6dBtC6"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yhwCz6PvYz9s7B for ; Thu, 23 Nov 2017 08:13:19 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751681AbdKVVNQ (ORCPT ); Wed, 22 Nov 2017 16:13:16 -0500 Received: from mail-wr0-f196.google.com ([209.85.128.196]:44409 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751884AbdKVVNJ (ORCPT ); Wed, 22 Nov 2017 16:13:09 -0500 Received: by mail-wr0-f196.google.com with SMTP id l22so15770168wrc.11 for ; Wed, 22 Nov 2017 13:13:09 -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=wrlo9ev/wTuM4+cHdguzEK/WWKxhWsMHH3qtgeG5p8c=; b=Ib6dBtC6n28LQBxBAo+JmT1YCEzl0KzrqVuWj0uLkALHWJnKskNAJNAzmcf1IYD0rK cXsrLcSUMnNpuUrBKXJbYCTL809WN1IK3k0tJX388HpYUzH6X0JDc/WBmlaXnJmX8bx6 WS9n8TZyhp0TYjv854zcpTgBuktFQ5qXBtjRau3Qf+7vF/c8QAI7t2nnehx6d+gkqCZk 9D9/P6IAhT8Knzl6pYprjQLhO9uR6zf9/PibJkuLUJEisdBFLrVlm1xqiwYZJSfCBQ5C ZdL6tn/LlXhZcS5UrJ2bANpa6xmFGWC5AYPu3L6uQR9TBNU40cSmsnl9e/Or/4sldX7U cxwA== 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=wrlo9ev/wTuM4+cHdguzEK/WWKxhWsMHH3qtgeG5p8c=; b=KB7Hb0jZNmN8nN2/JyAYjyhM94HrPZVaNfMdoVNVNaq/tEsrH4uWnalKEcNHexD5v/ VyRZt0gmF782iIDQUF/O3si4NfxiHqD7jcfFKuKkfjEzbOv5m3JZMG1s6pUKIMk2ELij 0y1/r88zf0jhwScr/RFvSeK/UQNDR9ugMgcAEvlbnMEvaPOvshfOYcHn0aUwF3j2gi1g B3HTGXVIsy2qfnNKSdu27xFe/OwN51Alz1YEGM47EHzze/B16ciDG76CC5GVpHUws0ME ZoVjp8LnQHA08OzccjgoZknkc5p3zeQJlMkCG3gOrXBC/T8EZVVyiU4cHXYgcnIzrcnO d8UQ== X-Gm-Message-State: AJaThX7wXtJV6ziZFRMqeDB7cd3m7FvATejFeQkYcU0xwzaWpLgicaLP kf6jruw5RtdiBQhMzvdCzzcUaw== X-Google-Smtp-Source: AGs4zMaPqgVU49lDdBf8r8gGRT63bcsuGO59GkvVWlh3pUWhzNuBRVBA1LlJD7Ijs2DJnHbsDBkTZA== X-Received: by 10.223.157.27 with SMTP id k27mr14755471wre.153.1511385188337; Wed, 22 Nov 2017 13:13:08 -0800 (PST) Received: from ?IPv6:2003:ea:8bc0:e400:58ac:8788:9665:db13? (p200300EA8BC0E40058AC87889665DB13.dip0.t-ipconnect.de. [2003:ea:8bc0:e400:58ac:8788:9665:db13]) by smtp.googlemail.com with ESMTPSA id 16sm16523998wrt.81.2017.11.22.13.13.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Nov 2017 13:13:07 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v4 2/7] eeprom: at24: change at24_translate_offset return type To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: <0448eec2-7dfb-ca79-d03a-d5b7fcb5d76c@gmail.com> Message-ID: <60d58343-c9c3-a209-d71f-ce5fbe08169d@gmail.com> Date: Wed, 22 Nov 2017 22:12:48 +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: <0448eec2-7dfb-ca79-d03a-d5b7fcb5d76c@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 --- 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 911cce8ec..fe4393ad6 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; @@ -574,7 +589,8 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count) if (unlikely(!count)) return count; - 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) { @@ -612,6 +628,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; @@ -619,7 +636,8 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count) if (unlikely(!count)) 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 Wed Nov 22 21:12:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 840521 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="o4zvVIbN"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yhwCw1CXmz9rxm for ; Thu, 23 Nov 2017 08:13:16 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751611AbdKVVNN (ORCPT ); Wed, 22 Nov 2017 16:13:13 -0500 Received: from mail-wr0-f195.google.com ([209.85.128.195]:39882 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751974AbdKVVNL (ORCPT ); Wed, 22 Nov 2017 16:13:11 -0500 Received: by mail-wr0-f195.google.com with SMTP id 11so12443561wrb.6 for ; Wed, 22 Nov 2017 13:13:10 -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=KzjrZeSBoGCKKusTaiHIDIoEs4tHWpUi2XH47hHbE60=; b=o4zvVIbNfpPGFH4xLhYiyOlIygI6kajKeVMrFoES6jY/3Abn2DEOXn9NI3mylMTJqz A8MYXQS+7masF2gRw31nip9FYOjhk96MqjfGyTqzLXJxGXJsJ4Kjv/nT/xsYxI87gTkr xpsvW1ZRlg0vT4RMZwQS+QvFwjenRSSeo71ZeOq0UW3ED8ROp78pSTWbeH2Wg52VR05m XvNv7xOAen2DBKmcCzJg2qPobZNXs2q+RydZT6sGGQgQWGvVnWRzaJYgAQOnRG/WdXGC 7l6FHtv9FFk87jzBu3fjKULZCQTk7rQt2EzLayeU5pbzdI7ijh0iq94yixuuQtrky68b N6Vw== 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=KzjrZeSBoGCKKusTaiHIDIoEs4tHWpUi2XH47hHbE60=; b=Eqk1GPV97lSc5T6Cl6LGXgbW9DeYptnbHoYMDeN8DYhuoRqtj4csVSybhZlv1bqfR+ GTR8EFkJUuD6GmB+FgECzfeDATMdJlnrtKZ23tc6/Wb3v339S8cEpwyaqUYZf851QC5L G2jbNUT4iLmSYo85LwjGtGbjW2FpoO7SYcbLOh7R1DPf9M5mw/29gLyon2hI3rN/vxOo 7EIl8KfQjnrh9I27xdcUvTd0rWuYXWVlZCKM3aq32khUXygJgfhRudlP/BaIb5t7eCux 1sEwhkRZEV03CfdeseP7tKqEavmsxgL1IsdDcjXvOcqINO3UsVD4LLAj8Eygb7ZhAEhV jwqA== X-Gm-Message-State: AJaThX6Xk4qz769a3L8oKsqkk86sWzISv9PXZLFQsEEfuCexj/SgOqW/ BqehTVSkazPa82ekv+riZKcmrg== X-Google-Smtp-Source: AGs4zMaDJdQaTnObn95KMhZSEKTeId3OBj+VagUNVhrewWqAi1z7boU7MDRxFFxolol9+K2XRrpXDA== X-Received: by 10.223.183.17 with SMTP id l17mr20262280wre.1.1511385189587; Wed, 22 Nov 2017 13:13:09 -0800 (PST) Received: from ?IPv6:2003:ea:8bc0:e400:58ac:8788:9665:db13? (p200300EA8BC0E40058AC87889665DB13.dip0.t-ipconnect.de. [2003:ea:8bc0:e400:58ac:8788:9665:db13]) by smtp.googlemail.com with ESMTPSA id f132sm3660659wmf.17.2017.11.22.13.13.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Nov 2017 13:13:09 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v4 3/7] eeprom: at24: add regmap-based write function To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: <0448eec2-7dfb-ca79-d03a-d5b7fcb5d76c@gmail.com> Message-ID: <81dfdad5-562c-665c-a749-e785d3da7189@gmail.com> Date: Wed, 22 Nov 2017 22:12:51 +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: <0448eec2-7dfb-ca79-d03a-d5b7fcb5d76c@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 --- 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); From patchwork Wed Nov 22 21:12:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 840525 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="kIb5lzXg"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yhwD15wkgz9rxm for ; Thu, 23 Nov 2017 08:13:21 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752140AbdKVVNP (ORCPT ); Wed, 22 Nov 2017 16:13:15 -0500 Received: from mail-wr0-f196.google.com ([209.85.128.196]:33817 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751681AbdKVVNM (ORCPT ); Wed, 22 Nov 2017 16:13:12 -0500 Received: by mail-wr0-f196.google.com with SMTP id k18so10846683wre.1 for ; Wed, 22 Nov 2017 13:13:11 -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=4EIJvyAx5ZsLpZPQ9Tm/Nb3Btaax3qUsWkYKYKgmIiU=; b=kIb5lzXgWFrsvHhiY94Z6JMwjwHBtXYXhr+YuK8Ryjo91X1kSUYtpRS8ggrmF/gI05 YPiLPhFaAby50NUlmYqGQFCrk1rV+CKaejIKkf//4GfbeWWoSDO0muXHdDgAuNu6D8b3 DOAQGi6Y+Nhh6FZlEPrsjnZ6oK1WJpzOmmP2x/+VXkitXCrlZbpqeXXP4JAzcNEQNYDp U5WrvZfOsv2GX+nZzQyEe3WQpx1Xyo6gcLT1ckqJ3AweymxH/518xqcXdVZ3TH0UjpKP /ymBIdFa19Bf5ECElNlZe/XNVm56zIM1Vhmz1C6btwbIsqzvxTaxw6nwp7AwpY5fH7n2 ai8A== 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=4EIJvyAx5ZsLpZPQ9Tm/Nb3Btaax3qUsWkYKYKgmIiU=; b=ZKfWouyWwTAoGxVoPEv0qnA7xV3+PrsQNxNS3wmsLPm8TQcAvrKFq8Y5x7YOSMRidI pi8p927VzlfSDk2xzZGnql6L7eZFgOsYML636chtEY0gO1hGhNSCNXMYP+AGAY1qAMLX dgcv+0vrAchePPOvGpBiSloXiZ0xdC0WhW2+55p7zc87JHgSd+a4Nv7/rmN9KUbMuw+p w9IeqV5ghzjg9LX64UQRQP93LLD0RLLJj2Lem3t02jJK5XBTI7/rW298ajlwtGWm554q bJp29sQXnEZRCHPA1FmHzX7uDw5RdH5fxhClLzyjoG5ALJxDofw3WVDzjl6UsVTi/AEu tpqQ== X-Gm-Message-State: AJaThX5VtuP/OvIo7KtgEGktL7ayCSkKkfttRksunfrE4xGVOkyJyb14 iWUMAkS3f3fumqwoOekNLzJgVw== X-Google-Smtp-Source: AGs4zMaZGW4Vv6bdVtxSS/DZ6YG91tSjJdSanj7Ipfyy88o4c3jRWZKXVGoJY2CtevwDDfMW5OsGQg== X-Received: by 10.223.170.143 with SMTP id h15mr20839970wrc.49.1511385190819; Wed, 22 Nov 2017 13:13:10 -0800 (PST) Received: from ?IPv6:2003:ea:8bc0:e400:58ac:8788:9665:db13? (p200300EA8BC0E40058AC87889665DB13.dip0.t-ipconnect.de. [2003:ea:8bc0:e400:58ac:8788:9665:db13]) by smtp.googlemail.com with ESMTPSA id q89sm10925667wrb.95.2017.11.22.13.13.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Nov 2017 13:13:10 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v4 4/7] eeprom: at24: remove old write functions To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: <0448eec2-7dfb-ca79-d03a-d5b7fcb5d76c@gmail.com> Message-ID: <366a5e66-46b1-dfaa-cdc3-a59cdb495a2f@gmail.com> Date: Wed, 22 Nov 2017 22:12:55 +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: <0448eec2-7dfb-ca79-d03a-d5b7fcb5d76c@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 --- 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 86a36482a..493e2b646 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; @@ -836,7 +735,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; @@ -860,15 +758,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) { @@ -880,12 +769,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 Wed Nov 22 21:12:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 840524 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="UkTZ1dhq"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yhwD04FLsz9rxm for ; Thu, 23 Nov 2017 08:13:20 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751719AbdKVVNS (ORCPT ); Wed, 22 Nov 2017 16:13:18 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:41555 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751438AbdKVVNN (ORCPT ); Wed, 22 Nov 2017 16:13:13 -0500 Received: by mail-wm0-f67.google.com with SMTP id b189so12994807wmd.0 for ; Wed, 22 Nov 2017 13:13:12 -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=CfClp2AWIxqP9V2z+/Dn42TzdbC97wAwDYyPfbEa0lw=; b=UkTZ1dhqP6NLVMPz+4JMyzdEnj2f+Z1+D4TXMk8pazFqRCZIha4R+4fLZAk7CO0FeK xI45DpzNG4uDSe1d4PmuFtEDy5DvMBH7qRQKnzRpf4ovgjxb7+KxIiV2NjtwfELBI1ZF l9oPsOFCG3FS5HIcTdnkp1Xv6urnG9sTyClO5coQkxeH4x4b7FNYjrKhoaXnSX+oNp0g v5RoASlKXHkERg5lIr2M2QYEQ4AuWEMvcIfcIOJBm9Hs84iLWHg5/hHRRzjpg7kblGVM IEIW22TZaij8UxJeOlFp0eXX68RYYWzQE3FIINBc6TvXvjlxWzgtbWKcVWLi0guKMNgA wwZw== 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=CfClp2AWIxqP9V2z+/Dn42TzdbC97wAwDYyPfbEa0lw=; b=UV86LfaGfiOzQMWS3tDhKr+b163C84OLWQkzMUUQWWx93+gzdMUZj+TvfnbofzmrVG ao2SoTJQuNs2Nayz1Ap4GkI4YKK1xlzTENhCh/f2S+dnDZgpr077GLSNxD0DxNuTeI4B yl7Z6t4/gWFE2voIh5JFTxUuY5yISrv0ThfMaUVRs6EgMh1dHv/y8dEs+xhOJxbHxX3c G5bvfErMJwojk7i816wnu6zmu84lFkhbIOMPuSz8T5B3BmlPe+86uvh0cl4hyITOfbQv 5VnUtUdRSE9xgIRHLlxxUK/EMg8YTa+fMWhn+7wuZAdy/ebt9Yn74x/KDCgqU59VCZJw Df7g== X-Gm-Message-State: AJaThX5cc5nP3OZl3doRrkhYb8jiko3RjSu7dN5+DrtaWp0UHAQsEPSr 1Yu3pq2p5XKG7FmgjAMrJUaf3g== X-Google-Smtp-Source: AGs4zMYsxO+vAgsIm27VPTNQ4424SimP3P19eU4KNhPjXbZ12TgH2vi1R9gHhfrdNhT6UrMJtId4kg== X-Received: by 10.28.69.8 with SMTP id s8mr4601632wma.65.1511385192108; Wed, 22 Nov 2017 13:13:12 -0800 (PST) Received: from ?IPv6:2003:ea:8bc0:e400:58ac:8788:9665:db13? (p200300EA8BC0E40058AC87889665DB13.dip0.t-ipconnect.de. [2003:ea:8bc0:e400:58ac:8788:9665:db13]) by smtp.googlemail.com with ESMTPSA id m23sm3157805wmc.29.2017.11.22.13.13.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Nov 2017 13:13:11 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v4 5/7] eeprom: at24: add regmap-based read function To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: <0448eec2-7dfb-ca79-d03a-d5b7fcb5d76c@gmail.com> Message-ID: <011081f7-f2af-0e78-f21b-c40493d63a70@gmail.com> Date: Wed, 22 Nov 2017 22:12:57 +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: <0448eec2-7dfb-ca79-d03a-d5b7fcb5d76c@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 --- 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 493e2b646..c16a9a495 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) { @@ -531,7 +562,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); @@ -621,6 +652,27 @@ 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 0x90; + 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 BIT(11); + else if (flags & AT24_FLAG_SERIAL) + /* + * Otherwise the word address must begin with a '10' sequence, + * regardless of the intended address. + */ + return BIT(7); + else + return 0; +} + static const struct regmap_config regmap_config_8 = { .reg_bits = 8, .val_bits = 8, @@ -749,6 +801,8 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) return -EINVAL; } + at24->offset_adj = at24_get_offset_adj(chip.flags); + if (chip.flags & AT24_FLAG_SERIAL) { at24->read_func = at24_eeprom_read_serial; } else if (chip.flags & AT24_FLAG_MAC) { From patchwork Wed Nov 22 21:12: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: 840527 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="LU1c54fh"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yhwD34CbRz9rxm for ; Thu, 23 Nov 2017 08:13:23 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751967AbdKVVNV (ORCPT ); Wed, 22 Nov 2017 16:13:21 -0500 Received: from mail-wr0-f195.google.com ([209.85.128.195]:41422 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751704AbdKVVNP (ORCPT ); Wed, 22 Nov 2017 16:13:15 -0500 Received: by mail-wr0-f195.google.com with SMTP id z14so15789734wrb.8 for ; Wed, 22 Nov 2017 13:13:14 -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=D+jKD0CDs8REhabxAjoatfAXjbIANzTzsEqmkWdEu0M=; b=LU1c54fhXhjct/zZqgsGnO4GDXKCaUR3SdV0KuLVvRNSYFRGXXyH29Wp4SUt31208w thckWb6fBo8WhxHt6LiDsaiHy6Cuc4hGsx7lbTxGcz4zVnLtZWQBuHg3QavEtkKp60I2 00vB8Ntqf/pLwOKi6FmfFXh45yRKEPia0Xkdt4g1JGj8ozgY+69Wa2ZMTE72dwxMDpgq 2v3ohroKZU2L/n9bGVYSANjkKasKgiivFcA+xCIOE1oqB05L0v7NFnBDyXTPIAM+eMfR CZdPkiW78EHM4ICK/RQN/G0Nw6iXc7YvmDgjuCCeJFlZVTR5EWDhP6fCOSZDzZzhX6uW NQbw== 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=D+jKD0CDs8REhabxAjoatfAXjbIANzTzsEqmkWdEu0M=; b=iSeLJDoxk0f67p0QhVhq9aXlkf1+2/4qc7rCJ0yf2V0cCnq3gqP/Y7N5Cew8kYPtw6 sD2E5e6ENLDzz3r+Mh9KouV9Bfpp85a7o6pINtN08OnXmq/PWCUqQfuzkztd+3sH3ibS A4Gk8fSEn8ffI1axP7E/cgl5VlUuuQYdYmXVPzg0zrUDpRRaDUVq7GrHGOeDOETkLlS1 Qm8EVSLi3AeJOD8W8nEGIovcYg0Jwn1s0gVH9yeV8bAJg2uOXcKGyzhJtSBXlVJ8Dqco 51+Z2FkV88ucJ3OIqOk3fdiCmV3lA8hYvdwRNcESd99+JfXYMftwkRyXmNeskPBsZ9bS f92Q== X-Gm-Message-State: AJaThX6D/tk2Y2yNTJh2Lvy4lXvTMwCJvX8hB/KEsXW0GePfEGexvI/7 BZzLnfIUch07xdsTAeoJaxXOgg== X-Google-Smtp-Source: AGs4zMbZ3+oWec+nsZ5IQy3zYEt6HD2trfjDfK6HFTQj39XblGiAFsM6P34nQF4SLc06+gVZawvdtg== X-Received: by 10.223.130.47 with SMTP id 44mr17815496wrb.59.1511385193499; Wed, 22 Nov 2017 13:13:13 -0800 (PST) Received: from ?IPv6:2003:ea:8bc0:e400:58ac:8788:9665:db13? (p200300EA8BC0E40058AC87889665DB13.dip0.t-ipconnect.de. [2003:ea:8bc0:e400:58ac:8788:9665:db13]) by smtp.googlemail.com with ESMTPSA id h2sm13004604wrf.47.2017.11.22.13.13.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Nov 2017 13:13:13 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v4 6/7] eeprom: at24: remove old read functions To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: <0448eec2-7dfb-ca79-d03a-d5b7fcb5d76c@gmail.com> Message-ID: <6dd42b09-a5bb-a399-e91f-d36527960504@gmail.com> Date: Wed, 22 Nov 2017 22:12: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: <0448eec2-7dfb-ca79-d03a-d5b7fcb5d76c@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 --- 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 c16a9a495..c65169fdf 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 @@ -786,7 +611,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; @@ -803,15 +627,6 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) at24->offset_adj = at24_get_offset_adj(chip.flags); - 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 Wed Nov 22 21:13:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 840526 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="PK+ZmrFg"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yhwD26Z9lz9s4s for ; Thu, 23 Nov 2017 08:13:22 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751942AbdKVVNU (ORCPT ); Wed, 22 Nov 2017 16:13:20 -0500 Received: from mail-wr0-f196.google.com ([209.85.128.196]:41423 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751974AbdKVVNQ (ORCPT ); Wed, 22 Nov 2017 16:13:16 -0500 Received: by mail-wr0-f196.google.com with SMTP id z14so15789777wrb.8 for ; Wed, 22 Nov 2017 13:13:15 -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=9j4EQ9Tb1rTqr6zfLlzSLMeJeVcncSLk9lxJHGVo3rA=; b=PK+ZmrFgziJQ05Nf5y+5f8ckQdj8oMNrdX9T1lnQE8GRWsJcdqth/r+ZEWlAuwoYyN uO6cw9Qb8FZHAcgXTUDA4+EXqssp3/ITwbgmdFQHEEVQQqwi3wQTjvPWiKSIDw5wfP8Z ooxARGEaaAQFTadHtm8NNChblGUmabtCDTb8lhw/2YIVbn5x4qH1LV4yuoaxs82f7CCf Lkd+JXcEmeVwtzOS0+1LnMJmunG51Na+FBx7aq3AcTj0RwTT8jRRzB+KrhW6HVBShtsU vrZJCzK3lSWBHLfARYjhQxubMxPcn6kE8wMprRZBb+XvY+KRj30wf+2hevVXVz/+C+Tw X2ew== 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=9j4EQ9Tb1rTqr6zfLlzSLMeJeVcncSLk9lxJHGVo3rA=; b=e51/OdzTuIIgQcuqXTotQsj8Gkf8GKgh7nUE8uFB1XIauQfnfqTlLpgJdPH3UCvxFG GSqoNNvmDYbO4uCkVTIKwT0Qy+6SE4oP6aTBdUee86BG0x8Zf33SVQ3PEyYLWxEh0RO1 yAgBEETd5XSwGxLEa9B2HrwBFHbg7rW2VXar9cdy2zmFBQGMlxEcNEASo5vIbLNHDe66 3t490Z3jlYPCd1Srzy8FB0s9sGMrw5nT24aJNAAzKo6QNZwh0c4aGOCJEsBsUAx6VGJ8 IXm8bVGx/H7G50ldP7vulIT7W+cM0BGxWJiIXn8gnf+NQRMBXZsdsjI8QeBp8BWyhm3h OmVg== X-Gm-Message-State: AJaThX5wUfvh0GnOwmY0ILxn1LErPH+tuUAdBUyX9QjsG/gLEbyiiE85 ZUd/uKncaNlNVd/mSuSWyygERQ== X-Google-Smtp-Source: AGs4zMZS58SP+EZRB0SQJDdw1cmVxRYMVM+6blAjM9rgBpyZY6lRwCBKW9cacplpiRCOVM4aFMfLcQ== X-Received: by 10.223.160.230 with SMTP id n35mr840773wrn.116.1511385194729; Wed, 22 Nov 2017 13:13:14 -0800 (PST) Received: from ?IPv6:2003:ea:8bc0:e400:58ac:8788:9665:db13? (p200300EA8BC0E40058AC87889665DB13.dip0.t-ipconnect.de. [2003:ea:8bc0:e400:58ac:8788:9665:db13]) by smtp.googlemail.com with ESMTPSA id g84sm2813919wmf.26.2017.11.22.13.13.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Nov 2017 13:13:14 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v4 7/7] eeprom: at24: remove now unneeded smbus-related code To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: <0448eec2-7dfb-ca79-d03a-d5b7fcb5d76c@gmail.com> Message-ID: <8f1da8f7-859e-e3ab-f669-49ce977468da@gmail.com> Date: Wed, 22 Nov 2017 22:13:02 +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: <0448eec2-7dfb-ca79-d03a-d5b7fcb5d76c@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 --- drivers/misc/eeprom/at24.c | 52 ++++------------------------------------------ 1 file changed, 4 insertions(+), 48 deletions(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index c65169fdf..d80f36d70 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -513,8 +513,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; @@ -566,33 +564,10 @@ 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_I2C)) 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; + I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) chip.page_size = 1; - } - } if (chip.flags & AT24_FLAG_TAKE8ADDR) num_addresses = 8; @@ -628,21 +603,8 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) at24->offset_adj = at24_get_offset_adj(chip.flags); 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++) { @@ -703,12 +665,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)