Commit b8cc9174 authored by Linus Torvalds's avatar Linus Torvalds

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

Pull regmap updates from Mark Brown:
 "A few new APIs here, support for the FSI bus (which is used in some
  PowerPC systems) plus a couple of new APIs, one allowing abstractions
  built on top of regmap to tell if the regmap can be used in an atomic
  context and one providing a callback for an in flight device which
  can't do interrupt masking very well.

  There's also a fix that I never got round to sending because it really
  should be fixed better but that's not happened yet and it does avoid
  the problem, the fix was in -next for a long time"

* tag 'regmap-v6.2' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap:
  regmap-irq: Add handle_mask_sync() callback
  regmap: Add FSI bus support
  regmap: add regmap_might_sleep()
  regmap-irq: Use the new num_config_regs property in regmap_add_irq_chip_fwnode
parents 1e4fa020 22250dba
......@@ -4,7 +4,7 @@
# subsystems should select the appropriate symbols.
config REGMAP
default y if (REGMAP_I2C || REGMAP_SPI || REGMAP_SPMI || REGMAP_W1 || REGMAP_AC97 || REGMAP_MMIO || REGMAP_IRQ || REGMAP_SOUNDWIRE || REGMAP_SOUNDWIRE_MBQ || REGMAP_SCCB || REGMAP_I3C || REGMAP_SPI_AVMM || REGMAP_MDIO)
default y if (REGMAP_I2C || REGMAP_SPI || REGMAP_SPMI || REGMAP_W1 || REGMAP_AC97 || REGMAP_MMIO || REGMAP_IRQ || REGMAP_SOUNDWIRE || REGMAP_SOUNDWIRE_MBQ || REGMAP_SCCB || REGMAP_I3C || REGMAP_SPI_AVMM || REGMAP_MDIO || REGMAP_FSI)
select IRQ_DOMAIN if REGMAP_IRQ
select MDIO_BUS if REGMAP_MDIO
bool
......@@ -65,3 +65,7 @@ config REGMAP_I3C
config REGMAP_SPI_AVMM
tristate
depends on SPI
config REGMAP_FSI
tristate
depends on FSI
......@@ -20,3 +20,4 @@ obj-$(CONFIG_REGMAP_SCCB) += regmap-sccb.o
obj-$(CONFIG_REGMAP_I3C) += regmap-i3c.o
obj-$(CONFIG_REGMAP_SPI_AVMM) += regmap-spi-avmm.o
obj-$(CONFIG_REGMAP_MDIO) += regmap-mdio.o
obj-$(CONFIG_REGMAP_FSI) += regmap-fsi.o
// SPDX-License-Identifier: GPL-2.0
//
// Register map access API - FSI support
//
// Copyright 2022 IBM Corp
//
// Author: Eddie James <eajames@linux.ibm.com>
#include <linux/fsi.h>
#include <linux/module.h>
#include <linux/regmap.h>
#include "internal.h"
static int regmap_fsi32_reg_read(void *context, unsigned int reg, unsigned int *val)
{
u32 v;
int ret;
ret = fsi_slave_read(context, reg, &v, sizeof(v));
if (ret)
return ret;
*val = v;
return 0;
}
static int regmap_fsi32_reg_write(void *context, unsigned int reg, unsigned int val)
{
u32 v = val;
return fsi_slave_write(context, reg, &v, sizeof(v));
}
static const struct regmap_bus regmap_fsi32 = {
.reg_write = regmap_fsi32_reg_write,
.reg_read = regmap_fsi32_reg_read,
};
static int regmap_fsi32le_reg_read(void *context, unsigned int reg, unsigned int *val)
{
__be32 v;
int ret;
ret = fsi_slave_read(context, reg, &v, sizeof(v));
if (ret)
return ret;
*val = be32_to_cpu(v);
return 0;
}
static int regmap_fsi32le_reg_write(void *context, unsigned int reg, unsigned int val)
{
__be32 v = cpu_to_be32(val);
return fsi_slave_write(context, reg, &v, sizeof(v));
}
static const struct regmap_bus regmap_fsi32le = {
.reg_write = regmap_fsi32le_reg_write,
.reg_read = regmap_fsi32le_reg_read,
};
static int regmap_fsi16_reg_read(void *context, unsigned int reg, unsigned int *val)
{
u16 v;
int ret;
ret = fsi_slave_read(context, reg, &v, sizeof(v));
if (ret)
return ret;
*val = v;
return 0;
}
static int regmap_fsi16_reg_write(void *context, unsigned int reg, unsigned int val)
{
u16 v;
if (val > 0xffff)
return -EINVAL;
v = val;
return fsi_slave_write(context, reg, &v, sizeof(v));
}
static const struct regmap_bus regmap_fsi16 = {
.reg_write = regmap_fsi16_reg_write,
.reg_read = regmap_fsi16_reg_read,
};
static int regmap_fsi16le_reg_read(void *context, unsigned int reg, unsigned int *val)
{
__be16 v;
int ret;
ret = fsi_slave_read(context, reg, &v, sizeof(v));
if (ret)
return ret;
*val = be16_to_cpu(v);
return 0;
}
static int regmap_fsi16le_reg_write(void *context, unsigned int reg, unsigned int val)
{
__be16 v;
if (val > 0xffff)
return -EINVAL;
v = cpu_to_be16(val);
return fsi_slave_write(context, reg, &v, sizeof(v));
}
static const struct regmap_bus regmap_fsi16le = {
.reg_write = regmap_fsi16le_reg_write,
.reg_read = regmap_fsi16le_reg_read,
};
static int regmap_fsi8_reg_read(void *context, unsigned int reg, unsigned int *val)
{
u8 v;
int ret;
ret = fsi_slave_read(context, reg, &v, sizeof(v));
if (ret)
return ret;
*val = v;
return 0;
}
static int regmap_fsi8_reg_write(void *context, unsigned int reg, unsigned int val)
{
u8 v;
if (val > 0xff)
return -EINVAL;
v = val;
return fsi_slave_write(context, reg, &v, sizeof(v));
}
static const struct regmap_bus regmap_fsi8 = {
.reg_write = regmap_fsi8_reg_write,
.reg_read = regmap_fsi8_reg_read,
};
static const struct regmap_bus *regmap_get_fsi_bus(struct fsi_device *fsi_dev,
const struct regmap_config *config)
{
const struct regmap_bus *bus = NULL;
if (config->reg_bits == 8 || config->reg_bits == 16 || config->reg_bits == 32) {
switch (config->val_bits) {
case 8:
bus = &regmap_fsi8;
break;
case 16:
switch (regmap_get_val_endian(&fsi_dev->dev, NULL, config)) {
case REGMAP_ENDIAN_LITTLE:
#ifdef __LITTLE_ENDIAN
case REGMAP_ENDIAN_NATIVE:
#endif
bus = &regmap_fsi16le;
break;
case REGMAP_ENDIAN_DEFAULT:
case REGMAP_ENDIAN_BIG:
#ifdef __BIG_ENDIAN
case REGMAP_ENDIAN_NATIVE:
#endif
bus = &regmap_fsi16;
break;
default:
break;
}
break;
case 32:
switch (regmap_get_val_endian(&fsi_dev->dev, NULL, config)) {
case REGMAP_ENDIAN_LITTLE:
#ifdef __LITTLE_ENDIAN
case REGMAP_ENDIAN_NATIVE:
#endif
bus = &regmap_fsi32le;
break;
case REGMAP_ENDIAN_DEFAULT:
case REGMAP_ENDIAN_BIG:
#ifdef __BIG_ENDIAN
case REGMAP_ENDIAN_NATIVE:
#endif
bus = &regmap_fsi32;
break;
default:
break;
}
break;
}
}
return bus ?: ERR_PTR(-EOPNOTSUPP);
}
struct regmap *__regmap_init_fsi(struct fsi_device *fsi_dev, const struct regmap_config *config,
struct lock_class_key *lock_key, const char *lock_name)
{
const struct regmap_bus *bus = regmap_get_fsi_bus(fsi_dev, config);
if (IS_ERR(bus))
return ERR_CAST(bus);
return __regmap_init(&fsi_dev->dev, bus, fsi_dev->slave, config, lock_key, lock_name);
}
EXPORT_SYMBOL_GPL(__regmap_init_fsi);
struct regmap *__devm_regmap_init_fsi(struct fsi_device *fsi_dev,
const struct regmap_config *config,
struct lock_class_key *lock_key, const char *lock_name)
{
const struct regmap_bus *bus = regmap_get_fsi_bus(fsi_dev, config);
if (IS_ERR(bus))
return ERR_CAST(bus);
return __devm_regmap_init(&fsi_dev->dev, bus, fsi_dev->slave, config, lock_key, lock_name);
}
EXPORT_SYMBOL_GPL(__devm_regmap_init_fsi);
MODULE_LICENSE("GPL");
......@@ -115,12 +115,20 @@ static void regmap_irq_sync_unlock(struct irq_data *data)
*/
for (i = 0; i < d->chip->num_regs; i++) {
if (d->mask_base) {
reg = d->get_irq_reg(d, d->mask_base, i);
ret = regmap_update_bits(d->map, reg,
d->mask_buf_def[i], d->mask_buf[i]);
if (ret)
dev_err(d->map->dev, "Failed to sync masks in %x\n",
reg);
if (d->chip->handle_mask_sync)
d->chip->handle_mask_sync(d->map, i,
d->mask_buf_def[i],
d->mask_buf[i],
d->chip->irq_drv_data);
else {
reg = d->get_irq_reg(d, d->mask_base, i);
ret = regmap_update_bits(d->map, reg,
d->mask_buf_def[i],
d->mask_buf[i]);
if (ret)
dev_err(d->map->dev, "Failed to sync masks in %x\n",
reg);
}
}
if (d->unmask_base) {
......@@ -722,6 +730,7 @@ int regmap_add_irq_chip_fwnode(struct fwnode_handle *fwnode,
int i;
int ret = -ENOMEM;
int num_type_reg;
int num_regs;
u32 reg;
if (chip->num_regs <= 0)
......@@ -796,14 +805,20 @@ int regmap_add_irq_chip_fwnode(struct fwnode_handle *fwnode,
goto err_alloc;
}
num_type_reg = chip->type_in_mask ? chip->num_regs : chip->num_type_reg;
if (num_type_reg) {
d->type_buf_def = kcalloc(num_type_reg,
/*
* Use num_config_regs if defined, otherwise fall back to num_type_reg
* to maintain backward compatibility.
*/
num_type_reg = chip->num_config_regs ? chip->num_config_regs
: chip->num_type_reg;
num_regs = chip->type_in_mask ? chip->num_regs : num_type_reg;
if (num_regs) {
d->type_buf_def = kcalloc(num_regs,
sizeof(*d->type_buf_def), GFP_KERNEL);
if (!d->type_buf_def)
goto err_alloc;
d->type_buf = kcalloc(num_type_reg, sizeof(*d->type_buf),
d->type_buf = kcalloc(num_regs, sizeof(*d->type_buf),
GFP_KERNEL);
if (!d->type_buf)
goto err_alloc;
......@@ -917,13 +932,23 @@ int regmap_add_irq_chip_fwnode(struct fwnode_handle *fwnode,
d->mask_buf[i] = d->mask_buf_def[i];
if (d->mask_base) {
reg = d->get_irq_reg(d, d->mask_base, i);
ret = regmap_update_bits(d->map, reg,
d->mask_buf_def[i], d->mask_buf[i]);
if (ret) {
dev_err(map->dev, "Failed to set masks in 0x%x: %d\n",
reg, ret);
goto err_alloc;
if (chip->handle_mask_sync) {
ret = chip->handle_mask_sync(d->map, i,
d->mask_buf_def[i],
d->mask_buf[i],
chip->irq_drv_data);
if (ret)
goto err_alloc;
} else {
reg = d->get_irq_reg(d, d->mask_base, i);
ret = regmap_update_bits(d->map, reg,
d->mask_buf_def[i],
d->mask_buf[i]);
if (ret) {
dev_err(map->dev, "Failed to set masks in 0x%x: %d\n",
reg, ret);
goto err_alloc;
}
}
}
......
......@@ -3486,6 +3486,19 @@ int regmap_get_reg_stride(struct regmap *map)
}
EXPORT_SYMBOL_GPL(regmap_get_reg_stride);
/**
* regmap_might_sleep() - Returns whether a regmap access might sleep.
*
* @map: Register map to operate on.
*
* Returns true if an access to the register might sleep, else false.
*/
bool regmap_might_sleep(struct regmap *map)
{
return map->can_sleep;
}
EXPORT_SYMBOL_GPL(regmap_might_sleep);
int regmap_parse_val(struct regmap *map, const void *buf,
unsigned int *val)
{
......
......@@ -24,6 +24,7 @@ struct module;
struct clk;
struct device;
struct device_node;
struct fsi_device;
struct i2c_client;
struct i3c_device;
struct irq_domain;
......@@ -628,6 +629,10 @@ struct regmap *__regmap_init_spi_avmm(struct spi_device *spi,
const struct regmap_config *config,
struct lock_class_key *lock_key,
const char *lock_name);
struct regmap *__regmap_init_fsi(struct fsi_device *fsi_dev,
const struct regmap_config *config,
struct lock_class_key *lock_key,
const char *lock_name);
struct regmap *__devm_regmap_init(struct device *dev,
const struct regmap_bus *bus,
......@@ -693,6 +698,11 @@ struct regmap *__devm_regmap_init_spi_avmm(struct spi_device *spi,
const struct regmap_config *config,
struct lock_class_key *lock_key,
const char *lock_name);
struct regmap *__devm_regmap_init_fsi(struct fsi_device *fsi_dev,
const struct regmap_config *config,
struct lock_class_key *lock_key,
const char *lock_name);
/*
* Wrapper for regmap_init macros to include a unique lockdep key and name
* for each call. No-op if CONFIG_LOCKDEP is not set.
......@@ -919,6 +929,19 @@ bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg);
__regmap_lockdep_wrapper(__regmap_init_spi_avmm, #config, \
spi, config)
/**
* regmap_init_fsi() - Initialise register map
*
* @fsi_dev: Device that will be interacted with
* @config: Configuration for register map
*
* The return value will be an ERR_PTR() on error or a valid pointer to
* a struct regmap.
*/
#define regmap_init_fsi(fsi_dev, config) \
__regmap_lockdep_wrapper(__regmap_init_fsi, #config, fsi_dev, \
config)
/**
* devm_regmap_init() - Initialise managed register map
*
......@@ -1148,6 +1171,20 @@ bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg);
__regmap_lockdep_wrapper(__devm_regmap_init_spi_avmm, #config, \
spi, config)
/**
* devm_regmap_init_fsi() - Initialise managed register map
*
* @fsi_dev: Device that will be interacted with
* @config: Configuration for register map
*
* The return value will be an ERR_PTR() on error or a valid pointer
* to a struct regmap. The regmap will be automatically freed by the
* device management code.
*/
#define devm_regmap_init_fsi(fsi_dev, config) \
__regmap_lockdep_wrapper(__devm_regmap_init_fsi, #config, \
fsi_dev, config)
int regmap_mmio_attach_clk(struct regmap *map, struct clk *clk);
void regmap_mmio_detach_clk(struct regmap *map);
void regmap_exit(struct regmap *map);
......@@ -1219,6 +1256,7 @@ static inline int regmap_write_bits(struct regmap *map, unsigned int reg,
int regmap_get_val_bytes(struct regmap *map);
int regmap_get_max_register(struct regmap *map);
int regmap_get_reg_stride(struct regmap *map);
bool regmap_might_sleep(struct regmap *map);
int regmap_async_complete(struct regmap *map);
bool regmap_can_raw_write(struct regmap *map);
size_t regmap_get_raw_read_max(struct regmap *map);
......@@ -1542,6 +1580,8 @@ struct regmap_irq_chip_data;
* before regmap_irq_handler process the interrupts.
* @handle_post_irq: Driver specific callback to handle interrupt from device
* after handling the interrupts in regmap_irq_handler().
* @handle_mask_sync: Callback used to handle IRQ mask syncs. The index will be
* in the range [0, num_regs)
* @set_type_virt: Driver specific callback to extend regmap_irq_set_type()
* and configure virt regs. Deprecated, use @set_type_config
* callback and config registers instead.
......@@ -1603,6 +1643,9 @@ struct regmap_irq_chip {
int (*handle_pre_irq)(void *irq_drv_data);
int (*handle_post_irq)(void *irq_drv_data);
int (*handle_mask_sync)(struct regmap *map, int index,
unsigned int mask_buf_def,
unsigned int mask_buf, void *irq_drv_data);
int (*set_type_virt)(unsigned int **buf, unsigned int type,
unsigned long hwirq, int reg);
int (*set_type_config)(unsigned int **buf, unsigned int type,
......@@ -1905,6 +1948,12 @@ static inline int regmap_get_reg_stride(struct regmap *map)
return -EINVAL;
}
static inline bool regmap_might_sleep(struct regmap *map)
{
WARN_ONCE(1, "regmap API is disabled");
return true;
}
static inline int regcache_sync(struct regmap *map)
{
WARN_ONCE(1, "regmap API is disabled");
......
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