abx500-core.c 3.8 KB

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