diff options
Diffstat (limited to 'drivers/base/regmap/regmap.c')
-rw-r--r-- | drivers/base/regmap/regmap.c | 76 |
1 files changed, 64 insertions, 12 deletions
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index 78f43fb2fe84..f2281af24ec6 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include <linux/export.h> | 15 | #include <linux/export.h> |
16 | #include <linux/mutex.h> | 16 | #include <linux/mutex.h> |
17 | #include <linux/err.h> | 17 | #include <linux/err.h> |
18 | #include <linux/of.h> | ||
18 | #include <linux/rbtree.h> | 19 | #include <linux/rbtree.h> |
19 | #include <linux/sched.h> | 20 | #include <linux/sched.h> |
20 | 21 | ||
@@ -109,7 +110,7 @@ bool regmap_readable(struct regmap *map, unsigned int reg) | |||
109 | 110 | ||
110 | bool regmap_volatile(struct regmap *map, unsigned int reg) | 111 | bool regmap_volatile(struct regmap *map, unsigned int reg) |
111 | { | 112 | { |
112 | if (!regmap_readable(map, reg)) | 113 | if (!map->format.format_write && !regmap_readable(map, reg)) |
113 | return false; | 114 | return false; |
114 | 115 | ||
115 | if (map->volatile_reg) | 116 | if (map->volatile_reg) |
@@ -448,6 +449,66 @@ int regmap_attach_dev(struct device *dev, struct regmap *map, | |||
448 | } | 449 | } |
449 | EXPORT_SYMBOL_GPL(regmap_attach_dev); | 450 | EXPORT_SYMBOL_GPL(regmap_attach_dev); |
450 | 451 | ||
452 | static enum regmap_endian regmap_get_reg_endian(const struct regmap_bus *bus, | ||
453 | const struct regmap_config *config) | ||
454 | { | ||
455 | enum regmap_endian endian; | ||
456 | |||
457 | /* Retrieve the endianness specification from the regmap config */ | ||
458 | endian = config->reg_format_endian; | ||
459 | |||
460 | /* If the regmap config specified a non-default value, use that */ | ||
461 | if (endian != REGMAP_ENDIAN_DEFAULT) | ||
462 | return endian; | ||
463 | |||
464 | /* Retrieve the endianness specification from the bus config */ | ||
465 | if (bus && bus->reg_format_endian_default) | ||
466 | endian = bus->reg_format_endian_default; | ||
467 | |||
468 | /* If the bus specified a non-default value, use that */ | ||
469 | if (endian != REGMAP_ENDIAN_DEFAULT) | ||
470 | return endian; | ||
471 | |||
472 | /* Use this if no other value was found */ | ||
473 | return REGMAP_ENDIAN_BIG; | ||
474 | } | ||
475 | |||
476 | static enum regmap_endian regmap_get_val_endian(struct device *dev, | ||
477 | const struct regmap_bus *bus, | ||
478 | const struct regmap_config *config) | ||
479 | { | ||
480 | struct device_node *np = dev->of_node; | ||
481 | enum regmap_endian endian; | ||
482 | |||
483 | /* Retrieve the endianness specification from the regmap config */ | ||
484 | endian = config->val_format_endian; | ||
485 | |||
486 | /* If the regmap config specified a non-default value, use that */ | ||
487 | if (endian != REGMAP_ENDIAN_DEFAULT) | ||
488 | return endian; | ||
489 | |||
490 | /* Parse the device's DT node for an endianness specification */ | ||
491 | if (of_property_read_bool(np, "big-endian")) | ||
492 | endian = REGMAP_ENDIAN_BIG; | ||
493 | else if (of_property_read_bool(np, "little-endian")) | ||
494 | endian = REGMAP_ENDIAN_LITTLE; | ||
495 | |||
496 | /* If the endianness was specified in DT, use that */ | ||
497 | if (endian != REGMAP_ENDIAN_DEFAULT) | ||
498 | return endian; | ||
499 | |||
500 | /* Retrieve the endianness specification from the bus config */ | ||
501 | if (bus && bus->val_format_endian_default) | ||
502 | endian = bus->val_format_endian_default; | ||
503 | |||
504 | /* If the bus specified a non-default value, use that */ | ||
505 | if (endian != REGMAP_ENDIAN_DEFAULT) | ||
506 | return endian; | ||
507 | |||
508 | /* Use this if no other value was found */ | ||
509 | return REGMAP_ENDIAN_BIG; | ||
510 | } | ||
511 | |||
451 | /** | 512 | /** |
452 | * regmap_init(): Initialise register map | 513 | * regmap_init(): Initialise register map |
453 | * | 514 | * |
@@ -551,17 +612,8 @@ struct regmap *regmap_init(struct device *dev, | |||
551 | map->reg_read = _regmap_bus_read; | 612 | map->reg_read = _regmap_bus_read; |
552 | } | 613 | } |
553 | 614 | ||
554 | reg_endian = config->reg_format_endian; | 615 | reg_endian = regmap_get_reg_endian(bus, config); |
555 | if (reg_endian == REGMAP_ENDIAN_DEFAULT) | 616 | val_endian = regmap_get_val_endian(dev, bus, config); |
556 | reg_endian = bus->reg_format_endian_default; | ||
557 | if (reg_endian == REGMAP_ENDIAN_DEFAULT) | ||
558 | reg_endian = REGMAP_ENDIAN_BIG; | ||
559 | |||
560 | val_endian = config->val_format_endian; | ||
561 | if (val_endian == REGMAP_ENDIAN_DEFAULT) | ||
562 | val_endian = bus->val_format_endian_default; | ||
563 | if (val_endian == REGMAP_ENDIAN_DEFAULT) | ||
564 | val_endian = REGMAP_ENDIAN_BIG; | ||
565 | 617 | ||
566 | switch (config->reg_bits + map->reg_shift) { | 618 | switch (config->reg_bits + map->reg_shift) { |
567 | case 2: | 619 | case 2: |