Mattias Wallin | fa66125 | 2010-05-01 18:26:20 +0200 | [diff] [blame] | 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 | |
| 8 | #include <linux/list.h> |
| 9 | #include <linux/slab.h> |
| 10 | #include <linux/err.h> |
Paul Gortmaker | 4e36dd3 | 2011-07-03 15:13:27 -0400 | [diff] [blame^] | 11 | #include <linux/module.h> |
Mattias Wallin | fa66125 | 2010-05-01 18:26:20 +0200 | [diff] [blame] | 12 | #include <linux/mfd/abx500.h> |
| 13 | |
| 14 | static LIST_HEAD(abx500_list); |
| 15 | |
| 16 | struct abx500_device_entry { |
| 17 | struct list_head list; |
| 18 | struct abx500_ops ops; |
| 19 | struct device *dev; |
| 20 | }; |
| 21 | |
| 22 | static void lookup_ops(struct device *dev, struct abx500_ops **ops) |
| 23 | { |
| 24 | struct abx500_device_entry *dev_entry; |
| 25 | |
| 26 | *ops = NULL; |
| 27 | list_for_each_entry(dev_entry, &abx500_list, list) { |
| 28 | if (dev_entry->dev == dev) { |
| 29 | *ops = &dev_entry->ops; |
| 30 | return; |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | int abx500_register_ops(struct device *dev, struct abx500_ops *ops) |
| 36 | { |
| 37 | struct abx500_device_entry *dev_entry; |
| 38 | |
| 39 | dev_entry = kzalloc(sizeof(struct abx500_device_entry), GFP_KERNEL); |
Julia Lawall | 25fe24f | 2010-05-28 22:58:46 +0200 | [diff] [blame] | 40 | if (!dev_entry) { |
Mattias Wallin | fa66125 | 2010-05-01 18:26:20 +0200 | [diff] [blame] | 41 | dev_err(dev, "register_ops kzalloc failed"); |
| 42 | return -ENOMEM; |
| 43 | } |
| 44 | dev_entry->dev = dev; |
| 45 | memcpy(&dev_entry->ops, ops, sizeof(struct abx500_ops)); |
| 46 | |
| 47 | list_add_tail(&dev_entry->list, &abx500_list); |
| 48 | return 0; |
| 49 | } |
| 50 | EXPORT_SYMBOL(abx500_register_ops); |
| 51 | |
| 52 | void abx500_remove_ops(struct device *dev) |
| 53 | { |
| 54 | struct abx500_device_entry *dev_entry, *tmp; |
| 55 | |
| 56 | list_for_each_entry_safe(dev_entry, tmp, &abx500_list, list) |
| 57 | { |
| 58 | if (dev_entry->dev == dev) { |
| 59 | list_del(&dev_entry->list); |
| 60 | kfree(dev_entry); |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | EXPORT_SYMBOL(abx500_remove_ops); |
| 65 | |
| 66 | int abx500_set_register_interruptible(struct device *dev, u8 bank, u8 reg, |
| 67 | u8 value) |
| 68 | { |
| 69 | struct abx500_ops *ops; |
| 70 | |
| 71 | lookup_ops(dev->parent, &ops); |
| 72 | if ((ops != NULL) && (ops->set_register != NULL)) |
| 73 | return ops->set_register(dev, bank, reg, value); |
| 74 | else |
| 75 | return -ENOTSUPP; |
| 76 | } |
| 77 | EXPORT_SYMBOL(abx500_set_register_interruptible); |
| 78 | |
| 79 | int abx500_get_register_interruptible(struct device *dev, u8 bank, u8 reg, |
| 80 | u8 *value) |
| 81 | { |
| 82 | struct abx500_ops *ops; |
| 83 | |
| 84 | lookup_ops(dev->parent, &ops); |
| 85 | if ((ops != NULL) && (ops->get_register != NULL)) |
| 86 | return ops->get_register(dev, bank, reg, value); |
| 87 | else |
| 88 | return -ENOTSUPP; |
| 89 | } |
| 90 | EXPORT_SYMBOL(abx500_get_register_interruptible); |
| 91 | |
| 92 | int abx500_get_register_page_interruptible(struct device *dev, u8 bank, |
| 93 | u8 first_reg, u8 *regvals, u8 numregs) |
| 94 | { |
| 95 | struct abx500_ops *ops; |
| 96 | |
| 97 | lookup_ops(dev->parent, &ops); |
| 98 | if ((ops != NULL) && (ops->get_register_page != NULL)) |
| 99 | return ops->get_register_page(dev, bank, |
| 100 | first_reg, regvals, numregs); |
| 101 | else |
| 102 | return -ENOTSUPP; |
| 103 | } |
| 104 | EXPORT_SYMBOL(abx500_get_register_page_interruptible); |
| 105 | |
| 106 | int abx500_mask_and_set_register_interruptible(struct device *dev, u8 bank, |
| 107 | u8 reg, u8 bitmask, u8 bitvalues) |
| 108 | { |
| 109 | struct abx500_ops *ops; |
| 110 | |
| 111 | lookup_ops(dev->parent, &ops); |
| 112 | if ((ops != NULL) && (ops->mask_and_set_register != NULL)) |
| 113 | return ops->mask_and_set_register(dev, bank, |
| 114 | reg, bitmask, bitvalues); |
| 115 | else |
| 116 | return -ENOTSUPP; |
| 117 | } |
| 118 | EXPORT_SYMBOL(abx500_mask_and_set_register_interruptible); |
| 119 | |
| 120 | int abx500_get_chip_id(struct device *dev) |
| 121 | { |
| 122 | struct abx500_ops *ops; |
| 123 | |
| 124 | lookup_ops(dev->parent, &ops); |
| 125 | if ((ops != NULL) && (ops->get_chip_id != NULL)) |
| 126 | return ops->get_chip_id(dev); |
| 127 | else |
| 128 | return -ENOTSUPP; |
| 129 | } |
| 130 | EXPORT_SYMBOL(abx500_get_chip_id); |
| 131 | |
| 132 | int abx500_event_registers_startup_state_get(struct device *dev, u8 *event) |
| 133 | { |
| 134 | struct abx500_ops *ops; |
| 135 | |
| 136 | lookup_ops(dev->parent, &ops); |
| 137 | if ((ops != NULL) && (ops->event_registers_startup_state_get != NULL)) |
| 138 | return ops->event_registers_startup_state_get(dev, event); |
| 139 | else |
| 140 | return -ENOTSUPP; |
| 141 | } |
| 142 | EXPORT_SYMBOL(abx500_event_registers_startup_state_get); |
| 143 | |
| 144 | int abx500_startup_irq_enabled(struct device *dev, unsigned int irq) |
| 145 | { |
| 146 | struct abx500_ops *ops; |
| 147 | |
| 148 | lookup_ops(dev->parent, &ops); |
| 149 | if ((ops != NULL) && (ops->startup_irq_enabled != NULL)) |
| 150 | return ops->startup_irq_enabled(dev, irq); |
| 151 | else |
| 152 | return -ENOTSUPP; |
| 153 | } |
| 154 | EXPORT_SYMBOL(abx500_startup_irq_enabled); |
| 155 | |
| 156 | MODULE_AUTHOR("Mattias Wallin <mattias.wallin@stericsson.com>"); |
| 157 | MODULE_DESCRIPTION("ABX500 core driver"); |
| 158 | MODULE_LICENSE("GPL"); |