Commit graph

522 commits

Author SHA1 Message Date
Alexander Shiyan
d323343335 regmap: irq: Allow using zero value for ack_base
In some cases, clear interrupt register may be at address 0.
This patch allows to use such configurations by adding additional
configuration bit to indicate this.

[With doc fix from Levente Kurusa <levex@linux.com> -- broonie]

Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
Signed-off-by: Mark Brown <broonie@linaro.org>
2013-12-16 20:50:13 +00:00
Mark Brown
652787ab1a Merge remote-tracking branches 'regmap/fix/doc' and 'regmap/fix/mmio' into regmap-linus 2013-11-26 13:16:56 +00:00
Stephen Warren
6b8e090ecc regmap: use IS_ERR() to check clk_get() results
clk_get() returns an error pointer, or a valid token to pass back to the
clock API. Hence, the result must be checked with IS_ERR(), not by
comparison against NULL.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
2013-11-26 13:16:31 +00:00
Cai Zhiyong
bd60e381fa 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>
2013-11-24 13:59:14 +00:00
Courtney Cavin
73f080fde5 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>
2013-11-21 14:05:31 +00:00
Gerhard Sittig
0093380c18 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>
2013-11-12 01:23:53 +00:00
Mark Brown
04bc9ac163 Merge remote-tracking branch 'regmap/topic/spmi' into regmap-next 2013-10-28 13:01:35 -07:00
Mark Brown
18f513db93 Merge remote-tracking branch 'regmap/topic/multi' into regmap-next 2013-10-28 13:01:34 -07:00
Mark Brown
6cf3d82323 Merge remote-tracking branch 'regmap/topic/irq' into regmap-next 2013-10-28 13:01:34 -07:00
Mark Brown
f2783f0e9c Merge remote-tracking branch 'regmap/topic/field' into regmap-next 2013-10-28 13:01:33 -07:00
Mark Brown
bee54e310e Merge remote-tracking branch 'regmap/topic/core' into regmap-next 2013-10-28 13:01:33 -07:00
Josh Cartwright
a01779f89f regmap: add SPMI support
Add basic support for the System Power Management Interface (SPMI) bus.
This is a simple implementation which only implements register accesses
via the Extended Register Read/Write Long commands.

Signed-off-by: Josh Cartwright <joshc@codeaurora.org>
Signed-off-by: Mark Brown <broonie@linaro.org>
2013-10-28 12:51:43 -07:00
Tero Kristo
a52eaeb189 regmap: debugfs: Fix a boot time crash with early regmap init
If called early enough, regmap_debugfs_init causes a crash, if the
fs subsystem does not have its mount cache created yet. Even if this
would work, the root node for the regmap debugfs is still missing,
thus postpone the regmap_debugfs_init in this case until the root
node is created. A special regmap_debugfs_early list is created for
this purpose which is parsed later in the boot.

Signed-off-by: Tero Kristo <t-kristo@ti.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
2013-10-24 13:50:58 +01:00
Yi Zhang
4bd7145b19 regmap: irq: clear status when disable irq
clear the status bit if the mask register doesn't prevent
the chip level irq from being asserted

OR in the following sequence, there will be irq storm happens:
1) interrupt is triggered;
2) another thread disables it(the mask bit is set);
3) _Then_ the interrupt thread is not ACKed(the status bit is not cleared),
   and it's ignored;
4) if the irq is still asserted because of the uncleared status bit,
   the irq storm happens;

Signed-off-by: Yi Zhang <yizhang@marvell.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
2013-10-22 13:28:08 +01:00
Mark Brown
04c50ccf0d 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>
2013-10-14 22:09:26 +01:00
Mark Brown
cd1b9dd022 regmap: spi: Handle async writes of only one buffer
If the value is zero then assume it has been included in the register data
and don't send anything, minimising the number of interactions with the
hardware.

Signed-off-by: Mark Brown <broonie@linaro.org>
2013-10-14 22:09:26 +01:00
Anthony Olech
e33fabd365 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>
2013-10-14 15:09:16 +01:00
Mark Brown
7ccda98393 Merge remote-tracking branch 'regmap/fix/core' into regmap-async 2013-10-10 21:50:18 +01:00
Mark Brown
affbe886e7 regmap: Use async I/O during cache sync
Try to speed up I/O a little by not synchronising until we are finished
scheduling writes. A brief survey of existing users suggests we have none
that would currently benefit from an async cache sync.

Signed-off-by: Mark Brown <broonie@linaro.org>
2013-10-10 21:15:23 +01:00
Mark Brown
1a25f26138 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>
2013-10-10 21:15:21 +01:00
Anthony Olech
4174a7a4f7 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>
2013-10-09 18:47:27 +01:00
Mark Brown
915f441b6f 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>
2013-10-09 14:05:26 +01:00
Mark Brown
0a8198094d 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>
2013-10-09 14:05:24 +01:00
Mark Brown
651e013e3c 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>
2013-10-09 14:05:21 +01:00
Mark Brown
7e09a97940 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>
2013-10-07 23:04:41 +01:00
Kuninori Morimoto
a0102375ee 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>
2013-09-17 13:46:57 +01:00
Kuninori Morimoto
fdf2002905 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>
2013-09-17 00:12:23 +01:00
Linus Torvalds
542a086ac7 Driver core patches for 3.12-rc1
Here's the big driver core pull request for 3.12-rc1.
 
 Lots of tiny changes here fixing up the way sysfs attributes are
 created, to try to make drivers simpler, and fix a whole class race
 conditions with creations of device attributes after the device was
 announced to userspace.
 
 All the various pieces are acked by the different subsystem maintainers.
 
 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.21 (GNU/Linux)
 
 iEYEABECAAYFAlIlIPcACgkQMUfUDdst+ynUMwCaAnITsxyDXYQ4DqEsz8EcOtMk
 718AoLrgnUZs3B+70AT34DVktg4HSThk
 =USl9
 -----END PGP SIGNATURE-----

Merge tag 'driver-core-3.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core

Pull driver core patches from Greg KH:
 "Here's the big driver core pull request for 3.12-rc1.

  Lots of tiny changes here fixing up the way sysfs attributes are
  created, to try to make drivers simpler, and fix a whole class race
  conditions with creations of device attributes after the device was
  announced to userspace.

  All the various pieces are acked by the different subsystem
  maintainers"

* tag 'driver-core-3.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core: (119 commits)
  firmware loader: fix pending_fw_head list corruption
  drivers/base/memory.c: introduce help macro to_memory_block
  dynamic debug: line queries failing due to uninitialized local variable
  sysfs: sysfs_create_groups returns a value.
  debugfs: provide debugfs_create_x64() when disabled
  rbd: convert bus code to use bus_groups
  firmware: dcdbas: use binary attribute groups
  sysfs: add sysfs_create/remove_groups for when SYSFS is not enabled
  driver core: add #include <linux/sysfs.h> to core files.
  HID: convert bus code to use dev_groups
  Input: serio: convert bus code to use drv_groups
  Input: gameport: convert bus code to use drv_groups
  driver core: firmware: use __ATTR_RW()
  driver core: core: use DEVICE_ATTR_RO
  driver core: bus: use DRIVER_ATTR_WO()
  driver core: create write-only attribute macros for devices and drivers
  sysfs: create __ATTR_WO()
  driver-core: platform: convert bus code to use dev_groups
  workqueue: convert bus code to use dev_groups
  MEI: convert bus code to use dev_groups
  ...
2013-09-03 11:37:15 -07:00
Linus Torvalds
8243b7f5dc regmap: Updates for v3.12
A quiet release for regmap, some cleanups, fixes and:
 
  - Improved node coalescing for rbtree, reducing memory usage and
    improving performance during syncs.
  - Support for registering multiple register patches.
  - A quirk for handling interrupts that need to be clear when masked
    in regmap-irq.
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.14 (GNU/Linux)
 
 iQIcBAABAgAGBQJSI6GWAAoJELSic+t+oim9Yo0P/iF0kj93XcN93urEjZ+TYWsd
 EfeqRv0AB+GB6WB7KR7Tg/bkYhH7xdm4pmTRHcSOZpwDu6tSyGZYD3lgnc9ZTeBF
 W4V5TLHyZu+VLORQcR3dQgzyzSHe+JtwVBYJPoA+JUAMSaKSchRZ0O8bQ4pw0CCH
 COw+UoSEt2/eBiVRkp5XkUZp6tb2jChRva+lZbTfEa3rBNFNnJ7dzlQAKx80Sc80
 ygK3nmLNfux7ZloeghOfHJFlCuo4Bf0u44lyOucOj+4ZgHq0b0CW6LZGGQBc2d9I
 6iVu2GZ81wbVtUg1mnTccmhVCd0MSFCytQrH9qYM7H/BK0L3gjMSnl6xJkBVItHx
 LuicibmdNNue6ToMsWS8nNQLDOqHC8p/RTJc+JY+9EqZF1e78/EIox42XAH/60mG
 PqRRtVtOsKreUzcfnpO4J6zhA8FCjgr4BsuQ7DXkl1SiKcikbIpzb+wlUxszD25m
 SiH4NsHzqwTv0AE4vIvfvz02cQwyPppBhPGJzmeMtlq45rhsZqhuhhPLu/XWY1H8
 n0uK+q0rMXtr7NZJArFNTrgKQet+gZTvJqlmi7Zl2QS7Zd4BAPFgOz7HpaF8lH4i
 9faUZgms6t4QmUncEGjOqyS62GiTHAApG9gA1UVE0xWT5q//zHN0BZN+rHx3aAR1
 TSwN/gxtLfCgYeWy6BWi
 =um4f
 -----END PGP SIGNATURE-----

Merge tag 'regmap-v3.12' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap

Pull regmap updates from Mark Brown:
 "A quiet release for regmap, some cleanups, fixes and:

   - Improved node coalescing for rbtree, reducing memory usage and
     improving performance during syncs.
   - Support for registering multiple register patches.
   - A quirk for handling interrupts that need to be clear when masked
     in regmap-irq"

* tag 'regmap-v3.12' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap:
  regmap: rbtree: Make cache_present bitmap per node
  regmap: rbtree: Reduce number of nodes, take 2
  regmap: rbtree: Simplify adjacent node look-up
  regmap: debugfs: Fix continued read from registers file
  regcache-rbtree: Fix reg_stride != 1
  regmap: Allow multiple patches to be registered
  regmap: regcache: allow read-only regs to be cached
  regmap: fix regcache_reg_present() for empty cache
  regmap: core: allow a virtual range to cover its own data window
  regmap: irq: document mask/wake_invert flags
  regmap: irq: make flags bool and put them in a bitfield
  regmap: irq: Allow to acknowledge masked interrupts during initialization
  regmap: Provide __acquires/__releases annotations
2013-09-03 10:07:40 -07:00
Mark Brown
365c9ee073 Merge remote-tracking branch 'regmap/topic/sparse' into regmap-next 2013-08-31 19:25:16 +01:00
Mark Brown
4460d028d4 Merge remote-tracking branch 'regmap/topic/rbtree' into regmap-next 2013-08-31 19:25:15 +01:00
Mark Brown
db00cb9943 Merge remote-tracking branch 'regmap/topic/range' into regmap-next 2013-08-31 19:25:14 +01:00
Mark Brown
3dedb61ec7 Merge remote-tracking branch 'regmap/topic/patch' into regmap-next 2013-08-31 19:25:13 +01:00
Mark Brown
1801ceaf07 Merge remote-tracking branch 'regmap/topic/irq' into regmap-next 2013-08-31 19:25:12 +01:00
Mark Brown
4ff4eb9e8c Merge remote-tracking branch 'regmap/topic/cache' into regmap-next 2013-08-31 19:25:11 +01:00
Lars-Peter Clausen
3f4ff561bc regmap: rbtree: Make cache_present bitmap per node
With devices which have a dense and small register map but placed at a large
offset the global cache_present bitmap imposes a huge memory overhead. Making
the cache_present per rbtree node avoids the issue and easily reduces the memory
footprint by a factor of ten. For devices with a more sparse map or without a
large base register offset the memory usage might increase slightly by a few
bytes, but not significantly. E.g. for a device which has ~50 registers at
offset 0x4000 the memory footprint of the register cache goes down form 2496
bytes to 175 bytes.

Moving the bitmap to a per node basis means that the handling of the bitmap is
now cache implementation specific and can no longer be managed by the core. The
regcache_sync_block() function is extended by a additional parameter so that the
cache implementation can tell the core which registers in the block are set and
which are not. The parameter is optional and if NULL the core assumes that all
registers are set. The rbtree cache also needs to implement its own drop
callback instead of relying on the core to handle this.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@linaro.org>
2013-08-29 13:32:41 +01:00
Lars-Peter Clausen
472fdec738 regmap: rbtree: Reduce number of nodes, take 2
Support for reducing the number of nodes and memory consumption of the rbtree
cache by allowing for small unused holes in the node's register cache block was
initially added in commit 0c7ed856 ("regmap: Cut down on the average # of nodes
in the rbtree cache"). But the commit had problems and so its effect was
reverted again in commit 4e67fb5 ("regmap: rbtree: Fix overlapping rbnodes.").
This patch brings the feature back of reducing the average number of nodes,
which will speedup node look-up, while at the same time also reducing the memory
usage of the rbtree cache. This patch takes a slightly different approach than
the original patch though. It modifies the adjacent node look-up to not only
consider nodes that are just one to the left or the right of the register but
any node that falls in a certain range around the register. The range is
calculated based on how much memory it would take to allocate a new node
compared to how much memory it takes adding a set of unused registers to an
existing node. E.g. if a node takes up 24 bytes and each register in a block
uses 1 byte the range will be from the register address - 24 to the register
address + 24. If we find a node that falls within this range it is cheaper or as
expensive to add the register to the existing node and have a couple of unused
registers in the node's cache compared to allocating a new node.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@linaro.org>
2013-08-29 13:32:40 +01:00
Lars-Peter Clausen
194c753a21 regmap: rbtree: Simplify adjacent node look-up
A register which is adjacent to a node will either be left to the first
register or right to the last register. It will not be within the node's range,
so there is no point in checking for each register cached by the node whether
the new register is next to it. It is sufficient to check whether the register
comes before the first register or after the last register of the node.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@linaro.org>
2013-08-29 13:32:40 +01:00
Mark Brown
65c180fd95 Merge remote-tracking branch 'regmap/topic/cache' into regmap-rbtree 2013-08-29 13:32:36 +01:00
Lars-Peter Clausen
26ee47411a regmap: debugfs: Fix continued read from registers file
The regmap_debugfs_get_dump_start() function maps from a file offset to the
register that can be found at that position in the file. This is done using a
look-up table. Commit d6814a7d ("regmap: debugfs: Suppress cache for partial
register files") added a check to bypass the look-up table for partial register
files, since the offsets in that table are only correct for the full register
file. The check incorrectly uses the file offset instead of the register base
address and returns it. This will cause the file offset to be interpreted as a
register address which will result in a incorrect output from the registers file
for all reads except at position 0.

The issue can easily be reproduced by doing small reads the registers file, e.g.
`dd if=registers bs=10 count=5`.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@linaro.org>
Cc: stable@vger.kernel.org
2013-08-28 18:27:08 +01:00
Lars-Peter Clausen
b6752123cc regcache-rbtree: Fix reg_stride != 1
There are a couple of calculations, which convert between register addresses and
block indices, in regcache_rbtree_sync() and regcache_rbtree_node_alloc() which
assume that reg_stride is 1. This will break the rb cache for configurations
which do not use a reg_stride of 1.

Also rename 'base' in regcache_rbtree_sync() to 'start' to avoid confusion with
'base_reg'.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@linaro.org>
2013-08-27 16:23:00 +01:00
David Jander
4e67fb5f5e regmap: rbtree: Fix overlapping rbnodes.
Avoid overlapping register regions by making the initial blklen of a new
node 1. If a register write occurs to a yet uncached register, that is
lower than but near an existing node's base_reg, a new node is created
and it's blklen is set to an arbitrary value (sizeof(*rbnode)). That may
cause this node to overlap with another node. Those nodes should be merged,
but this merge doesn't happen yet, so this patch at least makes the initial
blklen small enough to avoid hitting the wrong node, which may otherwise
lead to severe breakage.

Signed-off-by: David Jander <david@protonic.nl>
Signed-off-by: Mark Brown <broonie@linaro.org>
Cc: stable@vger.kernel.org
2013-08-21 17:03:54 +01:00
Mark Brown
aab13ebca2 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>
2013-08-16 20:33:05 +01:00
Ionut Nicu
515f226170 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>
2013-08-09 12:47:29 +01:00
Ionut Nicu
1767da9e8e regmap: fix regcache_reg_present() for empty cache
In the initial case when no reg_defaults values are
provided and no register value was added to the cache
yet, the cache_present bitmap is NULL. If this function
is invoked for any register it should return false
(i.e. the register is not cached) instead of true.

Signed-off-by: Ionut Nicu <ioan.nicu.ext@nsn.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
2013-08-09 12:47:29 +01:00
Philipp Zabel
f161d22081 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>
2013-08-06 18:33:59 +01:00
Lars-Peter Clausen
2d49b59875 regmap: cache: Make sure to sync the last register in a block
regcache_sync_block_raw_flush() expects the address of the register after last
register that needs to be synced as its parameter. But the last call to
regcache_sync_block_raw_flush() in regcache_sync_block_raw() passes the address
of the last register in the block. This effectively always skips over the last
register in a block, even if it needs to be synced. In order to fix it increase
the address by one register.

The issue was introduced in commit 75a5f89 ("regmap: cache: Write consecutive
registers in a single block write").

Cc: stable@vger.kernel.org # 3.10+
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@linaro.org>
2013-08-05 15:51:09 +01:00
Jingoo Han
34da5e6770 driver core: replace strict_strto*() with kstrto*()
The usage of strict_strto*() is not preferred, because
strict_strto*() is obsolete. Thus, kstrto*() should be
used.

Signed-off-by: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-07-26 18:02:43 -07:00
Philipp Zabel
2753e6f820 regmap: irq: Allow to acknowledge masked interrupts during initialization
In case the hardware interrupt mask register does not prevent the chip level
irq from being asserted by the corresponding interrupt status bit, already
set interrupt bits should to be cleared once after masking them during
initialization. Add a flag to let drivers enable this behavior.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: Mark Brown <broonie@linaro.org>
2013-07-23 20:39:12 +01:00
Fabio Estevam
b4519c71c4 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>
2013-07-16 11:17:43 +01:00
Linus Torvalds
f2ec26a3d4 regmap: Fix crash for async operation on busless maps
This fixes a crash if something tries to do an asynchronous operation on
 busless maps which was introduced during the merge window.
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.12 (GNU/Linux)
 
 iQIcBAABAgAGBQJR48ywAAoJELSic+t+oim9qWsP/1/t39jYvgHvkKyTKs9OHiDv
 tnhJdtbfGty10/wykRfkg5cKC+gCQaLjbBiynpOMUc0lURoCLZSIXaX/Y+mc7A8y
 HvnojQ2mUOxhYmeZsFgwnOFZmBLjTC4ZpqRmsuQ/t+qV41BbhXUVyN9nSbpjL35Z
 Fgq7za+vdLBxcHjKk6Xigi1XA2orgcIWoU9F8hcSLgw9XRjr1DhCS4KZliqZbVgR
 8ulANUro+tvzXM7PbTZmSDX6tXTy40IZBkVu74Tfh7y+stAr/nlpPcXMBW49hw+W
 9Z3NKYBTEnstBRjhWGqiPUtPGThme5fPu/nvASH8uMDIQDdCzm2oYhYaRtEoir0n
 SIu3vbaWCOtZNM6z1XWpoPPlb3e4HBbgm/kGur3DzCsb8LY23JzYxmGzN0JJ5om6
 2f1GwaIK2MYc4lT0iBkaw5MaNjFk3KJSw+MIjJ0bNUub3A8HwvCyN+BzRc87lnar
 RGpJ12wOBCtw+K5kqOuLPuPW0fyGOGIrxFJQy4ji+FSwasvA8bcJczhGroQayzrk
 kS6t38Iy0ZNSZ4IZYyYs5vwEqOumRYWNND/KI0lqPKhaysxGJ+YVTd42SiCF/1YN
 3NRAqEKgquUYvhacCealMQuDcQBRplHCwfbDco1gjcWfBugDq6P8ST9K2ZJ/8R+C
 O3HMMG6VlXKJ0K9GbnS7
 =c5Gp
 -----END PGP SIGNATURE-----

Merge tag 'regmap-v3.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap

Pull regmap fix from Mark Brown:
 "Fix regmap crash for async operation on busless maps

  This fixes a crash if something tries to do an asynchronous operation
  on busless maps which was introduced during the merge window"

* tag 'regmap-v3.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap:
  regmap: cache: bail in regmap_async_complete() for bus-less maps
2013-07-15 15:44:58 -07:00
Daniel Mack
f2e055e7c9 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>
2013-07-04 13:54:44 +01:00
Mark Brown
7bc8c4c37a Merge remote-tracking branch 'regmap/topic/field' into regmap-next 2013-06-30 12:40:03 +01:00
Mark Brown
ad4f496b44 Merge remote-tracking branch 'regmap/topic/debugfs' into regmap-next 2013-06-30 12:40:02 +01:00
Mark Brown
912af52f31 Merge remote-tracking branch 'regmap/topic/core' into regmap-next 2013-06-30 12:40:02 +01:00
Mark Brown
feff98f550 Merge remote-tracking branch 'regmap/topic/cache' into regmap-next 2013-06-30 12:40:01 +01:00
Mark Brown
d6814a7daf regmap: debugfs: Suppress cache for partial register files
The cache is based on the full register map so confuses things if used
for a partial map.

Reported-by: Bard Liao <bardliao@realtek.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-06-19 10:18:09 +01:00
Srinivas Kandagatla
6725228787 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>
2013-06-12 16:27:44 +01:00
Mark Brown
998a4f2f1c Merge remote-tracking branch 'regmap/fix/debugfs' into regmap-linus 2013-06-03 18:07:38 +01:00
Mark Brown
b92be6fecc 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>
2013-06-03 18:06:48 +01:00
Maarten ter Huurne
d856fce41b regmap: Implemented default cache sync operation
This can be used for cache types for which syncing values one by one is
equally efficient as syncing a range, such as the flat cache.

Signed-off-by: Maarten ter Huurne <maarten@treewalker.org>
Signed-off-by: Mark Brown <broonie@linaro.org>
2013-06-03 11:50:50 +01:00
Maarten ter Huurne
f3284f9153 regmap: rbtree: Fixed node range check on sync
A node starting before the minimum register is no reason to reject it,
since its end could be in range. The check for the end already exists
two lines lower, so we can just remove the incorrect check.

Signed-off-by: Maarten ter Huurne <maarten@treewalker.org>
Signed-off-by: Mark Brown <broonie@linaro.org>
2013-06-01 20:10:05 +01:00
Lars-Peter Clausen
92ab1aab59 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>
2013-05-25 11:16:02 -04:00
Lars-Peter Clausen
f20c783c3a regmap: regcache: Fixup locking for custom lock callbacks
The parameter passed to the regmap lock/unlock callbacks needs to be
map->lock_arg, regcache passes just map. This works fine in the case that no
custom locking callbacks are used since in this case map->lock_arg equals map,
but will break when custom locking callbacks are used. The issue was introduced
in commit 0d4529c5("regmap: make lock/unlock functions customizable") and is
fixed by this patch.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-05-23 11:02:14 -05:00
Lars-Peter Clausen
81485f5220 regmap: regcache: Fixup locking for custom lock callbacks
The parameter passed to the regmap lock/unlock callbacks needs to be
map->lock_arg, regcache passes just map. This works fine in the case that no
custom locking callbacks are used, since in this case map->lock_arg equals map,
but will break when custom locking callbacks are used. The issue was introduced
in commit 0d4529c5 ("regmap: make lock/unlock functions customizable") and is
fixed by this patch.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-05-23 09:07:33 -05:00
Srinivas Kandagatla
213fa5d968 regmap: debugfs: Fix return from regmap_debugfs_get_dump_start
regmap_debugfs_get_dump_start should return the offset of the register
it should start reading from, However in the current code at one point
the code does not return correct register offset.

With this patch all the returns from this function takes reg_stride in
to consideration to return correct offset.

Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@st.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-05-14 16:53:45 +04:00
Mark Brown
f9e464a566 regmap: debugfs: Don't mark lockdep as broken due to debugfs write
A register write to hardware is reasonably unlikely to cause locking
dependency issues, the reason we're tainting is that unexpected changes
in the hardware configuration may confuse drivers.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-05-12 19:01:39 +04:00
Dimitris Papastamos
68e850d80d regmap: debugfs: Check return value of regmap_write()
Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-05-12 18:57:48 +04:00
Mark Brown
7278af5fb3 regmap: rbtree: Use range information to allocate nodes
If range information has been provided then when we allocate a rbnode
within a range allocate the entire range. The goal is to minimise the
number of reallocations done when combining or extending blocks. At
present only readability and yes_ranges are taken into account, this is
expected to cover most cases efficiently.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-05-12 18:46:47 +04:00
Mark Brown
0186645d25 regmap: rbtree: Factor out node allocation
In preparation for being slightly smarter about how we allocate memory
factor out the node allocation.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-05-12 18:46:47 +04:00
Mark Brown
154881e59b 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>
2013-05-12 18:46:47 +04:00
Mark Brown
697e85bc6a regmap: Add support for discarding parts of the register cache
Allow drivers to discard parts of the register cache, for example if part
of the hardware has been reset.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-05-12 18:46:47 +04:00
Mark Brown
38a817965d Merge remote-tracking branch 'regmap/topic/range' into regmap-next 2013-04-16 16:05:50 +01:00
Mark Brown
7f47db4006 Merge remote-tracking branch 'regmap/topic/irq' into regmap-next 2013-04-16 16:05:48 +01:00
Mark Brown
5b3b448475 Merge remote-tracking branch 'regmap/topic/cache' into regmap-next 2013-04-16 16:05:46 +01:00
Mark Brown
b508c80c55 Merge remote-tracking branch 'regmap/topic/async' into regmap-next 2013-04-16 16:05:44 +01:00
Stephen Warren
5a08d15602 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>
2013-04-16 16:05:03 +01:00
Mark Brown
60f7110e36 Linux 3.9-rc7
-----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.19 (GNU/Linux)
 
 iQEcBAABAgAGBQJRa02/AAoJEHm+PkMAQRiGDRoH/08Cu2LpmX4VN+YMC3BkGWxn
 4oOHGqdN0hrIQ4TysC43QNL6g7QJUnIR6fChn7pRJ6a8ljdzKjDHr/tZSIPJE3Ns
 UAGIDaaQWnZvGmHPzpbo4gmdMOTxg9xmpgac6Qpk6QowPIPc6fhl6AichP9OdH2G
 Fp6Irfznn5ZCBldJYg2+umoHyFTZARCxtdOKmmUnB7zH0GaX5ZRf/R6nmZEPlxE+
 5qJC1yxRxJE+I7gjNRFovxaLPuAmjPy5j6NJuGP8rR6epkhcJ2EVHSliI3KDKAO6
 D3Fy9T5qHv2A2gvSxtC0m5/1WrutXZqxZ/DOB/uv9U7vqomiIs/EsHIuvc9qFBY=
 =NrST
 -----END PGP SIGNATURE-----

Merge tag 'v3.9-rc7' into regmap-cache

Linux 3.9-rc7
2013-04-16 16:02:41 +01:00
Mark Brown
51a246aa5c 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>
2013-04-09 18:03:25 +01:00
Stratos Karafotis
9659293c17 regmap: cache: Fix format specifier in dev_dbg
Fix format specifier in dev_dbg and suppress the following warning

drivers/base/regmap/regcache.c: In function
‘regcache_sync_block_raw_flush’:
drivers/base/regmap/regcache.c:593:2: warning: format ‘%d’ expects
argument of type ‘int’, but argument 4 has type ‘size_t’ [-Wformat]

Signed-off-by: Stratos Karafotis <stratosk@semaphore.gr>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-04-05 11:28:12 +01:00
Sachin Kamat
f52687afb8 regmap: cache: Make regcache_sync_block_raw static
regcache_sync_block_raw is used only in this file. Hence make it static.
Silences the following warning:
drivers/base/regmap/regcache.c:608:5: warning:
symbol 'regcache_sync_block_raw' was not declared. Should it be static?

Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-04-05 11:28:12 +01:00
Mark Brown
af8ee69df3 Merge remote-tracking branch 'regmap/fix/async' into tmp 2013-03-31 23:27:38 +01:00
Mark Brown
6d66df4109 Merge remote-tracking branch 'regmap/fix/core' into tmp 2013-03-31 23:09:22 +01:00
Mark Brown
75a5f89f63 regmap: cache: Write consecutive registers in a single block write
When syncing blocks of data using raw writes combine the writes into a
single block write, saving us bus overhead for setup, addressing and
teardown.

Currently the block write is done unconditionally as it is expected that
hardware which has a register format which can support raw writes will
support auto incrementing writes, this decision may need to be revised in
future.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Reviewed-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
2013-03-30 13:52:36 +00:00
Mark Brown
cfdeb8c37e regmap: cache: Split raw and non-raw syncs
For code clarity after implementing block writes split out the raw and
non-raw I/O sync implementations.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Reviewed-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
2013-03-30 13:52:31 +00:00
Mark Brown
f8bd822cbf regmap: cache: Factor out block sync
The idea of holding blocks of registers in device format is shared between
at least rbtree and lzo cache formats so split out the loop that does the
sync from the rbtree code so optimisations on it can be reused.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Reviewed-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
2013-03-30 13:52:25 +00:00
Mark Brown
78493f2d7b regmap: cache: Factor out reg_present support from rbtree cache
The idea of maintaining a bitmap of present registers is something that
can usefully be used by other cache types that maintain blocks of cached
registers so move the code out of the rbtree cache and into the generic
regcache code.

Refactor the interface slightly as we go to wrap the set bit and enlarge
bitmap operations (since we never do one without the other) and make it
more robust for reads of uncached registers by bounds checking before we
look at the bitmap.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Reviewed-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
2013-03-30 13:49:17 +00:00
Mark Brown
f951b6587b regmap: async: Add missing return
Let's only write once...

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-03-27 13:08:44 +00:00
Mark Brown
137b833457 regmap: cache: Use raw I/O to sync rbtrees if we can
This will bring no meaningful benefit by itself, it is done as a separate
commit to aid bisection if there are problems with the following commits
adding support for coalescing adjacent writes.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-03-27 13:03:41 +00:00
Mark Brown
221ad7f2df 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>
2013-03-27 13:03:39 +00:00
Mark Brown
8817796b75 regmap: cache: Provide a get address of value operation
Provide a helper to do the size based index into a block of registers and
use it when reading a value.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-03-26 21:38:16 +00:00
Dimitris Papastamos
0c7ed8563a regmap: Cut down on the average # of nodes in the rbtree cache
This patch aims to bring down the average number of nodes
in the rbtree cache and increase the average number of registers
per node.  This should improve general lookup and traversal times.
This is achieved by setting the minimum size of a block within the
rbnode to the size of the rbnode itself.  This will essentially
cache possibly non-existent registers so to combat this scenario,
we keep a separate bitmap in memory which keeps track of which register
exists.  The memory overhead of this change is likely in the order of
~5-10%, possibly less depending on the register file layout.  On my test
system with a bitmap of ~4300 bits and a relatively sparse register
layout, the memory requirements for the entire cache did not increase
(the cutting down of nodes which was about 50% of the original number
compensated the situation).

A second patch that can be built on top of this can look at the
ratio `sizeof(*rbnode) / map->cache_word_size' in order to suitably
adjust the block length of each block.

Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-03-26 21:38:15 +00:00
Mark Brown
584de329ca 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>
2013-03-26 19:17:32 +00:00
Mark Brown
f1b5c5c342 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>
2013-03-26 19:17:11 +00:00
Stephen Warren
bc8ce4afd7 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>
2013-03-21 20:08:15 +01:00
Mark Brown
eed456f93d regmap: irq: Clarify error message when we fail to request primary IRQ
Display the name for the chip rather than just the primary IRQ so it is
clearer what exactly has failed.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-03-19 10:50:56 +00:00
Lars-Peter Clausen
8abac3ba51 regmap: cache Fix regcache-rbtree sync
The last register block, which falls into the specified range, is not handled
correctly. The formula which calculates the number of register which should be
synced is inverse (and off by one). E.g. if all registers in that block should
be synced only one is synced, and if only one should be synced all (but one) are
synced. To calculate the number of registers that need to be synced we need to
subtract the number of the first register in the block from the max register
number and add one. This patch updates the code accordingly.

The issue was introduced in commit ac8d91c ("regmap: Supply ranges to the sync
operations").

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Cc: stable@vger.kernel.org
2013-03-13 19:07:19 +00:00
Dimitris Papastamos
a42277c739 regmap: rbtree Expose total memory consumption in the rbtree debugfs entry
Provide a feel of how much overhead the rbtree cache adds to
the game.

[Slightly reworded output in debugfs -- broonie]

Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-03-13 11:13:48 +00:00
Dimitris Papastamos
c6432ea9cc 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
2013-03-12 18:25:10 +00:00
Linus Torvalds
0c8150d2c4 regmap: PM fix for v3.9
A simple fix to stop us leaking a runtime PM reference in the case where
 we fail to enable a device.
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.12 (GNU/Linux)
 
 iQIcBAABAgAGBQJRNVQ5AAoJELSic+t+oim93WQQAJIToyJgnuoZfebD3vgT1Tey
 YVGM5YY0pL+Ec5Fg91vu/ypFaY888J3UlRtQGxEM13grPunR4y/OflRYAXXTnspW
 TcPbcWpkEv464iTQra2GY9Z4gqL9c6fKKBSFwrj74wRb+Jq0BQhrdmbw6U6pMnDS
 iAxngfYEdlIULy8gyGnAszJFrQWjYh4U4e7wnUlsOJoZbc7JpW/6ITslwG9PWwK7
 h+o7ekjn2anyjAqBStlnSOzQ12kcaam+cDh8Fa8TUmg3HTmFmuCytGA8+XwCVBSQ
 ndWIhL1bqeyk7MdS84HjatNRAfPtpSZ9ouxKvLHm/tgALTNt/7CIsXeCm+2OoCQU
 7uFJ01WnAstQ58ggEndgjvhr4wGRIp9VZXyVjm8tqH2CLT/UE7H+nnOAcABcd/cn
 jZ+t8DQHU2ST1Rvs4Mohax8K6XcOTEQLp/kuhPEUXyqsv73VqIsjloPtqcLbUQdA
 RYjMMsSFVFqlPQEOBTDNhGVjrfI4/tlkEh7Kw4VXSZXqf8cvTrAvbWYmMV/MJu2M
 pvncD872/jSatRbj5qocnUbOuEyQe3UmdBNtQrdWgseI1z0fyz41X/VvZlzgt+Ll
 se8iU4YojEviAUjPzKbKpFwr98r6pmMXtHqxDCYSv47YukiCC5QMenFukMGE5G9R
 2qSw38quY1edJiXnq42Y
 =D1mN
 -----END PGP SIGNATURE-----

Merge tag 'regmap-v3.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap

Pull regmap PM fix from Mark Brown:
 "A simple fix to stop us leaking a runtime PM reference in the case
  where we fail to enable a device."

* tag 'regmap-v3.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap:
  regmap: irq: call pm_runtime_put in pm_runtime_get_sync failed case
2013-03-07 13:06:21 -08:00
Dimitris Papastamos
065b4c5875 regmap: debugfs: Add a registers `range' file
This file lists the register ranges in the register map.  The condition
to split the range is based on whether the block is readable or not.

Ensure that we lock the `debugfs_off_cache' list whenever we access
and modify the list.  There is a possible race otherwise between the
read() operations of the `registers' file and the `range' file.

Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-03-04 10:33:03 +08:00
Dimitris Papastamos
480738de0e regmap: debugfs: Simplify calculation of `c->max_reg'
We don't need to use any of the file position information
to calculate the base and max register of each block.  Just
use the counter directly.

Set `i = base' at the top to avoid GCC flow analysis bugs.  The
value of `i' can never be undefined or 0 in the if (c) { ... }.

Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-03-04 10:33:02 +08:00
Mark Brown
eb4cb76ff0 regmap: cache: Store caches in native register format where possible
This allows the cached data to be sent directly to the device when
we sync it.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-03-04 10:30:28 +08:00
Mark Brown
8a819ff8ab 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>
2013-03-04 10:30:27 +08:00
Mark Brown
325acab447 regmap: cache: Use regcache_get_value() to check if we updated
Factor things out a little.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-03-04 10:30:27 +08:00
Mark Brown
879082c9fe regmap: cache: Pass the map rather than the word size when updating values
It's more idiomatic to pass the map structure around and this means we
can use other bits of information from the map.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-03-04 10:30:27 +08:00
Mark Brown
66baf40757 regmap: rbtree: Don't bother checking for noop updates
If we're updating a value in place it's more work to read the value and
compare the value with what we're about to set than it is to just write
the value into the cache; there are no further operations after writing
in the code even though there's an early return here.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-03-04 10:30:27 +08:00
Mark Brown
fe7d4ccd1d 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>
2013-03-04 10:28:29 +08:00
Li Fei
283189d3be regmap: irq: call pm_runtime_put in pm_runtime_get_sync failed case
Even in failed case of pm_runtime_get_sync, the usage_count
is incremented. In order to keep the usage_count with correct
value and runtime power management to behave correctly, call
pm_runtime_put(_sync) in such case.

Signed-off-by Liu Chuansheng <chuansheng.liu@intel.com>
Signed-off-by: Li Fei <fei.li@intel.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-03-01 14:54:16 +08:00
Linus Torvalds
9043a2650c The sweeping change is to make add_taint() explicitly indicate whether to disable
lockdep, but it's a mechanical change.
 
 Cheers,
 Rusty.
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.11 (GNU/Linux)
 
 iQIcBAABAgAGBQJRJAcuAAoJENkgDmzRrbjxsw0P/3eXb+LddYnx0V0uHYdKpCUf
 4vdW7X0fX3Z+aUK69IWRL/6ahoO4TpaHYGHBDjEoivyQ0GDq14X7JNWsYYt3LdMf
 3wmDgRc2cn/mZOJbFeVpNV8ox5l/xc0CUvV+iQ8tMjfQItXMXgWUFZKMECsXKSO6
 eex3lrw9M2jAX2uL8LQPp9W8xtKu24nSZRC6tH5riE/8fCzi1cZPPAqfxP5c8Lee
 ZXtbCRSyAFENZLpKyMe1PC7HvtJyi5NDn9xwOQiXULZV/VOlvP94DGBLIKCM/6dn
 4QvZxpG0P0uOlpCgRAVLyh/z7g4XY4VF/fHopLCmEcqLsvgD+V2LQpQ9zWUalLPC
 Z+pUpz2vu0gIddPU1nR8R6oGpEdJ8O12aJle62p/RSXWZGx12qUQ+Tamu0tgKcv1
 AsiJfbUGNDYfxgU6sHsoQjl2f68LTVckCU1C1LqEbW/S104EIORtGx30CHM4LRiO
 32kDC5TtgYDBKQAIqJ4bL48ZMh+9W3uX40p7xzOI5khHQjvswUKa3jcxupU0C1uv
 lx8KXo7pn8WT33QGysWC782wJCgJuzSc2vRn+KQoqoynuHGM6agaEtR59gil3QWO
 rQEcxH63BBRDgHlg4FM9IkJwwsnC3PWKL8gbX0uAWXAPMbgapJkuuGZAwt0WDGVK
 +GszxsFkCjlW0mK0egTb
 =tiSY
 -----END PGP SIGNATURE-----

Merge tag 'modules-next-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux

Pull module update from Rusty Russell:
 "The sweeping change is to make add_taint() explicitly indicate whether
  to disable lockdep, but it's a mechanical change."

* tag 'modules-next-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux:
  MODSIGN: Add option to not sign modules during modules_install
  MODSIGN: Add -s <signature> option to sign-file
  MODSIGN: Specify the hash algorithm on sign-file command line
  MODSIGN: Simplify Makefile with a Kconfig helper
  module: clean up load_module a little more.
  modpost: Ignore ARC specific non-alloc sections
  module: constify within_module_*
  taint: add explicit flag to show whether lock dep is still OK.
  module: printk message when module signature fail taints kernel.
2013-02-25 15:41:43 -08:00
Mark Brown
a2b37efc4e Merge remote-tracking branch 'regmap/topic/no-bus' into regmap-next 2013-02-14 17:11:09 +00:00
Mark Brown
a31f68497e Merge remote-tracking branch 'regmap/topic/mmio' into regmap-next 2013-02-14 17:11:08 +00:00
Mark Brown
5dea215028 Merge remote-tracking branch 'regmap/topic/irq' into regmap-next 2013-02-14 17:11:08 +00:00
Mark Brown
7798b582d3 Merge remote-tracking branch 'regmap/topic/flat' into regmap-next 2013-02-14 17:11:07 +00:00
Mark Brown
43280026c8 Merge remote-tracking branch 'regmap/topic/debugfs' into regmap-next 2013-02-14 17:11:06 +00:00
Mark Brown
3689cf7fd1 Merge remote-tracking branch 'regmap/topic/async' into regmap-next 2013-02-14 17:11:03 +00:00
Mark Brown
3bef9059dd Merge remote-tracking branch 'regmap/topic/24bit' into regmap-next 2013-02-14 17:11:00 +00:00
Philipp Zabel
878ec67b3a regmap: mmio: add register clock support
Some mmio devices have a dedicated interface clock that needs
to be enabled to access their registers. This patch optionally
enables a clock before accessing registers in the regmap_bus
callbacks.

I added (devm_)regmap_init_mmio_clk variants of the init
functions that have an added clk_id string parameter. This
is passed to clk_get to request the clock from the clk
framework.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-02-14 16:40:28 +00:00
Dimitris Papastamos
4dd7c5531d regmap: debugfs: Factor out debugfs_tot_len calc into a function
In preparation to support the regmap debugfs ranges functionality
factor this code out to a separate function.  We'll need to ensure
that the value has been correctly calculated from two separate places
in the code.

Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-02-11 11:25:33 +00:00
Dimitris Papastamos
cf57d6071f regmap: debugfs: Optimize seeking within blocks of registers
Optimize this so that we can better guess where to start scanning
from.  We know the length of the register field format, therefore
given the file pointer position align to the nearest register
field and scan from there onwards.  We round down in this calculation
and we let the rest of the code figure out where to start scanning
from.

Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-02-11 11:25:33 +00:00
Dimitris Papastamos
c2c1ee6601 regmap: debugfs: Add a `max_reg' member in struct regmap_debugfs_off_cache
We are keeping track of the maximum register as well, this will make
things easier for us in sharing this code with the code implementing
the register ranges functionality.  It also simplifies a bit the
calculations when looking for the relevant block:offset from within
the cache.

Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-02-11 11:25:32 +00:00
Dimitris Papastamos
f3eb83994c regmap: debugfs: Fix reading in register field units
At the moment, if the length of the register field format is
N bytes, we can only get anything meaningful back to userspace
by providing a buffer that is N + 2 bytes large.  Fix this
so we that we only need to provide a buffer of N bytes.

Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-02-08 11:31:34 +00:00
Mark Brown
95601d65a1 regmap: spi: Handle allocation failures gracefully
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-02-05 14:14:32 +00:00
Mark Brown
f88948eff9 regmap: Export regmap_async_complete()
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-02-05 13:53:26 +00:00
Axel Lin
f804fb562b 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>
2013-02-04 10:22:27 +00:00
Stephen Warren
30b2a55374 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>
2013-02-04 10:21:51 +00:00
Mark Brown
e0356dfe98 regmap: spi: Support asynchronous I/O for SPI
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-01-29 12:16:21 +08:00
Mark Brown
0d509f2b11 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>
2013-01-29 12:14:52 +08:00
Andrey Smirnov
d2a5884a64 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>
2013-01-29 11:42:49 +08:00
Russell King
a3471469bc regmap: regmap: avoid spurious warning in regmap_read_debugfs
Gcc warns about the case where regmap_read_debugfs tries to walk an
empty map->debugfs_off_cache list, which would results in uninitialized
variable getting returned, if we hadn't checked the same condition
just before that.

After an originally suggested inferior patch from Arnd Bergmann,
this is the solution that Russell King came up with, sidestepping
the problem by merging the error case for an empty list with the
normal path.

Without this patch, building mxs_defconfig results in:

drivers/base/regmap/regmap-debugfs.c: In function 'regmap_read_debugfs':
drivers/base/regmap/regmap-debugfs.c:147:9: : warning: 'ret' may be used uninitialized in this function [-Wmaybe-uninitialized]

Reported-by: Vincent Stehle <v-stehle@ti.com>
Cc: Mark Brown <broonie@opensource.wolfsonmicro.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-01-27 10:45:10 +08:00
Mark Brown
af4ca6a808 Merge remote-tracking branch 'regmap/fix/debugfs' into tmp 2013-01-24 19:04:16 +08:00
Nestor Ovroy
31b35e9edd 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>
2013-01-22 16:24:12 +08:00
Rusty Russell
373d4d0997 taint: add explicit flag to show whether lock dep is still OK.
Fix up all callers as they were before, with make one change: an
unsigned module taints the kernel, but doesn't turn off lockdep.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2013-01-21 17:17:57 +10:30
Mark Brown
f32ca3db7f regmap: debugfs: Fix seeking from the cache
We don't want to bomb out early if we failed to get the cache any more,
just soldier on instead and we won't get confused and always return the
first block.

Reported-by: Philipp Zabel <p.zabel@pengutronix.de
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-01-17 00:33:36 +09:00
Andrey Smirnov
07c320dc31 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>
2013-01-14 08:04:05 +09:00
Andrey Smirnov
ad278406b3 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>
2013-01-14 08:04:01 +09:00
Lars-Peter Clausen
237019e7e3 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>
2013-01-12 00:07:26 +00:00
Mark Brown
e8d6539c8a regmap: debugfs: Make sure we store the last entry in the offset cache
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-01-08 20:52:51 +00:00
Mark Brown
5bd9f4bb34 regmap: debugfs: Ensure a correct return value for empty caches
This should never happen in the real world.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-01-08 20:52:49 +00:00
Mark Brown
95f971c745 regmap: debugfs: Discard the cache if we fail to allocate an entry
Rather than trying to soldier on with a partially allocated cache just
throw the cache away and pretend we don't have one in case we can get a
full cache next time around.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-01-08 20:52:46 +00:00
Mark Brown
5a1d6d172b regmap: debugfs: Fix check for block start in cached seeks
Check for the block we were asked to start from, not the position we're
in.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-01-08 20:52:45 +00:00
Mark Brown
120f805181 regmap: debugfs: Fix attempts to read nonexistant register blocks
Return the start of the last block we tried to read rather than a position,
and also make sure we update the byte position while we're at it.  Without
this reads that go into nonexistant areas get confused.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-01-08 20:52:45 +00:00
Mark Brown
9442490a02 regmap: irq: Support wake IRQ mask inversion
Support devices which have an enable rather than mask register for wake
sources.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-01-04 20:53:44 +00:00
Mark Brown
33be49324f regmap: irq: Fix sync of wake statuses to hardware
This wasn't implemented but happened to work on test systems due to lack
of wake mask inversion support.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-01-04 20:53:43 +00:00
Mark Brown
a7440eaa90 regmap: irq: Use a bulk read for interrupt status where possible
If the interrupt status registers are a single block of registers and the
chip supports bulk reads then do a single bulk read rather than pay the
extra I/O cost. This restores the original behaviour which was lost when
support for register striding was added.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-01-04 20:53:42 +00:00
Mark Brown
bbae92ca49 regmap: irq: Factor register read out of the IRQ parsing loop
In preparation for adding back support for block reads.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-01-03 14:30:33 +00:00
Mark Brown
2ac902ce17 regmap: flat: Add flat cache type
While for I2C and SPI devices the overhead of using rbtree for devices with
only one block of registers is negligible the same isn't always going to
be true for MMIO devices where the I/O costs are very much lower. Cater
for these devices by adding a simple flat array type for them where the
lookups are simple array accesses, taking us right back to the original
ASoC cache implementation.

Thanks to Magnus Damm for the discussion which prompted this.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2013-01-02 10:58:53 +00:00
Laxman Dewangan
55ac85e942 regmap: irq: enable wake support by default
regmap-irq framework is used vastly by mfd drivers and some of
devices like TPS65910, TPS80036 do not support the wake base
register to enable wake.

Currently wake in regmap-irq only supported if client driver
passes the wake base register.

As the regmap-irq is mostly used by mfd devices and it is require
to have wake support from these devices in most of use cases,
enabling wake support by default in regmap-irq.

Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-12-24 16:18:26 +00:00
Mark Brown
7c8a299430 Merge remote-tracking branch 'regmap/topic/type' into regmap-next 2012-12-11 12:39:49 +09:00
Mark Brown
8e24a6e696 Merge remote-tracking branch 'regmap/topic/table' into regmap-next 2012-12-11 12:39:32 +09:00
Mark Brown
db760fbecd Merge remote-tracking branch 'regmap/topic/lock' into regmap-next 2012-12-11 12:39:30 +09:00
Mark Brown
4d348e6e0a Merge remote-tracking branch 'regmap/topic/domain' into regmap-next 2012-12-11 12:39:29 +09:00
Mark Brown
bcf86687d6 Merge remote-tracking branch 'regmap/topic/debugfs' into regmap-next 2012-12-11 12:39:20 +09:00
Mark Brown
5166b7c006 regmap: debugfs: Cache offsets of valid regions for dump
Avoid doing a linear scan of the entire register map for each read() of
the debugfs register dump by recording the offsets where valid registers
exist when we first read the registers file. This assumes the set of
valid registers never changes, if this is not the case invalidation of
the cache will be required.

This could be further improved for large blocks of contiguous registers
by calculating the register we will read from within the block - currently
we do a linear scan of the block. An rbtree may also be worthwhile.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-12-11 01:29:47 +09:00
Mark Brown
afab2f7b21 regmap: debugfs: Factor out initial seek
In preparation for doing things a bit more quickly than a linear scan
factor out the initial seek from the debugfs register dump.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-12-11 01:29:47 +09:00
Mark Brown
db04328c16 regmap: debugfs: Avoid overflows for very small reads
If count is less than the size of a register then we may hit integer
wraparound when trying to move backwards to check if we're still in
the buffer. Instead move the position forwards to check if it's still
in the buffer, we are unlikely to be able to allocate a buffer
sufficiently big to overflow here.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Cc: stable@vger.kernel.org
2012-12-11 01:29:39 +09:00
Mark Brown
cbc1938bad regmap: Cache register and value sizes for debugfs
No point in calculating them every time.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-12-06 15:10:21 +09:00
Davide Ciminaghi
76aad392f7 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>
2012-11-21 11:10:31 +09:00
Mark Brown
3afa24f7ad Merge branch 'topic/lock' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap into regmap-table 2012-11-21 11:09:46 +09:00
Mark Brown
869e4a5f58 Merge branches 'topic/core' and 'topic/range' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap into regmap-table 2012-11-21 11:08:31 +09:00
Mark Brown
6d04b8ac57 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>
2012-10-30 13:37:26 +00:00
Fabio Estevam
1a61cfe344 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>
2012-10-25 18:55:11 +01:00
Dong Aisheng
5784ee4dcb regmap: select REGMAP if REGMAP_MMIO and REGMAP_IRQ enabled
The regmap_mmio and regmap_irq depend on regmap core, if not select,
we may not compile regmap core and meet compiling errors as follows
if REGMAP_MMIO is selected by client drivers:
drivers/mfd/syscon.c:94:15: error: variable 'syscon_regmap_config' has initializer but incomplete type
drivers/mfd/syscon.c:95:2: error: unknown field 'reg_bits' specified in initializer
drivers/mfd/syscon.c:95:2: warning: excess elements in struct initializer [enabled by default]
drivers/mfd/syscon.c:95:2: warning: (near initialization for 'syscon_regmap_config') [enabled by default]
drivers/mfd/syscon.c:96:2: error: unknown field 'val_bits' specified in initializer
drivers/mfd/syscon.c:96:2: warning: excess elements in struct initializer [enabled by default]
drivers/mfd/syscon.c:96:2: warning: (near initialization for 'syscon_regmap_config') [enabled by default]
drivers/mfd/syscon.c:97:2: error: unknown field 'reg_stride' specified in initializer
drivers/mfd/syscon.c:97:2: warning: excess elements in struct initializer [enabled by default]
drivers/mfd/syscon.c:97:2: warning: (near initialization for 'syscon_regmap_config') [enabled by default]
drivers/mfd/syscon.c: In function 'syscon_probe':
drivers/mfd/syscon.c:124:2: error: invalid use of undefined type 'struct regmap_config'
drivers/mfd/syscon.c:125:2: error: implicit declaration of function 'devm_regmap_init_mmio' [-Werror=implicit-function-declaration]
drivers/mfd/syscon.c:125:17: warning: assignment makes pointer from integer without a cast [enabled by default]
cc1: some warnings being treated as errors

drivers/mfd/Kconfig:
config MFD_SYSCON
        bool "System Controller Register R/W Based on Regmap"
	depends on OF
	select REGMAP_MMIO
	help
	  Select this option to enable accessing system control registers
	    via regmap.

Signed-off-by: Dong Aisheng <dong.aisheng@linaro.org>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-10-17 22:09:35 +09:00
Davide Ciminaghi
0d4529c534 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>
2012-10-17 16:52:02 +09:00
Paul Bolle
a8f28cfad8 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>
2012-10-15 10:03:19 +09:00
Mark Brown
8a2ceac661 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>
2012-10-15 10:00:00 +09:00
Mark Brown
0ff3e62ff1 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>
2012-10-15 10:00:00 +09:00
Mark Brown
98bc7dfd76 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>
2012-10-15 10:00:00 +09:00
Mark Brown
4b020b3f9b 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>
2012-10-15 09:59:59 +09:00
Mark Brown
bd9cc12f4a regmap: Factor out debugfs register read
This will allow the use of the same code for reading register ranges.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-10-15 09:59:59 +09:00
Mark Brown
d058bb4961 regmap: Allow ranges to be named
For more useful diagnostics.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-10-15 09:59:59 +09:00
Mark Brown
061adc064a 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>
2012-10-15 09:59:59 +09:00
Mark Brown
e3549cd013 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>
2012-10-15 09:59:59 +09:00
Mark Brown
90f790d2dc regmap: irq: Allow users to retrieve the irq_domain
This is useful for integration with other subsystems, especially MFD,
and provides an alternative API for users that request their own IRQs.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-10-15 09:49:23 +09:00
Mark Brown
613dac31a6 Merge remote-tracking branches 'regmap/topic/cache' and 'regmap/topic/irq' into regmap-next 2012-09-22 12:02:05 -04:00
Yunfan Zhang
8138073951 regmap: no need primary handler for nested irq
The primary handler will NOT be called if the interrupt nests into
another interrupt thread. Remove it to avoid confusing.

Signed-off-by: Yunfan Zhang <yfzhang@marvell.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-09-09 11:05:45 +08:00
Xiaofan Tian
36ac914ba2 regmap: irq: Add mask invert flag for enable register
Currently, regmap will write 1 to mask_base to mask
an interrupt and write 0 to unmask it.

But some chips do not have an interrupt mask register,
and only have interrupt enable register.
Then we should write 0 to disable interrupt and 1 to enable.

So add an mask_invert flag to handle this.
If it is not set, behavior is same as previous.
If set it to 1, the mask value will be inverted
before written to mask_base

Signed-off-by: Xiaofan Tian <tianxf@marvell.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-08-30 11:13:41 -07:00
Mark Brown
0c00c50b41 regmap: irq: Enable devices for runtime PM while handling interrupts
Some devices need to have a runtime PM reference while handling interrupts
to ensure that the register I/O is available. Support this with a flag in
the chip.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-08-07 20:29:45 +01:00
Stephen Warren
40052ca0c2 regmap: irq: initialize all irqs to wake disabled
The kerneldoc for irq_set_irq_wake() says:

    Enable/disable power management wakeup mode, which is
    disabled by default.

regmap_irq_set_wake() clears bits to enable wake for an interrupt,
and sets bits to disable wake. Hence, we should set all bits in
wake_buf initially, to mirror the expected disabled state.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-08-04 12:13:54 +01:00
Stephen Warren
685879f4b2 regmap: set MASK_ON_SUSPEND/SKIP_SET_WAKE if no wake_base
If a regmap-irq chip has no wake base:

* There's no point calling .irq_set_wake, hence IRQCHIP_SKIP_SET_WAKE.

* If some IRQs in the chip are enabled for wake and some aren't, we
  should mask those interrupts that are not wake enabled, so that if
  they occur during suspend, the system is not awoken. Hence,
  IRQCHIP_MASK_ON_SUSPEND.

Note that IRQCHIP_MASK_ON_SUSPEND is handled by check_wakeup_irqs(),
which always iterates over every single interrupt in the system,
irrespective of whether an interrupt is a child of a controller whose
output interrupt has no wake-enabled inputs and hence is presumably
masked itself. Hence this change might cause interrupt unnecessary
masking operations and associated register I/O.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-08-04 12:13:53 +01:00
Stephen Warren
ca142750f8 regmap: name irq_chip based on regmap_irq_chip's name
This is intended to give each irq_chip a useful name, rather than hard-
coding them all as "regmap".

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-08-04 12:13:53 +01:00
Stephen Warren
7ac140ec42 regmap: store irq_chip inside regmap_irq_chip_data
This will allow later patches to adjust portions of the irq_chip
individually for each regmap_irq_chip that is created.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-08-04 12:13:53 +01:00
Mark Brown
0eb46ad0c8 regmap: irq: Only update mask bits when doing initial mask
Don't write the full register, it's possible there's bits other than the
masks in the same register which we shouldn't be changing.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Tested-by: Stephen Warren <swarren@wwwdotorg.org>
2012-08-04 12:13:53 +01:00
Stephen Warren
16032624f5 regmap: fix some error messages to take account of irq_reg_stride
A number of places in the code were printing error messages that included
the address of a register, but were not calculating the register address
in the same way as the access to the register. Use a temporary to solve
this.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-08-04 12:13:53 +01:00
Dimitris Papastamos
4d879514e7 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>
2012-08-04 11:07:57 +01:00
Mark Brown
38e23194e1 Merge branches 'regmap-core', 'regmap-irq' and 'regmap-page' into regmap-next
Conflicts (trivial context stuff):
	drivers/base/regmap/regmap.c
	include/linux/regmap.h
2012-07-22 19:26:07 +01:00
Dimitris Papastamos
463351194d regmap: Fix incorrect arguments to kzalloc() call
Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-07-18 22:13:53 +01:00
Mark Brown
1044c180de 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>
2012-07-06 14:16:16 +01:00
Krystian Garbaciak
632a5b01db 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>
2012-06-19 10:42:56 +01:00
Krystian Garbaciak
6863ca6227 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>
2012-06-17 21:34:18 +01:00
Krystian Garbaciak
fc3ebd788e 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>
2012-06-17 21:30:39 +01:00
Axel Lin
e8790ab4ce regmap: mmio: Staticize regmap_mmio_gen_context()
regmap_mmio_gen_context() is only used in regmap-mmio.c. Thus make it static.

Signed-off-by: Axel Lin <axel.lin@gmail.com>
Acked-by: Stephen Warren <swarren@wwwdotorg.org>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-06-13 19:15:11 +01:00
Mark Brown
752a6a5f84 regmap: Export regmap_reinit_cache()
It's supposed to be there for drivers.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-06-08 05:57:21 +08:00
Mark Brown
a43fd50dc9 regmap: Implement support for wake IRQs
Allow chips to provide a bank of registers for controlling the wake state
in a similar fashion to the masks and propagate the wake count to the
parent interrupt controller.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-06-05 14:38:20 +01:00
Mark Brown
bfd6185dde regmap: Don't try to map non-existant IRQs
If the driver supplied an empty entry in the array of IRQs then return
an error rather than trying to do the mapping. This is intended for use
with handling chip variants and similar situations.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-06-05 14:38:20 +01:00
Mark Brown
b026ddbbd2 regmap: Constify regmap_irq_chip
We should never be modifying it and it lets drivers declare it const.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-06-03 13:16:51 +01:00
Fabio Estevam
5494a98f45 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>
2012-06-03 13:14:01 +01:00
Stephen Warren
bfaa25f334 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>
2012-06-03 13:13:38 +01:00
Stephen Warren
6a55244e89 regmap: mmio: request native endian formatting
This will avoid the regmap core converting all addresses and values into
big endian, only for the mmio bus driver to have to convert them back to
native endian.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-06-03 13:11:43 +01:00
Stephen Warren
141eba2e00 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>
2012-06-03 13:11:43 +01:00