ARM: shmobile: Cleanup pm-rmobile.o build using Kconfig
[deliverable/linux.git] / arch / arm / mach-shmobile / pm-rmobile.c
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 "pm-rmobile.h"
21
22 /* SYSC */
23 #define SPDCR IOMEM(0xe6180008)
24 #define SWUCR IOMEM(0xe6180014)
25 #define PSTR IOMEM(0xe6180080)
26
27 #define PSTR_RETRIES 100
28 #define PSTR_DELAY_US 10
29
30 static int rmobile_pd_power_down(struct generic_pm_domain *genpd)
31 {
32 struct rmobile_pm_domain *rmobile_pd = to_rmobile_pd(genpd);
33 unsigned int mask = 1 << rmobile_pd->bit_shift;
34
35 if (rmobile_pd->suspend) {
36 int ret = rmobile_pd->suspend();
37
38 if (ret)
39 return ret;
40 }
41
42 if (__raw_readl(PSTR) & mask) {
43 unsigned int retry_count;
44 __raw_writel(mask, SPDCR);
45
46 for (retry_count = PSTR_RETRIES; retry_count; retry_count--) {
47 if (!(__raw_readl(SPDCR) & mask))
48 break;
49 cpu_relax();
50 }
51 }
52
53 if (!rmobile_pd->no_debug)
54 pr_debug("%s: Power off, 0x%08x -> PSTR = 0x%08x\n",
55 genpd->name, mask, __raw_readl(PSTR));
56
57 return 0;
58 }
59
60 static int __rmobile_pd_power_up(struct rmobile_pm_domain *rmobile_pd,
61 bool do_resume)
62 {
63 unsigned int mask = 1 << rmobile_pd->bit_shift;
64 unsigned int retry_count;
65 int ret = 0;
66
67 if (__raw_readl(PSTR) & mask)
68 goto out;
69
70 __raw_writel(mask, SWUCR);
71
72 for (retry_count = 2 * PSTR_RETRIES; retry_count; retry_count--) {
73 if (!(__raw_readl(SWUCR) & mask))
74 break;
75 if (retry_count > PSTR_RETRIES)
76 udelay(PSTR_DELAY_US);
77 else
78 cpu_relax();
79 }
80 if (!retry_count)
81 ret = -EIO;
82
83 if (!rmobile_pd->no_debug)
84 pr_debug("%s: Power on, 0x%08x -> PSTR = 0x%08x\n",
85 rmobile_pd->genpd.name, mask, __raw_readl(PSTR));
86
87 out:
88 if (ret == 0 && rmobile_pd->resume && do_resume)
89 rmobile_pd->resume();
90
91 return ret;
92 }
93
94 static int rmobile_pd_power_up(struct generic_pm_domain *genpd)
95 {
96 return __rmobile_pd_power_up(to_rmobile_pd(genpd), true);
97 }
98
99 static bool rmobile_pd_active_wakeup(struct device *dev)
100 {
101 return true;
102 }
103
104 static void rmobile_init_pm_domain(struct rmobile_pm_domain *rmobile_pd)
105 {
106 struct generic_pm_domain *genpd = &rmobile_pd->genpd;
107 struct dev_power_governor *gov = rmobile_pd->gov;
108
109 pm_genpd_init(genpd, gov ? : &simple_qos_governor, false);
110 genpd->dev_ops.stop = pm_clk_suspend;
111 genpd->dev_ops.start = pm_clk_resume;
112 genpd->dev_ops.active_wakeup = rmobile_pd_active_wakeup;
113 genpd->dev_irq_safe = true;
114 genpd->power_off = rmobile_pd_power_down;
115 genpd->power_on = rmobile_pd_power_up;
116 __rmobile_pd_power_up(rmobile_pd, false);
117 }
118
119 void rmobile_init_domains(struct rmobile_pm_domain domains[], int num)
120 {
121 int j;
122
123 for (j = 0; j < num; j++)
124 rmobile_init_pm_domain(&domains[j]);
125 }
126
127 void rmobile_add_device_to_domain_td(const char *domain_name,
128 struct platform_device *pdev,
129 struct gpd_timing_data *td)
130 {
131 struct device *dev = &pdev->dev;
132
133 __pm_genpd_name_add_device(domain_name, dev, td);
134 if (pm_clk_no_clocks(dev))
135 pm_clk_add(dev, NULL);
136 }
137
138 void rmobile_add_devices_to_domains(struct pm_domain_device data[],
139 int size)
140 {
141 struct gpd_timing_data latencies = {
142 .stop_latency_ns = DEFAULT_DEV_LATENCY_NS,
143 .start_latency_ns = DEFAULT_DEV_LATENCY_NS,
144 .save_state_latency_ns = DEFAULT_DEV_LATENCY_NS,
145 .restore_state_latency_ns = DEFAULT_DEV_LATENCY_NS,
146 };
147 int j;
148
149 for (j = 0; j < size; j++)
150 rmobile_add_device_to_domain_td(data[j].domain_name,
151 data[j].pdev, &latencies);
152 }
This page took 0.228777 seconds and 5 git commands to generate.