Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Mark Brown | b83a313 | 2011-05-11 19:59:58 +0200 | [diff] [blame] | 2 | #ifndef __LINUX_REGMAP_H |
| 3 | #define __LINUX_REGMAP_H |
| 4 | |
| 5 | /* |
| 6 | * Register map access API |
| 7 | * |
| 8 | * Copyright 2011 Wolfson Microelectronics plc |
| 9 | * |
| 10 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> |
Mark Brown | b83a313 | 2011-05-11 19:59:58 +0200 | [diff] [blame] | 11 | */ |
| 12 | |
Mark Brown | b83a313 | 2011-05-11 19:59:58 +0200 | [diff] [blame] | 13 | #include <linux/list.h> |
Krystian Garbaciak | 6863ca6 | 2012-06-15 11:23:56 +0100 | [diff] [blame] | 14 | #include <linux/rbtree.h> |
Sean Wang | f15cd6d | 2018-04-23 14:42:44 +0800 | [diff] [blame] | 15 | #include <linux/ktime.h> |
Masahiro Yamada | adf08d4 | 2016-10-13 19:07:54 +0900 | [diff] [blame] | 16 | #include <linux/delay.h> |
Mateusz Krawczuk | 49ccc14 | 2013-08-06 18:34:40 +0200 | [diff] [blame] | 17 | #include <linux/err.h> |
Kevin Hilman | 3f0fa9a | 2013-08-14 16:05:02 -0700 | [diff] [blame] | 18 | #include <linux/bug.h> |
Nicolas Boichat | 3cfe7a7 | 2015-07-08 14:30:18 +0800 | [diff] [blame] | 19 | #include <linux/lockdep.h> |
Mark Brown | b83a313 | 2011-05-11 19:59:58 +0200 | [diff] [blame] | 20 | |
Paul Gortmaker | de47725 | 2011-05-26 13:46:22 -0400 | [diff] [blame] | 21 | struct module; |
Maxime Ripard | 3189566 | 2018-02-21 10:20:25 +0100 | [diff] [blame] | 22 | struct clk; |
Paul Gortmaker | 313162d | 2012-01-30 11:46:54 -0500 | [diff] [blame] | 23 | struct device; |
Mark Brown | 9943fa3 | 2011-06-20 19:02:29 +0100 | [diff] [blame] | 24 | struct i2c_client; |
Mark Brown | 90f790d | 2012-08-20 21:45:05 +0100 | [diff] [blame] | 25 | struct irq_domain; |
Srinivas Kandagatla | 7d6f7fb | 2017-12-11 23:43:02 +0000 | [diff] [blame] | 26 | struct slim_device; |
Mark Brown | a676f08 | 2011-05-12 11:42:10 +0200 | [diff] [blame] | 27 | struct spi_device; |
Josh Cartwright | a01779f | 2013-10-28 13:12:35 -0500 | [diff] [blame] | 28 | struct spmi_device; |
Mark Brown | b83d2ff | 2012-03-11 11:49:17 +0000 | [diff] [blame] | 29 | struct regmap; |
Krystian Garbaciak | 6863ca6 | 2012-06-15 11:23:56 +0100 | [diff] [blame] | 30 | struct regmap_range_cfg; |
Srinivas Kandagatla | 6725228 | 2013-06-11 13:18:15 +0100 | [diff] [blame] | 31 | struct regmap_field; |
Mark Brown | 2285322 | 2014-11-18 19:45:51 +0100 | [diff] [blame] | 32 | struct snd_ac97; |
Vinod Koul | 7c22ce6 | 2018-01-08 15:50:59 +0530 | [diff] [blame] | 33 | struct sdw_slave; |
Mark Brown | 9943fa3 | 2011-06-20 19:02:29 +0100 | [diff] [blame] | 34 | |
Dimitris Papastamos | 9fabe24 | 2011-09-19 14:34:00 +0100 | [diff] [blame] | 35 | /* An enum of all the supported cache types */ |
| 36 | enum regcache_type { |
| 37 | REGCACHE_NONE, |
Dimitris Papastamos | 28644c80 | 2011-09-19 14:34:02 +0100 | [diff] [blame] | 38 | REGCACHE_RBTREE, |
Mark Brown | 2ac902c | 2012-12-19 14:51:55 +0000 | [diff] [blame] | 39 | REGCACHE_COMPRESSED, |
| 40 | REGCACHE_FLAT, |
Dimitris Papastamos | 9fabe24 | 2011-09-19 14:34:00 +0100 | [diff] [blame] | 41 | }; |
| 42 | |
Mark Brown | dd898b2 | 2011-07-20 22:28:58 +0100 | [diff] [blame] | 43 | /** |
Charles Keepax | 2cf8e2d | 2017-01-12 11:17:39 +0000 | [diff] [blame] | 44 | * struct reg_default - Default value for a register. |
Mark Brown | bd20eb5 | 2011-08-19 18:09:38 +0900 | [diff] [blame] | 45 | * |
| 46 | * @reg: Register address. |
| 47 | * @def: Register default value. |
Charles Keepax | 2cf8e2d | 2017-01-12 11:17:39 +0000 | [diff] [blame] | 48 | * |
| 49 | * We use an array of structs rather than a simple array as many modern devices |
| 50 | * have very sparse register maps. |
Mark Brown | bd20eb5 | 2011-08-19 18:09:38 +0900 | [diff] [blame] | 51 | */ |
| 52 | struct reg_default { |
| 53 | unsigned int reg; |
| 54 | unsigned int def; |
| 55 | }; |
| 56 | |
Nariman Poushin | 8019ff6 | 2015-07-16 16:36:21 +0100 | [diff] [blame] | 57 | /** |
Charles Keepax | 2cf8e2d | 2017-01-12 11:17:39 +0000 | [diff] [blame] | 58 | * struct reg_sequence - An individual write from a sequence of writes. |
Nariman Poushin | 8019ff6 | 2015-07-16 16:36:21 +0100 | [diff] [blame] | 59 | * |
| 60 | * @reg: Register address. |
| 61 | * @def: Register value. |
Nariman Poushin | 2de9d60 | 2015-07-16 16:36:22 +0100 | [diff] [blame] | 62 | * @delay_us: Delay to be applied after the register write in microseconds |
Charles Keepax | 2cf8e2d | 2017-01-12 11:17:39 +0000 | [diff] [blame] | 63 | * |
| 64 | * Register/value pairs for sequences of writes with an optional delay in |
| 65 | * microseconds to be applied after each write. |
Nariman Poushin | 8019ff6 | 2015-07-16 16:36:21 +0100 | [diff] [blame] | 66 | */ |
| 67 | struct reg_sequence { |
| 68 | unsigned int reg; |
| 69 | unsigned int def; |
Nariman Poushin | 2de9d60 | 2015-07-16 16:36:22 +0100 | [diff] [blame] | 70 | unsigned int delay_us; |
Nariman Poushin | 8019ff6 | 2015-07-16 16:36:21 +0100 | [diff] [blame] | 71 | }; |
| 72 | |
Kuninori Morimoto | ca7a944 | 2016-02-15 05:22:42 +0000 | [diff] [blame] | 73 | #define regmap_update_bits(map, reg, mask, val) \ |
| 74 | regmap_update_bits_base(map, reg, mask, val, NULL, false, false) |
Kuninori Morimoto | 30ed9cb | 2016-02-15 05:23:01 +0000 | [diff] [blame] | 75 | #define regmap_update_bits_async(map, reg, mask, val)\ |
| 76 | regmap_update_bits_base(map, reg, mask, val, NULL, true, false) |
Kuninori Morimoto | 98c2dc4 | 2016-02-15 05:23:17 +0000 | [diff] [blame] | 77 | #define regmap_update_bits_check(map, reg, mask, val, change)\ |
| 78 | regmap_update_bits_base(map, reg, mask, val, change, false, false) |
Kuninori Morimoto | 89d8d4b | 2016-02-15 05:23:37 +0000 | [diff] [blame] | 79 | #define regmap_update_bits_check_async(map, reg, mask, val, change)\ |
| 80 | regmap_update_bits_base(map, reg, mask, val, change, true, false) |
Kuninori Morimoto | ca7a944 | 2016-02-15 05:22:42 +0000 | [diff] [blame] | 81 | |
Kuninori Morimoto | b821957 | 2016-03-03 00:48:30 +0000 | [diff] [blame] | 82 | #define regmap_write_bits(map, reg, mask, val) \ |
| 83 | regmap_update_bits_base(map, reg, mask, val, NULL, false, true) |
| 84 | |
Kuninori Morimoto | 3674124 | 2016-02-15 05:24:15 +0000 | [diff] [blame] | 85 | #define regmap_field_write(field, val) \ |
| 86 | regmap_field_update_bits_base(field, ~0, val, NULL, false, false) |
Kuninori Morimoto | 489061b | 2016-02-15 05:25:54 +0000 | [diff] [blame] | 87 | #define regmap_field_force_write(field, val) \ |
| 88 | regmap_field_update_bits_base(field, ~0, val, NULL, false, true) |
Kuninori Morimoto | 721ed64 | 2016-02-15 05:24:33 +0000 | [diff] [blame] | 89 | #define regmap_field_update_bits(field, mask, val)\ |
| 90 | regmap_field_update_bits_base(field, mask, val, NULL, false, false) |
Kuninori Morimoto | 489061b | 2016-02-15 05:25:54 +0000 | [diff] [blame] | 91 | #define regmap_field_force_update_bits(field, mask, val) \ |
| 92 | regmap_field_update_bits_base(field, mask, val, NULL, false, true) |
Kuninori Morimoto | 3674124 | 2016-02-15 05:24:15 +0000 | [diff] [blame] | 93 | |
Kuninori Morimoto | bbf2c46 | 2016-02-15 05:25:15 +0000 | [diff] [blame] | 94 | #define regmap_fields_write(field, id, val) \ |
| 95 | regmap_fields_update_bits_base(field, id, ~0, val, NULL, false, false) |
Kuninori Morimoto | e6ef243 | 2016-02-15 05:26:14 +0000 | [diff] [blame] | 96 | #define regmap_fields_force_write(field, id, val) \ |
| 97 | regmap_fields_update_bits_base(field, id, ~0, val, NULL, false, true) |
Kuninori Morimoto | 4813860 | 2016-02-15 05:25:32 +0000 | [diff] [blame] | 98 | #define regmap_fields_update_bits(field, id, mask, val)\ |
| 99 | regmap_fields_update_bits_base(field, id, mask, val, NULL, false, false) |
Kuninori Morimoto | e6ef243 | 2016-02-15 05:26:14 +0000 | [diff] [blame] | 100 | #define regmap_fields_force_update_bits(field, id, mask, val) \ |
| 101 | regmap_fields_update_bits_base(field, id, mask, val, NULL, false, true) |
Kuninori Morimoto | bbf2c46 | 2016-02-15 05:25:15 +0000 | [diff] [blame] | 102 | |
Philipp Zabel | 08188ba | 2016-07-06 16:19:41 +0200 | [diff] [blame] | 103 | /** |
| 104 | * regmap_read_poll_timeout - Poll until a condition is met or a timeout occurs |
Charles Keepax | 2cf8e2d | 2017-01-12 11:17:39 +0000 | [diff] [blame] | 105 | * |
Philipp Zabel | 08188ba | 2016-07-06 16:19:41 +0200 | [diff] [blame] | 106 | * @map: Regmap to read from |
| 107 | * @addr: Address to poll |
| 108 | * @val: Unsigned integer variable to read the value into |
| 109 | * @cond: Break condition (usually involving @val) |
| 110 | * @sleep_us: Maximum time to sleep between reads in us (0 |
| 111 | * tight-loops). Should be less than ~20ms since usleep_range |
| 112 | * is used (see Documentation/timers/timers-howto.txt). |
| 113 | * @timeout_us: Timeout in us, 0 means never timeout |
| 114 | * |
| 115 | * Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_read |
| 116 | * error return value in case of a error read. In the two former cases, |
| 117 | * the last read value at @addr is stored in @val. Must not be called |
| 118 | * from atomic context if sleep_us or timeout_us are used. |
| 119 | * |
| 120 | * This is modelled after the readx_poll_timeout macros in linux/iopoll.h. |
| 121 | */ |
| 122 | #define regmap_read_poll_timeout(map, addr, val, cond, sleep_us, timeout_us) \ |
| 123 | ({ \ |
Arnd Bergmann | 1b0c22e | 2017-10-13 14:12:45 +0200 | [diff] [blame] | 124 | u64 __timeout_us = (timeout_us); \ |
| 125 | unsigned long __sleep_us = (sleep_us); \ |
| 126 | ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \ |
Ramesh Shanmugasundaram | 780b135 | 2017-07-03 12:04:21 +0100 | [diff] [blame] | 127 | int __ret; \ |
Arnd Bergmann | 1b0c22e | 2017-10-13 14:12:45 +0200 | [diff] [blame] | 128 | might_sleep_if(__sleep_us); \ |
Philipp Zabel | 08188ba | 2016-07-06 16:19:41 +0200 | [diff] [blame] | 129 | for (;;) { \ |
Ramesh Shanmugasundaram | 780b135 | 2017-07-03 12:04:21 +0100 | [diff] [blame] | 130 | __ret = regmap_read((map), (addr), &(val)); \ |
| 131 | if (__ret) \ |
Philipp Zabel | 08188ba | 2016-07-06 16:19:41 +0200 | [diff] [blame] | 132 | break; \ |
| 133 | if (cond) \ |
| 134 | break; \ |
Arnd Bergmann | 1b0c22e | 2017-10-13 14:12:45 +0200 | [diff] [blame] | 135 | if ((__timeout_us) && \ |
Ramesh Shanmugasundaram | 780b135 | 2017-07-03 12:04:21 +0100 | [diff] [blame] | 136 | ktime_compare(ktime_get(), __timeout) > 0) { \ |
| 137 | __ret = regmap_read((map), (addr), &(val)); \ |
Philipp Zabel | 08188ba | 2016-07-06 16:19:41 +0200 | [diff] [blame] | 138 | break; \ |
| 139 | } \ |
Arnd Bergmann | 1b0c22e | 2017-10-13 14:12:45 +0200 | [diff] [blame] | 140 | if (__sleep_us) \ |
| 141 | usleep_range((__sleep_us >> 2) + 1, __sleep_us); \ |
Philipp Zabel | 08188ba | 2016-07-06 16:19:41 +0200 | [diff] [blame] | 142 | } \ |
Ramesh Shanmugasundaram | 780b135 | 2017-07-03 12:04:21 +0100 | [diff] [blame] | 143 | __ret ?: ((cond) ? 0 : -ETIMEDOUT); \ |
Philipp Zabel | 08188ba | 2016-07-06 16:19:41 +0200 | [diff] [blame] | 144 | }) |
| 145 | |
Chen-Yu Tsai | 667063a | 2017-09-29 16:23:01 +0800 | [diff] [blame] | 146 | /** |
| 147 | * regmap_field_read_poll_timeout - Poll until a condition is met or timeout |
| 148 | * |
| 149 | * @field: Regmap field to read from |
| 150 | * @val: Unsigned integer variable to read the value into |
| 151 | * @cond: Break condition (usually involving @val) |
| 152 | * @sleep_us: Maximum time to sleep between reads in us (0 |
| 153 | * tight-loops). Should be less than ~20ms since usleep_range |
| 154 | * is used (see Documentation/timers/timers-howto.txt). |
| 155 | * @timeout_us: Timeout in us, 0 means never timeout |
| 156 | * |
| 157 | * Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_field_read |
| 158 | * error return value in case of a error read. In the two former cases, |
| 159 | * the last read value at @addr is stored in @val. Must not be called |
| 160 | * from atomic context if sleep_us or timeout_us are used. |
| 161 | * |
| 162 | * This is modelled after the readx_poll_timeout macros in linux/iopoll.h. |
| 163 | */ |
| 164 | #define regmap_field_read_poll_timeout(field, val, cond, sleep_us, timeout_us) \ |
| 165 | ({ \ |
Arnd Bergmann | 1b0c22e | 2017-10-13 14:12:45 +0200 | [diff] [blame] | 166 | u64 __timeout_us = (timeout_us); \ |
| 167 | unsigned long __sleep_us = (sleep_us); \ |
| 168 | ktime_t timeout = ktime_add_us(ktime_get(), __timeout_us); \ |
Chen-Yu Tsai | 667063a | 2017-09-29 16:23:01 +0800 | [diff] [blame] | 169 | int pollret; \ |
Arnd Bergmann | 1b0c22e | 2017-10-13 14:12:45 +0200 | [diff] [blame] | 170 | might_sleep_if(__sleep_us); \ |
Chen-Yu Tsai | 667063a | 2017-09-29 16:23:01 +0800 | [diff] [blame] | 171 | for (;;) { \ |
| 172 | pollret = regmap_field_read((field), &(val)); \ |
| 173 | if (pollret) \ |
| 174 | break; \ |
| 175 | if (cond) \ |
| 176 | break; \ |
Arnd Bergmann | 1b0c22e | 2017-10-13 14:12:45 +0200 | [diff] [blame] | 177 | if (__timeout_us && ktime_compare(ktime_get(), timeout) > 0) { \ |
Chen-Yu Tsai | 667063a | 2017-09-29 16:23:01 +0800 | [diff] [blame] | 178 | pollret = regmap_field_read((field), &(val)); \ |
| 179 | break; \ |
| 180 | } \ |
Arnd Bergmann | 1b0c22e | 2017-10-13 14:12:45 +0200 | [diff] [blame] | 181 | if (__sleep_us) \ |
| 182 | usleep_range((__sleep_us >> 2) + 1, __sleep_us); \ |
Chen-Yu Tsai | 667063a | 2017-09-29 16:23:01 +0800 | [diff] [blame] | 183 | } \ |
| 184 | pollret ?: ((cond) ? 0 : -ETIMEDOUT); \ |
| 185 | }) |
| 186 | |
Mark Brown | b83d2ff | 2012-03-11 11:49:17 +0000 | [diff] [blame] | 187 | #ifdef CONFIG_REGMAP |
| 188 | |
Stephen Warren | 141eba2 | 2012-05-24 10:47:26 -0600 | [diff] [blame] | 189 | enum regmap_endian { |
| 190 | /* Unspecified -> 0 -> Backwards compatible default */ |
| 191 | REGMAP_ENDIAN_DEFAULT = 0, |
| 192 | REGMAP_ENDIAN_BIG, |
| 193 | REGMAP_ENDIAN_LITTLE, |
| 194 | REGMAP_ENDIAN_NATIVE, |
| 195 | }; |
| 196 | |
Davide Ciminaghi | 76aad39 | 2012-11-20 15:20:30 +0100 | [diff] [blame] | 197 | /** |
Charles Keepax | 2cf8e2d | 2017-01-12 11:17:39 +0000 | [diff] [blame] | 198 | * struct regmap_range - A register range, used for access related checks |
| 199 | * (readable/writeable/volatile/precious checks) |
Davide Ciminaghi | 76aad39 | 2012-11-20 15:20:30 +0100 | [diff] [blame] | 200 | * |
| 201 | * @range_min: address of first register |
| 202 | * @range_max: address of last register |
| 203 | */ |
| 204 | struct regmap_range { |
| 205 | unsigned int range_min; |
| 206 | unsigned int range_max; |
| 207 | }; |
| 208 | |
Laxman Dewangan | 6112fe6 | 2013-09-20 18:00:10 +0530 | [diff] [blame] | 209 | #define regmap_reg_range(low, high) { .range_min = low, .range_max = high, } |
| 210 | |
Charles Keepax | 2cf8e2d | 2017-01-12 11:17:39 +0000 | [diff] [blame] | 211 | /** |
| 212 | * struct regmap_access_table - A table of register ranges for access checks |
Davide Ciminaghi | 76aad39 | 2012-11-20 15:20:30 +0100 | [diff] [blame] | 213 | * |
| 214 | * @yes_ranges : pointer to an array of regmap ranges used as "yes ranges" |
| 215 | * @n_yes_ranges: size of the above array |
| 216 | * @no_ranges: pointer to an array of regmap ranges used as "no ranges" |
| 217 | * @n_no_ranges: size of the above array |
Charles Keepax | 2cf8e2d | 2017-01-12 11:17:39 +0000 | [diff] [blame] | 218 | * |
| 219 | * A table of ranges including some yes ranges and some no ranges. |
| 220 | * If a register belongs to a no_range, the corresponding check function |
| 221 | * will return false. If a register belongs to a yes range, the corresponding |
| 222 | * check function will return true. "no_ranges" are searched first. |
Davide Ciminaghi | 76aad39 | 2012-11-20 15:20:30 +0100 | [diff] [blame] | 223 | */ |
| 224 | struct regmap_access_table { |
| 225 | const struct regmap_range *yes_ranges; |
| 226 | unsigned int n_yes_ranges; |
| 227 | const struct regmap_range *no_ranges; |
| 228 | unsigned int n_no_ranges; |
| 229 | }; |
| 230 | |
Davide Ciminaghi | 0d4529c | 2012-10-16 15:56:59 +0200 | [diff] [blame] | 231 | typedef void (*regmap_lock)(void *); |
| 232 | typedef void (*regmap_unlock)(void *); |
| 233 | |
Mark Brown | bd20eb5 | 2011-08-19 18:09:38 +0900 | [diff] [blame] | 234 | /** |
Charles Keepax | 2cf8e2d | 2017-01-12 11:17:39 +0000 | [diff] [blame] | 235 | * struct regmap_config - Configuration for the register map of a device. |
Mark Brown | dd898b2 | 2011-07-20 22:28:58 +0100 | [diff] [blame] | 236 | * |
Stephen Warren | d3c242e | 2012-04-04 15:48:29 -0600 | [diff] [blame] | 237 | * @name: Optional name of the regmap. Useful when a device has multiple |
| 238 | * register regions. |
| 239 | * |
Mark Brown | dd898b2 | 2011-07-20 22:28:58 +0100 | [diff] [blame] | 240 | * @reg_bits: Number of bits in a register address, mandatory. |
Stephen Warren | f01ee60 | 2012-04-09 13:40:24 -0600 | [diff] [blame] | 241 | * @reg_stride: The register address stride. Valid register addresses are a |
| 242 | * multiple of this value. If set to 0, a value of 1 will be |
| 243 | * used. |
Mark Brown | 82159ba | 2012-01-18 10:52:25 +0000 | [diff] [blame] | 244 | * @pad_bits: Number of bits of padding between register and value. |
Mark Brown | dd898b2 | 2011-07-20 22:28:58 +0100 | [diff] [blame] | 245 | * @val_bits: Number of bits in a register value, mandatory. |
Mark Brown | 2e2ae66 | 2011-07-20 22:33:39 +0100 | [diff] [blame] | 246 | * |
Mark Brown | 3566cc9 | 2011-08-09 10:23:22 +0900 | [diff] [blame] | 247 | * @writeable_reg: Optional callback returning true if the register |
Davide Ciminaghi | 76aad39 | 2012-11-20 15:20:30 +0100 | [diff] [blame] | 248 | * can be written to. If this field is NULL but wr_table |
| 249 | * (see below) is not, the check is performed on such table |
| 250 | * (a register is writeable if it belongs to one of the ranges |
| 251 | * specified by wr_table). |
Mark Brown | 3566cc9 | 2011-08-09 10:23:22 +0900 | [diff] [blame] | 252 | * @readable_reg: Optional callback returning true if the register |
Davide Ciminaghi | 76aad39 | 2012-11-20 15:20:30 +0100 | [diff] [blame] | 253 | * can be read from. If this field is NULL but rd_table |
| 254 | * (see below) is not, the check is performed on such table |
| 255 | * (a register is readable if it belongs to one of the ranges |
| 256 | * specified by rd_table). |
Mark Brown | 3566cc9 | 2011-08-09 10:23:22 +0900 | [diff] [blame] | 257 | * @volatile_reg: Optional callback returning true if the register |
Davide Ciminaghi | 76aad39 | 2012-11-20 15:20:30 +0100 | [diff] [blame] | 258 | * value can't be cached. If this field is NULL but |
| 259 | * volatile_table (see below) is not, the check is performed on |
| 260 | * such table (a register is volatile if it belongs to one of |
| 261 | * the ranges specified by volatile_table). |
Laszlo Papp | bdc3964 | 2014-01-09 14:13:41 +0000 | [diff] [blame] | 262 | * @precious_reg: Optional callback returning true if the register |
Davide Ciminaghi | 76aad39 | 2012-11-20 15:20:30 +0100 | [diff] [blame] | 263 | * should not be read outside of a call from the driver |
Laszlo Papp | bdc3964 | 2014-01-09 14:13:41 +0000 | [diff] [blame] | 264 | * (e.g., a clear on read interrupt status register). If this |
Davide Ciminaghi | 76aad39 | 2012-11-20 15:20:30 +0100 | [diff] [blame] | 265 | * field is NULL but precious_table (see below) is not, the |
| 266 | * check is performed on such table (a register is precious if |
| 267 | * it belongs to one of the ranges specified by precious_table). |
Ben Whitten | cdf6b11 | 2018-10-19 10:33:50 +0100 | [diff] [blame] | 268 | * @writeable_noinc_reg: Optional callback returning true if the register |
| 269 | * supports multiple write operations without incrementing |
| 270 | * the register number. If this field is NULL but |
| 271 | * wr_noinc_table (see below) is not, the check is |
| 272 | * performed on such table (a register is no increment |
| 273 | * writeable if it belongs to one of the ranges specified |
| 274 | * by wr_noinc_table). |
Crestez Dan Leonard | 74fe7b5 | 2018-08-07 17:52:17 +0300 | [diff] [blame] | 275 | * @readable_noinc_reg: Optional callback returning true if the register |
| 276 | * supports multiple read operations without incrementing |
| 277 | * the register number. If this field is NULL but |
| 278 | * rd_noinc_table (see below) is not, the check is |
| 279 | * performed on such table (a register is no increment |
| 280 | * readable if it belongs to one of the ranges specified |
| 281 | * by rd_noinc_table). |
Bartosz Golaszewski | c9b41fc | 2017-12-06 15:26:21 +0100 | [diff] [blame] | 282 | * @disable_locking: This regmap is either protected by external means or |
| 283 | * is guaranteed not be be accessed from multiple threads. |
| 284 | * Don't use any locking mechanisms. |
Davide Ciminaghi | 76aad39 | 2012-11-20 15:20:30 +0100 | [diff] [blame] | 285 | * @lock: Optional lock callback (overrides regmap's default lock |
| 286 | * function, based on spinlock or mutex). |
| 287 | * @unlock: As above for unlocking. |
| 288 | * @lock_arg: this field is passed as the only argument of lock/unlock |
| 289 | * functions (ignored in case regular lock/unlock functions |
| 290 | * are not overridden). |
Andrey Smirnov | d2a5884 | 2013-01-27 10:49:05 -0800 | [diff] [blame] | 291 | * @reg_read: Optional callback that if filled will be used to perform |
| 292 | * all the reads from the registers. Should only be provided for |
Laszlo Papp | bdc3964 | 2014-01-09 14:13:41 +0000 | [diff] [blame] | 293 | * devices whose read operation cannot be represented as a simple |
| 294 | * read operation on a bus such as SPI, I2C, etc. Most of the |
| 295 | * devices do not need this. |
Andrey Smirnov | d2a5884 | 2013-01-27 10:49:05 -0800 | [diff] [blame] | 296 | * @reg_write: Same as above for writing. |
| 297 | * @fast_io: Register IO is fast. Use a spinlock instead of a mutex |
| 298 | * to perform locking. This field is ignored if custom lock/unlock |
| 299 | * functions are used (see fields lock/unlock of struct regmap_config). |
| 300 | * This field is a duplicate of a similar file in |
| 301 | * 'struct regmap_bus' and serves exact same purpose. |
| 302 | * Use it only for "no-bus" cases. |
Stefan Agner | b429fab | 2016-01-19 17:14:39 -0800 | [diff] [blame] | 303 | * @max_register: Optional, specifies the maximum valid register address. |
Davide Ciminaghi | 76aad39 | 2012-11-20 15:20:30 +0100 | [diff] [blame] | 304 | * @wr_table: Optional, points to a struct regmap_access_table specifying |
| 305 | * valid ranges for write access. |
| 306 | * @rd_table: As above, for read access. |
| 307 | * @volatile_table: As above, for volatile registers. |
| 308 | * @precious_table: As above, for precious registers. |
Ben Whitten | cdf6b11 | 2018-10-19 10:33:50 +0100 | [diff] [blame] | 309 | * @wr_noinc_table: As above, for no increment writeable registers. |
Crestez Dan Leonard | 74fe7b5 | 2018-08-07 17:52:17 +0300 | [diff] [blame] | 310 | * @rd_noinc_table: As above, for no increment readable registers. |
Mark Brown | bd20eb5 | 2011-08-19 18:09:38 +0900 | [diff] [blame] | 311 | * @reg_defaults: Power on reset values for registers (for use with |
| 312 | * register cache support). |
| 313 | * @num_reg_defaults: Number of elements in reg_defaults. |
Lars-Peter Clausen | 6f30644 | 2011-09-05 20:46:32 +0200 | [diff] [blame] | 314 | * |
Tony Lindgren | f50e38c | 2016-09-15 13:56:10 -0700 | [diff] [blame] | 315 | * @read_flag_mask: Mask to be set in the top bytes of the register when doing |
Lars-Peter Clausen | 6f30644 | 2011-09-05 20:46:32 +0200 | [diff] [blame] | 316 | * a read. |
Tony Lindgren | f50e38c | 2016-09-15 13:56:10 -0700 | [diff] [blame] | 317 | * @write_flag_mask: Mask to be set in the top bytes of the register when doing |
Lars-Peter Clausen | 6f30644 | 2011-09-05 20:46:32 +0200 | [diff] [blame] | 318 | * a write. If both read_flag_mask and write_flag_mask are |
Andrew F. Davis | 9bf485c | 2018-01-07 17:19:09 -0600 | [diff] [blame] | 319 | * empty and zero_flag_mask is not set the regmap_bus default |
| 320 | * masks are used. |
| 321 | * @zero_flag_mask: If set, read_flag_mask and write_flag_mask are used even |
| 322 | * if they are both empty. |
David Frey | 1c96a2f | 2018-09-01 09:50:41 -0700 | [diff] [blame] | 323 | * @use_single_read: If set, converts the bulk read operation into a series of |
| 324 | * single read operations. This is useful for a device that |
| 325 | * does not support bulk read. |
| 326 | * @use_single_write: If set, converts the bulk write operation into a series of |
| 327 | * single write operations. This is useful for a device that |
| 328 | * does not support bulk write. |
Opensource [Anthony Olech] | e894c3f | 2014-03-04 13:54:02 +0000 | [diff] [blame] | 329 | * @can_multi_write: If set, the device supports the multi write mode of bulk |
| 330 | * write operations, if clear multi write requests will be |
| 331 | * split into individual write operations |
Dimitris Papastamos | 9fabe24 | 2011-09-19 14:34:00 +0100 | [diff] [blame] | 332 | * |
| 333 | * @cache_type: The actual cache type. |
| 334 | * @reg_defaults_raw: Power on reset values for registers (for use with |
| 335 | * register cache support). |
| 336 | * @num_reg_defaults_raw: Number of elements in reg_defaults_raw. |
Stephen Warren | 141eba2 | 2012-05-24 10:47:26 -0600 | [diff] [blame] | 337 | * @reg_format_endian: Endianness for formatted register addresses. If this is |
| 338 | * DEFAULT, the @reg_format_endian_default value from the |
| 339 | * regmap bus is used. |
| 340 | * @val_format_endian: Endianness for formatted register values. If this is |
| 341 | * DEFAULT, the @reg_format_endian_default value from the |
| 342 | * regmap bus is used. |
Krystian Garbaciak | 6863ca6 | 2012-06-15 11:23:56 +0100 | [diff] [blame] | 343 | * |
| 344 | * @ranges: Array of configuration entries for virtual address ranges. |
| 345 | * @num_ranges: Number of range configuration entries. |
Baolin Wang | a488781 | 2017-12-25 14:37:09 +0800 | [diff] [blame] | 346 | * @use_hwlock: Indicate if a hardware spinlock should be used. |
Baolin Wang | 8698b93 | 2017-11-01 10:11:55 +0800 | [diff] [blame] | 347 | * @hwlock_id: Specify the hardware spinlock id. |
| 348 | * @hwlock_mode: The hardware spinlock mode, should be HWLOCK_IRQSTATE, |
| 349 | * HWLOCK_IRQ or 0. |
Mark Brown | dd898b2 | 2011-07-20 22:28:58 +0100 | [diff] [blame] | 350 | */ |
Mark Brown | b83a313 | 2011-05-11 19:59:58 +0200 | [diff] [blame] | 351 | struct regmap_config { |
Stephen Warren | d3c242e | 2012-04-04 15:48:29 -0600 | [diff] [blame] | 352 | const char *name; |
| 353 | |
Mark Brown | b83a313 | 2011-05-11 19:59:58 +0200 | [diff] [blame] | 354 | int reg_bits; |
Stephen Warren | f01ee60 | 2012-04-09 13:40:24 -0600 | [diff] [blame] | 355 | int reg_stride; |
Mark Brown | 82159ba | 2012-01-18 10:52:25 +0000 | [diff] [blame] | 356 | int pad_bits; |
Mark Brown | b83a313 | 2011-05-11 19:59:58 +0200 | [diff] [blame] | 357 | int val_bits; |
Mark Brown | 2e2ae66 | 2011-07-20 22:33:39 +0100 | [diff] [blame] | 358 | |
Mark Brown | 2e2ae66 | 2011-07-20 22:33:39 +0100 | [diff] [blame] | 359 | bool (*writeable_reg)(struct device *dev, unsigned int reg); |
| 360 | bool (*readable_reg)(struct device *dev, unsigned int reg); |
| 361 | bool (*volatile_reg)(struct device *dev, unsigned int reg); |
Mark Brown | 1869488 | 2011-08-08 15:40:22 +0900 | [diff] [blame] | 362 | bool (*precious_reg)(struct device *dev, unsigned int reg); |
Ben Whitten | cdf6b11 | 2018-10-19 10:33:50 +0100 | [diff] [blame] | 363 | bool (*writeable_noinc_reg)(struct device *dev, unsigned int reg); |
Crestez Dan Leonard | 74fe7b5 | 2018-08-07 17:52:17 +0300 | [diff] [blame] | 364 | bool (*readable_noinc_reg)(struct device *dev, unsigned int reg); |
Bartosz Golaszewski | c9b41fc | 2017-12-06 15:26:21 +0100 | [diff] [blame] | 365 | |
| 366 | bool disable_locking; |
Davide Ciminaghi | 0d4529c | 2012-10-16 15:56:59 +0200 | [diff] [blame] | 367 | regmap_lock lock; |
| 368 | regmap_unlock unlock; |
| 369 | void *lock_arg; |
Mark Brown | bd20eb5 | 2011-08-19 18:09:38 +0900 | [diff] [blame] | 370 | |
Andrey Smirnov | d2a5884 | 2013-01-27 10:49:05 -0800 | [diff] [blame] | 371 | int (*reg_read)(void *context, unsigned int reg, unsigned int *val); |
| 372 | int (*reg_write)(void *context, unsigned int reg, unsigned int val); |
| 373 | |
| 374 | bool fast_io; |
| 375 | |
Mark Brown | bd20eb5 | 2011-08-19 18:09:38 +0900 | [diff] [blame] | 376 | unsigned int max_register; |
Davide Ciminaghi | 76aad39 | 2012-11-20 15:20:30 +0100 | [diff] [blame] | 377 | const struct regmap_access_table *wr_table; |
| 378 | const struct regmap_access_table *rd_table; |
| 379 | const struct regmap_access_table *volatile_table; |
| 380 | const struct regmap_access_table *precious_table; |
Ben Whitten | cdf6b11 | 2018-10-19 10:33:50 +0100 | [diff] [blame] | 381 | const struct regmap_access_table *wr_noinc_table; |
Crestez Dan Leonard | 74fe7b5 | 2018-08-07 17:52:17 +0300 | [diff] [blame] | 382 | const struct regmap_access_table *rd_noinc_table; |
Lars-Peter Clausen | 720e461 | 2011-11-16 16:28:17 +0100 | [diff] [blame] | 383 | const struct reg_default *reg_defaults; |
Dimitris Papastamos | 9fabe24 | 2011-09-19 14:34:00 +0100 | [diff] [blame] | 384 | unsigned int num_reg_defaults; |
| 385 | enum regcache_type cache_type; |
| 386 | const void *reg_defaults_raw; |
| 387 | unsigned int num_reg_defaults_raw; |
Lars-Peter Clausen | 6f30644 | 2011-09-05 20:46:32 +0200 | [diff] [blame] | 388 | |
Tony Lindgren | f50e38c | 2016-09-15 13:56:10 -0700 | [diff] [blame] | 389 | unsigned long read_flag_mask; |
| 390 | unsigned long write_flag_mask; |
Andrew F. Davis | 9bf485c | 2018-01-07 17:19:09 -0600 | [diff] [blame] | 391 | bool zero_flag_mask; |
Ashish Jangam | 2e33caf | 2012-04-30 23:23:40 +0100 | [diff] [blame] | 392 | |
David Frey | 1c96a2f | 2018-09-01 09:50:41 -0700 | [diff] [blame] | 393 | bool use_single_read; |
| 394 | bool use_single_write; |
Opensource [Anthony Olech] | e894c3f | 2014-03-04 13:54:02 +0000 | [diff] [blame] | 395 | bool can_multi_write; |
Stephen Warren | 141eba2 | 2012-05-24 10:47:26 -0600 | [diff] [blame] | 396 | |
| 397 | enum regmap_endian reg_format_endian; |
| 398 | enum regmap_endian val_format_endian; |
Mark Brown | 38e2319 | 2012-07-22 19:26:07 +0100 | [diff] [blame] | 399 | |
Krystian Garbaciak | 6863ca6 | 2012-06-15 11:23:56 +0100 | [diff] [blame] | 400 | const struct regmap_range_cfg *ranges; |
Mark Brown | e3549cd | 2012-10-02 20:17:15 +0100 | [diff] [blame] | 401 | unsigned int num_ranges; |
Baolin Wang | 8698b93 | 2017-11-01 10:11:55 +0800 | [diff] [blame] | 402 | |
Baolin Wang | a488781 | 2017-12-25 14:37:09 +0800 | [diff] [blame] | 403 | bool use_hwlock; |
Baolin Wang | 8698b93 | 2017-11-01 10:11:55 +0800 | [diff] [blame] | 404 | unsigned int hwlock_id; |
| 405 | unsigned int hwlock_mode; |
Krystian Garbaciak | 6863ca6 | 2012-06-15 11:23:56 +0100 | [diff] [blame] | 406 | }; |
| 407 | |
| 408 | /** |
Charles Keepax | 2cf8e2d | 2017-01-12 11:17:39 +0000 | [diff] [blame] | 409 | * struct regmap_range_cfg - Configuration for indirectly accessed or paged |
| 410 | * registers. |
Krystian Garbaciak | 6863ca6 | 2012-06-15 11:23:56 +0100 | [diff] [blame] | 411 | * |
Mark Brown | d058bb4 | 2012-10-03 12:40:47 +0100 | [diff] [blame] | 412 | * @name: Descriptive name for diagnostics |
| 413 | * |
Krystian Garbaciak | 6863ca6 | 2012-06-15 11:23:56 +0100 | [diff] [blame] | 414 | * @range_min: Address of the lowest register address in virtual range. |
| 415 | * @range_max: Address of the highest register in virtual range. |
| 416 | * |
Charles Keepax | 2cf8e2d | 2017-01-12 11:17:39 +0000 | [diff] [blame] | 417 | * @selector_reg: Register with selector field. |
| 418 | * @selector_mask: Bit shift for selector value. |
| 419 | * @selector_shift: Bit mask for selector value. |
Krystian Garbaciak | 6863ca6 | 2012-06-15 11:23:56 +0100 | [diff] [blame] | 420 | * |
| 421 | * @window_start: Address of first (lowest) register in data window. |
| 422 | * @window_len: Number of registers in data window. |
Charles Keepax | 2cf8e2d | 2017-01-12 11:17:39 +0000 | [diff] [blame] | 423 | * |
| 424 | * Registers, mapped to this virtual range, are accessed in two steps: |
| 425 | * 1. page selector register update; |
| 426 | * 2. access through data window registers. |
Krystian Garbaciak | 6863ca6 | 2012-06-15 11:23:56 +0100 | [diff] [blame] | 427 | */ |
| 428 | struct regmap_range_cfg { |
Mark Brown | d058bb4 | 2012-10-03 12:40:47 +0100 | [diff] [blame] | 429 | const char *name; |
| 430 | |
Krystian Garbaciak | 6863ca6 | 2012-06-15 11:23:56 +0100 | [diff] [blame] | 431 | /* Registers of virtual address range */ |
| 432 | unsigned int range_min; |
| 433 | unsigned int range_max; |
| 434 | |
| 435 | /* Page selector for indirect addressing */ |
| 436 | unsigned int selector_reg; |
| 437 | unsigned int selector_mask; |
| 438 | int selector_shift; |
| 439 | |
| 440 | /* Data window (per each page) */ |
| 441 | unsigned int window_start; |
| 442 | unsigned int window_len; |
Mark Brown | b83a313 | 2011-05-11 19:59:58 +0200 | [diff] [blame] | 443 | }; |
| 444 | |
Mark Brown | 0d509f2 | 2013-01-27 22:07:38 +0800 | [diff] [blame] | 445 | struct regmap_async; |
| 446 | |
Stephen Warren | 0135bbc | 2012-04-04 15:48:30 -0600 | [diff] [blame] | 447 | typedef int (*regmap_hw_write)(void *context, const void *data, |
Mark Brown | b83a313 | 2011-05-11 19:59:58 +0200 | [diff] [blame] | 448 | size_t count); |
Stephen Warren | 0135bbc | 2012-04-04 15:48:30 -0600 | [diff] [blame] | 449 | typedef int (*regmap_hw_gather_write)(void *context, |
Mark Brown | b83a313 | 2011-05-11 19:59:58 +0200 | [diff] [blame] | 450 | const void *reg, size_t reg_len, |
| 451 | const void *val, size_t val_len); |
Mark Brown | 0d509f2 | 2013-01-27 22:07:38 +0800 | [diff] [blame] | 452 | typedef int (*regmap_hw_async_write)(void *context, |
| 453 | const void *reg, size_t reg_len, |
| 454 | const void *val, size_t val_len, |
| 455 | struct regmap_async *async); |
Stephen Warren | 0135bbc | 2012-04-04 15:48:30 -0600 | [diff] [blame] | 456 | typedef int (*regmap_hw_read)(void *context, |
Mark Brown | b83a313 | 2011-05-11 19:59:58 +0200 | [diff] [blame] | 457 | const void *reg_buf, size_t reg_size, |
| 458 | void *val_buf, size_t val_size); |
Boris BREZILLON | 3ac1703 | 2014-04-17 11:40:11 +0200 | [diff] [blame] | 459 | typedef int (*regmap_hw_reg_read)(void *context, unsigned int reg, |
| 460 | unsigned int *val); |
| 461 | typedef int (*regmap_hw_reg_write)(void *context, unsigned int reg, |
| 462 | unsigned int val); |
Jon Ringle | 77792b1 | 2015-10-01 12:38:07 -0400 | [diff] [blame] | 463 | typedef int (*regmap_hw_reg_update_bits)(void *context, unsigned int reg, |
| 464 | unsigned int mask, unsigned int val); |
Mark Brown | 0d509f2 | 2013-01-27 22:07:38 +0800 | [diff] [blame] | 465 | typedef struct regmap_async *(*regmap_hw_async_alloc)(void); |
Stephen Warren | 0135bbc | 2012-04-04 15:48:30 -0600 | [diff] [blame] | 466 | typedef void (*regmap_hw_free_context)(void *context); |
Mark Brown | b83a313 | 2011-05-11 19:59:58 +0200 | [diff] [blame] | 467 | |
| 468 | /** |
Charles Keepax | 2cf8e2d | 2017-01-12 11:17:39 +0000 | [diff] [blame] | 469 | * struct regmap_bus - Description of a hardware bus for the register map |
| 470 | * infrastructure. |
Mark Brown | b83a313 | 2011-05-11 19:59:58 +0200 | [diff] [blame] | 471 | * |
Stephen Warren | bacdbe0 | 2012-04-04 15:48:28 -0600 | [diff] [blame] | 472 | * @fast_io: Register IO is fast. Use a spinlock instead of a mutex |
Davide Ciminaghi | 0d4529c | 2012-10-16 15:56:59 +0200 | [diff] [blame] | 473 | * to perform locking. This field is ignored if custom lock/unlock |
| 474 | * functions are used (see fields lock/unlock of |
| 475 | * struct regmap_config). |
Mark Brown | b83a313 | 2011-05-11 19:59:58 +0200 | [diff] [blame] | 476 | * @write: Write operation. |
| 477 | * @gather_write: Write operation with split register/value, return -ENOTSUPP |
| 478 | * if not implemented on a given device. |
Mark Brown | 0d509f2 | 2013-01-27 22:07:38 +0800 | [diff] [blame] | 479 | * @async_write: Write operation which completes asynchronously, optional and |
| 480 | * must serialise with respect to non-async I/O. |
Markus Pargmann | c5f58f2 | 2015-08-21 10:26:40 +0200 | [diff] [blame] | 481 | * @reg_write: Write a single register value to the given register address. This |
| 482 | * write operation has to complete when returning from the function. |
Charles Keepax | 2cf8e2d | 2017-01-12 11:17:39 +0000 | [diff] [blame] | 483 | * @reg_update_bits: Update bits operation to be used against volatile |
| 484 | * registers, intended for devices supporting some mechanism |
| 485 | * for setting clearing bits without having to |
| 486 | * read/modify/write. |
Mark Brown | b83a313 | 2011-05-11 19:59:58 +0200 | [diff] [blame] | 487 | * @read: Read operation. Data is returned in the buffer used to transmit |
| 488 | * data. |
Markus Pargmann | c5f58f2 | 2015-08-21 10:26:40 +0200 | [diff] [blame] | 489 | * @reg_read: Read a single register value from a given register address. |
| 490 | * @free_context: Free context. |
Mark Brown | 0d509f2 | 2013-01-27 22:07:38 +0800 | [diff] [blame] | 491 | * @async_alloc: Allocate a regmap_async() structure. |
Mark Brown | b83a313 | 2011-05-11 19:59:58 +0200 | [diff] [blame] | 492 | * @read_flag_mask: Mask to be set in the top byte of the register when doing |
| 493 | * a read. |
Stephen Warren | 141eba2 | 2012-05-24 10:47:26 -0600 | [diff] [blame] | 494 | * @reg_format_endian_default: Default endianness for formatted register |
| 495 | * addresses. Used when the regmap_config specifies DEFAULT. If this is |
| 496 | * DEFAULT, BIG is assumed. |
| 497 | * @val_format_endian_default: Default endianness for formatted register |
| 498 | * values. Used when the regmap_config specifies DEFAULT. If this is |
| 499 | * DEFAULT, BIG is assumed. |
Markus Pargmann | adaac45 | 2015-08-30 09:33:53 +0200 | [diff] [blame] | 500 | * @max_raw_read: Max raw read size that can be used on the bus. |
| 501 | * @max_raw_write: Max raw write size that can be used on the bus. |
Mark Brown | b83a313 | 2011-05-11 19:59:58 +0200 | [diff] [blame] | 502 | */ |
| 503 | struct regmap_bus { |
Stephen Warren | bacdbe0 | 2012-04-04 15:48:28 -0600 | [diff] [blame] | 504 | bool fast_io; |
Mark Brown | b83a313 | 2011-05-11 19:59:58 +0200 | [diff] [blame] | 505 | regmap_hw_write write; |
| 506 | regmap_hw_gather_write gather_write; |
Mark Brown | 0d509f2 | 2013-01-27 22:07:38 +0800 | [diff] [blame] | 507 | regmap_hw_async_write async_write; |
Boris BREZILLON | 3ac1703 | 2014-04-17 11:40:11 +0200 | [diff] [blame] | 508 | regmap_hw_reg_write reg_write; |
Jon Ringle | 77792b1 | 2015-10-01 12:38:07 -0400 | [diff] [blame] | 509 | regmap_hw_reg_update_bits reg_update_bits; |
Mark Brown | b83a313 | 2011-05-11 19:59:58 +0200 | [diff] [blame] | 510 | regmap_hw_read read; |
Boris BREZILLON | 3ac1703 | 2014-04-17 11:40:11 +0200 | [diff] [blame] | 511 | regmap_hw_reg_read reg_read; |
Stephen Warren | 0135bbc | 2012-04-04 15:48:30 -0600 | [diff] [blame] | 512 | regmap_hw_free_context free_context; |
Mark Brown | 0d509f2 | 2013-01-27 22:07:38 +0800 | [diff] [blame] | 513 | regmap_hw_async_alloc async_alloc; |
Mark Brown | b83a313 | 2011-05-11 19:59:58 +0200 | [diff] [blame] | 514 | u8 read_flag_mask; |
Stephen Warren | 141eba2 | 2012-05-24 10:47:26 -0600 | [diff] [blame] | 515 | enum regmap_endian reg_format_endian_default; |
| 516 | enum regmap_endian val_format_endian_default; |
Markus Pargmann | adaac45 | 2015-08-30 09:33:53 +0200 | [diff] [blame] | 517 | size_t max_raw_read; |
| 518 | size_t max_raw_write; |
Mark Brown | b83a313 | 2011-05-11 19:59:58 +0200 | [diff] [blame] | 519 | }; |
| 520 | |
Nicolas Boichat | 3cfe7a7 | 2015-07-08 14:30:18 +0800 | [diff] [blame] | 521 | /* |
| 522 | * __regmap_init functions. |
| 523 | * |
| 524 | * These functions take a lock key and name parameter, and should not be called |
| 525 | * directly. Instead, use the regmap_init macros that generate a key and name |
| 526 | * for each call. |
| 527 | */ |
| 528 | struct regmap *__regmap_init(struct device *dev, |
| 529 | const struct regmap_bus *bus, |
| 530 | void *bus_context, |
| 531 | const struct regmap_config *config, |
| 532 | struct lock_class_key *lock_key, |
| 533 | const char *lock_name); |
| 534 | struct regmap *__regmap_init_i2c(struct i2c_client *i2c, |
| 535 | const struct regmap_config *config, |
| 536 | struct lock_class_key *lock_key, |
| 537 | const char *lock_name); |
Akinobu Mita | bcf7eac | 2018-07-17 00:47:48 +0900 | [diff] [blame] | 538 | struct regmap *__regmap_init_sccb(struct i2c_client *i2c, |
| 539 | const struct regmap_config *config, |
| 540 | struct lock_class_key *lock_key, |
| 541 | const char *lock_name); |
Srinivas Kandagatla | 7d6f7fb | 2017-12-11 23:43:02 +0000 | [diff] [blame] | 542 | struct regmap *__regmap_init_slimbus(struct slim_device *slimbus, |
| 543 | const struct regmap_config *config, |
| 544 | struct lock_class_key *lock_key, |
| 545 | const char *lock_name); |
Nicolas Boichat | 3cfe7a7 | 2015-07-08 14:30:18 +0800 | [diff] [blame] | 546 | struct regmap *__regmap_init_spi(struct spi_device *dev, |
| 547 | const struct regmap_config *config, |
| 548 | struct lock_class_key *lock_key, |
| 549 | const char *lock_name); |
| 550 | struct regmap *__regmap_init_spmi_base(struct spmi_device *dev, |
| 551 | const struct regmap_config *config, |
| 552 | struct lock_class_key *lock_key, |
| 553 | const char *lock_name); |
| 554 | struct regmap *__regmap_init_spmi_ext(struct spmi_device *dev, |
| 555 | const struct regmap_config *config, |
| 556 | struct lock_class_key *lock_key, |
| 557 | const char *lock_name); |
Alex A. Mihaylov | cc5d0db | 2017-06-02 10:06:27 +0300 | [diff] [blame] | 558 | struct regmap *__regmap_init_w1(struct device *w1_dev, |
| 559 | const struct regmap_config *config, |
| 560 | struct lock_class_key *lock_key, |
| 561 | const char *lock_name); |
Nicolas Boichat | 3cfe7a7 | 2015-07-08 14:30:18 +0800 | [diff] [blame] | 562 | struct regmap *__regmap_init_mmio_clk(struct device *dev, const char *clk_id, |
| 563 | void __iomem *regs, |
| 564 | const struct regmap_config *config, |
| 565 | struct lock_class_key *lock_key, |
| 566 | const char *lock_name); |
| 567 | struct regmap *__regmap_init_ac97(struct snd_ac97 *ac97, |
| 568 | const struct regmap_config *config, |
| 569 | struct lock_class_key *lock_key, |
| 570 | const char *lock_name); |
Vinod Koul | 7c22ce6 | 2018-01-08 15:50:59 +0530 | [diff] [blame] | 571 | struct regmap *__regmap_init_sdw(struct sdw_slave *sdw, |
| 572 | const struct regmap_config *config, |
| 573 | struct lock_class_key *lock_key, |
| 574 | const char *lock_name); |
Nicolas Boichat | 3cfe7a7 | 2015-07-08 14:30:18 +0800 | [diff] [blame] | 575 | |
| 576 | struct regmap *__devm_regmap_init(struct device *dev, |
| 577 | const struct regmap_bus *bus, |
| 578 | void *bus_context, |
| 579 | const struct regmap_config *config, |
| 580 | struct lock_class_key *lock_key, |
| 581 | const char *lock_name); |
| 582 | struct regmap *__devm_regmap_init_i2c(struct i2c_client *i2c, |
| 583 | const struct regmap_config *config, |
| 584 | struct lock_class_key *lock_key, |
| 585 | const char *lock_name); |
Akinobu Mita | bcf7eac | 2018-07-17 00:47:48 +0900 | [diff] [blame] | 586 | struct regmap *__devm_regmap_init_sccb(struct i2c_client *i2c, |
| 587 | const struct regmap_config *config, |
| 588 | struct lock_class_key *lock_key, |
| 589 | const char *lock_name); |
Nicolas Boichat | 3cfe7a7 | 2015-07-08 14:30:18 +0800 | [diff] [blame] | 590 | struct regmap *__devm_regmap_init_spi(struct spi_device *dev, |
| 591 | const struct regmap_config *config, |
| 592 | struct lock_class_key *lock_key, |
| 593 | const char *lock_name); |
| 594 | struct regmap *__devm_regmap_init_spmi_base(struct spmi_device *dev, |
| 595 | const struct regmap_config *config, |
| 596 | struct lock_class_key *lock_key, |
| 597 | const char *lock_name); |
| 598 | struct regmap *__devm_regmap_init_spmi_ext(struct spmi_device *dev, |
| 599 | const struct regmap_config *config, |
| 600 | struct lock_class_key *lock_key, |
| 601 | const char *lock_name); |
Alex A. Mihaylov | cc5d0db | 2017-06-02 10:06:27 +0300 | [diff] [blame] | 602 | struct regmap *__devm_regmap_init_w1(struct device *w1_dev, |
| 603 | const struct regmap_config *config, |
| 604 | struct lock_class_key *lock_key, |
| 605 | const char *lock_name); |
Nicolas Boichat | 3cfe7a7 | 2015-07-08 14:30:18 +0800 | [diff] [blame] | 606 | struct regmap *__devm_regmap_init_mmio_clk(struct device *dev, |
| 607 | const char *clk_id, |
| 608 | void __iomem *regs, |
| 609 | const struct regmap_config *config, |
| 610 | struct lock_class_key *lock_key, |
| 611 | const char *lock_name); |
| 612 | struct regmap *__devm_regmap_init_ac97(struct snd_ac97 *ac97, |
| 613 | const struct regmap_config *config, |
| 614 | struct lock_class_key *lock_key, |
| 615 | const char *lock_name); |
Vinod Koul | 7c22ce6 | 2018-01-08 15:50:59 +0530 | [diff] [blame] | 616 | struct regmap *__devm_regmap_init_sdw(struct sdw_slave *sdw, |
| 617 | const struct regmap_config *config, |
| 618 | struct lock_class_key *lock_key, |
| 619 | const char *lock_name); |
Srinivas Kandagatla | ed24d56 | 2018-05-25 14:50:36 +0100 | [diff] [blame] | 620 | struct regmap *__devm_regmap_init_slimbus(struct slim_device *slimbus, |
| 621 | const struct regmap_config *config, |
| 622 | struct lock_class_key *lock_key, |
| 623 | const char *lock_name); |
Nicolas Boichat | 3cfe7a7 | 2015-07-08 14:30:18 +0800 | [diff] [blame] | 624 | /* |
| 625 | * Wrapper for regmap_init macros to include a unique lockdep key and name |
| 626 | * for each call. No-op if CONFIG_LOCKDEP is not set. |
| 627 | * |
| 628 | * @fn: Real function to call (in the form __[*_]regmap_init[_*]) |
| 629 | * @name: Config variable name (#config in the calling macro) |
| 630 | **/ |
| 631 | #ifdef CONFIG_LOCKDEP |
| 632 | #define __regmap_lockdep_wrapper(fn, name, ...) \ |
| 633 | ( \ |
| 634 | ({ \ |
| 635 | static struct lock_class_key _key; \ |
| 636 | fn(__VA_ARGS__, &_key, \ |
| 637 | KBUILD_BASENAME ":" \ |
| 638 | __stringify(__LINE__) ":" \ |
| 639 | "(" name ")->lock"); \ |
| 640 | }) \ |
| 641 | ) |
| 642 | #else |
| 643 | #define __regmap_lockdep_wrapper(fn, name, ...) fn(__VA_ARGS__, NULL, NULL) |
| 644 | #endif |
| 645 | |
Nicolas Boichat | 1ed8111 | 2015-08-11 18:04:21 +0800 | [diff] [blame] | 646 | /** |
Charles Keepax | 2cf8e2d | 2017-01-12 11:17:39 +0000 | [diff] [blame] | 647 | * regmap_init() - Initialise register map |
Nicolas Boichat | 1ed8111 | 2015-08-11 18:04:21 +0800 | [diff] [blame] | 648 | * |
| 649 | * @dev: Device that will be interacted with |
| 650 | * @bus: Bus-specific callbacks to use with device |
| 651 | * @bus_context: Data passed to bus-specific callbacks |
| 652 | * @config: Configuration for register map |
| 653 | * |
| 654 | * The return value will be an ERR_PTR() on error or a valid pointer to |
| 655 | * a struct regmap. This function should generally not be called |
| 656 | * directly, it should be called by bus-specific init functions. |
| 657 | */ |
Nicolas Boichat | 3cfe7a7 | 2015-07-08 14:30:18 +0800 | [diff] [blame] | 658 | #define regmap_init(dev, bus, bus_context, config) \ |
| 659 | __regmap_lockdep_wrapper(__regmap_init, #config, \ |
| 660 | dev, bus, bus_context, config) |
Michal Simek | 6cfec04 | 2014-02-10 16:22:33 +0100 | [diff] [blame] | 661 | int regmap_attach_dev(struct device *dev, struct regmap *map, |
Nicolas Boichat | 3cfe7a7 | 2015-07-08 14:30:18 +0800 | [diff] [blame] | 662 | const struct regmap_config *config); |
Mark Brown | a676f08 | 2011-05-12 11:42:10 +0200 | [diff] [blame] | 663 | |
Nicolas Boichat | 1ed8111 | 2015-08-11 18:04:21 +0800 | [diff] [blame] | 664 | /** |
Charles Keepax | 2cf8e2d | 2017-01-12 11:17:39 +0000 | [diff] [blame] | 665 | * regmap_init_i2c() - Initialise register map |
Nicolas Boichat | 1ed8111 | 2015-08-11 18:04:21 +0800 | [diff] [blame] | 666 | * |
| 667 | * @i2c: Device that will be interacted with |
| 668 | * @config: Configuration for register map |
| 669 | * |
| 670 | * The return value will be an ERR_PTR() on error or a valid pointer to |
| 671 | * a struct regmap. |
| 672 | */ |
Nicolas Boichat | 3cfe7a7 | 2015-07-08 14:30:18 +0800 | [diff] [blame] | 673 | #define regmap_init_i2c(i2c, config) \ |
| 674 | __regmap_lockdep_wrapper(__regmap_init_i2c, #config, \ |
| 675 | i2c, config) |
Mark Brown | 2285322 | 2014-11-18 19:45:51 +0100 | [diff] [blame] | 676 | |
Nicolas Boichat | 1ed8111 | 2015-08-11 18:04:21 +0800 | [diff] [blame] | 677 | /** |
Akinobu Mita | bcf7eac | 2018-07-17 00:47:48 +0900 | [diff] [blame] | 678 | * regmap_init_sccb() - Initialise register map |
| 679 | * |
| 680 | * @i2c: Device that will be interacted with |
| 681 | * @config: Configuration for register map |
| 682 | * |
| 683 | * The return value will be an ERR_PTR() on error or a valid pointer to |
| 684 | * a struct regmap. |
| 685 | */ |
| 686 | #define regmap_init_sccb(i2c, config) \ |
| 687 | __regmap_lockdep_wrapper(__regmap_init_sccb, #config, \ |
| 688 | i2c, config) |
| 689 | |
| 690 | /** |
Srinivas Kandagatla | 7d6f7fb | 2017-12-11 23:43:02 +0000 | [diff] [blame] | 691 | * regmap_init_slimbus() - Initialise register map |
| 692 | * |
| 693 | * @slimbus: Device that will be interacted with |
| 694 | * @config: Configuration for register map |
| 695 | * |
| 696 | * The return value will be an ERR_PTR() on error or a valid pointer to |
| 697 | * a struct regmap. |
| 698 | */ |
| 699 | #define regmap_init_slimbus(slimbus, config) \ |
| 700 | __regmap_lockdep_wrapper(__regmap_init_slimbus, #config, \ |
| 701 | slimbus, config) |
| 702 | |
| 703 | /** |
Charles Keepax | 2cf8e2d | 2017-01-12 11:17:39 +0000 | [diff] [blame] | 704 | * regmap_init_spi() - Initialise register map |
Nicolas Boichat | 1ed8111 | 2015-08-11 18:04:21 +0800 | [diff] [blame] | 705 | * |
Charles Keepax | 2cf8e2d | 2017-01-12 11:17:39 +0000 | [diff] [blame] | 706 | * @dev: Device that will be interacted with |
Nicolas Boichat | 1ed8111 | 2015-08-11 18:04:21 +0800 | [diff] [blame] | 707 | * @config: Configuration for register map |
| 708 | * |
| 709 | * The return value will be an ERR_PTR() on error or a valid pointer to |
| 710 | * a struct regmap. |
| 711 | */ |
Nicolas Boichat | 3cfe7a7 | 2015-07-08 14:30:18 +0800 | [diff] [blame] | 712 | #define regmap_init_spi(dev, config) \ |
| 713 | __regmap_lockdep_wrapper(__regmap_init_spi, #config, \ |
| 714 | dev, config) |
Nicolas Boichat | 1ed8111 | 2015-08-11 18:04:21 +0800 | [diff] [blame] | 715 | |
| 716 | /** |
Charles Keepax | 2cf8e2d | 2017-01-12 11:17:39 +0000 | [diff] [blame] | 717 | * regmap_init_spmi_base() - Create regmap for the Base register space |
| 718 | * |
| 719 | * @dev: SPMI device that will be interacted with |
Nicolas Boichat | 1ed8111 | 2015-08-11 18:04:21 +0800 | [diff] [blame] | 720 | * @config: Configuration for register map |
| 721 | * |
| 722 | * The return value will be an ERR_PTR() on error or a valid pointer to |
| 723 | * a struct regmap. |
| 724 | */ |
Nicolas Boichat | 3cfe7a7 | 2015-07-08 14:30:18 +0800 | [diff] [blame] | 725 | #define regmap_init_spmi_base(dev, config) \ |
| 726 | __regmap_lockdep_wrapper(__regmap_init_spmi_base, #config, \ |
| 727 | dev, config) |
Nicolas Boichat | 1ed8111 | 2015-08-11 18:04:21 +0800 | [diff] [blame] | 728 | |
| 729 | /** |
Charles Keepax | 2cf8e2d | 2017-01-12 11:17:39 +0000 | [diff] [blame] | 730 | * regmap_init_spmi_ext() - Create regmap for Ext register space |
| 731 | * |
| 732 | * @dev: Device that will be interacted with |
Nicolas Boichat | 1ed8111 | 2015-08-11 18:04:21 +0800 | [diff] [blame] | 733 | * @config: Configuration for register map |
| 734 | * |
| 735 | * The return value will be an ERR_PTR() on error or a valid pointer to |
| 736 | * a struct regmap. |
| 737 | */ |
Nicolas Boichat | 3cfe7a7 | 2015-07-08 14:30:18 +0800 | [diff] [blame] | 738 | #define regmap_init_spmi_ext(dev, config) \ |
| 739 | __regmap_lockdep_wrapper(__regmap_init_spmi_ext, #config, \ |
| 740 | dev, config) |
Nicolas Boichat | 1ed8111 | 2015-08-11 18:04:21 +0800 | [diff] [blame] | 741 | |
| 742 | /** |
Alex A. Mihaylov | cc5d0db | 2017-06-02 10:06:27 +0300 | [diff] [blame] | 743 | * regmap_init_w1() - Initialise register map |
| 744 | * |
| 745 | * @w1_dev: Device that will be interacted with |
| 746 | * @config: Configuration for register map |
| 747 | * |
| 748 | * The return value will be an ERR_PTR() on error or a valid pointer to |
| 749 | * a struct regmap. |
| 750 | */ |
| 751 | #define regmap_init_w1(w1_dev, config) \ |
| 752 | __regmap_lockdep_wrapper(__regmap_init_w1, #config, \ |
| 753 | w1_dev, config) |
| 754 | |
| 755 | /** |
Charles Keepax | 2cf8e2d | 2017-01-12 11:17:39 +0000 | [diff] [blame] | 756 | * regmap_init_mmio_clk() - Initialise register map with register clock |
Nicolas Boichat | 1ed8111 | 2015-08-11 18:04:21 +0800 | [diff] [blame] | 757 | * |
| 758 | * @dev: Device that will be interacted with |
| 759 | * @clk_id: register clock consumer ID |
| 760 | * @regs: Pointer to memory-mapped IO region |
| 761 | * @config: Configuration for register map |
| 762 | * |
| 763 | * The return value will be an ERR_PTR() on error or a valid pointer to |
| 764 | * a struct regmap. |
| 765 | */ |
Nicolas Boichat | 3cfe7a7 | 2015-07-08 14:30:18 +0800 | [diff] [blame] | 766 | #define regmap_init_mmio_clk(dev, clk_id, regs, config) \ |
| 767 | __regmap_lockdep_wrapper(__regmap_init_mmio_clk, #config, \ |
| 768 | dev, clk_id, regs, config) |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 769 | |
| 770 | /** |
Charles Keepax | 2cf8e2d | 2017-01-12 11:17:39 +0000 | [diff] [blame] | 771 | * regmap_init_mmio() - Initialise register map |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 772 | * |
| 773 | * @dev: Device that will be interacted with |
| 774 | * @regs: Pointer to memory-mapped IO region |
| 775 | * @config: Configuration for register map |
| 776 | * |
| 777 | * The return value will be an ERR_PTR() on error or a valid pointer to |
| 778 | * a struct regmap. |
| 779 | */ |
Nicolas Boichat | 3cfe7a7 | 2015-07-08 14:30:18 +0800 | [diff] [blame] | 780 | #define regmap_init_mmio(dev, regs, config) \ |
| 781 | regmap_init_mmio_clk(dev, NULL, regs, config) |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 782 | |
| 783 | /** |
Charles Keepax | 2cf8e2d | 2017-01-12 11:17:39 +0000 | [diff] [blame] | 784 | * regmap_init_ac97() - Initialise AC'97 register map |
Nicolas Boichat | 1ed8111 | 2015-08-11 18:04:21 +0800 | [diff] [blame] | 785 | * |
| 786 | * @ac97: Device that will be interacted with |
| 787 | * @config: Configuration for register map |
| 788 | * |
| 789 | * The return value will be an ERR_PTR() on error or a valid pointer to |
| 790 | * a struct regmap. |
| 791 | */ |
| 792 | #define regmap_init_ac97(ac97, config) \ |
| 793 | __regmap_lockdep_wrapper(__regmap_init_ac97, #config, \ |
| 794 | ac97, config) |
| 795 | bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg); |
| 796 | |
| 797 | /** |
Vinod Koul | 7c22ce6 | 2018-01-08 15:50:59 +0530 | [diff] [blame] | 798 | * regmap_init_sdw() - Initialise register map |
| 799 | * |
| 800 | * @sdw: Device that will be interacted with |
| 801 | * @config: Configuration for register map |
| 802 | * |
| 803 | * The return value will be an ERR_PTR() on error or a valid pointer to |
| 804 | * a struct regmap. |
| 805 | */ |
| 806 | #define regmap_init_sdw(sdw, config) \ |
| 807 | __regmap_lockdep_wrapper(__regmap_init_sdw, #config, \ |
| 808 | sdw, config) |
| 809 | |
| 810 | |
| 811 | /** |
Charles Keepax | 2cf8e2d | 2017-01-12 11:17:39 +0000 | [diff] [blame] | 812 | * devm_regmap_init() - Initialise managed register map |
Nicolas Boichat | 1ed8111 | 2015-08-11 18:04:21 +0800 | [diff] [blame] | 813 | * |
| 814 | * @dev: Device that will be interacted with |
| 815 | * @bus: Bus-specific callbacks to use with device |
| 816 | * @bus_context: Data passed to bus-specific callbacks |
| 817 | * @config: Configuration for register map |
| 818 | * |
| 819 | * The return value will be an ERR_PTR() on error or a valid pointer |
| 820 | * to a struct regmap. This function should generally not be called |
| 821 | * directly, it should be called by bus-specific init functions. The |
| 822 | * map will be automatically freed by the device management code. |
| 823 | */ |
| 824 | #define devm_regmap_init(dev, bus, bus_context, config) \ |
| 825 | __regmap_lockdep_wrapper(__devm_regmap_init, #config, \ |
| 826 | dev, bus, bus_context, config) |
| 827 | |
| 828 | /** |
Charles Keepax | 2cf8e2d | 2017-01-12 11:17:39 +0000 | [diff] [blame] | 829 | * devm_regmap_init_i2c() - Initialise managed register map |
Nicolas Boichat | 1ed8111 | 2015-08-11 18:04:21 +0800 | [diff] [blame] | 830 | * |
| 831 | * @i2c: Device that will be interacted with |
| 832 | * @config: Configuration for register map |
| 833 | * |
| 834 | * The return value will be an ERR_PTR() on error or a valid pointer |
| 835 | * to a struct regmap. The regmap will be automatically freed by the |
| 836 | * device management code. |
| 837 | */ |
| 838 | #define devm_regmap_init_i2c(i2c, config) \ |
| 839 | __regmap_lockdep_wrapper(__devm_regmap_init_i2c, #config, \ |
| 840 | i2c, config) |
| 841 | |
| 842 | /** |
Akinobu Mita | bcf7eac | 2018-07-17 00:47:48 +0900 | [diff] [blame] | 843 | * devm_regmap_init_sccb() - Initialise managed register map |
| 844 | * |
| 845 | * @i2c: Device that will be interacted with |
| 846 | * @config: Configuration for register map |
| 847 | * |
| 848 | * The return value will be an ERR_PTR() on error or a valid pointer |
| 849 | * to a struct regmap. The regmap will be automatically freed by the |
| 850 | * device management code. |
| 851 | */ |
| 852 | #define devm_regmap_init_sccb(i2c, config) \ |
| 853 | __regmap_lockdep_wrapper(__devm_regmap_init_sccb, #config, \ |
| 854 | i2c, config) |
| 855 | |
| 856 | /** |
Charles Keepax | 2cf8e2d | 2017-01-12 11:17:39 +0000 | [diff] [blame] | 857 | * devm_regmap_init_spi() - Initialise register map |
Nicolas Boichat | 1ed8111 | 2015-08-11 18:04:21 +0800 | [diff] [blame] | 858 | * |
Charles Keepax | 2cf8e2d | 2017-01-12 11:17:39 +0000 | [diff] [blame] | 859 | * @dev: Device that will be interacted with |
Nicolas Boichat | 1ed8111 | 2015-08-11 18:04:21 +0800 | [diff] [blame] | 860 | * @config: Configuration for register map |
| 861 | * |
| 862 | * The return value will be an ERR_PTR() on error or a valid pointer |
| 863 | * to a struct regmap. The map will be automatically freed by the |
| 864 | * device management code. |
| 865 | */ |
| 866 | #define devm_regmap_init_spi(dev, config) \ |
| 867 | __regmap_lockdep_wrapper(__devm_regmap_init_spi, #config, \ |
| 868 | dev, config) |
| 869 | |
| 870 | /** |
Charles Keepax | 2cf8e2d | 2017-01-12 11:17:39 +0000 | [diff] [blame] | 871 | * devm_regmap_init_spmi_base() - Create managed regmap for Base register space |
| 872 | * |
| 873 | * @dev: SPMI device that will be interacted with |
Nicolas Boichat | 1ed8111 | 2015-08-11 18:04:21 +0800 | [diff] [blame] | 874 | * @config: Configuration for register map |
| 875 | * |
| 876 | * The return value will be an ERR_PTR() on error or a valid pointer |
| 877 | * to a struct regmap. The regmap will be automatically freed by the |
| 878 | * device management code. |
| 879 | */ |
| 880 | #define devm_regmap_init_spmi_base(dev, config) \ |
| 881 | __regmap_lockdep_wrapper(__devm_regmap_init_spmi_base, #config, \ |
| 882 | dev, config) |
| 883 | |
| 884 | /** |
Charles Keepax | 2cf8e2d | 2017-01-12 11:17:39 +0000 | [diff] [blame] | 885 | * devm_regmap_init_spmi_ext() - Create managed regmap for Ext register space |
| 886 | * |
| 887 | * @dev: SPMI device that will be interacted with |
Nicolas Boichat | 1ed8111 | 2015-08-11 18:04:21 +0800 | [diff] [blame] | 888 | * @config: Configuration for register map |
| 889 | * |
| 890 | * The return value will be an ERR_PTR() on error or a valid pointer |
| 891 | * to a struct regmap. The regmap will be automatically freed by the |
| 892 | * device management code. |
| 893 | */ |
| 894 | #define devm_regmap_init_spmi_ext(dev, config) \ |
| 895 | __regmap_lockdep_wrapper(__devm_regmap_init_spmi_ext, #config, \ |
| 896 | dev, config) |
| 897 | |
| 898 | /** |
Alex A. Mihaylov | cc5d0db | 2017-06-02 10:06:27 +0300 | [diff] [blame] | 899 | * devm_regmap_init_w1() - Initialise managed register map |
| 900 | * |
| 901 | * @w1_dev: Device that will be interacted with |
| 902 | * @config: Configuration for register map |
| 903 | * |
| 904 | * The return value will be an ERR_PTR() on error or a valid pointer |
| 905 | * to a struct regmap. The regmap will be automatically freed by the |
| 906 | * device management code. |
| 907 | */ |
| 908 | #define devm_regmap_init_w1(w1_dev, config) \ |
| 909 | __regmap_lockdep_wrapper(__devm_regmap_init_w1, #config, \ |
| 910 | w1_dev, config) |
| 911 | /** |
Charles Keepax | 2cf8e2d | 2017-01-12 11:17:39 +0000 | [diff] [blame] | 912 | * devm_regmap_init_mmio_clk() - Initialise managed register map with clock |
Nicolas Boichat | 1ed8111 | 2015-08-11 18:04:21 +0800 | [diff] [blame] | 913 | * |
| 914 | * @dev: Device that will be interacted with |
| 915 | * @clk_id: register clock consumer ID |
| 916 | * @regs: Pointer to memory-mapped IO region |
| 917 | * @config: Configuration for register map |
| 918 | * |
| 919 | * The return value will be an ERR_PTR() on error or a valid pointer |
| 920 | * to a struct regmap. The regmap will be automatically freed by the |
| 921 | * device management code. |
| 922 | */ |
| 923 | #define devm_regmap_init_mmio_clk(dev, clk_id, regs, config) \ |
| 924 | __regmap_lockdep_wrapper(__devm_regmap_init_mmio_clk, #config, \ |
| 925 | dev, clk_id, regs, config) |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 926 | |
| 927 | /** |
Charles Keepax | 2cf8e2d | 2017-01-12 11:17:39 +0000 | [diff] [blame] | 928 | * devm_regmap_init_mmio() - Initialise managed register map |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 929 | * |
| 930 | * @dev: Device that will be interacted with |
| 931 | * @regs: Pointer to memory-mapped IO region |
| 932 | * @config: Configuration for register map |
| 933 | * |
| 934 | * The return value will be an ERR_PTR() on error or a valid pointer |
| 935 | * to a struct regmap. The regmap will be automatically freed by the |
| 936 | * device management code. |
| 937 | */ |
Nicolas Boichat | 3cfe7a7 | 2015-07-08 14:30:18 +0800 | [diff] [blame] | 938 | #define devm_regmap_init_mmio(dev, regs, config) \ |
| 939 | devm_regmap_init_mmio_clk(dev, NULL, regs, config) |
Mark Brown | c0eb467 | 2012-01-30 19:56:52 +0000 | [diff] [blame] | 940 | |
Nicolas Boichat | 1ed8111 | 2015-08-11 18:04:21 +0800 | [diff] [blame] | 941 | /** |
Charles Keepax | 2cf8e2d | 2017-01-12 11:17:39 +0000 | [diff] [blame] | 942 | * devm_regmap_init_ac97() - Initialise AC'97 register map |
Nicolas Boichat | 1ed8111 | 2015-08-11 18:04:21 +0800 | [diff] [blame] | 943 | * |
| 944 | * @ac97: Device that will be interacted with |
| 945 | * @config: Configuration for register map |
| 946 | * |
| 947 | * The return value will be an ERR_PTR() on error or a valid pointer |
| 948 | * to a struct regmap. The regmap will be automatically freed by the |
| 949 | * device management code. |
| 950 | */ |
| 951 | #define devm_regmap_init_ac97(ac97, config) \ |
| 952 | __regmap_lockdep_wrapper(__devm_regmap_init_ac97, #config, \ |
| 953 | ac97, config) |
Mark Brown | b83a313 | 2011-05-11 19:59:58 +0200 | [diff] [blame] | 954 | |
Vinod Koul | 7c22ce6 | 2018-01-08 15:50:59 +0530 | [diff] [blame] | 955 | /** |
| 956 | * devm_regmap_init_sdw() - Initialise managed register map |
| 957 | * |
| 958 | * @sdw: Device that will be interacted with |
| 959 | * @config: Configuration for register map |
| 960 | * |
| 961 | * The return value will be an ERR_PTR() on error or a valid pointer |
| 962 | * to a struct regmap. The regmap will be automatically freed by the |
| 963 | * device management code. |
| 964 | */ |
| 965 | #define devm_regmap_init_sdw(sdw, config) \ |
| 966 | __regmap_lockdep_wrapper(__devm_regmap_init_sdw, #config, \ |
| 967 | sdw, config) |
| 968 | |
Srinivas Kandagatla | ed24d56 | 2018-05-25 14:50:36 +0100 | [diff] [blame] | 969 | /** |
| 970 | * devm_regmap_init_slimbus() - Initialise managed register map |
| 971 | * |
| 972 | * @slimbus: Device that will be interacted with |
| 973 | * @config: Configuration for register map |
| 974 | * |
| 975 | * The return value will be an ERR_PTR() on error or a valid pointer |
| 976 | * to a struct regmap. The regmap will be automatically freed by the |
| 977 | * device management code. |
| 978 | */ |
| 979 | #define devm_regmap_init_slimbus(slimbus, config) \ |
| 980 | __regmap_lockdep_wrapper(__devm_regmap_init_slimbus, #config, \ |
| 981 | slimbus, config) |
Maxime Ripard | 3189566 | 2018-02-21 10:20:25 +0100 | [diff] [blame] | 982 | int regmap_mmio_attach_clk(struct regmap *map, struct clk *clk); |
| 983 | void regmap_mmio_detach_clk(struct regmap *map); |
Mark Brown | b83a313 | 2011-05-11 19:59:58 +0200 | [diff] [blame] | 984 | void regmap_exit(struct regmap *map); |
| 985 | int regmap_reinit_cache(struct regmap *map, |
| 986 | const struct regmap_config *config); |
Mark Brown | 72b39f6 | 2012-05-08 17:44:40 +0100 | [diff] [blame] | 987 | struct regmap *dev_get_regmap(struct device *dev, const char *name); |
Tuomas Tynkkynen | 8d7d397 | 2014-07-21 18:38:47 +0300 | [diff] [blame] | 988 | struct device *regmap_get_device(struct regmap *map); |
Mark Brown | b83a313 | 2011-05-11 19:59:58 +0200 | [diff] [blame] | 989 | int regmap_write(struct regmap *map, unsigned int reg, unsigned int val); |
Mark Brown | 915f441 | 2013-10-09 13:30:10 +0100 | [diff] [blame] | 990 | int regmap_write_async(struct regmap *map, unsigned int reg, unsigned int val); |
Mark Brown | b83a313 | 2011-05-11 19:59:58 +0200 | [diff] [blame] | 991 | int regmap_raw_write(struct regmap *map, unsigned int reg, |
| 992 | const void *val, size_t val_len); |
Ben Whitten | cdf6b11 | 2018-10-19 10:33:50 +0100 | [diff] [blame] | 993 | int regmap_noinc_write(struct regmap *map, unsigned int reg, |
| 994 | const void *val, size_t val_len); |
Laxman Dewangan | 8eaeb21 | 2012-02-12 19:49:43 +0530 | [diff] [blame] | 995 | int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val, |
| 996 | size_t val_count); |
Nariman Poushin | 8019ff6 | 2015-07-16 16:36:21 +0100 | [diff] [blame] | 997 | int regmap_multi_reg_write(struct regmap *map, const struct reg_sequence *regs, |
Anthony Olech | e33fabd | 2013-10-11 15:31:11 +0100 | [diff] [blame] | 998 | int num_regs); |
Charles Keepax | 1d5b40b | 2014-02-25 13:45:50 +0000 | [diff] [blame] | 999 | int regmap_multi_reg_write_bypassed(struct regmap *map, |
Nariman Poushin | 8019ff6 | 2015-07-16 16:36:21 +0100 | [diff] [blame] | 1000 | const struct reg_sequence *regs, |
Charles Keepax | 1d5b40b | 2014-02-25 13:45:50 +0000 | [diff] [blame] | 1001 | int num_regs); |
Mark Brown | 0d509f2 | 2013-01-27 22:07:38 +0800 | [diff] [blame] | 1002 | int regmap_raw_write_async(struct regmap *map, unsigned int reg, |
| 1003 | const void *val, size_t val_len); |
Mark Brown | b83a313 | 2011-05-11 19:59:58 +0200 | [diff] [blame] | 1004 | int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val); |
| 1005 | int regmap_raw_read(struct regmap *map, unsigned int reg, |
| 1006 | void *val, size_t val_len); |
Crestez Dan Leonard | 74fe7b5 | 2018-08-07 17:52:17 +0300 | [diff] [blame] | 1007 | int regmap_noinc_read(struct regmap *map, unsigned int reg, |
| 1008 | void *val, size_t val_len); |
Mark Brown | b83a313 | 2011-05-11 19:59:58 +0200 | [diff] [blame] | 1009 | int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val, |
| 1010 | size_t val_count); |
Kuninori Morimoto | 91d31b9 | 2016-02-15 05:22:18 +0000 | [diff] [blame] | 1011 | int regmap_update_bits_base(struct regmap *map, unsigned int reg, |
| 1012 | unsigned int mask, unsigned int val, |
| 1013 | bool *change, bool async, bool force); |
Mark Brown | a6539c3 | 2012-02-17 14:20:14 -0800 | [diff] [blame] | 1014 | int regmap_get_val_bytes(struct regmap *map); |
Srinivas Kandagatla | 668abc7 | 2015-05-21 17:42:43 +0100 | [diff] [blame] | 1015 | int regmap_get_max_register(struct regmap *map); |
Srinivas Kandagatla | a2f776c | 2015-05-21 17:42:54 +0100 | [diff] [blame] | 1016 | int regmap_get_reg_stride(struct regmap *map); |
Mark Brown | 0d509f2 | 2013-01-27 22:07:38 +0800 | [diff] [blame] | 1017 | int regmap_async_complete(struct regmap *map); |
Mark Brown | 221ad7f | 2013-03-26 21:24:20 +0000 | [diff] [blame] | 1018 | bool regmap_can_raw_write(struct regmap *map); |
Markus Pargmann | f50c9eb | 2015-08-30 09:33:54 +0200 | [diff] [blame] | 1019 | size_t regmap_get_raw_read_max(struct regmap *map); |
| 1020 | size_t regmap_get_raw_write_max(struct regmap *map); |
Mark Brown | b83a313 | 2011-05-11 19:59:58 +0200 | [diff] [blame] | 1021 | |
Mark Brown | 39a5843 | 2011-09-19 18:21:49 +0100 | [diff] [blame] | 1022 | int regcache_sync(struct regmap *map); |
Mark Brown | 4d4cfd1 | 2012-02-23 20:53:37 +0000 | [diff] [blame] | 1023 | int regcache_sync_region(struct regmap *map, unsigned int min, |
| 1024 | unsigned int max); |
Mark Brown | 697e85b | 2013-05-08 13:55:22 +0100 | [diff] [blame] | 1025 | int regcache_drop_region(struct regmap *map, unsigned int min, |
| 1026 | unsigned int max); |
Mark Brown | 92afb28 | 2011-09-19 18:22:14 +0100 | [diff] [blame] | 1027 | void regcache_cache_only(struct regmap *map, bool enable); |
Dimitris Papastamos | 6eb0f5e | 2011-09-29 14:36:27 +0100 | [diff] [blame] | 1028 | void regcache_cache_bypass(struct regmap *map, bool enable); |
Mark Brown | 8ae0d7e | 2011-10-26 10:34:22 +0200 | [diff] [blame] | 1029 | void regcache_mark_dirty(struct regmap *map); |
Mark Brown | 92afb28 | 2011-09-19 18:22:14 +0100 | [diff] [blame] | 1030 | |
Mark Brown | 154881e | 2013-05-08 13:55:23 +0100 | [diff] [blame] | 1031 | bool regmap_check_range_table(struct regmap *map, unsigned int reg, |
| 1032 | const struct regmap_access_table *table); |
| 1033 | |
Nariman Poushin | 8019ff6 | 2015-07-16 16:36:21 +0100 | [diff] [blame] | 1034 | int regmap_register_patch(struct regmap *map, const struct reg_sequence *regs, |
Mark Brown | 22f0d90 | 2012-01-21 12:01:14 +0000 | [diff] [blame] | 1035 | int num_regs); |
Nenghua Cao | 13ff50c | 2014-02-19 18:44:13 +0800 | [diff] [blame] | 1036 | int regmap_parse_val(struct regmap *map, const void *buf, |
| 1037 | unsigned int *val); |
Mark Brown | 22f0d90 | 2012-01-21 12:01:14 +0000 | [diff] [blame] | 1038 | |
Davide Ciminaghi | 76aad39 | 2012-11-20 15:20:30 +0100 | [diff] [blame] | 1039 | static inline bool regmap_reg_in_range(unsigned int reg, |
| 1040 | const struct regmap_range *range) |
| 1041 | { |
| 1042 | return reg >= range->range_min && reg <= range->range_max; |
| 1043 | } |
| 1044 | |
| 1045 | bool regmap_reg_in_ranges(unsigned int reg, |
| 1046 | const struct regmap_range *ranges, |
| 1047 | unsigned int nranges); |
| 1048 | |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 1049 | /** |
Charles Keepax | 2cf8e2d | 2017-01-12 11:17:39 +0000 | [diff] [blame] | 1050 | * struct reg_field - Description of an register field |
Srinivas Kandagatla | 6725228 | 2013-06-11 13:18:15 +0100 | [diff] [blame] | 1051 | * |
| 1052 | * @reg: Offset of the register within the regmap bank |
| 1053 | * @lsb: lsb of the register field. |
Bintian Wang | f27b37f | 2015-01-27 20:50:29 +0800 | [diff] [blame] | 1054 | * @msb: msb of the register field. |
Kuninori Morimoto | a010237 | 2013-09-01 20:30:50 -0700 | [diff] [blame] | 1055 | * @id_size: port size if it has some ports |
| 1056 | * @id_offset: address offset for each ports |
Srinivas Kandagatla | 6725228 | 2013-06-11 13:18:15 +0100 | [diff] [blame] | 1057 | */ |
| 1058 | struct reg_field { |
| 1059 | unsigned int reg; |
| 1060 | unsigned int lsb; |
| 1061 | unsigned int msb; |
Kuninori Morimoto | a010237 | 2013-09-01 20:30:50 -0700 | [diff] [blame] | 1062 | unsigned int id_size; |
| 1063 | unsigned int id_offset; |
Srinivas Kandagatla | 6725228 | 2013-06-11 13:18:15 +0100 | [diff] [blame] | 1064 | }; |
| 1065 | |
| 1066 | #define REG_FIELD(_reg, _lsb, _msb) { \ |
| 1067 | .reg = _reg, \ |
| 1068 | .lsb = _lsb, \ |
| 1069 | .msb = _msb, \ |
| 1070 | } |
| 1071 | |
| 1072 | struct regmap_field *regmap_field_alloc(struct regmap *regmap, |
| 1073 | struct reg_field reg_field); |
| 1074 | void regmap_field_free(struct regmap_field *field); |
| 1075 | |
| 1076 | struct regmap_field *devm_regmap_field_alloc(struct device *dev, |
| 1077 | struct regmap *regmap, struct reg_field reg_field); |
| 1078 | void devm_regmap_field_free(struct device *dev, struct regmap_field *field); |
| 1079 | |
| 1080 | int regmap_field_read(struct regmap_field *field, unsigned int *val); |
Kuninori Morimoto | 28972ea | 2016-02-15 05:23:55 +0000 | [diff] [blame] | 1081 | int regmap_field_update_bits_base(struct regmap_field *field, |
| 1082 | unsigned int mask, unsigned int val, |
| 1083 | bool *change, bool async, bool force); |
Kuninori Morimoto | a010237 | 2013-09-01 20:30:50 -0700 | [diff] [blame] | 1084 | int regmap_fields_read(struct regmap_field *field, unsigned int id, |
| 1085 | unsigned int *val); |
Kuninori Morimoto | e126ede | 2016-02-15 05:24:51 +0000 | [diff] [blame] | 1086 | int regmap_fields_update_bits_base(struct regmap_field *field, unsigned int id, |
| 1087 | unsigned int mask, unsigned int val, |
| 1088 | bool *change, bool async, bool force); |
Matti Vaittinen | 1c2928e | 2018-12-18 13:59:31 +0200 | [diff] [blame] | 1089 | /** |
| 1090 | * struct regmap_irq_type - IRQ type definitions. |
| 1091 | * |
| 1092 | * @type_reg_offset: Offset register for the irq type setting. |
| 1093 | * @type_rising_val: Register value to configure RISING type irq. |
| 1094 | * @type_falling_val: Register value to configure FALLING type irq. |
| 1095 | * @type_level_low_val: Register value to configure LEVEL_LOW type irq. |
| 1096 | * @type_level_high_val: Register value to configure LEVEL_HIGH type irq. |
| 1097 | * @types_supported: logical OR of IRQ_TYPE_* flags indicating supported types. |
| 1098 | */ |
| 1099 | struct regmap_irq_type { |
| 1100 | unsigned int type_reg_offset; |
| 1101 | unsigned int type_reg_mask; |
| 1102 | unsigned int type_rising_val; |
| 1103 | unsigned int type_falling_val; |
| 1104 | unsigned int type_level_low_val; |
| 1105 | unsigned int type_level_high_val; |
| 1106 | unsigned int types_supported; |
| 1107 | }; |
Srinivas Kandagatla | 6725228 | 2013-06-11 13:18:15 +0100 | [diff] [blame] | 1108 | |
| 1109 | /** |
Charles Keepax | 2cf8e2d | 2017-01-12 11:17:39 +0000 | [diff] [blame] | 1110 | * struct regmap_irq - Description of an IRQ for the generic regmap irq_chip. |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 1111 | * |
| 1112 | * @reg_offset: Offset of the status/mask register within the bank |
| 1113 | * @mask: Mask used to flag/control the register. |
Matti Vaittinen | 1c2928e | 2018-12-18 13:59:31 +0200 | [diff] [blame] | 1114 | * @type: IRQ trigger type setting details if supported. |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 1115 | */ |
| 1116 | struct regmap_irq { |
| 1117 | unsigned int reg_offset; |
| 1118 | unsigned int mask; |
Matti Vaittinen | 1c2928e | 2018-12-18 13:59:31 +0200 | [diff] [blame] | 1119 | struct regmap_irq_type type; |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 1120 | }; |
| 1121 | |
Qipeng Zha | b4fe8ba | 2015-09-15 00:39:17 +0800 | [diff] [blame] | 1122 | #define REGMAP_IRQ_REG(_irq, _off, _mask) \ |
| 1123 | [_irq] = { .reg_offset = (_off), .mask = (_mask) } |
| 1124 | |
Tony Xie | 43fac32 | 2018-10-30 18:07:56 +0800 | [diff] [blame] | 1125 | #define REGMAP_IRQ_REG_LINE(_id, _reg_bits) \ |
| 1126 | [_id] = { \ |
| 1127 | .mask = BIT((_id) % (_reg_bits)), \ |
| 1128 | .reg_offset = (_id) / (_reg_bits), \ |
| 1129 | } |
| 1130 | |
Matti Vaittinen | a2d2184 | 2019-01-22 11:42:24 +0200 | [diff] [blame] | 1131 | #define REGMAP_IRQ_MAIN_REG_OFFSET(arr) \ |
| 1132 | { .num_regs = ARRAY_SIZE((arr)), .offset = &(arr)[0] } |
| 1133 | |
| 1134 | struct regmap_irq_sub_irq_map { |
| 1135 | unsigned int num_regs; |
| 1136 | unsigned int *offset; |
| 1137 | }; |
| 1138 | |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 1139 | /** |
Charles Keepax | 2cf8e2d | 2017-01-12 11:17:39 +0000 | [diff] [blame] | 1140 | * struct regmap_irq_chip - Description of a generic regmap irq_chip. |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 1141 | * |
| 1142 | * @name: Descriptive name for IRQ controller. |
| 1143 | * |
Matti Vaittinen | a2d2184 | 2019-01-22 11:42:24 +0200 | [diff] [blame] | 1144 | * @main_status: Base main status register address. For chips which have |
| 1145 | * interrupts arranged in separate sub-irq blocks with own IRQ |
| 1146 | * registers and which have a main IRQ registers indicating |
| 1147 | * sub-irq blocks with unhandled interrupts. For such chips fill |
| 1148 | * sub-irq register information in status_base, mask_base and |
| 1149 | * ack_base. |
| 1150 | * @num_main_status_bits: Should be given to chips where number of meaningfull |
| 1151 | * main status bits differs from num_regs. |
| 1152 | * @sub_reg_offsets: arrays of mappings from main register bits to sub irq |
| 1153 | * registers. First item in array describes the registers |
| 1154 | * for first main status bit. Second array for second bit etc. |
| 1155 | * Offset is given as sub register status offset to |
| 1156 | * status_base. Should contain num_regs arrays. |
| 1157 | * Can be provided for chips with more complex mapping than |
| 1158 | * 1.st bit to 1.st sub-reg, 2.nd bit to 2.nd sub-reg, ... |
| 1159 | * @num_main_regs: Number of 'main status' irq registers for chips which have |
| 1160 | * main_status set. |
| 1161 | * |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 1162 | * @status_base: Base status register address. |
| 1163 | * @mask_base: Base mask register address. |
Michael Grzeschik | a71411d | 2017-06-23 14:35:09 +0200 | [diff] [blame] | 1164 | * @mask_writeonly: Base mask register is write only. |
Guo Zeng | 7b7d196 | 2015-09-17 05:23:20 +0000 | [diff] [blame] | 1165 | * @unmask_base: Base unmask register address. for chips who have |
| 1166 | * separate mask and unmask registers |
Alexander Shiyan | d323343 | 2013-12-15 13:36:51 +0400 | [diff] [blame] | 1167 | * @ack_base: Base ack address. If zero then the chip is clear on read. |
| 1168 | * Using zero value is possible with @use_ack bit. |
Mark Brown | a43fd50 | 2012-06-05 14:34:03 +0100 | [diff] [blame] | 1169 | * @wake_base: Base address for wake enables. If zero unsupported. |
Laxman Dewangan | 7a78479f | 2015-12-22 18:25:26 +0530 | [diff] [blame] | 1170 | * @type_base: Base address for irq type. If zero unsupported. |
Graeme Gregory | 022f926a | 2012-05-14 22:40:43 +0900 | [diff] [blame] | 1171 | * @irq_reg_stride: Stride to use for chips where registers are not contiguous. |
Philipp Zabel | 2753e6f | 2013-07-22 17:15:52 +0200 | [diff] [blame] | 1172 | * @init_ack_masked: Ack all masked interrupts once during initalization. |
Philipp Zabel | 68622bd | 2013-07-24 10:26:48 +0200 | [diff] [blame] | 1173 | * @mask_invert: Inverted mask register: cleared bits are masked out. |
Alexander Shiyan | d323343 | 2013-12-15 13:36:51 +0400 | [diff] [blame] | 1174 | * @use_ack: Use @ack register even if it is zero. |
Guo Zeng | a650fdd | 2015-09-17 05:23:21 +0000 | [diff] [blame] | 1175 | * @ack_invert: Inverted ack register: cleared bits for ack. |
Philipp Zabel | 68622bd | 2013-07-24 10:26:48 +0200 | [diff] [blame] | 1176 | * @wake_invert: Inverted wake register: cleared bits are wake enabled. |
Laxman Dewangan | 7a78479f | 2015-12-22 18:25:26 +0530 | [diff] [blame] | 1177 | * @type_invert: Invert the type flags. |
Bartosz Golaszewski | bc998a7 | 2018-12-07 14:04:52 +0100 | [diff] [blame] | 1178 | * @type_in_mask: Use the mask registers for controlling irq type. For |
| 1179 | * interrupts defining type_rising/falling_mask use mask_base |
| 1180 | * for edge configuration and never update bits in type_base. |
Bartosz Golaszewski | c82ea33 | 2018-12-19 12:18:05 +0100 | [diff] [blame] | 1181 | * @clear_on_unmask: For chips with interrupts cleared on read: read the status |
| 1182 | * registers before unmasking interrupts to clear any bits |
| 1183 | * set when they were masked. |
Mark Brown | 0c00c50 | 2012-07-24 15:41:19 +0100 | [diff] [blame] | 1184 | * @runtime_pm: Hold a runtime PM lock on the device when accessing it. |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 1185 | * |
| 1186 | * @num_regs: Number of registers in each control bank. |
| 1187 | * @irqs: Descriptors for individual IRQs. Interrupt numbers are |
| 1188 | * assigned based on the index in the array of the interrupt. |
| 1189 | * @num_irqs: Number of descriptors. |
Laxman Dewangan | 7a78479f | 2015-12-22 18:25:26 +0530 | [diff] [blame] | 1190 | * @num_type_reg: Number of type registers. |
| 1191 | * @type_reg_stride: Stride to use for chips where type registers are not |
| 1192 | * contiguous. |
Laxman Dewangan | ccc1256 | 2016-05-20 20:40:26 +0530 | [diff] [blame] | 1193 | * @handle_pre_irq: Driver specific callback to handle interrupt from device |
| 1194 | * before regmap_irq_handler process the interrupts. |
| 1195 | * @handle_post_irq: Driver specific callback to handle interrupt from device |
| 1196 | * after handling the interrupts in regmap_irq_handler(). |
| 1197 | * @irq_drv_data: Driver specific IRQ data which is passed as parameter when |
| 1198 | * driver specific pre/post interrupt handler is called. |
Charles Keepax | 2cf8e2d | 2017-01-12 11:17:39 +0000 | [diff] [blame] | 1199 | * |
| 1200 | * This is not intended to handle every possible interrupt controller, but |
| 1201 | * it should handle a substantial proportion of those that are found in the |
| 1202 | * wild. |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 1203 | */ |
| 1204 | struct regmap_irq_chip { |
| 1205 | const char *name; |
| 1206 | |
Matti Vaittinen | a2d2184 | 2019-01-22 11:42:24 +0200 | [diff] [blame] | 1207 | unsigned int main_status; |
| 1208 | unsigned int num_main_status_bits; |
| 1209 | struct regmap_irq_sub_irq_map *sub_reg_offsets; |
| 1210 | int num_main_regs; |
| 1211 | |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 1212 | unsigned int status_base; |
| 1213 | unsigned int mask_base; |
Guo Zeng | 7b7d196 | 2015-09-17 05:23:20 +0000 | [diff] [blame] | 1214 | unsigned int unmask_base; |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 1215 | unsigned int ack_base; |
Mark Brown | a43fd50 | 2012-06-05 14:34:03 +0100 | [diff] [blame] | 1216 | unsigned int wake_base; |
Laxman Dewangan | 7a78479f | 2015-12-22 18:25:26 +0530 | [diff] [blame] | 1217 | unsigned int type_base; |
Graeme Gregory | 022f926a | 2012-05-14 22:40:43 +0900 | [diff] [blame] | 1218 | unsigned int irq_reg_stride; |
Michael Grzeschik | a71411d | 2017-06-23 14:35:09 +0200 | [diff] [blame] | 1219 | bool mask_writeonly:1; |
Philipp Zabel | f484f7a | 2013-07-24 10:26:42 +0200 | [diff] [blame] | 1220 | bool init_ack_masked:1; |
| 1221 | bool mask_invert:1; |
Alexander Shiyan | d323343 | 2013-12-15 13:36:51 +0400 | [diff] [blame] | 1222 | bool use_ack:1; |
Guo Zeng | a650fdd | 2015-09-17 05:23:21 +0000 | [diff] [blame] | 1223 | bool ack_invert:1; |
Philipp Zabel | f484f7a | 2013-07-24 10:26:42 +0200 | [diff] [blame] | 1224 | bool wake_invert:1; |
| 1225 | bool runtime_pm:1; |
Laxman Dewangan | 7a78479f | 2015-12-22 18:25:26 +0530 | [diff] [blame] | 1226 | bool type_invert:1; |
Bartosz Golaszewski | bc998a7 | 2018-12-07 14:04:52 +0100 | [diff] [blame] | 1227 | bool type_in_mask:1; |
Bartosz Golaszewski | c82ea33 | 2018-12-19 12:18:05 +0100 | [diff] [blame] | 1228 | bool clear_on_unmask:1; |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 1229 | |
| 1230 | int num_regs; |
| 1231 | |
| 1232 | const struct regmap_irq *irqs; |
| 1233 | int num_irqs; |
Laxman Dewangan | 7a78479f | 2015-12-22 18:25:26 +0530 | [diff] [blame] | 1234 | |
| 1235 | int num_type_reg; |
| 1236 | unsigned int type_reg_stride; |
Laxman Dewangan | ccc1256 | 2016-05-20 20:40:26 +0530 | [diff] [blame] | 1237 | |
| 1238 | int (*handle_pre_irq)(void *irq_drv_data); |
| 1239 | int (*handle_post_irq)(void *irq_drv_data); |
| 1240 | void *irq_drv_data; |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 1241 | }; |
| 1242 | |
| 1243 | struct regmap_irq_chip_data; |
| 1244 | |
| 1245 | int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags, |
Mark Brown | b026ddb | 2012-05-31 21:01:46 +0100 | [diff] [blame] | 1246 | int irq_base, const struct regmap_irq_chip *chip, |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 1247 | struct regmap_irq_chip_data **data); |
| 1248 | void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data); |
Laxman Dewangan | 045b984 | 2016-02-10 14:29:50 +0530 | [diff] [blame] | 1249 | |
| 1250 | int devm_regmap_add_irq_chip(struct device *dev, struct regmap *map, int irq, |
| 1251 | int irq_flags, int irq_base, |
| 1252 | const struct regmap_irq_chip *chip, |
| 1253 | struct regmap_irq_chip_data **data); |
| 1254 | void devm_regmap_del_irq_chip(struct device *dev, int irq, |
| 1255 | struct regmap_irq_chip_data *data); |
| 1256 | |
Mark Brown | 209a600 | 2011-12-05 16:10:15 +0000 | [diff] [blame] | 1257 | int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data); |
Mark Brown | 4af8be6 | 2012-05-13 10:59:56 +0100 | [diff] [blame] | 1258 | int regmap_irq_get_virq(struct regmap_irq_chip_data *data, int irq); |
Mark Brown | 90f790d | 2012-08-20 21:45:05 +0100 | [diff] [blame] | 1259 | struct irq_domain *regmap_irq_get_domain(struct regmap_irq_chip_data *data); |
Mark Brown | b83a313 | 2011-05-11 19:59:58 +0200 | [diff] [blame] | 1260 | |
Mark Brown | 9cde5fc | 2012-02-17 14:49:51 -0800 | [diff] [blame] | 1261 | #else |
| 1262 | |
| 1263 | /* |
| 1264 | * These stubs should only ever be called by generic code which has |
| 1265 | * regmap based facilities, if they ever get called at runtime |
| 1266 | * something is going wrong and something probably needs to select |
| 1267 | * REGMAP. |
| 1268 | */ |
| 1269 | |
| 1270 | static inline int regmap_write(struct regmap *map, unsigned int reg, |
| 1271 | unsigned int val) |
| 1272 | { |
| 1273 | WARN_ONCE(1, "regmap API is disabled"); |
| 1274 | return -EINVAL; |
| 1275 | } |
| 1276 | |
Mark Brown | 915f441 | 2013-10-09 13:30:10 +0100 | [diff] [blame] | 1277 | static inline int regmap_write_async(struct regmap *map, unsigned int reg, |
| 1278 | unsigned int val) |
| 1279 | { |
| 1280 | WARN_ONCE(1, "regmap API is disabled"); |
| 1281 | return -EINVAL; |
| 1282 | } |
| 1283 | |
Mark Brown | 9cde5fc | 2012-02-17 14:49:51 -0800 | [diff] [blame] | 1284 | static inline int regmap_raw_write(struct regmap *map, unsigned int reg, |
| 1285 | const void *val, size_t val_len) |
| 1286 | { |
| 1287 | WARN_ONCE(1, "regmap API is disabled"); |
| 1288 | return -EINVAL; |
| 1289 | } |
| 1290 | |
Mark Brown | 0d509f2 | 2013-01-27 22:07:38 +0800 | [diff] [blame] | 1291 | static inline int regmap_raw_write_async(struct regmap *map, unsigned int reg, |
| 1292 | const void *val, size_t val_len) |
| 1293 | { |
| 1294 | WARN_ONCE(1, "regmap API is disabled"); |
| 1295 | return -EINVAL; |
| 1296 | } |
| 1297 | |
Ben Whitten | cdf6b11 | 2018-10-19 10:33:50 +0100 | [diff] [blame] | 1298 | static inline int regmap_noinc_write(struct regmap *map, unsigned int reg, |
| 1299 | const void *val, size_t val_len) |
| 1300 | { |
| 1301 | WARN_ONCE(1, "regmap API is disabled"); |
| 1302 | return -EINVAL; |
| 1303 | } |
| 1304 | |
Mark Brown | 9cde5fc | 2012-02-17 14:49:51 -0800 | [diff] [blame] | 1305 | static inline int regmap_bulk_write(struct regmap *map, unsigned int reg, |
| 1306 | const void *val, size_t val_count) |
| 1307 | { |
| 1308 | WARN_ONCE(1, "regmap API is disabled"); |
| 1309 | return -EINVAL; |
| 1310 | } |
| 1311 | |
| 1312 | static inline int regmap_read(struct regmap *map, unsigned int reg, |
| 1313 | unsigned int *val) |
| 1314 | { |
| 1315 | WARN_ONCE(1, "regmap API is disabled"); |
| 1316 | return -EINVAL; |
| 1317 | } |
| 1318 | |
| 1319 | static inline int regmap_raw_read(struct regmap *map, unsigned int reg, |
| 1320 | void *val, size_t val_len) |
| 1321 | { |
| 1322 | WARN_ONCE(1, "regmap API is disabled"); |
| 1323 | return -EINVAL; |
| 1324 | } |
| 1325 | |
Crestez Dan Leonard | 74fe7b5 | 2018-08-07 17:52:17 +0300 | [diff] [blame] | 1326 | static inline int regmap_noinc_read(struct regmap *map, unsigned int reg, |
| 1327 | void *val, size_t val_len) |
| 1328 | { |
| 1329 | WARN_ONCE(1, "regmap API is disabled"); |
| 1330 | return -EINVAL; |
| 1331 | } |
| 1332 | |
Mark Brown | 9cde5fc | 2012-02-17 14:49:51 -0800 | [diff] [blame] | 1333 | static inline int regmap_bulk_read(struct regmap *map, unsigned int reg, |
| 1334 | void *val, size_t val_count) |
| 1335 | { |
| 1336 | WARN_ONCE(1, "regmap API is disabled"); |
| 1337 | return -EINVAL; |
| 1338 | } |
| 1339 | |
Kuninori Morimoto | 91d31b9 | 2016-02-15 05:22:18 +0000 | [diff] [blame] | 1340 | static inline int regmap_update_bits_base(struct regmap *map, unsigned int reg, |
| 1341 | unsigned int mask, unsigned int val, |
| 1342 | bool *change, bool async, bool force) |
Mark Brown | 9cde5fc | 2012-02-17 14:49:51 -0800 | [diff] [blame] | 1343 | { |
| 1344 | WARN_ONCE(1, "regmap API is disabled"); |
| 1345 | return -EINVAL; |
| 1346 | } |
| 1347 | |
Kuninori Morimoto | 28972ea | 2016-02-15 05:23:55 +0000 | [diff] [blame] | 1348 | static inline int regmap_field_update_bits_base(struct regmap_field *field, |
| 1349 | unsigned int mask, unsigned int val, |
| 1350 | bool *change, bool async, bool force) |
Kuninori Morimoto | fd4b7286c | 2015-06-16 08:52:39 +0000 | [diff] [blame] | 1351 | { |
| 1352 | WARN_ONCE(1, "regmap API is disabled"); |
| 1353 | return -EINVAL; |
| 1354 | } |
| 1355 | |
Kuninori Morimoto | e126ede | 2016-02-15 05:24:51 +0000 | [diff] [blame] | 1356 | static inline int regmap_fields_update_bits_base(struct regmap_field *field, |
| 1357 | unsigned int id, |
| 1358 | unsigned int mask, unsigned int val, |
| 1359 | bool *change, bool async, bool force) |
Mark Brown | 915f441 | 2013-10-09 13:30:10 +0100 | [diff] [blame] | 1360 | { |
| 1361 | WARN_ONCE(1, "regmap API is disabled"); |
| 1362 | return -EINVAL; |
| 1363 | } |
| 1364 | |
Mark Brown | 9cde5fc | 2012-02-17 14:49:51 -0800 | [diff] [blame] | 1365 | static inline int regmap_get_val_bytes(struct regmap *map) |
| 1366 | { |
| 1367 | WARN_ONCE(1, "regmap API is disabled"); |
| 1368 | return -EINVAL; |
| 1369 | } |
| 1370 | |
Srinivas Kandagatla | 668abc7 | 2015-05-21 17:42:43 +0100 | [diff] [blame] | 1371 | static inline int regmap_get_max_register(struct regmap *map) |
| 1372 | { |
| 1373 | WARN_ONCE(1, "regmap API is disabled"); |
| 1374 | return -EINVAL; |
| 1375 | } |
| 1376 | |
Srinivas Kandagatla | a2f776c | 2015-05-21 17:42:54 +0100 | [diff] [blame] | 1377 | static inline int regmap_get_reg_stride(struct regmap *map) |
| 1378 | { |
| 1379 | WARN_ONCE(1, "regmap API is disabled"); |
| 1380 | return -EINVAL; |
| 1381 | } |
| 1382 | |
Mark Brown | 9cde5fc | 2012-02-17 14:49:51 -0800 | [diff] [blame] | 1383 | static inline int regcache_sync(struct regmap *map) |
| 1384 | { |
| 1385 | WARN_ONCE(1, "regmap API is disabled"); |
| 1386 | return -EINVAL; |
| 1387 | } |
| 1388 | |
Mark Brown | a313f9f | 2012-02-23 19:49:43 +0000 | [diff] [blame] | 1389 | static inline int regcache_sync_region(struct regmap *map, unsigned int min, |
| 1390 | unsigned int max) |
| 1391 | { |
| 1392 | WARN_ONCE(1, "regmap API is disabled"); |
| 1393 | return -EINVAL; |
| 1394 | } |
| 1395 | |
Mark Brown | 697e85b | 2013-05-08 13:55:22 +0100 | [diff] [blame] | 1396 | static inline int regcache_drop_region(struct regmap *map, unsigned int min, |
| 1397 | unsigned int max) |
| 1398 | { |
| 1399 | WARN_ONCE(1, "regmap API is disabled"); |
| 1400 | return -EINVAL; |
| 1401 | } |
| 1402 | |
Mark Brown | 9cde5fc | 2012-02-17 14:49:51 -0800 | [diff] [blame] | 1403 | static inline void regcache_cache_only(struct regmap *map, bool enable) |
| 1404 | { |
| 1405 | WARN_ONCE(1, "regmap API is disabled"); |
| 1406 | } |
| 1407 | |
| 1408 | static inline void regcache_cache_bypass(struct regmap *map, bool enable) |
| 1409 | { |
| 1410 | WARN_ONCE(1, "regmap API is disabled"); |
| 1411 | } |
| 1412 | |
| 1413 | static inline void regcache_mark_dirty(struct regmap *map) |
| 1414 | { |
| 1415 | WARN_ONCE(1, "regmap API is disabled"); |
| 1416 | } |
| 1417 | |
Mark Brown | 0d509f2 | 2013-01-27 22:07:38 +0800 | [diff] [blame] | 1418 | static inline void regmap_async_complete(struct regmap *map) |
| 1419 | { |
| 1420 | WARN_ONCE(1, "regmap API is disabled"); |
| 1421 | } |
| 1422 | |
Mark Brown | 9cde5fc | 2012-02-17 14:49:51 -0800 | [diff] [blame] | 1423 | static inline int regmap_register_patch(struct regmap *map, |
Daniel Wagner | a6baa3d | 2015-11-30 16:20:15 +0100 | [diff] [blame] | 1424 | const struct reg_sequence *regs, |
Mark Brown | 9cde5fc | 2012-02-17 14:49:51 -0800 | [diff] [blame] | 1425 | int num_regs) |
| 1426 | { |
| 1427 | WARN_ONCE(1, "regmap API is disabled"); |
| 1428 | return -EINVAL; |
| 1429 | } |
| 1430 | |
Nenghua Cao | 13ff50c | 2014-02-19 18:44:13 +0800 | [diff] [blame] | 1431 | static inline int regmap_parse_val(struct regmap *map, const void *buf, |
| 1432 | unsigned int *val) |
| 1433 | { |
| 1434 | WARN_ONCE(1, "regmap API is disabled"); |
| 1435 | return -EINVAL; |
| 1436 | } |
| 1437 | |
Mark Brown | 72b39f6 | 2012-05-08 17:44:40 +0100 | [diff] [blame] | 1438 | static inline struct regmap *dev_get_regmap(struct device *dev, |
| 1439 | const char *name) |
| 1440 | { |
Mark Brown | 72b39f6 | 2012-05-08 17:44:40 +0100 | [diff] [blame] | 1441 | return NULL; |
| 1442 | } |
| 1443 | |
Tuomas Tynkkynen | 8d7d397 | 2014-07-21 18:38:47 +0300 | [diff] [blame] | 1444 | static inline struct device *regmap_get_device(struct regmap *map) |
| 1445 | { |
| 1446 | WARN_ONCE(1, "regmap API is disabled"); |
Mark Brown | 1d33dc6 | 2014-07-25 19:01:53 +0100 | [diff] [blame] | 1447 | return NULL; |
Tuomas Tynkkynen | 8d7d397 | 2014-07-21 18:38:47 +0300 | [diff] [blame] | 1448 | } |
| 1449 | |
Mark Brown | 9cde5fc | 2012-02-17 14:49:51 -0800 | [diff] [blame] | 1450 | #endif |
| 1451 | |
Mark Brown | b83a313 | 2011-05-11 19:59:58 +0200 | [diff] [blame] | 1452 | #endif |