1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include <linux/init.h>
22#include <linux/kernel.h>
23#include <linux/io.h>
24#include <linux/cpumask.h>
25
26#include "flowctrl.h"
27#include "iomap.h"
28#include "fuse.h"
29
30static u8 flowctrl_offset_halt_cpu[] = {
31 FLOW_CTRL_HALT_CPU0_EVENTS,
32 FLOW_CTRL_HALT_CPU1_EVENTS,
33 FLOW_CTRL_HALT_CPU1_EVENTS + 8,
34 FLOW_CTRL_HALT_CPU1_EVENTS + 16,
35};
36
37static u8 flowctrl_offset_cpu_csr[] = {
38 FLOW_CTRL_CPU0_CSR,
39 FLOW_CTRL_CPU1_CSR,
40 FLOW_CTRL_CPU1_CSR + 8,
41 FLOW_CTRL_CPU1_CSR + 16,
42};
43
44static void flowctrl_update(u8 offset, u32 value)
45{
46 void __iomem *addr = IO_ADDRESS(TEGRA_FLOW_CTRL_BASE) + offset;
47
48 writel(value, addr);
49
50
51 wmb();
52 readl_relaxed(addr);
53}
54
55u32 flowctrl_read_cpu_csr(unsigned int cpuid)
56{
57 u8 offset = flowctrl_offset_cpu_csr[cpuid];
58 void __iomem *addr = IO_ADDRESS(TEGRA_FLOW_CTRL_BASE) + offset;
59
60 return readl(addr);
61}
62
63void flowctrl_write_cpu_csr(unsigned int cpuid, u32 value)
64{
65 return flowctrl_update(flowctrl_offset_cpu_csr[cpuid], value);
66}
67
68void flowctrl_write_cpu_halt(unsigned int cpuid, u32 value)
69{
70 return flowctrl_update(flowctrl_offset_halt_cpu[cpuid], value);
71}
72
73void flowctrl_cpu_suspend_enter(unsigned int cpuid)
74{
75 unsigned int reg;
76 int i;
77
78 reg = flowctrl_read_cpu_csr(cpuid);
79 switch (tegra_chip_id) {
80 case TEGRA20:
81
82 reg &= ~TEGRA20_FLOW_CTRL_CSR_WFE_BITMAP;
83
84 reg &= ~TEGRA20_FLOW_CTRL_CSR_WFI_BITMAP;
85
86 reg |= TEGRA20_FLOW_CTRL_CSR_WFE_CPU0 << cpuid;
87 break;
88 case TEGRA30:
89
90 reg &= ~TEGRA30_FLOW_CTRL_CSR_WFE_BITMAP;
91
92 reg &= ~TEGRA30_FLOW_CTRL_CSR_WFI_BITMAP;
93
94 reg |= TEGRA30_FLOW_CTRL_CSR_WFI_CPU0 << cpuid;
95 break;
96 }
97 reg |= FLOW_CTRL_CSR_INTR_FLAG;
98 reg |= FLOW_CTRL_CSR_EVENT_FLAG;
99 reg |= FLOW_CTRL_CSR_ENABLE;
100 flowctrl_write_cpu_csr(cpuid, reg);
101
102 for (i = 0; i < num_possible_cpus(); i++) {
103 if (i == cpuid)
104 continue;
105 reg = flowctrl_read_cpu_csr(i);
106 reg |= FLOW_CTRL_CSR_EVENT_FLAG;
107 reg |= FLOW_CTRL_CSR_INTR_FLAG;
108 flowctrl_write_cpu_csr(i, reg);
109 }
110}
111
112void flowctrl_cpu_suspend_exit(unsigned int cpuid)
113{
114 unsigned int reg;
115
116
117 reg = flowctrl_read_cpu_csr(cpuid);
118 switch (tegra_chip_id) {
119 case TEGRA20:
120
121 reg &= ~TEGRA20_FLOW_CTRL_CSR_WFE_BITMAP;
122
123 reg &= ~TEGRA20_FLOW_CTRL_CSR_WFI_BITMAP;
124 break;
125 case TEGRA30:
126
127 reg &= ~TEGRA30_FLOW_CTRL_CSR_WFE_BITMAP;
128
129 reg &= ~TEGRA30_FLOW_CTRL_CSR_WFI_BITMAP;
130 break;
131 }
132 reg &= ~FLOW_CTRL_CSR_ENABLE;
133 reg |= FLOW_CTRL_CSR_INTR_FLAG;
134 reg |= FLOW_CTRL_CSR_EVENT_FLAG;
135 flowctrl_write_cpu_csr(cpuid, reg);
136}
137