diff options
| author | Olof Johansson <olof@lixom.net> | 2013-02-05 15:13:10 -0500 |
|---|---|---|
| committer | Olof Johansson <olof@lixom.net> | 2013-02-05 15:13:10 -0500 |
| commit | bda6f8e6cdcdb55db9b2961b6a7c9d0d97da4765 (patch) | |
| tree | cec7c71c5120538352157fa1d2826efe881a7b0c /drivers/clk/tegra/clk-super.c | |
| parent | c35a0bfacb61f5c56e0e64f309d36c59c7fe8da3 (diff) | |
| parent | ef3ffe5a0458606c488def757bb7f6dd013c2db5 (diff) | |
Merge tag 'tegra-for-3.9-soc-ccf' of git://git.kernel.org/pub/scm/linux/kernel/git/swarren/linux-tegra into next/soc
From Stephen Warren:
ARM: tegra: Common Clock Framework rework
Tegra already supports the common clock framework, but had issues:
1) The clock driver was located in arch/arm/mach-tegra/ rather than
drivers/clk/.
2) A single "Tegra clock" type was implemented, rather than separate
clock types for PLL, mux, divider, ... type in HW.
3) Clock lookups by device drivers were still driven by device name
and connection ID, rather than through device tree.
This pull request solves all three issues. This required some DT changes
to add clocks properties, and driver changes to request clocks more
"correctly". Finally, this rework allows all AUXDATA to be removed from
Tegra board files, and various duplicate clock lookup entries to be
removed from the driver.
This pull request is based on the previous pull request, with tag
tegra-for-3.9-cleanup.
* tag 'tegra-for-3.9-soc-ccf' of git://git.kernel.org/pub/scm/linux/kernel/git/swarren/linux-tegra: (31 commits)
clk: tegra30: remove unused TEGRA_CLK_DUPLICATE()s
clk: tegra20: remove unused TEGRA_CLK_DUPLICATE()s
ARM: tegra30: remove auxdata
ARM: tegra20: remove auxdata
ASoC: tegra: remove auxdata
staging: nvec: remove use of clk_get_sys
ARM: tegra: paz00: add clock information to DT
ARM: tegra: add clock properties to Tegra30 DT
ARM: tegra: add clock properties to Tegra20 DT
spi: tegra: do not use clock name to get clock
ARM: tegra: remove legacy clock code
ARM: tegra: migrate to new clock code
clk: tegra: add clock support for Tegra30
clk: tegra: add clock support for Tegra20
clk: tegra: add Tegra specific clocks
ARM: tegra: define Tegra30 CAR binding
ARM: tegra: define Tegra20 CAR binding
ARM: tegra: move tegra_cpu_car.h to linux/clk/tegra.h
ARM: tegra: add function to read chipid
ARM: tegra: fix compile error when disable CPU_IDLE
...
Signed-off-by: Olof Johansson <olof@lixom.net>
Conflicts:
arch/arm/mach-tegra/board-dt-tegra20.c
arch/arm/mach-tegra/board-dt-tegra30.c
arch/arm/mach-tegra/common.c
arch/arm/mach-tegra/platsmp.c
drivers/clocksource/Makefile
Diffstat (limited to 'drivers/clk/tegra/clk-super.c')
| -rw-r--r-- | drivers/clk/tegra/clk-super.c | 154 |
1 files changed, 154 insertions, 0 deletions
diff --git a/drivers/clk/tegra/clk-super.c b/drivers/clk/tegra/clk-super.c new file mode 100644 index 000000000000..7ad48a832334 --- /dev/null +++ b/drivers/clk/tegra/clk-super.c | |||
| @@ -0,0 +1,154 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. | ||
| 3 | * | ||
| 4 | * This program is free software; you can redistribute it and/or modify it | ||
| 5 | * under the terms and conditions of the GNU General Public License, | ||
| 6 | * version 2, as published by the Free Software Foundation. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
| 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
| 11 | * more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include <linux/kernel.h> | ||
| 18 | #include <linux/io.h> | ||
| 19 | #include <linux/delay.h> | ||
| 20 | #include <linux/err.h> | ||
| 21 | #include <linux/slab.h> | ||
| 22 | #include <linux/clk-provider.h> | ||
| 23 | #include <linux/clk.h> | ||
| 24 | |||
| 25 | #include "clk.h" | ||
| 26 | |||
| 27 | #define SUPER_STATE_IDLE 0 | ||
| 28 | #define SUPER_STATE_RUN 1 | ||
| 29 | #define SUPER_STATE_IRQ 2 | ||
| 30 | #define SUPER_STATE_FIQ 3 | ||
| 31 | |||
| 32 | #define SUPER_STATE_SHIFT 28 | ||
| 33 | #define SUPER_STATE_MASK ((BIT(SUPER_STATE_IDLE) | BIT(SUPER_STATE_RUN) | \ | ||
| 34 | BIT(SUPER_STATE_IRQ) | BIT(SUPER_STATE_FIQ)) \ | ||
| 35 | << SUPER_STATE_SHIFT) | ||
| 36 | |||
| 37 | #define SUPER_LP_DIV2_BYPASS (1 << 16) | ||
| 38 | |||
| 39 | #define super_state(s) (BIT(s) << SUPER_STATE_SHIFT) | ||
| 40 | #define super_state_to_src_shift(m, s) ((m->width * s)) | ||
| 41 | #define super_state_to_src_mask(m) (((1 << m->width) - 1)) | ||
| 42 | |||
| 43 | static u8 clk_super_get_parent(struct clk_hw *hw) | ||
| 44 | { | ||
| 45 | struct tegra_clk_super_mux *mux = to_clk_super_mux(hw); | ||
| 46 | u32 val, state; | ||
| 47 | u8 source, shift; | ||
| 48 | |||
| 49 | val = readl_relaxed(mux->reg); | ||
| 50 | |||
| 51 | state = val & SUPER_STATE_MASK; | ||
| 52 | |||
| 53 | BUG_ON((state != super_state(SUPER_STATE_RUN)) && | ||
| 54 | (state != super_state(SUPER_STATE_IDLE))); | ||
| 55 | shift = (state == super_state(SUPER_STATE_IDLE)) ? | ||
| 56 | super_state_to_src_shift(mux, SUPER_STATE_IDLE) : | ||
| 57 | super_state_to_src_shift(mux, SUPER_STATE_RUN); | ||
| 58 | |||
| 59 | source = (val >> shift) & super_state_to_src_mask(mux); | ||
| 60 | |||
| 61 | /* | ||
| 62 | * If LP_DIV2_BYPASS is not set and PLLX is current parent then | ||
| 63 | * PLLX/2 is the input source to CCLKLP. | ||
| 64 | */ | ||
| 65 | if ((mux->flags & TEGRA_DIVIDER_2) && !(val & SUPER_LP_DIV2_BYPASS) && | ||
| 66 | (source == mux->pllx_index)) | ||
| 67 | source = mux->div2_index; | ||
| 68 | |||
| 69 | return source; | ||
| 70 | } | ||
| 71 | |||
| 72 | static int clk_super_set_parent(struct clk_hw *hw, u8 index) | ||
| 73 | { | ||
| 74 | struct tegra_clk_super_mux *mux = to_clk_super_mux(hw); | ||
| 75 | u32 val, state; | ||
| 76 | u8 parent_index, shift; | ||
| 77 | |||
| 78 | val = readl_relaxed(mux->reg); | ||
| 79 | state = val & SUPER_STATE_MASK; | ||
| 80 | BUG_ON((state != super_state(SUPER_STATE_RUN)) && | ||
| 81 | (state != super_state(SUPER_STATE_IDLE))); | ||
| 82 | shift = (state == super_state(SUPER_STATE_IDLE)) ? | ||
| 83 | super_state_to_src_shift(mux, SUPER_STATE_IDLE) : | ||
| 84 | super_state_to_src_shift(mux, SUPER_STATE_RUN); | ||
| 85 | |||
| 86 | /* | ||
| 87 | * For LP mode super-clock switch between PLLX direct | ||
| 88 | * and divided-by-2 outputs is allowed only when other | ||
| 89 | * than PLLX clock source is current parent. | ||
| 90 | */ | ||
| 91 | if ((mux->flags & TEGRA_DIVIDER_2) && ((index == mux->div2_index) || | ||
| 92 | (index == mux->pllx_index))) { | ||
| 93 | parent_index = clk_super_get_parent(hw); | ||
| 94 | if ((parent_index == mux->div2_index) || | ||
| 95 | (parent_index == mux->pllx_index)) | ||
| 96 | return -EINVAL; | ||
| 97 | |||
| 98 | val ^= SUPER_LP_DIV2_BYPASS; | ||
| 99 | writel_relaxed(val, mux->reg); | ||
| 100 | udelay(2); | ||
| 101 | |||
| 102 | if (index == mux->div2_index) | ||
| 103 | index = mux->pllx_index; | ||
| 104 | } | ||
| 105 | val &= ~((super_state_to_src_mask(mux)) << shift); | ||
| 106 | val |= (index & (super_state_to_src_mask(mux))) << shift; | ||
| 107 | |||
| 108 | writel_relaxed(val, mux->reg); | ||
| 109 | udelay(2); | ||
| 110 | return 0; | ||
| 111 | } | ||
| 112 | |||
| 113 | const struct clk_ops tegra_clk_super_ops = { | ||
| 114 | .get_parent = clk_super_get_parent, | ||
| 115 | .set_parent = clk_super_set_parent, | ||
| 116 | }; | ||
| 117 | |||
| 118 | struct clk *tegra_clk_register_super_mux(const char *name, | ||
| 119 | const char **parent_names, u8 num_parents, | ||
| 120 | unsigned long flags, void __iomem *reg, u8 clk_super_flags, | ||
| 121 | u8 width, u8 pllx_index, u8 div2_index, spinlock_t *lock) | ||
| 122 | { | ||
| 123 | struct tegra_clk_super_mux *super; | ||
| 124 | struct clk *clk; | ||
| 125 | struct clk_init_data init; | ||
| 126 | |||
| 127 | super = kzalloc(sizeof(*super), GFP_KERNEL); | ||
| 128 | if (!super) { | ||
| 129 | pr_err("%s: could not allocate super clk\n", __func__); | ||
| 130 | return ERR_PTR(-ENOMEM); | ||
| 131 | } | ||
| 132 | |||
| 133 | init.name = name; | ||
| 134 | init.ops = &tegra_clk_super_ops; | ||
| 135 | init.flags = flags; | ||
| 136 | init.parent_names = parent_names; | ||
| 137 | init.num_parents = num_parents; | ||
| 138 | |||
| 139 | super->reg = reg; | ||
| 140 | super->pllx_index = pllx_index; | ||
| 141 | super->div2_index = div2_index; | ||
| 142 | super->lock = lock; | ||
| 143 | super->width = width; | ||
| 144 | super->flags = clk_super_flags; | ||
| 145 | |||
| 146 | /* Data in .init is copied by clk_register(), so stack variable OK */ | ||
| 147 | super->hw.init = &init; | ||
| 148 | |||
| 149 | clk = clk_register(NULL, &super->hw); | ||
| 150 | if (IS_ERR(clk)) | ||
| 151 | kfree(super); | ||
| 152 | |||
| 153 | return clk; | ||
| 154 | } | ||
