blob: 5ba61f22c7033af6ea166166b7b9451e5c0af45a [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
Mark Brown9943fa32011-06-20 19:02:29 +010020struct i2c_client;
21
Mark Brownb83a3132011-05-11 19:59:58 +020022struct regmap_config {
23 int reg_bits;
24 int val_bits;
25};
26
27typedef int (*regmap_hw_write)(struct device *dev, const void *data,
28 size_t count);
29typedef int (*regmap_hw_gather_write)(struct device *dev,
30 const void *reg, size_t reg_len,
31 const void *val, size_t val_len);
32typedef int (*regmap_hw_read)(struct device *dev,
33 const void *reg_buf, size_t reg_size,
34 void *val_buf, size_t val_size);
35
36/**
37 * Description of a hardware bus for the register map infrastructure.
38 *
39 * @list: Internal use.
40 * @type: Bus type, used to identify bus to be used for a device.
41 * @write: Write operation.
42 * @gather_write: Write operation with split register/value, return -ENOTSUPP
43 * if not implemented on a given device.
44 * @read: Read operation. Data is returned in the buffer used to transmit
45 * data.
46 * @owner: Module with the bus implementation, used to pin the implementation
47 * in memory.
48 * @read_flag_mask: Mask to be set in the top byte of the register when doing
49 * a read.
50 */
51struct regmap_bus {
52 struct list_head list;
53 struct bus_type *type;
54 regmap_hw_write write;
55 regmap_hw_gather_write gather_write;
56 regmap_hw_read read;
57 struct module *owner;
58 u8 read_flag_mask;
59};
60
61struct regmap *regmap_init(struct device *dev,
62 const struct regmap_bus *bus,
63 const struct regmap_config *config);
Mark Brown9943fa32011-06-20 19:02:29 +010064struct regmap *regmap_init_i2c(struct i2c_client *i2c,
65 const struct regmap_config *config);
Mark Brownb83a3132011-05-11 19:59:58 +020066void regmap_exit(struct regmap *map);
67int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
68int regmap_raw_write(struct regmap *map, unsigned int reg,
69 const void *val, size_t val_len);
70int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
71int regmap_raw_read(struct regmap *map, unsigned int reg,
72 void *val, size_t val_len);
73int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
74 size_t val_count);
75int regmap_update_bits(struct regmap *map, unsigned int reg,
76 unsigned int mask, unsigned int val);
77
78#endif