2 * Copyright (c) 2017 Chen-Yu Tsai. 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/clk-provider.h>
15 #include <linux/clk/sunxi-ng.h>
17 #include "ccu_common.h"
20 * sunxi_ccu_set_mmc_timing_mode: Configure the MMC clock timing mode
21 * @clk: clock to be configured
22 * @new_mode: true for new timing mode introduced in A83T and later
24 * Returns 0 on success, -ENOTSUPP if the clock does not support
27 int sunxi_ccu_set_mmc_timing_mode(struct clk
*clk
, bool new_mode
)
29 struct clk_hw
*hw
= __clk_get_hw(clk
);
30 struct ccu_common
*cm
= hw_to_ccu_common(hw
);
34 if (!(cm
->features
& CCU_FEATURE_MMC_TIMING_SWITCH
))
37 spin_lock_irqsave(cm
->lock
, flags
);
39 val
= readl(cm
->base
+ cm
->reg
);
41 val
|= CCU_MMC_NEW_TIMING_MODE
;
43 val
&= ~CCU_MMC_NEW_TIMING_MODE
;
44 writel(val
, cm
->base
+ cm
->reg
);
46 spin_unlock_irqrestore(cm
->lock
, flags
);
50 EXPORT_SYMBOL_GPL(sunxi_ccu_set_mmc_timing_mode
);
53 * sunxi_ccu_set_mmc_timing_mode: Get the current MMC clock timing mode
54 * @clk: clock to query
56 * Returns 0 if the clock is in old timing mode, > 0 if it is in
57 * new timing mode, and -ENOTSUPP if the clock does not support
60 int sunxi_ccu_get_mmc_timing_mode(struct clk
*clk
)
62 struct clk_hw
*hw
= __clk_get_hw(clk
);
63 struct ccu_common
*cm
= hw_to_ccu_common(hw
);
65 if (!(cm
->features
& CCU_FEATURE_MMC_TIMING_SWITCH
))
68 return !!(readl(cm
->base
+ cm
->reg
) & CCU_MMC_NEW_TIMING_MODE
);
70 EXPORT_SYMBOL_GPL(sunxi_ccu_get_mmc_timing_mode
);