ARM: shmobile: Move common.h
[deliverable/linux.git] / arch / arm / mach-shmobile / pm-rmobile.c
CommitLineData
8f45b112
KM
1/*
2 * rmobile power management support
3 *
4 * Copyright (C) 2012 Renesas Solutions Corp.
5 * Copyright (C) 2012 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6 *
7 * based on pm-sh7372.c
8 * Copyright (C) 2011 Magnus Damm
9 *
10 * This file is subject to the terms and conditions of the GNU General Public
11 * License. See the file "COPYING" in the main directory of this archive
12 * for more details.
13 */
14#include <linux/console.h>
15#include <linux/delay.h>
16#include <linux/platform_device.h>
17#include <linux/pm.h>
18#include <linux/pm_clock.h>
19#include <asm/io.h>
20#include <mach/pm-rmobile.h>
21
22/* SYSC */
0a4b04dc
AB
23#define SPDCR IOMEM(0xe6180008)
24#define SWUCR IOMEM(0xe6180014)
25#define PSTR IOMEM(0xe6180080)
8f45b112
KM
26
27#define PSTR_RETRIES 100
28#define PSTR_DELAY_US 10
29
30#ifdef CONFIG_PM
31static int rmobile_pd_power_down(struct generic_pm_domain *genpd)
32{
33 struct rmobile_pm_domain *rmobile_pd = to_rmobile_pd(genpd);
34 unsigned int mask = 1 << rmobile_pd->bit_shift;
35
36 if (rmobile_pd->suspend) {
37 int ret = rmobile_pd->suspend();
38
39 if (ret)
40 return ret;
41 }
42
43 if (__raw_readl(PSTR) & mask) {
44 unsigned int retry_count;
45 __raw_writel(mask, SPDCR);
46
47 for (retry_count = PSTR_RETRIES; retry_count; retry_count--) {
48 if (!(__raw_readl(SPDCR) & mask))
49 break;
50 cpu_relax();
51 }
52 }
53
54 if (!rmobile_pd->no_debug)
55 pr_debug("%s: Power off, 0x%08x -> PSTR = 0x%08x\n",
56 genpd->name, mask, __raw_readl(PSTR));
57
58 return 0;
59}
60
61static int __rmobile_pd_power_up(struct rmobile_pm_domain *rmobile_pd,
62 bool do_resume)
63{
64 unsigned int mask = 1 << rmobile_pd->bit_shift;
65 unsigned int retry_count;
66 int ret = 0;
67
68 if (__raw_readl(PSTR) & mask)
69 goto out;
70
71 __raw_writel(mask, SWUCR);
72
73 for (retry_count = 2 * PSTR_RETRIES; retry_count; retry_count--) {
74 if (!(__raw_readl(SWUCR) & mask))
75 break;
76 if (retry_count > PSTR_RETRIES)
77 udelay(PSTR_DELAY_US);
78 else
79 cpu_relax();
80 }
81 if (!retry_count)
82 ret = -EIO;
83
84 if (!rmobile_pd->no_debug)
85 pr_debug("%s: Power on, 0x%08x -> PSTR = 0x%08x\n",
86 rmobile_pd->genpd.name, mask, __raw_readl(PSTR));
87
88out:
89 if (ret == 0 && rmobile_pd->resume && do_resume)
90 rmobile_pd->resume();
91
92 return ret;
93}
94
95static int rmobile_pd_power_up(struct generic_pm_domain *genpd)
96{
97 return __rmobile_pd_power_up(to_rmobile_pd(genpd), true);
98}
99
100static bool rmobile_pd_active_wakeup(struct device *dev)
101{
ab496b9d 102 return true;
8f45b112
KM
103}
104
a62595d3 105static void rmobile_init_pm_domain(struct rmobile_pm_domain *rmobile_pd)
8f45b112
KM
106{
107 struct generic_pm_domain *genpd = &rmobile_pd->genpd;
108 struct dev_power_governor *gov = rmobile_pd->gov;
109
110 pm_genpd_init(genpd, gov ? : &simple_qos_governor, false);
ab496b9d
UH
111 genpd->dev_ops.stop = pm_clk_suspend;
112 genpd->dev_ops.start = pm_clk_resume;
8f45b112
KM
113 genpd->dev_ops.active_wakeup = rmobile_pd_active_wakeup;
114 genpd->dev_irq_safe = true;
115 genpd->power_off = rmobile_pd_power_down;
116 genpd->power_on = rmobile_pd_power_up;
117 __rmobile_pd_power_up(rmobile_pd, false);
118}
119
0d09f450
RW
120void rmobile_init_domains(struct rmobile_pm_domain domains[], int num)
121{
122 int j;
123
124 for (j = 0; j < num; j++)
125 rmobile_init_pm_domain(&domains[j]);
126}
127
455ae3a5
RW
128void rmobile_add_device_to_domain_td(const char *domain_name,
129 struct platform_device *pdev,
130 struct gpd_timing_data *td)
8f45b112
KM
131{
132 struct device *dev = &pdev->dev;
133
455ae3a5 134 __pm_genpd_name_add_device(domain_name, dev, td);
8f45b112
KM
135 if (pm_clk_no_clocks(dev))
136 pm_clk_add(dev, NULL);
137}
138
ac18e02d
RW
139void rmobile_add_devices_to_domains(struct pm_domain_device data[],
140 int size)
8f45b112 141{
ac18e02d
RW
142 struct gpd_timing_data latencies = {
143 .stop_latency_ns = DEFAULT_DEV_LATENCY_NS,
144 .start_latency_ns = DEFAULT_DEV_LATENCY_NS,
145 .save_state_latency_ns = DEFAULT_DEV_LATENCY_NS,
146 .restore_state_latency_ns = DEFAULT_DEV_LATENCY_NS,
147 };
148 int j;
149
150 for (j = 0; j < size; j++)
151 rmobile_add_device_to_domain_td(data[j].domain_name,
152 data[j].pdev, &latencies);
8f45b112
KM
153}
154#endif /* CONFIG_PM */
This page took 0.123358 seconds and 5 git commands to generate.