Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge remote-tracking branch 'regmap/for-5.14' into regmap-next

+222 -8
+5 -1
drivers/base/regmap/Kconfig
··· 4 4 # subsystems should select the appropriate symbols. 5 5 6 6 config REGMAP 7 - 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) 7 + 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) 8 8 select IRQ_DOMAIN if REGMAP_IRQ 9 + select MDIO_BUS if REGMAP_MDIO 9 10 bool 10 11 11 12 config REGCACHE_COMPRESSED ··· 36 35 config REGMAP_W1 37 36 tristate 38 37 depends on W1 38 + 39 + config REGMAP_MDIO 40 + tristate 39 41 40 42 config REGMAP_MMIO 41 43 tristate
+1
drivers/base/regmap/Makefile
··· 19 19 obj-$(CONFIG_REGMAP_SCCB) += regmap-sccb.o 20 20 obj-$(CONFIG_REGMAP_I3C) += regmap-i3c.o 21 21 obj-$(CONFIG_REGMAP_SPI_AVMM) += regmap-spi-avmm.o 22 + obj-$(CONFIG_REGMAP_MDIO) += regmap-mdio.o
+38 -7
drivers/base/regmap/regmap-i2c.c
··· 306 306 static const struct regmap_bus *regmap_get_i2c_bus(struct i2c_client *i2c, 307 307 const struct regmap_config *config) 308 308 { 309 + const struct i2c_adapter_quirks *quirks; 310 + const struct regmap_bus *bus = NULL; 311 + struct regmap_bus *ret_bus; 312 + u16 max_read = 0, max_write = 0; 313 + 309 314 if (i2c_check_functionality(i2c->adapter, I2C_FUNC_I2C)) 310 - return &regmap_i2c; 315 + bus = &regmap_i2c; 311 316 else if (config->val_bits == 8 && config->reg_bits == 8 && 312 317 i2c_check_functionality(i2c->adapter, 313 318 I2C_FUNC_SMBUS_I2C_BLOCK)) 314 - return &regmap_i2c_smbus_i2c_block; 319 + bus = &regmap_i2c_smbus_i2c_block; 315 320 else if (config->val_bits == 8 && config->reg_bits == 16 && 316 321 i2c_check_functionality(i2c->adapter, 317 322 I2C_FUNC_SMBUS_I2C_BLOCK)) 318 - return &regmap_i2c_smbus_i2c_block_reg16; 323 + bus = &regmap_i2c_smbus_i2c_block_reg16; 319 324 else if (config->val_bits == 16 && config->reg_bits == 8 && 320 325 i2c_check_functionality(i2c->adapter, 321 326 I2C_FUNC_SMBUS_WORD_DATA)) 322 327 switch (regmap_get_val_endian(&i2c->dev, NULL, config)) { 323 328 case REGMAP_ENDIAN_LITTLE: 324 - return &regmap_smbus_word; 329 + bus = &regmap_smbus_word; 330 + break; 325 331 case REGMAP_ENDIAN_BIG: 326 - return &regmap_smbus_word_swapped; 332 + bus = &regmap_smbus_word_swapped; 333 + break; 327 334 default: /* everything else is not supported */ 328 335 break; 329 336 } 330 337 else if (config->val_bits == 8 && config->reg_bits == 8 && 331 338 i2c_check_functionality(i2c->adapter, 332 339 I2C_FUNC_SMBUS_BYTE_DATA)) 333 - return &regmap_smbus_byte; 340 + bus = &regmap_smbus_byte; 334 341 335 - return ERR_PTR(-ENOTSUPP); 342 + if (!bus) 343 + return ERR_PTR(-ENOTSUPP); 344 + 345 + quirks = i2c->adapter->quirks; 346 + if (quirks) { 347 + if (quirks->max_read_len && 348 + (bus->max_raw_read == 0 || bus->max_raw_read > quirks->max_read_len)) 349 + max_read = quirks->max_read_len; 350 + 351 + if (quirks->max_write_len && 352 + (bus->max_raw_write == 0 || bus->max_raw_write > quirks->max_write_len)) 353 + max_write = quirks->max_write_len; 354 + 355 + if (max_read || max_write) { 356 + ret_bus = kmemdup(bus, sizeof(*bus), GFP_KERNEL); 357 + if (!ret_bus) 358 + return ERR_PTR(-ENOMEM); 359 + ret_bus->free_on_exit = true; 360 + ret_bus->max_raw_read = max_read; 361 + ret_bus->max_raw_write = max_write; 362 + bus = ret_bus; 363 + } 364 + } 365 + 366 + return bus; 336 367 } 337 368 338 369 struct regmap *__regmap_init_i2c(struct i2c_client *i2c,
+7
drivers/base/regmap/regmap-irq.c
··· 531 531 } 532 532 } 533 533 534 + if (chip->status_invert) 535 + for (i = 0; i < data->chip->num_regs; i++) 536 + data->status_buf[i] = ~data->status_buf[i]; 537 + 534 538 /* 535 539 * Ignore masked IRQs and ack if we need to; we ack early so 536 540 * there is no race between handling and acknowleding the ··· 803 799 ret); 804 800 goto err_alloc; 805 801 } 802 + 803 + if (chip->status_invert) 804 + d->status_buf[i] = ~d->status_buf[i]; 806 805 807 806 if (d->status_buf[i] && (chip->ack_base || chip->use_ack)) { 808 807 reg = sub_irq_reg(d, d->chip->ack_base, i);
+116
drivers/base/regmap/regmap-mdio.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + 3 + #include <linux/errno.h> 4 + #include <linux/mdio.h> 5 + #include <linux/module.h> 6 + #include <linux/regmap.h> 7 + 8 + #define REGVAL_MASK GENMASK(15, 0) 9 + #define REGNUM_C22_MASK GENMASK(4, 0) 10 + /* Clause-45 mask includes the device type (5 bit) and actual register number (16 bit) */ 11 + #define REGNUM_C45_MASK GENMASK(20, 0) 12 + 13 + static int regmap_mdio_read(struct mdio_device *mdio_dev, u32 reg, unsigned int *val) 14 + { 15 + int ret; 16 + 17 + ret = mdiobus_read(mdio_dev->bus, mdio_dev->addr, reg); 18 + if (ret < 0) 19 + return ret; 20 + 21 + *val = ret & REGVAL_MASK; 22 + return 0; 23 + } 24 + 25 + static int regmap_mdio_write(struct mdio_device *mdio_dev, u32 reg, unsigned int val) 26 + { 27 + return mdiobus_write(mdio_dev->bus, mdio_dev->addr, reg, val); 28 + } 29 + 30 + static int regmap_mdio_c22_read(void *context, unsigned int reg, unsigned int *val) 31 + { 32 + struct mdio_device *mdio_dev = context; 33 + 34 + if (unlikely(reg & ~REGNUM_C22_MASK)) 35 + return -ENXIO; 36 + 37 + return regmap_mdio_read(mdio_dev, reg, val); 38 + } 39 + 40 + static int regmap_mdio_c22_write(void *context, unsigned int reg, unsigned int val) 41 + { 42 + struct mdio_device *mdio_dev = context; 43 + 44 + if (unlikely(reg & ~REGNUM_C22_MASK)) 45 + return -ENXIO; 46 + 47 + return mdiobus_write(mdio_dev->bus, mdio_dev->addr, reg, val); 48 + } 49 + 50 + static const struct regmap_bus regmap_mdio_c22_bus = { 51 + .reg_write = regmap_mdio_c22_write, 52 + .reg_read = regmap_mdio_c22_read, 53 + }; 54 + 55 + static int regmap_mdio_c45_read(void *context, unsigned int reg, unsigned int *val) 56 + { 57 + struct mdio_device *mdio_dev = context; 58 + 59 + if (unlikely(reg & ~REGNUM_C45_MASK)) 60 + return -ENXIO; 61 + 62 + return regmap_mdio_read(mdio_dev, MII_ADDR_C45 | reg, val); 63 + } 64 + 65 + static int regmap_mdio_c45_write(void *context, unsigned int reg, unsigned int val) 66 + { 67 + struct mdio_device *mdio_dev = context; 68 + 69 + if (unlikely(reg & ~REGNUM_C45_MASK)) 70 + return -ENXIO; 71 + 72 + return regmap_mdio_write(mdio_dev, MII_ADDR_C45 | reg, val); 73 + } 74 + 75 + static const struct regmap_bus regmap_mdio_c45_bus = { 76 + .reg_write = regmap_mdio_c45_write, 77 + .reg_read = regmap_mdio_c45_read, 78 + }; 79 + 80 + struct regmap *__regmap_init_mdio(struct mdio_device *mdio_dev, 81 + const struct regmap_config *config, struct lock_class_key *lock_key, 82 + const char *lock_name) 83 + { 84 + const struct regmap_bus *bus; 85 + 86 + if (config->reg_bits == 5 && config->val_bits == 16) 87 + bus = &regmap_mdio_c22_bus; 88 + else if (config->reg_bits == 21 && config->val_bits == 16) 89 + bus = &regmap_mdio_c45_bus; 90 + else 91 + return ERR_PTR(-EOPNOTSUPP); 92 + 93 + return __regmap_init(&mdio_dev->dev, bus, mdio_dev, config, lock_key, lock_name); 94 + } 95 + EXPORT_SYMBOL_GPL(__regmap_init_mdio); 96 + 97 + struct regmap *__devm_regmap_init_mdio(struct mdio_device *mdio_dev, 98 + const struct regmap_config *config, struct lock_class_key *lock_key, 99 + const char *lock_name) 100 + { 101 + const struct regmap_bus *bus; 102 + 103 + if (config->reg_bits == 5 && config->val_bits == 16) 104 + bus = &regmap_mdio_c22_bus; 105 + else if (config->reg_bits == 21 && config->val_bits == 16) 106 + bus = &regmap_mdio_c45_bus; 107 + else 108 + return ERR_PTR(-EOPNOTSUPP); 109 + 110 + return __devm_regmap_init(&mdio_dev->dev, bus, mdio_dev, config, lock_key, lock_name); 111 + } 112 + EXPORT_SYMBOL_GPL(__devm_regmap_init_mdio); 113 + 114 + MODULE_AUTHOR("Sander Vanheule <sander@svanheule.net>"); 115 + MODULE_DESCRIPTION("Regmap MDIO Module"); 116 + MODULE_LICENSE("GPL v2");
+15
drivers/base/regmap/regmap.c
··· 243 243 *out = cpu_to_be16((reg << 9) | val); 244 244 } 245 245 246 + static void regmap_format_7_17_write(struct regmap *map, 247 + unsigned int reg, unsigned int val) 248 + { 249 + u8 *out = map->work_buf; 250 + 251 + out[2] = val; 252 + out[1] = val >> 8; 253 + out[0] = (val >> 16) | (reg << 1); 254 + } 255 + 246 256 static void regmap_format_10_14_write(struct regmap *map, 247 257 unsigned int reg, unsigned int val) 248 258 { ··· 895 885 case 9: 896 886 map->format.format_write = regmap_format_7_9_write; 897 887 break; 888 + case 17: 889 + map->format.format_write = regmap_format_7_17_write; 890 + break; 898 891 default: 899 892 goto err_hwlock; 900 893 } ··· 1509 1496 mutex_destroy(&map->mutex); 1510 1497 kfree_const(map->name); 1511 1498 kfree(map->patch); 1499 + if (map->bus && map->bus->free_on_exit) 1500 + kfree(map->bus); 1512 1501 kfree(map); 1513 1502 } 1514 1503 EXPORT_SYMBOL_GPL(regmap_exit);
+40
include/linux/regmap.h
··· 27 27 struct i2c_client; 28 28 struct i3c_device; 29 29 struct irq_domain; 30 + struct mdio_device; 30 31 struct slim_device; 31 32 struct spi_device; 32 33 struct spmi_device; ··· 503 502 * DEFAULT, BIG is assumed. 504 503 * @max_raw_read: Max raw read size that can be used on the bus. 505 504 * @max_raw_write: Max raw write size that can be used on the bus. 505 + * @free_on_exit: kfree this on exit of regmap 506 506 */ 507 507 struct regmap_bus { 508 508 bool fast_io; ··· 521 519 enum regmap_endian val_format_endian_default; 522 520 size_t max_raw_read; 523 521 size_t max_raw_write; 522 + bool free_on_exit; 524 523 }; 525 524 526 525 /* ··· 538 535 struct lock_class_key *lock_key, 539 536 const char *lock_name); 540 537 struct regmap *__regmap_init_i2c(struct i2c_client *i2c, 538 + const struct regmap_config *config, 539 + struct lock_class_key *lock_key, 540 + const char *lock_name); 541 + struct regmap *__regmap_init_mdio(struct mdio_device *mdio_dev, 541 542 const struct regmap_config *config, 542 543 struct lock_class_key *lock_key, 543 544 const char *lock_name); ··· 598 591 struct lock_class_key *lock_key, 599 592 const char *lock_name); 600 593 struct regmap *__devm_regmap_init_i2c(struct i2c_client *i2c, 594 + const struct regmap_config *config, 595 + struct lock_class_key *lock_key, 596 + const char *lock_name); 597 + struct regmap *__devm_regmap_init_mdio(struct mdio_device *mdio_dev, 601 598 const struct regmap_config *config, 602 599 struct lock_class_key *lock_key, 603 600 const char *lock_name); ··· 707 696 #define regmap_init_i2c(i2c, config) \ 708 697 __regmap_lockdep_wrapper(__regmap_init_i2c, #config, \ 709 698 i2c, config) 699 + 700 + /** 701 + * regmap_init_mdio() - Initialise register map 702 + * 703 + * @mdio_dev: Device that will be interacted with 704 + * @config: Configuration for register map 705 + * 706 + * The return value will be an ERR_PTR() on error or a valid pointer to 707 + * a struct regmap. 708 + */ 709 + #define regmap_init_mdio(mdio_dev, config) \ 710 + __regmap_lockdep_wrapper(__regmap_init_mdio, #config, \ 711 + mdio_dev, config) 710 712 711 713 /** 712 714 * regmap_init_sccb() - Initialise register map ··· 911 887 #define devm_regmap_init_i2c(i2c, config) \ 912 888 __regmap_lockdep_wrapper(__devm_regmap_init_i2c, #config, \ 913 889 i2c, config) 890 + 891 + /** 892 + * devm_regmap_init_mdio() - Initialise managed register map 893 + * 894 + * @mdio_dev: Device that will be interacted with 895 + * @config: Configuration for register map 896 + * 897 + * The return value will be an ERR_PTR() on error or a valid pointer 898 + * to a struct regmap. The regmap will be automatically freed by the 899 + * device management code. 900 + */ 901 + #define devm_regmap_init_mdio(mdio_dev, config) \ 902 + __regmap_lockdep_wrapper(__devm_regmap_init_mdio, #config, \ 903 + mdio_dev, config) 914 904 915 905 /** 916 906 * devm_regmap_init_sccb() - Initialise managed register map ··· 1449 1411 * @not_fixed_stride: Used when chip peripherals are not laid out with fixed 1450 1412 * stride. Must be used with sub_reg_offsets containing the 1451 1413 * offsets to each peripheral. 1414 + * @status_invert: Inverted status register: cleared bits are active interrupts. 1452 1415 * @runtime_pm: Hold a runtime PM lock on the device when accessing it. 1453 1416 * 1454 1417 * @num_regs: Number of registers in each control bank. ··· 1502 1463 bool type_in_mask:1; 1503 1464 bool clear_on_unmask:1; 1504 1465 bool not_fixed_stride:1; 1466 + bool status_invert:1; 1505 1467 1506 1468 int num_regs; 1507 1469