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