regmap.h 35 KB

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