]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/base/regmap/regmap.c
Merge branch 'rc-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild
[karo-tx-linux.git] / drivers / base / regmap / regmap.c
index d34adef1e63e2bee55aa3cd5a9e7f2d98912103b..a941dcfe7590119f7f1cc1b4a69574ea3d47b9b6 100644 (file)
@@ -228,30 +228,39 @@ static void regmap_format_32_native(void *buf, unsigned int val,
        *(u32 *)buf = val << shift;
 }
 
-static unsigned int regmap_parse_8(void *buf)
+static void regmap_parse_inplace_noop(void *buf)
 {
-       u8 *b = buf;
+}
+
+static unsigned int regmap_parse_8(const void *buf)
+{
+       const u8 *b = buf;
 
        return b[0];
 }
 
-static unsigned int regmap_parse_16_be(void *buf)
+static unsigned int regmap_parse_16_be(const void *buf)
+{
+       const __be16 *b = buf;
+
+       return be16_to_cpu(b[0]);
+}
+
+static void regmap_parse_16_be_inplace(void *buf)
 {
        __be16 *b = buf;
 
        b[0] = be16_to_cpu(b[0]);
-
-       return b[0];
 }
 
-static unsigned int regmap_parse_16_native(void *buf)
+static unsigned int regmap_parse_16_native(const void *buf)
 {
        return *(u16 *)buf;
 }
 
-static unsigned int regmap_parse_24(void *buf)
+static unsigned int regmap_parse_24(const void *buf)
 {
-       u8 *b = buf;
+       const u8 *b = buf;
        unsigned int ret = b[2];
        ret |= ((unsigned int)b[1]) << 8;
        ret |= ((unsigned int)b[0]) << 16;
@@ -259,16 +268,21 @@ static unsigned int regmap_parse_24(void *buf)
        return ret;
 }
 
-static unsigned int regmap_parse_32_be(void *buf)
+static unsigned int regmap_parse_32_be(const void *buf)
+{
+       const __be32 *b = buf;
+
+       return be32_to_cpu(b[0]);
+}
+
+static void regmap_parse_32_be_inplace(void *buf)
 {
        __be32 *b = buf;
 
        b[0] = be32_to_cpu(b[0]);
-
-       return b[0];
 }
 
-static unsigned int regmap_parse_32_native(void *buf)
+static unsigned int regmap_parse_32_native(const void *buf)
 {
        return *(u32 *)buf;
 }
@@ -555,16 +569,21 @@ struct regmap *regmap_init(struct device *dev,
                goto err_map;
        }
 
+       if (val_endian == REGMAP_ENDIAN_NATIVE)
+               map->format.parse_inplace = regmap_parse_inplace_noop;
+
        switch (config->val_bits) {
        case 8:
                map->format.format_val = regmap_format_8;
                map->format.parse_val = regmap_parse_8;
+               map->format.parse_inplace = regmap_parse_inplace_noop;
                break;
        case 16:
                switch (val_endian) {
                case REGMAP_ENDIAN_BIG:
                        map->format.format_val = regmap_format_16_be;
                        map->format.parse_val = regmap_parse_16_be;
+                       map->format.parse_inplace = regmap_parse_16_be_inplace;
                        break;
                case REGMAP_ENDIAN_NATIVE:
                        map->format.format_val = regmap_format_16_native;
@@ -585,6 +604,7 @@ struct regmap *regmap_init(struct device *dev,
                case REGMAP_ENDIAN_BIG:
                        map->format.format_val = regmap_format_32_be;
                        map->format.parse_val = regmap_parse_32_be;
+                       map->format.parse_inplace = regmap_parse_32_be_inplace;
                        break;
                case REGMAP_ENDIAN_NATIVE:
                        map->format.format_val = regmap_format_32_native;
@@ -917,8 +937,8 @@ static int _regmap_select_page(struct regmap *map, unsigned int *reg,
        return 0;
 }
 
-static int _regmap_raw_write(struct regmap *map, unsigned int reg,
-                            const void *val, size_t val_len, bool async)
+int _regmap_raw_write(struct regmap *map, unsigned int reg,
+                     const void *val, size_t val_len, bool async)
 {
        struct regmap_range_node *range;
        unsigned long flags;
@@ -930,7 +950,7 @@ static int _regmap_raw_write(struct regmap *map, unsigned int reg,
        size_t len;
        int i;
 
-       BUG_ON(!map->bus);
+       WARN_ON(!map->bus);
 
        /* Check for unwritable registers before we start */
        if (map->writeable_reg)
@@ -998,6 +1018,8 @@ static int _regmap_raw_write(struct regmap *map, unsigned int reg,
                if (!async)
                        return -ENOMEM;
 
+               trace_regmap_async_write_start(map->dev, reg, val_len);
+
                async->work_buf = kzalloc(map->format.buf_size,
                                          GFP_KERNEL | GFP_DMA);
                if (!async->work_buf) {
@@ -1078,6 +1100,17 @@ static int _regmap_raw_write(struct regmap *map, unsigned int reg,
        return ret;
 }
 
+/**
+ * regmap_can_raw_write - Test if regmap_raw_write() is supported
+ *
+ * @map: Map to check.
+ */
+bool regmap_can_raw_write(struct regmap *map)
+{
+       return map->bus && map->format.format_val && map->format.format_reg;
+}
+EXPORT_SYMBOL_GPL(regmap_can_raw_write);
+
 static int _regmap_bus_formatted_write(void *context, unsigned int reg,
                                       unsigned int val)
 {
@@ -1085,7 +1118,7 @@ static int _regmap_bus_formatted_write(void *context, unsigned int reg,
        struct regmap_range_node *range;
        struct regmap *map = context;
 
-       BUG_ON(!map->bus || !map->format.format_write);
+       WARN_ON(!map->bus || !map->format.format_write);
 
        range = _regmap_range_lookup(map, reg);
        if (range) {
@@ -1111,7 +1144,7 @@ static int _regmap_bus_raw_write(void *context, unsigned int reg,
 {
        struct regmap *map = context;
 
-       BUG_ON(!map->bus || !map->format.format_val);
+       WARN_ON(!map->bus || !map->format.format_val);
 
        map->format.format_val(map->work_buf + map->format.reg_bytes
                               + map->format.pad_bytes, val, 0);
@@ -1201,12 +1234,10 @@ int regmap_raw_write(struct regmap *map, unsigned int reg,
 {
        int ret;
 
-       if (!map->bus)
+       if (!regmap_can_raw_write(map))
                return -EINVAL;
        if (val_len % map->format.val_bytes)
                return -EINVAL;
-       if (reg % map->reg_stride)
-               return -EINVAL;
 
        map->lock(map->lock_arg);
 
@@ -1241,7 +1272,7 @@ int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
 
        if (!map->bus)
                return -EINVAL;
-       if (!map->format.parse_val)
+       if (!map->format.parse_inplace)
                return -EINVAL;
        if (reg % map->reg_stride)
                return -EINVAL;
@@ -1259,7 +1290,7 @@ int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
                        goto out;
                }
                for (i = 0; i < val_count * val_bytes; i += val_bytes)
-                       map->format.parse_val(wval + i);
+                       map->format.parse_inplace(wval + i);
        }
        /*
         * Some devices does not support bulk write, for
@@ -1337,7 +1368,7 @@ static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
        u8 *u8 = map->work_buf;
        int ret;
 
-       BUG_ON(!map->bus);
+       WARN_ON(!map->bus);
 
        range = _regmap_range_lookup(map, reg);
        if (range) {
@@ -1392,7 +1423,7 @@ static int _regmap_read(struct regmap *map, unsigned int reg,
        int ret;
        void *context = _regmap_map_get_context(map);
 
-       BUG_ON(!map->reg_read);
+       WARN_ON(!map->reg_read);
 
        if (!map->cache_bypass) {
                ret = regcache_read(map, reg, val);
@@ -1520,7 +1551,7 @@ int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
 
        if (!map->bus)
                return -EINVAL;
-       if (!map->format.parse_val)
+       if (!map->format.parse_inplace)
                return -EINVAL;
        if (reg % map->reg_stride)
                return -EINVAL;
@@ -1547,7 +1578,7 @@ int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
                }
 
                for (i = 0; i < val_count * val_bytes; i += val_bytes)
-                       map->format.parse_val(val + i);
+                       map->format.parse_inplace(val + i);
        } else {
                for (i = 0; i < val_count; i++) {
                        unsigned int ival;
@@ -1641,6 +1672,8 @@ void regmap_async_complete_cb(struct regmap_async *async, int ret)
        struct regmap *map = async->map;
        bool wake;
 
+       trace_regmap_async_io_complete(map->dev);
+
        spin_lock(&map->async_lock);
 
        list_del(&async->list);
@@ -1687,6 +1720,8 @@ int regmap_async_complete(struct regmap *map)
        if (!map->bus->async_write)
                return 0;
 
+       trace_regmap_async_complete_start(map->dev);
+
        wait_event(map->async_waitq, regmap_async_is_done(map));
 
        spin_lock_irqsave(&map->async_lock, flags);
@@ -1694,6 +1729,8 @@ int regmap_async_complete(struct regmap *map)
        map->async_ret = 0;
        spin_unlock_irqrestore(&map->async_lock, flags);
 
+       trace_regmap_async_complete_done(map->dev);
+
        return ret;
 }
 EXPORT_SYMBOL_GPL(regmap_async_complete);