summaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-omap2/cm4xxx.c
blob: e4ebd6d5313589d54bddc91858466ed4e0c097ee (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
/*
 * OMAP4 CM module functions
 *
 * Copyright (C) 2009 Nokia Corporation
 * Paul Walmsley
 *
 * 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.
 */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/delay.h>
#include <linux/spinlock.h>
#include <linux/list.h>
#include <linux/errno.h>
#include <linux/err.h>
#include <linux/io.h>

#include <asm/atomic.h>

#include "cm.h"
#include "cm-regbits-4xxx.h"

/* XXX move this to cm.h */
/* MAX_MODULE_READY_TIME: max milliseconds for module to leave idle */
#define MAX_MODULE_READY_TIME			20000

/*
 * OMAP4_PRCM_CM_CLKCTRL_IDLEST_MASK: isolates the IDLEST field in the
 * CM_CLKCTRL register.
 */
#define OMAP4_PRCM_CM_CLKCTRL_IDLEST_MASK	(0x2 << 16)

/*
 * OMAP4 prcm_mod u32 fields contain packed data: the CM ID in bit 16 and
 * the PRCM module offset address (from the CM module base) in bits 15-0.
 */
#define OMAP4_PRCM_MOD_CM_ID_SHIFT		16
#define OMAP4_PRCM_MOD_OFFS_MASK		0xffff

/**
 * omap4_cm_wait_idlest_ready - wait for a module to leave idle or standby
 * @prcm_mod: PRCM module offset (XXX example)
 * @prcm_dev_offs: PRCM device offset (e.g. MCASP XXX example)
 *
 * XXX document
 */
int omap4_cm_wait_idlest_ready(u32 prcm_mod, u8 prcm_dev_offs)
{
	int i = 0;
	u8 cm_id;
	u16 prcm_mod_offs;
	u32 mask = OMAP4_PRCM_CM_CLKCTRL_IDLEST_MASK;

	cm_id = prcm_mod >> OMAP4_PRCM_MOD_CM_ID_SHIFT;
	prcm_mod_offs = prcm_mod & OMAP4_PRCM_MOD_OFFS_MASK;

	while (((omap4_cm_read_mod_reg(cm_id, prcm_mod_offs, prcm_dev_offs,
				       OMAP4_CM_CLKCTRL_DREG) & mask) != 0) &&
	       (i++ < MAX_MODULE_READY_TIME))
		udelay(1);

	return (i < MAX_MODULE_READY_TIME) ? 0 : -EBUSY;
}

OpenPOWER on IntegriCloud