regmap.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475
  1. /*
  2. * Register map access API
  3. *
  4. * Copyright 2011 Wolfson Microelectronics plc
  5. *
  6. * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/device.h>
  13. #include <linux/slab.h>
  14. #include <linux/export.h>
  15. #include <linux/mutex.h>
  16. #include <linux/err.h>
  17. #include <linux/rbtree.h>
  18. #define CREATE_TRACE_POINTS
  19. #include <trace/events/regmap.h>
  20. #include "internal.h"
  21. /*
  22. * Sometimes for failures during very early init the trace
  23. * infrastructure isn't available early enough to be used. For this
  24. * sort of problem defining LOG_DEVICE will add printks for basic
  25. * register I/O on a specific device.
  26. */
  27. #undef LOG_DEVICE
  28. static int _regmap_update_bits(struct regmap *map, unsigned int reg,
  29. unsigned int mask, unsigned int val,
  30. bool *change);
  31. bool regmap_writeable(struct regmap *map, unsigned int reg)
  32. {
  33. if (map->max_register && reg > map->max_register)
  34. return false;
  35. if (map->writeable_reg)
  36. return map->writeable_reg(map->dev, reg);
  37. return true;
  38. }
  39. bool regmap_readable(struct regmap *map, unsigned int reg)
  40. {
  41. if (map->max_register && reg > map->max_register)
  42. return false;
  43. if (map->format.format_write)
  44. return false;
  45. if (map->readable_reg)
  46. return map->readable_reg(map->dev, reg);
  47. return true;
  48. }
  49. bool regmap_volatile(struct regmap *map, unsigned int reg)
  50. {
  51. if (!regmap_readable(map, reg))
  52. return false;
  53. if (map->volatile_reg)
  54. return map->volatile_reg(map->dev, reg);
  55. return true;
  56. }
  57. bool regmap_precious(struct regmap *map, unsigned int reg)
  58. {
  59. if (!regmap_readable(map, reg))
  60. return false;
  61. if (map->precious_reg)
  62. return map->precious_reg(map->dev, reg);
  63. return false;
  64. }
  65. static bool regmap_volatile_range(struct regmap *map, unsigned int reg,
  66. unsigned int num)
  67. {
  68. unsigned int i;
  69. for (i = 0; i < num; i++)
  70. if (!regmap_volatile(map, reg + i))
  71. return false;
  72. return true;
  73. }
  74. static void regmap_format_2_6_write(struct regmap *map,
  75. unsigned int reg, unsigned int val)
  76. {
  77. u8 *out = map->work_buf;
  78. *out = (reg << 6) | val;
  79. }
  80. static void regmap_format_4_12_write(struct regmap *map,
  81. unsigned int reg, unsigned int val)
  82. {
  83. __be16 *out = map->work_buf;
  84. *out = cpu_to_be16((reg << 12) | val);
  85. }
  86. static void regmap_format_7_9_write(struct regmap *map,
  87. unsigned int reg, unsigned int val)
  88. {
  89. __be16 *out = map->work_buf;
  90. *out = cpu_to_be16((reg << 9) | val);
  91. }
  92. static void regmap_format_10_14_write(struct regmap *map,
  93. unsigned int reg, unsigned int val)
  94. {
  95. u8 *out = map->work_buf;
  96. out[2] = val;
  97. out[1] = (val >> 8) | (reg << 6);
  98. out[0] = reg >> 2;
  99. }
  100. static void regmap_format_8(void *buf, unsigned int val, unsigned int shift)
  101. {
  102. u8 *b = buf;
  103. b[0] = val << shift;
  104. }
  105. static void regmap_format_16_be(void *buf, unsigned int val, unsigned int shift)
  106. {
  107. __be16 *b = buf;
  108. b[0] = cpu_to_be16(val << shift);
  109. }
  110. static void regmap_format_16_native(void *buf, unsigned int val,
  111. unsigned int shift)
  112. {
  113. *(u16 *)buf = val << shift;
  114. }
  115. static void regmap_format_24(void *buf, unsigned int val, unsigned int shift)
  116. {
  117. u8 *b = buf;
  118. val <<= shift;
  119. b[0] = val >> 16;
  120. b[1] = val >> 8;
  121. b[2] = val;
  122. }
  123. static void regmap_format_32_be(void *buf, unsigned int val, unsigned int shift)
  124. {
  125. __be32 *b = buf;
  126. b[0] = cpu_to_be32(val << shift);
  127. }
  128. static void regmap_format_32_native(void *buf, unsigned int val,
  129. unsigned int shift)
  130. {
  131. *(u32 *)buf = val << shift;
  132. }
  133. static unsigned int regmap_parse_8(void *buf)
  134. {
  135. u8 *b = buf;
  136. return b[0];
  137. }
  138. static unsigned int regmap_parse_16_be(void *buf)
  139. {
  140. __be16 *b = buf;
  141. b[0] = be16_to_cpu(b[0]);
  142. return b[0];
  143. }
  144. static unsigned int regmap_parse_16_native(void *buf)
  145. {
  146. return *(u16 *)buf;
  147. }
  148. static unsigned int regmap_parse_24(void *buf)
  149. {
  150. u8 *b = buf;
  151. unsigned int ret = b[2];
  152. ret |= ((unsigned int)b[1]) << 8;
  153. ret |= ((unsigned int)b[0]) << 16;
  154. return ret;
  155. }
  156. static unsigned int regmap_parse_32_be(void *buf)
  157. {
  158. __be32 *b = buf;
  159. b[0] = be32_to_cpu(b[0]);
  160. return b[0];
  161. }
  162. static unsigned int regmap_parse_32_native(void *buf)
  163. {
  164. return *(u32 *)buf;
  165. }
  166. static void regmap_lock_mutex(struct regmap *map)
  167. {
  168. mutex_lock(&map->mutex);
  169. }
  170. static void regmap_unlock_mutex(struct regmap *map)
  171. {
  172. mutex_unlock(&map->mutex);
  173. }
  174. static void regmap_lock_spinlock(struct regmap *map)
  175. {
  176. spin_lock(&map->spinlock);
  177. }
  178. static void regmap_unlock_spinlock(struct regmap *map)
  179. {
  180. spin_unlock(&map->spinlock);
  181. }
  182. static void dev_get_regmap_release(struct device *dev, void *res)
  183. {
  184. /*
  185. * We don't actually have anything to do here; the goal here
  186. * is not to manage the regmap but to provide a simple way to
  187. * get the regmap back given a struct device.
  188. */
  189. }
  190. static bool _regmap_range_add(struct regmap *map,
  191. struct regmap_range_node *data)
  192. {
  193. struct rb_root *root = &map->range_tree;
  194. struct rb_node **new = &(root->rb_node), *parent = NULL;
  195. while (*new) {
  196. struct regmap_range_node *this =
  197. container_of(*new, struct regmap_range_node, node);
  198. parent = *new;
  199. if (data->range_max < this->range_min)
  200. new = &((*new)->rb_left);
  201. else if (data->range_min > this->range_max)
  202. new = &((*new)->rb_right);
  203. else
  204. return false;
  205. }
  206. rb_link_node(&data->node, parent, new);
  207. rb_insert_color(&data->node, root);
  208. return true;
  209. }
  210. static struct regmap_range_node *_regmap_range_lookup(struct regmap *map,
  211. unsigned int reg)
  212. {
  213. struct rb_node *node = map->range_tree.rb_node;
  214. while (node) {
  215. struct regmap_range_node *this =
  216. container_of(node, struct regmap_range_node, node);
  217. if (reg < this->range_min)
  218. node = node->rb_left;
  219. else if (reg > this->range_max)
  220. node = node->rb_right;
  221. else
  222. return this;
  223. }
  224. return NULL;
  225. }
  226. static void regmap_range_exit(struct regmap *map)
  227. {
  228. struct rb_node *next;
  229. struct regmap_range_node *range_node;
  230. next = rb_first(&map->range_tree);
  231. while (next) {
  232. range_node = rb_entry(next, struct regmap_range_node, node);
  233. next = rb_next(&range_node->node);
  234. rb_erase(&range_node->node, &map->range_tree);
  235. kfree(range_node);
  236. }
  237. kfree(map->selector_work_buf);
  238. }
  239. /**
  240. * regmap_init(): Initialise register map
  241. *
  242. * @dev: Device that will be interacted with
  243. * @bus: Bus-specific callbacks to use with device
  244. * @bus_context: Data passed to bus-specific callbacks
  245. * @config: Configuration for register map
  246. *
  247. * The return value will be an ERR_PTR() on error or a valid pointer to
  248. * a struct regmap. This function should generally not be called
  249. * directly, it should be called by bus-specific init functions.
  250. */
  251. struct regmap *regmap_init(struct device *dev,
  252. const struct regmap_bus *bus,
  253. void *bus_context,
  254. const struct regmap_config *config)
  255. {
  256. struct regmap *map, **m;
  257. int ret = -EINVAL;
  258. enum regmap_endian reg_endian, val_endian;
  259. int i, j;
  260. if (!bus || !config)
  261. goto err;
  262. map = kzalloc(sizeof(*map), GFP_KERNEL);
  263. if (map == NULL) {
  264. ret = -ENOMEM;
  265. goto err;
  266. }
  267. if (bus->fast_io) {
  268. spin_lock_init(&map->spinlock);
  269. map->lock = regmap_lock_spinlock;
  270. map->unlock = regmap_unlock_spinlock;
  271. } else {
  272. mutex_init(&map->mutex);
  273. map->lock = regmap_lock_mutex;
  274. map->unlock = regmap_unlock_mutex;
  275. }
  276. map->format.reg_bytes = DIV_ROUND_UP(config->reg_bits, 8);
  277. map->format.pad_bytes = config->pad_bits / 8;
  278. map->format.val_bytes = DIV_ROUND_UP(config->val_bits, 8);
  279. map->format.buf_size = DIV_ROUND_UP(config->reg_bits +
  280. config->val_bits + config->pad_bits, 8);
  281. map->reg_shift = config->pad_bits % 8;
  282. if (config->reg_stride)
  283. map->reg_stride = config->reg_stride;
  284. else
  285. map->reg_stride = 1;
  286. map->use_single_rw = config->use_single_rw;
  287. map->dev = dev;
  288. map->bus = bus;
  289. map->bus_context = bus_context;
  290. map->max_register = config->max_register;
  291. map->writeable_reg = config->writeable_reg;
  292. map->readable_reg = config->readable_reg;
  293. map->volatile_reg = config->volatile_reg;
  294. map->precious_reg = config->precious_reg;
  295. map->cache_type = config->cache_type;
  296. map->name = config->name;
  297. if (config->read_flag_mask || config->write_flag_mask) {
  298. map->read_flag_mask = config->read_flag_mask;
  299. map->write_flag_mask = config->write_flag_mask;
  300. } else {
  301. map->read_flag_mask = bus->read_flag_mask;
  302. }
  303. reg_endian = config->reg_format_endian;
  304. if (reg_endian == REGMAP_ENDIAN_DEFAULT)
  305. reg_endian = bus->reg_format_endian_default;
  306. if (reg_endian == REGMAP_ENDIAN_DEFAULT)
  307. reg_endian = REGMAP_ENDIAN_BIG;
  308. val_endian = config->val_format_endian;
  309. if (val_endian == REGMAP_ENDIAN_DEFAULT)
  310. val_endian = bus->val_format_endian_default;
  311. if (val_endian == REGMAP_ENDIAN_DEFAULT)
  312. val_endian = REGMAP_ENDIAN_BIG;
  313. switch (config->reg_bits + map->reg_shift) {
  314. case 2:
  315. switch (config->val_bits) {
  316. case 6:
  317. map->format.format_write = regmap_format_2_6_write;
  318. break;
  319. default:
  320. goto err_map;
  321. }
  322. break;
  323. case 4:
  324. switch (config->val_bits) {
  325. case 12:
  326. map->format.format_write = regmap_format_4_12_write;
  327. break;
  328. default:
  329. goto err_map;
  330. }
  331. break;
  332. case 7:
  333. switch (config->val_bits) {
  334. case 9:
  335. map->format.format_write = regmap_format_7_9_write;
  336. break;
  337. default:
  338. goto err_map;
  339. }
  340. break;
  341. case 10:
  342. switch (config->val_bits) {
  343. case 14:
  344. map->format.format_write = regmap_format_10_14_write;
  345. break;
  346. default:
  347. goto err_map;
  348. }
  349. break;
  350. case 8:
  351. map->format.format_reg = regmap_format_8;
  352. break;
  353. case 16:
  354. switch (reg_endian) {
  355. case REGMAP_ENDIAN_BIG:
  356. map->format.format_reg = regmap_format_16_be;
  357. break;
  358. case REGMAP_ENDIAN_NATIVE:
  359. map->format.format_reg = regmap_format_16_native;
  360. break;
  361. default:
  362. goto err_map;
  363. }
  364. break;
  365. case 32:
  366. switch (reg_endian) {
  367. case REGMAP_ENDIAN_BIG:
  368. map->format.format_reg = regmap_format_32_be;
  369. break;
  370. case REGMAP_ENDIAN_NATIVE:
  371. map->format.format_reg = regmap_format_32_native;
  372. break;
  373. default:
  374. goto err_map;
  375. }
  376. break;
  377. default:
  378. goto err_map;
  379. }
  380. switch (config->val_bits) {
  381. case 8:
  382. map->format.format_val = regmap_format_8;
  383. map->format.parse_val = regmap_parse_8;
  384. break;
  385. case 16:
  386. switch (val_endian) {
  387. case REGMAP_ENDIAN_BIG:
  388. map->format.format_val = regmap_format_16_be;
  389. map->format.parse_val = regmap_parse_16_be;
  390. break;
  391. case REGMAP_ENDIAN_NATIVE:
  392. map->format.format_val = regmap_format_16_native;
  393. map->format.parse_val = regmap_parse_16_native;
  394. break;
  395. default:
  396. goto err_map;
  397. }
  398. break;
  399. case 24:
  400. if (val_endian != REGMAP_ENDIAN_BIG)
  401. goto err_map;
  402. map->format.format_val = regmap_format_24;
  403. map->format.parse_val = regmap_parse_24;
  404. break;
  405. case 32:
  406. switch (val_endian) {
  407. case REGMAP_ENDIAN_BIG:
  408. map->format.format_val = regmap_format_32_be;
  409. map->format.parse_val = regmap_parse_32_be;
  410. break;
  411. case REGMAP_ENDIAN_NATIVE:
  412. map->format.format_val = regmap_format_32_native;
  413. map->format.parse_val = regmap_parse_32_native;
  414. break;
  415. default:
  416. goto err_map;
  417. }
  418. break;
  419. }
  420. if (map->format.format_write) {
  421. if ((reg_endian != REGMAP_ENDIAN_BIG) ||
  422. (val_endian != REGMAP_ENDIAN_BIG))
  423. goto err_map;
  424. map->use_single_rw = true;
  425. }
  426. if (!map->format.format_write &&
  427. !(map->format.format_reg && map->format.format_val))
  428. goto err_map;
  429. map->work_buf = kzalloc(map->format.buf_size, GFP_KERNEL);
  430. if (map->work_buf == NULL) {
  431. ret = -ENOMEM;
  432. goto err_map;
  433. }
  434. map->range_tree = RB_ROOT;
  435. for (i = 0; i < config->num_ranges; i++) {
  436. const struct regmap_range_cfg *range_cfg = &config->ranges[i];
  437. struct regmap_range_node *new;
  438. /* Sanity check */
  439. if (range_cfg->range_max < range_cfg->range_min) {
  440. dev_err(map->dev, "Invalid range %d: %d < %d\n", i,
  441. range_cfg->range_max, range_cfg->range_min);
  442. goto err_range;
  443. }
  444. if (range_cfg->range_max > map->max_register) {
  445. dev_err(map->dev, "Invalid range %d: %d > %d\n", i,
  446. range_cfg->range_max, map->max_register);
  447. goto err_range;
  448. }
  449. if (range_cfg->selector_reg > map->max_register) {
  450. dev_err(map->dev,
  451. "Invalid range %d: selector out of map\n", i);
  452. goto err_range;
  453. }
  454. if (range_cfg->window_len == 0) {
  455. dev_err(map->dev, "Invalid range %d: window_len 0\n",
  456. i);
  457. goto err_range;
  458. }
  459. /* Make sure, that this register range has no selector
  460. or data window within its boundary */
  461. for (j = 0; j < config->num_ranges; j++) {
  462. unsigned sel_reg = config->ranges[j].selector_reg;
  463. unsigned win_min = config->ranges[j].window_start;
  464. unsigned win_max = win_min +
  465. config->ranges[j].window_len - 1;
  466. if (range_cfg->range_min <= sel_reg &&
  467. sel_reg <= range_cfg->range_max) {
  468. dev_err(map->dev,
  469. "Range %d: selector for %d in window\n",
  470. i, j);
  471. goto err_range;
  472. }
  473. if (!(win_max < range_cfg->range_min ||
  474. win_min > range_cfg->range_max)) {
  475. dev_err(map->dev,
  476. "Range %d: window for %d in window\n",
  477. i, j);
  478. goto err_range;
  479. }
  480. }
  481. new = kzalloc(sizeof(*new), GFP_KERNEL);
  482. if (new == NULL) {
  483. ret = -ENOMEM;
  484. goto err_range;
  485. }
  486. new->map = map;
  487. new->name = range_cfg->name;
  488. new->range_min = range_cfg->range_min;
  489. new->range_max = range_cfg->range_max;
  490. new->selector_reg = range_cfg->selector_reg;
  491. new->selector_mask = range_cfg->selector_mask;
  492. new->selector_shift = range_cfg->selector_shift;
  493. new->window_start = range_cfg->window_start;
  494. new->window_len = range_cfg->window_len;
  495. if (_regmap_range_add(map, new) == false) {
  496. dev_err(map->dev, "Failed to add range %d\n", i);
  497. kfree(new);
  498. goto err_range;
  499. }
  500. if (map->selector_work_buf == NULL) {
  501. map->selector_work_buf =
  502. kzalloc(map->format.buf_size, GFP_KERNEL);
  503. if (map->selector_work_buf == NULL) {
  504. ret = -ENOMEM;
  505. goto err_range;
  506. }
  507. }
  508. }
  509. ret = regcache_init(map, config);
  510. if (ret != 0)
  511. goto err_range;
  512. regmap_debugfs_init(map, config->name);
  513. /* Add a devres resource for dev_get_regmap() */
  514. m = devres_alloc(dev_get_regmap_release, sizeof(*m), GFP_KERNEL);
  515. if (!m) {
  516. ret = -ENOMEM;
  517. goto err_debugfs;
  518. }
  519. *m = map;
  520. devres_add(dev, m);
  521. return map;
  522. err_debugfs:
  523. regmap_debugfs_exit(map);
  524. regcache_exit(map);
  525. err_range:
  526. regmap_range_exit(map);
  527. kfree(map->work_buf);
  528. err_map:
  529. kfree(map);
  530. err:
  531. return ERR_PTR(ret);
  532. }
  533. EXPORT_SYMBOL_GPL(regmap_init);
  534. static void devm_regmap_release(struct device *dev, void *res)
  535. {
  536. regmap_exit(*(struct regmap **)res);
  537. }
  538. /**
  539. * devm_regmap_init(): Initialise managed register map
  540. *
  541. * @dev: Device that will be interacted with
  542. * @bus: Bus-specific callbacks to use with device
  543. * @bus_context: Data passed to bus-specific callbacks
  544. * @config: Configuration for register map
  545. *
  546. * The return value will be an ERR_PTR() on error or a valid pointer
  547. * to a struct regmap. This function should generally not be called
  548. * directly, it should be called by bus-specific init functions. The
  549. * map will be automatically freed by the device management code.
  550. */
  551. struct regmap *devm_regmap_init(struct device *dev,
  552. const struct regmap_bus *bus,
  553. void *bus_context,
  554. const struct regmap_config *config)
  555. {
  556. struct regmap **ptr, *regmap;
  557. ptr = devres_alloc(devm_regmap_release, sizeof(*ptr), GFP_KERNEL);
  558. if (!ptr)
  559. return ERR_PTR(-ENOMEM);
  560. regmap = regmap_init(dev, bus, bus_context, config);
  561. if (!IS_ERR(regmap)) {
  562. *ptr = regmap;
  563. devres_add(dev, ptr);
  564. } else {
  565. devres_free(ptr);
  566. }
  567. return regmap;
  568. }
  569. EXPORT_SYMBOL_GPL(devm_regmap_init);
  570. /**
  571. * regmap_reinit_cache(): Reinitialise the current register cache
  572. *
  573. * @map: Register map to operate on.
  574. * @config: New configuration. Only the cache data will be used.
  575. *
  576. * Discard any existing register cache for the map and initialize a
  577. * new cache. This can be used to restore the cache to defaults or to
  578. * update the cache configuration to reflect runtime discovery of the
  579. * hardware.
  580. *
  581. * No explicit locking is done here, the user needs to ensure that
  582. * this function will not race with other calls to regmap.
  583. */
  584. int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config)
  585. {
  586. regcache_exit(map);
  587. regmap_debugfs_exit(map);
  588. map->max_register = config->max_register;
  589. map->writeable_reg = config->writeable_reg;
  590. map->readable_reg = config->readable_reg;
  591. map->volatile_reg = config->volatile_reg;
  592. map->precious_reg = config->precious_reg;
  593. map->cache_type = config->cache_type;
  594. regmap_debugfs_init(map, config->name);
  595. map->cache_bypass = false;
  596. map->cache_only = false;
  597. return regcache_init(map, config);
  598. }
  599. EXPORT_SYMBOL_GPL(regmap_reinit_cache);
  600. /**
  601. * regmap_exit(): Free a previously allocated register map
  602. */
  603. void regmap_exit(struct regmap *map)
  604. {
  605. regcache_exit(map);
  606. regmap_debugfs_exit(map);
  607. regmap_range_exit(map);
  608. if (map->bus->free_context)
  609. map->bus->free_context(map->bus_context);
  610. kfree(map->work_buf);
  611. kfree(map);
  612. }
  613. EXPORT_SYMBOL_GPL(regmap_exit);
  614. static int dev_get_regmap_match(struct device *dev, void *res, void *data)
  615. {
  616. struct regmap **r = res;
  617. if (!r || !*r) {
  618. WARN_ON(!r || !*r);
  619. return 0;
  620. }
  621. /* If the user didn't specify a name match any */
  622. if (data)
  623. return (*r)->name == data;
  624. else
  625. return 1;
  626. }
  627. /**
  628. * dev_get_regmap(): Obtain the regmap (if any) for a device
  629. *
  630. * @dev: Device to retrieve the map for
  631. * @name: Optional name for the register map, usually NULL.
  632. *
  633. * Returns the regmap for the device if one is present, or NULL. If
  634. * name is specified then it must match the name specified when
  635. * registering the device, if it is NULL then the first regmap found
  636. * will be used. Devices with multiple register maps are very rare,
  637. * generic code should normally not need to specify a name.
  638. */
  639. struct regmap *dev_get_regmap(struct device *dev, const char *name)
  640. {
  641. struct regmap **r = devres_find(dev, dev_get_regmap_release,
  642. dev_get_regmap_match, (void *)name);
  643. if (!r)
  644. return NULL;
  645. return *r;
  646. }
  647. EXPORT_SYMBOL_GPL(dev_get_regmap);
  648. static int _regmap_select_page(struct regmap *map, unsigned int *reg,
  649. struct regmap_range_node *range,
  650. unsigned int val_num)
  651. {
  652. void *orig_work_buf;
  653. unsigned int win_offset;
  654. unsigned int win_page;
  655. bool page_chg;
  656. int ret;
  657. win_offset = (*reg - range->range_min) % range->window_len;
  658. win_page = (*reg - range->range_min) / range->window_len;
  659. if (val_num > 1) {
  660. /* Bulk write shouldn't cross range boundary */
  661. if (*reg + val_num - 1 > range->range_max)
  662. return -EINVAL;
  663. /* ... or single page boundary */
  664. if (val_num > range->window_len - win_offset)
  665. return -EINVAL;
  666. }
  667. /* It is possible to have selector register inside data window.
  668. In that case, selector register is located on every page and
  669. it needs no page switching, when accessed alone. */
  670. if (val_num > 1 ||
  671. range->window_start + win_offset != range->selector_reg) {
  672. /* Use separate work_buf during page switching */
  673. orig_work_buf = map->work_buf;
  674. map->work_buf = map->selector_work_buf;
  675. ret = _regmap_update_bits(map, range->selector_reg,
  676. range->selector_mask,
  677. win_page << range->selector_shift,
  678. &page_chg);
  679. map->work_buf = orig_work_buf;
  680. if (ret != 0)
  681. return ret;
  682. }
  683. *reg = range->window_start + win_offset;
  684. return 0;
  685. }
  686. static int _regmap_raw_write(struct regmap *map, unsigned int reg,
  687. const void *val, size_t val_len)
  688. {
  689. struct regmap_range_node *range;
  690. u8 *u8 = map->work_buf;
  691. void *buf;
  692. int ret = -ENOTSUPP;
  693. size_t len;
  694. int i;
  695. /* Check for unwritable registers before we start */
  696. if (map->writeable_reg)
  697. for (i = 0; i < val_len / map->format.val_bytes; i++)
  698. if (!map->writeable_reg(map->dev,
  699. reg + (i * map->reg_stride)))
  700. return -EINVAL;
  701. if (!map->cache_bypass && map->format.parse_val) {
  702. unsigned int ival;
  703. int val_bytes = map->format.val_bytes;
  704. for (i = 0; i < val_len / val_bytes; i++) {
  705. memcpy(map->work_buf, val + (i * val_bytes), val_bytes);
  706. ival = map->format.parse_val(map->work_buf);
  707. ret = regcache_write(map, reg + (i * map->reg_stride),
  708. ival);
  709. if (ret) {
  710. dev_err(map->dev,
  711. "Error in caching of register: %x ret: %d\n",
  712. reg + i, ret);
  713. return ret;
  714. }
  715. }
  716. if (map->cache_only) {
  717. map->cache_dirty = true;
  718. return 0;
  719. }
  720. }
  721. range = _regmap_range_lookup(map, reg);
  722. if (range) {
  723. int val_num = val_len / map->format.val_bytes;
  724. int win_offset = (reg - range->range_min) % range->window_len;
  725. int win_residue = range->window_len - win_offset;
  726. /* If the write goes beyond the end of the window split it */
  727. while (val_num > win_residue) {
  728. dev_dbg(map->dev, "Writing window %d/%zu\n",
  729. win_residue, val_len / map->format.val_bytes);
  730. ret = _regmap_raw_write(map, reg, val, win_residue *
  731. map->format.val_bytes);
  732. if (ret != 0)
  733. return ret;
  734. reg += win_residue;
  735. val_num -= win_residue;
  736. val += win_residue * map->format.val_bytes;
  737. val_len -= win_residue * map->format.val_bytes;
  738. win_offset = (reg - range->range_min) %
  739. range->window_len;
  740. win_residue = range->window_len - win_offset;
  741. }
  742. ret = _regmap_select_page(map, &reg, range, val_num);
  743. if (ret != 0)
  744. return ret;
  745. }
  746. map->format.format_reg(map->work_buf, reg, map->reg_shift);
  747. u8[0] |= map->write_flag_mask;
  748. trace_regmap_hw_write_start(map->dev, reg,
  749. val_len / map->format.val_bytes);
  750. /* If we're doing a single register write we can probably just
  751. * send the work_buf directly, otherwise try to do a gather
  752. * write.
  753. */
  754. if (val == (map->work_buf + map->format.pad_bytes +
  755. map->format.reg_bytes))
  756. ret = map->bus->write(map->bus_context, map->work_buf,
  757. map->format.reg_bytes +
  758. map->format.pad_bytes +
  759. val_len);
  760. else if (map->bus->gather_write)
  761. ret = map->bus->gather_write(map->bus_context, map->work_buf,
  762. map->format.reg_bytes +
  763. map->format.pad_bytes,
  764. val, val_len);
  765. /* If that didn't work fall back on linearising by hand. */
  766. if (ret == -ENOTSUPP) {
  767. len = map->format.reg_bytes + map->format.pad_bytes + val_len;
  768. buf = kzalloc(len, GFP_KERNEL);
  769. if (!buf)
  770. return -ENOMEM;
  771. memcpy(buf, map->work_buf, map->format.reg_bytes);
  772. memcpy(buf + map->format.reg_bytes + map->format.pad_bytes,
  773. val, val_len);
  774. ret = map->bus->write(map->bus_context, buf, len);
  775. kfree(buf);
  776. }
  777. trace_regmap_hw_write_done(map->dev, reg,
  778. val_len / map->format.val_bytes);
  779. return ret;
  780. }
  781. int _regmap_write(struct regmap *map, unsigned int reg,
  782. unsigned int val)
  783. {
  784. struct regmap_range_node *range;
  785. int ret;
  786. BUG_ON(!map->format.format_write && !map->format.format_val);
  787. if (!map->cache_bypass && map->format.format_write) {
  788. ret = regcache_write(map, reg, val);
  789. if (ret != 0)
  790. return ret;
  791. if (map->cache_only) {
  792. map->cache_dirty = true;
  793. return 0;
  794. }
  795. }
  796. #ifdef LOG_DEVICE
  797. if (strcmp(dev_name(map->dev), LOG_DEVICE) == 0)
  798. dev_info(map->dev, "%x <= %x\n", reg, val);
  799. #endif
  800. trace_regmap_reg_write(map->dev, reg, val);
  801. if (map->format.format_write) {
  802. range = _regmap_range_lookup(map, reg);
  803. if (range) {
  804. ret = _regmap_select_page(map, &reg, range, 1);
  805. if (ret != 0)
  806. return ret;
  807. }
  808. map->format.format_write(map, reg, val);
  809. trace_regmap_hw_write_start(map->dev, reg, 1);
  810. ret = map->bus->write(map->bus_context, map->work_buf,
  811. map->format.buf_size);
  812. trace_regmap_hw_write_done(map->dev, reg, 1);
  813. return ret;
  814. } else {
  815. map->format.format_val(map->work_buf + map->format.reg_bytes
  816. + map->format.pad_bytes, val, 0);
  817. return _regmap_raw_write(map, reg,
  818. map->work_buf +
  819. map->format.reg_bytes +
  820. map->format.pad_bytes,
  821. map->format.val_bytes);
  822. }
  823. }
  824. /**
  825. * regmap_write(): Write a value to a single register
  826. *
  827. * @map: Register map to write to
  828. * @reg: Register to write to
  829. * @val: Value to be written
  830. *
  831. * A value of zero will be returned on success, a negative errno will
  832. * be returned in error cases.
  833. */
  834. int regmap_write(struct regmap *map, unsigned int reg, unsigned int val)
  835. {
  836. int ret;
  837. if (reg % map->reg_stride)
  838. return -EINVAL;
  839. map->lock(map);
  840. ret = _regmap_write(map, reg, val);
  841. map->unlock(map);
  842. return ret;
  843. }
  844. EXPORT_SYMBOL_GPL(regmap_write);
  845. /**
  846. * regmap_raw_write(): Write raw values to one or more registers
  847. *
  848. * @map: Register map to write to
  849. * @reg: Initial register to write to
  850. * @val: Block of data to be written, laid out for direct transmission to the
  851. * device
  852. * @val_len: Length of data pointed to by val.
  853. *
  854. * This function is intended to be used for things like firmware
  855. * download where a large block of data needs to be transferred to the
  856. * device. No formatting will be done on the data provided.
  857. *
  858. * A value of zero will be returned on success, a negative errno will
  859. * be returned in error cases.
  860. */
  861. int regmap_raw_write(struct regmap *map, unsigned int reg,
  862. const void *val, size_t val_len)
  863. {
  864. int ret;
  865. if (val_len % map->format.val_bytes)
  866. return -EINVAL;
  867. if (reg % map->reg_stride)
  868. return -EINVAL;
  869. map->lock(map);
  870. ret = _regmap_raw_write(map, reg, val, val_len);
  871. map->unlock(map);
  872. return ret;
  873. }
  874. EXPORT_SYMBOL_GPL(regmap_raw_write);
  875. /*
  876. * regmap_bulk_write(): Write multiple registers to the device
  877. *
  878. * @map: Register map to write to
  879. * @reg: First register to be write from
  880. * @val: Block of data to be written, in native register size for device
  881. * @val_count: Number of registers to write
  882. *
  883. * This function is intended to be used for writing a large block of
  884. * data to be device either in single transfer or multiple transfer.
  885. *
  886. * A value of zero will be returned on success, a negative errno will
  887. * be returned in error cases.
  888. */
  889. int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
  890. size_t val_count)
  891. {
  892. int ret = 0, i;
  893. size_t val_bytes = map->format.val_bytes;
  894. void *wval;
  895. if (!map->format.parse_val)
  896. return -EINVAL;
  897. if (reg % map->reg_stride)
  898. return -EINVAL;
  899. map->lock(map);
  900. /* No formatting is require if val_byte is 1 */
  901. if (val_bytes == 1) {
  902. wval = (void *)val;
  903. } else {
  904. wval = kmemdup(val, val_count * val_bytes, GFP_KERNEL);
  905. if (!wval) {
  906. ret = -ENOMEM;
  907. dev_err(map->dev, "Error in memory allocation\n");
  908. goto out;
  909. }
  910. for (i = 0; i < val_count * val_bytes; i += val_bytes)
  911. map->format.parse_val(wval + i);
  912. }
  913. /*
  914. * Some devices does not support bulk write, for
  915. * them we have a series of single write operations.
  916. */
  917. if (map->use_single_rw) {
  918. for (i = 0; i < val_count; i++) {
  919. ret = regmap_raw_write(map,
  920. reg + (i * map->reg_stride),
  921. val + (i * val_bytes),
  922. val_bytes);
  923. if (ret != 0)
  924. return ret;
  925. }
  926. } else {
  927. ret = _regmap_raw_write(map, reg, wval, val_bytes * val_count);
  928. }
  929. if (val_bytes != 1)
  930. kfree(wval);
  931. out:
  932. map->unlock(map);
  933. return ret;
  934. }
  935. EXPORT_SYMBOL_GPL(regmap_bulk_write);
  936. static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
  937. unsigned int val_len)
  938. {
  939. struct regmap_range_node *range;
  940. u8 *u8 = map->work_buf;
  941. int ret;
  942. range = _regmap_range_lookup(map, reg);
  943. if (range) {
  944. ret = _regmap_select_page(map, &reg, range,
  945. val_len / map->format.val_bytes);
  946. if (ret != 0)
  947. return ret;
  948. }
  949. map->format.format_reg(map->work_buf, reg, map->reg_shift);
  950. /*
  951. * Some buses or devices flag reads by setting the high bits in the
  952. * register addresss; since it's always the high bits for all
  953. * current formats we can do this here rather than in
  954. * formatting. This may break if we get interesting formats.
  955. */
  956. u8[0] |= map->read_flag_mask;
  957. trace_regmap_hw_read_start(map->dev, reg,
  958. val_len / map->format.val_bytes);
  959. ret = map->bus->read(map->bus_context, map->work_buf,
  960. map->format.reg_bytes + map->format.pad_bytes,
  961. val, val_len);
  962. trace_regmap_hw_read_done(map->dev, reg,
  963. val_len / map->format.val_bytes);
  964. return ret;
  965. }
  966. static int _regmap_read(struct regmap *map, unsigned int reg,
  967. unsigned int *val)
  968. {
  969. int ret;
  970. if (!map->cache_bypass) {
  971. ret = regcache_read(map, reg, val);
  972. if (ret == 0)
  973. return 0;
  974. }
  975. if (!map->format.parse_val)
  976. return -EINVAL;
  977. if (map->cache_only)
  978. return -EBUSY;
  979. ret = _regmap_raw_read(map, reg, map->work_buf, map->format.val_bytes);
  980. if (ret == 0) {
  981. *val = map->format.parse_val(map->work_buf);
  982. #ifdef LOG_DEVICE
  983. if (strcmp(dev_name(map->dev), LOG_DEVICE) == 0)
  984. dev_info(map->dev, "%x => %x\n", reg, *val);
  985. #endif
  986. trace_regmap_reg_read(map->dev, reg, *val);
  987. }
  988. if (ret == 0 && !map->cache_bypass)
  989. regcache_write(map, reg, *val);
  990. return ret;
  991. }
  992. /**
  993. * regmap_read(): Read a value from a single register
  994. *
  995. * @map: Register map to write to
  996. * @reg: Register to be read from
  997. * @val: Pointer to store read value
  998. *
  999. * A value of zero will be returned on success, a negative errno will
  1000. * be returned in error cases.
  1001. */
  1002. int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val)
  1003. {
  1004. int ret;
  1005. if (reg % map->reg_stride)
  1006. return -EINVAL;
  1007. map->lock(map);
  1008. ret = _regmap_read(map, reg, val);
  1009. map->unlock(map);
  1010. return ret;
  1011. }
  1012. EXPORT_SYMBOL_GPL(regmap_read);
  1013. /**
  1014. * regmap_raw_read(): Read raw data from the device
  1015. *
  1016. * @map: Register map to write to
  1017. * @reg: First register to be read from
  1018. * @val: Pointer to store read value
  1019. * @val_len: Size of data to read
  1020. *
  1021. * A value of zero will be returned on success, a negative errno will
  1022. * be returned in error cases.
  1023. */
  1024. int regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
  1025. size_t val_len)
  1026. {
  1027. size_t val_bytes = map->format.val_bytes;
  1028. size_t val_count = val_len / val_bytes;
  1029. unsigned int v;
  1030. int ret, i;
  1031. if (val_len % map->format.val_bytes)
  1032. return -EINVAL;
  1033. if (reg % map->reg_stride)
  1034. return -EINVAL;
  1035. map->lock(map);
  1036. if (regmap_volatile_range(map, reg, val_count) || map->cache_bypass ||
  1037. map->cache_type == REGCACHE_NONE) {
  1038. /* Physical block read if there's no cache involved */
  1039. ret = _regmap_raw_read(map, reg, val, val_len);
  1040. } else {
  1041. /* Otherwise go word by word for the cache; should be low
  1042. * cost as we expect to hit the cache.
  1043. */
  1044. for (i = 0; i < val_count; i++) {
  1045. ret = _regmap_read(map, reg + (i * map->reg_stride),
  1046. &v);
  1047. if (ret != 0)
  1048. goto out;
  1049. map->format.format_val(val + (i * val_bytes), v, 0);
  1050. }
  1051. }
  1052. out:
  1053. map->unlock(map);
  1054. return ret;
  1055. }
  1056. EXPORT_SYMBOL_GPL(regmap_raw_read);
  1057. /**
  1058. * regmap_bulk_read(): Read multiple registers from the device
  1059. *
  1060. * @map: Register map to write to
  1061. * @reg: First register to be read from
  1062. * @val: Pointer to store read value, in native register size for device
  1063. * @val_count: Number of registers to read
  1064. *
  1065. * A value of zero will be returned on success, a negative errno will
  1066. * be returned in error cases.
  1067. */
  1068. int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
  1069. size_t val_count)
  1070. {
  1071. int ret, i;
  1072. size_t val_bytes = map->format.val_bytes;
  1073. bool vol = regmap_volatile_range(map, reg, val_count);
  1074. if (!map->format.parse_val)
  1075. return -EINVAL;
  1076. if (reg % map->reg_stride)
  1077. return -EINVAL;
  1078. if (vol || map->cache_type == REGCACHE_NONE) {
  1079. /*
  1080. * Some devices does not support bulk read, for
  1081. * them we have a series of single read operations.
  1082. */
  1083. if (map->use_single_rw) {
  1084. for (i = 0; i < val_count; i++) {
  1085. ret = regmap_raw_read(map,
  1086. reg + (i * map->reg_stride),
  1087. val + (i * val_bytes),
  1088. val_bytes);
  1089. if (ret != 0)
  1090. return ret;
  1091. }
  1092. } else {
  1093. ret = regmap_raw_read(map, reg, val,
  1094. val_bytes * val_count);
  1095. if (ret != 0)
  1096. return ret;
  1097. }
  1098. for (i = 0; i < val_count * val_bytes; i += val_bytes)
  1099. map->format.parse_val(val + i);
  1100. } else {
  1101. for (i = 0; i < val_count; i++) {
  1102. unsigned int ival;
  1103. ret = regmap_read(map, reg + (i * map->reg_stride),
  1104. &ival);
  1105. if (ret != 0)
  1106. return ret;
  1107. memcpy(val + (i * val_bytes), &ival, val_bytes);
  1108. }
  1109. }
  1110. return 0;
  1111. }
  1112. EXPORT_SYMBOL_GPL(regmap_bulk_read);
  1113. static int _regmap_update_bits(struct regmap *map, unsigned int reg,
  1114. unsigned int mask, unsigned int val,
  1115. bool *change)
  1116. {
  1117. int ret;
  1118. unsigned int tmp, orig;
  1119. ret = _regmap_read(map, reg, &orig);
  1120. if (ret != 0)
  1121. return ret;
  1122. tmp = orig & ~mask;
  1123. tmp |= val & mask;
  1124. if (tmp != orig) {
  1125. ret = _regmap_write(map, reg, tmp);
  1126. *change = true;
  1127. } else {
  1128. *change = false;
  1129. }
  1130. return ret;
  1131. }
  1132. /**
  1133. * regmap_update_bits: Perform a read/modify/write cycle on the register map
  1134. *
  1135. * @map: Register map to update
  1136. * @reg: Register to update
  1137. * @mask: Bitmask to change
  1138. * @val: New value for bitmask
  1139. *
  1140. * Returns zero for success, a negative number on error.
  1141. */
  1142. int regmap_update_bits(struct regmap *map, unsigned int reg,
  1143. unsigned int mask, unsigned int val)
  1144. {
  1145. bool change;
  1146. int ret;
  1147. map->lock(map);
  1148. ret = _regmap_update_bits(map, reg, mask, val, &change);
  1149. map->unlock(map);
  1150. return ret;
  1151. }
  1152. EXPORT_SYMBOL_GPL(regmap_update_bits);
  1153. /**
  1154. * regmap_update_bits_check: Perform a read/modify/write cycle on the
  1155. * register map and report if updated
  1156. *
  1157. * @map: Register map to update
  1158. * @reg: Register to update
  1159. * @mask: Bitmask to change
  1160. * @val: New value for bitmask
  1161. * @change: Boolean indicating if a write was done
  1162. *
  1163. * Returns zero for success, a negative number on error.
  1164. */
  1165. int regmap_update_bits_check(struct regmap *map, unsigned int reg,
  1166. unsigned int mask, unsigned int val,
  1167. bool *change)
  1168. {
  1169. int ret;
  1170. map->lock(map);
  1171. ret = _regmap_update_bits(map, reg, mask, val, change);
  1172. map->unlock(map);
  1173. return ret;
  1174. }
  1175. EXPORT_SYMBOL_GPL(regmap_update_bits_check);
  1176. /**
  1177. * regmap_register_patch: Register and apply register updates to be applied
  1178. * on device initialistion
  1179. *
  1180. * @map: Register map to apply updates to.
  1181. * @regs: Values to update.
  1182. * @num_regs: Number of entries in regs.
  1183. *
  1184. * Register a set of register updates to be applied to the device
  1185. * whenever the device registers are synchronised with the cache and
  1186. * apply them immediately. Typically this is used to apply
  1187. * corrections to be applied to the device defaults on startup, such
  1188. * as the updates some vendors provide to undocumented registers.
  1189. */
  1190. int regmap_register_patch(struct regmap *map, const struct reg_default *regs,
  1191. int num_regs)
  1192. {
  1193. int i, ret;
  1194. bool bypass;
  1195. /* If needed the implementation can be extended to support this */
  1196. if (map->patch)
  1197. return -EBUSY;
  1198. map->lock(map);
  1199. bypass = map->cache_bypass;
  1200. map->cache_bypass = true;
  1201. /* Write out first; it's useful to apply even if we fail later. */
  1202. for (i = 0; i < num_regs; i++) {
  1203. ret = _regmap_write(map, regs[i].reg, regs[i].def);
  1204. if (ret != 0) {
  1205. dev_err(map->dev, "Failed to write %x = %x: %d\n",
  1206. regs[i].reg, regs[i].def, ret);
  1207. goto out;
  1208. }
  1209. }
  1210. map->patch = kcalloc(num_regs, sizeof(struct reg_default), GFP_KERNEL);
  1211. if (map->patch != NULL) {
  1212. memcpy(map->patch, regs,
  1213. num_regs * sizeof(struct reg_default));
  1214. map->patch_regs = num_regs;
  1215. } else {
  1216. ret = -ENOMEM;
  1217. }
  1218. out:
  1219. map->cache_bypass = bypass;
  1220. map->unlock(map);
  1221. return ret;
  1222. }
  1223. EXPORT_SYMBOL_GPL(regmap_register_patch);
  1224. /*
  1225. * regmap_get_val_bytes(): Report the size of a register value
  1226. *
  1227. * Report the size of a register value, mainly intended to for use by
  1228. * generic infrastructure built on top of regmap.
  1229. */
  1230. int regmap_get_val_bytes(struct regmap *map)
  1231. {
  1232. if (map->format.format_write)
  1233. return -EINVAL;
  1234. return map->format.val_bytes;
  1235. }
  1236. EXPORT_SYMBOL_GPL(regmap_get_val_bytes);
  1237. static int __init regmap_initcall(void)
  1238. {
  1239. regmap_debugfs_initcall();
  1240. return 0;
  1241. }
  1242. postcore_initcall(regmap_initcall);