diff options
Diffstat (limited to 'include/linux/regmap.h')
| -rw-r--r-- | include/linux/regmap.h | 95 |
1 files changed, 88 insertions, 7 deletions
diff --git a/include/linux/regmap.h b/include/linux/regmap.h index e3bcc3f4dcb8..b7e95bf942c9 100644 --- a/include/linux/regmap.h +++ b/include/linux/regmap.h | |||
| @@ -19,6 +19,7 @@ | |||
| 19 | struct module; | 19 | struct module; |
| 20 | struct device; | 20 | struct device; |
| 21 | struct i2c_client; | 21 | struct i2c_client; |
| 22 | struct irq_domain; | ||
| 22 | struct spi_device; | 23 | struct spi_device; |
| 23 | struct regmap; | 24 | struct regmap; |
| 24 | struct regmap_range_cfg; | 25 | struct regmap_range_cfg; |
| @@ -54,6 +55,39 @@ enum regmap_endian { | |||
| 54 | }; | 55 | }; |
| 55 | 56 | ||
| 56 | /** | 57 | /** |
| 58 | * A register range, used for access related checks | ||
| 59 | * (readable/writeable/volatile/precious checks) | ||
| 60 | * | ||
| 61 | * @range_min: address of first register | ||
| 62 | * @range_max: address of last register | ||
| 63 | */ | ||
| 64 | struct regmap_range { | ||
| 65 | unsigned int range_min; | ||
| 66 | unsigned int range_max; | ||
| 67 | }; | ||
| 68 | |||
| 69 | /* | ||
| 70 | * A table of ranges including some yes ranges and some no ranges. | ||
| 71 | * If a register belongs to a no_range, the corresponding check function | ||
| 72 | * will return false. If a register belongs to a yes range, the corresponding | ||
| 73 | * check function will return true. "no_ranges" are searched first. | ||
| 74 | * | ||
| 75 | * @yes_ranges : pointer to an array of regmap ranges used as "yes ranges" | ||
| 76 | * @n_yes_ranges: size of the above array | ||
| 77 | * @no_ranges: pointer to an array of regmap ranges used as "no ranges" | ||
| 78 | * @n_no_ranges: size of the above array | ||
| 79 | */ | ||
| 80 | struct regmap_access_table { | ||
| 81 | const struct regmap_range *yes_ranges; | ||
| 82 | unsigned int n_yes_ranges; | ||
| 83 | const struct regmap_range *no_ranges; | ||
| 84 | unsigned int n_no_ranges; | ||
| 85 | }; | ||
| 86 | |||
| 87 | typedef void (*regmap_lock)(void *); | ||
| 88 | typedef void (*regmap_unlock)(void *); | ||
| 89 | |||
| 90 | /** | ||
| 57 | * Configuration for the register map of a device. | 91 | * Configuration for the register map of a device. |
| 58 | * | 92 | * |
| 59 | * @name: Optional name of the regmap. Useful when a device has multiple | 93 | * @name: Optional name of the regmap. Useful when a device has multiple |
| @@ -67,16 +101,39 @@ enum regmap_endian { | |||
| 67 | * @val_bits: Number of bits in a register value, mandatory. | 101 | * @val_bits: Number of bits in a register value, mandatory. |
| 68 | * | 102 | * |
| 69 | * @writeable_reg: Optional callback returning true if the register | 103 | * @writeable_reg: Optional callback returning true if the register |
| 70 | * can be written to. | 104 | * can be written to. If this field is NULL but wr_table |
| 105 | * (see below) is not, the check is performed on such table | ||
| 106 | * (a register is writeable if it belongs to one of the ranges | ||
| 107 | * specified by wr_table). | ||
| 71 | * @readable_reg: Optional callback returning true if the register | 108 | * @readable_reg: Optional callback returning true if the register |
| 72 | * can be read from. | 109 | * can be read from. If this field is NULL but rd_table |
| 110 | * (see below) is not, the check is performed on such table | ||
| 111 | * (a register is readable if it belongs to one of the ranges | ||
| 112 | * specified by rd_table). | ||
| 73 | * @volatile_reg: Optional callback returning true if the register | 113 | * @volatile_reg: Optional callback returning true if the register |
| 74 | * value can't be cached. | 114 | * value can't be cached. If this field is NULL but |
| 115 | * volatile_table (see below) is not, the check is performed on | ||
| 116 | * such table (a register is volatile if it belongs to one of | ||
| 117 | * the ranges specified by volatile_table). | ||
| 75 | * @precious_reg: Optional callback returning true if the rgister | 118 | * @precious_reg: Optional callback returning true if the rgister |
| 76 | * should not be read outside of a call from the driver | 119 | * should not be read outside of a call from the driver |
| 77 | * (eg, a clear on read interrupt status register). | 120 | * (eg, a clear on read interrupt status register). If this |
| 121 | * field is NULL but precious_table (see below) is not, the | ||
| 122 | * check is performed on such table (a register is precious if | ||
| 123 | * it belongs to one of the ranges specified by precious_table). | ||
| 124 | * @lock: Optional lock callback (overrides regmap's default lock | ||
| 125 | * function, based on spinlock or mutex). | ||
| 126 | * @unlock: As above for unlocking. | ||
| 127 | * @lock_arg: this field is passed as the only argument of lock/unlock | ||
| 128 | * functions (ignored in case regular lock/unlock functions | ||
| 129 | * are not overridden). | ||
| 78 | * | 130 | * |
| 79 | * @max_register: Optional, specifies the maximum valid register index. | 131 | * @max_register: Optional, specifies the maximum valid register index. |
| 132 | * @wr_table: Optional, points to a struct regmap_access_table specifying | ||
| 133 | * valid ranges for write access. | ||
| 134 | * @rd_table: As above, for read access. | ||
| 135 | * @volatile_table: As above, for volatile registers. | ||
| 136 | * @precious_table: As above, for precious registers. | ||
| 80 | * @reg_defaults: Power on reset values for registers (for use with | 137 | * @reg_defaults: Power on reset values for registers (for use with |
| 81 | * register cache support). | 138 | * register cache support). |
| 82 | * @num_reg_defaults: Number of elements in reg_defaults. | 139 | * @num_reg_defaults: Number of elements in reg_defaults. |
| @@ -116,8 +173,15 @@ struct regmap_config { | |||
| 116 | bool (*readable_reg)(struct device *dev, unsigned int reg); | 173 | bool (*readable_reg)(struct device *dev, unsigned int reg); |
| 117 | bool (*volatile_reg)(struct device *dev, unsigned int reg); | 174 | bool (*volatile_reg)(struct device *dev, unsigned int reg); |
| 118 | bool (*precious_reg)(struct device *dev, unsigned int reg); | 175 | bool (*precious_reg)(struct device *dev, unsigned int reg); |
| 176 | regmap_lock lock; | ||
| 177 | regmap_unlock unlock; | ||
| 178 | void *lock_arg; | ||
| 119 | 179 | ||
| 120 | unsigned int max_register; | 180 | unsigned int max_register; |
| 181 | const struct regmap_access_table *wr_table; | ||
| 182 | const struct regmap_access_table *rd_table; | ||
| 183 | const struct regmap_access_table *volatile_table; | ||
| 184 | const struct regmap_access_table *precious_table; | ||
| 121 | const struct reg_default *reg_defaults; | 185 | const struct reg_default *reg_defaults; |
| 122 | unsigned int num_reg_defaults; | 186 | unsigned int num_reg_defaults; |
| 123 | enum regcache_type cache_type; | 187 | enum regcache_type cache_type; |
| @@ -133,7 +197,7 @@ struct regmap_config { | |||
| 133 | enum regmap_endian val_format_endian; | 197 | enum regmap_endian val_format_endian; |
| 134 | 198 | ||
| 135 | const struct regmap_range_cfg *ranges; | 199 | const struct regmap_range_cfg *ranges; |
| 136 | unsigned int n_ranges; | 200 | unsigned int num_ranges; |
| 137 | }; | 201 | }; |
| 138 | 202 | ||
| 139 | /** | 203 | /** |
| @@ -142,6 +206,8 @@ struct regmap_config { | |||
| 142 | * 1. page selector register update; | 206 | * 1. page selector register update; |
| 143 | * 2. access through data window registers. | 207 | * 2. access through data window registers. |
| 144 | * | 208 | * |
| 209 | * @name: Descriptive name for diagnostics | ||
| 210 | * | ||
| 145 | * @range_min: Address of the lowest register address in virtual range. | 211 | * @range_min: Address of the lowest register address in virtual range. |
| 146 | * @range_max: Address of the highest register in virtual range. | 212 | * @range_max: Address of the highest register in virtual range. |
| 147 | * | 213 | * |
| @@ -153,6 +219,8 @@ struct regmap_config { | |||
| 153 | * @window_len: Number of registers in data window. | 219 | * @window_len: Number of registers in data window. |
| 154 | */ | 220 | */ |
| 155 | struct regmap_range_cfg { | 221 | struct regmap_range_cfg { |
| 222 | const char *name; | ||
| 223 | |||
| 156 | /* Registers of virtual address range */ | 224 | /* Registers of virtual address range */ |
| 157 | unsigned int range_min; | 225 | unsigned int range_min; |
| 158 | unsigned int range_max; | 226 | unsigned int range_max; |
| @@ -181,7 +249,9 @@ typedef void (*regmap_hw_free_context)(void *context); | |||
| 181 | * Description of a hardware bus for the register map infrastructure. | 249 | * Description of a hardware bus for the register map infrastructure. |
| 182 | * | 250 | * |
| 183 | * @fast_io: Register IO is fast. Use a spinlock instead of a mutex | 251 | * @fast_io: Register IO is fast. Use a spinlock instead of a mutex |
| 184 | * to perform locking. | 252 | * to perform locking. This field is ignored if custom lock/unlock |
| 253 | * functions are used (see fields lock/unlock of | ||
| 254 | * struct regmap_config). | ||
| 185 | * @write: Write operation. | 255 | * @write: Write operation. |
| 186 | * @gather_write: Write operation with split register/value, return -ENOTSUPP | 256 | * @gather_write: Write operation with split register/value, return -ENOTSUPP |
| 187 | * if not implemented on a given device. | 257 | * if not implemented on a given device. |
| @@ -262,6 +332,16 @@ void regcache_mark_dirty(struct regmap *map); | |||
| 262 | int regmap_register_patch(struct regmap *map, const struct reg_default *regs, | 332 | int regmap_register_patch(struct regmap *map, const struct reg_default *regs, |
| 263 | int num_regs); | 333 | int num_regs); |
| 264 | 334 | ||
| 335 | static inline bool regmap_reg_in_range(unsigned int reg, | ||
| 336 | const struct regmap_range *range) | ||
| 337 | { | ||
| 338 | return reg >= range->range_min && reg <= range->range_max; | ||
| 339 | } | ||
| 340 | |||
| 341 | bool regmap_reg_in_ranges(unsigned int reg, | ||
| 342 | const struct regmap_range *ranges, | ||
| 343 | unsigned int nranges); | ||
| 344 | |||
| 265 | /** | 345 | /** |
| 266 | * Description of an IRQ for the generic regmap irq_chip. | 346 | * Description of an IRQ for the generic regmap irq_chip. |
| 267 | * | 347 | * |
| @@ -317,6 +397,7 @@ int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags, | |||
| 317 | void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data); | 397 | void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data); |
| 318 | int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data); | 398 | int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data); |
| 319 | int regmap_irq_get_virq(struct regmap_irq_chip_data *data, int irq); | 399 | int regmap_irq_get_virq(struct regmap_irq_chip_data *data, int irq); |
| 400 | struct irq_domain *regmap_irq_get_domain(struct regmap_irq_chip_data *data); | ||
| 320 | 401 | ||
| 321 | #else | 402 | #else |
| 322 | 403 | ||
