mtk-efuse.c (6ea24cf79e055f0a62a64baa8587e2254a493c7b) | mtk-efuse.c (ba360fd040e3417ed1d90e89d681698f82002207) |
---|---|
1/* 2 * Copyright (c) 2015 MediaTek Inc. 3 * Author: Andrew-CT Chen <andrew-ct.chen@mediatek.com> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License version 2 as 7 * published by the Free Software Foundation. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 */ 14 15#include <linux/device.h> 16#include <linux/module.h> | 1/* 2 * Copyright (c) 2015 MediaTek Inc. 3 * Author: Andrew-CT Chen <andrew-ct.chen@mediatek.com> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License version 2 as 7 * published by the Free Software Foundation. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 */ 14 15#include <linux/device.h> 16#include <linux/module.h> |
17#include <linux/io.h> |
|
17#include <linux/nvmem-provider.h> 18#include <linux/platform_device.h> | 18#include <linux/nvmem-provider.h> 19#include <linux/platform_device.h> |
19#include <linux/regmap.h> | |
20 | 20 |
21static struct regmap_config mtk_regmap_config = { 22 .reg_bits = 32, 23 .val_bits = 32, 24 .reg_stride = 4, 25}; | 21static int mtk_reg_read(void *context, 22 unsigned int reg, void *_val, size_t bytes) 23{ 24 void __iomem *base = context; 25 u32 *val = _val; 26 int i = 0, words = bytes / 4; |
26 | 27 |
28 while (words--) 29 *val++ = readl(base + reg + (i++ * 4)); 30 31 return 0; 32} 33 34static int mtk_reg_write(void *context, 35 unsigned int reg, void *_val, size_t bytes) 36{ 37 void __iomem *base = context; 38 u32 *val = _val; 39 int i = 0, words = bytes / 4; 40 41 while (words--) 42 writel(*val++, base + reg + (i++ * 4)); 43 44 return 0; 45} 46 |
|
27static int mtk_efuse_probe(struct platform_device *pdev) 28{ 29 struct device *dev = &pdev->dev; 30 struct resource *res; 31 struct nvmem_device *nvmem; 32 struct nvmem_config *econfig; | 47static int mtk_efuse_probe(struct platform_device *pdev) 48{ 49 struct device *dev = &pdev->dev; 50 struct resource *res; 51 struct nvmem_device *nvmem; 52 struct nvmem_config *econfig; |
33 struct regmap *regmap; | |
34 void __iomem *base; 35 36 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 37 base = devm_ioremap_resource(dev, res); 38 if (IS_ERR(base)) 39 return PTR_ERR(base); 40 41 econfig = devm_kzalloc(dev, sizeof(*econfig), GFP_KERNEL); 42 if (!econfig) 43 return -ENOMEM; 44 | 53 void __iomem *base; 54 55 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 56 base = devm_ioremap_resource(dev, res); 57 if (IS_ERR(base)) 58 return PTR_ERR(base); 59 60 econfig = devm_kzalloc(dev, sizeof(*econfig), GFP_KERNEL); 61 if (!econfig) 62 return -ENOMEM; 63 |
45 mtk_regmap_config.max_register = resource_size(res) - 1; 46 47 regmap = devm_regmap_init_mmio(dev, base, &mtk_regmap_config); 48 if (IS_ERR(regmap)) { 49 dev_err(dev, "regmap init failed\n"); 50 return PTR_ERR(regmap); 51 } 52 | 64 econfig->stride = 4; 65 econfig->word_size = 4; 66 econfig->reg_read = mtk_reg_read; 67 econfig->reg_write = mtk_reg_write; 68 econfig->size = resource_size(res); 69 econfig->priv = base; |
53 econfig->dev = dev; 54 econfig->owner = THIS_MODULE; 55 nvmem = nvmem_register(econfig); 56 if (IS_ERR(nvmem)) 57 return PTR_ERR(nvmem); 58 59 platform_set_drvdata(pdev, nvmem); 60 --- 50 unchanged lines hidden --- | 70 econfig->dev = dev; 71 econfig->owner = THIS_MODULE; 72 nvmem = nvmem_register(econfig); 73 if (IS_ERR(nvmem)) 74 return PTR_ERR(nvmem); 75 76 platform_set_drvdata(pdev, nvmem); 77 --- 50 unchanged lines hidden --- |