History log of /drivers/base/regmap/regmap.c
Revision Date Author Comments
d6b41cb06044a7d895db82bdd54f6e4219970510 28-Sep-2014 Xiubo Li <Li.Xiubo@freescale.com> regmap: fix possible ZERO_SIZE_PTR pointer dereferencing error.

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>
Cc: stable@vger.kernel.org
5336be8416a71b5568d2cf54a2f2066abe9f2a53 27-Sep-2014 Pankaj Dubey <pankaj.dubey@samsung.com> regmap: fix NULL pointer dereference in _regmap_write/read

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>
Cc: stable@vger.kernel.org
6e64b6ccc1e46932768e3bb8974fc2e5589bca7a 18-Sep-2014 Pankaj Dubey <pankaj.dubey@samsung.com> regmap: fix NULL pointer dereference in regmap_get_val_endian

Recents commits for getting reg endianness causing NULL pointer
dereference if dev is passed NULL in regmap_init_mmio. This patch
fixes this issue, and allows to parse reg endianness only if dev
and dev->of_node exist.

Signed-off-by: Pankaj Dubey <pankaj.dubey@samsung.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
cf673fbc6342b1c2310cdfdc4ed99f18f866b8e4 27-Aug-2014 Geert Uytterhoeven <geert+renesas@glider.be> regmap: Split regmap_get_endian() in two functions

Split regmap_get_endian() in two functions, regmap_get_reg_endian() and
regmap_get_val_endian().

This allows to:
- Get rid of the three switch()es on "type", incl. error handling in
three "default" cases,
- Get rid of the regmap_endian_type enum,
- Get rid of the non-NULL check of "config" (regmap_init() already
checks for that),
- Get rid of the "endian" output parameters, and just return the
regmap_endian enum value, as the functions can no longer fail.

This saves 21 lines of code (despite the still-present
one-comment-per-line over-documentation), and 30 bytes of code on ARM
V7.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
5844a8b9d98ec11ce1d77610daacf3f0a0e14715 26-Aug-2014 Mark Brown <broonie@linaro.org> regmap: Fix handling of volatile registers for format_write() chips

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
45e1a279ce1d2ff9b2b2fedf4cdced10c7ca3ab5 19-Aug-2014 Stephen Warren <swarren@nvidia.com> regmap: of_regmap_get_endian() cleanup

Commit d647c199510c ("regmap: add DT endianness binding support") had
some issues. Commit ba1b53feb8ca ("regmap: Fix DT endianess parsing
logic") fixed the main problem. This patch fixes the other.

Specifically, restore the overall default of REGMAP_ENDIAN_BIG if none of
the config, DT, or the bus specify any endianness. Without this,
of_regmap_get_endian() could return REGMAP_ENDIAN_DEFAULT, which the
calling code can't handle. Since all busses do specify an endianness in
the current code, this makes no difference right now, but I saw no
justification in the patch description for removing this final default.

Also, clean up the code a bit:

* s/of_regmap_get_endian/regmap_get_endian/ since the function isn't DT-
specific, even if the reason it was originally added was to add some
DT-specific features.
* After potentially reading an endianess specification from DT, the code
checks whether DT did specify an endianness, and if so, returns it. Move
this test outside the whole switch statement so that if the
REGMAP_ENDIAN_REG case ever modifies *endian, this check will pick that
up. This partially reverts part of commit ba1b53feb8ca ("regmap: Fix DT
endianess parsing logic"), while maintaining the bug-fix that commit
made to this code.
* Make the comments briefer, and only refer to the specific action taken
at their location. This makes most of the comments independent of DT,
and easier to follow.

Cc: Xiubo Li <Li.Xiubo@freescale.com>
Cc: Javier Martinez Canillas <javier.martinez@collabora.co.uk>
Cc: Thierry Reding <treding@nvidia.com>
Fixes: d647c199510c ("regmap: add DT endianness binding support")
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
ba1b53feb8cacbd84bcf0e48925e30ad29e141a6 18-Aug-2014 Javier Martinez Canillas <javier.martinez@collabora.co.uk> regmap: Fix DT endianess parsing logic

Commit d647c199510c ("regmap: add DT endianness binding support.")
added support to parse the device endianness from the device tree
but unfortunately the added logic doesn't have the same semantics
than the old code. This leads to a NULL dereference pointer error
when these properties are not provided by the Device Tree:

Unable to handle kernel NULL pointer dereference at virtual address 00000044
pgd = c0004000
[00000044] *pgd=00000000
Internal error: Oops: 5 [#1] PREEMPT SMP ARM
Modules linked in:
CPU: 5 PID: 1 Comm: swapper/0 Not tainted 3.17.0-rc1-next-20140818ccu #671
task: ea412800 ti: ea484000 task.ti: ea484000
PC is at regmap_update_bits+0xc/0x5c

The problem is that platforms that rely on the default value now
gets different values due two related issues in the current code:

a) It only parses the endianness from DT for the regmap registers
and not for the regmap values but it checks unconditionally in
both cases if the resulting endiannes is REGMAP_ENDIAN_NATIVE.

b) REGMAP_ENDIAN_NATIVE is not even a valid DT property according
to the regmap DT binding documentation so it shouldn't be set.

Signed-off-by: Javier Martinez Canillas <javier.martinez@collabora.co.uk>
Signed-off-by: Mark Brown <broonie@linaro.org>
d647c199510c2c126ac03ecbea51086e10126a40 14-Jul-2014 Xiubo Li <Li.Xiubo@freescale.com> regmap: add DT endianness binding support.

For many drivers which will support rich endianness of Devices
need define DT properties by itself with the binding support.

The endianness using regmap:
Index Device Properties if needs bytes-swap,
or just ignore it
-------------------------------------------------------------
1 BE 'big-endian'
2 LE 'little-endian'

The properties include all the register values and the buffers.
And these properties are very usful for the MMIO devices:

Such as: a memory-mapped device, on one SoC is in BE mode, while
in another SoC will be in LE mode, and the CPU will always in LE
mode.

For the first case, we must use cpu_to_be32/be32_to_cpu for
32-bit registers accessing, so the 'big-endian' property is needed.

For the second case, we can just ignore the bytes-swap
functions like cpu_to_le32/le32_to_cpu, so the 'little-endian'
property could be abscent.

And vice versa...

Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
fa2fbe4a981a70866d20cee62af0d89eb6b6027e 25-Jul-2014 Mark Brown <broonie@linaro.org> regmap: Allow regmap_get_device() to be used by modules

Signed-off-by: Mark Brown <broonie@linaro.org>
8d7d3972a9ae962bbf8ce49c83f4a40082708f69 21-Jul-2014 Tuomas Tynkkynen <ttynkkynen@nvidia.com> regmap: Add regmap_get_device

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>
b48d13988bee440e43a510ea8878f1f329cee189 22-Apr-2014 Geert Uytterhoeven <geert@linux-m68k.org> regmap: Add missing initialization of this_page

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>
f5727cd31283aa478f7f9396c6eb7b5aceebb869 30-Apr-2014 Xiubo Li <Li.Xiubo@freescale.com> regmap: Fix possible ZERO_SIZE_PTR pointer dereferencing error.

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>
3ac170376f2c5123414e0267aa0f9cf218965e24 17-Apr-2014 Boris BREZILLON <boris.brezillon@free-electrons.com> regmap: add reg_read/reg_write callbacks to regmap_bus struct

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>
4aa8c0694c731e03eb660b92a3afe14859142381 02-Apr-2014 Xiubo Li <Li.Xiubo@freescale.com> regmap: implement LE formatting/parsing for 16/32-bit values.

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>
a7a037c837cb0f9d011cb3ca6e6837989986570c 01-Apr-2014 Daeseok Youn <daeseok.youn@gmail.com> regmap: adds missing braces in regmap_init()

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>
4999e9621a58fa03fe18aa2ea55838bd2e755190 18-Mar-2014 Takashi Iwai <tiwai@suse.de> regmap: Fix possible sleep-in-atomic in regmap_bulk_write()

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>
56fb1c74f3bda1c0100fc3e9a7888c229174f9a4 18-Mar-2014 Mark Brown <broonie@linaro.org> regmap: Ensure regmap_register_patch() is compatible with fast_io

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>
e894c3f46c302716d2f156b1f3339e2f96ceb65c 04-Mar-2014 Opensource [Anthony Olech] <anthony.olech.opensource@diasemi.com> regmap: Implementation for regmap_multi_reg_write

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>
13ff50c85846338bb9820abd3933227b678dc086 19-Feb-2014 Nenghua Cao <nhcao@marvell.com> regmap: add regmap_parse_val api

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>
6bf13103b2dbf09d32a0da2e732b6196522c1462 25-Feb-2014 Charles Keepax <ckeepax@opensource.wolfsonmicro.com> regmap: Base regmap_register_patch on _regmap_multi_reg_write

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>
1d5b40bccf04994248b39e8ce234a7c1f3235cf5 25-Feb-2014 Charles Keepax <ckeepax@opensource.wolfsonmicro.com> regmap: Add bypassed version of regmap_multi_reg_write

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>
f7e2cec02b0e5bfe2180f09de9b0bc724774c51a 25-Feb-2014 Charles Keepax <ckeepax@opensource.wolfsonmicro.com> regmap: Mark reg_defaults in regmap_multi_reg_write as const

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>
53e87f88b14c011692ab2cb8c8abc994bdd28ae9 21-Feb-2014 Nenghua Cao <nhcao@marvell.com> regmap: fix coccinelle warnings

/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>
7a7a70b49b51e90593ae072a9402d6615d05e895 21-Feb-2014 Charles Keepax <ckeepax@opensource.wolfsonmicro.com> regmap: Check stride of register patch as we register it

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>
e2f74dc6739731a6b6900946a21ac235181aa60f 20-Feb-2014 Xiubo Li <Li.Xiubo@freescale.com> regmap: Clean up _regmap_update_bits()

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>
6cfec04bcc05a829179c02584bb55f28fee03795 10-Feb-2014 Michal Simek <michal.simek@xilinx.com> regmap: Separate regmap dev initialization

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>
d4807ad2c4c0e17b6f00e3be9492c81de0804f40 10-Feb-2014 Michal Simek <michal.simek@xilinx.com> regmap: Check readable regs in _regmap_read

Check if regs are readable.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
f4298360a5c21409e04cd2b0e220c8f8521fd14c 26-Dec-2013 Stephen Boyd <sboyd@codeaurora.org> regmap: Allow regmap_bulk_write() to work for "no-bus" regmaps

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>
3b58ee13da7510115b66f71c67c9e87b47e9c4aa 13-Dec-2013 Stephen Boyd <sboyd@codeaurora.org> regmap: Allow regmap_bulk_read() to work for "no-bus" regmaps

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>
bd60e381fab88979c3312265d18bb635c314d242 18-Nov-2013 Cai Zhiyong <caizhiyong@huawei.com> regmap: Fix 'ret' would return an uninitialized value

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>
73f080fde50de1be7ab1e62fd93287edaf0861db 21-Nov-2013 Courtney Cavin <courtney.cavin@sonymobile.com> regmap: make sure we unlock on failure in regmap_bulk_write

Signed-off-by: Courtney Cavin <courtney.cavin@sonymobile.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
0093380c18a4bfc5526577da576335d08bdea2e5 11-Nov-2013 Gerhard Sittig <gsi@denx.de> regmap: trivial comment fix (copy'n'paste error)

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>
04c50ccf0dab02923ef888a4839bfbd00de03181 10-Oct-2013 Mark Brown <broonie@linaro.org> regmap: Only send a single buffer for async I/O if writing one register

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>
e33fabd365596178e72f62bb4b89f0aaad0509ad 11-Oct-2013 Anthony Olech <anthony.olech.opensource@diasemi.com> regmap: new API regmap_multi_reg_write() definition

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>
1a25f26138cde2b83fd74ead6da0bbd4b6c42b60 10-Oct-2013 Mark Brown <broonie@linaro.org> regmap: Use async I/O for patch application

Try to speed up patch application a little using async I/O.

Signed-off-by: Mark Brown <broonie@linaro.org>
4174a7a4f763ed51809a4dbca06de054d31c1d38 09-Oct-2013 Anthony Olech <anthony.olech.opensource@diasemi.com> regmap: Fix regmap_bulk_write single-rw mutex deadlock

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>
915f441b6f31b1a8ee01e9263a4e2d44c434d832 09-Oct-2013 Mark Brown <broonie@linaro.org> regmap: Provide asynchronous write and update bits operations

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>
0a8198094da895c8d5db95812fe9de7027d808e4 09-Oct-2013 Mark Brown <broonie@linaro.org> regmap: Simplify the initiation of async I/O

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>
651e013e3ce6c0646c39a07e22bebad75a207209 08-Oct-2013 Mark Brown <broonie@linaro.org> regmap: Don't generate gather writes for single register raw writes

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>
7e09a979404ed07b8f05d09a0e87a87c7891f472 08-Oct-2013 Mark Brown <broonie@linaro.org> regmap: Cache async work structures

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>
a0102375ee82db1e08324b1a21484854cf2c1677 02-Sep-2013 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> regmap: Add regmap_fields APIs

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>
fdf200290581150f7b69148abf6ca860684cbfbb 02-Sep-2013 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> regmap: add regmap_field_update_bits()

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>
aab13ebca2c67c3b8f004a013a36f661a3950b00 11-Jul-2013 Mark Brown <broonie@linaro.org> regmap: Allow multiple patches to be registered

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>
515f2261703d09c6b647a5687b7d657dd5911065 09-Aug-2013 Ionut Nicu <ioan.nicu.ext@nsn.com> regmap: regcache: allow read-only regs to be cached

The regmap_writeable() check should not be done in
regcache_write() because this prevents read-only
registers to be cached. After a read on a read-only
register its value will not be stored in the cache
and the next time someone will try to read it the
value will be read from the bus instead of the
cache.

Instead the regmap_writeable() check should be done
in _regmap_write() to prevent callers from writing
to read-only registers.

Signed-off-by: Ionut Nicu <ioan.nicu.ext@nsn.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
f161d22081e9b81f0b35411c428af347ca3dd449 23-Jul-2013 Philipp Zabel <p.zabel@pengutronix.de> regmap: core: allow a virtual range to cover its own data window

I see no reason why a virtual range shouldn't be allowed to cover its
own data window if the page selection register is in the same place
on every page.
For chips which use paged access for all of their registers, but only
when connected via I2C, and which can access the whole register space
directly when connected via SPI, this allows to avoid acrobatics with
the register ranges by simply mapping the I2C ranges over the data
window beginning at 0x0, and then using linear access for the SPI
variant.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: Mark Brown <broonie@linaro.org>
b4519c71c45b31f5acd6db984c8830e52120323a 16-Jul-2013 Fabio Estevam <fabio.estevam@freescale.com> regmap: Provide __acquires/__releases annotations

Fix the following sparse warnings:

drivers/base/regmap/regmap.c:305:13: warning: context imbalance in 'regmap_lock_spinlock' - wrong count at exit
drivers/base/regmap/regmap.c:314:13: warning: context imbalance in 'regmap_unlock_spinlock' - unexpected unlock

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
f2e055e7c9c6084bfbaa68701e52562acf96419e 04-Jul-2013 Daniel Mack <zonque@gmail.com> regmap: cache: bail in regmap_async_complete() for bus-less maps

Commit f8bd822cb ("regmap: cache: Factor out block sync") made
regcache_rbtree_sync() call regmap_async_complete(), which in turn does
not check for map->bus before dereferencing it.

This causes a NULL pointer dereference on bus-less maps.

Signed-off-by: Daniel Mack <zonque@gmail.com>
Cc: stable@vger.kernel.org [v3.10 only]
Signed-off-by: Mark Brown <broonie@linaro.org>
67252287871113deba96adf7e4df1752f3f08688 11-Jun-2013 Srinivas Kandagatla <srinivas.kandagatla@st.com> regmap: Add regmap_field APIs

It is common to access regmap registers at bit level, using
regmap_update_bits or regmap_read functions, however the end user has to
take care of a mask or shifting. This becomes overhead when such use
cases are high. Having a common function to do this is much convenient
and less error prone.

The idea of regmap_field is simple, regmap_field gives a logical
structure to bits of the regmap register, and the driver can use this
logical entity without the knowledge of the bit positions and masks all
over the code. This way code looks much neat and it need not handle the
masks, shifts every time it access the those entities.

With this new regmap_field_read/write apis the end user can setup a
regmap field using regmap_field_init and use the return regmap_field to
read write the register field without worrying about the masks or
shifts.

Also this apis will be useful for drivers which are based on regmaps,
like some clocks or pinctrls which can work on the regmap_fields
directly without having to worry about bit positions.

Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@st.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
b92be6fecc9f1e8b927d99c12dad9f9dcd729727 03-Jun-2013 Mark Brown <broonie@linaro.org> regmap: core: Cache all registers by default when cache is enabled

Currently all register maps with a cache need to provide a volatile
callback since the default is to assume all registers are volatile.
This is not sensible if we have a cache so change the default to be
fully cached if a cache is provided.

Signed-off-by: Mark Brown <broonie@linaro.org>
92ab1aab59c61b3e05200b9aa0e05ab770059142 24-May-2013 Lars-Peter Clausen <lars@metafoo.de> regmap: Make regmap-mmio usable from atomic contexts

regmap-mmio uses a spinlock with spin_lock() and spin_unlock() for locking.
To be able to use the regmap API from different contexts (atomic vs non-atomic),
without the risk of race conditions, we need to use spin_lock_irqsave() and
spin_lock_irqrestore() instead. A new field, the spinlock_flags field, is added
to regmap struct to store the flags between regmap_{,un}lock_spinlock(). The
spinlock_flags field itself is also protected by the spinlock.

Thanks to Stephen Warren for the suggestion of this particular solution.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Reviewed-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
154881e59b8dbf84121e3e78c4e613e840752aa9 08-May-2013 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Make regmap_check_range_table() a public API

Allow drivers to use an access table as part of their implementation.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
5a08d15602987bbdff3407d7645f95b7a70f1a6f 21-Mar-2013 Stephen Warren <swarren@nvidia.com> regmap: don't corrupt work buffer in _regmap_raw_write()

_regmap_raw_write() contains code to call regcache_write() to write
values to the cache. That code calls memcpy() to copy the value data to
the start of the work_buf. However, at least when _regmap_raw_write() is
called from _regmap_bus_raw_write(), the value data is in the work_buf,
and this memcpy() operation may over-write part of that value data,
depending on the value of reg_bytes + pad_bytes. At least when using
reg_bytes==1 and pad_bytes==0, corruption of the value data does occur.

To solve this, remove the memcpy() operation, and modify the subsequent
.parse_val() call to parse the original value buffer directly.

At least in the case of 8-bit register address and 16-bit values, and
writes of single registers at a time, this memcpy-then-parse combination
used to cancel each-other out; for a work-buffer containing xx 89 03,
the memcpy changed it to 89 03 03, and the parse_val changed it back to
89 89 03, thus leaving the value uncorrupted. This appears completely
accidental though. Since commit 8a819ff "regmap: core: Split out in
place value parsing", .parse_val only returns the parsed value, and does
not modify the buffer, and hence does not (accidentally) undo the
corruption caused by memcpy(). This caused bogus values to get written
to HW, thus preventing e.g. audio playback on systems with a WM8903
CODEC. This patch fixes that.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
51a246aa5c0a14b3d34a5c6d3c9e271c784b127f 09-Apr-2013 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Back out work buffer fix

This reverts commit bc8ce4 (regmap: don't corrupt work buffer in
_regmap_raw_write()) since it turns out that it can cause issues when
taken in isolation from the other changes in -next that lead to its
discovery. On the basis that nobody noticed the problems for quite some
time without that subsequent work let's drop it from v3.9.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
f951b6587b94df2abb8c7a2425f7dcdb4fe647dc 27-Mar-2013 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: async: Add missing return

Let's only write once...

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
221ad7f2df7c54b3f05471a3599ea7368366aaeb 26-Mar-2013 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: core: Provide regmap_can_raw_write() operation

Mainly useful internally but exported since this is a public API that's
being checked for.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
584de329ca43cc6d73eb74885e1d5d9fc0549423 13-Mar-2013 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: core: Make raw write available to regcache

This allows the cache to sync values directly to the device when stored
in native format and also allows asynchronous I/O.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
f1b5c5c3423b59056d3ca956d2e795b7927d6008 13-Mar-2013 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: core: Warn on invalid operation combinations

Don't grind to a screaming halt, just generate a warning.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
bc8ce4afd7ee7e1421c935d24b1f879f82afdd4e 21-Mar-2013 Stephen Warren <swarren@nvidia.com> regmap: don't corrupt work buffer in _regmap_raw_write()

_regmap_raw_write() contains code to call regcache_write() to write
values to the cache. That code calls memcpy() to copy the value data to
the start of the work_buf. However, at least when _regmap_raw_write() is
called from _regmap_bus_raw_write(), the value data is in the work_buf,
and this memcpy() operation may over-write part of that value data,
depending on the value of reg_bytes + pad_bytes. At least when using
reg_bytes==1 and pad_bytes==0, corruption of the value data does occur.

To solve this, remove the memcpy() operation, and modify the subsequent
.parse_val() call to parse the original value buffer directly.

At least in the case of 8-bit register address and 16-bit values, and
writes of single registers at a time, this memcpy-then-parse combination
used to cancel each-other out; for a work-buffer containing xx 89 03,
the memcpy changed it to 89 03 03, and the parse_val changed it back to
89 89 03, thus leaving the value uncorrupted. This appears completely
accidental though. Since commit 8a819ff "regmap: core: Split out in
place value parsing", .parse_val only returns the parsed value, and does
not modify the buffer, and hence does not (accidentally) undo the
corruption caused by memcpy(). This caused bogus values to get written
to HW, thus preventing e.g. audio playback on systems with a WM8903
CODEC. This patch fixes that.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
c6432ea9cc043994d5b7dcb3ad86a087777cb40c 11-Mar-2013 Dimitris Papastamos <dp@opensource.wolfsonmicro.com> regmap: Initialize `map->debugfs' before regcache

In the rbtree code we are exposing statistics relating to the
number of nodes/registers of the rbtree cache for each of the
devices. Ensure that `map->debugfs' has been initialized before
we attempt to initialize the debugfs entry for the rbtree cache.

Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Cc: stable@vger.kernel.org
8a819ff8abac9ad49f120c84cce01878b3d235c2 04-Mar-2013 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: core: Split out in place value parsing

Currently the value parsing operations both return the parsed value and
modify the passed buffer. This precludes their use in places like the cache
code so split out the in place modification into a new parse_inplace()
operation.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
fe7d4ccd1d7748bc9919c1bdee1e8286776f75ff 21-Feb-2013 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: async: Add tracepoints for async I/O

Trace when we start and complete async writes, and when we start and
finish blocking for their completion. This is useful for performance
analysis of the resulting I/O patterns.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
f88948eff9a6160ed74e3ee4b12f41f5beeff115 05-Feb-2013 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Export regmap_async_complete()

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
f804fb562b0d9f4a8546fa2808d14e80aea8ff26 02-Feb-2013 Axel Lin <axel.lin@ingics.com> regmap: Export regmap_async_complete_cb

This fixes below build error when CONFIG_REGMAP=y && CONFIG_REGMAP_SPI=m

ERROR: "regmap_async_complete_cb" [drivers/base/regmap/regmap-spi.ko] undefined!
make[1]: *** [__modpost] Error 1
make: *** [modules] Error 2

Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
30b2a553742747d951861a6f582fa90dd9220124 03-Feb-2013 Stephen Warren <swarren@nvidia.com> regmap: include linux/sched.h to fix build

This fixes:

drivers/base/regmap/regmap.c: In function 'regmap_async_complete_cb':
drivers/base/regmap/regmap.c:1656:3: error: 'TASK_NORMAL' undeclared (first use in this function)
drivers/base/regmap/regmap.c:1656:3: note: each undeclared identifier is reported only once for each function it appears in
drivers/base/regmap/regmap.c: In function 'regmap_async_complete':
drivers/base/regmap/regmap.c:1688:2: error: 'TASK_UNINTERRUPTIBLE' undeclared (first use in this function)
drivers/base/regmap/regmap.c:1688:2: error: implicit declaration of function 'schedule'

An alternative might be to adjust linux/wait.h to include linux/sched.h,
but since that hasn't been done before, I assume we're consciously
avoiding doing that.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
0d509f2b112b21411712f0bf789b372987967e49 27-Jan-2013 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Add asynchronous I/O support

Some use cases like firmware download can transfer a lot of data in quick
succession. With high speed buses these use cases can benefit from having
multiple transfers scheduled at once since this allows the bus to minimise
the delay between transfers.

Support this by adding regmap_raw_write_async(), allowing raw transfers to
be scheduled, and regmap_async_complete() to wait for them to finish.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
d2a5884a64161b524cc6749ee11b95d252e497f3 27-Jan-2013 Andrey Smirnov <andrew.smirnov@gmail.com> regmap: Add "no-bus" option for regmap API

This commit adds provision for "no-bus" usage of the regmap API. In
this configuration user can provide API with two callbacks 'reg_read'
and 'reg_write' which are to be called when reads and writes to one of
device's registers is performed. This is useful for devices that
expose registers but whose register access sequence does not fit the 'bus'
abstraction.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
31b35e9edd51cab96d880248206c90b7177e3e5c 18-Jan-2013 Nestor Ovroy <novroy@riseup.net> regmap: fix small typo in regmap_bulk_write comment

Signed-off-by: Nestor Ovroy <novroy@riseup.net>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
07c320dc31d757b8cb59c64dab320215c929bf02 12-Jan-2013 Andrey Smirnov <andrew.smirnov@gmail.com> regmap: Add provisions to have user-defined write operation

This commit is a preparatory commit to provide "no-bus" configuration
option for regmap API. It adds necessary plumbing needed to have the
ability to provide user define register write function.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
ad278406b3b8b8e454af23b63df3c3d63f6aee94 12-Jan-2013 Andrey Smirnov <andrew.smirnov@gmail.com> regmap: Add provisions to have user-defined read operation

This commit is a preparatory commit to provide "no-bus" configuration
option for regmap API. It adds necessary plumbing needed to have the
ability to provide user define register read function.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
237019e7e356abb1bad591fa5edab68224793143 10-Jan-2013 Lars-Peter Clausen <lars@metafoo.de> regmap: Add support for 24 bit wide register addresses

Since regmap already has support for formatting 24 bit wide values, so adding
support for 24 bit wide registers is pretty much straight forward.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
76aad392f75e6ce5be3f106554e16f7ff96543e5 20-Nov-2012 Davide Ciminaghi <ciminaghi@gnudd.com> regmap: introduce tables for readable/writeable/volatile/precious checks

Many of the regmap enabled drivers implementing one or more of the
readable, writeable, volatile and precious methods use the same code
pattern:

return ((reg >= X && reg <= Y) || (reg >= W && reg <= Z) || ...)

Switch to a data driven approach, using tables to describe
readable/writeable/volatile and precious registers ranges instead.
The table based check can still be overridden by passing the usual function
pointers via struct regmap_config.

Signed-off-by: Davide Ciminaghi <ciminaghi@gnudd.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
6d04b8ac575c38d94515b4e8f3b800c5c61ef611 26-Oct-2012 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: core: Report registers in hex when we can't cache

This seems to be the most common way of reporting register numbers, it's
certainly what we do for trace.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
1a61cfe3445218637f38b355c76fc3132865a0a6 25-Oct-2012 Fabio Estevam <fabio.estevam@freescale.com> regmap: Fix printing of size_t variable

val_bytes is of 'size_t', so it should be printed as '%zu'.

Fixes the following build warning on x86:

drivers/base/regmap/regmap.c:872:4: warning: format '%d' expects argument of type 'int', but argument 5 has type 'size_t' [-Wformat]

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
0d4529c534c1c664f25088eb5f5b4d7ce0ee2510 16-Oct-2012 Davide Ciminaghi <ciminaghi@gnudd.com> regmap: make lock/unlock functions customizable

It is sometimes convenient for a regmap user to override the standard
regmap lock/unlock functions with custom functions.
For instance this can be useful in case an already existing spinlock
or mutex has to be used for locking a set of registers instead of the
internal regmap spinlock/mutex.
Note that the fast_io field of struct regmap_bus is ignored in case
custom locking functions are used.

Signed-off-by: Davide Ciminaghi <ciminaghi@gnudd.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
a8f28cfad8cd44d7c34b166d0e5ace1125dbee1f 08-Oct-2012 Paul Bolle <pebolle@tiscali.nl> regmap: silence GCC warning

Building regmap.o triggers this GCC warning:
drivers/base/regmap/regmap.c: In function ‘regmap_raw_read’:
drivers/base/regmap/regmap.c:1172:6: warning: ‘ret’ may be used uninitialized in this function [-Wmaybe-uninitialized]

Long story short: Jakub Jelinek pointed out that there is a type
mismatch between 'num' in regmap_volatile_range() and 'val_count' in
regmap_raw_read(). And indeed, converting 'num' to the type of
'val_count' (ie, size_t) makes this warning go away.

Signed-off-by: Paul Bolle <pebolle@tiscali.nl>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
8a2ceac6617a67d8a1ee4bd255743d577bde311a 04-Oct-2012 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Split raw writes that cross window boundaries

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@opensource.wolfsonmicro.com>
0ff3e62ff119f2b65b0a8ad48fcb669f609fd904 04-Oct-2012 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Make return code checks consistent

The range code was written to check for return codes less than zero as
errors but throughout the rest of the API return codes not equal to zero
are errors. Change all these checks to match the house style.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
98bc7dfd76407eaa0964ecb4d5319c957a3b9df9 04-Oct-2012 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Factor range lookup out of page selection

This will support a subsequent update to allow bulk writes to cross window
boundaries.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
4b020b3f9ba2af8031c5c7d759fbafd234d1c390 03-Oct-2012 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Provide debugfs read of register ranges

If a register range is named then provide a debugfs file showing the
contents of the range separately.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
d058bb49618482f2eff0db57618c9a7352916dd5 03-Oct-2012 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Allow ranges to be named

For more useful diagnostics.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
061adc064adbbdd9eb127ab2e86b7a71f4ccaf2e 03-Oct-2012 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: When we sanity check during range adds say what errors we find

Rather than just returning a single error code for every possible thing we
can notice print an error message saying what the problem was. This makes
it very much easier to figure out what's wrong and fix it.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
e3549cd01347ef211d01353bdf2572b086574007 02-Oct-2012 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Rename n_ranges to num_ranges

This makes things consistent with the rest of the API and is actually what
the documentation says. We don't currently have any in tree users so low
cost.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
4d879514e73f3e6b27617d9898c83c9939462dda 27-Jul-2012 Dimitris Papastamos <dp@opensource.wolfsonmicro.com> regmap: Don't lock in regmap_reinit_cache()

When bus->fast_io is set, the locking here is done with spinlocks.
This is currently true for the regmap-mmio bus implementation.

While holding a spinlock we can't go to sleep, various operations
like removing the debugfs entries or re-initializing the cache will
sleep, therefore, shift the locking up to the user.

Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
1044c180de4ba426aa5fb1b4b13b5f219ddb7105 06-Jul-2012 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Add hook for printk logging for debugging during early init

Sometimes for failures during very early init the trace infrastructure
isn't available early enough to be used. For this sort of problem
defining LOG_DEVICE will add printks for basic register I/O on a specific
device, allowing trace to be extracted when the trace system doesn't come
up early enough to work with.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
632a5b01db8cd4068a06f8a67720ea4f9b00d9b3 18-Jun-2012 Krystian Garbaciak <krystian.garbaciak@diasemi.com> regmap: Fix work_buf switching for page update during virtual range access.

After page update, orginal work_buf has to be restored regardless of
the result.

Signed-off-by: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
6863ca6227598d15c372f1e03449bbb4cfbcca7f 15-Jun-2012 Krystian Garbaciak <krystian.garbaciak@diasemi.com> regmap: Add support for register indirect addressing.

Devices with register paging or indirectly accessed registers can configure
register mapping to map those on virtual address range. During access to
virtually mapped register range, indirect addressing is processed
automatically, in following steps:
1. selector for page or indirect register is updated (when needed);
2. register in data window is accessed.

Configuration should provide minimum and maximum register for virtual range,
details of selector field for page selection, minimum and maximum register of
data window for indirect access.

Virtual range registers are managed by cache as well as direct access
registers. In order to make indirect access more efficient, selector register
should be declared as non-volatile, if possible.

struct regmap_config is extended with the following:
struct regmap_range_cfg *ranges;
unsigned int n_ranges;

[Also reordered debugfs init to later on since the cleanup code was
conflicting with the new cleanup code for ranges anyway -- broonie]

Signed-off-by: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
fc3ebd788e894b4dd6c9524cb3874eeeb1e862d6 15-Jun-2012 Krystian Garbaciak <krystian.garbaciak@diasemi.com> regmap: Move lock out from internal function _regmap_update_bits().

Locks are moved to regmap_update_bits(), which allows to reenter internal
function _regmap_update_bits() from inside of regmap read/write routines.

Signed-off-by: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
752a6a5f84bfed18d0709383913d9d9d21b61c77 14-May-2012 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Export regmap_reinit_cache()

It's supposed to be there for drivers.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
5494a98f451d59f6c05f3f688510e0832445f661 01-Jun-2012 Fabio Estevam <fabio.estevam@freescale.com> regmap: Fix the size calculation for map->format.buf_size

The word to be transmitted/received via regmap is composed by the following
parts:

config->reg_bits
config->val_bits
config->pad_bits

,so the total size should be calculated by summing up the number of bits of
each element and using a DIV_ROUND_UP to return the number of bytes.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
bfaa25f33425db16a942b7c71e396a47581c646d 24-May-2012 Stephen Warren <swarren@nvidia.com> regmap: clean up debugfs if regmap_init fails

If debugfs isn't cleaned up, stale files will be left in the filesystem
which will cause an OOPS when accessed the first time, and hang the
accessing application when accessed again, presumably due to some lock
being left held.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
141eba2e006dd8145bed2e49fae3de5af65ab9b0 24-May-2012 Stephen Warren <swarren@nvidia.com> regmap: allow busses to request formatting with specific endianness

Add a field to struct regmap_bus that allows bus drivers to request that
register addresses and values be formatted with a specific endianness.

The default endianness is unchanged from current operation: Big.

Implement native endian formatting/parsing for 16- and 32-bit values.
This will be enough to support regmap-mmio.c.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
6560ffd1ccd688152393dc7c35dbdcc33140633b 09-May-2012 Laxman Dewangan <ldewangan@nvidia.com> regmap: fix possible memory corruption in regmap_bulk_read()

The function regmap_bulk_read() calls the regmap_read() for
each register if set of register has volatile and cache is
enabled. In this case, last few register read makes the memory
corruption if the register size is not the size of unsigned int.
The regam_read() takes argument as unsigned int for returning
value and it update the value as
*val = map->format.parse_val(map->work_buf);
This causes complete 4 bytes (size of unsigned int) to get written.
Now if client pass the memory pointer for value which is equal to the
required size of register count in regmap_bulk_read() then last few
register read actually update the memory beyond passed pointer size.

Avoid this by using local variable for read and then do memcpy()
for actual byte copy to passed pointer based on register size.

I allocated one pointer ptr and take first 16 bytes dump of that
pointer then call regmap_bulk_read() with pointer which is just
on top of this allocated pointer and register count of 128. Here
register size is 1 byte.
The memory trace of last 5 register read are as follows:

[ 5.438589] regmap_bulk_read after regamp_read() for register 122
[ 5.447421] 0xef993c20 0xef993c00 0x00000000 0x00000001
[ 5.467535] regmap_bulk_read after regamp_read() for register 123
[ 5.476374] 0xef993c20 0xef993c00 0x00000000 0x00000001
[ 5.496425] regmap_bulk_read after regamp_read() for register 124
[ 5.505260] 0xef993c20 0xef993c00 0x00000000 0x00000001
[ 5.525372] regmap_bulk_read after regamp_read() for register 125
[ 5.534205] 0xef993c00 0xef993c00 0x00000000 0x00000001
[ 5.554258] regmap_bulk_read after regamp_read() for register 126
[ 5.563100] 0xef990000 0xef993c00 0x00000000 0x00000001
[ 5.554258] regmap_bulk_read after regamp_read() for register 127
[ 5.587108] 0xef000000 0xef993c00 0x00000000 0x00000001

Here it is observed that the memory content at first word started changing
on last 3 regmap_read() and so corruption happened.

Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
72b39f6f2b5a6b0beff14b80bed9756f151218a9 08-May-2012 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Implement dev_get_regmap()

Use devres to implement dev_get_regmap(). This should mean that in almost
all cases devices wishing to take advantage of framework features based on
regmap shouldn't need to explicitly pass the regmap into the framework.
This simplifies device setup a bit.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
7a6476143270d947924f5bbbc124accb0e558bf4 01-May-2012 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Devices using format_write don't support bulk operations

Set the use_single_rw flag for devices that use format_write() since
format_write() doesn't support any form of block operation.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2e33caf16f7a1903d226ef7f9f5ec6a234fee18e 01-May-2012 Ashish Jangam <ashish.jangam@kpitcummins.com> regmap: Converts group operation into single read write operations

Some devices does not support bulk read and write operations, for them
we have series of single write and read operations.

Signed-off-by: Anthony Olech <Anthony.Olech@diasemi.com>
Signed-off-by: Ashish Jangam <ashish.jangam@kpitcummins.com>
[Fixed coding style, don't check use_single_rw before assign --broonie ]
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
f298536728d02c19f11bda8d712ff61d767bab32 30-Apr-2012 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Cache single values read from the chip

If we don't have a cached value for a register and we can cache it then
when we do a read a value we should add it to the cache to save rereading
it later on. Do this for single register reads, for block reads the code
would be a little more complex and this covers most practical usage.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
edc9ae420f98dd094e47f8b2d33652858bdc830b 09-Apr-2012 Stephen Warren <swarren@nvidia.com> regmap: implement register striding

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>
4b5c0186e48c8d14fd7c38ff99b8d1b9aa475432 04-Apr-2012 Stephen Warren <swarren@nvidia.com> regmap: allow regmap instances to be named

Some devices have multiple separate register regions. Logically, one
regmap would be created per region. One issue that prevents this is that
each instance will attempt to create the same debugfs files. Avoid this
by allowing regmaps to be named, and use the name to construct the
debugfs directory name.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2690dfdb05abf3a8e11ff21ec12dbbe620a026fb 06-Apr-2012 Stephen Warren <swarren@nvidia.com> regmap: validate regmap_raw_read/write val_len

val_len should be a multiple of val_bytes. If it's not, error out early.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
a42678c4c8b5f6d489829ffc3071fa1f08ee99d1 04-Apr-2012 Stephen Warren <swarren@nvidia.com> regmap: introduce fast_io busses, and use a spinlock for them

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>
26b5e74d318241d95430d440e43ebbdfab3c70d4 04-Apr-2012 Stephen Warren <swarren@nvidia.com> regmap: introduce explicit bus_context for bus callbacks

The only context needed by I2C and SPI bus definitions is the device
itself; this can be converted to an i2c_client or spi_device in order
to perform IO on the device. However, other bus types may need more
context in order to perform IO. Enable this by having regmap_init accept
a bus_context parameter, and pass this to all bus callbacks. The
existing callbacks simply pass the struct device here. Future bus types
may pass something else.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
55c1371c79713fb3795a04d369e46680be5ae2bf 15-Mar-2012 Marc Reilly <marc@cpdesign.com.au> regmap: Use pad_bits and reg_bits when determining register format.

This change combines any padding bits into the register address bits when
determining register format handlers to use the next byte-divisible
register size.
A reg_shift member is introduced to the regmap struct to enable fixup
of the reg format.
Format handlers now take an extra parameter specifying the number of
bits to shift the value by.

Signed-off-by: Marc Reilly <marc@cpdesign.com.au>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
89a89b5e4fb23aa133e4aa9e0be97b43996d4ad2 15-Mar-2012 Marc Reilly <marc@cpdesign.com.au> regmap: Add support for device with 24 data bits.

Add support for devices with 24 data bits.

Signed-off-by: Marc Reilly <marc@cpdesign.com.au>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
f01ee60fffa4dc6c77122121233a793f7f696e67 09-Apr-2012 Stephen Warren <swarren@nvidia.com> regmap: implement register striding

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>
d3c242e1f22f5dfed009296ee45ce896153f0b53 04-Apr-2012 Stephen Warren <swarren@nvidia.com> regmap: allow regmap instances to be named

Some devices have multiple separate register regions. Logically, one
regmap would be created per region. One issue that prevents this is that
each instance will attempt to create the same debugfs files. Avoid this
by allowing regmaps to be named, and use the name to construct the
debugfs directory name.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
851960ba7cb38a6a108d102e4c8b0ab702972e22 06-Apr-2012 Stephen Warren <swarren@nvidia.com> regmap: validate regmap_raw_read/write val_len

val_len should be a multiple of val_bytes. If it's not, error out early.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
bacdbe077342ecc9e7b3e374cc5a41995116706a 04-Apr-2012 Stephen Warren <swarren@nvidia.com> regmap: introduce fast_io busses, and use a spinlock for them

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>
0135bbcc7a0cc056f0203ff839466236b8e3dc19 04-Apr-2012 Stephen Warren <swarren@nvidia.com> regmap: introduce explicit bus_context for bus callbacks

The only context needed by I2C and SPI bus definitions is the device
itself; this can be converted to an i2c_client or spi_device in order
to perform IO on the device. However, other bus types may need more
context in order to perform IO. Enable this by having regmap_init accept
a bus_context parameter, and pass this to all bus callbacks. The
existing callbacks simply pass the struct device here. Future bus types
may pass something else.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
d939fb9a78b4743bc4bc3cc415894ed42050c5cc 15-Mar-2012 Marc Reilly <marc@cpdesign.com.au> regmap: Use pad_bits and reg_bits when determining register format.

This change combines any padding bits into the register address bits when
determining register format handlers to use the next byte-divisible
register size.
A reg_shift member is introduced to the regmap struct to enable fixup
of the reg format.
Format handlers now take an extra parameter specifying the number of
bits to shift the value by.

Signed-off-by: Marc Reilly <marc@cpdesign.com.au>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
ea279fc5619e2541a0c28196b0fa06447d9ad026 15-Mar-2012 Marc Reilly <marc@cpdesign.com.au> regmap: Add support for device with 24 data bits.

Add support for devices with 24 data bits.

Signed-off-by: Marc Reilly <marc@cpdesign.com.au>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
51990e825431089747f8896244b5c17d3a6423f1 22-Jan-2012 Paul Gortmaker <paul.gortmaker@windriver.com> device.h: cleanup users outside of linux/include (C files)

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>
f5d6eba74b8aac7d4bf646c5445807aa6a247e6c 09-Mar-2012 Stephen Warren <swarren@wwwdotorg.org> regmap: Fix future missing prototype of devres_alloc() and friends

[Fix for breakage which will be introduced during the merge window via
header reworks in another tree, the regmap tree does include device.h
but Paul's tree breaks that. Reworded subject to reflect -- broonie]

regmap.s uses devres_alloc() and others that are prototyped in device.h.
Include that to solve the following:

drivers/base/regmap/regmap.c: In function 'devm_regmap_init':
drivers/base/regmap/regmap.c:331:2: error: implicit declaration of function 'devres_alloc' [-Werror=implicit-function-declaration]
drivers/base/regmap/regmap.c:338:3: error: implicit declaration of function 'devres_add' [-Werror=implicit-function-declaration]
drivers/base/regmap/regmap.c:340:3: error: implicit declaration of function 'devres_free' [-Werror=implicit-function-declaration]
drivers/base/regmap/regmap.c: In function '_regmap_raw_write':
drivers/base/regmap/regmap.c:421:5: error: implicit declaration of function 'dev_err' [-Werror=implicit-function-declaration]

Signed-off-by: Stephen Warren <swarren@wwwdotorg.org>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
19694b5ea1d3a723dafe9544b5ee9a935414dc28 29-Feb-2012 Paul Gortmaker <paul.gortmaker@windriver.com> regmap: delete unused module.h from drivers/base/regmap files

Remove unused module.h and/or replace with export.h
as required.

Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
b8fb5ab156055b745254609f4635fcfd6b7dabc8 21-Feb-2012 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Support raw reads from cached registers

Fall back to a register by register read to do so; most likely we'll be
cache only so the overhead will be low.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
a6539c32949063c8147905512a83a98842c2d254 17-Feb-2012 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Allow users to query the size of register values

Generic infrastructure based on top of regmap may want to operate on
blocks of data and therefore find it useful to find the size of the
register values. Provide an accessor operation for this.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
7d5e525b9ceda0e3b85da0acdaa2de19fea51edc 18-Feb-2012 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Implement support for 32 bit registers and values

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
8eaeb21925563075ae036c2e5ba8d041b70e18fa 12-Feb-2012 Laxman Dewangan <ldewangan@nvidia.com> regmap: add regmap_bulk_write() for register write

The bulk_write() supports the data transfer to multi
register which takes the data into cpu_endianness format
and does formatting of data to device format before
sending to device.
The transfer can be completed in single transfer or multiple
transfer based on data formatting.

Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
c9157198417076c0c2664ba997e7b0217f61fcce 10-Feb-2012 Laxman Dewangan <ldewangan@nvidia.com> regmap: Support for caching in reg_raw_write()

Adding support for caching of data into the
non-volatile register from the call of reg_raw_write().

This will allow the larger block of data write into multiple
register without worrying whether register is cached or not
through reg_raw_write().

Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2a14d7d9b7439fe62082a60a7f8983ccb463d134 10-Feb-2012 Axel Lin <axel.lin@gmail.com> regmap: Fix kcalloc parameters swapped

The first parameter should be "number of elements" and the second parameter
should be "element size".

Signed-off-by: Axel Lin <axel.lin@gmail.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
c0eb46766d395da8d62148bda2e59bad5e6ee2f2 30-Jan-2012 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Implement managed regmap_init()

Save error handling and unwinding code in drivers by providing managed
versions of the regmap init functions, simplifying usage.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
4191f19792bf91267835eb090d970e9cd6277a65 30-Jan-2012 Wolfram Sang <w.sang@pengutronix.de> regmap: if format_write is used, declare all registers as "unreadable"

Using .format_write means, we have a custom function to write to the
chip, but not to read back. Also, mark registers as "not precious" and
"not volatile" which is implicit because we cannot read them. Make those
functions use 'regmap_readable' to reuse the checks done there.

Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
c212acccc368a087a53559aac2b7d3be941b1252 28-Jan-2012 Wolfram Sang <w.sang@pengutronix.de> regmap: Properly round reg_bytes and val_bytes

For the upcoming 2/6-format, we don't see debugfs output otherwise,
since the current division results in 0. I'd think 10/14 is broken
currently, too.

Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
9aa507505cdcd10b7390398790f013374ee74a26 27-Jan-2012 Wolfram Sang <w.sang@pengutronix.de> regmap: Add support for 2/6 register formating

Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
a24f64a648376766497fddd8bc24b1ca5b906431 26-Jan-2012 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Reset device debugfs when reinitialising the cache

Most of the data exposed via debugfs is for or from the cache so reset
all the debugfs configuration to make sure everything is up to date with
the latest configuration, especially if we're changing cache type.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
22f0d90a34827812413bb3fbeda6a2a79bb58423 21-Jan-2012 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Support register patch sets

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>
421e8d2de3bd8b089dc6322d8589b7eb38437a23 20-Jan-2012 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Reset cache status when reinitialsing the cache

When we reinitialise the cache make sure that we reset the cache access
flags, ensuring that the reinitialised cache is in the default state
which is what callers would and do expect given the function name.

This is particularly likely to cause issues in systems where there was no
cache previously as those systems have cache bypass enabled, as for the
wm8994 driver where this was noticed.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
82159ba8e6ef8c38e3e0452d90b4ff8da9e4b2c1 18-Jan-2012 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Add support for padding between register and address

Some devices, especially those with high speed control interfaces, require
padding between the register and the data. Support this in the regmap API
by providing a pad_bits configuration parameter.

Only devices with integer byte counts are supported.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
94f9ec936513b9743996cf89d2f9c8e3110cf0f4 16-Nov-2011 Lars-Peter Clausen <lars@metafoo.de> regmap: Move initialization of regcache related fields to regcache_init

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>
bf315173359b2f3b8b8ccca4264815e91f30be12 03-Dec-2011 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Allow drivers to reinitialise the register cache at runtime

Sometimes the register map information may change in ways that drivers can
discover at runtime. For example, new revisions of a device may add new
registers. Support runtime discovery by drivers by allowing the register
cache to be reinitialised with a new function regmap_reinit_cache() which
discards the existing cache and creates a new one.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
018690d33ecf4aa1eb1415e38c40e2b0b6c7808e 29-Nov-2011 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Allow regmap_update_bits() users to detect changes

Some users of regmap_update_bits() would like to be able to tell their
users if they actually did an update so provide a variant which also
returns a flag indicating if an update took place. We could return a
tristate in the return value of regmap_update_bits() but this makes the
API more cumbersome to use and doesn't fit with the general zero for
success idiom we have.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
052d2cd123e7e36ce54558ac5af0360de2343b2b 21-Nov-2011 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Do debugfs init before cache init

This allows caches to add custom debugfs files.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
d91e8db2c3bbe8ef0e2f3e1a6ff5b31a8d53ef16 18-Nov-2011 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Suppress noop writes in regmap_update_bits()

If the new register value is identical to the original one then suppress
the write to the hardware in regmap_update_bits(), saving some I/O cost.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
7e5ec63ef574775900c82bd98f95bf039f513de3 16-Nov-2011 Lars-Peter Clausen <lars@metafoo.de> regmap: Add support for 10/14 register formating

This patch adds support for 10 bits register, 14 bits value type register
formating. This is for example used by the Analog Devices AD5380.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
19254411db4e69d90958244c5017e7e4a38547b0 16-Nov-2011 Lars-Peter Clausen <lars@metafoo.de> regmap: Try cached read before checking if a hardware read is possible

For some register format types we do not provide a parse_val so we can not do a
hardware read. But a cached read is still possible, so try to read from the
cache first, before checking whether a hardware read is possible. Otherwise the
cache becomes pretty useless for these register types.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
e5e3b8abeda1cf45f5a079458dbc267952694c7a 16-Nov-2011 Lars-Peter Clausen <lars@metafoo.de> regmap: Move initialization of regcache related fields to regcache_init

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>
abbb18fb4ad7472ee2e1351f0ca12bce64cac143 14-Nov-2011 Lars-Peter Clausen <lars@metafoo.de> regmap: return ERR_PTR instead of NULL in regmap_init

The regmap_init documentation states that it will either return a pointer to a
valid regmap structure or a ERR_PTR in case of an error. Currently it returns a
NULL pointer in case no bus or no config was given. Since NULL is not a
ERR_PTR a caller might assume that it is a pointer to a valid regmap structure,
so return a ERR_PTR(-EINVAL) instead.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
58072cbfc522c2520e34333a53c8f17bb1adb1a0 10-Nov-2011 Lars-Peter Clausen <lars@metafoo.de> regmap: Fix memory leak in regmap_init error path

If regcache initialization fails regmap_init will currently exit without
freeing work_buf.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
c48a9d74926c83f62b0251eff0a3dde259923856 08-Nov-2011 Lars-Peter Clausen <lars@metafoo.de> regmap: Support some more block operations on cached devices

Commit 10a08d9f ("regmap: Support some block operations on cached devices")
allowed raw read operations without throwing a warning when using caches if
all registers are volatile. This patch does the same for raw write operations.

This is for example useful when loading a firmware in a predefined volatile
region on a chip where we otherwise want registers to be cached.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
82cd9965c37be7e2cbcb79ad991a6b9860f855d8 08-Nov-2011 Lars-Peter Clausen <lars@metafoo.de> regmap: Add helper function for checking if a register range is volatile

We already have the same code for checking whether a register range is volatile
in two different places. Instead of duplicating it once more add a small helper
function for checking whether a register range is voltaile.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
8ae0d7e8a918e9603748abe9b31984fc5d96abb3 26-Oct-2011 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Track if the register cache is dirty and suppress unneeded syncs

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>
b973aa3624a531c7d2b4d8d199142299488f573e 28-Oct-2011 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Fix typo in kerneldoc for regmap_update_bits()

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
de2d808f4de091321978d05a85ef0819e8f3561a 10-Oct-2011 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Support some block operations on cached devices

Support raw reads if all the registers being read are volatile, the cache
will have no impact for tem.

Support bulk reads either directly (if all the registers are volatile) or
by falling back to iterating over single register reads otherwise.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
04e016adcae28b65ddc9e756947fa1526a51c0b5 09-Oct-2011 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Warn on raw I/O as well as bulk reads that bypass cache

As with the bulk reads we really should be able to make these play
nicely with the cache but warn for now.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Acked-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
4d2dc09538561eb8823c3c0072e6f5b868a5abe1 29-Sep-2011 Dimitris Papastamos <dp@opensource.wolfsonmicro.com> regmap: Make _regmap_write() global

Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
5d1729e7f02f050c73b68ce0198f8e5c48e9608a 19-Sep-2011 Dimitris Papastamos <dp@opensource.wolfsonmicro.com> regmap: Incorporate the regcache core into regmap

This patch incorporates the regcache core code into regmap. All previous
patches have been no-ops essentially up to this point.

The bulk read operation is not supported by regcache at the moment. This
will be implemented incrementally.

Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
Tested-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
6f306441e97f8f9d27c43a536360fe221f675a71 05-Sep-2011 Lars-Peter Clausen <lars@metafoo.de> regmap: Add support for device specific write and read flag masks.

Some buses like SPI have no standard notation of read or write operations.
The general scheme here is to set or clear specific bits in the register
address to indicate whether the operation is a read or write. We already
support having a read flag mask per bus, but as there is no standard
the bits which need to be set or cleared differ between devices and vendors,
thus we need a mechanism to specify them per device.

This patch adds two new entries to the regmap_config struct, read_flag_mask and
write_flag_mask. These will be or'ed onto the top byte when doing a read or
write operation. If both masks are empty the device will fallback to the
regmap_bus masks.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
5204f5e3f5b3c706e52682590de5974a82ea54f9 05-Sep-2011 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Remove bitrotted module_put()s

The conversion to per bus type registration functions means we don't need
to do module_get()s to hold the bus types in memory (their users will link
to them) so we removed all those calls. This left module_put() calls in
the cleanup paths which aren't needed and which cause unbalanced puts if
we ever try to unload anything.

Reported-by: Jonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
8de2f081ef8ee716663f916df9f2a7d015fa0dad 10-Aug-2011 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Add functions to check for access on registers

We're going to be using these in quite a few places so factor out the
readable/writable/volatile/precious checks.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2efe1642b73e74604498175de032b8a604868fb7 08-Aug-2011 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Skip precious registers when dumping registers via debugfs

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
31244e396fa9e4854cfd6dfe305983e77802c156 20-Jul-2011 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Provide register map dump via debugfs

Copy over the read parts of the ASoC debugfs implementation into regmap,
allowing users to see what the register values the device has are at
runtime. The implementation, especially the support for seeking, is
mostly due to Dimitris Papastamos' work in ASoC.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
93de91245b66f20dd387c2745744950a11a5c436 20-Jul-2011 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Use a local header for API internals

Allowing the implementation to be multi-file.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
73304781274200c341996f65220d36b3cda8e217 24-Jul-2011 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Implement writable register checks

This is mainly intended to be used by devices which can dynamically
block register writes at runtime, for other devices there is usually
limited value.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
fb2736bbaee0e704a4f33912cf532597b2dc5b33 24-Jul-2011 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Add basic tracepoints

Trace single register reads and writes, plus start/stop tracepoints for
the actual I/O to see where we're spending time. This makes it easy to
have always on logging without overwhelming the logs and also lets us take
advantage of all the context and time information that the trace subsystem
collects for us.

We don't currently trace register values for bulk operations as this would
add complexity and overhead parsing the cooked data that's being worked
with.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2547e201b3693f91d643fc0d21ef86171894b59b 20-Jul-2011 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Just send the buffer directly for single register writes

When doing a single register write we use work_buf for both the register
and the value with the buffer formatted for sending directly to the device
so we can just do a write() directly. This saves allocating a temporary
buffer if we can't do gather writes and is likely to be faster than doing
a gather write.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2e2ae66df37a14c9b33889b243b0ae1352ada1dd 20-Jul-2011 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Allow devices to specify which registers are accessible

This is currently unused but we need to know which registers exist and
their properties in order to implement diagnostics like register map
dumps and the cache features.

We use callbacks partly because properties can vary at runtime (eg, through
access locks on registers) and partly because big switch statements are a
good compromise between readable code and small data size for providing
information on big register maps.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
40c5cc263954444f5a76cbf25d408c42da480122 24-Jul-2011 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Fix bulk reads

We should be reading the number of bytes we were asked for, not the size
of a single register.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
b83a313bf2520183641cf485d68cc273323597d2 11-May-2011 Mark Brown <broonie@opensource.wolfsonmicro.com> regmap: Add generic non-memory mapped register access API

There are many places in the tree where we implement register access for
devices on non-memory mapped buses, especially I2C and SPI. Since hardware
designers seem to have settled on a relatively consistent set of register
interfaces this can be effectively factored out into shared code. There
are a standard set of formats for marshalling data for exchange with the
device, with the actual I/O mechanisms generally being simple byte
streams.

We create an abstraction for marshaling data into formats which can be
sent on the control interfaces, and create a standard method for
plugging in actual transport underneath that.

This is mostly a refactoring and renaming of the bottom level of the
existing code for sharing register I/O which we have in ASoC. A
subsequent patch in this series converts ASoC to use this. The main
difference in interface is that reads return values by writing to a
location provided by a pointer rather than in the return value, ensuring
we can use the full range of the type for register data. We also use
unsigned types rather than ints for the same reason.

As some of the devices can have very large register maps the existing
ASoC code also contains infrastructure for managing register caches.
This cache work will be moved over in a future stage to allow for
separate review, the current patch only deals with the physical I/O.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Acked-by: Liam Girdwood <lrg@ti.com>
Acked-by: Greg Kroah-Hartman <gregkh@suse.de>
Acked-by: Wolfram Sang <w.sang@pengutronix.de>
Acked-by: Grant Likely <grant.likely@secretlab.ca>