regmap-spmi.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Register map access API - SPMI support
  3. *
  4. * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
  5. *
  6. * Based on regmap-i2c.c:
  7. * Copyright 2011 Wolfson Microelectronics plc
  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 and
  12. * only version 2 as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. */
  20. #include <linux/regmap.h>
  21. #include <linux/spmi.h>
  22. #include <linux/module.h>
  23. #include <linux/init.h>
  24. static int regmap_spmi_read(void *context,
  25. const void *reg, size_t reg_size,
  26. void *val, size_t val_size)
  27. {
  28. BUG_ON(reg_size != 2);
  29. return spmi_ext_register_readl(context, *(u16 *)reg,
  30. val, val_size);
  31. }
  32. static int regmap_spmi_gather_write(void *context,
  33. const void *reg, size_t reg_size,
  34. const void *val, size_t val_size)
  35. {
  36. BUG_ON(reg_size != 2);
  37. return spmi_ext_register_writel(context, *(u16 *)reg, val, val_size);
  38. }
  39. static int regmap_spmi_write(void *context, const void *data,
  40. size_t count)
  41. {
  42. BUG_ON(count < 2);
  43. return regmap_spmi_gather_write(context, data, 2, data + 2, count - 2);
  44. }
  45. static struct regmap_bus regmap_spmi = {
  46. .read = regmap_spmi_read,
  47. .write = regmap_spmi_write,
  48. .gather_write = regmap_spmi_gather_write,
  49. .reg_format_endian_default = REGMAP_ENDIAN_NATIVE,
  50. .val_format_endian_default = REGMAP_ENDIAN_NATIVE,
  51. };
  52. /**
  53. * regmap_init_spmi(): Initialize register map
  54. *
  55. * @sdev: Device that will be interacted with
  56. * @config: Configuration for register map
  57. *
  58. * The return value will be an ERR_PTR() on error or a valid pointer to
  59. * a struct regmap.
  60. */
  61. struct regmap *regmap_init_spmi(struct spmi_device *sdev,
  62. const struct regmap_config *config)
  63. {
  64. return regmap_init(&sdev->dev, &regmap_spmi, sdev, config);
  65. }
  66. EXPORT_SYMBOL_GPL(regmap_init_spmi);
  67. /**
  68. * devm_regmap_init_spmi(): Initialise managed register map
  69. *
  70. * @sdev: Device that will be interacted with
  71. * @config: Configuration for register map
  72. *
  73. * The return value will be an ERR_PTR() on error or a valid pointer
  74. * to a struct regmap. The regmap will be automatically freed by the
  75. * device management code.
  76. */
  77. struct regmap *devm_regmap_init_spmi(struct spmi_device *sdev,
  78. const struct regmap_config *config)
  79. {
  80. return devm_regmap_init(&sdev->dev, &regmap_spmi, sdev, config);
  81. }
  82. EXPORT_SYMBOL_GPL(devm_regmap_init_spmi);
  83. MODULE_LICENSE("GPL");