Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d856fce4 authored by Maarten ter Huurne's avatar Maarten ter Huurne Committed by Mark Brown
Browse files

regmap: Implemented default cache sync operation



This can be used for cache types for which syncing values one by one is
equally efficient as syncing a range, such as the flat cache.

Signed-off-by: default avatarMaarten ter Huurne <maarten@treewalker.org>
Signed-off-by: default avatarMark Brown <broonie@linaro.org>
parent 92ab1aab
Loading
Loading
Loading
Loading
+42 −4
Original line number Original line Diff line number Diff line
@@ -250,6 +250,38 @@ int regcache_write(struct regmap *map,
	return 0;
	return 0;
}
}


static int regcache_default_sync(struct regmap *map, unsigned int min,
				 unsigned int max)
{
	unsigned int reg;

	for (reg = min; reg <= max; reg++) {
		unsigned int val;
		int ret;

		if (regmap_volatile(map, reg))
			continue;

		ret = regcache_read(map, reg, &val);
		if (ret)
			return ret;

		/* Is this the hardware default?  If so skip. */
		ret = regcache_lookup_reg(map, reg);
		if (ret >= 0 && val == map->reg_defaults[ret].def)
			continue;

		map->cache_bypass = 1;
		ret = _regmap_write(map, reg, val);
		map->cache_bypass = 0;
		if (ret)
			return ret;
		dev_dbg(map->dev, "Synced register %#x, value %#x\n", reg, val);
	}

	return 0;
}

/**
/**
 * regcache_sync: Sync the register cache with the hardware.
 * regcache_sync: Sync the register cache with the hardware.
 *
 *
@@ -268,7 +300,7 @@ int regcache_sync(struct regmap *map)
	const char *name;
	const char *name;
	unsigned int bypass;
	unsigned int bypass;


	BUG_ON(!map->cache_ops || !map->cache_ops->sync);
	BUG_ON(!map->cache_ops);


	map->lock(map->lock_arg);
	map->lock(map->lock_arg);
	/* Remember the initial bypass state */
	/* Remember the initial bypass state */
@@ -297,7 +329,10 @@ int regcache_sync(struct regmap *map)
	}
	}
	map->cache_bypass = 0;
	map->cache_bypass = 0;


	if (map->cache_ops->sync)
		ret = map->cache_ops->sync(map, 0, map->max_register);
		ret = map->cache_ops->sync(map, 0, map->max_register);
	else
		ret = regcache_default_sync(map, 0, map->max_register);


	if (ret == 0)
	if (ret == 0)
		map->cache_dirty = false;
		map->cache_dirty = false;
@@ -331,7 +366,7 @@ int regcache_sync_region(struct regmap *map, unsigned int min,
	const char *name;
	const char *name;
	unsigned int bypass;
	unsigned int bypass;


	BUG_ON(!map->cache_ops || !map->cache_ops->sync);
	BUG_ON(!map->cache_ops);


	map->lock(map->lock_arg);
	map->lock(map->lock_arg);


@@ -346,7 +381,10 @@ int regcache_sync_region(struct regmap *map, unsigned int min,
	if (!map->cache_dirty)
	if (!map->cache_dirty)
		goto out;
		goto out;


	if (map->cache_ops->sync)
		ret = map->cache_ops->sync(map, min, max);
		ret = map->cache_ops->sync(map, min, max);
	else
		ret = regcache_default_sync(map, min, max);


out:
out:
	trace_regcache_sync(map->dev, name, "stop region");
	trace_regcache_sync(map->dev, name, "stop region");