regmap.h 26 KB

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