sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / drivers / clk / qcom / clk-regmap.c
blob1c856d330733f160041a695a4aa205430e05a840
1 /*
2 * Copyright (c) 2014, The Linux Foundation. All rights reserved.
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.
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.
14 #include <linux/device.h>
15 #include <linux/clk-provider.h>
16 #include <linux/regmap.h>
17 #include <linux/export.h>
19 #include "clk-regmap.h"
21 /**
22 * clk_is_enabled_regmap - standard is_enabled() for regmap users
24 * @hw: clk to operate on
26 * Clocks that use regmap for their register I/O can set the
27 * enable_reg and enable_mask fields in their struct clk_regmap and then use
28 * this as their is_enabled operation, saving some code.
30 int clk_is_enabled_regmap(struct clk_hw *hw)
32 struct clk_regmap *rclk = to_clk_regmap(hw);
33 unsigned int val;
34 int ret;
36 ret = regmap_read(rclk->regmap, rclk->enable_reg, &val);
37 if (ret != 0)
38 return ret;
40 if (rclk->enable_is_inverted)
41 return (val & rclk->enable_mask) == 0;
42 else
43 return (val & rclk->enable_mask) != 0;
45 EXPORT_SYMBOL_GPL(clk_is_enabled_regmap);
47 /**
48 * clk_enable_regmap - standard enable() for regmap users
50 * @hw: clk to operate on
52 * Clocks that use regmap for their register I/O can set the
53 * enable_reg and enable_mask fields in their struct clk_regmap and then use
54 * this as their enable() operation, saving some code.
56 int clk_enable_regmap(struct clk_hw *hw)
58 struct clk_regmap *rclk = to_clk_regmap(hw);
59 unsigned int val;
61 if (rclk->enable_is_inverted)
62 val = 0;
63 else
64 val = rclk->enable_mask;
66 return regmap_update_bits(rclk->regmap, rclk->enable_reg,
67 rclk->enable_mask, val);
69 EXPORT_SYMBOL_GPL(clk_enable_regmap);
71 /**
72 * clk_disable_regmap - standard disable() for regmap users
74 * @hw: clk to operate on
76 * Clocks that use regmap for their register I/O can set the
77 * enable_reg and enable_mask fields in their struct clk_regmap and then use
78 * this as their disable() operation, saving some code.
80 void clk_disable_regmap(struct clk_hw *hw)
82 struct clk_regmap *rclk = to_clk_regmap(hw);
83 unsigned int val;
85 if (rclk->enable_is_inverted)
86 val = rclk->enable_mask;
87 else
88 val = 0;
90 regmap_update_bits(rclk->regmap, rclk->enable_reg, rclk->enable_mask,
91 val);
93 EXPORT_SYMBOL_GPL(clk_disable_regmap);
95 /**
96 * devm_clk_register_regmap - register a clk_regmap clock
98 * @rclk: clk to operate on
100 * Clocks that use regmap for their register I/O should register their
101 * clk_regmap struct via this function so that the regmap is initialized
102 * and so that the clock is registered with the common clock framework.
104 int devm_clk_register_regmap(struct device *dev, struct clk_regmap *rclk)
106 if (dev && dev_get_regmap(dev, NULL))
107 rclk->regmap = dev_get_regmap(dev, NULL);
108 else if (dev && dev->parent)
109 rclk->regmap = dev_get_regmap(dev->parent, NULL);
111 return devm_clk_hw_register(dev, &rclk->hw);
113 EXPORT_SYMBOL_GPL(devm_clk_register_regmap);