Changeset 625 for GPL/branches/uniaud32-next/lib32/regmap.c
- Timestamp:
- Jan 3, 2021, 7:20:20 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GPL/branches/uniaud32-next/lib32/regmap.c
r621 r625 10 10 * published by the Free Software Foundation. 11 11 */ 12 /* from 4.1 4.202*/12 /* from 4.19.163 */ 13 13 14 14 #include <linux/device.h> … … 22 22 #include <linux/delay.h> 23 23 #include <linux/log2.h> 24 //#include <linux/hwspinlock.h> 25 #include <asm/unaligned.h> 24 26 #include <linux/module.h> 25 27 #include <linux/workqueue.h> 26 28 #include <linux/byteorder/little_endian.h> 27 29 #include <linux/printk.h> 30 31 /* hwspinlock mode argument */ 32 #define HWLOCK_IRQSTATE 0x01 /* Disable interrupts, save state */ 33 #define HWLOCK_IRQ 0x02 /* Disable interrupts, don't save state */ 34 #define HWLOCK_RAW 0x03 28 35 29 36 #define CREATE_TRACE_POINTS … … 40 47 #undef LOG_DEVICE 41 48 42 staticint _regmap_update_bits(struct regmap *map, unsigned int reg,49 /*static inline*/ int _regmap_update_bits(struct regmap *map, unsigned int reg, 43 50 unsigned int mask, unsigned int val, 44 51 bool *change, bool force_write); 45 52 46 staticint _regmap_bus_reg_read(void *context, unsigned int reg,53 /*static inline*/ int _regmap_bus_reg_read(void *context, unsigned int reg, 47 54 unsigned int *val); 48 staticint _regmap_bus_read(void *context, unsigned int reg,55 /*static inline*/ int _regmap_bus_read(void *context, unsigned int reg, 49 56 unsigned int *val); 50 staticint _regmap_bus_formatted_write(void *context, unsigned int reg,57 /*static inline*/ int _regmap_bus_formatted_write(void *context, unsigned int reg, 51 58 unsigned int val); 52 staticint _regmap_bus_reg_write(void *context, unsigned int reg,59 /*static inline*/ int _regmap_bus_reg_write(void *context, unsigned int reg, 53 60 unsigned int val); 54 staticint _regmap_bus_raw_write(void *context, unsigned int reg,61 /*static inline*/ int _regmap_bus_raw_write(void *context, unsigned int reg, 55 62 unsigned int val); 56 63 … … 173 180 } 174 181 175 static bool regmap_volatile_range(struct regmap *map, unsigned int reg, 182 bool regmap_readable_noinc(struct regmap *map, unsigned int reg) 183 { 184 if (map->readable_noinc_reg) 185 return map->readable_noinc_reg(map->dev, reg); 186 187 if (map->rd_noinc_table) 188 return regmap_check_range_table(map, reg, map->rd_noinc_table); 189 190 return true; 191 } 192 193 /*static inline*/ bool regmap_volatile_range(struct regmap *map, unsigned int reg, 176 194 size_t num) 177 195 { … … 179 197 180 198 for (i = 0; i < num; i++) 181 if (!regmap_volatile(map, reg + i))199 if (!regmap_volatile(map, reg + regmap_get_offset(map, i))) 182 200 return false; 183 201 … … 185 203 } 186 204 187 staticvoid regmap_format_2_6_write(struct regmap *map,205 /*static inline*/ void regmap_format_2_6_write(struct regmap *map, 188 206 unsigned int reg, unsigned int val) 189 207 { … … 193 211 } 194 212 195 staticvoid regmap_format_4_12_write(struct regmap *map,213 /*static inline*/ void regmap_format_4_12_write(struct regmap *map, 196 214 unsigned int reg, unsigned int val) 197 215 { … … 200 218 } 201 219 202 staticvoid regmap_format_7_9_write(struct regmap *map,220 /*static inline*/ void regmap_format_7_9_write(struct regmap *map, 203 221 unsigned int reg, unsigned int val) 204 222 { … … 207 225 } 208 226 209 staticvoid regmap_format_10_14_write(struct regmap *map,227 /*static inline*/ void regmap_format_10_14_write(struct regmap *map, 210 228 unsigned int reg, unsigned int val) 211 229 { … … 217 235 } 218 236 219 staticvoid regmap_format_8(void *buf, unsigned int val, unsigned int shift)237 /*static inline*/ void regmap_format_8(void *buf, unsigned int val, unsigned int shift) 220 238 { 221 239 u8 *b = buf; … … 224 242 } 225 243 226 static void regmap_format_16_be(void *buf, unsigned int val, unsigned int shift) 227 { 228 __be16 *b = buf; 229 230 b[0] = cpu_to_be16(val << shift); 231 } 232 233 static void regmap_format_16_le(void *buf, unsigned int val, unsigned int shift) 234 { 235 __le16 *b = buf; 236 237 b[0] = cpu_to_le16(val << shift); 238 } 239 240 static void regmap_format_16_native(void *buf, unsigned int val, 244 /*static inline*/ void regmap_format_16_be(void *buf, unsigned int val, unsigned int shift) 245 { 246 put_unaligned_be16(val << shift, buf); 247 } 248 249 /*static inline*/ void regmap_format_16_le(void *buf, unsigned int val, unsigned int shift) 250 { 251 put_unaligned_le16(val << shift, buf); 252 } 253 254 /*static inline*/ void regmap_format_16_native(void *buf, unsigned int val, 241 255 unsigned int shift) 242 256 { 243 *(u16 *)buf = val << shift; 244 } 245 246 static void regmap_format_24(void *buf, unsigned int val, unsigned int shift) 257 u16 v = val << shift; 258 259 memcpy(buf, &v, sizeof(v)); 260 } 261 262 /*static inline*/ void regmap_format_24(void *buf, unsigned int val, unsigned int shift) 247 263 { 248 264 u8 *b = buf; … … 255 271 } 256 272 257 static void regmap_format_32_be(void *buf, unsigned int val, unsigned int shift) 258 { 259 __be32 *b = buf; 260 261 b[0] = cpu_to_be32(val << shift); 262 } 263 264 static void regmap_format_32_le(void *buf, unsigned int val, unsigned int shift) 265 { 266 __le32 *b = buf; 267 268 b[0] = cpu_to_le32(val << shift); 269 } 270 271 static void regmap_format_32_native(void *buf, unsigned int val, 273 /*static inline*/ void regmap_format_32_be(void *buf, unsigned int val, unsigned int shift) 274 { 275 put_unaligned_be32(val << shift, buf); 276 } 277 278 /*static inline*/ void regmap_format_32_le(void *buf, unsigned int val, unsigned int shift) 279 { 280 put_unaligned_le32(val << shift, buf); 281 } 282 283 /*static inline*/ void regmap_format_32_native(void *buf, unsigned int val, 272 284 unsigned int shift) 273 285 { 274 *(u32 *)buf = val << shift; 286 u32 v = val << shift; 287 288 memcpy(buf, &v, sizeof(v)); 275 289 } 276 290 277 291 #ifdef CONFIG_64BIT 278 static void regmap_format_64_be(void *buf, unsigned int val, unsigned int shift) 279 { 280 __be64 *b = buf; 281 282 b[0] = cpu_to_be64((u64)val << shift); 283 } 284 285 static void regmap_format_64_le(void *buf, unsigned int val, unsigned int shift) 286 { 287 __le64 *b = buf; 288 289 b[0] = cpu_to_le64((u64)val << shift); 290 } 291 292 static void regmap_format_64_native(void *buf, unsigned int val, 292 /*static inline*/ void regmap_format_64_be(void *buf, unsigned int val, unsigned int shift) 293 { 294 put_unaligned_be64((u64) val << shift, buf); 295 } 296 297 /*static inline*/ void regmap_format_64_le(void *buf, unsigned int val, unsigned int shift) 298 { 299 put_unaligned_le64((u64) val << shift, buf); 300 } 301 302 /*static inline*/ void regmap_format_64_native(void *buf, unsigned int val, 293 303 unsigned int shift) 294 304 { 295 *(u64 *)buf = (u64)val << shift; 305 u64 v = (u64) val << shift; 306 307 memcpy(buf, &v, sizeof(v)); 296 308 } 297 309 #endif 298 310 299 staticvoid regmap_parse_inplace_noop(void *buf)300 { 301 } 302 303 staticunsigned int regmap_parse_8(const void *buf)311 /*static inline*/ void regmap_parse_inplace_noop(void *buf) 312 { 313 } 314 315 /*static inline*/ unsigned int regmap_parse_8(const void *buf) 304 316 { 305 317 const u8 *b = buf; … … 308 320 } 309 321 310 static unsigned int regmap_parse_16_be(const void *buf) 311 { 312 const __be16 *b = buf; 313 314 return be16_to_cpu(b[0]); 315 } 316 317 static unsigned int regmap_parse_16_le(const void *buf) 318 { 319 const __le16 *b = buf; 320 321 return le16_to_cpu(b[0]); 322 } 323 324 static void regmap_parse_16_be_inplace(void *buf) 325 { 326 __be16 *b = buf; 327 328 b[0] = be16_to_cpu(b[0]); 329 } 330 331 static void regmap_parse_16_le_inplace(void *buf) 332 { 333 __le16 *b = buf; 334 335 b[0] = le16_to_cpu(b[0]); 336 } 337 338 static unsigned int regmap_parse_16_native(const void *buf) 339 { 340 return *(u16 *)buf; 341 } 342 343 static unsigned int regmap_parse_24(const void *buf) 322 /*static inline*/ unsigned int regmap_parse_16_be(const void *buf) 323 { 324 return get_unaligned_be16(buf); 325 } 326 327 /*static inline*/ unsigned int regmap_parse_16_le(const void *buf) 328 { 329 return get_unaligned_le16(buf); 330 } 331 332 /*static inline*/ void regmap_parse_16_be_inplace(void *buf) 333 { 334 u16 v = get_unaligned_be16(buf); 335 336 memcpy(buf, &v, sizeof(v)); 337 } 338 339 /*static inline*/ void regmap_parse_16_le_inplace(void *buf) 340 { 341 u16 v = get_unaligned_le16(buf); 342 343 memcpy(buf, &v, sizeof(v)); 344 } 345 346 /*static inline*/ unsigned int regmap_parse_16_native(const void *buf) 347 { 348 u16 v; 349 350 memcpy(&v, buf, sizeof(v)); 351 return v; 352 } 353 354 /*static inline*/ unsigned int regmap_parse_24(const void *buf) 344 355 { 345 356 const u8 *b = buf; … … 351 362 } 352 363 353 static unsigned int regmap_parse_32_be(const void *buf) 354 { 355 const __be32 *b = buf; 356 357 return be32_to_cpu(b[0]); 358 } 359 360 static unsigned int regmap_parse_32_le(const void *buf) 361 { 362 const __le32 *b = buf; 363 364 return le32_to_cpu(b[0]); 365 } 366 367 static void regmap_parse_32_be_inplace(void *buf) 368 { 369 __be32 *b = buf; 370 371 b[0] = be32_to_cpu(b[0]); 372 } 373 374 static void regmap_parse_32_le_inplace(void *buf) 375 { 376 __le32 *b = buf; 377 378 b[0] = le32_to_cpu(b[0]); 379 } 380 381 static unsigned int regmap_parse_32_native(const void *buf) 382 { 383 return *(u32 *)buf; 364 /*static inline*/ unsigned int regmap_parse_32_be(const void *buf) 365 { 366 return get_unaligned_be32(buf); 367 } 368 369 /*static inline*/ unsigned int regmap_parse_32_le(const void *buf) 370 { 371 return get_unaligned_le32(buf); 372 } 373 374 /*static inline*/ void regmap_parse_32_be_inplace(void *buf) 375 { 376 u32 v = get_unaligned_be32(buf); 377 378 memcpy(buf, &v, sizeof(v)); 379 } 380 381 /*static inline*/ void regmap_parse_32_le_inplace(void *buf) 382 { 383 u32 v = get_unaligned_le32(buf); 384 385 memcpy(buf, &v, sizeof(v)); 386 } 387 388 /*static inline*/ unsigned int regmap_parse_32_native(const void *buf) 389 { 390 u32 v; 391 392 memcpy(&v, buf, sizeof(v)); 393 return v; 384 394 } 385 395 386 396 #ifdef CONFIG_64BIT 387 static unsigned int regmap_parse_64_be(const void *buf) 388 { 389 const __be64 *b = buf; 390 391 return be64_to_cpu(b[0]); 392 } 393 394 static unsigned int regmap_parse_64_le(const void *buf) 395 { 396 const __le64 *b = buf; 397 398 return le64_to_cpu(b[0]); 399 } 400 401 static void regmap_parse_64_be_inplace(void *buf) 402 { 403 __be64 *b = buf; 404 405 b[0] = be64_to_cpu(b[0]); 406 } 407 408 static void regmap_parse_64_le_inplace(void *buf) 409 { 410 __le64 *b = buf; 411 412 b[0] = le64_to_cpu(b[0]); 413 } 414 415 static unsigned int regmap_parse_64_native(const void *buf) 416 { 417 return *(u64 *)buf; 397 /*static inline*/ unsigned int regmap_parse_64_be(const void *buf) 398 { 399 return get_unaligned_be64(buf); 400 } 401 402 /*static inline*/ unsigned int regmap_parse_64_le(const void *buf) 403 { 404 return get_unaligned_le64(buf); 405 } 406 407 /*static inline*/ void regmap_parse_64_be_inplace(void *buf) 408 { 409 u64 v = get_unaligned_be64(buf); 410 411 memcpy(buf, &v, sizeof(v)); 412 } 413 414 /*static inline*/ void regmap_parse_64_le_inplace(void *buf) 415 { 416 u64 v = get_unaligned_le64(buf); 417 418 memcpy(buf, &v, sizeof(v)); 419 } 420 421 /*static inline*/ unsigned int regmap_parse_64_native(const void *buf) 422 { 423 u64 v; 424 425 memcpy(&v, buf, sizeof(v)); 426 return v; 418 427 } 419 428 #endif 420 429 421 static void regmap_lock_mutex(void *__map) 430 /*static inline*/ void regmap_lock_hwlock(void *__map) 431 { 432 struct regmap *map = __map; 433 434 // hwspin_lock_timeout(map->hwlock, UINT_MAX); 435 } 436 437 /*static inline*/ void regmap_lock_hwlock_irq(void *__map) 438 { 439 struct regmap *map = __map; 440 441 // hwspin_lock_timeout_irq(map->hwlock, UINT_MAX); 442 } 443 444 /*static inline*/ void regmap_lock_hwlock_irqsave(void *__map) 445 { 446 struct regmap *map = __map; 447 448 // hwspin_lock_timeout_irqsave(map->hwlock, UINT_MAX, 449 // &map->spinlock_flags); 450 } 451 452 /*static inline*/ void regmap_unlock_hwlock(void *__map) 453 { 454 struct regmap *map = __map; 455 456 // hwspin_unlock(map->hwlock); 457 } 458 459 /*static inline*/ void regmap_unlock_hwlock_irq(void *__map) 460 { 461 struct regmap *map = __map; 462 463 // hwspin_unlock_irq(map->hwlock); 464 } 465 466 /*static inline*/ void regmap_unlock_hwlock_irqrestore(void *__map) 467 { 468 struct regmap *map = __map; 469 470 // hwspin_unlock_irqrestore(map->hwlock, &map->spinlock_flags); 471 } 472 473 /*static inline*/ void regmap_lock_unlock_none(void *__map) 474 { 475 476 } 477 478 /*static inline*/ void regmap_lock_mutex(void *__map) 422 479 { 423 480 struct regmap *map = __map; … … 425 482 } 426 483 427 staticvoid regmap_unlock_mutex(void *__map)484 /*static inline*/ void regmap_unlock_mutex(void *__map) 428 485 { 429 486 struct regmap *map = __map; … … 431 488 } 432 489 433 staticvoid regmap_lock_spinlock(void *__map)490 /*static inline*/ void regmap_lock_spinlock(void *__map) 434 491 __acquires(&map->spinlock) 435 492 { … … 441 498 } 442 499 443 staticvoid regmap_unlock_spinlock(void *__map)500 /*static inline*/ void regmap_unlock_spinlock(void *__map) 444 501 __releases(&map->spinlock) 445 502 { … … 448 505 } 449 506 450 staticvoid dev_get_regmap_release(struct device *dev, void *res)507 /*static inline*/ void dev_get_regmap_release(struct device *dev, void *res) 451 508 { 452 509 /* … … 457 514 } 458 515 459 staticbool _regmap_range_add(struct regmap *map,516 /*static inline*/ bool _regmap_range_add(struct regmap *map, 460 517 struct regmap_range_node *data) 461 518 { … … 482 539 } 483 540 484 staticstruct regmap_range_node *_regmap_range_lookup(struct regmap *map,541 /*static inline*/ struct regmap_range_node *_regmap_range_lookup(struct regmap *map, 485 542 unsigned int reg) 486 543 { … … 502 559 } 503 560 504 staticvoid regmap_range_exit(struct regmap *map)561 /*static inline*/ void regmap_range_exit(struct regmap *map) 505 562 { 506 563 struct rb_node *next; … … 540 597 EXPORT_SYMBOL_GPL(regmap_attach_dev); 541 598 542 staticenum regmap_endian regmap_get_reg_endian(const struct regmap_bus *bus,599 /*static inline*/ enum regmap_endian regmap_get_reg_endian(const struct regmap_bus *bus, 543 600 const struct regmap_config *config) 544 601 { … … 633 690 } 634 691 635 if (config->lock && config->unlock) { 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 } 703 704 if (config->disable_locking) { 705 map->lock = map->unlock = regmap_lock_unlock_none; 706 regmap_debugfs_disable(map); 707 } else if (config->lock && config->unlock) { 636 708 map->lock = config->lock; 637 709 map->unlock = config->unlock; 638 710 map->lock_arg = config->lock_arg; 711 } 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 718 switch (config->hwlock_mode) { 719 case HWLOCK_IRQSTATE: 720 map->lock = regmap_lock_hwlock_irqsave; 721 map->unlock = regmap_unlock_hwlock_irqrestore; 722 break; 723 case HWLOCK_IRQ: 724 map->lock = regmap_lock_hwlock_irq; 725 map->unlock = regmap_unlock_hwlock_irq; 726 break; 727 default: 728 map->lock = regmap_lock_hwlock; 729 map->unlock = regmap_unlock_hwlock; 730 break; 731 } 732 733 map->lock_arg = map; 639 734 } else { 640 735 if ((bus && bus->fast_io) || … … 693 788 map->volatile_table = config->volatile_table; 694 789 map->precious_table = config->precious_table; 790 map->rd_noinc_table = config->rd_noinc_table; 695 791 map->writeable_reg = config->writeable_reg; 696 792 map->readable_reg = config->readable_reg; 697 793 map->volatile_reg = config->volatile_reg; 698 794 map->precious_reg = config->precious_reg; 795 map->readable_noinc_reg = config->readable_noinc_reg; 699 796 map->cache_type = config->cache_type; 700 map->name = config->name;701 797 702 798 spin_lock_init(&map->async_lock); … … 705 801 init_waitqueue_head(&map->async_waitq); 706 802 707 if (config->read_flag_mask || config->write_flag_mask) { 803 if (config->read_flag_mask || 804 config->write_flag_mask || 805 config->zero_flag_mask) { 708 806 map->read_flag_mask = config->read_flag_mask; 709 807 map->write_flag_mask = config->write_flag_mask; … … 739 837 break; 740 838 default: 741 goto err_ map;839 goto err_hwlock; 742 840 } 743 841 break; … … 749 847 break; 750 848 default: 751 goto err_ map;849 goto err_hwlock; 752 850 } 753 851 break; … … 759 857 break; 760 858 default: 761 goto err_ map;859 goto err_hwlock; 762 860 } 763 861 break; … … 769 867 break; 770 868 default: 771 goto err_ map;869 goto err_hwlock; 772 870 } 773 871 break; … … 789 887 break; 790 888 default: 791 goto err_ map;889 goto err_hwlock; 792 890 } 793 891 break; … … 795 893 case 24: 796 894 if (reg_endian != REGMAP_ENDIAN_BIG) 797 goto err_ map;895 goto err_hwlock; 798 896 map->format.format_reg = regmap_format_24; 799 897 break; … … 811 909 break; 812 910 default: 813 goto err_ map;911 goto err_hwlock; 814 912 } 815 913 break; … … 828 926 break; 829 927 default: 830 goto err_ map;928 goto err_hwlock; 831 929 } 832 930 break; … … 834 932 835 933 default: 836 goto err_ map;934 goto err_hwlock; 837 935 } 838 936 … … 863 961 break; 864 962 default: 865 goto err_ map;963 goto err_hwlock; 866 964 } 867 965 break; 868 966 case 24: 869 967 if (val_endian != REGMAP_ENDIAN_BIG) 870 goto err_ map;968 goto err_hwlock; 871 969 map->format.format_val = regmap_format_24; 872 970 map->format.parse_val = regmap_parse_24; … … 889 987 break; 890 988 default: 891 goto err_ map;989 goto err_hwlock; 892 990 } 893 991 break; … … 910 1008 break; 911 1009 default: 912 goto err_ map;1010 goto err_hwlock; 913 1011 } 914 1012 break; … … 919 1017 if ((reg_endian != REGMAP_ENDIAN_BIG) || 920 1018 (val_endian != REGMAP_ENDIAN_BIG)) 921 goto err_ map;1019 goto err_hwlock; 922 1020 map->use_single_write = true; 923 1021 } … … 925 1023 if (!map->format.format_write && 926 1024 !(map->format.format_reg && map->format.format_val)) 927 goto err_ map;1025 goto err_hwlock; 928 1026 929 1027 map->work_buf = kzalloc(map->format.buf_size, GFP_KERNEL); 930 1028 if (map->work_buf == NULL) { 931 1029 ret = -ENOMEM; 932 goto err_ map;1030 goto err_hwlock; 933 1031 } 934 1032 … … 1047 1145 if (dev) { 1048 1146 ret = regmap_attach_dev(dev, map, config); 1049 1050 1147 if (ret != 0) 1051 1148 goto err_regcache; 1149 } else { 1150 regmap_debugfs_init(map, config->name); 1052 1151 } 1053 1152 … … 1059 1158 regmap_range_exit(map); 1060 1159 kfree(map->work_buf); 1160 err_hwlock: 1161 // if (map->hwlock) 1162 // hwspin_lock_free(map->hwlock); 1163 err_name: 1164 // kfree_const(map->name); 1061 1165 err_map: 1062 1166 kfree(map); … … 1067 1171 1068 1172 #ifndef TARGET_OS2 1069 staticvoid devm_regmap_release(struct device *dev, void *res)1173 /*static inline*/ void devm_regmap_release(struct device *dev, void *res) 1070 1174 { 1071 1175 regmap_exit(*(struct regmap **)res); … … 1099 1203 #endif 1100 1204 1101 staticvoid regmap_field_init(struct regmap_field *rm_field,1205 /*static inline*/ void regmap_field_init(struct regmap_field *rm_field, 1102 1206 struct regmap *regmap, struct reg_field reg_field) 1103 1207 { … … 1216 1320 map->volatile_reg = config->volatile_reg; 1217 1321 map->precious_reg = config->precious_reg; 1322 map->readable_noinc_reg = config->readable_noinc_reg; 1218 1323 map->cache_type = config->cache_type; 1219 1324 … … 1250 1355 kfree(async); 1251 1356 } 1357 // if (map->hwlock) 1358 // hwspin_lock_free(map->hwlock); 1359 // kfree_const(map->name); 1360 kfree(map->patch); 1252 1361 kfree(map); 1253 1362 } 1254 1363 EXPORT_SYMBOL_GPL(regmap_exit); 1255 1364 1256 staticint dev_get_regmap_match(struct device *dev, void *res, void *data)1365 /*static inline*/ int dev_get_regmap_match(struct device *dev, void *res, void *data) 1257 1366 { 1258 1367 struct regmap **r = res; … … 1305 1414 EXPORT_SYMBOL_GPL(regmap_get_device); 1306 1415 1307 staticint _regmap_select_page(struct regmap *map, unsigned int *reg,1416 /*static inline*/ int _regmap_select_page(struct regmap *map, unsigned int *reg, 1308 1417 struct regmap_range_node *range, 1309 1418 unsigned int val_num) … … 1353 1462 } 1354 1463 1355 staticvoid regmap_set_work_buf_flag_mask(struct regmap *map, int max_bytes,1464 /*static inline*/ void regmap_set_work_buf_flag_mask(struct regmap *map, int max_bytes, 1356 1465 unsigned long mask) 1357 1466 { … … 1368 1477 } 1369 1478 1370 int _regmap_raw_write(struct regmap *map, unsigned int reg,1371 1479 /*static inline*/ int _regmap_raw_write_impl(struct regmap *map, unsigned int reg, 1480 const void *val, size_t val_len) 1372 1481 { 1373 1482 struct regmap_range_node *range; … … 1420 1529 dev_dbg(map->dev, "Writing window %d/%zu\n", 1421 1530 win_residue, val_len / map->format.val_bytes); 1422 ret = _regmap_raw_write(map, reg, val, win_residue * 1423 map->format.val_bytes); 1531 ret = _regmap_raw_write_impl(map, reg, val, 1532 win_residue * 1533 map->format.val_bytes); 1424 1534 if (ret != 0) 1425 1535 return ret; … … 1588 1698 EXPORT_SYMBOL_GPL(regmap_get_raw_write_max); 1589 1699 1590 staticint _regmap_bus_formatted_write(void *context, unsigned int reg,1700 /*static inline*/ int _regmap_bus_formatted_write(void *context, unsigned int reg, 1591 1701 unsigned int val) 1592 1702 { … … 1612 1722 } 1613 1723 1614 staticint _regmap_bus_reg_write(void *context, unsigned int reg,1724 /*static inline*/ int _regmap_bus_reg_write(void *context, unsigned int reg, 1615 1725 unsigned int val) 1616 1726 { … … 1620 1730 } 1621 1731 1622 staticint _regmap_bus_raw_write(void *context, unsigned int reg,1732 /*static inline*/ int _regmap_bus_raw_write(void *context, unsigned int reg, 1623 1733 unsigned int val) 1624 1734 { … … 1629 1739 map->format.format_val(map->work_buf + map->format.reg_bytes 1630 1740 + map->format.pad_bytes, val, 0); 1631 return _regmap_raw_write (map, reg,1632 map->work_buf +1633 map->format.reg_bytes +1634 map->format.pad_bytes,1635 map->format.val_bytes);1636 } 1637 1638 staticinline void *_regmap_map_get_context(struct regmap *map)1741 return _regmap_raw_write_impl(map, reg, 1742 map->work_buf + 1743 map->format.reg_bytes + 1744 map->format.pad_bytes, 1745 map->format.val_bytes); 1746 } 1747 1748 /*static inline*/ inline void *_regmap_map_get_context(struct regmap *map) 1639 1749 { 1640 1750 return (map->bus) ? map : map->bus_context; … … 1728 1838 EXPORT_SYMBOL_GPL(regmap_write_async); 1729 1839 1840 int _regmap_raw_write(struct regmap *map, unsigned int reg, 1841 const void *val, size_t val_len) 1842 { 1843 size_t val_bytes = map->format.val_bytes; 1844 size_t val_count = val_len / val_bytes; 1845 size_t chunk_count, chunk_bytes; 1846 size_t chunk_regs = val_count; 1847 int ret, i; 1848 1849 if (!val_count) 1850 return -EINVAL; 1851 1852 if (map->use_single_write) 1853 chunk_regs = 1; 1854 else if (map->max_raw_write && val_len > map->max_raw_write) 1855 chunk_regs = map->max_raw_write / val_bytes; 1856 1857 chunk_count = val_count / chunk_regs; 1858 chunk_bytes = chunk_regs * val_bytes; 1859 1860 /* Write as many bytes as possible with chunk_size */ 1861 for (i = 0; i < chunk_count; i++) { 1862 ret = _regmap_raw_write_impl(map, reg, val, chunk_bytes); 1863 if (ret) 1864 return ret; 1865 1866 reg += regmap_get_offset(map, chunk_regs); 1867 val += chunk_bytes; 1868 val_len -= chunk_bytes; 1869 } 1870 1871 /* Write remaining bytes */ 1872 if (val_len) 1873 ret = _regmap_raw_write_impl(map, reg, val, val_len); 1874 1875 return ret; 1876 } 1877 1730 1878 /** 1731 1879 * regmap_raw_write() - Write raw values to one or more registers … … 1753 1901 if (val_len % map->format.val_bytes) 1754 1902 return -EINVAL; 1755 if (map->max_raw_write && map->max_raw_write < val_len)1756 return -E2BIG;1757 1903 1758 1904 map->lock(map->lock_arg); … … 1845 1991 int ret = 0, i; 1846 1992 size_t val_bytes = map->format.val_bytes; 1847 size_t total_size = val_bytes * val_count;1848 1993 1849 1994 if (!IS_ALIGNED(reg, map->reg_stride)) … … 1851 1996 1852 1997 /* 1853 * Some devices don't support bulk write, for 1854 * them we have a series of single write operations in the first two if 1855 * blocks. 1856 * 1857 * The first if block is used for memory mapped io. It does not allow 1858 * val_bytes of 3 for example. 1859 * The second one is for busses that do not provide raw I/O. 1860 * The third one is used for busses which do not have these limitations 1861 * and can write arbitrary value lengths. 1998 * Some devices don't support bulk write, for them we have a series of 1999 * single write operations. 1862 2000 */ 1863 if (!map->bus ) {2001 if (!map->bus || !map->format.parse_inplace) { 1864 2002 map->lock(map->lock_arg); 1865 2003 for (i = 0; i < val_count; i++) { … … 1894 2032 out: 1895 2033 map->unlock(map->lock_arg); 1896 } else if (map->bus && !map->format.parse_inplace) {1897 const u8 *u8 = val;1898 const u16 *u16 = val;1899 const u32 *u32 = val;1900 unsigned int ival;1901 1902 for (i = 0; i < val_count; i++) {1903 switch (map->format.val_bytes) {1904 case 4:1905 ival = u32[i];1906 break;1907 case 2:1908 ival = u16[i];1909 break;1910 case 1:1911 ival = u8[i];1912 break;1913 default:1914 return -EINVAL;1915 }1916 1917 ret = regmap_write(map, reg + (i * map->reg_stride),1918 ival);1919 if (ret)1920 return ret;1921 }1922 } else if (map->use_single_write ||1923 (map->max_raw_write && map->max_raw_write < total_size)) {1924 int chunk_stride = map->reg_stride;1925 size_t chunk_size = val_bytes;1926 size_t chunk_count = val_count;1927 1928 if (!map->use_single_write) {1929 chunk_size = map->max_raw_write;1930 if (chunk_size % val_bytes)1931 chunk_size -= chunk_size % val_bytes;1932 chunk_count = total_size / chunk_size;1933 chunk_stride *= chunk_size / val_bytes;1934 }1935 1936 map->lock(map->lock_arg);1937 /* Write as many bytes as possible with chunk_size */1938 for (i = 0; i < chunk_count; i++) {1939 ret = _regmap_raw_write(map,1940 reg + (i * chunk_stride),1941 val + (i * chunk_size),1942 chunk_size);1943 if (ret)1944 break;1945 }1946 1947 /* Write remaining bytes */1948 if (!ret && chunk_size * i < total_size) {1949 ret = _regmap_raw_write(map, reg + (i * chunk_stride),1950 val + (i * chunk_size),1951 total_size - i * chunk_size);1952 }1953 map->unlock(map->lock_arg);1954 2034 } else { 1955 2035 void *wval; 1956 2036 1957 if (!val_count)1958 return -EINVAL;1959 1960 2037 wval = kmemdup(val, val_count * val_bytes, map->alloc_flags); 1961 if (!wval) { 1962 dev_err(map->dev, "Error in memory allocation\n"); 2038 if (!wval) 1963 2039 return -ENOMEM; 1964 } 2040 1965 2041 for (i = 0; i < val_count * val_bytes; i += val_bytes) 1966 2042 map->format.parse_inplace(wval + i); 1967 2043 1968 map->lock(map->lock_arg); 1969 ret = _regmap_raw_write(map, reg, wval, val_bytes * val_count); 1970 map->unlock(map->lock_arg); 2044 ret = regmap_raw_write(map, reg, wval, val_bytes * val_count); 1971 2045 1972 2046 kfree(wval); … … 1983 2057 * relative. The page register has been written if that was necessary. 1984 2058 */ 1985 staticint _regmap_raw_multi_reg_write(struct regmap *map,2059 /*static inline*/ int _regmap_raw_multi_reg_write(struct regmap *map, 1986 2060 const struct reg_sequence *regs, 1987 2061 size_t num_regs) … … 2029 2103 } 2030 2104 2031 staticunsigned int _regmap_register_page(struct regmap *map,2105 /*static inline*/ unsigned int _regmap_register_page(struct regmap *map, 2032 2106 unsigned int reg, 2033 2107 struct regmap_range_node *range) … … 2038 2112 } 2039 2113 2040 staticint _regmap_range_multi_paged_reg_write(struct regmap *map,2114 /*static inline*/ int _regmap_range_multi_paged_reg_write(struct regmap *map, 2041 2115 struct reg_sequence *regs, 2042 2116 size_t num_regs) … … 2115 2189 } 2116 2190 2117 staticint _regmap_multi_reg_write(struct regmap *map,2191 /*static inline*/ int _regmap_multi_reg_write(struct regmap *map, 2118 2192 const struct reg_sequence *regs, 2119 2193 size_t num_regs) … … 2310 2384 EXPORT_SYMBOL_GPL(regmap_raw_write_async); 2311 2385 2312 staticint _regmap_raw_read(struct regmap *map, unsigned int reg, void *val,2313 unsigned int val_len )2386 /*static inline*/ int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val, 2387 unsigned int val_len, bool noinc) 2314 2388 { 2315 2389 struct regmap_range_node *range; … … 2324 2398 if (range) { 2325 2399 ret = _regmap_select_page(map, ®, range, 2326 val_len / map->format.val_bytes);2400 noinc ? 1 : val_len / map->format.val_bytes); 2327 2401 if (ret != 0) 2328 2402 return ret; … … 2340 2414 } 2341 2415 2342 staticint _regmap_bus_reg_read(void *context, unsigned int reg,2416 /*static inline*/ int _regmap_bus_reg_read(void *context, unsigned int reg, 2343 2417 unsigned int *val) 2344 2418 { … … 2348 2422 } 2349 2423 2350 staticint _regmap_bus_read(void *context, unsigned int reg,2424 /*static inline*/ int _regmap_bus_read(void *context, unsigned int reg, 2351 2425 unsigned int *val) 2352 2426 { 2353 2427 int ret; 2354 2428 struct regmap *map = context; 2429 void *work_val = map->work_buf + map->format.reg_bytes + 2430 map->format.pad_bytes; 2355 2431 2356 2432 if (!map->format.parse_val) 2357 2433 return -EINVAL; 2358 2434 2359 ret = _regmap_raw_read(map, reg, map->work_buf, map->format.val_bytes);2435 ret = _regmap_raw_read(map, reg, work_val, map->format.val_bytes, false); 2360 2436 if (ret == 0) 2361 *val = map->format.parse_val( map->work_buf);2437 *val = map->format.parse_val(work_val); 2362 2438 2363 2439 return ret; 2364 2440 } 2365 2441 2366 staticint _regmap_read(struct regmap *map, unsigned int reg,2442 /*static inline*/ int _regmap_read(struct regmap *map, unsigned int reg, 2367 2443 unsigned int *val) 2368 2444 { … … 2455 2531 if (regmap_volatile_range(map, reg, val_count) || map->cache_bypass || 2456 2532 map->cache_type == REGCACHE_NONE) { 2533 size_t chunk_count, chunk_bytes; 2534 size_t chunk_regs = val_count; 2535 2457 2536 if (!map->bus->read) { 2458 2537 ret = -ENOTSUPP; 2459 2538 goto out; 2460 2539 } 2461 if (map->max_raw_read && map->max_raw_read < val_len) { 2462 ret = -E2BIG; 2463 goto out; 2464 } 2465 2466 /* Physical block read if there's no cache involved */ 2467 ret = _regmap_raw_read(map, reg, val, val_len); 2468 2540 2541 if (map->use_single_read) 2542 chunk_regs = 1; 2543 else if (map->max_raw_read && val_len > map->max_raw_read) 2544 chunk_regs = map->max_raw_read / val_bytes; 2545 2546 chunk_count = val_count / chunk_regs; 2547 chunk_bytes = chunk_regs * val_bytes; 2548 2549 /* Read bytes that fit into whole chunks */ 2550 for (i = 0; i < chunk_count; i++) { 2551 ret = _regmap_raw_read(map, reg, val, chunk_bytes, false); 2552 if (ret != 0) 2553 goto out; 2554 2555 reg += regmap_get_offset(map, chunk_regs); 2556 val += chunk_bytes; 2557 val_len -= chunk_bytes; 2558 } 2559 2560 /* Read remaining bytes */ 2561 if (val_len) { 2562 ret = _regmap_raw_read(map, reg, val, val_len, false); 2563 if (ret != 0) 2564 goto out; 2565 } 2469 2566 } else { 2470 2567 /* Otherwise go word by word for the cache; should be low … … 2489 2586 2490 2587 /** 2491 * regmap_field_read() - Read a value to a single register field 2588 * regmap_noinc_read(): Read data from a register without incrementing the 2589 * register number 2590 * 2591 * @map: Register map to read from 2592 * @reg: Register to read from 2593 * @val: Pointer to data buffer 2594 * @val_len: Length of output buffer in bytes. 2595 * 2596 * The regmap API usually assumes that bulk bus read operations will read a 2597 * range of registers. Some devices have certain registers for which a read 2598 * operation read will read from an internal FIFO. 2599 * 2600 * The target register must be volatile but registers after it can be 2601 * completely unrelated cacheable registers. 2602 * 2603 * This will attempt multiple reads as required to read val_len bytes. 2604 * 2605 * A value of zero will be returned on success, a negative errno will be 2606 * returned in error cases. 2607 */ 2608 int regmap_noinc_read(struct regmap *map, unsigned int reg, 2609 void *val, size_t val_len) 2610 { 2611 size_t read_len; 2612 int ret; 2613 2614 if (!map->bus) 2615 return -EINVAL; 2616 if (!map->bus->read) 2617 return -ENOTSUPP; 2618 if (val_len % map->format.val_bytes) 2619 return -EINVAL; 2620 if (!IS_ALIGNED(reg, map->reg_stride)) 2621 return -EINVAL; 2622 if (val_len == 0) 2623 return -EINVAL; 2624 2625 map->lock(map->lock_arg); 2626 2627 if (!regmap_volatile(map, reg) || !regmap_readable_noinc(map, reg)) { 2628 ret = -EINVAL; 2629 goto out_unlock; 2630 } 2631 2632 while (val_len) { 2633 if (map->max_raw_read && map->max_raw_read < val_len) 2634 read_len = map->max_raw_read; 2635 else 2636 read_len = val_len; 2637 ret = _regmap_raw_read(map, reg, val, read_len, true); 2638 if (ret) 2639 goto out_unlock; 2640 val = ((u8 *)val) + read_len; 2641 val_len -= read_len; 2642 } 2643 2644 out_unlock: 2645 map->unlock(map->lock_arg); 2646 return ret; 2647 } 2648 EXPORT_SYMBOL_GPL(regmap_noinc_read); 2649 2650 /** 2651 * regmap_field_read(): Read a value to a single register field 2492 2652 * 2493 2653 * @field: Register field to read from … … 2566 2726 if (!IS_ALIGNED(reg, map->reg_stride)) 2567 2727 return -EINVAL; 2728 if (val_count == 0) 2729 return -EINVAL; 2568 2730 2569 2731 if (map->bus && map->format.parse_inplace && (vol || map->cache_type == REGCACHE_NONE)) { 2570 /* 2571 * Some devices does not support bulk read, for 2572 * them we have a series of single read operations. 2573 */ 2574 size_t total_size = val_bytes * val_count; 2575 2576 if (!map->use_single_read && 2577 (!map->max_raw_read || map->max_raw_read > total_size)) { 2578 ret = regmap_raw_read(map, reg, val, 2579 val_bytes * val_count); 2580 if (ret != 0) 2581 return ret; 2582 } else { 2583 /* 2584 * Some devices do not support bulk read or do not 2585 * support large bulk reads, for them we have a series 2586 * of read operations. 2587 */ 2588 int chunk_stride = map->reg_stride; 2589 size_t chunk_size = val_bytes; 2590 size_t chunk_count = val_count; 2591 2592 if (!map->use_single_read) { 2593 chunk_size = map->max_raw_read; 2594 if (chunk_size % val_bytes) 2595 chunk_size -= chunk_size % val_bytes; 2596 chunk_count = total_size / chunk_size; 2597 chunk_stride *= chunk_size / val_bytes; 2598 } 2599 2600 /* Read bytes that fit into a multiple of chunk_size */ 2601 for (i = 0; i < chunk_count; i++) { 2602 ret = regmap_raw_read(map, 2603 reg + (i * chunk_stride), 2604 val + (i * chunk_size), 2605 chunk_size); 2606 if (ret != 0) 2607 return ret; 2608 } 2609 2610 /* Read remaining bytes */ 2611 if (chunk_size * i < total_size) { 2612 ret = regmap_raw_read(map, 2613 reg + (i * chunk_stride), 2614 val + (i * chunk_size), 2615 total_size - i * chunk_size); 2616 if (ret != 0) 2617 return ret; 2618 } 2619 } 2732 ret = regmap_raw_read(map, reg, val, val_bytes * val_count); 2733 if (ret != 0) 2734 return ret; 2620 2735 2621 2736 for (i = 0; i < val_count * val_bytes; i += val_bytes) 2622 2737 map->format.parse_inplace(val + i); 2623 2738 } else { 2739 #ifdef CONFIG_64BIT 2740 u64 *u64 = val; 2741 #endif 2742 u32 *u32 = val; 2743 u16 *u16 = val; 2744 u8 *u8 = val; 2745 2746 map->lock(map->lock_arg); 2747 2624 2748 for (i = 0; i < val_count; i++) { 2625 2749 unsigned int ival; 2626 ret = regmap_read(map, reg + regmap_get_offset(map, i), 2627 &ival); 2750 2751 ret = _regmap_read(map, reg + regmap_get_offset(map, i), 2752 &ival); 2628 2753 if (ret != 0) 2629 return ret; 2630 2631 if (map->format.format_val) { 2632 map->format.format_val(val + (i * val_bytes), ival, 0); 2633 } else { 2634 /* Devices providing read and write 2635 * operations can use the bulk I/O 2636 * functions if they define a val_bytes, 2637 * we assume that the values are native 2638 * endian. 2639 */ 2754 goto out; 2755 2756 switch (map->format.val_bytes) { 2640 2757 #ifdef CONFIG_64BIT 2641 u64 *u64 = val; 2758 case 8: 2759 u64[i] = ival; 2760 break; 2642 2761 #endif 2643 u32 *u32 = val; 2644 u16 *u16 = val; 2645 u8 *u8 = val; 2646 2647 switch (map->format.val_bytes) { 2648 #ifdef CONFIG_64BIT 2649 case 8: 2650 u64[i] = ival; 2651 break; 2652 #endif 2653 case 4: 2654 u32[i] = ival; 2655 break; 2656 case 2: 2657 u16[i] = ival; 2658 break; 2659 case 1: 2660 u8[i] = ival; 2661 break; 2662 default: 2663 return -EINVAL; 2664 } 2762 case 4: 2763 u32[i] = ival; 2764 break; 2765 case 2: 2766 u16[i] = ival; 2767 break; 2768 case 1: 2769 u8[i] = ival; 2770 break; 2771 default: 2772 ret = -EINVAL; 2773 goto out; 2665 2774 } 2666 2775 } 2667 } 2668 2669 return 0; 2776 2777 out: 2778 map->unlock(map->lock_arg); 2779 } 2780 2781 return ret; 2670 2782 } 2671 2783 EXPORT_SYMBOL_GPL(regmap_bulk_read); 2672 2784 2673 staticint _regmap_update_bits(struct regmap *map, unsigned int reg,2785 /*static inline*/ int _regmap_update_bits(struct regmap *map, unsigned int reg, 2674 2786 unsigned int mask, unsigned int val, 2675 2787 bool *change, bool force_write) … … 2764 2876 EXPORT_SYMBOL_GPL(regmap_async_complete_cb); 2765 2877 2766 #ifndef TARGET_OS2 2767 static int regmap_async_is_done(struct regmap *map) 2878 /*static inline*/ int regmap_async_is_done(struct regmap *map) 2768 2879 { 2769 2880 unsigned long flags; … … 2776 2887 return ret; 2777 2888 } 2778 #endif2779 2889 2780 2890 /** … … 2795 2905 return 0; 2796 2906 2797 // FIXMEwait_event(map->async_waitq, regmap_async_is_done(map));2907 // wait_event(map->async_waitq, regmap_async_is_done(map)); 2798 2908 2799 2909 spin_lock_irqsave(&map->async_lock, flags); … … 2835 2945 return 0; 2836 2946 #endif 2837 2838 2947 p = krealloc(map->patch, 2839 2948 sizeof(struct reg_sequence) * (map->patch_regs + num_regs), … … 2924 3033 EXPORT_SYMBOL_GPL(regmap_parse_val); 2925 3034 2926 staticint __init regmap_initcall(void)3035 /*static inline*/ int __init regmap_initcall(void) 2927 3036 { 2928 3037 regmap_debugfs_initcall();
Note:
See TracChangeset
for help on using the changeset viewer.