1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2007-2010 ST-Ericsson
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/init.h>
12 #include <linux/export.h>
13 #include <linux/mfd/abx500.h>
15 static LIST_HEAD(abx500_list
);
17 struct abx500_device_entry
{
18 struct list_head list
;
19 struct abx500_ops ops
;
23 static void lookup_ops(struct device
*dev
, struct abx500_ops
**ops
)
25 struct abx500_device_entry
*dev_entry
;
28 list_for_each_entry(dev_entry
, &abx500_list
, list
) {
29 if (dev_entry
->dev
== dev
) {
30 *ops
= &dev_entry
->ops
;
36 int abx500_register_ops(struct device
*dev
, struct abx500_ops
*ops
)
38 struct abx500_device_entry
*dev_entry
;
40 dev_entry
= devm_kzalloc(dev
, sizeof(*dev_entry
), GFP_KERNEL
);
45 memcpy(&dev_entry
->ops
, ops
, sizeof(*ops
));
47 list_add_tail(&dev_entry
->list
, &abx500_list
);
50 EXPORT_SYMBOL(abx500_register_ops
);
52 void abx500_remove_ops(struct device
*dev
)
54 struct abx500_device_entry
*dev_entry
, *tmp
;
56 list_for_each_entry_safe(dev_entry
, tmp
, &abx500_list
, list
)
57 if (dev_entry
->dev
== dev
)
58 list_del(&dev_entry
->list
);
60 EXPORT_SYMBOL(abx500_remove_ops
);
62 int abx500_set_register_interruptible(struct device
*dev
, u8 bank
, u8 reg
,
65 struct abx500_ops
*ops
;
67 lookup_ops(dev
->parent
, &ops
);
68 if (ops
&& ops
->set_register
)
69 return ops
->set_register(dev
, bank
, reg
, value
);
73 EXPORT_SYMBOL(abx500_set_register_interruptible
);
75 int abx500_get_register_interruptible(struct device
*dev
, u8 bank
, u8 reg
,
78 struct abx500_ops
*ops
;
80 lookup_ops(dev
->parent
, &ops
);
81 if (ops
&& ops
->get_register
)
82 return ops
->get_register(dev
, bank
, reg
, value
);
86 EXPORT_SYMBOL(abx500_get_register_interruptible
);
88 int abx500_get_register_page_interruptible(struct device
*dev
, u8 bank
,
89 u8 first_reg
, u8
*regvals
, u8 numregs
)
91 struct abx500_ops
*ops
;
93 lookup_ops(dev
->parent
, &ops
);
94 if (ops
&& ops
->get_register_page
)
95 return ops
->get_register_page(dev
, bank
,
96 first_reg
, regvals
, numregs
);
100 EXPORT_SYMBOL(abx500_get_register_page_interruptible
);
102 int abx500_mask_and_set_register_interruptible(struct device
*dev
, u8 bank
,
103 u8 reg
, u8 bitmask
, u8 bitvalues
)
105 struct abx500_ops
*ops
;
107 lookup_ops(dev
->parent
, &ops
);
108 if (ops
&& ops
->mask_and_set_register
)
109 return ops
->mask_and_set_register(dev
, bank
,
110 reg
, bitmask
, bitvalues
);
114 EXPORT_SYMBOL(abx500_mask_and_set_register_interruptible
);
116 int abx500_get_chip_id(struct device
*dev
)
118 struct abx500_ops
*ops
;
120 lookup_ops(dev
->parent
, &ops
);
121 if (ops
&& ops
->get_chip_id
)
122 return ops
->get_chip_id(dev
);
126 EXPORT_SYMBOL(abx500_get_chip_id
);
128 int abx500_event_registers_startup_state_get(struct device
*dev
, u8
*event
)
130 struct abx500_ops
*ops
;
132 lookup_ops(dev
->parent
, &ops
);
133 if (ops
&& ops
->event_registers_startup_state_get
)
134 return ops
->event_registers_startup_state_get(dev
, event
);
138 EXPORT_SYMBOL(abx500_event_registers_startup_state_get
);
140 int abx500_startup_irq_enabled(struct device
*dev
, unsigned int irq
)
142 struct abx500_ops
*ops
;
144 lookup_ops(dev
->parent
, &ops
);
145 if (ops
&& ops
->startup_irq_enabled
)
146 return ops
->startup_irq_enabled(dev
, irq
);
150 EXPORT_SYMBOL(abx500_startup_irq_enabled
);