Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752614AbcD1Gvp (ORCPT ); Thu, 28 Apr 2016 02:51:45 -0400 Received: from mout.kundenserver.de ([212.227.17.24]:55915 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751689AbcD1Gvm (ORCPT ); Thu, 28 Apr 2016 02:51:42 -0400 Subject: Re: [PATCH 11/12] nvmem: mxs-ocotp: remove nvmem regmap dependency To: Srinivas Kandagatla References: <1461526096-29584-1-git-send-email-srinivas.kandagatla@linaro.org> <1461526096-29584-12-git-send-email-srinivas.kandagatla@linaro.org> Cc: Greg Kroah-Hartman , andrew@lunn.ch, Heiko Stuebner , Wolfram Sang , Joachim Eastwood , linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, Chen-Yu Tsai , Mark Brown , linux-i2c@vger.kernel.org, Matthias Brugger , linux-mediatek@lists.infradead.org, Maxime Ripard , linux-arm-kernel@lists.infradead.org From: Stefan Wahren Message-ID: <5721B2BA.4080100@i2se.com> Date: Thu, 28 Apr 2016 08:50:34 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 In-Reply-To: <1461526096-29584-12-git-send-email-srinivas.kandagatla@linaro.org> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:KMmdfgVoMtN0ZbA+7GUF65xvt4y2hHfUVgKcTbDtq6OcpIbEGEt UxwtAiiAykhuc+AIOI6Uo/TPYjLQRikDrVz1bhzP4rbQ4Q1aQuMRxXU9US8wE6VoWHJnUb2 X5nLvI9atUibSfVZOja3F32T8nzw91QMnsEJHFYP4hpru/OLQPrqKZD3OlG41657g4b2kaH fyd2b3csH9Pap4SMpmpcg== X-UI-Out-Filterresults: notjunk:1;V01:K0:qJdaHytI664=:9lTk00xAzR17infufqibgy JaJm0m/Z2y6tPfiHgW2LJDMY4+eTHsaKE0lQCQMq62gnbFnmHHkRhsGGqN7+XvptbORPAXt6x UjWioW8yfFmQMQP1oL5ftpBaOOMMcfupXHGiLz9S2dMsAWBdUOkG0tr+ahzcqNKjJdBR1zfVU radkQIP9nBnB6I17G/bxaZpzEGACtqYQ7VEYAtR/pIevU5i/fP7zegq/EPux+8hNsgSxP3oyD tbIkXHbFG2emFu++dek4jZISl9o9EqecRHlpJjSf4Y4JxSw2hsKKUPEWe/Vh+htw1d3ZIdqx/ xxwvCsKJCIiTnYYOviNx2daxlQkQUrFN86QQbgcmNUdIhUn2SNAXjYFhl24qzEQyRaKDjtR8n JBqFqdVpPCEVeYh4qcc6ZDDpJ4b0l4BB0JoSQ9y/hwxYxPprnnS+FNRpbLW2fJx3IIZI7/hCY Ird7JorlqSXbQMvS3vwQifwJ05YjNLw5zjbP/1F/9hwEioSQqOs4HrCNtbc0JwKNCG+j9j8nD ez9glwaZYBoc65IKCOXbGHHdRBWgBpriAGVZtObhLfYfsCE6nVLzunts0n7Ua3oYFzc0t3Uhp PhA95cUhHPoaBsaKYBMjQq/DRaNjHa27DTcjnjUuieB96DcR46ATlK3i2aLq++8VduIxCx5Cs KC5L6y2I8auQ4zOfFtBco98d0sDobJCaFXTEgQnOYOqffPqH3ouT/LTCsDFB+w+czjq3dShl+ bYa6TXDiCH6OUKyQ Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5046 Lines: 174 Hi Srinivas, Am 24.04.2016 um 21:28 schrieb Srinivas Kandagatla: > This patch moves to nvmem support in the driver to use callback > instead of regmap. > > Signed-off-by: Srinivas Kandagatla > --- > drivers/nvmem/mxs-ocotp.c | 79 +++++++++++++---------------------------------- > 1 file changed, 21 insertions(+), 58 deletions(-) > > diff --git a/drivers/nvmem/mxs-ocotp.c b/drivers/nvmem/mxs-ocotp.c > index 8ba19bb..3bf962c 100644 > --- a/drivers/nvmem/mxs-ocotp.c > +++ b/drivers/nvmem/mxs-ocotp.c the include of regmap.h should also be removed. > @@ -66,11 +66,10 @@ static int mxs_ocotp_wait(struct mxs_ocotp *otp) > return 0; > } > > -static int mxs_ocotp_read(void *context, const void *reg, size_t reg_size, > - void *val, size_t val_size) > +static int mxs_ocotp_read(void *context, unsigned int offset, > + void *val, size_t bytes) > { > struct mxs_ocotp *otp = context; > - unsigned int offset = *(u32 *)reg; > u32 *buf = val; > int ret; > > @@ -94,17 +93,16 @@ static int mxs_ocotp_read(void *context, const void *reg, size_t reg_size, > if (ret) > goto close_banks; > > - while (val_size) { > + while (bytes) { > if ((offset < OCOTP_DATA_OFFSET) || (offset % 16)) { > /* fill up non-data register */ > - *buf = 0; > + *buf++ = 0; > } else { > - *buf = readl(otp->base + offset); > + *buf++ = readl(otp->base + offset); > } > > - buf++; > - val_size--; > - offset += reg_size; > + bytes -= 4; > + offset += 4; This change would also fix the buffer overflow but Stanislav's patch should be applied before to get the fix in stable. > } > > close_banks: > @@ -117,57 +115,28 @@ disable_clk: > return ret; > } > > -static int mxs_ocotp_write(void *context, const void *data, size_t count) > -{ > - /* We don't want to support writing */ > - return 0; > -} > - > -static bool mxs_ocotp_writeable_reg(struct device *dev, unsigned int reg) > -{ > - return false; > -} > - > static struct nvmem_config ocotp_config = { > .name = "mxs-ocotp", > + .stride = 16, > + .word_size = 4, > .owner = THIS_MODULE, .reg_read = mxs_ocotp_read, > }; > > -static const struct regmap_range imx23_ranges[] = { > - regmap_reg_range(OCOTP_DATA_OFFSET, 0x210), > -}; > - > -static const struct regmap_access_table imx23_access = { > - .yes_ranges = imx23_ranges, > - .n_yes_ranges = ARRAY_SIZE(imx23_ranges), > -}; > - > -static const struct regmap_range imx28_ranges[] = { > - regmap_reg_range(OCOTP_DATA_OFFSET, 0x290), > -}; > - > -static const struct regmap_access_table imx28_access = { > - .yes_ranges = imx28_ranges, > - .n_yes_ranges = ARRAY_SIZE(imx28_ranges), > +struct imx_data { struct mxs_data These chips are named imx2x but the platform is mxs. Please don't ask why. > + int max_reg; Since nvmem_config uses "size" instead of "max_reg" we better use "size" here, too. This avoids confusion and potential issues see below. > }; > > -static struct regmap_bus mxs_ocotp_bus = { > - .read = mxs_ocotp_read, > - .write = mxs_ocotp_write, /* make regmap_init() happy */ > - .reg_format_endian_default = REGMAP_ENDIAN_NATIVE, > - .val_format_endian_default = REGMAP_ENDIAN_NATIVE, > +static const struct imx_data imx23_data = { static const struct mxs_data imx23_data > + .max_reg = 0x210, .size = 0x220, > }; > > -static struct regmap_config mxs_ocotp_config = { > - .reg_bits = 32, > - .val_bits = 32, > - .reg_stride = 16, > - .writeable_reg = mxs_ocotp_writeable_reg, > +static const struct imx_data imx28_data = { static const struct mxs_data imx28_data > + .max_reg = 0x290, .size = 0x2a0, > }; > > static const struct of_device_id mxs_ocotp_match[] = { > - { .compatible = "fsl,imx23-ocotp", .data = &imx23_access }, > - { .compatible = "fsl,imx28-ocotp", .data = &imx28_access }, > + { .compatible = "fsl,imx23-ocotp", .data = &imx23_data }, > + { .compatible = "fsl,imx28-ocotp", .data = &imx23_data }, .compatible = "fsl,imx28-ocotp", .data = &imx28_data > { /* sentinel */}, > }; > MODULE_DEVICE_TABLE(of, mxs_ocotp_match); > @@ -175,6 +144,7 @@ MODULE_DEVICE_TABLE(of, mxs_ocotp_match); > static int mxs_ocotp_probe(struct platform_device *pdev) > { > struct device *dev = &pdev->dev; > + struct imx_data *data; const struct mxs_data *data > struct mxs_ocotp *otp; > struct resource *res; > const struct of_device_id *match; > @@ -205,17 +175,10 @@ static int mxs_ocotp_probe(struct platform_device *pdev) > return ret; > } > > - access = match->data; > - mxs_ocotp_config.rd_table = access; > - mxs_ocotp_config.max_register = access->yes_ranges[0].range_max; > - > - regmap = devm_regmap_init(dev, &mxs_ocotp_bus, otp, &mxs_ocotp_config); > - if (IS_ERR(regmap)) { > - dev_err(dev, "regmap init failed\n"); > - ret = PTR_ERR(regmap); > - goto err_clk; > - } > + data = match->data; > > + ocotp_config.size = data->max_reg; data->size Regards Stefan > + ocotp_config.priv = otp; > ocotp_config.dev = dev; > otp->nvmem = nvmem_register(&ocotp_config); > if (IS_ERR(otp->nvmem)) {