Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

nvmem: lpc18xx-eeprom: remove nvmem regmap dependency

This patch moves to nvmem support in the driver to use callback
instead of regmap.

Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Srinivas Kandagatla and committed by
Greg Kroah-Hartman
2e8d0733 33e5e29c

+26 -68
+26 -68
drivers/nvmem/lpc18xx_eeprom.c
··· 16 16 #include <linux/module.h> 17 17 #include <linux/nvmem-provider.h> 18 18 #include <linux/platform_device.h> 19 - #include <linux/regmap.h> 20 19 #include <linux/reset.h> 21 20 22 21 /* Registers */ ··· 50 51 struct nvmem_device *nvmem; 51 52 unsigned reg_bytes; 52 53 unsigned val_bytes; 53 - }; 54 - 55 - static struct regmap_config lpc18xx_regmap_config = { 56 - .reg_bits = 32, 57 - .reg_stride = 4, 58 - .val_bits = 32, 54 + int size; 59 55 }; 60 56 61 57 static inline void lpc18xx_eeprom_writel(struct lpc18xx_eeprom_dev *eeprom, ··· 89 95 return -ETIMEDOUT; 90 96 } 91 97 92 - static int lpc18xx_eeprom_gather_write(void *context, const void *reg, 93 - size_t reg_size, const void *val, 94 - size_t val_size) 98 + static int lpc18xx_eeprom_gather_write(void *context, unsigned int reg, 99 + void *val, size_t bytes) 95 100 { 96 101 struct lpc18xx_eeprom_dev *eeprom = context; 97 - unsigned int offset = *(u32 *)reg; 102 + unsigned int offset = reg; 98 103 int ret; 99 104 100 - if (offset % lpc18xx_regmap_config.reg_stride) 105 + /* 106 + * The last page contains the EEPROM initialization data and is not 107 + * writable. 108 + */ 109 + if ((reg > eeprom->size - LPC18XX_EEPROM_PAGE_SIZE) || 110 + (reg + bytes > eeprom->size - LPC18XX_EEPROM_PAGE_SIZE)) 101 111 return -EINVAL; 112 + 102 113 103 114 lpc18xx_eeprom_writel(eeprom, LPC18XX_EEPROM_PWRDWN, 104 115 LPC18XX_EEPROM_PWRDWN_NO); ··· 111 112 /* Wait 100 us while the EEPROM wakes up */ 112 113 usleep_range(100, 200); 113 114 114 - while (val_size) { 115 + while (bytes) { 115 116 writel(*(u32 *)val, eeprom->mem_base + offset); 116 117 ret = lpc18xx_eeprom_busywait_until_prog(eeprom); 117 118 if (ret < 0) 118 119 return ret; 119 120 120 - val_size -= eeprom->val_bytes; 121 + bytes -= eeprom->val_bytes; 121 122 val += eeprom->val_bytes; 122 123 offset += eeprom->val_bytes; 123 124 } ··· 128 129 return 0; 129 130 } 130 131 131 - static int lpc18xx_eeprom_write(void *context, const void *data, size_t count) 132 + static int lpc18xx_eeprom_read(void *context, unsigned int offset, 133 + void *val, size_t bytes) 132 134 { 133 135 struct lpc18xx_eeprom_dev *eeprom = context; 134 - unsigned int offset = eeprom->reg_bytes; 135 - 136 - if (count <= offset) 137 - return -EINVAL; 138 - 139 - return lpc18xx_eeprom_gather_write(context, data, eeprom->reg_bytes, 140 - data + offset, count - offset); 141 - } 142 - 143 - static int lpc18xx_eeprom_read(void *context, const void *reg, size_t reg_size, 144 - void *val, size_t val_size) 145 - { 146 - struct lpc18xx_eeprom_dev *eeprom = context; 147 - unsigned int offset = *(u32 *)reg; 148 136 149 137 lpc18xx_eeprom_writel(eeprom, LPC18XX_EEPROM_PWRDWN, 150 138 LPC18XX_EEPROM_PWRDWN_NO); ··· 139 153 /* Wait 100 us while the EEPROM wakes up */ 140 154 usleep_range(100, 200); 141 155 142 - while (val_size) { 156 + while (bytes) { 143 157 *(u32 *)val = readl(eeprom->mem_base + offset); 144 - val_size -= eeprom->val_bytes; 158 + bytes -= eeprom->val_bytes; 145 159 val += eeprom->val_bytes; 146 160 offset += eeprom->val_bytes; 147 161 } ··· 152 166 return 0; 153 167 } 154 168 155 - static struct regmap_bus lpc18xx_eeprom_bus = { 156 - .write = lpc18xx_eeprom_write, 157 - .gather_write = lpc18xx_eeprom_gather_write, 158 - .read = lpc18xx_eeprom_read, 159 - .reg_format_endian_default = REGMAP_ENDIAN_NATIVE, 160 - .val_format_endian_default = REGMAP_ENDIAN_NATIVE, 161 - }; 162 - 163 - static bool lpc18xx_eeprom_writeable_reg(struct device *dev, unsigned int reg) 164 - { 165 - /* 166 - * The last page contains the EEPROM initialization data and is not 167 - * writable. 168 - */ 169 - return reg <= lpc18xx_regmap_config.max_register - 170 - LPC18XX_EEPROM_PAGE_SIZE; 171 - } 172 - 173 - static bool lpc18xx_eeprom_readable_reg(struct device *dev, unsigned int reg) 174 - { 175 - return reg <= lpc18xx_regmap_config.max_register; 176 - } 177 169 178 170 static struct nvmem_config lpc18xx_nvmem_config = { 179 171 .name = "lpc18xx-eeprom", 172 + .stride = 4, 173 + .word_size = 4, 174 + .reg_read = lpc18xx_eeprom_read, 175 + .reg_write = lpc18xx_eeprom_gather_write, 180 176 .owner = THIS_MODULE, 181 177 }; 182 178 ··· 168 200 struct device *dev = &pdev->dev; 169 201 struct reset_control *rst; 170 202 unsigned long clk_rate; 171 - struct regmap *regmap; 172 203 struct resource *res; 173 204 int ret; 174 205 ··· 210 243 goto err_clk; 211 244 } 212 245 213 - eeprom->val_bytes = lpc18xx_regmap_config.val_bits / BITS_PER_BYTE; 214 - eeprom->reg_bytes = lpc18xx_regmap_config.reg_bits / BITS_PER_BYTE; 246 + eeprom->val_bytes = 4; 247 + eeprom->reg_bytes = 4; 215 248 216 249 /* 217 250 * Clock rate is generated by dividing the system bus clock by the ··· 231 264 lpc18xx_eeprom_writel(eeprom, LPC18XX_EEPROM_PWRDWN, 232 265 LPC18XX_EEPROM_PWRDWN_YES); 233 266 234 - lpc18xx_regmap_config.max_register = resource_size(res) - 1; 235 - lpc18xx_regmap_config.writeable_reg = lpc18xx_eeprom_writeable_reg; 236 - lpc18xx_regmap_config.readable_reg = lpc18xx_eeprom_readable_reg; 237 - 238 - regmap = devm_regmap_init(dev, &lpc18xx_eeprom_bus, eeprom, 239 - &lpc18xx_regmap_config); 240 - if (IS_ERR(regmap)) { 241 - dev_err(dev, "regmap init failed: %ld\n", PTR_ERR(regmap)); 242 - ret = PTR_ERR(regmap); 243 - goto err_clk; 244 - } 245 - 267 + eeprom->size = resource_size(res); 268 + lpc18xx_nvmem_config.size = resource_size(res); 246 269 lpc18xx_nvmem_config.dev = dev; 270 + lpc18xx_nvmem_config.priv = eeprom; 247 271 248 272 eeprom->nvmem = nvmem_register(&lpc18xx_nvmem_config); 249 273 if (IS_ERR(eeprom->nvmem)) {