clkctrl.c 17.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * OMAP clkctrl clock support
 *
 * Copyright (C) 2017 Texas Instruments, Inc.
 *
 * Tero Kristo <t-kristo@ti.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
 * kind, whether express or implied; without even the implied warranty
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include <linux/clk-provider.h>
#include <linux/slab.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/clk/ti.h>
#include <linux/delay.h>
24
#include <linux/timekeeping.h>
25 26
#include "clock.h"

27
#define NO_IDLEST			0
28 29 30 31 32 33 34 35 36

#define OMAP4_MODULEMODE_MASK		0x3

#define MODULEMODE_HWCTRL		0x1
#define MODULEMODE_SWCTRL		0x2

#define OMAP4_IDLEST_MASK		(0x3 << 16)
#define OMAP4_IDLEST_SHIFT		16

37 38 39
#define OMAP4_STBYST_MASK		BIT(18)
#define OMAP4_STBYST_SHIFT		18

40 41 42 43 44 45 46 47 48 49 50 51 52
#define CLKCTRL_IDLEST_FUNCTIONAL	0x0
#define CLKCTRL_IDLEST_INTERFACE_IDLE	0x2
#define CLKCTRL_IDLEST_DISABLED		0x3

/* These timeouts are in us */
#define OMAP4_MAX_MODULE_READY_TIME	2000
#define OMAP4_MAX_MODULE_DISABLE_TIME	5000

static bool _early_timeout = true;

struct omap_clkctrl_provider {
	void __iomem *base;
	struct list_head clocks;
53
	char *clkdm_name;
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
};

struct omap_clkctrl_clk {
	struct clk_hw *clk;
	u16 reg_offset;
	int bit_offset;
	struct list_head node;
};

union omap4_timeout {
	u32 cycles;
	ktime_t start;
};

static const struct omap_clkctrl_data default_clkctrl_data[] __initconst = {
	{ 0 },
};

static u32 _omap4_idlest(u32 val)
{
	val &= OMAP4_IDLEST_MASK;
	val >>= OMAP4_IDLEST_SHIFT;

	return val;
}

static bool _omap4_is_idle(u32 val)
{
	val = _omap4_idlest(val);

	return val == CLKCTRL_IDLEST_DISABLED;
}

static bool _omap4_is_ready(u32 val)
{
	val = _omap4_idlest(val);

	return val == CLKCTRL_IDLEST_FUNCTIONAL ||
	       val == CLKCTRL_IDLEST_INTERFACE_IDLE;
}

static bool _omap4_is_timeout(union omap4_timeout *time, u32 timeout)
{
97 98 99 100 101 102 103 104 105
	/*
	 * There are two special cases where ktime_to_ns() can't be
	 * used to track the timeouts. First one is during early boot
	 * when the timers haven't been initialized yet. The second
	 * one is during suspend-resume cycle while timekeeping is
	 * being suspended / resumed. Clocksource for the system
	 * can be from a timer that requires pm_runtime access, which
	 * will eventually bring us here with timekeeping_suspended,
	 * during both suspend entry and resume paths. This happens
106 107
	 * at least on am43xx platform. Account for flakeyness
	 * with udelay() by multiplying the timeout value by 2.
108 109
	 */
	if (unlikely(_early_timeout || timekeeping_suspended)) {
110
		if (time->cycles++ < timeout) {
111
			udelay(1 * 2);
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
			return false;
		}
	} else {
		if (!ktime_to_ns(time->start)) {
			time->start = ktime_get();
			return false;
		}

		if (ktime_us_delta(ktime_get(), time->start) < timeout) {
			cpu_relax();
			return false;
		}
	}

	return true;
}

static int __init _omap4_disable_early_timeout(void)
{
	_early_timeout = false;

	return 0;
}
arch_initcall(_omap4_disable_early_timeout);

static int _omap4_clkctrl_clk_enable(struct clk_hw *hw)
{
	struct clk_hw_omap *clk = to_clk_hw_omap(hw);
	u32 val;
	int ret;
	union omap4_timeout timeout = { 0 };

	if (clk->clkdm) {
		ret = ti_clk_ll_ops->clkdm_clk_enable(clk->clkdm, hw->clk);
		if (ret) {
			WARN(1,
			     "%s: could not enable %s's clockdomain %s: %d\n",
			     __func__, clk_hw_get_name(hw),
			     clk->clkdm_name, ret);
			return ret;
		}
	}

155 156 157
	if (!clk->enable_bit)
		return 0;

158 159 160 161 162 163 164
	val = ti_clk_ll_ops->clk_readl(&clk->enable_reg);

	val &= ~OMAP4_MODULEMODE_MASK;
	val |= clk->enable_bit;

	ti_clk_ll_ops->clk_writel(val, &clk->enable_reg);

165
	if (test_bit(NO_IDLEST, &clk->flags))
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
		return 0;

	/* Wait until module is enabled */
	while (!_omap4_is_ready(ti_clk_ll_ops->clk_readl(&clk->enable_reg))) {
		if (_omap4_is_timeout(&timeout, OMAP4_MAX_MODULE_READY_TIME)) {
			pr_err("%s: failed to enable\n", clk_hw_get_name(hw));
			return -EBUSY;
		}
	}

	return 0;
}

static void _omap4_clkctrl_clk_disable(struct clk_hw *hw)
{
	struct clk_hw_omap *clk = to_clk_hw_omap(hw);
	u32 val;
	union omap4_timeout timeout = { 0 };

	if (!clk->enable_bit)
186
		goto exit;
187 188 189 190 191 192 193

	val = ti_clk_ll_ops->clk_readl(&clk->enable_reg);

	val &= ~OMAP4_MODULEMODE_MASK;

	ti_clk_ll_ops->clk_writel(val, &clk->enable_reg);

194
	if (test_bit(NO_IDLEST, &clk->flags))
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
		goto exit;

	/* Wait until module is disabled */
	while (!_omap4_is_idle(ti_clk_ll_ops->clk_readl(&clk->enable_reg))) {
		if (_omap4_is_timeout(&timeout,
				      OMAP4_MAX_MODULE_DISABLE_TIME)) {
			pr_err("%s: failed to disable\n", clk_hw_get_name(hw));
			break;
		}
	}

exit:
	if (clk->clkdm)
		ti_clk_ll_ops->clkdm_clk_disable(clk->clkdm, hw->clk);
}

static int _omap4_clkctrl_clk_is_enabled(struct clk_hw *hw)
{
	struct clk_hw_omap *clk = to_clk_hw_omap(hw);
	u32 val;

	val = ti_clk_ll_ops->clk_readl(&clk->enable_reg);

	if (val & clk->enable_bit)
		return 1;

	return 0;
}

static const struct clk_ops omap4_clkctrl_clk_ops = {
	.enable		= _omap4_clkctrl_clk_enable,
	.disable	= _omap4_clkctrl_clk_disable,
	.is_enabled	= _omap4_clkctrl_clk_is_enabled,
228
	.init		= omap2_init_clk_clkdm,
229 230 231 232 233 234 235
};

static struct clk_hw *_ti_omap4_clkctrl_xlate(struct of_phandle_args *clkspec,
					      void *data)
{
	struct omap_clkctrl_provider *provider = data;
	struct omap_clkctrl_clk *entry;
236
	bool found = false;
237 238 239 240 241 242 243 244 245

	if (clkspec->args_count != 2)
		return ERR_PTR(-EINVAL);

	pr_debug("%s: looking for %x:%x\n", __func__,
		 clkspec->args[0], clkspec->args[1]);

	list_for_each_entry(entry, &provider->clocks, node) {
		if (entry->reg_offset == clkspec->args[0] &&
246 247
		    entry->bit_offset == clkspec->args[1]) {
			found = true;
248
			break;
249
		}
250 251
	}

252
	if (!found)
253 254 255 256 257
		return ERR_PTR(-EINVAL);

	return entry->clk;
}

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
/* Get clkctrl clock base name based on clkctrl_name or dts node */
static const char * __init clkctrl_get_clock_name(struct device_node *np,
						  const char *clkctrl_name,
						  int offset, int index,
						  bool legacy_naming)
{
	char *clock_name;

	/* l4per-clkctrl:1234:0 style naming based on clkctrl_name */
	if (clkctrl_name && !legacy_naming) {
		clock_name = kasprintf(GFP_KERNEL, "%s-clkctrl:%04x:%d",
				       clkctrl_name, offset, index);
		strreplace(clock_name, '_', '-');

		return clock_name;
	}

	/* l4per:1234:0 old style naming based on clkctrl_name */
	if (clkctrl_name)
		return kasprintf(GFP_KERNEL, "%s_cm:clk:%04x:%d",
				 clkctrl_name, offset, index);

	/* l4per_cm:1234:0 old style naming based on parent node name */
	if (legacy_naming)
		return kasprintf(GFP_KERNEL, "%pOFn:clk:%04x:%d",
				 np->parent, offset, index);

	/* l4per-clkctrl:1234:0 style naming based on node name */
	return kasprintf(GFP_KERNEL, "%pOFn:%04x:%d", np, offset, index);
}

289 290 291 292
static int __init
_ti_clkctrl_clk_register(struct omap_clkctrl_provider *provider,
			 struct device_node *node, struct clk_hw *clk_hw,
			 u16 offset, u8 bit, const char * const *parents,
293 294
			 int num_parents, const struct clk_ops *ops,
			 const char *clkctrl_name)
295 296 297 298 299 300
{
	struct clk_init_data init = { NULL };
	struct clk *clk;
	struct omap_clkctrl_clk *clkctrl_clk;
	int ret = 0;

301 302 303 304
	init.name = clkctrl_get_clock_name(node, clkctrl_name, offset, bit,
					   ti_clk_get_features()->flags &
					   TI_CLK_CLKCTRL_COMPAT);

305 306 307 308 309 310 311 312 313 314
	clkctrl_clk = kzalloc(sizeof(*clkctrl_clk), GFP_KERNEL);
	if (!init.name || !clkctrl_clk) {
		ret = -ENOMEM;
		goto cleanup;
	}

	clk_hw->init = &init;
	init.parent_names = parents;
	init.num_parents = num_parents;
	init.ops = ops;
315
	init.flags = 0;
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

	clk = ti_clk_register(NULL, clk_hw, init.name);
	if (IS_ERR_OR_NULL(clk)) {
		ret = -EINVAL;
		goto cleanup;
	}

	clkctrl_clk->reg_offset = offset;
	clkctrl_clk->bit_offset = bit;
	clkctrl_clk->clk = clk_hw;

	list_add(&clkctrl_clk->node, &provider->clocks);

	return 0;

cleanup:
	kfree(init.name);
	kfree(clkctrl_clk);
	return ret;
}

static void __init
_ti_clkctrl_setup_gate(struct omap_clkctrl_provider *provider,
		       struct device_node *node, u16 offset,
		       const struct omap_clkctrl_bit_data *data,
341
		       void __iomem *reg, const char *clkctrl_name)
342 343 344 345 346 347 348 349 350 351 352 353
{
	struct clk_hw_omap *clk_hw;

	clk_hw = kzalloc(sizeof(*clk_hw), GFP_KERNEL);
	if (!clk_hw)
		return;

	clk_hw->enable_bit = data->bit;
	clk_hw->enable_reg.ptr = reg;

	if (_ti_clkctrl_clk_register(provider, node, &clk_hw->hw, offset,
				     data->bit, data->parents, 1,
354
				     &omap_gate_clk_ops, clkctrl_name))
355 356 357 358 359 360 361
		kfree(clk_hw);
}

static void __init
_ti_clkctrl_setup_mux(struct omap_clkctrl_provider *provider,
		      struct device_node *node, u16 offset,
		      const struct omap_clkctrl_bit_data *data,
362
		      void __iomem *reg, const char *clkctrl_name)
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
{
	struct clk_omap_mux *mux;
	int num_parents = 0;
	const char * const *pname;

	mux = kzalloc(sizeof(*mux), GFP_KERNEL);
	if (!mux)
		return;

	pname = data->parents;
	while (*pname) {
		num_parents++;
		pname++;
	}

	mux->mask = num_parents;
379 380 381
	if (!(mux->flags & CLK_MUX_INDEX_ONE))
		mux->mask--;

382 383 384 385 386 387 388
	mux->mask = (1 << fls(mux->mask)) - 1;

	mux->shift = data->bit;
	mux->reg.ptr = reg;

	if (_ti_clkctrl_clk_register(provider, node, &mux->hw, offset,
				     data->bit, data->parents, num_parents,
389
				     &ti_clk_mux_ops, clkctrl_name))
390 391 392 393 394 395 396
		kfree(mux);
}

static void __init
_ti_clkctrl_setup_div(struct omap_clkctrl_provider *provider,
		      struct device_node *node, u16 offset,
		      const struct omap_clkctrl_bit_data *data,
397
		      void __iomem *reg, const char *clkctrl_name)
398 399 400
{
	struct clk_omap_divider *div;
	const struct omap_clkctrl_div_data *div_data = data->data;
401
	u8 div_flags = 0;
402 403 404 405 406 407 408

	div = kzalloc(sizeof(*div), GFP_KERNEL);
	if (!div)
		return;

	div->reg.ptr = reg;
	div->shift = data->bit;
409 410 411 412
	div->flags = div_data->flags;

	if (div->flags & CLK_DIVIDER_POWER_OF_TWO)
		div_flags |= CLKF_INDEX_POWER_OF_TWO;
413

414 415
	if (ti_clk_parse_divider_data((int *)div_data->dividers, 0,
				      div_data->max_div, div_flags,
416
				      div)) {
417 418
		pr_err("%s: Data parsing for %pOF:%04x:%d failed\n", __func__,
		       node, offset, data->bit);
419 420 421 422 423 424
		kfree(div);
		return;
	}

	if (_ti_clkctrl_clk_register(provider, node, &div->hw, offset,
				     data->bit, data->parents, 1,
425
				     &ti_clk_divider_ops, clkctrl_name))
426 427 428 429 430 431 432
		kfree(div);
}

static void __init
_ti_clkctrl_setup_subclks(struct omap_clkctrl_provider *provider,
			  struct device_node *node,
			  const struct omap_clkctrl_reg_data *data,
433
			  void __iomem *reg, const char *clkctrl_name)
434 435 436 437 438 439 440 441 442 443
{
	const struct omap_clkctrl_bit_data *bits = data->bit_data;

	if (!bits)
		return;

	while (bits->bit) {
		switch (bits->type) {
		case TI_CLK_GATE:
			_ti_clkctrl_setup_gate(provider, node, data->offset,
444
					       bits, reg, clkctrl_name);
445 446 447 448
			break;

		case TI_CLK_DIVIDER:
			_ti_clkctrl_setup_div(provider, node, data->offset,
449
					      bits, reg, clkctrl_name);
450 451 452 453
			break;

		case TI_CLK_MUX:
			_ti_clkctrl_setup_mux(provider, node, data->offset,
454
					      bits, reg, clkctrl_name);
455 456 457 458 459 460 461 462 463 464 465
			break;

		default:
			pr_err("%s: bad subclk type: %d\n", __func__,
			       bits->type);
			return;
		}
		bits++;
	}
}

466 467 468 469 470 471
static void __init _clkctrl_add_provider(void *data,
					 struct device_node *np)
{
	of_clk_add_hw_provider(np, _ti_omap4_clkctrl_xlate, data);
}

472 473 474 475 476
/*
 * Get clock name based on "clock-output-names" property or the
 * compatible property for clkctrl.
 */
static const char * __init clkctrl_get_name(struct device_node *np)
477 478 479 480
{
	struct property *prop;
	const int prefix_len = 11;
	const char *compat;
481
	const char *output;
482 483
	char *name;

484 485 486 487 488 489 490 491 492 493 494 495 496 497
	if (!of_property_read_string_index(np, "clock-output-names", 0,
					   &output)) {
		const char *end;
		int len;

		len = strlen(output);
		end = strstr(output, "_clkctrl");
		if (end)
			len -= strlen(end);
		name = kstrndup(output, len, GFP_KERNEL);

		return name;
	}

498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514
	of_property_for_each_string(np, "compatible", prop, compat) {
		if (!strncmp("ti,clkctrl-", compat, prefix_len)) {
			/* Two letter minimum name length for l3, l4 etc */
			if (strnlen(compat + prefix_len, 16) < 2)
				continue;
			name = kasprintf(GFP_KERNEL, "%s", compat + prefix_len);
			if (!name)
				continue;
			strreplace(name, '-', '_');

			return name;
		}
	}

	return NULL;
}

515 516 517 518 519 520 521 522
static void __init _ti_omap4_clkctrl_setup(struct device_node *node)
{
	struct omap_clkctrl_provider *provider;
	const struct omap_clkctrl_data *data = default_clkctrl_data;
	const struct omap_clkctrl_reg_data *reg_data;
	struct clk_init_data init = { NULL };
	struct clk_hw_omap *hw;
	struct clk *clk;
523
	struct omap_clkctrl_clk *clkctrl_clk = NULL;
524
	const __be32 *addrp;
525
	bool legacy_naming;
526
	const char *clkctrl_name;
527
	u32 addr;
528
	int ret;
529
	char *c;
530
	u16 soc_mask = 0;
531

532
	if (!(ti_clk_get_features()->flags & TI_CLK_CLKCTRL_COMPAT) &&
533
	    of_node_name_eq(node, "clk"))
534
		ti_clk_features.flags |= TI_CLK_CLKCTRL_COMPAT;
535 536 537 538

	addrp = of_get_address(node, 0, NULL, NULL);
	addr = (u32)of_translate_address(node, addrp);

539 540 541 542
#ifdef CONFIG_ARCH_OMAP4
	if (of_machine_is_compatible("ti,omap4"))
		data = omap4_clkctrl_data;
#endif
543 544 545 546
#ifdef CONFIG_SOC_OMAP5
	if (of_machine_is_compatible("ti,omap5"))
		data = omap5_clkctrl_data;
#endif
547
#ifdef CONFIG_SOC_DRA7XX
548 549 550 551 552 553
	if (of_machine_is_compatible("ti,dra7")) {
		if (ti_clk_get_features()->flags & TI_CLK_CLKCTRL_COMPAT)
			data = dra7_clkctrl_compat_data;
		else
			data = dra7_clkctrl_data;
	}
554 555 556 557 558 559 560

	if (of_machine_is_compatible("ti,dra72"))
		soc_mask = CLKF_SOC_DRA72;
	if (of_machine_is_compatible("ti,dra74"))
		soc_mask = CLKF_SOC_DRA74;
	if (of_machine_is_compatible("ti,dra76"))
		soc_mask = CLKF_SOC_DRA76;
561
#endif
562
#ifdef CONFIG_SOC_AM33XX
563 564
	if (of_machine_is_compatible("ti,am33xx"))
		data = am3_clkctrl_data;
565
#endif
566
#ifdef CONFIG_SOC_AM43XX
567 568
	if (of_machine_is_compatible("ti,am4372"))
		data = am4_clkctrl_data;
569

570 571
	if (of_machine_is_compatible("ti,am438x"))
		data = am438x_clkctrl_data;
572
#endif
573 574 575
#ifdef CONFIG_SOC_TI81XX
	if (of_machine_is_compatible("ti,dm814"))
		data = dm814_clkctrl_data;
576 577 578

	if (of_machine_is_compatible("ti,dm816"))
		data = dm816_clkctrl_data;
579
#endif
580

581 582 583
	if (ti_clk_get_features()->flags & TI_CLK_DEVICE_TYPE_GP)
		soc_mask |= CLKF_SOC_NONSEC;

584 585 586 587 588 589 590 591
	while (data->addr) {
		if (addr == data->addr)
			break;

		data++;
	}

	if (!data->addr) {
592
		pr_err("%pOF not found from clkctrl data.\n", node);
593 594 595 596 597 598 599 600 601
		return;
	}

	provider = kzalloc(sizeof(*provider), GFP_KERNEL);
	if (!provider)
		return;

	provider->base = of_iomap(node, 0);

602 603 604 605 606 607 608 609 610 611 612 613 614
	legacy_naming = ti_clk_get_features()->flags & TI_CLK_CLKCTRL_COMPAT;
	clkctrl_name = clkctrl_get_name(node);
	if (clkctrl_name) {
		provider->clkdm_name = kasprintf(GFP_KERNEL,
						 "%s_clkdm", clkctrl_name);
		goto clkdm_found;
	}

	/*
	 * The code below can be removed when all clkctrl nodes use domain
	 * specific compatible proprerty and standard clock node naming
	 */
	if (legacy_naming) {
615
		provider->clkdm_name = kasprintf(GFP_KERNEL, "%pOFnxxx", node->parent);
616 617 618 619 620 621 622 623 624
		if (!provider->clkdm_name) {
			kfree(provider);
			return;
		}

		/*
		 * Create default clkdm name, replace _cm from end of parent
		 * node name with _clkdm
		 */
625
		provider->clkdm_name[strlen(provider->clkdm_name) - 2] = 0;
626
	} else {
627
		provider->clkdm_name = kasprintf(GFP_KERNEL, "%pOFn", node);
628 629 630 631 632 633 634 635 636 637
		if (!provider->clkdm_name) {
			kfree(provider);
			return;
		}

		/*
		 * Create default clkdm name, replace _clkctrl from end of
		 * node name with _clkdm
		 */
		provider->clkdm_name[strlen(provider->clkdm_name) - 7] = 0;
638 639 640 641
	}

	strcat(provider->clkdm_name, "clkdm");

642 643 644 645 646 647 648 649
	/* Replace any dash from the clkdm name with underscore */
	c = provider->clkdm_name;

	while (*c) {
		if (*c == '-')
			*c = '_';
		c++;
	}
650
clkdm_found:
651 652 653 654 655 656
	INIT_LIST_HEAD(&provider->clocks);

	/* Generate clocks */
	reg_data = data->regs;

	while (reg_data->parent) {
657 658 659 660 661 662
		if ((reg_data->flags & CLKF_SOC_MASK) &&
		    (reg_data->flags & soc_mask) == 0) {
			reg_data++;
			continue;
		}

663 664 665 666 667 668 669
		hw = kzalloc(sizeof(*hw), GFP_KERNEL);
		if (!hw)
			return;

		hw->enable_reg.ptr = provider->base + reg_data->offset;

		_ti_clkctrl_setup_subclks(provider, node, reg_data,
670
					  hw->enable_reg.ptr, clkctrl_name);
671 672 673 674 675 676

		if (reg_data->flags & CLKF_SW_SUP)
			hw->enable_bit = MODULEMODE_SWCTRL;
		if (reg_data->flags & CLKF_HW_SUP)
			hw->enable_bit = MODULEMODE_HWCTRL;
		if (reg_data->flags & CLKF_NO_IDLEST)
677
			set_bit(NO_IDLEST, &hw->flags);
678

679 680 681 682 683
		if (reg_data->clkdm_name)
			hw->clkdm_name = reg_data->clkdm_name;
		else
			hw->clkdm_name = provider->clkdm_name;

684 685 686
		init.parent_names = &reg_data->parent;
		init.num_parents = 1;
		init.flags = 0;
687 688
		if (reg_data->flags & CLKF_SET_RATE_PARENT)
			init.flags |= CLK_SET_RATE_PARENT;
689 690 691 692 693 694 695

		init.name = clkctrl_get_clock_name(node, clkctrl_name,
						   reg_data->offset, 0,
						   legacy_naming);
		if (!init.name)
			goto cleanup;

696
		clkctrl_clk = kzalloc(sizeof(*clkctrl_clk), GFP_KERNEL);
697
		if (!clkctrl_clk)
698 699 700 701 702
			goto cleanup;

		init.ops = &omap4_clkctrl_clk_ops;
		hw->hw.init = &init;

703
		clk = ti_clk_register_omap_hw(NULL, &hw->hw, init.name);
704 705 706 707 708 709 710 711 712 713 714
		if (IS_ERR_OR_NULL(clk))
			goto cleanup;

		clkctrl_clk->reg_offset = reg_data->offset;
		clkctrl_clk->clk = &hw->hw;

		list_add(&clkctrl_clk->node, &provider->clocks);

		reg_data++;
	}

715 716 717 718
	ret = of_clk_add_hw_provider(node, _ti_omap4_clkctrl_xlate, provider);
	if (ret == -EPROBE_DEFER)
		ti_clk_retry_init(node, provider, _clkctrl_add_provider);

719 720
	kfree(clkctrl_name);

721 722 723 724 725
	return;

cleanup:
	kfree(hw);
	kfree(init.name);
726
	kfree(clkctrl_name);
727 728 729 730
	kfree(clkctrl_clk);
}
CLK_OF_DECLARE(ti_omap4_clkctrl_clock, "ti,clkctrl",
	       _ti_omap4_clkctrl_setup);
731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760

/**
 * ti_clk_is_in_standby - Check if clkctrl clock is in standby or not
 * @clk: clock to check standby status for
 *
 * Finds whether the provided clock is in standby mode or not. Returns
 * true if the provided clock is a clkctrl type clock and it is in standby,
 * false otherwise.
 */
bool ti_clk_is_in_standby(struct clk *clk)
{
	struct clk_hw *hw;
	struct clk_hw_omap *hwclk;
	u32 val;

	hw = __clk_get_hw(clk);

	if (!omap2_clk_is_hw_omap(hw))
		return false;

	hwclk = to_clk_hw_omap(hw);

	val = ti_clk_ll_ops->clk_readl(&hwclk->enable_reg);

	if (val & OMAP4_STBYST_MASK)
		return true;

	return false;
}
EXPORT_SYMBOL_GPL(ti_clk_is_in_standby);