diff options
author | Srinivas Kandagatla <srinivas.kandagatla@linaro.org> | 2016-04-24 15:28:07 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2016-05-01 17:01:00 -0400 |
commit | 01973a01f9ec34b706bf474dc4fb8c2bd9741d2b (patch) | |
tree | f36be16c8e4e649a7111642d9619d229ad842047 | |
parent | cf0361a2d2b809c6f5b73313544711648fd7afdd (diff) |
eeprom: at25: 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>
-rw-r--r-- | drivers/misc/eeprom/Kconfig | 1 | ||||
-rw-r--r-- | drivers/misc/eeprom/at25.c | 89 |
2 files changed, 19 insertions, 71 deletions
diff --git a/drivers/misc/eeprom/Kconfig b/drivers/misc/eeprom/Kconfig index 2d70464e8c8d..c4e41c26649e 100644 --- a/drivers/misc/eeprom/Kconfig +++ b/drivers/misc/eeprom/Kconfig | |||
@@ -31,7 +31,6 @@ config EEPROM_AT24 | |||
31 | config EEPROM_AT25 | 31 | config EEPROM_AT25 |
32 | tristate "SPI EEPROMs from most vendors" | 32 | tristate "SPI EEPROMs from most vendors" |
33 | depends on SPI && SYSFS | 33 | depends on SPI && SYSFS |
34 | select REGMAP | ||
35 | select NVMEM | 34 | select NVMEM |
36 | help | 35 | help |
37 | Enable this driver to get read/write support to most SPI EEPROMs, | 36 | Enable this driver to get read/write support to most SPI EEPROMs, |
diff --git a/drivers/misc/eeprom/at25.c b/drivers/misc/eeprom/at25.c index fa36a6e37084..a2858b33585e 100644 --- a/drivers/misc/eeprom/at25.c +++ b/drivers/misc/eeprom/at25.c | |||
@@ -17,7 +17,6 @@ | |||
17 | #include <linux/sched.h> | 17 | #include <linux/sched.h> |
18 | 18 | ||
19 | #include <linux/nvmem-provider.h> | 19 | #include <linux/nvmem-provider.h> |
20 | #include <linux/regmap.h> | ||
21 | #include <linux/spi/spi.h> | 20 | #include <linux/spi/spi.h> |
22 | #include <linux/spi/eeprom.h> | 21 | #include <linux/spi/eeprom.h> |
23 | #include <linux/property.h> | 22 | #include <linux/property.h> |
@@ -34,7 +33,6 @@ struct at25_data { | |||
34 | struct mutex lock; | 33 | struct mutex lock; |
35 | struct spi_eeprom chip; | 34 | struct spi_eeprom chip; |
36 | unsigned addrlen; | 35 | unsigned addrlen; |
37 | struct regmap_config regmap_config; | ||
38 | struct nvmem_config nvmem_config; | 36 | struct nvmem_config nvmem_config; |
39 | struct nvmem_device *nvmem; | 37 | struct nvmem_device *nvmem; |
40 | }; | 38 | }; |
@@ -65,14 +63,11 @@ struct at25_data { | |||
65 | 63 | ||
66 | #define io_limit PAGE_SIZE /* bytes */ | 64 | #define io_limit PAGE_SIZE /* bytes */ |
67 | 65 | ||
68 | static ssize_t | 66 | static int at25_ee_read(void *priv, unsigned int offset, |
69 | at25_ee_read( | 67 | void *val, size_t count) |
70 | struct at25_data *at25, | ||
71 | char *buf, | ||
72 | unsigned offset, | ||
73 | size_t count | ||
74 | ) | ||
75 | { | 68 | { |
69 | struct at25_data *at25 = priv; | ||
70 | char *buf = val; | ||
76 | u8 command[EE_MAXADDRLEN + 1]; | 71 | u8 command[EE_MAXADDRLEN + 1]; |
77 | u8 *cp; | 72 | u8 *cp; |
78 | ssize_t status; | 73 | ssize_t status; |
@@ -81,11 +76,11 @@ at25_ee_read( | |||
81 | u8 instr; | 76 | u8 instr; |
82 | 77 | ||
83 | if (unlikely(offset >= at25->chip.byte_len)) | 78 | if (unlikely(offset >= at25->chip.byte_len)) |
84 | return 0; | 79 | return -EINVAL; |
85 | if ((offset + count) > at25->chip.byte_len) | 80 | if ((offset + count) > at25->chip.byte_len) |
86 | count = at25->chip.byte_len - offset; | 81 | count = at25->chip.byte_len - offset; |
87 | if (unlikely(!count)) | 82 | if (unlikely(!count)) |
88 | return count; | 83 | return -EINVAL; |
89 | 84 | ||
90 | cp = command; | 85 | cp = command; |
91 | 86 | ||
@@ -131,28 +126,14 @@ at25_ee_read( | |||
131 | count, offset, (int) status); | 126 | count, offset, (int) status); |
132 | 127 | ||
133 | mutex_unlock(&at25->lock); | 128 | mutex_unlock(&at25->lock); |
134 | return status ? status : count; | 129 | return status; |
135 | } | 130 | } |
136 | 131 | ||
137 | static int at25_regmap_read(void *context, const void *reg, size_t reg_size, | 132 | static int at25_ee_write(void *priv, unsigned int off, void *val, size_t count) |
138 | void *val, size_t val_size) | ||
139 | { | 133 | { |
140 | struct at25_data *at25 = context; | 134 | struct at25_data *at25 = priv; |
141 | off_t offset = *(u32 *)reg; | 135 | const char *buf = val; |
142 | int err; | 136 | int status = 0; |
143 | |||
144 | err = at25_ee_read(at25, val, offset, val_size); | ||
145 | if (err) | ||
146 | return err; | ||
147 | return 0; | ||
148 | } | ||
149 | |||
150 | static ssize_t | ||
151 | at25_ee_write(struct at25_data *at25, const char *buf, loff_t off, | ||
152 | size_t count) | ||
153 | { | ||
154 | ssize_t status = 0; | ||
155 | unsigned written = 0; | ||
156 | unsigned buf_size; | 137 | unsigned buf_size; |
157 | u8 *bounce; | 138 | u8 *bounce; |
158 | 139 | ||
@@ -161,7 +142,7 @@ at25_ee_write(struct at25_data *at25, const char *buf, loff_t off, | |||
161 | if ((off + count) > at25->chip.byte_len) | 142 | if ((off + count) > at25->chip.byte_len) |
162 | count = at25->chip.byte_len - off; | 143 | count = at25->chip.byte_len - off; |
163 | if (unlikely(!count)) | 144 | if (unlikely(!count)) |
164 | return count; | 145 | return -EINVAL; |
165 | 146 | ||
166 | /* Temp buffer starts with command and address */ | 147 | /* Temp buffer starts with command and address */ |
167 | buf_size = at25->chip.page_size; | 148 | buf_size = at25->chip.page_size; |
@@ -256,40 +237,15 @@ at25_ee_write(struct at25_data *at25, const char *buf, loff_t off, | |||
256 | off += segment; | 237 | off += segment; |
257 | buf += segment; | 238 | buf += segment; |
258 | count -= segment; | 239 | count -= segment; |
259 | written += segment; | ||
260 | 240 | ||
261 | } while (count > 0); | 241 | } while (count > 0); |
262 | 242 | ||
263 | mutex_unlock(&at25->lock); | 243 | mutex_unlock(&at25->lock); |
264 | 244 | ||
265 | kfree(bounce); | 245 | kfree(bounce); |
266 | return written ? written : status; | 246 | return status; |
267 | } | 247 | } |
268 | 248 | ||
269 | static int at25_regmap_write(void *context, const void *data, size_t count) | ||
270 | { | ||
271 | struct at25_data *at25 = context; | ||
272 | const char *buf; | ||
273 | u32 offset; | ||
274 | size_t len; | ||
275 | int err; | ||
276 | |||
277 | memcpy(&offset, data, sizeof(offset)); | ||
278 | buf = (const char *)data + sizeof(offset); | ||
279 | len = count - sizeof(offset); | ||
280 | |||
281 | err = at25_ee_write(at25, buf, offset, len); | ||
282 | if (err) | ||
283 | return err; | ||
284 | return 0; | ||
285 | } | ||
286 | |||
287 | static const struct regmap_bus at25_regmap_bus = { | ||
288 | .read = at25_regmap_read, | ||
289 | .write = at25_regmap_write, | ||
290 | .reg_format_endian_default = REGMAP_ENDIAN_NATIVE, | ||
291 | }; | ||
292 | |||
293 | /*-------------------------------------------------------------------------*/ | 249 | /*-------------------------------------------------------------------------*/ |
294 | 250 | ||
295 | static int at25_fw_to_chip(struct device *dev, struct spi_eeprom *chip) | 251 | static int at25_fw_to_chip(struct device *dev, struct spi_eeprom *chip) |
@@ -349,7 +305,6 @@ static int at25_probe(struct spi_device *spi) | |||
349 | { | 305 | { |
350 | struct at25_data *at25 = NULL; | 306 | struct at25_data *at25 = NULL; |
351 | struct spi_eeprom chip; | 307 | struct spi_eeprom chip; |
352 | struct regmap *regmap; | ||
353 | int err; | 308 | int err; |
354 | int sr; | 309 | int sr; |
355 | int addrlen; | 310 | int addrlen; |
@@ -394,18 +349,6 @@ static int at25_probe(struct spi_device *spi) | |||
394 | spi_set_drvdata(spi, at25); | 349 | spi_set_drvdata(spi, at25); |
395 | at25->addrlen = addrlen; | 350 | at25->addrlen = addrlen; |
396 | 351 | ||
397 | at25->regmap_config.reg_bits = 32; | ||
398 | at25->regmap_config.val_bits = 8; | ||
399 | at25->regmap_config.reg_stride = 1; | ||
400 | at25->regmap_config.max_register = chip.byte_len - 1; | ||
401 | |||
402 | regmap = devm_regmap_init(&spi->dev, &at25_regmap_bus, at25, | ||
403 | &at25->regmap_config); | ||
404 | if (IS_ERR(regmap)) { | ||
405 | dev_err(&spi->dev, "regmap init failed\n"); | ||
406 | return PTR_ERR(regmap); | ||
407 | } | ||
408 | |||
409 | at25->nvmem_config.name = dev_name(&spi->dev); | 352 | at25->nvmem_config.name = dev_name(&spi->dev); |
410 | at25->nvmem_config.dev = &spi->dev; | 353 | at25->nvmem_config.dev = &spi->dev; |
411 | at25->nvmem_config.read_only = chip.flags & EE_READONLY; | 354 | at25->nvmem_config.read_only = chip.flags & EE_READONLY; |
@@ -413,6 +356,12 @@ static int at25_probe(struct spi_device *spi) | |||
413 | at25->nvmem_config.owner = THIS_MODULE; | 356 | at25->nvmem_config.owner = THIS_MODULE; |
414 | at25->nvmem_config.compat = true; | 357 | at25->nvmem_config.compat = true; |
415 | at25->nvmem_config.base_dev = &spi->dev; | 358 | at25->nvmem_config.base_dev = &spi->dev; |
359 | at25->nvmem_config.reg_read = at25_ee_read; | ||
360 | at25->nvmem_config.reg_write = at25_ee_write; | ||
361 | at25->nvmem_config.priv = at25; | ||
362 | at25->nvmem_config.stride = 4; | ||
363 | at25->nvmem_config.word_size = 1; | ||
364 | at25->nvmem_config.size = chip.byte_len; | ||
416 | 365 | ||
417 | at25->nvmem = nvmem_register(&at25->nvmem_config); | 366 | at25->nvmem = nvmem_register(&at25->nvmem_config); |
418 | if (IS_ERR(at25->nvmem)) | 367 | if (IS_ERR(at25->nvmem)) |