ab8500-sysctrl.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (C) ST-Ericsson SA 2010
  3. * Author: Mattias Nilsson <mattias.i.nilsson@stericsson.com> for ST Ericsson.
  4. * License terms: GNU General Public License (GPL) version 2
  5. */
  6. #include <linux/err.h>
  7. #include <linux/module.h>
  8. #include <linux/platform_device.h>
  9. #include <linux/pm.h>
  10. #include <linux/signal.h>
  11. #include <linux/mfd/abx500.h>
  12. #include <linux/mfd/abx500/ab8500.h>
  13. #include <linux/mfd/abx500/ab8500-sysctrl.h>
  14. static struct device *sysctrl_dev;
  15. void ab8500_power_off(void)
  16. {
  17. sigset_t old;
  18. sigset_t all;
  19. sigfillset(&all);
  20. if (!sigprocmask(SIG_BLOCK, &all, &old)) {
  21. (void)ab8500_sysctrl_set(AB8500_STW4500CTRL1,
  22. AB8500_STW4500CTRL1_SWOFF |
  23. AB8500_STW4500CTRL1_SWRESET4500N);
  24. (void)sigprocmask(SIG_SETMASK, &old, NULL);
  25. }
  26. }
  27. static inline bool valid_bank(u8 bank)
  28. {
  29. return ((bank == AB8500_SYS_CTRL1_BLOCK) ||
  30. (bank == AB8500_SYS_CTRL2_BLOCK));
  31. }
  32. int ab8500_sysctrl_read(u16 reg, u8 *value)
  33. {
  34. u8 bank;
  35. if (sysctrl_dev == NULL)
  36. return -EAGAIN;
  37. bank = (reg >> 8);
  38. if (!valid_bank(bank))
  39. return -EINVAL;
  40. return abx500_get_register_interruptible(sysctrl_dev, bank,
  41. (u8)(reg & 0xFF), value);
  42. }
  43. int ab8500_sysctrl_write(u16 reg, u8 mask, u8 value)
  44. {
  45. u8 bank;
  46. if (sysctrl_dev == NULL)
  47. return -EAGAIN;
  48. bank = (reg >> 8);
  49. if (!valid_bank(bank))
  50. return -EINVAL;
  51. return abx500_mask_and_set_register_interruptible(sysctrl_dev, bank,
  52. (u8)(reg & 0xFF), mask, value);
  53. }
  54. static int ab8500_sysctrl_probe(struct platform_device *pdev)
  55. {
  56. struct ab8500_platform_data *plat;
  57. sysctrl_dev = &pdev->dev;
  58. plat = dev_get_platdata(pdev->dev.parent);
  59. if (plat->pm_power_off)
  60. pm_power_off = ab8500_power_off;
  61. return 0;
  62. }
  63. static int ab8500_sysctrl_remove(struct platform_device *pdev)
  64. {
  65. sysctrl_dev = NULL;
  66. return 0;
  67. }
  68. static struct platform_driver ab8500_sysctrl_driver = {
  69. .driver = {
  70. .name = "ab8500-sysctrl",
  71. .owner = THIS_MODULE,
  72. },
  73. .probe = ab8500_sysctrl_probe,
  74. .remove = ab8500_sysctrl_remove,
  75. };
  76. static int __init ab8500_sysctrl_init(void)
  77. {
  78. return platform_driver_register(&ab8500_sysctrl_driver);
  79. }
  80. subsys_initcall(ab8500_sysctrl_init);
  81. MODULE_AUTHOR("Mattias Nilsson <mattias.i.nilsson@stericsson.com");
  82. MODULE_DESCRIPTION("AB8500 system control driver");
  83. MODULE_LICENSE("GPL v2");