pm-common.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (C) 2013 Samsung Electronics Co., Ltd.
  3. * Tomasz Figa <t.figa@samsung.com>
  4. * Copyright (C) 2008 Openmoko, Inc.
  5. * Copyright (C) 2004-2008 Simtec Electronics
  6. * Ben Dooks <ben@simtec.co.uk>
  7. * http://armlinux.simtec.co.uk/
  8. *
  9. * Samsung common power management helper functions.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. */
  15. #include <linux/io.h>
  16. #include <linux/kernel.h>
  17. #include <plat/pm-common.h>
  18. /* helper functions to save and restore register state */
  19. /**
  20. * s3c_pm_do_save() - save a set of registers for restoration on resume.
  21. * @ptr: Pointer to an array of registers.
  22. * @count: Size of the ptr array.
  23. *
  24. * Run through the list of registers given, saving their contents in the
  25. * array for later restoration when we wakeup.
  26. */
  27. void s3c_pm_do_save(struct sleep_save *ptr, int count)
  28. {
  29. for (; count > 0; count--, ptr++) {
  30. ptr->val = readl_relaxed(ptr->reg);
  31. S3C_PMDBG("saved %p value %08lx\n", ptr->reg, ptr->val);
  32. }
  33. }
  34. /**
  35. * s3c_pm_do_restore() - restore register values from the save list.
  36. * @ptr: Pointer to an array of registers.
  37. * @count: Size of the ptr array.
  38. *
  39. * Restore the register values saved from s3c_pm_do_save().
  40. *
  41. * Note, we do not use S3C_PMDBG() in here, as the system may not have
  42. * restore the UARTs state yet
  43. */
  44. void s3c_pm_do_restore(const struct sleep_save *ptr, int count)
  45. {
  46. for (; count > 0; count--, ptr++) {
  47. pr_debug("restore %p (restore %08lx, was %08x)\n",
  48. ptr->reg, ptr->val, readl_relaxed(ptr->reg));
  49. writel_relaxed(ptr->val, ptr->reg);
  50. }
  51. }
  52. /**
  53. * s3c_pm_do_restore_core() - early restore register values from save list.
  54. *
  55. * This is similar to s3c_pm_do_restore() except we try and minimise the
  56. * side effects of the function in case registers that hardware might need
  57. * to work has been restored.
  58. *
  59. * WARNING: Do not put any debug in here that may effect memory or use
  60. * peripherals, as things may be changing!
  61. */
  62. void s3c_pm_do_restore_core(const struct sleep_save *ptr, int count)
  63. {
  64. for (; count > 0; count--, ptr++)
  65. writel_relaxed(ptr->val, ptr->reg);
  66. }