Changeset 652 for GPL/branches/uniaud32-next/lib32/regmap.c
- Timestamp:
- Jan 24, 2021, 8:40:08 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GPL/branches/uniaud32-next/lib32/regmap.c
r638 r652 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 9 * it under the terms of the GNU General Public License version 2 as 10 * published by the Free Software Foundation. 11 */ 12 /* from 4.19.163 */ 1 // SPDX-License-Identifier: GPL-2.0 2 // 3 // Register map access API 4 // 5 // Copyright 2011 Wolfson Microelectronics plc 6 // 7 // Author: Mark Brown <broonie@opensource.wolfsonmicro.com> 8 9 /* from 5.10.10 */ 13 10 14 11 #include <linux/device.h> … … 17 14 #include <linux/mutex.h> 18 15 #include <linux/err.h> 19 #include <linux/of.h>16 //#include <linux/property.h> 20 17 #include <linux/rbtree.h> 21 18 #include <linux/sched.h> … … 47 44 #undef LOG_DEVICE 48 45 49 /*static inline*/ int _regmap_update_bits(struct regmap *map, unsigned int reg, 46 #ifdef LOG_DEVICE 47 static inline bool regmap_should_log(struct regmap *map) 48 { 49 return (map->dev && strcmp(dev_name(map->dev), LOG_DEVICE) == 0); 50 } 51 #else 52 static inline bool regmap_should_log(struct regmap *map) { return false; } 53 #endif 54 55 56 static int _regmap_update_bits(struct regmap *map, unsigned int reg, 50 57 unsigned int mask, unsigned int val, 51 58 bool *change, bool force_write); 52 59 53 /*static inline*/int _regmap_bus_reg_read(void *context, unsigned int reg,60 static int _regmap_bus_reg_read(void *context, unsigned int reg, 54 61 unsigned int *val); 55 /*static inline*/int _regmap_bus_read(void *context, unsigned int reg,62 static int _regmap_bus_read(void *context, unsigned int reg, 56 63 unsigned int *val); 57 /*static inline*/int _regmap_bus_formatted_write(void *context, unsigned int reg,64 static int _regmap_bus_formatted_write(void *context, unsigned int reg, 58 65 unsigned int val); 59 /*static inline*/int _regmap_bus_reg_write(void *context, unsigned int reg,66 static int _regmap_bus_reg_write(void *context, unsigned int reg, 60 67 unsigned int val); 61 /*static inline*/int _regmap_bus_raw_write(void *context, unsigned int reg,68 static int _regmap_bus_raw_write(void *context, unsigned int reg, 62 69 unsigned int val); 63 70 … … 180 187 } 181 188 189 bool regmap_writeable_noinc(struct regmap *map, unsigned int reg) 190 { 191 if (map->writeable_noinc_reg) 192 return map->writeable_noinc_reg(map->dev, reg); 193 194 if (map->wr_noinc_table) 195 return regmap_check_range_table(map, reg, map->wr_noinc_table); 196 197 return true; 198 } 199 182 200 bool regmap_readable_noinc(struct regmap *map, unsigned int reg) 183 201 { … … 191 209 } 192 210 193 /*static inline*/bool regmap_volatile_range(struct regmap *map, unsigned int reg,211 static bool regmap_volatile_range(struct regmap *map, unsigned int reg, 194 212 size_t num) 195 213 { … … 203 221 } 204 222 205 /*static inline*/ void regmap_format_2_6_write(struct regmap *map,223 static void regmap_format_12_20_write(struct regmap *map, 206 224 unsigned int reg, unsigned int val) 207 225 { 208 226 u8 *out = map->work_buf; 209 227 228 out[0] = reg >> 4; 229 out[1] = (reg << 4) | (val >> 16); 230 out[2] = val >> 8; 231 out[3] = val; 232 } 233 234 235 static void regmap_format_2_6_write(struct regmap *map, 236 unsigned int reg, unsigned int val) 237 { 238 u8 *out = map->work_buf; 239 210 240 *out = (reg << 6) | val; 211 241 } 212 242 213 /*static inline*/void regmap_format_4_12_write(struct regmap *map,243 static void regmap_format_4_12_write(struct regmap *map, 214 244 unsigned int reg, unsigned int val) 215 245 { … … 218 248 } 219 249 220 /*static inline*/void regmap_format_7_9_write(struct regmap *map,250 static void regmap_format_7_9_write(struct regmap *map, 221 251 unsigned int reg, unsigned int val) 222 252 { … … 225 255 } 226 256 227 /*static inline*/void regmap_format_10_14_write(struct regmap *map,257 static void regmap_format_10_14_write(struct regmap *map, 228 258 unsigned int reg, unsigned int val) 229 259 { … … 235 265 } 236 266 237 /*static inline*/void regmap_format_8(void *buf, unsigned int val, unsigned int shift)267 static void regmap_format_8(void *buf, unsigned int val, unsigned int shift) 238 268 { 239 269 u8 *b = buf; … … 242 272 } 243 273 244 /*static inline*/void regmap_format_16_be(void *buf, unsigned int val, unsigned int shift)274 static void regmap_format_16_be(void *buf, unsigned int val, unsigned int shift) 245 275 { 246 276 put_unaligned_be16(val << shift, buf); 247 277 } 248 278 249 /*static inline*/void regmap_format_16_le(void *buf, unsigned int val, unsigned int shift)279 static void regmap_format_16_le(void *buf, unsigned int val, unsigned int shift) 250 280 { 251 281 put_unaligned_le16(val << shift, buf); 252 282 } 253 283 254 /*static inline*/void regmap_format_16_native(void *buf, unsigned int val,284 static void regmap_format_16_native(void *buf, unsigned int val, 255 285 unsigned int shift) 256 286 { … … 260 290 } 261 291 262 /*static inline*/void regmap_format_24(void *buf, unsigned int val, unsigned int shift)292 static void regmap_format_24(void *buf, unsigned int val, unsigned int shift) 263 293 { 264 294 u8 *b = buf; … … 271 301 } 272 302 273 /*static inline*/void regmap_format_32_be(void *buf, unsigned int val, unsigned int shift)303 static void regmap_format_32_be(void *buf, unsigned int val, unsigned int shift) 274 304 { 275 305 put_unaligned_be32(val << shift, buf); 276 306 } 277 307 278 /*static inline*/void regmap_format_32_le(void *buf, unsigned int val, unsigned int shift)308 static void regmap_format_32_le(void *buf, unsigned int val, unsigned int shift) 279 309 { 280 310 put_unaligned_le32(val << shift, buf); 281 311 } 282 312 283 /*static inline*/void regmap_format_32_native(void *buf, unsigned int val,313 static void regmap_format_32_native(void *buf, unsigned int val, 284 314 unsigned int shift) 285 315 { … … 290 320 291 321 #ifdef CONFIG_64BIT 292 /*static inline*/void regmap_format_64_be(void *buf, unsigned int val, unsigned int shift)322 static void regmap_format_64_be(void *buf, unsigned int val, unsigned int shift) 293 323 { 294 324 put_unaligned_be64((u64) val << shift, buf); 295 325 } 296 326 297 /*static inline*/void regmap_format_64_le(void *buf, unsigned int val, unsigned int shift)327 static void regmap_format_64_le(void *buf, unsigned int val, unsigned int shift) 298 328 { 299 329 put_unaligned_le64((u64) val << shift, buf); 300 330 } 301 331 302 /*static inline*/void regmap_format_64_native(void *buf, unsigned int val,332 static void regmap_format_64_native(void *buf, unsigned int val, 303 333 unsigned int shift) 304 334 { … … 309 339 #endif 310 340 311 /*static inline*/void regmap_parse_inplace_noop(void *buf)312 { 313 } 314 315 /*static inline*/unsigned int regmap_parse_8(const void *buf)341 static void regmap_parse_inplace_noop(void *buf) 342 { 343 } 344 345 static unsigned int regmap_parse_8(const void *buf) 316 346 { 317 347 const u8 *b = buf; … … 320 350 } 321 351 322 /*static inline*/unsigned int regmap_parse_16_be(const void *buf)352 static unsigned int regmap_parse_16_be(const void *buf) 323 353 { 324 354 return get_unaligned_be16(buf); 325 355 } 326 356 327 /*static inline*/unsigned int regmap_parse_16_le(const void *buf)357 static unsigned int regmap_parse_16_le(const void *buf) 328 358 { 329 359 return get_unaligned_le16(buf); 330 360 } 331 361 332 /*static inline*/void regmap_parse_16_be_inplace(void *buf)362 static void regmap_parse_16_be_inplace(void *buf) 333 363 { 334 364 u16 v = get_unaligned_be16(buf); … … 337 367 } 338 368 339 /*static inline*/void regmap_parse_16_le_inplace(void *buf)369 static void regmap_parse_16_le_inplace(void *buf) 340 370 { 341 371 u16 v = get_unaligned_le16(buf); … … 344 374 } 345 375 346 /*static inline*/unsigned int regmap_parse_16_native(const void *buf)376 static unsigned int regmap_parse_16_native(const void *buf) 347 377 { 348 378 u16 v; … … 352 382 } 353 383 354 /*static inline*/unsigned int regmap_parse_24(const void *buf)384 static unsigned int regmap_parse_24(const void *buf) 355 385 { 356 386 const u8 *b = buf; … … 362 392 } 363 393 364 /*static inline*/unsigned int regmap_parse_32_be(const void *buf)394 static unsigned int regmap_parse_32_be(const void *buf) 365 395 { 366 396 return get_unaligned_be32(buf); 367 397 } 368 398 369 /*static inline*/unsigned int regmap_parse_32_le(const void *buf)399 static unsigned int regmap_parse_32_le(const void *buf) 370 400 { 371 401 return get_unaligned_le32(buf); 372 402 } 373 403 374 /*static inline*/void regmap_parse_32_be_inplace(void *buf)404 static void regmap_parse_32_be_inplace(void *buf) 375 405 { 376 406 u32 v = get_unaligned_be32(buf); … … 379 409 } 380 410 381 /*static inline*/void regmap_parse_32_le_inplace(void *buf)411 static void regmap_parse_32_le_inplace(void *buf) 382 412 { 383 413 u32 v = get_unaligned_le32(buf); … … 386 416 } 387 417 388 /*static inline*/unsigned int regmap_parse_32_native(const void *buf)418 static unsigned int regmap_parse_32_native(const void *buf) 389 419 { 390 420 u32 v; … … 395 425 396 426 #ifdef CONFIG_64BIT 397 /*static inline*/unsigned int regmap_parse_64_be(const void *buf)427 static unsigned int regmap_parse_64_be(const void *buf) 398 428 { 399 429 return get_unaligned_be64(buf); 400 430 } 401 431 402 /*static inline*/unsigned int regmap_parse_64_le(const void *buf)432 static unsigned int regmap_parse_64_le(const void *buf) 403 433 { 404 434 return get_unaligned_le64(buf); 405 435 } 406 436 407 /*static inline*/void regmap_parse_64_be_inplace(void *buf)437 static void regmap_parse_64_be_inplace(void *buf) 408 438 { 409 439 u64 v = get_unaligned_be64(buf); … … 412 442 } 413 443 414 /*static inline*/void regmap_parse_64_le_inplace(void *buf)444 static void regmap_parse_64_le_inplace(void *buf) 415 445 { 416 446 u64 v = get_unaligned_le64(buf); … … 419 449 } 420 450 421 /*static inline*/unsigned int regmap_parse_64_native(const void *buf)451 static unsigned int regmap_parse_64_native(const void *buf) 422 452 { 423 453 u64 v; … … 428 458 #endif 429 459 430 /*static inline*/void regmap_lock_hwlock(void *__map)431 { 432 //NOT_USEDstruct regmap *map = __map;460 static void regmap_lock_hwlock(void *__map) 461 { 462 struct regmap *map = __map; 433 463 434 464 // hwspin_lock_timeout(map->hwlock, UINT_MAX); 435 465 } 436 466 437 /*static inline*/void regmap_lock_hwlock_irq(void *__map)438 { 439 //NOT_USEDstruct regmap *map = __map;467 static void regmap_lock_hwlock_irq(void *__map) 468 { 469 struct regmap *map = __map; 440 470 441 471 // hwspin_lock_timeout_irq(map->hwlock, UINT_MAX); 442 472 } 443 473 444 /*static inline*/void regmap_lock_hwlock_irqsave(void *__map)445 { 446 //NOT_USEDstruct regmap *map = __map;474 static void regmap_lock_hwlock_irqsave(void *__map) 475 { 476 struct regmap *map = __map; 447 477 448 478 // hwspin_lock_timeout_irqsave(map->hwlock, UINT_MAX, … … 450 480 } 451 481 452 /*static inline*/void regmap_unlock_hwlock(void *__map)453 { 454 //NOT_USEDstruct regmap *map = __map;482 static void regmap_unlock_hwlock(void *__map) 483 { 484 struct regmap *map = __map; 455 485 456 486 // hwspin_unlock(map->hwlock); 457 487 } 458 488 459 /*static inline*/void regmap_unlock_hwlock_irq(void *__map)460 { 461 //NOT_USEDstruct regmap *map = __map;489 static void regmap_unlock_hwlock_irq(void *__map) 490 { 491 struct regmap *map = __map; 462 492 463 493 // hwspin_unlock_irq(map->hwlock); 464 494 } 465 495 466 /*static inline*/void regmap_unlock_hwlock_irqrestore(void *__map)467 { 468 //NOT_USEDstruct regmap *map = __map;496 static void regmap_unlock_hwlock_irqrestore(void *__map) 497 { 498 struct regmap *map = __map; 469 499 470 500 // hwspin_unlock_irqrestore(map->hwlock, &map->spinlock_flags); 471 501 } 472 502 473 /*static inline*/void regmap_lock_unlock_none(void *__map)474 { 475 476 } 477 478 /*static inline*/void regmap_lock_mutex(void *__map)503 static void regmap_lock_unlock_none(void *__map) 504 { 505 506 } 507 508 static void regmap_lock_mutex(void *__map) 479 509 { 480 510 struct regmap *map = __map; … … 482 512 } 483 513 484 /*static inline*/void regmap_unlock_mutex(void *__map)514 static void regmap_unlock_mutex(void *__map) 485 515 { 486 516 struct regmap *map = __map; … … 488 518 } 489 519 490 /*static inline*/void regmap_lock_spinlock(void *__map)520 static void regmap_lock_spinlock(void *__map) 491 521 __acquires(&map->spinlock) 492 522 { … … 498 528 } 499 529 500 /*static inline*/void regmap_unlock_spinlock(void *__map)530 static void regmap_unlock_spinlock(void *__map) 501 531 __releases(&map->spinlock) 502 532 { … … 505 535 } 506 536 507 /*static inline*/void dev_get_regmap_release(struct device *dev, void *res)537 static void dev_get_regmap_release(struct device *dev, void *res) 508 538 { 509 539 /* … … 514 544 } 515 545 516 /*static inline*/bool _regmap_range_add(struct regmap *map,546 static bool _regmap_range_add(struct regmap *map, 517 547 struct regmap_range_node *data) 518 548 { … … 539 569 } 540 570 541 /*static inline*/struct regmap_range_node *_regmap_range_lookup(struct regmap *map,571 static struct regmap_range_node *_regmap_range_lookup(struct regmap *map, 542 572 unsigned int reg) 543 573 { … … 559 589 } 560 590 561 /*static inline*/void regmap_range_exit(struct regmap *map)591 static void regmap_range_exit(struct regmap *map) 562 592 { 563 593 struct rb_node *next; … … 575 605 } 576 606 607 static int regmap_set_name(struct regmap *map, const struct regmap_config *config) 608 { 609 if (config->name) { 610 #ifndef TARGET_OS2 611 const char *name = kstrdup_const(config->name, GFP_KERNEL); 612 #else 613 const char *name = config->name; 614 #endif 615 616 if (!name) 617 return -ENOMEM; 618 619 #ifndef TARGET_OS2 620 kfree_const(map->name); 621 #else 622 kfree(map->name); 623 #endif 624 map->name = name; 625 } 626 627 return 0; 628 } 629 577 630 int regmap_attach_dev(struct device *dev, struct regmap *map, 578 631 const struct regmap_config *config) 579 632 { 580 633 struct regmap **m; 634 int ret; 581 635 582 636 map->dev = dev; 583 637 584 regmap_debugfs_init(map, config->name); 638 ret = regmap_set_name(map, config); 639 if (ret) 640 return ret; 641 642 regmap_debugfs_init(map); 585 643 586 644 /* Add a devres resource for dev_get_regmap() */ … … 597 655 EXPORT_SYMBOL_GPL(regmap_attach_dev); 598 656 599 /*static inline*/enum regmap_endian regmap_get_reg_endian(const struct regmap_bus *bus,657 static enum regmap_endian regmap_get_reg_endian(const struct regmap_bus *bus, 600 658 const struct regmap_config *config) 601 659 { … … 625 683 const struct regmap_config *config) 626 684 { 627 struct device_node *np; 685 #ifndef TARGET_OS2 686 struct fwnode_handle *fwnode = dev ? dev_fwnode(dev) : NULL; 687 #else 688 struct fwnode_handle *fwnode = NULL; 689 #endif 628 690 enum regmap_endian endian; 629 691 … … 635 697 return endian; 636 698 637 /* If the dev and dev->of_node exist try to get endianness from DT */ 638 if (dev && dev->of_node) { 639 np = dev->of_node; 640 641 /* Parse the device's DT node for an endianness specification */ 642 if (of_property_read_bool(np, "big-endian")) 643 endian = REGMAP_ENDIAN_BIG; 644 else if (of_property_read_bool(np, "little-endian")) 645 endian = REGMAP_ENDIAN_LITTLE; 646 else if (of_property_read_bool(np, "native-endian")) 647 endian = REGMAP_ENDIAN_NATIVE; 648 649 /* If the endianness was specified in DT, use that */ 650 if (endian != REGMAP_ENDIAN_DEFAULT) 651 return endian; 652 } 699 #ifndef TARGET_OS2 700 /* If the firmware node exist try to get endianness from it */ 701 if (fwnode_property_read_bool(fwnode, "big-endian")) 702 endian = REGMAP_ENDIAN_BIG; 703 else if (fwnode_property_read_bool(fwnode, "little-endian")) 704 endian = REGMAP_ENDIAN_LITTLE; 705 else if (fwnode_property_read_bool(fwnode, "native-endian")) 706 endian = REGMAP_ENDIAN_NATIVE; 707 #endif 708 /* If the endianness was specified in fwnode, use that */ 709 if (endian != REGMAP_ENDIAN_DEFAULT) 710 return endian; 653 711 654 712 /* Retrieve the endianness specification from the bus config */ … … 690 748 } 691 749 692 if (config->name) { 693 #ifndef TARGET_OS2 694 map->name = kstrdup_const(config->name, GFP_KERNEL); 695 #else 696 map->name = config->name; 697 #endif 698 if (!map->name) { 699 ret = -ENOMEM; 700 goto err_map; 701 } 702 } 750 ret = regmap_set_name(map, config); 751 if (ret) 752 goto err_map; 753 754 ret = -EINVAL; /* Later error paths rely on this */ 703 755 704 756 if (config->disable_locking) { 705 757 map->lock = map->unlock = regmap_lock_unlock_none; 758 map->can_sleep = config->can_sleep; 706 759 regmap_debugfs_disable(map); 707 760 } else if (config->lock && config->unlock) { … … 709 762 map->unlock = config->unlock; 710 763 map->lock_arg = config->lock_arg; 764 map->can_sleep = config->can_sleep; 711 765 } else if (config->use_hwlock) { 712 // map->hwlock = hwspin_lock_request_specific(config->hwlock_id); 713 // if (!map->hwlock) { 714 // ret = -ENXIO; 715 // goto err_name; 716 // } 717 766 #ifndef TARGET_OS2 767 map->hwlock = hwspin_lock_request_specific(config->hwlock_id); 768 if (!map->hwlock) { 769 ret = -ENXIO; 770 goto err_name; 771 } 772 #endif 718 773 switch (config->hwlock_mode) { 719 774 case HWLOCK_IRQSTATE: … … 744 799 map->lock = regmap_lock_mutex; 745 800 map->unlock = regmap_unlock_mutex; 801 map->can_sleep = true; 746 802 lockdep_set_class_and_name(&map->mutex, 747 803 lock_key, lock_name); … … 774 830 map->reg_stride_order = -1; 775 831 map->use_single_read = config->use_single_read || !bus || !bus->read; 776 map->use_single_write = config->use_single_ read|| !bus || !bus->write;832 map->use_single_write = config->use_single_write || !bus || !bus->write; 777 833 map->can_multi_write = config->can_multi_write && bus && bus->write; 778 834 if (bus) { … … 788 844 map->volatile_table = config->volatile_table; 789 845 map->precious_table = config->precious_table; 846 map->wr_noinc_table = config->wr_noinc_table; 790 847 map->rd_noinc_table = config->rd_noinc_table; 791 848 map->writeable_reg = config->writeable_reg; … … 793 850 map->volatile_reg = config->volatile_reg; 794 851 map->precious_reg = config->precious_reg; 852 map->writeable_noinc_reg = config->writeable_noinc_reg; 795 853 map->readable_noinc_reg = config->readable_noinc_reg; 796 854 map->cache_type = config->cache_type; … … 819 877 map->reg_read = _regmap_bus_reg_read; 820 878 map->reg_write = _regmap_bus_reg_write; 879 map->reg_update_bits = bus->reg_update_bits; 821 880 822 881 map->defer_caching = false; … … 865 924 case 14: 866 925 map->format.format_write = regmap_format_10_14_write; 926 break; 927 default: 928 goto err_hwlock; 929 } 930 break; 931 932 case 12: 933 switch (config->val_bits) { 934 case 20: 935 map->format.format_write = regmap_format_12_20_write; 867 936 break; 868 937 default: … … 1048 1117 memset(&map->range_tree, 0, sizeof(struct rb_root)); 1049 1118 #endif 1050 1051 1119 for (i = 0; i < config->num_ranges; i++) { 1052 1120 const struct regmap_range_cfg *range_cfg = &config->ranges[i]; … … 1148 1216 goto err_regcache; 1149 1217 } else { 1150 regmap_debugfs_init(map , config->name);1218 regmap_debugfs_init(map); 1151 1219 } 1152 1220 … … 1159 1227 kfree(map->work_buf); 1160 1228 err_hwlock: 1161 // if (map->hwlock) 1162 // hwspin_lock_free(map->hwlock); 1163 //err_name: 1164 // kfree_const(map->name); 1229 #ifndef TARGET_OS2 1230 if (map->hwlock) 1231 hwspin_lock_free(map->hwlock); 1232 #endif 1233 err_name: 1234 #ifndef TARGET_OS2 1235 kfree_const(map->name); 1236 #else 1237 kfree(map->name); 1238 #endif 1165 1239 err_map: 1166 1240 kfree(map); … … 1171 1245 1172 1246 #ifndef TARGET_OS2 1173 /*static inline*/void devm_regmap_release(struct device *dev, void *res)1247 static void devm_regmap_release(struct device *dev, void *res) 1174 1248 { 1175 1249 regmap_exit(*(struct regmap **)res); … … 1203 1277 #endif 1204 1278 1205 /*static inline*/void regmap_field_init(struct regmap_field *rm_field,1279 static void regmap_field_init(struct regmap_field *rm_field, 1206 1280 struct regmap *regmap, struct reg_field reg_field) 1207 1281 { … … 1240 1314 } 1241 1315 EXPORT_SYMBOL_GPL(devm_regmap_field_alloc); 1316 #endif 1317 1318 /** 1319 * regmap_field_bulk_alloc() - Allocate and initialise a bulk register field. 1320 * 1321 * @regmap: regmap bank in which this register field is located. 1322 * @rm_field: regmap register fields within the bank. 1323 * @reg_field: Register fields within the bank. 1324 * @num_fields: Number of register fields. 1325 * 1326 * The return value will be an -ENOMEM on error or zero for success. 1327 * Newly allocated regmap_fields should be freed by calling 1328 * regmap_field_bulk_free() 1329 */ 1330 int regmap_field_bulk_alloc(struct regmap *regmap, 1331 struct regmap_field **rm_field, 1332 struct reg_field *reg_field, 1333 int num_fields) 1334 { 1335 struct regmap_field *rf; 1336 int i; 1337 1338 rf = kcalloc(num_fields, sizeof(*rf), GFP_KERNEL); 1339 if (!rf) 1340 return -ENOMEM; 1341 1342 for (i = 0; i < num_fields; i++) { 1343 regmap_field_init(&rf[i], regmap, reg_field[i]); 1344 rm_field[i] = &rf[i]; 1345 } 1346 1347 return 0; 1348 } 1349 EXPORT_SYMBOL_GPL(regmap_field_bulk_alloc); 1350 1351 #ifndef TARGET_OS2 1352 /** 1353 * devm_regmap_field_bulk_alloc() - Allocate and initialise a bulk register 1354 * fields. 1355 * 1356 * @dev: Device that will be interacted with 1357 * @regmap: regmap bank in which this register field is located. 1358 * @rm_field: regmap register fields within the bank. 1359 * @reg_field: Register fields within the bank. 1360 * @num_fields: Number of register fields. 1361 * 1362 * The return value will be an -ENOMEM on error or zero for success. 1363 * Newly allocated regmap_fields will be automatically freed by the 1364 * device management code. 1365 */ 1366 int devm_regmap_field_bulk_alloc(struct device *dev, 1367 struct regmap *regmap, 1368 struct regmap_field **rm_field, 1369 struct reg_field *reg_field, 1370 int num_fields) 1371 { 1372 struct regmap_field *rf; 1373 int i; 1374 1375 rf = devm_kcalloc(dev, num_fields, sizeof(*rf), GFP_KERNEL); 1376 if (!rf) 1377 return -ENOMEM; 1378 1379 for (i = 0; i < num_fields; i++) { 1380 regmap_field_init(&rf[i], regmap, reg_field[i]); 1381 rm_field[i] = &rf[i]; 1382 } 1383 1384 return 0; 1385 } 1386 EXPORT_SYMBOL_GPL(devm_regmap_field_bulk_alloc); 1387 #endif 1388 1389 /** 1390 * regmap_field_bulk_free() - Free register field allocated using 1391 * regmap_field_bulk_alloc. 1392 * 1393 * @field: regmap fields which should be freed. 1394 */ 1395 void regmap_field_bulk_free(struct regmap_field *field) 1396 { 1397 kfree(field); 1398 } 1399 EXPORT_SYMBOL_GPL(regmap_field_bulk_free); 1400 1401 #ifndef TARGET_OS2 1402 /** 1403 * devm_regmap_field_bulk_free() - Free a bulk register field allocated using 1404 * devm_regmap_field_bulk_alloc. 1405 * 1406 * @dev: Device that will be interacted with 1407 * @field: regmap field which should be freed. 1408 * 1409 * Free register field allocated using devm_regmap_field_bulk_alloc(). Usually 1410 * drivers need not call this function, as the memory allocated via devm 1411 * will be freed as per device-driver life-cycle. 1412 */ 1413 void devm_regmap_field_bulk_free(struct device *dev, 1414 struct regmap_field *field) 1415 { 1416 devm_kfree(dev, field); 1417 } 1418 EXPORT_SYMBOL_GPL(devm_regmap_field_bulk_free); 1242 1419 1243 1420 /** … … 1312 1489 int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config) 1313 1490 { 1491 int ret; 1492 1314 1493 regcache_exit(map); 1315 1494 regmap_debugfs_exit(map); … … 1320 1499 map->volatile_reg = config->volatile_reg; 1321 1500 map->precious_reg = config->precious_reg; 1501 map->writeable_noinc_reg = config->writeable_noinc_reg; 1322 1502 map->readable_noinc_reg = config->readable_noinc_reg; 1323 1503 map->cache_type = config->cache_type; 1324 1504 1325 regmap_debugfs_init(map, config->name); 1505 ret = regmap_set_name(map, config); 1506 if (ret) 1507 return ret; 1508 1509 regmap_debugfs_init(map); 1326 1510 1327 1511 map->cache_bypass = false; … … 1355 1539 kfree(async); 1356 1540 } 1357 // if (map->hwlock) 1358 // hwspin_lock_free(map->hwlock); 1359 // kfree_const(map->name); 1541 #ifndef TARGET_OS2 1542 if (map->hwlock) 1543 hwspin_lock_free(map->hwlock); 1544 #endif 1545 if (map->lock == regmap_lock_mutex) 1546 mutex_destroy(&map->mutex); 1547 #ifndef TARGET_OS2 1548 kfree_const(map->name); 1549 #else 1550 kfree(map->name); 1551 #endif 1360 1552 kfree(map->patch); 1361 1553 kfree(map); … … 1363 1555 EXPORT_SYMBOL_GPL(regmap_exit); 1364 1556 1365 /*static inline*/int dev_get_regmap_match(struct device *dev, void *res, void *data)1557 static int dev_get_regmap_match(struct device *dev, void *res, void *data) 1366 1558 { 1367 1559 struct regmap **r = res; … … 1414 1606 EXPORT_SYMBOL_GPL(regmap_get_device); 1415 1607 1416 /*static inline*/int _regmap_select_page(struct regmap *map, unsigned int *reg,1608 static int _regmap_select_page(struct regmap *map, unsigned int *reg, 1417 1609 struct regmap_range_node *range, 1418 1610 unsigned int val_num) … … 1462 1654 } 1463 1655 1464 /*static inline*/void regmap_set_work_buf_flag_mask(struct regmap *map, int max_bytes,1656 static void regmap_set_work_buf_flag_mask(struct regmap *map, int max_bytes, 1465 1657 unsigned long mask) 1466 1658 { … … 1477 1669 } 1478 1670 1479 /*static inline*/int _regmap_raw_write_impl(struct regmap *map, unsigned int reg,1480 const void *val, size_t val_len )1671 static int _regmap_raw_write_impl(struct regmap *map, unsigned int reg, 1672 const void *val, size_t val_len, bool noinc) 1481 1673 { 1482 1674 struct regmap_range_node *range; … … 1491 1683 WARN_ON(!map->bus); 1492 1684 1493 /* Check for unwritable registers before we start */ 1494 if (map->writeable_reg) 1495 for (i = 0; i < val_len / map->format.val_bytes; i++) 1496 if (!map->writeable_reg(map->dev, 1497 reg + regmap_get_offset(map, i))) 1685 /* Check for unwritable or noinc registers in range 1686 * before we start 1687 */ 1688 if (!regmap_writeable_noinc(map, reg)) { 1689 for (i = 0; i < val_len / map->format.val_bytes; i++) { 1690 unsigned int element = 1691 reg + regmap_get_offset(map, i); 1692 if (!regmap_writeable(map, element) || 1693 regmap_writeable_noinc(map, element)) 1498 1694 return -EINVAL; 1695 } 1696 } 1499 1697 1500 1698 if (!map->cache_bypass && map->format.parse_val) { … … 1531 1729 ret = _regmap_raw_write_impl(map, reg, val, 1532 1730 win_residue * 1533 map->format.val_bytes );1731 map->format.val_bytes, noinc); 1534 1732 if (ret != 0) 1535 1733 return ret; … … 1545 1743 } 1546 1744 1547 ret = _regmap_select_page(map, ®, range, val_num);1745 ret = _regmap_select_page(map, ®, range, noinc ? 1 : val_num); 1548 1746 if (ret != 0) 1549 1747 return ret; … … 1698 1896 EXPORT_SYMBOL_GPL(regmap_get_raw_write_max); 1699 1897 1700 /*static inline*/int _regmap_bus_formatted_write(void *context, unsigned int reg,1898 static int _regmap_bus_formatted_write(void *context, unsigned int reg, 1701 1899 unsigned int val) 1702 1900 { … … 1722 1920 } 1723 1921 1724 /*static inline*/int _regmap_bus_reg_write(void *context, unsigned int reg,1922 static int _regmap_bus_reg_write(void *context, unsigned int reg, 1725 1923 unsigned int val) 1726 1924 { … … 1730 1928 } 1731 1929 1732 /*static inline*/int _regmap_bus_raw_write(void *context, unsigned int reg,1930 static int _regmap_bus_raw_write(void *context, unsigned int reg, 1733 1931 unsigned int val) 1734 1932 { … … 1743 1941 map->format.reg_bytes + 1744 1942 map->format.pad_bytes, 1745 map->format.val_bytes); 1746 } 1747 1748 /*static inline*/ inline void *_regmap_map_get_context(struct regmap *map) 1943 map->format.val_bytes, 1944 false); 1945 } 1946 1947 static inline void *_regmap_map_get_context(struct regmap *map) 1749 1948 { 1750 1949 return (map->bus) ? map : map->bus_context; … … 1770 1969 } 1771 1970 1772 #ifdef LOG_DEVICE 1773 if (map->dev && strcmp(dev_name(map->dev), LOG_DEVICE) == 0) 1971 if (regmap_should_log(map)) 1774 1972 dev_info(map->dev, "%x <= %x\n", reg, val); 1973 1974 return map->reg_write(context, reg, val); 1975 } 1976 1977 #ifdef TARGET_OS2 1978 #define IS_ALIGNED(x, a) (((x) & ((unsigned int)(a) - 1)) == 0) 1775 1979 #endif 1776 1777 return map->reg_write(context, reg, val);1778 }1779 1780 #define IS_ALIGNED(x, a) (((x) & ((unsigned int)(a) - 1)) == 0)1781 1980 1782 1981 /** … … 1839 2038 1840 2039 int _regmap_raw_write(struct regmap *map, unsigned int reg, 1841 const void *val, size_t val_len )2040 const void *val, size_t val_len, bool noinc) 1842 2041 { 1843 2042 size_t val_bytes = map->format.val_bytes; … … 1860 2059 /* Write as many bytes as possible with chunk_size */ 1861 2060 for (i = 0; i < chunk_count; i++) { 1862 ret = _regmap_raw_write_impl(map, reg, val, chunk_bytes );2061 ret = _regmap_raw_write_impl(map, reg, val, chunk_bytes, noinc); 1863 2062 if (ret) 1864 2063 return ret; … … 1871 2070 /* Write remaining bytes */ 1872 2071 if (val_len) 1873 ret = _regmap_raw_write_impl(map, reg, val, val_len );2072 ret = _regmap_raw_write_impl(map, reg, val, val_len, noinc); 1874 2073 1875 2074 return ret; … … 1904 2103 map->lock(map->lock_arg); 1905 2104 1906 ret = _regmap_raw_write(map, reg, val, val_len );2105 ret = _regmap_raw_write(map, reg, val, val_len, false); 1907 2106 1908 2107 map->unlock(map->lock_arg); … … 1911 2110 } 1912 2111 EXPORT_SYMBOL_GPL(regmap_raw_write); 2112 2113 /** 2114 * regmap_noinc_write(): Write data from a register without incrementing the 2115 * register number 2116 * 2117 * @map: Register map to write to 2118 * @reg: Register to write to 2119 * @val: Pointer to data buffer 2120 * @val_len: Length of output buffer in bytes. 2121 * 2122 * The regmap API usually assumes that bulk bus write operations will write a 2123 * range of registers. Some devices have certain registers for which a write 2124 * operation can write to an internal FIFO. 2125 * 2126 * The target register must be volatile but registers after it can be 2127 * completely unrelated cacheable registers. 2128 * 2129 * This will attempt multiple writes as required to write val_len bytes. 2130 * 2131 * A value of zero will be returned on success, a negative errno will be 2132 * returned in error cases. 2133 */ 2134 int regmap_noinc_write(struct regmap *map, unsigned int reg, 2135 const void *val, size_t val_len) 2136 { 2137 size_t write_len; 2138 int ret; 2139 2140 if (!map->bus) 2141 return -EINVAL; 2142 if (!map->bus->write) 2143 return -ENOTSUPP; 2144 if (val_len % map->format.val_bytes) 2145 return -EINVAL; 2146 if (!IS_ALIGNED(reg, map->reg_stride)) 2147 return -EINVAL; 2148 if (val_len == 0) 2149 return -EINVAL; 2150 2151 map->lock(map->lock_arg); 2152 2153 if (!regmap_volatile(map, reg) || !regmap_writeable_noinc(map, reg)) { 2154 ret = -EINVAL; 2155 goto out_unlock; 2156 } 2157 2158 while (val_len) { 2159 if (map->max_raw_write && map->max_raw_write < val_len) 2160 write_len = map->max_raw_write; 2161 else 2162 write_len = val_len; 2163 ret = _regmap_raw_write(map, reg, val, write_len, true); 2164 if (ret) 2165 goto out_unlock; 2166 val = ((u8 *)val) + write_len; 2167 val_len -= write_len; 2168 } 2169 2170 out_unlock: 2171 map->unlock(map->lock_arg); 2172 return ret; 2173 } 2174 EXPORT_SYMBOL_GPL(regmap_noinc_write); 1913 2175 1914 2176 /** … … 1956 2218 * be returned in error cases. 1957 2219 */ 1958 int regmap_fields_update_bits_base(struct regmap_field *field, 2220 int regmap_fields_update_bits_base(struct regmap_field *field, unsigned int id, 1959 2221 unsigned int mask, unsigned int val, 1960 2222 bool *change, bool async, bool force) … … 2057 2319 * relative. The page register has been written if that was necessary. 2058 2320 */ 2059 /*static inline*/int _regmap_raw_multi_reg_write(struct regmap *map,2321 static int _regmap_raw_multi_reg_write(struct regmap *map, 2060 2322 const struct reg_sequence *regs, 2061 2323 size_t num_regs) … … 2098 2360 2099 2361 for (i = 0; i < num_regs; i++) { 2100 int reg; 2101 reg = regs[i].reg; 2362 int reg = regs[i].reg; 2102 2363 } 2103 2364 return ret; 2104 2365 } 2105 2366 2106 /*static inline*/unsigned int _regmap_register_page(struct regmap *map,2367 static unsigned int _regmap_register_page(struct regmap *map, 2107 2368 unsigned int reg, 2108 2369 struct regmap_range_node *range) … … 2113 2374 } 2114 2375 2115 /*static inline*/int _regmap_range_multi_paged_reg_write(struct regmap *map,2376 static int _regmap_range_multi_paged_reg_write(struct regmap *map, 2116 2377 struct reg_sequence *regs, 2117 2378 size_t num_regs) … … 2166 2427 return ret; 2167 2428 2168 if (regs[i].delay_us) 2169 udelay(regs[i].delay_us); 2429 if (regs[i].delay_us) { 2430 #ifndef TARGET_OS2 2431 if (map->can_sleep) 2432 fsleep(regs[i].delay_us); 2433 else 2434 #endif 2435 udelay(regs[i].delay_us); 2436 } 2170 2437 2171 2438 base += n; … … 2190 2457 } 2191 2458 2192 /*static inline*/int _regmap_multi_reg_write(struct regmap *map,2459 static int _regmap_multi_reg_write(struct regmap *map, 2193 2460 const struct reg_sequence *regs, 2194 2461 size_t num_regs) … … 2203 2470 return ret; 2204 2471 2205 if (regs[i].delay_us) 2206 udelay(regs[i].delay_us); 2472 if (regs[i].delay_us) { 2473 #ifndef TARGET_OS2 2474 if (map->can_sleep) 2475 fsleep(regs[i].delay_us); 2476 else 2477 #endif 2478 udelay(regs[i].delay_us); 2479 } 2207 2480 } 2208 2481 return 0; … … 2375 2648 map->async = true; 2376 2649 2377 ret = _regmap_raw_write(map, reg, val, val_len );2650 ret = _regmap_raw_write(map, reg, val, val_len, false); 2378 2651 2379 2652 map->async = false; … … 2385 2658 EXPORT_SYMBOL_GPL(regmap_raw_write_async); 2386 2659 2387 /*static inline*/int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val,2660 static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val, 2388 2661 unsigned int val_len, bool noinc) 2389 2662 { … … 2415 2688 } 2416 2689 2417 /*static inline*/int _regmap_bus_reg_read(void *context, unsigned int reg,2690 static int _regmap_bus_reg_read(void *context, unsigned int reg, 2418 2691 unsigned int *val) 2419 2692 { … … 2423 2696 } 2424 2697 2425 /*static inline*/int _regmap_bus_read(void *context, unsigned int reg,2698 static int _regmap_bus_read(void *context, unsigned int reg, 2426 2699 unsigned int *val) 2427 2700 { … … 2441 2714 } 2442 2715 2443 /*static inline*/int _regmap_read(struct regmap *map, unsigned int reg,2716 static int _regmap_read(struct regmap *map, unsigned int reg, 2444 2717 unsigned int *val) 2445 2718 { … … 2461 2734 ret = map->reg_read(context, reg, val); 2462 2735 if (ret == 0) { 2463 #ifdef LOG_DEVICE 2464 if (map->dev && strcmp(dev_name(map->dev), LOG_DEVICE) == 0) 2736 if (regmap_should_log(map)) 2465 2737 dev_info(map->dev, "%x => %x\n", reg, *val); 2466 #endif2467 2738 2468 2739 if (!map->cache_bypass) … … 2784 3055 EXPORT_SYMBOL_GPL(regmap_bulk_read); 2785 3056 2786 /*static inline*/int _regmap_update_bits(struct regmap *map, unsigned int reg,3057 static int _regmap_update_bits(struct regmap *map, unsigned int reg, 2787 3058 unsigned int mask, unsigned int val, 2788 3059 bool *change, bool force_write) … … 2858 3129 EXPORT_SYMBOL_GPL(regmap_update_bits_base); 2859 3130 3131 /** 3132 * regmap_test_bits() - Check if all specified bits are set in a register. 3133 * 3134 * @map: Register map to operate on 3135 * @reg: Register to read from 3136 * @bits: Bits to test 3137 * 3138 * Returns 0 if at least one of the tested bits is not set, 1 if all tested 3139 * bits are set and a negative error number if the underlying regmap_read() 3140 * fails. 3141 */ 3142 int regmap_test_bits(struct regmap *map, unsigned int reg, unsigned int bits) 3143 { 3144 unsigned int val, ret; 3145 3146 ret = regmap_read(map, reg, &val); 3147 if (ret) 3148 return ret; 3149 3150 return (val & bits) == bits; 3151 } 3152 EXPORT_SYMBOL_GPL(regmap_test_bits); 3153 2860 3154 void regmap_async_complete_cb(struct regmap_async *async, int ret) 2861 3155 { … … 2877 3171 EXPORT_SYMBOL_GPL(regmap_async_complete_cb); 2878 3172 2879 /*static inline*/int regmap_async_is_done(struct regmap *map)3173 static int regmap_async_is_done(struct regmap *map) 2880 3174 { 2881 3175 unsigned long flags; … … 2906 3200 return 0; 2907 3201 2908 // wait_event(map->async_waitq, regmap_async_is_done(map)); 2909 3202 #ifndef TARGET_OS2 3203 wait_event(map->async_waitq, regmap_async_is_done(map)); 3204 #endif 2910 3205 spin_lock_irqsave(&map->async_lock, flags); 2911 3206 ret = map->async_ret; … … 2941 3236 bool bypass; 2942 3237 2943 #if 03238 #ifndef TARGET_OS2 2944 3239 if (WARN_ONCE(num_regs <= 0, "invalid registers number (%d)\n", 2945 3240 num_regs)) 2946 3241 return 0; 3242 #else 3243 if (num_regs <= 0) { 3244 pr_warn("invalid registers number (%d)", num_regs); 3245 return 0; 3246 } 2947 3247 #endif 2948 3248 p = krealloc(map->patch, … … 3034 3334 EXPORT_SYMBOL_GPL(regmap_parse_val); 3035 3335 3036 /*static inline*/int __init regmap_initcall(void)3336 static int __init regmap_initcall(void) 3037 3337 { 3038 3338 regmap_debugfs_initcall();
Note:
See TracChangeset
for help on using the changeset viewer.