diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2014-01-25 16:18:00 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-01-25 16:18:00 -0500 |
commit | bb1b64908f5a346b0654f02999e1a022a7e0c07d (patch) | |
tree | 0531fff6b1277750bc18c0a54d92be719f213b1c | |
parent | 4ba9920e5e9c0e16b5ed24292d45322907bb9035 (diff) | |
parent | 86776fc174973e556be7d668763f509a81124f8b (diff) |
Merge tag 'regmap-v3.14' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap
Pull regmap updates from Mark Brown:
"Nothing terribly exciting with regmap this release, mainly a few small
extensions to allow more devices to be supported:
- Allow the bulk I/O APIs to be used with no-bus regmaps
- Support interrupt controllers with zero ack base
- Warning and spelling fixes"
* tag 'regmap-v3.14' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap:
regmap: fix a couple of typos
regmap: Allow regmap_bulk_write() to work for "no-bus" regmaps
regmap: Allow regmap_bulk_read() to work for "no-bus" regmaps
regmap: irq: Allow using zero value for ack_base
regmap: Fix 'ret' would return an uninitialized value
-rw-r--r-- | drivers/base/regmap/regmap-irq.c | 6 | ||||
-rw-r--r-- | drivers/base/regmap/regmap.c | 72 | ||||
-rw-r--r-- | include/linux/regmap.h | 15 |
3 files changed, 54 insertions, 39 deletions
diff --git a/drivers/base/regmap/regmap-irq.c b/drivers/base/regmap/regmap-irq.c index 763c60d3d277..82692068d3cb 100644 --- a/drivers/base/regmap/regmap-irq.c +++ b/drivers/base/regmap/regmap-irq.c | |||
@@ -113,7 +113,7 @@ static void regmap_irq_sync_unlock(struct irq_data *data) | |||
113 | * OR if there is masked interrupt which hasn't been Acked, | 113 | * OR if there is masked interrupt which hasn't been Acked, |
114 | * it'll be ignored in irq handler, then may introduce irq storm | 114 | * it'll be ignored in irq handler, then may introduce irq storm |
115 | */ | 115 | */ |
116 | if (d->mask_buf[i] && d->chip->ack_base) { | 116 | if (d->mask_buf[i] && (d->chip->ack_base || d->chip->use_ack)) { |
117 | reg = d->chip->ack_base + | 117 | reg = d->chip->ack_base + |
118 | (i * map->reg_stride * d->irq_reg_stride); | 118 | (i * map->reg_stride * d->irq_reg_stride); |
119 | ret = regmap_write(map, reg, d->mask_buf[i]); | 119 | ret = regmap_write(map, reg, d->mask_buf[i]); |
@@ -271,7 +271,7 @@ static irqreturn_t regmap_irq_thread(int irq, void *d) | |||
271 | for (i = 0; i < data->chip->num_regs; i++) { | 271 | for (i = 0; i < data->chip->num_regs; i++) { |
272 | data->status_buf[i] &= ~data->mask_buf[i]; | 272 | data->status_buf[i] &= ~data->mask_buf[i]; |
273 | 273 | ||
274 | if (data->status_buf[i] && chip->ack_base) { | 274 | if (data->status_buf[i] && (chip->ack_base || chip->use_ack)) { |
275 | reg = chip->ack_base + | 275 | reg = chip->ack_base + |
276 | (i * map->reg_stride * data->irq_reg_stride); | 276 | (i * map->reg_stride * data->irq_reg_stride); |
277 | ret = regmap_write(map, reg, data->status_buf[i]); | 277 | ret = regmap_write(map, reg, data->status_buf[i]); |
@@ -448,7 +448,7 @@ int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags, | |||
448 | goto err_alloc; | 448 | goto err_alloc; |
449 | } | 449 | } |
450 | 450 | ||
451 | if (d->status_buf[i] && chip->ack_base) { | 451 | if (d->status_buf[i] && (chip->ack_base || chip->use_ack)) { |
452 | reg = chip->ack_base + | 452 | reg = chip->ack_base + |
453 | (i * map->reg_stride * d->irq_reg_stride); | 453 | (i * map->reg_stride * d->irq_reg_stride); |
454 | ret = regmap_write(map, reg, | 454 | ret = regmap_write(map, reg, |
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..4149f1a9b003 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 |
@@ -497,11 +497,13 @@ struct regmap_irq { | |||
497 | * | 497 | * |
498 | * @status_base: Base status register address. | 498 | * @status_base: Base status register address. |
499 | * @mask_base: Base mask register address. | 499 | * @mask_base: Base mask register address. |
500 | * @ack_base: Base ack address. If zero then the chip is clear on read. | 500 | * @ack_base: Base ack address. If zero then the chip is clear on read. |
501 | * Using zero value is possible with @use_ack bit. | ||
501 | * @wake_base: Base address for wake enables. If zero unsupported. | 502 | * @wake_base: Base address for wake enables. If zero unsupported. |
502 | * @irq_reg_stride: Stride to use for chips where registers are not contiguous. | 503 | * @irq_reg_stride: Stride to use for chips where registers are not contiguous. |
503 | * @init_ack_masked: Ack all masked interrupts once during initalization. | 504 | * @init_ack_masked: Ack all masked interrupts once during initalization. |
504 | * @mask_invert: Inverted mask register: cleared bits are masked out. | 505 | * @mask_invert: Inverted mask register: cleared bits are masked out. |
506 | * @use_ack: Use @ack register even if it is zero. | ||
505 | * @wake_invert: Inverted wake register: cleared bits are wake enabled. | 507 | * @wake_invert: Inverted wake register: cleared bits are wake enabled. |
506 | * @runtime_pm: Hold a runtime PM lock on the device when accessing it. | 508 | * @runtime_pm: Hold a runtime PM lock on the device when accessing it. |
507 | * | 509 | * |
@@ -520,6 +522,7 @@ struct regmap_irq_chip { | |||
520 | unsigned int irq_reg_stride; | 522 | unsigned int irq_reg_stride; |
521 | bool init_ack_masked:1; | 523 | bool init_ack_masked:1; |
522 | bool mask_invert:1; | 524 | bool mask_invert:1; |
525 | bool use_ack:1; | ||
523 | bool wake_invert:1; | 526 | bool wake_invert:1; |
524 | bool runtime_pm:1; | 527 | bool runtime_pm:1; |
525 | 528 | ||