diff options
Diffstat (limited to 'drivers/nvmem/qfprom.c')
| -rw-r--r-- | drivers/nvmem/qfprom.c | 56 |
1 files changed, 37 insertions, 19 deletions
diff --git a/drivers/nvmem/qfprom.c b/drivers/nvmem/qfprom.c index 3829e5fbf8c3..b5305f08b184 100644 --- a/drivers/nvmem/qfprom.c +++ b/drivers/nvmem/qfprom.c | |||
| @@ -13,21 +13,35 @@ | |||
| 13 | 13 | ||
| 14 | #include <linux/device.h> | 14 | #include <linux/device.h> |
| 15 | #include <linux/module.h> | 15 | #include <linux/module.h> |
| 16 | #include <linux/io.h> | ||
| 16 | #include <linux/nvmem-provider.h> | 17 | #include <linux/nvmem-provider.h> |
| 17 | #include <linux/platform_device.h> | 18 | #include <linux/platform_device.h> |
| 18 | #include <linux/regmap.h> | ||
| 19 | 19 | ||
| 20 | static struct regmap_config qfprom_regmap_config = { | 20 | static int qfprom_reg_read(void *context, |
| 21 | .reg_bits = 32, | 21 | unsigned int reg, void *_val, size_t bytes) |
| 22 | .val_bits = 8, | 22 | { |
| 23 | .reg_stride = 1, | 23 | void __iomem *base = context; |
| 24 | .val_format_endian = REGMAP_ENDIAN_LITTLE, | 24 | u32 *val = _val; |
| 25 | }; | 25 | int i = 0, words = bytes / 4; |
| 26 | 26 | ||
| 27 | static struct nvmem_config econfig = { | 27 | while (words--) |
| 28 | .name = "qfprom", | 28 | *val++ = readl(base + reg + (i++ * 4)); |
| 29 | .owner = THIS_MODULE, | 29 | |
| 30 | }; | 30 | return 0; |
| 31 | } | ||
| 32 | |||
| 33 | static int qfprom_reg_write(void *context, | ||
| 34 | unsigned int reg, void *_val, size_t bytes) | ||
| 35 | { | ||
| 36 | void __iomem *base = context; | ||
| 37 | u32 *val = _val; | ||
| 38 | int i = 0, words = bytes / 4; | ||
| 39 | |||
| 40 | while (words--) | ||
| 41 | writel(*val++, base + reg + (i++ * 4)); | ||
| 42 | |||
| 43 | return 0; | ||
| 44 | } | ||
| 31 | 45 | ||
| 32 | static int qfprom_remove(struct platform_device *pdev) | 46 | static int qfprom_remove(struct platform_device *pdev) |
| 33 | { | 47 | { |
| @@ -36,12 +50,20 @@ static int qfprom_remove(struct platform_device *pdev) | |||
| 36 | return nvmem_unregister(nvmem); | 50 | return nvmem_unregister(nvmem); |
| 37 | } | 51 | } |
| 38 | 52 | ||
| 53 | static struct nvmem_config econfig = { | ||
| 54 | .name = "qfprom", | ||
| 55 | .owner = THIS_MODULE, | ||
| 56 | .stride = 4, | ||
| 57 | .word_size = 1, | ||
| 58 | .reg_read = qfprom_reg_read, | ||
| 59 | .reg_write = qfprom_reg_write, | ||
| 60 | }; | ||
| 61 | |||
| 39 | static int qfprom_probe(struct platform_device *pdev) | 62 | static int qfprom_probe(struct platform_device *pdev) |
| 40 | { | 63 | { |
| 41 | struct device *dev = &pdev->dev; | 64 | struct device *dev = &pdev->dev; |
| 42 | struct resource *res; | 65 | struct resource *res; |
| 43 | struct nvmem_device *nvmem; | 66 | struct nvmem_device *nvmem; |
| 44 | struct regmap *regmap; | ||
| 45 | void __iomem *base; | 67 | void __iomem *base; |
| 46 | 68 | ||
| 47 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 69 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| @@ -49,14 +71,10 @@ static int qfprom_probe(struct platform_device *pdev) | |||
| 49 | if (IS_ERR(base)) | 71 | if (IS_ERR(base)) |
| 50 | return PTR_ERR(base); | 72 | return PTR_ERR(base); |
| 51 | 73 | ||
| 52 | qfprom_regmap_config.max_register = resource_size(res) - 1; | 74 | econfig.size = resource_size(res); |
| 53 | |||
| 54 | regmap = devm_regmap_init_mmio(dev, base, &qfprom_regmap_config); | ||
| 55 | if (IS_ERR(regmap)) { | ||
| 56 | dev_err(dev, "regmap init failed\n"); | ||
| 57 | return PTR_ERR(regmap); | ||
| 58 | } | ||
| 59 | econfig.dev = dev; | 75 | econfig.dev = dev; |
| 76 | econfig.priv = base; | ||
| 77 | |||
| 60 | nvmem = nvmem_register(&econfig); | 78 | nvmem = nvmem_register(&econfig); |
| 61 | if (IS_ERR(nvmem)) | 79 | if (IS_ERR(nvmem)) |
| 62 | return PTR_ERR(nvmem); | 80 | return PTR_ERR(nvmem); |
