ab8500-sysctrl.c 1.8 KB

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