Skip to content

Commit

Permalink
Merge tag 'regmap-v5.8' of git://git.kernel.org/pub/scm/linux/kernel/…
Browse files Browse the repository at this point in the history
…git/broonie/regmap

Pull regmap updates from Mark Brown:
 "This has been a very active release for the regmap API for some
  reason, a lot of it due to new devices with odd requirements that can
  sensibly be handled here.

   - Add support for buses implementing a custom reg_update_bits()
     method in case the bus has a native operation for this.

   - Support 16 bit register addresses in SMBus.

   - Allow customization of the device attached to regmap-irq.

   - Helpers for bitfield operations and per-port field initializations"

* tag 'regmap-v5.8' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap:
  regmap: provide helpers for simple bit operations
  regmap: add helper for per-port regfield initialization
  regmap-i2c: add 16-bit width registers support
  regmap: Simplify implementation of the regmap_field_read_poll_timeout() macro
  regmap: Simplify implementation of the regmap_read_poll_timeout() macro
  regmap: add reg_sequence helpers
  regmap-irq: make it possible to add irq_chip do a specific device node
  regmap: Add bus reg_update_bits() support
  regmap: debugfs: check count when read regmap file
  • Loading branch information
torvalds committed Jun 1, 2020
2 parents 129b9a5 + 9b98f92 commit 213fd09
Show file tree
Hide file tree
Showing 5 changed files with 228 additions and 55 deletions.
6 changes: 6 additions & 0 deletions drivers/base/regmap/regmap-debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ static ssize_t regmap_read_debugfs(struct regmap *map, unsigned int from,
if (*ppos < 0 || !count)
return -EINVAL;

if (count > (PAGE_SIZE << (MAX_ORDER - 1)))
count = PAGE_SIZE << (MAX_ORDER - 1);

buf = kmalloc(count, GFP_KERNEL);
if (!buf)
return -ENOMEM;
Expand Down Expand Up @@ -371,6 +374,9 @@ static ssize_t regmap_reg_ranges_read_file(struct file *file,
if (*ppos < 0 || !count)
return -EINVAL;

if (count > (PAGE_SIZE << (MAX_ORDER - 1)))
count = PAGE_SIZE << (MAX_ORDER - 1);

buf = kmalloc(count, GFP_KERNEL);
if (!buf)
return -ENOMEM;
Expand Down
61 changes: 61 additions & 0 deletions drivers/base/regmap/regmap-i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,63 @@ static const struct regmap_bus regmap_i2c_smbus_i2c_block = {
.max_raw_write = I2C_SMBUS_BLOCK_MAX,
};

static int regmap_i2c_smbus_i2c_write_reg16(void *context, const void *data,
size_t count)
{
struct device *dev = context;
struct i2c_client *i2c = to_i2c_client(dev);

if (count < 2)
return -EINVAL;

count--;
return i2c_smbus_write_i2c_block_data(i2c, ((u8 *)data)[0], count,
(u8 *)data + 1);
}

static int regmap_i2c_smbus_i2c_read_reg16(void *context, const void *reg,
size_t reg_size, void *val,
size_t val_size)
{
struct device *dev = context;
struct i2c_client *i2c = to_i2c_client(dev);
int ret, count, len = val_size;

if (reg_size != 2)
return -EINVAL;

ret = i2c_smbus_write_byte_data(i2c, ((u16 *)reg)[0] & 0xff,
((u16 *)reg)[0] >> 8);
if (ret < 0)
return ret;

count = 0;
do {
/* Current Address Read */
ret = i2c_smbus_read_byte(i2c);
if (ret < 0)
break;

*((u8 *)val++) = ret;
count++;
len--;
} while (len > 0);

if (count == val_size)
return 0;
else if (ret < 0)
return ret;
else
return -EIO;
}

static const struct regmap_bus regmap_i2c_smbus_i2c_block_reg16 = {
.write = regmap_i2c_smbus_i2c_write_reg16,
.read = regmap_i2c_smbus_i2c_read_reg16,
.max_raw_read = I2C_SMBUS_BLOCK_MAX,
.max_raw_write = I2C_SMBUS_BLOCK_MAX,
};

static const struct regmap_bus *regmap_get_i2c_bus(struct i2c_client *i2c,
const struct regmap_config *config)
{
Expand All @@ -255,6 +312,10 @@ static const struct regmap_bus *regmap_get_i2c_bus(struct i2c_client *i2c,
i2c_check_functionality(i2c->adapter,
I2C_FUNC_SMBUS_I2C_BLOCK))
return &regmap_i2c_smbus_i2c_block;
else if (config->val_bits == 8 && config->reg_bits == 16 &&
i2c_check_functionality(i2c->adapter,
I2C_FUNC_SMBUS_I2C_BLOCK))
return &regmap_i2c_smbus_i2c_block_reg16;
else if (config->val_bits == 16 && config->reg_bits == 8 &&
i2c_check_functionality(i2c->adapter,
I2C_FUNC_SMBUS_WORD_DATA))
Expand Down
84 changes: 68 additions & 16 deletions drivers/base/regmap/regmap-irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,9 @@ static const struct irq_domain_ops regmap_domain_ops = {
};

/**
* regmap_add_irq_chip() - Use standard regmap IRQ controller handling
* regmap_add_irq_chip_np() - Use standard regmap IRQ controller handling
*
* @np: The device_node where the IRQ domain should be added to.
* @map: The regmap for the device.
* @irq: The IRQ the device uses to signal interrupts.
* @irq_flags: The IRQF_ flags to use for the primary interrupt.
Expand All @@ -556,9 +557,10 @@ static const struct irq_domain_ops regmap_domain_ops = {
* register cache. The chip driver is responsible for restoring the
* register values used by the IRQ controller over suspend and resume.
*/
int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
int irq_base, const struct regmap_irq_chip *chip,
struct regmap_irq_chip_data **data)
int regmap_add_irq_chip_np(struct device_node *np, struct regmap *map, int irq,
int irq_flags, int irq_base,
const struct regmap_irq_chip *chip,
struct regmap_irq_chip_data **data)
{
struct regmap_irq_chip_data *d;
int i;
Expand Down Expand Up @@ -769,12 +771,10 @@ int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
}

if (irq_base)
d->domain = irq_domain_add_legacy(map->dev->of_node,
chip->num_irqs, irq_base, 0,
&regmap_domain_ops, d);
d->domain = irq_domain_add_legacy(np, chip->num_irqs, irq_base,
0, &regmap_domain_ops, d);
else
d->domain = irq_domain_add_linear(map->dev->of_node,
chip->num_irqs,
d->domain = irq_domain_add_linear(np, chip->num_irqs,
&regmap_domain_ops, d);
if (!d->domain) {
dev_err(map->dev, "Failed to create IRQ domain\n");
Expand Down Expand Up @@ -808,6 +808,30 @@ int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
kfree(d);
return ret;
}
EXPORT_SYMBOL_GPL(regmap_add_irq_chip_np);

/**
* regmap_add_irq_chip() - Use standard regmap IRQ controller handling
*
* @map: The regmap for the device.
* @irq: The IRQ the device uses to signal interrupts.
* @irq_flags: The IRQF_ flags to use for the primary interrupt.
* @irq_base: Allocate at specific IRQ number if irq_base > 0.
* @chip: Configuration for the interrupt controller.
* @data: Runtime data structure for the controller, allocated on success.
*
* Returns 0 on success or an errno on failure.
*
* This is the same as regmap_add_irq_chip_np, except that the device
* node of the regmap is used.
*/
int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
int irq_base, const struct regmap_irq_chip *chip,
struct regmap_irq_chip_data **data)
{
return regmap_add_irq_chip_np(map->dev->of_node, map, irq, irq_flags,
irq_base, chip, data);
}
EXPORT_SYMBOL_GPL(regmap_add_irq_chip);

/**
Expand Down Expand Up @@ -875,9 +899,10 @@ static int devm_regmap_irq_chip_match(struct device *dev, void *res, void *data)
}

/**
* devm_regmap_add_irq_chip() - Resource manager regmap_add_irq_chip()
* devm_regmap_add_irq_chip_np() - Resource manager regmap_add_irq_chip_np()
*
* @dev: The device pointer on which irq_chip belongs to.
* @np: The device_node where the IRQ domain should be added to.
* @map: The regmap for the device.
* @irq: The IRQ the device uses to signal interrupts
* @irq_flags: The IRQF_ flags to use for the primary interrupt.
Expand All @@ -890,10 +915,11 @@ static int devm_regmap_irq_chip_match(struct device *dev, void *res, void *data)
* The &regmap_irq_chip_data will be automatically released when the device is
* unbound.
*/
int devm_regmap_add_irq_chip(struct device *dev, struct regmap *map, int irq,
int irq_flags, int irq_base,
const struct regmap_irq_chip *chip,
struct regmap_irq_chip_data **data)
int devm_regmap_add_irq_chip_np(struct device *dev, struct device_node *np,
struct regmap *map, int irq, int irq_flags,
int irq_base,
const struct regmap_irq_chip *chip,
struct regmap_irq_chip_data **data)
{
struct regmap_irq_chip_data **ptr, *d;
int ret;
Expand All @@ -903,8 +929,8 @@ int devm_regmap_add_irq_chip(struct device *dev, struct regmap *map, int irq,
if (!ptr)
return -ENOMEM;

ret = regmap_add_irq_chip(map, irq, irq_flags, irq_base,
chip, &d);
ret = regmap_add_irq_chip_np(np, map, irq, irq_flags, irq_base,
chip, &d);
if (ret < 0) {
devres_free(ptr);
return ret;
Expand All @@ -915,6 +941,32 @@ int devm_regmap_add_irq_chip(struct device *dev, struct regmap *map, int irq,
*data = d;
return 0;
}
EXPORT_SYMBOL_GPL(devm_regmap_add_irq_chip_np);

/**
* devm_regmap_add_irq_chip() - Resource manager regmap_add_irq_chip()
*
* @dev: The device pointer on which irq_chip belongs to.
* @map: The regmap for the device.
* @irq: The IRQ the device uses to signal interrupts
* @irq_flags: The IRQF_ flags to use for the primary interrupt.
* @irq_base: Allocate at specific IRQ number if irq_base > 0.
* @chip: Configuration for the interrupt controller.
* @data: Runtime data structure for the controller, allocated on success
*
* Returns 0 on success or an errno on failure.
*
* The &regmap_irq_chip_data will be automatically released when the device is
* unbound.
*/
int devm_regmap_add_irq_chip(struct device *dev, struct regmap *map, int irq,
int irq_flags, int irq_base,
const struct regmap_irq_chip *chip,
struct regmap_irq_chip_data **data)
{
return devm_regmap_add_irq_chip_np(dev, map->dev->of_node, map, irq,
irq_flags, irq_base, chip, data);
}
EXPORT_SYMBOL_GPL(devm_regmap_add_irq_chip);

/**
Expand Down
23 changes: 23 additions & 0 deletions drivers/base/regmap/regmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,7 @@ struct regmap *__regmap_init(struct device *dev,
} else if (!bus->read || !bus->write) {
map->reg_read = _regmap_bus_reg_read;
map->reg_write = _regmap_bus_reg_write;
map->reg_update_bits = bus->reg_update_bits;

map->defer_caching = false;
goto skip_format_initialization;
Expand Down Expand Up @@ -2936,6 +2937,28 @@ int regmap_update_bits_base(struct regmap *map, unsigned int reg,
}
EXPORT_SYMBOL_GPL(regmap_update_bits_base);

/**
* regmap_test_bits() - Check if all specified bits are set in a register.
*
* @map: Register map to operate on
* @reg: Register to read from
* @bits: Bits to test
*
* Returns -1 if the underlying regmap_read() fails, 0 if at least one of the
* tested bits is not set and 1 if all tested bits are set.
*/
int regmap_test_bits(struct regmap *map, unsigned int reg, unsigned int bits)
{
unsigned int val, ret;

ret = regmap_read(map, reg, &val);
if (ret)
return ret;

return (val & bits) == bits;
}
EXPORT_SYMBOL_GPL(regmap_test_bits);

void regmap_async_complete_cb(struct regmap_async *async, int ret)
{
struct regmap *map = async->map;
Expand Down
Loading

0 comments on commit 213fd09

Please sign in to comment.