Skip to content

Commit 64c9247

Browse files
claudiubezneabebarino
authored andcommitted
clk: at91: clk-generated: pass the id of changeable parent at registration
Pass the ID of changeable parent at registration. This will allow the scalability of this clock driver with regards to the changeable parent ID for versions of this IP where changeable parent is not the last one in the parents list (e.g. SAMA7G5). With this the clock flags are set to zero in case we have no changeable parent. Also in clk_generated_best_diff() the *best_diff variable is check against tmp_diff variable using ">=" operator instead of ">" so that in case the requested frequency could be obtained using fix parents + gck dividers but the clock also supports changeable parent to be able to force the usage of the changeable parent. Signed-off-by: Claudiu Beznea <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Stephen Boyd <[email protected]>
1 parent 42324d9 commit 64c9247

File tree

5 files changed

+37
-35
lines changed

5 files changed

+37
-35
lines changed

drivers/clk/at91/clk-generated.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
#define GENERATED_MAX_DIV 255
2020

21-
#define GCK_INDEX_DT_AUDIO_PLL 5
22-
2321
struct clk_generated {
2422
struct clk_hw hw;
2523
struct regmap *regmap;
@@ -29,7 +27,7 @@ struct clk_generated {
2927
u32 gckdiv;
3028
const struct clk_pcr_layout *layout;
3129
u8 parent_id;
32-
bool audio_pll_allowed;
30+
int chg_pid;
3331
};
3432

3533
#define to_clk_generated(hw) \
@@ -109,7 +107,7 @@ static void clk_generated_best_diff(struct clk_rate_request *req,
109107
tmp_rate = parent_rate / div;
110108
tmp_diff = abs(req->rate - tmp_rate);
111109

112-
if (*best_diff < 0 || *best_diff > tmp_diff) {
110+
if (*best_diff < 0 || *best_diff >= tmp_diff) {
113111
*best_rate = tmp_rate;
114112
*best_diff = tmp_diff;
115113
req->best_parent_rate = parent_rate;
@@ -129,7 +127,10 @@ static int clk_generated_determine_rate(struct clk_hw *hw,
129127
int i;
130128
u32 div;
131129

132-
for (i = 0; i < clk_hw_get_num_parents(hw) - 1; i++) {
130+
for (i = 0; i < clk_hw_get_num_parents(hw); i++) {
131+
if (gck->chg_pid == i)
132+
continue;
133+
133134
parent = clk_hw_get_parent_by_index(hw, i);
134135
if (!parent)
135136
continue;
@@ -161,10 +162,10 @@ static int clk_generated_determine_rate(struct clk_hw *hw,
161162
* that the only clks able to modify gck rate are those of audio IPs.
162163
*/
163164

164-
if (!gck->audio_pll_allowed)
165+
if (gck->chg_pid < 0)
165166
goto end;
166167

167-
parent = clk_hw_get_parent_by_index(hw, GCK_INDEX_DT_AUDIO_PLL);
168+
parent = clk_hw_get_parent_by_index(hw, gck->chg_pid);
168169
if (!parent)
169170
goto end;
170171

@@ -272,8 +273,8 @@ struct clk_hw * __init
272273
at91_clk_register_generated(struct regmap *regmap, spinlock_t *lock,
273274
const struct clk_pcr_layout *layout,
274275
const char *name, const char **parent_names,
275-
u8 num_parents, u8 id, bool pll_audio,
276-
const struct clk_range *range)
276+
u8 num_parents, u8 id,
277+
const struct clk_range *range, int chg_pid)
277278
{
278279
struct clk_generated *gck;
279280
struct clk_init_data init;
@@ -288,15 +289,16 @@ at91_clk_register_generated(struct regmap *regmap, spinlock_t *lock,
288289
init.ops = &generated_ops;
289290
init.parent_names = parent_names;
290291
init.num_parents = num_parents;
291-
init.flags = CLK_SET_RATE_GATE | CLK_SET_PARENT_GATE |
292-
CLK_SET_RATE_PARENT;
292+
init.flags = CLK_SET_RATE_GATE | CLK_SET_PARENT_GATE;
293+
if (chg_pid >= 0)
294+
init.flags |= CLK_SET_RATE_PARENT;
293295

294296
gck->id = id;
295297
gck->hw.init = &init;
296298
gck->regmap = regmap;
297299
gck->lock = lock;
298300
gck->range = *range;
299-
gck->audio_pll_allowed = pll_audio;
301+
gck->chg_pid = chg_pid;
300302
gck->layout = layout;
301303

302304
clk_generated_startup(gck);

drivers/clk/at91/dt-compat.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
#define SYSTEM_MAX_ID 31
2424

25+
#define GCK_INDEX_DT_AUDIO_PLL 5
26+
2527
#ifdef CONFIG_HAVE_AT91_AUDIO_PLL
2628
static void __init of_sama5d2_clk_audio_pll_frac_setup(struct device_node *np)
2729
{
@@ -135,7 +137,7 @@ static void __init of_sama5d2_clk_generated_setup(struct device_node *np)
135137
return;
136138

137139
for_each_child_of_node(np, gcknp) {
138-
bool pll_audio = false;
140+
int chg_pid = INT_MIN;
139141

140142
if (of_property_read_u32(gcknp, "reg", &id))
141143
continue;
@@ -152,12 +154,12 @@ static void __init of_sama5d2_clk_generated_setup(struct device_node *np)
152154
if (of_device_is_compatible(np, "atmel,sama5d2-clk-generated") &&
153155
(id == GCK_ID_I2S0 || id == GCK_ID_I2S1 ||
154156
id == GCK_ID_CLASSD))
155-
pll_audio = true;
157+
chg_pid = GCK_INDEX_DT_AUDIO_PLL;
156158

157159
hw = at91_clk_register_generated(regmap, &pmc_pcr_lock,
158160
&dt_pcr_layout, name,
159161
parent_names, num_parents,
160-
id, pll_audio, &range);
162+
id, &range, chg_pid);
161163
if (IS_ERR(hw))
162164
continue;
163165

drivers/clk/at91/pmc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ struct clk_hw * __init
122122
at91_clk_register_generated(struct regmap *regmap, spinlock_t *lock,
123123
const struct clk_pcr_layout *layout,
124124
const char *name, const char **parent_names,
125-
u8 num_parents, u8 id, bool pll_audio,
126-
const struct clk_range *range);
125+
u8 num_parents, u8 id,
126+
const struct clk_range *range, int chg_pid);
127127

128128
struct clk_hw * __init
129129
at91_clk_register_h32mx(struct regmap *regmap, const char *name,

drivers/clk/at91/sam9x60.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,7 @@ static void __init sam9x60_pmc_setup(struct device_node *np)
290290
sam9x60_gck[i].n,
291291
parent_names, 6,
292292
sam9x60_gck[i].id,
293-
false,
294-
&sam9x60_gck[i].r);
293+
&sam9x60_gck[i].r, INT_MIN);
295294
if (IS_ERR(hw))
296295
goto err_free;
297296

drivers/clk/at91/sama5d2.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -116,21 +116,20 @@ static const struct {
116116
char *n;
117117
u8 id;
118118
struct clk_range r;
119-
bool pll;
119+
int chg_pid;
120120
} sama5d2_gck[] = {
121-
{ .n = "sdmmc0_gclk", .id = 31, },
122-
{ .n = "sdmmc1_gclk", .id = 32, },
123-
{ .n = "tcb0_gclk", .id = 35, .r = { .min = 0, .max = 83000000 }, },
124-
{ .n = "tcb1_gclk", .id = 36, .r = { .min = 0, .max = 83000000 }, },
125-
{ .n = "pwm_gclk", .id = 38, .r = { .min = 0, .max = 83000000 }, },
126-
{ .n = "isc_gclk", .id = 46, },
127-
{ .n = "pdmic_gclk", .id = 48, },
128-
{ .n = "i2s0_gclk", .id = 54, .pll = true },
129-
{ .n = "i2s1_gclk", .id = 55, .pll = true },
130-
{ .n = "can0_gclk", .id = 56, .r = { .min = 0, .max = 80000000 }, },
131-
{ .n = "can1_gclk", .id = 57, .r = { .min = 0, .max = 80000000 }, },
132-
{ .n = "classd_gclk", .id = 59, .r = { .min = 0, .max = 100000000 },
133-
.pll = true },
121+
{ .n = "sdmmc0_gclk", .id = 31, .chg_pid = INT_MIN, },
122+
{ .n = "sdmmc1_gclk", .id = 32, .chg_pid = INT_MIN, },
123+
{ .n = "tcb0_gclk", .id = 35, .chg_pid = INT_MIN, .r = { .min = 0, .max = 83000000 }, },
124+
{ .n = "tcb1_gclk", .id = 36, .chg_pid = INT_MIN, .r = { .min = 0, .max = 83000000 }, },
125+
{ .n = "pwm_gclk", .id = 38, .chg_pid = INT_MIN, .r = { .min = 0, .max = 83000000 }, },
126+
{ .n = "isc_gclk", .id = 46, .chg_pid = INT_MIN, },
127+
{ .n = "pdmic_gclk", .id = 48, .chg_pid = INT_MIN, },
128+
{ .n = "i2s0_gclk", .id = 54, .chg_pid = 5, },
129+
{ .n = "i2s1_gclk", .id = 55, .chg_pid = 5, },
130+
{ .n = "can0_gclk", .id = 56, .chg_pid = INT_MIN, .r = { .min = 0, .max = 80000000 }, },
131+
{ .n = "can1_gclk", .id = 57, .chg_pid = INT_MIN, .r = { .min = 0, .max = 80000000 }, },
132+
{ .n = "classd_gclk", .id = 59, .chg_pid = 5, .r = { .min = 0, .max = 100000000 }, },
134133
};
135134

136135
static const struct clk_programmable_layout sama5d2_programmable_layout = {
@@ -324,8 +323,8 @@ static void __init sama5d2_pmc_setup(struct device_node *np)
324323
sama5d2_gck[i].n,
325324
parent_names, 6,
326325
sama5d2_gck[i].id,
327-
sama5d2_gck[i].pll,
328-
&sama5d2_gck[i].r);
326+
&sama5d2_gck[i].r,
327+
sama5d2_gck[i].chg_pid);
329328
if (IS_ERR(hw))
330329
goto err_free;
331330

0 commit comments

Comments
 (0)