regmap.h 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373
  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. * @readable_noinc_reg: Optional callback returning true if the register
  253. * supports multiple read operations without incrementing
  254. * the register number. If this field is NULL but
  255. * rd_noinc_table (see below) is not, the check is
  256. * performed on such table (a register is no increment
  257. * readable if it belongs to one of the ranges specified
  258. * by rd_noinc_table).
  259. * @disable_locking: This regmap is either protected by external means or
  260. * is guaranteed not be be accessed from multiple threads.
  261. * Don't use any locking mechanisms.
  262. * @lock: Optional lock callback (overrides regmap's default lock
  263. * function, based on spinlock or mutex).
  264. * @unlock: As above for unlocking.
  265. * @lock_arg: this field is passed as the only argument of lock/unlock
  266. * functions (ignored in case regular lock/unlock functions
  267. * are not overridden).
  268. * @reg_read: Optional callback that if filled will be used to perform
  269. * all the reads from the registers. Should only be provided for
  270. * devices whose read operation cannot be represented as a simple
  271. * read operation on a bus such as SPI, I2C, etc. Most of the
  272. * devices do not need this.
  273. * @reg_write: Same as above for writing.
  274. * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
  275. * to perform locking. This field is ignored if custom lock/unlock
  276. * functions are used (see fields lock/unlock of struct regmap_config).
  277. * This field is a duplicate of a similar file in
  278. * 'struct regmap_bus' and serves exact same purpose.
  279. * Use it only for "no-bus" cases.
  280. * @max_register: Optional, specifies the maximum valid register address.
  281. * @wr_table: Optional, points to a struct regmap_access_table specifying
  282. * valid ranges for write access.
  283. * @rd_table: As above, for read access.
  284. * @volatile_table: As above, for volatile registers.
  285. * @precious_table: As above, for precious registers.
  286. * @rd_noinc_table: As above, for no increment readable registers.
  287. * @reg_defaults: Power on reset values for registers (for use with
  288. * register cache support).
  289. * @num_reg_defaults: Number of elements in reg_defaults.
  290. *
  291. * @read_flag_mask: Mask to be set in the top bytes of the register when doing
  292. * a read.
  293. * @write_flag_mask: Mask to be set in the top bytes of the register when doing
  294. * a write. If both read_flag_mask and write_flag_mask are
  295. * empty and zero_flag_mask is not set the regmap_bus default
  296. * masks are used.
  297. * @zero_flag_mask: If set, read_flag_mask and write_flag_mask are used even
  298. * if they are both empty.
  299. * @use_single_rw: If set, converts the bulk read and write operations into
  300. * a series of single read and write operations. This is useful
  301. * for device that does not support bulk read and write.
  302. * @can_multi_write: If set, the device supports the multi write mode of bulk
  303. * write operations, if clear multi write requests will be
  304. * split into individual write operations
  305. *
  306. * @cache_type: The actual cache type.
  307. * @reg_defaults_raw: Power on reset values for registers (for use with
  308. * register cache support).
  309. * @num_reg_defaults_raw: Number of elements in reg_defaults_raw.
  310. * @reg_format_endian: Endianness for formatted register addresses. If this is
  311. * DEFAULT, the @reg_format_endian_default value from the
  312. * regmap bus is used.
  313. * @val_format_endian: Endianness for formatted register values. If this is
  314. * DEFAULT, the @reg_format_endian_default value from the
  315. * regmap bus is used.
  316. *
  317. * @ranges: Array of configuration entries for virtual address ranges.
  318. * @num_ranges: Number of range configuration entries.
  319. * @use_hwlock: Indicate if a hardware spinlock should be used.
  320. * @hwlock_id: Specify the hardware spinlock id.
  321. * @hwlock_mode: The hardware spinlock mode, should be HWLOCK_IRQSTATE,
  322. * HWLOCK_IRQ or 0.
  323. */
  324. struct regmap_config {
  325. const char *name;
  326. int reg_bits;
  327. int reg_stride;
  328. int pad_bits;
  329. int val_bits;
  330. bool (*writeable_reg)(struct device *dev, unsigned int reg);
  331. bool (*readable_reg)(struct device *dev, unsigned int reg);
  332. bool (*volatile_reg)(struct device *dev, unsigned int reg);
  333. bool (*precious_reg)(struct device *dev, unsigned int reg);
  334. bool (*readable_noinc_reg)(struct device *dev, unsigned int reg);
  335. bool disable_locking;
  336. regmap_lock lock;
  337. regmap_unlock unlock;
  338. void *lock_arg;
  339. int (*reg_read)(void *context, unsigned int reg, unsigned int *val);
  340. int (*reg_write)(void *context, unsigned int reg, unsigned int val);
  341. bool fast_io;
  342. unsigned int max_register;
  343. const struct regmap_access_table *wr_table;
  344. const struct regmap_access_table *rd_table;
  345. const struct regmap_access_table *volatile_table;
  346. const struct regmap_access_table *precious_table;
  347. const struct regmap_access_table *rd_noinc_table;
  348. const struct reg_default *reg_defaults;
  349. unsigned int num_reg_defaults;
  350. enum regcache_type cache_type;
  351. const void *reg_defaults_raw;
  352. unsigned int num_reg_defaults_raw;
  353. unsigned long read_flag_mask;
  354. unsigned long write_flag_mask;
  355. bool zero_flag_mask;
  356. bool use_single_rw;
  357. bool can_multi_write;
  358. enum regmap_endian reg_format_endian;
  359. enum regmap_endian val_format_endian;
  360. const struct regmap_range_cfg *ranges;
  361. unsigned int num_ranges;
  362. bool use_hwlock;
  363. unsigned int hwlock_id;
  364. unsigned int hwlock_mode;
  365. };
  366. /**
  367. * struct regmap_range_cfg - Configuration for indirectly accessed or paged
  368. * registers.
  369. *
  370. * @name: Descriptive name for diagnostics
  371. *
  372. * @range_min: Address of the lowest register address in virtual range.
  373. * @range_max: Address of the highest register in virtual range.
  374. *
  375. * @selector_reg: Register with selector field.
  376. * @selector_mask: Bit shift for selector value.
  377. * @selector_shift: Bit mask for selector value.
  378. *
  379. * @window_start: Address of first (lowest) register in data window.
  380. * @window_len: Number of registers in data window.
  381. *
  382. * Registers, mapped to this virtual range, are accessed in two steps:
  383. * 1. page selector register update;
  384. * 2. access through data window registers.
  385. */
  386. struct regmap_range_cfg {
  387. const char *name;
  388. /* Registers of virtual address range */
  389. unsigned int range_min;
  390. unsigned int range_max;
  391. /* Page selector for indirect addressing */
  392. unsigned int selector_reg;
  393. unsigned int selector_mask;
  394. int selector_shift;
  395. /* Data window (per each page) */
  396. unsigned int window_start;
  397. unsigned int window_len;
  398. };
  399. struct regmap_async;
  400. typedef int (*regmap_hw_write)(void *context, const void *data,
  401. size_t count);
  402. typedef int (*regmap_hw_gather_write)(void *context,
  403. const void *reg, size_t reg_len,
  404. const void *val, size_t val_len);
  405. typedef int (*regmap_hw_async_write)(void *context,
  406. const void *reg, size_t reg_len,
  407. const void *val, size_t val_len,
  408. struct regmap_async *async);
  409. typedef int (*regmap_hw_read)(void *context,
  410. const void *reg_buf, size_t reg_size,
  411. void *val_buf, size_t val_size);
  412. typedef int (*regmap_hw_reg_read)(void *context, unsigned int reg,
  413. unsigned int *val);
  414. typedef int (*regmap_hw_reg_write)(void *context, unsigned int reg,
  415. unsigned int val);
  416. typedef int (*regmap_hw_reg_update_bits)(void *context, unsigned int reg,
  417. unsigned int mask, unsigned int val);
  418. typedef struct regmap_async *(*regmap_hw_async_alloc)(void);
  419. typedef void (*regmap_hw_free_context)(void *context);
  420. /**
  421. * struct regmap_bus - Description of a hardware bus for the register map
  422. * infrastructure.
  423. *
  424. * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
  425. * to perform locking. This field is ignored if custom lock/unlock
  426. * functions are used (see fields lock/unlock of
  427. * struct regmap_config).
  428. * @write: Write operation.
  429. * @gather_write: Write operation with split register/value, return -ENOTSUPP
  430. * if not implemented on a given device.
  431. * @async_write: Write operation which completes asynchronously, optional and
  432. * must serialise with respect to non-async I/O.
  433. * @reg_write: Write a single register value to the given register address. This
  434. * write operation has to complete when returning from the function.
  435. * @reg_update_bits: Update bits operation to be used against volatile
  436. * registers, intended for devices supporting some mechanism
  437. * for setting clearing bits without having to
  438. * read/modify/write.
  439. * @read: Read operation. Data is returned in the buffer used to transmit
  440. * data.
  441. * @reg_read: Read a single register value from a given register address.
  442. * @free_context: Free context.
  443. * @async_alloc: Allocate a regmap_async() structure.
  444. * @read_flag_mask: Mask to be set in the top byte of the register when doing
  445. * a read.
  446. * @reg_format_endian_default: Default endianness for formatted register
  447. * addresses. Used when the regmap_config specifies DEFAULT. If this is
  448. * DEFAULT, BIG is assumed.
  449. * @val_format_endian_default: Default endianness for formatted register
  450. * values. Used when the regmap_config specifies DEFAULT. If this is
  451. * DEFAULT, BIG is assumed.
  452. * @max_raw_read: Max raw read size that can be used on the bus.
  453. * @max_raw_write: Max raw write size that can be used on the bus.
  454. */
  455. struct regmap_bus {
  456. bool fast_io;
  457. regmap_hw_write write;
  458. regmap_hw_gather_write gather_write;
  459. regmap_hw_async_write async_write;
  460. regmap_hw_reg_write reg_write;
  461. regmap_hw_reg_update_bits reg_update_bits;
  462. regmap_hw_read read;
  463. regmap_hw_reg_read reg_read;
  464. regmap_hw_free_context free_context;
  465. regmap_hw_async_alloc async_alloc;
  466. u8 read_flag_mask;
  467. enum regmap_endian reg_format_endian_default;
  468. enum regmap_endian val_format_endian_default;
  469. size_t max_raw_read;
  470. size_t max_raw_write;
  471. };
  472. /*
  473. * __regmap_init functions.
  474. *
  475. * These functions take a lock key and name parameter, and should not be called
  476. * directly. Instead, use the regmap_init macros that generate a key and name
  477. * for each call.
  478. */
  479. struct regmap *__regmap_init(struct device *dev,
  480. const struct regmap_bus *bus,
  481. void *bus_context,
  482. const struct regmap_config *config,
  483. struct lock_class_key *lock_key,
  484. const char *lock_name);
  485. struct regmap *__regmap_init_i2c(struct i2c_client *i2c,
  486. const struct regmap_config *config,
  487. struct lock_class_key *lock_key,
  488. const char *lock_name);
  489. struct regmap *__regmap_init_sccb(struct i2c_client *i2c,
  490. const struct regmap_config *config,
  491. struct lock_class_key *lock_key,
  492. const char *lock_name);
  493. struct regmap *__regmap_init_slimbus(struct slim_device *slimbus,
  494. const struct regmap_config *config,
  495. struct lock_class_key *lock_key,
  496. const char *lock_name);
  497. struct regmap *__regmap_init_spi(struct spi_device *dev,
  498. const struct regmap_config *config,
  499. struct lock_class_key *lock_key,
  500. const char *lock_name);
  501. struct regmap *__regmap_init_spmi_base(struct spmi_device *dev,
  502. const struct regmap_config *config,
  503. struct lock_class_key *lock_key,
  504. const char *lock_name);
  505. struct regmap *__regmap_init_spmi_ext(struct spmi_device *dev,
  506. const struct regmap_config *config,
  507. struct lock_class_key *lock_key,
  508. const char *lock_name);
  509. struct regmap *__regmap_init_w1(struct device *w1_dev,
  510. const struct regmap_config *config,
  511. struct lock_class_key *lock_key,
  512. const char *lock_name);
  513. struct regmap *__regmap_init_mmio_clk(struct device *dev, const char *clk_id,
  514. void __iomem *regs,
  515. const struct regmap_config *config,
  516. struct lock_class_key *lock_key,
  517. const char *lock_name);
  518. struct regmap *__regmap_init_ac97(struct snd_ac97 *ac97,
  519. const struct regmap_config *config,
  520. struct lock_class_key *lock_key,
  521. const char *lock_name);
  522. struct regmap *__regmap_init_sdw(struct sdw_slave *sdw,
  523. const struct regmap_config *config,
  524. struct lock_class_key *lock_key,
  525. const char *lock_name);
  526. struct regmap *__devm_regmap_init(struct device *dev,
  527. const struct regmap_bus *bus,
  528. void *bus_context,
  529. const struct regmap_config *config,
  530. struct lock_class_key *lock_key,
  531. const char *lock_name);
  532. struct regmap *__devm_regmap_init_i2c(struct i2c_client *i2c,
  533. const struct regmap_config *config,
  534. struct lock_class_key *lock_key,
  535. const char *lock_name);
  536. struct regmap *__devm_regmap_init_sccb(struct i2c_client *i2c,
  537. const struct regmap_config *config,
  538. struct lock_class_key *lock_key,
  539. const char *lock_name);
  540. struct regmap *__devm_regmap_init_spi(struct spi_device *dev,
  541. const struct regmap_config *config,
  542. struct lock_class_key *lock_key,
  543. const char *lock_name);
  544. struct regmap *__devm_regmap_init_spmi_base(struct spmi_device *dev,
  545. const struct regmap_config *config,
  546. struct lock_class_key *lock_key,
  547. const char *lock_name);
  548. struct regmap *__devm_regmap_init_spmi_ext(struct spmi_device *dev,
  549. const struct regmap_config *config,
  550. struct lock_class_key *lock_key,
  551. const char *lock_name);
  552. struct regmap *__devm_regmap_init_w1(struct device *w1_dev,
  553. const struct regmap_config *config,
  554. struct lock_class_key *lock_key,
  555. const char *lock_name);
  556. struct regmap *__devm_regmap_init_mmio_clk(struct device *dev,
  557. const char *clk_id,
  558. void __iomem *regs,
  559. const struct regmap_config *config,
  560. struct lock_class_key *lock_key,
  561. const char *lock_name);
  562. struct regmap *__devm_regmap_init_ac97(struct snd_ac97 *ac97,
  563. const struct regmap_config *config,
  564. struct lock_class_key *lock_key,
  565. const char *lock_name);
  566. struct regmap *__devm_regmap_init_sdw(struct sdw_slave *sdw,
  567. const struct regmap_config *config,
  568. struct lock_class_key *lock_key,
  569. const char *lock_name);
  570. struct regmap *__devm_regmap_init_slimbus(struct slim_device *slimbus,
  571. const struct regmap_config *config,
  572. struct lock_class_key *lock_key,
  573. const char *lock_name);
  574. /*
  575. * Wrapper for regmap_init macros to include a unique lockdep key and name
  576. * for each call. No-op if CONFIG_LOCKDEP is not set.
  577. *
  578. * @fn: Real function to call (in the form __[*_]regmap_init[_*])
  579. * @name: Config variable name (#config in the calling macro)
  580. **/
  581. #ifdef CONFIG_LOCKDEP
  582. #define __regmap_lockdep_wrapper(fn, name, ...) \
  583. ( \
  584. ({ \
  585. static struct lock_class_key _key; \
  586. fn(__VA_ARGS__, &_key, \
  587. KBUILD_BASENAME ":" \
  588. __stringify(__LINE__) ":" \
  589. "(" name ")->lock"); \
  590. }) \
  591. )
  592. #else
  593. #define __regmap_lockdep_wrapper(fn, name, ...) fn(__VA_ARGS__, NULL, NULL)
  594. #endif
  595. /**
  596. * regmap_init() - Initialise register map
  597. *
  598. * @dev: Device that will be interacted with
  599. * @bus: Bus-specific callbacks to use with device
  600. * @bus_context: Data passed to bus-specific callbacks
  601. * @config: Configuration for register map
  602. *
  603. * The return value will be an ERR_PTR() on error or a valid pointer to
  604. * a struct regmap. This function should generally not be called
  605. * directly, it should be called by bus-specific init functions.
  606. */
  607. #define regmap_init(dev, bus, bus_context, config) \
  608. __regmap_lockdep_wrapper(__regmap_init, #config, \
  609. dev, bus, bus_context, config)
  610. int regmap_attach_dev(struct device *dev, struct regmap *map,
  611. const struct regmap_config *config);
  612. /**
  613. * regmap_init_i2c() - Initialise register map
  614. *
  615. * @i2c: Device that will be interacted with
  616. * @config: Configuration for register map
  617. *
  618. * The return value will be an ERR_PTR() on error or a valid pointer to
  619. * a struct regmap.
  620. */
  621. #define regmap_init_i2c(i2c, config) \
  622. __regmap_lockdep_wrapper(__regmap_init_i2c, #config, \
  623. i2c, config)
  624. /**
  625. * regmap_init_sccb() - Initialise register map
  626. *
  627. * @i2c: Device that will be interacted with
  628. * @config: Configuration for register map
  629. *
  630. * The return value will be an ERR_PTR() on error or a valid pointer to
  631. * a struct regmap.
  632. */
  633. #define regmap_init_sccb(i2c, config) \
  634. __regmap_lockdep_wrapper(__regmap_init_sccb, #config, \
  635. i2c, config)
  636. /**
  637. * regmap_init_slimbus() - Initialise register map
  638. *
  639. * @slimbus: Device that will be interacted with
  640. * @config: Configuration for register map
  641. *
  642. * The return value will be an ERR_PTR() on error or a valid pointer to
  643. * a struct regmap.
  644. */
  645. #define regmap_init_slimbus(slimbus, config) \
  646. __regmap_lockdep_wrapper(__regmap_init_slimbus, #config, \
  647. slimbus, config)
  648. /**
  649. * regmap_init_spi() - Initialise register map
  650. *
  651. * @dev: Device that will be interacted with
  652. * @config: Configuration for register map
  653. *
  654. * The return value will be an ERR_PTR() on error or a valid pointer to
  655. * a struct regmap.
  656. */
  657. #define regmap_init_spi(dev, config) \
  658. __regmap_lockdep_wrapper(__regmap_init_spi, #config, \
  659. dev, config)
  660. /**
  661. * regmap_init_spmi_base() - Create regmap for the Base register space
  662. *
  663. * @dev: SPMI device that will be interacted with
  664. * @config: Configuration for register map
  665. *
  666. * The return value will be an ERR_PTR() on error or a valid pointer to
  667. * a struct regmap.
  668. */
  669. #define regmap_init_spmi_base(dev, config) \
  670. __regmap_lockdep_wrapper(__regmap_init_spmi_base, #config, \
  671. dev, config)
  672. /**
  673. * regmap_init_spmi_ext() - Create regmap for Ext register space
  674. *
  675. * @dev: Device that will be interacted with
  676. * @config: Configuration for register map
  677. *
  678. * The return value will be an ERR_PTR() on error or a valid pointer to
  679. * a struct regmap.
  680. */
  681. #define regmap_init_spmi_ext(dev, config) \
  682. __regmap_lockdep_wrapper(__regmap_init_spmi_ext, #config, \
  683. dev, config)
  684. /**
  685. * regmap_init_w1() - Initialise register map
  686. *
  687. * @w1_dev: Device that will be interacted with
  688. * @config: Configuration for register map
  689. *
  690. * The return value will be an ERR_PTR() on error or a valid pointer to
  691. * a struct regmap.
  692. */
  693. #define regmap_init_w1(w1_dev, config) \
  694. __regmap_lockdep_wrapper(__regmap_init_w1, #config, \
  695. w1_dev, config)
  696. /**
  697. * regmap_init_mmio_clk() - Initialise register map with register clock
  698. *
  699. * @dev: Device that will be interacted with
  700. * @clk_id: register clock consumer ID
  701. * @regs: Pointer to memory-mapped IO region
  702. * @config: Configuration for register map
  703. *
  704. * The return value will be an ERR_PTR() on error or a valid pointer to
  705. * a struct regmap.
  706. */
  707. #define regmap_init_mmio_clk(dev, clk_id, regs, config) \
  708. __regmap_lockdep_wrapper(__regmap_init_mmio_clk, #config, \
  709. dev, clk_id, regs, config)
  710. /**
  711. * regmap_init_mmio() - Initialise register map
  712. *
  713. * @dev: Device that will be interacted with
  714. * @regs: Pointer to memory-mapped IO region
  715. * @config: Configuration for register map
  716. *
  717. * The return value will be an ERR_PTR() on error or a valid pointer to
  718. * a struct regmap.
  719. */
  720. #define regmap_init_mmio(dev, regs, config) \
  721. regmap_init_mmio_clk(dev, NULL, regs, config)
  722. /**
  723. * regmap_init_ac97() - Initialise AC'97 register map
  724. *
  725. * @ac97: Device that will be interacted with
  726. * @config: Configuration for register map
  727. *
  728. * The return value will be an ERR_PTR() on error or a valid pointer to
  729. * a struct regmap.
  730. */
  731. #define regmap_init_ac97(ac97, config) \
  732. __regmap_lockdep_wrapper(__regmap_init_ac97, #config, \
  733. ac97, config)
  734. bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg);
  735. /**
  736. * regmap_init_sdw() - Initialise register map
  737. *
  738. * @sdw: Device that will be interacted with
  739. * @config: Configuration for register map
  740. *
  741. * The return value will be an ERR_PTR() on error or a valid pointer to
  742. * a struct regmap.
  743. */
  744. #define regmap_init_sdw(sdw, config) \
  745. __regmap_lockdep_wrapper(__regmap_init_sdw, #config, \
  746. sdw, config)
  747. /**
  748. * devm_regmap_init() - Initialise managed register map
  749. *
  750. * @dev: Device that will be interacted with
  751. * @bus: Bus-specific callbacks to use with device
  752. * @bus_context: Data passed to bus-specific callbacks
  753. * @config: Configuration for register map
  754. *
  755. * The return value will be an ERR_PTR() on error or a valid pointer
  756. * to a struct regmap. This function should generally not be called
  757. * directly, it should be called by bus-specific init functions. The
  758. * map will be automatically freed by the device management code.
  759. */
  760. #define devm_regmap_init(dev, bus, bus_context, config) \
  761. __regmap_lockdep_wrapper(__devm_regmap_init, #config, \
  762. dev, bus, bus_context, config)
  763. /**
  764. * devm_regmap_init_i2c() - Initialise managed register map
  765. *
  766. * @i2c: Device that will be interacted with
  767. * @config: Configuration for register map
  768. *
  769. * The return value will be an ERR_PTR() on error or a valid pointer
  770. * to a struct regmap. The regmap will be automatically freed by the
  771. * device management code.
  772. */
  773. #define devm_regmap_init_i2c(i2c, config) \
  774. __regmap_lockdep_wrapper(__devm_regmap_init_i2c, #config, \
  775. i2c, config)
  776. /**
  777. * devm_regmap_init_sccb() - Initialise managed register map
  778. *
  779. * @i2c: Device that will be interacted with
  780. * @config: Configuration for register map
  781. *
  782. * The return value will be an ERR_PTR() on error or a valid pointer
  783. * to a struct regmap. The regmap will be automatically freed by the
  784. * device management code.
  785. */
  786. #define devm_regmap_init_sccb(i2c, config) \
  787. __regmap_lockdep_wrapper(__devm_regmap_init_sccb, #config, \
  788. i2c, config)
  789. /**
  790. * devm_regmap_init_spi() - Initialise register map
  791. *
  792. * @dev: Device that will be interacted with
  793. * @config: Configuration for register map
  794. *
  795. * The return value will be an ERR_PTR() on error or a valid pointer
  796. * to a struct regmap. The map will be automatically freed by the
  797. * device management code.
  798. */
  799. #define devm_regmap_init_spi(dev, config) \
  800. __regmap_lockdep_wrapper(__devm_regmap_init_spi, #config, \
  801. dev, config)
  802. /**
  803. * devm_regmap_init_spmi_base() - Create managed regmap for Base register space
  804. *
  805. * @dev: SPMI device that will be interacted with
  806. * @config: Configuration for register map
  807. *
  808. * The return value will be an ERR_PTR() on error or a valid pointer
  809. * to a struct regmap. The regmap will be automatically freed by the
  810. * device management code.
  811. */
  812. #define devm_regmap_init_spmi_base(dev, config) \
  813. __regmap_lockdep_wrapper(__devm_regmap_init_spmi_base, #config, \
  814. dev, config)
  815. /**
  816. * devm_regmap_init_spmi_ext() - Create managed regmap for Ext register space
  817. *
  818. * @dev: SPMI device that will be interacted with
  819. * @config: Configuration for register map
  820. *
  821. * The return value will be an ERR_PTR() on error or a valid pointer
  822. * to a struct regmap. The regmap will be automatically freed by the
  823. * device management code.
  824. */
  825. #define devm_regmap_init_spmi_ext(dev, config) \
  826. __regmap_lockdep_wrapper(__devm_regmap_init_spmi_ext, #config, \
  827. dev, config)
  828. /**
  829. * devm_regmap_init_w1() - Initialise managed register map
  830. *
  831. * @w1_dev: Device that will be interacted with
  832. * @config: Configuration for register map
  833. *
  834. * The return value will be an ERR_PTR() on error or a valid pointer
  835. * to a struct regmap. The regmap will be automatically freed by the
  836. * device management code.
  837. */
  838. #define devm_regmap_init_w1(w1_dev, config) \
  839. __regmap_lockdep_wrapper(__devm_regmap_init_w1, #config, \
  840. w1_dev, config)
  841. /**
  842. * devm_regmap_init_mmio_clk() - Initialise managed register map with clock
  843. *
  844. * @dev: Device that will be interacted with
  845. * @clk_id: register clock consumer ID
  846. * @regs: Pointer to memory-mapped IO region
  847. * @config: Configuration for register map
  848. *
  849. * The return value will be an ERR_PTR() on error or a valid pointer
  850. * to a struct regmap. The regmap will be automatically freed by the
  851. * device management code.
  852. */
  853. #define devm_regmap_init_mmio_clk(dev, clk_id, regs, config) \
  854. __regmap_lockdep_wrapper(__devm_regmap_init_mmio_clk, #config, \
  855. dev, clk_id, regs, config)
  856. /**
  857. * devm_regmap_init_mmio() - Initialise managed register map
  858. *
  859. * @dev: Device that will be interacted with
  860. * @regs: Pointer to memory-mapped IO region
  861. * @config: Configuration for register map
  862. *
  863. * The return value will be an ERR_PTR() on error or a valid pointer
  864. * to a struct regmap. The regmap will be automatically freed by the
  865. * device management code.
  866. */
  867. #define devm_regmap_init_mmio(dev, regs, config) \
  868. devm_regmap_init_mmio_clk(dev, NULL, regs, config)
  869. /**
  870. * devm_regmap_init_ac97() - Initialise AC'97 register map
  871. *
  872. * @ac97: Device that will be interacted with
  873. * @config: Configuration for register map
  874. *
  875. * The return value will be an ERR_PTR() on error or a valid pointer
  876. * to a struct regmap. The regmap will be automatically freed by the
  877. * device management code.
  878. */
  879. #define devm_regmap_init_ac97(ac97, config) \
  880. __regmap_lockdep_wrapper(__devm_regmap_init_ac97, #config, \
  881. ac97, config)
  882. /**
  883. * devm_regmap_init_sdw() - Initialise managed register map
  884. *
  885. * @sdw: Device that will be interacted with
  886. * @config: Configuration for register map
  887. *
  888. * The return value will be an ERR_PTR() on error or a valid pointer
  889. * to a struct regmap. The regmap will be automatically freed by the
  890. * device management code.
  891. */
  892. #define devm_regmap_init_sdw(sdw, config) \
  893. __regmap_lockdep_wrapper(__devm_regmap_init_sdw, #config, \
  894. sdw, config)
  895. /**
  896. * devm_regmap_init_slimbus() - Initialise managed register map
  897. *
  898. * @slimbus: Device that will be interacted with
  899. * @config: Configuration for register map
  900. *
  901. * The return value will be an ERR_PTR() on error or a valid pointer
  902. * to a struct regmap. The regmap will be automatically freed by the
  903. * device management code.
  904. */
  905. #define devm_regmap_init_slimbus(slimbus, config) \
  906. __regmap_lockdep_wrapper(__devm_regmap_init_slimbus, #config, \
  907. slimbus, config)
  908. int regmap_mmio_attach_clk(struct regmap *map, struct clk *clk);
  909. void regmap_mmio_detach_clk(struct regmap *map);
  910. void regmap_exit(struct regmap *map);
  911. int regmap_reinit_cache(struct regmap *map,
  912. const struct regmap_config *config);
  913. struct regmap *dev_get_regmap(struct device *dev, const char *name);
  914. struct device *regmap_get_device(struct regmap *map);
  915. int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
  916. int regmap_write_async(struct regmap *map, unsigned int reg, unsigned int val);
  917. int regmap_raw_write(struct regmap *map, unsigned int reg,
  918. const void *val, size_t val_len);
  919. int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
  920. size_t val_count);
  921. int regmap_multi_reg_write(struct regmap *map, const struct reg_sequence *regs,
  922. int num_regs);
  923. int regmap_multi_reg_write_bypassed(struct regmap *map,
  924. const struct reg_sequence *regs,
  925. int num_regs);
  926. int regmap_raw_write_async(struct regmap *map, unsigned int reg,
  927. const void *val, size_t val_len);
  928. int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
  929. int regmap_raw_read(struct regmap *map, unsigned int reg,
  930. void *val, size_t val_len);
  931. int regmap_noinc_read(struct regmap *map, unsigned int reg,
  932. void *val, size_t val_len);
  933. int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
  934. size_t val_count);
  935. int regmap_update_bits_base(struct regmap *map, unsigned int reg,
  936. unsigned int mask, unsigned int val,
  937. bool *change, bool async, bool force);
  938. int regmap_get_val_bytes(struct regmap *map);
  939. int regmap_get_max_register(struct regmap *map);
  940. int regmap_get_reg_stride(struct regmap *map);
  941. int regmap_async_complete(struct regmap *map);
  942. bool regmap_can_raw_write(struct regmap *map);
  943. size_t regmap_get_raw_read_max(struct regmap *map);
  944. size_t regmap_get_raw_write_max(struct regmap *map);
  945. int regcache_sync(struct regmap *map);
  946. int regcache_sync_region(struct regmap *map, unsigned int min,
  947. unsigned int max);
  948. int regcache_drop_region(struct regmap *map, unsigned int min,
  949. unsigned int max);
  950. void regcache_cache_only(struct regmap *map, bool enable);
  951. void regcache_cache_bypass(struct regmap *map, bool enable);
  952. void regcache_mark_dirty(struct regmap *map);
  953. bool regmap_check_range_table(struct regmap *map, unsigned int reg,
  954. const struct regmap_access_table *table);
  955. int regmap_register_patch(struct regmap *map, const struct reg_sequence *regs,
  956. int num_regs);
  957. int regmap_parse_val(struct regmap *map, const void *buf,
  958. unsigned int *val);
  959. static inline bool regmap_reg_in_range(unsigned int reg,
  960. const struct regmap_range *range)
  961. {
  962. return reg >= range->range_min && reg <= range->range_max;
  963. }
  964. bool regmap_reg_in_ranges(unsigned int reg,
  965. const struct regmap_range *ranges,
  966. unsigned int nranges);
  967. /**
  968. * struct reg_field - Description of an register field
  969. *
  970. * @reg: Offset of the register within the regmap bank
  971. * @lsb: lsb of the register field.
  972. * @msb: msb of the register field.
  973. * @id_size: port size if it has some ports
  974. * @id_offset: address offset for each ports
  975. */
  976. struct reg_field {
  977. unsigned int reg;
  978. unsigned int lsb;
  979. unsigned int msb;
  980. unsigned int id_size;
  981. unsigned int id_offset;
  982. };
  983. #define REG_FIELD(_reg, _lsb, _msb) { \
  984. .reg = _reg, \
  985. .lsb = _lsb, \
  986. .msb = _msb, \
  987. }
  988. struct regmap_field *regmap_field_alloc(struct regmap *regmap,
  989. struct reg_field reg_field);
  990. void regmap_field_free(struct regmap_field *field);
  991. struct regmap_field *devm_regmap_field_alloc(struct device *dev,
  992. struct regmap *regmap, struct reg_field reg_field);
  993. void devm_regmap_field_free(struct device *dev, struct regmap_field *field);
  994. int regmap_field_read(struct regmap_field *field, unsigned int *val);
  995. int regmap_field_update_bits_base(struct regmap_field *field,
  996. unsigned int mask, unsigned int val,
  997. bool *change, bool async, bool force);
  998. int regmap_fields_read(struct regmap_field *field, unsigned int id,
  999. unsigned int *val);
  1000. int regmap_fields_update_bits_base(struct regmap_field *field, unsigned int id,
  1001. unsigned int mask, unsigned int val,
  1002. bool *change, bool async, bool force);
  1003. /**
  1004. * struct regmap_irq - Description of an IRQ for the generic regmap irq_chip.
  1005. *
  1006. * @reg_offset: Offset of the status/mask register within the bank
  1007. * @mask: Mask used to flag/control the register.
  1008. * @type_reg_offset: Offset register for the irq type setting.
  1009. * @type_rising_mask: Mask bit to configure RISING type irq.
  1010. * @type_falling_mask: Mask bit to configure FALLING type irq.
  1011. */
  1012. struct regmap_irq {
  1013. unsigned int reg_offset;
  1014. unsigned int mask;
  1015. unsigned int type_reg_offset;
  1016. unsigned int type_rising_mask;
  1017. unsigned int type_falling_mask;
  1018. };
  1019. #define REGMAP_IRQ_REG(_irq, _off, _mask) \
  1020. [_irq] = { .reg_offset = (_off), .mask = (_mask) }
  1021. /**
  1022. * struct regmap_irq_chip - Description of a generic regmap irq_chip.
  1023. *
  1024. * @name: Descriptive name for IRQ controller.
  1025. *
  1026. * @status_base: Base status register address.
  1027. * @mask_base: Base mask register address.
  1028. * @mask_writeonly: Base mask register is write only.
  1029. * @unmask_base: Base unmask register address. for chips who have
  1030. * separate mask and unmask registers
  1031. * @ack_base: Base ack address. If zero then the chip is clear on read.
  1032. * Using zero value is possible with @use_ack bit.
  1033. * @wake_base: Base address for wake enables. If zero unsupported.
  1034. * @type_base: Base address for irq type. If zero unsupported.
  1035. * @irq_reg_stride: Stride to use for chips where registers are not contiguous.
  1036. * @init_ack_masked: Ack all masked interrupts once during initalization.
  1037. * @mask_invert: Inverted mask register: cleared bits are masked out.
  1038. * @use_ack: Use @ack register even if it is zero.
  1039. * @ack_invert: Inverted ack register: cleared bits for ack.
  1040. * @wake_invert: Inverted wake register: cleared bits are wake enabled.
  1041. * @type_invert: Invert the type flags.
  1042. * @runtime_pm: Hold a runtime PM lock on the device when accessing it.
  1043. *
  1044. * @num_regs: Number of registers in each control bank.
  1045. * @irqs: Descriptors for individual IRQs. Interrupt numbers are
  1046. * assigned based on the index in the array of the interrupt.
  1047. * @num_irqs: Number of descriptors.
  1048. * @num_type_reg: Number of type registers.
  1049. * @type_reg_stride: Stride to use for chips where type registers are not
  1050. * contiguous.
  1051. * @handle_pre_irq: Driver specific callback to handle interrupt from device
  1052. * before regmap_irq_handler process the interrupts.
  1053. * @handle_post_irq: Driver specific callback to handle interrupt from device
  1054. * after handling the interrupts in regmap_irq_handler().
  1055. * @irq_drv_data: Driver specific IRQ data which is passed as parameter when
  1056. * driver specific pre/post interrupt handler is called.
  1057. *
  1058. * This is not intended to handle every possible interrupt controller, but
  1059. * it should handle a substantial proportion of those that are found in the
  1060. * wild.
  1061. */
  1062. struct regmap_irq_chip {
  1063. const char *name;
  1064. unsigned int status_base;
  1065. unsigned int mask_base;
  1066. unsigned int unmask_base;
  1067. unsigned int ack_base;
  1068. unsigned int wake_base;
  1069. unsigned int type_base;
  1070. unsigned int irq_reg_stride;
  1071. bool mask_writeonly:1;
  1072. bool init_ack_masked:1;
  1073. bool mask_invert:1;
  1074. bool use_ack:1;
  1075. bool ack_invert:1;
  1076. bool wake_invert:1;
  1077. bool runtime_pm:1;
  1078. bool type_invert:1;
  1079. int num_regs;
  1080. const struct regmap_irq *irqs;
  1081. int num_irqs;
  1082. int num_type_reg;
  1083. unsigned int type_reg_stride;
  1084. int (*handle_pre_irq)(void *irq_drv_data);
  1085. int (*handle_post_irq)(void *irq_drv_data);
  1086. void *irq_drv_data;
  1087. };
  1088. struct regmap_irq_chip_data;
  1089. int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
  1090. int irq_base, const struct regmap_irq_chip *chip,
  1091. struct regmap_irq_chip_data **data);
  1092. void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data);
  1093. int devm_regmap_add_irq_chip(struct device *dev, struct regmap *map, int irq,
  1094. int irq_flags, int irq_base,
  1095. const struct regmap_irq_chip *chip,
  1096. struct regmap_irq_chip_data **data);
  1097. void devm_regmap_del_irq_chip(struct device *dev, int irq,
  1098. struct regmap_irq_chip_data *data);
  1099. int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data);
  1100. int regmap_irq_get_virq(struct regmap_irq_chip_data *data, int irq);
  1101. struct irq_domain *regmap_irq_get_domain(struct regmap_irq_chip_data *data);
  1102. #else
  1103. /*
  1104. * These stubs should only ever be called by generic code which has
  1105. * regmap based facilities, if they ever get called at runtime
  1106. * something is going wrong and something probably needs to select
  1107. * REGMAP.
  1108. */
  1109. static inline int regmap_write(struct regmap *map, unsigned int reg,
  1110. unsigned int val)
  1111. {
  1112. WARN_ONCE(1, "regmap API is disabled");
  1113. return -EINVAL;
  1114. }
  1115. static inline int regmap_write_async(struct regmap *map, unsigned int reg,
  1116. unsigned int val)
  1117. {
  1118. WARN_ONCE(1, "regmap API is disabled");
  1119. return -EINVAL;
  1120. }
  1121. static inline int regmap_raw_write(struct regmap *map, unsigned int reg,
  1122. const void *val, size_t val_len)
  1123. {
  1124. WARN_ONCE(1, "regmap API is disabled");
  1125. return -EINVAL;
  1126. }
  1127. static inline int regmap_raw_write_async(struct regmap *map, unsigned int reg,
  1128. const void *val, size_t val_len)
  1129. {
  1130. WARN_ONCE(1, "regmap API is disabled");
  1131. return -EINVAL;
  1132. }
  1133. static inline int regmap_bulk_write(struct regmap *map, unsigned int reg,
  1134. const void *val, size_t val_count)
  1135. {
  1136. WARN_ONCE(1, "regmap API is disabled");
  1137. return -EINVAL;
  1138. }
  1139. static inline int regmap_read(struct regmap *map, unsigned int reg,
  1140. unsigned int *val)
  1141. {
  1142. WARN_ONCE(1, "regmap API is disabled");
  1143. return -EINVAL;
  1144. }
  1145. static inline int regmap_raw_read(struct regmap *map, unsigned int reg,
  1146. void *val, size_t val_len)
  1147. {
  1148. WARN_ONCE(1, "regmap API is disabled");
  1149. return -EINVAL;
  1150. }
  1151. static inline int regmap_noinc_read(struct regmap *map, unsigned int reg,
  1152. void *val, size_t val_len)
  1153. {
  1154. WARN_ONCE(1, "regmap API is disabled");
  1155. return -EINVAL;
  1156. }
  1157. static inline int regmap_bulk_read(struct regmap *map, unsigned int reg,
  1158. void *val, size_t val_count)
  1159. {
  1160. WARN_ONCE(1, "regmap API is disabled");
  1161. return -EINVAL;
  1162. }
  1163. static inline int regmap_update_bits_base(struct regmap *map, unsigned int reg,
  1164. unsigned int mask, unsigned int val,
  1165. bool *change, bool async, bool force)
  1166. {
  1167. WARN_ONCE(1, "regmap API is disabled");
  1168. return -EINVAL;
  1169. }
  1170. static inline int regmap_field_update_bits_base(struct regmap_field *field,
  1171. unsigned int mask, unsigned int val,
  1172. bool *change, bool async, bool force)
  1173. {
  1174. WARN_ONCE(1, "regmap API is disabled");
  1175. return -EINVAL;
  1176. }
  1177. static inline int regmap_fields_update_bits_base(struct regmap_field *field,
  1178. unsigned int id,
  1179. unsigned int mask, unsigned int val,
  1180. bool *change, bool async, bool force)
  1181. {
  1182. WARN_ONCE(1, "regmap API is disabled");
  1183. return -EINVAL;
  1184. }
  1185. static inline int regmap_get_val_bytes(struct regmap *map)
  1186. {
  1187. WARN_ONCE(1, "regmap API is disabled");
  1188. return -EINVAL;
  1189. }
  1190. static inline int regmap_get_max_register(struct regmap *map)
  1191. {
  1192. WARN_ONCE(1, "regmap API is disabled");
  1193. return -EINVAL;
  1194. }
  1195. static inline int regmap_get_reg_stride(struct regmap *map)
  1196. {
  1197. WARN_ONCE(1, "regmap API is disabled");
  1198. return -EINVAL;
  1199. }
  1200. static inline int regcache_sync(struct regmap *map)
  1201. {
  1202. WARN_ONCE(1, "regmap API is disabled");
  1203. return -EINVAL;
  1204. }
  1205. static inline int regcache_sync_region(struct regmap *map, unsigned int min,
  1206. unsigned int max)
  1207. {
  1208. WARN_ONCE(1, "regmap API is disabled");
  1209. return -EINVAL;
  1210. }
  1211. static inline int regcache_drop_region(struct regmap *map, unsigned int min,
  1212. unsigned int max)
  1213. {
  1214. WARN_ONCE(1, "regmap API is disabled");
  1215. return -EINVAL;
  1216. }
  1217. static inline void regcache_cache_only(struct regmap *map, bool enable)
  1218. {
  1219. WARN_ONCE(1, "regmap API is disabled");
  1220. }
  1221. static inline void regcache_cache_bypass(struct regmap *map, bool enable)
  1222. {
  1223. WARN_ONCE(1, "regmap API is disabled");
  1224. }
  1225. static inline void regcache_mark_dirty(struct regmap *map)
  1226. {
  1227. WARN_ONCE(1, "regmap API is disabled");
  1228. }
  1229. static inline void regmap_async_complete(struct regmap *map)
  1230. {
  1231. WARN_ONCE(1, "regmap API is disabled");
  1232. }
  1233. static inline int regmap_register_patch(struct regmap *map,
  1234. const struct reg_sequence *regs,
  1235. int num_regs)
  1236. {
  1237. WARN_ONCE(1, "regmap API is disabled");
  1238. return -EINVAL;
  1239. }
  1240. static inline int regmap_parse_val(struct regmap *map, const void *buf,
  1241. unsigned int *val)
  1242. {
  1243. WARN_ONCE(1, "regmap API is disabled");
  1244. return -EINVAL;
  1245. }
  1246. static inline struct regmap *dev_get_regmap(struct device *dev,
  1247. const char *name)
  1248. {
  1249. return NULL;
  1250. }
  1251. static inline struct device *regmap_get_device(struct regmap *map)
  1252. {
  1253. WARN_ONCE(1, "regmap API is disabled");
  1254. return NULL;
  1255. }
  1256. #endif
  1257. #endif