regmap.c (0135bbcc7a0cc056f0203ff839466236b8e3dc19) | regmap.c (bacdbe077342ecc9e7b3e374cc5a41995116706a) |
---|---|
1/* 2 * Register map access API 3 * 4 * Copyright 2011 Wolfson Microelectronics plc 5 * 6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> 7 * 8 * This program is free software; you can redistribute it and/or modify --- 144 unchanged lines hidden (view full) --- 153{ 154 __be32 *b = buf; 155 156 b[0] = be32_to_cpu(b[0]); 157 158 return b[0]; 159} 160 | 1/* 2 * Register map access API 3 * 4 * Copyright 2011 Wolfson Microelectronics plc 5 * 6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> 7 * 8 * This program is free software; you can redistribute it and/or modify --- 144 unchanged lines hidden (view full) --- 153{ 154 __be32 *b = buf; 155 156 b[0] = be32_to_cpu(b[0]); 157 158 return b[0]; 159} 160 |
161static void regmap_lock_mutex(struct regmap *map) 162{ 163 mutex_lock(&map->mutex); 164} 165 166static void regmap_unlock_mutex(struct regmap *map) 167{ 168 mutex_unlock(&map->mutex); 169} 170 171static void regmap_lock_spinlock(struct regmap *map) 172{ 173 spin_lock(&map->spinlock); 174} 175 176static void regmap_unlock_spinlock(struct regmap *map) 177{ 178 spin_unlock(&map->spinlock); 179} 180 |
|
161/** 162 * regmap_init(): Initialise register map 163 * 164 * @dev: Device that will be interacted with 165 * @bus: Bus-specific callbacks to use with device 166 * @bus_context: Data passed to bus-specific callbacks 167 * @config: Configuration for register map 168 * --- 13 unchanged lines hidden (view full) --- 182 goto err; 183 184 map = kzalloc(sizeof(*map), GFP_KERNEL); 185 if (map == NULL) { 186 ret = -ENOMEM; 187 goto err; 188 } 189 | 181/** 182 * regmap_init(): Initialise register map 183 * 184 * @dev: Device that will be interacted with 185 * @bus: Bus-specific callbacks to use with device 186 * @bus_context: Data passed to bus-specific callbacks 187 * @config: Configuration for register map 188 * --- 13 unchanged lines hidden (view full) --- 202 goto err; 203 204 map = kzalloc(sizeof(*map), GFP_KERNEL); 205 if (map == NULL) { 206 ret = -ENOMEM; 207 goto err; 208 } 209 |
190 mutex_init(&map->lock); | 210 if (bus->fast_io) { 211 spin_lock_init(&map->spinlock); 212 map->lock = regmap_lock_spinlock; 213 map->unlock = regmap_unlock_spinlock; 214 } else { 215 mutex_init(&map->mutex); 216 map->lock = regmap_lock_mutex; 217 map->unlock = regmap_unlock_mutex; 218 } |
191 map->format.buf_size = (config->reg_bits + config->val_bits) / 8; 192 map->format.reg_bytes = DIV_ROUND_UP(config->reg_bits, 8); 193 map->format.pad_bytes = config->pad_bits / 8; 194 map->format.val_bytes = DIV_ROUND_UP(config->val_bits, 8); 195 map->format.buf_size += map->format.pad_bytes; 196 map->dev = dev; 197 map->bus = bus; 198 map->bus_context = bus_context; --- 161 unchanged lines hidden (view full) --- 360 * new cache. This can be used to restore the cache to defaults or to 361 * update the cache configuration to reflect runtime discovery of the 362 * hardware. 363 */ 364int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config) 365{ 366 int ret; 367 | 219 map->format.buf_size = (config->reg_bits + config->val_bits) / 8; 220 map->format.reg_bytes = DIV_ROUND_UP(config->reg_bits, 8); 221 map->format.pad_bytes = config->pad_bits / 8; 222 map->format.val_bytes = DIV_ROUND_UP(config->val_bits, 8); 223 map->format.buf_size += map->format.pad_bytes; 224 map->dev = dev; 225 map->bus = bus; 226 map->bus_context = bus_context; --- 161 unchanged lines hidden (view full) --- 388 * new cache. This can be used to restore the cache to defaults or to 389 * update the cache configuration to reflect runtime discovery of the 390 * hardware. 391 */ 392int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config) 393{ 394 int ret; 395 |
368 mutex_lock(&map->lock); | 396 map->lock(map); |
369 370 regcache_exit(map); 371 regmap_debugfs_exit(map); 372 373 map->max_register = config->max_register; 374 map->writeable_reg = config->writeable_reg; 375 map->readable_reg = config->readable_reg; 376 map->volatile_reg = config->volatile_reg; 377 map->precious_reg = config->precious_reg; 378 map->cache_type = config->cache_type; 379 380 regmap_debugfs_init(map); 381 382 map->cache_bypass = false; 383 map->cache_only = false; 384 385 ret = regcache_init(map, config); 386 | 397 398 regcache_exit(map); 399 regmap_debugfs_exit(map); 400 401 map->max_register = config->max_register; 402 map->writeable_reg = config->writeable_reg; 403 map->readable_reg = config->readable_reg; 404 map->volatile_reg = config->volatile_reg; 405 map->precious_reg = config->precious_reg; 406 map->cache_type = config->cache_type; 407 408 regmap_debugfs_init(map); 409 410 map->cache_bypass = false; 411 map->cache_only = false; 412 413 ret = regcache_init(map, config); 414 |
387 mutex_unlock(&map->lock); | 415 map->unlock(map); |
388 389 return ret; 390} 391 392/** 393 * regmap_exit(): Free a previously allocated register map 394 */ 395void regmap_exit(struct regmap *map) --- 135 unchanged lines hidden (view full) --- 531 * 532 * A value of zero will be returned on success, a negative errno will 533 * be returned in error cases. 534 */ 535int regmap_write(struct regmap *map, unsigned int reg, unsigned int val) 536{ 537 int ret; 538 | 416 417 return ret; 418} 419 420/** 421 * regmap_exit(): Free a previously allocated register map 422 */ 423void regmap_exit(struct regmap *map) --- 135 unchanged lines hidden (view full) --- 559 * 560 * A value of zero will be returned on success, a negative errno will 561 * be returned in error cases. 562 */ 563int regmap_write(struct regmap *map, unsigned int reg, unsigned int val) 564{ 565 int ret; 566 |
539 mutex_lock(&map->lock); | 567 map->lock(map); |
540 541 ret = _regmap_write(map, reg, val); 542 | 568 569 ret = _regmap_write(map, reg, val); 570 |
543 mutex_unlock(&map->lock); | 571 map->unlock(map); |
544 545 return ret; 546} 547EXPORT_SYMBOL_GPL(regmap_write); 548 549/** 550 * regmap_raw_write(): Write raw values to one or more registers 551 * --- 10 unchanged lines hidden (view full) --- 562 * A value of zero will be returned on success, a negative errno will 563 * be returned in error cases. 564 */ 565int regmap_raw_write(struct regmap *map, unsigned int reg, 566 const void *val, size_t val_len) 567{ 568 int ret; 569 | 572 573 return ret; 574} 575EXPORT_SYMBOL_GPL(regmap_write); 576 577/** 578 * regmap_raw_write(): Write raw values to one or more registers 579 * --- 10 unchanged lines hidden (view full) --- 590 * A value of zero will be returned on success, a negative errno will 591 * be returned in error cases. 592 */ 593int regmap_raw_write(struct regmap *map, unsigned int reg, 594 const void *val, size_t val_len) 595{ 596 int ret; 597 |
570 mutex_lock(&map->lock); | 598 map->lock(map); |
571 572 ret = _regmap_raw_write(map, reg, val, val_len); 573 | 599 600 ret = _regmap_raw_write(map, reg, val, val_len); 601 |
574 mutex_unlock(&map->lock); | 602 map->unlock(map); |
575 576 return ret; 577} 578EXPORT_SYMBOL_GPL(regmap_raw_write); 579 580/* 581 * regmap_bulk_write(): Write multiple registers to the device 582 * --- 13 unchanged lines hidden (view full) --- 596{ 597 int ret = 0, i; 598 size_t val_bytes = map->format.val_bytes; 599 void *wval; 600 601 if (!map->format.parse_val) 602 return -EINVAL; 603 | 603 604 return ret; 605} 606EXPORT_SYMBOL_GPL(regmap_raw_write); 607 608/* 609 * regmap_bulk_write(): Write multiple registers to the device 610 * --- 13 unchanged lines hidden (view full) --- 624{ 625 int ret = 0, i; 626 size_t val_bytes = map->format.val_bytes; 627 void *wval; 628 629 if (!map->format.parse_val) 630 return -EINVAL; 631 |
604 mutex_lock(&map->lock); | 632 map->lock(map); |
605 606 /* No formatting is require if val_byte is 1 */ 607 if (val_bytes == 1) { 608 wval = (void *)val; 609 } else { 610 wval = kmemdup(val, val_count * val_bytes, GFP_KERNEL); 611 if (!wval) { 612 ret = -ENOMEM; --- 4 unchanged lines hidden (view full) --- 617 map->format.parse_val(wval + i); 618 } 619 ret = _regmap_raw_write(map, reg, wval, val_bytes * val_count); 620 621 if (val_bytes != 1) 622 kfree(wval); 623 624out: | 633 634 /* No formatting is require if val_byte is 1 */ 635 if (val_bytes == 1) { 636 wval = (void *)val; 637 } else { 638 wval = kmemdup(val, val_count * val_bytes, GFP_KERNEL); 639 if (!wval) { 640 ret = -ENOMEM; --- 4 unchanged lines hidden (view full) --- 645 map->format.parse_val(wval + i); 646 } 647 ret = _regmap_raw_write(map, reg, wval, val_bytes * val_count); 648 649 if (val_bytes != 1) 650 kfree(wval); 651 652out: |
625 mutex_unlock(&map->lock); | 653 map->unlock(map); |
626 return ret; 627} 628EXPORT_SYMBOL_GPL(regmap_bulk_write); 629 630static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val, 631 unsigned int val_len) 632{ 633 u8 *u8 = map->work_buf; --- 57 unchanged lines hidden (view full) --- 691 * 692 * A value of zero will be returned on success, a negative errno will 693 * be returned in error cases. 694 */ 695int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val) 696{ 697 int ret; 698 | 654 return ret; 655} 656EXPORT_SYMBOL_GPL(regmap_bulk_write); 657 658static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val, 659 unsigned int val_len) 660{ 661 u8 *u8 = map->work_buf; --- 57 unchanged lines hidden (view full) --- 719 * 720 * A value of zero will be returned on success, a negative errno will 721 * be returned in error cases. 722 */ 723int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val) 724{ 725 int ret; 726 |
699 mutex_lock(&map->lock); | 727 map->lock(map); |
700 701 ret = _regmap_read(map, reg, val); 702 | 728 729 ret = _regmap_read(map, reg, val); 730 |
703 mutex_unlock(&map->lock); | 731 map->unlock(map); |
704 705 return ret; 706} 707EXPORT_SYMBOL_GPL(regmap_read); 708 709/** 710 * regmap_raw_read(): Read raw data from the device 711 * --- 8 unchanged lines hidden (view full) --- 720int regmap_raw_read(struct regmap *map, unsigned int reg, void *val, 721 size_t val_len) 722{ 723 size_t val_bytes = map->format.val_bytes; 724 size_t val_count = val_len / val_bytes; 725 unsigned int v; 726 int ret, i; 727 | 732 733 return ret; 734} 735EXPORT_SYMBOL_GPL(regmap_read); 736 737/** 738 * regmap_raw_read(): Read raw data from the device 739 * --- 8 unchanged lines hidden (view full) --- 748int regmap_raw_read(struct regmap *map, unsigned int reg, void *val, 749 size_t val_len) 750{ 751 size_t val_bytes = map->format.val_bytes; 752 size_t val_count = val_len / val_bytes; 753 unsigned int v; 754 int ret, i; 755 |
728 mutex_lock(&map->lock); | 756 map->lock(map); |
729 730 if (regmap_volatile_range(map, reg, val_count) || map->cache_bypass || 731 map->cache_type == REGCACHE_NONE) { 732 /* Physical block read if there's no cache involved */ 733 ret = _regmap_raw_read(map, reg, val, val_len); 734 735 } else { 736 /* Otherwise go word by word for the cache; should be low --- 4 unchanged lines hidden (view full) --- 741 if (ret != 0) 742 goto out; 743 744 map->format.format_val(val + (i * val_bytes), v); 745 } 746 } 747 748 out: | 757 758 if (regmap_volatile_range(map, reg, val_count) || map->cache_bypass || 759 map->cache_type == REGCACHE_NONE) { 760 /* Physical block read if there's no cache involved */ 761 ret = _regmap_raw_read(map, reg, val, val_len); 762 763 } else { 764 /* Otherwise go word by word for the cache; should be low --- 4 unchanged lines hidden (view full) --- 769 if (ret != 0) 770 goto out; 771 772 map->format.format_val(val + (i * val_bytes), v); 773 } 774 } 775 776 out: |
749 mutex_unlock(&map->lock); | 777 map->unlock(map); |
750 751 return ret; 752} 753EXPORT_SYMBOL_GPL(regmap_raw_read); 754 755/** 756 * regmap_bulk_read(): Read multiple registers from the device 757 * --- 36 unchanged lines hidden (view full) --- 794 795static int _regmap_update_bits(struct regmap *map, unsigned int reg, 796 unsigned int mask, unsigned int val, 797 bool *change) 798{ 799 int ret; 800 unsigned int tmp, orig; 801 | 778 779 return ret; 780} 781EXPORT_SYMBOL_GPL(regmap_raw_read); 782 783/** 784 * regmap_bulk_read(): Read multiple registers from the device 785 * --- 36 unchanged lines hidden (view full) --- 822 823static int _regmap_update_bits(struct regmap *map, unsigned int reg, 824 unsigned int mask, unsigned int val, 825 bool *change) 826{ 827 int ret; 828 unsigned int tmp, orig; 829 |
802 mutex_lock(&map->lock); | 830 map->lock(map); |
803 804 ret = _regmap_read(map, reg, &orig); 805 if (ret != 0) 806 goto out; 807 808 tmp = orig & ~mask; 809 tmp |= val & mask; 810 811 if (tmp != orig) { 812 ret = _regmap_write(map, reg, tmp); 813 *change = true; 814 } else { 815 *change = false; 816 } 817 818out: | 831 832 ret = _regmap_read(map, reg, &orig); 833 if (ret != 0) 834 goto out; 835 836 tmp = orig & ~mask; 837 tmp |= val & mask; 838 839 if (tmp != orig) { 840 ret = _regmap_write(map, reg, tmp); 841 *change = true; 842 } else { 843 *change = false; 844 } 845 846out: |
819 mutex_unlock(&map->lock); | 847 map->unlock(map); |
820 821 return ret; 822} 823 824/** 825 * regmap_update_bits: Perform a read/modify/write cycle on the register map 826 * 827 * @map: Register map to update --- 50 unchanged lines hidden (view full) --- 878{ 879 int i, ret; 880 bool bypass; 881 882 /* If needed the implementation can be extended to support this */ 883 if (map->patch) 884 return -EBUSY; 885 | 848 849 return ret; 850} 851 852/** 853 * regmap_update_bits: Perform a read/modify/write cycle on the register map 854 * 855 * @map: Register map to update --- 50 unchanged lines hidden (view full) --- 906{ 907 int i, ret; 908 bool bypass; 909 910 /* If needed the implementation can be extended to support this */ 911 if (map->patch) 912 return -EBUSY; 913 |
886 mutex_lock(&map->lock); | 914 map->lock(map); |
887 888 bypass = map->cache_bypass; 889 890 map->cache_bypass = true; 891 892 /* Write out first; it's useful to apply even if we fail later. */ 893 for (i = 0; i < num_regs; i++) { 894 ret = _regmap_write(map, regs[i].reg, regs[i].def); --- 11 unchanged lines hidden (view full) --- 906 map->patch_regs = num_regs; 907 } else { 908 ret = -ENOMEM; 909 } 910 911out: 912 map->cache_bypass = bypass; 913 | 915 916 bypass = map->cache_bypass; 917 918 map->cache_bypass = true; 919 920 /* Write out first; it's useful to apply even if we fail later. */ 921 for (i = 0; i < num_regs; i++) { 922 ret = _regmap_write(map, regs[i].reg, regs[i].def); --- 11 unchanged lines hidden (view full) --- 934 map->patch_regs = num_regs; 935 } else { 936 ret = -ENOMEM; 937 } 938 939out: 940 map->cache_bypass = bypass; 941 |
914 mutex_unlock(&map->lock); | 942 map->unlock(map); |
915 916 return ret; 917} 918EXPORT_SYMBOL_GPL(regmap_register_patch); 919 920/* 921 * regmap_get_val_bytes(): Report the size of a register value 922 * --- 19 unchanged lines hidden --- | 943 944 return ret; 945} 946EXPORT_SYMBOL_GPL(regmap_register_patch); 947 948/* 949 * regmap_get_val_bytes(): Report the size of a register value 950 * --- 19 unchanged lines hidden --- |