Merge tag 'trace-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt...
[linux/fpc-iii.git] / drivers / clk / qcom / clk-regmap.c
blobce80db27ccf2af5f66ada93c02850d66af460994
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2014, The Linux Foundation. All rights reserved.
4 */
6 #include <linux/device.h>
7 #include <linux/clk-provider.h>
8 #include <linux/regmap.h>
9 #include <linux/export.h>
11 #include "clk-regmap.h"
13 /**
14 * clk_is_enabled_regmap - standard is_enabled() for regmap users
16 * @hw: clk to operate on
18 * Clocks that use regmap for their register I/O can set the
19 * enable_reg and enable_mask fields in their struct clk_regmap and then use
20 * this as their is_enabled operation, saving some code.
22 int clk_is_enabled_regmap(struct clk_hw *hw)
24 struct clk_regmap *rclk = to_clk_regmap(hw);
25 unsigned int val;
26 int ret;
28 ret = regmap_read(rclk->regmap, rclk->enable_reg, &val);
29 if (ret != 0)
30 return ret;
32 if (rclk->enable_is_inverted)
33 return (val & rclk->enable_mask) == 0;
34 else
35 return (val & rclk->enable_mask) != 0;
37 EXPORT_SYMBOL_GPL(clk_is_enabled_regmap);
39 /**
40 * clk_enable_regmap - standard enable() for regmap users
42 * @hw: clk to operate on
44 * Clocks that use regmap for their register I/O can set the
45 * enable_reg and enable_mask fields in their struct clk_regmap and then use
46 * this as their enable() operation, saving some code.
48 int clk_enable_regmap(struct clk_hw *hw)
50 struct clk_regmap *rclk = to_clk_regmap(hw);
51 unsigned int val;
53 if (rclk->enable_is_inverted)
54 val = 0;
55 else
56 val = rclk->enable_mask;
58 return regmap_update_bits(rclk->regmap, rclk->enable_reg,
59 rclk->enable_mask, val);
61 EXPORT_SYMBOL_GPL(clk_enable_regmap);
63 /**
64 * clk_disable_regmap - standard disable() for regmap users
66 * @hw: clk to operate on
68 * Clocks that use regmap for their register I/O can set the
69 * enable_reg and enable_mask fields in their struct clk_regmap and then use
70 * this as their disable() operation, saving some code.
72 void clk_disable_regmap(struct clk_hw *hw)
74 struct clk_regmap *rclk = to_clk_regmap(hw);
75 unsigned int val;
77 if (rclk->enable_is_inverted)
78 val = rclk->enable_mask;
79 else
80 val = 0;
82 regmap_update_bits(rclk->regmap, rclk->enable_reg, rclk->enable_mask,
83 val);
85 EXPORT_SYMBOL_GPL(clk_disable_regmap);
87 /**
88 * devm_clk_register_regmap - register a clk_regmap clock
90 * @rclk: clk to operate on
92 * Clocks that use regmap for their register I/O should register their
93 * clk_regmap struct via this function so that the regmap is initialized
94 * and so that the clock is registered with the common clock framework.
96 int devm_clk_register_regmap(struct device *dev, struct clk_regmap *rclk)
98 if (dev && dev_get_regmap(dev, NULL))
99 rclk->regmap = dev_get_regmap(dev, NULL);
100 else if (dev && dev->parent)
101 rclk->regmap = dev_get_regmap(dev->parent, NULL);
103 return devm_clk_hw_register(dev, &rclk->hw);
105 EXPORT_SYMBOL_GPL(devm_clk_register_regmap);