diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-10-25 07:57:45 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-10-25 07:57:45 -0400 |
| commit | 4e7e2a2008f5d8c49791c412849d5b0232d39bb3 (patch) | |
| tree | 32c3fa2d5cefb388689cb795225022769bf7b413 | |
| parent | 8a9ea3237e7eb5c25f09e429ad242ae5a3d5ea22 (diff) | |
| parent | 7cccbdc84487616c3dbe493b04bfa1f362f4bc56 (diff) | |
Merge branch 'for-linus' of git://opensource.wolfsonmicro.com/regmap
* 'for-linus' of git://opensource.wolfsonmicro.com/regmap: (62 commits)
mfd: Enable rbtree cache for wm831x devices
regmap: Support some block operations on cached devices
regmap: Allow caches for devices with no defaults
regmap: Ensure rbtree syncs registers set to zero properly
regmap: Allow rbtree to cache zero default values
regmap: Warn on raw I/O as well as bulk reads that bypass cache
regmap: Return a sensible error code if we fail to read the cache
regmap: Use bsearch() to search the register defaults
regmap: Fix doc comment
regmap: Optimize the lookup path to use binary search
regmap: Ensure we scream if we enable cache bypass/only at the same time
regmap: Implement regcache_cache_bypass helper function
regmap: Save/restore the bypass state upon syncing
regmap: Lock the sync path, ensure we use the lockless _regmap_write()
regmap: Fix apostrophe usage
regmap: Make _regmap_write() global
regmap: Fix lock used for regcache_cache_only()
regmap: Grab the lock in regcache_cache_only()
regmap: Modify map->cache_bypass directly
regmap: Fix regcache_sync generic implementation
...
| -rw-r--r-- | drivers/base/regmap/Kconfig | 2 | ||||
| -rw-r--r-- | drivers/base/regmap/Makefile | 3 | ||||
| -rw-r--r-- | drivers/base/regmap/internal.h | 128 | ||||
| -rw-r--r-- | drivers/base/regmap/regcache-indexed.c | 64 | ||||
| -rw-r--r-- | drivers/base/regmap/regcache-lzo.c | 361 | ||||
| -rw-r--r-- | drivers/base/regmap/regcache-rbtree.c | 345 | ||||
| -rw-r--r-- | drivers/base/regmap/regcache.c | 401 | ||||
| -rw-r--r-- | drivers/base/regmap/regmap-debugfs.c | 209 | ||||
| -rw-r--r-- | drivers/base/regmap/regmap-i2c.c | 2 | ||||
| -rw-r--r-- | drivers/base/regmap/regmap-spi.c | 2 | ||||
| -rw-r--r-- | drivers/base/regmap/regmap.c | 221 | ||||
| -rw-r--r-- | drivers/mfd/Kconfig | 3 | ||||
| -rw-r--r-- | drivers/mfd/wm831x-core.c | 437 | ||||
| -rw-r--r-- | drivers/mfd/wm831x-i2c.c | 76 | ||||
| -rw-r--r-- | drivers/mfd/wm831x-spi.c | 204 | ||||
| -rw-r--r-- | drivers/mfd/wm8400-core.c | 106 | ||||
| -rw-r--r-- | drivers/mfd/wm8994-core.c | 178 | ||||
| -rw-r--r-- | include/linux/mfd/wm831x/core.h | 12 | ||||
| -rw-r--r-- | include/linux/mfd/wm831x/pdata.h | 3 | ||||
| -rw-r--r-- | include/linux/mfd/wm8400-private.h | 7 | ||||
| -rw-r--r-- | include/linux/mfd/wm8994/core.h | 9 | ||||
| -rw-r--r-- | include/linux/regmap.h | 79 | ||||
| -rw-r--r-- | include/trace/events/regmap.h | 136 |
23 files changed, 2421 insertions, 567 deletions
diff --git a/drivers/base/regmap/Kconfig b/drivers/base/regmap/Kconfig index fabbf6cc5367..2fc6a66f39a4 100644 --- a/drivers/base/regmap/Kconfig +++ b/drivers/base/regmap/Kconfig | |||
| @@ -4,6 +4,8 @@ | |||
| 4 | 4 | ||
| 5 | config REGMAP | 5 | config REGMAP |
| 6 | default y if (REGMAP_I2C || REGMAP_SPI) | 6 | default y if (REGMAP_I2C || REGMAP_SPI) |
| 7 | select LZO_COMPRESS | ||
| 8 | select LZO_DECOMPRESS | ||
| 7 | bool | 9 | bool |
| 8 | 10 | ||
| 9 | config REGMAP_I2C | 11 | config REGMAP_I2C |
diff --git a/drivers/base/regmap/Makefile b/drivers/base/regmap/Makefile index f476f4571295..0573c8a9dacb 100644 --- a/drivers/base/regmap/Makefile +++ b/drivers/base/regmap/Makefile | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | obj-$(CONFIG_REGMAP) += regmap.o | 1 | obj-$(CONFIG_REGMAP) += regmap.o regcache.o regcache-indexed.o regcache-rbtree.o regcache-lzo.o |
| 2 | obj-$(CONFIG_DEBUG_FS) += regmap-debugfs.o | ||
| 2 | obj-$(CONFIG_REGMAP_I2C) += regmap-i2c.o | 3 | obj-$(CONFIG_REGMAP_I2C) += regmap-i2c.o |
| 3 | obj-$(CONFIG_REGMAP_SPI) += regmap-spi.o | 4 | obj-$(CONFIG_REGMAP_SPI) += regmap-spi.o |
diff --git a/drivers/base/regmap/internal.h b/drivers/base/regmap/internal.h new file mode 100644 index 000000000000..348ff02eb93e --- /dev/null +++ b/drivers/base/regmap/internal.h | |||
| @@ -0,0 +1,128 @@ | |||
| 1 | /* | ||
| 2 | * Register map access API internal header | ||
| 3 | * | ||
| 4 | * Copyright 2011 Wolfson Microelectronics plc | ||
| 5 | * | ||
| 6 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> | ||
| 7 | * | ||
| 8 | * This program is free software; you can redistribute it and/or modify | ||
| 9 | * it under the terms of the GNU General Public License version 2 as | ||
| 10 | * published by the Free Software Foundation. | ||
| 11 | */ | ||
| 12 | |||
| 13 | #ifndef _REGMAP_INTERNAL_H | ||
| 14 | #define _REGMAP_INTERNAL_H | ||
| 15 | |||
| 16 | #include <linux/regmap.h> | ||
| 17 | #include <linux/fs.h> | ||
| 18 | |||
| 19 | struct regmap; | ||
| 20 | struct regcache_ops; | ||
| 21 | |||
| 22 | struct regmap_format { | ||
| 23 | size_t buf_size; | ||
| 24 | size_t reg_bytes; | ||
| 25 | size_t val_bytes; | ||
| 26 | void (*format_write)(struct regmap *map, | ||
| 27 | unsigned int reg, unsigned int val); | ||
| 28 | void (*format_reg)(void *buf, unsigned int reg); | ||
| 29 | void (*format_val)(void *buf, unsigned int val); | ||
| 30 | unsigned int (*parse_val)(void *buf); | ||
| 31 | }; | ||
| 32 | |||
| 33 | struct regmap { | ||
| 34 | struct mutex lock; | ||
| 35 | |||
| 36 | struct device *dev; /* Device we do I/O on */ | ||
| 37 | void *work_buf; /* Scratch buffer used to format I/O */ | ||
| 38 | struct regmap_format format; /* Buffer format */ | ||
| 39 | const struct regmap_bus *bus; | ||
| 40 | |||
| 41 | #ifdef CONFIG_DEBUG_FS | ||
| 42 | struct dentry *debugfs; | ||
| 43 | #endif | ||
| 44 | |||
| 45 | unsigned int max_register; | ||
| 46 | bool (*writeable_reg)(struct device *dev, unsigned int reg); | ||
| 47 | bool (*readable_reg)(struct device *dev, unsigned int reg); | ||
| 48 | bool (*volatile_reg)(struct device *dev, unsigned int reg); | ||
| 49 | bool (*precious_reg)(struct device *dev, unsigned int reg); | ||
| 50 | |||
| 51 | u8 read_flag_mask; | ||
| 52 | u8 write_flag_mask; | ||
| 53 | |||
| 54 | /* regcache specific members */ | ||
| 55 | const struct regcache_ops *cache_ops; | ||
| 56 | enum regcache_type cache_type; | ||
| 57 | |||
| 58 | /* number of bytes in reg_defaults_raw */ | ||
| 59 | unsigned int cache_size_raw; | ||
| 60 | /* number of bytes per word in reg_defaults_raw */ | ||
| 61 | unsigned int cache_word_size; | ||
| 62 | /* number of entries in reg_defaults */ | ||
| 63 | unsigned int num_reg_defaults; | ||
| 64 | /* number of entries in reg_defaults_raw */ | ||
| 65 | unsigned int num_reg_defaults_raw; | ||
| 66 | |||
| 67 | /* if set, only the cache is modified not the HW */ | ||
| 68 | unsigned int cache_only:1; | ||
| 69 | /* if set, only the HW is modified not the cache */ | ||
| 70 | unsigned int cache_bypass:1; | ||
| 71 | /* if set, remember to free reg_defaults_raw */ | ||
| 72 | unsigned int cache_free:1; | ||
| 73 | |||
| 74 | struct reg_default *reg_defaults; | ||
| 75 | const void *reg_defaults_raw; | ||
| 76 | void *cache; | ||
| 77 | }; | ||
| 78 | |||
| 79 | struct regcache_ops { | ||
| 80 | const char *name; | ||
| 81 | enum regcache_type type; | ||
| 82 | int (*init)(struct regmap *map); | ||
| 83 | int (*exit)(struct regmap *map); | ||
| 84 | int (*read)(struct regmap *map, unsigned int reg, unsigned int *value); | ||
| 85 | int (*write)(struct regmap *map, unsigned int reg, unsigned int value); | ||
| 86 | int (*sync)(struct regmap *map); | ||
| 87 | }; | ||
| 88 | |||
| 89 | bool regmap_writeable(struct regmap *map, unsigned int reg); | ||
| 90 | bool regmap_readable(struct regmap *map, unsigned int reg); | ||
| 91 | bool regmap_volatile(struct regmap *map, unsigned int reg); | ||
| 92 | bool regmap_precious(struct regmap *map, unsigned int reg); | ||
| 93 | |||
| 94 | int _regmap_write(struct regmap *map, unsigned int reg, | ||
| 95 | unsigned int val); | ||
| 96 | |||
| 97 | #ifdef CONFIG_DEBUG_FS | ||
| 98 | extern void regmap_debugfs_initcall(void); | ||
| 99 | extern void regmap_debugfs_init(struct regmap *map); | ||
| 100 | extern void regmap_debugfs_exit(struct regmap *map); | ||
| 101 | #else | ||
| 102 | static inline void regmap_debugfs_initcall(void) { } | ||
| 103 | static inline void regmap_debugfs_init(struct regmap *map) { } | ||
| 104 | static inline void regmap_debugfs_exit(struct regmap *map) { } | ||
| 105 | #endif | ||
| 106 | |||
| 107 | /* regcache core declarations */ | ||
| 108 | int regcache_init(struct regmap *map); | ||
| 109 | void regcache_exit(struct regmap *map); | ||
| 110 | int regcache_read(struct regmap *map, | ||
| 111 | unsigned int reg, unsigned int *value); | ||
| 112 | int regcache_write(struct regmap *map, | ||
| 113 | unsigned int reg, unsigned int value); | ||
| 114 | int regcache_sync(struct regmap *map); | ||
| 115 | |||
| 116 | unsigned int regcache_get_val(const void *base, unsigned int idx, | ||
| 117 | unsigned int word_size); | ||
| 118 | bool regcache_set_val(void *base, unsigned int idx, | ||
| 119 | unsigned int val, unsigned int word_size); | ||
| 120 | int regcache_lookup_reg(struct regmap *map, unsigned int reg); | ||
| 121 | int regcache_insert_reg(struct regmap *map, unsigned int reg, | ||
| 122 | unsigned int val); | ||
| 123 | |||
| 124 | extern struct regcache_ops regcache_indexed_ops; | ||
| 125 | extern struct regcache_ops regcache_rbtree_ops; | ||
| 126 | extern struct regcache_ops regcache_lzo_ops; | ||
| 127 | |||
| 128 | #endif | ||
diff --git a/drivers/base/regmap/regcache-indexed.c b/drivers/base/regmap/regcache-indexed.c new file mode 100644 index 000000000000..507731ad8ec1 --- /dev/null +++ b/drivers/base/regmap/regcache-indexed.c | |||
| @@ -0,0 +1,64 @@ | |||
| 1 | /* | ||
| 2 | * Register cache access API - indexed caching support | ||
| 3 | * | ||
| 4 | * Copyright 2011 Wolfson Microelectronics plc | ||
| 5 | * | ||
| 6 | * Author: Dimitris Papastamos <dp@opensource.wolfsonmicro.com> | ||
| 7 | * | ||
| 8 | * This program is free software; you can redistribute it and/or modify | ||
| 9 | * it under the terms of the GNU General Public License version 2 as | ||
| 10 | * published by the Free Software Foundation. | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include <linux/slab.h> | ||
| 14 | |||
| 15 | #include "internal.h" | ||
| 16 | |||
| 17 | static int regcache_indexed_read(struct regmap *map, unsigned int reg, | ||
| 18 | unsigned int *value) | ||
| 19 | { | ||
| 20 | int ret; | ||
| 21 | |||
| 22 | ret = regcache_lookup_reg(map, reg); | ||
| 23 | if (ret >= 0) | ||
| 24 | *value = map->reg_defaults[ret].def; | ||
| 25 | |||
| 26 | return ret; | ||
| 27 | } | ||
| 28 | |||
| 29 | static int regcache_indexed_write(struct regmap *map, unsigned int reg, | ||
| 30 | unsigned int value) | ||
| 31 | { | ||
| 32 | int ret; | ||
| 33 | |||
| 34 | ret = regcache_lookup_reg(map, reg); | ||
| 35 | if (ret < 0) | ||
| 36 | return regcache_insert_reg(map, reg, value); | ||
| 37 | map->reg_defaults[ret].def = value; | ||
| 38 | return 0; | ||
| 39 | } | ||
| 40 | |||
| 41 | static int regcache_indexed_sync(struct regmap *map) | ||
| 42 | { | ||
| 43 | unsigned int i; | ||
| 44 | int ret; | ||
| 45 | |||
| 46 | for (i = 0; i < map->num_reg_defaults; i++) { | ||
| 47 | ret = _regmap_write(map, map->reg_defaults[i].reg, | ||
| 48 | map->reg_defaults[i].def); | ||
| 49 | if (ret < 0) | ||
| 50 | return ret; | ||
| 51 | dev_dbg(map->dev, "Synced register %#x, value %#x\n", | ||
| 52 | map->reg_defaults[i].reg, | ||
| 53 | map->reg_defaults[i].def); | ||
| 54 | } | ||
| 55 | return 0; | ||
| 56 | } | ||
| 57 | |||
| 58 | struct regcache_ops regcache_indexed_ops = { | ||
| 59 | .type = REGCACHE_INDEXED, | ||
| 60 | .name = "indexed", | ||
| 61 | .read = regcache_indexed_read, | ||
| 62 | .write = regcache_indexed_write, | ||
| 63 | .sync = regcache_indexed_sync | ||
| 64 | }; | ||
diff --git a/drivers/base/regmap/regcache-lzo.c b/drivers/base/regmap/regcache-lzo.c new file mode 100644 index 000000000000..066aeece3626 --- /dev/null +++ b/drivers/base/regmap/regcache-lzo.c | |||
| @@ -0,0 +1,361 @@ | |||
| 1 | /* | ||
| 2 | * Register cache access API - LZO caching support | ||
| 3 | * | ||
| 4 | * Copyright 2011 Wolfson Microelectronics plc | ||
| 5 | * | ||
| 6 | * Author: Dimitris Papastamos <dp@opensource.wolfsonmicro.com> | ||
| 7 | * | ||
| 8 | * This program is free software; you can redistribute it and/or modify | ||
| 9 | * it under the terms of the GNU General Public License version 2 as | ||
| 10 | * published by the Free Software Foundation. | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include <linux/slab.h> | ||
| 14 | #include <linux/lzo.h> | ||
| 15 | |||
| 16 | #include "internal.h" | ||
| 17 | |||
| 18 | struct regcache_lzo_ctx { | ||
| 19 | void *wmem; | ||
| 20 | void *dst; | ||
| 21 | const void *src; | ||
| 22 | size_t src_len; | ||
| 23 | size_t dst_len; | ||
| 24 | size_t decompressed_size; | ||
| 25 | unsigned long *sync_bmp; | ||
| 26 | int sync_bmp_nbits; | ||
| 27 | }; | ||
| 28 | |||
| 29 | #define LZO_BLOCK_NUM 8 | ||
| 30 | static int regcache_lzo_block_count(void) | ||
| 31 | { | ||
| 32 | return LZO_BLOCK_NUM; | ||
| 33 | } | ||
| 34 | |||
| 35 | static int regcache_lzo_prepare(struct regcache_lzo_ctx *lzo_ctx) | ||
| 36 | { | ||
| 37 | lzo_ctx->wmem = kmalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL); | ||
| 38 | if (!lzo_ctx->wmem) | ||
| 39 | return -ENOMEM; | ||
| 40 | return 0; | ||
| 41 | } | ||
| 42 | |||
| 43 | static int regcache_lzo_compress(struct regcache_lzo_ctx *lzo_ctx) | ||
| 44 | { | ||
| 45 | size_t compress_size; | ||
| 46 | int ret; | ||
| 47 | |||
| 48 | ret = lzo1x_1_compress(lzo_ctx->src, lzo_ctx->src_len, | ||
| 49 | lzo_ctx->dst, &compress_size, lzo_ctx->wmem); | ||
| 50 | if (ret != LZO_E_OK || compress_size > lzo_ctx->dst_len) | ||
| 51 | return -EINVAL; | ||
| 52 | lzo_ctx->dst_len = compress_size; | ||
| 53 | return 0; | ||
| 54 | } | ||
| 55 | |||
| 56 | static int regcache_lzo_decompress(struct regcache_lzo_ctx *lzo_ctx) | ||
| 57 | { | ||
| 58 | size_t dst_len; | ||
| 59 | int ret; | ||
| 60 | |||
| 61 | dst_len = lzo_ctx->dst_len; | ||
| 62 | ret = lzo1x_decompress_safe(lzo_ctx->src, lzo_ctx->src_len, | ||
| 63 | lzo_ctx->dst, &dst_len); | ||
| 64 | if (ret != LZO_E_OK || dst_len != lzo_ctx->dst_len) | ||
| 65 | return -EINVAL; | ||
| 66 | return 0; | ||
| 67 | } | ||
| 68 | |||
| 69 | static int regcache_lzo_compress_cache_block(struct regmap *map, | ||
| 70 | struct regcache_lzo_ctx *lzo_ctx) | ||
| 71 | { | ||
| 72 | int ret; | ||
| 73 | |||
| 74 | lzo_ctx->dst_len = lzo1x_worst_compress(PAGE_SIZE); | ||
| 75 | lzo_ctx->dst = kmalloc(lzo_ctx->dst_len, GFP_KERNEL); | ||
| 76 | if (!lzo_ctx->dst) { | ||
| 77 | lzo_ctx->dst_len = 0; | ||
| 78 | return -ENOMEM; | ||
| 79 | } | ||
| 80 | |||
| 81 | ret = regcache_lzo_compress(lzo_ctx); | ||
| 82 | if (ret < 0) | ||
| 83 | return ret; | ||
| 84 | return 0; | ||
| 85 | } | ||
| 86 | |||
| 87 | static int regcache_lzo_decompress_cache_block(struct regmap *map, | ||
| 88 | struct regcache_lzo_ctx *lzo_ctx) | ||
| 89 | { | ||
| 90 | int ret; | ||
| 91 | |||
| 92 | lzo_ctx->dst_len = lzo_ctx->decompressed_size; | ||
| 93 | lzo_ctx->dst = kmalloc(lzo_ctx->dst_len, GFP_KERNEL); | ||
| 94 | if (!lzo_ctx->dst) { | ||
| 95 | lzo_ctx->dst_len = 0; | ||
| 96 | return -ENOMEM; | ||
| 97 | } | ||
| 98 | |||
| 99 | ret = regcache_lzo_decompress(lzo_ctx); | ||
| 100 | if (ret < 0) | ||
| 101 | return ret; | ||
| 102 | return 0; | ||
| 103 | } | ||
| 104 | |||
| 105 | static inline int regcache_lzo_get_blkindex(struct regmap *map, | ||
| 106 | unsigned int reg) | ||
| 107 | { | ||
| 108 | return (reg * map->cache_word_size) / | ||
| 109 | DIV_ROUND_UP(map->cache_size_raw, regcache_lzo_block_count()); | ||
| 110 | } | ||
| 111 | |||
| 112 | static inline int regcache_lzo_get_blkpos(struct regmap *map, | ||
| 113 | unsigned int reg) | ||
| 114 | { | ||
| 115 | return reg % (DIV_ROUND_UP(map->cache_size_raw, regcache_lzo_block_count()) / | ||
| 116 | map->cache_word_size); | ||
| 117 | } | ||
| 118 | |||
| 119 | static inline int regcache_lzo_get_blksize(struct regmap *map) | ||
| 120 | { | ||
| 121 | return DIV_ROUND_UP(map->cache_size_raw, regcache_lzo_block_count()); | ||
| 122 | } | ||
| 123 | |||
| 124 | static int regcache_lzo_init(struct regmap *map) | ||
| 125 | { | ||
| 126 | struct regcache_lzo_ctx **lzo_blocks; | ||
| 127 | size_t bmp_size; | ||
| 128 | int ret, i, blksize, blkcount; | ||
| 129 | const char *p, *end; | ||
| 130 | unsigned long *sync_bmp; | ||
| 131 | |||
| 132 | ret = 0; | ||
| 133 | |||
| 134 | blkcount = regcache_lzo_block_count(); | ||
| 135 | map->cache = kzalloc(blkcount * sizeof *lzo_blocks, | ||
| 136 | GFP_KERNEL); | ||
| 137 | if (!map->cache) | ||
| 138 | return -ENOMEM; | ||
| 139 | lzo_blocks = map->cache; | ||
| 140 | |||
| 141 | /* | ||
| 142 | * allocate a bitmap to be used when syncing the cache with | ||
| 143 | * the hardware. Each time a register is modified, the corresponding | ||
| 144 | * bit is set in the bitmap, so we know that we have to sync | ||
| 145 | * that register. | ||
| 146 | */ | ||
| 147 | bmp_size = map->num_reg_defaults_raw; | ||
| 148 | sync_bmp = kmalloc(BITS_TO_LONGS(bmp_size) * sizeof(long), | ||
| 149 | GFP_KERNEL); | ||
| 150 | if (!sync_bmp) { | ||
| 151 | ret = -ENOMEM; | ||
| 152 | goto err; | ||
| 153 | } | ||
| 154 | bitmap_zero(sync_bmp, bmp_size); | ||
| 155 | |||
| 156 | /* allocate the lzo blocks and initialize them */ | ||
| 157 | for (i = 0; i < blkcount; i++) { | ||
| 158 | lzo_blocks[i] = kzalloc(sizeof **lzo_blocks, | ||
| 159 | GFP_KERNEL); | ||
| 160 | if (!lzo_blocks[i]) { | ||
| 161 | kfree(sync_bmp); | ||
| 162 | ret = -ENOMEM; | ||
| 163 | goto err; | ||
| 164 | } | ||
| 165 | lzo_blocks[i]->sync_bmp = sync_bmp; | ||
| 166 | lzo_blocks[i]->sync_bmp_nbits = bmp_size; | ||
| 167 | /* alloc the working space for the compressed block */ | ||
| 168 | ret = regcache_lzo_prepare(lzo_blocks[i]); | ||
| 169 | if (ret < 0) | ||
| 170 | goto err; | ||
| 171 | } | ||
| 172 | |||
| 173 | blksize = regcache_lzo_get_blksize(map); | ||
| 174 | p = map->reg_defaults_raw; | ||
| 175 | end = map->reg_defaults_raw + map->cache_size_raw; | ||
| 176 | /* compress the register map and fill the lzo blocks */ | ||
| 177 | for (i = 0; i < blkcount; i++, p += blksize) { | ||
| 178 | lzo_blocks[i]->src = p; | ||
| 179 | if (p + blksize > end) | ||
| 180 | lzo_blocks[i]->src_len = end - p; | ||
| 181 | else | ||
| 182 | lzo_blocks[i]->src_len = blksize; | ||
| 183 | ret = regcache_lzo_compress_cache_block(map, | ||
| 184 | lzo_blocks[i]); | ||
| 185 | if (ret < 0) | ||
| 186 | goto err; | ||
| 187 | lzo_blocks[i]->decompressed_size = | ||
| 188 | lzo_blocks[i]->src_len; | ||
| 189 | } | ||
| 190 | |||
| 191 | return 0; | ||
| 192 | err: | ||
| 193 | regcache_exit(map); | ||
| 194 | return ret; | ||
| 195 | } | ||
| 196 | |||
| 197 | static int regcache_lzo_exit(struct regmap *map) | ||
| 198 | { | ||
| 199 | struct regcache_lzo_ctx **lzo_blocks; | ||
| 200 | int i, blkcount; | ||
| 201 | |||
| 202 | lzo_blocks = map->cache; | ||
| 203 | if (!lzo_blocks) | ||
| 204 | return 0; | ||
| 205 | |||
| 206 | blkcount = regcache_lzo_block_count(); | ||
| 207 | /* | ||
| 208 | * the pointer to the bitmap used for syncing the cache | ||
| 209 | * is shared amongst all lzo_blocks. Ensure it is freed | ||
| 210 | * only once. | ||
| 211 | */ | ||
| 212 | if (lzo_blocks[0]) | ||
| 213 | kfree(lzo_blocks[0]->sync_bmp); | ||
| 214 | for (i = 0; i < blkcount; i++) { | ||
| 215 | if (lzo_blocks[i]) { | ||
| 216 | kfree(lzo_blocks[i]->wmem); | ||
| 217 | kfree(lzo_blocks[i]->dst); | ||
| 218 | } | ||
| 219 | /* each lzo_block is a pointer returned by kmalloc or NULL */ | ||
| 220 | kfree(lzo_blocks[i]); | ||
| 221 | } | ||
| 222 | kfree(lzo_blocks); | ||
| 223 | map->cache = NULL; | ||
| 224 | return 0; | ||
| 225 | } | ||
| 226 | |||
| 227 | static int regcache_lzo_read(struct regmap *map, | ||
| 228 | unsigned int reg, unsigned int *value) | ||
| 229 | { | ||
| 230 | struct regcache_lzo_ctx *lzo_block, **lzo_blocks; | ||
| 231 | int ret, blkindex, blkpos; | ||
| 232 | size_t blksize, tmp_dst_len; | ||
| 233 | void *tmp_dst; | ||
| 234 | |||
| 235 | /* index of the compressed lzo block */ | ||
| 236 | blkindex = regcache_lzo_get_blkindex(map, reg); | ||
| 237 | /* register index within the decompressed block */ | ||
| 238 | blkpos = regcache_lzo_get_blkpos(map, reg); | ||
| 239 | /* size of the compressed block */ | ||
| 240 | blksize = regcache_lzo_get_blksize(map); | ||
| 241 | lzo_blocks = map->cache; | ||
| 242 | lzo_block = lzo_blocks[blkindex]; | ||
| 243 | |||
| 244 | /* save the pointer and length of the compressed block */ | ||
| 245 | tmp_dst = lzo_block->dst; | ||
| 246 | tmp_dst_len = lzo_block->dst_len; | ||
| 247 | |||
| 248 | /* prepare the source to be the compressed block */ | ||
| 249 | lzo_block->src = lzo_block->dst; | ||
| 250 | lzo_block->src_len = lzo_block->dst_len; | ||
| 251 | |||
| 252 | /* decompress the block */ | ||
| 253 | ret = regcache_lzo_decompress_cache_block(map, lzo_block); | ||
| 254 | if (ret >= 0) | ||
| 255 | /* fetch the value from the cache */ | ||
| 256 | *value = regcache_get_val(lzo_block->dst, blkpos, | ||
| 257 | map->cache_word_size); | ||
| 258 | |||
| 259 | kfree(lzo_block->dst); | ||
| 260 | /* restore the pointer and length of the compressed block */ | ||
| 261 | lzo_block->dst = tmp_dst; | ||
| 262 | lzo_block->dst_len = tmp_dst_len; | ||
| 263 | |||
| 264 | return ret; | ||
| 265 | } | ||
| 266 | |||
| 267 | static int regcache_lzo_write(struct regmap *map, | ||
| 268 | unsigned int reg, unsigned int value) | ||
| 269 | { | ||
| 270 | struct regcache_lzo_ctx *lzo_block, **lzo_blocks; | ||
| 271 | int ret, blkindex, blkpos; | ||
| 272 | size_t blksize, tmp_dst_len; | ||
| 273 | void *tmp_dst; | ||
| 274 | |||
| 275 | /* index of the compressed lzo block */ | ||
| 276 | blkindex = regcache_lzo_get_blkindex(map, reg); | ||
| 277 | /* register index within the decompressed block */ | ||
| 278 | blkpos = regcache_lzo_get_blkpos(map, reg); | ||
| 279 | /* size of the compressed block */ | ||
| 280 | blksize = regcache_lzo_get_blksize(map); | ||
| 281 | lzo_blocks = map->cache; | ||
| 282 | lzo_block = lzo_blocks[blkindex]; | ||
| 283 | |||
| 284 | /* save the pointer and length of the compressed block */ | ||
| 285 | tmp_dst = lzo_block->dst; | ||
| 286 | tmp_dst_len = lzo_block->dst_len; | ||
| 287 | |||
| 288 | /* prepare the source to be the compressed block */ | ||
| 289 | lzo_block->src = lzo_block->dst; | ||
| 290 | lzo_block->src_len = lzo_block->dst_len; | ||
| 291 | |||
| 292 | /* decompress the block */ | ||
| 293 | ret = regcache_lzo_decompress_cache_block(map, lzo_block); | ||
| 294 | if (ret < 0) { | ||
| 295 | kfree(lzo_block->dst); | ||
| 296 | goto out; | ||
| 297 | } | ||
| 298 | |||
| 299 | /* write the new value to the cache */ | ||
| 300 | if (regcache_set_val(lzo_block->dst, blkpos, value, | ||
| 301 | map->cache_word_size)) { | ||
| 302 | kfree(lzo_block->dst); | ||
| 303 | goto out; | ||
| 304 | } | ||
| 305 | |||
| 306 | /* prepare the source to be the decompressed block */ | ||
| 307 | lzo_block->src = lzo_block->dst; | ||
| 308 | lzo_block->src_len = lzo_block->dst_len; | ||
| 309 | |||
| 310 | /* compress the block */ | ||
| 311 | ret = regcache_lzo_compress_cache_block(map, lzo_block); | ||
| 312 | if (ret < 0) { | ||
| 313 | kfree(lzo_block->dst); | ||
| 314 | kfree(lzo_block->src); | ||
| 315 | goto out; | ||
| 316 | } | ||
| 317 | |||
| 318 | /* set the bit so we know we have to sync this register */ | ||
| 319 | set_bit(reg, lzo_block->sync_bmp); | ||
| 320 | kfree(tmp_dst); | ||
| 321 | kfree(lzo_block->src); | ||
| 322 | return 0; | ||
| 323 | out: | ||
| 324 | lzo_block->dst = tmp_dst; | ||
| 325 | lzo_block->dst_len = tmp_dst_len; | ||
| 326 | return ret; | ||
| 327 | } | ||
| 328 | |||
| 329 | static int regcache_lzo_sync(struct regmap *map) | ||
| 330 | { | ||
| 331 | struct regcache_lzo_ctx **lzo_blocks; | ||
| 332 | unsigned int val; | ||
| 333 | int i; | ||
| 334 | int ret; | ||
| 335 | |||
| 336 | lzo_blocks = map->cache; | ||
| 337 | for_each_set_bit(i, lzo_blocks[0]->sync_bmp, lzo_blocks[0]->sync_bmp_nbits) { | ||
| 338 | ret = regcache_read(map, i, &val); | ||
| 339 | if (ret) | ||
| 340 | return ret; | ||
| 341 | map->cache_bypass = 1; | ||
| 342 | ret = _regmap_write(map, i, val); | ||
| 343 | map->cache_bypass = 0; | ||
| 344 | if (ret) | ||
| 345 | return ret; | ||
| 346 | dev_dbg(map->dev, "Synced register %#x, value %#x\n", | ||
| 347 | i, val); | ||
| 348 | } | ||
| 349 | |||
| 350 | return 0; | ||
| 351 | } | ||
| 352 | |||
| 353 | struct regcache_ops regcache_lzo_ops = { | ||
| 354 | .type = REGCACHE_LZO, | ||
| 355 | .name = "lzo", | ||
| 356 | .init = regcache_lzo_init, | ||
| 357 | .exit = regcache_lzo_exit, | ||
| 358 | .read = regcache_lzo_read, | ||
| 359 | .write = regcache_lzo_write, | ||
| 360 | .sync = regcache_lzo_sync | ||
| 361 | }; | ||
diff --git a/drivers/base/regmap/regcache-rbtree.c b/drivers/base/regmap/regcache-rbtree.c new file mode 100644 index 000000000000..e31498499b0f --- /dev/null +++ b/drivers/base/regmap/regcache-rbtree.c | |||
| @@ -0,0 +1,345 @@ | |||
| 1 | /* | ||
| 2 | * Register cache access API - rbtree caching support | ||
| 3 | * | ||
| 4 | * Copyright 2011 Wolfson Microelectronics plc | ||
| 5 | * | ||
| 6 | * Author: Dimitris Papastamos <dp@opensource.wolfsonmicro.com> | ||
| 7 | * | ||
| 8 | * This program is free software; you can redistribute it and/or modify | ||
| 9 | * it under the terms of the GNU General Public License version 2 as | ||
| 10 | * published by the Free Software Foundation. | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include <linux/slab.h> | ||
| 14 | #include <linux/rbtree.h> | ||
| 15 | |||
| 16 | #include "internal.h" | ||
| 17 | |||
| 18 | static int regcache_rbtree_write(struct regmap *map, unsigned int reg, | ||
| 19 | unsigned int value); | ||
| 20 | |||
| 21 | struct regcache_rbtree_node { | ||
| 22 | /* the actual rbtree node holding this block */ | ||
| 23 | struct rb_node node; | ||
| 24 | /* base register handled by this block */ | ||
| 25 | unsigned int base_reg; | ||
| 26 | /* block of adjacent registers */ | ||
| 27 | void *block; | ||
| 28 | /* number of registers available in the block */ | ||
| 29 | unsigned int blklen; | ||
| 30 | } __attribute__ ((packed)); | ||
| 31 | |||
| 32 | struct regcache_rbtree_ctx { | ||
| 33 | struct rb_root root; | ||
| 34 | struct regcache_rbtree_node *cached_rbnode; | ||
| 35 | }; | ||
| 36 | |||
| 37 | static inline void regcache_rbtree_get_base_top_reg( | ||
| 38 | struct regcache_rbtree_node *rbnode, | ||
| 39 | unsigned int *base, unsigned int *top) | ||
| 40 | { | ||
| 41 | *base = rbnode->base_reg; | ||
| 42 | *top = rbnode->base_reg + rbnode->blklen - 1; | ||
| 43 | } | ||
| 44 | |||
| 45 | static unsigned int regcache_rbtree_get_register( | ||
| 46 | struct regcache_rbtree_node *rbnode, unsigned int idx, | ||
| 47 | unsigned int word_size) | ||
| 48 | { | ||
| 49 | return regcache_get_val(rbnode->block, idx, word_size); | ||
| 50 | } | ||
| 51 | |||
| 52 | static void regcache_rbtree_set_register(struct regcache_rbtree_node *rbnode, | ||
| 53 | unsigned int idx, unsigned int val, | ||
| 54 | unsigned int word_size) | ||
| 55 | { | ||
| 56 | regcache_set_val(rbnode->block, idx, val, word_size); | ||
| 57 | } | ||
| 58 | |||
| 59 | static struct regcache_rbtree_node *regcache_rbtree_lookup(struct regmap *map, | ||
| 60 | unsigned int reg) | ||
| 61 | { | ||
| 62 | struct regcache_rbtree_ctx *rbtree_ctx = map->cache; | ||
| 63 | struct rb_node *node; | ||
| 64 | struct regcache_rbtree_node *rbnode; | ||
| 65 | unsigned int base_reg, top_reg; | ||
| 66 | |||
| 67 | rbnode = rbtree_ctx->cached_rbnode; | ||
| 68 | if (rbnode) { | ||
| 69 | regcache_rbtree_get_base_top_reg(rbnode, &base_reg, &top_reg); | ||
| 70 | if (reg >= base_reg && reg <= top_reg) | ||
| 71 | return rbnode; | ||
| 72 | } | ||
| 73 | |||
| 74 | node = rbtree_ctx->root.rb_node; | ||
| 75 | while (node) { | ||
| 76 | rbnode = container_of(node, struct regcache_rbtree_node, node); | ||
| 77 | regcache_rbtree_get_base_top_reg(rbnode, &base_reg, &top_reg); | ||
| 78 | if (reg >= base_reg && reg <= top_reg) { | ||
| 79 | rbtree_ctx->cached_rbnode = rbnode; | ||
| 80 | return rbnode; | ||
| 81 | } else if (reg > top_reg) { | ||
| 82 | node = node->rb_right; | ||
| 83 | } else if (reg < base_reg) { | ||
| 84 | node = node->rb_left; | ||
| 85 | } | ||
| 86 | } | ||
| 87 | |||
| 88 | return NULL; | ||
| 89 | } | ||
| 90 | |||
| 91 | static int regcache_rbtree_insert(struct rb_root *root, | ||
| 92 | struct regcache_rbtree_node *rbnode) | ||
| 93 | { | ||
| 94 | struct rb_node **new, *parent; | ||
| 95 | struct regcache_rbtree_node *rbnode_tmp; | ||
| 96 | unsigned int base_reg_tmp, top_reg_tmp; | ||
| 97 | unsigned int base_reg; | ||
| 98 | |||
| 99 | parent = NULL; | ||
| 100 | new = &root->rb_node; | ||
| 101 | while (*new) { | ||
| 102 | rbnode_tmp = container_of(*new, struct regcache_rbtree_node, | ||
| 103 | node); | ||
| 104 | /* base and top registers of the current rbnode */ | ||
| 105 | regcache_rbtree_get_base_top_reg(rbnode_tmp, &base_reg_tmp, | ||
| 106 | &top_reg_tmp); | ||
| 107 | /* base register of the rbnode to be added */ | ||
| 108 | base_reg = rbnode->base_reg; | ||
| 109 | parent = *new; | ||
| 110 | /* if this register has already been inserted, just return */ | ||
| 111 | if (base_reg >= base_reg_tmp && | ||
| 112 | base_reg <= top_reg_tmp) | ||
| 113 | return 0; | ||
| 114 | else if (base_reg > top_reg_tmp) | ||
| 115 | new = &((*new)->rb_right); | ||
| 116 | else if (base_reg < base_reg_tmp) | ||
| 117 | new = &((*new)->rb_left); | ||
| 118 | } | ||
| 119 | |||
| 120 | /* insert the node into the rbtree */ | ||
| 121 | rb_link_node(&rbnode->node, parent, new); | ||
| 122 | rb_insert_color(&rbnode->node, root); | ||
| 123 | |||
| 124 | return 1; | ||
| 125 | } | ||
| 126 | |||
| 127 | static int regcache_rbtree_init(struct regmap *map) | ||
| 128 | { | ||
| 129 | struct regcache_rbtree_ctx *rbtree_ctx; | ||
| 130 | int i; | ||
| 131 | int ret; | ||
| 132 | |||
| 133 | map->cache = kmalloc(sizeof *rbtree_ctx, GFP_KERNEL); | ||
| 134 | if (!map->cache) | ||
| 135 | return -ENOMEM; | ||
| 136 | |||
| 137 | rbtree_ctx = map->cache; | ||
| 138 | rbtree_ctx->root = RB_ROOT; | ||
| 139 | rbtree_ctx->cached_rbnode = NULL; | ||
| 140 | |||
| 141 | for (i = 0; i < map->num_reg_defaults; i++) { | ||
| 142 | ret = regcache_rbtree_write(map, | ||
| 143 | map->reg_defaults[i].reg, | ||
| 144 | map->reg_defaults[i].def); | ||
| 145 | if (ret) | ||
| 146 | goto err; | ||
| 147 | } | ||
| 148 | |||
| 149 | return 0; | ||
| 150 | |||
| 151 | err: | ||
| 152 | regcache_exit(map); | ||
| 153 | return ret; | ||
| 154 | } | ||
| 155 | |||
| 156 | static int regcache_rbtree_exit(struct regmap *map) | ||
| 157 | { | ||
| 158 | struct rb_node *next; | ||
| 159 | struct regcache_rbtree_ctx *rbtree_ctx; | ||
| 160 | struct regcache_rbtree_node *rbtree_node; | ||
| 161 | |||
| 162 | /* if we've already been called then just return */ | ||
| 163 | rbtree_ctx = map->cache; | ||
| 164 | if (!rbtree_ctx) | ||
| 165 | return 0; | ||
| 166 | |||
| 167 | /* free up the rbtree */ | ||
| 168 | next = rb_first(&rbtree_ctx->root); | ||
| 169 | while (next) { | ||
| 170 | rbtree_node = rb_entry(next, struct regcache_rbtree_node, node); | ||
| 171 | next = rb_next(&rbtree_node->node); | ||
| 172 | rb_erase(&rbtree_node->node, &rbtree_ctx->root); | ||
| 173 | kfree(rbtree_node->block); | ||
| 174 | kfree(rbtree_node); | ||
| 175 | } | ||
| 176 | |||
| 177 | /* release the resources */ | ||
| 178 | kfree(map->cache); | ||
| 179 | map->cache = NULL; | ||
| 180 | |||
| 181 | return 0; | ||
| 182 | } | ||
| 183 | |||
| 184 | static int regcache_rbtree_read(struct regmap *map, | ||
| 185 | unsigned int reg, unsigned int *value) | ||
| 186 | { | ||
| 187 | struct regcache_rbtree_node *rbnode; | ||
| 188 | unsigned int reg_tmp; | ||
| 189 | |||
| 190 | rbnode = regcache_rbtree_lookup(map, reg); | ||
| 191 | if (rbnode) { | ||
| 192 | reg_tmp = reg - rbnode->base_reg; | ||
| 193 | *value = regcache_rbtree_get_register(rbnode, reg_tmp, | ||
| 194 | map->cache_word_size); | ||
| 195 | } else { | ||
| 196 | return -ENOENT; | ||
| 197 | } | ||
| 198 | |||
| 199 | return 0; | ||
| 200 | } | ||
| 201 | |||
| 202 | |||
| 203 | static int regcache_rbtree_insert_to_block(struct regcache_rbtree_node *rbnode, | ||
| 204 | unsigned int pos, unsigned int reg, | ||
| 205 | unsigned int value, unsigned int word_size) | ||
| 206 | { | ||
| 207 | u8 *blk; | ||
| 208 | |||
| 209 | blk = krealloc(rbnode->block, | ||
| 210 | (rbnode->blklen + 1) * word_size, GFP_KERNEL); | ||
| 211 | if (!blk) | ||
| 212 | return -ENOMEM; | ||
| 213 | |||
| 214 | /* insert the register value in the correct place in the rbnode block */ | ||
| 215 | memmove(blk + (pos + 1) * word_size, | ||
| 216 | blk + pos * word_size, | ||
| 217 | (rbnode->blklen - pos) * word_size); | ||
| 218 | |||
| 219 | /* update the rbnode block, its size and the base register */ | ||
| 220 | rbnode->block = blk; | ||
| 221 | rbnode->blklen++; | ||
| 222 | if (!pos) | ||
| 223 | rbnode->base_reg = reg; | ||
| 224 | |||
| 225 | regcache_rbtree_set_register(rbnode, pos, value, word_size); | ||
| 226 | return 0; | ||
| 227 | } | ||
| 228 | |||
| 229 | static int regcache_rbtree_write(struct regmap *map, unsigned int reg, | ||
| 230 | unsigned int value) | ||
| 231 | { | ||
| 232 | struct regcache_rbtree_ctx *rbtree_ctx; | ||
| 233 | struct regcache_rbtree_node *rbnode, *rbnode_tmp; | ||
| 234 | struct rb_node *node; | ||
| 235 | unsigned int val; | ||
| 236 | unsigned int reg_tmp; | ||
| 237 | unsigned int pos; | ||
| 238 | int i; | ||
| 239 | int ret; | ||
| 240 | |||
| 241 | rbtree_ctx = map->cache; | ||
| 242 | /* if we can't locate it in the cached rbnode we'll have | ||
| 243 | * to traverse the rbtree looking for it. | ||
| 244 | */ | ||
| 245 | rbnode = regcache_rbtree_lookup(map, reg); | ||
| 246 | if (rbnode) { | ||
| 247 | reg_tmp = reg - rbnode->base_reg; | ||
| 248 | val = regcache_rbtree_get_register(rbnode, reg_tmp, | ||
| 249 | map->cache_word_size); | ||
| 250 | if (val == value) | ||
| 251 | return 0; | ||
| 252 | regcache_rbtree_set_register(rbnode, reg_tmp, value, | ||
| 253 | map->cache_word_size); | ||
| 254 | } else { | ||
| 255 | /* look for an adjacent register to the one we are about to add */ | ||
| 256 | for (node = rb_first(&rbtree_ctx->root); node; | ||
| 257 | node = rb_next(node)) { | ||
| 258 | rbnode_tmp = rb_entry(node, struct regcache_rbtree_node, node); | ||
| 259 | for (i = 0; i < rbnode_tmp->blklen; i++) { | ||
| 260 | reg_tmp = rbnode_tmp->base_reg + i; | ||
| 261 | if (abs(reg_tmp - reg) != 1) | ||
| 262 | continue; | ||
| 263 | /* decide where in the block to place our register */ | ||
| 264 | if (reg_tmp + 1 == reg) | ||
| 265 | pos = i + 1; | ||
| 266 | else | ||
| 267 | pos = i; | ||
| 268 | ret = regcache_rbtree_insert_to_block(rbnode_tmp, pos, | ||
| 269 | reg, value, | ||
| 270 | map->cache_word_size); | ||
| 271 | if (ret) | ||
| 272 | return ret; | ||
| 273 | rbtree_ctx->cached_rbnode = rbnode_tmp; | ||
| 274 | return 0; | ||
| 275 | } | ||
| 276 | } | ||
| 277 | /* we did not manage to find a place to insert it in an existing | ||
| 278 | * block so create a new rbnode with a single register in its block. | ||
| 279 | * This block will get populated further if any other adjacent | ||
| 280 | * registers get modified in the future. | ||
| 281 | */ | ||
| 282 | rbnode = kzalloc(sizeof *rbnode, GFP_KERNEL); | ||
| 283 | if (!rbnode) | ||
| 284 | return -ENOMEM; | ||
| 285 | rbnode->blklen = 1; | ||
| 286 | rbnode->base_reg = reg; | ||
| 287 | rbnode->block = kmalloc(rbnode->blklen * map->cache_word_size, | ||
| 288 | GFP_KERNEL); | ||
| 289 | if (!rbnode->block) { | ||
| 290 | kfree(rbnode); | ||
| 291 | return -ENOMEM; | ||
| 292 | } | ||
| 293 | regcache_rbtree_set_register(rbnode, 0, value, map->cache_word_size); | ||
| 294 | regcache_rbtree_insert(&rbtree_ctx->root, rbnode); | ||
| 295 | rbtree_ctx->cached_rbnode = rbnode; | ||
| 296 | } | ||
| 297 | |||
| 298 | return 0; | ||
| 299 | } | ||
| 300 | |||
| 301 | static int regcache_rbtree_sync(struct regmap *map) | ||
| 302 | { | ||
| 303 | struct regcache_rbtree_ctx *rbtree_ctx; | ||
| 304 | struct rb_node *node; | ||
| 305 | struct regcache_rbtree_node *rbnode; | ||
| 306 | unsigned int regtmp; | ||
| 307 | unsigned int val; | ||
| 308 | int ret; | ||
| 309 | int i; | ||
| 310 | |||
| 311 | rbtree_ctx = map->cache; | ||
| 312 | for (node = rb_first(&rbtree_ctx->root); node; node = rb_next(node)) { | ||
| 313 | rbnode = rb_entry(node, struct regcache_rbtree_node, node); | ||
| 314 | for (i = 0; i < rbnode->blklen; i++) { | ||
| 315 | regtmp = rbnode->base_reg + i; | ||
| 316 | val = regcache_rbtree_get_register(rbnode, i, | ||
| 317 | map->cache_word_size); | ||
| 318 | |||
| 319 | /* Is this the hardware default? If so skip. */ | ||
| 320 | ret = regcache_lookup_reg(map, i); | ||
| 321 | if (ret > 0 && val == map->reg_defaults[ret].def) | ||
| 322 | continue; | ||
| 323 | |||
| 324 | map->cache_bypass = 1; | ||
| 325 | ret = _regmap_write(map, regtmp, val); | ||
| 326 | map->cache_bypass = 0; | ||
| 327 | if (ret) | ||
| 328 | return ret; | ||
| 329 | dev_dbg(map->dev, "Synced register %#x, value %#x\n", | ||
| 330 | regtmp, val); | ||
| 331 | } | ||
| 332 | } | ||
| 333 | |||
| 334 | return 0; | ||
| 335 | } | ||
| 336 | |||
| 337 | struct regcache_ops regcache_rbtree_ops = { | ||
| 338 | .type = REGCACHE_RBTREE, | ||
| 339 | .name = "rbtree", | ||
| 340 | .init = regcache_rbtree_init, | ||
| 341 | .exit = regcache_rbtree_exit, | ||
| 342 | .read = regcache_rbtree_read, | ||
| 343 | .write = regcache_rbtree_write, | ||
| 344 | .sync = regcache_rbtree_sync | ||
| 345 | }; | ||
diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c new file mode 100644 index 000000000000..afcfef838263 --- /dev/null +++ b/drivers/base/regmap/regcache.c | |||
| @@ -0,0 +1,401 @@ | |||
| 1 | /* | ||
| 2 | * Register cache access API | ||
| 3 | * | ||
| 4 | * Copyright 2011 Wolfson Microelectronics plc | ||
| 5 | * | ||
| 6 | * Author: Dimitris Papastamos <dp@opensource.wolfsonmicro.com> | ||
| 7 | * | ||
| 8 | * This program is free software; you can redistribute it and/or modify | ||
| 9 | * it under the terms of the GNU General Public License version 2 as | ||
| 10 | * published by the Free Software Foundation. | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include <linux/slab.h> | ||
| 14 | #include <trace/events/regmap.h> | ||
| 15 | #include <linux/bsearch.h> | ||
| 16 | #include <linux/sort.h> | ||
| 17 | |||
| 18 | #include "internal.h" | ||
| 19 | |||
| 20 | static const struct regcache_ops *cache_types[] = { | ||
| 21 | ®cache_indexed_ops, | ||
| 22 | ®cache_rbtree_ops, | ||
| 23 | ®cache_lzo_ops, | ||
| 24 | }; | ||
| 25 | |||
| 26 | static int regcache_hw_init(struct regmap *map) | ||
| 27 | { | ||
| 28 | int i, j; | ||
| 29 | int ret; | ||
| 30 | int count; | ||
| 31 | unsigned int val; | ||
| 32 | void *tmp_buf; | ||
| 33 | |||
| 34 | if (!map->num_reg_defaults_raw) | ||
| 35 | return -EINVAL; | ||
| 36 | |||
| 37 | if (!map->reg_defaults_raw) { | ||
| 38 | dev_warn(map->dev, "No cache defaults, reading back from HW\n"); | ||
| 39 | tmp_buf = kmalloc(map->cache_size_raw, GFP_KERNEL); | ||
| 40 | if (!tmp_buf) | ||
| 41 | return -EINVAL; | ||
| 42 | ret = regmap_bulk_read(map, 0, tmp_buf, | ||
| 43 | map->num_reg_defaults_raw); | ||
| 44 | if (ret < 0) { | ||
| 45 | kfree(tmp_buf); | ||
| 46 | return ret; | ||
| 47 | } | ||
| 48 | map->reg_defaults_raw = tmp_buf; | ||
| 49 | map->cache_free = 1; | ||
| 50 | } | ||
| 51 | |||
| 52 | /* calculate the size of reg_defaults */ | ||
| 53 | for (count = 0, i = 0; i < map->num_reg_defaults_raw; i++) { | ||
| 54 | val = regcache_get_val(map->reg_defaults_raw, | ||
| 55 | i, map->cache_word_size); | ||
| 56 | if (!val) | ||
| 57 | continue; | ||
| 58 | count++; | ||
| 59 | } | ||
| 60 | |||
| 61 | map->reg_defaults = kmalloc(count * sizeof(struct reg_default), | ||
| 62 | GFP_KERNEL); | ||
| 63 | if (!map->reg_defaults) | ||
| 64 | return -ENOMEM; | ||
| 65 | |||
| 66 | /* fill the reg_defaults */ | ||
| 67 | map->num_reg_defaults = count; | ||
| 68 | for (i = 0, j = 0; i < map->num_reg_defaults_raw; i++) { | ||
| 69 | val = regcache_get_val(map->reg_defaults_raw, | ||
| 70 | i, map->cache_word_size); | ||
| 71 | if (!val) | ||
| 72 | continue; | ||
| 73 | map->reg_defaults[j].reg = i; | ||
| 74 | map->reg_defaults[j].def = val; | ||
| 75 | j++; | ||
| 76 | } | ||
| 77 | |||
| 78 | return 0; | ||
| 79 | } | ||
| 80 | |||
| 81 | int regcache_init(struct regmap *map) | ||
| 82 | { | ||
| 83 | int ret; | ||
| 84 | int i; | ||
| 85 | void *tmp_buf; | ||
| 86 | |||
| 87 | if (map->cache_type == REGCACHE_NONE) { | ||
| 88 | map->cache_bypass = true; | ||
| 89 | return 0; | ||
| 90 | } | ||
| 91 | |||
| 92 | for (i = 0; i < ARRAY_SIZE(cache_types); i++) | ||
| 93 | if (cache_types[i]->type == map->cache_type) | ||
| 94 | break; | ||
| 95 | |||
| 96 | if (i == ARRAY_SIZE(cache_types)) { | ||
| 97 | dev_err(map->dev, "Could not match compress type: %d\n", | ||
| 98 | map->cache_type); | ||
| 99 | return -EINVAL; | ||
| 100 | } | ||
| 101 | |||
| 102 | map->cache = NULL; | ||
| 103 | map->cache_ops = cache_types[i]; | ||
| 104 | |||
| 105 | if (!map->cache_ops->read || | ||
| 106 | !map->cache_ops->write || | ||
| 107 | !map->cache_ops->name) | ||
| 108 | return -EINVAL; | ||
| 109 | |||
| 110 | /* We still need to ensure that the reg_defaults | ||
| 111 | * won't vanish from under us. We'll need to make | ||
| 112 | * a copy of it. | ||
| 113 | */ | ||
| 114 | if (map->reg_defaults) { | ||
| 115 | if (!map->num_reg_defaults) | ||
| 116 | return -EINVAL; | ||
| 117 | tmp_buf = kmemdup(map->reg_defaults, map->num_reg_defaults * | ||
| 118 | sizeof(struct reg_default), GFP_KERNEL); | ||
| 119 | if (!tmp_buf) | ||
| 120 | return -ENOMEM; | ||
| 121 | map->reg_defaults = tmp_buf; | ||
| 122 | } else if (map->num_reg_defaults_raw) { | ||
| 123 | /* Some devices such as PMICs don't have cache defaults, | ||
| 124 | * we cope with this by reading back the HW registers and | ||
| 125 | * crafting the cache defaults by hand. | ||
| 126 | */ | ||
| 127 | ret = regcache_hw_init(map); | ||
| 128 | if (ret < 0) | ||
| 129 | return ret; | ||
| 130 | } | ||
| 131 | |||
| 132 | if (!map->max_register) | ||
| 133 | map->max_register = map->num_reg_defaults_raw; | ||
| 134 | |||
| 135 | if (map->cache_ops->init) { | ||
| 136 | dev_dbg(map->dev, "Initializing %s cache\n", | ||
| 137 | map->cache_ops->name); | ||
| 138 | return map->cache_ops->init(map); | ||
| 139 | } | ||
| 140 | return 0; | ||
| 141 | } | ||
| 142 | |||
| 143 | void regcache_exit(struct regmap *map) | ||
| 144 | { | ||
| 145 | if (map->cache_type == REGCACHE_NONE) | ||
| 146 | return; | ||
| 147 | |||
| 148 | BUG_ON(!map->cache_ops); | ||
| 149 | |||
| 150 | kfree(map->reg_defaults); | ||
| 151 | if (map->cache_free) | ||
| 152 | kfree(map->reg_defaults_raw); | ||
| 153 | |||
| 154 | if (map->cache_ops->exit) { | ||
| 155 | dev_dbg(map->dev, "Destroying %s cache\n", | ||
| 156 | map->cache_ops->name); | ||
| 157 | map->cache_ops->exit(map); | ||
| 158 | } | ||
| 159 | } | ||
| 160 | |||
| 161 | /** | ||
| 162 | * regcache_read: Fetch the value of a given register from the cache. | ||
| 163 | * | ||
| 164 | * @map: map to configure. | ||
| 165 | * @reg: The register index. | ||
| 166 | * @value: The value to be returned. | ||
| 167 | * | ||
| 168 | * Return a negative value on failure, 0 on success. | ||
| 169 | */ | ||
| 170 | int regcache_read(struct regmap *map, | ||
| 171 | unsigned int reg, unsigned int *value) | ||
| 172 | { | ||
| 173 | if (map->cache_type == REGCACHE_NONE) | ||
| 174 | return -ENOSYS; | ||
| 175 | |||
| 176 | BUG_ON(!map->cache_ops); | ||
| 177 | |||
| 178 | if (!regmap_readable(map, reg)) | ||
| 179 | return -EIO; | ||
| 180 | |||
| 181 | if (!regmap_volatile(map, reg)) | ||
| 182 | return map->cache_ops->read(map, reg, value); | ||
| 183 | |||
| 184 | return -EINVAL; | ||
| 185 | } | ||
| 186 | EXPORT_SYMBOL_GPL(regcache_read); | ||
| 187 | |||
| 188 | /** | ||
| 189 | * regcache_write: Set the value of a given register in the cache. | ||
| 190 | * | ||
| 191 | * @map: map to configure. | ||
| 192 | * @reg: The register index. | ||
| 193 | * @value: The new register value. | ||
| 194 | * | ||
| 195 | * Return a negative value on failure, 0 on success. | ||
| 196 | */ | ||
| 197 | int regcache_write(struct regmap *map, | ||
| 198 | unsigned int reg, unsigned int value) | ||
| 199 | { | ||
| 200 | if (map->cache_type == REGCACHE_NONE) | ||
| 201 | return 0; | ||
| 202 | |||
| 203 | BUG_ON(!map->cache_ops); | ||
| 204 | |||
| 205 | if (!regmap_writeable(map, reg)) | ||
| 206 | return -EIO; | ||
| 207 | |||
| 208 | if (!regmap_volatile(map, reg)) | ||
| 209 | return map->cache_ops->write(map, reg, value); | ||
| 210 | |||
| 211 | return 0; | ||
| 212 | } | ||
| 213 | EXPORT_SYMBOL_GPL(regcache_write); | ||
| 214 | |||
| 215 | /** | ||
| 216 | * regcache_sync: Sync the register cache with the hardware. | ||
| 217 | * | ||
| 218 | * @map: map to configure. | ||
| 219 | * | ||
| 220 | * Any registers that should not be synced should be marked as | ||
| 221 | * volatile. In general drivers can choose not to use the provided | ||
| 222 | * syncing functionality if they so require. | ||
| 223 | * | ||
| 224 | * Return a negative value on failure, 0 on success. | ||
| 225 | */ | ||
| 226 | int regcache_sync(struct regmap *map) | ||
| 227 | { | ||
| 228 | int ret = 0; | ||
| 229 | unsigned int val; | ||
| 230 | unsigned int i; | ||
| 231 | const char *name; | ||
| 232 | unsigned int bypass; | ||
| 233 | |||
| 234 | BUG_ON(!map->cache_ops); | ||
| 235 | |||
| 236 | mutex_lock(&map->lock); | ||
| 237 | /* Remember the initial bypass state */ | ||
| 238 | bypass = map->cache_bypass; | ||
| 239 | dev_dbg(map->dev, "Syncing %s cache\n", | ||
| 240 | map->cache_ops->name); | ||
| 241 | name = map->cache_ops->name; | ||
| 242 | trace_regcache_sync(map->dev, name, "start"); | ||
| 243 | if (map->cache_ops->sync) { | ||
| 244 | ret = map->cache_ops->sync(map); | ||
| 245 | } else { | ||
| 246 | for (i = 0; i < map->num_reg_defaults; i++) { | ||
| 247 | ret = regcache_read(map, i, &val); | ||
| 248 | if (ret < 0) | ||
| 249 | goto out; | ||
| 250 | map->cache_bypass = 1; | ||
| 251 | ret = _regmap_write(map, i, val); | ||
| 252 | map->cache_bypass = 0; | ||
| 253 | if (ret < 0) | ||
| 254 | goto out; | ||
| 255 | dev_dbg(map->dev, "Synced register %#x, value %#x\n", | ||
| 256 | map->reg_defaults[i].reg, | ||
| 257 | map->reg_defaults[i].def); | ||
| 258 | } | ||
| 259 | |||
| 260 | } | ||
| 261 | out: | ||
| 262 | trace_regcache_sync(map->dev, name, "stop"); | ||
| 263 | /* Restore the bypass state */ | ||
| 264 | map->cache_bypass = bypass; | ||
| 265 | mutex_unlock(&map->lock); | ||
| 266 | |||
| 267 | return ret; | ||
| 268 | } | ||
| 269 | EXPORT_SYMBOL_GPL(regcache_sync); | ||
| 270 | |||
| 271 | /** | ||
| 272 | * regcache_cache_only: Put a register map into cache only mode | ||
| 273 | * | ||
| 274 | * @map: map to configure | ||
| 275 | * @cache_only: flag if changes should be written to the hardware | ||
| 276 | * | ||
| 277 | * When a register map is marked as cache only writes to the register | ||
| 278 | * map API will only update the register cache, they will not cause | ||
| 279 | * any hardware changes. This is useful for allowing portions of | ||
| 280 | * drivers to act as though the device were functioning as normal when | ||
| 281 | * it is disabled for power saving reasons. | ||
| 282 | */ | ||
| 283 | void regcache_cache_only(struct regmap *map, bool enable) | ||
| 284 | { | ||
| 285 | mutex_lock(&map->lock); | ||
| 286 | WARN_ON(map->cache_bypass && enable); | ||
| 287 | map->cache_only = enable; | ||
| 288 | mutex_unlock(&map->lock); | ||
| 289 | } | ||
| 290 | EXPORT_SYMBOL_GPL(regcache_cache_only); | ||
| 291 | |||
| 292 | /** | ||
| 293 | * regcache_cache_bypass: Put a register map into cache bypass mode | ||
| 294 | * | ||
| 295 | * @map: map to configure | ||
| 296 | * @cache_bypass: flag if changes should not be written to the hardware | ||
| 297 | * | ||
| 298 | * When a register map is marked with the cache bypass option, writes | ||
| 299 | * to the register map API will only update the hardware and not the | ||
| 300 | * the cache directly. This is useful when syncing the cache back to | ||
| 301 | * the hardware. | ||
| 302 | */ | ||
| 303 | void regcache_cache_bypass(struct regmap *map, bool enable) | ||
| 304 | { | ||
| 305 | mutex_lock(&map->lock); | ||
| 306 | WARN_ON(map->cache_only && enable); | ||
| 307 | map->cache_bypass = enable; | ||
| 308 | mutex_unlock(&map->lock); | ||
| 309 | } | ||
| 310 | EXPORT_SYMBOL_GPL(regcache_cache_bypass); | ||
| 311 | |||
| 312 | bool regcache_set_val(void *base, unsigned int idx, | ||
| 313 | unsigned int val, unsigned int word_size) | ||
| 314 | { | ||
| 315 | switch (word_size) { | ||
| 316 | case 1: { | ||
| 317 | u8 *cache = base; | ||
| 318 | if (cache[idx] == val) | ||
| 319 | return true; | ||
| 320 | cache[idx] = val; | ||
| 321 | break; | ||
| 322 | } | ||
| 323 | case 2: { | ||
| 324 | u16 *cache = base; | ||
| 325 | if (cache[idx] == val) | ||
| 326 | return true; | ||
| 327 | cache[idx] = val; | ||
| 328 | break; | ||
| 329 | } | ||
| 330 | default: | ||
| 331 | BUG(); | ||
| 332 | } | ||
| 333 | /* unreachable */ | ||
| 334 | return false; | ||
| 335 | } | ||
| 336 | |||
| 337 | unsigned int regcache_get_val(const void *base, unsigned int idx, | ||
| 338 | unsigned int word_size) | ||
| 339 | { | ||
| 340 | if (!base) | ||
| 341 | return -EINVAL; | ||
| 342 | |||
| 343 | switch (word_size) { | ||
| 344 | case 1: { | ||
| 345 | const u8 *cache = base; | ||
| 346 | return cache[idx]; | ||
| 347 | } | ||
| 348 | case 2: { | ||
| 349 | const u16 *cache = base; | ||
| 350 | return cache[idx]; | ||
| 351 | } | ||
| 352 | default: | ||
| 353 | BUG(); | ||
| 354 | } | ||
| 355 | /* unreachable */ | ||
| 356 | return -1; | ||
| 357 | } | ||
| 358 | |||
| 359 | static int regcache_default_cmp(const void *a, const void *b) | ||
| 360 | { | ||
| 361 | const struct reg_default *_a = a; | ||
| 362 | const struct reg_default *_b = b; | ||
| 363 | |||
| 364 | return _a->reg - _b->reg; | ||
| 365 | } | ||
| 366 | |||
| 367 | int regcache_lookup_reg(struct regmap *map, unsigned int reg) | ||
| 368 | { | ||
| 369 | struct reg_default key; | ||
| 370 | struct reg_default *r; | ||
| 371 | |||
| 372 | key.reg = reg; | ||
| 373 | key.def = 0; | ||
| 374 | |||
| 375 | r = bsearch(&key, map->reg_defaults, map->num_reg_defaults, | ||
| 376 | sizeof(struct reg_default), regcache_default_cmp); | ||
| 377 | |||
| 378 | if (r) | ||
| 379 | return r - map->reg_defaults; | ||
| 380 | else | ||
| 381 | return -ENOENT; | ||
| 382 | } | ||
| 383 | |||
| 384 | int regcache_insert_reg(struct regmap *map, unsigned int reg, | ||
| 385 | unsigned int val) | ||
| 386 | { | ||
| 387 | void *tmp; | ||
| 388 | |||
| 389 | tmp = krealloc(map->reg_defaults, | ||
| 390 | (map->num_reg_defaults + 1) * sizeof(struct reg_default), | ||
| 391 | GFP_KERNEL); | ||
| 392 | if (!tmp) | ||
| 393 | return -ENOMEM; | ||
| 394 | map->reg_defaults = tmp; | ||
| 395 | map->num_reg_defaults++; | ||
| 396 | map->reg_defaults[map->num_reg_defaults - 1].reg = reg; | ||
| 397 | map->reg_defaults[map->num_reg_defaults - 1].def = val; | ||
| 398 | sort(map->reg_defaults, map->num_reg_defaults, | ||
| 399 | sizeof(struct reg_default), regcache_default_cmp, NULL); | ||
| 400 | return 0; | ||
| 401 | } | ||
diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c new file mode 100644 index 000000000000..6f397476e27c --- /dev/null +++ b/drivers/base/regmap/regmap-debugfs.c | |||
| @@ -0,0 +1,209 @@ | |||
| 1 | /* | ||
| 2 | * Register map access API - debugfs | ||
| 3 | * | ||
| 4 | * Copyright 2011 Wolfson Microelectronics plc | ||
| 5 | * | ||
| 6 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> | ||
| 7 | * | ||
| 8 | * This program is free software; you can redistribute it and/or modify | ||
| 9 | * it under the terms of the GNU General Public License version 2 as | ||
| 10 | * published by the Free Software Foundation. | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include <linux/slab.h> | ||
| 14 | #include <linux/module.h> | ||
| 15 | #include <linux/mutex.h> | ||
| 16 | #include <linux/debugfs.h> | ||
| 17 | #include <linux/uaccess.h> | ||
| 18 | |||
| 19 | #include "internal.h" | ||
| 20 | |||
| 21 | static struct dentry *regmap_debugfs_root; | ||
| 22 | |||
| 23 | /* Calculate the length of a fixed format */ | ||
| 24 | static size_t regmap_calc_reg_len(int max_val, char *buf, size_t buf_size) | ||
| 25 | { | ||
| 26 | snprintf(buf, buf_size, "%x", max_val); | ||
| 27 | return strlen(buf); | ||
| 28 | } | ||
| 29 | |||
| 30 | static int regmap_open_file(struct inode *inode, struct file *file) | ||
| 31 | { | ||
| 32 | file->private_data = inode->i_private; | ||
| 33 | return 0; | ||
| 34 | } | ||
| 35 | |||
| 36 | static ssize_t regmap_map_read_file(struct file *file, char __user *user_buf, | ||
| 37 | size_t count, loff_t *ppos) | ||
| 38 | { | ||
| 39 | int reg_len, val_len, tot_len; | ||
| 40 | size_t buf_pos = 0; | ||
| 41 | loff_t p = 0; | ||
| 42 | ssize_t ret; | ||
| 43 | int i; | ||
| 44 | struct regmap *map = file->private_data; | ||
| 45 | char *buf; | ||
| 46 | unsigned int val; | ||
| 47 | |||
| 48 | if (*ppos < 0 || !count) | ||
| 49 | return -EINVAL; | ||
| 50 | |||
| 51 | buf = kmalloc(count, GFP_KERNEL); | ||
| 52 | if (!buf) | ||
| 53 | return -ENOMEM; | ||
| 54 | |||
| 55 | /* Calculate the length of a fixed format */ | ||
| 56 | reg_len = regmap_calc_reg_len(map->max_register, buf, count); | ||
| 57 | val_len = 2 * map->format.val_bytes; | ||
| 58 | tot_len = reg_len + val_len + 3; /* : \n */ | ||
| 59 | |||
| 60 | for (i = 0; i < map->max_register + 1; i++) { | ||
| 61 | if (!regmap_readable(map, i)) | ||
| 62 | continue; | ||
| 63 | |||
| 64 | if (regmap_precious(map, i)) | ||
| 65 | continue; | ||
| 66 | |||
| 67 | /* If we're in the region the user is trying to read */ | ||
| 68 | if (p >= *ppos) { | ||
| 69 | /* ...but not beyond it */ | ||
| 70 | if (buf_pos >= count - 1 - tot_len) | ||
| 71 | break; | ||
| 72 | |||
| 73 | /* Format the register */ | ||
| 74 | snprintf(buf + buf_pos, count - buf_pos, "%.*x: ", | ||
| 75 | reg_len, i); | ||
| 76 | buf_pos += reg_len + 2; | ||
| 77 | |||
| 78 | /* Format the value, write all X if we can't read */ | ||
| 79 | ret = regmap_read(map, i, &val); | ||
| 80 | if (ret == 0) | ||
| 81 | snprintf(buf + buf_pos, count - buf_pos, | ||
| 82 | "%.*x", val_len, val); | ||
| 83 | else | ||
| 84 | memset(buf + buf_pos, 'X', val_len); | ||
| 85 | buf_pos += 2 * map->format.val_bytes; | ||
| 86 | |||
| 87 | buf[buf_pos++] = '\n'; | ||
| 88 | } | ||
| 89 | p += tot_len; | ||
| 90 | } | ||
| 91 | |||
| 92 | ret = buf_pos; | ||
| 93 | |||
| 94 | if (copy_to_user(user_buf, buf, buf_pos)) { | ||
| 95 | ret = -EFAULT; | ||
| 96 | goto out; | ||
| 97 | } | ||
| 98 | |||
| 99 | *ppos += buf_pos; | ||
| 100 | |||
| 101 | out: | ||
| 102 | kfree(buf); | ||
| 103 | return ret; | ||
| 104 | } | ||
| 105 | |||
| 106 | static const struct file_operations regmap_map_fops = { | ||
| 107 | .open = regmap_open_file, | ||
| 108 | .read = regmap_map_read_file, | ||
| 109 | .llseek = default_llseek, | ||
| 110 | }; | ||
| 111 | |||
| 112 | static ssize_t regmap_access_read_file(struct file *file, | ||
| 113 | char __user *user_buf, size_t count, | ||
| 114 | loff_t *ppos) | ||
| 115 | { | ||
| 116 | int reg_len, tot_len; | ||
| 117 | size_t buf_pos = 0; | ||
| 118 | loff_t p = 0; | ||
| 119 | ssize_t ret; | ||
| 120 | int i; | ||
| 121 | struct regmap *map = file->private_data; | ||
| 122 | char *buf; | ||
| 123 | |||
| 124 | if (*ppos < 0 || !count) | ||
| 125 | return -EINVAL; | ||
| 126 | |||
| 127 | buf = kmalloc(count, GFP_KERNEL); | ||
| 128 | if (!buf) | ||
| 129 | return -ENOMEM; | ||
| 130 | |||
| 131 | /* Calculate the length of a fixed format */ | ||
| 132 | reg_len = regmap_calc_reg_len(map->max_register, buf, count); | ||
| 133 | tot_len = reg_len + 10; /* ': R W V P\n' */ | ||
| 134 | |||
| 135 | for (i = 0; i < map->max_register + 1; i++) { | ||
| 136 | /* Ignore registers which are neither readable nor writable */ | ||
| 137 | if (!regmap_readable(map, i) && !regmap_writeable(map, i)) | ||
| 138 | continue; | ||
| 139 | |||
| 140 | /* If we're in the region the user is trying to read */ | ||
| 141 | if (p >= *ppos) { | ||
| 142 | /* ...but not beyond it */ | ||
| 143 | if (buf_pos >= count - 1 - tot_len) | ||
| 144 | break; | ||
| 145 | |||
| 146 | /* Format the register */ | ||
| 147 | snprintf(buf + buf_pos, count - buf_pos, | ||
| 148 | "%.*x: %c %c %c %c\n", | ||
| 149 | reg_len, i, | ||
| 150 | regmap_readable(map, i) ? 'y' : 'n', | ||
| 151 | regmap_writeable(map, i) ? 'y' : 'n', | ||
| 152 | regmap_volatile(map, i) ? 'y' : 'n', | ||
| 153 | regmap_precious(map, i) ? 'y' : 'n'); | ||
| 154 | |||
| 155 | buf_pos += tot_len; | ||
| 156 | } | ||
| 157 | p += tot_len; | ||
| 158 | } | ||
| 159 | |||
| 160 | ret = buf_pos; | ||
| 161 | |||
| 162 | if (copy_to_user(user_buf, buf, buf_pos)) { | ||
| 163 | ret = -EFAULT; | ||
| 164 | goto out; | ||
| 165 | } | ||
| 166 | |||
| 167 | *ppos += buf_pos; | ||
| 168 | |||
| 169 | out: | ||
| 170 | kfree(buf); | ||
| 171 | return ret; | ||
| 172 | } | ||
| 173 | |||
| 174 | static const struct file_operations regmap_access_fops = { | ||
| 175 | .open = regmap_open_file, | ||
| 176 | .read = regmap_access_read_file, | ||
| 177 | .llseek = default_llseek, | ||
| 178 | }; | ||
| 179 | |||
| 180 | void regmap_debugfs_init(struct regmap *map) | ||
| 181 | { | ||
| 182 | map->debugfs = debugfs_create_dir(dev_name(map->dev), | ||
| 183 | regmap_debugfs_root); | ||
| 184 | if (!map->debugfs) { | ||
| 185 | dev_warn(map->dev, "Failed to create debugfs directory\n"); | ||
| 186 | return; | ||
| 187 | } | ||
| 188 | |||
| 189 | if (map->max_register) { | ||
| 190 | debugfs_create_file("registers", 0400, map->debugfs, | ||
| 191 | map, ®map_map_fops); | ||
| 192 | debugfs_create_file("access", 0400, map->debugfs, | ||
| 193 | map, ®map_access_fops); | ||
| 194 | } | ||
| 195 | } | ||
| 196 | |||
| 197 | void regmap_debugfs_exit(struct regmap *map) | ||
| 198 | { | ||
| 199 | debugfs_remove_recursive(map->debugfs); | ||
| 200 | } | ||
| 201 | |||
| 202 | void regmap_debugfs_initcall(void) | ||
| 203 | { | ||
| 204 | regmap_debugfs_root = debugfs_create_dir("regmap", NULL); | ||
| 205 | if (!regmap_debugfs_root) { | ||
| 206 | pr_warn("regmap: Failed to create debugfs root\n"); | ||
| 207 | return; | ||
| 208 | } | ||
| 209 | } | ||
diff --git a/drivers/base/regmap/regmap-i2c.c b/drivers/base/regmap/regmap-i2c.c index c4f7a45cd2c3..38621ec87c05 100644 --- a/drivers/base/regmap/regmap-i2c.c +++ b/drivers/base/regmap/regmap-i2c.c | |||
| @@ -90,11 +90,9 @@ static int regmap_i2c_read(struct device *dev, | |||
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | static struct regmap_bus regmap_i2c = { | 92 | static struct regmap_bus regmap_i2c = { |
| 93 | .type = &i2c_bus_type, | ||
| 94 | .write = regmap_i2c_write, | 93 | .write = regmap_i2c_write, |
| 95 | .gather_write = regmap_i2c_gather_write, | 94 | .gather_write = regmap_i2c_gather_write, |
| 96 | .read = regmap_i2c_read, | 95 | .read = regmap_i2c_read, |
| 97 | .owner = THIS_MODULE, | ||
| 98 | }; | 96 | }; |
| 99 | 97 | ||
| 100 | /** | 98 | /** |
diff --git a/drivers/base/regmap/regmap-spi.c b/drivers/base/regmap/regmap-spi.c index f8396945d6ed..2560658de344 100644 --- a/drivers/base/regmap/regmap-spi.c +++ b/drivers/base/regmap/regmap-spi.c | |||
| @@ -48,11 +48,9 @@ static int regmap_spi_read(struct device *dev, | |||
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | static struct regmap_bus regmap_spi = { | 50 | static struct regmap_bus regmap_spi = { |
| 51 | .type = &spi_bus_type, | ||
| 52 | .write = regmap_spi_write, | 51 | .write = regmap_spi_write, |
| 53 | .gather_write = regmap_spi_gather_write, | 52 | .gather_write = regmap_spi_gather_write, |
| 54 | .read = regmap_spi_read, | 53 | .read = regmap_spi_read, |
| 55 | .owner = THIS_MODULE, | ||
| 56 | .read_flag_mask = 0x80, | 54 | .read_flag_mask = 0x80, |
| 57 | }; | 55 | }; |
| 58 | 56 | ||
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index 20663f8dae45..bf441db1ee90 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c | |||
| @@ -15,29 +15,54 @@ | |||
| 15 | #include <linux/mutex.h> | 15 | #include <linux/mutex.h> |
| 16 | #include <linux/err.h> | 16 | #include <linux/err.h> |
| 17 | 17 | ||
| 18 | #include <linux/regmap.h> | 18 | #define CREATE_TRACE_POINTS |
| 19 | 19 | #include <trace/events/regmap.h> | |
| 20 | struct regmap; | 20 | |
| 21 | 21 | #include "internal.h" | |
| 22 | struct regmap_format { | 22 | |
| 23 | size_t buf_size; | 23 | bool regmap_writeable(struct regmap *map, unsigned int reg) |
| 24 | size_t reg_bytes; | 24 | { |
| 25 | size_t val_bytes; | 25 | if (map->max_register && reg > map->max_register) |
| 26 | void (*format_write)(struct regmap *map, | 26 | return false; |
| 27 | unsigned int reg, unsigned int val); | 27 | |
| 28 | void (*format_reg)(void *buf, unsigned int reg); | 28 | if (map->writeable_reg) |
| 29 | void (*format_val)(void *buf, unsigned int val); | 29 | return map->writeable_reg(map->dev, reg); |
| 30 | unsigned int (*parse_val)(void *buf); | 30 | |
| 31 | }; | 31 | return true; |
| 32 | 32 | } | |
| 33 | struct regmap { | 33 | |
| 34 | struct mutex lock; | 34 | bool regmap_readable(struct regmap *map, unsigned int reg) |
| 35 | 35 | { | |
| 36 | struct device *dev; /* Device we do I/O on */ | 36 | if (map->max_register && reg > map->max_register) |
| 37 | void *work_buf; /* Scratch buffer used to format I/O */ | 37 | return false; |
| 38 | struct regmap_format format; /* Buffer format */ | 38 | |
| 39 | const struct regmap_bus *bus; | 39 | if (map->readable_reg) |
| 40 | }; | 40 | return map->readable_reg(map->dev, reg); |
| 41 | |||
| 42 | return true; | ||
| 43 | } | ||
| 44 | |||
| 45 | bool regmap_volatile(struct regmap *map, unsigned int reg) | ||
| 46 | { | ||
| 47 | if (map->max_register && reg > map->max_register) | ||
| 48 | return false; | ||
| 49 | |||
| 50 | if (map->volatile_reg) | ||
| 51 | return map->volatile_reg(map->dev, reg); | ||
| 52 | |||
| 53 | return true; | ||
| 54 | } | ||
| 55 | |||
| 56 | bool regmap_precious(struct regmap *map, unsigned int reg) | ||
| 57 | { | ||
| 58 | if (map->max_register && reg > map->max_register) | ||
| 59 | return false; | ||
| 60 | |||
| 61 | if (map->precious_reg) | ||
| 62 | return map->precious_reg(map->dev, reg); | ||
| 63 | |||
| 64 | return false; | ||
| 65 | } | ||
| 41 | 66 | ||
| 42 | static void regmap_format_4_12_write(struct regmap *map, | 67 | static void regmap_format_4_12_write(struct regmap *map, |
| 43 | unsigned int reg, unsigned int val) | 68 | unsigned int reg, unsigned int val) |
| @@ -116,6 +141,25 @@ struct regmap *regmap_init(struct device *dev, | |||
| 116 | map->format.val_bytes = config->val_bits / 8; | 141 | map->format.val_bytes = config->val_bits / 8; |
| 117 | map->dev = dev; | 142 | map->dev = dev; |
| 118 | map->bus = bus; | 143 | map->bus = bus; |
| 144 | map->max_register = config->max_register; | ||
| 145 | map->writeable_reg = config->writeable_reg; | ||
| 146 | map->readable_reg = config->readable_reg; | ||
| 147 | map->volatile_reg = config->volatile_reg; | ||
| 148 | map->precious_reg = config->precious_reg; | ||
| 149 | map->cache_type = config->cache_type; | ||
| 150 | map->reg_defaults = config->reg_defaults; | ||
| 151 | map->num_reg_defaults = config->num_reg_defaults; | ||
| 152 | map->num_reg_defaults_raw = config->num_reg_defaults_raw; | ||
| 153 | map->reg_defaults_raw = config->reg_defaults_raw; | ||
| 154 | map->cache_size_raw = (config->val_bits / 8) * config->num_reg_defaults_raw; | ||
| 155 | map->cache_word_size = config->val_bits / 8; | ||
| 156 | |||
| 157 | if (config->read_flag_mask || config->write_flag_mask) { | ||
| 158 | map->read_flag_mask = config->read_flag_mask; | ||
| 159 | map->write_flag_mask = config->write_flag_mask; | ||
| 160 | } else { | ||
| 161 | map->read_flag_mask = bus->read_flag_mask; | ||
| 162 | } | ||
| 119 | 163 | ||
| 120 | switch (config->reg_bits) { | 164 | switch (config->reg_bits) { |
| 121 | case 4: | 165 | case 4: |
| @@ -171,6 +215,12 @@ struct regmap *regmap_init(struct device *dev, | |||
| 171 | goto err_map; | 215 | goto err_map; |
| 172 | } | 216 | } |
| 173 | 217 | ||
| 218 | ret = regcache_init(map); | ||
| 219 | if (ret < 0) | ||
| 220 | goto err_map; | ||
| 221 | |||
| 222 | regmap_debugfs_init(map); | ||
| 223 | |||
| 174 | return map; | 224 | return map; |
| 175 | 225 | ||
| 176 | err_map: | 226 | err_map: |
| @@ -185,6 +235,8 @@ EXPORT_SYMBOL_GPL(regmap_init); | |||
| 185 | */ | 235 | */ |
| 186 | void regmap_exit(struct regmap *map) | 236 | void regmap_exit(struct regmap *map) |
| 187 | { | 237 | { |
| 238 | regcache_exit(map); | ||
| 239 | regmap_debugfs_exit(map); | ||
| 188 | kfree(map->work_buf); | 240 | kfree(map->work_buf); |
| 189 | kfree(map); | 241 | kfree(map); |
| 190 | } | 242 | } |
| @@ -193,19 +245,38 @@ EXPORT_SYMBOL_GPL(regmap_exit); | |||
| 193 | static int _regmap_raw_write(struct regmap *map, unsigned int reg, | 245 | static int _regmap_raw_write(struct regmap *map, unsigned int reg, |
| 194 | const void *val, size_t val_len) | 246 | const void *val, size_t val_len) |
| 195 | { | 247 | { |
| 248 | u8 *u8 = map->work_buf; | ||
| 196 | void *buf; | 249 | void *buf; |
| 197 | int ret = -ENOTSUPP; | 250 | int ret = -ENOTSUPP; |
| 198 | size_t len; | 251 | size_t len; |
| 252 | int i; | ||
| 253 | |||
| 254 | /* Check for unwritable registers before we start */ | ||
| 255 | if (map->writeable_reg) | ||
| 256 | for (i = 0; i < val_len / map->format.val_bytes; i++) | ||
| 257 | if (!map->writeable_reg(map->dev, reg + i)) | ||
| 258 | return -EINVAL; | ||
| 199 | 259 | ||
| 200 | map->format.format_reg(map->work_buf, reg); | 260 | map->format.format_reg(map->work_buf, reg); |
| 201 | 261 | ||
| 202 | /* Try to do a gather write if we can */ | 262 | u8[0] |= map->write_flag_mask; |
| 203 | if (map->bus->gather_write) | 263 | |
| 264 | trace_regmap_hw_write_start(map->dev, reg, | ||
| 265 | val_len / map->format.val_bytes); | ||
| 266 | |||
| 267 | /* If we're doing a single register write we can probably just | ||
| 268 | * send the work_buf directly, otherwise try to do a gather | ||
| 269 | * write. | ||
| 270 | */ | ||
| 271 | if (val == map->work_buf + map->format.reg_bytes) | ||
| 272 | ret = map->bus->write(map->dev, map->work_buf, | ||
| 273 | map->format.reg_bytes + val_len); | ||
| 274 | else if (map->bus->gather_write) | ||
| 204 | ret = map->bus->gather_write(map->dev, map->work_buf, | 275 | ret = map->bus->gather_write(map->dev, map->work_buf, |
| 205 | map->format.reg_bytes, | 276 | map->format.reg_bytes, |
| 206 | val, val_len); | 277 | val, val_len); |
| 207 | 278 | ||
| 208 | /* Otherwise fall back on linearising by hand. */ | 279 | /* If that didn't work fall back on linearising by hand. */ |
| 209 | if (ret == -ENOTSUPP) { | 280 | if (ret == -ENOTSUPP) { |
| 210 | len = map->format.reg_bytes + val_len; | 281 | len = map->format.reg_bytes + val_len; |
| 211 | buf = kmalloc(len, GFP_KERNEL); | 282 | buf = kmalloc(len, GFP_KERNEL); |
| @@ -219,19 +290,39 @@ static int _regmap_raw_write(struct regmap *map, unsigned int reg, | |||
| 219 | kfree(buf); | 290 | kfree(buf); |
| 220 | } | 291 | } |
| 221 | 292 | ||
| 293 | trace_regmap_hw_write_done(map->dev, reg, | ||
| 294 | val_len / map->format.val_bytes); | ||
| 295 | |||
| 222 | return ret; | 296 | return ret; |
| 223 | } | 297 | } |
| 224 | 298 | ||
| 225 | static int _regmap_write(struct regmap *map, unsigned int reg, | 299 | int _regmap_write(struct regmap *map, unsigned int reg, |
| 226 | unsigned int val) | 300 | unsigned int val) |
| 227 | { | 301 | { |
| 302 | int ret; | ||
| 228 | BUG_ON(!map->format.format_write && !map->format.format_val); | 303 | BUG_ON(!map->format.format_write && !map->format.format_val); |
| 229 | 304 | ||
| 305 | if (!map->cache_bypass) { | ||
| 306 | ret = regcache_write(map, reg, val); | ||
| 307 | if (ret != 0) | ||
| 308 | return ret; | ||
| 309 | if (map->cache_only) | ||
| 310 | return 0; | ||
| 311 | } | ||
| 312 | |||
| 313 | trace_regmap_reg_write(map->dev, reg, val); | ||
| 314 | |||
| 230 | if (map->format.format_write) { | 315 | if (map->format.format_write) { |
| 231 | map->format.format_write(map, reg, val); | 316 | map->format.format_write(map, reg, val); |
| 232 | 317 | ||
| 233 | return map->bus->write(map->dev, map->work_buf, | 318 | trace_regmap_hw_write_start(map->dev, reg, 1); |
| 234 | map->format.buf_size); | 319 | |
| 320 | ret = map->bus->write(map->dev, map->work_buf, | ||
| 321 | map->format.buf_size); | ||
| 322 | |||
| 323 | trace_regmap_hw_write_done(map->dev, reg, 1); | ||
| 324 | |||
| 325 | return ret; | ||
| 235 | } else { | 326 | } else { |
| 236 | map->format.format_val(map->work_buf + map->format.reg_bytes, | 327 | map->format.format_val(map->work_buf + map->format.reg_bytes, |
| 237 | val); | 328 | val); |
| @@ -286,6 +377,8 @@ int regmap_raw_write(struct regmap *map, unsigned int reg, | |||
| 286 | { | 377 | { |
| 287 | int ret; | 378 | int ret; |
| 288 | 379 | ||
| 380 | WARN_ON(map->cache_type != REGCACHE_NONE); | ||
| 381 | |||
| 289 | mutex_lock(&map->lock); | 382 | mutex_lock(&map->lock); |
| 290 | 383 | ||
| 291 | ret = _regmap_raw_write(map, reg, val, val_len); | 384 | ret = _regmap_raw_write(map, reg, val, val_len); |
| @@ -305,20 +398,23 @@ static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val, | |||
| 305 | map->format.format_reg(map->work_buf, reg); | 398 | map->format.format_reg(map->work_buf, reg); |
| 306 | 399 | ||
| 307 | /* | 400 | /* |
| 308 | * Some buses flag reads by setting the high bits in the | 401 | * Some buses or devices flag reads by setting the high bits in the |
| 309 | * register addresss; since it's always the high bits for all | 402 | * register addresss; since it's always the high bits for all |
| 310 | * current formats we can do this here rather than in | 403 | * current formats we can do this here rather than in |
| 311 | * formatting. This may break if we get interesting formats. | 404 | * formatting. This may break if we get interesting formats. |
| 312 | */ | 405 | */ |
| 313 | if (map->bus->read_flag_mask) | 406 | u8[0] |= map->read_flag_mask; |
| 314 | u8[0] |= map->bus->read_flag_mask; | 407 | |
| 408 | trace_regmap_hw_read_start(map->dev, reg, | ||
| 409 | val_len / map->format.val_bytes); | ||
| 315 | 410 | ||
| 316 | ret = map->bus->read(map->dev, map->work_buf, map->format.reg_bytes, | 411 | ret = map->bus->read(map->dev, map->work_buf, map->format.reg_bytes, |
| 317 | val, val_len); | 412 | val, val_len); |
| 318 | if (ret != 0) | ||
| 319 | return ret; | ||
| 320 | 413 | ||
| 321 | return 0; | 414 | trace_regmap_hw_read_done(map->dev, reg, |
| 415 | val_len / map->format.val_bytes); | ||
| 416 | |||
| 417 | return ret; | ||
| 322 | } | 418 | } |
| 323 | 419 | ||
| 324 | static int _regmap_read(struct regmap *map, unsigned int reg, | 420 | static int _regmap_read(struct regmap *map, unsigned int reg, |
| @@ -329,9 +425,20 @@ static int _regmap_read(struct regmap *map, unsigned int reg, | |||
| 329 | if (!map->format.parse_val) | 425 | if (!map->format.parse_val) |
| 330 | return -EINVAL; | 426 | return -EINVAL; |
| 331 | 427 | ||
| 428 | if (!map->cache_bypass) { | ||
| 429 | ret = regcache_read(map, reg, val); | ||
| 430 | if (ret == 0) | ||
| 431 | return 0; | ||
| 432 | } | ||
| 433 | |||
| 434 | if (map->cache_only) | ||
| 435 | return -EBUSY; | ||
| 436 | |||
| 332 | ret = _regmap_raw_read(map, reg, map->work_buf, map->format.val_bytes); | 437 | ret = _regmap_raw_read(map, reg, map->work_buf, map->format.val_bytes); |
| 333 | if (ret == 0) | 438 | if (ret == 0) { |
| 334 | *val = map->format.parse_val(map->work_buf); | 439 | *val = map->format.parse_val(map->work_buf); |
| 440 | trace_regmap_reg_read(map->dev, reg, *val); | ||
| 441 | } | ||
| 335 | 442 | ||
| 336 | return ret; | 443 | return ret; |
| 337 | } | 444 | } |
| @@ -375,6 +482,14 @@ int regmap_raw_read(struct regmap *map, unsigned int reg, void *val, | |||
| 375 | size_t val_len) | 482 | size_t val_len) |
| 376 | { | 483 | { |
| 377 | int ret; | 484 | int ret; |
| 485 | int i; | ||
| 486 | bool vol = true; | ||
| 487 | |||
| 488 | for (i = 0; i < val_len / map->format.val_bytes; i++) | ||
| 489 | if (!regmap_volatile(map, reg + i)) | ||
| 490 | vol = false; | ||
| 491 | |||
| 492 | WARN_ON(!vol && map->cache_type != REGCACHE_NONE); | ||
| 378 | 493 | ||
| 379 | mutex_lock(&map->lock); | 494 | mutex_lock(&map->lock); |
| 380 | 495 | ||
| @@ -402,16 +517,30 @@ int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val, | |||
| 402 | { | 517 | { |
| 403 | int ret, i; | 518 | int ret, i; |
| 404 | size_t val_bytes = map->format.val_bytes; | 519 | size_t val_bytes = map->format.val_bytes; |
| 520 | bool vol = true; | ||
| 405 | 521 | ||
| 406 | if (!map->format.parse_val) | 522 | if (!map->format.parse_val) |
| 407 | return -EINVAL; | 523 | return -EINVAL; |
| 408 | 524 | ||
| 409 | ret = regmap_raw_read(map, reg, val, val_bytes * val_count); | 525 | /* Is this a block of volatile registers? */ |
| 410 | if (ret != 0) | 526 | for (i = 0; i < val_count; i++) |
| 411 | return ret; | 527 | if (!regmap_volatile(map, reg + i)) |
| 528 | vol = false; | ||
| 529 | |||
| 530 | if (vol || map->cache_type == REGCACHE_NONE) { | ||
| 531 | ret = regmap_raw_read(map, reg, val, val_bytes * val_count); | ||
| 532 | if (ret != 0) | ||
| 533 | return ret; | ||
| 412 | 534 | ||
| 413 | for (i = 0; i < val_count * val_bytes; i += val_bytes) | 535 | for (i = 0; i < val_count * val_bytes; i += val_bytes) |
| 414 | map->format.parse_val(val + i); | 536 | map->format.parse_val(val + i); |
| 537 | } else { | ||
| 538 | for (i = 0; i < val_count; i++) { | ||
| 539 | ret = regmap_read(map, reg + i, val + (i * val_bytes)); | ||
| 540 | if (ret != 0) | ||
| 541 | return ret; | ||
| 542 | } | ||
| 543 | } | ||
| 415 | 544 | ||
| 416 | return 0; | 545 | return 0; |
| 417 | } | 546 | } |
| @@ -450,3 +579,11 @@ out: | |||
| 450 | return ret; | 579 | return ret; |
| 451 | } | 580 | } |
| 452 | EXPORT_SYMBOL_GPL(regmap_update_bits); | 581 | EXPORT_SYMBOL_GPL(regmap_update_bits); |
| 582 | |||
| 583 | static int __init regmap_initcall(void) | ||
| 584 | { | ||
| 585 | regmap_debugfs_initcall(); | ||
| 586 | |||
| 587 | return 0; | ||
| 588 | } | ||
| 589 | postcore_initcall(regmap_initcall); | ||
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 21574bdf485f..a67adcbd0fa1 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig | |||
| @@ -404,6 +404,7 @@ config MFD_WM831X_I2C | |||
| 404 | bool "Support Wolfson Microelectronics WM831x/2x PMICs with I2C" | 404 | bool "Support Wolfson Microelectronics WM831x/2x PMICs with I2C" |
| 405 | select MFD_CORE | 405 | select MFD_CORE |
| 406 | select MFD_WM831X | 406 | select MFD_WM831X |
| 407 | select REGMAP_I2C | ||
| 407 | depends on I2C=y && GENERIC_HARDIRQS | 408 | depends on I2C=y && GENERIC_HARDIRQS |
| 408 | help | 409 | help |
| 409 | Support for the Wolfson Microelecronics WM831x and WM832x PMICs | 410 | Support for the Wolfson Microelecronics WM831x and WM832x PMICs |
| @@ -415,6 +416,7 @@ config MFD_WM831X_SPI | |||
| 415 | bool "Support Wolfson Microelectronics WM831x/2x PMICs with SPI" | 416 | bool "Support Wolfson Microelectronics WM831x/2x PMICs with SPI" |
| 416 | select MFD_CORE | 417 | select MFD_CORE |
| 417 | select MFD_WM831X | 418 | select MFD_WM831X |
| 419 | select REGMAP_SPI | ||
| 418 | depends on SPI_MASTER && GENERIC_HARDIRQS | 420 | depends on SPI_MASTER && GENERIC_HARDIRQS |
| 419 | help | 421 | help |
| 420 | Support for the Wolfson Microelecronics WM831x and WM832x PMICs | 422 | Support for the Wolfson Microelecronics WM831x and WM832x PMICs |
| @@ -488,6 +490,7 @@ config MFD_WM8350_I2C | |||
| 488 | config MFD_WM8994 | 490 | config MFD_WM8994 |
| 489 | bool "Support Wolfson Microelectronics WM8994" | 491 | bool "Support Wolfson Microelectronics WM8994" |
| 490 | select MFD_CORE | 492 | select MFD_CORE |
| 493 | select REGMAP_I2C | ||
| 491 | depends on I2C=y && GENERIC_HARDIRQS | 494 | depends on I2C=y && GENERIC_HARDIRQS |
| 492 | help | 495 | help |
| 493 | The WM8994 is a highly integrated hi-fi CODEC designed for | 496 | The WM8994 is a highly integrated hi-fi CODEC designed for |
diff --git a/drivers/mfd/wm831x-core.c b/drivers/mfd/wm831x-core.c index 282e76ab678f..0a2b8d41a702 100644 --- a/drivers/mfd/wm831x-core.c +++ b/drivers/mfd/wm831x-core.c | |||
| @@ -18,12 +18,14 @@ | |||
| 18 | #include <linux/delay.h> | 18 | #include <linux/delay.h> |
| 19 | #include <linux/mfd/core.h> | 19 | #include <linux/mfd/core.h> |
| 20 | #include <linux/slab.h> | 20 | #include <linux/slab.h> |
| 21 | #include <linux/err.h> | ||
| 21 | 22 | ||
| 22 | #include <linux/mfd/wm831x/core.h> | 23 | #include <linux/mfd/wm831x/core.h> |
| 23 | #include <linux/mfd/wm831x/pdata.h> | 24 | #include <linux/mfd/wm831x/pdata.h> |
| 24 | #include <linux/mfd/wm831x/irq.h> | 25 | #include <linux/mfd/wm831x/irq.h> |
| 25 | #include <linux/mfd/wm831x/auxadc.h> | 26 | #include <linux/mfd/wm831x/auxadc.h> |
| 26 | #include <linux/mfd/wm831x/otp.h> | 27 | #include <linux/mfd/wm831x/otp.h> |
| 28 | #include <linux/mfd/wm831x/pmu.h> | ||
| 27 | #include <linux/mfd/wm831x/regulator.h> | 29 | #include <linux/mfd/wm831x/regulator.h> |
| 28 | 30 | ||
| 29 | /* Current settings - values are 2*2^(reg_val/4) microamps. These are | 31 | /* Current settings - values are 2*2^(reg_val/4) microamps. These are |
| @@ -160,27 +162,350 @@ int wm831x_reg_unlock(struct wm831x *wm831x) | |||
| 160 | } | 162 | } |
| 161 | EXPORT_SYMBOL_GPL(wm831x_reg_unlock); | 163 | EXPORT_SYMBOL_GPL(wm831x_reg_unlock); |
| 162 | 164 | ||
| 163 | static int wm831x_read(struct wm831x *wm831x, unsigned short reg, | 165 | static bool wm831x_reg_readable(struct device *dev, unsigned int reg) |
| 164 | int bytes, void *dest) | ||
| 165 | { | 166 | { |
| 166 | int ret, i; | 167 | switch (reg) { |
| 167 | u16 *buf = dest; | 168 | case WM831X_RESET_ID: |
| 168 | 169 | case WM831X_REVISION: | |
| 169 | BUG_ON(bytes % 2); | 170 | case WM831X_PARENT_ID: |
| 170 | BUG_ON(bytes <= 0); | 171 | case WM831X_SYSVDD_CONTROL: |
| 172 | case WM831X_THERMAL_MONITORING: | ||
| 173 | case WM831X_POWER_STATE: | ||
| 174 | case WM831X_WATCHDOG: | ||
| 175 | case WM831X_ON_PIN_CONTROL: | ||
| 176 | case WM831X_RESET_CONTROL: | ||
| 177 | case WM831X_CONTROL_INTERFACE: | ||
| 178 | case WM831X_SECURITY_KEY: | ||
| 179 | case WM831X_SOFTWARE_SCRATCH: | ||
| 180 | case WM831X_OTP_CONTROL: | ||
| 181 | case WM831X_GPIO_LEVEL: | ||
| 182 | case WM831X_SYSTEM_STATUS: | ||
| 183 | case WM831X_ON_SOURCE: | ||
| 184 | case WM831X_OFF_SOURCE: | ||
| 185 | case WM831X_SYSTEM_INTERRUPTS: | ||
| 186 | case WM831X_INTERRUPT_STATUS_1: | ||
| 187 | case WM831X_INTERRUPT_STATUS_2: | ||
| 188 | case WM831X_INTERRUPT_STATUS_3: | ||
| 189 | case WM831X_INTERRUPT_STATUS_4: | ||
| 190 | case WM831X_INTERRUPT_STATUS_5: | ||
| 191 | case WM831X_IRQ_CONFIG: | ||
| 192 | case WM831X_SYSTEM_INTERRUPTS_MASK: | ||
| 193 | case WM831X_INTERRUPT_STATUS_1_MASK: | ||
| 194 | case WM831X_INTERRUPT_STATUS_2_MASK: | ||
| 195 | case WM831X_INTERRUPT_STATUS_3_MASK: | ||
| 196 | case WM831X_INTERRUPT_STATUS_4_MASK: | ||
| 197 | case WM831X_INTERRUPT_STATUS_5_MASK: | ||
| 198 | case WM831X_RTC_WRITE_COUNTER: | ||
| 199 | case WM831X_RTC_TIME_1: | ||
| 200 | case WM831X_RTC_TIME_2: | ||
| 201 | case WM831X_RTC_ALARM_1: | ||
| 202 | case WM831X_RTC_ALARM_2: | ||
| 203 | case WM831X_RTC_CONTROL: | ||
| 204 | case WM831X_RTC_TRIM: | ||
| 205 | case WM831X_TOUCH_CONTROL_1: | ||
| 206 | case WM831X_TOUCH_CONTROL_2: | ||
| 207 | case WM831X_TOUCH_DATA_X: | ||
| 208 | case WM831X_TOUCH_DATA_Y: | ||
| 209 | case WM831X_TOUCH_DATA_Z: | ||
| 210 | case WM831X_AUXADC_DATA: | ||
| 211 | case WM831X_AUXADC_CONTROL: | ||
| 212 | case WM831X_AUXADC_SOURCE: | ||
| 213 | case WM831X_COMPARATOR_CONTROL: | ||
| 214 | case WM831X_COMPARATOR_1: | ||
| 215 | case WM831X_COMPARATOR_2: | ||
| 216 | case WM831X_COMPARATOR_3: | ||
| 217 | case WM831X_COMPARATOR_4: | ||
| 218 | case WM831X_GPIO1_CONTROL: | ||
| 219 | case WM831X_GPIO2_CONTROL: | ||
| 220 | case WM831X_GPIO3_CONTROL: | ||
| 221 | case WM831X_GPIO4_CONTROL: | ||
| 222 | case WM831X_GPIO5_CONTROL: | ||
| 223 | case WM831X_GPIO6_CONTROL: | ||
| 224 | case WM831X_GPIO7_CONTROL: | ||
| 225 | case WM831X_GPIO8_CONTROL: | ||
| 226 | case WM831X_GPIO9_CONTROL: | ||
| 227 | case WM831X_GPIO10_CONTROL: | ||
| 228 | case WM831X_GPIO11_CONTROL: | ||
| 229 | case WM831X_GPIO12_CONTROL: | ||
| 230 | case WM831X_GPIO13_CONTROL: | ||
| 231 | case WM831X_GPIO14_CONTROL: | ||
| 232 | case WM831X_GPIO15_CONTROL: | ||
| 233 | case WM831X_GPIO16_CONTROL: | ||
| 234 | case WM831X_CHARGER_CONTROL_1: | ||
| 235 | case WM831X_CHARGER_CONTROL_2: | ||
| 236 | case WM831X_CHARGER_STATUS: | ||
| 237 | case WM831X_BACKUP_CHARGER_CONTROL: | ||
| 238 | case WM831X_STATUS_LED_1: | ||
| 239 | case WM831X_STATUS_LED_2: | ||
| 240 | case WM831X_CURRENT_SINK_1: | ||
| 241 | case WM831X_CURRENT_SINK_2: | ||
| 242 | case WM831X_DCDC_ENABLE: | ||
| 243 | case WM831X_LDO_ENABLE: | ||
| 244 | case WM831X_DCDC_STATUS: | ||
| 245 | case WM831X_LDO_STATUS: | ||
| 246 | case WM831X_DCDC_UV_STATUS: | ||
| 247 | case WM831X_LDO_UV_STATUS: | ||
| 248 | case WM831X_DC1_CONTROL_1: | ||
| 249 | case WM831X_DC1_CONTROL_2: | ||
| 250 | case WM831X_DC1_ON_CONFIG: | ||
| 251 | case WM831X_DC1_SLEEP_CONTROL: | ||
| 252 | case WM831X_DC1_DVS_CONTROL: | ||
| 253 | case WM831X_DC2_CONTROL_1: | ||
| 254 | case WM831X_DC2_CONTROL_2: | ||
| 255 | case WM831X_DC2_ON_CONFIG: | ||
| 256 | case WM831X_DC2_SLEEP_CONTROL: | ||
| 257 | case WM831X_DC2_DVS_CONTROL: | ||
| 258 | case WM831X_DC3_CONTROL_1: | ||
| 259 | case WM831X_DC3_CONTROL_2: | ||
| 260 | case WM831X_DC3_ON_CONFIG: | ||
| 261 | case WM831X_DC3_SLEEP_CONTROL: | ||
| 262 | case WM831X_DC4_CONTROL: | ||
| 263 | case WM831X_DC4_SLEEP_CONTROL: | ||
| 264 | case WM831X_EPE1_CONTROL: | ||
| 265 | case WM831X_EPE2_CONTROL: | ||
| 266 | case WM831X_LDO1_CONTROL: | ||
| 267 | case WM831X_LDO1_ON_CONTROL: | ||
| 268 | case WM831X_LDO1_SLEEP_CONTROL: | ||
| 269 | case WM831X_LDO2_CONTROL: | ||
| 270 | case WM831X_LDO2_ON_CONTROL: | ||
| 271 | case WM831X_LDO2_SLEEP_CONTROL: | ||
| 272 | case WM831X_LDO3_CONTROL: | ||
| 273 | case WM831X_LDO3_ON_CONTROL: | ||
| 274 | case WM831X_LDO3_SLEEP_CONTROL: | ||
| 275 | case WM831X_LDO4_CONTROL: | ||
| 276 | case WM831X_LDO4_ON_CONTROL: | ||
| 277 | case WM831X_LDO4_SLEEP_CONTROL: | ||
| 278 | case WM831X_LDO5_CONTROL: | ||
| 279 | case WM831X_LDO5_ON_CONTROL: | ||
| 280 | case WM831X_LDO5_SLEEP_CONTROL: | ||
| 281 | case WM831X_LDO6_CONTROL: | ||
| 282 | case WM831X_LDO6_ON_CONTROL: | ||
| 283 | case WM831X_LDO6_SLEEP_CONTROL: | ||
| 284 | case WM831X_LDO7_CONTROL: | ||
| 285 | case WM831X_LDO7_ON_CONTROL: | ||
| 286 | case WM831X_LDO7_SLEEP_CONTROL: | ||
| 287 | case WM831X_LDO8_CONTROL: | ||
| 288 | case WM831X_LDO8_ON_CONTROL: | ||
| 289 | case WM831X_LDO8_SLEEP_CONTROL: | ||
| 290 | case WM831X_LDO9_CONTROL: | ||
| 291 | case WM831X_LDO9_ON_CONTROL: | ||
| 292 | case WM831X_LDO9_SLEEP_CONTROL: | ||
| 293 | case WM831X_LDO10_CONTROL: | ||
| 294 | case WM831X_LDO10_ON_CONTROL: | ||
| 295 | case WM831X_LDO10_SLEEP_CONTROL: | ||
| 296 | case WM831X_LDO11_ON_CONTROL: | ||
| 297 | case WM831X_LDO11_SLEEP_CONTROL: | ||
| 298 | case WM831X_POWER_GOOD_SOURCE_1: | ||
| 299 | case WM831X_POWER_GOOD_SOURCE_2: | ||
| 300 | case WM831X_CLOCK_CONTROL_1: | ||
| 301 | case WM831X_CLOCK_CONTROL_2: | ||
| 302 | case WM831X_FLL_CONTROL_1: | ||
| 303 | case WM831X_FLL_CONTROL_2: | ||
| 304 | case WM831X_FLL_CONTROL_3: | ||
| 305 | case WM831X_FLL_CONTROL_4: | ||
| 306 | case WM831X_FLL_CONTROL_5: | ||
| 307 | case WM831X_UNIQUE_ID_1: | ||
| 308 | case WM831X_UNIQUE_ID_2: | ||
| 309 | case WM831X_UNIQUE_ID_3: | ||
| 310 | case WM831X_UNIQUE_ID_4: | ||
| 311 | case WM831X_UNIQUE_ID_5: | ||
| 312 | case WM831X_UNIQUE_ID_6: | ||
| 313 | case WM831X_UNIQUE_ID_7: | ||
| 314 | case WM831X_UNIQUE_ID_8: | ||
| 315 | case WM831X_FACTORY_OTP_ID: | ||
| 316 | case WM831X_FACTORY_OTP_1: | ||
| 317 | case WM831X_FACTORY_OTP_2: | ||
| 318 | case WM831X_FACTORY_OTP_3: | ||
| 319 | case WM831X_FACTORY_OTP_4: | ||
| 320 | case WM831X_FACTORY_OTP_5: | ||
| 321 | case WM831X_CUSTOMER_OTP_ID: | ||
| 322 | case WM831X_DC1_OTP_CONTROL: | ||
| 323 | case WM831X_DC2_OTP_CONTROL: | ||
| 324 | case WM831X_DC3_OTP_CONTROL: | ||
| 325 | case WM831X_LDO1_2_OTP_CONTROL: | ||
| 326 | case WM831X_LDO3_4_OTP_CONTROL: | ||
| 327 | case WM831X_LDO5_6_OTP_CONTROL: | ||
| 328 | case WM831X_LDO7_8_OTP_CONTROL: | ||
| 329 | case WM831X_LDO9_10_OTP_CONTROL: | ||
| 330 | case WM831X_LDO11_EPE_CONTROL: | ||
| 331 | case WM831X_GPIO1_OTP_CONTROL: | ||
| 332 | case WM831X_GPIO2_OTP_CONTROL: | ||
| 333 | case WM831X_GPIO3_OTP_CONTROL: | ||
| 334 | case WM831X_GPIO4_OTP_CONTROL: | ||
| 335 | case WM831X_GPIO5_OTP_CONTROL: | ||
| 336 | case WM831X_GPIO6_OTP_CONTROL: | ||
| 337 | case WM831X_DBE_CHECK_DATA: | ||
| 338 | return true; | ||
| 339 | default: | ||
| 340 | return false; | ||
| 341 | } | ||
| 342 | } | ||
| 171 | 343 | ||
| 172 | ret = wm831x->read_dev(wm831x, reg, bytes, dest); | 344 | static bool wm831x_reg_writeable(struct device *dev, unsigned int reg) |
| 173 | if (ret < 0) | 345 | { |
| 174 | return ret; | 346 | struct wm831x *wm831x = dev_get_drvdata(dev); |
| 175 | 347 | ||
| 176 | for (i = 0; i < bytes / 2; i++) { | 348 | if (wm831x_reg_locked(wm831x, reg)) |
| 177 | buf[i] = be16_to_cpu(buf[i]); | 349 | return false; |
| 178 | 350 | ||
| 179 | dev_vdbg(wm831x->dev, "Read %04x from R%d(0x%x)\n", | 351 | switch (reg) { |
| 180 | buf[i], reg + i, reg + i); | 352 | case WM831X_SYSVDD_CONTROL: |
| 353 | case WM831X_THERMAL_MONITORING: | ||
| 354 | case WM831X_POWER_STATE: | ||
| 355 | case WM831X_WATCHDOG: | ||
| 356 | case WM831X_ON_PIN_CONTROL: | ||
| 357 | case WM831X_RESET_CONTROL: | ||
| 358 | case WM831X_CONTROL_INTERFACE: | ||
| 359 | case WM831X_SECURITY_KEY: | ||
| 360 | case WM831X_SOFTWARE_SCRATCH: | ||
| 361 | case WM831X_OTP_CONTROL: | ||
| 362 | case WM831X_GPIO_LEVEL: | ||
| 363 | case WM831X_INTERRUPT_STATUS_1: | ||
| 364 | case WM831X_INTERRUPT_STATUS_2: | ||
| 365 | case WM831X_INTERRUPT_STATUS_3: | ||
| 366 | case WM831X_INTERRUPT_STATUS_4: | ||
| 367 | case WM831X_INTERRUPT_STATUS_5: | ||
| 368 | case WM831X_IRQ_CONFIG: | ||
| 369 | case WM831X_SYSTEM_INTERRUPTS_MASK: | ||
| 370 | case WM831X_INTERRUPT_STATUS_1_MASK: | ||
| 371 | case WM831X_INTERRUPT_STATUS_2_MASK: | ||
| 372 | case WM831X_INTERRUPT_STATUS_3_MASK: | ||
| 373 | case WM831X_INTERRUPT_STATUS_4_MASK: | ||
| 374 | case WM831X_INTERRUPT_STATUS_5_MASK: | ||
| 375 | case WM831X_RTC_TIME_1: | ||
| 376 | case WM831X_RTC_TIME_2: | ||
| 377 | case WM831X_RTC_ALARM_1: | ||
| 378 | case WM831X_RTC_ALARM_2: | ||
| 379 | case WM831X_RTC_CONTROL: | ||
| 380 | case WM831X_RTC_TRIM: | ||
| 381 | case WM831X_TOUCH_CONTROL_1: | ||
| 382 | case WM831X_TOUCH_CONTROL_2: | ||
| 383 | case WM831X_AUXADC_CONTROL: | ||
| 384 | case WM831X_AUXADC_SOURCE: | ||
| 385 | case WM831X_COMPARATOR_CONTROL: | ||
| 386 | case WM831X_COMPARATOR_1: | ||
| 387 | case WM831X_COMPARATOR_2: | ||
| 388 | case WM831X_COMPARATOR_3: | ||
| 389 | case WM831X_COMPARATOR_4: | ||
| 390 | case WM831X_GPIO1_CONTROL: | ||
| 391 | case WM831X_GPIO2_CONTROL: | ||
| 392 | case WM831X_GPIO3_CONTROL: | ||
| 393 | case WM831X_GPIO4_CONTROL: | ||
| 394 | case WM831X_GPIO5_CONTROL: | ||
| 395 | case WM831X_GPIO6_CONTROL: | ||
| 396 | case WM831X_GPIO7_CONTROL: | ||
| 397 | case WM831X_GPIO8_CONTROL: | ||
| 398 | case WM831X_GPIO9_CONTROL: | ||
| 399 | case WM831X_GPIO10_CONTROL: | ||
| 400 | case WM831X_GPIO11_CONTROL: | ||
| 401 | case WM831X_GPIO12_CONTROL: | ||
| 402 | case WM831X_GPIO13_CONTROL: | ||
| 403 | case WM831X_GPIO14_CONTROL: | ||
| 404 | case WM831X_GPIO15_CONTROL: | ||
| 405 | case WM831X_GPIO16_CONTROL: | ||
| 406 | case WM831X_CHARGER_CONTROL_1: | ||
| 407 | case WM831X_CHARGER_CONTROL_2: | ||
| 408 | case WM831X_CHARGER_STATUS: | ||
| 409 | case WM831X_BACKUP_CHARGER_CONTROL: | ||
| 410 | case WM831X_STATUS_LED_1: | ||
| 411 | case WM831X_STATUS_LED_2: | ||
| 412 | case WM831X_CURRENT_SINK_1: | ||
| 413 | case WM831X_CURRENT_SINK_2: | ||
| 414 | case WM831X_DCDC_ENABLE: | ||
| 415 | case WM831X_LDO_ENABLE: | ||
| 416 | case WM831X_DC1_CONTROL_1: | ||
| 417 | case WM831X_DC1_CONTROL_2: | ||
| 418 | case WM831X_DC1_ON_CONFIG: | ||
| 419 | case WM831X_DC1_SLEEP_CONTROL: | ||
| 420 | case WM831X_DC1_DVS_CONTROL: | ||
| 421 | case WM831X_DC2_CONTROL_1: | ||
| 422 | case WM831X_DC2_CONTROL_2: | ||
| 423 | case WM831X_DC2_ON_CONFIG: | ||
| 424 | case WM831X_DC2_SLEEP_CONTROL: | ||
| 425 | case WM831X_DC2_DVS_CONTROL: | ||
| 426 | case WM831X_DC3_CONTROL_1: | ||
| 427 | case WM831X_DC3_CONTROL_2: | ||
| 428 | case WM831X_DC3_ON_CONFIG: | ||
| 429 | case WM831X_DC3_SLEEP_CONTROL: | ||
| 430 | case WM831X_DC4_CONTROL: | ||
| 431 | case WM831X_DC4_SLEEP_CONTROL: | ||
| 432 | case WM831X_EPE1_CONTROL: | ||
| 433 | case WM831X_EPE2_CONTROL: | ||
| 434 | case WM831X_LDO1_CONTROL: | ||
| 435 | case WM831X_LDO1_ON_CONTROL: | ||
| 436 | case WM831X_LDO1_SLEEP_CONTROL: | ||
| 437 | case WM831X_LDO2_CONTROL: | ||
| 438 | case WM831X_LDO2_ON_CONTROL: | ||
| 439 | case WM831X_LDO2_SLEEP_CONTROL: | ||
| 440 | case WM831X_LDO3_CONTROL: | ||
| 441 | case WM831X_LDO3_ON_CONTROL: | ||
| 442 | case WM831X_LDO3_SLEEP_CONTROL: | ||
| 443 | case WM831X_LDO4_CONTROL: | ||
| 444 | case WM831X_LDO4_ON_CONTROL: | ||
| 445 | case WM831X_LDO4_SLEEP_CONTROL: | ||
| 446 | case WM831X_LDO5_CONTROL: | ||
| 447 | case WM831X_LDO5_ON_CONTROL: | ||
| 448 | case WM831X_LDO5_SLEEP_CONTROL: | ||
| 449 | case WM831X_LDO6_CONTROL: | ||
| 450 | case WM831X_LDO6_ON_CONTROL: | ||
| 451 | case WM831X_LDO6_SLEEP_CONTROL: | ||
| 452 | case WM831X_LDO7_CONTROL: | ||
| 453 | case WM831X_LDO7_ON_CONTROL: | ||
| 454 | case WM831X_LDO7_SLEEP_CONTROL: | ||
| 455 | case WM831X_LDO8_CONTROL: | ||
| 456 | case WM831X_LDO8_ON_CONTROL: | ||
| 457 | case WM831X_LDO8_SLEEP_CONTROL: | ||
| 458 | case WM831X_LDO9_CONTROL: | ||
| 459 | case WM831X_LDO9_ON_CONTROL: | ||
| 460 | case WM831X_LDO9_SLEEP_CONTROL: | ||
| 461 | case WM831X_LDO10_CONTROL: | ||
| 462 | case WM831X_LDO10_ON_CONTROL: | ||
| 463 | case WM831X_LDO10_SLEEP_CONTROL: | ||
| 464 | case WM831X_LDO11_ON_CONTROL: | ||
| 465 | case WM831X_LDO11_SLEEP_CONTROL: | ||
| 466 | case WM831X_POWER_GOOD_SOURCE_1: | ||
| 467 | case WM831X_POWER_GOOD_SOURCE_2: | ||
| 468 | case WM831X_CLOCK_CONTROL_1: | ||
| 469 | case WM831X_CLOCK_CONTROL_2: | ||
| 470 | case WM831X_FLL_CONTROL_1: | ||
| 471 | case WM831X_FLL_CONTROL_2: | ||
| 472 | case WM831X_FLL_CONTROL_3: | ||
| 473 | case WM831X_FLL_CONTROL_4: | ||
| 474 | case WM831X_FLL_CONTROL_5: | ||
| 475 | return true; | ||
| 476 | default: | ||
| 477 | return false; | ||
| 181 | } | 478 | } |
| 479 | } | ||
| 182 | 480 | ||
| 183 | return 0; | 481 | static bool wm831x_reg_volatile(struct device *dev, unsigned int reg) |
| 482 | { | ||
| 483 | switch (reg) { | ||
| 484 | case WM831X_SYSTEM_STATUS: | ||
| 485 | case WM831X_ON_SOURCE: | ||
| 486 | case WM831X_OFF_SOURCE: | ||
| 487 | case WM831X_GPIO_LEVEL: | ||
| 488 | case WM831X_SYSTEM_INTERRUPTS: | ||
| 489 | case WM831X_INTERRUPT_STATUS_1: | ||
| 490 | case WM831X_INTERRUPT_STATUS_2: | ||
| 491 | case WM831X_INTERRUPT_STATUS_3: | ||
| 492 | case WM831X_INTERRUPT_STATUS_4: | ||
| 493 | case WM831X_INTERRUPT_STATUS_5: | ||
| 494 | case WM831X_RTC_TIME_1: | ||
| 495 | case WM831X_RTC_TIME_2: | ||
| 496 | case WM831X_TOUCH_DATA_X: | ||
| 497 | case WM831X_TOUCH_DATA_Y: | ||
| 498 | case WM831X_TOUCH_DATA_Z: | ||
| 499 | case WM831X_AUXADC_DATA: | ||
| 500 | case WM831X_CHARGER_STATUS: | ||
| 501 | case WM831X_DCDC_STATUS: | ||
| 502 | case WM831X_LDO_STATUS: | ||
| 503 | case WM831X_DCDC_UV_STATUS: | ||
| 504 | case WM831X_LDO_UV_STATUS: | ||
| 505 | return true; | ||
| 506 | default: | ||
| 507 | return false; | ||
| 508 | } | ||
| 184 | } | 509 | } |
| 185 | 510 | ||
| 186 | /** | 511 | /** |
| @@ -191,14 +516,10 @@ static int wm831x_read(struct wm831x *wm831x, unsigned short reg, | |||
| 191 | */ | 516 | */ |
| 192 | int wm831x_reg_read(struct wm831x *wm831x, unsigned short reg) | 517 | int wm831x_reg_read(struct wm831x *wm831x, unsigned short reg) |
| 193 | { | 518 | { |
| 194 | unsigned short val; | 519 | unsigned int val; |
| 195 | int ret; | 520 | int ret; |
| 196 | 521 | ||
| 197 | mutex_lock(&wm831x->io_lock); | 522 | ret = regmap_read(wm831x->regmap, reg, &val); |
| 198 | |||
| 199 | ret = wm831x_read(wm831x, reg, 2, &val); | ||
| 200 | |||
| 201 | mutex_unlock(&wm831x->io_lock); | ||
| 202 | 523 | ||
| 203 | if (ret < 0) | 524 | if (ret < 0) |
| 204 | return ret; | 525 | return ret; |
| @@ -218,15 +539,7 @@ EXPORT_SYMBOL_GPL(wm831x_reg_read); | |||
| 218 | int wm831x_bulk_read(struct wm831x *wm831x, unsigned short reg, | 539 | int wm831x_bulk_read(struct wm831x *wm831x, unsigned short reg, |
| 219 | int count, u16 *buf) | 540 | int count, u16 *buf) |
| 220 | { | 541 | { |
| 221 | int ret; | 542 | return regmap_bulk_read(wm831x->regmap, reg, buf, count); |
| 222 | |||
| 223 | mutex_lock(&wm831x->io_lock); | ||
| 224 | |||
| 225 | ret = wm831x_read(wm831x, reg, count * 2, buf); | ||
| 226 | |||
| 227 | mutex_unlock(&wm831x->io_lock); | ||
| 228 | |||
| 229 | return ret; | ||
| 230 | } | 543 | } |
| 231 | EXPORT_SYMBOL_GPL(wm831x_bulk_read); | 544 | EXPORT_SYMBOL_GPL(wm831x_bulk_read); |
| 232 | 545 | ||
| @@ -234,7 +547,7 @@ static int wm831x_write(struct wm831x *wm831x, unsigned short reg, | |||
| 234 | int bytes, void *src) | 547 | int bytes, void *src) |
| 235 | { | 548 | { |
| 236 | u16 *buf = src; | 549 | u16 *buf = src; |
| 237 | int i; | 550 | int i, ret; |
| 238 | 551 | ||
| 239 | BUG_ON(bytes % 2); | 552 | BUG_ON(bytes % 2); |
| 240 | BUG_ON(bytes <= 0); | 553 | BUG_ON(bytes <= 0); |
| @@ -245,11 +558,10 @@ static int wm831x_write(struct wm831x *wm831x, unsigned short reg, | |||
| 245 | 558 | ||
| 246 | dev_vdbg(wm831x->dev, "Write %04x to R%d(0x%x)\n", | 559 | dev_vdbg(wm831x->dev, "Write %04x to R%d(0x%x)\n", |
| 247 | buf[i], reg + i, reg + i); | 560 | buf[i], reg + i, reg + i); |
| 248 | 561 | ret = regmap_write(wm831x->regmap, reg + i, buf[i]); | |
| 249 | buf[i] = cpu_to_be16(buf[i]); | ||
| 250 | } | 562 | } |
| 251 | 563 | ||
| 252 | return wm831x->write_dev(wm831x, reg, bytes, src); | 564 | return 0; |
| 253 | } | 565 | } |
| 254 | 566 | ||
| 255 | /** | 567 | /** |
| @@ -286,20 +598,14 @@ int wm831x_set_bits(struct wm831x *wm831x, unsigned short reg, | |||
| 286 | unsigned short mask, unsigned short val) | 598 | unsigned short mask, unsigned short val) |
| 287 | { | 599 | { |
| 288 | int ret; | 600 | int ret; |
| 289 | u16 r; | ||
| 290 | 601 | ||
| 291 | mutex_lock(&wm831x->io_lock); | 602 | mutex_lock(&wm831x->io_lock); |
| 292 | 603 | ||
| 293 | ret = wm831x_read(wm831x, reg, 2, &r); | 604 | if (!wm831x_reg_locked(wm831x, reg)) |
| 294 | if (ret < 0) | 605 | ret = regmap_update_bits(wm831x->regmap, reg, mask, val); |
| 295 | goto out; | 606 | else |
| 296 | 607 | ret = -EPERM; | |
| 297 | r &= ~mask; | ||
| 298 | r |= val & mask; | ||
| 299 | |||
| 300 | ret = wm831x_write(wm831x, reg, 2, &r); | ||
| 301 | 608 | ||
| 302 | out: | ||
| 303 | mutex_unlock(&wm831x->io_lock); | 609 | mutex_unlock(&wm831x->io_lock); |
| 304 | 610 | ||
| 305 | return ret; | 611 | return ret; |
| @@ -1292,6 +1598,19 @@ static struct mfd_cell backlight_devs[] = { | |||
| 1292 | }, | 1598 | }, |
| 1293 | }; | 1599 | }; |
| 1294 | 1600 | ||
| 1601 | struct regmap_config wm831x_regmap_config = { | ||
| 1602 | .reg_bits = 16, | ||
| 1603 | .val_bits = 16, | ||
| 1604 | |||
| 1605 | .cache_type = REGCACHE_RBTREE, | ||
| 1606 | |||
| 1607 | .max_register = WM831X_DBE_CHECK_DATA, | ||
| 1608 | .readable_reg = wm831x_reg_readable, | ||
| 1609 | .writeable_reg = wm831x_reg_writeable, | ||
| 1610 | .volatile_reg = wm831x_reg_volatile, | ||
| 1611 | }; | ||
| 1612 | EXPORT_SYMBOL_GPL(wm831x_regmap_config); | ||
| 1613 | |||
| 1295 | /* | 1614 | /* |
| 1296 | * Instantiate the generic non-control parts of the device. | 1615 | * Instantiate the generic non-control parts of the device. |
| 1297 | */ | 1616 | */ |
| @@ -1305,11 +1624,12 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq) | |||
| 1305 | mutex_init(&wm831x->io_lock); | 1624 | mutex_init(&wm831x->io_lock); |
| 1306 | mutex_init(&wm831x->key_lock); | 1625 | mutex_init(&wm831x->key_lock); |
| 1307 | dev_set_drvdata(wm831x->dev, wm831x); | 1626 | dev_set_drvdata(wm831x->dev, wm831x); |
| 1627 | wm831x->soft_shutdown = pdata->soft_shutdown; | ||
| 1308 | 1628 | ||
| 1309 | ret = wm831x_reg_read(wm831x, WM831X_PARENT_ID); | 1629 | ret = wm831x_reg_read(wm831x, WM831X_PARENT_ID); |
| 1310 | if (ret < 0) { | 1630 | if (ret < 0) { |
| 1311 | dev_err(wm831x->dev, "Failed to read parent ID: %d\n", ret); | 1631 | dev_err(wm831x->dev, "Failed to read parent ID: %d\n", ret); |
| 1312 | goto err; | 1632 | goto err_regmap; |
| 1313 | } | 1633 | } |
| 1314 | switch (ret) { | 1634 | switch (ret) { |
| 1315 | case 0x6204: | 1635 | case 0x6204: |
| @@ -1318,20 +1638,20 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq) | |||
| 1318 | default: | 1638 | default: |
| 1319 | dev_err(wm831x->dev, "Device is not a WM831x: ID %x\n", ret); | 1639 | dev_err(wm831x->dev, "Device is not a WM831x: ID %x\n", ret); |
| 1320 | ret = -EINVAL; | 1640 | ret = -EINVAL; |
| 1321 | goto err; | 1641 | goto err_regmap; |
| 1322 | } | 1642 | } |
| 1323 | 1643 | ||
| 1324 | ret = wm831x_reg_read(wm831x, WM831X_REVISION); | 1644 | ret = wm831x_reg_read(wm831x, WM831X_REVISION); |
| 1325 | if (ret < 0) { | 1645 | if (ret < 0) { |
| 1326 | dev_err(wm831x->dev, "Failed to read revision: %d\n", ret); | 1646 | dev_err(wm831x->dev, "Failed to read revision: %d\n", ret); |
| 1327 | goto err; | 1647 | goto err_regmap; |
| 1328 | } | 1648 | } |
| 1329 | rev = (ret & WM831X_PARENT_REV_MASK) >> WM831X_PARENT_REV_SHIFT; | 1649 | rev = (ret & WM831X_PARENT_REV_MASK) >> WM831X_PARENT_REV_SHIFT; |
| 1330 | 1650 | ||
| 1331 | ret = wm831x_reg_read(wm831x, WM831X_RESET_ID); | 1651 | ret = wm831x_reg_read(wm831x, WM831X_RESET_ID); |
| 1332 | if (ret < 0) { | 1652 | if (ret < 0) { |
| 1333 | dev_err(wm831x->dev, "Failed to read device ID: %d\n", ret); | 1653 | dev_err(wm831x->dev, "Failed to read device ID: %d\n", ret); |
| 1334 | goto err; | 1654 | goto err_regmap; |
| 1335 | } | 1655 | } |
| 1336 | 1656 | ||
| 1337 | /* Some engineering samples do not have the ID set, rely on | 1657 | /* Some engineering samples do not have the ID set, rely on |
| @@ -1406,7 +1726,7 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq) | |||
| 1406 | default: | 1726 | default: |
| 1407 | dev_err(wm831x->dev, "Unknown WM831x device %04x\n", ret); | 1727 | dev_err(wm831x->dev, "Unknown WM831x device %04x\n", ret); |
| 1408 | ret = -EINVAL; | 1728 | ret = -EINVAL; |
| 1409 | goto err; | 1729 | goto err_regmap; |
| 1410 | } | 1730 | } |
| 1411 | 1731 | ||
| 1412 | /* This will need revisiting in future but is OK for all | 1732 | /* This will need revisiting in future but is OK for all |
| @@ -1420,7 +1740,7 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq) | |||
| 1420 | ret = wm831x_reg_read(wm831x, WM831X_SECURITY_KEY); | 1740 | ret = wm831x_reg_read(wm831x, WM831X_SECURITY_KEY); |
| 1421 | if (ret < 0) { | 1741 | if (ret < 0) { |
| 1422 | dev_err(wm831x->dev, "Failed to read security key: %d\n", ret); | 1742 | dev_err(wm831x->dev, "Failed to read security key: %d\n", ret); |
| 1423 | goto err; | 1743 | goto err_regmap; |
| 1424 | } | 1744 | } |
| 1425 | if (ret != 0) { | 1745 | if (ret != 0) { |
| 1426 | dev_warn(wm831x->dev, "Security key had non-zero value %x\n", | 1746 | dev_warn(wm831x->dev, "Security key had non-zero value %x\n", |
| @@ -1433,7 +1753,7 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq) | |||
| 1433 | ret = pdata->pre_init(wm831x); | 1753 | ret = pdata->pre_init(wm831x); |
| 1434 | if (ret != 0) { | 1754 | if (ret != 0) { |
| 1435 | dev_err(wm831x->dev, "pre_init() failed: %d\n", ret); | 1755 | dev_err(wm831x->dev, "pre_init() failed: %d\n", ret); |
| 1436 | goto err; | 1756 | goto err_regmap; |
| 1437 | } | 1757 | } |
| 1438 | } | 1758 | } |
| 1439 | 1759 | ||
| @@ -1456,7 +1776,7 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq) | |||
| 1456 | 1776 | ||
| 1457 | ret = wm831x_irq_init(wm831x, irq); | 1777 | ret = wm831x_irq_init(wm831x, irq); |
| 1458 | if (ret != 0) | 1778 | if (ret != 0) |
| 1459 | goto err; | 1779 | goto err_regmap; |
| 1460 | 1780 | ||
| 1461 | wm831x_auxadc_init(wm831x); | 1781 | wm831x_auxadc_init(wm831x); |
| 1462 | 1782 | ||
| @@ -1552,8 +1872,9 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq) | |||
| 1552 | 1872 | ||
| 1553 | err_irq: | 1873 | err_irq: |
| 1554 | wm831x_irq_exit(wm831x); | 1874 | wm831x_irq_exit(wm831x); |
| 1555 | err: | 1875 | err_regmap: |
| 1556 | mfd_remove_devices(wm831x->dev); | 1876 | mfd_remove_devices(wm831x->dev); |
| 1877 | regmap_exit(wm831x->regmap); | ||
| 1557 | kfree(wm831x); | 1878 | kfree(wm831x); |
| 1558 | return ret; | 1879 | return ret; |
| 1559 | } | 1880 | } |
| @@ -1565,6 +1886,7 @@ void wm831x_device_exit(struct wm831x *wm831x) | |||
| 1565 | if (wm831x->irq_base) | 1886 | if (wm831x->irq_base) |
| 1566 | free_irq(wm831x->irq_base + WM831X_IRQ_AUXADC_DATA, wm831x); | 1887 | free_irq(wm831x->irq_base + WM831X_IRQ_AUXADC_DATA, wm831x); |
| 1567 | wm831x_irq_exit(wm831x); | 1888 | wm831x_irq_exit(wm831x); |
| 1889 | regmap_exit(wm831x->regmap); | ||
| 1568 | kfree(wm831x); | 1890 | kfree(wm831x); |
| 1569 | } | 1891 | } |
| 1570 | 1892 | ||
| @@ -1604,6 +1926,15 @@ int wm831x_device_suspend(struct wm831x *wm831x) | |||
| 1604 | return 0; | 1926 | return 0; |
| 1605 | } | 1927 | } |
| 1606 | 1928 | ||
| 1929 | void wm831x_device_shutdown(struct wm831x *wm831x) | ||
| 1930 | { | ||
| 1931 | if (wm831x->soft_shutdown) { | ||
| 1932 | dev_info(wm831x->dev, "Initiating shutdown...\n"); | ||
| 1933 | wm831x_set_bits(wm831x, WM831X_POWER_STATE, WM831X_CHIP_ON, 0); | ||
| 1934 | } | ||
| 1935 | } | ||
| 1936 | EXPORT_SYMBOL_GPL(wm831x_device_shutdown); | ||
| 1937 | |||
| 1607 | MODULE_DESCRIPTION("Core support for the WM831X AudioPlus PMIC"); | 1938 | MODULE_DESCRIPTION("Core support for the WM831X AudioPlus PMIC"); |
| 1608 | MODULE_LICENSE("GPL"); | 1939 | MODULE_LICENSE("GPL"); |
| 1609 | MODULE_AUTHOR("Mark Brown"); | 1940 | MODULE_AUTHOR("Mark Brown"); |
diff --git a/drivers/mfd/wm831x-i2c.c b/drivers/mfd/wm831x-i2c.c index a06cbc739716..ac8da1d439da 100644 --- a/drivers/mfd/wm831x-i2c.c +++ b/drivers/mfd/wm831x-i2c.c | |||
| @@ -18,67 +18,17 @@ | |||
| 18 | #include <linux/delay.h> | 18 | #include <linux/delay.h> |
| 19 | #include <linux/mfd/core.h> | 19 | #include <linux/mfd/core.h> |
| 20 | #include <linux/slab.h> | 20 | #include <linux/slab.h> |
| 21 | #include <linux/err.h> | ||
| 22 | #include <linux/regmap.h> | ||
| 21 | 23 | ||
| 22 | #include <linux/mfd/wm831x/core.h> | 24 | #include <linux/mfd/wm831x/core.h> |
| 23 | #include <linux/mfd/wm831x/pdata.h> | 25 | #include <linux/mfd/wm831x/pdata.h> |
| 24 | 26 | ||
| 25 | static int wm831x_i2c_read_device(struct wm831x *wm831x, unsigned short reg, | ||
| 26 | int bytes, void *dest) | ||
| 27 | { | ||
| 28 | struct i2c_client *i2c = wm831x->control_data; | ||
| 29 | int ret; | ||
| 30 | u16 r = cpu_to_be16(reg); | ||
| 31 | |||
| 32 | ret = i2c_master_send(i2c, (unsigned char *)&r, 2); | ||
| 33 | if (ret < 0) | ||
| 34 | return ret; | ||
| 35 | if (ret != 2) | ||
| 36 | return -EIO; | ||
| 37 | |||
| 38 | ret = i2c_master_recv(i2c, dest, bytes); | ||
| 39 | if (ret < 0) | ||
| 40 | return ret; | ||
| 41 | if (ret != bytes) | ||
| 42 | return -EIO; | ||
| 43 | return 0; | ||
| 44 | } | ||
| 45 | |||
| 46 | /* Currently we allocate the write buffer on the stack; this is OK for | ||
| 47 | * small writes - if we need to do large writes this will need to be | ||
| 48 | * revised. | ||
| 49 | */ | ||
| 50 | static int wm831x_i2c_write_device(struct wm831x *wm831x, unsigned short reg, | ||
| 51 | int bytes, void *src) | ||
| 52 | { | ||
| 53 | struct i2c_client *i2c = wm831x->control_data; | ||
| 54 | struct i2c_msg xfer[2]; | ||
| 55 | int ret; | ||
| 56 | |||
| 57 | reg = cpu_to_be16(reg); | ||
| 58 | |||
| 59 | xfer[0].addr = i2c->addr; | ||
| 60 | xfer[0].flags = 0; | ||
| 61 | xfer[0].len = 2; | ||
| 62 | xfer[0].buf = (char *)® | ||
| 63 | |||
| 64 | xfer[1].addr = i2c->addr; | ||
| 65 | xfer[1].flags = I2C_M_NOSTART; | ||
| 66 | xfer[1].len = bytes; | ||
| 67 | xfer[1].buf = (char *)src; | ||
| 68 | |||
| 69 | ret = i2c_transfer(i2c->adapter, xfer, 2); | ||
| 70 | if (ret < 0) | ||
| 71 | return ret; | ||
| 72 | if (ret != 2) | ||
| 73 | return -EIO; | ||
| 74 | |||
| 75 | return 0; | ||
| 76 | } | ||
| 77 | |||
| 78 | static int wm831x_i2c_probe(struct i2c_client *i2c, | 27 | static int wm831x_i2c_probe(struct i2c_client *i2c, |
| 79 | const struct i2c_device_id *id) | 28 | const struct i2c_device_id *id) |
| 80 | { | 29 | { |
| 81 | struct wm831x *wm831x; | 30 | struct wm831x *wm831x; |
| 31 | int ret; | ||
| 82 | 32 | ||
| 83 | wm831x = kzalloc(sizeof(struct wm831x), GFP_KERNEL); | 33 | wm831x = kzalloc(sizeof(struct wm831x), GFP_KERNEL); |
| 84 | if (wm831x == NULL) | 34 | if (wm831x == NULL) |
| @@ -86,9 +36,15 @@ static int wm831x_i2c_probe(struct i2c_client *i2c, | |||
| 86 | 36 | ||
| 87 | i2c_set_clientdata(i2c, wm831x); | 37 | i2c_set_clientdata(i2c, wm831x); |
| 88 | wm831x->dev = &i2c->dev; | 38 | wm831x->dev = &i2c->dev; |
| 89 | wm831x->control_data = i2c; | 39 | |
| 90 | wm831x->read_dev = wm831x_i2c_read_device; | 40 | wm831x->regmap = regmap_init_i2c(i2c, &wm831x_regmap_config); |
| 91 | wm831x->write_dev = wm831x_i2c_write_device; | 41 | if (IS_ERR(wm831x->regmap)) { |
| 42 | ret = PTR_ERR(wm831x->regmap); | ||
| 43 | dev_err(wm831x->dev, "Failed to allocate register map: %d\n", | ||
| 44 | ret); | ||
| 45 | kfree(wm831x); | ||
| 46 | return ret; | ||
| 47 | } | ||
| 92 | 48 | ||
| 93 | return wm831x_device_init(wm831x, id->driver_data, i2c->irq); | 49 | return wm831x_device_init(wm831x, id->driver_data, i2c->irq); |
| 94 | } | 50 | } |
| @@ -109,6 +65,13 @@ static int wm831x_i2c_suspend(struct device *dev) | |||
| 109 | return wm831x_device_suspend(wm831x); | 65 | return wm831x_device_suspend(wm831x); |
| 110 | } | 66 | } |
| 111 | 67 | ||
| 68 | static void wm831x_i2c_shutdown(struct i2c_client *i2c) | ||
| 69 | { | ||
| 70 | struct wm831x *wm831x = i2c_get_clientdata(i2c); | ||
| 71 | |||
| 72 | wm831x_device_shutdown(wm831x); | ||
| 73 | } | ||
| 74 | |||
| 112 | static const struct i2c_device_id wm831x_i2c_id[] = { | 75 | static const struct i2c_device_id wm831x_i2c_id[] = { |
| 113 | { "wm8310", WM8310 }, | 76 | { "wm8310", WM8310 }, |
| 114 | { "wm8311", WM8311 }, | 77 | { "wm8311", WM8311 }, |
| @@ -133,6 +96,7 @@ static struct i2c_driver wm831x_i2c_driver = { | |||
| 133 | }, | 96 | }, |
| 134 | .probe = wm831x_i2c_probe, | 97 | .probe = wm831x_i2c_probe, |
| 135 | .remove = wm831x_i2c_remove, | 98 | .remove = wm831x_i2c_remove, |
| 99 | .shutdown = wm831x_i2c_shutdown, | ||
| 136 | .id_table = wm831x_i2c_id, | 100 | .id_table = wm831x_i2c_id, |
| 137 | }; | 101 | }; |
| 138 | 102 | ||
diff --git a/drivers/mfd/wm831x-spi.c b/drivers/mfd/wm831x-spi.c index eed8e4f7a5a1..8d6a9a969dbc 100644 --- a/drivers/mfd/wm831x-spi.c +++ b/drivers/mfd/wm831x-spi.c | |||
| @@ -16,78 +16,19 @@ | |||
| 16 | #include <linux/module.h> | 16 | #include <linux/module.h> |
| 17 | #include <linux/pm.h> | 17 | #include <linux/pm.h> |
| 18 | #include <linux/spi/spi.h> | 18 | #include <linux/spi/spi.h> |
| 19 | #include <linux/regmap.h> | ||
| 20 | #include <linux/err.h> | ||
| 19 | 21 | ||
| 20 | #include <linux/mfd/wm831x/core.h> | 22 | #include <linux/mfd/wm831x/core.h> |
| 21 | 23 | ||
| 22 | static int wm831x_spi_read_device(struct wm831x *wm831x, unsigned short reg, | ||
| 23 | int bytes, void *dest) | ||
| 24 | { | ||
| 25 | u16 tx_val; | ||
| 26 | u16 *d = dest; | ||
| 27 | int r, ret; | ||
| 28 | |||
| 29 | /* Go register at a time */ | ||
| 30 | for (r = reg; r < reg + (bytes / 2); r++) { | ||
| 31 | tx_val = r | 0x8000; | ||
| 32 | |||
| 33 | ret = spi_write_then_read(wm831x->control_data, | ||
| 34 | (u8 *)&tx_val, 2, (u8 *)d, 2); | ||
| 35 | if (ret != 0) | ||
| 36 | return ret; | ||
| 37 | |||
| 38 | *d = be16_to_cpu(*d); | ||
| 39 | |||
| 40 | d++; | ||
| 41 | } | ||
| 42 | |||
| 43 | return 0; | ||
| 44 | } | ||
| 45 | |||
| 46 | static int wm831x_spi_write_device(struct wm831x *wm831x, unsigned short reg, | ||
| 47 | int bytes, void *src) | ||
| 48 | { | ||
| 49 | struct spi_device *spi = wm831x->control_data; | ||
| 50 | u16 *s = src; | ||
| 51 | u16 data[2]; | ||
| 52 | int ret, r; | ||
| 53 | |||
| 54 | /* Go register at a time */ | ||
| 55 | for (r = reg; r < reg + (bytes / 2); r++) { | ||
| 56 | data[0] = r; | ||
| 57 | data[1] = *s++; | ||
| 58 | |||
| 59 | ret = spi_write(spi, (char *)&data, sizeof(data)); | ||
| 60 | if (ret != 0) | ||
| 61 | return ret; | ||
| 62 | } | ||
| 63 | |||
| 64 | return 0; | ||
| 65 | } | ||
| 66 | |||
| 67 | static int __devinit wm831x_spi_probe(struct spi_device *spi) | 24 | static int __devinit wm831x_spi_probe(struct spi_device *spi) |
| 68 | { | 25 | { |
| 26 | const struct spi_device_id *id = spi_get_device_id(spi); | ||
| 69 | struct wm831x *wm831x; | 27 | struct wm831x *wm831x; |
| 70 | enum wm831x_parent type; | 28 | enum wm831x_parent type; |
| 29 | int ret; | ||
| 71 | 30 | ||
| 72 | /* Currently SPI support for ID tables is unmerged, we're faking it */ | 31 | type = (enum wm831x_parent)id->driver_data; |
| 73 | if (strcmp(spi->modalias, "wm8310") == 0) | ||
| 74 | type = WM8310; | ||
| 75 | else if (strcmp(spi->modalias, "wm8311") == 0) | ||
| 76 | type = WM8311; | ||
| 77 | else if (strcmp(spi->modalias, "wm8312") == 0) | ||
| 78 | type = WM8312; | ||
| 79 | else if (strcmp(spi->modalias, "wm8320") == 0) | ||
| 80 | type = WM8320; | ||
| 81 | else if (strcmp(spi->modalias, "wm8321") == 0) | ||
| 82 | type = WM8321; | ||
| 83 | else if (strcmp(spi->modalias, "wm8325") == 0) | ||
| 84 | type = WM8325; | ||
| 85 | else if (strcmp(spi->modalias, "wm8326") == 0) | ||
| 86 | type = WM8326; | ||
| 87 | else { | ||
| 88 | dev_err(&spi->dev, "Unknown device type\n"); | ||
| 89 | return -EINVAL; | ||
| 90 | } | ||
| 91 | 32 | ||
| 92 | wm831x = kzalloc(sizeof(struct wm831x), GFP_KERNEL); | 33 | wm831x = kzalloc(sizeof(struct wm831x), GFP_KERNEL); |
| 93 | if (wm831x == NULL) | 34 | if (wm831x == NULL) |
| @@ -98,9 +39,15 @@ static int __devinit wm831x_spi_probe(struct spi_device *spi) | |||
| 98 | 39 | ||
| 99 | dev_set_drvdata(&spi->dev, wm831x); | 40 | dev_set_drvdata(&spi->dev, wm831x); |
| 100 | wm831x->dev = &spi->dev; | 41 | wm831x->dev = &spi->dev; |
| 101 | wm831x->control_data = spi; | 42 | |
| 102 | wm831x->read_dev = wm831x_spi_read_device; | 43 | wm831x->regmap = regmap_init_spi(spi, &wm831x_regmap_config); |
| 103 | wm831x->write_dev = wm831x_spi_write_device; | 44 | if (IS_ERR(wm831x->regmap)) { |
| 45 | ret = PTR_ERR(wm831x->regmap); | ||
| 46 | dev_err(wm831x->dev, "Failed to allocate register map: %d\n", | ||
| 47 | ret); | ||
| 48 | kfree(wm831x); | ||
| 49 | return ret; | ||
| 50 | } | ||
| 104 | 51 | ||
| 105 | return wm831x_device_init(wm831x, type, spi->irq); | 52 | return wm831x_device_init(wm831x, type, spi->irq); |
| 106 | } | 53 | } |
| @@ -121,119 +68,50 @@ static int wm831x_spi_suspend(struct device *dev) | |||
| 121 | return wm831x_device_suspend(wm831x); | 68 | return wm831x_device_suspend(wm831x); |
| 122 | } | 69 | } |
| 123 | 70 | ||
| 71 | static void wm831x_spi_shutdown(struct spi_device *spi) | ||
| 72 | { | ||
| 73 | struct wm831x *wm831x = dev_get_drvdata(&spi->dev); | ||
| 74 | |||
| 75 | wm831x_device_shutdown(wm831x); | ||
| 76 | } | ||
| 77 | |||
| 124 | static const struct dev_pm_ops wm831x_spi_pm = { | 78 | static const struct dev_pm_ops wm831x_spi_pm = { |
| 125 | .freeze = wm831x_spi_suspend, | 79 | .freeze = wm831x_spi_suspend, |
| 126 | .suspend = wm831x_spi_suspend, | 80 | .suspend = wm831x_spi_suspend, |
| 127 | }; | 81 | }; |
| 128 | 82 | ||
| 129 | static struct spi_driver wm8310_spi_driver = { | 83 | static const struct spi_device_id wm831x_spi_ids[] = { |
| 130 | .driver = { | 84 | { "wm8310", WM8310 }, |
| 131 | .name = "wm8310", | 85 | { "wm8311", WM8311 }, |
| 132 | .bus = &spi_bus_type, | 86 | { "wm8312", WM8312 }, |
| 133 | .owner = THIS_MODULE, | 87 | { "wm8320", WM8320 }, |
| 134 | .pm = &wm831x_spi_pm, | 88 | { "wm8321", WM8321 }, |
| 135 | }, | 89 | { "wm8325", WM8325 }, |
| 136 | .probe = wm831x_spi_probe, | 90 | { "wm8326", WM8326 }, |
| 137 | .remove = __devexit_p(wm831x_spi_remove), | 91 | { }, |
| 138 | }; | 92 | }; |
| 93 | MODULE_DEVICE_TABLE(spi, wm831x_spi_id); | ||
| 139 | 94 | ||
| 140 | static struct spi_driver wm8311_spi_driver = { | 95 | static struct spi_driver wm831x_spi_driver = { |
| 141 | .driver = { | 96 | .driver = { |
| 142 | .name = "wm8311", | 97 | .name = "wm831x", |
| 143 | .bus = &spi_bus_type, | ||
| 144 | .owner = THIS_MODULE, | ||
| 145 | .pm = &wm831x_spi_pm, | ||
| 146 | }, | ||
| 147 | .probe = wm831x_spi_probe, | ||
| 148 | .remove = __devexit_p(wm831x_spi_remove), | ||
| 149 | }; | ||
| 150 | |||
| 151 | static struct spi_driver wm8312_spi_driver = { | ||
| 152 | .driver = { | ||
| 153 | .name = "wm8312", | ||
| 154 | .bus = &spi_bus_type, | ||
| 155 | .owner = THIS_MODULE, | ||
| 156 | .pm = &wm831x_spi_pm, | ||
| 157 | }, | ||
| 158 | .probe = wm831x_spi_probe, | ||
| 159 | .remove = __devexit_p(wm831x_spi_remove), | ||
| 160 | }; | ||
| 161 | |||
| 162 | static struct spi_driver wm8320_spi_driver = { | ||
| 163 | .driver = { | ||
| 164 | .name = "wm8320", | ||
| 165 | .bus = &spi_bus_type, | ||
| 166 | .owner = THIS_MODULE, | ||
| 167 | .pm = &wm831x_spi_pm, | ||
| 168 | }, | ||
| 169 | .probe = wm831x_spi_probe, | ||
| 170 | .remove = __devexit_p(wm831x_spi_remove), | ||
| 171 | }; | ||
| 172 | |||
| 173 | static struct spi_driver wm8321_spi_driver = { | ||
| 174 | .driver = { | ||
| 175 | .name = "wm8321", | ||
| 176 | .bus = &spi_bus_type, | ||
| 177 | .owner = THIS_MODULE, | ||
| 178 | .pm = &wm831x_spi_pm, | ||
| 179 | }, | ||
| 180 | .probe = wm831x_spi_probe, | ||
| 181 | .remove = __devexit_p(wm831x_spi_remove), | ||
| 182 | }; | ||
| 183 | |||
| 184 | static struct spi_driver wm8325_spi_driver = { | ||
| 185 | .driver = { | ||
| 186 | .name = "wm8325", | ||
| 187 | .bus = &spi_bus_type, | ||
| 188 | .owner = THIS_MODULE, | ||
| 189 | .pm = &wm831x_spi_pm, | ||
| 190 | }, | ||
| 191 | .probe = wm831x_spi_probe, | ||
| 192 | .remove = __devexit_p(wm831x_spi_remove), | ||
| 193 | }; | ||
| 194 | |||
| 195 | static struct spi_driver wm8326_spi_driver = { | ||
| 196 | .driver = { | ||
| 197 | .name = "wm8326", | ||
| 198 | .bus = &spi_bus_type, | 98 | .bus = &spi_bus_type, |
| 199 | .owner = THIS_MODULE, | 99 | .owner = THIS_MODULE, |
| 200 | .pm = &wm831x_spi_pm, | 100 | .pm = &wm831x_spi_pm, |
| 201 | }, | 101 | }, |
| 102 | .id_table = wm831x_spi_ids, | ||
| 202 | .probe = wm831x_spi_probe, | 103 | .probe = wm831x_spi_probe, |
| 203 | .remove = __devexit_p(wm831x_spi_remove), | 104 | .remove = __devexit_p(wm831x_spi_remove), |
| 105 | .shutdown = wm831x_spi_shutdown, | ||
| 204 | }; | 106 | }; |
| 205 | 107 | ||
| 206 | static int __init wm831x_spi_init(void) | 108 | static int __init wm831x_spi_init(void) |
| 207 | { | 109 | { |
| 208 | int ret; | 110 | int ret; |
| 209 | 111 | ||
| 210 | ret = spi_register_driver(&wm8310_spi_driver); | 112 | ret = spi_register_driver(&wm831x_spi_driver); |
| 211 | if (ret != 0) | ||
| 212 | pr_err("Failed to register WM8310 SPI driver: %d\n", ret); | ||
| 213 | |||
| 214 | ret = spi_register_driver(&wm8311_spi_driver); | ||
| 215 | if (ret != 0) | ||
| 216 | pr_err("Failed to register WM8311 SPI driver: %d\n", ret); | ||
| 217 | |||
| 218 | ret = spi_register_driver(&wm8312_spi_driver); | ||
| 219 | if (ret != 0) | ||
| 220 | pr_err("Failed to register WM8312 SPI driver: %d\n", ret); | ||
| 221 | |||
| 222 | ret = spi_register_driver(&wm8320_spi_driver); | ||
| 223 | if (ret != 0) | ||
| 224 | pr_err("Failed to register WM8320 SPI driver: %d\n", ret); | ||
| 225 | |||
| 226 | ret = spi_register_driver(&wm8321_spi_driver); | ||
| 227 | if (ret != 0) | ||
| 228 | pr_err("Failed to register WM8321 SPI driver: %d\n", ret); | ||
| 229 | |||
| 230 | ret = spi_register_driver(&wm8325_spi_driver); | ||
| 231 | if (ret != 0) | ||
| 232 | pr_err("Failed to register WM8325 SPI driver: %d\n", ret); | ||
| 233 | |||
| 234 | ret = spi_register_driver(&wm8326_spi_driver); | ||
| 235 | if (ret != 0) | 113 | if (ret != 0) |
| 236 | pr_err("Failed to register WM8326 SPI driver: %d\n", ret); | 114 | pr_err("Failed to register WM831x SPI driver: %d\n", ret); |
| 237 | 115 | ||
| 238 | return 0; | 116 | return 0; |
| 239 | } | 117 | } |
| @@ -241,13 +119,7 @@ subsys_initcall(wm831x_spi_init); | |||
| 241 | 119 | ||
| 242 | static void __exit wm831x_spi_exit(void) | 120 | static void __exit wm831x_spi_exit(void) |
| 243 | { | 121 | { |
| 244 | spi_unregister_driver(&wm8326_spi_driver); | 122 | spi_unregister_driver(&wm831x_spi_driver); |
| 245 | spi_unregister_driver(&wm8325_spi_driver); | ||
| 246 | spi_unregister_driver(&wm8321_spi_driver); | ||
| 247 | spi_unregister_driver(&wm8320_spi_driver); | ||
| 248 | spi_unregister_driver(&wm8312_spi_driver); | ||
| 249 | spi_unregister_driver(&wm8311_spi_driver); | ||
| 250 | spi_unregister_driver(&wm8310_spi_driver); | ||
| 251 | } | 123 | } |
| 252 | module_exit(wm831x_spi_exit); | 124 | module_exit(wm831x_spi_exit); |
| 253 | 125 | ||
diff --git a/drivers/mfd/wm8400-core.c b/drivers/mfd/wm8400-core.c index 597f82edacaa..e06ba9440cdb 100644 --- a/drivers/mfd/wm8400-core.c +++ b/drivers/mfd/wm8400-core.c | |||
| @@ -13,11 +13,13 @@ | |||
| 13 | */ | 13 | */ |
| 14 | 14 | ||
| 15 | #include <linux/bug.h> | 15 | #include <linux/bug.h> |
| 16 | #include <linux/err.h> | ||
| 16 | #include <linux/i2c.h> | 17 | #include <linux/i2c.h> |
| 17 | #include <linux/kernel.h> | 18 | #include <linux/kernel.h> |
| 18 | #include <linux/mfd/core.h> | 19 | #include <linux/mfd/core.h> |
| 19 | #include <linux/mfd/wm8400-private.h> | 20 | #include <linux/mfd/wm8400-private.h> |
| 20 | #include <linux/mfd/wm8400-audio.h> | 21 | #include <linux/mfd/wm8400-audio.h> |
| 22 | #include <linux/regmap.h> | ||
| 21 | #include <linux/slab.h> | 23 | #include <linux/slab.h> |
| 22 | 24 | ||
| 23 | static struct { | 25 | static struct { |
| @@ -123,14 +125,9 @@ static int wm8400_read(struct wm8400 *wm8400, u8 reg, int num_regs, u16 *dest) | |||
| 123 | /* If there are any volatile reads then read back the entire block */ | 125 | /* If there are any volatile reads then read back the entire block */ |
| 124 | for (i = reg; i < reg + num_regs; i++) | 126 | for (i = reg; i < reg + num_regs; i++) |
| 125 | if (reg_data[i].vol) { | 127 | if (reg_data[i].vol) { |
| 126 | ret = wm8400->read_dev(wm8400->io_data, reg, | 128 | ret = regmap_bulk_read(wm8400->regmap, reg, dest, |
| 127 | num_regs, dest); | 129 | num_regs); |
| 128 | if (ret != 0) | 130 | return ret; |
| 129 | return ret; | ||
| 130 | for (i = 0; i < num_regs; i++) | ||
| 131 | dest[i] = be16_to_cpu(dest[i]); | ||
| 132 | |||
| 133 | return 0; | ||
| 134 | } | 131 | } |
| 135 | 132 | ||
| 136 | /* Otherwise use the cache */ | 133 | /* Otherwise use the cache */ |
| @@ -149,14 +146,11 @@ static int wm8400_write(struct wm8400 *wm8400, u8 reg, int num_regs, | |||
| 149 | for (i = 0; i < num_regs; i++) { | 146 | for (i = 0; i < num_regs; i++) { |
| 150 | BUG_ON(!reg_data[reg + i].writable); | 147 | BUG_ON(!reg_data[reg + i].writable); |
| 151 | wm8400->reg_cache[reg + i] = src[i]; | 148 | wm8400->reg_cache[reg + i] = src[i]; |
| 152 | src[i] = cpu_to_be16(src[i]); | 149 | ret = regmap_write(wm8400->regmap, reg, src[i]); |
| 150 | if (ret != 0) | ||
| 151 | return ret; | ||
| 153 | } | 152 | } |
| 154 | 153 | ||
| 155 | /* Do the actual I/O */ | ||
| 156 | ret = wm8400->write_dev(wm8400->io_data, reg, num_regs, src); | ||
| 157 | if (ret != 0) | ||
| 158 | return -EIO; | ||
| 159 | |||
| 160 | return 0; | 154 | return 0; |
| 161 | } | 155 | } |
| 162 | 156 | ||
| @@ -270,14 +264,14 @@ static int wm8400_init(struct wm8400 *wm8400, | |||
| 270 | dev_set_drvdata(wm8400->dev, wm8400); | 264 | dev_set_drvdata(wm8400->dev, wm8400); |
| 271 | 265 | ||
| 272 | /* Check that this is actually a WM8400 */ | 266 | /* Check that this is actually a WM8400 */ |
| 273 | ret = wm8400->read_dev(wm8400->io_data, WM8400_RESET_ID, 1, ®); | 267 | ret = regmap_read(wm8400->regmap, WM8400_RESET_ID, &i); |
| 274 | if (ret != 0) { | 268 | if (ret != 0) { |
| 275 | dev_err(wm8400->dev, "Chip ID register read failed\n"); | 269 | dev_err(wm8400->dev, "Chip ID register read failed\n"); |
| 276 | return -EIO; | 270 | return -EIO; |
| 277 | } | 271 | } |
| 278 | if (be16_to_cpu(reg) != reg_data[WM8400_RESET_ID].default_val) { | 272 | if (i != reg_data[WM8400_RESET_ID].default_val) { |
| 279 | dev_err(wm8400->dev, "Device is not a WM8400, ID is %x\n", | 273 | dev_err(wm8400->dev, "Device is not a WM8400, ID is %x\n", |
| 280 | be16_to_cpu(reg)); | 274 | reg); |
| 281 | return -ENODEV; | 275 | return -ENODEV; |
| 282 | } | 276 | } |
| 283 | 277 | ||
| @@ -285,9 +279,8 @@ static int wm8400_init(struct wm8400 *wm8400, | |||
| 285 | * is a PMIC we can't reset it safely so initialise the register | 279 | * is a PMIC we can't reset it safely so initialise the register |
| 286 | * cache from the hardware. | 280 | * cache from the hardware. |
| 287 | */ | 281 | */ |
| 288 | ret = wm8400->read_dev(wm8400->io_data, 0, | 282 | ret = regmap_raw_read(wm8400->regmap, 0, wm8400->reg_cache, |
| 289 | ARRAY_SIZE(wm8400->reg_cache), | 283 | ARRAY_SIZE(wm8400->reg_cache)); |
| 290 | wm8400->reg_cache); | ||
| 291 | if (ret != 0) { | 284 | if (ret != 0) { |
| 292 | dev_err(wm8400->dev, "Register cache read failed\n"); | 285 | dev_err(wm8400->dev, "Register cache read failed\n"); |
| 293 | return -EIO; | 286 | return -EIO; |
| @@ -337,60 +330,13 @@ static void wm8400_release(struct wm8400 *wm8400) | |||
| 337 | mfd_remove_devices(wm8400->dev); | 330 | mfd_remove_devices(wm8400->dev); |
| 338 | } | 331 | } |
| 339 | 332 | ||
| 340 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | 333 | static const struct regmap_config wm8400_regmap_config = { |
| 341 | static int wm8400_i2c_read(void *io_data, char reg, int count, u16 *dest) | 334 | .reg_bits = 8, |
| 342 | { | 335 | .val_bits = 16, |
| 343 | struct i2c_client *i2c = io_data; | 336 | .max_register = WM8400_REGISTER_COUNT - 1, |
| 344 | struct i2c_msg xfer[2]; | 337 | }; |
| 345 | int ret; | ||
| 346 | |||
| 347 | /* Write register */ | ||
| 348 | xfer[0].addr = i2c->addr; | ||
| 349 | xfer[0].flags = 0; | ||
| 350 | xfer[0].len = 1; | ||
| 351 | xfer[0].buf = ® | ||
| 352 | |||
| 353 | /* Read data */ | ||
| 354 | xfer[1].addr = i2c->addr; | ||
| 355 | xfer[1].flags = I2C_M_RD; | ||
| 356 | xfer[1].len = count * sizeof(u16); | ||
| 357 | xfer[1].buf = (u8 *)dest; | ||
| 358 | |||
| 359 | ret = i2c_transfer(i2c->adapter, xfer, 2); | ||
| 360 | if (ret == 2) | ||
| 361 | ret = 0; | ||
| 362 | else if (ret >= 0) | ||
| 363 | ret = -EIO; | ||
| 364 | |||
| 365 | return ret; | ||
| 366 | } | ||
| 367 | |||
| 368 | static int wm8400_i2c_write(void *io_data, char reg, int count, const u16 *src) | ||
| 369 | { | ||
| 370 | struct i2c_client *i2c = io_data; | ||
| 371 | u8 *msg; | ||
| 372 | int ret; | ||
| 373 | |||
| 374 | /* We add 1 byte for device register - ideally I2C would gather. */ | ||
| 375 | msg = kmalloc((count * sizeof(u16)) + 1, GFP_KERNEL); | ||
| 376 | if (msg == NULL) | ||
| 377 | return -ENOMEM; | ||
| 378 | |||
| 379 | msg[0] = reg; | ||
| 380 | memcpy(&msg[1], src, count * sizeof(u16)); | ||
| 381 | |||
| 382 | ret = i2c_master_send(i2c, msg, (count * sizeof(u16)) + 1); | ||
| 383 | |||
| 384 | if (ret == (count * 2) + 1) | ||
| 385 | ret = 0; | ||
| 386 | else if (ret >= 0) | ||
| 387 | ret = -EIO; | ||
| 388 | |||
| 389 | kfree(msg); | ||
| 390 | |||
| 391 | return ret; | ||
| 392 | } | ||
| 393 | 338 | ||
| 339 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | ||
| 394 | static int wm8400_i2c_probe(struct i2c_client *i2c, | 340 | static int wm8400_i2c_probe(struct i2c_client *i2c, |
| 395 | const struct i2c_device_id *id) | 341 | const struct i2c_device_id *id) |
| 396 | { | 342 | { |
| @@ -403,18 +349,23 @@ static int wm8400_i2c_probe(struct i2c_client *i2c, | |||
| 403 | goto err; | 349 | goto err; |
| 404 | } | 350 | } |
| 405 | 351 | ||
| 406 | wm8400->io_data = i2c; | 352 | wm8400->regmap = regmap_init_i2c(i2c, &wm8400_regmap_config); |
| 407 | wm8400->read_dev = wm8400_i2c_read; | 353 | if (IS_ERR(wm8400->regmap)) { |
| 408 | wm8400->write_dev = wm8400_i2c_write; | 354 | ret = PTR_ERR(wm8400->regmap); |
| 355 | goto struct_err; | ||
| 356 | } | ||
| 357 | |||
| 409 | wm8400->dev = &i2c->dev; | 358 | wm8400->dev = &i2c->dev; |
| 410 | i2c_set_clientdata(i2c, wm8400); | 359 | i2c_set_clientdata(i2c, wm8400); |
| 411 | 360 | ||
| 412 | ret = wm8400_init(wm8400, i2c->dev.platform_data); | 361 | ret = wm8400_init(wm8400, i2c->dev.platform_data); |
| 413 | if (ret != 0) | 362 | if (ret != 0) |
| 414 | goto struct_err; | 363 | goto map_err; |
| 415 | 364 | ||
| 416 | return 0; | 365 | return 0; |
| 417 | 366 | ||
| 367 | map_err: | ||
| 368 | regmap_exit(wm8400->regmap); | ||
| 418 | struct_err: | 369 | struct_err: |
| 419 | kfree(wm8400); | 370 | kfree(wm8400); |
| 420 | err: | 371 | err: |
| @@ -426,6 +377,7 @@ static int wm8400_i2c_remove(struct i2c_client *i2c) | |||
| 426 | struct wm8400 *wm8400 = i2c_get_clientdata(i2c); | 377 | struct wm8400 *wm8400 = i2c_get_clientdata(i2c); |
| 427 | 378 | ||
| 428 | wm8400_release(wm8400); | 379 | wm8400_release(wm8400); |
| 380 | regmap_exit(wm8400->regmap); | ||
| 429 | kfree(wm8400); | 381 | kfree(wm8400); |
| 430 | 382 | ||
| 431 | return 0; | 383 | return 0; |
diff --git a/drivers/mfd/wm8994-core.c b/drivers/mfd/wm8994-core.c index 96479c9b1728..bfde4e8ec638 100644 --- a/drivers/mfd/wm8994-core.c +++ b/drivers/mfd/wm8994-core.c | |||
| @@ -16,9 +16,11 @@ | |||
| 16 | #include <linux/module.h> | 16 | #include <linux/module.h> |
| 17 | #include <linux/slab.h> | 17 | #include <linux/slab.h> |
| 18 | #include <linux/i2c.h> | 18 | #include <linux/i2c.h> |
| 19 | #include <linux/err.h> | ||
| 19 | #include <linux/delay.h> | 20 | #include <linux/delay.h> |
| 20 | #include <linux/mfd/core.h> | 21 | #include <linux/mfd/core.h> |
| 21 | #include <linux/pm_runtime.h> | 22 | #include <linux/pm_runtime.h> |
| 23 | #include <linux/regmap.h> | ||
| 22 | #include <linux/regulator/consumer.h> | 24 | #include <linux/regulator/consumer.h> |
| 23 | #include <linux/regulator/machine.h> | 25 | #include <linux/regulator/machine.h> |
| 24 | 26 | ||
| @@ -29,22 +31,7 @@ | |||
| 29 | static int wm8994_read(struct wm8994 *wm8994, unsigned short reg, | 31 | static int wm8994_read(struct wm8994 *wm8994, unsigned short reg, |
| 30 | int bytes, void *dest) | 32 | int bytes, void *dest) |
| 31 | { | 33 | { |
| 32 | int ret, i; | 34 | return regmap_raw_read(wm8994->regmap, reg, dest, bytes); |
| 33 | u16 *buf = dest; | ||
| 34 | |||
| 35 | BUG_ON(bytes % 2); | ||
| 36 | BUG_ON(bytes <= 0); | ||
| 37 | |||
| 38 | ret = wm8994->read_dev(wm8994, reg, bytes, dest); | ||
| 39 | if (ret < 0) | ||
| 40 | return ret; | ||
| 41 | |||
| 42 | for (i = 0; i < bytes / 2; i++) { | ||
| 43 | dev_vdbg(wm8994->dev, "Read %04x from R%d(0x%x)\n", | ||
| 44 | be16_to_cpu(buf[i]), reg + i, reg + i); | ||
| 45 | } | ||
| 46 | |||
| 47 | return 0; | ||
| 48 | } | 35 | } |
| 49 | 36 | ||
| 50 | /** | 37 | /** |
| @@ -55,19 +42,15 @@ static int wm8994_read(struct wm8994 *wm8994, unsigned short reg, | |||
| 55 | */ | 42 | */ |
| 56 | int wm8994_reg_read(struct wm8994 *wm8994, unsigned short reg) | 43 | int wm8994_reg_read(struct wm8994 *wm8994, unsigned short reg) |
| 57 | { | 44 | { |
| 58 | unsigned short val; | 45 | unsigned int val; |
| 59 | int ret; | 46 | int ret; |
| 60 | 47 | ||
| 61 | mutex_lock(&wm8994->io_lock); | 48 | ret = regmap_read(wm8994->regmap, reg, &val); |
| 62 | |||
| 63 | ret = wm8994_read(wm8994, reg, 2, &val); | ||
| 64 | |||
| 65 | mutex_unlock(&wm8994->io_lock); | ||
| 66 | 49 | ||
| 67 | if (ret < 0) | 50 | if (ret < 0) |
| 68 | return ret; | 51 | return ret; |
| 69 | else | 52 | else |
| 70 | return be16_to_cpu(val); | 53 | return val; |
| 71 | } | 54 | } |
| 72 | EXPORT_SYMBOL_GPL(wm8994_reg_read); | 55 | EXPORT_SYMBOL_GPL(wm8994_reg_read); |
| 73 | 56 | ||
| @@ -82,33 +65,13 @@ EXPORT_SYMBOL_GPL(wm8994_reg_read); | |||
| 82 | int wm8994_bulk_read(struct wm8994 *wm8994, unsigned short reg, | 65 | int wm8994_bulk_read(struct wm8994 *wm8994, unsigned short reg, |
| 83 | int count, u16 *buf) | 66 | int count, u16 *buf) |
| 84 | { | 67 | { |
| 85 | int ret; | 68 | return regmap_bulk_read(wm8994->regmap, reg, buf, count); |
| 86 | |||
| 87 | mutex_lock(&wm8994->io_lock); | ||
| 88 | |||
| 89 | ret = wm8994_read(wm8994, reg, count * 2, buf); | ||
| 90 | |||
| 91 | mutex_unlock(&wm8994->io_lock); | ||
| 92 | |||
| 93 | return ret; | ||
| 94 | } | 69 | } |
| 95 | EXPORT_SYMBOL_GPL(wm8994_bulk_read); | ||
| 96 | 70 | ||
| 97 | static int wm8994_write(struct wm8994 *wm8994, unsigned short reg, | 71 | static int wm8994_write(struct wm8994 *wm8994, unsigned short reg, |
| 98 | int bytes, const void *src) | 72 | int bytes, const void *src) |
| 99 | { | 73 | { |
| 100 | const u16 *buf = src; | 74 | return regmap_raw_write(wm8994->regmap, reg, src, bytes); |
| 101 | int i; | ||
| 102 | |||
| 103 | BUG_ON(bytes % 2); | ||
| 104 | BUG_ON(bytes <= 0); | ||
| 105 | |||
| 106 | for (i = 0; i < bytes / 2; i++) { | ||
| 107 | dev_vdbg(wm8994->dev, "Write %04x to R%d(0x%x)\n", | ||
| 108 | be16_to_cpu(buf[i]), reg + i, reg + i); | ||
| 109 | } | ||
| 110 | |||
| 111 | return wm8994->write_dev(wm8994, reg, bytes, src); | ||
| 112 | } | 75 | } |
| 113 | 76 | ||
| 114 | /** | 77 | /** |
| @@ -121,17 +84,7 @@ static int wm8994_write(struct wm8994 *wm8994, unsigned short reg, | |||
| 121 | int wm8994_reg_write(struct wm8994 *wm8994, unsigned short reg, | 84 | int wm8994_reg_write(struct wm8994 *wm8994, unsigned short reg, |
| 122 | unsigned short val) | 85 | unsigned short val) |
| 123 | { | 86 | { |
| 124 | int ret; | 87 | return regmap_write(wm8994->regmap, reg, val); |
| 125 | |||
| 126 | val = cpu_to_be16(val); | ||
| 127 | |||
| 128 | mutex_lock(&wm8994->io_lock); | ||
| 129 | |||
| 130 | ret = wm8994_write(wm8994, reg, 2, &val); | ||
| 131 | |||
| 132 | mutex_unlock(&wm8994->io_lock); | ||
| 133 | |||
| 134 | return ret; | ||
| 135 | } | 88 | } |
| 136 | EXPORT_SYMBOL_GPL(wm8994_reg_write); | 89 | EXPORT_SYMBOL_GPL(wm8994_reg_write); |
| 137 | 90 | ||
| @@ -146,15 +99,7 @@ EXPORT_SYMBOL_GPL(wm8994_reg_write); | |||
| 146 | int wm8994_bulk_write(struct wm8994 *wm8994, unsigned short reg, | 99 | int wm8994_bulk_write(struct wm8994 *wm8994, unsigned short reg, |
| 147 | int count, const u16 *buf) | 100 | int count, const u16 *buf) |
| 148 | { | 101 | { |
| 149 | int ret; | 102 | return regmap_raw_write(wm8994->regmap, reg, buf, count * sizeof(u16)); |
| 150 | |||
| 151 | mutex_lock(&wm8994->io_lock); | ||
| 152 | |||
| 153 | ret = wm8994_write(wm8994, reg, count * 2, buf); | ||
| 154 | |||
| 155 | mutex_unlock(&wm8994->io_lock); | ||
| 156 | |||
| 157 | return ret; | ||
| 158 | } | 103 | } |
| 159 | EXPORT_SYMBOL_GPL(wm8994_bulk_write); | 104 | EXPORT_SYMBOL_GPL(wm8994_bulk_write); |
| 160 | 105 | ||
| @@ -169,28 +114,7 @@ EXPORT_SYMBOL_GPL(wm8994_bulk_write); | |||
| 169 | int wm8994_set_bits(struct wm8994 *wm8994, unsigned short reg, | 114 | int wm8994_set_bits(struct wm8994 *wm8994, unsigned short reg, |
| 170 | unsigned short mask, unsigned short val) | 115 | unsigned short mask, unsigned short val) |
| 171 | { | 116 | { |
| 172 | int ret; | 117 | return regmap_update_bits(wm8994->regmap, reg, mask, val); |
| 173 | u16 r; | ||
| 174 | |||
| 175 | mutex_lock(&wm8994->io_lock); | ||
| 176 | |||
| 177 | ret = wm8994_read(wm8994, reg, 2, &r); | ||
| 178 | if (ret < 0) | ||
| 179 | goto out; | ||
| 180 | |||
| 181 | r = be16_to_cpu(r); | ||
| 182 | |||
| 183 | r &= ~mask; | ||
| 184 | r |= val; | ||
| 185 | |||
| 186 | r = cpu_to_be16(r); | ||
| 187 | |||
| 188 | ret = wm8994_write(wm8994, reg, 2, &r); | ||
| 189 | |||
| 190 | out: | ||
| 191 | mutex_unlock(&wm8994->io_lock); | ||
| 192 | |||
| 193 | return ret; | ||
| 194 | } | 118 | } |
| 195 | EXPORT_SYMBOL_GPL(wm8994_set_bits); | 119 | EXPORT_SYMBOL_GPL(wm8994_set_bits); |
| 196 | 120 | ||
| @@ -378,6 +302,11 @@ static int wm8994_ldo_in_use(struct wm8994_pdata *pdata, int ldo) | |||
| 378 | } | 302 | } |
| 379 | #endif | 303 | #endif |
| 380 | 304 | ||
| 305 | static struct regmap_config wm8994_regmap_config = { | ||
| 306 | .reg_bits = 16, | ||
| 307 | .val_bits = 16, | ||
| 308 | }; | ||
| 309 | |||
| 381 | /* | 310 | /* |
| 382 | * Instantiate the generic non-control parts of the device. | 311 | * Instantiate the generic non-control parts of the device. |
| 383 | */ | 312 | */ |
| @@ -387,7 +316,6 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq) | |||
| 387 | const char *devname; | 316 | const char *devname; |
| 388 | int ret, i; | 317 | int ret, i; |
| 389 | 318 | ||
| 390 | mutex_init(&wm8994->io_lock); | ||
| 391 | dev_set_drvdata(wm8994->dev, wm8994); | 319 | dev_set_drvdata(wm8994->dev, wm8994); |
| 392 | 320 | ||
| 393 | /* Add the on-chip regulators first for bootstrapping */ | 321 | /* Add the on-chip regulators first for bootstrapping */ |
| @@ -397,7 +325,7 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq) | |||
| 397 | NULL, 0); | 325 | NULL, 0); |
| 398 | if (ret != 0) { | 326 | if (ret != 0) { |
| 399 | dev_err(wm8994->dev, "Failed to add children: %d\n", ret); | 327 | dev_err(wm8994->dev, "Failed to add children: %d\n", ret); |
| 400 | goto err; | 328 | goto err_regmap; |
| 401 | } | 329 | } |
| 402 | 330 | ||
| 403 | switch (wm8994->type) { | 331 | switch (wm8994->type) { |
| @@ -409,7 +337,7 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq) | |||
| 409 | break; | 337 | break; |
| 410 | default: | 338 | default: |
| 411 | BUG(); | 339 | BUG(); |
| 412 | goto err; | 340 | goto err_regmap; |
| 413 | } | 341 | } |
| 414 | 342 | ||
| 415 | wm8994->supplies = kzalloc(sizeof(struct regulator_bulk_data) * | 343 | wm8994->supplies = kzalloc(sizeof(struct regulator_bulk_data) * |
| @@ -417,7 +345,7 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq) | |||
| 417 | GFP_KERNEL); | 345 | GFP_KERNEL); |
| 418 | if (!wm8994->supplies) { | 346 | if (!wm8994->supplies) { |
| 419 | ret = -ENOMEM; | 347 | ret = -ENOMEM; |
| 420 | goto err; | 348 | goto err_regmap; |
| 421 | } | 349 | } |
| 422 | 350 | ||
| 423 | switch (wm8994->type) { | 351 | switch (wm8994->type) { |
| @@ -431,7 +359,7 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq) | |||
| 431 | break; | 359 | break; |
| 432 | default: | 360 | default: |
| 433 | BUG(); | 361 | BUG(); |
| 434 | goto err; | 362 | goto err_regmap; |
| 435 | } | 363 | } |
| 436 | 364 | ||
| 437 | ret = regulator_bulk_get(wm8994->dev, wm8994->num_supplies, | 365 | ret = regulator_bulk_get(wm8994->dev, wm8994->num_supplies, |
| @@ -554,7 +482,8 @@ err_get: | |||
| 554 | regulator_bulk_free(wm8994->num_supplies, wm8994->supplies); | 482 | regulator_bulk_free(wm8994->num_supplies, wm8994->supplies); |
| 555 | err_supplies: | 483 | err_supplies: |
| 556 | kfree(wm8994->supplies); | 484 | kfree(wm8994->supplies); |
| 557 | err: | 485 | err_regmap: |
| 486 | regmap_exit(wm8994->regmap); | ||
| 558 | mfd_remove_devices(wm8994->dev); | 487 | mfd_remove_devices(wm8994->dev); |
| 559 | kfree(wm8994); | 488 | kfree(wm8994); |
| 560 | return ret; | 489 | return ret; |
| @@ -569,62 +498,15 @@ static void wm8994_device_exit(struct wm8994 *wm8994) | |||
| 569 | wm8994->supplies); | 498 | wm8994->supplies); |
| 570 | regulator_bulk_free(wm8994->num_supplies, wm8994->supplies); | 499 | regulator_bulk_free(wm8994->num_supplies, wm8994->supplies); |
| 571 | kfree(wm8994->supplies); | 500 | kfree(wm8994->supplies); |
| 501 | regmap_exit(wm8994->regmap); | ||
| 572 | kfree(wm8994); | 502 | kfree(wm8994); |
| 573 | } | 503 | } |
| 574 | 504 | ||
| 575 | static int wm8994_i2c_read_device(struct wm8994 *wm8994, unsigned short reg, | ||
| 576 | int bytes, void *dest) | ||
| 577 | { | ||
| 578 | struct i2c_client *i2c = wm8994->control_data; | ||
| 579 | int ret; | ||
| 580 | u16 r = cpu_to_be16(reg); | ||
| 581 | |||
| 582 | ret = i2c_master_send(i2c, (unsigned char *)&r, 2); | ||
| 583 | if (ret < 0) | ||
| 584 | return ret; | ||
| 585 | if (ret != 2) | ||
| 586 | return -EIO; | ||
| 587 | |||
| 588 | ret = i2c_master_recv(i2c, dest, bytes); | ||
| 589 | if (ret < 0) | ||
| 590 | return ret; | ||
| 591 | if (ret != bytes) | ||
| 592 | return -EIO; | ||
| 593 | return 0; | ||
| 594 | } | ||
| 595 | |||
| 596 | static int wm8994_i2c_write_device(struct wm8994 *wm8994, unsigned short reg, | ||
| 597 | int bytes, const void *src) | ||
| 598 | { | ||
| 599 | struct i2c_client *i2c = wm8994->control_data; | ||
| 600 | struct i2c_msg xfer[2]; | ||
| 601 | int ret; | ||
| 602 | |||
| 603 | reg = cpu_to_be16(reg); | ||
| 604 | |||
| 605 | xfer[0].addr = i2c->addr; | ||
| 606 | xfer[0].flags = 0; | ||
| 607 | xfer[0].len = 2; | ||
| 608 | xfer[0].buf = (char *)® | ||
| 609 | |||
| 610 | xfer[1].addr = i2c->addr; | ||
| 611 | xfer[1].flags = I2C_M_NOSTART; | ||
| 612 | xfer[1].len = bytes; | ||
| 613 | xfer[1].buf = (char *)src; | ||
| 614 | |||
| 615 | ret = i2c_transfer(i2c->adapter, xfer, 2); | ||
| 616 | if (ret < 0) | ||
| 617 | return ret; | ||
| 618 | if (ret != 2) | ||
| 619 | return -EIO; | ||
| 620 | |||
| 621 | return 0; | ||
| 622 | } | ||
| 623 | |||
| 624 | static int wm8994_i2c_probe(struct i2c_client *i2c, | 505 | static int wm8994_i2c_probe(struct i2c_client *i2c, |
| 625 | const struct i2c_device_id *id) | 506 | const struct i2c_device_id *id) |
| 626 | { | 507 | { |
| 627 | struct wm8994 *wm8994; | 508 | struct wm8994 *wm8994; |
| 509 | int ret; | ||
| 628 | 510 | ||
| 629 | wm8994 = kzalloc(sizeof(struct wm8994), GFP_KERNEL); | 511 | wm8994 = kzalloc(sizeof(struct wm8994), GFP_KERNEL); |
| 630 | if (wm8994 == NULL) | 512 | if (wm8994 == NULL) |
| @@ -632,12 +514,18 @@ static int wm8994_i2c_probe(struct i2c_client *i2c, | |||
| 632 | 514 | ||
| 633 | i2c_set_clientdata(i2c, wm8994); | 515 | i2c_set_clientdata(i2c, wm8994); |
| 634 | wm8994->dev = &i2c->dev; | 516 | wm8994->dev = &i2c->dev; |
| 635 | wm8994->control_data = i2c; | ||
| 636 | wm8994->read_dev = wm8994_i2c_read_device; | ||
| 637 | wm8994->write_dev = wm8994_i2c_write_device; | ||
| 638 | wm8994->irq = i2c->irq; | 517 | wm8994->irq = i2c->irq; |
| 639 | wm8994->type = id->driver_data; | 518 | wm8994->type = id->driver_data; |
| 640 | 519 | ||
| 520 | wm8994->regmap = regmap_init_i2c(i2c, &wm8994_regmap_config); | ||
| 521 | if (IS_ERR(wm8994->regmap)) { | ||
| 522 | ret = PTR_ERR(wm8994->regmap); | ||
| 523 | dev_err(wm8994->dev, "Failed to allocate register map: %d\n", | ||
| 524 | ret); | ||
| 525 | kfree(wm8994); | ||
| 526 | return ret; | ||
| 527 | } | ||
| 528 | |||
| 641 | return wm8994_device_init(wm8994, i2c->irq); | 529 | return wm8994_device_init(wm8994, i2c->irq); |
| 642 | } | 530 | } |
| 643 | 531 | ||
diff --git a/include/linux/mfd/wm831x/core.h b/include/linux/mfd/wm831x/core.h index 8dda8ded5cda..ed8fe0d04097 100644 --- a/include/linux/mfd/wm831x/core.h +++ b/include/linux/mfd/wm831x/core.h | |||
| @@ -18,6 +18,7 @@ | |||
| 18 | #include <linux/completion.h> | 18 | #include <linux/completion.h> |
| 19 | #include <linux/interrupt.h> | 19 | #include <linux/interrupt.h> |
| 20 | #include <linux/list.h> | 20 | #include <linux/list.h> |
| 21 | #include <linux/regmap.h> | ||
| 21 | 22 | ||
| 22 | /* | 23 | /* |
| 23 | * Register values. | 24 | * Register values. |
| @@ -361,12 +362,8 @@ struct wm831x { | |||
| 361 | struct mutex io_lock; | 362 | struct mutex io_lock; |
| 362 | 363 | ||
| 363 | struct device *dev; | 364 | struct device *dev; |
| 364 | int (*read_dev)(struct wm831x *wm831x, unsigned short reg, | ||
| 365 | int bytes, void *dest); | ||
| 366 | int (*write_dev)(struct wm831x *wm831x, unsigned short reg, | ||
| 367 | int bytes, void *src); | ||
| 368 | 365 | ||
| 369 | void *control_data; | 366 | struct regmap *regmap; |
| 370 | 367 | ||
| 371 | int irq; /* Our chip IRQ */ | 368 | int irq; /* Our chip IRQ */ |
| 372 | struct mutex irq_lock; | 369 | struct mutex irq_lock; |
| @@ -374,6 +371,8 @@ struct wm831x { | |||
| 374 | int irq_masks_cur[WM831X_NUM_IRQ_REGS]; /* Currently active value */ | 371 | int irq_masks_cur[WM831X_NUM_IRQ_REGS]; /* Currently active value */ |
| 375 | int irq_masks_cache[WM831X_NUM_IRQ_REGS]; /* Cached hardware value */ | 372 | int irq_masks_cache[WM831X_NUM_IRQ_REGS]; /* Cached hardware value */ |
| 376 | 373 | ||
| 374 | bool soft_shutdown; | ||
| 375 | |||
| 377 | /* Chip revision based flags */ | 376 | /* Chip revision based flags */ |
| 378 | unsigned has_gpio_ena:1; /* Has GPIO enable bit */ | 377 | unsigned has_gpio_ena:1; /* Has GPIO enable bit */ |
| 379 | unsigned has_cs_sts:1; /* Has current sink status bit */ | 378 | unsigned has_cs_sts:1; /* Has current sink status bit */ |
| @@ -412,8 +411,11 @@ int wm831x_bulk_read(struct wm831x *wm831x, unsigned short reg, | |||
| 412 | int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq); | 411 | int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq); |
| 413 | void wm831x_device_exit(struct wm831x *wm831x); | 412 | void wm831x_device_exit(struct wm831x *wm831x); |
| 414 | int wm831x_device_suspend(struct wm831x *wm831x); | 413 | int wm831x_device_suspend(struct wm831x *wm831x); |
| 414 | void wm831x_device_shutdown(struct wm831x *wm831x); | ||
| 415 | int wm831x_irq_init(struct wm831x *wm831x, int irq); | 415 | int wm831x_irq_init(struct wm831x *wm831x, int irq); |
| 416 | void wm831x_irq_exit(struct wm831x *wm831x); | 416 | void wm831x_irq_exit(struct wm831x *wm831x); |
| 417 | void wm831x_auxadc_init(struct wm831x *wm831x); | 417 | void wm831x_auxadc_init(struct wm831x *wm831x); |
| 418 | 418 | ||
| 419 | extern struct regmap_config wm831x_regmap_config; | ||
| 420 | |||
| 419 | #endif | 421 | #endif |
diff --git a/include/linux/mfd/wm831x/pdata.h b/include/linux/mfd/wm831x/pdata.h index 0ba24599fe51..1d7a3f7b3b5d 100644 --- a/include/linux/mfd/wm831x/pdata.h +++ b/include/linux/mfd/wm831x/pdata.h | |||
| @@ -123,6 +123,9 @@ struct wm831x_pdata { | |||
| 123 | /** Disable the touchscreen */ | 123 | /** Disable the touchscreen */ |
| 124 | bool disable_touch; | 124 | bool disable_touch; |
| 125 | 125 | ||
| 126 | /** The driver should initiate a power off sequence during shutdown */ | ||
| 127 | bool soft_shutdown; | ||
| 128 | |||
| 126 | int irq_base; | 129 | int irq_base; |
| 127 | int gpio_base; | 130 | int gpio_base; |
| 128 | int gpio_defaults[WM831X_GPIO_NUM]; | 131 | int gpio_defaults[WM831X_GPIO_NUM]; |
diff --git a/include/linux/mfd/wm8400-private.h b/include/linux/mfd/wm8400-private.h index 2aab4e93a5c9..0147b6968510 100644 --- a/include/linux/mfd/wm8400-private.h +++ b/include/linux/mfd/wm8400-private.h | |||
| @@ -25,16 +25,15 @@ | |||
| 25 | #include <linux/mutex.h> | 25 | #include <linux/mutex.h> |
| 26 | #include <linux/platform_device.h> | 26 | #include <linux/platform_device.h> |
| 27 | 27 | ||
| 28 | struct regmap; | ||
| 29 | |||
| 28 | #define WM8400_REGISTER_COUNT 0x55 | 30 | #define WM8400_REGISTER_COUNT 0x55 |
| 29 | 31 | ||
| 30 | struct wm8400 { | 32 | struct wm8400 { |
| 31 | struct device *dev; | 33 | struct device *dev; |
| 32 | 34 | ||
| 33 | int (*read_dev)(void *data, char reg, int count, u16 *dst); | ||
| 34 | int (*write_dev)(void *data, char reg, int count, const u16 *src); | ||
| 35 | |||
| 36 | struct mutex io_lock; | 35 | struct mutex io_lock; |
| 37 | void *io_data; | 36 | struct regmap *regmap; |
| 38 | 37 | ||
| 39 | u16 reg_cache[WM8400_REGISTER_COUNT]; | 38 | u16 reg_cache[WM8400_REGISTER_COUNT]; |
| 40 | 39 | ||
diff --git a/include/linux/mfd/wm8994/core.h b/include/linux/mfd/wm8994/core.h index f0b69cdae41c..45df450d869f 100644 --- a/include/linux/mfd/wm8994/core.h +++ b/include/linux/mfd/wm8994/core.h | |||
| @@ -24,6 +24,7 @@ enum wm8994_type { | |||
| 24 | 24 | ||
| 25 | struct regulator_dev; | 25 | struct regulator_dev; |
| 26 | struct regulator_bulk_data; | 26 | struct regulator_bulk_data; |
| 27 | struct regmap; | ||
| 27 | 28 | ||
| 28 | #define WM8994_NUM_GPIO_REGS 11 | 29 | #define WM8994_NUM_GPIO_REGS 11 |
| 29 | #define WM8994_NUM_LDO_REGS 2 | 30 | #define WM8994_NUM_LDO_REGS 2 |
| @@ -50,18 +51,12 @@ struct regulator_bulk_data; | |||
| 50 | #define WM8994_IRQ_GPIO(x) (x + WM8994_IRQ_TEMP_WARN) | 51 | #define WM8994_IRQ_GPIO(x) (x + WM8994_IRQ_TEMP_WARN) |
| 51 | 52 | ||
| 52 | struct wm8994 { | 53 | struct wm8994 { |
| 53 | struct mutex io_lock; | ||
| 54 | struct mutex irq_lock; | 54 | struct mutex irq_lock; |
| 55 | 55 | ||
| 56 | enum wm8994_type type; | 56 | enum wm8994_type type; |
| 57 | 57 | ||
| 58 | struct device *dev; | 58 | struct device *dev; |
| 59 | int (*read_dev)(struct wm8994 *wm8994, unsigned short reg, | 59 | struct regmap *regmap; |
| 60 | int bytes, void *dest); | ||
| 61 | int (*write_dev)(struct wm8994 *wm8994, unsigned short reg, | ||
| 62 | int bytes, const void *src); | ||
| 63 | |||
| 64 | void *control_data; | ||
| 65 | 60 | ||
| 66 | int gpio_base; | 61 | int gpio_base; |
| 67 | int irq_base; | 62 | int irq_base; |
diff --git a/include/linux/regmap.h b/include/linux/regmap.h index 60a65cd7e1a0..3daac2d8dc37 100644 --- a/include/linux/regmap.h +++ b/include/linux/regmap.h | |||
| @@ -20,9 +20,77 @@ | |||
| 20 | struct i2c_client; | 20 | struct i2c_client; |
| 21 | struct spi_device; | 21 | struct spi_device; |
| 22 | 22 | ||
| 23 | /* An enum of all the supported cache types */ | ||
| 24 | enum regcache_type { | ||
| 25 | REGCACHE_NONE, | ||
| 26 | REGCACHE_INDEXED, | ||
| 27 | REGCACHE_RBTREE, | ||
| 28 | REGCACHE_LZO | ||
| 29 | }; | ||
| 30 | |||
| 31 | /** | ||
| 32 | * Default value for a register. We use an array of structs rather | ||
| 33 | * than a simple array as many modern devices have very sparse | ||
| 34 | * register maps. | ||
| 35 | * | ||
| 36 | * @reg: Register address. | ||
| 37 | * @def: Register default value. | ||
| 38 | */ | ||
| 39 | struct reg_default { | ||
| 40 | unsigned int reg; | ||
| 41 | unsigned int def; | ||
| 42 | }; | ||
| 43 | |||
| 44 | /** | ||
| 45 | * Configuration for the register map of a device. | ||
| 46 | * | ||
| 47 | * @reg_bits: Number of bits in a register address, mandatory. | ||
| 48 | * @val_bits: Number of bits in a register value, mandatory. | ||
| 49 | * | ||
| 50 | * @writeable_reg: Optional callback returning true if the register | ||
| 51 | * can be written to. | ||
| 52 | * @readable_reg: Optional callback returning true if the register | ||
| 53 | * can be read from. | ||
| 54 | * @volatile_reg: Optional callback returning true if the register | ||
| 55 | * value can't be cached. | ||
| 56 | * @precious_reg: Optional callback returning true if the rgister | ||
| 57 | * should not be read outside of a call from the driver | ||
| 58 | * (eg, a clear on read interrupt status register). | ||
| 59 | * | ||
| 60 | * @max_register: Optional, specifies the maximum valid register index. | ||
| 61 | * @reg_defaults: Power on reset values for registers (for use with | ||
| 62 | * register cache support). | ||
| 63 | * @num_reg_defaults: Number of elements in reg_defaults. | ||
| 64 | * | ||
| 65 | * @read_flag_mask: Mask to be set in the top byte of the register when doing | ||
| 66 | * a read. | ||
| 67 | * @write_flag_mask: Mask to be set in the top byte of the register when doing | ||
| 68 | * a write. If both read_flag_mask and write_flag_mask are | ||
| 69 | * empty the regmap_bus default masks are used. | ||
| 70 | * | ||
| 71 | * @cache_type: The actual cache type. | ||
| 72 | * @reg_defaults_raw: Power on reset values for registers (for use with | ||
| 73 | * register cache support). | ||
| 74 | * @num_reg_defaults_raw: Number of elements in reg_defaults_raw. | ||
| 75 | */ | ||
| 23 | struct regmap_config { | 76 | struct regmap_config { |
| 24 | int reg_bits; | 77 | int reg_bits; |
| 25 | int val_bits; | 78 | int val_bits; |
| 79 | |||
| 80 | bool (*writeable_reg)(struct device *dev, unsigned int reg); | ||
| 81 | bool (*readable_reg)(struct device *dev, unsigned int reg); | ||
| 82 | bool (*volatile_reg)(struct device *dev, unsigned int reg); | ||
| 83 | bool (*precious_reg)(struct device *dev, unsigned int reg); | ||
| 84 | |||
| 85 | unsigned int max_register; | ||
| 86 | struct reg_default *reg_defaults; | ||
| 87 | unsigned int num_reg_defaults; | ||
| 88 | enum regcache_type cache_type; | ||
| 89 | const void *reg_defaults_raw; | ||
| 90 | unsigned int num_reg_defaults_raw; | ||
| 91 | |||
| 92 | u8 read_flag_mask; | ||
| 93 | u8 write_flag_mask; | ||
| 26 | }; | 94 | }; |
| 27 | 95 | ||
| 28 | typedef int (*regmap_hw_write)(struct device *dev, const void *data, | 96 | typedef int (*regmap_hw_write)(struct device *dev, const void *data, |
| @@ -37,25 +105,18 @@ typedef int (*regmap_hw_read)(struct device *dev, | |||
| 37 | /** | 105 | /** |
| 38 | * Description of a hardware bus for the register map infrastructure. | 106 | * Description of a hardware bus for the register map infrastructure. |
| 39 | * | 107 | * |
| 40 | * @list: Internal use. | ||
| 41 | * @type: Bus type, used to identify bus to be used for a device. | ||
| 42 | * @write: Write operation. | 108 | * @write: Write operation. |
| 43 | * @gather_write: Write operation with split register/value, return -ENOTSUPP | 109 | * @gather_write: Write operation with split register/value, return -ENOTSUPP |
| 44 | * if not implemented on a given device. | 110 | * if not implemented on a given device. |
| 45 | * @read: Read operation. Data is returned in the buffer used to transmit | 111 | * @read: Read operation. Data is returned in the buffer used to transmit |
| 46 | * data. | 112 | * 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 | 113 | * @read_flag_mask: Mask to be set in the top byte of the register when doing |
| 50 | * a read. | 114 | * a read. |
| 51 | */ | 115 | */ |
| 52 | struct regmap_bus { | 116 | struct regmap_bus { |
| 53 | struct list_head list; | ||
| 54 | struct bus_type *type; | ||
| 55 | regmap_hw_write write; | 117 | regmap_hw_write write; |
| 56 | regmap_hw_gather_write gather_write; | 118 | regmap_hw_gather_write gather_write; |
| 57 | regmap_hw_read read; | 119 | regmap_hw_read read; |
| 58 | struct module *owner; | ||
| 59 | u8 read_flag_mask; | 120 | u8 read_flag_mask; |
| 60 | }; | 121 | }; |
| 61 | 122 | ||
| @@ -79,4 +140,8 @@ int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val, | |||
| 79 | int regmap_update_bits(struct regmap *map, unsigned int reg, | 140 | int regmap_update_bits(struct regmap *map, unsigned int reg, |
| 80 | unsigned int mask, unsigned int val); | 141 | unsigned int mask, unsigned int val); |
| 81 | 142 | ||
| 143 | int regcache_sync(struct regmap *map); | ||
| 144 | void regcache_cache_only(struct regmap *map, bool enable); | ||
| 145 | void regcache_cache_bypass(struct regmap *map, bool enable); | ||
| 146 | |||
| 82 | #endif | 147 | #endif |
diff --git a/include/trace/events/regmap.h b/include/trace/events/regmap.h new file mode 100644 index 000000000000..1e3193b8fcc8 --- /dev/null +++ b/include/trace/events/regmap.h | |||
| @@ -0,0 +1,136 @@ | |||
| 1 | #undef TRACE_SYSTEM | ||
| 2 | #define TRACE_SYSTEM regmap | ||
| 3 | |||
| 4 | #if !defined(_TRACE_REGMAP_H) || defined(TRACE_HEADER_MULTI_READ) | ||
| 5 | #define _TRACE_REGMAP_H | ||
| 6 | |||
| 7 | #include <linux/device.h> | ||
| 8 | #include <linux/ktime.h> | ||
| 9 | #include <linux/tracepoint.h> | ||
| 10 | |||
| 11 | struct regmap; | ||
| 12 | |||
| 13 | /* | ||
| 14 | * Log register events | ||
| 15 | */ | ||
| 16 | DECLARE_EVENT_CLASS(regmap_reg, | ||
| 17 | |||
| 18 | TP_PROTO(struct device *dev, unsigned int reg, | ||
| 19 | unsigned int val), | ||
| 20 | |||
| 21 | TP_ARGS(dev, reg, val), | ||
| 22 | |||
| 23 | TP_STRUCT__entry( | ||
| 24 | __string( name, dev_name(dev) ) | ||
| 25 | __field( unsigned int, reg ) | ||
| 26 | __field( unsigned int, val ) | ||
| 27 | ), | ||
| 28 | |||
| 29 | TP_fast_assign( | ||
| 30 | __assign_str(name, dev_name(dev)); | ||
| 31 | __entry->reg = reg; | ||
| 32 | __entry->val = val; | ||
| 33 | ), | ||
| 34 | |||
| 35 | TP_printk("%s reg=%x val=%x", __get_str(name), | ||
| 36 | (unsigned int)__entry->reg, | ||
| 37 | (unsigned int)__entry->val) | ||
| 38 | ); | ||
| 39 | |||
| 40 | DEFINE_EVENT(regmap_reg, regmap_reg_write, | ||
| 41 | |||
| 42 | TP_PROTO(struct device *dev, unsigned int reg, | ||
| 43 | unsigned int val), | ||
| 44 | |||
| 45 | TP_ARGS(dev, reg, val) | ||
| 46 | |||
| 47 | ); | ||
| 48 | |||
| 49 | DEFINE_EVENT(regmap_reg, regmap_reg_read, | ||
| 50 | |||
| 51 | TP_PROTO(struct device *dev, unsigned int reg, | ||
| 52 | unsigned int val), | ||
| 53 | |||
| 54 | TP_ARGS(dev, reg, val) | ||
| 55 | |||
| 56 | ); | ||
| 57 | |||
| 58 | DECLARE_EVENT_CLASS(regmap_block, | ||
| 59 | |||
| 60 | TP_PROTO(struct device *dev, unsigned int reg, int count), | ||
| 61 | |||
| 62 | TP_ARGS(dev, reg, count), | ||
| 63 | |||
| 64 | TP_STRUCT__entry( | ||
| 65 | __string( name, dev_name(dev) ) | ||
| 66 | __field( unsigned int, reg ) | ||
| 67 | __field( int, count ) | ||
| 68 | ), | ||
| 69 | |||
| 70 | TP_fast_assign( | ||
| 71 | __assign_str(name, dev_name(dev)); | ||
| 72 | __entry->reg = reg; | ||
| 73 | __entry->count = count; | ||
| 74 | ), | ||
| 75 | |||
| 76 | TP_printk("%s reg=%x count=%d", __get_str(name), | ||
| 77 | (unsigned int)__entry->reg, | ||
| 78 | (int)__entry->count) | ||
| 79 | ); | ||
| 80 | |||
| 81 | DEFINE_EVENT(regmap_block, regmap_hw_read_start, | ||
| 82 | |||
| 83 | TP_PROTO(struct device *dev, unsigned int reg, int count), | ||
| 84 | |||
| 85 | TP_ARGS(dev, reg, count) | ||
| 86 | ); | ||
| 87 | |||
| 88 | DEFINE_EVENT(regmap_block, regmap_hw_read_done, | ||
| 89 | |||
| 90 | TP_PROTO(struct device *dev, unsigned int reg, int count), | ||
| 91 | |||
| 92 | TP_ARGS(dev, reg, count) | ||
| 93 | ); | ||
| 94 | |||
| 95 | DEFINE_EVENT(regmap_block, regmap_hw_write_start, | ||
| 96 | |||
| 97 | TP_PROTO(struct device *dev, unsigned int reg, int count), | ||
| 98 | |||
| 99 | TP_ARGS(dev, reg, count) | ||
| 100 | ); | ||
| 101 | |||
| 102 | DEFINE_EVENT(regmap_block, regmap_hw_write_done, | ||
| 103 | |||
| 104 | TP_PROTO(struct device *dev, unsigned int reg, int count), | ||
| 105 | |||
| 106 | TP_ARGS(dev, reg, count) | ||
| 107 | ); | ||
| 108 | |||
| 109 | TRACE_EVENT(regcache_sync, | ||
| 110 | |||
| 111 | TP_PROTO(struct device *dev, const char *type, | ||
| 112 | const char *status), | ||
| 113 | |||
| 114 | TP_ARGS(dev, type, status), | ||
| 115 | |||
| 116 | TP_STRUCT__entry( | ||
| 117 | __string( name, dev_name(dev) ) | ||
| 118 | __string( status, status ) | ||
| 119 | __string( type, type ) | ||
| 120 | __field( int, type ) | ||
| 121 | ), | ||
| 122 | |||
| 123 | TP_fast_assign( | ||
| 124 | __assign_str(name, dev_name(dev)); | ||
| 125 | __assign_str(status, status); | ||
| 126 | __assign_str(type, type); | ||
| 127 | ), | ||
| 128 | |||
| 129 | TP_printk("%s type=%s status=%s", __get_str(name), | ||
| 130 | __get_str(type), __get_str(status)) | ||
| 131 | ); | ||
| 132 | |||
| 133 | #endif /* _TRACE_REGMAP_H */ | ||
| 134 | |||
| 135 | /* This part must be outside protection */ | ||
| 136 | #include <trace/define_trace.h> | ||
