regcache-flat.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Register cache access API - flat caching support
  3. *
  4. * Copyright 2012 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/seq_file.h>
  14. #include <linux/slab.h>
  15. #include "internal.h"
  16. static int regcache_flat_init(struct regmap *map)
  17. {
  18. int i;
  19. unsigned int *cache;
  20. map->cache = kzalloc(sizeof(unsigned int) * (map->max_register + 1),
  21. GFP_KERNEL);
  22. if (!map->cache)
  23. return -ENOMEM;
  24. cache = map->cache;
  25. for (i = 0; i < map->num_reg_defaults; i++)
  26. cache[map->reg_defaults[i].reg] = map->reg_defaults[i].def;
  27. return 0;
  28. }
  29. static int regcache_flat_exit(struct regmap *map)
  30. {
  31. kfree(map->cache);
  32. map->cache = NULL;
  33. return 0;
  34. }
  35. static int regcache_flat_read(struct regmap *map,
  36. unsigned int reg, unsigned int *value)
  37. {
  38. unsigned int *cache = map->cache;
  39. *value = cache[reg];
  40. return 0;
  41. }
  42. static int regcache_flat_write(struct regmap *map, unsigned int reg,
  43. unsigned int value)
  44. {
  45. unsigned int *cache = map->cache;
  46. cache[reg] = value;
  47. return 0;
  48. }
  49. struct regcache_ops regcache_flat_ops = {
  50. .type = REGCACHE_FLAT,
  51. .name = "flat",
  52. .init = regcache_flat_init,
  53. .exit = regcache_flat_exit,
  54. .read = regcache_flat_read,
  55. .write = regcache_flat_write,
  56. };