regmap.h 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. #ifndef __LINUX_REGMAP_H
  3. #define __LINUX_REGMAP_H
  4. /*
  5. * Register map access API
  6. *
  7. * Copyright 2011 Wolfson Microelectronics plc
  8. *
  9. * Author: Mark Brown <[email protected]>
  10. */
  11. #include <linux/list.h>
  12. #include <linux/rbtree.h>
  13. #include <linux/ktime.h>
  14. #include <linux/delay.h>
  15. #include <linux/err.h>
  16. #include <linux/bug.h>
  17. #include <linux/lockdep.h>
  18. #include <linux/iopoll.h>
  19. #include <linux/fwnode.h>
  20. #include <linux/android_kabi.h>
  21. struct module;
  22. struct clk;
  23. struct device;
  24. struct device_node;
  25. struct i2c_client;
  26. struct i3c_device;
  27. struct irq_domain;
  28. struct mdio_device;
  29. struct slim_device;
  30. struct spi_device;
  31. struct spmi_device;
  32. struct regmap;
  33. struct regmap_range_cfg;
  34. struct regmap_field;
  35. struct snd_ac97;
  36. struct sdw_slave;
  37. /* An enum of all the supported cache types */
  38. enum regcache_type {
  39. REGCACHE_NONE,
  40. REGCACHE_RBTREE,
  41. REGCACHE_COMPRESSED,
  42. REGCACHE_FLAT,
  43. };
  44. /**
  45. * struct reg_default - Default value for a register.
  46. *
  47. * @reg: Register address.
  48. * @def: Register default value.
  49. *
  50. * We use an array of structs rather than a simple array as many modern devices
  51. * have very sparse register maps.
  52. */
  53. struct reg_default {
  54. unsigned int reg;
  55. unsigned int def;
  56. };
  57. /**
  58. * struct reg_sequence - An individual write from a sequence of writes.
  59. *
  60. * @reg: Register address.
  61. * @def: Register value.
  62. * @delay_us: Delay to be applied after the register write in microseconds
  63. *
  64. * Register/value pairs for sequences of writes with an optional delay in
  65. * microseconds to be applied after each write.
  66. */
  67. struct reg_sequence {
  68. unsigned int reg;
  69. unsigned int def;
  70. unsigned int delay_us;
  71. };
  72. #define REG_SEQ(_reg, _def, _delay_us) { \
  73. .reg = _reg, \
  74. .def = _def, \
  75. .delay_us = _delay_us, \
  76. }
  77. #define REG_SEQ0(_reg, _def) REG_SEQ(_reg, _def, 0)
  78. /**
  79. * regmap_read_poll_timeout - Poll until a condition is met or a timeout occurs
  80. *
  81. * @map: Regmap to read from
  82. * @addr: Address to poll
  83. * @val: Unsigned integer variable to read the value into
  84. * @cond: Break condition (usually involving @val)
  85. * @sleep_us: Maximum time to sleep between reads in us (0
  86. * tight-loops). Should be less than ~20ms since usleep_range
  87. * is used (see Documentation/timers/timers-howto.rst).
  88. * @timeout_us: Timeout in us, 0 means never timeout
  89. *
  90. * Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_read
  91. * error return value in case of a error read. In the two former cases,
  92. * the last read value at @addr is stored in @val. Must not be called
  93. * from atomic context if sleep_us or timeout_us are used.
  94. *
  95. * This is modelled after the readx_poll_timeout macros in linux/iopoll.h.
  96. */
  97. #define regmap_read_poll_timeout(map, addr, val, cond, sleep_us, timeout_us) \
  98. ({ \
  99. int __ret, __tmp; \
  100. __tmp = read_poll_timeout(regmap_read, __ret, __ret || (cond), \
  101. sleep_us, timeout_us, false, (map), (addr), &(val)); \
  102. __ret ?: __tmp; \
  103. })
  104. /**
  105. * regmap_read_poll_timeout_atomic - Poll until a condition is met or a timeout occurs
  106. *
  107. * @map: Regmap to read from
  108. * @addr: Address to poll
  109. * @val: Unsigned integer variable to read the value into
  110. * @cond: Break condition (usually involving @val)
  111. * @delay_us: Time to udelay between reads in us (0 tight-loops).
  112. * Should be less than ~10us since udelay is used
  113. * (see Documentation/timers/timers-howto.rst).
  114. * @timeout_us: Timeout in us, 0 means never timeout
  115. *
  116. * Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_read
  117. * error return value in case of a error read. In the two former cases,
  118. * the last read value at @addr is stored in @val.
  119. *
  120. * This is modelled after the readx_poll_timeout_atomic macros in linux/iopoll.h.
  121. *
  122. * Note: In general regmap cannot be used in atomic context. If you want to use
  123. * this macro then first setup your regmap for atomic use (flat or no cache
  124. * and MMIO regmap).
  125. */
  126. #define regmap_read_poll_timeout_atomic(map, addr, val, cond, delay_us, timeout_us) \
  127. ({ \
  128. u64 __timeout_us = (timeout_us); \
  129. unsigned long __delay_us = (delay_us); \
  130. ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \
  131. int __ret; \
  132. for (;;) { \
  133. __ret = regmap_read((map), (addr), &(val)); \
  134. if (__ret) \
  135. break; \
  136. if (cond) \
  137. break; \
  138. if ((__timeout_us) && \
  139. ktime_compare(ktime_get(), __timeout) > 0) { \
  140. __ret = regmap_read((map), (addr), &(val)); \
  141. break; \
  142. } \
  143. if (__delay_us) \
  144. udelay(__delay_us); \
  145. } \
  146. __ret ?: ((cond) ? 0 : -ETIMEDOUT); \
  147. })
  148. /**
  149. * regmap_field_read_poll_timeout - Poll until a condition is met or timeout
  150. *
  151. * @field: Regmap field to read from
  152. * @val: Unsigned integer variable to read the value into
  153. * @cond: Break condition (usually involving @val)
  154. * @sleep_us: Maximum time to sleep between reads in us (0
  155. * tight-loops). Should be less than ~20ms since usleep_range
  156. * is used (see Documentation/timers/timers-howto.rst).
  157. * @timeout_us: Timeout in us, 0 means never timeout
  158. *
  159. * Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_field_read
  160. * error return value in case of a error read. In the two former cases,
  161. * the last read value at @addr is stored in @val. Must not be called
  162. * from atomic context if sleep_us or timeout_us are used.
  163. *
  164. * This is modelled after the readx_poll_timeout macros in linux/iopoll.h.
  165. */
  166. #define regmap_field_read_poll_timeout(field, val, cond, sleep_us, timeout_us) \
  167. ({ \
  168. int __ret, __tmp; \
  169. __tmp = read_poll_timeout(regmap_field_read, __ret, __ret || (cond), \
  170. sleep_us, timeout_us, false, (field), &(val)); \
  171. __ret ?: __tmp; \
  172. })
  173. #ifdef CONFIG_REGMAP
  174. enum regmap_endian {
  175. /* Unspecified -> 0 -> Backwards compatible default */
  176. REGMAP_ENDIAN_DEFAULT = 0,
  177. REGMAP_ENDIAN_BIG,
  178. REGMAP_ENDIAN_LITTLE,
  179. REGMAP_ENDIAN_NATIVE,
  180. };
  181. /**
  182. * struct regmap_range - A register range, used for access related checks
  183. * (readable/writeable/volatile/precious checks)
  184. *
  185. * @range_min: address of first register
  186. * @range_max: address of last register
  187. */
  188. struct regmap_range {
  189. unsigned int range_min;
  190. unsigned int range_max;
  191. };
  192. #define regmap_reg_range(low, high) { .range_min = low, .range_max = high, }
  193. /**
  194. * struct regmap_access_table - A table of register ranges for access checks
  195. *
  196. * @yes_ranges : pointer to an array of regmap ranges used as "yes ranges"
  197. * @n_yes_ranges: size of the above array
  198. * @no_ranges: pointer to an array of regmap ranges used as "no ranges"
  199. * @n_no_ranges: size of the above array
  200. *
  201. * A table of ranges including some yes ranges and some no ranges.
  202. * If a register belongs to a no_range, the corresponding check function
  203. * will return false. If a register belongs to a yes range, the corresponding
  204. * check function will return true. "no_ranges" are searched first.
  205. */
  206. struct regmap_access_table {
  207. const struct regmap_range *yes_ranges;
  208. unsigned int n_yes_ranges;
  209. const struct regmap_range *no_ranges;
  210. unsigned int n_no_ranges;
  211. };
  212. typedef void (*regmap_lock)(void *);
  213. typedef void (*regmap_unlock)(void *);
  214. /**
  215. * struct regmap_config - Configuration for the register map of a device.
  216. *
  217. * @name: Optional name of the regmap. Useful when a device has multiple
  218. * register regions.
  219. *
  220. * @reg_bits: Number of bits in a register address, mandatory.
  221. * @reg_stride: The register address stride. Valid register addresses are a
  222. * multiple of this value. If set to 0, a value of 1 will be
  223. * used.
  224. * @reg_downshift: The number of bits to downshift the register before
  225. * performing any operations.
  226. * @reg_base: Value to be added to every register address before performing any
  227. * operation.
  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. * @writeable_noinc_reg: Optional callback returning true if the register
  253. * supports multiple write operations without incrementing
  254. * the register number. If this field is NULL but
  255. * wr_noinc_table (see below) is not, the check is
  256. * performed on such table (a register is no increment
  257. * writeable if it belongs to one of the ranges specified
  258. * by wr_noinc_table).
  259. * @readable_noinc_reg: Optional callback returning true if the register
  260. * supports multiple read operations without incrementing
  261. * the register number. If this field is NULL but
  262. * rd_noinc_table (see below) is not, the check is
  263. * performed on such table (a register is no increment
  264. * readable if it belongs to one of the ranges specified
  265. * by rd_noinc_table).
  266. * @disable_locking: This regmap is either protected by external means or
  267. * is guaranteed not to be accessed from multiple threads.
  268. * Don't use any locking mechanisms.
  269. * @lock: Optional lock callback (overrides regmap's default lock
  270. * function, based on spinlock or mutex).
  271. * @unlock: As above for unlocking.
  272. * @lock_arg: this field is passed as the only argument of lock/unlock
  273. * functions (ignored in case regular lock/unlock functions
  274. * are not overridden).
  275. * @reg_read: Optional callback that if filled will be used to perform
  276. * all the reads from the registers. Should only be provided for
  277. * devices whose read operation cannot be represented as a simple
  278. * read operation on a bus such as SPI, I2C, etc. Most of the
  279. * devices do not need this.
  280. * @reg_write: Same as above for writing.
  281. * @reg_update_bits: Optional callback that if filled will be used to perform
  282. * all the update_bits(rmw) operation. Should only be provided
  283. * if the function require special handling with lock and reg
  284. * handling and the operation cannot be represented as a simple
  285. * update_bits operation on a bus such as SPI, I2C, etc.
  286. * @read: Optional callback that if filled will be used to perform all the
  287. * bulk reads from the registers. Data is returned in the buffer used
  288. * to transmit data.
  289. * @write: Same as above for writing.
  290. * @max_raw_read: Max raw read size that can be used on the device.
  291. * @max_raw_write: Max raw write size that can be used on the device.
  292. * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
  293. * to perform locking. This field is ignored if custom lock/unlock
  294. * functions are used (see fields lock/unlock of struct regmap_config).
  295. * This field is a duplicate of a similar file in
  296. * 'struct regmap_bus' and serves exact same purpose.
  297. * Use it only for "no-bus" cases.
  298. * @io_port: Support IO port accessors. Makes sense only when MMIO vs. IO port
  299. * access can be distinguished.
  300. * @max_register: Optional, specifies the maximum valid register address.
  301. * @wr_table: Optional, points to a struct regmap_access_table specifying
  302. * valid ranges for write access.
  303. * @rd_table: As above, for read access.
  304. * @volatile_table: As above, for volatile registers.
  305. * @precious_table: As above, for precious registers.
  306. * @wr_noinc_table: As above, for no increment writeable registers.
  307. * @rd_noinc_table: As above, for no increment readable registers.
  308. * @reg_defaults: Power on reset values for registers (for use with
  309. * register cache support).
  310. * @num_reg_defaults: Number of elements in reg_defaults.
  311. *
  312. * @read_flag_mask: Mask to be set in the top bytes of the register when doing
  313. * a read.
  314. * @write_flag_mask: Mask to be set in the top bytes of the register when doing
  315. * a write. If both read_flag_mask and write_flag_mask are
  316. * empty and zero_flag_mask is not set the regmap_bus default
  317. * masks are used.
  318. * @zero_flag_mask: If set, read_flag_mask and write_flag_mask are used even
  319. * if they are both empty.
  320. * @use_relaxed_mmio: If set, MMIO R/W operations will not use memory barriers.
  321. * This can avoid load on devices which don't require strict
  322. * orderings, but drivers should carefully add any explicit
  323. * memory barriers when they may require them.
  324. * @use_single_read: If set, converts the bulk read operation into a series of
  325. * single read operations. This is useful for a device that
  326. * does not support bulk read.
  327. * @use_single_write: If set, converts the bulk write operation into a series of
  328. * single write operations. This is useful for a device that
  329. * does not support bulk write.
  330. * @can_multi_write: If set, the device supports the multi write mode of bulk
  331. * write operations, if clear multi write requests will be
  332. * split into individual write operations
  333. *
  334. * @cache_type: The actual cache type.
  335. * @reg_defaults_raw: Power on reset values for registers (for use with
  336. * register cache support).
  337. * @num_reg_defaults_raw: Number of elements in reg_defaults_raw.
  338. * @reg_format_endian: Endianness for formatted register addresses. If this is
  339. * DEFAULT, the @reg_format_endian_default value from the
  340. * regmap bus is used.
  341. * @val_format_endian: Endianness for formatted register values. If this is
  342. * DEFAULT, the @reg_format_endian_default value from the
  343. * regmap bus is used.
  344. *
  345. * @ranges: Array of configuration entries for virtual address ranges.
  346. * @num_ranges: Number of range configuration entries.
  347. * @use_hwlock: Indicate if a hardware spinlock should be used.
  348. * @use_raw_spinlock: Indicate if a raw spinlock should be used.
  349. * @hwlock_id: Specify the hardware spinlock id.
  350. * @hwlock_mode: The hardware spinlock mode, should be HWLOCK_IRQSTATE,
  351. * HWLOCK_IRQ or 0.
  352. * @can_sleep: Optional, specifies whether regmap operations can sleep.
  353. */
  354. struct regmap_config {
  355. const char *name;
  356. int reg_bits;
  357. int reg_stride;
  358. int reg_downshift;
  359. unsigned int reg_base;
  360. int pad_bits;
  361. int val_bits;
  362. bool (*writeable_reg)(struct device *dev, unsigned int reg);
  363. bool (*readable_reg)(struct device *dev, unsigned int reg);
  364. bool (*volatile_reg)(struct device *dev, unsigned int reg);
  365. bool (*precious_reg)(struct device *dev, unsigned int reg);
  366. bool (*writeable_noinc_reg)(struct device *dev, unsigned int reg);
  367. bool (*readable_noinc_reg)(struct device *dev, unsigned int reg);
  368. bool disable_locking;
  369. regmap_lock lock;
  370. regmap_unlock unlock;
  371. void *lock_arg;
  372. int (*reg_read)(void *context, unsigned int reg, unsigned int *val);
  373. int (*reg_write)(void *context, unsigned int reg, unsigned int val);
  374. int (*reg_update_bits)(void *context, unsigned int reg,
  375. unsigned int mask, unsigned int val);
  376. /* Bulk read/write */
  377. int (*read)(void *context, const void *reg_buf, size_t reg_size,
  378. void *val_buf, size_t val_size);
  379. int (*write)(void *context, const void *data, size_t count);
  380. size_t max_raw_read;
  381. size_t max_raw_write;
  382. bool fast_io;
  383. bool io_port;
  384. unsigned int max_register;
  385. const struct regmap_access_table *wr_table;
  386. const struct regmap_access_table *rd_table;
  387. const struct regmap_access_table *volatile_table;
  388. const struct regmap_access_table *precious_table;
  389. const struct regmap_access_table *wr_noinc_table;
  390. const struct regmap_access_table *rd_noinc_table;
  391. const struct reg_default *reg_defaults;
  392. unsigned int num_reg_defaults;
  393. enum regcache_type cache_type;
  394. const void *reg_defaults_raw;
  395. unsigned int num_reg_defaults_raw;
  396. unsigned long read_flag_mask;
  397. unsigned long write_flag_mask;
  398. bool zero_flag_mask;
  399. bool use_single_read;
  400. bool use_single_write;
  401. bool use_relaxed_mmio;
  402. bool can_multi_write;
  403. enum regmap_endian reg_format_endian;
  404. enum regmap_endian val_format_endian;
  405. const struct regmap_range_cfg *ranges;
  406. unsigned int num_ranges;
  407. bool use_hwlock;
  408. bool use_raw_spinlock;
  409. unsigned int hwlock_id;
  410. unsigned int hwlock_mode;
  411. bool can_sleep;
  412. ANDROID_KABI_RESERVE(1);
  413. };
  414. /**
  415. * struct regmap_range_cfg - Configuration for indirectly accessed or paged
  416. * registers.
  417. *
  418. * @name: Descriptive name for diagnostics
  419. *
  420. * @range_min: Address of the lowest register address in virtual range.
  421. * @range_max: Address of the highest register in virtual range.
  422. *
  423. * @selector_reg: Register with selector field.
  424. * @selector_mask: Bit mask for selector value.
  425. * @selector_shift: Bit shift for selector value.
  426. *
  427. * @window_start: Address of first (lowest) register in data window.
  428. * @window_len: Number of registers in data window.
  429. *
  430. * Registers, mapped to this virtual range, are accessed in two steps:
  431. * 1. page selector register update;
  432. * 2. access through data window registers.
  433. */
  434. struct regmap_range_cfg {
  435. const char *name;
  436. /* Registers of virtual address range */
  437. unsigned int range_min;
  438. unsigned int range_max;
  439. /* Page selector for indirect addressing */
  440. unsigned int selector_reg;
  441. unsigned int selector_mask;
  442. int selector_shift;
  443. /* Data window (per each page) */
  444. unsigned int window_start;
  445. unsigned int window_len;
  446. ANDROID_KABI_RESERVE(1);
  447. };
  448. struct regmap_async;
  449. typedef int (*regmap_hw_write)(void *context, const void *data,
  450. size_t count);
  451. typedef int (*regmap_hw_gather_write)(void *context,
  452. const void *reg, size_t reg_len,
  453. const void *val, size_t val_len);
  454. typedef int (*regmap_hw_async_write)(void *context,
  455. const void *reg, size_t reg_len,
  456. const void *val, size_t val_len,
  457. struct regmap_async *async);
  458. typedef int (*regmap_hw_read)(void *context,
  459. const void *reg_buf, size_t reg_size,
  460. void *val_buf, size_t val_size);
  461. typedef int (*regmap_hw_reg_read)(void *context, unsigned int reg,
  462. unsigned int *val);
  463. typedef int (*regmap_hw_reg_noinc_read)(void *context, unsigned int reg,
  464. void *val, size_t val_count);
  465. typedef int (*regmap_hw_reg_write)(void *context, unsigned int reg,
  466. unsigned int val);
  467. typedef int (*regmap_hw_reg_noinc_write)(void *context, unsigned int reg,
  468. const void *val, size_t val_count);
  469. typedef int (*regmap_hw_reg_update_bits)(void *context, unsigned int reg,
  470. unsigned int mask, unsigned int val);
  471. typedef struct regmap_async *(*regmap_hw_async_alloc)(void);
  472. typedef void (*regmap_hw_free_context)(void *context);
  473. /**
  474. * struct regmap_bus - Description of a hardware bus for the register map
  475. * infrastructure.
  476. *
  477. * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
  478. * to perform locking. This field is ignored if custom lock/unlock
  479. * functions are used (see fields lock/unlock of
  480. * struct regmap_config).
  481. * @write: Write operation.
  482. * @gather_write: Write operation with split register/value, return -ENOTSUPP
  483. * if not implemented on a given device.
  484. * @async_write: Write operation which completes asynchronously, optional and
  485. * must serialise with respect to non-async I/O.
  486. * @reg_write: Write a single register value to the given register address. This
  487. * write operation has to complete when returning from the function.
  488. * @reg_write_noinc: Write multiple register value to the same register. This
  489. * write operation has to complete when returning from the function.
  490. * @reg_update_bits: Update bits operation to be used against volatile
  491. * registers, intended for devices supporting some mechanism
  492. * for setting clearing bits without having to
  493. * read/modify/write.
  494. * @read: Read operation. Data is returned in the buffer used to transmit
  495. * data.
  496. * @reg_read: Read a single register value from a given register address.
  497. * @free_context: Free context.
  498. * @async_alloc: Allocate a regmap_async() structure.
  499. * @read_flag_mask: Mask to be set in the top byte of the register when doing
  500. * a read.
  501. * @reg_format_endian_default: Default endianness for formatted register
  502. * addresses. Used when the regmap_config specifies DEFAULT. If this is
  503. * DEFAULT, BIG is assumed.
  504. * @val_format_endian_default: Default endianness for formatted register
  505. * values. Used when the regmap_config specifies DEFAULT. If this is
  506. * DEFAULT, BIG is assumed.
  507. * @max_raw_read: Max raw read size that can be used on the bus.
  508. * @max_raw_write: Max raw write size that can be used on the bus.
  509. * @free_on_exit: kfree this on exit of regmap
  510. */
  511. struct regmap_bus {
  512. bool fast_io;
  513. regmap_hw_write write;
  514. regmap_hw_gather_write gather_write;
  515. regmap_hw_async_write async_write;
  516. regmap_hw_reg_write reg_write;
  517. regmap_hw_reg_noinc_write reg_noinc_write;
  518. regmap_hw_reg_update_bits reg_update_bits;
  519. regmap_hw_read read;
  520. regmap_hw_reg_read reg_read;
  521. regmap_hw_reg_noinc_read reg_noinc_read;
  522. regmap_hw_free_context free_context;
  523. regmap_hw_async_alloc async_alloc;
  524. u8 read_flag_mask;
  525. enum regmap_endian reg_format_endian_default;
  526. enum regmap_endian val_format_endian_default;
  527. size_t max_raw_read;
  528. size_t max_raw_write;
  529. bool free_on_exit;
  530. ANDROID_KABI_RESERVE(1);
  531. };
  532. /*
  533. * __regmap_init functions.
  534. *
  535. * These functions take a lock key and name parameter, and should not be called
  536. * directly. Instead, use the regmap_init macros that generate a key and name
  537. * for each call.
  538. */
  539. struct regmap *__regmap_init(struct device *dev,
  540. const struct regmap_bus *bus,
  541. void *bus_context,
  542. const struct regmap_config *config,
  543. struct lock_class_key *lock_key,
  544. const char *lock_name);
  545. struct regmap *__regmap_init_i2c(struct i2c_client *i2c,
  546. const struct regmap_config *config,
  547. struct lock_class_key *lock_key,
  548. const char *lock_name);
  549. struct regmap *__regmap_init_mdio(struct mdio_device *mdio_dev,
  550. const struct regmap_config *config,
  551. struct lock_class_key *lock_key,
  552. const char *lock_name);
  553. struct regmap *__regmap_init_sccb(struct i2c_client *i2c,
  554. const struct regmap_config *config,
  555. struct lock_class_key *lock_key,
  556. const char *lock_name);
  557. struct regmap *__regmap_init_slimbus(struct slim_device *slimbus,
  558. const struct regmap_config *config,
  559. struct lock_class_key *lock_key,
  560. const char *lock_name);
  561. struct regmap *__regmap_init_spi(struct spi_device *dev,
  562. const struct regmap_config *config,
  563. struct lock_class_key *lock_key,
  564. const char *lock_name);
  565. struct regmap *__regmap_init_spmi_base(struct spmi_device *dev,
  566. const struct regmap_config *config,
  567. struct lock_class_key *lock_key,
  568. const char *lock_name);
  569. struct regmap *__regmap_init_spmi_ext(struct spmi_device *dev,
  570. const struct regmap_config *config,
  571. struct lock_class_key *lock_key,
  572. const char *lock_name);
  573. struct regmap *__regmap_init_w1(struct device *w1_dev,
  574. const struct regmap_config *config,
  575. struct lock_class_key *lock_key,
  576. const char *lock_name);
  577. struct regmap *__regmap_init_mmio_clk(struct device *dev, const char *clk_id,
  578. void __iomem *regs,
  579. const struct regmap_config *config,
  580. struct lock_class_key *lock_key,
  581. const char *lock_name);
  582. struct regmap *__regmap_init_ac97(struct snd_ac97 *ac97,
  583. const struct regmap_config *config,
  584. struct lock_class_key *lock_key,
  585. const char *lock_name);
  586. struct regmap *__regmap_init_sdw(struct sdw_slave *sdw,
  587. const struct regmap_config *config,
  588. struct lock_class_key *lock_key,
  589. const char *lock_name);
  590. struct regmap *__regmap_init_sdw_mbq(struct sdw_slave *sdw,
  591. const struct regmap_config *config,
  592. struct lock_class_key *lock_key,
  593. const char *lock_name);
  594. struct regmap *__regmap_init_spi_avmm(struct spi_device *spi,
  595. const struct regmap_config *config,
  596. struct lock_class_key *lock_key,
  597. const char *lock_name);
  598. struct regmap *__devm_regmap_init(struct device *dev,
  599. const struct regmap_bus *bus,
  600. void *bus_context,
  601. const struct regmap_config *config,
  602. struct lock_class_key *lock_key,
  603. const char *lock_name);
  604. struct regmap *__devm_regmap_init_i2c(struct i2c_client *i2c,
  605. const struct regmap_config *config,
  606. struct lock_class_key *lock_key,
  607. const char *lock_name);
  608. struct regmap *__devm_regmap_init_mdio(struct mdio_device *mdio_dev,
  609. const struct regmap_config *config,
  610. struct lock_class_key *lock_key,
  611. const char *lock_name);
  612. struct regmap *__devm_regmap_init_sccb(struct i2c_client *i2c,
  613. const struct regmap_config *config,
  614. struct lock_class_key *lock_key,
  615. const char *lock_name);
  616. struct regmap *__devm_regmap_init_spi(struct spi_device *dev,
  617. const struct regmap_config *config,
  618. struct lock_class_key *lock_key,
  619. const char *lock_name);
  620. struct regmap *__devm_regmap_init_spmi_base(struct spmi_device *dev,
  621. const struct regmap_config *config,
  622. struct lock_class_key *lock_key,
  623. const char *lock_name);
  624. struct regmap *__devm_regmap_init_spmi_ext(struct spmi_device *dev,
  625. const struct regmap_config *config,
  626. struct lock_class_key *lock_key,
  627. const char *lock_name);
  628. struct regmap *__devm_regmap_init_w1(struct device *w1_dev,
  629. const struct regmap_config *config,
  630. struct lock_class_key *lock_key,
  631. const char *lock_name);
  632. struct regmap *__devm_regmap_init_mmio_clk(struct device *dev,
  633. const char *clk_id,
  634. void __iomem *regs,
  635. const struct regmap_config *config,
  636. struct lock_class_key *lock_key,
  637. const char *lock_name);
  638. struct regmap *__devm_regmap_init_ac97(struct snd_ac97 *ac97,
  639. const struct regmap_config *config,
  640. struct lock_class_key *lock_key,
  641. const char *lock_name);
  642. struct regmap *__devm_regmap_init_sdw(struct sdw_slave *sdw,
  643. const struct regmap_config *config,
  644. struct lock_class_key *lock_key,
  645. const char *lock_name);
  646. struct regmap *__devm_regmap_init_sdw_mbq(struct sdw_slave *sdw,
  647. const struct regmap_config *config,
  648. struct lock_class_key *lock_key,
  649. const char *lock_name);
  650. struct regmap *__devm_regmap_init_slimbus(struct slim_device *slimbus,
  651. const struct regmap_config *config,
  652. struct lock_class_key *lock_key,
  653. const char *lock_name);
  654. struct regmap *__devm_regmap_init_i3c(struct i3c_device *i3c,
  655. const struct regmap_config *config,
  656. struct lock_class_key *lock_key,
  657. const char *lock_name);
  658. struct regmap *__devm_regmap_init_spi_avmm(struct spi_device *spi,
  659. const struct regmap_config *config,
  660. struct lock_class_key *lock_key,
  661. const char *lock_name);
  662. /*
  663. * Wrapper for regmap_init macros to include a unique lockdep key and name
  664. * for each call. No-op if CONFIG_LOCKDEP is not set.
  665. *
  666. * @fn: Real function to call (in the form __[*_]regmap_init[_*])
  667. * @name: Config variable name (#config in the calling macro)
  668. **/
  669. #ifdef CONFIG_LOCKDEP
  670. #define __regmap_lockdep_wrapper(fn, name, ...) \
  671. ( \
  672. ({ \
  673. static struct lock_class_key _key; \
  674. fn(__VA_ARGS__, &_key, \
  675. KBUILD_BASENAME ":" \
  676. __stringify(__LINE__) ":" \
  677. "(" name ")->lock"); \
  678. }) \
  679. )
  680. #else
  681. #define __regmap_lockdep_wrapper(fn, name, ...) fn(__VA_ARGS__, NULL, NULL)
  682. #endif
  683. /**
  684. * regmap_init() - Initialise register map
  685. *
  686. * @dev: Device that will be interacted with
  687. * @bus: Bus-specific callbacks to use with device
  688. * @bus_context: Data passed to bus-specific callbacks
  689. * @config: Configuration for register map
  690. *
  691. * The return value will be an ERR_PTR() on error or a valid pointer to
  692. * a struct regmap. This function should generally not be called
  693. * directly, it should be called by bus-specific init functions.
  694. */
  695. #define regmap_init(dev, bus, bus_context, config) \
  696. __regmap_lockdep_wrapper(__regmap_init, #config, \
  697. dev, bus, bus_context, config)
  698. int regmap_attach_dev(struct device *dev, struct regmap *map,
  699. const struct regmap_config *config);
  700. /**
  701. * regmap_init_i2c() - Initialise register map
  702. *
  703. * @i2c: Device that will be interacted with
  704. * @config: Configuration for register map
  705. *
  706. * The return value will be an ERR_PTR() on error or a valid pointer to
  707. * a struct regmap.
  708. */
  709. #define regmap_init_i2c(i2c, config) \
  710. __regmap_lockdep_wrapper(__regmap_init_i2c, #config, \
  711. i2c, config)
  712. /**
  713. * regmap_init_mdio() - Initialise register map
  714. *
  715. * @mdio_dev: Device that will be interacted with
  716. * @config: Configuration for register map
  717. *
  718. * The return value will be an ERR_PTR() on error or a valid pointer to
  719. * a struct regmap.
  720. */
  721. #define regmap_init_mdio(mdio_dev, config) \
  722. __regmap_lockdep_wrapper(__regmap_init_mdio, #config, \
  723. mdio_dev, config)
  724. /**
  725. * regmap_init_sccb() - Initialise register map
  726. *
  727. * @i2c: Device that will be interacted with
  728. * @config: Configuration for register map
  729. *
  730. * The return value will be an ERR_PTR() on error or a valid pointer to
  731. * a struct regmap.
  732. */
  733. #define regmap_init_sccb(i2c, config) \
  734. __regmap_lockdep_wrapper(__regmap_init_sccb, #config, \
  735. i2c, config)
  736. /**
  737. * regmap_init_slimbus() - Initialise register map
  738. *
  739. * @slimbus: Device that will be interacted with
  740. * @config: Configuration for register map
  741. *
  742. * The return value will be an ERR_PTR() on error or a valid pointer to
  743. * a struct regmap.
  744. */
  745. #define regmap_init_slimbus(slimbus, config) \
  746. __regmap_lockdep_wrapper(__regmap_init_slimbus, #config, \
  747. slimbus, config)
  748. /**
  749. * regmap_init_spi() - Initialise register map
  750. *
  751. * @dev: Device that will be interacted with
  752. * @config: Configuration for register map
  753. *
  754. * The return value will be an ERR_PTR() on error or a valid pointer to
  755. * a struct regmap.
  756. */
  757. #define regmap_init_spi(dev, config) \
  758. __regmap_lockdep_wrapper(__regmap_init_spi, #config, \
  759. dev, config)
  760. /**
  761. * regmap_init_spmi_base() - Create regmap for the Base register space
  762. *
  763. * @dev: SPMI device that will be interacted with
  764. * @config: Configuration for register map
  765. *
  766. * The return value will be an ERR_PTR() on error or a valid pointer to
  767. * a struct regmap.
  768. */
  769. #define regmap_init_spmi_base(dev, config) \
  770. __regmap_lockdep_wrapper(__regmap_init_spmi_base, #config, \
  771. dev, config)
  772. /**
  773. * regmap_init_spmi_ext() - Create regmap for Ext register space
  774. *
  775. * @dev: 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 to
  779. * a struct regmap.
  780. */
  781. #define regmap_init_spmi_ext(dev, config) \
  782. __regmap_lockdep_wrapper(__regmap_init_spmi_ext, #config, \
  783. dev, config)
  784. /**
  785. * regmap_init_w1() - Initialise register map
  786. *
  787. * @w1_dev: Device that will be interacted with
  788. * @config: Configuration for register map
  789. *
  790. * The return value will be an ERR_PTR() on error or a valid pointer to
  791. * a struct regmap.
  792. */
  793. #define regmap_init_w1(w1_dev, config) \
  794. __regmap_lockdep_wrapper(__regmap_init_w1, #config, \
  795. w1_dev, config)
  796. /**
  797. * regmap_init_mmio_clk() - Initialise register map with register clock
  798. *
  799. * @dev: Device that will be interacted with
  800. * @clk_id: register clock consumer ID
  801. * @regs: Pointer to memory-mapped IO region
  802. * @config: Configuration for register map
  803. *
  804. * The return value will be an ERR_PTR() on error or a valid pointer to
  805. * a struct regmap.
  806. */
  807. #define regmap_init_mmio_clk(dev, clk_id, regs, config) \
  808. __regmap_lockdep_wrapper(__regmap_init_mmio_clk, #config, \
  809. dev, clk_id, regs, config)
  810. /**
  811. * regmap_init_mmio() - Initialise register map
  812. *
  813. * @dev: Device that will be interacted with
  814. * @regs: Pointer to memory-mapped IO region
  815. * @config: Configuration for register map
  816. *
  817. * The return value will be an ERR_PTR() on error or a valid pointer to
  818. * a struct regmap.
  819. */
  820. #define regmap_init_mmio(dev, regs, config) \
  821. regmap_init_mmio_clk(dev, NULL, regs, config)
  822. /**
  823. * 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 to
  829. * a struct regmap.
  830. */
  831. #define regmap_init_ac97(ac97, config) \
  832. __regmap_lockdep_wrapper(__regmap_init_ac97, #config, \
  833. ac97, config)
  834. bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg);
  835. /**
  836. * regmap_init_sdw() - Initialise 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 to
  842. * a struct regmap.
  843. */
  844. #define regmap_init_sdw(sdw, config) \
  845. __regmap_lockdep_wrapper(__regmap_init_sdw, #config, \
  846. sdw, config)
  847. /**
  848. * regmap_init_sdw_mbq() - Initialise register map
  849. *
  850. * @sdw: Device that will be interacted with
  851. * @config: Configuration for register map
  852. *
  853. * The return value will be an ERR_PTR() on error or a valid pointer to
  854. * a struct regmap.
  855. */
  856. #define regmap_init_sdw_mbq(sdw, config) \
  857. __regmap_lockdep_wrapper(__regmap_init_sdw_mbq, #config, \
  858. sdw, config)
  859. /**
  860. * regmap_init_spi_avmm() - Initialize register map for Intel SPI Slave
  861. * to AVMM Bus Bridge
  862. *
  863. * @spi: Device that will be interacted with
  864. * @config: Configuration for register map
  865. *
  866. * The return value will be an ERR_PTR() on error or a valid pointer
  867. * to a struct regmap.
  868. */
  869. #define regmap_init_spi_avmm(spi, config) \
  870. __regmap_lockdep_wrapper(__regmap_init_spi_avmm, #config, \
  871. spi, config)
  872. /**
  873. * devm_regmap_init() - Initialise managed register map
  874. *
  875. * @dev: Device that will be interacted with
  876. * @bus: Bus-specific callbacks to use with device
  877. * @bus_context: Data passed to bus-specific callbacks
  878. * @config: Configuration for register map
  879. *
  880. * The return value will be an ERR_PTR() on error or a valid pointer
  881. * to a struct regmap. This function should generally not be called
  882. * directly, it should be called by bus-specific init functions. The
  883. * map will be automatically freed by the device management code.
  884. */
  885. #define devm_regmap_init(dev, bus, bus_context, config) \
  886. __regmap_lockdep_wrapper(__devm_regmap_init, #config, \
  887. dev, bus, bus_context, config)
  888. /**
  889. * devm_regmap_init_i2c() - Initialise managed register map
  890. *
  891. * @i2c: Device that will be interacted with
  892. * @config: Configuration for register map
  893. *
  894. * The return value will be an ERR_PTR() on error or a valid pointer
  895. * to a struct regmap. The regmap will be automatically freed by the
  896. * device management code.
  897. */
  898. #define devm_regmap_init_i2c(i2c, config) \
  899. __regmap_lockdep_wrapper(__devm_regmap_init_i2c, #config, \
  900. i2c, config)
  901. /**
  902. * devm_regmap_init_mdio() - Initialise managed register map
  903. *
  904. * @mdio_dev: Device that will be interacted with
  905. * @config: Configuration for register map
  906. *
  907. * The return value will be an ERR_PTR() on error or a valid pointer
  908. * to a struct regmap. The regmap will be automatically freed by the
  909. * device management code.
  910. */
  911. #define devm_regmap_init_mdio(mdio_dev, config) \
  912. __regmap_lockdep_wrapper(__devm_regmap_init_mdio, #config, \
  913. mdio_dev, config)
  914. /**
  915. * devm_regmap_init_sccb() - Initialise managed register map
  916. *
  917. * @i2c: Device that will be interacted with
  918. * @config: Configuration for register map
  919. *
  920. * The return value will be an ERR_PTR() on error or a valid pointer
  921. * to a struct regmap. The regmap will be automatically freed by the
  922. * device management code.
  923. */
  924. #define devm_regmap_init_sccb(i2c, config) \
  925. __regmap_lockdep_wrapper(__devm_regmap_init_sccb, #config, \
  926. i2c, config)
  927. /**
  928. * devm_regmap_init_spi() - Initialise register map
  929. *
  930. * @dev: Device that will be interacted with
  931. * @config: Configuration for register map
  932. *
  933. * The return value will be an ERR_PTR() on error or a valid pointer
  934. * to a struct regmap. The map will be automatically freed by the
  935. * device management code.
  936. */
  937. #define devm_regmap_init_spi(dev, config) \
  938. __regmap_lockdep_wrapper(__devm_regmap_init_spi, #config, \
  939. dev, config)
  940. /**
  941. * devm_regmap_init_spmi_base() - Create managed regmap for Base register space
  942. *
  943. * @dev: SPMI device that will be interacted with
  944. * @config: Configuration for register map
  945. *
  946. * The return value will be an ERR_PTR() on error or a valid pointer
  947. * to a struct regmap. The regmap will be automatically freed by the
  948. * device management code.
  949. */
  950. #define devm_regmap_init_spmi_base(dev, config) \
  951. __regmap_lockdep_wrapper(__devm_regmap_init_spmi_base, #config, \
  952. dev, config)
  953. /**
  954. * devm_regmap_init_spmi_ext() - Create managed regmap for Ext register space
  955. *
  956. * @dev: SPMI device that will be interacted with
  957. * @config: Configuration for register map
  958. *
  959. * The return value will be an ERR_PTR() on error or a valid pointer
  960. * to a struct regmap. The regmap will be automatically freed by the
  961. * device management code.
  962. */
  963. #define devm_regmap_init_spmi_ext(dev, config) \
  964. __regmap_lockdep_wrapper(__devm_regmap_init_spmi_ext, #config, \
  965. dev, config)
  966. /**
  967. * devm_regmap_init_w1() - Initialise managed register map
  968. *
  969. * @w1_dev: Device that will be interacted with
  970. * @config: Configuration for register map
  971. *
  972. * The return value will be an ERR_PTR() on error or a valid pointer
  973. * to a struct regmap. The regmap will be automatically freed by the
  974. * device management code.
  975. */
  976. #define devm_regmap_init_w1(w1_dev, config) \
  977. __regmap_lockdep_wrapper(__devm_regmap_init_w1, #config, \
  978. w1_dev, config)
  979. /**
  980. * devm_regmap_init_mmio_clk() - Initialise managed register map with clock
  981. *
  982. * @dev: Device that will be interacted with
  983. * @clk_id: register clock consumer ID
  984. * @regs: Pointer to memory-mapped IO region
  985. * @config: Configuration for register map
  986. *
  987. * The return value will be an ERR_PTR() on error or a valid pointer
  988. * to a struct regmap. The regmap will be automatically freed by the
  989. * device management code.
  990. */
  991. #define devm_regmap_init_mmio_clk(dev, clk_id, regs, config) \
  992. __regmap_lockdep_wrapper(__devm_regmap_init_mmio_clk, #config, \
  993. dev, clk_id, regs, config)
  994. /**
  995. * devm_regmap_init_mmio() - Initialise managed register map
  996. *
  997. * @dev: Device that will be interacted with
  998. * @regs: Pointer to memory-mapped IO region
  999. * @config: Configuration for register map
  1000. *
  1001. * The return value will be an ERR_PTR() on error or a valid pointer
  1002. * to a struct regmap. The regmap will be automatically freed by the
  1003. * device management code.
  1004. */
  1005. #define devm_regmap_init_mmio(dev, regs, config) \
  1006. devm_regmap_init_mmio_clk(dev, NULL, regs, config)
  1007. /**
  1008. * devm_regmap_init_ac97() - Initialise AC'97 register map
  1009. *
  1010. * @ac97: Device that will be interacted with
  1011. * @config: Configuration for register map
  1012. *
  1013. * The return value will be an ERR_PTR() on error or a valid pointer
  1014. * to a struct regmap. The regmap will be automatically freed by the
  1015. * device management code.
  1016. */
  1017. #define devm_regmap_init_ac97(ac97, config) \
  1018. __regmap_lockdep_wrapper(__devm_regmap_init_ac97, #config, \
  1019. ac97, config)
  1020. /**
  1021. * devm_regmap_init_sdw() - Initialise managed register map
  1022. *
  1023. * @sdw: Device that will be interacted with
  1024. * @config: Configuration for register map
  1025. *
  1026. * The return value will be an ERR_PTR() on error or a valid pointer
  1027. * to a struct regmap. The regmap will be automatically freed by the
  1028. * device management code.
  1029. */
  1030. #define devm_regmap_init_sdw(sdw, config) \
  1031. __regmap_lockdep_wrapper(__devm_regmap_init_sdw, #config, \
  1032. sdw, config)
  1033. /**
  1034. * devm_regmap_init_sdw_mbq() - Initialise managed register map
  1035. *
  1036. * @sdw: Device that will be interacted with
  1037. * @config: Configuration for register map
  1038. *
  1039. * The return value will be an ERR_PTR() on error or a valid pointer
  1040. * to a struct regmap. The regmap will be automatically freed by the
  1041. * device management code.
  1042. */
  1043. #define devm_regmap_init_sdw_mbq(sdw, config) \
  1044. __regmap_lockdep_wrapper(__devm_regmap_init_sdw_mbq, #config, \
  1045. sdw, config)
  1046. /**
  1047. * devm_regmap_init_slimbus() - Initialise managed register map
  1048. *
  1049. * @slimbus: Device that will be interacted with
  1050. * @config: Configuration for register map
  1051. *
  1052. * The return value will be an ERR_PTR() on error or a valid pointer
  1053. * to a struct regmap. The regmap will be automatically freed by the
  1054. * device management code.
  1055. */
  1056. #define devm_regmap_init_slimbus(slimbus, config) \
  1057. __regmap_lockdep_wrapper(__devm_regmap_init_slimbus, #config, \
  1058. slimbus, config)
  1059. /**
  1060. * devm_regmap_init_i3c() - Initialise managed register map
  1061. *
  1062. * @i3c: Device that will be interacted with
  1063. * @config: Configuration for register map
  1064. *
  1065. * The return value will be an ERR_PTR() on error or a valid pointer
  1066. * to a struct regmap. The regmap will be automatically freed by the
  1067. * device management code.
  1068. */
  1069. #define devm_regmap_init_i3c(i3c, config) \
  1070. __regmap_lockdep_wrapper(__devm_regmap_init_i3c, #config, \
  1071. i3c, config)
  1072. /**
  1073. * devm_regmap_init_spi_avmm() - Initialize register map for Intel SPI Slave
  1074. * to AVMM Bus Bridge
  1075. *
  1076. * @spi: Device that will be interacted with
  1077. * @config: Configuration for register map
  1078. *
  1079. * The return value will be an ERR_PTR() on error or a valid pointer
  1080. * to a struct regmap. The map will be automatically freed by the
  1081. * device management code.
  1082. */
  1083. #define devm_regmap_init_spi_avmm(spi, config) \
  1084. __regmap_lockdep_wrapper(__devm_regmap_init_spi_avmm, #config, \
  1085. spi, config)
  1086. int regmap_mmio_attach_clk(struct regmap *map, struct clk *clk);
  1087. void regmap_mmio_detach_clk(struct regmap *map);
  1088. void regmap_exit(struct regmap *map);
  1089. int regmap_reinit_cache(struct regmap *map,
  1090. const struct regmap_config *config);
  1091. struct regmap *dev_get_regmap(struct device *dev, const char *name);
  1092. struct device *regmap_get_device(struct regmap *map);
  1093. int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
  1094. int regmap_write_async(struct regmap *map, unsigned int reg, unsigned int val);
  1095. int regmap_raw_write(struct regmap *map, unsigned int reg,
  1096. const void *val, size_t val_len);
  1097. int regmap_noinc_write(struct regmap *map, unsigned int reg,
  1098. const void *val, size_t val_len);
  1099. int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
  1100. size_t val_count);
  1101. int regmap_multi_reg_write(struct regmap *map, const struct reg_sequence *regs,
  1102. int num_regs);
  1103. int regmap_multi_reg_write_bypassed(struct regmap *map,
  1104. const struct reg_sequence *regs,
  1105. int num_regs);
  1106. int regmap_raw_write_async(struct regmap *map, unsigned int reg,
  1107. const void *val, size_t val_len);
  1108. int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
  1109. int regmap_raw_read(struct regmap *map, unsigned int reg,
  1110. void *val, size_t val_len);
  1111. int regmap_noinc_read(struct regmap *map, unsigned int reg,
  1112. void *val, size_t val_len);
  1113. int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
  1114. size_t val_count);
  1115. int regmap_update_bits_base(struct regmap *map, unsigned int reg,
  1116. unsigned int mask, unsigned int val,
  1117. bool *change, bool async, bool force);
  1118. static inline int regmap_update_bits(struct regmap *map, unsigned int reg,
  1119. unsigned int mask, unsigned int val)
  1120. {
  1121. return regmap_update_bits_base(map, reg, mask, val, NULL, false, false);
  1122. }
  1123. static inline int regmap_update_bits_async(struct regmap *map, unsigned int reg,
  1124. unsigned int mask, unsigned int val)
  1125. {
  1126. return regmap_update_bits_base(map, reg, mask, val, NULL, true, false);
  1127. }
  1128. static inline int regmap_update_bits_check(struct regmap *map, unsigned int reg,
  1129. unsigned int mask, unsigned int val,
  1130. bool *change)
  1131. {
  1132. return regmap_update_bits_base(map, reg, mask, val,
  1133. change, false, false);
  1134. }
  1135. static inline int
  1136. regmap_update_bits_check_async(struct regmap *map, unsigned int reg,
  1137. unsigned int mask, unsigned int val,
  1138. bool *change)
  1139. {
  1140. return regmap_update_bits_base(map, reg, mask, val,
  1141. change, true, false);
  1142. }
  1143. static inline int regmap_write_bits(struct regmap *map, unsigned int reg,
  1144. unsigned int mask, unsigned int val)
  1145. {
  1146. return regmap_update_bits_base(map, reg, mask, val, NULL, false, true);
  1147. }
  1148. int regmap_get_val_bytes(struct regmap *map);
  1149. int regmap_get_max_register(struct regmap *map);
  1150. int regmap_get_reg_stride(struct regmap *map);
  1151. int regmap_async_complete(struct regmap *map);
  1152. bool regmap_can_raw_write(struct regmap *map);
  1153. size_t regmap_get_raw_read_max(struct regmap *map);
  1154. size_t regmap_get_raw_write_max(struct regmap *map);
  1155. int regcache_sync(struct regmap *map);
  1156. int regcache_sync_region(struct regmap *map, unsigned int min,
  1157. unsigned int max);
  1158. int regcache_drop_region(struct regmap *map, unsigned int min,
  1159. unsigned int max);
  1160. void regcache_cache_only(struct regmap *map, bool enable);
  1161. void regcache_cache_bypass(struct regmap *map, bool enable);
  1162. void regcache_mark_dirty(struct regmap *map);
  1163. bool regmap_check_range_table(struct regmap *map, unsigned int reg,
  1164. const struct regmap_access_table *table);
  1165. int regmap_register_patch(struct regmap *map, const struct reg_sequence *regs,
  1166. int num_regs);
  1167. int regmap_parse_val(struct regmap *map, const void *buf,
  1168. unsigned int *val);
  1169. static inline bool regmap_reg_in_range(unsigned int reg,
  1170. const struct regmap_range *range)
  1171. {
  1172. return reg >= range->range_min && reg <= range->range_max;
  1173. }
  1174. bool regmap_reg_in_ranges(unsigned int reg,
  1175. const struct regmap_range *ranges,
  1176. unsigned int nranges);
  1177. static inline int regmap_set_bits(struct regmap *map,
  1178. unsigned int reg, unsigned int bits)
  1179. {
  1180. return regmap_update_bits_base(map, reg, bits, bits,
  1181. NULL, false, false);
  1182. }
  1183. static inline int regmap_clear_bits(struct regmap *map,
  1184. unsigned int reg, unsigned int bits)
  1185. {
  1186. return regmap_update_bits_base(map, reg, bits, 0, NULL, false, false);
  1187. }
  1188. int regmap_test_bits(struct regmap *map, unsigned int reg, unsigned int bits);
  1189. /**
  1190. * struct reg_field - Description of an register field
  1191. *
  1192. * @reg: Offset of the register within the regmap bank
  1193. * @lsb: lsb of the register field.
  1194. * @msb: msb of the register field.
  1195. * @id_size: port size if it has some ports
  1196. * @id_offset: address offset for each ports
  1197. */
  1198. struct reg_field {
  1199. unsigned int reg;
  1200. unsigned int lsb;
  1201. unsigned int msb;
  1202. unsigned int id_size;
  1203. unsigned int id_offset;
  1204. };
  1205. #define REG_FIELD(_reg, _lsb, _msb) { \
  1206. .reg = _reg, \
  1207. .lsb = _lsb, \
  1208. .msb = _msb, \
  1209. }
  1210. #define REG_FIELD_ID(_reg, _lsb, _msb, _size, _offset) { \
  1211. .reg = _reg, \
  1212. .lsb = _lsb, \
  1213. .msb = _msb, \
  1214. .id_size = _size, \
  1215. .id_offset = _offset, \
  1216. }
  1217. struct regmap_field *regmap_field_alloc(struct regmap *regmap,
  1218. struct reg_field reg_field);
  1219. void regmap_field_free(struct regmap_field *field);
  1220. struct regmap_field *devm_regmap_field_alloc(struct device *dev,
  1221. struct regmap *regmap, struct reg_field reg_field);
  1222. void devm_regmap_field_free(struct device *dev, struct regmap_field *field);
  1223. int regmap_field_bulk_alloc(struct regmap *regmap,
  1224. struct regmap_field **rm_field,
  1225. const struct reg_field *reg_field,
  1226. int num_fields);
  1227. void regmap_field_bulk_free(struct regmap_field *field);
  1228. int devm_regmap_field_bulk_alloc(struct device *dev, struct regmap *regmap,
  1229. struct regmap_field **field,
  1230. const struct reg_field *reg_field,
  1231. int num_fields);
  1232. void devm_regmap_field_bulk_free(struct device *dev,
  1233. struct regmap_field *field);
  1234. int regmap_field_read(struct regmap_field *field, unsigned int *val);
  1235. int regmap_field_update_bits_base(struct regmap_field *field,
  1236. unsigned int mask, unsigned int val,
  1237. bool *change, bool async, bool force);
  1238. int regmap_fields_read(struct regmap_field *field, unsigned int id,
  1239. unsigned int *val);
  1240. int regmap_fields_update_bits_base(struct regmap_field *field, unsigned int id,
  1241. unsigned int mask, unsigned int val,
  1242. bool *change, bool async, bool force);
  1243. static inline int regmap_field_write(struct regmap_field *field,
  1244. unsigned int val)
  1245. {
  1246. return regmap_field_update_bits_base(field, ~0, val,
  1247. NULL, false, false);
  1248. }
  1249. static inline int regmap_field_force_write(struct regmap_field *field,
  1250. unsigned int val)
  1251. {
  1252. return regmap_field_update_bits_base(field, ~0, val, NULL, false, true);
  1253. }
  1254. static inline int regmap_field_update_bits(struct regmap_field *field,
  1255. unsigned int mask, unsigned int val)
  1256. {
  1257. return regmap_field_update_bits_base(field, mask, val,
  1258. NULL, false, false);
  1259. }
  1260. static inline int regmap_field_set_bits(struct regmap_field *field,
  1261. unsigned int bits)
  1262. {
  1263. return regmap_field_update_bits_base(field, bits, bits, NULL, false,
  1264. false);
  1265. }
  1266. static inline int regmap_field_clear_bits(struct regmap_field *field,
  1267. unsigned int bits)
  1268. {
  1269. return regmap_field_update_bits_base(field, bits, 0, NULL, false,
  1270. false);
  1271. }
  1272. int regmap_field_test_bits(struct regmap_field *field, unsigned int bits);
  1273. static inline int
  1274. regmap_field_force_update_bits(struct regmap_field *field,
  1275. unsigned int mask, unsigned int val)
  1276. {
  1277. return regmap_field_update_bits_base(field, mask, val,
  1278. NULL, false, true);
  1279. }
  1280. static inline int regmap_fields_write(struct regmap_field *field,
  1281. unsigned int id, unsigned int val)
  1282. {
  1283. return regmap_fields_update_bits_base(field, id, ~0, val,
  1284. NULL, false, false);
  1285. }
  1286. static inline int regmap_fields_force_write(struct regmap_field *field,
  1287. unsigned int id, unsigned int val)
  1288. {
  1289. return regmap_fields_update_bits_base(field, id, ~0, val,
  1290. NULL, false, true);
  1291. }
  1292. static inline int
  1293. regmap_fields_update_bits(struct regmap_field *field, unsigned int id,
  1294. unsigned int mask, unsigned int val)
  1295. {
  1296. return regmap_fields_update_bits_base(field, id, mask, val,
  1297. NULL, false, false);
  1298. }
  1299. static inline int
  1300. regmap_fields_force_update_bits(struct regmap_field *field, unsigned int id,
  1301. unsigned int mask, unsigned int val)
  1302. {
  1303. return regmap_fields_update_bits_base(field, id, mask, val,
  1304. NULL, false, true);
  1305. }
  1306. /**
  1307. * struct regmap_irq_type - IRQ type definitions.
  1308. *
  1309. * @type_reg_offset: Offset register for the irq type setting.
  1310. * @type_rising_val: Register value to configure RISING type irq.
  1311. * @type_falling_val: Register value to configure FALLING type irq.
  1312. * @type_level_low_val: Register value to configure LEVEL_LOW type irq.
  1313. * @type_level_high_val: Register value to configure LEVEL_HIGH type irq.
  1314. * @types_supported: logical OR of IRQ_TYPE_* flags indicating supported types.
  1315. */
  1316. struct regmap_irq_type {
  1317. unsigned int type_reg_offset;
  1318. unsigned int type_reg_mask;
  1319. unsigned int type_rising_val;
  1320. unsigned int type_falling_val;
  1321. unsigned int type_level_low_val;
  1322. unsigned int type_level_high_val;
  1323. unsigned int types_supported;
  1324. };
  1325. /**
  1326. * struct regmap_irq - Description of an IRQ for the generic regmap irq_chip.
  1327. *
  1328. * @reg_offset: Offset of the status/mask register within the bank
  1329. * @mask: Mask used to flag/control the register.
  1330. * @type: IRQ trigger type setting details if supported.
  1331. */
  1332. struct regmap_irq {
  1333. unsigned int reg_offset;
  1334. unsigned int mask;
  1335. struct regmap_irq_type type;
  1336. };
  1337. #define REGMAP_IRQ_REG(_irq, _off, _mask) \
  1338. [_irq] = { .reg_offset = (_off), .mask = (_mask) }
  1339. #define REGMAP_IRQ_REG_LINE(_id, _reg_bits) \
  1340. [_id] = { \
  1341. .mask = BIT((_id) % (_reg_bits)), \
  1342. .reg_offset = (_id) / (_reg_bits), \
  1343. }
  1344. #define REGMAP_IRQ_MAIN_REG_OFFSET(arr) \
  1345. { .num_regs = ARRAY_SIZE((arr)), .offset = &(arr)[0] }
  1346. struct regmap_irq_sub_irq_map {
  1347. unsigned int num_regs;
  1348. unsigned int *offset;
  1349. };
  1350. struct regmap_irq_chip_data;
  1351. /**
  1352. * struct regmap_irq_chip - Description of a generic regmap irq_chip.
  1353. *
  1354. * @name: Descriptive name for IRQ controller.
  1355. *
  1356. * @main_status: Base main status register address. For chips which have
  1357. * interrupts arranged in separate sub-irq blocks with own IRQ
  1358. * registers and which have a main IRQ registers indicating
  1359. * sub-irq blocks with unhandled interrupts. For such chips fill
  1360. * sub-irq register information in status_base, mask_base and
  1361. * ack_base.
  1362. * @num_main_status_bits: Should be given to chips where number of meaningfull
  1363. * main status bits differs from num_regs.
  1364. * @sub_reg_offsets: arrays of mappings from main register bits to sub irq
  1365. * registers. First item in array describes the registers
  1366. * for first main status bit. Second array for second bit etc.
  1367. * Offset is given as sub register status offset to
  1368. * status_base. Should contain num_regs arrays.
  1369. * Can be provided for chips with more complex mapping than
  1370. * 1.st bit to 1.st sub-reg, 2.nd bit to 2.nd sub-reg, ...
  1371. * When used with not_fixed_stride, each one-element array
  1372. * member contains offset calculated as address from each
  1373. * peripheral to first peripheral.
  1374. * @num_main_regs: Number of 'main status' irq registers for chips which have
  1375. * main_status set.
  1376. *
  1377. * @status_base: Base status register address.
  1378. * @mask_base: Base mask register address. Mask bits are set to 1 when an
  1379. * interrupt is masked, 0 when unmasked.
  1380. * @unmask_base: Base unmask register address. Unmask bits are set to 1 when
  1381. * an interrupt is unmasked and 0 when masked.
  1382. * @ack_base: Base ack address. If zero then the chip is clear on read.
  1383. * Using zero value is possible with @use_ack bit.
  1384. * @wake_base: Base address for wake enables. If zero unsupported.
  1385. * @type_base: Base address for irq type. If zero unsupported. Deprecated,
  1386. * use @config_base instead.
  1387. * @virt_reg_base: Base addresses for extra config regs. Deprecated, use
  1388. * @config_base instead.
  1389. * @config_base: Base address for IRQ type config regs. If null unsupported.
  1390. * @irq_reg_stride: Stride to use for chips where registers are not contiguous.
  1391. * @init_ack_masked: Ack all masked interrupts once during initalization.
  1392. * @mask_invert: Inverted mask register: cleared bits are masked out.
  1393. * Deprecated; prefer describing an inverted mask register as
  1394. * an unmask register.
  1395. * @mask_unmask_non_inverted: Controls mask bit inversion for chips that set
  1396. * both @mask_base and @unmask_base. If false, mask and unmask bits are
  1397. * inverted (which is deprecated behavior); if true, bits will not be
  1398. * inverted and the registers keep their normal behavior. Note that if
  1399. * you use only one of @mask_base or @unmask_base, this flag has no
  1400. * effect and is unnecessary. Any new drivers that set both @mask_base
  1401. * and @unmask_base should set this to true to avoid relying on the
  1402. * deprecated behavior.
  1403. * @use_ack: Use @ack register even if it is zero.
  1404. * @ack_invert: Inverted ack register: cleared bits for ack.
  1405. * @clear_ack: Use this to set 1 and 0 or vice-versa to clear interrupts.
  1406. * @wake_invert: Inverted wake register: cleared bits are wake enabled.
  1407. * @type_invert: Invert the type flags. Deprecated, use config registers
  1408. * instead.
  1409. * @type_in_mask: Use the mask registers for controlling irq type. Use this if
  1410. * the hardware provides separate bits for rising/falling edge
  1411. * or low/high level interrupts and they should be combined into
  1412. * a single logical interrupt. Use &struct regmap_irq_type data
  1413. * to define the mask bit for each irq type.
  1414. * @clear_on_unmask: For chips with interrupts cleared on read: read the status
  1415. * registers before unmasking interrupts to clear any bits
  1416. * set when they were masked.
  1417. * @not_fixed_stride: Used when chip peripherals are not laid out with fixed
  1418. * stride. Must be used with sub_reg_offsets containing the
  1419. * offsets to each peripheral. Deprecated; the same thing
  1420. * can be accomplished with a @get_irq_reg callback, without
  1421. * the need for a @sub_reg_offsets table.
  1422. * @status_invert: Inverted status register: cleared bits are active interrupts.
  1423. * @runtime_pm: Hold a runtime PM lock on the device when accessing it.
  1424. *
  1425. * @num_regs: Number of registers in each control bank.
  1426. * @irqs: Descriptors for individual IRQs. Interrupt numbers are
  1427. * assigned based on the index in the array of the interrupt.
  1428. * @num_irqs: Number of descriptors.
  1429. * @num_type_reg: Number of type registers. Deprecated, use config registers
  1430. * instead.
  1431. * @num_virt_regs: Number of non-standard irq configuration registers.
  1432. * If zero unsupported. Deprecated, use config registers
  1433. * instead.
  1434. * @num_config_bases: Number of config base registers.
  1435. * @num_config_regs: Number of config registers for each config base register.
  1436. * @handle_pre_irq: Driver specific callback to handle interrupt from device
  1437. * before regmap_irq_handler process the interrupts.
  1438. * @handle_post_irq: Driver specific callback to handle interrupt from device
  1439. * after handling the interrupts in regmap_irq_handler().
  1440. * @set_type_virt: Driver specific callback to extend regmap_irq_set_type()
  1441. * and configure virt regs. Deprecated, use @set_type_config
  1442. * callback and config registers instead.
  1443. * @set_type_config: Callback used for configuring irq types.
  1444. * @get_irq_reg: Callback for mapping (base register, index) pairs to register
  1445. * addresses. The base register will be one of @status_base,
  1446. * @mask_base, etc., @main_status, or any of @config_base.
  1447. * The index will be in the range [0, num_main_regs[ for the
  1448. * main status base, [0, num_type_settings[ for any config
  1449. * register base, and [0, num_regs[ for any other base.
  1450. * If unspecified then regmap_irq_get_irq_reg_linear() is used.
  1451. * @irq_drv_data: Driver specific IRQ data which is passed as parameter when
  1452. * driver specific pre/post interrupt handler is called.
  1453. *
  1454. * This is not intended to handle every possible interrupt controller, but
  1455. * it should handle a substantial proportion of those that are found in the
  1456. * wild.
  1457. */
  1458. struct regmap_irq_chip {
  1459. const char *name;
  1460. unsigned int main_status;
  1461. unsigned int num_main_status_bits;
  1462. struct regmap_irq_sub_irq_map *sub_reg_offsets;
  1463. int num_main_regs;
  1464. unsigned int status_base;
  1465. unsigned int mask_base;
  1466. unsigned int unmask_base;
  1467. unsigned int ack_base;
  1468. unsigned int wake_base;
  1469. unsigned int type_base;
  1470. unsigned int *virt_reg_base;
  1471. const unsigned int *config_base;
  1472. unsigned int irq_reg_stride;
  1473. unsigned int init_ack_masked:1;
  1474. unsigned int mask_invert:1;
  1475. unsigned int mask_unmask_non_inverted:1;
  1476. unsigned int use_ack:1;
  1477. unsigned int ack_invert:1;
  1478. unsigned int clear_ack:1;
  1479. unsigned int wake_invert:1;
  1480. unsigned int runtime_pm:1;
  1481. unsigned int type_invert:1;
  1482. unsigned int type_in_mask:1;
  1483. unsigned int clear_on_unmask:1;
  1484. unsigned int not_fixed_stride:1;
  1485. unsigned int status_invert:1;
  1486. int num_regs;
  1487. const struct regmap_irq *irqs;
  1488. int num_irqs;
  1489. int num_type_reg;
  1490. int num_virt_regs;
  1491. int num_config_bases;
  1492. int num_config_regs;
  1493. int (*handle_pre_irq)(void *irq_drv_data);
  1494. int (*handle_post_irq)(void *irq_drv_data);
  1495. int (*set_type_virt)(unsigned int **buf, unsigned int type,
  1496. unsigned long hwirq, int reg);
  1497. int (*set_type_config)(unsigned int **buf, unsigned int type,
  1498. const struct regmap_irq *irq_data, int idx);
  1499. unsigned int (*get_irq_reg)(struct regmap_irq_chip_data *data,
  1500. unsigned int base, int index);
  1501. void *irq_drv_data;
  1502. };
  1503. unsigned int regmap_irq_get_irq_reg_linear(struct regmap_irq_chip_data *data,
  1504. unsigned int base, int index);
  1505. int regmap_irq_set_type_config_simple(unsigned int **buf, unsigned int type,
  1506. const struct regmap_irq *irq_data, int idx);
  1507. int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
  1508. int irq_base, const struct regmap_irq_chip *chip,
  1509. struct regmap_irq_chip_data **data);
  1510. int regmap_add_irq_chip_fwnode(struct fwnode_handle *fwnode,
  1511. struct regmap *map, int irq,
  1512. int irq_flags, int irq_base,
  1513. const struct regmap_irq_chip *chip,
  1514. struct regmap_irq_chip_data **data);
  1515. void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data);
  1516. int devm_regmap_add_irq_chip(struct device *dev, struct regmap *map, int irq,
  1517. int irq_flags, int irq_base,
  1518. const struct regmap_irq_chip *chip,
  1519. struct regmap_irq_chip_data **data);
  1520. int devm_regmap_add_irq_chip_fwnode(struct device *dev,
  1521. struct fwnode_handle *fwnode,
  1522. struct regmap *map, int irq,
  1523. int irq_flags, int irq_base,
  1524. const struct regmap_irq_chip *chip,
  1525. struct regmap_irq_chip_data **data);
  1526. void devm_regmap_del_irq_chip(struct device *dev, int irq,
  1527. struct regmap_irq_chip_data *data);
  1528. int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data);
  1529. int regmap_irq_get_virq(struct regmap_irq_chip_data *data, int irq);
  1530. struct irq_domain *regmap_irq_get_domain(struct regmap_irq_chip_data *data);
  1531. #else
  1532. /*
  1533. * These stubs should only ever be called by generic code which has
  1534. * regmap based facilities, if they ever get called at runtime
  1535. * something is going wrong and something probably needs to select
  1536. * REGMAP.
  1537. */
  1538. static inline int regmap_write(struct regmap *map, unsigned int reg,
  1539. unsigned int val)
  1540. {
  1541. WARN_ONCE(1, "regmap API is disabled");
  1542. return -EINVAL;
  1543. }
  1544. static inline int regmap_write_async(struct regmap *map, unsigned int reg,
  1545. unsigned int val)
  1546. {
  1547. WARN_ONCE(1, "regmap API is disabled");
  1548. return -EINVAL;
  1549. }
  1550. static inline int regmap_raw_write(struct regmap *map, unsigned int reg,
  1551. const void *val, size_t val_len)
  1552. {
  1553. WARN_ONCE(1, "regmap API is disabled");
  1554. return -EINVAL;
  1555. }
  1556. static inline int regmap_raw_write_async(struct regmap *map, unsigned int reg,
  1557. const void *val, size_t val_len)
  1558. {
  1559. WARN_ONCE(1, "regmap API is disabled");
  1560. return -EINVAL;
  1561. }
  1562. static inline int regmap_noinc_write(struct regmap *map, unsigned int reg,
  1563. const void *val, size_t val_len)
  1564. {
  1565. WARN_ONCE(1, "regmap API is disabled");
  1566. return -EINVAL;
  1567. }
  1568. static inline int regmap_bulk_write(struct regmap *map, unsigned int reg,
  1569. const void *val, size_t val_count)
  1570. {
  1571. WARN_ONCE(1, "regmap API is disabled");
  1572. return -EINVAL;
  1573. }
  1574. static inline int regmap_read(struct regmap *map, unsigned int reg,
  1575. unsigned int *val)
  1576. {
  1577. WARN_ONCE(1, "regmap API is disabled");
  1578. return -EINVAL;
  1579. }
  1580. static inline int regmap_raw_read(struct regmap *map, unsigned int reg,
  1581. void *val, size_t val_len)
  1582. {
  1583. WARN_ONCE(1, "regmap API is disabled");
  1584. return -EINVAL;
  1585. }
  1586. static inline int regmap_noinc_read(struct regmap *map, unsigned int reg,
  1587. void *val, size_t val_len)
  1588. {
  1589. WARN_ONCE(1, "regmap API is disabled");
  1590. return -EINVAL;
  1591. }
  1592. static inline int regmap_bulk_read(struct regmap *map, unsigned int reg,
  1593. void *val, size_t val_count)
  1594. {
  1595. WARN_ONCE(1, "regmap API is disabled");
  1596. return -EINVAL;
  1597. }
  1598. static inline int regmap_update_bits_base(struct regmap *map, unsigned int reg,
  1599. unsigned int mask, unsigned int val,
  1600. bool *change, bool async, bool force)
  1601. {
  1602. WARN_ONCE(1, "regmap API is disabled");
  1603. return -EINVAL;
  1604. }
  1605. static inline int regmap_set_bits(struct regmap *map,
  1606. unsigned int reg, unsigned int bits)
  1607. {
  1608. WARN_ONCE(1, "regmap API is disabled");
  1609. return -EINVAL;
  1610. }
  1611. static inline int regmap_clear_bits(struct regmap *map,
  1612. unsigned int reg, unsigned int bits)
  1613. {
  1614. WARN_ONCE(1, "regmap API is disabled");
  1615. return -EINVAL;
  1616. }
  1617. static inline int regmap_test_bits(struct regmap *map,
  1618. unsigned int reg, unsigned int bits)
  1619. {
  1620. WARN_ONCE(1, "regmap API is disabled");
  1621. return -EINVAL;
  1622. }
  1623. static inline int regmap_field_update_bits_base(struct regmap_field *field,
  1624. unsigned int mask, unsigned int val,
  1625. bool *change, bool async, bool force)
  1626. {
  1627. WARN_ONCE(1, "regmap API is disabled");
  1628. return -EINVAL;
  1629. }
  1630. static inline int regmap_fields_update_bits_base(struct regmap_field *field,
  1631. unsigned int id,
  1632. unsigned int mask, unsigned int val,
  1633. bool *change, bool async, bool force)
  1634. {
  1635. WARN_ONCE(1, "regmap API is disabled");
  1636. return -EINVAL;
  1637. }
  1638. static inline int regmap_update_bits(struct regmap *map, unsigned int reg,
  1639. unsigned int mask, unsigned int val)
  1640. {
  1641. WARN_ONCE(1, "regmap API is disabled");
  1642. return -EINVAL;
  1643. }
  1644. static inline int regmap_update_bits_async(struct regmap *map, unsigned int reg,
  1645. unsigned int mask, unsigned int val)
  1646. {
  1647. WARN_ONCE(1, "regmap API is disabled");
  1648. return -EINVAL;
  1649. }
  1650. static inline int regmap_update_bits_check(struct regmap *map, unsigned int reg,
  1651. unsigned int mask, unsigned int val,
  1652. bool *change)
  1653. {
  1654. WARN_ONCE(1, "regmap API is disabled");
  1655. return -EINVAL;
  1656. }
  1657. static inline int
  1658. regmap_update_bits_check_async(struct regmap *map, unsigned int reg,
  1659. unsigned int mask, unsigned int val,
  1660. bool *change)
  1661. {
  1662. WARN_ONCE(1, "regmap API is disabled");
  1663. return -EINVAL;
  1664. }
  1665. static inline int regmap_write_bits(struct regmap *map, unsigned int reg,
  1666. unsigned int mask, unsigned int val)
  1667. {
  1668. WARN_ONCE(1, "regmap API is disabled");
  1669. return -EINVAL;
  1670. }
  1671. static inline int regmap_field_write(struct regmap_field *field,
  1672. unsigned int val)
  1673. {
  1674. WARN_ONCE(1, "regmap API is disabled");
  1675. return -EINVAL;
  1676. }
  1677. static inline int regmap_field_force_write(struct regmap_field *field,
  1678. unsigned int val)
  1679. {
  1680. WARN_ONCE(1, "regmap API is disabled");
  1681. return -EINVAL;
  1682. }
  1683. static inline int regmap_field_update_bits(struct regmap_field *field,
  1684. unsigned int mask, unsigned int val)
  1685. {
  1686. WARN_ONCE(1, "regmap API is disabled");
  1687. return -EINVAL;
  1688. }
  1689. static inline int
  1690. regmap_field_force_update_bits(struct regmap_field *field,
  1691. unsigned int mask, unsigned int val)
  1692. {
  1693. WARN_ONCE(1, "regmap API is disabled");
  1694. return -EINVAL;
  1695. }
  1696. static inline int regmap_field_set_bits(struct regmap_field *field,
  1697. unsigned int bits)
  1698. {
  1699. WARN_ONCE(1, "regmap API is disabled");
  1700. return -EINVAL;
  1701. }
  1702. static inline int regmap_field_clear_bits(struct regmap_field *field,
  1703. unsigned int bits)
  1704. {
  1705. WARN_ONCE(1, "regmap API is disabled");
  1706. return -EINVAL;
  1707. }
  1708. static inline int regmap_field_test_bits(struct regmap_field *field,
  1709. unsigned int bits)
  1710. {
  1711. WARN_ONCE(1, "regmap API is disabled");
  1712. return -EINVAL;
  1713. }
  1714. static inline int regmap_fields_write(struct regmap_field *field,
  1715. unsigned int id, unsigned int val)
  1716. {
  1717. WARN_ONCE(1, "regmap API is disabled");
  1718. return -EINVAL;
  1719. }
  1720. static inline int regmap_fields_force_write(struct regmap_field *field,
  1721. unsigned int id, unsigned int val)
  1722. {
  1723. WARN_ONCE(1, "regmap API is disabled");
  1724. return -EINVAL;
  1725. }
  1726. static inline int
  1727. regmap_fields_update_bits(struct regmap_field *field, unsigned int id,
  1728. unsigned int mask, unsigned int val)
  1729. {
  1730. WARN_ONCE(1, "regmap API is disabled");
  1731. return -EINVAL;
  1732. }
  1733. static inline int
  1734. regmap_fields_force_update_bits(struct regmap_field *field, unsigned int id,
  1735. unsigned int mask, unsigned int val)
  1736. {
  1737. WARN_ONCE(1, "regmap API is disabled");
  1738. return -EINVAL;
  1739. }
  1740. static inline int regmap_get_val_bytes(struct regmap *map)
  1741. {
  1742. WARN_ONCE(1, "regmap API is disabled");
  1743. return -EINVAL;
  1744. }
  1745. static inline int regmap_get_max_register(struct regmap *map)
  1746. {
  1747. WARN_ONCE(1, "regmap API is disabled");
  1748. return -EINVAL;
  1749. }
  1750. static inline int regmap_get_reg_stride(struct regmap *map)
  1751. {
  1752. WARN_ONCE(1, "regmap API is disabled");
  1753. return -EINVAL;
  1754. }
  1755. static inline int regcache_sync(struct regmap *map)
  1756. {
  1757. WARN_ONCE(1, "regmap API is disabled");
  1758. return -EINVAL;
  1759. }
  1760. static inline int regcache_sync_region(struct regmap *map, unsigned int min,
  1761. unsigned int max)
  1762. {
  1763. WARN_ONCE(1, "regmap API is disabled");
  1764. return -EINVAL;
  1765. }
  1766. static inline int regcache_drop_region(struct regmap *map, unsigned int min,
  1767. unsigned int max)
  1768. {
  1769. WARN_ONCE(1, "regmap API is disabled");
  1770. return -EINVAL;
  1771. }
  1772. static inline void regcache_cache_only(struct regmap *map, bool enable)
  1773. {
  1774. WARN_ONCE(1, "regmap API is disabled");
  1775. }
  1776. static inline void regcache_cache_bypass(struct regmap *map, bool enable)
  1777. {
  1778. WARN_ONCE(1, "regmap API is disabled");
  1779. }
  1780. static inline void regcache_mark_dirty(struct regmap *map)
  1781. {
  1782. WARN_ONCE(1, "regmap API is disabled");
  1783. }
  1784. static inline void regmap_async_complete(struct regmap *map)
  1785. {
  1786. WARN_ONCE(1, "regmap API is disabled");
  1787. }
  1788. static inline int regmap_register_patch(struct regmap *map,
  1789. const struct reg_sequence *regs,
  1790. int num_regs)
  1791. {
  1792. WARN_ONCE(1, "regmap API is disabled");
  1793. return -EINVAL;
  1794. }
  1795. static inline int regmap_parse_val(struct regmap *map, const void *buf,
  1796. unsigned int *val)
  1797. {
  1798. WARN_ONCE(1, "regmap API is disabled");
  1799. return -EINVAL;
  1800. }
  1801. static inline struct regmap *dev_get_regmap(struct device *dev,
  1802. const char *name)
  1803. {
  1804. return NULL;
  1805. }
  1806. static inline struct device *regmap_get_device(struct regmap *map)
  1807. {
  1808. WARN_ONCE(1, "regmap API is disabled");
  1809. return NULL;
  1810. }
  1811. #endif
  1812. #endif