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