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