blob: a26c1d0014010500f1fef96b400bb8a90a865d5c [file] [log] [blame]
Mark Brownb83a3132011-05-11 19:59:58 +02001#ifndef __LINUX_REGMAP_H
2#define __LINUX_REGMAP_H
3
4/*
5 * Register map access API
6 *
7 * Copyright 2011 Wolfson Microelectronics plc
8 *
9 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 */
15
16#include <linux/device.h>
17#include <linux/list.h>
18#include <linux/module.h>
19
20struct regmap_config {
21 int reg_bits;
22 int val_bits;
23};
24
25typedef int (*regmap_hw_write)(struct device *dev, const void *data,
26 size_t count);
27typedef int (*regmap_hw_gather_write)(struct device *dev,
28 const void *reg, size_t reg_len,
29 const void *val, size_t val_len);
30typedef int (*regmap_hw_read)(struct device *dev,
31 const void *reg_buf, size_t reg_size,
32 void *val_buf, size_t val_size);
33
34/**
35 * Description of a hardware bus for the register map infrastructure.
36 *
37 * @list: Internal use.
38 * @type: Bus type, used to identify bus to be used for a device.
39 * @write: Write operation.
40 * @gather_write: Write operation with split register/value, return -ENOTSUPP
41 * if not implemented on a given device.
42 * @read: Read operation. Data is returned in the buffer used to transmit
43 * data.
44 * @owner: Module with the bus implementation, used to pin the implementation
45 * in memory.
46 * @read_flag_mask: Mask to be set in the top byte of the register when doing
47 * a read.
48 */
49struct regmap_bus {
50 struct list_head list;
51 struct bus_type *type;
52 regmap_hw_write write;
53 regmap_hw_gather_write gather_write;
54 regmap_hw_read read;
55 struct module *owner;
56 u8 read_flag_mask;
57};
58
59struct regmap *regmap_init(struct device *dev,
60 const struct regmap_bus *bus,
61 const struct regmap_config *config);
62void regmap_exit(struct regmap *map);
63int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
64int regmap_raw_write(struct regmap *map, unsigned int reg,
65 const void *val, size_t val_len);
66int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
67int regmap_raw_read(struct regmap *map, unsigned int reg,
68 void *val, size_t val_len);
69int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
70 size_t val_count);
71int regmap_update_bits(struct regmap *map, unsigned int reg,
72 unsigned int mask, unsigned int val);
73
74#endif