Merge branch 'for-4.14-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj...
[sfrench/cifs-2.6.git] / drivers / clk / meson / gxbb-aoclk-regmap.c
1 /*
2  * Copyright (c) 2017 BayLibre, SAS.
3  * Author: Neil Armstrong <narmstrong@baylibre.com>
4  *
5  * SPDX-License-Identifier: GPL-2.0+
6  */
7
8 #include <linux/clk-provider.h>
9 #include <linux/bitfield.h>
10 #include <linux/regmap.h>
11 #include "gxbb-aoclk.h"
12
13 static int aoclk_gate_regmap_enable(struct clk_hw *hw)
14 {
15         struct aoclk_gate_regmap *gate = to_aoclk_gate_regmap(hw);
16
17         return regmap_update_bits(gate->regmap, AO_RTI_GEN_CNTL_REG0,
18                                   BIT(gate->bit_idx), BIT(gate->bit_idx));
19 }
20
21 static void aoclk_gate_regmap_disable(struct clk_hw *hw)
22 {
23         struct aoclk_gate_regmap *gate = to_aoclk_gate_regmap(hw);
24
25         regmap_update_bits(gate->regmap, AO_RTI_GEN_CNTL_REG0,
26                            BIT(gate->bit_idx), 0);
27 }
28
29 static int aoclk_gate_regmap_is_enabled(struct clk_hw *hw)
30 {
31         struct aoclk_gate_regmap *gate = to_aoclk_gate_regmap(hw);
32         unsigned int val;
33         int ret;
34
35         ret = regmap_read(gate->regmap, AO_RTI_GEN_CNTL_REG0, &val);
36         if (ret)
37                 return ret;
38
39         return (val & BIT(gate->bit_idx)) != 0;
40 }
41
42 const struct clk_ops meson_aoclk_gate_regmap_ops = {
43         .enable = aoclk_gate_regmap_enable,
44         .disable = aoclk_gate_regmap_disable,
45         .is_enabled = aoclk_gate_regmap_is_enabled,
46 };