Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pm.c
Go to the documentation of this file.
1 /* linux/arch/arm/plat-s3c64xx/pm.c
2  *
3  * Copyright 2008 Openmoko, Inc.
4  * Copyright 2008 Simtec Electronics
5  * Ben Dooks <[email protected]>
6  * http://armlinux.simtec.co.uk/
7  *
8  * S3C64XX CPU PM support.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License version 2 as
12  * published by the Free Software Foundation.
13 */
14 
15 #include <linux/init.h>
16 #include <linux/suspend.h>
17 #include <linux/serial_core.h>
18 #include <linux/io.h>
19 #include <linux/gpio.h>
20 #include <linux/pm_domain.h>
21 
22 #include <mach/map.h>
23 #include <mach/irqs.h>
24 
25 #include <plat/devs.h>
26 #include <plat/pm.h>
27 #include <plat/wakeup-mask.h>
28 
29 #include <mach/regs-sys.h>
30 #include <mach/regs-gpio.h>
31 #include <mach/regs-clock.h>
32 #include <mach/regs-syscon-power.h>
33 #include <mach/regs-gpio-memport.h>
34 #include <mach/regs-modem.h>
35 
37  char *const name;
41 };
42 
43 static int s3c64xx_pd_off(struct generic_pm_domain *domain)
44 {
45  struct s3c64xx_pm_domain *pd;
46  u32 val;
47 
48  pd = container_of(domain, struct s3c64xx_pm_domain, pd);
49 
51  val &= ~(pd->ena);
53 
54  return 0;
55 }
56 
57 static int s3c64xx_pd_on(struct generic_pm_domain *domain)
58 {
59  struct s3c64xx_pm_domain *pd;
60  u32 val;
61  long retry = 1000000L;
62 
63  pd = container_of(domain, struct s3c64xx_pm_domain, pd);
64 
66  val |= pd->ena;
68 
69  /* Not all domains provide power status readback */
70  if (pd->pwr_stat) {
71  do {
72  cpu_relax();
74  break;
75  } while (retry--);
76 
77  if (!retry) {
78  pr_err("Failed to start domain %s\n", pd->name);
79  return -EBUSY;
80  }
81  }
82 
83  return 0;
84 }
85 
86 static struct s3c64xx_pm_domain s3c64xx_pm_irom = {
87  .name = "IROM",
89  .pd = {
90  .power_off = s3c64xx_pd_off,
91  .power_on = s3c64xx_pd_on,
92  },
93 };
94 
95 static struct s3c64xx_pm_domain s3c64xx_pm_etm = {
96  .name = "ETM",
98  .pwr_stat = S3C64XX_BLKPWRSTAT_ETM,
99  .pd = {
100  .power_off = s3c64xx_pd_off,
101  .power_on = s3c64xx_pd_on,
102  },
103 };
104 
105 static struct s3c64xx_pm_domain s3c64xx_pm_s = {
106  .name = "S",
108  .pwr_stat = S3C64XX_BLKPWRSTAT_S,
109  .pd = {
110  .power_off = s3c64xx_pd_off,
111  .power_on = s3c64xx_pd_on,
112  },
113 };
114 
115 static struct s3c64xx_pm_domain s3c64xx_pm_f = {
116  .name = "F",
118  .pwr_stat = S3C64XX_BLKPWRSTAT_F,
119  .pd = {
120  .power_off = s3c64xx_pd_off,
121  .power_on = s3c64xx_pd_on,
122  },
123 };
124 
125 static struct s3c64xx_pm_domain s3c64xx_pm_p = {
126  .name = "P",
128  .pwr_stat = S3C64XX_BLKPWRSTAT_P,
129  .pd = {
130  .power_off = s3c64xx_pd_off,
131  .power_on = s3c64xx_pd_on,
132  },
133 };
134 
135 static struct s3c64xx_pm_domain s3c64xx_pm_i = {
136  .name = "I",
138  .pwr_stat = S3C64XX_BLKPWRSTAT_I,
139  .pd = {
140  .power_off = s3c64xx_pd_off,
141  .power_on = s3c64xx_pd_on,
142  },
143 };
144 
145 static struct s3c64xx_pm_domain s3c64xx_pm_g = {
146  .name = "G",
148  .pd = {
149  .power_off = s3c64xx_pd_off,
150  .power_on = s3c64xx_pd_on,
151  },
152 };
153 
154 static struct s3c64xx_pm_domain s3c64xx_pm_v = {
155  .name = "V",
157  .pwr_stat = S3C64XX_BLKPWRSTAT_V,
158  .pd = {
159  .power_off = s3c64xx_pd_off,
160  .power_on = s3c64xx_pd_on,
161  },
162 };
163 
164 static struct s3c64xx_pm_domain *s3c64xx_always_on_pm_domains[] = {
165  &s3c64xx_pm_irom,
166 };
167 
168 static struct s3c64xx_pm_domain *s3c64xx_pm_domains[] = {
169  &s3c64xx_pm_etm,
170  &s3c64xx_pm_g,
171  &s3c64xx_pm_v,
172  &s3c64xx_pm_i,
173  &s3c64xx_pm_p,
174  &s3c64xx_pm_s,
175  &s3c64xx_pm_f,
176 };
177 
178 #ifdef CONFIG_S3C_PM_DEBUG_LED_SMDK
179 void s3c_pm_debug_smdkled(u32 set, u32 clear)
180 {
181  unsigned long flags;
182  int i;
183 
184  local_irq_save(flags);
185  for (i = 0; i < 4; i++) {
186  if (clear & (1 << i))
187  gpio_set_value(S3C64XX_GPN(12 + i), 0);
188  if (set & (1 << i))
189  gpio_set_value(S3C64XX_GPN(12 + i), 1);
190  }
191  local_irq_restore(flags);
192 }
193 #endif
194 
195 static struct sleep_save core_save[] = {
208 
211 
214 
215 #ifndef CONFIG_CPU_FREQ
218 #endif
219 };
220 
221 static struct sleep_save misc_save[] = {
225 
227 
233 
236 
238 };
239 
241 {
243 }
244 
246 {
248 
249  s3c_pm_debug_smdkled(1 << 2, 0);
250 
251  s3c_pm_do_restore_core(core_save, ARRAY_SIZE(core_save));
252  s3c_pm_do_restore(misc_save, ARRAY_SIZE(misc_save));
253 }
254 
256 {
257  s3c_pm_do_save(misc_save, ARRAY_SIZE(misc_save));
258  s3c_pm_do_save(core_save, ARRAY_SIZE(core_save));
259 }
260 
261 /* since both s3c6400 and s3c6410 share the same sleep pm calls, we
262  * put the per-cpu code in here until any new cpu comes along and changes
263  * this.
264  */
265 
266 static int s3c64xx_cpu_suspend(unsigned long arg)
267 {
268  unsigned long tmp;
269 
270  /* set our standby method to sleep */
271 
276 
277  /* clear any old wakeup */
278 
281 
282  /* set the LED state to 0110 over sleep */
283  s3c_pm_debug_smdkled(3 << 1, 0xf);
284 
285  /* issue the standby signal into the pm unit. Note, we
286  * issue a write-buffer drain just in case */
287 
288  tmp = 0;
289 
290  asm("b 1f\n\t"
291  ".align 5\n\t"
292  "1:\n\t"
293  "mcr p15, 0, %0, c7, c10, 5\n\t"
294  "mcr p15, 0, %0, c7, c10, 4\n\t"
295  "mcr p15, 0, %0, c7, c0, 4" :: "r" (tmp));
296 
297  /* we should never get past here */
298 
299  panic("sleep resumed to originator?");
300 }
301 
302 /* mapping of interrupts to parts of the wakeup mask */
303 static struct samsung_wakeup_mask wake_irqs[] = {
305  { .irq = IRQ_RTC_TIC, .bit = S3C64XX_PWRCFG_RTC_TICK_DISABLE, },
306  { .irq = IRQ_PENDN, .bit = S3C64XX_PWRCFG_TS_DISABLE, },
307  { .irq = IRQ_HSMMC0, .bit = S3C64XX_PWRCFG_MMC0_DISABLE, },
308  { .irq = IRQ_HSMMC1, .bit = S3C64XX_PWRCFG_MMC1_DISABLE, },
309  { .irq = IRQ_HSMMC2, .bit = S3C64XX_PWRCFG_MMC2_DISABLE, },
310  { .irq = NO_WAKEUP_IRQ, .bit = S3C64XX_PWRCFG_BATF_DISABLE},
311  { .irq = NO_WAKEUP_IRQ, .bit = S3C64XX_PWRCFG_MSM_DISABLE },
312  { .irq = NO_WAKEUP_IRQ, .bit = S3C64XX_PWRCFG_HSI_DISABLE },
313  { .irq = NO_WAKEUP_IRQ, .bit = S3C64XX_PWRCFG_MSM_DISABLE },
314 };
315 
316 static void s3c64xx_pm_prepare(void)
317 {
319  wake_irqs, ARRAY_SIZE(wake_irqs));
320 
321  /* store address of resume. */
323 
324  /* ensure previous wakeup state is cleared before sleeping */
326 }
327 
329 {
330  int i;
331 
332  s3c_pm_init();
333 
334  for (i = 0; i < ARRAY_SIZE(s3c64xx_always_on_pm_domains); i++)
335  pm_genpd_init(&s3c64xx_always_on_pm_domains[i]->pd,
336  &pm_domain_always_on_gov, false);
337 
338  for (i = 0; i < ARRAY_SIZE(s3c64xx_pm_domains); i++)
339  pm_genpd_init(&s3c64xx_pm_domains[i]->pd, NULL, false);
340 
341  if (dev_get_platdata(&s3c_device_fb.dev))
342  pm_genpd_add_device(&s3c64xx_pm_f.pd, &s3c_device_fb.dev);
343 
344  return 0;
345 }
346 
347 static __init int s3c64xx_pm_initcall(void)
348 {
349  pm_cpu_prep = s3c64xx_pm_prepare;
350  pm_cpu_sleep = s3c64xx_cpu_suspend;
351  pm_uart_udivslot = 1;
352 
353 #ifdef CONFIG_S3C_PM_DEBUG_LED_SMDK
354  gpio_request(S3C64XX_GPN(12), "DEBUG_LED0");
355  gpio_request(S3C64XX_GPN(13), "DEBUG_LED1");
356  gpio_request(S3C64XX_GPN(14), "DEBUG_LED2");
357  gpio_request(S3C64XX_GPN(15), "DEBUG_LED3");
362 #endif
363 
364  return 0;
365 }
366 arch_initcall(s3c64xx_pm_initcall);
367 
369 {
370  pm_genpd_poweroff_unused();
371 
372  return 0;
373 }