clk-regmap.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright (c) 2014, The Linux Foundation. All rights reserved.
  3. *
  4. * This software is licensed under the terms of the GNU General Public
  5. * License version 2, as published by the Free Software Foundation, and
  6. * may be copied, distributed, and modified under those terms.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include <linux/device.h>
  14. #include <linux/clk-provider.h>
  15. #include <linux/regmap.h>
  16. #include <linux/export.h>
  17. #include "clk-regmap.h"
  18. /**
  19. * clk_is_enabled_regmap - standard is_enabled() for regmap users
  20. *
  21. * @hw: clk to operate on
  22. *
  23. * Clocks that use regmap for their register I/O can set the
  24. * enable_reg and enable_mask fields in their struct clk_regmap and then use
  25. * this as their is_enabled operation, saving some code.
  26. */
  27. int clk_is_enabled_regmap(struct clk_hw *hw)
  28. {
  29. struct clk_regmap *rclk = to_clk_regmap(hw);
  30. unsigned int val;
  31. int ret;
  32. ret = regmap_read(rclk->regmap, rclk->enable_reg, &val);
  33. if (ret != 0)
  34. return ret;
  35. if (rclk->enable_is_inverted)
  36. return (val & rclk->enable_mask) == 0;
  37. else
  38. return (val & rclk->enable_mask) != 0;
  39. }
  40. EXPORT_SYMBOL_GPL(clk_is_enabled_regmap);
  41. /**
  42. * clk_enable_regmap - standard enable() for regmap users
  43. *
  44. * @hw: clk to operate on
  45. *
  46. * Clocks that use regmap for their register I/O can set the
  47. * enable_reg and enable_mask fields in their struct clk_regmap and then use
  48. * this as their enable() operation, saving some code.
  49. */
  50. int clk_enable_regmap(struct clk_hw *hw)
  51. {
  52. struct clk_regmap *rclk = to_clk_regmap(hw);
  53. unsigned int val;
  54. if (rclk->enable_is_inverted)
  55. val = 0;
  56. else
  57. val = rclk->enable_mask;
  58. return regmap_update_bits(rclk->regmap, rclk->enable_reg,
  59. rclk->enable_mask, val);
  60. }
  61. EXPORT_SYMBOL_GPL(clk_enable_regmap);
  62. /**
  63. * clk_disable_regmap - standard disable() for regmap users
  64. *
  65. * @hw: clk to operate on
  66. *
  67. * Clocks that use regmap for their register I/O can set the
  68. * enable_reg and enable_mask fields in their struct clk_regmap and then use
  69. * this as their disable() operation, saving some code.
  70. */
  71. void clk_disable_regmap(struct clk_hw *hw)
  72. {
  73. struct clk_regmap *rclk = to_clk_regmap(hw);
  74. unsigned int val;
  75. if (rclk->enable_is_inverted)
  76. val = rclk->enable_mask;
  77. else
  78. val = 0;
  79. regmap_update_bits(rclk->regmap, rclk->enable_reg, rclk->enable_mask,
  80. val);
  81. }
  82. EXPORT_SYMBOL_GPL(clk_disable_regmap);
  83. /**
  84. * devm_clk_register_regmap - register a clk_regmap clock
  85. *
  86. * @rclk: clk to operate on
  87. *
  88. * Clocks that use regmap for their register I/O should register their
  89. * clk_regmap struct via this function so that the regmap is initialized
  90. * and so that the clock is registered with the common clock framework.
  91. */
  92. struct clk *devm_clk_register_regmap(struct device *dev,
  93. struct clk_regmap *rclk)
  94. {
  95. if (dev && dev_get_regmap(dev, NULL))
  96. rclk->regmap = dev_get_regmap(dev, NULL);
  97. else if (dev && dev->parent)
  98. rclk->regmap = dev_get_regmap(dev->parent, NULL);
  99. return devm_clk_register(dev, &rclk->hw);
  100. }
  101. EXPORT_SYMBOL_GPL(devm_clk_register_regmap);