abx500-core.c 3.9 KB

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