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: 8921061 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A0B64BF440 for ; Sun, 24 Apr 2016 19:31:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A468C201EC for ; Sun, 24 Apr 2016 19:31:49 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9F5D020155 for ; Sun, 24 Apr 2016 19:31:48 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1auPjW-0007QS-Lh; Sun, 24 Apr 2016 19:30:18 +0000 Received: from merlin.infradead.org ([2001:4978:20e::2]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1auPiO-00056I-UK for linux-arm-kernel@bombadil.infradead.org; Sun, 24 Apr 2016 19:29:09 +0000 Received: from mail-wm0-x233.google.com ([2a00:1450:400c:c09::233]) by merlin.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1auPiN-00089V-0T for linux-arm-kernel@lists.infradead.org; Sun, 24 Apr 2016 19:29:08 +0000 Received: by mail-wm0-x233.google.com with SMTP id v200so11013503wmv.1 for ; Sun, 24 Apr 2016 12:28:47 -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=S9UXgla3X417VpcfqfDvebW/m31LNl3FUyVQiYjAb24kjYrFqrTetPbu2QtD3iKOrH 4grgZTxXrxVbir5V1A2l+foRHSQNZgnOnXGT8mf7cjZm5XPdZ2x0CcqyT4d44wu97/mR hLIWizh+vG2Lb0IpeUfMMCLonjmIKPtSXJeoeKQNuyr2r1Hv1gj9KIxIX8twPvlcIIwF BOBbxMd+IZW/BUnB+MOuxryUBoBCZN7fsiHT4o7RzxPV2n9fur0UbVkZkbJGfX64auxB ED2jsGf+KujcWhwlcstT6y16ya2TdcJS4tsLOMU5fgXEg5w5JaVsADZk4Ahoa+vFrB4w wsvQ== X-Gm-Message-State: AOPr4FU0hZWPowoIUDiSRAG8If53JyrZdG5q7j5CqWjtDyllBMbmwCQAM0+RVlPwTilo+Fst 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160424_152907_285016_EF903CA6 X-CRM114-Status: GOOD ( 20.46 ) X-Spam-Score: -2.7 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: andrew@lunn.ch, Heiko Stuebner , Wolfram Sang , Joachim Eastwood , linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, Chen-Yu Tsai , Mark Brown , Srinivas Kandagatla , linux-i2c@vger.kernel.org, Matthias Brugger , linux-mediatek@lists.infradead.org, Maxime Ripard , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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)) {