-
Notifications
You must be signed in to change notification settings - Fork 34
Add clock driver for meson #278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
terryzbai
wants to merge
21
commits into
main
Choose a base branch
from
clk_driver
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 18 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
8c5a295
Clock driver for odroidc4
terryzbai b8ba1d2
add Makefile
terryzbai b4d4e1d
Clock driver for maaxboard
terryzbai 5716ded
Clk: fix style
terryzbai 72b06b1
clk: modify interfaces and fix issues during initialisation
terryzbai ea8a58e
clk: fix style and add licenses
terryzbai 4a05f3c
clk: fix style and data types
terryzbai 2e6d30d
clk: combine regmap_* and regmap_mux_* operations
terryzbai f101648
clk: add get/set parent interfaces
terryzbai b10c144
clk: set_rate for maaxboard clocks
terryzbai c48175d
clk: reorganise files
terryzbai 9ce6302
Update clock driver to current sddf build style, added meta.py
omeh-a 3bd5a78
Replace setvar constants, move all memory region setup to meta.py
omeh-a 79f7d04
Clock driver for maaxboard
terryzbai 9ba2dc7
examples/clk: remove timer for client
terryzbai 7a80eef
examples/clk: remove dts dir
terryzbai e2376c5
drivers/clk: add sddf_clk_set_cpu_freq() interface
terryzbai 750ab83
drivers/clk: add ARM_CLK and remove sddf_clk_set_cpu_freq()
terryzbai 475bbd1
drivers/clk: fix compilation complaints
terryzbai b407725
drivers/clk: fix returned_freq of clk_set_rate()
terryzbai 8522ac6
drivers/clk: fix parent clock of ARM_CLK for imx8mq
terryzbai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,261 @@ | ||
| // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) | ||
| /* | ||
| * Operations for MPLL clocks are derived from: | ||
| * https://github.com/torvalds/linux/blob/ | ||
| * befe87380e21f0d37633273e1068c9318f8135ff/drivers/clk/meson/clk-mpll.c | ||
| * | ||
| * Copyright (c) 2016 AmLogic, Inc. | ||
| * Author: Michael Turquette <mturquette@baylibre.com> | ||
| */ | ||
|
|
||
| // SPDX-License-Identifier: GPL-2.0-only | ||
| /* | ||
| * Operations for PLL clocks are derived from: | ||
| * https://github.com/torvalds/linux/blob/ | ||
| * befe87380e21f0d37633273e1068c9318f8135ff/drivers/clk/meson/clk-pll.c | ||
| * | ||
| * Copyright (c) 2015 Endless Mobile, Inc. | ||
| * Author: Carlo Caione <carlo@endlessm.com> | ||
| * | ||
| * Copyright (c) 2018 Baylibre, SAS. | ||
| * Author: Jerome Brunet <jbrunet@baylibre.com> | ||
| */ | ||
|
|
||
| // SPDX-License-Identifier: GPL-2.0-only | ||
| /* | ||
| * Operations for gate clocks are derived from: | ||
| * https://github.com/torvalds/linux/blob/ | ||
| * befe87380e21f0d37633273e1068c9318f8135ff/drivers/clk/meson/clk-regmap.c | ||
| * | ||
| * Copyright (c) 2018 BayLibre, SAS. | ||
| * Author: Jerome Brunet <jbrunet@baylibre.com> | ||
| */ | ||
|
|
||
| // SPDX-License-Identifier: GPL-2.0-only | ||
| /* | ||
| * Operations for fixed factor clocks are derived from: | ||
| * https://github.com/torvalds/linux/blob/ | ||
| * befe87380e21f0d37633273e1068c9318f8135ff/drivers/clk/clk-fixed-factor.c | ||
| * | ||
| * Copyright (C) 2011 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de> | ||
| */ | ||
|
|
||
| // SPDX-License-Identifier: GPL-2.0-only | ||
| /* | ||
| * Operations for divider clocks are derived from: | ||
| * https://github.com/torvalds/linux/blob/ | ||
| * befe87380e21f0d37633273e1068c9318f8135ff/drivers/clk/clk-divider.c | ||
| * | ||
| * Copyright (C) 2011 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de> | ||
| * Copyright (C) 2011 Richard Zhao, Linaro <richard.zhao@linaro.org> | ||
| * Copyright (C) 2011-2012 Mike Turquette, Linaro Ltd <mturquette@linaro.org> | ||
| * | ||
| * Adjustable divider clock implementation | ||
| */ | ||
|
|
||
| // SPDX-License-Identifier: GPL-2.0-only | ||
| /* | ||
| * Operations for multiplexer clocks are derived from: | ||
| * https://github.com/torvalds/linux/blob/ | ||
| * befe87380e21f0d37633273e1068c9318f8135ff/drivers/clk/clk-mux.c | ||
| * | ||
| * Copyright (C) 2011 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de> | ||
| * Copyright (C) 2011 Richard Zhao, Linaro <richard.zhao@linaro.org> | ||
| * Copyright (C) 2011-2012 Mike Turquette, Linaro Ltd <mturquette@linaro.org> | ||
| * | ||
| * Simple multiplexer clock implementation | ||
| */ | ||
|
|
||
| // SPDX-License-Identifier: GPL-2.0-only | ||
| /* | ||
| * Operations for meson_vid_pll_div are derived from: | ||
| * https://github.com/torvalds/linux/blob/ | ||
| * 7ec462100ef9142344ddbf86f2c3008b97acddbe/drivers/clk/meson/vid-pll-div.c | ||
| * https://github.com/torvalds/linux/blob/ | ||
| * 7ec462100ef9142344ddbf86f2c3008b97acddbe/drivers/clk/meson/vclk.c | ||
| * | ||
| * Copyright (c) 2018 BayLibre, SAS. | ||
| * Author: Neil Armstrong <narmstrong@baylibre.com> | ||
| */ | ||
|
|
||
| #include <clk.h> | ||
| #include <clk-operations.h> | ||
| #include <sddf/timer/client.h> | ||
| #include <sddf/util/printf.h> | ||
| #include <clk_utils.h> | ||
|
|
||
| static inline int clk_gate_enable(struct clk *clk) | ||
| { | ||
| struct clk_gate_data *data = (struct clk_gate_data *)(clk->data); | ||
|
|
||
| return regmap_update_bits(clk->base, data->offset, data->bit_idx, MASK(1), 1); | ||
| } | ||
|
|
||
| static inline int clk_gate_disable(struct clk *clk) | ||
| { | ||
| struct clk_gate_data *data = (struct clk_gate_data *)(clk->data); | ||
|
|
||
| regmap_update_bits(clk->base, data->offset, data->bit_idx, MASK(1), 0); | ||
| return 0; | ||
| } | ||
|
|
||
| static inline int clk_gate_is_enabled(struct clk *clk) | ||
| { | ||
| struct clk_gate_data *data = (struct clk_gate_data *)(clk->data); | ||
|
|
||
| /* TODO: to be checked */ | ||
| /* if (gate->flags & CLK_GATE_SET_TO_DISABLE) */ | ||
| /* val ^= BIT(gate->bit_idx); */ | ||
|
|
||
| /* val &= BIT(gate->bit_idx); */ | ||
| /* return val ? 1 : 0; */ | ||
|
|
||
| return regmap_read_bits(clk->base, data->offset, data->bit_idx, MASK(1)); | ||
| } | ||
|
|
||
| const struct clk_ops clk_gate_ops = { | ||
| .enable = clk_gate_enable, | ||
| .disable = clk_gate_disable, | ||
| .is_enabled = clk_gate_is_enabled, | ||
| }; | ||
|
|
||
| const struct clk_ops clk_gate_ro_ops = { | ||
| .is_enabled = clk_gate_is_enabled, | ||
| }; | ||
|
|
||
| static inline uint64_t clk_div_recalc_rate(const struct clk *clk, uint64_t prate) | ||
| { | ||
|
|
||
| struct clk_div_data *data = (struct clk_div_data *)(clk->data); | ||
| uint32_t div = regmap_read_bits(clk->base, data->offset, data->shift, MASK(data->width)); | ||
|
|
||
| /* TODO: Need to verify the following cases */ | ||
| if (data->flags & CLK_DIVIDER_ONE_BASED) { | ||
| ; | ||
| } else if (data->flags & CLK_DIVIDER_POWER_OF_TWO) { | ||
| div = 1 << div; | ||
| } else if (data->flags & CLK_DIVIDER_MAX_AT_ZERO) { | ||
| div = div ? div : MASK(data->width) + 1; | ||
| } else { | ||
| div += 1; | ||
| } | ||
|
|
||
| return DIV_ROUND_UP_ULL((uint64_t)prate, div); | ||
| } | ||
|
|
||
| static inline int clk_div_set_rate(const struct clk *clk, uint64_t rate, uint64_t parent_rate) | ||
| { | ||
| struct clk_div_data *data = (struct clk_div_data *)(clk->data); | ||
| uint32_t div = DIV_ROUND_UP(parent_rate, rate); | ||
|
|
||
| if (data->flags & CLK_DIVIDER_ONE_BASED) { | ||
| ; | ||
| } else if (data->flags & CLK_DIVIDER_POWER_OF_TWO) { | ||
| /* div = __ffs(div); */ | ||
| } else if (data->flags & CLK_DIVIDER_MAX_AT_ZERO) { | ||
| div = (div == MASK(data->width) + 1) ? 0 : div; | ||
| } else { | ||
| div -= 1; | ||
| } | ||
| return regmap_update_bits(clk->base, data->offset, data->shift, MASK(data->width), div); | ||
| } | ||
|
|
||
| const struct clk_ops clk_divider_ops = { | ||
|
terryzbai marked this conversation as resolved.
|
||
| .enable = NULL, | ||
| .recalc_rate = clk_div_recalc_rate, | ||
| /* .determine_rate = clk_div_determine_rate, */ | ||
| .set_rate = clk_div_set_rate, | ||
| }; | ||
|
|
||
| const struct clk_ops clk_divider_ro_ops = { | ||
| .recalc_rate = clk_div_recalc_rate, | ||
| /* .determine_rate = clk_div_determine_rate, */ | ||
| }; | ||
|
|
||
| static inline int clk_mux_get_parent(const struct clk *clk, uint8_t *index) | ||
| { | ||
| struct clk_mux_data *data = (struct clk_mux_data *)(clk->data); | ||
| uint32_t num_parents = clk->hw.init->num_parents; | ||
| uint32_t val = regmap_read_bits(clk->base, data->offset, data->shift, data->mask); | ||
|
|
||
| if (data->table) { | ||
| int i; | ||
| for (i = 0; i < num_parents; i++) { | ||
| if (data->table[i] == val) { | ||
| *index = i; | ||
| return 0; | ||
| } | ||
| } | ||
| return CLK_UNKNOWN_TARGET; | ||
| } | ||
|
|
||
| /* if (val && (flags & CLK_MUX_INDEX_BIT)) */ | ||
| /* val = ffs(val) - 1; */ | ||
|
|
||
| /* if (val && (flags & CLK_MUX_INDEX_ONE)) */ | ||
| /* val--; */ | ||
|
|
||
| if (val >= num_parents) | ||
| return CLK_UNKNOWN_TARGET; | ||
|
|
||
| *index = val; | ||
| return 0; | ||
| } | ||
|
|
||
| static inline int clk_mux_set_parent(struct clk *clk, uint8_t index) | ||
| { | ||
| struct clk_mux_data *data = (struct clk_mux_data *)(clk->data); | ||
|
|
||
| if (data->table) { | ||
| uint32_t val = data->table[index]; | ||
| return regmap_update_bits(clk->base, data->offset, data->shift, data->mask, val); | ||
| } | ||
|
|
||
| return regmap_update_bits(clk->base, data->offset, data->shift, data->mask, index); | ||
| } | ||
|
|
||
| const struct clk_ops clk_mux_ops = { | ||
| .get_parent = clk_mux_get_parent, .set_parent = clk_mux_set_parent, | ||
| /* .determine_rate = clk_mux_determine_rate, */ | ||
| }; | ||
|
|
||
| const struct clk_ops clk_mux_ro_ops = { | ||
| .get_parent = clk_mux_get_parent, | ||
| }; | ||
|
|
||
| static inline uint64_t clk_factor_recalc_rate(const struct clk *clk, uint64_t parent_rate) | ||
| { | ||
| struct clk_fixed_factor_data *data = (struct clk_fixed_factor_data *)(clk->data); | ||
| uint64_t rate; | ||
|
|
||
| rate = (uint64_t)parent_rate * data->mult; | ||
| do_div(rate, data->div); | ||
| return (uint64_t)rate; | ||
| } | ||
|
|
||
| const struct clk_ops clk_fixed_factor_ops = { | ||
| /* .round_rate = clk_factor_round_rate, */ | ||
| /* .set_rate = clk_factor_set_rate, */ | ||
| .recalc_rate = clk_factor_recalc_rate, | ||
| /* .recalc_accuracy = clk_factor_recalc_accuracy, */ | ||
| }; | ||
|
|
||
| static inline int clk_source_set_rate(const struct clk *clk, uint64_t rate, uint64_t parent_rate) | ||
| { | ||
| struct clk_source_data *data = (struct clk_source_data *)(clk->data); | ||
| data->rate = rate; | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| static inline uint64_t clk_source_get_rate(const struct clk *clk, uint64_t prate) | ||
| { | ||
| struct clk_source_data *data = (struct clk_source_data *)(clk->data); | ||
|
|
||
| return data->rate; | ||
| } | ||
|
|
||
| const struct clk_ops clk_source_ops = { | ||
| .recalc_rate = clk_source_get_rate, | ||
| .set_rate = clk_source_set_rate, | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.