summaryrefslogtreecommitdiff
path: root/drivers/base/regmap/regmap.c
AgeCommit message (Collapse)Author
2014-10-30regmap: fix possible ZERO_SIZE_PTR pointer dereferencing error.Xiubo Li
commit d6b41cb06044a7d895db82bdd54f6e4219970510 upstream. Since we cannot make sure the 'val_count' will always be none zero here, and then if it equals to zero, the kmemdup() will return ZERO_SIZE_PTR, which equals to ((void *)16). So this patch fix this with just doing the zero check before calling kmemdup(). Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com> Signed-off-by: Mark Brown <broonie@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-10-30regmap: fix NULL pointer dereference in _regmap_write/readPankaj Dubey
commit 5336be8416a71b5568d2cf54a2f2066abe9f2a53 upstream. If LOG_DEVICE is defined and map->dev is NULL it will lead to NULL pointer dereference. This patch fixes this issue by adding check for dev->NULL in all such places in regmap.c Signed-off-by: Pankaj Dubey <pankaj.dubey@samsung.com> Signed-off-by: Mark Brown <broonie@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-08-26regmap: Fix handling of volatile registers for format_write() chipsMark Brown
A previous over-zealous factorisation of code means that we only treat registers as volatile if they are readable. For most devices this is fine since normally most registers can be read and volatility implies readability but for format_write() devices where there is no readback from the hardware and we use volatility to mean simply uncacheability this means that we end up treating all registers as cacheble. A bigger refactoring of the code to clarify this is in order but as a fix make a minimal change and only check readability when checking volatility if there is no format_write() operation defined for the device. Signed-off-by: Mark Brown <broonie@linaro.org> Tested-by: Lars-Peter Clausen <lars@metafoo.de> Cc: stable@vger.kernel.org
2014-07-25regmap: Allow regmap_get_device() to be used by modulesMark Brown
Signed-off-by: Mark Brown <broonie@linaro.org>
2014-07-25regmap: Add regmap_get_deviceTuomas Tynkkynen
Add a new function regmap_get_device to obtain the underlying struct device from a regmap. Signed-off-by: Tuomas Tynkkynen <ttynkkynen@nvidia.com> Signed-off-by: Mark Brown <broonie@linaro.org>
2014-06-02Merge remote-tracking branch 'regmap/topic/smbus' into regmap-nextMark Brown
2014-06-02Merge remote-tracking branches 'regmap/topic/irq', 'regmap/topic/le', ↵Mark Brown
'regmap/topic/mmio' and 'regmap/topic/rbtree' into regmap-next
2014-04-30regmap: Add missing initialization of this_pageGeert Uytterhoeven
drivers/base/regmap/regmap.c: In function ‘_regmap_range_multi_paged_reg_write’: drivers/base/regmap/regmap.c:1665: warning: ‘this_page’ may be used uninitialized in this function Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org> Signed-off-by: Mark Brown <broonie@linaro.org>
2014-04-30regmap: Fix possible ZERO_SIZE_PTR pointer dereferencing error.Xiubo Li
Since we cannot make sure the 'len = pair_size * num_regs' will always be none zero from the users, and then if 'num_regs' equals to zero by mistake or other reasons, the kzalloc() will return ZERO_SIZE_PTR, which equals to ((void *)16). So this patch fix this with just doing the 'len' zero check before calling kzalloc(). Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com> Signed-off-by: Mark Brown <broonie@linaro.org>
2014-04-18regmap: add reg_read/reg_write callbacks to regmap_bus structBoris BREZILLON
Some busses do not support sending/receiving multiple registers in one go. Such kind of busses just unpack the registers that have been previously packed by the regmap core or pack registers that will be later unpacked by the core code. Add reg_write and reg_read callbacks in order to optimize access through this kind of busses. Signed-off-by: Boris BREZILLON <boris.brezillon@free-electrons.com> Signed-off-by: Mark Brown <broonie@linaro.org>
2014-04-14regmap: implement LE formatting/parsing for 16/32-bit values.Xiubo Li
Allow busses to request little endianness formatting and parsing for 16- and 32-bit values. This will be useful to support regmap-mmio. For the following the scenarios using the regmap-mmio, for example: Index CPU Device Endianess flag for values ---------------------------------------------------------- 1 LE LE REGMAP_ENDIAN_DEFAULT/NATIVE 2 LE BE REGMAP_ENDIAN_BIG 3 BE BE REGMAP_ENDIAN_DEFAULT/NATIVE 4 BE LE REGMAP_ENDIAN_LITTLE For one device driver, which will support all the cases above, needs two boolean properties in DT node like: 'big-endian' for case 2 and 'little-endian' for case 4, and for cases 1 and 3 they all will be absent. Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com> Signed-off-by: Mark Brown <broonie@linaro.org>
2014-04-11Merge tag 'regmap-v3.15-nodev' of ↵Linus Torvalds
git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap Pull regmap fix from Mark Brown: "regmap: Fix for nodev mode Add mising braces so that the nodev mode actually works (which was a bit of an oversight)" Testing schmesting. We don't need not steenking testing. We have deadlines to beat, and new code to write. * tag 'regmap-v3.15-nodev' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap: regmap: adds missing braces in regmap_init()
2014-04-01regmap: adds missing braces in regmap_init()Daeseok Youn
It need to add curly braces because the inner for "if" has two statements. coccicheck says: drivers/base/regmap/regmap.c:765:2-44: code aligned with following code on line 766 Signed-off-by: Daeseok Youn <daeseok.youn@gmail.com> Signed-off-by: Mark Brown <broonie@linaro.org>
2014-03-28Merge remote-tracking branches 'regmap/topic/cache', 'regmap/topic/irq', ↵Mark Brown
'regmap/topic/lock', 'regmap/topic/mmio', 'regmap/topic/nodev', 'regmap/topic/parse-val' and 'regmap/topic/patch' into regmap-next
2014-03-18regmap: Fix possible sleep-in-atomic in regmap_bulk_write()Takashi Iwai
regmap deploys the spinlock for the protection when set up in fast_io mode. This may lead to sleep-in-atomic by memory allocation with GFP_KERNEL in regmap_bulk_write(). This patch fixes it by moving the allocation out of the lock. [Fix excessively large locked region -- broonie] Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Mark Brown <broonie@linaro.org>
2014-03-18regmap: Ensure regmap_register_patch() is compatible with fast_ioMark Brown
With fast_io we use mutexes to lock the I/O operations so we would need to do GFP_ATOMIC allocations if we wanted to do allocations inside the lock as we do currently. Since it is unlikely that we will want to register a patch outside of init where concurrency shouldn't be an issue move the allocation of the patch data outside the lock. Reported-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Mark Brown <broonie@linaro.org>
2014-03-10regmap: Implementation for regmap_multi_reg_writeOpensource [Anthony Olech]
This is the implementation of regmap_multi_reg_write() There is a new capability 'can_multi_write' that device drivers must set in order to use this multi reg write mode. This replaces the first definition, which just defined the API. Signed-off-by: Anthony Olech <anthony.olech.opensource@diasemi.com> Signed-off-by: Mark Brown <broonie@linaro.org>
2014-03-06regmap: add regmap_parse_val apiNenghua Cao
In some cases, we need regmap's format parse_val function to do be/le translation according to the bus configuration. For example, snd_soc_bytes_put() uses regmap to write/read values, and use cpu_to_be() directly to covert MASK into big endian. This is a defect, and should use regmap's format function to do it according to bus configuration. Signed-off-by: Nenghua Cao <nhcao@marvell.com> Signed-off-by: Mark Brown <broonie@linaro.org>
2014-02-26regmap: Base regmap_register_patch on _regmap_multi_reg_writeCharles Keepax
Since we now have an internal version of regmap_multi_reg_write use this to apply the register patch. Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@linaro.org>
2014-02-26regmap: Add bypassed version of regmap_multi_reg_writeCharles Keepax
Devices with more complex boot proceedures may occasionally apply the register patch manual. regmap_multi_reg_write is a logical way to do so, however the patch must be applied with cache bypass on, such that it doesn't override any user settings. This patch adds a regmap_multi_reg_write_bypassed function that applies a set of writes with the bypass enabled. Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@linaro.org>
2014-02-26regmap: Mark reg_defaults in regmap_multi_reg_write as constCharles Keepax
There should be no need for the writes supplied to this function to be edited by it so mark them as const. Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@linaro.org>
2014-02-22regmap: fix coccinelle warningsNenghua Cao
/drivers/base/regmap/regmap.c:717:6-33: WARNING: Comparison to bool. More information about semantic patching is available at http://coccinelle.lip6.fr/ Signed-off-by: Nenghua Cao <nhcao@marvell.com> Signed-off-by: Mark Brown <broonie@linaro.org>
2014-02-22regmap: Check stride of register patch as we register itCharles Keepax
Currently, we check the registers in the patch are aligned to the register stride everytime we sync the cache and the first time the patch is written out is unchecked. This patch checks the register patch when we first register it so the first writes are no longer unchecked and then doesn't check on subsequent syncs as the patch will be unchanged. Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@linaro.org>
2014-02-20regmap: Clean up _regmap_update_bits()Xiubo Li
Since sometimes the 'config' parameter has no use, it should be NULL. And make the code simplifier. Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com> Signed-off-by: Mark Brown <broonie@linaro.org>
2014-02-16regmap: Separate regmap dev initializationMichal Simek
Create special function regmap_attach_dev which can be called separately out of regmap_init. Signed-off-by: Michal Simek <michal.simek@xilinx.com> Signed-off-by: Mark Brown <broonie@linaro.org>
2014-02-11regmap: Check readable regs in _regmap_readMichal Simek
Check if regs are readable. Signed-off-by: Michal Simek <michal.simek@xilinx.com> Signed-off-by: Mark Brown <broonie@linaro.org>
2013-12-30regmap: Allow regmap_bulk_write() to work for "no-bus" regmapsStephen Boyd
regmap_bulk_write() should decay to performing individual writes if we're using a "no-bus" regmap. Unfortunately, it returns an error because there is no map->bus pointer. Fix it. Signed-off-by: Stephen Boyd <sboyd@codeaurora.org> Signed-off-by: Mark Brown <broonie@linaro.org>
2013-12-30Merge tag 'v3.13-rc4' into regmap-coreMark Brown
Needed as a subsequent patch is built on some of the fixes. Linux 3.13-rc4
2013-12-16regmap: Allow regmap_bulk_read() to work for "no-bus" regmapsStephen Boyd
regmap_bulk_read() should decay to performing individual reads if we're using a "no-bus" regmap. Unfortunately, it returns an error because there is no map->bus pointer. Fix it. Signed-off-by: Stephen Boyd <sboyd@codeaurora.org> Signed-off-by: Mark Brown <broonie@linaro.org>
2013-11-26Merge remote-tracking branches 'regmap/fix/doc' and 'regmap/fix/mmio' into ↵Mark Brown
regmap-linus
2013-11-24regmap: Fix 'ret' would return an uninitialized valueCai Zhiyong
This patch give a warning when calling regmap_register_patch with parameter num_regs <= 0. When the num_regs parameter is zero and krealloc doesn't fail, then the code would return an uninitialized value. However, calling this function with num_regs == 0, would be a waste as it essentially does nothing. Signed-off-by: Cai Zhiyong <caizhiyong@huawei.com> Reviewed-by: Geyslan G. Bem <geyslan@gmail.com> Signed-off-by: Mark Brown <broonie@linaro.org>
2013-11-21regmap: make sure we unlock on failure in regmap_bulk_writeCourtney Cavin
Signed-off-by: Courtney Cavin <courtney.cavin@sonymobile.com> Signed-off-by: Mark Brown <broonie@linaro.org>
2013-11-12regmap: trivial comment fix (copy'n'paste error)Gerhard Sittig
fix a trivial copy'n'paste error in the regmap kerneldoc, s/write/read/ for the regmap_read(), regmap_raw_read() and regmap_bulk_read() routines Signed-off-by: Gerhard Sittig <gsi@denx.de> Signed-off-by: Mark Brown <broonie@linaro.org>
2013-10-28Merge remote-tracking branch 'regmap/topic/multi' into regmap-nextMark Brown
2013-10-28Merge remote-tracking branch 'regmap/topic/field' into regmap-nextMark Brown
2013-10-14regmap: Only send a single buffer for async I/O if writing one registerMark Brown
Extend the interface for async I/O by allowing the value buffer to be omitted and sending the value as part of the register buffer, minimising the number of separate hardware operations required. Signed-off-by: Mark Brown <broonie@linaro.org>
2013-10-14regmap: new API regmap_multi_reg_write() definitionAnthony Olech
New API regmap_multi_reg_write() is defined that allows a set of reg,val pairs to be written to a I2C client device as one block transfer from the point of view of a single I2C master system. A simple demonstration implementation is included that just splits the block write request into a sequence of single register writes. The implementation will be modified later to support those I2C clients that implement the alternative non-standard MULTIWRITE block write mode so to achieve a single I2C transfer that will be atomic even in multiple I2C master systems. Signed-off-by: Anthony Olech <anthony.olech.opensource@diasemi.com> Signed-off-by: David Dajun Chen <david.chen@diasemi.com> Signed-off-by: Mark Brown <broonie@linaro.org>
2013-10-10Merge remote-tracking branch 'regmap/fix/core' into regmap-asyncMark Brown
2013-10-10regmap: Use async I/O for patch applicationMark Brown
Try to speed up patch application a little using async I/O. Signed-off-by: Mark Brown <broonie@linaro.org>
2013-10-09regmap: Fix regmap_bulk_write single-rw mutex deadlockAnthony Olech
When regmap_bulk_write() is called with the map->use_single_rw flag set an immediate mutex deadlock happens because regmap_raw_write() is called after obtaining the mutex and regmap_raw_write() itself then tries to obtain the mutex as well. It is obvious that no one other than myself tried it with a real device. I did, but only for the purposes of an experiment and demonstration. But even if this situation will never ever happen with a real device, it is a bug and therefore should be fixed. Signed-off-by: Anthony Olech <anthony.olech.opensource@diasemi.com> Signed-off-by: Mark Brown <broonie@linaro.org>
2013-10-09regmap: Provide asynchronous write and update bits operationsMark Brown
Make it easier for drivers to include single register writes in asynchronous sequences by providing async versions of the write and update bits operations. The update bits operations are only likely to be effective when used with devices that have caches but this is common enough to be useful. Signed-off-by: Mark Brown <broonie@linaro.org>
2013-10-09regmap: Simplify the initiation of async I/OMark Brown
Rather than passing a flag around through the entire call stack store it in the regmap struct and read it when required. This minimises the visibility of the feature through the API, minimising the code updates needed to use it more widely. Signed-off-by: Mark Brown <broonie@linaro.org>
2013-10-09regmap: Don't generate gather writes for single register raw writesMark Brown
Since it is quite common for single register raw or async writes to be generated by rbtree cache syncs or firmware downloads and essentially all hardware will be faster with only a single transfer optimise this case by copying single values into the internal scratch buffer before sending. Signed-off-by: Mark Brown <broonie@linaro.org>
2013-10-07regmap: Cache async work structuresMark Brown
Rather than allocating and deallocating the structures used to manage async transfers each time we do one keep the structures around as long as the regmap is around. This should provide a small performance improvement. Signed-off-by: Mark Brown <broonie@linaro.org>
2013-09-17regmap: Add regmap_fields APIsKuninori Morimoto
Current Linux kernel is supporting regmap_field method and it is very useful feature. It needs one regmap_filed for one register access. OTOH, there is multi port device which has many same registers in the market. The difference for each register access is only its address offset. Current API needs many regmap_field for such device, but it is not good. This patch adds new regmap_fileds API which can care about multi port/offset access via regmap. Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Signed-off-by: Mark Brown <broonie@linaro.org>
2013-09-17regmap: add regmap_field_update_bits()Kuninori Morimoto
Current regmap_field is supporting read/write functions. This patch adds new update_bits function for it. Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Signed-off-by: Mark Brown <broonie@linaro.org>
2013-08-31Merge remote-tracking branch 'regmap/topic/sparse' into regmap-nextMark Brown
2013-08-31Merge remote-tracking branch 'regmap/topic/range' into regmap-nextMark Brown
2013-08-31Merge remote-tracking branch 'regmap/topic/patch' into regmap-nextMark Brown
2013-08-16regmap: Allow multiple patches to be registeredMark Brown
It may be useful to register multiple patches with regmap, for example one that depends on the device revision and one that depends on the system configuration. Add support for doing this, appending any new patches to the existing patches. Signed-off-by: Mark Brown <broonie@linaro.org>