regmap.h 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318
  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. struct regmap *__devm_regmap_init_slimbus(struct slim_device *slimbus,
  553. const struct regmap_config *config,
  554. struct lock_class_key *lock_key,
  555. const char *lock_name);
  556. /*
  557. * Wrapper for regmap_init macros to include a unique lockdep key and name
  558. * for each call. No-op if CONFIG_LOCKDEP is not set.
  559. *
  560. * @fn: Real function to call (in the form __[*_]regmap_init[_*])
  561. * @name: Config variable name (#config in the calling macro)
  562. **/
  563. #ifdef CONFIG_LOCKDEP
  564. #define __regmap_lockdep_wrapper(fn, name, ...) \
  565. ( \
  566. ({ \
  567. static struct lock_class_key _key; \
  568. fn(__VA_ARGS__, &_key, \
  569. KBUILD_BASENAME ":" \
  570. __stringify(__LINE__) ":" \
  571. "(" name ")->lock"); \
  572. }) \
  573. )
  574. #else
  575. #define __regmap_lockdep_wrapper(fn, name, ...) fn(__VA_ARGS__, NULL, NULL)
  576. #endif
  577. /**
  578. * regmap_init() - Initialise register map
  579. *
  580. * @dev: Device that will be interacted with
  581. * @bus: Bus-specific callbacks to use with device
  582. * @bus_context: Data passed to bus-specific callbacks
  583. * @config: Configuration for register map
  584. *
  585. * The return value will be an ERR_PTR() on error or a valid pointer to
  586. * a struct regmap. This function should generally not be called
  587. * directly, it should be called by bus-specific init functions.
  588. */
  589. #define regmap_init(dev, bus, bus_context, config) \
  590. __regmap_lockdep_wrapper(__regmap_init, #config, \
  591. dev, bus, bus_context, config)
  592. int regmap_attach_dev(struct device *dev, struct regmap *map,
  593. const struct regmap_config *config);
  594. /**
  595. * regmap_init_i2c() - Initialise register map
  596. *
  597. * @i2c: 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 to
  601. * a struct regmap.
  602. */
  603. #define regmap_init_i2c(i2c, config) \
  604. __regmap_lockdep_wrapper(__regmap_init_i2c, #config, \
  605. i2c, config)
  606. /**
  607. * regmap_init_slimbus() - Initialise register map
  608. *
  609. * @slimbus: Device that will be interacted with
  610. * @config: Configuration for register map
  611. *
  612. * The return value will be an ERR_PTR() on error or a valid pointer to
  613. * a struct regmap.
  614. */
  615. #define regmap_init_slimbus(slimbus, config) \
  616. __regmap_lockdep_wrapper(__regmap_init_slimbus, #config, \
  617. slimbus, config)
  618. /**
  619. * regmap_init_spi() - Initialise register map
  620. *
  621. * @dev: Device that will be interacted with
  622. * @config: Configuration for register map
  623. *
  624. * The return value will be an ERR_PTR() on error or a valid pointer to
  625. * a struct regmap.
  626. */
  627. #define regmap_init_spi(dev, config) \
  628. __regmap_lockdep_wrapper(__regmap_init_spi, #config, \
  629. dev, config)
  630. /**
  631. * regmap_init_spmi_base() - Create regmap for the Base register space
  632. *
  633. * @dev: SPMI device that will be interacted with
  634. * @config: Configuration for register map
  635. *
  636. * The return value will be an ERR_PTR() on error or a valid pointer to
  637. * a struct regmap.
  638. */
  639. #define regmap_init_spmi_base(dev, config) \
  640. __regmap_lockdep_wrapper(__regmap_init_spmi_base, #config, \
  641. dev, config)
  642. /**
  643. * regmap_init_spmi_ext() - Create regmap for Ext register space
  644. *
  645. * @dev: Device that will be interacted with
  646. * @config: Configuration for register map
  647. *
  648. * The return value will be an ERR_PTR() on error or a valid pointer to
  649. * a struct regmap.
  650. */
  651. #define regmap_init_spmi_ext(dev, config) \
  652. __regmap_lockdep_wrapper(__regmap_init_spmi_ext, #config, \
  653. dev, config)
  654. /**
  655. * regmap_init_w1() - Initialise register map
  656. *
  657. * @w1_dev: Device that will be interacted with
  658. * @config: Configuration for register map
  659. *
  660. * The return value will be an ERR_PTR() on error or a valid pointer to
  661. * a struct regmap.
  662. */
  663. #define regmap_init_w1(w1_dev, config) \
  664. __regmap_lockdep_wrapper(__regmap_init_w1, #config, \
  665. w1_dev, config)
  666. /**
  667. * regmap_init_mmio_clk() - Initialise register map with register clock
  668. *
  669. * @dev: Device that will be interacted with
  670. * @clk_id: register clock consumer ID
  671. * @regs: Pointer to memory-mapped IO region
  672. * @config: Configuration for register map
  673. *
  674. * The return value will be an ERR_PTR() on error or a valid pointer to
  675. * a struct regmap.
  676. */
  677. #define regmap_init_mmio_clk(dev, clk_id, regs, config) \
  678. __regmap_lockdep_wrapper(__regmap_init_mmio_clk, #config, \
  679. dev, clk_id, regs, config)
  680. /**
  681. * regmap_init_mmio() - Initialise register map
  682. *
  683. * @dev: Device that will be interacted with
  684. * @regs: Pointer to memory-mapped IO region
  685. * @config: Configuration for register map
  686. *
  687. * The return value will be an ERR_PTR() on error or a valid pointer to
  688. * a struct regmap.
  689. */
  690. #define regmap_init_mmio(dev, regs, config) \
  691. regmap_init_mmio_clk(dev, NULL, regs, config)
  692. /**
  693. * regmap_init_ac97() - Initialise AC'97 register map
  694. *
  695. * @ac97: Device that will be interacted with
  696. * @config: Configuration for register map
  697. *
  698. * The return value will be an ERR_PTR() on error or a valid pointer to
  699. * a struct regmap.
  700. */
  701. #define regmap_init_ac97(ac97, config) \
  702. __regmap_lockdep_wrapper(__regmap_init_ac97, #config, \
  703. ac97, config)
  704. bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg);
  705. /**
  706. * regmap_init_sdw() - Initialise register map
  707. *
  708. * @sdw: Device that will be interacted with
  709. * @config: Configuration for register map
  710. *
  711. * The return value will be an ERR_PTR() on error or a valid pointer to
  712. * a struct regmap.
  713. */
  714. #define regmap_init_sdw(sdw, config) \
  715. __regmap_lockdep_wrapper(__regmap_init_sdw, #config, \
  716. sdw, config)
  717. /**
  718. * devm_regmap_init() - Initialise managed register map
  719. *
  720. * @dev: Device that will be interacted with
  721. * @bus: Bus-specific callbacks to use with device
  722. * @bus_context: Data passed to bus-specific callbacks
  723. * @config: Configuration for register map
  724. *
  725. * The return value will be an ERR_PTR() on error or a valid pointer
  726. * to a struct regmap. This function should generally not be called
  727. * directly, it should be called by bus-specific init functions. The
  728. * map will be automatically freed by the device management code.
  729. */
  730. #define devm_regmap_init(dev, bus, bus_context, config) \
  731. __regmap_lockdep_wrapper(__devm_regmap_init, #config, \
  732. dev, bus, bus_context, config)
  733. /**
  734. * devm_regmap_init_i2c() - Initialise managed register map
  735. *
  736. * @i2c: Device that will be interacted with
  737. * @config: Configuration for register map
  738. *
  739. * The return value will be an ERR_PTR() on error or a valid pointer
  740. * to a struct regmap. The regmap will be automatically freed by the
  741. * device management code.
  742. */
  743. #define devm_regmap_init_i2c(i2c, config) \
  744. __regmap_lockdep_wrapper(__devm_regmap_init_i2c, #config, \
  745. i2c, config)
  746. /**
  747. * devm_regmap_init_spi() - Initialise register map
  748. *
  749. * @dev: Device that will be interacted with
  750. * @config: Configuration for register map
  751. *
  752. * The return value will be an ERR_PTR() on error or a valid pointer
  753. * to a struct regmap. The map will be automatically freed by the
  754. * device management code.
  755. */
  756. #define devm_regmap_init_spi(dev, config) \
  757. __regmap_lockdep_wrapper(__devm_regmap_init_spi, #config, \
  758. dev, config)
  759. /**
  760. * devm_regmap_init_spmi_base() - Create managed regmap for Base register space
  761. *
  762. * @dev: SPMI device that will be interacted with
  763. * @config: Configuration for register map
  764. *
  765. * The return value will be an ERR_PTR() on error or a valid pointer
  766. * to a struct regmap. The regmap will be automatically freed by the
  767. * device management code.
  768. */
  769. #define devm_regmap_init_spmi_base(dev, config) \
  770. __regmap_lockdep_wrapper(__devm_regmap_init_spmi_base, #config, \
  771. dev, config)
  772. /**
  773. * devm_regmap_init_spmi_ext() - Create managed regmap for Ext register space
  774. *
  775. * @dev: SPMI device that will be interacted with
  776. * @config: Configuration for register map
  777. *
  778. * The return value will be an ERR_PTR() on error or a valid pointer
  779. * to a struct regmap. The regmap will be automatically freed by the
  780. * device management code.
  781. */
  782. #define devm_regmap_init_spmi_ext(dev, config) \
  783. __regmap_lockdep_wrapper(__devm_regmap_init_spmi_ext, #config, \
  784. dev, config)
  785. /**
  786. * devm_regmap_init_w1() - Initialise managed register map
  787. *
  788. * @w1_dev: Device that will be interacted with
  789. * @config: Configuration for register map
  790. *
  791. * The return value will be an ERR_PTR() on error or a valid pointer
  792. * to a struct regmap. The regmap will be automatically freed by the
  793. * device management code.
  794. */
  795. #define devm_regmap_init_w1(w1_dev, config) \
  796. __regmap_lockdep_wrapper(__devm_regmap_init_w1, #config, \
  797. w1_dev, config)
  798. /**
  799. * devm_regmap_init_mmio_clk() - Initialise managed register map with clock
  800. *
  801. * @dev: Device that will be interacted with
  802. * @clk_id: register clock consumer ID
  803. * @regs: Pointer to memory-mapped IO region
  804. * @config: Configuration for register map
  805. *
  806. * The return value will be an ERR_PTR() on error or a valid pointer
  807. * to a struct regmap. The regmap will be automatically freed by the
  808. * device management code.
  809. */
  810. #define devm_regmap_init_mmio_clk(dev, clk_id, regs, config) \
  811. __regmap_lockdep_wrapper(__devm_regmap_init_mmio_clk, #config, \
  812. dev, clk_id, regs, config)
  813. /**
  814. * devm_regmap_init_mmio() - Initialise managed register map
  815. *
  816. * @dev: Device that will be interacted with
  817. * @regs: Pointer to memory-mapped IO region
  818. * @config: Configuration for register map
  819. *
  820. * The return value will be an ERR_PTR() on error or a valid pointer
  821. * to a struct regmap. The regmap will be automatically freed by the
  822. * device management code.
  823. */
  824. #define devm_regmap_init_mmio(dev, regs, config) \
  825. devm_regmap_init_mmio_clk(dev, NULL, regs, config)
  826. /**
  827. * devm_regmap_init_ac97() - Initialise AC'97 register map
  828. *
  829. * @ac97: Device that will be interacted with
  830. * @config: Configuration for register map
  831. *
  832. * The return value will be an ERR_PTR() on error or a valid pointer
  833. * to a struct regmap. The regmap will be automatically freed by the
  834. * device management code.
  835. */
  836. #define devm_regmap_init_ac97(ac97, config) \
  837. __regmap_lockdep_wrapper(__devm_regmap_init_ac97, #config, \
  838. ac97, config)
  839. /**
  840. * devm_regmap_init_sdw() - Initialise managed register map
  841. *
  842. * @sdw: Device that will be interacted with
  843. * @config: Configuration for register map
  844. *
  845. * The return value will be an ERR_PTR() on error or a valid pointer
  846. * to a struct regmap. The regmap will be automatically freed by the
  847. * device management code.
  848. */
  849. #define devm_regmap_init_sdw(sdw, config) \
  850. __regmap_lockdep_wrapper(__devm_regmap_init_sdw, #config, \
  851. sdw, config)
  852. /**
  853. * devm_regmap_init_slimbus() - Initialise managed register map
  854. *
  855. * @slimbus: Device that will be interacted with
  856. * @config: Configuration for register map
  857. *
  858. * The return value will be an ERR_PTR() on error or a valid pointer
  859. * to a struct regmap. The regmap will be automatically freed by the
  860. * device management code.
  861. */
  862. #define devm_regmap_init_slimbus(slimbus, config) \
  863. __regmap_lockdep_wrapper(__devm_regmap_init_slimbus, #config, \
  864. slimbus, config)
  865. int regmap_mmio_attach_clk(struct regmap *map, struct clk *clk);
  866. void regmap_mmio_detach_clk(struct regmap *map);
  867. void regmap_exit(struct regmap *map);
  868. int regmap_reinit_cache(struct regmap *map,
  869. const struct regmap_config *config);
  870. struct regmap *dev_get_regmap(struct device *dev, const char *name);
  871. struct device *regmap_get_device(struct regmap *map);
  872. int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
  873. int regmap_write_async(struct regmap *map, unsigned int reg, unsigned int val);
  874. int regmap_raw_write(struct regmap *map, unsigned int reg,
  875. const void *val, size_t val_len);
  876. int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
  877. size_t val_count);
  878. int regmap_multi_reg_write(struct regmap *map, const struct reg_sequence *regs,
  879. int num_regs);
  880. int regmap_multi_reg_write_bypassed(struct regmap *map,
  881. const struct reg_sequence *regs,
  882. int num_regs);
  883. int regmap_raw_write_async(struct regmap *map, unsigned int reg,
  884. const void *val, size_t val_len);
  885. int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
  886. int regmap_raw_read(struct regmap *map, unsigned int reg,
  887. void *val, size_t val_len);
  888. int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
  889. size_t val_count);
  890. int regmap_update_bits_base(struct regmap *map, unsigned int reg,
  891. unsigned int mask, unsigned int val,
  892. bool *change, bool async, bool force);
  893. int regmap_get_val_bytes(struct regmap *map);
  894. int regmap_get_max_register(struct regmap *map);
  895. int regmap_get_reg_stride(struct regmap *map);
  896. int regmap_async_complete(struct regmap *map);
  897. bool regmap_can_raw_write(struct regmap *map);
  898. size_t regmap_get_raw_read_max(struct regmap *map);
  899. size_t regmap_get_raw_write_max(struct regmap *map);
  900. int regcache_sync(struct regmap *map);
  901. int regcache_sync_region(struct regmap *map, unsigned int min,
  902. unsigned int max);
  903. int regcache_drop_region(struct regmap *map, unsigned int min,
  904. unsigned int max);
  905. void regcache_cache_only(struct regmap *map, bool enable);
  906. void regcache_cache_bypass(struct regmap *map, bool enable);
  907. void regcache_mark_dirty(struct regmap *map);
  908. bool regmap_check_range_table(struct regmap *map, unsigned int reg,
  909. const struct regmap_access_table *table);
  910. int regmap_register_patch(struct regmap *map, const struct reg_sequence *regs,
  911. int num_regs);
  912. int regmap_parse_val(struct regmap *map, const void *buf,
  913. unsigned int *val);
  914. static inline bool regmap_reg_in_range(unsigned int reg,
  915. const struct regmap_range *range)
  916. {
  917. return reg >= range->range_min && reg <= range->range_max;
  918. }
  919. bool regmap_reg_in_ranges(unsigned int reg,
  920. const struct regmap_range *ranges,
  921. unsigned int nranges);
  922. /**
  923. * struct reg_field - Description of an register field
  924. *
  925. * @reg: Offset of the register within the regmap bank
  926. * @lsb: lsb of the register field.
  927. * @msb: msb of the register field.
  928. * @id_size: port size if it has some ports
  929. * @id_offset: address offset for each ports
  930. */
  931. struct reg_field {
  932. unsigned int reg;
  933. unsigned int lsb;
  934. unsigned int msb;
  935. unsigned int id_size;
  936. unsigned int id_offset;
  937. };
  938. #define REG_FIELD(_reg, _lsb, _msb) { \
  939. .reg = _reg, \
  940. .lsb = _lsb, \
  941. .msb = _msb, \
  942. }
  943. struct regmap_field *regmap_field_alloc(struct regmap *regmap,
  944. struct reg_field reg_field);
  945. void regmap_field_free(struct regmap_field *field);
  946. struct regmap_field *devm_regmap_field_alloc(struct device *dev,
  947. struct regmap *regmap, struct reg_field reg_field);
  948. void devm_regmap_field_free(struct device *dev, struct regmap_field *field);
  949. int regmap_field_read(struct regmap_field *field, unsigned int *val);
  950. int regmap_field_update_bits_base(struct regmap_field *field,
  951. unsigned int mask, unsigned int val,
  952. bool *change, bool async, bool force);
  953. int regmap_fields_read(struct regmap_field *field, unsigned int id,
  954. unsigned int *val);
  955. int regmap_fields_update_bits_base(struct regmap_field *field, unsigned int id,
  956. unsigned int mask, unsigned int val,
  957. bool *change, bool async, bool force);
  958. /**
  959. * struct regmap_irq - Description of an IRQ for the generic regmap irq_chip.
  960. *
  961. * @reg_offset: Offset of the status/mask register within the bank
  962. * @mask: Mask used to flag/control the register.
  963. * @type_reg_offset: Offset register for the irq type setting.
  964. * @type_rising_mask: Mask bit to configure RISING type irq.
  965. * @type_falling_mask: Mask bit to configure FALLING type irq.
  966. */
  967. struct regmap_irq {
  968. unsigned int reg_offset;
  969. unsigned int mask;
  970. unsigned int type_reg_offset;
  971. unsigned int type_rising_mask;
  972. unsigned int type_falling_mask;
  973. };
  974. #define REGMAP_IRQ_REG(_irq, _off, _mask) \
  975. [_irq] = { .reg_offset = (_off), .mask = (_mask) }
  976. /**
  977. * struct regmap_irq_chip - Description of a generic regmap irq_chip.
  978. *
  979. * @name: Descriptive name for IRQ controller.
  980. *
  981. * @status_base: Base status register address.
  982. * @mask_base: Base mask register address.
  983. * @mask_writeonly: Base mask register is write only.
  984. * @unmask_base: Base unmask register address. for chips who have
  985. * separate mask and unmask registers
  986. * @ack_base: Base ack address. If zero then the chip is clear on read.
  987. * Using zero value is possible with @use_ack bit.
  988. * @wake_base: Base address for wake enables. If zero unsupported.
  989. * @type_base: Base address for irq type. If zero unsupported.
  990. * @irq_reg_stride: Stride to use for chips where registers are not contiguous.
  991. * @init_ack_masked: Ack all masked interrupts once during initalization.
  992. * @mask_invert: Inverted mask register: cleared bits are masked out.
  993. * @use_ack: Use @ack register even if it is zero.
  994. * @ack_invert: Inverted ack register: cleared bits for ack.
  995. * @wake_invert: Inverted wake register: cleared bits are wake enabled.
  996. * @type_invert: Invert the type flags.
  997. * @runtime_pm: Hold a runtime PM lock on the device when accessing it.
  998. *
  999. * @num_regs: Number of registers in each control bank.
  1000. * @irqs: Descriptors for individual IRQs. Interrupt numbers are
  1001. * assigned based on the index in the array of the interrupt.
  1002. * @num_irqs: Number of descriptors.
  1003. * @num_type_reg: Number of type registers.
  1004. * @type_reg_stride: Stride to use for chips where type registers are not
  1005. * contiguous.
  1006. * @handle_pre_irq: Driver specific callback to handle interrupt from device
  1007. * before regmap_irq_handler process the interrupts.
  1008. * @handle_post_irq: Driver specific callback to handle interrupt from device
  1009. * after handling the interrupts in regmap_irq_handler().
  1010. * @irq_drv_data: Driver specific IRQ data which is passed as parameter when
  1011. * driver specific pre/post interrupt handler is called.
  1012. *
  1013. * This is not intended to handle every possible interrupt controller, but
  1014. * it should handle a substantial proportion of those that are found in the
  1015. * wild.
  1016. */
  1017. struct regmap_irq_chip {
  1018. const char *name;
  1019. unsigned int status_base;
  1020. unsigned int mask_base;
  1021. unsigned int unmask_base;
  1022. unsigned int ack_base;
  1023. unsigned int wake_base;
  1024. unsigned int type_base;
  1025. unsigned int irq_reg_stride;
  1026. bool mask_writeonly:1;
  1027. bool init_ack_masked:1;
  1028. bool mask_invert:1;
  1029. bool use_ack:1;
  1030. bool ack_invert:1;
  1031. bool wake_invert:1;
  1032. bool runtime_pm:1;
  1033. bool type_invert:1;
  1034. int num_regs;
  1035. const struct regmap_irq *irqs;
  1036. int num_irqs;
  1037. int num_type_reg;
  1038. unsigned int type_reg_stride;
  1039. int (*handle_pre_irq)(void *irq_drv_data);
  1040. int (*handle_post_irq)(void *irq_drv_data);
  1041. void *irq_drv_data;
  1042. };
  1043. struct regmap_irq_chip_data;
  1044. int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
  1045. int irq_base, const struct regmap_irq_chip *chip,
  1046. struct regmap_irq_chip_data **data);
  1047. void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data);
  1048. int devm_regmap_add_irq_chip(struct device *dev, struct regmap *map, int irq,
  1049. int irq_flags, int irq_base,
  1050. const struct regmap_irq_chip *chip,
  1051. struct regmap_irq_chip_data **data);
  1052. void devm_regmap_del_irq_chip(struct device *dev, int irq,
  1053. struct regmap_irq_chip_data *data);
  1054. int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data);
  1055. int regmap_irq_get_virq(struct regmap_irq_chip_data *data, int irq);
  1056. struct irq_domain *regmap_irq_get_domain(struct regmap_irq_chip_data *data);
  1057. #else
  1058. /*
  1059. * These stubs should only ever be called by generic code which has
  1060. * regmap based facilities, if they ever get called at runtime
  1061. * something is going wrong and something probably needs to select
  1062. * REGMAP.
  1063. */
  1064. static inline int regmap_write(struct regmap *map, unsigned int reg,
  1065. unsigned int val)
  1066. {
  1067. WARN_ONCE(1, "regmap API is disabled");
  1068. return -EINVAL;
  1069. }
  1070. static inline int regmap_write_async(struct regmap *map, unsigned int reg,
  1071. unsigned int val)
  1072. {
  1073. WARN_ONCE(1, "regmap API is disabled");
  1074. return -EINVAL;
  1075. }
  1076. static inline int regmap_raw_write(struct regmap *map, unsigned int reg,
  1077. const void *val, size_t val_len)
  1078. {
  1079. WARN_ONCE(1, "regmap API is disabled");
  1080. return -EINVAL;
  1081. }
  1082. static inline int regmap_raw_write_async(struct regmap *map, unsigned int reg,
  1083. const void *val, size_t val_len)
  1084. {
  1085. WARN_ONCE(1, "regmap API is disabled");
  1086. return -EINVAL;
  1087. }
  1088. static inline int regmap_bulk_write(struct regmap *map, unsigned int reg,
  1089. const void *val, size_t val_count)
  1090. {
  1091. WARN_ONCE(1, "regmap API is disabled");
  1092. return -EINVAL;
  1093. }
  1094. static inline int regmap_read(struct regmap *map, unsigned int reg,
  1095. unsigned int *val)
  1096. {
  1097. WARN_ONCE(1, "regmap API is disabled");
  1098. return -EINVAL;
  1099. }
  1100. static inline int regmap_raw_read(struct regmap *map, unsigned int reg,
  1101. void *val, size_t val_len)
  1102. {
  1103. WARN_ONCE(1, "regmap API is disabled");
  1104. return -EINVAL;
  1105. }
  1106. static inline int regmap_bulk_read(struct regmap *map, unsigned int reg,
  1107. void *val, size_t val_count)
  1108. {
  1109. WARN_ONCE(1, "regmap API is disabled");
  1110. return -EINVAL;
  1111. }
  1112. static inline int regmap_update_bits_base(struct regmap *map, unsigned int reg,
  1113. unsigned int mask, unsigned int val,
  1114. bool *change, bool async, bool force)
  1115. {
  1116. WARN_ONCE(1, "regmap API is disabled");
  1117. return -EINVAL;
  1118. }
  1119. static inline int regmap_field_update_bits_base(struct regmap_field *field,
  1120. unsigned int mask, unsigned int val,
  1121. bool *change, bool async, bool force)
  1122. {
  1123. WARN_ONCE(1, "regmap API is disabled");
  1124. return -EINVAL;
  1125. }
  1126. static inline int regmap_fields_update_bits_base(struct regmap_field *field,
  1127. unsigned int id,
  1128. unsigned int mask, unsigned int val,
  1129. bool *change, bool async, bool force)
  1130. {
  1131. WARN_ONCE(1, "regmap API is disabled");
  1132. return -EINVAL;
  1133. }
  1134. static inline int regmap_get_val_bytes(struct regmap *map)
  1135. {
  1136. WARN_ONCE(1, "regmap API is disabled");
  1137. return -EINVAL;
  1138. }
  1139. static inline int regmap_get_max_register(struct regmap *map)
  1140. {
  1141. WARN_ONCE(1, "regmap API is disabled");
  1142. return -EINVAL;
  1143. }
  1144. static inline int regmap_get_reg_stride(struct regmap *map)
  1145. {
  1146. WARN_ONCE(1, "regmap API is disabled");
  1147. return -EINVAL;
  1148. }
  1149. static inline int regcache_sync(struct regmap *map)
  1150. {
  1151. WARN_ONCE(1, "regmap API is disabled");
  1152. return -EINVAL;
  1153. }
  1154. static inline int regcache_sync_region(struct regmap *map, unsigned int min,
  1155. unsigned int max)
  1156. {
  1157. WARN_ONCE(1, "regmap API is disabled");
  1158. return -EINVAL;
  1159. }
  1160. static inline int regcache_drop_region(struct regmap *map, unsigned int min,
  1161. unsigned int max)
  1162. {
  1163. WARN_ONCE(1, "regmap API is disabled");
  1164. return -EINVAL;
  1165. }
  1166. static inline void regcache_cache_only(struct regmap *map, bool enable)
  1167. {
  1168. WARN_ONCE(1, "regmap API is disabled");
  1169. }
  1170. static inline void regcache_cache_bypass(struct regmap *map, bool enable)
  1171. {
  1172. WARN_ONCE(1, "regmap API is disabled");
  1173. }
  1174. static inline void regcache_mark_dirty(struct regmap *map)
  1175. {
  1176. WARN_ONCE(1, "regmap API is disabled");
  1177. }
  1178. static inline void regmap_async_complete(struct regmap *map)
  1179. {
  1180. WARN_ONCE(1, "regmap API is disabled");
  1181. }
  1182. static inline int regmap_register_patch(struct regmap *map,
  1183. const struct reg_sequence *regs,
  1184. int num_regs)
  1185. {
  1186. WARN_ONCE(1, "regmap API is disabled");
  1187. return -EINVAL;
  1188. }
  1189. static inline int regmap_parse_val(struct regmap *map, const void *buf,
  1190. unsigned int *val)
  1191. {
  1192. WARN_ONCE(1, "regmap API is disabled");
  1193. return -EINVAL;
  1194. }
  1195. static inline struct regmap *dev_get_regmap(struct device *dev,
  1196. const char *name)
  1197. {
  1198. return NULL;
  1199. }
  1200. static inline struct device *regmap_get_device(struct regmap *map)
  1201. {
  1202. WARN_ONCE(1, "regmap API is disabled");
  1203. return NULL;
  1204. }
  1205. #endif
  1206. #endif