regmap.h 37 KB

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