Skip to content

Commit f5644f1

Browse files
committed
clk: at91: Migrate to clk_hw based registration and OF APIs
Now that we have clk_hw based provider APIs to register clks, we can get rid of struct clk pointers in this driver, allowing us to move closer to a clear split of consumer and provider clk APIs. Signed-off-by: Stephen Boyd <[email protected]> Acked-by: Alexandre Belloni <[email protected]> Tested-by: Alexandre Belloni <[email protected]> Acked-by: Boris Brezillon <[email protected]> Signed-off-by: Stephen Boyd <[email protected]>
1 parent b19f009 commit f5644f1

File tree

13 files changed

+277
-199
lines changed

13 files changed

+277
-199
lines changed

drivers/clk/at91/clk-generated.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,16 @@ static void clk_generated_startup(struct clk_generated *gck)
233233
>> AT91_PMC_PCR_GCKDIV_OFFSET;
234234
}
235235

236-
static struct clk * __init
237-
at91_clk_register_generated(struct regmap *regmap, spinlock_t *lock, const char
238-
*name, const char **parent_names, u8 num_parents,
239-
u8 id, const struct clk_range *range)
236+
static struct clk_hw * __init
237+
at91_clk_register_generated(struct regmap *regmap, spinlock_t *lock,
238+
const char *name, const char **parent_names,
239+
u8 num_parents, u8 id,
240+
const struct clk_range *range)
240241
{
241242
struct clk_generated *gck;
242-
struct clk *clk = NULL;
243243
struct clk_init_data init;
244+
struct clk_hw *hw;
245+
int ret;
244246

245247
gck = kzalloc(sizeof(*gck), GFP_KERNEL);
246248
if (!gck)
@@ -258,21 +260,23 @@ at91_clk_register_generated(struct regmap *regmap, spinlock_t *lock, const char
258260
gck->lock = lock;
259261
gck->range = *range;
260262

261-
clk = clk_register(NULL, &gck->hw);
262-
if (IS_ERR(clk))
263+
hw = &gck->hw;
264+
ret = clk_hw_register(NULL, &gck->hw);
265+
if (ret) {
263266
kfree(gck);
264-
else
267+
hw = ERR_PTR(ret);
268+
} else
265269
clk_generated_startup(gck);
266270

267-
return clk;
271+
return hw;
268272
}
269273

270274
static void __init of_sama5d2_clk_generated_setup(struct device_node *np)
271275
{
272276
int num;
273277
u32 id;
274278
const char *name;
275-
struct clk *clk;
279+
struct clk_hw *hw;
276280
unsigned int num_parents;
277281
const char *parent_names[GENERATED_SOURCE_MAX];
278282
struct device_node *gcknp;
@@ -306,13 +310,13 @@ static void __init of_sama5d2_clk_generated_setup(struct device_node *np)
306310
of_at91_get_clk_range(gcknp, "atmel,clk-output-range",
307311
&range);
308312

309-
clk = at91_clk_register_generated(regmap, &pmc_pcr_lock, name,
313+
hw = at91_clk_register_generated(regmap, &pmc_pcr_lock, name,
310314
parent_names, num_parents,
311315
id, &range);
312-
if (IS_ERR(clk))
316+
if (IS_ERR(hw))
313317
continue;
314318

315-
of_clk_add_provider(gcknp, of_clk_src_simple_get, clk);
319+
of_clk_add_hw_provider(gcknp, of_clk_hw_simple_get, hw);
316320
}
317321
}
318322
CLK_OF_DECLARE(of_sama5d2_clk_generated_setup, "atmel,sama5d2-clk-generated",

drivers/clk/at91/clk-h32mx.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static void __init of_sama5d4_clk_h32mx_setup(struct device_node *np)
9292
struct clk_init_data init;
9393
const char *parent_name;
9494
struct regmap *regmap;
95-
struct clk *clk;
95+
int ret;
9696

9797
regmap = syscon_node_to_regmap(of_get_parent(np));
9898
if (IS_ERR(regmap))
@@ -113,13 +113,13 @@ static void __init of_sama5d4_clk_h32mx_setup(struct device_node *np)
113113
h32mxclk->hw.init = &init;
114114
h32mxclk->regmap = regmap;
115115

116-
clk = clk_register(NULL, &h32mxclk->hw);
117-
if (IS_ERR(clk)) {
116+
ret = clk_hw_register(NULL, &h32mxclk->hw);
117+
if (ret) {
118118
kfree(h32mxclk);
119119
return;
120120
}
121121

122-
of_clk_add_provider(np, of_clk_src_simple_get, clk);
122+
of_clk_add_hw_provider(np, of_clk_hw_simple_get, &h32mxclk->hw);
123123
}
124124
CLK_OF_DECLARE(of_sama5d4_clk_h32mx_setup, "atmel,sama5d4-clk-h32mx",
125125
of_sama5d4_clk_h32mx_setup);

drivers/clk/at91/clk-main.c

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,16 @@ static const struct clk_ops main_osc_ops = {
128128
.is_prepared = clk_main_osc_is_prepared,
129129
};
130130

131-
static struct clk * __init
131+
static struct clk_hw * __init
132132
at91_clk_register_main_osc(struct regmap *regmap,
133133
const char *name,
134134
const char *parent_name,
135135
bool bypass)
136136
{
137137
struct clk_main_osc *osc;
138-
struct clk *clk = NULL;
139138
struct clk_init_data init;
139+
struct clk_hw *hw;
140+
int ret;
140141

141142
if (!name || !parent_name)
142143
return ERR_PTR(-EINVAL);
@@ -160,16 +161,19 @@ at91_clk_register_main_osc(struct regmap *regmap,
160161
AT91_PMC_MOSCEN,
161162
AT91_PMC_OSCBYPASS | AT91_PMC_KEY);
162163

163-
clk = clk_register(NULL, &osc->hw);
164-
if (IS_ERR(clk))
164+
hw = &osc->hw;
165+
ret = clk_hw_register(NULL, &osc->hw);
166+
if (ret) {
165167
kfree(osc);
168+
hw = ERR_PTR(ret);
169+
}
166170

167-
return clk;
171+
return hw;
168172
}
169173

170174
static void __init of_at91rm9200_clk_main_osc_setup(struct device_node *np)
171175
{
172-
struct clk *clk;
176+
struct clk_hw *hw;
173177
const char *name = np->name;
174178
const char *parent_name;
175179
struct regmap *regmap;
@@ -183,11 +187,11 @@ static void __init of_at91rm9200_clk_main_osc_setup(struct device_node *np)
183187
if (IS_ERR(regmap))
184188
return;
185189

186-
clk = at91_clk_register_main_osc(regmap, name, parent_name, bypass);
187-
if (IS_ERR(clk))
190+
hw = at91_clk_register_main_osc(regmap, name, parent_name, bypass);
191+
if (IS_ERR(hw))
188192
return;
189193

190-
of_clk_add_provider(np, of_clk_src_simple_get, clk);
194+
of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
191195
}
192196
CLK_OF_DECLARE(at91rm9200_clk_main_osc, "atmel,at91rm9200-clk-main-osc",
193197
of_at91rm9200_clk_main_osc_setup);
@@ -271,14 +275,15 @@ static const struct clk_ops main_rc_osc_ops = {
271275
.recalc_accuracy = clk_main_rc_osc_recalc_accuracy,
272276
};
273277

274-
static struct clk * __init
278+
static struct clk_hw * __init
275279
at91_clk_register_main_rc_osc(struct regmap *regmap,
276280
const char *name,
277281
u32 frequency, u32 accuracy)
278282
{
279283
struct clk_main_rc_osc *osc;
280-
struct clk *clk = NULL;
281284
struct clk_init_data init;
285+
struct clk_hw *hw;
286+
int ret;
282287

283288
if (!name || !frequency)
284289
return ERR_PTR(-EINVAL);
@@ -298,16 +303,19 @@ at91_clk_register_main_rc_osc(struct regmap *regmap,
298303
osc->frequency = frequency;
299304
osc->accuracy = accuracy;
300305

301-
clk = clk_register(NULL, &osc->hw);
302-
if (IS_ERR(clk))
306+
hw = &osc->hw;
307+
ret = clk_hw_register(NULL, hw);
308+
if (ret) {
303309
kfree(osc);
310+
hw = ERR_PTR(ret);
311+
}
304312

305-
return clk;
313+
return hw;
306314
}
307315

308316
static void __init of_at91sam9x5_clk_main_rc_osc_setup(struct device_node *np)
309317
{
310-
struct clk *clk;
318+
struct clk_hw *hw;
311319
u32 frequency = 0;
312320
u32 accuracy = 0;
313321
const char *name = np->name;
@@ -321,11 +329,11 @@ static void __init of_at91sam9x5_clk_main_rc_osc_setup(struct device_node *np)
321329
if (IS_ERR(regmap))
322330
return;
323331

324-
clk = at91_clk_register_main_rc_osc(regmap, name, frequency, accuracy);
325-
if (IS_ERR(clk))
332+
hw = at91_clk_register_main_rc_osc(regmap, name, frequency, accuracy);
333+
if (IS_ERR(hw))
326334
return;
327335

328-
of_clk_add_provider(np, of_clk_src_simple_get, clk);
336+
of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
329337
}
330338
CLK_OF_DECLARE(at91sam9x5_clk_main_rc_osc, "atmel,at91sam9x5-clk-main-rc-osc",
331339
of_at91sam9x5_clk_main_rc_osc_setup);
@@ -395,14 +403,15 @@ static const struct clk_ops rm9200_main_ops = {
395403
.recalc_rate = clk_rm9200_main_recalc_rate,
396404
};
397405

398-
static struct clk * __init
406+
static struct clk_hw * __init
399407
at91_clk_register_rm9200_main(struct regmap *regmap,
400408
const char *name,
401409
const char *parent_name)
402410
{
403411
struct clk_rm9200_main *clkmain;
404-
struct clk *clk = NULL;
405412
struct clk_init_data init;
413+
struct clk_hw *hw;
414+
int ret;
406415

407416
if (!name)
408417
return ERR_PTR(-EINVAL);
@@ -423,16 +432,19 @@ at91_clk_register_rm9200_main(struct regmap *regmap,
423432
clkmain->hw.init = &init;
424433
clkmain->regmap = regmap;
425434

426-
clk = clk_register(NULL, &clkmain->hw);
427-
if (IS_ERR(clk))
435+
hw = &clkmain->hw;
436+
ret = clk_hw_register(NULL, &clkmain->hw);
437+
if (ret) {
428438
kfree(clkmain);
439+
hw = ERR_PTR(ret);
440+
}
429441

430-
return clk;
442+
return hw;
431443
}
432444

433445
static void __init of_at91rm9200_clk_main_setup(struct device_node *np)
434446
{
435-
struct clk *clk;
447+
struct clk_hw *hw;
436448
const char *parent_name;
437449
const char *name = np->name;
438450
struct regmap *regmap;
@@ -444,11 +456,11 @@ static void __init of_at91rm9200_clk_main_setup(struct device_node *np)
444456
if (IS_ERR(regmap))
445457
return;
446458

447-
clk = at91_clk_register_rm9200_main(regmap, name, parent_name);
448-
if (IS_ERR(clk))
459+
hw = at91_clk_register_rm9200_main(regmap, name, parent_name);
460+
if (IS_ERR(hw))
449461
return;
450462

451-
of_clk_add_provider(np, of_clk_src_simple_get, clk);
463+
of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
452464
}
453465
CLK_OF_DECLARE(at91rm9200_clk_main, "atmel,at91rm9200-clk-main",
454466
of_at91rm9200_clk_main_setup);
@@ -529,16 +541,17 @@ static const struct clk_ops sam9x5_main_ops = {
529541
.get_parent = clk_sam9x5_main_get_parent,
530542
};
531543

532-
static struct clk * __init
544+
static struct clk_hw * __init
533545
at91_clk_register_sam9x5_main(struct regmap *regmap,
534546
const char *name,
535547
const char **parent_names,
536548
int num_parents)
537549
{
538550
struct clk_sam9x5_main *clkmain;
539-
struct clk *clk = NULL;
540551
struct clk_init_data init;
541552
unsigned int status;
553+
struct clk_hw *hw;
554+
int ret;
542555

543556
if (!name)
544557
return ERR_PTR(-EINVAL);
@@ -561,16 +574,19 @@ at91_clk_register_sam9x5_main(struct regmap *regmap,
561574
regmap_read(clkmain->regmap, AT91_CKGR_MOR, &status);
562575
clkmain->parent = status & AT91_PMC_MOSCEN ? 1 : 0;
563576

564-
clk = clk_register(NULL, &clkmain->hw);
565-
if (IS_ERR(clk))
577+
hw = &clkmain->hw;
578+
ret = clk_hw_register(NULL, &clkmain->hw);
579+
if (ret) {
566580
kfree(clkmain);
581+
hw = ERR_PTR(ret);
582+
}
567583

568-
return clk;
584+
return hw;
569585
}
570586

571587
static void __init of_at91sam9x5_clk_main_setup(struct device_node *np)
572588
{
573-
struct clk *clk;
589+
struct clk_hw *hw;
574590
const char *parent_names[2];
575591
unsigned int num_parents;
576592
const char *name = np->name;
@@ -587,12 +603,12 @@ static void __init of_at91sam9x5_clk_main_setup(struct device_node *np)
587603

588604
of_property_read_string(np, "clock-output-names", &name);
589605

590-
clk = at91_clk_register_sam9x5_main(regmap, name, parent_names,
606+
hw = at91_clk_register_sam9x5_main(regmap, name, parent_names,
591607
num_parents);
592-
if (IS_ERR(clk))
608+
if (IS_ERR(hw))
593609
return;
594610

595-
of_clk_add_provider(np, of_clk_src_simple_get, clk);
611+
of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
596612
}
597613
CLK_OF_DECLARE(at91sam9x5_clk_main, "atmel,at91sam9x5-clk-main",
598614
of_at91sam9x5_clk_main_setup);

drivers/clk/at91/clk-master.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,17 @@ static const struct clk_ops master_ops = {
120120
.get_parent = clk_master_get_parent,
121121
};
122122

123-
static struct clk * __init
123+
static struct clk_hw * __init
124124
at91_clk_register_master(struct regmap *regmap,
125125
const char *name, int num_parents,
126126
const char **parent_names,
127127
const struct clk_master_layout *layout,
128128
const struct clk_master_characteristics *characteristics)
129129
{
130130
struct clk_master *master;
131-
struct clk *clk = NULL;
132131
struct clk_init_data init;
132+
struct clk_hw *hw;
133+
int ret;
133134

134135
if (!name || !num_parents || !parent_names)
135136
return ERR_PTR(-EINVAL);
@@ -149,12 +150,14 @@ at91_clk_register_master(struct regmap *regmap,
149150
master->characteristics = characteristics;
150151
master->regmap = regmap;
151152

152-
clk = clk_register(NULL, &master->hw);
153-
if (IS_ERR(clk)) {
153+
hw = &master->hw;
154+
ret = clk_hw_register(NULL, &master->hw);
155+
if (ret) {
154156
kfree(master);
157+
hw = ERR_PTR(ret);
155158
}
156159

157-
return clk;
160+
return hw;
158161
}
159162

160163

@@ -198,7 +201,7 @@ static void __init
198201
of_at91_clk_master_setup(struct device_node *np,
199202
const struct clk_master_layout *layout)
200203
{
201-
struct clk *clk;
204+
struct clk_hw *hw;
202205
unsigned int num_parents;
203206
const char *parent_names[MASTER_SOURCE_MAX];
204207
const char *name = np->name;
@@ -221,13 +224,13 @@ of_at91_clk_master_setup(struct device_node *np,
221224
if (IS_ERR(regmap))
222225
return;
223226

224-
clk = at91_clk_register_master(regmap, name, num_parents,
227+
hw = at91_clk_register_master(regmap, name, num_parents,
225228
parent_names, layout,
226229
characteristics);
227-
if (IS_ERR(clk))
230+
if (IS_ERR(hw))
228231
goto out_free_characteristics;
229232

230-
of_clk_add_provider(np, of_clk_src_simple_get, clk);
233+
of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
231234
return;
232235

233236
out_free_characteristics:

0 commit comments

Comments
 (0)