@@ -442,12 +442,20 @@ static struct regmap_range_cfg test_range = {
442
442
.range_max = 40 ,
443
443
};
444
444
445
- static bool test_range_volatile (struct device * dev , unsigned int reg )
445
+ static bool test_range_window_volatile (struct device * dev , unsigned int reg )
446
446
{
447
447
if (reg >= test_range .window_start &&
448
448
reg <= test_range .window_start + test_range .window_len )
449
449
return true;
450
450
451
+ return false;
452
+ }
453
+
454
+ static bool test_range_all_volatile (struct device * dev , unsigned int reg )
455
+ {
456
+ if (test_range_window_volatile (dev , reg ))
457
+ return true;
458
+
451
459
if (reg >= test_range .range_min && reg <= test_range .range_max )
452
460
return true;
453
461
@@ -465,7 +473,7 @@ static void basic_ranges(struct kunit *test)
465
473
466
474
config = test_regmap_config ;
467
475
config .cache_type = t -> type ;
468
- config .volatile_reg = test_range_volatile ;
476
+ config .volatile_reg = test_range_all_volatile ;
469
477
config .ranges = & test_range ;
470
478
config .num_ranges = 1 ;
471
479
config .max_register = test_range .range_max ;
@@ -875,6 +883,59 @@ static void cache_present(struct kunit *test)
875
883
regmap_exit (map );
876
884
}
877
885
886
+ /* Check that caching the window register works with sync */
887
+ static void cache_range_window_reg (struct kunit * test )
888
+ {
889
+ struct regcache_types * t = (struct regcache_types * )test -> param_value ;
890
+ struct regmap * map ;
891
+ struct regmap_config config ;
892
+ struct regmap_ram_data * data ;
893
+ unsigned int val ;
894
+ int i ;
895
+
896
+ config = test_regmap_config ;
897
+ config .cache_type = t -> type ;
898
+ config .volatile_reg = test_range_window_volatile ;
899
+ config .ranges = & test_range ;
900
+ config .num_ranges = 1 ;
901
+ config .max_register = test_range .range_max ;
902
+
903
+ map = gen_regmap (& config , & data );
904
+ KUNIT_ASSERT_FALSE (test , IS_ERR (map ));
905
+ if (IS_ERR (map ))
906
+ return ;
907
+
908
+ /* Write new values to the entire range */
909
+ for (i = test_range .range_min ; i <= test_range .range_max ; i ++ )
910
+ KUNIT_ASSERT_EQ (test , 0 , regmap_write (map , i , 0 ));
911
+
912
+ val = data -> vals [test_range .selector_reg ] & test_range .selector_mask ;
913
+ KUNIT_ASSERT_EQ (test , val , 2 );
914
+
915
+ /* Write to the first register in the range to reset the page */
916
+ KUNIT_ASSERT_EQ (test , 0 , regmap_write (map , test_range .range_min , 0 ));
917
+ val = data -> vals [test_range .selector_reg ] & test_range .selector_mask ;
918
+ KUNIT_ASSERT_EQ (test , val , 0 );
919
+
920
+ /* Trigger a cache sync */
921
+ regcache_mark_dirty (map );
922
+ KUNIT_ASSERT_EQ (test , 0 , regcache_sync (map ));
923
+
924
+ /* Write to the first register again, the page should be reset */
925
+ KUNIT_ASSERT_EQ (test , 0 , regmap_write (map , test_range .range_min , 0 ));
926
+ val = data -> vals [test_range .selector_reg ] & test_range .selector_mask ;
927
+ KUNIT_ASSERT_EQ (test , val , 0 );
928
+
929
+ /* Trigger another cache sync */
930
+ regcache_mark_dirty (map );
931
+ KUNIT_ASSERT_EQ (test , 0 , regcache_sync (map ));
932
+
933
+ /* Write to the last register again, the page should be reset */
934
+ KUNIT_ASSERT_EQ (test , 0 , regmap_write (map , test_range .range_max , 0 ));
935
+ val = data -> vals [test_range .selector_reg ] & test_range .selector_mask ;
936
+ KUNIT_ASSERT_EQ (test , val , 2 );
937
+ }
938
+
878
939
struct raw_test_types {
879
940
const char * name ;
880
941
@@ -1217,6 +1278,7 @@ static struct kunit_case regmap_test_cases[] = {
1217
1278
KUNIT_CASE_PARAM (cache_sync_patch , real_cache_types_gen_params ),
1218
1279
KUNIT_CASE_PARAM (cache_drop , sparse_cache_types_gen_params ),
1219
1280
KUNIT_CASE_PARAM (cache_present , sparse_cache_types_gen_params ),
1281
+ KUNIT_CASE_PARAM (cache_range_window_reg , real_cache_types_gen_params ),
1220
1282
1221
1283
KUNIT_CASE_PARAM (raw_read_defaults_single , raw_test_types_gen_params ),
1222
1284
KUNIT_CASE_PARAM (raw_read_defaults , raw_test_types_gen_params ),
0 commit comments