blob: b43706aa08bd89bccbce5c715f127212cafa0964 [file] [log] [blame]
Rajendra Nayak68b921a2011-02-25 16:06:47 -07001/*
2 * OMAP4 clockdomain control
3 *
4 * Copyright (C) 2008-2010 Texas Instruments, Inc.
5 * Copyright (C) 2008-2010 Nokia Corporation
6 *
7 * Derived from mach-omap2/clockdomain.c written by Paul Walmsley
8 * Rajendra Nayak <rnayak@ti.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14
Rajendra Nayak15b08d92011-02-25 15:48:14 -070015#include <linux/kernel.h>
Rajendra Nayak68b921a2011-02-25 16:06:47 -070016#include "clockdomain.h"
17#include "cminst44xx.h"
Rajendra Nayak15b08d92011-02-25 15:48:14 -070018#include "cm44xx.h"
19
20static int omap4_clkdm_add_wkup_sleep_dep(struct clockdomain *clkdm1,
21 struct clockdomain *clkdm2)
22{
23 omap4_cminst_set_inst_reg_bits((1 << clkdm2->dep_bit),
24 clkdm1->prcm_partition,
25 clkdm1->cm_inst, clkdm1->clkdm_offs +
26 OMAP4_CM_STATICDEP);
27 return 0;
28}
29
30static int omap4_clkdm_del_wkup_sleep_dep(struct clockdomain *clkdm1,
31 struct clockdomain *clkdm2)
32{
33 omap4_cminst_clear_inst_reg_bits((1 << clkdm2->dep_bit),
34 clkdm1->prcm_partition,
35 clkdm1->cm_inst, clkdm1->clkdm_offs +
36 OMAP4_CM_STATICDEP);
37 return 0;
38}
39
40static int omap4_clkdm_read_wkup_sleep_dep(struct clockdomain *clkdm1,
41 struct clockdomain *clkdm2)
42{
43 return omap4_cminst_read_inst_reg_bits(clkdm1->prcm_partition,
44 clkdm1->cm_inst, clkdm1->clkdm_offs +
45 OMAP4_CM_STATICDEP,
46 (1 << clkdm2->dep_bit));
47}
48
49static int omap4_clkdm_clear_all_wkup_sleep_deps(struct clockdomain *clkdm)
50{
51 struct clkdm_dep *cd;
52 u32 mask = 0;
53
54 for (cd = clkdm->wkdep_srcs; cd && cd->clkdm_name; cd++) {
55 if (!omap_chip_is(cd->omap_chip))
56 continue;
57 if (!cd->clkdm)
58 continue; /* only happens if data is erroneous */
59
60 mask |= 1 << cd->clkdm->dep_bit;
61 atomic_set(&cd->wkdep_usecount, 0);
62 }
63
64 omap4_cminst_clear_inst_reg_bits(mask, clkdm->prcm_partition,
65 clkdm->cm_inst, clkdm->clkdm_offs +
66 OMAP4_CM_STATICDEP);
67 return 0;
68}
Rajendra Nayak68b921a2011-02-25 16:06:47 -070069
70static int omap4_clkdm_sleep(struct clockdomain *clkdm)
71{
72 omap4_cminst_clkdm_force_sleep(clkdm->prcm_partition,
73 clkdm->cm_inst, clkdm->clkdm_offs);
74 return 0;
75}
76
77static int omap4_clkdm_wakeup(struct clockdomain *clkdm)
78{
79 omap4_cminst_clkdm_force_wakeup(clkdm->prcm_partition,
80 clkdm->cm_inst, clkdm->clkdm_offs);
81 return 0;
82}
83
Rajendra Nayak5cd19372011-02-25 16:06:48 -070084static void omap4_clkdm_allow_idle(struct clockdomain *clkdm)
85{
86 omap4_cminst_clkdm_enable_hwsup(clkdm->prcm_partition,
87 clkdm->cm_inst, clkdm->clkdm_offs);
88}
89
90static void omap4_clkdm_deny_idle(struct clockdomain *clkdm)
91{
92 omap4_cminst_clkdm_disable_hwsup(clkdm->prcm_partition,
93 clkdm->cm_inst, clkdm->clkdm_offs);
94}
95
Rajendra Nayak4da71ae2011-02-25 16:06:48 -070096static int omap4_clkdm_clk_enable(struct clockdomain *clkdm)
97{
Rajendra Nayak555e74e2011-07-10 05:56:55 -060098 if (clkdm->flags & CLKDM_CAN_FORCE_WAKEUP)
99 return omap4_clkdm_wakeup(clkdm);
Rajendra Nayak4da71ae2011-02-25 16:06:48 -0700100
101 return 0;
102}
103
104static int omap4_clkdm_clk_disable(struct clockdomain *clkdm)
105{
106 bool hwsup = false;
107
108 hwsup = omap4_cminst_is_clkdm_in_hwsup(clkdm->prcm_partition,
109 clkdm->cm_inst, clkdm->clkdm_offs);
110
Rajendra Nayak555e74e2011-07-10 05:56:55 -0600111 if (!hwsup && (clkdm->flags & CLKDM_CAN_FORCE_SLEEP))
112 omap4_clkdm_sleep(clkdm);
Rajendra Nayak4da71ae2011-02-25 16:06:48 -0700113
114 return 0;
115}
116
Rajendra Nayak68b921a2011-02-25 16:06:47 -0700117struct clkdm_ops omap4_clkdm_operations = {
Rajendra Nayak15b08d92011-02-25 15:48:14 -0700118 .clkdm_add_wkdep = omap4_clkdm_add_wkup_sleep_dep,
119 .clkdm_del_wkdep = omap4_clkdm_del_wkup_sleep_dep,
120 .clkdm_read_wkdep = omap4_clkdm_read_wkup_sleep_dep,
121 .clkdm_clear_all_wkdeps = omap4_clkdm_clear_all_wkup_sleep_deps,
122 .clkdm_add_sleepdep = omap4_clkdm_add_wkup_sleep_dep,
123 .clkdm_del_sleepdep = omap4_clkdm_del_wkup_sleep_dep,
124 .clkdm_read_sleepdep = omap4_clkdm_read_wkup_sleep_dep,
125 .clkdm_clear_all_sleepdeps = omap4_clkdm_clear_all_wkup_sleep_deps,
Rajendra Nayak68b921a2011-02-25 16:06:47 -0700126 .clkdm_sleep = omap4_clkdm_sleep,
127 .clkdm_wakeup = omap4_clkdm_wakeup,
Rajendra Nayak5cd19372011-02-25 16:06:48 -0700128 .clkdm_allow_idle = omap4_clkdm_allow_idle,
129 .clkdm_deny_idle = omap4_clkdm_deny_idle,
Rajendra Nayak4da71ae2011-02-25 16:06:48 -0700130 .clkdm_clk_enable = omap4_clkdm_clk_enable,
131 .clkdm_clk_disable = omap4_clkdm_clk_disable,
Rajendra Nayak68b921a2011-02-25 16:06:47 -0700132};