diff options
author | Mark Brown <broonie@linaro.org> | 2014-01-09 09:34:13 -0500 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2014-01-09 09:34:13 -0500 |
commit | eec8ae7a547037b498ba9e9159905090255e0197 (patch) | |
tree | 33c568114f9904266cb2b2905148f8c6f499761f | |
parent | d6e0a2dd12f4067a5bcefb8bbd8ddbeff800afbc (diff) | |
parent | bdc39644b5b42568499496a9fbd99a29ebf1f776 (diff) |
Merge remote-tracking branch 'regmap/topic/core' into regmap-next
-rw-r--r-- | drivers/base/regmap/regmap.c | 72 | ||||
-rw-r--r-- | include/linux/regmap.h | 10 |
2 files changed, 47 insertions, 35 deletions
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index c2e002100949..6a19515f8a45 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c | |||
@@ -1514,21 +1514,49 @@ int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val, | |||
1514 | { | 1514 | { |
1515 | int ret = 0, i; | 1515 | int ret = 0, i; |
1516 | size_t val_bytes = map->format.val_bytes; | 1516 | size_t val_bytes = map->format.val_bytes; |
1517 | void *wval; | ||
1518 | 1517 | ||
1519 | if (!map->bus) | 1518 | if (map->bus && !map->format.parse_inplace) |
1520 | return -EINVAL; | ||
1521 | if (!map->format.parse_inplace) | ||
1522 | return -EINVAL; | 1519 | return -EINVAL; |
1523 | if (reg % map->reg_stride) | 1520 | if (reg % map->reg_stride) |
1524 | return -EINVAL; | 1521 | return -EINVAL; |
1525 | 1522 | ||
1526 | map->lock(map->lock_arg); | 1523 | map->lock(map->lock_arg); |
1524 | /* | ||
1525 | * Some devices don't support bulk write, for | ||
1526 | * them we have a series of single write operations. | ||
1527 | */ | ||
1528 | if (!map->bus || map->use_single_rw) { | ||
1529 | for (i = 0; i < val_count; i++) { | ||
1530 | unsigned int ival; | ||
1531 | |||
1532 | switch (val_bytes) { | ||
1533 | case 1: | ||
1534 | ival = *(u8 *)(val + (i * val_bytes)); | ||
1535 | break; | ||
1536 | case 2: | ||
1537 | ival = *(u16 *)(val + (i * val_bytes)); | ||
1538 | break; | ||
1539 | case 4: | ||
1540 | ival = *(u32 *)(val + (i * val_bytes)); | ||
1541 | break; | ||
1542 | #ifdef CONFIG_64BIT | ||
1543 | case 8: | ||
1544 | ival = *(u64 *)(val + (i * val_bytes)); | ||
1545 | break; | ||
1546 | #endif | ||
1547 | default: | ||
1548 | ret = -EINVAL; | ||
1549 | goto out; | ||
1550 | } | ||
1527 | 1551 | ||
1528 | /* No formatting is require if val_byte is 1 */ | 1552 | ret = _regmap_write(map, reg + (i * map->reg_stride), |
1529 | if (val_bytes == 1) { | 1553 | ival); |
1530 | wval = (void *)val; | 1554 | if (ret != 0) |
1555 | goto out; | ||
1556 | } | ||
1531 | } else { | 1557 | } else { |
1558 | void *wval; | ||
1559 | |||
1532 | wval = kmemdup(val, val_count * val_bytes, GFP_KERNEL); | 1560 | wval = kmemdup(val, val_count * val_bytes, GFP_KERNEL); |
1533 | if (!wval) { | 1561 | if (!wval) { |
1534 | ret = -ENOMEM; | 1562 | ret = -ENOMEM; |
@@ -1537,27 +1565,11 @@ int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val, | |||
1537 | } | 1565 | } |
1538 | for (i = 0; i < val_count * val_bytes; i += val_bytes) | 1566 | for (i = 0; i < val_count * val_bytes; i += val_bytes) |
1539 | map->format.parse_inplace(wval + i); | 1567 | map->format.parse_inplace(wval + i); |
1540 | } | 1568 | |
1541 | /* | ||
1542 | * Some devices does not support bulk write, for | ||
1543 | * them we have a series of single write operations. | ||
1544 | */ | ||
1545 | if (map->use_single_rw) { | ||
1546 | for (i = 0; i < val_count; i++) { | ||
1547 | ret = _regmap_raw_write(map, | ||
1548 | reg + (i * map->reg_stride), | ||
1549 | val + (i * val_bytes), | ||
1550 | val_bytes); | ||
1551 | if (ret != 0) | ||
1552 | goto out; | ||
1553 | } | ||
1554 | } else { | ||
1555 | ret = _regmap_raw_write(map, reg, wval, val_bytes * val_count); | 1569 | ret = _regmap_raw_write(map, reg, wval, val_bytes * val_count); |
1556 | } | ||
1557 | 1570 | ||
1558 | if (val_bytes != 1) | ||
1559 | kfree(wval); | 1571 | kfree(wval); |
1560 | 1572 | } | |
1561 | out: | 1573 | out: |
1562 | map->unlock(map->lock_arg); | 1574 | map->unlock(map->lock_arg); |
1563 | return ret; | 1575 | return ret; |
@@ -1897,14 +1909,10 @@ int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val, | |||
1897 | size_t val_bytes = map->format.val_bytes; | 1909 | size_t val_bytes = map->format.val_bytes; |
1898 | bool vol = regmap_volatile_range(map, reg, val_count); | 1910 | bool vol = regmap_volatile_range(map, reg, val_count); |
1899 | 1911 | ||
1900 | if (!map->bus) | ||
1901 | return -EINVAL; | ||
1902 | if (!map->format.parse_inplace) | ||
1903 | return -EINVAL; | ||
1904 | if (reg % map->reg_stride) | 1912 | if (reg % map->reg_stride) |
1905 | return -EINVAL; | 1913 | return -EINVAL; |
1906 | 1914 | ||
1907 | if (vol || map->cache_type == REGCACHE_NONE) { | 1915 | if (map->bus && map->format.parse_inplace && (vol || map->cache_type == REGCACHE_NONE)) { |
1908 | /* | 1916 | /* |
1909 | * Some devices does not support bulk read, for | 1917 | * Some devices does not support bulk read, for |
1910 | * them we have a series of single read operations. | 1918 | * them we have a series of single read operations. |
@@ -2173,6 +2181,10 @@ int regmap_register_patch(struct regmap *map, const struct reg_default *regs, | |||
2173 | int i, ret; | 2181 | int i, ret; |
2174 | bool bypass; | 2182 | bool bypass; |
2175 | 2183 | ||
2184 | if (WARN_ONCE(num_regs <= 0, "invalid registers number (%d)\n", | ||
2185 | num_regs)) | ||
2186 | return 0; | ||
2187 | |||
2176 | map->lock(map->lock_arg); | 2188 | map->lock(map->lock_arg); |
2177 | 2189 | ||
2178 | bypass = map->cache_bypass; | 2190 | bypass = map->cache_bypass; |
diff --git a/include/linux/regmap.h b/include/linux/regmap.h index e55907804d39..1f6643ce216a 100644 --- a/include/linux/regmap.h +++ b/include/linux/regmap.h | |||
@@ -122,9 +122,9 @@ typedef void (*regmap_unlock)(void *); | |||
122 | * volatile_table (see below) is not, the check is performed on | 122 | * volatile_table (see below) is not, the check is performed on |
123 | * such table (a register is volatile if it belongs to one of | 123 | * such table (a register is volatile if it belongs to one of |
124 | * the ranges specified by volatile_table). | 124 | * the ranges specified by volatile_table). |
125 | * @precious_reg: Optional callback returning true if the rgister | 125 | * @precious_reg: Optional callback returning true if the register |
126 | * should not be read outside of a call from the driver | 126 | * should not be read outside of a call from the driver |
127 | * (eg, a clear on read interrupt status register). If this | 127 | * (e.g., a clear on read interrupt status register). If this |
128 | * field is NULL but precious_table (see below) is not, the | 128 | * field is NULL but precious_table (see below) is not, the |
129 | * check is performed on such table (a register is precious if | 129 | * check is performed on such table (a register is precious if |
130 | * it belongs to one of the ranges specified by precious_table). | 130 | * it belongs to one of the ranges specified by precious_table). |
@@ -136,9 +136,9 @@ typedef void (*regmap_unlock)(void *); | |||
136 | * are not overridden). | 136 | * are not overridden). |
137 | * @reg_read: Optional callback that if filled will be used to perform | 137 | * @reg_read: Optional callback that if filled will be used to perform |
138 | * all the reads from the registers. Should only be provided for | 138 | * all the reads from the registers. Should only be provided for |
139 | * devices whos read operation cannot be represented as a simple read | 139 | * devices whose read operation cannot be represented as a simple |
140 | * operation on a bus such as SPI, I2C, etc. Most of the devices do | 140 | * read operation on a bus such as SPI, I2C, etc. Most of the |
141 | * not need this. | 141 | * devices do not need this. |
142 | * @reg_write: Same as above for writing. | 142 | * @reg_write: Same as above for writing. |
143 | * @fast_io: Register IO is fast. Use a spinlock instead of a mutex | 143 | * @fast_io: Register IO is fast. Use a spinlock instead of a mutex |
144 | * to perform locking. This field is ignored if custom lock/unlock | 144 | * to perform locking. This field is ignored if custom lock/unlock |