Commit c6b38ec0 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'regmap-v3.15' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap

Pull regmap updates from Mark Brown:
 "Quite a busy release for regmap this time around, the standout changes
  are:

   - A real implementation of regmap_multi_write() and a bypassed
     version of it for use by drivers doing patch-like things with more
     open coding for surrounding startup sequences.
   - Support fast_io on bulk operations.
   - Support split device binding and map initialisation for use by
     devices required in early init (mainly system controllers).
   - Fixes for some operations on maps with strides set.
   - Export the value parsing operations to help generic code built on
     top of the API.
   - Support for MMIO regmaps with non-32 bit register sizes.

  plus a few smaller fixes"

* tag 'regmap-v3.15' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap: (22 commits)
  regmap: mmio: Add regmap_mmio_regbits_check.
  regmap: mmio: Add support for 1/2/8 bytes wide register address.
  regmap: mmio: add regmap_mmio_{regsize, count}_check.
  regmap: cache: Don't attempt to sync non-writeable registers
  regmap: cache: Step by stride in default sync
  regmap: Fix possible sleep-in-atomic in regmap_bulk_write()
  regmap: Ensure regmap_register_patch() is compatible with fast_io
  regmap: irq: Set data pointer only on regmap_add_irq_chip success
  regmap: Implementation for regmap_multi_reg_write
  regmap: add regmap_parse_val api
  mfd: arizona: Use new regmap features for manual register patch
  regmap: Base regmap_register_patch on _regmap_multi_reg_write
  regmap: Add bypassed version of regmap_multi_reg_write
  regmap: Mark reg_defaults in regmap_multi_reg_write as const
  regmap: fix coccinelle warnings
  regmap: Check stride of register patch as we register it
  regmap: Clean up _regmap_update_bits()
  regmap: Separate regmap dev initialization
  regmap: Check readable regs in _regmap_read
  regmap: irq: Remove domain on exit
  ...
parents d64b3932 6012b1f3
......@@ -134,6 +134,8 @@ struct regmap {
/* if set, converts bulk rw to single rw */
bool use_single_rw;
/* if set, the device supports multi write mode */
bool can_multi_write;
struct rb_root range_tree;
void *selector_work_buf; /* Scratch buffer used for selector */
......
......@@ -249,11 +249,12 @@ static int regcache_default_sync(struct regmap *map, unsigned int min,
{
unsigned int reg;
for (reg = min; reg <= max; reg++) {
for (reg = min; reg <= max; reg += map->reg_stride) {
unsigned int val;
int ret;
if (regmap_volatile(map, reg))
if (regmap_volatile(map, reg) ||
!regmap_writeable(map, reg))
continue;
ret = regcache_read(map, reg, &val);
......@@ -312,10 +313,6 @@ int regcache_sync(struct regmap *map)
/* Apply any patch first */
map->cache_bypass = 1;
for (i = 0; i < map->patch_regs; i++) {
if (map->patch[i].reg % map->reg_stride) {
ret = -EINVAL;
goto out;
}
ret = _regmap_write(map, map->patch[i].reg, map->patch[i].def);
if (ret != 0) {
dev_err(map->dev, "Failed to write %x = %x: %d\n",
......@@ -636,10 +633,10 @@ static int regcache_sync_block_raw_flush(struct regmap *map, const void **data,
if (*data == NULL)
return 0;
count = cur - base;
count = (cur - base) / map->reg_stride;
dev_dbg(map->dev, "Writing %zu bytes for %d registers from 0x%x-0x%x\n",
count * val_bytes, count, base, cur - 1);
count * val_bytes, count, base, cur - map->reg_stride);
map->cache_bypass = 1;
......
......@@ -511,7 +511,7 @@ void regmap_debugfs_init(struct regmap *map, const char *name)
debugfs_create_file("range", 0400, map->debugfs,
map, &regmap_reg_ranges_fops);
if (map->max_register) {
if (map->max_register || regmap_readable(map, 0)) {
debugfs_create_file("registers", 0400, map->debugfs,
map, &regmap_map_fops);
debugfs_create_file("access", 0400, map->debugfs,
......
......@@ -368,8 +368,6 @@ int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
if (!d)
return -ENOMEM;
*data = d;
d->status_buf = kzalloc(sizeof(unsigned int) * chip->num_regs,
GFP_KERNEL);
if (!d->status_buf)
......@@ -506,6 +504,8 @@ int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
goto err_domain;
}
*data = d;
return 0;
err_domain:
......@@ -533,7 +533,7 @@ void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *d)
return;
free_irq(irq, d);
/* We should unmap the domain but... */
irq_domain_remove(d->domain);
kfree(d->wake_buf);
kfree(d->mask_buf_def);
kfree(d->mask_buf);
......
......@@ -26,10 +26,47 @@
struct regmap_mmio_context {
void __iomem *regs;
unsigned reg_bytes;
unsigned val_bytes;
unsigned pad_bytes;
struct clk *clk;
};
static inline void regmap_mmio_regsize_check(size_t reg_size)
{
switch (reg_size) {
case 1:
case 2:
case 4:
#ifdef CONFIG_64BIT
case 8:
#endif
break;
default:
BUG();
}
}
static int regmap_mmio_regbits_check(size_t reg_bits)
{
switch (reg_bits) {
case 8:
case 16:
case 32:
#ifdef CONFIG_64BIT
case 64:
#endif
return 0;
default:
return -EINVAL;
}
}
static inline void regmap_mmio_count_check(size_t count)
{
BUG_ON(count % 2 != 0);
}
static int regmap_mmio_gather_write(void *context,
const void *reg, size_t reg_size,
const void *val, size_t val_size)
......@@ -38,7 +75,7 @@ static int regmap_mmio_gather_write(void *context,
u32 offset;
int ret;
BUG_ON(reg_size != 4);
regmap_mmio_regsize_check(reg_size);
if (!IS_ERR(ctx->clk)) {
ret = clk_enable(ctx->clk);
......@@ -81,9 +118,13 @@ static int regmap_mmio_gather_write(void *context,
static int regmap_mmio_write(void *context, const void *data, size_t count)
{
BUG_ON(count < 4);
struct regmap_mmio_context *ctx = context;
u32 offset = ctx->reg_bytes + ctx->pad_bytes;
regmap_mmio_count_check(count);
return regmap_mmio_gather_write(context, data, 4, data + 4, count - 4);
return regmap_mmio_gather_write(context, data, ctx->reg_bytes,
data + offset, count - offset);
}
static int regmap_mmio_read(void *context,
......@@ -94,7 +135,7 @@ static int regmap_mmio_read(void *context,
u32 offset;
int ret;
BUG_ON(reg_size != 4);
regmap_mmio_regsize_check(reg_size);
if (!IS_ERR(ctx->clk)) {
ret = clk_enable(ctx->clk);
......@@ -165,8 +206,9 @@ static struct regmap_mmio_context *regmap_mmio_gen_context(struct device *dev,
int min_stride;
int ret;
if (config->reg_bits != 32)
return ERR_PTR(-EINVAL);
ret = regmap_mmio_regbits_check(config->reg_bits);
if (ret)
return ERR_PTR(ret);
if (config->pad_bits)
return ERR_PTR(-EINVAL);
......@@ -209,6 +251,8 @@ static struct regmap_mmio_context *regmap_mmio_gen_context(struct device *dev,
ctx->regs = regs;
ctx->val_bytes = config->val_bits / 8;
ctx->reg_bytes = config->reg_bits / 8;
ctx->pad_bytes = config->pad_bits / 8;
ctx->clk = ERR_PTR(-ENODEV);
if (clk_id == NULL)
......
This diff is collapsed.
......@@ -251,8 +251,6 @@ static int arizona_apply_hardware_patch(struct arizona* arizona)
unsigned int fll, sysclk;
int ret, err;
regcache_cache_bypass(arizona->regmap, true);
/* Cache existing FLL and SYSCLK settings */
ret = regmap_read(arizona->regmap, ARIZONA_FLL1_CONTROL_1, &fll);
if (ret != 0) {
......@@ -322,8 +320,6 @@ static int arizona_apply_hardware_patch(struct arizona* arizona)
err);
}
regcache_cache_bypass(arizona->regmap, false);
if (ret != 0)
return ret;
else
......
......@@ -80,8 +80,7 @@ static const struct reg_default wm5102_revb_patch[] = {
int wm5102_patch(struct arizona *arizona)
{
const struct reg_default *wm5102_patch;
int ret = 0;
int i, patch_size;
int patch_size;
switch (arizona->rev) {
case 0:
......@@ -92,21 +91,9 @@ int wm5102_patch(struct arizona *arizona)
patch_size = ARRAY_SIZE(wm5102_revb_patch);
}
regcache_cache_bypass(arizona->regmap, true);
for (i = 0; i < patch_size; i++) {
ret = regmap_write(arizona->regmap, wm5102_patch[i].reg,
wm5102_patch[i].def);
if (ret != 0) {
dev_err(arizona->dev, "Failed to write %x = %x: %d\n",
wm5102_patch[i].reg, wm5102_patch[i].def, ret);
goto out;
}
}
out:
regcache_cache_bypass(arizona->regmap, false);
return ret;
return regmap_multi_reg_write_bypassed(arizona->regmap,
wm5102_patch,
patch_size);
}
static const struct regmap_irq wm5102_aod_irqs[ARIZONA_NUM_IRQ] = {
......
......@@ -164,6 +164,9 @@ typedef void (*regmap_unlock)(void *);
* @use_single_rw: If set, converts the bulk read and write operations into
* a series of single read and write operations. This is useful
* for device that does not support bulk read and write.
* @can_multi_write: If set, the device supports the multi write mode of bulk
* write operations, if clear multi write requests will be
* split into individual write operations
*
* @cache_type: The actual cache type.
* @reg_defaults_raw: Power on reset values for registers (for use with
......@@ -215,6 +218,7 @@ struct regmap_config {
u8 write_flag_mask;
bool use_single_rw;
bool can_multi_write;
enum regmap_endian reg_format_endian;
enum regmap_endian val_format_endian;
......@@ -317,6 +321,8 @@ struct regmap *regmap_init(struct device *dev,
const struct regmap_bus *bus,
void *bus_context,
const struct regmap_config *config);
int regmap_attach_dev(struct device *dev, struct regmap *map,
const struct regmap_config *config);
struct regmap *regmap_init_i2c(struct i2c_client *i2c,
const struct regmap_config *config);
struct regmap *regmap_init_spi(struct spi_device *dev,
......@@ -386,8 +392,11 @@ int regmap_raw_write(struct regmap *map, unsigned int reg,
const void *val, size_t val_len);
int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
size_t val_count);
int regmap_multi_reg_write(struct regmap *map, struct reg_default *regs,
int regmap_multi_reg_write(struct regmap *map, const struct reg_default *regs,
int num_regs);
int regmap_multi_reg_write_bypassed(struct regmap *map,
const struct reg_default *regs,
int num_regs);
int regmap_raw_write_async(struct regmap *map, unsigned int reg,
const void *val, size_t val_len);
int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
......@@ -423,6 +432,8 @@ bool regmap_check_range_table(struct regmap *map, unsigned int reg,
int regmap_register_patch(struct regmap *map, const struct reg_default *regs,
int num_regs);
int regmap_parse_val(struct regmap *map, const void *buf,
unsigned int *val);
static inline bool regmap_reg_in_range(unsigned int reg,
const struct regmap_range *range)
......@@ -695,6 +706,13 @@ static inline int regmap_register_patch(struct regmap *map,
return -EINVAL;
}
static inline int regmap_parse_val(struct regmap *map, const void *buf,
unsigned int *val)
{
WARN_ONCE(1, "regmap API is disabled");
return -EINVAL;
}
static inline struct regmap *dev_get_regmap(struct device *dev,
const char *name)
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment