aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Brown <broonie@kernel.org>2016-03-05 07:30:41 -0500
committerMark Brown <broonie@kernel.org>2016-03-05 07:30:41 -0500
commitd25263d917caadba52275bf95c9b3400fe77edbe (patch)
treedc6e8c0e3e287d4619421b83970b1c0c90d9e249
parent0b74f06fcbfd38ebf3c869ae41015cd5b581eb4f (diff)
parentb821957a5ae76994eebf9eed3247be0ba5775c30 (diff)
Merge remote-tracking branch 'regmap/topic/update-bits' into regmap-next
-rw-r--r--drivers/base/regmap/regmap.c217
-rw-r--r--include/linux/regmap.h97
2 files changed, 88 insertions, 226 deletions
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 8c25635164be..df2d2ef5d6b3 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -1698,100 +1698,63 @@ int regmap_raw_write(struct regmap *map, unsigned int reg,
1698EXPORT_SYMBOL_GPL(regmap_raw_write); 1698EXPORT_SYMBOL_GPL(regmap_raw_write);
1699 1699
1700/** 1700/**
1701 * regmap_field_write(): Write a value to a single register field 1701 * regmap_field_update_bits_base():
1702 * 1702 * Perform a read/modify/write cycle on the register field
1703 * @field: Register field to write to 1703 * with change, async, force option
1704 * @val: Value to be written
1705 *
1706 * A value of zero will be returned on success, a negative errno will
1707 * be returned in error cases.
1708 */
1709int regmap_field_write(struct regmap_field *field, unsigned int val)
1710{
1711 return regmap_update_bits(field->regmap, field->reg,
1712 field->mask, val << field->shift);
1713}
1714EXPORT_SYMBOL_GPL(regmap_field_write);
1715
1716/**
1717 * regmap_field_update_bits(): Perform a read/modify/write cycle
1718 * on the register field
1719 * 1704 *
1720 * @field: Register field to write to 1705 * @field: Register field to write to
1721 * @mask: Bitmask to change 1706 * @mask: Bitmask to change
1722 * @val: Value to be written 1707 * @val: Value to be written
1708 * @change: Boolean indicating if a write was done
1709 * @async: Boolean indicating asynchronously
1710 * @force: Boolean indicating use force update
1723 * 1711 *
1724 * A value of zero will be returned on success, a negative errno will 1712 * A value of zero will be returned on success, a negative errno will
1725 * be returned in error cases. 1713 * be returned in error cases.
1726 */ 1714 */
1727int regmap_field_update_bits(struct regmap_field *field, unsigned int mask, unsigned int val) 1715int regmap_field_update_bits_base(struct regmap_field *field,
1716 unsigned int mask, unsigned int val,
1717 bool *change, bool async, bool force)
1728{ 1718{
1729 mask = (mask << field->shift) & field->mask; 1719 mask = (mask << field->shift) & field->mask;
1730 1720
1731 return regmap_update_bits(field->regmap, field->reg, 1721 return regmap_update_bits_base(field->regmap, field->reg,
1732 mask, val << field->shift); 1722 mask, val << field->shift,
1733} 1723 change, async, force);
1734EXPORT_SYMBOL_GPL(regmap_field_update_bits);
1735
1736/**
1737 * regmap_fields_write(): Write a value to a single register field with port ID
1738 *
1739 * @field: Register field to write to
1740 * @id: port ID
1741 * @val: Value to be written
1742 *
1743 * A value of zero will be returned on success, a negative errno will
1744 * be returned in error cases.
1745 */
1746int regmap_fields_write(struct regmap_field *field, unsigned int id,
1747 unsigned int val)
1748{
1749 if (id >= field->id_size)
1750 return -EINVAL;
1751
1752 return regmap_update_bits(field->regmap,
1753 field->reg + (field->id_offset * id),
1754 field->mask, val << field->shift);
1755}
1756EXPORT_SYMBOL_GPL(regmap_fields_write);
1757
1758int regmap_fields_force_write(struct regmap_field *field, unsigned int id,
1759 unsigned int val)
1760{
1761 if (id >= field->id_size)
1762 return -EINVAL;
1763
1764 return regmap_write_bits(field->regmap,
1765 field->reg + (field->id_offset * id),
1766 field->mask, val << field->shift);
1767} 1724}
1768EXPORT_SYMBOL_GPL(regmap_fields_force_write); 1725EXPORT_SYMBOL_GPL(regmap_field_update_bits_base);
1769 1726
1770/** 1727/**
1771 * regmap_fields_update_bits(): Perform a read/modify/write cycle 1728 * regmap_fields_update_bits_base():
1772 * on the register field 1729 * Perform a read/modify/write cycle on the register field
1730 * with change, async, force option
1773 * 1731 *
1774 * @field: Register field to write to 1732 * @field: Register field to write to
1775 * @id: port ID 1733 * @id: port ID
1776 * @mask: Bitmask to change 1734 * @mask: Bitmask to change
1777 * @val: Value to be written 1735 * @val: Value to be written
1736 * @change: Boolean indicating if a write was done
1737 * @async: Boolean indicating asynchronously
1738 * @force: Boolean indicating use force update
1778 * 1739 *
1779 * A value of zero will be returned on success, a negative errno will 1740 * A value of zero will be returned on success, a negative errno will
1780 * be returned in error cases. 1741 * be returned in error cases.
1781 */ 1742 */
1782int regmap_fields_update_bits(struct regmap_field *field, unsigned int id, 1743int regmap_fields_update_bits_base(struct regmap_field *field, unsigned int id,
1783 unsigned int mask, unsigned int val) 1744 unsigned int mask, unsigned int val,
1745 bool *change, bool async, bool force)
1784{ 1746{
1785 if (id >= field->id_size) 1747 if (id >= field->id_size)
1786 return -EINVAL; 1748 return -EINVAL;
1787 1749
1788 mask = (mask << field->shift) & field->mask; 1750 mask = (mask << field->shift) & field->mask;
1789 1751
1790 return regmap_update_bits(field->regmap, 1752 return regmap_update_bits_base(field->regmap,
1791 field->reg + (field->id_offset * id), 1753 field->reg + (field->id_offset * id),
1792 mask, val << field->shift); 1754 mask, val << field->shift,
1755 change, async, force);
1793} 1756}
1794EXPORT_SYMBOL_GPL(regmap_fields_update_bits); 1757EXPORT_SYMBOL_GPL(regmap_fields_update_bits_base);
1795 1758
1796/* 1759/*
1797 * regmap_bulk_write(): Write multiple registers to the device 1760 * regmap_bulk_write(): Write multiple registers to the device
@@ -2660,138 +2623,36 @@ static int _regmap_update_bits(struct regmap *map, unsigned int reg,
2660} 2623}
2661 2624
2662/** 2625/**
2663 * regmap_update_bits: Perform a read/modify/write cycle on the register map 2626 * regmap_update_bits_base:
2664 * 2627 * Perform a read/modify/write cycle on the
2665 * @map: Register map to update 2628 * register map with change, async, force option
2666 * @reg: Register to update
2667 * @mask: Bitmask to change
2668 * @val: New value for bitmask
2669 *
2670 * Returns zero for success, a negative number on error.
2671 */
2672int regmap_update_bits(struct regmap *map, unsigned int reg,
2673 unsigned int mask, unsigned int val)
2674{
2675 int ret;
2676
2677 map->lock(map->lock_arg);
2678 ret = _regmap_update_bits(map, reg, mask, val, NULL, false);
2679 map->unlock(map->lock_arg);
2680
2681 return ret;
2682}
2683EXPORT_SYMBOL_GPL(regmap_update_bits);
2684
2685/**
2686 * regmap_write_bits: Perform a read/modify/write cycle on the register map
2687 *
2688 * @map: Register map to update
2689 * @reg: Register to update
2690 * @mask: Bitmask to change
2691 * @val: New value for bitmask
2692 *
2693 * Returns zero for success, a negative number on error.
2694 */
2695int regmap_write_bits(struct regmap *map, unsigned int reg,
2696 unsigned int mask, unsigned int val)
2697{
2698 int ret;
2699
2700 map->lock(map->lock_arg);
2701 ret = _regmap_update_bits(map, reg, mask, val, NULL, true);
2702 map->unlock(map->lock_arg);
2703
2704 return ret;
2705}
2706EXPORT_SYMBOL_GPL(regmap_write_bits);
2707
2708/**
2709 * regmap_update_bits_async: Perform a read/modify/write cycle on the register
2710 * map asynchronously
2711 *
2712 * @map: Register map to update
2713 * @reg: Register to update
2714 * @mask: Bitmask to change
2715 * @val: New value for bitmask
2716 *
2717 * With most buses the read must be done synchronously so this is most
2718 * useful for devices with a cache which do not need to interact with
2719 * the hardware to determine the current register value.
2720 *
2721 * Returns zero for success, a negative number on error.
2722 */
2723int regmap_update_bits_async(struct regmap *map, unsigned int reg,
2724 unsigned int mask, unsigned int val)
2725{
2726 int ret;
2727
2728 map->lock(map->lock_arg);
2729
2730 map->async = true;
2731
2732 ret = _regmap_update_bits(map, reg, mask, val, NULL, false);
2733
2734 map->async = false;
2735
2736 map->unlock(map->lock_arg);
2737
2738 return ret;
2739}
2740EXPORT_SYMBOL_GPL(regmap_update_bits_async);
2741
2742/**
2743 * regmap_update_bits_check: Perform a read/modify/write cycle on the
2744 * register map and report if updated
2745 *
2746 * @map: Register map to update
2747 * @reg: Register to update
2748 * @mask: Bitmask to change
2749 * @val: New value for bitmask
2750 * @change: Boolean indicating if a write was done
2751 *
2752 * Returns zero for success, a negative number on error.
2753 */
2754int regmap_update_bits_check(struct regmap *map, unsigned int reg,
2755 unsigned int mask, unsigned int val,
2756 bool *change)
2757{
2758 int ret;
2759
2760 map->lock(map->lock_arg);
2761 ret = _regmap_update_bits(map, reg, mask, val, change, false);
2762 map->unlock(map->lock_arg);
2763 return ret;
2764}
2765EXPORT_SYMBOL_GPL(regmap_update_bits_check);
2766
2767/**
2768 * regmap_update_bits_check_async: Perform a read/modify/write cycle on the
2769 * register map asynchronously and report if
2770 * updated
2771 * 2629 *
2772 * @map: Register map to update 2630 * @map: Register map to update
2773 * @reg: Register to update 2631 * @reg: Register to update
2774 * @mask: Bitmask to change 2632 * @mask: Bitmask to change
2775 * @val: New value for bitmask 2633 * @val: New value for bitmask
2776 * @change: Boolean indicating if a write was done 2634 * @change: Boolean indicating if a write was done
2635 * @async: Boolean indicating asynchronously
2636 * @force: Boolean indicating use force update
2777 * 2637 *
2638 * if async was true,
2778 * With most buses the read must be done synchronously so this is most 2639 * With most buses the read must be done synchronously so this is most
2779 * useful for devices with a cache which do not need to interact with 2640 * useful for devices with a cache which do not need to interact with
2780 * the hardware to determine the current register value. 2641 * the hardware to determine the current register value.
2781 * 2642 *
2782 * Returns zero for success, a negative number on error. 2643 * Returns zero for success, a negative number on error.
2783 */ 2644 */
2784int regmap_update_bits_check_async(struct regmap *map, unsigned int reg, 2645int regmap_update_bits_base(struct regmap *map, unsigned int reg,
2785 unsigned int mask, unsigned int val, 2646 unsigned int mask, unsigned int val,
2786 bool *change) 2647 bool *change, bool async, bool force)
2787{ 2648{
2788 int ret; 2649 int ret;
2789 2650
2790 map->lock(map->lock_arg); 2651 map->lock(map->lock_arg);
2791 2652
2792 map->async = true; 2653 map->async = async;
2793 2654
2794 ret = _regmap_update_bits(map, reg, mask, val, change, false); 2655 ret = _regmap_update_bits(map, reg, mask, val, change, force);
2795 2656
2796 map->async = false; 2657 map->async = false;
2797 2658
@@ -2799,7 +2660,7 @@ int regmap_update_bits_check_async(struct regmap *map, unsigned int reg,
2799 2660
2800 return ret; 2661 return ret;
2801} 2662}
2802EXPORT_SYMBOL_GPL(regmap_update_bits_check_async); 2663EXPORT_SYMBOL_GPL(regmap_update_bits_base);
2803 2664
2804void regmap_async_complete_cb(struct regmap_async *async, int ret) 2665void regmap_async_complete_cb(struct regmap_async *async, int ret)
2805{ 2666{
diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index 182602bca923..3dc08ce15426 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -65,6 +65,36 @@ struct reg_sequence {
65 unsigned int delay_us; 65 unsigned int delay_us;
66}; 66};
67 67
68#define regmap_update_bits(map, reg, mask, val) \
69 regmap_update_bits_base(map, reg, mask, val, NULL, false, false)
70#define regmap_update_bits_async(map, reg, mask, val)\
71 regmap_update_bits_base(map, reg, mask, val, NULL, true, false)
72#define regmap_update_bits_check(map, reg, mask, val, change)\
73 regmap_update_bits_base(map, reg, mask, val, change, false, false)
74#define regmap_update_bits_check_async(map, reg, mask, val, change)\
75 regmap_update_bits_base(map, reg, mask, val, change, true, false)
76
77#define regmap_write_bits(map, reg, mask, val) \
78 regmap_update_bits_base(map, reg, mask, val, NULL, false, true)
79
80#define regmap_field_write(field, val) \
81 regmap_field_update_bits_base(field, ~0, val, NULL, false, false)
82#define regmap_field_force_write(field, val) \
83 regmap_field_update_bits_base(field, ~0, val, NULL, false, true)
84#define regmap_field_update_bits(field, mask, val)\
85 regmap_field_update_bits_base(field, mask, val, NULL, false, false)
86#define regmap_field_force_update_bits(field, mask, val) \
87 regmap_field_update_bits_base(field, mask, val, NULL, false, true)
88
89#define regmap_fields_write(field, id, val) \
90 regmap_fields_update_bits_base(field, id, ~0, val, NULL, false, false)
91#define regmap_fields_force_write(field, id, val) \
92 regmap_fields_update_bits_base(field, id, ~0, val, NULL, false, true)
93#define regmap_fields_update_bits(field, id, mask, val)\
94 regmap_fields_update_bits_base(field, id, mask, val, NULL, false, false)
95#define regmap_fields_force_update_bits(field, id, mask, val) \
96 regmap_fields_update_bits_base(field, id, mask, val, NULL, false, true)
97
68#ifdef CONFIG_REGMAP 98#ifdef CONFIG_REGMAP
69 99
70enum regmap_endian { 100enum regmap_endian {
@@ -691,18 +721,9 @@ int regmap_raw_read(struct regmap *map, unsigned int reg,
691 void *val, size_t val_len); 721 void *val, size_t val_len);
692int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val, 722int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
693 size_t val_count); 723 size_t val_count);
694int regmap_update_bits(struct regmap *map, unsigned int reg, 724int regmap_update_bits_base(struct regmap *map, unsigned int reg,
695 unsigned int mask, unsigned int val); 725 unsigned int mask, unsigned int val,
696int regmap_write_bits(struct regmap *map, unsigned int reg, 726 bool *change, bool async, bool force);
697 unsigned int mask, unsigned int val);
698int regmap_update_bits_async(struct regmap *map, unsigned int reg,
699 unsigned int mask, unsigned int val);
700int regmap_update_bits_check(struct regmap *map, unsigned int reg,
701 unsigned int mask, unsigned int val,
702 bool *change);
703int regmap_update_bits_check_async(struct regmap *map, unsigned int reg,
704 unsigned int mask, unsigned int val,
705 bool *change);
706int regmap_get_val_bytes(struct regmap *map); 727int regmap_get_val_bytes(struct regmap *map);
707int regmap_get_max_register(struct regmap *map); 728int regmap_get_max_register(struct regmap *map);
708int regmap_get_reg_stride(struct regmap *map); 729int regmap_get_reg_stride(struct regmap *map);
@@ -770,18 +791,14 @@ struct regmap_field *devm_regmap_field_alloc(struct device *dev,
770void devm_regmap_field_free(struct device *dev, struct regmap_field *field); 791void devm_regmap_field_free(struct device *dev, struct regmap_field *field);
771 792
772int regmap_field_read(struct regmap_field *field, unsigned int *val); 793int regmap_field_read(struct regmap_field *field, unsigned int *val);
773int regmap_field_write(struct regmap_field *field, unsigned int val); 794int regmap_field_update_bits_base(struct regmap_field *field,
774int regmap_field_update_bits(struct regmap_field *field, 795 unsigned int mask, unsigned int val,
775 unsigned int mask, unsigned int val); 796 bool *change, bool async, bool force);
776
777int regmap_fields_write(struct regmap_field *field, unsigned int id,
778 unsigned int val);
779int regmap_fields_force_write(struct regmap_field *field, unsigned int id,
780 unsigned int val);
781int regmap_fields_read(struct regmap_field *field, unsigned int id, 797int regmap_fields_read(struct regmap_field *field, unsigned int id,
782 unsigned int *val); 798 unsigned int *val);
783int regmap_fields_update_bits(struct regmap_field *field, unsigned int id, 799int regmap_fields_update_bits_base(struct regmap_field *field, unsigned int id,
784 unsigned int mask, unsigned int val); 800 unsigned int mask, unsigned int val,
801 bool *change, bool async, bool force);
785 802
786/** 803/**
787 * Description of an IRQ for the generic regmap irq_chip. 804 * Description of an IRQ for the generic regmap irq_chip.
@@ -945,42 +962,26 @@ static inline int regmap_bulk_read(struct regmap *map, unsigned int reg,
945 return -EINVAL; 962 return -EINVAL;
946} 963}
947 964
948static inline int regmap_update_bits(struct regmap *map, unsigned int reg, 965static inline int regmap_update_bits_base(struct regmap *map, unsigned int reg,
949 unsigned int mask, unsigned int val) 966 unsigned int mask, unsigned int val,
950{ 967 bool *change, bool async, bool force)
951 WARN_ONCE(1, "regmap API is disabled");
952 return -EINVAL;
953}
954
955static inline int regmap_write_bits(struct regmap *map, unsigned int reg,
956 unsigned int mask, unsigned int val)
957{ 968{
958 WARN_ONCE(1, "regmap API is disabled"); 969 WARN_ONCE(1, "regmap API is disabled");
959 return -EINVAL; 970 return -EINVAL;
960} 971}
961 972
962static inline int regmap_update_bits_async(struct regmap *map, 973static inline int regmap_field_update_bits_base(struct regmap_field *field,
963 unsigned int reg, 974 unsigned int mask, unsigned int val,
964 unsigned int mask, unsigned int val) 975 bool *change, bool async, bool force)
965{ 976{
966 WARN_ONCE(1, "regmap API is disabled"); 977 WARN_ONCE(1, "regmap API is disabled");
967 return -EINVAL; 978 return -EINVAL;
968} 979}
969 980
970static inline int regmap_update_bits_check(struct regmap *map, 981static inline int regmap_fields_update_bits_base(struct regmap_field *field,
971 unsigned int reg, 982 unsigned int id,
972 unsigned int mask, unsigned int val, 983 unsigned int mask, unsigned int val,
973 bool *change) 984 bool *change, bool async, bool force)
974{
975 WARN_ONCE(1, "regmap API is disabled");
976 return -EINVAL;
977}
978
979static inline int regmap_update_bits_check_async(struct regmap *map,
980 unsigned int reg,
981 unsigned int mask,
982 unsigned int val,
983 bool *change)
984{ 985{
985 WARN_ONCE(1, "regmap API is disabled"); 986 WARN_ONCE(1, "regmap API is disabled");
986 return -EINVAL; 987 return -EINVAL;