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