Merge remote-tracking branch 'asoc/fix/dapm' into asoc-linus
[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 genpd->flags = GENPD_FLAG_PM_CLK;
110 pm_genpd_init(genpd, gov ? : &simple_qos_governor, false);
111 genpd->dev_ops.active_wakeup = rmobile_pd_active_wakeup;
112 genpd->power_off = rmobile_pd_power_down;
113 genpd->power_on = rmobile_pd_power_up;
114 __rmobile_pd_power_up(rmobile_pd, false);
115 }
116
117 void rmobile_init_domains(struct rmobile_pm_domain domains[], int num)
118 {
119 int j;
120
121 for (j = 0; j < num; j++)
122 rmobile_init_pm_domain(&domains[j]);
123 }
124
125 void rmobile_add_device_to_domain_td(const char *domain_name,
126 struct platform_device *pdev,
127 struct gpd_timing_data *td)
128 {
129 struct device *dev = &pdev->dev;
130
131 __pm_genpd_name_add_device(domain_name, dev, td);
132 if (pm_clk_no_clocks(dev))
133 pm_clk_add(dev, NULL);
134 }
135
136 void rmobile_add_devices_to_domains(struct pm_domain_device data[],
137 int size)
138 {
139 struct gpd_timing_data latencies = {
140 .stop_latency_ns = DEFAULT_DEV_LATENCY_NS,
141 .start_latency_ns = DEFAULT_DEV_LATENCY_NS,
142 .save_state_latency_ns = DEFAULT_DEV_LATENCY_NS,
143 .restore_state_latency_ns = DEFAULT_DEV_LATENCY_NS,
144 };
145 int j;
146
147 for (j = 0; j < size; j++)
148 rmobile_add_device_to_domain_td(data[j].domain_name,
149 data[j].pdev, &latencies);
150 }
This page took 0.033171 seconds and 5 git commands to generate.