From patchwork Thu Nov 16 20:25:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 838782 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="HHrRkPE0"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ydCTj6zHRz9rxm for ; Fri, 17 Nov 2017 07:27:21 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759016AbdKPU1U (ORCPT ); Thu, 16 Nov 2017 15:27:20 -0500 Received: from mail-wr0-f195.google.com ([209.85.128.195]:40764 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759008AbdKPU1T (ORCPT ); Thu, 16 Nov 2017 15:27:19 -0500 Received: by mail-wr0-f195.google.com with SMTP id p96so240193wrb.7 for ; Thu, 16 Nov 2017 12:27:18 -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=VondLYtRXytkZBNT0DptBu0LRqx4tIDOC7Q+W+or1y4=; b=HHrRkPE0rMepV1znsWDOP/UstpIyZdAtyNfFvUx/RRMje5lE4i/VDScaONHUIlrH26 qIGd9AC9SulWh/K9FOg4zwQ8vxfN10D49qNDnq0kCir7PJkOgt4mK0d1XVzi0fLH2+g1 ohkbV+31ymb7zWS/oPkD31CyWSN2JKookSDYIX8bFUw3+9zgu+MN1WBJQMH2VaA0um3H /R2y41IwXR9wjl+FHLNifNLoGq5oNE9oXd2dJpUYkwI+VPhh8/vEVM4yw9BjAHF2U8lG UKl1+TWcBtvDMwifWXQcZhPUzLeYJg+fKJU3t4Fiekh3fL6a/c7kkfWWqH0F07kutAFi 4oqw== 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=VondLYtRXytkZBNT0DptBu0LRqx4tIDOC7Q+W+or1y4=; b=VIOfZXIiJMyJ+cpYKyrdibgn+TN7Lbfugi0liur0FWPBYOjNO8ycqyGD0dFjegrY3L D5hc+QmJlA4K7Tj1wZdQXpq+Ete1OoWEYRl4vn7Li3hCdUbM/Zm/YR4qRwZYB16TSEfb ldZp/UX6cUNAruI3Z2hgB8FNA6SScHCj41COItmM0rMWa7zUWYx/NuPKv5+U2Q7oDq3S XvvV5jH/pXh9p2e0C30qWx6ddT/YL0+M34rdBgS0IdibCO89m4PosYfkDMlmpGJeeTLM s3tl1XDVhzq+RIZYu+z/6LTIJkRNttQsGsRcLM11LiJN5p4f76nKTcCswKCVH/OLcjiw Nc2g== X-Gm-Message-State: AJaThX6GzFfZzrEsekqRBL9brwAxtCUzWjNX12Zt2oQb+6mdczTK65Jc Yf8eS6IGUO7ny5S1ESYXbPsXig== X-Google-Smtp-Source: AGs4zMYrxRyvTGVpiJPizLRPJwtcF4Ddomg7UWbxgzrA1MUMMyZ9D+8ozIFl3wRuufAE3DB7gUzKtQ== X-Received: by 10.223.176.143 with SMTP id i15mr984478wra.240.1510864037471; Thu, 16 Nov 2017 12:27:17 -0800 (PST) Received: from ?IPv6:2003:ea:8bc0:e400:5d3b:3d3e:54b7:39d0? (p200300EA8BC0E4005D3B3D3E54B739D0.dip0.t-ipconnect.de. [2003:ea:8bc0:e400:5d3b:3d3e:54b7:39d0]) by smtp.googlemail.com with ESMTPSA id q13sm1236926wrg.97.2017.11.16.12.27.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Nov 2017 12:27:16 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v2 1/7] eeprom: at24: add basic regmap_i2c support To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: Message-ID: <451022fc-e20e-3539-e459-63d64598327d@gmail.com> Date: Thu, 16 Nov 2017 21:25:49 +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 --- 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 Thu Nov 16 20:26: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: 838783 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="YhD4TbJQ"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ydCTk7156z9s71 for ; Fri, 17 Nov 2017 07:27:22 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759036AbdKPU1V (ORCPT ); Thu, 16 Nov 2017 15:27:21 -0500 Received: from mail-wr0-f196.google.com ([209.85.128.196]:44241 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759003AbdKPU1U (ORCPT ); Thu, 16 Nov 2017 15:27:20 -0500 Received: by mail-wr0-f196.google.com with SMTP id l22so228715wrc.11 for ; Thu, 16 Nov 2017 12:27: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=g3Jr37gHypCsZQfPwNowOu+yJD/ujHcxumyaActrvgg=; b=YhD4TbJQlPltmEbTVhGvtJxf2UUAA6odIkDD/3zGSSbnZdRixS5QbUSab62XRmj+a8 ZhPfGjWqM1zfl7kdu/JSAVRUfgo2xGjY/tL2cGnZsYtcHo2Quz1J2OAQNaqfYT3trMcF Xa41WEPJXxvpv186pbM4zrCUFbmArMFpoCtIEctaEbgxPRzW1GzYqCGtDkO350nP+E6p saHRMEND0+qUpYFe2/iptpp0jFHo/walIbzopbZ8OU03K4M3Io3D6NYNU2v5u6kTZxLE TYKsNJpUjvEtTraFJW5S6NJ6NrqX5zw0cezrs2Br6S/ZeV9wN4fp4VvoHReHKLMtNMtM KUCw== 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=g3Jr37gHypCsZQfPwNowOu+yJD/ujHcxumyaActrvgg=; b=goCerC3Ufy4qQJttbekI0NsEPyO70S29CmnT6yL3NndNDBjOOej64v24ReHe3/XKyN iMOCyYMRveqZkoVu+Ek228yUpu1wNahYbyKUucb1uIMadMQFzYqQ4Qzy9veEajD2NIxg A4YWPJc9jQPiVqq42qOm8sf3D3IY/7Dn4Z2HjS+izFdG8XmxPzcpec8Qj4BezL/NMMgF QacnBvSLxl0jIcw6Hy9TH4LNP41AN/N0JRfXNrXSV41X7kaAP6b3hZDJiyXQ2jY38GQZ djgnOz+qf1xRxAm0Sz3DAA7RSFKpd8DmbKrFJzpxI7WdUlTlsXYT9MOm2akZOLqXyJ4i 2hWA== X-Gm-Message-State: AJaThX6zqPY9nv8yLLl6rpROdKW9uB3pycETzzOI00QoqNpBD2Qpm9Vt 5EnmPndKiRegROlpOh8mpa9/ow== X-Google-Smtp-Source: AGs4zMYKGTtLKwWl5JbtfePzLUaDNIYXO77ZjOleRg44/1yGj2dlYzyYYDEZ2t06ZN3+LO4dmMUk5w== X-Received: by 10.223.182.73 with SMTP id i9mr2636308wre.113.1510864038737; Thu, 16 Nov 2017 12:27:18 -0800 (PST) Received: from ?IPv6:2003:ea:8bc0:e400:5d3b:3d3e:54b7:39d0? (p200300EA8BC0E4005D3B3D3E54B739D0.dip0.t-ipconnect.de. [2003:ea:8bc0:e400:5d3b:3d3e:54b7:39d0]) by smtp.googlemail.com with ESMTPSA id 16sm1627797wrt.81.2017.11.16.12.27.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Nov 2017 12:27:18 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v2 2/7] eeprom: at24: change at24_translate_offset return type To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: Message-ID: <9b0019a9-f272-e345-d814-fcb05f978554@gmail.com> Date: Thu, 16 Nov 2017 21:26: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 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 --- drivers/misc/eeprom/at24.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 911cce8ec..1411fa029 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,7 +280,7 @@ 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, @@ -290,7 +290,7 @@ static ssize_t at24_eeprom_read_smbus(struct at24_data *at24, char *buf, struct i2c_client *client; int status; - client = at24_translate_offset(at24, &offset); + client = at24_translate_offset(at24, &offset)->client; if (count > io_limit) count = io_limit; @@ -324,7 +324,7 @@ static ssize_t at24_eeprom_read_i2c(struct at24_data *at24, char *buf, u8 msgbuf[2]; memset(msg, 0, sizeof(msg)); - client = at24_translate_offset(at24, &offset); + client = at24_translate_offset(at24, &offset)->client; if (count > io_limit) count = io_limit; @@ -373,7 +373,7 @@ static ssize_t at24_eeprom_read_serial(struct at24_data *at24, char *buf, u8 addrbuf[2]; int status; - client = at24_translate_offset(at24, &offset); + client = at24_translate_offset(at24, &offset)->client; memset(msg, 0, sizeof(msg)); msg[0].addr = client->addr; @@ -426,7 +426,7 @@ static ssize_t at24_eeprom_read_mac(struct at24_data *at24, char *buf, u8 addrbuf[2]; int status; - client = at24_translate_offset(at24, &offset); + client = at24_translate_offset(at24, &offset)->client; memset(msg, 0, sizeof(msg)); msg[0].addr = client->addr; @@ -481,7 +481,7 @@ static ssize_t at24_eeprom_write_smbus_block(struct at24_data *at24, struct i2c_client *client; ssize_t status = 0; - client = at24_translate_offset(at24, &offset); + client = at24_translate_offset(at24, &offset)->client; count = at24_adjust_write_count(at24, offset, count); loop_until_timeout(timeout, write_time) { @@ -508,7 +508,7 @@ static ssize_t at24_eeprom_write_smbus_byte(struct at24_data *at24, struct i2c_client *client; ssize_t status = 0; - client = at24_translate_offset(at24, &offset); + client = at24_translate_offset(at24, &offset)->client; loop_until_timeout(timeout, write_time) { status = i2c_smbus_write_byte_data(client, offset, buf[0]); @@ -534,7 +534,7 @@ static ssize_t at24_eeprom_write_i2c(struct at24_data *at24, const char *buf, ssize_t status = 0; int i = 0; - client = at24_translate_offset(at24, &offset); + client = at24_translate_offset(at24, &offset)->client; count = at24_adjust_write_count(at24, offset, count); msg.addr = client->addr; @@ -574,7 +574,7 @@ 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); + client = at24_translate_offset(at24, &off)->client; ret = pm_runtime_get_sync(&client->dev); if (ret < 0) { @@ -619,7 +619,7 @@ 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); + client = at24_translate_offset(at24, &off)->client; ret = pm_runtime_get_sync(&client->dev); if (ret < 0) { From patchwork Thu Nov 16 20:26:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 838784 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="LpimsnzH"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ydCTl5MJXz9rxm for ; Fri, 17 Nov 2017 07:27:23 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759040AbdKPU1W (ORCPT ); Thu, 16 Nov 2017 15:27:22 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:39199 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759008AbdKPU1V (ORCPT ); Thu, 16 Nov 2017 15:27:21 -0500 Received: by mail-wm0-f66.google.com with SMTP id l8so2558275wmg.4 for ; Thu, 16 Nov 2017 12:27: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=Xjl8gm8IOuc8azzQ7wKi6uJHUf8C/SIq9jBW9mCxfbU=; b=LpimsnzHPht7+D/CulYWAlhsXa0CyY0V58dspRwwS2ZosMf0y6nB8t+5lmTKCNWxFt y+VdE4taZp8rSG5VeM86xUAiJ/YT3vSqYTkqixTUnUNfDNyhoRxeNXYszZhbw06ySxg7 k/bEUpmkXNyER8FU9DelouEV1i1IqdMf8recljmVV57yd2HsMg4kqVLgA+X5wRiU1ful wFb59Ga4E4NWadAomrmisdhu9Do6F/FBB9I/1M6Y8M9PHmzIM2CcgWu9J7HAK9cV5GiZ Iqi2cmJri4aE58Qqc6YhCGOjcMoyj+75GL9wPfkwXn5n5lJ9y0uK+AG/+HeuVg7BNQOj O8Wg== 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=Xjl8gm8IOuc8azzQ7wKi6uJHUf8C/SIq9jBW9mCxfbU=; b=ftZAWh8+vHpTSetenHfYfenCMQFVayiqMJBvICrno/Yy0f7zZ+k0X526dGpSPM6e1f 1fnWm48sKFGCKx807h8NHRgVaZn3FxfWyUur0SMXZwIIQfcli4gLuuj90jIQ9FA8j24Q Xz+mKCmEg/RrL5AASWLfkvlyIglK5DrGinnga/0yybJ3QXTEcv9aFK/hCZaROCkaUZdf bsvKY6F0a6GfCi+JPa0N8RwyATr7SdHmmwYJuVZHTUE+EhujFeTtByAaPl/TF5UW/X5M 3N9tQsnfk/KrprQwIda2V2noeoGpT/Dwv/8zGhJBjIc564tWpIxdy92HPi1Bb+XFTk6R lIig== X-Gm-Message-State: AJaThX5h+ySt5cjgYuB46VQ4PXwt99pBQk/HWlhoS2yB/J9jzIDyAj1A fbvZ6YPgXXYc0cwiH1KL68YW5A== X-Google-Smtp-Source: AGs4zMakzxqFkmySE2FUUrvB5wxm2F0gcArujESlnZXLdHz8lBK+7/XSmG8KnnZmihJ2zDXT5oWbQA== X-Received: by 10.28.112.22 with SMTP id l22mr2340464wmc.35.1510864039974; Thu, 16 Nov 2017 12:27:19 -0800 (PST) Received: from ?IPv6:2003:ea:8bc0:e400:5d3b:3d3e:54b7:39d0? (p200300EA8BC0E4005D3B3D3E54B739D0.dip0.t-ipconnect.de. [2003:ea:8bc0:e400:5d3b:3d3e:54b7:39d0]) by smtp.googlemail.com with ESMTPSA id m37sm2467635wrm.4.2017.11.16.12.27.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Nov 2017 12:27:19 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v2 3/7] eeprom: at24: add regmap-based write function To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: Message-ID: Date: Thu, 16 Nov 2017 21:26:19 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: 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 --- drivers/misc/eeprom/at24.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 1411fa029..c0c59575e 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -525,6 +525,22 @@ 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 regmap *regmap; + + regmap = at24_translate_offset(at24, &offset)->regmap; + count = at24_adjust_write_count(at24, offset, count); + + loop_until_timeout(timeout, write_time) + if (!regmap_bulk_write(regmap, offset, buf, count)) + return count; + + return -ETIMEDOUT; +} + static ssize_t at24_eeprom_write_i2c(struct at24_data *at24, const char *buf, unsigned int offset, size_t count) { @@ -636,7 +652,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 Thu Nov 16 20:26: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: 838785 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="GwoYVbFj"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ydCTn1DK1z9rxm for ; Fri, 17 Nov 2017 07:27:25 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759045AbdKPU1X (ORCPT ); Thu, 16 Nov 2017 15:27:23 -0500 Received: from mail-wr0-f193.google.com ([209.85.128.193]:33761 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759005AbdKPU1W (ORCPT ); Thu, 16 Nov 2017 15:27:22 -0500 Received: by mail-wr0-f193.google.com with SMTP id 4so255831wrt.0 for ; Thu, 16 Nov 2017 12:27: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=Dqdhk1SZYBVHuSZ2x7D3QyA7oBGBIA2p0lzjj4sk4oY=; b=GwoYVbFj4KwXWvH5dLuI+snelCNlSbbeRofHEEvgPuc7YnBPjZ0gHeHhkW32HUfwj8 cd4IN/0W9jegmSUUFMz2XY9T3M8x+N5t45vLeosRLMx5zqpi9uO18vQ6wBjRFkILjSkm XNQLi+kABAxpKUe7MTdzdDglr4/bAW9Xru8+yRtmz2V+FHLcu7hYvzbTtRkaXdV8i8fi FetJw3AspyS/K1JgeNPeixQ8teX1FkCVTl+ZsNxKQ1l54l4phvV1H4mliDT9zKsm6LFR AjC/M/3Qyc7tQ9Kh5t5v/2e/X52SK6LP4YP8Pa2yHG0zlxbgT3THK6EEAyRizuOmklTP 1j/A== 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=Dqdhk1SZYBVHuSZ2x7D3QyA7oBGBIA2p0lzjj4sk4oY=; b=ivKjz5/TWL/K2CMkpZ0ljxnjq6geHeWLjwhWKN71YOPlzke6asPqwhhGIqIAwsUrW8 xfdArJ5NH9BTcPNGc5COS4TN4SXTyoLGrCVXaKyR/zWDEnJacekmW9zS/mcObeWrf/8y guTEZO1w/VOhRIFv5fJ8IrDRA8T3W+5Mnx5yi0yhg5T9lMR3pNfAD890TiF1d4Hmslnk GNoEASwyfad4FB+YwAW+PShYCUbUSVOoJvLZ2DYPA/8zqSm3sq12s1uEB0WQLS0TAew/ nSh8NN4vo1ieuBbRkx7qYAkRc47+9lDIyRfNu6sErJKzJ5gwxCG22M5F8UrfMmFgToEA Cedw== X-Gm-Message-State: AJaThX4ko4olxEokic8uiEojTrO3b7DYUPk32N6djpVXCDO9vCTzW9An lMlIdeXk1rl/DCwG3EVWcAhTRg== X-Google-Smtp-Source: AGs4zMYPe8h2QXBO6EMQCOJmJXBYcN6R7n3bnsevXZjg+4uyR5CgNwrJdffnKiuyC6qK9snTfIMCYg== X-Received: by 10.223.160.86 with SMTP id l22mr2501386wrl.187.1510864041191; Thu, 16 Nov 2017 12:27:21 -0800 (PST) Received: from ?IPv6:2003:ea:8bc0:e400:5d3b:3d3e:54b7:39d0? (p200300EA8BC0E4005D3B3D3E54B739D0.dip0.t-ipconnect.de. [2003:ea:8bc0:e400:5d3b:3d3e:54b7:39d0]) by smtp.googlemail.com with ESMTPSA id c54sm3117753wra.84.2017.11.16.12.27.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Nov 2017 12:27:20 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v2 4/7] eeprom: at24: remove old write functions To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: Message-ID: Date: Thu, 16 Nov 2017 21:26: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 Remove the old and now unused write functions. Signed-off-by: Heiner Kallweit --- v2: - rebased --- drivers/misc/eeprom/at24.c | 111 --------------------------------------------- 1 file changed, 111 deletions(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index c0c59575e..28ea1a950 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; @@ -473,58 +469,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 i2c_client *client; - ssize_t status = 0; - - client = at24_translate_offset(at24, &offset)->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 i2c_client *client; - ssize_t status = 0; - - client = at24_translate_offset(at24, &offset)->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) { @@ -541,45 +485,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 i2c_client *client; - struct i2c_msg msg; - ssize_t status = 0; - int i = 0; - - client = at24_translate_offset(at24, &offset)->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; @@ -809,7 +714,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; @@ -833,15 +737,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) { @@ -853,12 +748,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 Thu Nov 16 20:26:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 838786 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="rm+MwP5P"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ydCTp3K4bz9rxm for ; Fri, 17 Nov 2017 07:27:26 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759052AbdKPU1Z (ORCPT ); Thu, 16 Nov 2017 15:27:25 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:43523 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759041AbdKPU1X (ORCPT ); Thu, 16 Nov 2017 15:27:23 -0500 Received: by mail-wm0-f66.google.com with SMTP id x63so2620132wmf.2 for ; Thu, 16 Nov 2017 12:27:23 -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=uVF/159J/rYezfhZokuTyeLNYYHLVGvTNAzComI3Bpk=; b=rm+MwP5PjUchNRowYV6yn48CdSNJIzcSeWH19FghnLWtNMXYz/l/UWDQQcU1aN7L/T gIdtT1WWzEXes7wTuhj9GNMDfr61hHQ6y9a4/O4FyLJpRgsVXFeF1zCDQ83MajGHCMGU L5MhXpOISfW8On1wbJwsHjccfv1s8PcPpRGnCk0FA6ki3ryp9KoWj6A6MP7MFmQOfxZ3 uwOgOccFCI07V3RqGjz+tC5v6tFQWcOMlFCoXHyWJbRZK69TCX74YsHyts0pIhdTh6k0 qSkbe74l+2rEcG0gp9srzMA5Vg2IMTVswLGavj8+0tkdFw3uupYhXwbnbytoUO2lDTWr 3r6Q== 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=uVF/159J/rYezfhZokuTyeLNYYHLVGvTNAzComI3Bpk=; b=qugl1yOzCeGJSYIsY/i5npASeTSGIa7VhVUEKFQofhiDhwPuX7O5NiOHgZzcEXv4mY BvhFX2XKKR9mtcGvzJg5eaQnX+nN1P0slESSsyZayfSJ11sGWzGiHERYDkfh1JbNTX8m VjZTeDIaFE+vc6wNaNkRwFOgAPt5J6M30tlOp7EAFJkFNvpV/K2EkybIM1w6h4e1CbXo Q5U3ontpTIVf6i0QkETEhCFQzdbDJPDK9YgJqD+m7hWbkToZWGrrGK9wYW6gJmU4ME9u dUXozW71wLtDRgeggRulAPr+JI/YGhKjBcSRlFpqi+rCec3si9nm0lXP+hlhLrfZoOLN 76GA== X-Gm-Message-State: AJaThX7RjWJ/Jcaw6Aogfcj76BYm0yLW6J5+xk7G93xsWgX9nMxTxcXC I59SA75rb8FJXOO8vLqZBoZVbQ== X-Google-Smtp-Source: AGs4zMZzvxt3iAnQ4/R3hsp6TsnpGTBolma+KABU552YV22saZ+Dd0vvcInlr/5zcoiAWwVAI6AlDA== X-Received: by 10.28.230.140 with SMTP id e12mr2282884wmi.118.1510864042502; Thu, 16 Nov 2017 12:27:22 -0800 (PST) Received: from ?IPv6:2003:ea:8bc0:e400:5d3b:3d3e:54b7:39d0? (p200300EA8BC0E4005D3B3D3E54B739D0.dip0.t-ipconnect.de. [2003:ea:8bc0:e400:5d3b:3d3e:54b7:39d0]) by smtp.googlemail.com with ESMTPSA id z192sm1284074wmc.32.2017.11.16.12.27.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Nov 2017 12:27:22 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v2 5/7] eeprom: at24: add regmap-based read functions To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: Message-ID: <055dce44-43fb-c90f-6e94-ca8035b16832@gmail.com> Date: Thu, 16 Nov 2017 21:26:44 +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 functions. Signed-off-by: Heiner Kallweit --- v2: - rebased --- drivers/misc/eeprom/at24.c | 58 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 28ea1a950..391e0d998 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -310,6 +310,59 @@ 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 regmap *regmap; + + regmap = at24_translate_offset(at24, &offset)->regmap; + + if (count > io_limit) + count = io_limit; + + if (at24->chip.flags & AT24_FLAG_MAC) + offset += 0x90; + + loop_until_timeout(timeout, read_time) + if (!regmap_bulk_read(regmap, offset, buf, count)) + return count; + + return -ETIMEDOUT; +} + +static ssize_t at24_regmap_read_serial(struct at24_data *at24, char *buf, + unsigned int offset, size_t count) +{ + unsigned long timeout, read_time; + struct regmap *regmap; + + regmap = at24_translate_offset(at24, &offset)->regmap; + + if (count > io_limit) + count = io_limit; + + 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. + */ + offset |= BIT(11); + else + /* + * Otherwise the word address must begin with a '10' sequence, + * regardless of the intended address. + */ + offset |= BIT(7); + + loop_until_timeout(timeout, read_time) + if (!regmap_bulk_read(regmap, offset, buf, count)) + return count; + + return -ETIMEDOUT; +} + static ssize_t at24_eeprom_read_i2c(struct at24_data *at24, char *buf, unsigned int offset, size_t count) { @@ -512,7 +565,10 @@ 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); + if (at24->chip.flags & AT24_FLAG_SERIAL) + status = at24_regmap_read_serial(at24, buf, off, count); + else + status = at24_regmap_read(at24, buf, off, count); if (status < 0) { mutex_unlock(&at24->lock); pm_runtime_put(&client->dev); From patchwork Thu Nov 16 20:26: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: 838787 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="j8pXfCqI"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ydCTr55Jsz9rxm for ; Fri, 17 Nov 2017 07:27:28 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759003AbdKPU11 (ORCPT ); Thu, 16 Nov 2017 15:27:27 -0500 Received: from mail-wr0-f195.google.com ([209.85.128.195]:37783 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759050AbdKPU1Z (ORCPT ); Thu, 16 Nov 2017 15:27:25 -0500 Received: by mail-wr0-f195.google.com with SMTP id k61so244942wrc.4 for ; Thu, 16 Nov 2017 12:27:24 -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=z23vUIsCiZKxmXeURCR2YkoGpZL6MKMT3DC/FVqf7kk=; b=j8pXfCqIcNuySj1yq88Qg141x2qniU9F7pCSzdM5vSCniQkfgtFDT5k3JMjUVpn/dO A+ln2LxyIxJu7hyYBPzH2dKledEH2nICqBA4QyyoPlpgQfXQu2f54vEMNo91Q6M9C0yl QhCgHhmItCibdXvPViDjP6//CHuzdRVZGEnq6Gq7LSNI1MQ6mTPHzDyqWEMMN65HvXVO gRSL9AAGnJqmbUdHCCx6bsieVZdb/os6cNP50HRZX+HtqdHcPDc3AaR2pQlbWDcQ1CzG jYtccT5EqvQCzt6gF8PKUfX7wxpJLbEa0YWm1Fj81xguGtMebMVGDMFkkGmITaUqnGxB YvaA== 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=z23vUIsCiZKxmXeURCR2YkoGpZL6MKMT3DC/FVqf7kk=; b=AUgNkbmKQ7GybGoNqu8jznIXRGCHrysHEPwLpNMkXhorIky4axmLnHVkJRY7vfwu9h QnzSJX3kj3mswZ8lzWX3Ai/nYVo8yZZXc5ZHH7sNFRd/6mpzhJKpazhmJK9xzKpVVejy T5PTQ5Ehr2i42fLBW2Yntc/Y3Xd6FR8Lt34lVp83lYvn2TqoX9KAU+H+mT2iRfYJLpqv 5W3UYaEwha/Jy8k3IgcyDGi8ocoeo2BmU53J8Xxz6z5bTir81J1aQPDasvoyrJGTwU// 79rAXwVucwbyLMw/3BkYgcGC6fp8VzH7SkA2rXOJaydyqmXZXOtnG7/S2b7N0ilsQY9c 8hRA== X-Gm-Message-State: AJaThX62d0HfBjjW9pgNjhMhIWEv1X6Uy7DNrFGZ+RjcO5ccxi/ap0sS KJXqJM88b4T0JhkI+AwLwlfcEw== X-Google-Smtp-Source: AGs4zMZJLty01jISqTempM88EDOIZpgPugkqTY8bKTBl8jooKEWFsAr/5nMy4YrcfAPh7qLq80+/AQ== X-Received: by 10.223.179.194 with SMTP id x2mr2568596wrd.266.1510864043869; Thu, 16 Nov 2017 12:27:23 -0800 (PST) Received: from ?IPv6:2003:ea:8bc0:e400:5d3b:3d3e:54b7:39d0? (p200300EA8BC0E4005D3B3D3E54B739D0.dip0.t-ipconnect.de. [2003:ea:8bc0:e400:5d3b:3d3e:54b7:39d0]) by smtp.googlemail.com with ESMTPSA id z108sm3357616wrb.67.2017.11.16.12.27.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Nov 2017 12:27:23 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v2 6/7] eeprom: at24: eeprom: at24: remove old read functions To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: Message-ID: Date: Thu, 16 Nov 2017 21:26: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: 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 --- drivers/misc/eeprom/at24.c | 177 --------------------------------------------- 1 file changed, 177 deletions(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 391e0d998..a4e157b6b 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,37 +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 i2c_client *client; - int status; - - client = at24_translate_offset(at24, &offset)->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) { @@ -363,139 +329,6 @@ static ssize_t at24_regmap_read_serial(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 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)->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 i2c_client *client; - struct i2c_msg msg[2]; - u8 addrbuf[2]; - int status; - - client = at24_translate_offset(at24, &offset)->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 i2c_client *client; - struct i2c_msg msg[2]; - u8 addrbuf[2]; - int status; - - client = at24_translate_offset(at24, &offset)->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 @@ -769,7 +602,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; @@ -784,15 +616,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 Thu Nov 16 20:27:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 838788 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="S0Cwq/dH"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ydCTs3XVsz9s71 for ; Fri, 17 Nov 2017 07:27:29 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759059AbdKPU11 (ORCPT ); Thu, 16 Nov 2017 15:27:27 -0500 Received: from mail-wr0-f193.google.com ([209.85.128.193]:39873 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759056AbdKPU10 (ORCPT ); Thu, 16 Nov 2017 15:27:26 -0500 Received: by mail-wr0-f193.google.com with SMTP id o88so240040wrb.6 for ; Thu, 16 Nov 2017 12:27:25 -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=XG5XIe2bdknGjZLF0Ikah4CaixM3o9hX+Tniiey85QQ=; b=S0Cwq/dHRF4RJz4s1FKy4yg/DIfMBb3xVia4/ZnlmU78ffjPdYlge993q1dYQ6rAjW 2EEs75geuuoz9DDGX7P1ezg3xqA/3ZwNkflKMfZ/WMqvu0UtocZZGdXp9lrWJiSrtxa/ l8uusGuSdf1vBuMOOuDzwBW2Y9yIMVqCL1QnkEY5nuXD2DIp3gkNFdb4wPTS+wU4mVvj SOJoT13A4hv5j6UxoizjZtfHjlV2VvlhAFUPm0Jtsvt4usIGmBNV8xRc+zXf6hWCbSRZ 4ejEiyMsCcpET3ixvmH4qlLsZSvV9w8EaSHwGYq93DlqE30RndxfuHnqXKDO6T7BNBLI 0CnQ== 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=XG5XIe2bdknGjZLF0Ikah4CaixM3o9hX+Tniiey85QQ=; b=UZPGZ39gVwppFEAPfxJWZdzCPPAdf1PMl12iEq6OrC6gBuhg2D0phcHT35GOLBOpgx mr0rx2QIjUKgFW8Z6ZkRANZFraK1cat+pWGXMyvbZWqgGuu40gANRKOFWZNhMwRA4u/q SOMRqEThOHlYySKuGds2BTUaguElx1ffblU1JkiS2Gt2ZbigibKnQvaFy7PfPDpNYXHV 0zXInwrBIa9UdY8gwyUOjIxUQNLQ6VH1lbpEjlubDdUsSlvaKRnU/Y2w5CfeTWt9xT10 Q4++KMFSGFw+cnOWKLeTAvBfb3CamKB0ACa8TwQcDRJGbBdrcHll7MrsPqOLxiMY+8uX ZAVg== X-Gm-Message-State: AJaThX5tMUlBVf7QZbn/B3Ise2WTjK+js5DXgu4ZRc/SJly8uKmNpAxP BthfU0BrE2RnlT3UtL5EnRGWPA== X-Google-Smtp-Source: AGs4zMbjRRKhiCCdAYtZP/JYxZgheGOkTNYh6cE5f9M2HbkEn/exsFNSAxA4W+VDTDB7Qsy5PPrh1Q== X-Received: by 10.223.177.220 with SMTP id r28mr2450821wra.83.1510864045109; Thu, 16 Nov 2017 12:27:25 -0800 (PST) Received: from ?IPv6:2003:ea:8bc0:e400:5d3b:3d3e:54b7:39d0? (p200300EA8BC0E4005D3B3D3E54B739D0.dip0.t-ipconnect.de. [2003:ea:8bc0:e400:5d3b:3d3e:54b7:39d0]) by smtp.googlemail.com with ESMTPSA id p81sm1842382wrc.61.2017.11.16.12.27.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Nov 2017 12:27:24 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v2 7/7] eeprom: at24: remove now unneeded smbus-related code To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: Message-ID: Date: Thu, 16 Nov 2017 21:27:11 +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 --- 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 a4e157b6b..89eaa85b1 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -504,8 +504,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; @@ -557,33 +555,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; @@ -617,21 +592,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++) { @@ -692,12 +654,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)