From patchwork Sun Apr 24 19:28:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 66538 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp696540qge; Sun, 24 Apr 2016 12:29:39 -0700 (PDT) X-Received: by 10.98.66.89 with SMTP id p86mr43271054pfa.42.1461526179664; Sun, 24 Apr 2016 12:29:39 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id sg7si3464924pac.221.2016.04.24.12.29.39; Sun, 24 Apr 2016 12:29:39 -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 S1752608AbcDXT3i (ORCPT + 1 other); Sun, 24 Apr 2016 15:29:38 -0400 Received: from mail-wm0-f47.google.com ([74.125.82.47]:36128 "EHLO mail-wm0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753256AbcDXT2r (ORCPT ); Sun, 24 Apr 2016 15:28:47 -0400 Received: by mail-wm0-f47.google.com with SMTP id v188so75428162wme.1 for ; Sun, 24 Apr 2016 12:28:46 -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=iIcmNx/L4tEQzwDS4wX0c0i1QfH4aLt9lIIyQDJpTow=; b=Cmjd7V6+ozcsSvYS3Re5JtSYa0xfDDZuq9pElMT1t7J5nu5TP62JOpSTt6Xla1fi5A BmXajIh7iWW87oZz7vjmXtZmr0XtRvUBSq3t+GIR0yJ2C7VmAtYGymZ5suHv1lkpGtYX FtrRQlXFVR9+77ckV/R1n8jjtpxqK6J90+dDc= 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=iIcmNx/L4tEQzwDS4wX0c0i1QfH4aLt9lIIyQDJpTow=; b=SeiDbJI2WWXtU4FyzyfVpMk/b+GYiStVHDY4EVKW1gFulHExn4fCuBySvwzbe57/Wq zzGXCvanTYZFTOY08fhU/IIAwMFA3YMe4uFGW4vMmw0E2LRF2BXKzj4wqf7ZtgeDKmcO yYMbk1l+lYMYdvlGyDCFq0SFlHbYtytSgTW2maWDSiJt4C7M3+06vPRfF+HdgFQ9+VQD DmenFaT5z7zl99k6fmiMpqYv7c8VysDDa7yDVFWZxdQxIN1WMnwBWXW9ZnzgfAhHhggv tTBFdxoy/B2icDGQFrfy90ZpluxD967BLwbhuyCPzvVmTrpKc795QVDq7QU+MAHrd01r +RfQ== X-Gm-Message-State: AOPr4FVEF/CZQLsJrYYxn00UIMndhamVMYeYP+ItRwqBvJc5k2v0Vbbn1SyYAcQe4Aw8Dr98 X-Received: by 10.28.183.134 with SMTP id h128mr3244280wmf.63.1461526125797; Sun, 24 Apr 2016 12:28:45 -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.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 24 Apr 2016 12:28:45 -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 10/12] nvmem: lpc18xx-eeprom: remove nvmem regmap dependency Date: Sun, 24 Apr 2016 20:28:14 +0100 Message-Id: <1461526096-29584-11-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/nvmem/lpc18xx_eeprom.c | 94 ++++++++++++------------------------------ 1 file changed, 26 insertions(+), 68 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/nvmem/lpc18xx_eeprom.c b/drivers/nvmem/lpc18xx_eeprom.c index 878fce7..c81ae4c 100644 --- a/drivers/nvmem/lpc18xx_eeprom.c +++ b/drivers/nvmem/lpc18xx_eeprom.c @@ -16,7 +16,6 @@ #include #include #include -#include #include /* Registers */ @@ -51,12 +50,7 @@ struct lpc18xx_eeprom_dev { struct nvmem_device *nvmem; unsigned reg_bytes; unsigned val_bytes; -}; - -static struct regmap_config lpc18xx_regmap_config = { - .reg_bits = 32, - .reg_stride = 4, - .val_bits = 32, + int size; }; static inline void lpc18xx_eeprom_writel(struct lpc18xx_eeprom_dev *eeprom, @@ -95,30 +89,35 @@ static int lpc18xx_eeprom_busywait_until_prog(struct lpc18xx_eeprom_dev *eeprom) return -ETIMEDOUT; } -static int lpc18xx_eeprom_gather_write(void *context, const void *reg, - size_t reg_size, const void *val, - size_t val_size) +static int lpc18xx_eeprom_gather_write(void *context, unsigned int reg, + void *val, size_t bytes) { struct lpc18xx_eeprom_dev *eeprom = context; - unsigned int offset = *(u32 *)reg; + unsigned int offset = reg; int ret; - if (offset % lpc18xx_regmap_config.reg_stride) + /* + * The last page contains the EEPROM initialization data and is not + * writable. + */ + if ((reg > eeprom->size - LPC18XX_EEPROM_PAGE_SIZE) || + (reg + bytes > eeprom->size - LPC18XX_EEPROM_PAGE_SIZE)) return -EINVAL; + lpc18xx_eeprom_writel(eeprom, LPC18XX_EEPROM_PWRDWN, LPC18XX_EEPROM_PWRDWN_NO); /* Wait 100 us while the EEPROM wakes up */ usleep_range(100, 200); - while (val_size) { + while (bytes) { writel(*(u32 *)val, eeprom->mem_base + offset); ret = lpc18xx_eeprom_busywait_until_prog(eeprom); if (ret < 0) return ret; - val_size -= eeprom->val_bytes; + bytes -= eeprom->val_bytes; val += eeprom->val_bytes; offset += eeprom->val_bytes; } @@ -129,23 +128,10 @@ static int lpc18xx_eeprom_gather_write(void *context, const void *reg, return 0; } -static int lpc18xx_eeprom_write(void *context, const void *data, size_t count) +static int lpc18xx_eeprom_read(void *context, unsigned int offset, + void *val, size_t bytes) { struct lpc18xx_eeprom_dev *eeprom = context; - unsigned int offset = eeprom->reg_bytes; - - if (count <= offset) - return -EINVAL; - - return lpc18xx_eeprom_gather_write(context, data, eeprom->reg_bytes, - data + offset, count - offset); -} - -static int lpc18xx_eeprom_read(void *context, const void *reg, size_t reg_size, - void *val, size_t val_size) -{ - struct lpc18xx_eeprom_dev *eeprom = context; - unsigned int offset = *(u32 *)reg; lpc18xx_eeprom_writel(eeprom, LPC18XX_EEPROM_PWRDWN, LPC18XX_EEPROM_PWRDWN_NO); @@ -153,9 +139,9 @@ static int lpc18xx_eeprom_read(void *context, const void *reg, size_t reg_size, /* Wait 100 us while the EEPROM wakes up */ usleep_range(100, 200); - while (val_size) { + while (bytes) { *(u32 *)val = readl(eeprom->mem_base + offset); - val_size -= eeprom->val_bytes; + bytes -= eeprom->val_bytes; val += eeprom->val_bytes; offset += eeprom->val_bytes; } @@ -166,31 +152,13 @@ static int lpc18xx_eeprom_read(void *context, const void *reg, size_t reg_size, return 0; } -static struct regmap_bus lpc18xx_eeprom_bus = { - .write = lpc18xx_eeprom_write, - .gather_write = lpc18xx_eeprom_gather_write, - .read = lpc18xx_eeprom_read, - .reg_format_endian_default = REGMAP_ENDIAN_NATIVE, - .val_format_endian_default = REGMAP_ENDIAN_NATIVE, -}; - -static bool lpc18xx_eeprom_writeable_reg(struct device *dev, unsigned int reg) -{ - /* - * The last page contains the EEPROM initialization data and is not - * writable. - */ - return reg <= lpc18xx_regmap_config.max_register - - LPC18XX_EEPROM_PAGE_SIZE; -} - -static bool lpc18xx_eeprom_readable_reg(struct device *dev, unsigned int reg) -{ - return reg <= lpc18xx_regmap_config.max_register; -} static struct nvmem_config lpc18xx_nvmem_config = { .name = "lpc18xx-eeprom", + .stride = 4, + .word_size = 4, + .reg_read = lpc18xx_eeprom_read, + .reg_write = lpc18xx_eeprom_gather_write, .owner = THIS_MODULE, }; @@ -200,7 +168,6 @@ static int lpc18xx_eeprom_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct reset_control *rst; unsigned long clk_rate; - struct regmap *regmap; struct resource *res; int ret; @@ -243,8 +210,8 @@ static int lpc18xx_eeprom_probe(struct platform_device *pdev) goto err_clk; } - eeprom->val_bytes = lpc18xx_regmap_config.val_bits / BITS_PER_BYTE; - eeprom->reg_bytes = lpc18xx_regmap_config.reg_bits / BITS_PER_BYTE; + eeprom->val_bytes = 4; + eeprom->reg_bytes = 4; /* * Clock rate is generated by dividing the system bus clock by the @@ -264,19 +231,10 @@ static int lpc18xx_eeprom_probe(struct platform_device *pdev) lpc18xx_eeprom_writel(eeprom, LPC18XX_EEPROM_PWRDWN, LPC18XX_EEPROM_PWRDWN_YES); - lpc18xx_regmap_config.max_register = resource_size(res) - 1; - lpc18xx_regmap_config.writeable_reg = lpc18xx_eeprom_writeable_reg; - lpc18xx_regmap_config.readable_reg = lpc18xx_eeprom_readable_reg; - - regmap = devm_regmap_init(dev, &lpc18xx_eeprom_bus, eeprom, - &lpc18xx_regmap_config); - if (IS_ERR(regmap)) { - dev_err(dev, "regmap init failed: %ld\n", PTR_ERR(regmap)); - ret = PTR_ERR(regmap); - goto err_clk; - } - + eeprom->size = resource_size(res); + lpc18xx_nvmem_config.size = resource_size(res); lpc18xx_nvmem_config.dev = dev; + lpc18xx_nvmem_config.priv = eeprom; eeprom->nvmem = nvmem_register(&lpc18xx_nvmem_config); if (IS_ERR(eeprom->nvmem)) {