@@ -680,6 +680,47 @@ static void cache_sync_defaults(struct kunit *test)
680680 regmap_exit (map );
681681}
682682
683+ static void cache_sync_readonly (struct kunit * test )
684+ {
685+ struct regcache_types * t = (struct regcache_types * )test -> param_value ;
686+ struct regmap * map ;
687+ struct regmap_config config ;
688+ struct regmap_ram_data * data ;
689+ unsigned int val ;
690+ int i ;
691+
692+ config = test_regmap_config ;
693+ config .cache_type = t -> type ;
694+ config .writeable_reg = reg_5_false ;
695+
696+ map = gen_regmap (& config , & data );
697+ KUNIT_ASSERT_FALSE (test , IS_ERR (map ));
698+ if (IS_ERR (map ))
699+ return ;
700+
701+ /* Read all registers to fill the cache */
702+ for (i = 0 ; i < BLOCK_TEST_SIZE ; i ++ )
703+ KUNIT_EXPECT_EQ (test , 0 , regmap_read (map , i , & val ));
704+
705+ /* Change the value of all registers, readonly should fail */
706+ get_random_bytes (& val , sizeof (val ));
707+ regcache_cache_only (map , true);
708+ for (i = 0 ; i < BLOCK_TEST_SIZE ; i ++ )
709+ KUNIT_EXPECT_EQ (test , i != 5 , regmap_write (map , i , val ) == 0 );
710+ regcache_cache_only (map , false);
711+
712+ /* Resync */
713+ for (i = 0 ; i < BLOCK_TEST_SIZE ; i ++ )
714+ data -> written [i ] = false;
715+ KUNIT_EXPECT_EQ (test , 0 , regcache_sync (map ));
716+
717+ /* Did that match what we see on the device? */
718+ for (i = 0 ; i < BLOCK_TEST_SIZE ; i ++ )
719+ KUNIT_EXPECT_EQ (test , i != 5 , data -> written [i ]);
720+
721+ regmap_exit (map );
722+ }
723+
683724static void cache_sync_patch (struct kunit * test )
684725{
685726 struct regcache_types * t = (struct regcache_types * )test -> param_value ;
@@ -1119,6 +1160,7 @@ static struct kunit_case regmap_test_cases[] = {
11191160 KUNIT_CASE_PARAM (cache_bypass , real_cache_types_gen_params ),
11201161 KUNIT_CASE_PARAM (cache_sync , real_cache_types_gen_params ),
11211162 KUNIT_CASE_PARAM (cache_sync_defaults , real_cache_types_gen_params ),
1163+ KUNIT_CASE_PARAM (cache_sync_readonly , real_cache_types_gen_params ),
11221164 KUNIT_CASE_PARAM (cache_sync_patch , real_cache_types_gen_params ),
11231165 KUNIT_CASE_PARAM (cache_drop , sparse_cache_types_gen_params ),
11241166
0 commit comments