Loading drivers/nvmem/imx-ocotp.c +11 −44 Original line number Diff line number Diff line Loading @@ -22,7 +22,6 @@ #include <linux/of.h> #include <linux/of_device.h> #include <linux/platform_device.h> #include <linux/regmap.h> #include <linux/slab.h> struct ocotp_priv { Loading @@ -31,59 +30,34 @@ struct ocotp_priv { unsigned int nregs; }; static int imx_ocotp_read(void *context, const void *reg, size_t reg_size, void *val, size_t val_size) static int imx_ocotp_read(void *context, unsigned int offset, void *val, size_t bytes) { struct ocotp_priv *priv = context; unsigned int offset = *(u32 *)reg; unsigned int count; u32 *buf = val; int i; u32 index; index = offset >> 2; count = val_size >> 2; count = bytes >> 2; if (count > (priv->nregs - index)) count = priv->nregs - index; for (i = index; i < (index + count); i++) { *(u32 *)val = readl(priv->base + 0x400 + i * 0x10); val += 4; } return 0; } for (i = index; i < (index + count); i++) *buf++ = readl(priv->base + 0x400 + i * 0x10); static int imx_ocotp_write(void *context, const void *data, size_t count) { /* Not implemented */ return 0; } static struct regmap_bus imx_ocotp_bus = { .read = imx_ocotp_read, .write = imx_ocotp_write, .reg_format_endian_default = REGMAP_ENDIAN_NATIVE, .val_format_endian_default = REGMAP_ENDIAN_NATIVE, }; static bool imx_ocotp_writeable_reg(struct device *dev, unsigned int reg) { return false; } static struct regmap_config imx_ocotp_regmap_config = { .reg_bits = 32, .val_bits = 32, .reg_stride = 4, .writeable_reg = imx_ocotp_writeable_reg, .name = "imx-ocotp", }; static struct nvmem_config imx_ocotp_nvmem_config = { .name = "imx-ocotp", .read_only = true, .word_size = 4, .stride = 4, .owner = THIS_MODULE, .reg_read = imx_ocotp_read, }; static const struct of_device_id imx_ocotp_dt_ids[] = { Loading @@ -99,7 +73,6 @@ static int imx_ocotp_probe(struct platform_device *pdev) const struct of_device_id *of_id; struct device *dev = &pdev->dev; struct resource *res; struct regmap *regmap; struct ocotp_priv *priv; struct nvmem_device *nvmem; Loading @@ -114,15 +87,9 @@ static int imx_ocotp_probe(struct platform_device *pdev) of_id = of_match_device(imx_ocotp_dt_ids, dev); priv->nregs = (unsigned int)of_id->data; imx_ocotp_regmap_config.max_register = 4 * priv->nregs - 4; regmap = devm_regmap_init(dev, &imx_ocotp_bus, priv, &imx_ocotp_regmap_config); if (IS_ERR(regmap)) { dev_err(dev, "regmap init failed\n"); return PTR_ERR(regmap); } imx_ocotp_nvmem_config.size = 4 * priv->nregs; imx_ocotp_nvmem_config.dev = dev; imx_ocotp_nvmem_config.priv = priv; nvmem = nvmem_register(&imx_ocotp_nvmem_config); if (IS_ERR(nvmem)) return PTR_ERR(nvmem); Loading Loading
drivers/nvmem/imx-ocotp.c +11 −44 Original line number Diff line number Diff line Loading @@ -22,7 +22,6 @@ #include <linux/of.h> #include <linux/of_device.h> #include <linux/platform_device.h> #include <linux/regmap.h> #include <linux/slab.h> struct ocotp_priv { Loading @@ -31,59 +30,34 @@ struct ocotp_priv { unsigned int nregs; }; static int imx_ocotp_read(void *context, const void *reg, size_t reg_size, void *val, size_t val_size) static int imx_ocotp_read(void *context, unsigned int offset, void *val, size_t bytes) { struct ocotp_priv *priv = context; unsigned int offset = *(u32 *)reg; unsigned int count; u32 *buf = val; int i; u32 index; index = offset >> 2; count = val_size >> 2; count = bytes >> 2; if (count > (priv->nregs - index)) count = priv->nregs - index; for (i = index; i < (index + count); i++) { *(u32 *)val = readl(priv->base + 0x400 + i * 0x10); val += 4; } return 0; } for (i = index; i < (index + count); i++) *buf++ = readl(priv->base + 0x400 + i * 0x10); static int imx_ocotp_write(void *context, const void *data, size_t count) { /* Not implemented */ return 0; } static struct regmap_bus imx_ocotp_bus = { .read = imx_ocotp_read, .write = imx_ocotp_write, .reg_format_endian_default = REGMAP_ENDIAN_NATIVE, .val_format_endian_default = REGMAP_ENDIAN_NATIVE, }; static bool imx_ocotp_writeable_reg(struct device *dev, unsigned int reg) { return false; } static struct regmap_config imx_ocotp_regmap_config = { .reg_bits = 32, .val_bits = 32, .reg_stride = 4, .writeable_reg = imx_ocotp_writeable_reg, .name = "imx-ocotp", }; static struct nvmem_config imx_ocotp_nvmem_config = { .name = "imx-ocotp", .read_only = true, .word_size = 4, .stride = 4, .owner = THIS_MODULE, .reg_read = imx_ocotp_read, }; static const struct of_device_id imx_ocotp_dt_ids[] = { Loading @@ -99,7 +73,6 @@ static int imx_ocotp_probe(struct platform_device *pdev) const struct of_device_id *of_id; struct device *dev = &pdev->dev; struct resource *res; struct regmap *regmap; struct ocotp_priv *priv; struct nvmem_device *nvmem; Loading @@ -114,15 +87,9 @@ static int imx_ocotp_probe(struct platform_device *pdev) of_id = of_match_device(imx_ocotp_dt_ids, dev); priv->nregs = (unsigned int)of_id->data; imx_ocotp_regmap_config.max_register = 4 * priv->nregs - 4; regmap = devm_regmap_init(dev, &imx_ocotp_bus, priv, &imx_ocotp_regmap_config); if (IS_ERR(regmap)) { dev_err(dev, "regmap init failed\n"); return PTR_ERR(regmap); } imx_ocotp_nvmem_config.size = 4 * priv->nregs; imx_ocotp_nvmem_config.dev = dev; imx_ocotp_nvmem_config.priv = priv; nvmem = nvmem_register(&imx_ocotp_nvmem_config); if (IS_ERR(nvmem)) return PTR_ERR(nvmem); Loading