From patchwork Sun Apr 24 19:28:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 66533 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp696307qge; Sun, 24 Apr 2016 12:28:47 -0700 (PDT) X-Received: by 10.98.95.4 with SMTP id t4mr43350519pfb.100.1461526123238; Sun, 24 Apr 2016 12:28:43 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id xk1si1742754pab.132.2016.04.24.12.28.43; Sun, 24 Apr 2016 12:28:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-i2c-owner@vger.kernel.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752608AbcDXT2k (ORCPT + 1 other); Sun, 24 Apr 2016 15:28:40 -0400 Received: from mail-wm0-f54.google.com ([74.125.82.54]:37816 "EHLO mail-wm0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751170AbcDXT2g (ORCPT ); Sun, 24 Apr 2016 15:28:36 -0400 Received: by mail-wm0-f54.google.com with SMTP id n3so97907032wmn.0 for ; Sun, 24 Apr 2016 12:28:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PQP5th4TJhlT61/zsj5Z0V9qhQkYjVM7jhkBg3Q958k=; b=Jx6bxOMtDEnKV1IC0LEN97I7kPj3BzCcPrw2LxxfkS1gMWxSFtM2DPFc9SMc9EA9l+ 2wk2RSAc/qOJCtCF/J3sA0to2wAQSasNtUg2XqfNqNscRgYrIlyY+12EAwVeon+rjMxX FqLcBzfpqoZwuUNCulwASdjrWRjNgXktYstlM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PQP5th4TJhlT61/zsj5Z0V9qhQkYjVM7jhkBg3Q958k=; b=P4BKd9OxA7YOg8lgXVfho9prb/rj0WCaRqRxoJRNqmC2gazKFr54GtaImBuP+3OOj8 tgioiVal5RMpVuBKqaixOBUPhCgdXwtpl02m3NK3IfDff76BcBQQwWWrO6A6x4sde3vy 5Om0bj4PeAVQHrg+zDUXVF4JqH8LYyLOqgT+rBgqH2u+SasnmmTSJBDms+L/cWAmsu1Y T6exAnVNmNF/SZz1J/eGC9QManqVvVuYUQ25W9joXYlCzU6IVW5lYON2EFA9Uai2+WqE kcbf0XTjHIV8imq9DdN8ZLu2rdd1WSUHeLR+7w6a3phafmeOwrXwAch51masZgeXPqeU 5PYg== X-Gm-Message-State: AOPr4FWOrMxhhBKLFzGq+Mxvu9N2iICRGHugg6kfl901Nubom56B3Le3MXmIZhqI5dU71B4B X-Received: by 10.28.214.137 with SMTP id n131mr8123273wmg.33.1461526114887; Sun, 24 Apr 2016 12:28:34 -0700 (PDT) Received: from localhost.localdomain (host-92-17-247-99.as13285.net. [92.17.247.99]) by smtp.gmail.com with ESMTPSA id q127sm15007708wmd.13.2016.04.24.12.28.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 24 Apr 2016 12:28:34 -0700 (PDT) From: Srinivas Kandagatla To: Greg Kroah-Hartman Cc: Wolfram Sang , Srinivas Kandagatla , Maxime Ripard , Joachim Eastwood , Matthias Brugger , Heiko Stuebner , Chen-Yu Tsai , linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, Mark Brown , andrew@lunn.ch Subject: [PATCH 02/12] eeprom: at24: remove nvmem regmap dependency Date: Sun, 24 Apr 2016 20:28:06 +0100 Message-Id: <1461526096-29584-3-git-send-email-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1461526096-29584-1-git-send-email-srinivas.kandagatla@linaro.org> References: <1461526096-29584-1-git-send-email-srinivas.kandagatla@linaro.org> Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org This patch moves to nvmem support in the driver to use callback instead of regmap. Signed-off-by: Srinivas Kandagatla --- drivers/misc/eeprom/Kconfig | 1 - drivers/misc/eeprom/at24.c | 103 ++++++++++---------------------------------- 2 files changed, 22 insertions(+), 82 deletions(-) -- 2.5.0 -- To unsubscribe from this list: send the line "unsubscribe linux-i2c" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/misc/eeprom/Kconfig b/drivers/misc/eeprom/Kconfig index cfc493c..2d70464 100644 --- a/drivers/misc/eeprom/Kconfig +++ b/drivers/misc/eeprom/Kconfig @@ -3,7 +3,6 @@ menu "EEPROM support" config EEPROM_AT24 tristate "I2C EEPROMs / RAMs / ROMs from most vendors" depends on I2C && SYSFS - select REGMAP select NVMEM help Enable this driver to get read/write support to most I2C EEPROMs diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 089d694..de550a6 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -23,7 +23,6 @@ #include #include #include -#include #include /* @@ -69,7 +68,6 @@ struct at24_data { unsigned write_max; unsigned num_addresses; - struct regmap_config regmap_config; struct nvmem_config nvmem_config; struct nvmem_device *nvmem; @@ -252,10 +250,10 @@ static ssize_t at24_eeprom_read(struct at24_data *at24, char *buf, return -ETIMEDOUT; } -static ssize_t at24_read(struct at24_data *at24, - char *buf, loff_t off, size_t count) +static int at24_read(void *priv, unsigned int off, void *val, size_t count) { - ssize_t retval = 0; + struct at24_data *at24 = priv; + char *buf = val; if (unlikely(!count)) return count; @@ -267,23 +265,21 @@ static ssize_t at24_read(struct at24_data *at24, mutex_lock(&at24->lock); while (count) { - ssize_t status; + int status; status = at24_eeprom_read(at24, buf, off, count); - if (status <= 0) { - if (retval == 0) - retval = status; - break; + if (status < 0) { + mutex_unlock(&at24->lock); + return status; } buf += status; off += status; count -= status; - retval += status; } mutex_unlock(&at24->lock); - return retval; + return 0; } /* @@ -372,13 +368,13 @@ static ssize_t at24_eeprom_write(struct at24_data *at24, const char *buf, return -ETIMEDOUT; } -static ssize_t at24_write(struct at24_data *at24, const char *buf, loff_t off, - size_t count) +static int at24_write(void *priv, unsigned int off, void *val, size_t count) { - ssize_t retval = 0; + struct at24_data *at24 = priv; + char *buf = val; if (unlikely(!count)) - return count; + return -EINVAL; /* * Write data to chip, protecting against concurrent updates @@ -387,70 +383,23 @@ static ssize_t at24_write(struct at24_data *at24, const char *buf, loff_t off, mutex_lock(&at24->lock); while (count) { - ssize_t status; + int status; status = at24_eeprom_write(at24, buf, off, count); - if (status <= 0) { - if (retval == 0) - retval = status; - break; + if (status < 0) { + mutex_unlock(&at24->lock); + return status; } buf += status; off += status; count -= status; - retval += status; } mutex_unlock(&at24->lock); - return retval; -} - -/*-------------------------------------------------------------------------*/ - -/* - * Provide a regmap interface, which is registered with the NVMEM - * framework -*/ -static int at24_regmap_read(void *context, const void *reg, size_t reg_size, - void *val, size_t val_size) -{ - struct at24_data *at24 = context; - off_t offset = *(u32 *)reg; - int err; - - err = at24_read(at24, val, offset, val_size); - if (err) - return err; - return 0; -} - -static int at24_regmap_write(void *context, const void *data, size_t count) -{ - struct at24_data *at24 = context; - const char *buf; - u32 offset; - size_t len; - int err; - - memcpy(&offset, data, sizeof(offset)); - buf = (const char *)data + sizeof(offset); - len = count - sizeof(offset); - - err = at24_write(at24, buf, offset, len); - if (err) - return err; return 0; } -static const struct regmap_bus at24_regmap_bus = { - .read = at24_regmap_read, - .write = at24_regmap_write, - .reg_format_endian_default = REGMAP_ENDIAN_NATIVE, -}; - -/*-------------------------------------------------------------------------*/ - #ifdef CONFIG_OF static void at24_get_ofdata(struct i2c_client *client, struct at24_platform_data *chip) @@ -482,7 +431,6 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) struct at24_data *at24; int err; unsigned i, num_addresses; - struct regmap *regmap; if (client->dev.platform_data) { chip = *(struct at24_platform_data *)client->dev.platform_data; @@ -612,19 +560,6 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) } } - at24->regmap_config.reg_bits = 32; - at24->regmap_config.val_bits = 8; - at24->regmap_config.reg_stride = 1; - at24->regmap_config.max_register = chip.byte_len - 1; - - regmap = devm_regmap_init(&client->dev, &at24_regmap_bus, at24, - &at24->regmap_config); - if (IS_ERR(regmap)) { - dev_err(&client->dev, "regmap init failed\n"); - err = PTR_ERR(regmap); - goto err_clients; - } - at24->nvmem_config.name = dev_name(&client->dev); at24->nvmem_config.dev = &client->dev; at24->nvmem_config.read_only = !writable; @@ -632,6 +567,12 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) at24->nvmem_config.owner = THIS_MODULE; at24->nvmem_config.compat = true; at24->nvmem_config.base_dev = &client->dev; + at24->nvmem_config.reg_read = at24_read; + at24->nvmem_config.reg_write = at24_write; + at24->nvmem_config.priv = at24; + at24->nvmem_config.stride = 4; + at24->nvmem_config.word_size = 1; + at24->nvmem_config.size = chip.byte_len; at24->nvmem = nvmem_register(&at24->nvmem_config);