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>
8 #include <linux/list.h>
9 #include <linux/slab.h>
10 #include <linux/err.h>
11 #include <linux/module.h>
12 #include <linux/mfd/abx500.h>
14 static LIST_HEAD(abx500_list
);
16 struct abx500_device_entry
{
17 struct list_head list
;
18 struct abx500_ops ops
;
22 static void lookup_ops(struct device
*dev
, struct abx500_ops
**ops
)
24 struct abx500_device_entry
*dev_entry
;
27 list_for_each_entry(dev_entry
, &abx500_list
, list
) {
28 if (dev_entry
->dev
== dev
) {
29 *ops
= &dev_entry
->ops
;
35 int abx500_register_ops(struct device
*dev
, struct abx500_ops
*ops
)
37 struct abx500_device_entry
*dev_entry
;
39 dev_entry
= devm_kzalloc(dev
,
40 sizeof(struct abx500_device_entry
),
43 dev_err(dev
, "register_ops kzalloc failed");
47 memcpy(&dev_entry
->ops
, ops
, sizeof(struct abx500_ops
));
49 list_add_tail(&dev_entry
->list
, &abx500_list
);
52 EXPORT_SYMBOL(abx500_register_ops
);
54 void abx500_remove_ops(struct device
*dev
)
56 struct abx500_device_entry
*dev_entry
, *tmp
;
58 list_for_each_entry_safe(dev_entry
, tmp
, &abx500_list
, list
)
59 if (dev_entry
->dev
== dev
)
60 list_del(&dev_entry
->list
);
62 EXPORT_SYMBOL(abx500_remove_ops
);
64 int abx500_set_register_interruptible(struct device
*dev
, u8 bank
, u8 reg
,
67 struct abx500_ops
*ops
;
69 lookup_ops(dev
->parent
, &ops
);
70 if ((ops
!= NULL
) && (ops
->set_register
!= NULL
))
71 return ops
->set_register(dev
, bank
, reg
, value
);
75 EXPORT_SYMBOL(abx500_set_register_interruptible
);
77 int abx500_get_register_interruptible(struct device
*dev
, u8 bank
, u8 reg
,
80 struct abx500_ops
*ops
;
82 lookup_ops(dev
->parent
, &ops
);
83 if ((ops
!= NULL
) && (ops
->get_register
!= NULL
))
84 return ops
->get_register(dev
, bank
, reg
, value
);
88 EXPORT_SYMBOL(abx500_get_register_interruptible
);
90 int abx500_get_register_page_interruptible(struct device
*dev
, u8 bank
,
91 u8 first_reg
, u8
*regvals
, u8 numregs
)
93 struct abx500_ops
*ops
;
95 lookup_ops(dev
->parent
, &ops
);
96 if ((ops
!= NULL
) && (ops
->get_register_page
!= NULL
))
97 return ops
->get_register_page(dev
, bank
,
98 first_reg
, regvals
, numregs
);
102 EXPORT_SYMBOL(abx500_get_register_page_interruptible
);
104 int abx500_mask_and_set_register_interruptible(struct device
*dev
, u8 bank
,
105 u8 reg
, u8 bitmask
, u8 bitvalues
)
107 struct abx500_ops
*ops
;
109 lookup_ops(dev
->parent
, &ops
);
110 if ((ops
!= NULL
) && (ops
->mask_and_set_register
!= NULL
))
111 return ops
->mask_and_set_register(dev
, bank
,
112 reg
, bitmask
, bitvalues
);
116 EXPORT_SYMBOL(abx500_mask_and_set_register_interruptible
);
118 int abx500_get_chip_id(struct device
*dev
)
120 struct abx500_ops
*ops
;
122 lookup_ops(dev
->parent
, &ops
);
123 if ((ops
!= NULL
) && (ops
->get_chip_id
!= NULL
))
124 return ops
->get_chip_id(dev
);
128 EXPORT_SYMBOL(abx500_get_chip_id
);
130 int abx500_event_registers_startup_state_get(struct device
*dev
, u8
*event
)
132 struct abx500_ops
*ops
;
134 lookup_ops(dev
->parent
, &ops
);
135 if ((ops
!= NULL
) && (ops
->event_registers_startup_state_get
!= NULL
))
136 return ops
->event_registers_startup_state_get(dev
, event
);
140 EXPORT_SYMBOL(abx500_event_registers_startup_state_get
);
142 int abx500_startup_irq_enabled(struct device
*dev
, unsigned int irq
)
144 struct abx500_ops
*ops
;
146 lookup_ops(dev
->parent
, &ops
);
147 if ((ops
!= NULL
) && (ops
->startup_irq_enabled
!= NULL
))
148 return ops
->startup_irq_enabled(dev
, irq
);
152 EXPORT_SYMBOL(abx500_startup_irq_enabled
);
154 MODULE_AUTHOR("Mattias Wallin <mattias.wallin@stericsson.com>");
155 MODULE_DESCRIPTION("ABX500 core driver");
156 MODULE_LICENSE("GPL");