regmap: Updates for v5.18

A couple of small fixes, plus some new features that enable us to handle
 devices that reformat register addresses depending on the bus used to
 handle the control interface more gracefully.
 -----BEGIN PGP SIGNATURE-----
 
 iQEzBAABCgAdFiEEreZoqmdXGLWf4p/qJNaLcl1Uh9AFAmI4aVQACgkQJNaLcl1U
 h9DH7Qf/UfcjSp9MbQ7vZ+uuSQFjcRSSKri0VzFSETAaXBSyDOF43L/3dk60xDo5
 +4Om4LX3LZvA387I3bctPaij8fNp+X1bYr2pWUbh/FnJ+fS7PUfzXbQXkh/tKsMP
 qhYCcrWVBnGTj0OZAuazYW79V1LolBGC5+YjDRipbcwZhqNVWZKuWVYUhLOduZ5G
 5n5PxUyPnDEYF6ixJQq2QiCA6Pb/BSPgviaEHVxeLWxs8IOtq+9u69ijecfDYiwD
 vMpFlOnPoy+Bpu7gnU2LhDZ/Nmxvi22BtRxt4qtmC3lTq9Cf/Xrtm2En3aaRsero
 SsLc0ZaHkt6W9V5O0yFNrjWLslTAJg==
 =3oe7
 -----END PGP SIGNATURE-----

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

Pull regmap updates from Mark Brown:
 "A couple of small fixes, plus some new features that enable us to
  handle devices that reformat register addresses depending on the bus
  used to handle the control interface more gracefully"

* tag 'regmap-v5.18' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap:
  regmap: allow a defined reg_base to be added to every address
  regmap: add configurable downshift for addresses
  regmap: irq: cleanup comments
  regmap-irq: Fix typo in comment
This commit is contained in:
Linus Torvalds 2022-03-21 18:22:42 -07:00
commit a50a8c3833
4 changed files with 22 additions and 3 deletions

View File

@ -31,6 +31,7 @@ struct regmap_format {
size_t buf_size; size_t buf_size;
size_t reg_bytes; size_t reg_bytes;
size_t pad_bytes; size_t pad_bytes;
size_t reg_downshift;
size_t val_bytes; size_t val_bytes;
void (*format_write)(struct regmap *map, void (*format_write)(struct regmap *map,
unsigned int reg, unsigned int val); unsigned int reg, unsigned int val);
@ -62,6 +63,7 @@ struct regmap {
regmap_unlock unlock; regmap_unlock unlock;
void *lock_arg; /* This is passed to lock/unlock functions */ void *lock_arg; /* This is passed to lock/unlock functions */
gfp_t alloc_flags; gfp_t alloc_flags;
unsigned int reg_base;
struct device *dev; /* Device we do I/O on */ struct device *dev; /* Device we do I/O on */
void *work_buf; /* Scratch buffer used to format I/O */ void *work_buf; /* Scratch buffer used to format I/O */

View File

@ -535,7 +535,7 @@ static irqreturn_t regmap_irq_thread(int irq, void *d)
/* /*
* Ignore masked IRQs and ack if we need to; we ack early so * Ignore masked IRQs and ack if we need to; we ack early so
* there is no race between handling and acknowleding the * there is no race between handling and acknowledging the
* interrupt. We assume that typically few of the interrupts * interrupt. We assume that typically few of the interrupts
* will fire simultaneously so don't worry about overhead from * will fire simultaneously so don't worry about overhead from
* doing a write per register. * doing a write per register.
@ -1045,7 +1045,7 @@ int devm_regmap_add_irq_chip_fwnode(struct device *dev,
EXPORT_SYMBOL_GPL(devm_regmap_add_irq_chip_fwnode); EXPORT_SYMBOL_GPL(devm_regmap_add_irq_chip_fwnode);
/** /**
* devm_regmap_add_irq_chip() - Resource manager regmap_add_irq_chip() * devm_regmap_add_irq_chip() - Resource managed regmap_add_irq_chip()
* *
* @dev: The device pointer on which irq_chip belongs to. * @dev: The device pointer on which irq_chip belongs to.
* @map: The regmap for the device. * @map: The regmap for the device.
@ -1074,7 +1074,7 @@ EXPORT_SYMBOL_GPL(devm_regmap_add_irq_chip);
/** /**
* devm_regmap_del_irq_chip() - Resource managed regmap_del_irq_chip() * devm_regmap_del_irq_chip() - Resource managed regmap_del_irq_chip()
* *
* @dev: Device for which which resource was allocated. * @dev: Device for which the resource was allocated.
* @irq: Primary IRQ for the device. * @irq: Primary IRQ for the device.
* @data: &regmap_irq_chip_data allocated by regmap_add_irq_chip(). * @data: &regmap_irq_chip_data allocated by regmap_add_irq_chip().
* *

View File

@ -821,8 +821,11 @@ struct regmap *__regmap_init(struct device *dev,
else else
map->alloc_flags = GFP_KERNEL; map->alloc_flags = GFP_KERNEL;
map->reg_base = config->reg_base;
map->format.reg_bytes = DIV_ROUND_UP(config->reg_bits, 8); map->format.reg_bytes = DIV_ROUND_UP(config->reg_bits, 8);
map->format.pad_bytes = config->pad_bits / 8; map->format.pad_bytes = config->pad_bits / 8;
map->format.reg_downshift = config->reg_downshift;
map->format.val_bytes = DIV_ROUND_UP(config->val_bits, 8); map->format.val_bytes = DIV_ROUND_UP(config->val_bits, 8);
map->format.buf_size = DIV_ROUND_UP(config->reg_bits + map->format.buf_size = DIV_ROUND_UP(config->reg_bits +
config->val_bits + config->pad_bits, 8); config->val_bits + config->pad_bits, 8);
@ -1735,6 +1738,8 @@ static int _regmap_raw_write_impl(struct regmap *map, unsigned int reg,
return ret; return ret;
} }
reg += map->reg_base;
reg >>= map->format.reg_downshift;
map->format.format_reg(map->work_buf, reg, map->reg_shift); map->format.format_reg(map->work_buf, reg, map->reg_shift);
regmap_set_work_buf_flag_mask(map, map->format.reg_bytes, regmap_set_work_buf_flag_mask(map, map->format.reg_bytes,
map->write_flag_mask); map->write_flag_mask);
@ -1905,6 +1910,8 @@ static int _regmap_bus_formatted_write(void *context, unsigned int reg,
return ret; return ret;
} }
reg += map->reg_base;
reg >>= map->format.reg_downshift;
map->format.format_write(map, reg, val); map->format.format_write(map, reg, val);
trace_regmap_hw_write_start(map, reg, 1); trace_regmap_hw_write_start(map, reg, 1);
@ -2346,6 +2353,8 @@ static int _regmap_raw_multi_reg_write(struct regmap *map,
unsigned int reg = regs[i].reg; unsigned int reg = regs[i].reg;
unsigned int val = regs[i].def; unsigned int val = regs[i].def;
trace_regmap_hw_write_start(map, reg, 1); trace_regmap_hw_write_start(map, reg, 1);
reg += map->reg_base;
reg >>= map->format.reg_downshift;
map->format.format_reg(u8, reg, map->reg_shift); map->format.format_reg(u8, reg, map->reg_shift);
u8 += reg_bytes + pad_bytes; u8 += reg_bytes + pad_bytes;
map->format.format_val(u8, val, 0); map->format.format_val(u8, val, 0);
@ -2673,6 +2682,8 @@ static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
return ret; return ret;
} }
reg += map->reg_base;
reg >>= map->format.reg_downshift;
map->format.format_reg(map->work_buf, reg, map->reg_shift); map->format.format_reg(map->work_buf, reg, map->reg_shift);
regmap_set_work_buf_flag_mask(map, map->format.reg_bytes, regmap_set_work_buf_flag_mask(map, map->format.reg_bytes,
map->read_flag_mask); map->read_flag_mask);

View File

@ -237,6 +237,10 @@ typedef void (*regmap_unlock)(void *);
* @reg_stride: The register address stride. Valid register addresses are a * @reg_stride: The register address stride. Valid register addresses are a
* multiple of this value. If set to 0, a value of 1 will be * multiple of this value. If set to 0, a value of 1 will be
* used. * used.
* @reg_downshift: The number of bits to downshift the register before
* performing any operations.
* @reg_base: Value to be added to every register address before performing any
* operation.
* @pad_bits: Number of bits of padding between register and value. * @pad_bits: Number of bits of padding between register and value.
* @val_bits: Number of bits in a register value, mandatory. * @val_bits: Number of bits in a register value, mandatory.
* *
@ -360,6 +364,8 @@ struct regmap_config {
int reg_bits; int reg_bits;
int reg_stride; int reg_stride;
int reg_downshift;
unsigned int reg_base;
int pad_bits; int pad_bits;
int val_bits; int val_bits;