regcache.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  1. /*
  2. * Register cache access API
  3. *
  4. * Copyright 2011 Wolfson Microelectronics plc
  5. *
  6. * Author: Dimitris Papastamos <dp@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/bsearch.h>
  13. #include <linux/device.h>
  14. #include <linux/export.h>
  15. #include <linux/slab.h>
  16. #include <linux/sort.h>
  17. #include "trace.h"
  18. #include "internal.h"
  19. static const struct regcache_ops *cache_types[] = {
  20. &regcache_rbtree_ops,
  21. &regcache_lzo_ops,
  22. &regcache_flat_ops,
  23. };
  24. static int regcache_hw_init(struct regmap *map)
  25. {
  26. int i, j;
  27. int ret;
  28. int count;
  29. unsigned int reg, val;
  30. void *tmp_buf;
  31. if (!map->num_reg_defaults_raw)
  32. return -EINVAL;
  33. /* calculate the size of reg_defaults */
  34. for (count = 0, i = 0; i < map->num_reg_defaults_raw; i++)
  35. if (regmap_readable(map, i * map->reg_stride) &&
  36. !regmap_volatile(map, i * map->reg_stride))
  37. count++;
  38. /* all registers are unreadable or volatile, so just bypass */
  39. if (!count) {
  40. map->cache_bypass = true;
  41. return 0;
  42. }
  43. map->num_reg_defaults = count;
  44. map->reg_defaults = kmalloc_array(count, sizeof(struct reg_default),
  45. GFP_KERNEL);
  46. if (!map->reg_defaults)
  47. return -ENOMEM;
  48. if (!map->reg_defaults_raw) {
  49. bool cache_bypass = map->cache_bypass;
  50. dev_warn(map->dev, "No cache defaults, reading back from HW\n");
  51. /* Bypass the cache access till data read from HW */
  52. map->cache_bypass = true;
  53. tmp_buf = kmalloc(map->cache_size_raw, GFP_KERNEL);
  54. if (!tmp_buf) {
  55. ret = -ENOMEM;
  56. goto err_free;
  57. }
  58. ret = regmap_raw_read(map, 0, tmp_buf,
  59. map->cache_size_raw);
  60. map->cache_bypass = cache_bypass;
  61. if (ret == 0) {
  62. map->reg_defaults_raw = tmp_buf;
  63. map->cache_free = 1;
  64. } else {
  65. kfree(tmp_buf);
  66. }
  67. }
  68. /* fill the reg_defaults */
  69. for (i = 0, j = 0; i < map->num_reg_defaults_raw; i++) {
  70. reg = i * map->reg_stride;
  71. if (!regmap_readable(map, reg))
  72. continue;
  73. if (regmap_volatile(map, reg))
  74. continue;
  75. if (map->reg_defaults_raw) {
  76. val = regcache_get_val(map, map->reg_defaults_raw, i);
  77. } else {
  78. bool cache_bypass = map->cache_bypass;
  79. map->cache_bypass = true;
  80. ret = regmap_read(map, reg, &val);
  81. map->cache_bypass = cache_bypass;
  82. if (ret != 0) {
  83. dev_err(map->dev, "Failed to read %d: %d\n",
  84. reg, ret);
  85. goto err_free;
  86. }
  87. }
  88. map->reg_defaults[j].reg = reg;
  89. map->reg_defaults[j].def = val;
  90. j++;
  91. }
  92. return 0;
  93. err_free:
  94. kfree(map->reg_defaults);
  95. return ret;
  96. }
  97. int regcache_init(struct regmap *map, const struct regmap_config *config)
  98. {
  99. int ret;
  100. int i;
  101. void *tmp_buf;
  102. if (map->cache_type == REGCACHE_NONE) {
  103. if (config->reg_defaults || config->num_reg_defaults_raw)
  104. dev_warn(map->dev,
  105. "No cache used with register defaults set!\n");
  106. map->cache_bypass = true;
  107. return 0;
  108. }
  109. if (config->reg_defaults && !config->num_reg_defaults) {
  110. dev_err(map->dev,
  111. "Register defaults are set without the number!\n");
  112. return -EINVAL;
  113. }
  114. for (i = 0; i < config->num_reg_defaults; i++)
  115. if (config->reg_defaults[i].reg % map->reg_stride)
  116. return -EINVAL;
  117. for (i = 0; i < ARRAY_SIZE(cache_types); i++)
  118. if (cache_types[i]->type == map->cache_type)
  119. break;
  120. if (i == ARRAY_SIZE(cache_types)) {
  121. dev_err(map->dev, "Could not match compress type: %d\n",
  122. map->cache_type);
  123. return -EINVAL;
  124. }
  125. map->num_reg_defaults = config->num_reg_defaults;
  126. map->num_reg_defaults_raw = config->num_reg_defaults_raw;
  127. map->reg_defaults_raw = config->reg_defaults_raw;
  128. map->cache_word_size = DIV_ROUND_UP(config->val_bits, 8);
  129. map->cache_size_raw = map->cache_word_size * config->num_reg_defaults_raw;
  130. map->cache = NULL;
  131. map->cache_ops = cache_types[i];
  132. if (!map->cache_ops->read ||
  133. !map->cache_ops->write ||
  134. !map->cache_ops->name)
  135. return -EINVAL;
  136. /* We still need to ensure that the reg_defaults
  137. * won't vanish from under us. We'll need to make
  138. * a copy of it.
  139. */
  140. if (config->reg_defaults) {
  141. tmp_buf = kmemdup(config->reg_defaults, map->num_reg_defaults *
  142. sizeof(struct reg_default), GFP_KERNEL);
  143. if (!tmp_buf)
  144. return -ENOMEM;
  145. map->reg_defaults = tmp_buf;
  146. } else if (map->num_reg_defaults_raw) {
  147. /* Some devices such as PMICs don't have cache defaults,
  148. * we cope with this by reading back the HW registers and
  149. * crafting the cache defaults by hand.
  150. */
  151. ret = regcache_hw_init(map);
  152. if (ret < 0)
  153. return ret;
  154. if (map->cache_bypass)
  155. return 0;
  156. }
  157. if (!map->max_register)
  158. map->max_register = map->num_reg_defaults_raw;
  159. if (map->cache_ops->init) {
  160. dev_dbg(map->dev, "Initializing %s cache\n",
  161. map->cache_ops->name);
  162. ret = map->cache_ops->init(map);
  163. if (ret)
  164. goto err_free;
  165. }
  166. return 0;
  167. err_free:
  168. kfree(map->reg_defaults);
  169. if (map->cache_free)
  170. kfree(map->reg_defaults_raw);
  171. return ret;
  172. }
  173. void regcache_exit(struct regmap *map)
  174. {
  175. if (map->cache_type == REGCACHE_NONE)
  176. return;
  177. BUG_ON(!map->cache_ops);
  178. kfree(map->reg_defaults);
  179. if (map->cache_free)
  180. kfree(map->reg_defaults_raw);
  181. if (map->cache_ops->exit) {
  182. dev_dbg(map->dev, "Destroying %s cache\n",
  183. map->cache_ops->name);
  184. map->cache_ops->exit(map);
  185. }
  186. }
  187. /**
  188. * regcache_read: Fetch the value of a given register from the cache.
  189. *
  190. * @map: map to configure.
  191. * @reg: The register index.
  192. * @value: The value to be returned.
  193. *
  194. * Return a negative value on failure, 0 on success.
  195. */
  196. int regcache_read(struct regmap *map,
  197. unsigned int reg, unsigned int *value)
  198. {
  199. int ret;
  200. if (map->cache_type == REGCACHE_NONE)
  201. return -ENOSYS;
  202. BUG_ON(!map->cache_ops);
  203. if (!regmap_volatile(map, reg)) {
  204. ret = map->cache_ops->read(map, reg, value);
  205. if (ret == 0)
  206. trace_regmap_reg_read_cache(map, reg, *value);
  207. return ret;
  208. }
  209. return -EINVAL;
  210. }
  211. /**
  212. * regcache_write: Set the value of a given register in the cache.
  213. *
  214. * @map: map to configure.
  215. * @reg: The register index.
  216. * @value: The new register value.
  217. *
  218. * Return a negative value on failure, 0 on success.
  219. */
  220. int regcache_write(struct regmap *map,
  221. unsigned int reg, unsigned int value)
  222. {
  223. if (map->cache_type == REGCACHE_NONE)
  224. return 0;
  225. BUG_ON(!map->cache_ops);
  226. if (!regmap_volatile(map, reg))
  227. return map->cache_ops->write(map, reg, value);
  228. return 0;
  229. }
  230. static bool regcache_reg_needs_sync(struct regmap *map, unsigned int reg,
  231. unsigned int val)
  232. {
  233. int ret;
  234. /* If we don't know the chip just got reset, then sync everything. */
  235. if (!map->no_sync_defaults)
  236. return true;
  237. /* Is this the hardware default? If so skip. */
  238. ret = regcache_lookup_reg(map, reg);
  239. if (ret >= 0 && val == map->reg_defaults[ret].def)
  240. return false;
  241. return true;
  242. }
  243. static int regcache_default_sync(struct regmap *map, unsigned int min,
  244. unsigned int max)
  245. {
  246. unsigned int reg;
  247. for (reg = min; reg <= max; reg += map->reg_stride) {
  248. unsigned int val;
  249. int ret;
  250. if (regmap_volatile(map, reg) ||
  251. !regmap_writeable(map, reg))
  252. continue;
  253. ret = regcache_read(map, reg, &val);
  254. if (ret)
  255. return ret;
  256. if (!regcache_reg_needs_sync(map, reg, val))
  257. continue;
  258. map->cache_bypass = true;
  259. ret = _regmap_write(map, reg, val);
  260. map->cache_bypass = false;
  261. if (ret) {
  262. dev_err(map->dev, "Unable to sync register %#x. %d\n",
  263. reg, ret);
  264. return ret;
  265. }
  266. dev_dbg(map->dev, "Synced register %#x, value %#x\n", reg, val);
  267. }
  268. return 0;
  269. }
  270. /**
  271. * regcache_sync: Sync the register cache with the hardware.
  272. *
  273. * @map: map to configure.
  274. *
  275. * Any registers that should not be synced should be marked as
  276. * volatile. In general drivers can choose not to use the provided
  277. * syncing functionality if they so require.
  278. *
  279. * Return a negative value on failure, 0 on success.
  280. */
  281. int regcache_sync(struct regmap *map)
  282. {
  283. int ret = 0;
  284. unsigned int i;
  285. const char *name;
  286. bool bypass;
  287. BUG_ON(!map->cache_ops);
  288. map->lock(map->lock_arg);
  289. /* Remember the initial bypass state */
  290. bypass = map->cache_bypass;
  291. dev_dbg(map->dev, "Syncing %s cache\n",
  292. map->cache_ops->name);
  293. name = map->cache_ops->name;
  294. trace_regcache_sync(map, name, "start");
  295. if (!map->cache_dirty)
  296. goto out;
  297. map->async = true;
  298. /* Apply any patch first */
  299. map->cache_bypass = true;
  300. for (i = 0; i < map->patch_regs; i++) {
  301. ret = _regmap_write(map, map->patch[i].reg, map->patch[i].def);
  302. if (ret != 0) {
  303. dev_err(map->dev, "Failed to write %x = %x: %d\n",
  304. map->patch[i].reg, map->patch[i].def, ret);
  305. goto out;
  306. }
  307. }
  308. map->cache_bypass = false;
  309. if (map->cache_ops->sync)
  310. ret = map->cache_ops->sync(map, 0, map->max_register);
  311. else
  312. ret = regcache_default_sync(map, 0, map->max_register);
  313. if (ret == 0)
  314. map->cache_dirty = false;
  315. out:
  316. /* Restore the bypass state */
  317. map->async = false;
  318. map->cache_bypass = bypass;
  319. map->no_sync_defaults = false;
  320. map->unlock(map->lock_arg);
  321. regmap_async_complete(map);
  322. trace_regcache_sync(map, name, "stop");
  323. return ret;
  324. }
  325. EXPORT_SYMBOL_GPL(regcache_sync);
  326. /**
  327. * regcache_sync_region: Sync part of the register cache with the hardware.
  328. *
  329. * @map: map to sync.
  330. * @min: first register to sync
  331. * @max: last register to sync
  332. *
  333. * Write all non-default register values in the specified region to
  334. * the hardware.
  335. *
  336. * Return a negative value on failure, 0 on success.
  337. */
  338. int regcache_sync_region(struct regmap *map, unsigned int min,
  339. unsigned int max)
  340. {
  341. int ret = 0;
  342. const char *name;
  343. bool bypass;
  344. BUG_ON(!map->cache_ops);
  345. map->lock(map->lock_arg);
  346. /* Remember the initial bypass state */
  347. bypass = map->cache_bypass;
  348. name = map->cache_ops->name;
  349. dev_dbg(map->dev, "Syncing %s cache from %d-%d\n", name, min, max);
  350. trace_regcache_sync(map, name, "start region");
  351. if (!map->cache_dirty)
  352. goto out;
  353. map->async = true;
  354. if (map->cache_ops->sync)
  355. ret = map->cache_ops->sync(map, min, max);
  356. else
  357. ret = regcache_default_sync(map, min, max);
  358. out:
  359. /* Restore the bypass state */
  360. map->cache_bypass = bypass;
  361. map->async = false;
  362. map->no_sync_defaults = false;
  363. map->unlock(map->lock_arg);
  364. regmap_async_complete(map);
  365. trace_regcache_sync(map, name, "stop region");
  366. return ret;
  367. }
  368. EXPORT_SYMBOL_GPL(regcache_sync_region);
  369. /**
  370. * regcache_drop_region: Discard part of the register cache
  371. *
  372. * @map: map to operate on
  373. * @min: first register to discard
  374. * @max: last register to discard
  375. *
  376. * Discard part of the register cache.
  377. *
  378. * Return a negative value on failure, 0 on success.
  379. */
  380. int regcache_drop_region(struct regmap *map, unsigned int min,
  381. unsigned int max)
  382. {
  383. int ret = 0;
  384. if (!map->cache_ops || !map->cache_ops->drop)
  385. return -EINVAL;
  386. map->lock(map->lock_arg);
  387. trace_regcache_drop_region(map, min, max);
  388. ret = map->cache_ops->drop(map, min, max);
  389. map->unlock(map->lock_arg);
  390. return ret;
  391. }
  392. EXPORT_SYMBOL_GPL(regcache_drop_region);
  393. /**
  394. * regcache_cache_only: Put a register map into cache only mode
  395. *
  396. * @map: map to configure
  397. * @cache_only: flag if changes should be written to the hardware
  398. *
  399. * When a register map is marked as cache only writes to the register
  400. * map API will only update the register cache, they will not cause
  401. * any hardware changes. This is useful for allowing portions of
  402. * drivers to act as though the device were functioning as normal when
  403. * it is disabled for power saving reasons.
  404. */
  405. void regcache_cache_only(struct regmap *map, bool enable)
  406. {
  407. map->lock(map->lock_arg);
  408. WARN_ON(map->cache_bypass && enable);
  409. map->cache_only = enable;
  410. trace_regmap_cache_only(map, enable);
  411. map->unlock(map->lock_arg);
  412. }
  413. EXPORT_SYMBOL_GPL(regcache_cache_only);
  414. /**
  415. * regcache_mark_dirty: Indicate that HW registers were reset to default values
  416. *
  417. * @map: map to mark
  418. *
  419. * Inform regcache that the device has been powered down or reset, so that
  420. * on resume, regcache_sync() knows to write out all non-default values
  421. * stored in the cache.
  422. *
  423. * If this function is not called, regcache_sync() will assume that
  424. * the hardware state still matches the cache state, modulo any writes that
  425. * happened when cache_only was true.
  426. */
  427. void regcache_mark_dirty(struct regmap *map)
  428. {
  429. map->lock(map->lock_arg);
  430. map->cache_dirty = true;
  431. map->no_sync_defaults = true;
  432. map->unlock(map->lock_arg);
  433. }
  434. EXPORT_SYMBOL_GPL(regcache_mark_dirty);
  435. /**
  436. * regcache_cache_bypass: Put a register map into cache bypass mode
  437. *
  438. * @map: map to configure
  439. * @cache_bypass: flag if changes should not be written to the cache
  440. *
  441. * When a register map is marked with the cache bypass option, writes
  442. * to the register map API will only update the hardware and not the
  443. * the cache directly. This is useful when syncing the cache back to
  444. * the hardware.
  445. */
  446. void regcache_cache_bypass(struct regmap *map, bool enable)
  447. {
  448. map->lock(map->lock_arg);
  449. WARN_ON(map->cache_only && enable);
  450. map->cache_bypass = enable;
  451. trace_regmap_cache_bypass(map, enable);
  452. map->unlock(map->lock_arg);
  453. }
  454. EXPORT_SYMBOL_GPL(regcache_cache_bypass);
  455. bool regcache_set_val(struct regmap *map, void *base, unsigned int idx,
  456. unsigned int val)
  457. {
  458. if (regcache_get_val(map, base, idx) == val)
  459. return true;
  460. /* Use device native format if possible */
  461. if (map->format.format_val) {
  462. map->format.format_val(base + (map->cache_word_size * idx),
  463. val, 0);
  464. return false;
  465. }
  466. switch (map->cache_word_size) {
  467. case 1: {
  468. u8 *cache = base;
  469. cache[idx] = val;
  470. break;
  471. }
  472. case 2: {
  473. u16 *cache = base;
  474. cache[idx] = val;
  475. break;
  476. }
  477. case 4: {
  478. u32 *cache = base;
  479. cache[idx] = val;
  480. break;
  481. }
  482. #ifdef CONFIG_64BIT
  483. case 8: {
  484. u64 *cache = base;
  485. cache[idx] = val;
  486. break;
  487. }
  488. #endif
  489. default:
  490. BUG();
  491. }
  492. return false;
  493. }
  494. unsigned int regcache_get_val(struct regmap *map, const void *base,
  495. unsigned int idx)
  496. {
  497. if (!base)
  498. return -EINVAL;
  499. /* Use device native format if possible */
  500. if (map->format.parse_val)
  501. return map->format.parse_val(regcache_get_val_addr(map, base,
  502. idx));
  503. switch (map->cache_word_size) {
  504. case 1: {
  505. const u8 *cache = base;
  506. return cache[idx];
  507. }
  508. case 2: {
  509. const u16 *cache = base;
  510. return cache[idx];
  511. }
  512. case 4: {
  513. const u32 *cache = base;
  514. return cache[idx];
  515. }
  516. #ifdef CONFIG_64BIT
  517. case 8: {
  518. const u64 *cache = base;
  519. return cache[idx];
  520. }
  521. #endif
  522. default:
  523. BUG();
  524. }
  525. /* unreachable */
  526. return -1;
  527. }
  528. static int regcache_default_cmp(const void *a, const void *b)
  529. {
  530. const struct reg_default *_a = a;
  531. const struct reg_default *_b = b;
  532. return _a->reg - _b->reg;
  533. }
  534. int regcache_lookup_reg(struct regmap *map, unsigned int reg)
  535. {
  536. struct reg_default key;
  537. struct reg_default *r;
  538. key.reg = reg;
  539. key.def = 0;
  540. r = bsearch(&key, map->reg_defaults, map->num_reg_defaults,
  541. sizeof(struct reg_default), regcache_default_cmp);
  542. if (r)
  543. return r - map->reg_defaults;
  544. else
  545. return -ENOENT;
  546. }
  547. static bool regcache_reg_present(unsigned long *cache_present, unsigned int idx)
  548. {
  549. if (!cache_present)
  550. return true;
  551. return test_bit(idx, cache_present);
  552. }
  553. static int regcache_sync_block_single(struct regmap *map, void *block,
  554. unsigned long *cache_present,
  555. unsigned int block_base,
  556. unsigned int start, unsigned int end)
  557. {
  558. unsigned int i, regtmp, val;
  559. int ret;
  560. for (i = start; i < end; i++) {
  561. regtmp = block_base + (i * map->reg_stride);
  562. if (!regcache_reg_present(cache_present, i) ||
  563. !regmap_writeable(map, regtmp))
  564. continue;
  565. val = regcache_get_val(map, block, i);
  566. if (!regcache_reg_needs_sync(map, regtmp, val))
  567. continue;
  568. map->cache_bypass = true;
  569. ret = _regmap_write(map, regtmp, val);
  570. map->cache_bypass = false;
  571. if (ret != 0) {
  572. dev_err(map->dev, "Unable to sync register %#x. %d\n",
  573. regtmp, ret);
  574. return ret;
  575. }
  576. dev_dbg(map->dev, "Synced register %#x, value %#x\n",
  577. regtmp, val);
  578. }
  579. return 0;
  580. }
  581. static int regcache_sync_block_raw_flush(struct regmap *map, const void **data,
  582. unsigned int base, unsigned int cur)
  583. {
  584. size_t val_bytes = map->format.val_bytes;
  585. int ret, count;
  586. if (*data == NULL)
  587. return 0;
  588. count = (cur - base) / map->reg_stride;
  589. dev_dbg(map->dev, "Writing %zu bytes for %d registers from 0x%x-0x%x\n",
  590. count * val_bytes, count, base, cur - map->reg_stride);
  591. map->cache_bypass = true;
  592. ret = _regmap_raw_write(map, base, *data, count * val_bytes);
  593. if (ret)
  594. dev_err(map->dev, "Unable to sync registers %#x-%#x. %d\n",
  595. base, cur - map->reg_stride, ret);
  596. map->cache_bypass = false;
  597. *data = NULL;
  598. return ret;
  599. }
  600. static int regcache_sync_block_raw(struct regmap *map, void *block,
  601. unsigned long *cache_present,
  602. unsigned int block_base, unsigned int start,
  603. unsigned int end)
  604. {
  605. unsigned int i, val;
  606. unsigned int regtmp = 0;
  607. unsigned int base = 0;
  608. const void *data = NULL;
  609. int ret;
  610. for (i = start; i < end; i++) {
  611. regtmp = block_base + (i * map->reg_stride);
  612. if (!regcache_reg_present(cache_present, i) ||
  613. !regmap_writeable(map, regtmp)) {
  614. ret = regcache_sync_block_raw_flush(map, &data,
  615. base, regtmp);
  616. if (ret != 0)
  617. return ret;
  618. continue;
  619. }
  620. val = regcache_get_val(map, block, i);
  621. if (!regcache_reg_needs_sync(map, regtmp, val)) {
  622. ret = regcache_sync_block_raw_flush(map, &data,
  623. base, regtmp);
  624. if (ret != 0)
  625. return ret;
  626. continue;
  627. }
  628. if (!data) {
  629. data = regcache_get_val_addr(map, block, i);
  630. base = regtmp;
  631. }
  632. }
  633. return regcache_sync_block_raw_flush(map, &data, base, regtmp +
  634. map->reg_stride);
  635. }
  636. int regcache_sync_block(struct regmap *map, void *block,
  637. unsigned long *cache_present,
  638. unsigned int block_base, unsigned int start,
  639. unsigned int end)
  640. {
  641. if (regmap_can_raw_write(map) && !map->use_single_write)
  642. return regcache_sync_block_raw(map, block, cache_present,
  643. block_base, start, end);
  644. else
  645. return regcache_sync_block_single(map, block, cache_present,
  646. block_base, start, end);
  647. }