pm.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  1. /* linux/arch/arm/plat-s3c24xx/pm.c
  2. *
  3. * Copyright (c) 2004,2006 Simtec Electronics
  4. * Ben Dooks <ben@simtec.co.uk>
  5. *
  6. * S3C24XX Power Manager (Suspend-To-RAM) support
  7. *
  8. * See Documentation/arm/Samsung-S3C24XX/Suspend.txt for more information
  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 as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. *
  24. * Parts based on arch/arm/mach-pxa/pm.c
  25. *
  26. * Thanks to Dimitry Andric for debugging
  27. */
  28. #include <linux/init.h>
  29. #include <linux/suspend.h>
  30. #include <linux/errno.h>
  31. #include <linux/time.h>
  32. #include <linux/interrupt.h>
  33. #include <linux/crc32.h>
  34. #include <linux/ioport.h>
  35. #include <linux/serial_core.h>
  36. #include <linux/io.h>
  37. #include <asm/cacheflush.h>
  38. #include <mach/hardware.h>
  39. #include <plat/regs-serial.h>
  40. #include <mach/regs-clock.h>
  41. #include <mach/regs-gpio.h>
  42. #include <mach/regs-mem.h>
  43. #include <mach/regs-irq.h>
  44. #include <asm/mach/time.h>
  45. #include <plat/pm.h>
  46. #define PFX "s3c24xx-pm: "
  47. static struct sleep_save core_save[] = {
  48. SAVE_ITEM(S3C2410_LOCKTIME),
  49. SAVE_ITEM(S3C2410_CLKCON),
  50. /* we restore the timings here, with the proviso that the board
  51. * brings the system up in an slower, or equal frequency setting
  52. * to the original system.
  53. *
  54. * if we cannot guarantee this, then things are going to go very
  55. * wrong here, as we modify the refresh and both pll settings.
  56. */
  57. SAVE_ITEM(S3C2410_BWSCON),
  58. SAVE_ITEM(S3C2410_BANKCON0),
  59. SAVE_ITEM(S3C2410_BANKCON1),
  60. SAVE_ITEM(S3C2410_BANKCON2),
  61. SAVE_ITEM(S3C2410_BANKCON3),
  62. SAVE_ITEM(S3C2410_BANKCON4),
  63. SAVE_ITEM(S3C2410_BANKCON5),
  64. #ifndef CONFIG_CPU_FREQ
  65. SAVE_ITEM(S3C2410_CLKDIVN),
  66. SAVE_ITEM(S3C2410_MPLLCON),
  67. SAVE_ITEM(S3C2410_REFRESH),
  68. #endif
  69. SAVE_ITEM(S3C2410_UPLLCON),
  70. SAVE_ITEM(S3C2410_CLKSLOW),
  71. };
  72. static struct gpio_sleep {
  73. void __iomem *base;
  74. unsigned int gpcon;
  75. unsigned int gpdat;
  76. unsigned int gpup;
  77. } gpio_save[] = {
  78. [0] = {
  79. .base = S3C2410_GPACON,
  80. },
  81. [1] = {
  82. .base = S3C2410_GPBCON,
  83. },
  84. [2] = {
  85. .base = S3C2410_GPCCON,
  86. },
  87. [3] = {
  88. .base = S3C2410_GPDCON,
  89. },
  90. [4] = {
  91. .base = S3C2410_GPECON,
  92. },
  93. [5] = {
  94. .base = S3C2410_GPFCON,
  95. },
  96. [6] = {
  97. .base = S3C2410_GPGCON,
  98. },
  99. [7] = {
  100. .base = S3C2410_GPHCON,
  101. },
  102. };
  103. static struct sleep_save misc_save[] = {
  104. SAVE_ITEM(S3C2410_DCLKCON),
  105. };
  106. #ifdef CONFIG_S3C2410_PM_DEBUG
  107. #define SAVE_UART(va) \
  108. SAVE_ITEM((va) + S3C2410_ULCON), \
  109. SAVE_ITEM((va) + S3C2410_UCON), \
  110. SAVE_ITEM((va) + S3C2410_UFCON), \
  111. SAVE_ITEM((va) + S3C2410_UMCON), \
  112. SAVE_ITEM((va) + S3C2410_UBRDIV)
  113. static struct sleep_save uart_save[] = {
  114. SAVE_UART(S3C24XX_VA_UART0),
  115. SAVE_UART(S3C24XX_VA_UART1),
  116. #ifndef CONFIG_CPU_S3C2400
  117. SAVE_UART(S3C24XX_VA_UART2),
  118. #endif
  119. };
  120. /* debug
  121. *
  122. * we send the debug to printascii() to allow it to be seen if the
  123. * system never wakes up from the sleep
  124. */
  125. static void s3c2410_pm_debug_init(void)
  126. {
  127. unsigned long tmp = __raw_readl(S3C2410_CLKCON);
  128. /* re-start uart clocks */
  129. tmp |= S3C2410_CLKCON_UART0;
  130. tmp |= S3C2410_CLKCON_UART1;
  131. tmp |= S3C2410_CLKCON_UART2;
  132. __raw_writel(tmp, S3C2410_CLKCON);
  133. udelay(10);
  134. }
  135. #else
  136. #define s3c2410_pm_debug_init() do { } while(0)
  137. static struct sleep_save uart_save[] = {};
  138. #endif
  139. #if defined(CONFIG_S3C2410_PM_CHECK) && CONFIG_S3C2410_PM_CHECK_CHUNKSIZE != 0
  140. /* suspend checking code...
  141. *
  142. * this next area does a set of crc checks over all the installed
  143. * memory, so the system can verify if the resume was ok.
  144. *
  145. * CONFIG_S3C2410_PM_CHECK_CHUNKSIZE defines the block-size for the CRC,
  146. * increasing it will mean that the area corrupted will be less easy to spot,
  147. * and reducing the size will cause the CRC save area to grow
  148. */
  149. #define CHECK_CHUNKSIZE (CONFIG_S3C2410_PM_CHECK_CHUNKSIZE * 1024)
  150. static u32 crc_size; /* size needed for the crc block */
  151. static u32 *crcs; /* allocated over suspend/resume */
  152. typedef u32 *(run_fn_t)(struct resource *ptr, u32 *arg);
  153. /* s3c2410_pm_run_res
  154. *
  155. * go thorugh the given resource list, and look for system ram
  156. */
  157. static void s3c2410_pm_run_res(struct resource *ptr, run_fn_t fn, u32 *arg)
  158. {
  159. while (ptr != NULL) {
  160. if (ptr->child != NULL)
  161. s3c2410_pm_run_res(ptr->child, fn, arg);
  162. if ((ptr->flags & IORESOURCE_MEM) &&
  163. strcmp(ptr->name, "System RAM") == 0) {
  164. S3C_PMDBG("Found system RAM at %08lx..%08lx\n",
  165. ptr->start, ptr->end);
  166. arg = (fn)(ptr, arg);
  167. }
  168. ptr = ptr->sibling;
  169. }
  170. }
  171. static void s3c2410_pm_run_sysram(run_fn_t fn, u32 *arg)
  172. {
  173. s3c2410_pm_run_res(&iomem_resource, fn, arg);
  174. }
  175. static u32 *s3c2410_pm_countram(struct resource *res, u32 *val)
  176. {
  177. u32 size = (u32)(res->end - res->start)+1;
  178. size += CHECK_CHUNKSIZE-1;
  179. size /= CHECK_CHUNKSIZE;
  180. S3C_PMDBG("Area %08lx..%08lx, %d blocks\n", res->start, res->end, size);
  181. *val += size * sizeof(u32);
  182. return val;
  183. }
  184. /* s3c2410_pm_prepare_check
  185. *
  186. * prepare the necessary information for creating the CRCs. This
  187. * must be done before the final save, as it will require memory
  188. * allocating, and thus touching bits of the kernel we do not
  189. * know about.
  190. */
  191. static void s3c2410_pm_check_prepare(void)
  192. {
  193. crc_size = 0;
  194. s3c2410_pm_run_sysram(s3c2410_pm_countram, &crc_size);
  195. S3C_PMDBG("s3c2410_pm_prepare_check: %u checks needed\n", crc_size);
  196. crcs = kmalloc(crc_size+4, GFP_KERNEL);
  197. if (crcs == NULL)
  198. printk(KERN_ERR "Cannot allocated CRC save area\n");
  199. }
  200. static u32 *s3c2410_pm_makecheck(struct resource *res, u32 *val)
  201. {
  202. unsigned long addr, left;
  203. for (addr = res->start; addr < res->end;
  204. addr += CHECK_CHUNKSIZE) {
  205. left = res->end - addr;
  206. if (left > CHECK_CHUNKSIZE)
  207. left = CHECK_CHUNKSIZE;
  208. *val = crc32_le(~0, phys_to_virt(addr), left);
  209. val++;
  210. }
  211. return val;
  212. }
  213. /* s3c2410_pm_check_store
  214. *
  215. * compute the CRC values for the memory blocks before the final
  216. * sleep.
  217. */
  218. static void s3c2410_pm_check_store(void)
  219. {
  220. if (crcs != NULL)
  221. s3c2410_pm_run_sysram(s3c2410_pm_makecheck, crcs);
  222. }
  223. /* in_region
  224. *
  225. * return TRUE if the area defined by ptr..ptr+size contatins the
  226. * what..what+whatsz
  227. */
  228. static inline int in_region(void *ptr, int size, void *what, size_t whatsz)
  229. {
  230. if ((what+whatsz) < ptr)
  231. return 0;
  232. if (what > (ptr+size))
  233. return 0;
  234. return 1;
  235. }
  236. static u32 *s3c2410_pm_runcheck(struct resource *res, u32 *val)
  237. {
  238. void *save_at = phys_to_virt(s3c_sleep_save_phys);
  239. unsigned long addr;
  240. unsigned long left;
  241. void *ptr;
  242. u32 calc;
  243. for (addr = res->start; addr < res->end;
  244. addr += CHECK_CHUNKSIZE) {
  245. left = res->end - addr;
  246. if (left > CHECK_CHUNKSIZE)
  247. left = CHECK_CHUNKSIZE;
  248. ptr = phys_to_virt(addr);
  249. if (in_region(ptr, left, crcs, crc_size)) {
  250. S3C_PMDBG("skipping %08lx, has crc block in\n", addr);
  251. goto skip_check;
  252. }
  253. if (in_region(ptr, left, save_at, 32*4 )) {
  254. S3C_PMDBG("skipping %08lx, has save block in\n", addr);
  255. goto skip_check;
  256. }
  257. /* calculate and check the checksum */
  258. calc = crc32_le(~0, ptr, left);
  259. if (calc != *val) {
  260. printk(KERN_ERR PFX "Restore CRC error at "
  261. "%08lx (%08x vs %08x)\n", addr, calc, *val);
  262. S3C_PMDBG("Restore CRC error at %08lx (%08x vs %08x)\n",
  263. addr, calc, *val);
  264. }
  265. skip_check:
  266. val++;
  267. }
  268. return val;
  269. }
  270. /* s3c2410_pm_check_restore
  271. *
  272. * check the CRCs after the restore event and free the memory used
  273. * to hold them
  274. */
  275. static void s3c2410_pm_check_restore(void)
  276. {
  277. if (crcs != NULL) {
  278. s3c2410_pm_run_sysram(s3c2410_pm_runcheck, crcs);
  279. kfree(crcs);
  280. crcs = NULL;
  281. }
  282. }
  283. #else
  284. #define s3c2410_pm_check_prepare() do { } while(0)
  285. #define s3c2410_pm_check_restore() do { } while(0)
  286. #define s3c2410_pm_check_store() do { } while(0)
  287. #endif
  288. /* s3c2410_pm_show_resume_irqs
  289. *
  290. * print any IRQs asserted at resume time (ie, we woke from)
  291. */
  292. static void s3c2410_pm_show_resume_irqs(int start, unsigned long which,
  293. unsigned long mask)
  294. {
  295. int i;
  296. which &= ~mask;
  297. for (i = 0; i <= 31; i++) {
  298. if ((which) & (1L<<i)) {
  299. S3C_PMDBG("IRQ %d asserted at resume\n", start+i);
  300. }
  301. }
  302. }
  303. /* s3c2410_pm_check_resume_pin
  304. *
  305. * check to see if the pin is configured correctly for sleep mode, and
  306. * make any necessary adjustments if it is not
  307. */
  308. static void s3c2410_pm_check_resume_pin(unsigned int pin, unsigned int irqoffs)
  309. {
  310. unsigned long irqstate;
  311. unsigned long pinstate;
  312. int irq = s3c2410_gpio_getirq(pin);
  313. if (irqoffs < 4)
  314. irqstate = s3c_irqwake_intmask & (1L<<irqoffs);
  315. else
  316. irqstate = s3c_irqwake_eintmask & (1L<<irqoffs);
  317. pinstate = s3c2410_gpio_getcfg(pin);
  318. if (!irqstate) {
  319. if (pinstate == S3C2410_GPIO_IRQ)
  320. S3C_PMDBG("Leaving IRQ %d (pin %d) enabled\n", irq, pin);
  321. } else {
  322. if (pinstate == S3C2410_GPIO_IRQ) {
  323. S3C_PMDBG("Disabling IRQ %d (pin %d)\n", irq, pin);
  324. s3c2410_gpio_cfgpin(pin, S3C2410_GPIO_INPUT);
  325. }
  326. }
  327. }
  328. /* s3c2410_pm_configure_extint
  329. *
  330. * configure all external interrupt pins
  331. */
  332. static void s3c2410_pm_configure_extint(void)
  333. {
  334. int pin;
  335. /* for each of the external interrupts (EINT0..EINT15) we
  336. * need to check wether it is an external interrupt source,
  337. * and then configure it as an input if it is not
  338. */
  339. for (pin = S3C2410_GPF0; pin <= S3C2410_GPF7; pin++) {
  340. s3c2410_pm_check_resume_pin(pin, pin - S3C2410_GPF0);
  341. }
  342. for (pin = S3C2410_GPG0; pin <= S3C2410_GPG7; pin++) {
  343. s3c2410_pm_check_resume_pin(pin, (pin - S3C2410_GPG0)+8);
  344. }
  345. }
  346. /* offsets for CON/DAT/UP registers */
  347. #define OFFS_CON (S3C2410_GPACON - S3C2410_GPACON)
  348. #define OFFS_DAT (S3C2410_GPADAT - S3C2410_GPACON)
  349. #define OFFS_UP (S3C2410_GPBUP - S3C2410_GPBCON)
  350. /* s3c2410_pm_save_gpios()
  351. *
  352. * Save the state of the GPIOs
  353. */
  354. static void s3c2410_pm_save_gpios(void)
  355. {
  356. struct gpio_sleep *gps = gpio_save;
  357. unsigned int gpio;
  358. for (gpio = 0; gpio < ARRAY_SIZE(gpio_save); gpio++, gps++) {
  359. void __iomem *base = gps->base;
  360. gps->gpcon = __raw_readl(base + OFFS_CON);
  361. gps->gpdat = __raw_readl(base + OFFS_DAT);
  362. if (gpio > 0)
  363. gps->gpup = __raw_readl(base + OFFS_UP);
  364. }
  365. }
  366. /* Test whether the given masked+shifted bits of an GPIO configuration
  367. * are one of the SFN (special function) modes. */
  368. static inline int is_sfn(unsigned long con)
  369. {
  370. return (con == 2 || con == 3);
  371. }
  372. /* Test if the given masked+shifted GPIO configuration is an input */
  373. static inline int is_in(unsigned long con)
  374. {
  375. return con == 0;
  376. }
  377. /* Test if the given masked+shifted GPIO configuration is an output */
  378. static inline int is_out(unsigned long con)
  379. {
  380. return con == 1;
  381. }
  382. /* s3c2410_pm_restore_gpio()
  383. *
  384. * Restore one of the GPIO banks that was saved during suspend. This is
  385. * not as simple as once thought, due to the possibility of glitches
  386. * from the order that the CON and DAT registers are set in.
  387. *
  388. * The three states the pin can be are {IN,OUT,SFN} which gives us 9
  389. * combinations of changes to check. Three of these, if the pin stays
  390. * in the same configuration can be discounted. This leaves us with
  391. * the following:
  392. *
  393. * { IN => OUT } Change DAT first
  394. * { IN => SFN } Change CON first
  395. * { OUT => SFN } Change CON first, so new data will not glitch
  396. * { OUT => IN } Change CON first, so new data will not glitch
  397. * { SFN => IN } Change CON first
  398. * { SFN => OUT } Change DAT first, so new data will not glitch [1]
  399. *
  400. * We do not currently deal with the UP registers as these control
  401. * weak resistors, so a small delay in change should not need to bring
  402. * these into the calculations.
  403. *
  404. * [1] this assumes that writing to a pin DAT whilst in SFN will set the
  405. * state for when it is next output.
  406. */
  407. static void s3c2410_pm_restore_gpio(int index, struct gpio_sleep *gps)
  408. {
  409. void __iomem *base = gps->base;
  410. unsigned long gps_gpcon = gps->gpcon;
  411. unsigned long gps_gpdat = gps->gpdat;
  412. unsigned long old_gpcon;
  413. unsigned long old_gpdat;
  414. unsigned long old_gpup = 0x0;
  415. unsigned long gpcon;
  416. int nr;
  417. old_gpcon = __raw_readl(base + OFFS_CON);
  418. old_gpdat = __raw_readl(base + OFFS_DAT);
  419. if (base == S3C2410_GPACON) {
  420. /* GPACON only has one bit per control / data and no PULLUPs.
  421. * GPACON[x] = 0 => Output, 1 => SFN */
  422. /* first set all SFN bits to SFN */
  423. gpcon = old_gpcon | gps->gpcon;
  424. __raw_writel(gpcon, base + OFFS_CON);
  425. /* now set all the other bits */
  426. __raw_writel(gps_gpdat, base + OFFS_DAT);
  427. __raw_writel(gps_gpcon, base + OFFS_CON);
  428. } else {
  429. unsigned long old, new, mask;
  430. unsigned long change_mask = 0x0;
  431. old_gpup = __raw_readl(base + OFFS_UP);
  432. /* Create a change_mask of all the items that need to have
  433. * their CON value changed before their DAT value, so that
  434. * we minimise the work between the two settings.
  435. */
  436. for (nr = 0, mask = 0x03; nr < 32; nr += 2, mask <<= 2) {
  437. old = (old_gpcon & mask) >> nr;
  438. new = (gps_gpcon & mask) >> nr;
  439. /* If there is no change, then skip */
  440. if (old == new)
  441. continue;
  442. /* If both are special function, then skip */
  443. if (is_sfn(old) && is_sfn(new))
  444. continue;
  445. /* Change is IN => OUT, do not change now */
  446. if (is_in(old) && is_out(new))
  447. continue;
  448. /* Change is SFN => OUT, do not change now */
  449. if (is_sfn(old) && is_out(new))
  450. continue;
  451. /* We should now be at the case of IN=>SFN,
  452. * OUT=>SFN, OUT=>IN, SFN=>IN. */
  453. change_mask |= mask;
  454. }
  455. /* Write the new CON settings */
  456. gpcon = old_gpcon & ~change_mask;
  457. gpcon |= gps_gpcon & change_mask;
  458. __raw_writel(gpcon, base + OFFS_CON);
  459. /* Now change any items that require DAT,CON */
  460. __raw_writel(gps_gpdat, base + OFFS_DAT);
  461. __raw_writel(gps_gpcon, base + OFFS_CON);
  462. __raw_writel(gps->gpup, base + OFFS_UP);
  463. }
  464. S3C_PMDBG("GPIO[%d] CON %08lx => %08lx, DAT %08lx => %08lx\n",
  465. index, old_gpcon, gps_gpcon, old_gpdat, gps_gpdat);
  466. }
  467. /** s3c2410_pm_restore_gpios()
  468. *
  469. * Restore the state of the GPIOs
  470. */
  471. static void s3c2410_pm_restore_gpios(void)
  472. {
  473. struct gpio_sleep *gps = gpio_save;
  474. int gpio;
  475. for (gpio = 0; gpio < ARRAY_SIZE(gpio_save); gpio++, gps++) {
  476. s3c2410_pm_restore_gpio(gpio, gps);
  477. }
  478. }
  479. void (*pm_cpu_prep)(void);
  480. void (*pm_cpu_sleep)(void);
  481. #define any_allowed(mask, allow) (((mask) & (allow)) != (allow))
  482. /* s3c2410_pm_enter
  483. *
  484. * central control for sleep/resume process
  485. */
  486. static int s3c2410_pm_enter(suspend_state_t state)
  487. {
  488. unsigned long regs_save[16];
  489. /* ensure the debug is initialised (if enabled) */
  490. s3c2410_pm_debug_init();
  491. S3C_PMDBG("s3c2410_pm_enter(%d)\n", state);
  492. if (pm_cpu_prep == NULL || pm_cpu_sleep == NULL) {
  493. printk(KERN_ERR PFX "error: no cpu sleep functions set\n");
  494. return -EINVAL;
  495. }
  496. /* check if we have anything to wake-up with... bad things seem
  497. * to happen if you suspend with no wakeup (system will often
  498. * require a full power-cycle)
  499. */
  500. if (!any_allowed(s3c_irqwake_intmask, s3c_irqwake_intallow) &&
  501. !any_allowed(s3c_irqwake_eintmask, s3c_irqwake_eintallow)) {
  502. printk(KERN_ERR PFX "No sources enabled for wake-up!\n");
  503. printk(KERN_ERR PFX "Aborting sleep\n");
  504. return -EINVAL;
  505. }
  506. /* prepare check area if configured */
  507. s3c2410_pm_check_prepare();
  508. /* store the physical address of the register recovery block */
  509. s3c_sleep_save_phys = virt_to_phys(regs_save);
  510. S3C_PMDBG("s3c_sleep_save_phys=0x%08lx\n", s3c_sleep_save_phys);
  511. /* save all necessary core registers not covered by the drivers */
  512. s3c2410_pm_save_gpios();
  513. s3c_pm_do_save(misc_save, ARRAY_SIZE(misc_save));
  514. s3c_pm_do_save(core_save, ARRAY_SIZE(core_save));
  515. s3c_pm_do_save(uart_save, ARRAY_SIZE(uart_save));
  516. /* set the irq configuration for wake */
  517. s3c2410_pm_configure_extint();
  518. S3C_PMDBG("sleep: irq wakeup masks: %08lx,%08lx\n",
  519. s3c_irqwake_intmask, s3c_irqwake_eintmask);
  520. __raw_writel(s3c_irqwake_intmask, S3C2410_INTMSK);
  521. __raw_writel(s3c_irqwake_eintmask, S3C2410_EINTMASK);
  522. /* ack any outstanding external interrupts before we go to sleep */
  523. __raw_writel(__raw_readl(S3C2410_EINTPEND), S3C2410_EINTPEND);
  524. __raw_writel(__raw_readl(S3C2410_INTPND), S3C2410_INTPND);
  525. __raw_writel(__raw_readl(S3C2410_SRCPND), S3C2410_SRCPND);
  526. /* call cpu specific preparation */
  527. pm_cpu_prep();
  528. /* flush cache back to ram */
  529. flush_cache_all();
  530. s3c2410_pm_check_store();
  531. /* send the cpu to sleep... */
  532. __raw_writel(0x00, S3C2410_CLKCON); /* turn off clocks over sleep */
  533. /* s3c2410_cpu_save will also act as our return point from when
  534. * we resume as it saves its own register state, so use the return
  535. * code to differentiate return from save and return from sleep */
  536. if (s3c2410_cpu_save(regs_save) == 0) {
  537. flush_cache_all();
  538. pm_cpu_sleep();
  539. }
  540. /* restore the cpu state */
  541. cpu_init();
  542. /* restore the system state */
  543. s3c_pm_do_restore_core(core_save, ARRAY_SIZE(core_save));
  544. s3c_pm_do_restore(misc_save, ARRAY_SIZE(misc_save));
  545. s3c_pm_do_restore(uart_save, ARRAY_SIZE(uart_save));
  546. s3c2410_pm_restore_gpios();
  547. s3c2410_pm_debug_init();
  548. /* check what irq (if any) restored the system */
  549. S3C_PMDBG("post sleep: IRQs 0x%08x, 0x%08x\n",
  550. __raw_readl(S3C2410_SRCPND),
  551. __raw_readl(S3C2410_EINTPEND));
  552. s3c2410_pm_show_resume_irqs(IRQ_EINT0, __raw_readl(S3C2410_SRCPND),
  553. s3c_irqwake_intmask);
  554. s3c2410_pm_show_resume_irqs(IRQ_EINT4-4, __raw_readl(S3C2410_EINTPEND),
  555. s3c_irqwake_eintmask);
  556. S3C_PMDBG("post sleep, preparing to return\n");
  557. s3c2410_pm_check_restore();
  558. /* ok, let's return from sleep */
  559. S3C_PMDBG("S3C2410 PM Resume (post-restore)\n");
  560. return 0;
  561. }
  562. static struct platform_suspend_ops s3c2410_pm_ops = {
  563. .enter = s3c2410_pm_enter,
  564. .valid = suspend_valid_only_mem,
  565. };
  566. /* s3c2410_pm_init
  567. *
  568. * Attach the power management functions. This should be called
  569. * from the board specific initialisation if the board supports
  570. * it.
  571. */
  572. int __init s3c2410_pm_init(void)
  573. {
  574. printk("S3C2410 Power Management, (c) 2004 Simtec Electronics\n");
  575. suspend_set_ops(&s3c2410_pm_ops);
  576. return 0;
  577. }