1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2017 Chen-Yu Tsai. All rights reserved.
6 #include <linux/clk-provider.h>
7 #include <linux/clk/sunxi-ng.h>
10 #include "ccu_common.h"
13 * sunxi_ccu_set_mmc_timing_mode: Configure the MMC clock timing mode
14 * @clk: clock to be configured
15 * @new_mode: true for new timing mode introduced in A83T and later
17 * Returns 0 on success, -ENOTSUPP if the clock does not support
20 int sunxi_ccu_set_mmc_timing_mode(struct clk
*clk
, bool new_mode
)
22 struct clk_hw
*hw
= __clk_get_hw(clk
);
23 struct ccu_common
*cm
= hw_to_ccu_common(hw
);
27 if (!(cm
->features
& CCU_FEATURE_MMC_TIMING_SWITCH
))
30 spin_lock_irqsave(cm
->lock
, flags
);
32 val
= readl(cm
->base
+ cm
->reg
);
34 val
|= CCU_MMC_NEW_TIMING_MODE
;
36 val
&= ~CCU_MMC_NEW_TIMING_MODE
;
37 writel(val
, cm
->base
+ cm
->reg
);
39 spin_unlock_irqrestore(cm
->lock
, flags
);
43 EXPORT_SYMBOL_GPL(sunxi_ccu_set_mmc_timing_mode
);
46 * sunxi_ccu_set_mmc_timing_mode: Get the current MMC clock timing mode
47 * @clk: clock to query
49 * Returns 0 if the clock is in old timing mode, > 0 if it is in
50 * new timing mode, and -ENOTSUPP if the clock does not support
53 int sunxi_ccu_get_mmc_timing_mode(struct clk
*clk
)
55 struct clk_hw
*hw
= __clk_get_hw(clk
);
56 struct ccu_common
*cm
= hw_to_ccu_common(hw
);
58 if (!(cm
->features
& CCU_FEATURE_MMC_TIMING_SWITCH
))
61 return !!(readl(cm
->base
+ cm
->reg
) & CCU_MMC_NEW_TIMING_MODE
);
63 EXPORT_SYMBOL_GPL(sunxi_ccu_get_mmc_timing_mode
);