Skip to content

Commit

Permalink
nvmem: mtk-efuse: remove nvmem regmap dependency
Browse files Browse the repository at this point in the history
Regmap raw accessors are bus specific implementations, using regmap raw
apis in nvmem breaks nvmem providers based on regmap mmio.
This patch moves to nvmem support in the driver to use callback
instead of regmap, which is what the nvmem core supports now.

Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Srinivas Kandagatla authored and Greg Kroah-Hartman committed Jun 25, 2016
1 parent 194c858 commit ba360fd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
1 change: 0 additions & 1 deletion drivers/nvmem/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ config MTK_EFUSE
tristate "Mediatek SoCs EFUSE support"
depends on ARCH_MEDIATEK || COMPILE_TEST
depends on HAS_IOMEM
select REGMAP_MMIO
help
This is a driver to access hardware related data like sensor
calibration, HDMI impedance etc.
Expand Down
47 changes: 32 additions & 15 deletions drivers/nvmem/mtk-efuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,42 @@

#include <linux/device.h>
#include <linux/module.h>
#include <linux/io.h>
#include <linux/nvmem-provider.h>
#include <linux/platform_device.h>
#include <linux/regmap.h>

static struct regmap_config mtk_regmap_config = {
.reg_bits = 32,
.val_bits = 32,
.reg_stride = 4,
};
static int mtk_reg_read(void *context,
unsigned int reg, void *_val, size_t bytes)
{
void __iomem *base = context;
u32 *val = _val;
int i = 0, words = bytes / 4;

while (words--)
*val++ = readl(base + reg + (i++ * 4));

return 0;
}

static int mtk_reg_write(void *context,
unsigned int reg, void *_val, size_t bytes)
{
void __iomem *base = context;
u32 *val = _val;
int i = 0, words = bytes / 4;

while (words--)
writel(*val++, base + reg + (i++ * 4));

return 0;
}

static int mtk_efuse_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct resource *res;
struct nvmem_device *nvmem;
struct nvmem_config *econfig;
struct regmap *regmap;
void __iomem *base;

res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Expand All @@ -42,14 +61,12 @@ static int mtk_efuse_probe(struct platform_device *pdev)
if (!econfig)
return -ENOMEM;

mtk_regmap_config.max_register = resource_size(res) - 1;

regmap = devm_regmap_init_mmio(dev, base, &mtk_regmap_config);
if (IS_ERR(regmap)) {
dev_err(dev, "regmap init failed\n");
return PTR_ERR(regmap);
}

econfig->stride = 4;
econfig->word_size = 4;
econfig->reg_read = mtk_reg_read;
econfig->reg_write = mtk_reg_write;
econfig->size = resource_size(res);
econfig->priv = base;
econfig->dev = dev;
econfig->owner = THIS_MODULE;
nvmem = nvmem_register(econfig);
Expand Down

0 comments on commit ba360fd

Please sign in to comment.