blob: ec55d1de1b55ec061490838658a8b87d603a86d0 [file] [log] [blame]
Peter De Schrijver26fe6812012-02-10 01:47:44 +02001/*
2 * arch/arm/mach-tegra/flowctrl.c
3 *
4 * functions and macros to control the flowcontroller
5 *
6 * Copyright (c) 2010-2012, NVIDIA Corporation. All rights reserved.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms and conditions of the GNU General Public License,
10 * version 2, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
Joseph Lo01459c62012-10-31 17:41:20 +080021#include <linux/cpumask.h>
Thierry Redinga0524ac2014-07-11 09:44:49 +020022#include <linux/init.h>
23#include <linux/io.h>
24#include <linux/kernel.h>
Peter De Schrijver26fe6812012-02-10 01:47:44 +020025
Thierry Reding304664e2014-07-11 09:52:41 +020026#include <soc/tegra/fuse.h>
27
Peter De Schrijver26fe6812012-02-10 01:47:44 +020028#include "flowctrl.h"
Stephen Warren2be39c02012-10-04 14:24:09 -060029#include "iomap.h"
Peter De Schrijver26fe6812012-02-10 01:47:44 +020030
Hiroshi Doyudeeb8d12013-01-03 08:27:05 +020031static u8 flowctrl_offset_halt_cpu[] = {
Peter De Schrijver26fe6812012-02-10 01:47:44 +020032 FLOW_CTRL_HALT_CPU0_EVENTS,
33 FLOW_CTRL_HALT_CPU1_EVENTS,
34 FLOW_CTRL_HALT_CPU1_EVENTS + 8,
35 FLOW_CTRL_HALT_CPU1_EVENTS + 16,
36};
37
Hiroshi Doyudeeb8d12013-01-03 08:27:05 +020038static u8 flowctrl_offset_cpu_csr[] = {
Peter De Schrijver26fe6812012-02-10 01:47:44 +020039 FLOW_CTRL_CPU0_CSR,
40 FLOW_CTRL_CPU1_CSR,
41 FLOW_CTRL_CPU1_CSR + 8,
42 FLOW_CTRL_CPU1_CSR + 16,
43};
44
45static void flowctrl_update(u8 offset, u32 value)
46{
47 void __iomem *addr = IO_ADDRESS(TEGRA_FLOW_CTRL_BASE) + offset;
48
49 writel(value, addr);
50
51 /* ensure the update has reached the flow controller */
52 wmb();
53 readl_relaxed(addr);
54}
55
Joseph Lo01459c62012-10-31 17:41:20 +080056u32 flowctrl_read_cpu_csr(unsigned int cpuid)
57{
58 u8 offset = flowctrl_offset_cpu_csr[cpuid];
59 void __iomem *addr = IO_ADDRESS(TEGRA_FLOW_CTRL_BASE) + offset;
60
61 return readl(addr);
62}
63
Peter De Schrijver26fe6812012-02-10 01:47:44 +020064void flowctrl_write_cpu_csr(unsigned int cpuid, u32 value)
65{
Peter De Schrijver97e7abc2012-05-14 13:27:09 +030066 return flowctrl_update(flowctrl_offset_cpu_csr[cpuid], value);
Peter De Schrijver26fe6812012-02-10 01:47:44 +020067}
68
69void flowctrl_write_cpu_halt(unsigned int cpuid, u32 value)
70{
Peter De Schrijver97e7abc2012-05-14 13:27:09 +030071 return flowctrl_update(flowctrl_offset_halt_cpu[cpuid], value);
Peter De Schrijver26fe6812012-02-10 01:47:44 +020072}
Joseph Lo01459c62012-10-31 17:41:20 +080073
74void flowctrl_cpu_suspend_enter(unsigned int cpuid)
75{
76 unsigned int reg;
77 int i;
78
79 reg = flowctrl_read_cpu_csr(cpuid);
Thierry Reding304664e2014-07-11 09:52:41 +020080 switch (tegra_get_chip_id()) {
Joseph Loafec5812013-01-15 22:11:01 +000081 case TEGRA20:
82 /* clear wfe bitmap */
83 reg &= ~TEGRA20_FLOW_CTRL_CSR_WFE_BITMAP;
84 /* clear wfi bitmap */
85 reg &= ~TEGRA20_FLOW_CTRL_CSR_WFI_BITMAP;
86 /* pwr gating on wfe */
87 reg |= TEGRA20_FLOW_CTRL_CSR_WFE_CPU0 << cpuid;
88 break;
89 case TEGRA30:
Joseph Lodd6fe9a2013-07-03 17:50:43 +080090 case TEGRA114:
Joseph Lof0c4ac12013-10-11 17:58:38 +080091 case TEGRA124:
Joseph Loafec5812013-01-15 22:11:01 +000092 /* clear wfe bitmap */
93 reg &= ~TEGRA30_FLOW_CTRL_CSR_WFE_BITMAP;
94 /* clear wfi bitmap */
95 reg &= ~TEGRA30_FLOW_CTRL_CSR_WFI_BITMAP;
96 /* pwr gating on wfi */
97 reg |= TEGRA30_FLOW_CTRL_CSR_WFI_CPU0 << cpuid;
98 break;
99 }
Joseph Lo01459c62012-10-31 17:41:20 +0800100 reg |= FLOW_CTRL_CSR_INTR_FLAG; /* clear intr flag */
101 reg |= FLOW_CTRL_CSR_EVENT_FLAG; /* clear event flag */
Joseph Lo01459c62012-10-31 17:41:20 +0800102 reg |= FLOW_CTRL_CSR_ENABLE; /* pwr gating */
103 flowctrl_write_cpu_csr(cpuid, reg);
104
105 for (i = 0; i < num_possible_cpus(); i++) {
106 if (i == cpuid)
107 continue;
108 reg = flowctrl_read_cpu_csr(i);
109 reg |= FLOW_CTRL_CSR_EVENT_FLAG;
110 reg |= FLOW_CTRL_CSR_INTR_FLAG;
111 flowctrl_write_cpu_csr(i, reg);
112 }
113}
114
115void flowctrl_cpu_suspend_exit(unsigned int cpuid)
116{
117 unsigned int reg;
118
119 /* Disable powergating via flow controller for CPU0 */
120 reg = flowctrl_read_cpu_csr(cpuid);
Thierry Reding304664e2014-07-11 09:52:41 +0200121 switch (tegra_get_chip_id()) {
Joseph Loafec5812013-01-15 22:11:01 +0000122 case TEGRA20:
123 /* clear wfe bitmap */
124 reg &= ~TEGRA20_FLOW_CTRL_CSR_WFE_BITMAP;
125 /* clear wfi bitmap */
126 reg &= ~TEGRA20_FLOW_CTRL_CSR_WFI_BITMAP;
127 break;
128 case TEGRA30:
Joseph Lodd6fe9a2013-07-03 17:50:43 +0800129 case TEGRA114:
Joseph Lof0c4ac12013-10-11 17:58:38 +0800130 case TEGRA124:
Joseph Loafec5812013-01-15 22:11:01 +0000131 /* clear wfe bitmap */
132 reg &= ~TEGRA30_FLOW_CTRL_CSR_WFE_BITMAP;
133 /* clear wfi bitmap */
134 reg &= ~TEGRA30_FLOW_CTRL_CSR_WFI_BITMAP;
135 break;
136 }
Joseph Lo01459c62012-10-31 17:41:20 +0800137 reg &= ~FLOW_CTRL_CSR_ENABLE; /* clear enable */
138 reg |= FLOW_CTRL_CSR_INTR_FLAG; /* clear intr */
139 reg |= FLOW_CTRL_CSR_EVENT_FLAG; /* clear event */
140 flowctrl_write_cpu_csr(cpuid, reg);
141}