aboutsummaryrefslogtreecommitdiff
path: root/drivers/base/regmap/regcache.c
AgeCommit message (Collapse)Author
2012-04-10regmap: implement register stridingStephen Warren
regmap_config.reg_stride is introduced. All extant register addresses are a multiple of this value. Users of serial-oriented regmap busses will typically set this to 1. Users of the MMIO regmap bus will typically set this based on the value size of their registers, in bytes, so 4 for a 32-bit register. Throughout the regmap code, actual register addresses are used. Wherever the register address is used to index some array of values, the address is divided by the stride to determine the index, or vice-versa. Error- checking is added to all entry-points for register address data to ensure that register addresses actually satisfy the specified stride. The MMIO bus ensures that the specified stride is large enough for the register size. Signed-off-by: Stephen Warren <swarren@nvidia.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-04-10Merge branches 'regmap-core', 'regmap-mmio' and 'regmap-naming' into ↵Mark Brown
regmap-stride
2012-04-06regmap: introduce fast_io busses, and use a spinlock for themStephen Warren
Some bus types have very fast IO. For these, acquiring a mutex for every IO operation is a significant overhead. Allow busses to indicate their IO is fast, and enhance regmap to use a spinlock for those busses. [Currently limited to native endian registers -- broonie] Signed-off-by: Stephen Warren <swarren@nvidia.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-04-03regmap: Export regcache_sync_region()Mark Brown
regcache_sync_region() isn't going to be useful to most drivers if we don't export it since otherwise they can't use it when built modular. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-03-24Merge tag 'device-for-3.4' of ↵Linus Torvalds
git://git.kernel.org/pub/scm/linux/kernel/git/paulg/linux Pull <linux/device.h> avoidance patches from Paul Gortmaker: "Nearly every subsystem has some kind of header with a proto like: void foo(struct device *dev); and yet there is no reason for most of these guys to care about the sub fields within the device struct. This allows us to significantly reduce the scope of headers including headers. For this instance, a reduction of about 40% is achieved by replacing the include with the simple fact that the device is some kind of a struct. Unlike the much larger module.h cleanup, this one is simply two commits. One to fix the implicit <linux/device.h> users, and then one to delete the device.h includes from the linux/include/ dir wherever possible." * tag 'device-for-3.4' of git://git.kernel.org/pub/scm/linux/kernel/git/paulg/linux: device.h: audit and cleanup users in main include dir device.h: cleanup users outside of linux/include (C files)
2012-03-14Merge remote-tracking branch 'regmap/topic/bulk' into regmap-nextMark Brown
2012-03-14Merge remote-tracking branches 'regmap/topic/patch' and 'regmap/topic/sync' ↵Mark Brown
into regmap-next
2012-03-14Merge remote-tracking branch 'regmap/topic/drivers' into regmap-nextMark Brown
Resolved simple add/add conflicts: drivers/base/regmap/internal.h drivers/base/regmap/regmap.c
2012-03-11device.h: cleanup users outside of linux/include (C files)Paul Gortmaker
For files that are actively using linux/device.h, make sure that they call it out. This will allow us to clean up some of the implicit uses of linux/device.h within include/* without introducing build regressions. Yes, this was created by "cheating" -- i.e. the headers were cleaned up, and then the fallout was found and fixed, and then the two commits were reordered. This ensures we don't introduce build regressions into the git history. Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
2012-02-24regmap: Allow drivers to sync only part of the register cacheMark Brown
Provide a regcache_sync_region() operation which allows drivers to write only part of the cache back to the hardware. This is intended for use in cases like power domains or DSP memories where part of the device register map may be reset without fully resetting the device. Fully supporting these devices is likely to require additional work to make specific regions of the register map cache only while they are in reset, but this is enough for most devices. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-02-24regmap: Supply ranges to the sync operationsMark Brown
In order to allow us to support partial sync operations add minimum and maximum register arguments to the sync operation and update the rbtree and lzo caches to use this new information. The LZO implementation is obviously not good, we could exit the iteration earlier, but there may be room for more wide reaching optimisation there. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-02-23regmap: Add tracepoints for cache only and cache bypassMark Brown
Useful for figuring out where the hardware interaction went or came from. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-02-23regmap: Mark the cache as clean after a successful syncMark Brown
Previously the cache would never be marked clean, meaning syncs would never be suppressed which isn't the end of the world but could be inefficient. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-02-23regmap: Remove default cache sync implementationMark Brown
It's not used as all cache types have sync operations so it's just dead code which never gets tested. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-02-20Merge branch 'topic/patch' of ↵Mark Brown
git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap into regmap-drivers
2012-02-17regmap: Implement support for 32 bit registers and valuesMark Brown
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-02-17regmap: Bypassing cache when initializing cacheLaxman Dewangan
During regcache_init, if client has not passed the default data of cached register then it is directly read from the hw to initialize cache. This hw register read happens before cache ops are initialized and hence avoiding register read to check for the data available on cache or not by enabling flag of cache_bypass. Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-02-15regmap: Fix cache defaults initialization from raw cache defaultsLars-Peter Clausen
Currently registers with a value of 0 are ignored when initializing the register defaults from raw defaults. This worked in the past, because registers without a explicit default were assumed to have a default value of 0. This was changed in commit b03622a8 ("regmap: Ensure rbtree syncs registers set to zero properly"). As a result registers, which have a raw default value of 0 are now assumed to have no default. This again can result in unnecessary writes when syncing the cache. It will also result in unnecessary reads for e.g. the first update operation. In the case where readback is not possible this will even let the update operation fail, if the register has not been written to before. So this patch removes the check. Instead it adds a check to ignore raw defaults for registers which are volatile, since those registers are not cached. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Cc: stable@vger.kernel.org
2012-01-31regmap: Remove incorrect unreachable comment in regcache_set_val()Axel Lin
regcache_set_val() returns false if cache[idx] != val. Thus it actually is not unreachable. Signed-off-by: Axel Lin <axel.lin@gmail.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-01-25regmap: Bypass the cache when applying patchesMark Brown
Otherwise any patch that affects a register which is writable may trash cached values. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-01-25regmap: Skip patch application when the cache is not dirty on syncMark Brown
On the basis that if we don't actually need to resync the cache then the patches are probably also already applied. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-01-25regmap: Unexport regcache_write() and regcache_read()Mark Brown
They have no current users which is fortunate as they don't take the lock and therefore aren't safe to use externally. We'll need to add new operations if direct cache access is needed. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-01-23regmap: Support register patch setsMark Brown
Device manufacturers frequently provide register sequences, usually not fully documented, to be run at startup in order to provide better defaults for devices (for example, improving performance in the light of silicon evaluation). Support such updates by allowing drivers to register update sets with the core. These updates will be written to the device immediately and will also be rewritten when the cache is synced. The assumption is that the reason for resyncing the cache will always be that the device has been powered off. If this turns out to not be the case then a separate operation can be provided. Currently the implementation only allows a single set of updates to be specified for a device, this could be extended in future. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2011-11-30regmap: Add trace event for successful cache readsMark Brown
Currently we only trace physical reads, there's no instrumentation if the read is satisfied from cache. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2011-11-20regmap: Remove indexed cache typeMark Brown
There should be no situation where it offers any advantage over rbtree and there are no current users so remove the code for simplicity. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2011-11-17regmap: Drop check whether a register is readable in regcache_readLars-Peter Clausen
One of the reasons for using a cache is to have a software shadow of a register which is writable but not readable. This allows us to do a read-modify-write operation on such a register. Currently regcache checks whether a register is readable when performing a cached read and returns an error if it is not. Drop this check, since it will prevent us from using the cache for registers where read-back is not possible. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2011-11-17regmap: Properly round cache_word_sizeLars-Peter Clausen
regcache currently only properly works with val bit sizes of 8 or 16, since it will, when calculating the cache word size, round down. This causes the cache storage to be too small to hold the full register value. Fix this by rounding up instead. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2011-11-16regmap: Make reg_config reg_defaults constLars-Peter Clausen
The reg_defaults field usually points to a static per driver array, which should not be modified. Make requirement this explicit by making reg_defaults const. To allow this the regcache_init code needs some minor changes. Previoulsy the reg_config was not available in regcache_init and regmap->reg_defaults was used to pass the default register set to regcache_init. Now that the reg_config is available we can work on it directly. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2011-11-16regmap: Move initialization of regcache related fields to regcache_initLars-Peter Clausen
Move the initialization regcache related fields of the regmap struct to regcache_init. This allows us to keep regmap and regcache code better separated. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2011-11-14regmap: Fix memory leak in regcache_init error pathLars-Peter Clausen
Make sure all allocated memory gets freed again in case initializing the cache failed. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Acked-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2011-11-14regmap: Fix memory leak in regcache_hw_init error pathLars-Peter Clausen
Make sure reg_defaults_raw gets freed in case of an error. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Acked-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2011-11-08regmap: Track if the register cache is dirty and suppress unneeded syncsMark Brown
Allow drivers to optimise out the register cache sync if they didn't need to do one. If the hardware is desynced from the register cache (by power loss for example) then the driver should call regcache_mark_dirty() to let the core know about this. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2011-10-31drivers/base: Add export.h for EXPORT_SYMBOL/THIS_MODULE as required.Paul Gortmaker
Most of these files were implicitly getting EXPORT_SYMBOL via device.h which was including module.h, but that path will be broken soon. [ with input from Stephen Rothwell <sfr@canb.auug.org.au> ] Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
2011-10-10regmap: Allow caches for devices with no defaultsMark Brown
We only really need the defaults in order to cut down the number of registers we sync and to satisfy reads while the device is powered off but not all devices are going to need to do that (always on devices like PMICs being the prime example) so don't require those devices to supply a default. Instead only try to fall back to hardware defaults if the driver told us to. Devices using LZO won't be able to instantiate with this, that will require some updates in the LZO code to handle this case. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Acked-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
2011-10-10regmap: Return a sensible error code if we fail to read the cacheMark Brown
If a register isn't cached then let callers know that so they can fall back or error handle appropriately. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Acked-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
2011-10-09regmap: Use bsearch() to search the register defaultsMark Brown
Rather than open coding a binary search use the standard bsearch() using the comparison function we're already using for sort() on insert. This fixes a lockup I was observing due to iterating on min <= max rather than min < max when we fail to look up. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Acked-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
2011-10-03regmap: Fix doc commentDimitris Papastamos
Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2011-10-03regmap: Optimize the lookup path to use binary searchDimitris Papastamos
Since there are more lookups than insertions in a typical scenario, optimize the linear search into a binary search. For this to work, we need to keep reg_defaults sorted upon insertions, for now be lazy and use sort(). Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2011-09-30regmap: Ensure we scream if we enable cache bypass/only at the same timeDimitris Papastamos
Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2011-09-30regmap: Implement regcache_cache_bypass helper functionDimitris Papastamos
Ensure we've got a function so users can enable/disable the cache bypass option. Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2011-09-30regmap: Save/restore the bypass state upon syncingDimitris Papastamos
Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2011-09-30regmap: Lock the sync path, ensure we use the lockless _regmap_write()Dimitris Papastamos
Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2011-09-30regmap: Fix apostrophe usageMark Brown
An apostrophe does not mean "look out, here comes an s!". Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2011-09-29regmap: Fix lock used for regcache_cache_only()Mark Brown
Reported-by: Stephen Rothwell <sfr@canb.auug.org.au> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2011-09-28regmap: Grab the lock in regcache_cache_only()Dimitris Papastamos
Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2011-09-28regmap: Modify map->cache_bypass directlyDimitris Papastamos
In preperation for the upcoming patches, modify map->cache_bypass directly. The helper functions will grab an exclusive lock. Because we'll have acquired the same lock we need to avoid a deadlock. Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2011-09-28regmap: Fix regcache_sync generic implementationDimitris Papastamos
We want to use regmap_write() to actually write anything to the HW. Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2011-09-27regmap: Implement generic syncing functionalityDimitris Papastamos
In the absence of a sync callback, do it manually. This of course can't take advantange of the specific optimizations of each cache type but it will do well enough in most cases. Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2011-09-19regmap: Allow drivers to control cache_only flagMark Brown
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2011-09-19regmap: A cache type of _NONE behaves like a bypassed cacheMark Brown
Avoid extra special casing by setting the cache_bypass flag when we're not caching. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>