From patchwork Wed Nov 22 07:02:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 840322 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="RCeIsBA3"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yhYQf1jm0z9s1h for ; Wed, 22 Nov 2017 18:06:18 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751207AbdKVHGQ (ORCPT ); Wed, 22 Nov 2017 02:06:16 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:42658 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751148AbdKVHGQ (ORCPT ); Wed, 22 Nov 2017 02:06:16 -0500 Received: by mail-wm0-f65.google.com with SMTP id l188so6249552wma.1 for ; Tue, 21 Nov 2017 23:06: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=iiIcrVI3nDYjsxUnissfFnftNirVxOVw0z2KBd8qI/M=; b=RCeIsBA3/I1Tlp63gA+9nKLP3NbUeqM3QZ8oIfBNVCbfyD6ZFF52D87pnmBJVmOqRp XvT59ZnQmbgblP7TWKIWyOo48j39WZMm17vWE68GE4bBIsw6fe6a7PTJwM9Bjr/4aaZo lcYIgEEHTlYOvwFIQLAUuuqnvBZc9FDmO9iBwJV/5kSBIGBZs2pjfeMPbfEjck5xV5NZ X/LwQuZZUfYoxU66aTk4QLMXB3QRhmvDUXvulWZlWMl6H6WsZcWKCHNqOEwFNNGUw7py jfQ49WPZ8PlJoapomv0jcmbMbxCGd6fnWJCN7ctDvdUpH3ogXCw/aAJFxD2rfdX5iHqe aCFw== 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=iiIcrVI3nDYjsxUnissfFnftNirVxOVw0z2KBd8qI/M=; b=hjXBxFome11V8xKMIqxHaiF9ftGLU9BD7akwlTLxs8iGwJ+jDDuEaTUhmcQ36DI2h3 ibo4iBara6oJ/0OZfcnzlIvSkm+mwsgSLVIyUNiW+lfElkqtxcHTsh/iMK4CxePltHmR +QHF6jBZJqv8Lo3YLiyrrhqO33YZHGTXiG/7G341SPdEKCJhyqjeM6XLaHuzOAVHmh3s HICDKOb+Ot1gz2yLDI4nWJ40KsXHJU32zFI3v7cuipN9Ho6uxAN3t1ns3l4ld9Abj7U/ MG8OE6fhg9+B6fA2r9Po0Rm58WtMor7yghclkYs740UDp0FwtbEhTB7l/NxdxwymtzHA qIlg== X-Gm-Message-State: AJaThX52MS7ehM8Pv8HBAFVx+GwX7AXaw4GGrglDoavYcMB3iVOiYHIW tNsLks45jTywfBRLzP/eeBT06SWrrs8= X-Google-Smtp-Source: AGs4zMarO7f4wRsWgFQoTmkV7r73PCNC5IDu0qlF8XVHoKtuwEmJ68VLBhkQ5YOpWb3Z/+HiSvjIiQ== X-Received: by 10.80.215.29 with SMTP id t29mr28324965edi.45.1511334374654; Tue, 21 Nov 2017 23:06:14 -0800 (PST) Received: from [192.168.178.85] (pD9F90FDA.dip0.t-ipconnect.de. [217.249.15.218]) by smtp.googlemail.com with ESMTPSA id h2sm9994325edf.39.2017.11.21.23.06.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Nov 2017 23:06:14 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v3 1/7] eeprom: at24: add basic regmap_i2c support To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: Message-ID: <706d90a9-781f-0bff-6aff-edfd57d59de1@gmail.com> Date: Wed, 22 Nov 2017 08:02:33 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org 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 --- 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 07:02:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 840323 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="gHYXObQt"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yhYQg271wz9s7g for ; Wed, 22 Nov 2017 18:06:19 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751258AbdKVHGS (ORCPT ); Wed, 22 Nov 2017 02:06:18 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:38597 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751148AbdKVHGR (ORCPT ); Wed, 22 Nov 2017 02:06:17 -0500 Received: by mail-wm0-f67.google.com with SMTP id 128so7931777wmo.3 for ; Tue, 21 Nov 2017 23:06:16 -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=zP0WvjTBkNR+BTBGubeJHNqMoGCqN8lpcE9LcogMn24=; b=gHYXObQtrgWOPW54fW5AtWIP0kunaG1nUqZM5Wccz/SwTQnGJbdZyAsIHB5z4RTcG2 hBh0ruTnWMJX9UOYmVGl4+hbb3Kl2EpQjtmJ+q4uMc7lXqsnzm+vDKCmQsdJdXTdGj3y yFPLDLsSQ0g79j3zI290utuUIOyqF9vyFE8pGMtGi2df8s/DPT0NFf0N3P2vFG0Xfr+/ RnXItUBi84tRQdXR7NeYHYtE23hM/58AO/vbOe8V0605OQ/AN+3Xv8PAxA9IWItW0qZY 7FhsV/eDHo5eB6A2CvvPVlzfzAovwJyYzeLBWuNG8U6q6LaOanyIz2mWLu3Ck8hVe3Ol WFHA== 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=zP0WvjTBkNR+BTBGubeJHNqMoGCqN8lpcE9LcogMn24=; b=M7oskxH1gioTI0VuynKKw2xWhAjUP864uqfFP+QsALvWMcsaqsN+TWeUXPjzaMLDYO 8/89E43knd9b8S5xoer4NlkhJE8JaNrn5oo8/akzFTYD8uImqrA4umMJKd3dIGsFBMlw 8cke6bCPh1BOCZHfQQEwaISoQQxlO4mkL67q/Nh7RC0zczjhV6gPzMvbDRaLNUuZn9Ya FpiRfbtZKpVbzHhBCqcSKDz+YElI3v9SDNEgTFv0MDxA2/L57XudHmTU118cHd97L+iL fH4HCqj3S1zquZS7zTo857ESw7l875RYcRFM5Y9ls8COv2jPAMeSH4Gc/YGkonbO+oTQ qKAQ== X-Gm-Message-State: AJaThX62NEmkM00X7S2jjUMfn0bXuyyHC6h0yhGKF9VA19M6kPobk1mr 4FTVYYDY3HEvVlPAQHtB3NeDisbkJJ8= X-Google-Smtp-Source: AGs4zMb5uT+0hsYmf83UZOUUVCz0gCbo8pAd9wHIuqRsmnu/Gby+vx/B2/+awNfCkt//93AjQaS/tA== X-Received: by 10.80.151.215 with SMTP id f23mr27991006edb.141.1511334375961; Tue, 21 Nov 2017 23:06:15 -0800 (PST) Received: from [192.168.178.85] (pD9F90FDA.dip0.t-ipconnect.de. [217.249.15.218]) by smtp.googlemail.com with ESMTPSA id s7sm11584897edm.80.2017.11.21.23.06.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Nov 2017 23:06:15 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v3 2/7] eeprom: at24: change at24_translate_offset return type To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: Message-ID: <86b7e7c1-9983-ed96-ca4a-e0091a815d8a@gmail.com> Date: Wed, 22 Nov 2017 08:02:47 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org 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 --- 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 07:02:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 840324 X-Patchwork-Delegate: bartekgola@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="S6PnsDf+"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yhYQh3nykz9s8J for ; Wed, 22 Nov 2017 18:06:20 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751148AbdKVHGT (ORCPT ); Wed, 22 Nov 2017 02:06:19 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:37872 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751216AbdKVHGS (ORCPT ); Wed, 22 Nov 2017 02:06:18 -0500 Received: by mail-wm0-f67.google.com with SMTP id v186so7936625wma.2 for ; Tue, 21 Nov 2017 23:06:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=tksBOi84IHbfCBNaMkElx26wHXi0CjLypBNSP7koDhw=; b=S6PnsDf+FzN+Q/Dv8XT5xy/Vi7LBq/txsqncsoTcrwFKo6n60csQEKCu8QVh6B/Ap6 HAQRP02cgsjfMTnyYlzP3JuIJEsBNK8dPoBy/0F7U/nzsn9L1hPE1mYfaYKapU9M0gBw Z+r7tGwjMQHiWXT87+xCXXWeExNqVPgIreFDh4UjyCnYgf+qf8NpL0gdcvYTr65pdGGO iHbFG+5ECdDudMhjH7atxMgHc736NDt/6MXlmIR8GUZTPPUGwCyeWspOczzvap9fa+dI EZXhPSYe8FsqIeSbk3EGnwBhpJJMGb/xSBpRPnoHQSVsfMhWufWbHd4BFAEW3X9hi7K5 ai8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=tksBOi84IHbfCBNaMkElx26wHXi0CjLypBNSP7koDhw=; b=kPT2H+/0+c43CCOxMY16rvTi9hmGgoPg+w3TSN1+rFe2GDuKzl5Ljdfl8oF+V0lENN KuBqNtM1TZ4487w6pTfcbMLxHocAuTIDgfKX87batTi2cnCRA5QC0+H3HTYHSOcGULFW ZYsBDC+I1HeFbm1IbwKNmuwBiq7gSXE41bDrWMNnhAIgysUXJr6dHcE/Eitao11W/Wum dPxngPGtUAFsl6tXWnfVzBudZwt2Eako8Wqtue29MWsbM3+ou+fSNccVUaRlCzHcPtJy sYyrC2yIq1fZSmKq/WoZJt2TeLvMvw6n7uBlp5880JfOpWQ6yJGjypfGAp/TL2KtgmoB JMeg== X-Gm-Message-State: AJaThX7BnN8huH39CBFWh846+UGBltXj8M8IJahQH8ImdEnKcpuE1dI6 5mxfL3f6ApYVL2leZM4voccCJDU2mCg= X-Google-Smtp-Source: AGs4zMYvwHdlx06jmal8iGWXYeUSoqva5wlC0RRs1Z1F2J2wSTRgBAA+KaudtcoqJnanSW13ffrsfw== X-Received: by 10.80.214.74 with SMTP id c10mr10215466edj.271.1511334377074; Tue, 21 Nov 2017 23:06:17 -0800 (PST) Received: from [192.168.178.85] (pD9F90FDA.dip0.t-ipconnect.de. [217.249.15.218]) by smtp.googlemail.com with ESMTPSA id p7sm10378285edj.5.2017.11.21.23.06.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Nov 2017 23:06:16 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v3 3/7] eeprom: at24: add regmap-based write function To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: Message-ID: Date: Wed, 22 Nov 2017 08:02:59 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Add a regmap-based write function. Signed-off-by: Heiner Kallweit --- v2: - rebased v3: - improve readability - re-introduce debug message --- drivers/misc/eeprom/at24.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index fe4393ad6..86a36482a 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -537,6 +537,31 @@ static ssize_t at24_eeprom_write_smbus_byte(struct at24_data *at24, return -ETIMEDOUT; } +static ssize_t at24_regmap_write(struct at24_data *at24, const char *buf, + unsigned int offset, size_t count) +{ + unsigned long timeout, write_time; + struct at24_client *at24_client; + struct i2c_client *client; + struct regmap *regmap; + int ret; + + at24_client = at24_translate_offset(at24, &offset); + regmap = at24_client->regmap; + client = at24_client->client; + count = at24_adjust_write_count(at24, offset, count); + + loop_until_timeout(timeout, write_time) { + ret = regmap_bulk_write(regmap, offset, buf, count); + dev_dbg(&client->dev, "write %zu@%d --> %d (%ld)\n", + count, offset, ret, jiffies); + if (!ret) + return count; + } + + return -ETIMEDOUT; +} + static ssize_t at24_eeprom_write_i2c(struct at24_data *at24, const char *buf, unsigned int offset, size_t count) { @@ -654,7 +679,7 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count) while (count) { int status; - status = at24->write_func(at24, buf, off, count); + status = at24_regmap_write(at24, buf, off, count); if (status < 0) { mutex_unlock(&at24->lock); pm_runtime_put(&client->dev); From patchwork Wed Nov 22 07:03:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 840325 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="ip7IaAo6"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yhYQj1M1yz9s9Y for ; Wed, 22 Nov 2017 18:06:21 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751357AbdKVHGU (ORCPT ); Wed, 22 Nov 2017 02:06:20 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:42664 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751293AbdKVHGT (ORCPT ); Wed, 22 Nov 2017 02:06:19 -0500 Received: by mail-wm0-f67.google.com with SMTP id l188so6249848wma.1 for ; Tue, 21 Nov 2017 23:06:19 -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=vFTNXByeoE9sc4Aeb7FUymVySIBVjFI/09K+WypyQ8M=; b=ip7IaAo6h74ebH75B71LAAl7UhDFyBiGaccJRBX0xxiGyBNDgjjxfzOjGL0kXJUjVm O6SRh7Y7fiuQ2W1lVF14sv4MqBDZKLgwuGzk81xSx0Snq5xj1YocMlmwlUmrYjd27pC/ NfPSInwAyHjkAh/D2TNQgLg+uXObGSxMg4wHEUDagm8u2CQuI9HAlRVsjwwnCiy/Hqk6 JWNeky8sQMc7rfcJgoptNdzwEOXgkdnpOIoDi3xkLqjVcZVGGnTxNm7w0IntwbK+f0KF xc8hjsRgVJqsrWPpIgeuS8gOyOaYaFRAZq4en6O0RgTFYz3pNqNn4iMgSYghL3ZNfT8P koVQ== 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=vFTNXByeoE9sc4Aeb7FUymVySIBVjFI/09K+WypyQ8M=; b=kmny9lgdg+p3KL1EjApPfbcnBnIrwBDnumQXN1JH9q2piuNtclWxvedEedQ6Mj64+q YpJYmBe7wIhPgENIsSykYKEhcTC0hEdSfrqh7rx++d8X/TEgVC1GF+jYncy3Q1Qq1Bjr mJhYpw+VwzTJKavx7mJ5x6TSHGQjPrYW1OOCk9fGFC6IrIK9LMBId+wBWNNF96GXST5R TPUt2I4b7tD05sJFzdqyJxQzorCbQOVx8/OcnE67MNZhb7j7aeuSYTg7MNhlTEG1zcjp uheyB04eLikAqZjeHhZ3RtexQpOifb+Uf2LuBbblCdm47Z5M4afD31vza2wiJIW0fgvc sCug== X-Gm-Message-State: AJaThX7a3PvDBDaZNu3pk4RctEwpVn07G+g7LYn5iJ9ZM/kjTOGX+Vkm wIKv06kCQnIiBhOMAyilKrxj8FmdwRY= X-Google-Smtp-Source: AGs4zMYBHD2q37SvKuL2rLunHX/kIPxRXAbOU6TeKwAVZsajX7NCGp/FHrrFQz5YZzmFUZDaojcsRw== X-Received: by 10.80.158.194 with SMTP id a60mr27149829edf.228.1511334378220; Tue, 21 Nov 2017 23:06:18 -0800 (PST) Received: from [192.168.178.85] (pD9F90FDA.dip0.t-ipconnect.de. [217.249.15.218]) by smtp.googlemail.com with ESMTPSA id h4sm2405441edb.16.2017.11.21.23.06.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Nov 2017 23:06:17 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v3 4/7] eeprom: at24: remove old write functions To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: Message-ID: <9ffe0f35-4e81-3424-02c6-fee44661006a@gmail.com> Date: Wed, 22 Nov 2017 08:03:06 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Remove the old and now unused write functions. Signed-off-by: Heiner Kallweit --- v2: - rebased v3: - rebased --- 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 07:05:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 840326 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="kk/+ujYu"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yhYQk0rJZz9s1h for ; Wed, 22 Nov 2017 18:06:22 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751293AbdKVHGV (ORCPT ); Wed, 22 Nov 2017 02:06:21 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:46772 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751216AbdKVHGU (ORCPT ); Wed, 22 Nov 2017 02:06:20 -0500 Received: by mail-wm0-f68.google.com with SMTP id u83so8054937wmb.5 for ; Tue, 21 Nov 2017 23:06:20 -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=5o82NuNWhZpzHnzcBgVkm1CNquA1mxq1simKWkBWKQ8=; b=kk/+ujYuh+79H8R84qYqIQdmFCxMTl2+MzFHg4JjxD/ruBKEelpgW4exN/CDnVw14m yB5dzNYOOZbPSGiA9asMEIsHDH38Q/nQO9xB8eMrDt04Bm4sza8hti4qto3bImBAK1cg 5JLdLzVuQ5YNcg04cWk3q77YJbauQ8TTOpM4KcyeOGV1y80sH/SuT/sFUyivWSzVAu3f 4zfsFa2E+heyjzSzoAAMyz+KqyEdPhORgZmL7W41dqRl9LGEVjeCXbqCo7XYl2EvQKfA xxtWYGSlEFVMkSLkzGwNW+9/qJW8TGrW3loUBwrahR+Y84ZdEGjFs0Rw62md0wsHyJXW UcCQ== 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=5o82NuNWhZpzHnzcBgVkm1CNquA1mxq1simKWkBWKQ8=; b=XHyjDCZP799arTYpv0RiaavToygX8A4LDZzqjAn42LY2r+hzAmVSlzPPPk/QHuT/BR uB90dxzimw7Xm1JbJcL0HQEH57cH1qHYeCndiMlFmtM6ErN/M+VyEWGnUYBmfikjYgRz Y4j2hSx/GuB+/uvRY+861rcIhgu9pN82MlpvQWre2NYspDbFz1AmDEccjerPGyJudIhf /HWe4KSfl69+1P95jtH0q+wjYntkCGhSAnZLX7n7rl08yYdWRm4D/v/Z1zL+6hpREUvA ujx0KzKSQJwxpCX+55EC297I1UgmYd9KKG86SX6ODtTq3gNHs1EfuzV8tZvh7tsDFpi4 auvw== X-Gm-Message-State: AJaThX78dsrHI3QSN+JoQh9wekIBHJ97wD8xbF4aGODdDA83JRL6wYRZ QRBKaJvvid2AYZzO1tFSnr/yFLCC6i4= X-Google-Smtp-Source: AGs4zMZrJPmF3EUqpk4JcbbZOCYeyV1UgQElfXTfxpB/pOiFpxTEJmrIm9kShzsgO9Rd9j5VYR1IvA== X-Received: by 10.80.145.81 with SMTP id f17mr28635719eda.215.1511334379378; Tue, 21 Nov 2017 23:06:19 -0800 (PST) Received: from [192.168.178.85] (pD9F90FDA.dip0.t-ipconnect.de. [217.249.15.218]) by smtp.googlemail.com with ESMTPSA id d9sm11705211edb.18.2017.11.21.23.06.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Nov 2017 23:06:19 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v3 5/7] eeprom: at24: add regmap-based read function To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: Message-ID: Date: Wed, 22 Nov 2017 08:05:58 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Add 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 --- drivers/misc/eeprom/at24.c | 53 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 493e2b646..589e6d855 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -312,6 +312,57 @@ static ssize_t at24_eeprom_read_smbus(struct at24_data *at24, char *buf, return -ETIMEDOUT; } +static void at24_adjust_read_offset(struct at24_data *at24, + unsigned int *offset) +{ + u8 flags = at24->chip.flags; + + if (flags & AT24_FLAG_MAC) + *offset += 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. + */ + *offset |= BIT(11); + else if (flags & AT24_FLAG_SERIAL) + /* + * Otherwise the word address must begin with a '10' sequence, + * regardless of the intended address. + */ + *offset |= BIT(7); +} + +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; + + at24_adjust_read_offset(at24, &offset); + + 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 +582,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); From patchwork Wed Nov 22 07:06:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 840327 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="oXtyzbqL"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yhYQl3DvNz9s1h for ; Wed, 22 Nov 2017 18:06:23 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751360AbdKVHGW (ORCPT ); Wed, 22 Nov 2017 02:06:22 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:38607 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751216AbdKVHGW (ORCPT ); Wed, 22 Nov 2017 02:06:22 -0500 Received: by mail-wm0-f65.google.com with SMTP id 128so7932083wmo.3 for ; Tue, 21 Nov 2017 23:06:21 -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=eXme6AzqfxymrLi40ymVbZYPiXBrYYfmXdqM5/Eziw0=; b=oXtyzbqLUa2THtPqE8ioJYY1kkmx6CpaLcFXFCqA60gBSIATMVAP0UyXphX+SkMTSx x7t1aiuStt8gP9blR7rtjKW5m4OaPRHLGMw6qMewgjW7T0UfCm1H1hfZstqeeGrfBgRI ccIh6ht3mCOvko/fAEzBlC1m7R24/S7DcgXi3KFGcKCQyGqEAVfM7YUxEuiCTSFKUvI+ 8/YQRIPdUk9BJAmFoOD0qcHPXZdF4rR5NF151gF0gJCEW8rQ/8Xlt2SRwgWWVlg6Xghs dhvOm75xtc8HujmR73/4nJszfOjfohJTIW2Nn1f6qUgX9QJG+uhQlln/akBmP96SY8Qe RIZQ== 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=eXme6AzqfxymrLi40ymVbZYPiXBrYYfmXdqM5/Eziw0=; b=DACTCfPj8VGLq62xmA7eydSDDYAAVTOt3gOLATLAq9WKFZngTFm2yEbucTzMQeRgI+ PkbRAMKDPvAwEET7DrKrSV1hyPCaqjIEOKbXRTwnBftpISefgNe9YAKjk+S5oatfHCuU LmU9n03jr5SjlMe2hgeSQ+ajSpt1Liedd7X5KMKEQpdANdvSFEbaKFVXxWfIlYfXdmjl IwyGk6C9QMY4gIPW0bDTOk7MDW8i8/xywrlUV3fylWViODIVJlBq/a5Ckyhf1wFC6gXo cACBrZWkEOD1/zv6W3ENbGx+THu1tcQY5D3PvSlWqSOuVcqUi0eHaQRh/Goofh7ByHGr 3gIg== X-Gm-Message-State: AJaThX6bFz2vrUVoaLXrw9t9Xr1R8ObRyVTyKAXqXW93PYqSfmF4CGzU piaOvSu+VHDvvjGK5ixdOi1ibh440mI= X-Google-Smtp-Source: AGs4zMbXzxBSYJgDGZoKGobZbq0Eu7TRqVmHORSxS6MIecsrdNmFiymsV+C0HJpK1JSYGJtuO/xllQ== X-Received: by 10.80.159.3 with SMTP id b3mr27114639edf.163.1511334380545; Tue, 21 Nov 2017 23:06:20 -0800 (PST) Received: from [192.168.178.85] (pD9F90FDA.dip0.t-ipconnect.de. [217.249.15.218]) by smtp.googlemail.com with ESMTPSA id d5sm5906848edj.65.2017.11.21.23.06.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Nov 2017 23:06:20 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v3 6/7] eeprom: at24: remove old read functions To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: Message-ID: <51f3e68c-fc54-df9f-71ba-2930adb68520@gmail.com> Date: Wed, 22 Nov 2017 08:06:04 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Remove the old and now unused read functions. Signed-off-by: Heiner Kallweit --- v2: - rebased v3: - 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 589e6d855..fa1dfd9c0 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, @@ -279,39 +276,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 void at24_adjust_read_offset(struct at24_data *at24, unsigned int *offset) { @@ -363,145 +327,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 @@ -785,7 +610,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; @@ -800,15 +624,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 Wed Nov 22 07:06:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 840328 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="vKCGwuEV"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yhYQm4Rbbz9s8J for ; Wed, 22 Nov 2017 18:06:24 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751216AbdKVHGX (ORCPT ); Wed, 22 Nov 2017 02:06:23 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:41981 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751371AbdKVHGX (ORCPT ); Wed, 22 Nov 2017 02:06:23 -0500 Received: by mail-wm0-f65.google.com with SMTP id b189so8028171wmd.0 for ; Tue, 21 Nov 2017 23:06:22 -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=Tjcdu08IA58iVsXmLLTHSk3UuPe3GW/jaungM2TsTSQ=; b=vKCGwuEVluxmNs7CmICRxwjy+AXy1wEtjGgnk4iPPFzGs31l2aXRvxk8ETVons0VkH xumaGxzJj4WcvCuOxLFQQ6yn4C2y+sS2vRidn3gIS1kU2FTo8re9zz1I2v/UNFsZ6u0c yHHLVVY80RoyBHmKyA3evTtwJAnaZXOpyNIObx+9MGWlIw15zhkhYOoQ+skes6hdWlve OihHoaCtgyVWSkQ81oaWKFd77vYevJ0BIlG2kB0lPGwzjgJOZ+B1DnxM0pmTidqhwD/D 8INe8nV05sZ/Btbybwdj/jUgYnGMsef4RsnJEFlTBLge67wbCTqVffdlfE837wDJpwQh LVgA== 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=Tjcdu08IA58iVsXmLLTHSk3UuPe3GW/jaungM2TsTSQ=; b=Nbm0T4L01TJ9xw78xmMbkLUjPeCcN2m46JXUUCbhHaAbQeqtPtZplluW2DR3pWcxbW QijyI7uWxJXuOpAFzI86Lt0NqiJCr9Jvze/s4Hu7qQwjoUNLTtucElbtH+HpDwHP1Bjh qxJl6vF3C5uQpCsGsEnIUPs0i7xQlIV2/fmzb5xgXZF7flyfyS/TNmnMWzYS9F6ihG8V QDHA3KSsD9IWQHryWgryVmMF5HVuITJ7PAc2BTbUrwuKjMyUQ4VfvTVsPozaLXQBoeoK wYFdjIynDUW5G8Az4S01PnOtIsDPO5eENCHtlWcc0aD7l0U/FSOggP31MsFtNl12mTNq cx+A== X-Gm-Message-State: AJaThX7v7wiao8fdS/C+88IAODcb7dXA720ctYBu8N9qYhF+B/sEWekm nUSRDGrKMKDZMSWlBgKfpsYamJ25Ygc= X-Google-Smtp-Source: AGs4zMZKsJp08Eva5jECCe1qxNmKEd2Sx0DChxIxtKR0QQigvXaZ4nNSlX/+vtSA/a2YpZ7O0A4Gsw== X-Received: by 10.80.181.70 with SMTP id z6mr28721271edd.201.1511334381861; Tue, 21 Nov 2017 23:06:21 -0800 (PST) Received: from [192.168.178.85] (pD9F90FDA.dip0.t-ipconnect.de. [217.249.15.218]) by smtp.googlemail.com with ESMTPSA id e46sm12002455edb.93.2017.11.21.23.06.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Nov 2017 23:06:21 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v3 7/7] eeprom: at24: remove now unneeded smbus-related code To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: Message-ID: Date: Wed, 22 Nov 2017 08:06:09 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Remove remaining now unneeded code dealing with SMBUS details. Signed-off-by: Heiner Kallweit --- v2: - rebased v3: - 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 fa1dfd9c0..fc20e610c 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -512,8 +512,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; @@ -565,33 +563,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; @@ -625,21 +600,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++) { @@ -700,12 +662,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)