abx500-core.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Copyright (C) 2007-2010 ST-Ericsson
  3. * License terms: GNU General Public License (GPL) version 2
  4. * Register access functions for the ABX500 Mixed Signal IC family.
  5. * Author: Mattias Wallin <mattias.wallin@stericsson.com>
  6. */
  7. #include <linux/list.h>
  8. #include <linux/slab.h>
  9. #include <linux/err.h>
  10. #include <linux/module.h>
  11. #include <linux/mfd/abx500.h>
  12. static LIST_HEAD(abx500_list);
  13. struct abx500_device_entry {
  14. struct list_head list;
  15. struct abx500_ops ops;
  16. struct device *dev;
  17. };
  18. static void lookup_ops(struct device *dev, struct abx500_ops **ops)
  19. {
  20. struct abx500_device_entry *dev_entry;
  21. *ops = NULL;
  22. list_for_each_entry(dev_entry, &abx500_list, list) {
  23. if (dev_entry->dev == dev) {
  24. *ops = &dev_entry->ops;
  25. return;
  26. }
  27. }
  28. }
  29. int abx500_register_ops(struct device *dev, struct abx500_ops *ops)
  30. {
  31. struct abx500_device_entry *dev_entry;
  32. dev_entry = kzalloc(sizeof(struct abx500_device_entry), GFP_KERNEL);
  33. if (!dev_entry) {
  34. dev_err(dev, "register_ops kzalloc failed");
  35. return -ENOMEM;
  36. }
  37. dev_entry->dev = dev;
  38. memcpy(&dev_entry->ops, ops, sizeof(struct abx500_ops));
  39. list_add_tail(&dev_entry->list, &abx500_list);
  40. return 0;
  41. }
  42. EXPORT_SYMBOL(abx500_register_ops);
  43. void abx500_remove_ops(struct device *dev)
  44. {
  45. struct abx500_device_entry *dev_entry, *tmp;
  46. list_for_each_entry_safe(dev_entry, tmp, &abx500_list, list)
  47. {
  48. if (dev_entry->dev == dev) {
  49. list_del(&dev_entry->list);
  50. kfree(dev_entry);
  51. }
  52. }
  53. }
  54. EXPORT_SYMBOL(abx500_remove_ops);
  55. int abx500_set_register_interruptible(struct device *dev, u8 bank, u8 reg,
  56. u8 value)
  57. {
  58. struct abx500_ops *ops;
  59. lookup_ops(dev->parent, &ops);
  60. if ((ops != NULL) && (ops->set_register != NULL))
  61. return ops->set_register(dev, bank, reg, value);
  62. else
  63. return -ENOTSUPP;
  64. }
  65. EXPORT_SYMBOL(abx500_set_register_interruptible);
  66. int abx500_get_register_interruptible(struct device *dev, u8 bank, u8 reg,
  67. u8 *value)
  68. {
  69. struct abx500_ops *ops;
  70. lookup_ops(dev->parent, &ops);
  71. if ((ops != NULL) && (ops->get_register != NULL))
  72. return ops->get_register(dev, bank, reg, value);
  73. else
  74. return -ENOTSUPP;
  75. }
  76. EXPORT_SYMBOL(abx500_get_register_interruptible);
  77. int abx500_get_register_page_interruptible(struct device *dev, u8 bank,
  78. u8 first_reg, u8 *regvals, u8 numregs)
  79. {
  80. struct abx500_ops *ops;
  81. lookup_ops(dev->parent, &ops);
  82. if ((ops != NULL) && (ops->get_register_page != NULL))
  83. return ops->get_register_page(dev, bank,
  84. first_reg, regvals, numregs);
  85. else
  86. return -ENOTSUPP;
  87. }
  88. EXPORT_SYMBOL(abx500_get_register_page_interruptible);
  89. int abx500_mask_and_set_register_interruptible(struct device *dev, u8 bank,
  90. u8 reg, u8 bitmask, u8 bitvalues)
  91. {
  92. struct abx500_ops *ops;
  93. lookup_ops(dev->parent, &ops);
  94. if ((ops != NULL) && (ops->mask_and_set_register != NULL))
  95. return ops->mask_and_set_register(dev, bank,
  96. reg, bitmask, bitvalues);
  97. else
  98. return -ENOTSUPP;
  99. }
  100. EXPORT_SYMBOL(abx500_mask_and_set_register_interruptible);
  101. int abx500_get_chip_id(struct device *dev)
  102. {
  103. struct abx500_ops *ops;
  104. lookup_ops(dev->parent, &ops);
  105. if ((ops != NULL) && (ops->get_chip_id != NULL))
  106. return ops->get_chip_id(dev);
  107. else
  108. return -ENOTSUPP;
  109. }
  110. EXPORT_SYMBOL(abx500_get_chip_id);
  111. int abx500_event_registers_startup_state_get(struct device *dev, u8 *event)
  112. {
  113. struct abx500_ops *ops;
  114. lookup_ops(dev->parent, &ops);
  115. if ((ops != NULL) && (ops->event_registers_startup_state_get != NULL))
  116. return ops->event_registers_startup_state_get(dev, event);
  117. else
  118. return -ENOTSUPP;
  119. }
  120. EXPORT_SYMBOL(abx500_event_registers_startup_state_get);
  121. int abx500_startup_irq_enabled(struct device *dev, unsigned int irq)
  122. {
  123. struct abx500_ops *ops;
  124. lookup_ops(dev->parent, &ops);
  125. if ((ops != NULL) && (ops->startup_irq_enabled != NULL))
  126. return ops->startup_irq_enabled(dev, irq);
  127. else
  128. return -ENOTSUPP;
  129. }
  130. EXPORT_SYMBOL(abx500_startup_irq_enabled);
  131. MODULE_AUTHOR("Mattias Wallin <mattias.wallin@stericsson.com>");
  132. MODULE_DESCRIPTION("ABX500 core driver");
  133. MODULE_LICENSE("GPL");