]>
Commit | Line | Data |
---|---|---|
b83a313b MB |
1 | #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 | ||
9943fa30 | 20 | struct i2c_client; |
a676f083 | 21 | struct spi_device; |
9943fa30 | 22 | |
dd898b20 MB |
23 | /** |
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. | |
2e2ae66d MB |
28 | * |
29 | * @max_register: Optional, specifies the maximum valid register index. | |
30 | * @writeable_register: Optional callback returning true if the register | |
31 | * can be written to. | |
32 | * @readable_register: Optional callback returning true if the register | |
33 | * can be read from. | |
34 | * @volatile_register: Optional callback returning true if the register | |
35 | * value can't be cached. | |
dd898b20 | 36 | */ |
b83a313b MB |
37 | struct regmap_config { |
38 | int reg_bits; | |
39 | int val_bits; | |
2e2ae66d MB |
40 | |
41 | unsigned int max_register; | |
42 | bool (*writeable_reg)(struct device *dev, unsigned int reg); | |
43 | bool (*readable_reg)(struct device *dev, unsigned int reg); | |
44 | bool (*volatile_reg)(struct device *dev, unsigned int reg); | |
b83a313b MB |
45 | }; |
46 | ||
47 | typedef int (*regmap_hw_write)(struct device *dev, const void *data, | |
48 | size_t count); | |
49 | typedef int (*regmap_hw_gather_write)(struct device *dev, | |
50 | const void *reg, size_t reg_len, | |
51 | const void *val, size_t val_len); | |
52 | typedef int (*regmap_hw_read)(struct device *dev, | |
53 | const void *reg_buf, size_t reg_size, | |
54 | void *val_buf, size_t val_size); | |
55 | ||
56 | /** | |
57 | * Description of a hardware bus for the register map infrastructure. | |
58 | * | |
59 | * @list: Internal use. | |
60 | * @type: Bus type, used to identify bus to be used for a device. | |
61 | * @write: Write operation. | |
62 | * @gather_write: Write operation with split register/value, return -ENOTSUPP | |
63 | * if not implemented on a given device. | |
64 | * @read: Read operation. Data is returned in the buffer used to transmit | |
65 | * data. | |
66 | * @owner: Module with the bus implementation, used to pin the implementation | |
67 | * in memory. | |
68 | * @read_flag_mask: Mask to be set in the top byte of the register when doing | |
69 | * a read. | |
70 | */ | |
71 | struct regmap_bus { | |
72 | struct list_head list; | |
73 | struct bus_type *type; | |
74 | regmap_hw_write write; | |
75 | regmap_hw_gather_write gather_write; | |
76 | regmap_hw_read read; | |
77 | struct module *owner; | |
78 | u8 read_flag_mask; | |
79 | }; | |
80 | ||
81 | struct regmap *regmap_init(struct device *dev, | |
82 | const struct regmap_bus *bus, | |
83 | const struct regmap_config *config); | |
9943fa30 MB |
84 | struct regmap *regmap_init_i2c(struct i2c_client *i2c, |
85 | const struct regmap_config *config); | |
a676f083 MB |
86 | struct regmap *regmap_init_spi(struct spi_device *dev, |
87 | const struct regmap_config *config); | |
88 | ||
b83a313b MB |
89 | void regmap_exit(struct regmap *map); |
90 | int regmap_write(struct regmap *map, unsigned int reg, unsigned int val); | |
91 | int regmap_raw_write(struct regmap *map, unsigned int reg, | |
92 | const void *val, size_t val_len); | |
93 | int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val); | |
94 | int regmap_raw_read(struct regmap *map, unsigned int reg, | |
95 | void *val, size_t val_len); | |
96 | int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val, | |
97 | size_t val_count); | |
98 | int regmap_update_bits(struct regmap *map, unsigned int reg, | |
99 | unsigned int mask, unsigned int val); | |
100 | ||
101 | #endif |