diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2015-09-08 19:48:55 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-09-08 19:48:55 -0400 |
commit | e81b594cdae73f341ea13bc9fb2b57a5b739c1a3 (patch) | |
tree | 2061ee4e7b77caa891a973cb647da63c2f6ff3ca | |
parent | fa815580fb87d1b8c218f9eba8122b2fc3f1a68c (diff) | |
parent | 072502a67c9164625288cca17704808e6c06273f (diff) |
Merge tag 'regmap-v4.3' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap
Pull regmap updates from Mark Brown:
"This has been a busy release for regmap.
By far the biggest set of changes here are those from Markus Pargmann
which implement support for block transfers in smbus devices. This
required quite a bit of refactoring but leaves us better able to
handle odd restrictions that controllers may have and with better
performance on smbus.
Other new features include:
- Fix interactions with lockdep for nested regmaps (eg, when a device
using regmap is connected to a bus where the bus controller has a
separate regmap). Lockdep's default class identification is too
crude to work without help.
- Support for must write bitfield operations, useful for operations
which require writing a bit to trigger them from Kuniori Morimoto.
- Support for delaying during register patch application from Nariman
Poushin.
- Support for overriding cache state via the debugfs implementation
from Richard Fitzgerald"
* tag 'regmap-v4.3' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap: (25 commits)
regmap: fix a NULL pointer dereference in __regmap_init
regmap: Support bulk reads for devices without raw formatting
regmap-i2c: Add smbus i2c block support
regmap: Add raw_write/read checks for max_raw_write/read sizes
regmap: regmap max_raw_read/write getter functions
regmap: Introduce max_raw_read/write for regmap_bulk_read/write
regmap: Add missing comments about struct regmap_bus
regmap: No multi_write support if bus->write does not exist
regmap: Split use_single_rw internally into use_single_read/write
regmap: Fix regmap_bulk_write for bus writes
regmap: regmap_raw_read return error on !bus->read
regulator: core: Print at debug level on debugfs creation failure
regmap: Fix regmap_can_raw_write check
regmap: fix typos in regmap.c
regmap: Fix integertypes for register address and value
regmap: Move documentation to regmap.h
regmap: Use different lockdep class for each regmap init call
thermal: sti: Add parentheses around bridge->ops->regmap_init call
mfd: vexpress: Add parentheses around bridge->ops->regmap_init call
regmap: debugfs: Fix misuse of IS_ENABLED
...
-rw-r--r-- | drivers/base/regmap/internal.h | 10 | ||||
-rw-r--r-- | drivers/base/regmap/regcache.c | 2 | ||||
-rw-r--r-- | drivers/base/regmap/regmap-ac97.c | 41 | ||||
-rw-r--r-- | drivers/base/regmap/regmap-debugfs.c | 99 | ||||
-rw-r--r-- | drivers/base/regmap/regmap-i2c.c | 90 | ||||
-rw-r--r-- | drivers/base/regmap/regmap-irq.c | 4 | ||||
-rw-r--r-- | drivers/base/regmap/regmap-mmio.c | 52 | ||||
-rw-r--r-- | drivers/base/regmap/regmap-spi.c | 41 | ||||
-rw-r--r-- | drivers/base/regmap/regmap-spmi.c | 78 | ||||
-rw-r--r-- | drivers/base/regmap/regmap.c | 295 | ||||
-rw-r--r-- | drivers/bus/vexpress-config.c | 2 | ||||
-rw-r--r-- | drivers/regulator/core.c | 2 | ||||
-rw-r--r-- | drivers/thermal/st/st_thermal.c | 2 | ||||
-rw-r--r-- | fs/debugfs/file.c | 14 | ||||
-rw-r--r-- | include/linux/debugfs.h | 20 | ||||
-rw-r--r-- | include/linux/regmap.h | 359 |
16 files changed, 808 insertions, 303 deletions
diff --git a/drivers/base/regmap/internal.h b/drivers/base/regmap/internal.h index 873ddf91c9d3..cc557886ab23 100644 --- a/drivers/base/regmap/internal.h +++ b/drivers/base/regmap/internal.h | |||
@@ -139,11 +139,17 @@ struct regmap { | |||
139 | struct reg_sequence *patch; | 139 | struct reg_sequence *patch; |
140 | int patch_regs; | 140 | int patch_regs; |
141 | 141 | ||
142 | /* if set, converts bulk rw to single rw */ | 142 | /* if set, converts bulk read to single read */ |
143 | bool use_single_rw; | 143 | bool use_single_read; |
144 | /* if set, converts bulk read to single read */ | ||
145 | bool use_single_write; | ||
144 | /* if set, the device supports multi write mode */ | 146 | /* if set, the device supports multi write mode */ |
145 | bool can_multi_write; | 147 | bool can_multi_write; |
146 | 148 | ||
149 | /* if set, raw reads/writes are limited to this size */ | ||
150 | size_t max_raw_read; | ||
151 | size_t max_raw_write; | ||
152 | |||
147 | struct rb_root range_tree; | 153 | struct rb_root range_tree; |
148 | void *selector_work_buf; /* Scratch buffer used for selector */ | 154 | void *selector_work_buf; /* Scratch buffer used for selector */ |
149 | }; | 155 | }; |
diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c index b9862d741a56..6f8a13ec32a4 100644 --- a/drivers/base/regmap/regcache.c +++ b/drivers/base/regmap/regcache.c | |||
@@ -729,7 +729,7 @@ int regcache_sync_block(struct regmap *map, void *block, | |||
729 | unsigned int block_base, unsigned int start, | 729 | unsigned int block_base, unsigned int start, |
730 | unsigned int end) | 730 | unsigned int end) |
731 | { | 731 | { |
732 | if (regmap_can_raw_write(map) && !map->use_single_rw) | 732 | if (regmap_can_raw_write(map) && !map->use_single_write) |
733 | return regcache_sync_block_raw(map, block, cache_present, | 733 | return regcache_sync_block_raw(map, block, cache_present, |
734 | block_base, start, end); | 734 | block_base, start, end); |
735 | else | 735 | else |
diff --git a/drivers/base/regmap/regmap-ac97.c b/drivers/base/regmap/regmap-ac97.c index 8d304e2a943d..c03ebfd4c731 100644 --- a/drivers/base/regmap/regmap-ac97.c +++ b/drivers/base/regmap/regmap-ac97.c | |||
@@ -78,37 +78,24 @@ static const struct regmap_bus ac97_regmap_bus = { | |||
78 | .reg_read = regmap_ac97_reg_read, | 78 | .reg_read = regmap_ac97_reg_read, |
79 | }; | 79 | }; |
80 | 80 | ||
81 | /** | 81 | struct regmap *__regmap_init_ac97(struct snd_ac97 *ac97, |
82 | * regmap_init_ac97(): Initialise AC'97 register map | 82 | const struct regmap_config *config, |
83 | * | 83 | struct lock_class_key *lock_key, |
84 | * @ac97: Device that will be interacted with | 84 | const char *lock_name) |
85 | * @config: Configuration for register map | ||
86 | * | ||
87 | * The return value will be an ERR_PTR() on error or a valid pointer to | ||
88 | * a struct regmap. | ||
89 | */ | ||
90 | struct regmap *regmap_init_ac97(struct snd_ac97 *ac97, | ||
91 | const struct regmap_config *config) | ||
92 | { | 85 | { |
93 | return regmap_init(&ac97->dev, &ac97_regmap_bus, ac97, config); | 86 | return __regmap_init(&ac97->dev, &ac97_regmap_bus, ac97, config, |
87 | lock_key, lock_name); | ||
94 | } | 88 | } |
95 | EXPORT_SYMBOL_GPL(regmap_init_ac97); | 89 | EXPORT_SYMBOL_GPL(__regmap_init_ac97); |
96 | 90 | ||
97 | /** | 91 | struct regmap *__devm_regmap_init_ac97(struct snd_ac97 *ac97, |
98 | * devm_regmap_init_ac97(): Initialise AC'97 register map | 92 | const struct regmap_config *config, |
99 | * | 93 | struct lock_class_key *lock_key, |
100 | * @ac97: Device that will be interacted with | 94 | const char *lock_name) |
101 | * @config: Configuration for register map | ||
102 | * | ||
103 | * The return value will be an ERR_PTR() on error or a valid pointer | ||
104 | * to a struct regmap. The regmap will be automatically freed by the | ||
105 | * device management code. | ||
106 | */ | ||
107 | struct regmap *devm_regmap_init_ac97(struct snd_ac97 *ac97, | ||
108 | const struct regmap_config *config) | ||
109 | { | 95 | { |
110 | return devm_regmap_init(&ac97->dev, &ac97_regmap_bus, ac97, config); | 96 | return __devm_regmap_init(&ac97->dev, &ac97_regmap_bus, ac97, config, |
97 | lock_key, lock_name); | ||
111 | } | 98 | } |
112 | EXPORT_SYMBOL_GPL(devm_regmap_init_ac97); | 99 | EXPORT_SYMBOL_GPL(__devm_regmap_init_ac97); |
113 | 100 | ||
114 | MODULE_LICENSE("GPL v2"); | 101 | MODULE_LICENSE("GPL v2"); |
diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c index 5799a0b9e6cc..f42f2bac6466 100644 --- a/drivers/base/regmap/regmap-debugfs.c +++ b/drivers/base/regmap/regmap-debugfs.c | |||
@@ -469,6 +469,87 @@ static const struct file_operations regmap_access_fops = { | |||
469 | .llseek = default_llseek, | 469 | .llseek = default_llseek, |
470 | }; | 470 | }; |
471 | 471 | ||
472 | static ssize_t regmap_cache_only_write_file(struct file *file, | ||
473 | const char __user *user_buf, | ||
474 | size_t count, loff_t *ppos) | ||
475 | { | ||
476 | struct regmap *map = container_of(file->private_data, | ||
477 | struct regmap, cache_only); | ||
478 | ssize_t result; | ||
479 | bool was_enabled, require_sync = false; | ||
480 | int err; | ||
481 | |||
482 | map->lock(map->lock_arg); | ||
483 | |||
484 | was_enabled = map->cache_only; | ||
485 | |||
486 | result = debugfs_write_file_bool(file, user_buf, count, ppos); | ||
487 | if (result < 0) { | ||
488 | map->unlock(map->lock_arg); | ||
489 | return result; | ||
490 | } | ||
491 | |||
492 | if (map->cache_only && !was_enabled) { | ||
493 | dev_warn(map->dev, "debugfs cache_only=Y forced\n"); | ||
494 | add_taint(TAINT_USER, LOCKDEP_STILL_OK); | ||
495 | } else if (!map->cache_only && was_enabled) { | ||
496 | dev_warn(map->dev, "debugfs cache_only=N forced: syncing cache\n"); | ||
497 | require_sync = true; | ||
498 | } | ||
499 | |||
500 | map->unlock(map->lock_arg); | ||
501 | |||
502 | if (require_sync) { | ||
503 | err = regcache_sync(map); | ||
504 | if (err) | ||
505 | dev_err(map->dev, "Failed to sync cache %d\n", err); | ||
506 | } | ||
507 | |||
508 | return result; | ||
509 | } | ||
510 | |||
511 | static const struct file_operations regmap_cache_only_fops = { | ||
512 | .open = simple_open, | ||
513 | .read = debugfs_read_file_bool, | ||
514 | .write = regmap_cache_only_write_file, | ||
515 | }; | ||
516 | |||
517 | static ssize_t regmap_cache_bypass_write_file(struct file *file, | ||
518 | const char __user *user_buf, | ||
519 | size_t count, loff_t *ppos) | ||
520 | { | ||
521 | struct regmap *map = container_of(file->private_data, | ||
522 | struct regmap, cache_bypass); | ||
523 | ssize_t result; | ||
524 | bool was_enabled; | ||
525 | |||
526 | map->lock(map->lock_arg); | ||
527 | |||
528 | was_enabled = map->cache_bypass; | ||
529 | |||
530 | result = debugfs_write_file_bool(file, user_buf, count, ppos); | ||
531 | if (result < 0) | ||
532 | goto out; | ||
533 | |||
534 | if (map->cache_bypass && !was_enabled) { | ||
535 | dev_warn(map->dev, "debugfs cache_bypass=Y forced\n"); | ||
536 | add_taint(TAINT_USER, LOCKDEP_STILL_OK); | ||
537 | } else if (!map->cache_bypass && was_enabled) { | ||
538 | dev_warn(map->dev, "debugfs cache_bypass=N forced\n"); | ||
539 | } | ||
540 | |||
541 | out: | ||
542 | map->unlock(map->lock_arg); | ||
543 | |||
544 | return result; | ||
545 | } | ||
546 | |||
547 | static const struct file_operations regmap_cache_bypass_fops = { | ||
548 | .open = simple_open, | ||
549 | .read = debugfs_read_file_bool, | ||
550 | .write = regmap_cache_bypass_write_file, | ||
551 | }; | ||
552 | |||
472 | void regmap_debugfs_init(struct regmap *map, const char *name) | 553 | void regmap_debugfs_init(struct regmap *map, const char *name) |
473 | { | 554 | { |
474 | struct rb_node *next; | 555 | struct rb_node *next; |
@@ -518,10 +599,11 @@ void regmap_debugfs_init(struct regmap *map, const char *name) | |||
518 | if (map->max_register || regmap_readable(map, 0)) { | 599 | if (map->max_register || regmap_readable(map, 0)) { |
519 | umode_t registers_mode; | 600 | umode_t registers_mode; |
520 | 601 | ||
521 | if (IS_ENABLED(REGMAP_ALLOW_WRITE_DEBUGFS)) | 602 | #if defined(REGMAP_ALLOW_WRITE_DEBUGFS) |
522 | registers_mode = 0600; | 603 | registers_mode = 0600; |
523 | else | 604 | #else |
524 | registers_mode = 0400; | 605 | registers_mode = 0400; |
606 | #endif | ||
525 | 607 | ||
526 | debugfs_create_file("registers", registers_mode, map->debugfs, | 608 | debugfs_create_file("registers", registers_mode, map->debugfs, |
527 | map, ®map_map_fops); | 609 | map, ®map_map_fops); |
@@ -530,12 +612,13 @@ void regmap_debugfs_init(struct regmap *map, const char *name) | |||
530 | } | 612 | } |
531 | 613 | ||
532 | if (map->cache_type) { | 614 | if (map->cache_type) { |
533 | debugfs_create_bool("cache_only", 0400, map->debugfs, | 615 | debugfs_create_file("cache_only", 0600, map->debugfs, |
534 | &map->cache_only); | 616 | &map->cache_only, ®map_cache_only_fops); |
535 | debugfs_create_bool("cache_dirty", 0400, map->debugfs, | 617 | debugfs_create_bool("cache_dirty", 0400, map->debugfs, |
536 | &map->cache_dirty); | 618 | &map->cache_dirty); |
537 | debugfs_create_bool("cache_bypass", 0400, map->debugfs, | 619 | debugfs_create_file("cache_bypass", 0600, map->debugfs, |
538 | &map->cache_bypass); | 620 | &map->cache_bypass, |
621 | ®map_cache_bypass_fops); | ||
539 | } | 622 | } |
540 | 623 | ||
541 | next = rb_first(&map->range_tree); | 624 | next = rb_first(&map->range_tree); |
diff --git a/drivers/base/regmap/regmap-i2c.c b/drivers/base/regmap/regmap-i2c.c index 4b76e33110a2..1a8ec3b2b601 100644 --- a/drivers/base/regmap/regmap-i2c.c +++ b/drivers/base/regmap/regmap-i2c.c | |||
@@ -209,11 +209,60 @@ static struct regmap_bus regmap_i2c = { | |||
209 | .val_format_endian_default = REGMAP_ENDIAN_BIG, | 209 | .val_format_endian_default = REGMAP_ENDIAN_BIG, |
210 | }; | 210 | }; |
211 | 211 | ||
212 | static int regmap_i2c_smbus_i2c_write(void *context, const void *data, | ||
213 | size_t count) | ||
214 | { | ||
215 | struct device *dev = context; | ||
216 | struct i2c_client *i2c = to_i2c_client(dev); | ||
217 | |||
218 | if (count < 1) | ||
219 | return -EINVAL; | ||
220 | if (count >= I2C_SMBUS_BLOCK_MAX) | ||
221 | return -E2BIG; | ||
222 | |||
223 | --count; | ||
224 | return i2c_smbus_write_i2c_block_data(i2c, ((u8 *)data)[0], count, | ||
225 | ((u8 *)data + 1)); | ||
226 | } | ||
227 | |||
228 | static int regmap_i2c_smbus_i2c_read(void *context, const void *reg, | ||
229 | size_t reg_size, void *val, | ||
230 | size_t val_size) | ||
231 | { | ||
232 | struct device *dev = context; | ||
233 | struct i2c_client *i2c = to_i2c_client(dev); | ||
234 | int ret; | ||
235 | |||
236 | if (reg_size != 1 || val_size < 1) | ||
237 | return -EINVAL; | ||
238 | if (val_size >= I2C_SMBUS_BLOCK_MAX) | ||
239 | return -E2BIG; | ||
240 | |||
241 | ret = i2c_smbus_read_i2c_block_data(i2c, ((u8 *)reg)[0], val_size, val); | ||
242 | if (ret == val_size) | ||
243 | return 0; | ||
244 | else if (ret < 0) | ||
245 | return ret; | ||
246 | else | ||
247 | return -EIO; | ||
248 | } | ||
249 | |||
250 | static struct regmap_bus regmap_i2c_smbus_i2c_block = { | ||
251 | .write = regmap_i2c_smbus_i2c_write, | ||
252 | .read = regmap_i2c_smbus_i2c_read, | ||
253 | .max_raw_read = I2C_SMBUS_BLOCK_MAX, | ||
254 | .max_raw_write = I2C_SMBUS_BLOCK_MAX, | ||
255 | }; | ||
256 | |||
212 | static const struct regmap_bus *regmap_get_i2c_bus(struct i2c_client *i2c, | 257 | static const struct regmap_bus *regmap_get_i2c_bus(struct i2c_client *i2c, |
213 | const struct regmap_config *config) | 258 | const struct regmap_config *config) |
214 | { | 259 | { |
215 | if (i2c_check_functionality(i2c->adapter, I2C_FUNC_I2C)) | 260 | if (i2c_check_functionality(i2c->adapter, I2C_FUNC_I2C)) |
216 | return ®map_i2c; | 261 | return ®map_i2c; |
262 | else if (config->reg_bits == 8 && | ||
263 | i2c_check_functionality(i2c->adapter, | ||
264 | I2C_FUNC_SMBUS_I2C_BLOCK)) | ||
265 | return ®map_i2c_smbus_i2c_block; | ||
217 | else if (config->val_bits == 16 && config->reg_bits == 8 && | 266 | else if (config->val_bits == 16 && config->reg_bits == 8 && |
218 | i2c_check_functionality(i2c->adapter, | 267 | i2c_check_functionality(i2c->adapter, |
219 | I2C_FUNC_SMBUS_WORD_DATA)) | 268 | I2C_FUNC_SMBUS_WORD_DATA)) |
@@ -233,47 +282,34 @@ static const struct regmap_bus *regmap_get_i2c_bus(struct i2c_client *i2c, | |||
233 | return ERR_PTR(-ENOTSUPP); | 282 | return ERR_PTR(-ENOTSUPP); |
234 | } | 283 | } |
235 | 284 | ||
236 | /** | 285 | struct regmap *__regmap_init_i2c(struct i2c_client *i2c, |
237 | * regmap_init_i2c(): Initialise register map | 286 | const struct regmap_config *config, |
238 | * | 287 | struct lock_class_key *lock_key, |
239 | * @i2c: Device that will be interacted with | 288 | const char *lock_name) |
240 | * @config: Configuration for register map | ||
241 | * | ||
242 | * The return value will be an ERR_PTR() on error or a valid pointer to | ||
243 | * a struct regmap. | ||
244 | */ | ||
245 | struct regmap *regmap_init_i2c(struct i2c_client *i2c, | ||
246 | const struct regmap_config *config) | ||
247 | { | 289 | { |
248 | const struct regmap_bus *bus = regmap_get_i2c_bus(i2c, config); | 290 | const struct regmap_bus *bus = regmap_get_i2c_bus(i2c, config); |
249 | 291 | ||
250 | if (IS_ERR(bus)) | 292 | if (IS_ERR(bus)) |
251 | return ERR_CAST(bus); | 293 | return ERR_CAST(bus); |
252 | 294 | ||
253 | return regmap_init(&i2c->dev, bus, &i2c->dev, config); | 295 | return __regmap_init(&i2c->dev, bus, &i2c->dev, config, |
296 | lock_key, lock_name); | ||
254 | } | 297 | } |
255 | EXPORT_SYMBOL_GPL(regmap_init_i2c); | 298 | EXPORT_SYMBOL_GPL(__regmap_init_i2c); |
256 | 299 | ||
257 | /** | 300 | struct regmap *__devm_regmap_init_i2c(struct i2c_client *i2c, |
258 | * devm_regmap_init_i2c(): Initialise managed register map | 301 | const struct regmap_config *config, |
259 | * | 302 | struct lock_class_key *lock_key, |
260 | * @i2c: Device that will be interacted with | 303 | const char *lock_name) |
261 | * @config: Configuration for register map | ||
262 | * | ||
263 | * The return value will be an ERR_PTR() on error or a valid pointer | ||
264 | * to a struct regmap. The regmap will be automatically freed by the | ||
265 | * device management code. | ||
266 | */ | ||
267 | struct regmap *devm_regmap_init_i2c(struct i2c_client *i2c, | ||
268 | const struct regmap_config *config) | ||
269 | { | 304 | { |
270 | const struct regmap_bus *bus = regmap_get_i2c_bus(i2c, config); | 305 | const struct regmap_bus *bus = regmap_get_i2c_bus(i2c, config); |
271 | 306 | ||
272 | if (IS_ERR(bus)) | 307 | if (IS_ERR(bus)) |
273 | return ERR_CAST(bus); | 308 | return ERR_CAST(bus); |
274 | 309 | ||
275 | return devm_regmap_init(&i2c->dev, bus, &i2c->dev, config); | 310 | return __devm_regmap_init(&i2c->dev, bus, &i2c->dev, config, |
311 | lock_key, lock_name); | ||
276 | } | 312 | } |
277 | EXPORT_SYMBOL_GPL(devm_regmap_init_i2c); | 313 | EXPORT_SYMBOL_GPL(__devm_regmap_init_i2c); |
278 | 314 | ||
279 | MODULE_LICENSE("GPL"); | 315 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/base/regmap/regmap-irq.c b/drivers/base/regmap/regmap-irq.c index 2597600a5d26..38d1f72d869c 100644 --- a/drivers/base/regmap/regmap-irq.c +++ b/drivers/base/regmap/regmap-irq.c | |||
@@ -209,7 +209,7 @@ static irqreturn_t regmap_irq_thread(int irq, void *d) | |||
209 | * Read in the statuses, using a single bulk read if possible | 209 | * Read in the statuses, using a single bulk read if possible |
210 | * in order to reduce the I/O overheads. | 210 | * in order to reduce the I/O overheads. |
211 | */ | 211 | */ |
212 | if (!map->use_single_rw && map->reg_stride == 1 && | 212 | if (!map->use_single_read && map->reg_stride == 1 && |
213 | data->irq_reg_stride == 1) { | 213 | data->irq_reg_stride == 1) { |
214 | u8 *buf8 = data->status_reg_buf; | 214 | u8 *buf8 = data->status_reg_buf; |
215 | u16 *buf16 = data->status_reg_buf; | 215 | u16 *buf16 = data->status_reg_buf; |
@@ -398,7 +398,7 @@ int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags, | |||
398 | else | 398 | else |
399 | d->irq_reg_stride = 1; | 399 | d->irq_reg_stride = 1; |
400 | 400 | ||
401 | if (!map->use_single_rw && map->reg_stride == 1 && | 401 | if (!map->use_single_read && map->reg_stride == 1 && |
402 | d->irq_reg_stride == 1) { | 402 | d->irq_reg_stride == 1) { |
403 | d->status_reg_buf = kmalloc(map->format.val_bytes * | 403 | d->status_reg_buf = kmalloc(map->format.val_bytes * |
404 | chip->num_regs, GFP_KERNEL); | 404 | chip->num_regs, GFP_KERNEL); |
diff --git a/drivers/base/regmap/regmap-mmio.c b/drivers/base/regmap/regmap-mmio.c index 04a329a377e9..426a57e41ac7 100644 --- a/drivers/base/regmap/regmap-mmio.c +++ b/drivers/base/regmap/regmap-mmio.c | |||
@@ -296,20 +296,11 @@ err_free: | |||
296 | return ERR_PTR(ret); | 296 | return ERR_PTR(ret); |
297 | } | 297 | } |
298 | 298 | ||
299 | /** | 299 | struct regmap *__regmap_init_mmio_clk(struct device *dev, const char *clk_id, |
300 | * regmap_init_mmio_clk(): Initialise register map with register clock | 300 | void __iomem *regs, |
301 | * | 301 | const struct regmap_config *config, |
302 | * @dev: Device that will be interacted with | 302 | struct lock_class_key *lock_key, |
303 | * @clk_id: register clock consumer ID | 303 | const char *lock_name) |
304 | * @regs: Pointer to memory-mapped IO region | ||
305 | * @config: Configuration for register map | ||
306 | * | ||
307 | * The return value will be an ERR_PTR() on error or a valid pointer to | ||
308 | * a struct regmap. | ||
309 | */ | ||
310 | struct regmap *regmap_init_mmio_clk(struct device *dev, const char *clk_id, | ||
311 | void __iomem *regs, | ||
312 | const struct regmap_config *config) | ||
313 | { | 304 | { |
314 | struct regmap_mmio_context *ctx; | 305 | struct regmap_mmio_context *ctx; |
315 | 306 | ||
@@ -317,25 +308,17 @@ struct regmap *regmap_init_mmio_clk(struct device *dev, const char *clk_id, | |||
317 | if (IS_ERR(ctx)) | 308 | if (IS_ERR(ctx)) |
318 | return ERR_CAST(ctx); | 309 | return ERR_CAST(ctx); |
319 | 310 | ||
320 | return regmap_init(dev, ®map_mmio, ctx, config); | 311 | return __regmap_init(dev, ®map_mmio, ctx, config, |
312 | lock_key, lock_name); | ||
321 | } | 313 | } |
322 | EXPORT_SYMBOL_GPL(regmap_init_mmio_clk); | 314 | EXPORT_SYMBOL_GPL(__regmap_init_mmio_clk); |
323 | 315 | ||
324 | /** | 316 | struct regmap *__devm_regmap_init_mmio_clk(struct device *dev, |
325 | * devm_regmap_init_mmio_clk(): Initialise managed register map with clock | 317 | const char *clk_id, |
326 | * | 318 | void __iomem *regs, |
327 | * @dev: Device that will be interacted with | 319 | const struct regmap_config *config, |
328 | * @clk_id: register clock consumer ID | 320 | struct lock_class_key *lock_key, |
329 | * @regs: Pointer to memory-mapped IO region | 321 | const char *lock_name) |
330 | * @config: Configuration for register map | ||
331 | * | ||
332 | * The return value will be an ERR_PTR() on error or a valid pointer | ||
333 | * to a struct regmap. The regmap will be automatically freed by the | ||
334 | * device management code. | ||
335 | */ | ||
336 | struct regmap *devm_regmap_init_mmio_clk(struct device *dev, const char *clk_id, | ||
337 | void __iomem *regs, | ||
338 | const struct regmap_config *config) | ||
339 | { | 322 | { |
340 | struct regmap_mmio_context *ctx; | 323 | struct regmap_mmio_context *ctx; |
341 | 324 | ||
@@ -343,8 +326,9 @@ struct regmap *devm_regmap_init_mmio_clk(struct device *dev, const char *clk_id, | |||
343 | if (IS_ERR(ctx)) | 326 | if (IS_ERR(ctx)) |
344 | return ERR_CAST(ctx); | 327 | return ERR_CAST(ctx); |
345 | 328 | ||
346 | return devm_regmap_init(dev, ®map_mmio, ctx, config); | 329 | return __devm_regmap_init(dev, ®map_mmio, ctx, config, |
330 | lock_key, lock_name); | ||
347 | } | 331 | } |
348 | EXPORT_SYMBOL_GPL(devm_regmap_init_mmio_clk); | 332 | EXPORT_SYMBOL_GPL(__devm_regmap_init_mmio_clk); |
349 | 333 | ||
350 | MODULE_LICENSE("GPL v2"); | 334 | MODULE_LICENSE("GPL v2"); |
diff --git a/drivers/base/regmap/regmap-spi.c b/drivers/base/regmap/regmap-spi.c index 53d1148e80a0..edd9a839d004 100644 --- a/drivers/base/regmap/regmap-spi.c +++ b/drivers/base/regmap/regmap-spi.c | |||
@@ -113,37 +113,24 @@ static struct regmap_bus regmap_spi = { | |||
113 | .val_format_endian_default = REGMAP_ENDIAN_BIG, | 113 | .val_format_endian_default = REGMAP_ENDIAN_BIG, |
114 | }; | 114 | }; |
115 | 115 | ||
116 | /** | 116 | struct regmap *__regmap_init_spi(struct spi_device *spi, |
117 | * regmap_init_spi(): Initialise register map | 117 | const struct regmap_config *config, |
118 | * | 118 | struct lock_class_key *lock_key, |
119 | * @spi: Device that will be interacted with | 119 | const char *lock_name) |
120 | * @config: Configuration for register map | ||
121 | * | ||
122 | * The return value will be an ERR_PTR() on error or a valid pointer to | ||
123 | * a struct regmap. | ||
124 | */ | ||
125 | struct regmap *regmap_init_spi(struct spi_device *spi, | ||
126 | const struct regmap_config *config) | ||
127 | { | 120 | { |
128 | return regmap_init(&spi->dev, ®map_spi, &spi->dev, config); | 121 | return __regmap_init(&spi->dev, ®map_spi, &spi->dev, config, |
122 | lock_key, lock_name); | ||
129 | } | 123 | } |
130 | EXPORT_SYMBOL_GPL(regmap_init_spi); | 124 | EXPORT_SYMBOL_GPL(__regmap_init_spi); |
131 | 125 | ||
132 | /** | 126 | struct regmap *__devm_regmap_init_spi(struct spi_device *spi, |
133 | * devm_regmap_init_spi(): Initialise register map | 127 | const struct regmap_config *config, |
134 | * | 128 | struct lock_class_key *lock_key, |
135 | * @spi: Device that will be interacted with | 129 | const char *lock_name) |
136 | * @config: Configuration for register map | ||
137 | * | ||
138 | * The return value will be an ERR_PTR() on error or a valid pointer | ||
139 | * to a struct regmap. The map will be automatically freed by the | ||
140 | * device management code. | ||
141 | */ | ||
142 | struct regmap *devm_regmap_init_spi(struct spi_device *spi, | ||
143 | const struct regmap_config *config) | ||
144 | { | 130 | { |
145 | return devm_regmap_init(&spi->dev, ®map_spi, &spi->dev, config); | 131 | return __devm_regmap_init(&spi->dev, ®map_spi, &spi->dev, config, |
132 | lock_key, lock_name); | ||
146 | } | 133 | } |
147 | EXPORT_SYMBOL_GPL(devm_regmap_init_spi); | 134 | EXPORT_SYMBOL_GPL(__devm_regmap_init_spi); |
148 | 135 | ||
149 | MODULE_LICENSE("GPL"); | 136 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/base/regmap/regmap-spmi.c b/drivers/base/regmap/regmap-spmi.c index d7026dc33388..7e58f6560399 100644 --- a/drivers/base/regmap/regmap-spmi.c +++ b/drivers/base/regmap/regmap-spmi.c | |||
@@ -91,36 +91,25 @@ static struct regmap_bus regmap_spmi_base = { | |||
91 | .val_format_endian_default = REGMAP_ENDIAN_NATIVE, | 91 | .val_format_endian_default = REGMAP_ENDIAN_NATIVE, |
92 | }; | 92 | }; |
93 | 93 | ||
94 | /** | 94 | struct regmap *__regmap_init_spmi_base(struct spmi_device *sdev, |
95 | * regmap_init_spmi_base(): Create regmap for the Base register space | 95 | const struct regmap_config *config, |
96 | * @sdev: SPMI device that will be interacted with | 96 | struct lock_class_key *lock_key, |
97 | * @config: Configuration for register map | 97 | const char *lock_name) |
98 | * | ||
99 | * The return value will be an ERR_PTR() on error or a valid pointer to | ||
100 | * a struct regmap. | ||
101 | */ | ||
102 | struct regmap *regmap_init_spmi_base(struct spmi_device *sdev, | ||
103 | const struct regmap_config *config) | ||
104 | { | 98 | { |
105 | return regmap_init(&sdev->dev, ®map_spmi_base, sdev, config); | 99 | return __regmap_init(&sdev->dev, ®map_spmi_base, sdev, config, |
100 | lock_key, lock_name); | ||
106 | } | 101 | } |
107 | EXPORT_SYMBOL_GPL(regmap_init_spmi_base); | 102 | EXPORT_SYMBOL_GPL(__regmap_init_spmi_base); |
108 | 103 | ||
109 | /** | 104 | struct regmap *__devm_regmap_init_spmi_base(struct spmi_device *sdev, |
110 | * devm_regmap_init_spmi_base(): Create managed regmap for Base register space | 105 | const struct regmap_config *config, |
111 | * @sdev: SPMI device that will be interacted with | 106 | struct lock_class_key *lock_key, |
112 | * @config: Configuration for register map | 107 | const char *lock_name) |
113 | * | ||
114 | * The return value will be an ERR_PTR() on error or a valid pointer | ||
115 | * to a struct regmap. The regmap will be automatically freed by the | ||
116 | * device management code. | ||
117 | */ | ||
118 | struct regmap *devm_regmap_init_spmi_base(struct spmi_device *sdev, | ||
119 | const struct regmap_config *config) | ||
120 | { | 108 | { |
121 | return devm_regmap_init(&sdev->dev, ®map_spmi_base, sdev, config); | 109 | return __devm_regmap_init(&sdev->dev, ®map_spmi_base, sdev, config, |
110 | lock_key, lock_name); | ||
122 | } | 111 | } |
123 | EXPORT_SYMBOL_GPL(devm_regmap_init_spmi_base); | 112 | EXPORT_SYMBOL_GPL(__devm_regmap_init_spmi_base); |
124 | 113 | ||
125 | static int regmap_spmi_ext_read(void *context, | 114 | static int regmap_spmi_ext_read(void *context, |
126 | const void *reg, size_t reg_size, | 115 | const void *reg, size_t reg_size, |
@@ -222,35 +211,24 @@ static struct regmap_bus regmap_spmi_ext = { | |||
222 | .val_format_endian_default = REGMAP_ENDIAN_NATIVE, | 211 | .val_format_endian_default = REGMAP_ENDIAN_NATIVE, |
223 | }; | 212 | }; |
224 | 213 | ||
225 | /** | 214 | struct regmap *__regmap_init_spmi_ext(struct spmi_device *sdev, |
226 | * regmap_init_spmi_ext(): Create regmap for Ext register space | 215 | const struct regmap_config *config, |
227 | * @sdev: Device that will be interacted with | 216 | struct lock_class_key *lock_key, |
228 | * @config: Configuration for register map | 217 | const char *lock_name) |
229 | * | ||
230 | * The return value will be an ERR_PTR() on error or a valid pointer to | ||
231 | * a struct regmap. | ||
232 | */ | ||
233 | struct regmap *regmap_init_spmi_ext(struct spmi_device *sdev, | ||
234 | const struct regmap_config *config) | ||
235 | { | 218 | { |
236 | return regmap_init(&sdev->dev, ®map_spmi_ext, sdev, config); | 219 | return __regmap_init(&sdev->dev, ®map_spmi_ext, sdev, config, |
220 | lock_key, lock_name); | ||
237 | } | 221 | } |
238 | EXPORT_SYMBOL_GPL(regmap_init_spmi_ext); | 222 | EXPORT_SYMBOL_GPL(__regmap_init_spmi_ext); |
239 | 223 | ||
240 | /** | 224 | struct regmap *__devm_regmap_init_spmi_ext(struct spmi_device *sdev, |
241 | * devm_regmap_init_spmi_ext(): Create managed regmap for Ext register space | 225 | const struct regmap_config *config, |
242 | * @sdev: SPMI device that will be interacted with | 226 | struct lock_class_key *lock_key, |
243 | * @config: Configuration for register map | 227 | const char *lock_name) |
244 | * | ||
245 | * The return value will be an ERR_PTR() on error or a valid pointer | ||
246 | * to a struct regmap. The regmap will be automatically freed by the | ||
247 | * device management code. | ||
248 | */ | ||
249 | struct regmap *devm_regmap_init_spmi_ext(struct spmi_device *sdev, | ||
250 | const struct regmap_config *config) | ||
251 | { | 228 | { |
252 | return devm_regmap_init(&sdev->dev, ®map_spmi_ext, sdev, config); | 229 | return __devm_regmap_init(&sdev->dev, ®map_spmi_ext, sdev, config, |
230 | lock_key, lock_name); | ||
253 | } | 231 | } |
254 | EXPORT_SYMBOL_GPL(devm_regmap_init_spmi_ext); | 232 | EXPORT_SYMBOL_GPL(__devm_regmap_init_spmi_ext); |
255 | 233 | ||
256 | MODULE_LICENSE("GPL"); | 234 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index 0a849eeaf952..afaf56200674 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <linux/of.h> | 18 | #include <linux/of.h> |
19 | #include <linux/rbtree.h> | 19 | #include <linux/rbtree.h> |
20 | #include <linux/sched.h> | 20 | #include <linux/sched.h> |
21 | #include <linux/delay.h> | ||
21 | 22 | ||
22 | #define CREATE_TRACE_POINTS | 23 | #define CREATE_TRACE_POINTS |
23 | #include "trace.h" | 24 | #include "trace.h" |
@@ -93,6 +94,9 @@ bool regmap_writeable(struct regmap *map, unsigned int reg) | |||
93 | 94 | ||
94 | bool regmap_readable(struct regmap *map, unsigned int reg) | 95 | bool regmap_readable(struct regmap *map, unsigned int reg) |
95 | { | 96 | { |
97 | if (!map->reg_read) | ||
98 | return false; | ||
99 | |||
96 | if (map->max_register && reg > map->max_register) | 100 | if (map->max_register && reg > map->max_register) |
97 | return false; | 101 | return false; |
98 | 102 | ||
@@ -515,22 +519,12 @@ enum regmap_endian regmap_get_val_endian(struct device *dev, | |||
515 | } | 519 | } |
516 | EXPORT_SYMBOL_GPL(regmap_get_val_endian); | 520 | EXPORT_SYMBOL_GPL(regmap_get_val_endian); |
517 | 521 | ||
518 | /** | 522 | struct regmap *__regmap_init(struct device *dev, |
519 | * regmap_init(): Initialise register map | 523 | const struct regmap_bus *bus, |
520 | * | 524 | void *bus_context, |
521 | * @dev: Device that will be interacted with | 525 | const struct regmap_config *config, |
522 | * @bus: Bus-specific callbacks to use with device | 526 | struct lock_class_key *lock_key, |
523 | * @bus_context: Data passed to bus-specific callbacks | 527 | const char *lock_name) |
524 | * @config: Configuration for register map | ||
525 | * | ||
526 | * The return value will be an ERR_PTR() on error or a valid pointer to | ||
527 | * a struct regmap. This function should generally not be called | ||
528 | * directly, it should be called by bus-specific init functions. | ||
529 | */ | ||
530 | struct regmap *regmap_init(struct device *dev, | ||
531 | const struct regmap_bus *bus, | ||
532 | void *bus_context, | ||
533 | const struct regmap_config *config) | ||
534 | { | 528 | { |
535 | struct regmap *map; | 529 | struct regmap *map; |
536 | int ret = -EINVAL; | 530 | int ret = -EINVAL; |
@@ -556,10 +550,14 @@ struct regmap *regmap_init(struct device *dev, | |||
556 | spin_lock_init(&map->spinlock); | 550 | spin_lock_init(&map->spinlock); |
557 | map->lock = regmap_lock_spinlock; | 551 | map->lock = regmap_lock_spinlock; |
558 | map->unlock = regmap_unlock_spinlock; | 552 | map->unlock = regmap_unlock_spinlock; |
553 | lockdep_set_class_and_name(&map->spinlock, | ||
554 | lock_key, lock_name); | ||
559 | } else { | 555 | } else { |
560 | mutex_init(&map->mutex); | 556 | mutex_init(&map->mutex); |
561 | map->lock = regmap_lock_mutex; | 557 | map->lock = regmap_lock_mutex; |
562 | map->unlock = regmap_unlock_mutex; | 558 | map->unlock = regmap_unlock_mutex; |
559 | lockdep_set_class_and_name(&map->mutex, | ||
560 | lock_key, lock_name); | ||
563 | } | 561 | } |
564 | map->lock_arg = map; | 562 | map->lock_arg = map; |
565 | } | 563 | } |
@@ -573,8 +571,13 @@ struct regmap *regmap_init(struct device *dev, | |||
573 | map->reg_stride = config->reg_stride; | 571 | map->reg_stride = config->reg_stride; |
574 | else | 572 | else |
575 | map->reg_stride = 1; | 573 | map->reg_stride = 1; |
576 | map->use_single_rw = config->use_single_rw; | 574 | map->use_single_read = config->use_single_rw || !bus || !bus->read; |
577 | map->can_multi_write = config->can_multi_write; | 575 | map->use_single_write = config->use_single_rw || !bus || !bus->write; |
576 | map->can_multi_write = config->can_multi_write && bus && bus->write; | ||
577 | if (bus) { | ||
578 | map->max_raw_read = bus->max_raw_read; | ||
579 | map->max_raw_write = bus->max_raw_write; | ||
580 | } | ||
578 | map->dev = dev; | 581 | map->dev = dev; |
579 | map->bus = bus; | 582 | map->bus = bus; |
580 | map->bus_context = bus_context; | 583 | map->bus_context = bus_context; |
@@ -763,7 +766,7 @@ struct regmap *regmap_init(struct device *dev, | |||
763 | if ((reg_endian != REGMAP_ENDIAN_BIG) || | 766 | if ((reg_endian != REGMAP_ENDIAN_BIG) || |
764 | (val_endian != REGMAP_ENDIAN_BIG)) | 767 | (val_endian != REGMAP_ENDIAN_BIG)) |
765 | goto err_map; | 768 | goto err_map; |
766 | map->use_single_rw = true; | 769 | map->use_single_write = true; |
767 | } | 770 | } |
768 | 771 | ||
769 | if (!map->format.format_write && | 772 | if (!map->format.format_write && |
@@ -899,30 +902,19 @@ err_map: | |||
899 | err: | 902 | err: |
900 | return ERR_PTR(ret); | 903 | return ERR_PTR(ret); |
901 | } | 904 | } |
902 | EXPORT_SYMBOL_GPL(regmap_init); | 905 | EXPORT_SYMBOL_GPL(__regmap_init); |
903 | 906 | ||
904 | static void devm_regmap_release(struct device *dev, void *res) | 907 | static void devm_regmap_release(struct device *dev, void *res) |
905 | { | 908 | { |
906 | regmap_exit(*(struct regmap **)res); | 909 | regmap_exit(*(struct regmap **)res); |
907 | } | 910 | } |
908 | 911 | ||
909 | /** | 912 | struct regmap *__devm_regmap_init(struct device *dev, |
910 | * devm_regmap_init(): Initialise managed register map | 913 | const struct regmap_bus *bus, |
911 | * | 914 | void *bus_context, |
912 | * @dev: Device that will be interacted with | 915 | const struct regmap_config *config, |
913 | * @bus: Bus-specific callbacks to use with device | 916 | struct lock_class_key *lock_key, |
914 | * @bus_context: Data passed to bus-specific callbacks | 917 | const char *lock_name) |
915 | * @config: Configuration for register map | ||
916 | * | ||
917 | * The return value will be an ERR_PTR() on error or a valid pointer | ||
918 | * to a struct regmap. This function should generally not be called | ||
919 | * directly, it should be called by bus-specific init functions. The | ||
920 | * map will be automatically freed by the device management code. | ||
921 | */ | ||
922 | struct regmap *devm_regmap_init(struct device *dev, | ||
923 | const struct regmap_bus *bus, | ||
924 | void *bus_context, | ||
925 | const struct regmap_config *config) | ||
926 | { | 918 | { |
927 | struct regmap **ptr, *regmap; | 919 | struct regmap **ptr, *regmap; |
928 | 920 | ||
@@ -930,7 +922,8 @@ struct regmap *devm_regmap_init(struct device *dev, | |||
930 | if (!ptr) | 922 | if (!ptr) |
931 | return ERR_PTR(-ENOMEM); | 923 | return ERR_PTR(-ENOMEM); |
932 | 924 | ||
933 | regmap = regmap_init(dev, bus, bus_context, config); | 925 | regmap = __regmap_init(dev, bus, bus_context, config, |
926 | lock_key, lock_name); | ||
934 | if (!IS_ERR(regmap)) { | 927 | if (!IS_ERR(regmap)) { |
935 | *ptr = regmap; | 928 | *ptr = regmap; |
936 | devres_add(dev, ptr); | 929 | devres_add(dev, ptr); |
@@ -940,7 +933,7 @@ struct regmap *devm_regmap_init(struct device *dev, | |||
940 | 933 | ||
941 | return regmap; | 934 | return regmap; |
942 | } | 935 | } |
943 | EXPORT_SYMBOL_GPL(devm_regmap_init); | 936 | EXPORT_SYMBOL_GPL(__devm_regmap_init); |
944 | 937 | ||
945 | static void regmap_field_init(struct regmap_field *rm_field, | 938 | static void regmap_field_init(struct regmap_field *rm_field, |
946 | struct regmap *regmap, struct reg_field reg_field) | 939 | struct regmap *regmap, struct reg_field reg_field) |
@@ -1382,10 +1375,33 @@ int _regmap_raw_write(struct regmap *map, unsigned int reg, | |||
1382 | */ | 1375 | */ |
1383 | bool regmap_can_raw_write(struct regmap *map) | 1376 | bool regmap_can_raw_write(struct regmap *map) |
1384 | { | 1377 | { |
1385 | return map->bus && map->format.format_val && map->format.format_reg; | 1378 | return map->bus && map->bus->write && map->format.format_val && |
1379 | map->format.format_reg; | ||
1386 | } | 1380 | } |
1387 | EXPORT_SYMBOL_GPL(regmap_can_raw_write); | 1381 | EXPORT_SYMBOL_GPL(regmap_can_raw_write); |
1388 | 1382 | ||
1383 | /** | ||
1384 | * regmap_get_raw_read_max - Get the maximum size we can read | ||
1385 | * | ||
1386 | * @map: Map to check. | ||
1387 | */ | ||
1388 | size_t regmap_get_raw_read_max(struct regmap *map) | ||
1389 | { | ||
1390 | return map->max_raw_read; | ||
1391 | } | ||
1392 | EXPORT_SYMBOL_GPL(regmap_get_raw_read_max); | ||
1393 | |||
1394 | /** | ||
1395 | * regmap_get_raw_write_max - Get the maximum size we can read | ||
1396 | * | ||
1397 | * @map: Map to check. | ||
1398 | */ | ||
1399 | size_t regmap_get_raw_write_max(struct regmap *map) | ||
1400 | { | ||
1401 | return map->max_raw_write; | ||
1402 | } | ||
1403 | EXPORT_SYMBOL_GPL(regmap_get_raw_write_max); | ||
1404 | |||
1389 | static int _regmap_bus_formatted_write(void *context, unsigned int reg, | 1405 | static int _regmap_bus_formatted_write(void *context, unsigned int reg, |
1390 | unsigned int val) | 1406 | unsigned int val) |
1391 | { | 1407 | { |
@@ -1555,6 +1571,8 @@ int regmap_raw_write(struct regmap *map, unsigned int reg, | |||
1555 | return -EINVAL; | 1571 | return -EINVAL; |
1556 | if (val_len % map->format.val_bytes) | 1572 | if (val_len % map->format.val_bytes) |
1557 | return -EINVAL; | 1573 | return -EINVAL; |
1574 | if (map->max_raw_write && map->max_raw_write > val_len) | ||
1575 | return -E2BIG; | ||
1558 | 1576 | ||
1559 | map->lock(map->lock_arg); | 1577 | map->lock(map->lock_arg); |
1560 | 1578 | ||
@@ -1681,6 +1699,7 @@ int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val, | |||
1681 | { | 1699 | { |
1682 | int ret = 0, i; | 1700 | int ret = 0, i; |
1683 | size_t val_bytes = map->format.val_bytes; | 1701 | size_t val_bytes = map->format.val_bytes; |
1702 | size_t total_size = val_bytes * val_count; | ||
1684 | 1703 | ||
1685 | if (map->bus && !map->format.parse_inplace) | 1704 | if (map->bus && !map->format.parse_inplace) |
1686 | return -EINVAL; | 1705 | return -EINVAL; |
@@ -1689,9 +1708,15 @@ int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val, | |||
1689 | 1708 | ||
1690 | /* | 1709 | /* |
1691 | * Some devices don't support bulk write, for | 1710 | * Some devices don't support bulk write, for |
1692 | * them we have a series of single write operations. | 1711 | * them we have a series of single write operations in the first two if |
1712 | * blocks. | ||
1713 | * | ||
1714 | * The first if block is used for memory mapped io. It does not allow | ||
1715 | * val_bytes of 3 for example. | ||
1716 | * The second one is used for busses which do not have this limitation | ||
1717 | * and can write arbitrary value lengths. | ||
1693 | */ | 1718 | */ |
1694 | if (!map->bus || map->use_single_rw) { | 1719 | if (!map->bus) { |
1695 | map->lock(map->lock_arg); | 1720 | map->lock(map->lock_arg); |
1696 | for (i = 0; i < val_count; i++) { | 1721 | for (i = 0; i < val_count; i++) { |
1697 | unsigned int ival; | 1722 | unsigned int ival; |
@@ -1723,6 +1748,38 @@ int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val, | |||
1723 | } | 1748 | } |
1724 | out: | 1749 | out: |
1725 | map->unlock(map->lock_arg); | 1750 | map->unlock(map->lock_arg); |
1751 | } else if (map->use_single_write || | ||
1752 | (map->max_raw_write && map->max_raw_write < total_size)) { | ||
1753 | int chunk_stride = map->reg_stride; | ||
1754 | size_t chunk_size = val_bytes; | ||
1755 | size_t chunk_count = val_count; | ||
1756 | |||
1757 | if (!map->use_single_write) { | ||
1758 | chunk_size = map->max_raw_write; | ||
1759 | if (chunk_size % val_bytes) | ||
1760 | chunk_size -= chunk_size % val_bytes; | ||
1761 | chunk_count = total_size / chunk_size; | ||
1762 | chunk_stride *= chunk_size / val_bytes; | ||
1763 | } | ||
1764 | |||
1765 | map->lock(map->lock_arg); | ||
1766 | /* Write as many bytes as possible with chunk_size */ | ||
1767 | for (i = 0; i < chunk_count; i++) { | ||
1768 | ret = _regmap_raw_write(map, | ||
1769 | reg + (i * chunk_stride), | ||
1770 | val + (i * chunk_size), | ||
1771 | chunk_size); | ||
1772 | if (ret) | ||
1773 | break; | ||
1774 | } | ||
1775 | |||
1776 | /* Write remaining bytes */ | ||
1777 | if (!ret && chunk_size * i < total_size) { | ||
1778 | ret = _regmap_raw_write(map, reg + (i * chunk_stride), | ||
1779 | val + (i * chunk_size), | ||
1780 | total_size - i * chunk_size); | ||
1781 | } | ||
1782 | map->unlock(map->lock_arg); | ||
1726 | } else { | 1783 | } else { |
1727 | void *wval; | 1784 | void *wval; |
1728 | 1785 | ||
@@ -1752,7 +1809,7 @@ EXPORT_SYMBOL_GPL(regmap_bulk_write); | |||
1752 | * | 1809 | * |
1753 | * the (register,newvalue) pairs in regs have not been formatted, but | 1810 | * the (register,newvalue) pairs in regs have not been formatted, but |
1754 | * they are all in the same page and have been changed to being page | 1811 | * they are all in the same page and have been changed to being page |
1755 | * relative. The page register has been written if that was neccessary. | 1812 | * relative. The page register has been written if that was necessary. |
1756 | */ | 1813 | */ |
1757 | static int _regmap_raw_multi_reg_write(struct regmap *map, | 1814 | static int _regmap_raw_multi_reg_write(struct regmap *map, |
1758 | const struct reg_sequence *regs, | 1815 | const struct reg_sequence *regs, |
@@ -1780,8 +1837,8 @@ static int _regmap_raw_multi_reg_write(struct regmap *map, | |||
1780 | u8 = buf; | 1837 | u8 = buf; |
1781 | 1838 | ||
1782 | for (i = 0; i < num_regs; i++) { | 1839 | for (i = 0; i < num_regs; i++) { |
1783 | int reg = regs[i].reg; | 1840 | unsigned int reg = regs[i].reg; |
1784 | int val = regs[i].def; | 1841 | unsigned int val = regs[i].def; |
1785 | trace_regmap_hw_write_start(map, reg, 1); | 1842 | trace_regmap_hw_write_start(map, reg, 1); |
1786 | map->format.format_reg(u8, reg, map->reg_shift); | 1843 | map->format.format_reg(u8, reg, map->reg_shift); |
1787 | u8 += reg_bytes + pad_bytes; | 1844 | u8 += reg_bytes + pad_bytes; |
@@ -1819,10 +1876,12 @@ static int _regmap_range_multi_paged_reg_write(struct regmap *map, | |||
1819 | int i, n; | 1876 | int i, n; |
1820 | struct reg_sequence *base; | 1877 | struct reg_sequence *base; |
1821 | unsigned int this_page = 0; | 1878 | unsigned int this_page = 0; |
1879 | unsigned int page_change = 0; | ||
1822 | /* | 1880 | /* |
1823 | * the set of registers are not neccessarily in order, but | 1881 | * the set of registers are not neccessarily in order, but |
1824 | * since the order of write must be preserved this algorithm | 1882 | * since the order of write must be preserved this algorithm |
1825 | * chops the set each time the page changes | 1883 | * chops the set each time the page changes. This also applies |
1884 | * if there is a delay required at any point in the sequence. | ||
1826 | */ | 1885 | */ |
1827 | base = regs; | 1886 | base = regs; |
1828 | for (i = 0, n = 0; i < num_regs; i++, n++) { | 1887 | for (i = 0, n = 0; i < num_regs; i++, n++) { |
@@ -1838,16 +1897,48 @@ static int _regmap_range_multi_paged_reg_write(struct regmap *map, | |||
1838 | this_page = win_page; | 1897 | this_page = win_page; |
1839 | if (win_page != this_page) { | 1898 | if (win_page != this_page) { |
1840 | this_page = win_page; | 1899 | this_page = win_page; |
1900 | page_change = 1; | ||
1901 | } | ||
1902 | } | ||
1903 | |||
1904 | /* If we have both a page change and a delay make sure to | ||
1905 | * write the regs and apply the delay before we change the | ||
1906 | * page. | ||
1907 | */ | ||
1908 | |||
1909 | if (page_change || regs[i].delay_us) { | ||
1910 | |||
1911 | /* For situations where the first write requires | ||
1912 | * a delay we need to make sure we don't call | ||
1913 | * raw_multi_reg_write with n=0 | ||
1914 | * This can't occur with page breaks as we | ||
1915 | * never write on the first iteration | ||
1916 | */ | ||
1917 | if (regs[i].delay_us && i == 0) | ||
1918 | n = 1; | ||
1919 | |||
1841 | ret = _regmap_raw_multi_reg_write(map, base, n); | 1920 | ret = _regmap_raw_multi_reg_write(map, base, n); |
1842 | if (ret != 0) | 1921 | if (ret != 0) |
1843 | return ret; | 1922 | return ret; |
1923 | |||
1924 | if (regs[i].delay_us) | ||
1925 | udelay(regs[i].delay_us); | ||
1926 | |||
1844 | base += n; | 1927 | base += n; |
1845 | n = 0; | 1928 | n = 0; |
1846 | } | 1929 | |
1847 | ret = _regmap_select_page(map, &base[n].reg, range, 1); | 1930 | if (page_change) { |
1848 | if (ret != 0) | 1931 | ret = _regmap_select_page(map, |
1849 | return ret; | 1932 | &base[n].reg, |
1933 | range, 1); | ||
1934 | if (ret != 0) | ||
1935 | return ret; | ||
1936 | |||
1937 | page_change = 0; | ||
1938 | } | ||
1939 | |||
1850 | } | 1940 | } |
1941 | |||
1851 | } | 1942 | } |
1852 | if (n > 0) | 1943 | if (n > 0) |
1853 | return _regmap_raw_multi_reg_write(map, base, n); | 1944 | return _regmap_raw_multi_reg_write(map, base, n); |
@@ -1866,6 +1957,9 @@ static int _regmap_multi_reg_write(struct regmap *map, | |||
1866 | ret = _regmap_write(map, regs[i].reg, regs[i].def); | 1957 | ret = _regmap_write(map, regs[i].reg, regs[i].def); |
1867 | if (ret != 0) | 1958 | if (ret != 0) |
1868 | return ret; | 1959 | return ret; |
1960 | |||
1961 | if (regs[i].delay_us) | ||
1962 | udelay(regs[i].delay_us); | ||
1869 | } | 1963 | } |
1870 | return 0; | 1964 | return 0; |
1871 | } | 1965 | } |
@@ -1905,8 +1999,12 @@ static int _regmap_multi_reg_write(struct regmap *map, | |||
1905 | for (i = 0; i < num_regs; i++) { | 1999 | for (i = 0; i < num_regs; i++) { |
1906 | unsigned int reg = regs[i].reg; | 2000 | unsigned int reg = regs[i].reg; |
1907 | struct regmap_range_node *range; | 2001 | struct regmap_range_node *range; |
2002 | |||
2003 | /* Coalesce all the writes between a page break or a delay | ||
2004 | * in a sequence | ||
2005 | */ | ||
1908 | range = _regmap_range_lookup(map, reg); | 2006 | range = _regmap_range_lookup(map, reg); |
1909 | if (range) { | 2007 | if (range || regs[i].delay_us) { |
1910 | size_t len = sizeof(struct reg_sequence)*num_regs; | 2008 | size_t len = sizeof(struct reg_sequence)*num_regs; |
1911 | struct reg_sequence *base = kmemdup(regs, len, | 2009 | struct reg_sequence *base = kmemdup(regs, len, |
1912 | GFP_KERNEL); | 2010 | GFP_KERNEL); |
@@ -2062,7 +2160,7 @@ static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val, | |||
2062 | 2160 | ||
2063 | /* | 2161 | /* |
2064 | * Some buses or devices flag reads by setting the high bits in the | 2162 | * Some buses or devices flag reads by setting the high bits in the |
2065 | * register addresss; since it's always the high bits for all | 2163 | * register address; since it's always the high bits for all |
2066 | * current formats we can do this here rather than in | 2164 | * current formats we can do this here rather than in |
2067 | * formatting. This may break if we get interesting formats. | 2165 | * formatting. This may break if we get interesting formats. |
2068 | */ | 2166 | */ |
@@ -2109,8 +2207,6 @@ static int _regmap_read(struct regmap *map, unsigned int reg, | |||
2109 | int ret; | 2207 | int ret; |
2110 | void *context = _regmap_map_get_context(map); | 2208 | void *context = _regmap_map_get_context(map); |
2111 | 2209 | ||
2112 | WARN_ON(!map->reg_read); | ||
2113 | |||
2114 | if (!map->cache_bypass) { | 2210 | if (!map->cache_bypass) { |
2115 | ret = regcache_read(map, reg, val); | 2211 | ret = regcache_read(map, reg, val); |
2116 | if (ret == 0) | 2212 | if (ret == 0) |
@@ -2191,11 +2287,22 @@ int regmap_raw_read(struct regmap *map, unsigned int reg, void *val, | |||
2191 | return -EINVAL; | 2287 | return -EINVAL; |
2192 | if (reg % map->reg_stride) | 2288 | if (reg % map->reg_stride) |
2193 | return -EINVAL; | 2289 | return -EINVAL; |
2290 | if (val_count == 0) | ||
2291 | return -EINVAL; | ||
2194 | 2292 | ||
2195 | map->lock(map->lock_arg); | 2293 | map->lock(map->lock_arg); |
2196 | 2294 | ||
2197 | if (regmap_volatile_range(map, reg, val_count) || map->cache_bypass || | 2295 | if (regmap_volatile_range(map, reg, val_count) || map->cache_bypass || |
2198 | map->cache_type == REGCACHE_NONE) { | 2296 | map->cache_type == REGCACHE_NONE) { |
2297 | if (!map->bus->read) { | ||
2298 | ret = -ENOTSUPP; | ||
2299 | goto out; | ||
2300 | } | ||
2301 | if (map->max_raw_read && map->max_raw_read < val_len) { | ||
2302 | ret = -E2BIG; | ||
2303 | goto out; | ||
2304 | } | ||
2305 | |||
2199 | /* Physical block read if there's no cache involved */ | 2306 | /* Physical block read if there's no cache involved */ |
2200 | ret = _regmap_raw_read(map, reg, val, val_len); | 2307 | ret = _regmap_raw_read(map, reg, val, val_len); |
2201 | 2308 | ||
@@ -2304,20 +2411,51 @@ int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val, | |||
2304 | * Some devices does not support bulk read, for | 2411 | * Some devices does not support bulk read, for |
2305 | * them we have a series of single read operations. | 2412 | * them we have a series of single read operations. |
2306 | */ | 2413 | */ |
2307 | if (map->use_single_rw) { | 2414 | size_t total_size = val_bytes * val_count; |
2308 | for (i = 0; i < val_count; i++) { | 2415 | |
2309 | ret = regmap_raw_read(map, | 2416 | if (!map->use_single_read && |
2310 | reg + (i * map->reg_stride), | 2417 | (!map->max_raw_read || map->max_raw_read > total_size)) { |
2311 | val + (i * val_bytes), | ||
2312 | val_bytes); | ||
2313 | if (ret != 0) | ||
2314 | return ret; | ||
2315 | } | ||
2316 | } else { | ||
2317 | ret = regmap_raw_read(map, reg, val, | 2418 | ret = regmap_raw_read(map, reg, val, |
2318 | val_bytes * val_count); | 2419 | val_bytes * val_count); |
2319 | if (ret != 0) | 2420 | if (ret != 0) |
2320 | return ret; | 2421 | return ret; |
2422 | } else { | ||
2423 | /* | ||
2424 | * Some devices do not support bulk read or do not | ||
2425 | * support large bulk reads, for them we have a series | ||
2426 | * of read operations. | ||
2427 | */ | ||
2428 | int chunk_stride = map->reg_stride; | ||
2429 | size_t chunk_size = val_bytes; | ||
2430 | size_t chunk_count = val_count; | ||
2431 | |||
2432 | if (!map->use_single_read) { | ||
2433 | chunk_size = map->max_raw_read; | ||
2434 | if (chunk_size % val_bytes) | ||
2435 | chunk_size -= chunk_size % val_bytes; | ||
2436 | chunk_count = total_size / chunk_size; | ||
2437 | chunk_stride *= chunk_size / val_bytes; | ||
2438 | } | ||
2439 | |||
2440 | /* Read bytes that fit into a multiple of chunk_size */ | ||
2441 | for (i = 0; i < chunk_count; i++) { | ||
2442 | ret = regmap_raw_read(map, | ||
2443 | reg + (i * chunk_stride), | ||
2444 | val + (i * chunk_size), | ||
2445 | chunk_size); | ||
2446 | if (ret != 0) | ||
2447 | return ret; | ||
2448 | } | ||
2449 | |||
2450 | /* Read remaining bytes */ | ||
2451 | if (chunk_size * i < total_size) { | ||
2452 | ret = regmap_raw_read(map, | ||
2453 | reg + (i * chunk_stride), | ||
2454 | val + (i * chunk_size), | ||
2455 | total_size - i * chunk_size); | ||
2456 | if (ret != 0) | ||
2457 | return ret; | ||
2458 | } | ||
2321 | } | 2459 | } |
2322 | 2460 | ||
2323 | for (i = 0; i < val_count * val_bytes; i += val_bytes) | 2461 | for (i = 0; i < val_count * val_bytes; i += val_bytes) |
@@ -2329,7 +2467,34 @@ int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val, | |||
2329 | &ival); | 2467 | &ival); |
2330 | if (ret != 0) | 2468 | if (ret != 0) |
2331 | return ret; | 2469 | return ret; |
2332 | map->format.format_val(val + (i * val_bytes), ival, 0); | 2470 | |
2471 | if (map->format.format_val) { | ||
2472 | map->format.format_val(val + (i * val_bytes), ival, 0); | ||
2473 | } else { | ||
2474 | /* Devices providing read and write | ||
2475 | * operations can use the bulk I/O | ||
2476 | * functions if they define a val_bytes, | ||
2477 | * we assume that the values are native | ||
2478 | * endian. | ||
2479 | */ | ||
2480 | u32 *u32 = val; | ||
2481 | u16 *u16 = val; | ||
2482 | u8 *u8 = val; | ||
2483 | |||
2484 | switch (map->format.val_bytes) { | ||
2485 | case 4: | ||
2486 | u32[i] = ival; | ||
2487 | break; | ||
2488 | case 2: | ||
2489 | u16[i] = ival; | ||
2490 | break; | ||
2491 | case 1: | ||
2492 | u8[i] = ival; | ||
2493 | break; | ||
2494 | default: | ||
2495 | return -EINVAL; | ||
2496 | } | ||
2497 | } | ||
2333 | } | 2498 | } |
2334 | } | 2499 | } |
2335 | 2500 | ||
diff --git a/drivers/bus/vexpress-config.c b/drivers/bus/vexpress-config.c index a64763b6b5fd..6575c0fe6a4e 100644 --- a/drivers/bus/vexpress-config.c +++ b/drivers/bus/vexpress-config.c | |||
@@ -107,7 +107,7 @@ struct regmap *devm_regmap_init_vexpress_config(struct device *dev) | |||
107 | if (!res) | 107 | if (!res) |
108 | return ERR_PTR(-ENOMEM); | 108 | return ERR_PTR(-ENOMEM); |
109 | 109 | ||
110 | regmap = bridge->ops->regmap_init(dev, bridge->context); | 110 | regmap = (bridge->ops->regmap_init)(dev, bridge->context); |
111 | if (IS_ERR(regmap)) { | 111 | if (IS_ERR(regmap)) { |
112 | devres_free(res); | 112 | devres_free(res); |
113 | return regmap; | 113 | return regmap; |
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index de9f272a0faf..7a85ac9e32c5 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c | |||
@@ -1262,7 +1262,7 @@ static struct regulator *create_regulator(struct regulator_dev *rdev, | |||
1262 | regulator->debugfs = debugfs_create_dir(regulator->supply_name, | 1262 | regulator->debugfs = debugfs_create_dir(regulator->supply_name, |
1263 | rdev->debugfs); | 1263 | rdev->debugfs); |
1264 | if (!regulator->debugfs) { | 1264 | if (!regulator->debugfs) { |
1265 | rdev_warn(rdev, "Failed to create debugfs directory\n"); | 1265 | rdev_dbg(rdev, "Failed to create debugfs directory\n"); |
1266 | } else { | 1266 | } else { |
1267 | debugfs_create_u32("uA_load", 0444, regulator->debugfs, | 1267 | debugfs_create_u32("uA_load", 0444, regulator->debugfs, |
1268 | ®ulator->uA_load); | 1268 | ®ulator->uA_load); |
diff --git a/drivers/thermal/st/st_thermal.c b/drivers/thermal/st/st_thermal.c index 76c515dd802b..88c759d746c3 100644 --- a/drivers/thermal/st/st_thermal.c +++ b/drivers/thermal/st/st_thermal.c | |||
@@ -214,7 +214,7 @@ int st_thermal_register(struct platform_device *pdev, | |||
214 | 214 | ||
215 | sensor->ops = sensor->cdata->ops; | 215 | sensor->ops = sensor->cdata->ops; |
216 | 216 | ||
217 | ret = sensor->ops->regmap_init(sensor); | 217 | ret = (sensor->ops->regmap_init)(sensor); |
218 | if (ret) | 218 | if (ret) |
219 | return ret; | 219 | return ret; |
220 | 220 | ||
diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c index 284f9aa0028b..6c55ade071c3 100644 --- a/fs/debugfs/file.c +++ b/fs/debugfs/file.c | |||
@@ -435,8 +435,8 @@ struct dentry *debugfs_create_atomic_t(const char *name, umode_t mode, | |||
435 | } | 435 | } |
436 | EXPORT_SYMBOL_GPL(debugfs_create_atomic_t); | 436 | EXPORT_SYMBOL_GPL(debugfs_create_atomic_t); |
437 | 437 | ||
438 | static ssize_t read_file_bool(struct file *file, char __user *user_buf, | 438 | ssize_t debugfs_read_file_bool(struct file *file, char __user *user_buf, |
439 | size_t count, loff_t *ppos) | 439 | size_t count, loff_t *ppos) |
440 | { | 440 | { |
441 | char buf[3]; | 441 | char buf[3]; |
442 | u32 *val = file->private_data; | 442 | u32 *val = file->private_data; |
@@ -449,9 +449,10 @@ static ssize_t read_file_bool(struct file *file, char __user *user_buf, | |||
449 | buf[2] = 0x00; | 449 | buf[2] = 0x00; |
450 | return simple_read_from_buffer(user_buf, count, ppos, buf, 2); | 450 | return simple_read_from_buffer(user_buf, count, ppos, buf, 2); |
451 | } | 451 | } |
452 | EXPORT_SYMBOL_GPL(debugfs_read_file_bool); | ||
452 | 453 | ||
453 | static ssize_t write_file_bool(struct file *file, const char __user *user_buf, | 454 | ssize_t debugfs_write_file_bool(struct file *file, const char __user *user_buf, |
454 | size_t count, loff_t *ppos) | 455 | size_t count, loff_t *ppos) |
455 | { | 456 | { |
456 | char buf[32]; | 457 | char buf[32]; |
457 | size_t buf_size; | 458 | size_t buf_size; |
@@ -468,10 +469,11 @@ static ssize_t write_file_bool(struct file *file, const char __user *user_buf, | |||
468 | 469 | ||
469 | return count; | 470 | return count; |
470 | } | 471 | } |
472 | EXPORT_SYMBOL_GPL(debugfs_write_file_bool); | ||
471 | 473 | ||
472 | static const struct file_operations fops_bool = { | 474 | static const struct file_operations fops_bool = { |
473 | .read = read_file_bool, | 475 | .read = debugfs_read_file_bool, |
474 | .write = write_file_bool, | 476 | .write = debugfs_write_file_bool, |
475 | .open = simple_open, | 477 | .open = simple_open, |
476 | .llseek = default_llseek, | 478 | .llseek = default_llseek, |
477 | }; | 479 | }; |
diff --git a/include/linux/debugfs.h b/include/linux/debugfs.h index 420311bcee38..9beb636b97eb 100644 --- a/include/linux/debugfs.h +++ b/include/linux/debugfs.h | |||
@@ -116,6 +116,12 @@ struct dentry *debugfs_create_devm_seqfile(struct device *dev, const char *name, | |||
116 | 116 | ||
117 | bool debugfs_initialized(void); | 117 | bool debugfs_initialized(void); |
118 | 118 | ||
119 | ssize_t debugfs_read_file_bool(struct file *file, char __user *user_buf, | ||
120 | size_t count, loff_t *ppos); | ||
121 | |||
122 | ssize_t debugfs_write_file_bool(struct file *file, const char __user *user_buf, | ||
123 | size_t count, loff_t *ppos); | ||
124 | |||
119 | #else | 125 | #else |
120 | 126 | ||
121 | #include <linux/err.h> | 127 | #include <linux/err.h> |
@@ -282,6 +288,20 @@ static inline struct dentry *debugfs_create_devm_seqfile(struct device *dev, | |||
282 | return ERR_PTR(-ENODEV); | 288 | return ERR_PTR(-ENODEV); |
283 | } | 289 | } |
284 | 290 | ||
291 | static inline ssize_t debugfs_read_file_bool(struct file *file, | ||
292 | char __user *user_buf, | ||
293 | size_t count, loff_t *ppos) | ||
294 | { | ||
295 | return -ENODEV; | ||
296 | } | ||
297 | |||
298 | static inline ssize_t debugfs_write_file_bool(struct file *file, | ||
299 | const char __user *user_buf, | ||
300 | size_t count, loff_t *ppos) | ||
301 | { | ||
302 | return -ENODEV; | ||
303 | } | ||
304 | |||
285 | #endif | 305 | #endif |
286 | 306 | ||
287 | #endif | 307 | #endif |
diff --git a/include/linux/regmap.h b/include/linux/regmap.h index 4a6759098769..8fc0bfd8edc4 100644 --- a/include/linux/regmap.h +++ b/include/linux/regmap.h | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/rbtree.h> | 17 | #include <linux/rbtree.h> |
18 | #include <linux/err.h> | 18 | #include <linux/err.h> |
19 | #include <linux/bug.h> | 19 | #include <linux/bug.h> |
20 | #include <linux/lockdep.h> | ||
20 | 21 | ||
21 | struct module; | 22 | struct module; |
22 | struct device; | 23 | struct device; |
@@ -51,14 +52,17 @@ struct reg_default { | |||
51 | }; | 52 | }; |
52 | 53 | ||
53 | /** | 54 | /** |
54 | * Register/value pairs for sequences of writes | 55 | * Register/value pairs for sequences of writes with an optional delay in |
56 | * microseconds to be applied after each write. | ||
55 | * | 57 | * |
56 | * @reg: Register address. | 58 | * @reg: Register address. |
57 | * @def: Register value. | 59 | * @def: Register value. |
60 | * @delay_us: Delay to be applied after the register write in microseconds | ||
58 | */ | 61 | */ |
59 | struct reg_sequence { | 62 | struct reg_sequence { |
60 | unsigned int reg; | 63 | unsigned int reg; |
61 | unsigned int def; | 64 | unsigned int def; |
65 | unsigned int delay_us; | ||
62 | }; | 66 | }; |
63 | 67 | ||
64 | #ifdef CONFIG_REGMAP | 68 | #ifdef CONFIG_REGMAP |
@@ -307,8 +311,12 @@ typedef void (*regmap_hw_free_context)(void *context); | |||
307 | * if not implemented on a given device. | 311 | * if not implemented on a given device. |
308 | * @async_write: Write operation which completes asynchronously, optional and | 312 | * @async_write: Write operation which completes asynchronously, optional and |
309 | * must serialise with respect to non-async I/O. | 313 | * must serialise with respect to non-async I/O. |
314 | * @reg_write: Write a single register value to the given register address. This | ||
315 | * write operation has to complete when returning from the function. | ||
310 | * @read: Read operation. Data is returned in the buffer used to transmit | 316 | * @read: Read operation. Data is returned in the buffer used to transmit |
311 | * data. | 317 | * data. |
318 | * @reg_read: Read a single register value from a given register address. | ||
319 | * @free_context: Free context. | ||
312 | * @async_alloc: Allocate a regmap_async() structure. | 320 | * @async_alloc: Allocate a regmap_async() structure. |
313 | * @read_flag_mask: Mask to be set in the top byte of the register when doing | 321 | * @read_flag_mask: Mask to be set in the top byte of the register when doing |
314 | * a read. | 322 | * a read. |
@@ -318,7 +326,8 @@ typedef void (*regmap_hw_free_context)(void *context); | |||
318 | * @val_format_endian_default: Default endianness for formatted register | 326 | * @val_format_endian_default: Default endianness for formatted register |
319 | * values. Used when the regmap_config specifies DEFAULT. If this is | 327 | * values. Used when the regmap_config specifies DEFAULT. If this is |
320 | * DEFAULT, BIG is assumed. | 328 | * DEFAULT, BIG is assumed. |
321 | * @async_size: Size of struct used for async work. | 329 | * @max_raw_read: Max raw read size that can be used on the bus. |
330 | * @max_raw_write: Max raw write size that can be used on the bus. | ||
322 | */ | 331 | */ |
323 | struct regmap_bus { | 332 | struct regmap_bus { |
324 | bool fast_io; | 333 | bool fast_io; |
@@ -333,47 +342,186 @@ struct regmap_bus { | |||
333 | u8 read_flag_mask; | 342 | u8 read_flag_mask; |
334 | enum regmap_endian reg_format_endian_default; | 343 | enum regmap_endian reg_format_endian_default; |
335 | enum regmap_endian val_format_endian_default; | 344 | enum regmap_endian val_format_endian_default; |
345 | size_t max_raw_read; | ||
346 | size_t max_raw_write; | ||
336 | }; | 347 | }; |
337 | 348 | ||
338 | struct regmap *regmap_init(struct device *dev, | 349 | /* |
339 | const struct regmap_bus *bus, | 350 | * __regmap_init functions. |
340 | void *bus_context, | 351 | * |
341 | const struct regmap_config *config); | 352 | * These functions take a lock key and name parameter, and should not be called |
353 | * directly. Instead, use the regmap_init macros that generate a key and name | ||
354 | * for each call. | ||
355 | */ | ||
356 | struct regmap *__regmap_init(struct device *dev, | ||
357 | const struct regmap_bus *bus, | ||
358 | void *bus_context, | ||
359 | const struct regmap_config *config, | ||
360 | struct lock_class_key *lock_key, | ||
361 | const char *lock_name); | ||
362 | struct regmap *__regmap_init_i2c(struct i2c_client *i2c, | ||
363 | const struct regmap_config *config, | ||
364 | struct lock_class_key *lock_key, | ||
365 | const char *lock_name); | ||
366 | struct regmap *__regmap_init_spi(struct spi_device *dev, | ||
367 | const struct regmap_config *config, | ||
368 | struct lock_class_key *lock_key, | ||
369 | const char *lock_name); | ||
370 | struct regmap *__regmap_init_spmi_base(struct spmi_device *dev, | ||
371 | const struct regmap_config *config, | ||
372 | struct lock_class_key *lock_key, | ||
373 | const char *lock_name); | ||
374 | struct regmap *__regmap_init_spmi_ext(struct spmi_device *dev, | ||
375 | const struct regmap_config *config, | ||
376 | struct lock_class_key *lock_key, | ||
377 | const char *lock_name); | ||
378 | struct regmap *__regmap_init_mmio_clk(struct device *dev, const char *clk_id, | ||
379 | void __iomem *regs, | ||
380 | const struct regmap_config *config, | ||
381 | struct lock_class_key *lock_key, | ||
382 | const char *lock_name); | ||
383 | struct regmap *__regmap_init_ac97(struct snd_ac97 *ac97, | ||
384 | const struct regmap_config *config, | ||
385 | struct lock_class_key *lock_key, | ||
386 | const char *lock_name); | ||
387 | |||
388 | struct regmap *__devm_regmap_init(struct device *dev, | ||
389 | const struct regmap_bus *bus, | ||
390 | void *bus_context, | ||
391 | const struct regmap_config *config, | ||
392 | struct lock_class_key *lock_key, | ||
393 | const char *lock_name); | ||
394 | struct regmap *__devm_regmap_init_i2c(struct i2c_client *i2c, | ||
395 | const struct regmap_config *config, | ||
396 | struct lock_class_key *lock_key, | ||
397 | const char *lock_name); | ||
398 | struct regmap *__devm_regmap_init_spi(struct spi_device *dev, | ||
399 | const struct regmap_config *config, | ||
400 | struct lock_class_key *lock_key, | ||
401 | const char *lock_name); | ||
402 | struct regmap *__devm_regmap_init_spmi_base(struct spmi_device *dev, | ||
403 | const struct regmap_config *config, | ||
404 | struct lock_class_key *lock_key, | ||
405 | const char *lock_name); | ||
406 | struct regmap *__devm_regmap_init_spmi_ext(struct spmi_device *dev, | ||
407 | const struct regmap_config *config, | ||
408 | struct lock_class_key *lock_key, | ||
409 | const char *lock_name); | ||
410 | struct regmap *__devm_regmap_init_mmio_clk(struct device *dev, | ||
411 | const char *clk_id, | ||
412 | void __iomem *regs, | ||
413 | const struct regmap_config *config, | ||
414 | struct lock_class_key *lock_key, | ||
415 | const char *lock_name); | ||
416 | struct regmap *__devm_regmap_init_ac97(struct snd_ac97 *ac97, | ||
417 | const struct regmap_config *config, | ||
418 | struct lock_class_key *lock_key, | ||
419 | const char *lock_name); | ||
420 | |||
421 | /* | ||
422 | * Wrapper for regmap_init macros to include a unique lockdep key and name | ||
423 | * for each call. No-op if CONFIG_LOCKDEP is not set. | ||
424 | * | ||
425 | * @fn: Real function to call (in the form __[*_]regmap_init[_*]) | ||
426 | * @name: Config variable name (#config in the calling macro) | ||
427 | **/ | ||
428 | #ifdef CONFIG_LOCKDEP | ||
429 | #define __regmap_lockdep_wrapper(fn, name, ...) \ | ||
430 | ( \ | ||
431 | ({ \ | ||
432 | static struct lock_class_key _key; \ | ||
433 | fn(__VA_ARGS__, &_key, \ | ||
434 | KBUILD_BASENAME ":" \ | ||
435 | __stringify(__LINE__) ":" \ | ||
436 | "(" name ")->lock"); \ | ||
437 | }) \ | ||
438 | ) | ||
439 | #else | ||
440 | #define __regmap_lockdep_wrapper(fn, name, ...) fn(__VA_ARGS__, NULL, NULL) | ||
441 | #endif | ||
442 | |||
443 | /** | ||
444 | * regmap_init(): Initialise register map | ||
445 | * | ||
446 | * @dev: Device that will be interacted with | ||
447 | * @bus: Bus-specific callbacks to use with device | ||
448 | * @bus_context: Data passed to bus-specific callbacks | ||
449 | * @config: Configuration for register map | ||
450 | * | ||
451 | * The return value will be an ERR_PTR() on error or a valid pointer to | ||
452 | * a struct regmap. This function should generally not be called | ||
453 | * directly, it should be called by bus-specific init functions. | ||
454 | */ | ||
455 | #define regmap_init(dev, bus, bus_context, config) \ | ||
456 | __regmap_lockdep_wrapper(__regmap_init, #config, \ | ||
457 | dev, bus, bus_context, config) | ||
342 | int regmap_attach_dev(struct device *dev, struct regmap *map, | 458 | int regmap_attach_dev(struct device *dev, struct regmap *map, |
343 | const struct regmap_config *config); | 459 | const struct regmap_config *config); |
344 | struct regmap *regmap_init_i2c(struct i2c_client *i2c, | ||
345 | const struct regmap_config *config); | ||
346 | struct regmap *regmap_init_spi(struct spi_device *dev, | ||
347 | const struct regmap_config *config); | ||
348 | struct regmap *regmap_init_spmi_base(struct spmi_device *dev, | ||
349 | const struct regmap_config *config); | ||
350 | struct regmap *regmap_init_spmi_ext(struct spmi_device *dev, | ||
351 | const struct regmap_config *config); | ||
352 | struct regmap *regmap_init_mmio_clk(struct device *dev, const char *clk_id, | ||
353 | void __iomem *regs, | ||
354 | const struct regmap_config *config); | ||
355 | struct regmap *regmap_init_ac97(struct snd_ac97 *ac97, | ||
356 | const struct regmap_config *config); | ||
357 | |||
358 | struct regmap *devm_regmap_init(struct device *dev, | ||
359 | const struct regmap_bus *bus, | ||
360 | void *bus_context, | ||
361 | const struct regmap_config *config); | ||
362 | struct regmap *devm_regmap_init_i2c(struct i2c_client *i2c, | ||
363 | const struct regmap_config *config); | ||
364 | struct regmap *devm_regmap_init_spi(struct spi_device *dev, | ||
365 | const struct regmap_config *config); | ||
366 | struct regmap *devm_regmap_init_spmi_base(struct spmi_device *dev, | ||
367 | const struct regmap_config *config); | ||
368 | struct regmap *devm_regmap_init_spmi_ext(struct spmi_device *dev, | ||
369 | const struct regmap_config *config); | ||
370 | struct regmap *devm_regmap_init_mmio_clk(struct device *dev, const char *clk_id, | ||
371 | void __iomem *regs, | ||
372 | const struct regmap_config *config); | ||
373 | struct regmap *devm_regmap_init_ac97(struct snd_ac97 *ac97, | ||
374 | const struct regmap_config *config); | ||
375 | 460 | ||
376 | bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg); | 461 | /** |
462 | * regmap_init_i2c(): Initialise register map | ||
463 | * | ||
464 | * @i2c: Device that will be interacted with | ||
465 | * @config: Configuration for register map | ||
466 | * | ||
467 | * The return value will be an ERR_PTR() on error or a valid pointer to | ||
468 | * a struct regmap. | ||
469 | */ | ||
470 | #define regmap_init_i2c(i2c, config) \ | ||
471 | __regmap_lockdep_wrapper(__regmap_init_i2c, #config, \ | ||
472 | i2c, config) | ||
473 | |||
474 | /** | ||
475 | * regmap_init_spi(): Initialise register map | ||
476 | * | ||
477 | * @spi: Device that will be interacted with | ||
478 | * @config: Configuration for register map | ||
479 | * | ||
480 | * The return value will be an ERR_PTR() on error or a valid pointer to | ||
481 | * a struct regmap. | ||
482 | */ | ||
483 | #define regmap_init_spi(dev, config) \ | ||
484 | __regmap_lockdep_wrapper(__regmap_init_spi, #config, \ | ||
485 | dev, config) | ||
486 | |||
487 | /** | ||
488 | * regmap_init_spmi_base(): Create regmap for the Base register space | ||
489 | * @sdev: SPMI device that will be interacted with | ||
490 | * @config: Configuration for register map | ||
491 | * | ||
492 | * The return value will be an ERR_PTR() on error or a valid pointer to | ||
493 | * a struct regmap. | ||
494 | */ | ||
495 | #define regmap_init_spmi_base(dev, config) \ | ||
496 | __regmap_lockdep_wrapper(__regmap_init_spmi_base, #config, \ | ||
497 | dev, config) | ||
498 | |||
499 | /** | ||
500 | * regmap_init_spmi_ext(): Create regmap for Ext register space | ||
501 | * @sdev: Device that will be interacted with | ||
502 | * @config: Configuration for register map | ||
503 | * | ||
504 | * The return value will be an ERR_PTR() on error or a valid pointer to | ||
505 | * a struct regmap. | ||
506 | */ | ||
507 | #define regmap_init_spmi_ext(dev, config) \ | ||
508 | __regmap_lockdep_wrapper(__regmap_init_spmi_ext, #config, \ | ||
509 | dev, config) | ||
510 | |||
511 | /** | ||
512 | * regmap_init_mmio_clk(): Initialise register map with register clock | ||
513 | * | ||
514 | * @dev: Device that will be interacted with | ||
515 | * @clk_id: register clock consumer ID | ||
516 | * @regs: Pointer to memory-mapped IO region | ||
517 | * @config: Configuration for register map | ||
518 | * | ||
519 | * The return value will be an ERR_PTR() on error or a valid pointer to | ||
520 | * a struct regmap. | ||
521 | */ | ||
522 | #define regmap_init_mmio_clk(dev, clk_id, regs, config) \ | ||
523 | __regmap_lockdep_wrapper(__regmap_init_mmio_clk, #config, \ | ||
524 | dev, clk_id, regs, config) | ||
377 | 525 | ||
378 | /** | 526 | /** |
379 | * regmap_init_mmio(): Initialise register map | 527 | * regmap_init_mmio(): Initialise register map |
@@ -385,12 +533,109 @@ bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg); | |||
385 | * The return value will be an ERR_PTR() on error or a valid pointer to | 533 | * The return value will be an ERR_PTR() on error or a valid pointer to |
386 | * a struct regmap. | 534 | * a struct regmap. |
387 | */ | 535 | */ |
388 | static inline struct regmap *regmap_init_mmio(struct device *dev, | 536 | #define regmap_init_mmio(dev, regs, config) \ |
389 | void __iomem *regs, | 537 | regmap_init_mmio_clk(dev, NULL, regs, config) |
390 | const struct regmap_config *config) | 538 | |
391 | { | 539 | /** |
392 | return regmap_init_mmio_clk(dev, NULL, regs, config); | 540 | * regmap_init_ac97(): Initialise AC'97 register map |
393 | } | 541 | * |
542 | * @ac97: Device that will be interacted with | ||
543 | * @config: Configuration for register map | ||
544 | * | ||
545 | * The return value will be an ERR_PTR() on error or a valid pointer to | ||
546 | * a struct regmap. | ||
547 | */ | ||
548 | #define regmap_init_ac97(ac97, config) \ | ||
549 | __regmap_lockdep_wrapper(__regmap_init_ac97, #config, \ | ||
550 | ac97, config) | ||
551 | bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg); | ||
552 | |||
553 | /** | ||
554 | * devm_regmap_init(): Initialise managed register map | ||
555 | * | ||
556 | * @dev: Device that will be interacted with | ||
557 | * @bus: Bus-specific callbacks to use with device | ||
558 | * @bus_context: Data passed to bus-specific callbacks | ||
559 | * @config: Configuration for register map | ||
560 | * | ||
561 | * The return value will be an ERR_PTR() on error or a valid pointer | ||
562 | * to a struct regmap. This function should generally not be called | ||
563 | * directly, it should be called by bus-specific init functions. The | ||
564 | * map will be automatically freed by the device management code. | ||
565 | */ | ||
566 | #define devm_regmap_init(dev, bus, bus_context, config) \ | ||
567 | __regmap_lockdep_wrapper(__devm_regmap_init, #config, \ | ||
568 | dev, bus, bus_context, config) | ||
569 | |||
570 | /** | ||
571 | * devm_regmap_init_i2c(): Initialise managed register map | ||
572 | * | ||
573 | * @i2c: Device that will be interacted with | ||
574 | * @config: Configuration for register map | ||
575 | * | ||
576 | * The return value will be an ERR_PTR() on error or a valid pointer | ||
577 | * to a struct regmap. The regmap will be automatically freed by the | ||
578 | * device management code. | ||
579 | */ | ||
580 | #define devm_regmap_init_i2c(i2c, config) \ | ||
581 | __regmap_lockdep_wrapper(__devm_regmap_init_i2c, #config, \ | ||
582 | i2c, config) | ||
583 | |||
584 | /** | ||
585 | * devm_regmap_init_spi(): Initialise register map | ||
586 | * | ||
587 | * @spi: Device that will be interacted with | ||
588 | * @config: Configuration for register map | ||
589 | * | ||
590 | * The return value will be an ERR_PTR() on error or a valid pointer | ||
591 | * to a struct regmap. The map will be automatically freed by the | ||
592 | * device management code. | ||
593 | */ | ||
594 | #define devm_regmap_init_spi(dev, config) \ | ||
595 | __regmap_lockdep_wrapper(__devm_regmap_init_spi, #config, \ | ||
596 | dev, config) | ||
597 | |||
598 | /** | ||
599 | * devm_regmap_init_spmi_base(): Create managed regmap for Base register space | ||
600 | * @sdev: SPMI device that will be interacted with | ||
601 | * @config: Configuration for register map | ||
602 | * | ||
603 | * The return value will be an ERR_PTR() on error or a valid pointer | ||
604 | * to a struct regmap. The regmap will be automatically freed by the | ||
605 | * device management code. | ||
606 | */ | ||
607 | #define devm_regmap_init_spmi_base(dev, config) \ | ||
608 | __regmap_lockdep_wrapper(__devm_regmap_init_spmi_base, #config, \ | ||
609 | dev, config) | ||
610 | |||
611 | /** | ||
612 | * devm_regmap_init_spmi_ext(): Create managed regmap for Ext register space | ||
613 | * @sdev: SPMI device that will be interacted with | ||
614 | * @config: Configuration for register map | ||
615 | * | ||
616 | * The return value will be an ERR_PTR() on error or a valid pointer | ||
617 | * to a struct regmap. The regmap will be automatically freed by the | ||
618 | * device management code. | ||
619 | */ | ||
620 | #define devm_regmap_init_spmi_ext(dev, config) \ | ||
621 | __regmap_lockdep_wrapper(__devm_regmap_init_spmi_ext, #config, \ | ||
622 | dev, config) | ||
623 | |||
624 | /** | ||
625 | * devm_regmap_init_mmio_clk(): Initialise managed register map with clock | ||
626 | * | ||
627 | * @dev: Device that will be interacted with | ||
628 | * @clk_id: register clock consumer ID | ||
629 | * @regs: Pointer to memory-mapped IO region | ||
630 | * @config: Configuration for register map | ||
631 | * | ||
632 | * The return value will be an ERR_PTR() on error or a valid pointer | ||
633 | * to a struct regmap. The regmap will be automatically freed by the | ||
634 | * device management code. | ||
635 | */ | ||
636 | #define devm_regmap_init_mmio_clk(dev, clk_id, regs, config) \ | ||
637 | __regmap_lockdep_wrapper(__devm_regmap_init_mmio_clk, #config, \ | ||
638 | dev, clk_id, regs, config) | ||
394 | 639 | ||
395 | /** | 640 | /** |
396 | * devm_regmap_init_mmio(): Initialise managed register map | 641 | * devm_regmap_init_mmio(): Initialise managed register map |
@@ -403,12 +648,22 @@ static inline struct regmap *regmap_init_mmio(struct device *dev, | |||
403 | * to a struct regmap. The regmap will be automatically freed by the | 648 | * to a struct regmap. The regmap will be automatically freed by the |
404 | * device management code. | 649 | * device management code. |
405 | */ | 650 | */ |
406 | static inline struct regmap *devm_regmap_init_mmio(struct device *dev, | 651 | #define devm_regmap_init_mmio(dev, regs, config) \ |
407 | void __iomem *regs, | 652 | devm_regmap_init_mmio_clk(dev, NULL, regs, config) |
408 | const struct regmap_config *config) | 653 | |
409 | { | 654 | /** |
410 | return devm_regmap_init_mmio_clk(dev, NULL, regs, config); | 655 | * devm_regmap_init_ac97(): Initialise AC'97 register map |
411 | } | 656 | * |
657 | * @ac97: Device that will be interacted with | ||
658 | * @config: Configuration for register map | ||
659 | * | ||
660 | * The return value will be an ERR_PTR() on error or a valid pointer | ||
661 | * to a struct regmap. The regmap will be automatically freed by the | ||
662 | * device management code. | ||
663 | */ | ||
664 | #define devm_regmap_init_ac97(ac97, config) \ | ||
665 | __regmap_lockdep_wrapper(__devm_regmap_init_ac97, #config, \ | ||
666 | ac97, config) | ||
412 | 667 | ||
413 | void regmap_exit(struct regmap *map); | 668 | void regmap_exit(struct regmap *map); |
414 | int regmap_reinit_cache(struct regmap *map, | 669 | int regmap_reinit_cache(struct regmap *map, |
@@ -450,6 +705,8 @@ int regmap_get_max_register(struct regmap *map); | |||
450 | int regmap_get_reg_stride(struct regmap *map); | 705 | int regmap_get_reg_stride(struct regmap *map); |
451 | int regmap_async_complete(struct regmap *map); | 706 | int regmap_async_complete(struct regmap *map); |
452 | bool regmap_can_raw_write(struct regmap *map); | 707 | bool regmap_can_raw_write(struct regmap *map); |
708 | size_t regmap_get_raw_read_max(struct regmap *map); | ||
709 | size_t regmap_get_raw_write_max(struct regmap *map); | ||
453 | 710 | ||
454 | int regcache_sync(struct regmap *map); | 711 | int regcache_sync(struct regmap *map); |
455 | int regcache_sync_region(struct regmap *map, unsigned int min, | 712 | int regcache_sync_region(struct regmap *map, unsigned int min, |