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 | dd898b2 | 2011-07-20 22:28:58 +0100 | [diff] [blame] | 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. |
Mark Brown | 2e2ae66 | 2011-07-20 22:33:39 +0100 | [diff] [blame] | 28 | * |
| 29 | * @max_register: Optional, specifies the maximum valid register index. |
Mark Brown | 3566cc9 | 2011-08-09 10:23:22 +0900 | [diff] [blame^] | 30 | * @writeable_reg: Optional callback returning true if the register |
| 31 | * can be written to. |
| 32 | * @readable_reg: Optional callback returning true if the register |
| 33 | * can be read from. |
| 34 | * @volatile_reg: Optional callback returning true if the register |
| 35 | * value can't be cached. |
| 36 | * @precious_reg: Optional callback returning true if the rgister |
| 37 | * should not be read outside of a call from the driver |
| 38 | * (eg, a clear on read interrupt status register). |
Mark Brown | dd898b2 | 2011-07-20 22:28:58 +0100 | [diff] [blame] | 39 | */ |
Mark Brown | b83a313 | 2011-05-11 19:59:58 +0200 | [diff] [blame] | 40 | struct regmap_config { |
| 41 | int reg_bits; |
| 42 | int val_bits; |
Mark Brown | 2e2ae66 | 2011-07-20 22:33:39 +0100 | [diff] [blame] | 43 | |
| 44 | unsigned int max_register; |
| 45 | bool (*writeable_reg)(struct device *dev, unsigned int reg); |
| 46 | bool (*readable_reg)(struct device *dev, unsigned int reg); |
| 47 | bool (*volatile_reg)(struct device *dev, unsigned int reg); |
Mark Brown | 1869488 | 2011-08-08 15:40:22 +0900 | [diff] [blame] | 48 | bool (*precious_reg)(struct device *dev, unsigned int reg); |
Mark Brown | b83a313 | 2011-05-11 19:59:58 +0200 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | typedef int (*regmap_hw_write)(struct device *dev, const void *data, |
| 52 | size_t count); |
| 53 | typedef int (*regmap_hw_gather_write)(struct device *dev, |
| 54 | const void *reg, size_t reg_len, |
| 55 | const void *val, size_t val_len); |
| 56 | typedef int (*regmap_hw_read)(struct device *dev, |
| 57 | const void *reg_buf, size_t reg_size, |
| 58 | void *val_buf, size_t val_size); |
| 59 | |
| 60 | /** |
| 61 | * Description of a hardware bus for the register map infrastructure. |
| 62 | * |
| 63 | * @list: Internal use. |
| 64 | * @type: Bus type, used to identify bus to be used for a device. |
| 65 | * @write: Write operation. |
| 66 | * @gather_write: Write operation with split register/value, return -ENOTSUPP |
| 67 | * if not implemented on a given device. |
| 68 | * @read: Read operation. Data is returned in the buffer used to transmit |
| 69 | * data. |
| 70 | * @owner: Module with the bus implementation, used to pin the implementation |
| 71 | * in memory. |
| 72 | * @read_flag_mask: Mask to be set in the top byte of the register when doing |
| 73 | * a read. |
| 74 | */ |
| 75 | struct regmap_bus { |
| 76 | struct list_head list; |
| 77 | struct bus_type *type; |
| 78 | regmap_hw_write write; |
| 79 | regmap_hw_gather_write gather_write; |
| 80 | regmap_hw_read read; |
| 81 | struct module *owner; |
| 82 | u8 read_flag_mask; |
| 83 | }; |
| 84 | |
| 85 | struct regmap *regmap_init(struct device *dev, |
| 86 | const struct regmap_bus *bus, |
| 87 | const struct regmap_config *config); |
Mark Brown | 9943fa3 | 2011-06-20 19:02:29 +0100 | [diff] [blame] | 88 | struct regmap *regmap_init_i2c(struct i2c_client *i2c, |
| 89 | const struct regmap_config *config); |
Mark Brown | a676f08 | 2011-05-12 11:42:10 +0200 | [diff] [blame] | 90 | struct regmap *regmap_init_spi(struct spi_device *dev, |
| 91 | const struct regmap_config *config); |
| 92 | |
Mark Brown | b83a313 | 2011-05-11 19:59:58 +0200 | [diff] [blame] | 93 | void regmap_exit(struct regmap *map); |
| 94 | int regmap_write(struct regmap *map, unsigned int reg, unsigned int val); |
| 95 | int regmap_raw_write(struct regmap *map, unsigned int reg, |
| 96 | const void *val, size_t val_len); |
| 97 | int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val); |
| 98 | int regmap_raw_read(struct regmap *map, unsigned int reg, |
| 99 | void *val, size_t val_len); |
| 100 | int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val, |
| 101 | size_t val_count); |
| 102 | int regmap_update_bits(struct regmap *map, unsigned int reg, |
| 103 | unsigned int mask, unsigned int val); |
| 104 | |
| 105 | #endif |