ab8500-sysctrl.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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/platform_device.h>
  8. #include <linux/mfd/ab8500.h>
  9. #include <linux/mfd/abx500.h>
  10. #include <linux/mfd/ab8500/sysctrl.h>
  11. static struct device *sysctrl_dev;
  12. static inline bool valid_bank(u8 bank)
  13. {
  14. return ((bank == AB8500_SYS_CTRL1_BLOCK) ||
  15. (bank == AB8500_SYS_CTRL2_BLOCK));
  16. }
  17. int ab8500_sysctrl_read(u16 reg, u8 *value)
  18. {
  19. u8 bank;
  20. if (sysctrl_dev == NULL)
  21. return -EAGAIN;
  22. bank = (reg >> 8);
  23. if (!valid_bank(bank))
  24. return -EINVAL;
  25. return abx500_get_register_interruptible(sysctrl_dev, bank,
  26. (u8)(reg & 0xFF), value);
  27. }
  28. int ab8500_sysctrl_write(u16 reg, u8 mask, u8 value)
  29. {
  30. u8 bank;
  31. if (sysctrl_dev == NULL)
  32. return -EAGAIN;
  33. bank = (reg >> 8);
  34. if (!valid_bank(bank))
  35. return -EINVAL;
  36. return abx500_mask_and_set_register_interruptible(sysctrl_dev, bank,
  37. (u8)(reg & 0xFF), mask, value);
  38. }
  39. static int __devinit ab8500_sysctrl_probe(struct platform_device *pdev)
  40. {
  41. sysctrl_dev = &pdev->dev;
  42. return 0;
  43. }
  44. static int __devexit ab8500_sysctrl_remove(struct platform_device *pdev)
  45. {
  46. sysctrl_dev = NULL;
  47. return 0;
  48. }
  49. static struct platform_driver ab8500_sysctrl_driver = {
  50. .driver = {
  51. .name = "ab8500-sysctrl",
  52. .owner = THIS_MODULE,
  53. },
  54. .probe = ab8500_sysctrl_probe,
  55. .remove = __devexit_p(ab8500_sysctrl_remove),
  56. };
  57. static int __init ab8500_sysctrl_init(void)
  58. {
  59. return platform_driver_register(&ab8500_sysctrl_driver);
  60. }
  61. subsys_initcall(ab8500_sysctrl_init);
  62. MODULE_AUTHOR("Mattias Nilsson <mattias.i.nilsson@stericsson.com");
  63. MODULE_DESCRIPTION("AB8500 system control driver");
  64. MODULE_LICENSE("GPL v2");