[PATCH 3/3] regmap: Split raw writes that cross window boundaries

From: Mark Brown
Date: Thu Oct 04 2012 - 13:36:36 EST


If a block write covers a paged memory region and crosses a window
boundary then rather than failing the write split the transfer up
into multiple writes, making the whole process more transparent for
drivers.

Signed-off-by: Mark Brown <broonie@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
---
drivers/base/regmap/regmap.c | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index baf9586..07ea564 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -852,8 +852,25 @@ static int _regmap_raw_write(struct regmap *map, unsigned int reg,

range = _regmap_range_lookup(map, reg);
if (range) {
- ret = _regmap_select_page(map, &reg, range,
- val_len / map->format.val_bytes);
+ int val_num = val_len / map->format.val_bytes;
+ int win_offset = (reg - range->range_min) % range->window_len;
+ int win_residue = range->window_len - win_offset;
+
+ /* If the write goes beyond the end of the window split it */
+ while (val_num > win_residue) {
+ dev_dbg(map->dev, "Writing window %d/%d\n",
+ win_residue, val_len);
+ ret = _regmap_raw_write(map, reg, val, win_residue);
+ if (ret != 0)
+ return ret;
+
+ val += win_residue;
+ val_len -= win_residue;
+ val_num = val_len / map->format.val_bytes;
+ win_residue = range->window_len - win_offset;
+ }
+
+ ret = _regmap_select_page(map, &reg, range, val_num);
if (ret != 0)
return ret;
}
--
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/