1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2014, The Linux Foundation. All rights reserved.
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"
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
);
28 ret
= regmap_read(rclk
->regmap
, rclk
->enable_reg
, &val
);
32 if (rclk
->enable_is_inverted
)
33 return (val
& rclk
->enable_mask
) == 0;
35 return (val
& rclk
->enable_mask
) != 0;
37 EXPORT_SYMBOL_GPL(clk_is_enabled_regmap
);
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
);
53 if (rclk
->enable_is_inverted
)
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
);
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
);
77 if (rclk
->enable_is_inverted
)
78 val
= rclk
->enable_mask
;
82 regmap_update_bits(rclk
->regmap
, rclk
->enable_reg
, rclk
->enable_mask
,
85 EXPORT_SYMBOL_GPL(clk_disable_regmap
);
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
);