regmap.h 26 KB

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