regmap.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  1. #ifndef __LINUX_REGMAP_H
  2. #define __LINUX_REGMAP_H
  3. /*
  4. * Register map access API
  5. *
  6. * Copyright 2011 Wolfson Microelectronics plc
  7. *
  8. * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/list.h>
  15. #include <linux/rbtree.h>
  16. #include <linux/err.h>
  17. #include <linux/bug.h>
  18. struct module;
  19. struct device;
  20. struct i2c_client;
  21. struct irq_domain;
  22. struct spi_device;
  23. struct spmi_device;
  24. struct regmap;
  25. struct regmap_range_cfg;
  26. struct regmap_field;
  27. struct snd_ac97;
  28. /* An enum of all the supported cache types */
  29. enum regcache_type {
  30. REGCACHE_NONE,
  31. REGCACHE_RBTREE,
  32. REGCACHE_COMPRESSED,
  33. REGCACHE_FLAT,
  34. };
  35. /**
  36. * Default value for a register. We use an array of structs rather
  37. * than a simple array as many modern devices have very sparse
  38. * register maps.
  39. *
  40. * @reg: Register address.
  41. * @def: Register default value.
  42. */
  43. struct reg_default {
  44. unsigned int reg;
  45. unsigned int def;
  46. };
  47. /**
  48. * Register/value pairs for sequences of writes with an optional delay in
  49. * microseconds to be applied after each write.
  50. *
  51. * @reg: Register address.
  52. * @def: Register value.
  53. * @delay_us: Delay to be applied after the register write in microseconds
  54. */
  55. struct reg_sequence {
  56. unsigned int reg;
  57. unsigned int def;
  58. unsigned int delay_us;
  59. };
  60. #ifdef CONFIG_REGMAP
  61. enum regmap_endian {
  62. /* Unspecified -> 0 -> Backwards compatible default */
  63. REGMAP_ENDIAN_DEFAULT = 0,
  64. REGMAP_ENDIAN_BIG,
  65. REGMAP_ENDIAN_LITTLE,
  66. REGMAP_ENDIAN_NATIVE,
  67. };
  68. /**
  69. * A register range, used for access related checks
  70. * (readable/writeable/volatile/precious checks)
  71. *
  72. * @range_min: address of first register
  73. * @range_max: address of last register
  74. */
  75. struct regmap_range {
  76. unsigned int range_min;
  77. unsigned int range_max;
  78. };
  79. #define regmap_reg_range(low, high) { .range_min = low, .range_max = high, }
  80. /*
  81. * A table of ranges including some yes ranges and some no ranges.
  82. * If a register belongs to a no_range, the corresponding check function
  83. * will return false. If a register belongs to a yes range, the corresponding
  84. * check function will return true. "no_ranges" are searched first.
  85. *
  86. * @yes_ranges : pointer to an array of regmap ranges used as "yes ranges"
  87. * @n_yes_ranges: size of the above array
  88. * @no_ranges: pointer to an array of regmap ranges used as "no ranges"
  89. * @n_no_ranges: size of the above array
  90. */
  91. struct regmap_access_table {
  92. const struct regmap_range *yes_ranges;
  93. unsigned int n_yes_ranges;
  94. const struct regmap_range *no_ranges;
  95. unsigned int n_no_ranges;
  96. };
  97. typedef void (*regmap_lock)(void *);
  98. typedef void (*regmap_unlock)(void *);
  99. /**
  100. * Configuration for the register map of a device.
  101. *
  102. * @name: Optional name of the regmap. Useful when a device has multiple
  103. * register regions.
  104. *
  105. * @reg_bits: Number of bits in a register address, mandatory.
  106. * @reg_stride: The register address stride. Valid register addresses are a
  107. * multiple of this value. If set to 0, a value of 1 will be
  108. * used.
  109. * @pad_bits: Number of bits of padding between register and value.
  110. * @val_bits: Number of bits in a register value, mandatory.
  111. *
  112. * @writeable_reg: Optional callback returning true if the register
  113. * can be written to. If this field is NULL but wr_table
  114. * (see below) is not, the check is performed on such table
  115. * (a register is writeable if it belongs to one of the ranges
  116. * specified by wr_table).
  117. * @readable_reg: Optional callback returning true if the register
  118. * can be read from. If this field is NULL but rd_table
  119. * (see below) is not, the check is performed on such table
  120. * (a register is readable if it belongs to one of the ranges
  121. * specified by rd_table).
  122. * @volatile_reg: Optional callback returning true if the register
  123. * value can't be cached. If this field is NULL but
  124. * volatile_table (see below) is not, the check is performed on
  125. * such table (a register is volatile if it belongs to one of
  126. * the ranges specified by volatile_table).
  127. * @precious_reg: Optional callback returning true if the register
  128. * should not be read outside of a call from the driver
  129. * (e.g., a clear on read interrupt status register). If this
  130. * field is NULL but precious_table (see below) is not, the
  131. * check is performed on such table (a register is precious if
  132. * it belongs to one of the ranges specified by precious_table).
  133. * @lock: Optional lock callback (overrides regmap's default lock
  134. * function, based on spinlock or mutex).
  135. * @unlock: As above for unlocking.
  136. * @lock_arg: this field is passed as the only argument of lock/unlock
  137. * functions (ignored in case regular lock/unlock functions
  138. * are not overridden).
  139. * @reg_read: Optional callback that if filled will be used to perform
  140. * all the reads from the registers. Should only be provided for
  141. * devices whose read operation cannot be represented as a simple
  142. * read operation on a bus such as SPI, I2C, etc. Most of the
  143. * devices do not need this.
  144. * @reg_write: Same as above for writing.
  145. * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
  146. * to perform locking. This field is ignored if custom lock/unlock
  147. * functions are used (see fields lock/unlock of struct regmap_config).
  148. * This field is a duplicate of a similar file in
  149. * 'struct regmap_bus' and serves exact same purpose.
  150. * Use it only for "no-bus" cases.
  151. * @max_register: Optional, specifies the maximum valid register index.
  152. * @wr_table: Optional, points to a struct regmap_access_table specifying
  153. * valid ranges for write access.
  154. * @rd_table: As above, for read access.
  155. * @volatile_table: As above, for volatile registers.
  156. * @precious_table: As above, for precious registers.
  157. * @reg_defaults: Power on reset values for registers (for use with
  158. * register cache support).
  159. * @num_reg_defaults: Number of elements in reg_defaults.
  160. *
  161. * @read_flag_mask: Mask to be set in the top byte of the register when doing
  162. * a read.
  163. * @write_flag_mask: Mask to be set in the top byte of the register when doing
  164. * a write. If both read_flag_mask and write_flag_mask are
  165. * empty the regmap_bus default masks are used.
  166. * @use_single_rw: If set, converts the bulk read and write operations into
  167. * a series of single read and write operations. This is useful
  168. * for device that does not support bulk read and write.
  169. * @can_multi_write: If set, the device supports the multi write mode of bulk
  170. * write operations, if clear multi write requests will be
  171. * split into individual write operations
  172. *
  173. * @cache_type: The actual cache type.
  174. * @reg_defaults_raw: Power on reset values for registers (for use with
  175. * register cache support).
  176. * @num_reg_defaults_raw: Number of elements in reg_defaults_raw.
  177. * @reg_format_endian: Endianness for formatted register addresses. If this is
  178. * DEFAULT, the @reg_format_endian_default value from the
  179. * regmap bus is used.
  180. * @val_format_endian: Endianness for formatted register values. If this is
  181. * DEFAULT, the @reg_format_endian_default value from the
  182. * regmap bus is used.
  183. *
  184. * @ranges: Array of configuration entries for virtual address ranges.
  185. * @num_ranges: Number of range configuration entries.
  186. */
  187. struct regmap_config {
  188. const char *name;
  189. int reg_bits;
  190. int reg_stride;
  191. int pad_bits;
  192. int val_bits;
  193. bool (*writeable_reg)(struct device *dev, unsigned int reg);
  194. bool (*readable_reg)(struct device *dev, unsigned int reg);
  195. bool (*volatile_reg)(struct device *dev, unsigned int reg);
  196. bool (*precious_reg)(struct device *dev, unsigned int reg);
  197. regmap_lock lock;
  198. regmap_unlock unlock;
  199. void *lock_arg;
  200. int (*reg_read)(void *context, unsigned int reg, unsigned int *val);
  201. int (*reg_write)(void *context, unsigned int reg, unsigned int val);
  202. bool fast_io;
  203. unsigned int max_register;
  204. const struct regmap_access_table *wr_table;
  205. const struct regmap_access_table *rd_table;
  206. const struct regmap_access_table *volatile_table;
  207. const struct regmap_access_table *precious_table;
  208. const struct reg_default *reg_defaults;
  209. unsigned int num_reg_defaults;
  210. enum regcache_type cache_type;
  211. const void *reg_defaults_raw;
  212. unsigned int num_reg_defaults_raw;
  213. u8 read_flag_mask;
  214. u8 write_flag_mask;
  215. bool use_single_rw;
  216. bool can_multi_write;
  217. enum regmap_endian reg_format_endian;
  218. enum regmap_endian val_format_endian;
  219. const struct regmap_range_cfg *ranges;
  220. unsigned int num_ranges;
  221. };
  222. /**
  223. * Configuration for indirectly accessed or paged registers.
  224. * Registers, mapped to this virtual range, are accessed in two steps:
  225. * 1. page selector register update;
  226. * 2. access through data window registers.
  227. *
  228. * @name: Descriptive name for diagnostics
  229. *
  230. * @range_min: Address of the lowest register address in virtual range.
  231. * @range_max: Address of the highest register in virtual range.
  232. *
  233. * @page_sel_reg: Register with selector field.
  234. * @page_sel_mask: Bit shift for selector value.
  235. * @page_sel_shift: Bit mask for selector value.
  236. *
  237. * @window_start: Address of first (lowest) register in data window.
  238. * @window_len: Number of registers in data window.
  239. */
  240. struct regmap_range_cfg {
  241. const char *name;
  242. /* Registers of virtual address range */
  243. unsigned int range_min;
  244. unsigned int range_max;
  245. /* Page selector for indirect addressing */
  246. unsigned int selector_reg;
  247. unsigned int selector_mask;
  248. int selector_shift;
  249. /* Data window (per each page) */
  250. unsigned int window_start;
  251. unsigned int window_len;
  252. };
  253. struct regmap_async;
  254. typedef int (*regmap_hw_write)(void *context, const void *data,
  255. size_t count);
  256. typedef int (*regmap_hw_gather_write)(void *context,
  257. const void *reg, size_t reg_len,
  258. const void *val, size_t val_len);
  259. typedef int (*regmap_hw_async_write)(void *context,
  260. const void *reg, size_t reg_len,
  261. const void *val, size_t val_len,
  262. struct regmap_async *async);
  263. typedef int (*regmap_hw_read)(void *context,
  264. const void *reg_buf, size_t reg_size,
  265. void *val_buf, size_t val_size);
  266. typedef int (*regmap_hw_reg_read)(void *context, unsigned int reg,
  267. unsigned int *val);
  268. typedef int (*regmap_hw_reg_write)(void *context, unsigned int reg,
  269. unsigned int val);
  270. typedef struct regmap_async *(*regmap_hw_async_alloc)(void);
  271. typedef void (*regmap_hw_free_context)(void *context);
  272. /**
  273. * Description of a hardware bus for the register map infrastructure.
  274. *
  275. * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
  276. * to perform locking. This field is ignored if custom lock/unlock
  277. * functions are used (see fields lock/unlock of
  278. * struct regmap_config).
  279. * @write: Write operation.
  280. * @gather_write: Write operation with split register/value, return -ENOTSUPP
  281. * if not implemented on a given device.
  282. * @async_write: Write operation which completes asynchronously, optional and
  283. * must serialise with respect to non-async I/O.
  284. * @read: Read operation. Data is returned in the buffer used to transmit
  285. * data.
  286. * @async_alloc: Allocate a regmap_async() structure.
  287. * @read_flag_mask: Mask to be set in the top byte of the register when doing
  288. * a read.
  289. * @reg_format_endian_default: Default endianness for formatted register
  290. * addresses. Used when the regmap_config specifies DEFAULT. If this is
  291. * DEFAULT, BIG is assumed.
  292. * @val_format_endian_default: Default endianness for formatted register
  293. * values. Used when the regmap_config specifies DEFAULT. If this is
  294. * DEFAULT, BIG is assumed.
  295. * @async_size: Size of struct used for async work.
  296. */
  297. struct regmap_bus {
  298. bool fast_io;
  299. regmap_hw_write write;
  300. regmap_hw_gather_write gather_write;
  301. regmap_hw_async_write async_write;
  302. regmap_hw_reg_write reg_write;
  303. regmap_hw_read read;
  304. regmap_hw_reg_read reg_read;
  305. regmap_hw_free_context free_context;
  306. regmap_hw_async_alloc async_alloc;
  307. u8 read_flag_mask;
  308. enum regmap_endian reg_format_endian_default;
  309. enum regmap_endian val_format_endian_default;
  310. };
  311. struct regmap *regmap_init(struct device *dev,
  312. const struct regmap_bus *bus,
  313. void *bus_context,
  314. const struct regmap_config *config);
  315. int regmap_attach_dev(struct device *dev, struct regmap *map,
  316. const struct regmap_config *config);
  317. struct regmap *regmap_init_i2c(struct i2c_client *i2c,
  318. const struct regmap_config *config);
  319. struct regmap *regmap_init_spi(struct spi_device *dev,
  320. const struct regmap_config *config);
  321. struct regmap *regmap_init_spmi_base(struct spmi_device *dev,
  322. const struct regmap_config *config);
  323. struct regmap *regmap_init_spmi_ext(struct spmi_device *dev,
  324. const struct regmap_config *config);
  325. struct regmap *regmap_init_mmio_clk(struct device *dev, const char *clk_id,
  326. void __iomem *regs,
  327. const struct regmap_config *config);
  328. struct regmap *regmap_init_ac97(struct snd_ac97 *ac97,
  329. const struct regmap_config *config);
  330. struct regmap *devm_regmap_init(struct device *dev,
  331. const struct regmap_bus *bus,
  332. void *bus_context,
  333. const struct regmap_config *config);
  334. struct regmap *devm_regmap_init_i2c(struct i2c_client *i2c,
  335. const struct regmap_config *config);
  336. struct regmap *devm_regmap_init_spi(struct spi_device *dev,
  337. const struct regmap_config *config);
  338. struct regmap *devm_regmap_init_spmi_base(struct spmi_device *dev,
  339. const struct regmap_config *config);
  340. struct regmap *devm_regmap_init_spmi_ext(struct spmi_device *dev,
  341. const struct regmap_config *config);
  342. struct regmap *devm_regmap_init_mmio_clk(struct device *dev, const char *clk_id,
  343. void __iomem *regs,
  344. const struct regmap_config *config);
  345. struct regmap *devm_regmap_init_ac97(struct snd_ac97 *ac97,
  346. const struct regmap_config *config);
  347. bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg);
  348. /**
  349. * regmap_init_mmio(): Initialise register map
  350. *
  351. * @dev: Device that will be interacted with
  352. * @regs: Pointer to memory-mapped IO region
  353. * @config: Configuration for register map
  354. *
  355. * The return value will be an ERR_PTR() on error or a valid pointer to
  356. * a struct regmap.
  357. */
  358. static inline struct regmap *regmap_init_mmio(struct device *dev,
  359. void __iomem *regs,
  360. const struct regmap_config *config)
  361. {
  362. return regmap_init_mmio_clk(dev, NULL, regs, config);
  363. }
  364. /**
  365. * devm_regmap_init_mmio(): Initialise managed register map
  366. *
  367. * @dev: Device that will be interacted with
  368. * @regs: Pointer to memory-mapped IO region
  369. * @config: Configuration for register map
  370. *
  371. * The return value will be an ERR_PTR() on error or a valid pointer
  372. * to a struct regmap. The regmap will be automatically freed by the
  373. * device management code.
  374. */
  375. static inline struct regmap *devm_regmap_init_mmio(struct device *dev,
  376. void __iomem *regs,
  377. const struct regmap_config *config)
  378. {
  379. return devm_regmap_init_mmio_clk(dev, NULL, regs, config);
  380. }
  381. void regmap_exit(struct regmap *map);
  382. int regmap_reinit_cache(struct regmap *map,
  383. const struct regmap_config *config);
  384. struct regmap *dev_get_regmap(struct device *dev, const char *name);
  385. struct device *regmap_get_device(struct regmap *map);
  386. int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
  387. int regmap_write_async(struct regmap *map, unsigned int reg, unsigned int val);
  388. int regmap_raw_write(struct regmap *map, unsigned int reg,
  389. const void *val, size_t val_len);
  390. int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
  391. size_t val_count);
  392. int regmap_multi_reg_write(struct regmap *map, const struct reg_sequence *regs,
  393. int num_regs);
  394. int regmap_multi_reg_write_bypassed(struct regmap *map,
  395. const struct reg_sequence *regs,
  396. int num_regs);
  397. int regmap_raw_write_async(struct regmap *map, unsigned int reg,
  398. const void *val, size_t val_len);
  399. int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
  400. int regmap_raw_read(struct regmap *map, unsigned int reg,
  401. void *val, size_t val_len);
  402. int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
  403. size_t val_count);
  404. int regmap_update_bits(struct regmap *map, unsigned int reg,
  405. unsigned int mask, unsigned int val);
  406. int regmap_update_bits_async(struct regmap *map, unsigned int reg,
  407. unsigned int mask, unsigned int val);
  408. int regmap_update_bits_check(struct regmap *map, unsigned int reg,
  409. unsigned int mask, unsigned int val,
  410. bool *change);
  411. int regmap_update_bits_check_async(struct regmap *map, unsigned int reg,
  412. unsigned int mask, unsigned int val,
  413. bool *change);
  414. int regmap_get_val_bytes(struct regmap *map);
  415. int regmap_get_max_register(struct regmap *map);
  416. int regmap_get_reg_stride(struct regmap *map);
  417. int regmap_async_complete(struct regmap *map);
  418. bool regmap_can_raw_write(struct regmap *map);
  419. int regcache_sync(struct regmap *map);
  420. int regcache_sync_region(struct regmap *map, unsigned int min,
  421. unsigned int max);
  422. int regcache_drop_region(struct regmap *map, unsigned int min,
  423. unsigned int max);
  424. void regcache_cache_only(struct regmap *map, bool enable);
  425. void regcache_cache_bypass(struct regmap *map, bool enable);
  426. void regcache_mark_dirty(struct regmap *map);
  427. bool regmap_check_range_table(struct regmap *map, unsigned int reg,
  428. const struct regmap_access_table *table);
  429. int regmap_register_patch(struct regmap *map, const struct reg_sequence *regs,
  430. int num_regs);
  431. int regmap_parse_val(struct regmap *map, const void *buf,
  432. unsigned int *val);
  433. static inline bool regmap_reg_in_range(unsigned int reg,
  434. const struct regmap_range *range)
  435. {
  436. return reg >= range->range_min && reg <= range->range_max;
  437. }
  438. bool regmap_reg_in_ranges(unsigned int reg,
  439. const struct regmap_range *ranges,
  440. unsigned int nranges);
  441. /**
  442. * Description of an register field
  443. *
  444. * @reg: Offset of the register within the regmap bank
  445. * @lsb: lsb of the register field.
  446. * @msb: msb of the register field.
  447. * @id_size: port size if it has some ports
  448. * @id_offset: address offset for each ports
  449. */
  450. struct reg_field {
  451. unsigned int reg;
  452. unsigned int lsb;
  453. unsigned int msb;
  454. unsigned int id_size;
  455. unsigned int id_offset;
  456. };
  457. #define REG_FIELD(_reg, _lsb, _msb) { \
  458. .reg = _reg, \
  459. .lsb = _lsb, \
  460. .msb = _msb, \
  461. }
  462. struct regmap_field *regmap_field_alloc(struct regmap *regmap,
  463. struct reg_field reg_field);
  464. void regmap_field_free(struct regmap_field *field);
  465. struct regmap_field *devm_regmap_field_alloc(struct device *dev,
  466. struct regmap *regmap, struct reg_field reg_field);
  467. void devm_regmap_field_free(struct device *dev, struct regmap_field *field);
  468. int regmap_field_read(struct regmap_field *field, unsigned int *val);
  469. int regmap_field_write(struct regmap_field *field, unsigned int val);
  470. int regmap_field_update_bits(struct regmap_field *field,
  471. unsigned int mask, unsigned int val);
  472. int regmap_fields_write(struct regmap_field *field, unsigned int id,
  473. unsigned int val);
  474. int regmap_fields_read(struct regmap_field *field, unsigned int id,
  475. unsigned int *val);
  476. int regmap_fields_update_bits(struct regmap_field *field, unsigned int id,
  477. unsigned int mask, unsigned int val);
  478. /**
  479. * Description of an IRQ for the generic regmap irq_chip.
  480. *
  481. * @reg_offset: Offset of the status/mask register within the bank
  482. * @mask: Mask used to flag/control the register.
  483. */
  484. struct regmap_irq {
  485. unsigned int reg_offset;
  486. unsigned int mask;
  487. };
  488. /**
  489. * Description of a generic regmap irq_chip. This is not intended to
  490. * handle every possible interrupt controller, but it should handle a
  491. * substantial proportion of those that are found in the wild.
  492. *
  493. * @name: Descriptive name for IRQ controller.
  494. *
  495. * @status_base: Base status register address.
  496. * @mask_base: Base mask register address.
  497. * @ack_base: Base ack address. If zero then the chip is clear on read.
  498. * Using zero value is possible with @use_ack bit.
  499. * @wake_base: Base address for wake enables. If zero unsupported.
  500. * @irq_reg_stride: Stride to use for chips where registers are not contiguous.
  501. * @init_ack_masked: Ack all masked interrupts once during initalization.
  502. * @mask_invert: Inverted mask register: cleared bits are masked out.
  503. * @use_ack: Use @ack register even if it is zero.
  504. * @wake_invert: Inverted wake register: cleared bits are wake enabled.
  505. * @runtime_pm: Hold a runtime PM lock on the device when accessing it.
  506. *
  507. * @num_regs: Number of registers in each control bank.
  508. * @irqs: Descriptors for individual IRQs. Interrupt numbers are
  509. * assigned based on the index in the array of the interrupt.
  510. * @num_irqs: Number of descriptors.
  511. */
  512. struct regmap_irq_chip {
  513. const char *name;
  514. unsigned int status_base;
  515. unsigned int mask_base;
  516. unsigned int ack_base;
  517. unsigned int wake_base;
  518. unsigned int irq_reg_stride;
  519. bool init_ack_masked:1;
  520. bool mask_invert:1;
  521. bool use_ack:1;
  522. bool wake_invert:1;
  523. bool runtime_pm:1;
  524. int num_regs;
  525. const struct regmap_irq *irqs;
  526. int num_irqs;
  527. };
  528. struct regmap_irq_chip_data;
  529. int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
  530. int irq_base, const struct regmap_irq_chip *chip,
  531. struct regmap_irq_chip_data **data);
  532. void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data);
  533. int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data);
  534. int regmap_irq_get_virq(struct regmap_irq_chip_data *data, int irq);
  535. struct irq_domain *regmap_irq_get_domain(struct regmap_irq_chip_data *data);
  536. #else
  537. /*
  538. * These stubs should only ever be called by generic code which has
  539. * regmap based facilities, if they ever get called at runtime
  540. * something is going wrong and something probably needs to select
  541. * REGMAP.
  542. */
  543. static inline int regmap_write(struct regmap *map, unsigned int reg,
  544. unsigned int val)
  545. {
  546. WARN_ONCE(1, "regmap API is disabled");
  547. return -EINVAL;
  548. }
  549. static inline int regmap_write_async(struct regmap *map, unsigned int reg,
  550. unsigned int val)
  551. {
  552. WARN_ONCE(1, "regmap API is disabled");
  553. return -EINVAL;
  554. }
  555. static inline int regmap_raw_write(struct regmap *map, unsigned int reg,
  556. const void *val, size_t val_len)
  557. {
  558. WARN_ONCE(1, "regmap API is disabled");
  559. return -EINVAL;
  560. }
  561. static inline int regmap_raw_write_async(struct regmap *map, unsigned int reg,
  562. const void *val, size_t val_len)
  563. {
  564. WARN_ONCE(1, "regmap API is disabled");
  565. return -EINVAL;
  566. }
  567. static inline int regmap_bulk_write(struct regmap *map, unsigned int reg,
  568. const void *val, size_t val_count)
  569. {
  570. WARN_ONCE(1, "regmap API is disabled");
  571. return -EINVAL;
  572. }
  573. static inline int regmap_read(struct regmap *map, unsigned int reg,
  574. unsigned int *val)
  575. {
  576. WARN_ONCE(1, "regmap API is disabled");
  577. return -EINVAL;
  578. }
  579. static inline int regmap_raw_read(struct regmap *map, unsigned int reg,
  580. void *val, size_t val_len)
  581. {
  582. WARN_ONCE(1, "regmap API is disabled");
  583. return -EINVAL;
  584. }
  585. static inline int regmap_bulk_read(struct regmap *map, unsigned int reg,
  586. void *val, size_t val_count)
  587. {
  588. WARN_ONCE(1, "regmap API is disabled");
  589. return -EINVAL;
  590. }
  591. static inline int regmap_update_bits(struct regmap *map, unsigned int reg,
  592. unsigned int mask, unsigned int val)
  593. {
  594. WARN_ONCE(1, "regmap API is disabled");
  595. return -EINVAL;
  596. }
  597. static inline int regmap_update_bits_async(struct regmap *map,
  598. unsigned int reg,
  599. unsigned int mask, unsigned int val)
  600. {
  601. WARN_ONCE(1, "regmap API is disabled");
  602. return -EINVAL;
  603. }
  604. static inline int regmap_update_bits_check(struct regmap *map,
  605. unsigned int reg,
  606. unsigned int mask, unsigned int val,
  607. bool *change)
  608. {
  609. WARN_ONCE(1, "regmap API is disabled");
  610. return -EINVAL;
  611. }
  612. static inline int regmap_update_bits_check_async(struct regmap *map,
  613. unsigned int reg,
  614. unsigned int mask,
  615. unsigned int val,
  616. bool *change)
  617. {
  618. WARN_ONCE(1, "regmap API is disabled");
  619. return -EINVAL;
  620. }
  621. static inline int regmap_get_val_bytes(struct regmap *map)
  622. {
  623. WARN_ONCE(1, "regmap API is disabled");
  624. return -EINVAL;
  625. }
  626. static inline int regmap_get_max_register(struct regmap *map)
  627. {
  628. WARN_ONCE(1, "regmap API is disabled");
  629. return -EINVAL;
  630. }
  631. static inline int regmap_get_reg_stride(struct regmap *map)
  632. {
  633. WARN_ONCE(1, "regmap API is disabled");
  634. return -EINVAL;
  635. }
  636. static inline int regcache_sync(struct regmap *map)
  637. {
  638. WARN_ONCE(1, "regmap API is disabled");
  639. return -EINVAL;
  640. }
  641. static inline int regcache_sync_region(struct regmap *map, unsigned int min,
  642. unsigned int max)
  643. {
  644. WARN_ONCE(1, "regmap API is disabled");
  645. return -EINVAL;
  646. }
  647. static inline int regcache_drop_region(struct regmap *map, unsigned int min,
  648. unsigned int max)
  649. {
  650. WARN_ONCE(1, "regmap API is disabled");
  651. return -EINVAL;
  652. }
  653. static inline void regcache_cache_only(struct regmap *map, bool enable)
  654. {
  655. WARN_ONCE(1, "regmap API is disabled");
  656. }
  657. static inline void regcache_cache_bypass(struct regmap *map, bool enable)
  658. {
  659. WARN_ONCE(1, "regmap API is disabled");
  660. }
  661. static inline void regcache_mark_dirty(struct regmap *map)
  662. {
  663. WARN_ONCE(1, "regmap API is disabled");
  664. }
  665. static inline void regmap_async_complete(struct regmap *map)
  666. {
  667. WARN_ONCE(1, "regmap API is disabled");
  668. }
  669. static inline int regmap_register_patch(struct regmap *map,
  670. const struct reg_default *regs,
  671. int num_regs)
  672. {
  673. WARN_ONCE(1, "regmap API is disabled");
  674. return -EINVAL;
  675. }
  676. static inline int regmap_parse_val(struct regmap *map, const void *buf,
  677. unsigned int *val)
  678. {
  679. WARN_ONCE(1, "regmap API is disabled");
  680. return -EINVAL;
  681. }
  682. static inline struct regmap *dev_get_regmap(struct device *dev,
  683. const char *name)
  684. {
  685. return NULL;
  686. }
  687. static inline struct device *regmap_get_device(struct regmap *map)
  688. {
  689. WARN_ONCE(1, "regmap API is disabled");
  690. return NULL;
  691. }
  692. #endif
  693. #endif