regmap.h 29 KB

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