aboutsummaryrefslogtreecommitdiff
path: root/drivers/clk/hisilicon/clk-hi3xxx.c
blob: 72115a5763bbc491c18c0d974c15c87f846b77c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
/*
 * Hisilicon clock driver
 *
 * Copyright (c) 2012-2013 Hisilicon Limited.
 * Copyright (c) 2012-2013 Linaro Limited.
 *
 * Author: Haojian Zhuang <haojian.zhuang@linaro.org>
 *	   Xin Li <li.xin@linaro.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */

#include <linux/kernel.h>
#include <linux/clk-provider.h>
#include <linux/clk-private.h>
#include <linux/clkdev.h>
#include <linux/delay.h>
#include <linux/io.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/of_device.h>
#include <linux/slab.h>
#include <linux/clk.h>

#define HI3620_DISABLE_OFF		0x4
#define HI3620_STATUS_OFF		0x8

#define WIDTH_TO_MASK(width)	((1 << (width)) - 1)

/*
 * The reverse of DIV_ROUND_UP: The maximum number which
 * divided by m is r
 */
#define MULT_ROUND_UP(r, m) ((r) * (m) + (m) - 1)

enum {
	HS_PMCTRL,
	HS_SYSCTRL,
	HS_EDC,
};

struct hi3620_periclk {
	struct clk_hw	hw;
	void __iomem	*enable;	/* enable register */
	void __iomem	*reset;		/* reset register */
	u32		ebits;		/* bits in enable/disable register */
	u32		rbits;		/* bits in reset/unreset register */
	spinlock_t	*lock;
};

struct hi3620_muxclk {
	struct clk_hw	hw;
	void __iomem	*reg;		/* mux register */
	u8		shift;
	u8		width;
	u32		mbits;		/* mask bits in mux register */
	spinlock_t	*lock;
};

struct hi3620_divclk {
	struct clk_hw	hw;
	void __iomem	*reg;		/* divider register */
	u8		shift;
	u8		width;
	u32		mbits;		/* mask bits in divider register */
	const struct clk_div_table	*table;
	spinlock_t	*lock;
};

struct hs_clk {
	void __iomem	*pmctrl;
	void __iomem	*sctrl;
	void __iomem	*edc;
	spinlock_t	lock;
};

static void __iomem __init *hs_init_clocks(struct device_node *np);

static struct hs_clk hs_clk;

static int hi3620_clkgate_prepare(struct clk_hw *hw)
{
	struct hi3620_periclk *pclk;
	unsigned long flags = 0;

	pclk = container_of(hw, struct hi3620_periclk, hw);

	if (pclk->lock)
		spin_lock_irqsave(pclk->lock, flags);
	if (pclk->reset) {
		writel_relaxed(pclk->rbits, pclk->reset + HI3620_DISABLE_OFF);
		readl_relaxed(pclk->reset + HI3620_STATUS_OFF);
	}
	if (pclk->lock)
		spin_unlock_irqrestore(pclk->lock, flags);
	return 0;
}

static int hi3620_clkgate_enable(struct clk_hw *hw)
{
	struct hi3620_periclk *pclk;
	unsigned long flags = 0;

	pclk = container_of(hw, struct hi3620_periclk, hw);
	if (pclk->lock)
		spin_lock_irqsave(pclk->lock, flags);
	writel_relaxed(pclk->ebits, pclk->enable);
	readl_relaxed(pclk->enable + HI3620_STATUS_OFF);
	if (pclk->lock)
		spin_unlock_irqrestore(pclk->lock, flags);
	return 0;
}

static void hi3620_clkgate_disable(struct clk_hw *hw)
{
	struct hi3620_periclk *pclk;
	unsigned long flags = 0;

	pclk = container_of(hw, struct hi3620_periclk, hw);
	if (pclk->lock)
		spin_lock_irqsave(pclk->lock, flags);
	writel_relaxed(pclk->ebits, pclk->enable + HI3620_DISABLE_OFF);
	readl_relaxed(pclk->enable + HI3620_STATUS_OFF);
	if (pclk->lock)
		spin_unlock_irqrestore(pclk->lock, flags);
}

static struct clk_ops hi3620_clkgate_ops = {
	.prepare	= hi3620_clkgate_prepare,
	.enable		= hi3620_clkgate_enable,
	.disable	= hi3620_clkgate_disable,
};

static void __init hi3620_clkgate_setup(struct device_node *np)
{
	struct hi3620_periclk *pclk;
	struct clk_init_data *init;
	struct clk *clk;
	const char *clk_name, *name, **parent_names;
	void __iomem *reg_base;
	u32 rdata[2], gdata[2];

	reg_base = hs_init_clocks(np);
	if (!reg_base)
		return;

	if (of_property_read_string(np, "clock-output-names", &clk_name))
		return;
	if (of_property_read_u32_array(np, "hisilicon,hi3620-clkgate",
				       &gdata[0], 2))
		return;

	/* gate only has the fixed parent */
	parent_names = kzalloc(sizeof(char *), GFP_KERNEL);
	if (!parent_names)
		return;
	parent_names[0] = of_clk_get_parent_name(np, 0);

	pclk = kzalloc(sizeof(*pclk), GFP_KERNEL);
	if (!pclk)
		goto err_pclk;

	init = kzalloc(sizeof(*init), GFP_KERNEL);
	if (!init)
		goto err_init;
	init->name = kstrdup(clk_name, GFP_KERNEL);
	init->ops = &hi3620_clkgate_ops;
	init->flags = CLK_SET_RATE_PARENT;
	init->parent_names = parent_names;
	init->num_parents = 1;

	if (of_property_read_u32_array(np, "hisilicon,hi3620-clkreset",
				       &rdata[0], 2)) {
		pclk->reset = 0;
		pclk->rbits = 0;
	} else {
		pclk->reset = reg_base + rdata[0];
		pclk->rbits = rdata[1];
	}
	pclk->enable = reg_base + gdata[0];
	pclk->ebits = gdata[1];
	pclk->lock = &hs_clk.lock;
	pclk->hw.init = init;

	clk = clk_register(NULL, &pclk->hw);
	if (IS_ERR(clk))
		goto err_clk;
	if (!of_property_read_string(np, "clock-names", &name))
		clk_register_clkdev(clk, name, NULL);
	of_clk_add_provider(np, of_clk_src_simple_get, clk);
	return;
err_clk:
	kfree(init);
err_init:
	kfree(pclk);
err_pclk:
	kfree(parent_names);
}

static u8 hi3620_clk_get_parent(struct clk_hw *hw)
{
	struct hi3620_muxclk *mclk;
	u32 data;
	unsigned long flags = 0;

	mclk = container_of(hw, struct hi3620_muxclk, hw);

	if (mclk->lock)
		spin_lock_irqsave(mclk->lock, flags);

	data = readl_relaxed(mclk->reg) >> mclk->shift;
	data &= WIDTH_TO_MASK(mclk->width);

	if (mclk->lock)
		spin_unlock_irqrestore(mclk->lock, flags);

	if (data >= __clk_get_num_parents(hw->clk))
		return -EINVAL;

	return (u8)data;
}

static int hi3620_clk_set_parent(struct clk_hw *hw, u8 index)
{
	struct hi3620_muxclk *mclk;
	u32 data;
	unsigned long flags = 0;

	mclk = container_of(hw, struct hi3620_muxclk, hw);

	if (mclk->lock)
		spin_lock_irqsave(mclk->lock, flags);

	data = readl_relaxed(mclk->reg);
	data &= ~(WIDTH_TO_MASK(mclk->width) << mclk->shift);
	data |= index << mclk->shift;
	writel_relaxed(data, mclk->reg);
	/* set mask enable bits */
	data |= mclk->mbits;
	writel_relaxed(data, mclk->reg);

	if (mclk->lock)
		spin_unlock_irqrestore(mclk->lock, flags);

	return 0;
}

static struct clk_ops hi3620_clkmux_ops = {
	.get_parent	= hi3620_clk_get_parent,
	.set_parent	= hi3620_clk_set_parent,
};

static void __init hi3620_clkmux_setup(struct device_node *np)
{
	struct hi3620_muxclk *mclk;
	struct clk_init_data *init;
	struct clk *clk;
	const char *clk_name, **parent_names;
	void __iomem *reg_base;
	u32 rdata[2];
	u8 num_parents;
	int i;

	reg_base = hs_init_clocks(np);
	if (!reg_base)
		return;

	if (of_property_read_string(np, "clock-output-names", &clk_name))
		return;
	if (of_property_read_u32_array(np, "hisilicon,hi3620-clkmux",
				       &rdata[0], 2))
		return;
	/* get the count of items in mux */
	for (i = 0; ; i++) {
		/* parent's #clock-cells property is always 0 */
		if (!of_parse_phandle(np, "clocks", i))
			break;
	}
	parent_names = kzalloc(sizeof(char *) * i, GFP_KERNEL);
	if (!parent_names)
		return;

	for (num_parents = i, i = 0; i < num_parents; i++)
		parent_names[i] = of_clk_get_parent_name(np, i);

	mclk = kzalloc(sizeof(*mclk), GFP_KERNEL);
	if (!mclk)
		goto err_mclk;
	init = kzalloc(sizeof(*init), GFP_KERNEL);
	if (!init)
		goto err_init;
	init->name = kstrdup(clk_name, GFP_KERNEL);
	init->ops = &hi3620_clkmux_ops;
	init->flags = CLK_SET_RATE_PARENT;
	init->parent_names = parent_names;
	init->num_parents = num_parents;

	mclk->reg = reg_base + rdata[0];
	/* enable_mask bits are in higher 16bits */
	mclk->mbits = rdata[1] << 16;
	mclk->shift = ffs(rdata[1]) - 1;
	mclk->width = fls(rdata[1]) - ffs(rdata[1]) + 1;
	mclk->lock = &hs_clk.lock;
	mclk->hw.init = init;

	clk = clk_register(NULL, &mclk->hw);
	if (IS_ERR(clk))
		goto err_clk;
	of_clk_add_provider(np, of_clk_src_simple_get, clk);

	return;
err_clk:
	kfree(init);
err_init:
	kfree(mclk);
err_mclk:
	kfree(parent_names);
}

static void __init hs_clkgate_setup(struct device_node *np)
{
	struct clk *clk;
	const char *clk_name, **parent_names, *name;
	unsigned long flags = 0;
	void __iomem *reg_base;
	u32 data[2];

	reg_base = hs_init_clocks(np);
	if (!reg_base)
		return;
	if (of_property_read_string(np, "clock-output-names", &clk_name))
		return;
	if (of_property_read_u32_array(np, "hisilicon,clkgate",
				       &data[0], 2))
		return;
	if (of_property_read_bool(np, "hisilicon,clkgate-inverted"))
		flags = CLK_GATE_SET_TO_DISABLE;
	/* gate only has the fixed parent */
	parent_names = kzalloc(sizeof(char *), GFP_KERNEL);
	if (!parent_names)
		return;
	parent_names[0] = of_clk_get_parent_name(np, 0);

	clk = clk_register_gate(NULL, clk_name, parent_names[0], 0,
				reg_base + data[0], (u8)data[1], flags,
				&hs_clk.lock);
	if (IS_ERR(clk))
		goto err;
	if (!of_property_read_string(np, "clock-names", &name))
		clk_register_clkdev(clk, name, NULL);
	of_clk_add_provider(np, of_clk_src_simple_get, clk);
	return;
err:
	kfree(parent_names);
}

void __init hs_fixed_factor_setup(struct device_node *np)
{
	struct clk *clk;
	const char *clk_name, **parent_names;
	u32 data[2];

	if (of_property_read_string(np, "clock-output-names", &clk_name))
		return;
	if (of_property_read_u32_array(np, "hisilicon,fixed-factor",
				       data, 2))
		return ;
	/* gate only has the fixed parent */
	parent_names = kzalloc(sizeof(char *), GFP_KERNEL);
	if (!parent_names)
		return;
	parent_names[0] = of_clk_get_parent_name(np, 0);

	clk = clk_register_fixed_factor(NULL, clk_name, parent_names[0],
					CLK_SET_RATE_PARENT,
					data[0], data[1]);
	if (IS_ERR(clk))
		goto err;
	of_clk_add_provider(np, of_clk_src_simple_get, clk);
	return;
err:
	kfree(parent_names);
}

static unsigned int hi3620_get_table_maxdiv(const struct clk_div_table *table)
{
	unsigned int maxdiv = 0;
	const struct clk_div_table *clkt;

	for (clkt = table; clkt->div; clkt++)
		if (clkt->div > maxdiv)
			maxdiv = clkt->div;
	return maxdiv;
}

static unsigned int hi3620_get_table_div(const struct clk_div_table *table,
							unsigned int val)
{
	const struct clk_div_table *clkt;

	for (clkt = table; clkt->div; clkt++)
		if (clkt->val == val)
			return clkt->div;
	return 0;
}

static unsigned int hi3620_get_table_val(const struct clk_div_table *table,
					 unsigned int div)
{
	const struct clk_div_table *clkt;

	for (clkt = table; clkt->div; clkt++)
		if (clkt->div == div)
			return clkt->val;
	return 0;
}

static unsigned long hi3620_clkdiv_recalc_rate(struct clk_hw *hw,
					       unsigned long parent_rate)
{
	struct hi3620_divclk *dclk = container_of(hw, struct hi3620_divclk, hw);
	unsigned int div, val;

	val = readl_relaxed(dclk->reg) >> dclk->shift;
	val &= WIDTH_TO_MASK(dclk->width);

	div = hi3620_get_table_div(dclk->table, val);
	if (!div) {
		pr_warning("%s: Invalid divisor for clock %s\n", __func__,
			   __clk_get_name(hw->clk));
		return parent_rate;
	}

	return parent_rate / div;
}

static bool hi3620_is_valid_table_div(const struct clk_div_table *table,
				      unsigned int div)
{
	const struct clk_div_table *clkt;

	for (clkt = table; clkt->div; clkt++)
		if (clkt->div == div)
			return true;
	return false;
}

static int hi3620_clkdiv_bestdiv(struct clk_hw *hw, unsigned long rate,
				 unsigned long *best_parent_rate)
{
	struct hi3620_divclk *dclk = container_of(hw, struct hi3620_divclk, hw);
	struct clk *clk_parent = __clk_get_parent(hw->clk);
	int i, bestdiv = 0;
	unsigned long parent_rate, best = 0, now, maxdiv;

	maxdiv = hi3620_get_table_maxdiv(dclk->table);

	if (!(__clk_get_flags(hw->clk) & CLK_SET_RATE_PARENT)) {
		parent_rate = *best_parent_rate;
		bestdiv = DIV_ROUND_UP(parent_rate, rate);
		bestdiv = bestdiv == 0 ? 1 : bestdiv;
		bestdiv = bestdiv > maxdiv ? maxdiv : bestdiv;
		return bestdiv;
	}

	/*
	 * The maximum divider we can use without overflowing
	 * unsigned long in rate * i below
	 */
	maxdiv = min(ULONG_MAX / rate, maxdiv);

	for (i = 1; i <= maxdiv; i++) {
		if (!hi3620_is_valid_table_div(dclk->table, i))
			continue;
		parent_rate = __clk_round_rate(clk_parent,
					       MULT_ROUND_UP(rate, i));
		now = parent_rate / i;
		if (now <= rate && now > best) {
			bestdiv = i;
			best = now;
			*best_parent_rate = parent_rate;
		}
	}

	if (!bestdiv) {
		bestdiv = hi3620_get_table_maxdiv(dclk->table);
		*best_parent_rate = __clk_round_rate(clk_parent, 1);
	}

	return bestdiv;
}

static long hi3620_clkdiv_round_rate(struct clk_hw *hw, unsigned long rate,
				     unsigned long *prate)
{
	int div;

	if (!rate)
		rate = 1;
	div = hi3620_clkdiv_bestdiv(hw, rate, prate);

	return *prate / div;
}

static int hi3620_clkdiv_set_rate(struct clk_hw *hw, unsigned long rate,
				  unsigned long parent_rate)
{
	struct hi3620_divclk *dclk = container_of(hw, struct hi3620_divclk, hw);
	unsigned int div, value;
	unsigned long flags = 0;
	u32 data;

	div = parent_rate / rate;
	value = hi3620_get_table_val(dclk->table, div);

	if (value > WIDTH_TO_MASK(dclk->width))
		value = WIDTH_TO_MASK(dclk->width);

	if (dclk->lock)
		spin_lock_irqsave(dclk->lock, flags);

	data = readl_relaxed(dclk->reg);
	data &= ~(WIDTH_TO_MASK(dclk->width) << dclk->shift);
	data |= value << dclk->shift;
	data |= dclk->mbits;
	writel_relaxed(data, dclk->reg);

	if (dclk->lock)
		spin_unlock_irqrestore(dclk->lock, flags);

	return 0;
}

static struct clk_ops hi3620_clkdiv_ops = {
	.recalc_rate = hi3620_clkdiv_recalc_rate,
	.round_rate = hi3620_clkdiv_round_rate,
	.set_rate = hi3620_clkdiv_set_rate,
};

void __init hi3620_clkdiv_setup(struct device_node *np)
{
	struct clk *clk;
	const char *clk_name, **parent_names;
	struct clk_init_data *init;
	struct clk_div_table *table;
	struct hi3620_divclk *dclk;
	void __iomem *reg_base;
	unsigned int table_num;
	int i;
	u32 data[2];
    unsigned int max_div, min_div;
	struct of_phandle_args div_table;

	reg_base = hs_init_clocks(np);
	if (!reg_base)
		return;

	if (of_property_read_string(np, "clock-output-names", &clk_name))
		return;

    /*process the div_table*/
    if (of_property_read_u32_array(np, "hisilicon,clkdiv-table",
				       &data[0], 2))
		return;

    max_div = (u8)data[0];
    min_div = (u8)data[1];

	if (of_property_read_u32_array(np, "hisilicon,clkdiv",
                       &data[0], 2))
        return;

	/*table ends with <0, 0>, so plus one to table_num*/
	table_num = max_div - min_div + 1;

	table = kzalloc(sizeof(struct clk_div_table) * table_num, GFP_KERNEL);
	if (!table)
		return ;

	for (i = 0; i < table_num; i++) {
		table[i].div = min_div + i;
		table[i].val = table[i].div - 1;
	}

	/* gate only has the fixed parent */
	parent_names = kzalloc(sizeof(char *), GFP_KERNEL);
	if (!parent_names)
		goto err_par;
	parent_names[0] = of_clk_get_parent_name(np, 0);

	dclk = kzalloc(sizeof(*dclk), GFP_KERNEL);
	if (!dclk)
		goto err_dclk;
	init = kzalloc(sizeof(*init), GFP_KERNEL);
	if (!init)
		goto err_init;
	init->name = kstrdup(clk_name, GFP_KERNEL);
	init->ops = &hi3620_clkdiv_ops;
	init->parent_names = parent_names;
	init->num_parents = 1;

	dclk->reg = reg_base + data[0];
	dclk->shift = ffs(data[1]) - 1;
	dclk->width = fls(data[1]) - ffs(data[1]) + 1;
	dclk->mbits = data[1] << 16;
	dclk->lock = &hs_clk.lock;
	dclk->hw.init = init;
	dclk->table = table;
	clk = clk_register(NULL, &dclk->hw);
	if (IS_ERR(clk))
		goto err_clk;
	of_clk_add_provider(np, of_clk_src_simple_get, clk);
	clk_register_clkdev(clk, clk_name, NULL);
	return;
err_clk:
	kfree(init);
err_init:
	kfree(dclk);
err_dclk:
	kfree(parent_names);
err_par:
	kfree(table);
}

CLK_OF_DECLARE(hi3620_mux, "hisilicon,hi3620-clk-mux", hi3620_clkmux_setup)
CLK_OF_DECLARE(hi3620_gate, "hisilicon,hi3620-clk-gate", hi3620_clkgate_setup)
CLK_OF_DECLARE(hi3620_div, "hisilicon,hi3620-clk-div", hi3620_clkdiv_setup)
CLK_OF_DECLARE(hs_gate, "hisilicon,clk-gate", hs_clkgate_setup)
CLK_OF_DECLARE(hs_fixed, "hisilicon,clk-fixed-factor", hs_fixed_factor_setup)

static const struct of_device_id hs_of_match[] = {
	{ .compatible = "hisilicon,pmctrl",	.data = (void *)HS_PMCTRL, },
	{ .compatible = "hisilicon,sysctrl",	.data = (void *)HS_SYSCTRL, },
	{ .compatible = "hisilicon,hi3620-fb",	.data = (void *)HS_EDC, },
};

static void __iomem __init *hs_init_clocks(struct device_node *np)
{
	struct device_node *parent;
	const struct of_device_id *match;
	void __iomem *ret = NULL;

	parent = of_get_parent(np);
	if (!parent)
		goto out;
	match = of_match_node(hs_of_match, parent);
	if (!match)
		goto out;
	switch ((unsigned int)match->data) {
	case HS_PMCTRL:
		if (!hs_clk.pmctrl) {
			ret = of_iomap(parent, 0);
			WARN_ON(!ret);
			hs_clk.pmctrl = ret;
		} else {
			ret = hs_clk.pmctrl;
		}
		break;
	case HS_SYSCTRL:
		if (!hs_clk.sctrl) {
			ret = of_iomap(parent, 0);
			WARN_ON(!ret);
			hs_clk.sctrl = ret;
		} else {
			ret = hs_clk.sctrl;
		}
		break;
	case HS_EDC:
		if (!hs_clk.edc) {
			ret = of_iomap(parent, 0);
			WARN_ON(!ret);
			hs_clk.edc = ret;
		} else {
			ret = hs_clk.edc;
		}
		break;
	}
out:
	return ret;
}