-
Notifications
You must be signed in to change notification settings - Fork 18
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
Add clock driver for meson #278
Open
terryzbai
wants to merge
11
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 all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7f26516
Clock driver for odroidc4
terryzbai 1e28903
add Makefile
terryzbai 1f03995
Clock driver for maaxboard
terryzbai 06bd8b6
Clk: fix style
terryzbai 9d0fa57
clk: modify interfaces and fix issues during initialisation
terryzbai 1acc8de
clk: fix style and add licenses
terryzbai 0a6c664
clk: fix style and data types
terryzbai d8a400c
clk: combine regmap_* and regmap_mux_* operations
terryzbai e38a2d3
clk: add get/set parent interfaces
terryzbai 38d9f73
clk: set_rate for maaxboard clocks
terryzbai 8812739
clk: reorganise files
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 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 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,262 @@ | ||
// 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 <[email protected]> | ||
*/ | ||
|
||
// 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 <[email protected]> | ||
* | ||
* Copyright (c) 2018 Baylibre, SAS. | ||
* Author: Jerome Brunet <[email protected]> | ||
*/ | ||
|
||
// 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 <[email protected]> | ||
*/ | ||
|
||
// 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 <[email protected]> | ||
*/ | ||
|
||
// 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 <[email protected]> | ||
* Copyright (C) 2011 Richard Zhao, Linaro <[email protected]> | ||
* Copyright (C) 2011-2012 Mike Turquette, Linaro Ltd <[email protected]> | ||
* | ||
* 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 <[email protected]> | ||
* Copyright (C) 2011 Richard Zhao, Linaro <[email protected]> | ||
* Copyright (C) 2011-2012 Mike Turquette, Linaro Ltd <[email protected]> | ||
* | ||
* 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 <[email protected]> | ||
*/ | ||
|
||
#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) { | ||
/* TODO: to be implemented */ | ||
; | ||
} 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 = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't be needed in our LionsOS systems |
||
.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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need to provide the vector of functions; our systems will have only a single clock driver in them. Kill the 'static' and just link directly against the symbols instead of via a function pointer