Merge remote-tracking branches 'asoc/topic/rcar', 'asoc/topic/rockchip', 'asoc/topic...
[cascardo/linux.git] / drivers / base / regmap / regmap.c
index ee54e84..4b89c95 100644 (file)
@@ -557,6 +557,8 @@ enum regmap_endian regmap_get_val_endian(struct device *dev,
                        endian = REGMAP_ENDIAN_BIG;
                else if (of_property_read_bool(np, "little-endian"))
                        endian = REGMAP_ENDIAN_LITTLE;
+               else if (of_property_read_bool(np, "native-endian"))
+                       endian = REGMAP_ENDIAN_NATIVE;
 
                /* If the endianness was specified in DT, use that */
                if (endian != REGMAP_ENDIAN_DEFAULT)
@@ -1690,100 +1692,63 @@ int regmap_raw_write(struct regmap *map, unsigned int reg,
 EXPORT_SYMBOL_GPL(regmap_raw_write);
 
 /**
- * regmap_field_write(): Write a value to a single register field
- *
- * @field: Register field to write to
- * @val: Value to be written
- *
- * A value of zero will be returned on success, a negative errno will
- * be returned in error cases.
- */
-int regmap_field_write(struct regmap_field *field, unsigned int val)
-{
-       return regmap_update_bits(field->regmap, field->reg,
-                               field->mask, val << field->shift);
-}
-EXPORT_SYMBOL_GPL(regmap_field_write);
-
-/**
- * regmap_field_update_bits(): Perform a read/modify/write cycle
- *                              on the register field
+ * regmap_field_update_bits_base():
+ *     Perform a read/modify/write cycle on the register field
+ *     with change, async, force option
  *
  * @field: Register field to write to
  * @mask: Bitmask to change
  * @val: Value to be written
+ * @change: Boolean indicating if a write was done
+ * @async: Boolean indicating asynchronously
+ * @force: Boolean indicating use force update
  *
  * A value of zero will be returned on success, a negative errno will
  * be returned in error cases.
  */
-int regmap_field_update_bits(struct regmap_field *field, unsigned int mask, unsigned int val)
+int regmap_field_update_bits_base(struct regmap_field *field,
+                                 unsigned int mask, unsigned int val,
+                                 bool *change, bool async, bool force)
 {
        mask = (mask << field->shift) & field->mask;
 
-       return regmap_update_bits(field->regmap, field->reg,
-                                 mask, val << field->shift);
-}
-EXPORT_SYMBOL_GPL(regmap_field_update_bits);
-
-/**
- * regmap_fields_write(): Write a value to a single register field with port ID
- *
- * @field: Register field to write to
- * @id: port ID
- * @val: Value to be written
- *
- * A value of zero will be returned on success, a negative errno will
- * be returned in error cases.
- */
-int regmap_fields_write(struct regmap_field *field, unsigned int id,
-                       unsigned int val)
-{
-       if (id >= field->id_size)
-               return -EINVAL;
-
-       return regmap_update_bits(field->regmap,
-                                 field->reg + (field->id_offset * id),
-                                 field->mask, val << field->shift);
-}
-EXPORT_SYMBOL_GPL(regmap_fields_write);
-
-int regmap_fields_force_write(struct regmap_field *field, unsigned int id,
-                       unsigned int val)
-{
-       if (id >= field->id_size)
-               return -EINVAL;
-
-       return regmap_write_bits(field->regmap,
-                                 field->reg + (field->id_offset * id),
-                                 field->mask, val << field->shift);
+       return regmap_update_bits_base(field->regmap, field->reg,
+                                      mask, val << field->shift,
+                                      change, async, force);
 }
-EXPORT_SYMBOL_GPL(regmap_fields_force_write);
+EXPORT_SYMBOL_GPL(regmap_field_update_bits_base);
 
 /**
- * regmap_fields_update_bits():        Perform a read/modify/write cycle
- *                              on the register field
+ * regmap_fields_update_bits_base():
+ *     Perform a read/modify/write cycle on the register field
+ *     with change, async, force option
  *
  * @field: Register field to write to
  * @id: port ID
  * @mask: Bitmask to change
  * @val: Value to be written
+ * @change: Boolean indicating if a write was done
+ * @async: Boolean indicating asynchronously
+ * @force: Boolean indicating use force update
  *
  * A value of zero will be returned on success, a negative errno will
  * be returned in error cases.
  */
-int regmap_fields_update_bits(struct regmap_field *field,  unsigned int id,
-                             unsigned int mask, unsigned int val)
+int regmap_fields_update_bits_base(struct regmap_field *field,  unsigned int id,
+                                  unsigned int mask, unsigned int val,
+                                  bool *change, bool async, bool force)
 {
        if (id >= field->id_size)
                return -EINVAL;
 
        mask = (mask << field->shift) & field->mask;
 
-       return regmap_update_bits(field->regmap,
-                                 field->reg + (field->id_offset * id),
-                                 mask, val << field->shift);
+       return regmap_update_bits_base(field->regmap,
+                                      field->reg + (field->id_offset * id),
+                                      mask, val << field->shift,
+                                      change, async, force);
 }
-EXPORT_SYMBOL_GPL(regmap_fields_update_bits);
+EXPORT_SYMBOL_GPL(regmap_fields_update_bits_base);
 
 /*
  * regmap_bulk_write(): Write multiple registers to the device
@@ -2253,6 +2218,9 @@ static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
 
        WARN_ON(!map->bus);
 
+       if (!map->bus || !map->bus->read)
+               return -EINVAL;
+
        range = _regmap_range_lookup(map, reg);
        if (range) {
                ret = _regmap_select_page(map, &reg, range,
@@ -2648,76 +2616,36 @@ static int _regmap_update_bits(struct regmap *map, unsigned int reg,
 }
 
 /**
- * regmap_update_bits: Perform a read/modify/write cycle on the register map
- *
- * @map: Register map to update
- * @reg: Register to update
- * @mask: Bitmask to change
- * @val: New value for bitmask
- *
- * Returns zero for success, a negative number on error.
- */
-int regmap_update_bits(struct regmap *map, unsigned int reg,
-                      unsigned int mask, unsigned int val)
-{
-       int ret;
-
-       map->lock(map->lock_arg);
-       ret = _regmap_update_bits(map, reg, mask, val, NULL, false);
-       map->unlock(map->lock_arg);
-
-       return ret;
-}
-EXPORT_SYMBOL_GPL(regmap_update_bits);
-
-/**
- * regmap_write_bits: Perform a read/modify/write cycle on the register map
- *
- * @map: Register map to update
- * @reg: Register to update
- * @mask: Bitmask to change
- * @val: New value for bitmask
- *
- * Returns zero for success, a negative number on error.
- */
-int regmap_write_bits(struct regmap *map, unsigned int reg,
-                     unsigned int mask, unsigned int val)
-{
-       int ret;
-
-       map->lock(map->lock_arg);
-       ret = _regmap_update_bits(map, reg, mask, val, NULL, true);
-       map->unlock(map->lock_arg);
-
-       return ret;
-}
-EXPORT_SYMBOL_GPL(regmap_write_bits);
-
-/**
- * regmap_update_bits_async: Perform a read/modify/write cycle on the register
- *                           map asynchronously
+ * regmap_update_bits_base:
+ *     Perform a read/modify/write cycle on the
+ *     register map with change, async, force option
  *
  * @map: Register map to update
  * @reg: Register to update
  * @mask: Bitmask to change
  * @val: New value for bitmask
+ * @change: Boolean indicating if a write was done
+ * @async: Boolean indicating asynchronously
+ * @force: Boolean indicating use force update
  *
+ * if async was true,
  * With most buses the read must be done synchronously so this is most
  * useful for devices with a cache which do not need to interact with
  * the hardware to determine the current register value.
  *
  * Returns zero for success, a negative number on error.
  */
-int regmap_update_bits_async(struct regmap *map, unsigned int reg,
-                            unsigned int mask, unsigned int val)
+int regmap_update_bits_base(struct regmap *map, unsigned int reg,
+                           unsigned int mask, unsigned int val,
+                           bool *change, bool async, bool force)
 {
        int ret;
 
        map->lock(map->lock_arg);
 
-       map->async = true;
+       map->async = async;
 
-       ret = _regmap_update_bits(map, reg, mask, val, NULL, false);
+       ret = _regmap_update_bits(map, reg, mask, val, change, force);
 
        map->async = false;
 
@@ -2725,69 +2653,30 @@ int regmap_update_bits_async(struct regmap *map, unsigned int reg,
 
        return ret;
 }
-EXPORT_SYMBOL_GPL(regmap_update_bits_async);
+EXPORT_SYMBOL_GPL(regmap_update_bits_base);
 
 /**
- * regmap_update_bits_check: Perform a read/modify/write cycle on the
- *                           register map and report if updated
- *
- * @map: Register map to update
- * @reg: Register to update
- * @mask: Bitmask to change
- * @val: New value for bitmask
- * @change: Boolean indicating if a write was done
- *
- * Returns zero for success, a negative number on error.
- */
-int regmap_update_bits_check(struct regmap *map, unsigned int reg,
-                            unsigned int mask, unsigned int val,
-                            bool *change)
-{
-       int ret;
-
-       map->lock(map->lock_arg);
-       ret = _regmap_update_bits(map, reg, mask, val, change, false);
-       map->unlock(map->lock_arg);
-       return ret;
-}
-EXPORT_SYMBOL_GPL(regmap_update_bits_check);
-
-/**
- * regmap_update_bits_check_async: Perform a read/modify/write cycle on the
- *                                 register map asynchronously and report if
- *                                 updated
+ * regmap_write_bits: Perform a read/modify/write cycle on the register map
  *
  * @map: Register map to update
  * @reg: Register to update
  * @mask: Bitmask to change
  * @val: New value for bitmask
- * @change: Boolean indicating if a write was done
- *
- * With most buses the read must be done synchronously so this is most
- * useful for devices with a cache which do not need to interact with
- * the hardware to determine the current register value.
  *
  * Returns zero for success, a negative number on error.
  */
-int regmap_update_bits_check_async(struct regmap *map, unsigned int reg,
-                                  unsigned int mask, unsigned int val,
-                                  bool *change)
+int regmap_write_bits(struct regmap *map, unsigned int reg,
+                     unsigned int mask, unsigned int val)
 {
        int ret;
 
        map->lock(map->lock_arg);
-
-       map->async = true;
-
-       ret = _regmap_update_bits(map, reg, mask, val, change, false);
-
-       map->async = false;
-
+       ret = _regmap_update_bits(map, reg, mask, val, NULL, true);
        map->unlock(map->lock_arg);
 
        return ret;
 }
-EXPORT_SYMBOL_GPL(regmap_update_bits_check_async);
+EXPORT_SYMBOL_GPL(regmap_write_bits);
 
 void regmap_async_complete_cb(struct regmap_async *async, int ret)
 {