regmap.h 45 KB

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