diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2011-05-11 13:59:58 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2011-07-23 02:56:03 -0400 |
commit | b83a313bf2520183641cf485d68cc273323597d2 (patch) | |
tree | e478834902bba3d4c774804d55a88c9b50bca2c0 /include/linux/regmap.h | |
parent | 620917de59eeb934b9f8cf35cc2d95c1ac8ed0fc (diff) |
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>
Diffstat (limited to 'include/linux/regmap.h')
-rw-r--r-- | include/linux/regmap.h | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/include/linux/regmap.h b/include/linux/regmap.h new file mode 100644 index 000000000000..a26c1d001401 --- /dev/null +++ b/include/linux/regmap.h | |||
@@ -0,0 +1,74 @@ | |||
1 | #ifndef __LINUX_REGMAP_H | ||
2 | #define __LINUX_REGMAP_H | ||
3 | |||
4 | /* | ||
5 | * Register map access API | ||
6 | * | ||
7 | * Copyright 2011 Wolfson Microelectronics plc | ||
8 | * | ||
9 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU General Public License version 2 as | ||
13 | * published by the Free Software Foundation. | ||
14 | */ | ||
15 | |||
16 | #include <linux/device.h> | ||
17 | #include <linux/list.h> | ||
18 | #include <linux/module.h> | ||
19 | |||
20 | struct regmap_config { | ||
21 | int reg_bits; | ||
22 | int val_bits; | ||
23 | }; | ||
24 | |||
25 | typedef int (*regmap_hw_write)(struct device *dev, const void *data, | ||
26 | size_t count); | ||
27 | typedef int (*regmap_hw_gather_write)(struct device *dev, | ||
28 | const void *reg, size_t reg_len, | ||
29 | const void *val, size_t val_len); | ||
30 | typedef int (*regmap_hw_read)(struct device *dev, | ||
31 | const void *reg_buf, size_t reg_size, | ||
32 | void *val_buf, size_t val_size); | ||
33 | |||
34 | /** | ||
35 | * Description of a hardware bus for the register map infrastructure. | ||
36 | * | ||
37 | * @list: Internal use. | ||
38 | * @type: Bus type, used to identify bus to be used for a device. | ||
39 | * @write: Write operation. | ||
40 | * @gather_write: Write operation with split register/value, return -ENOTSUPP | ||
41 | * if not implemented on a given device. | ||
42 | * @read: Read operation. Data is returned in the buffer used to transmit | ||
43 | * data. | ||
44 | * @owner: Module with the bus implementation, used to pin the implementation | ||
45 | * in memory. | ||
46 | * @read_flag_mask: Mask to be set in the top byte of the register when doing | ||
47 | * a read. | ||
48 | */ | ||
49 | struct regmap_bus { | ||
50 | struct list_head list; | ||
51 | struct bus_type *type; | ||
52 | regmap_hw_write write; | ||
53 | regmap_hw_gather_write gather_write; | ||
54 | regmap_hw_read read; | ||
55 | struct module *owner; | ||
56 | u8 read_flag_mask; | ||
57 | }; | ||
58 | |||
59 | struct regmap *regmap_init(struct device *dev, | ||
60 | const struct regmap_bus *bus, | ||
61 | const struct regmap_config *config); | ||
62 | void regmap_exit(struct regmap *map); | ||
63 | int regmap_write(struct regmap *map, unsigned int reg, unsigned int val); | ||
64 | int regmap_raw_write(struct regmap *map, unsigned int reg, | ||
65 | const void *val, size_t val_len); | ||
66 | int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val); | ||
67 | int regmap_raw_read(struct regmap *map, unsigned int reg, | ||
68 | void *val, size_t val_len); | ||
69 | int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val, | ||
70 | size_t val_count); | ||
71 | int regmap_update_bits(struct regmap *map, unsigned int reg, | ||
72 | unsigned int mask, unsigned int val); | ||
73 | |||
74 | #endif | ||