pm.c 19 KB

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