@@ -474,6 +474,7 @@ struct ds5 {
474474 int is_depth , is_y8 , is_rgb , is_imu ;
475475 bool metadata_enabled ;
476476 int aggregated ;
477+ int reset_gen ;
477478 u16 fw_version ;
478479 u16 fw_build ;
479480#ifdef CONFIG_VIDEO_D4XX_SERDES
@@ -492,6 +493,8 @@ struct ds5_counters {
492493 unsigned int n_ctrl ;
493494};
494495
496+ static atomic_t ds5_reset_gen = ATOMIC_INIT (0 );
497+
495498#ifdef CONFIG_VIDEO_D4XX_SERDES
496499static DEFINE_MUTEX (serdes_lock__ );
497500
@@ -1652,9 +1655,41 @@ static int ds5_setup_pipeline(struct ds5 *state, u8 data_type1, u8 data_type2,
16521655}
16531656#endif
16541657
1658+ static void ds5_config_cache_clear (struct ds5_sensor * sensor )
1659+ {
1660+ sensor -> cached_dt_value = 0xFFFF ;
1661+ sensor -> cached_md_value = 0xFFFF ;
1662+ sensor -> cached_override_value = 0xFFFF ;
1663+ sensor -> cached_fps_value = 0xFFFF ;
1664+ sensor -> cached_width_value = 0xFFFF ;
1665+ sensor -> cached_height_value = 0xFFFF ;
1666+ }
1667+
1668+ static void ds5_invalidate_state_cache (struct ds5 * state )
1669+ {
1670+ struct ds5_sensor * sensors [] = {
1671+ & state -> depth .sensor ,
1672+ & state -> ir .sensor ,
1673+ & state -> rgb .sensor ,
1674+ & state -> imu .sensor ,
1675+ };
1676+ int i ;
1677+
1678+ for (i = 0 ; i < ARRAY_SIZE (sensors ); i ++ ) {
1679+ struct ds5_sensor * sensor = sensors [i ];
1680+
1681+ ds5_config_cache_clear (sensor );
1682+ sensor -> pipe_id = PIPE_NOT_CONFIGURED ;
1683+ sensor -> pipe_data_type1 = 0 ;
1684+ sensor -> pipe_data_type2 = 0 ;
1685+ sensor -> pipe_vc_id = 0 ;
1686+ }
1687+ }
1688+
16551689static int ds5_configure (struct ds5 * state )
16561690{
16571691 struct ds5_sensor * sensor ;
1692+ int current_reset_gen ;
16581693 u16 fmt , md_fmt , vc_id ;
16591694#ifdef CONFIG_VIDEO_D4XX_SERDES
16601695 u16 data_type1 , data_type2 ;
@@ -1668,6 +1703,12 @@ static int ds5_configure(struct ds5 *state)
16681703 u16 height_value = 0 ;
16691704 int ret ;
16701705
1706+ current_reset_gen = atomic_read (& ds5_reset_gen );
1707+ if (state -> reset_gen != current_reset_gen ) {
1708+ ds5_invalidate_state_cache (state );
1709+ state -> reset_gen = current_reset_gen ;
1710+ }
1711+
16711712 if (state -> is_depth ) {
16721713 sensor = & state -> depth .sensor ;
16731714 dt_addr = DS5_DEPTH_STREAM_DT ;
@@ -1775,6 +1816,9 @@ static int ds5_configure(struct ds5 *state)
17751816 sensor -> config .format -> data_type == GMSL_CSI_DT_YUV422_8 )
17761817 dt_value = 0x32 ;
17771818
1819+ dev_dbg (& state -> client -> dev , "sensor %p: dt_value=0x%x, cached_dt_value=0x%x, cached_fps_value=%u, framerate=%u\n" ,
1820+ sensor , dt_value , sensor -> cached_dt_value , sensor -> cached_fps_value , sensor -> config .framerate );
1821+
17781822 if (sensor -> cached_dt_value != dt_value ) {
17791823 ret = ds5_write (state , dt_addr , dt_value );
17801824 if (ret < 0 )
@@ -2183,16 +2227,6 @@ static int ds5_set_calibration_data(struct ds5 *state,
21832227#define DS5_HW_RESET_STATUS_READY 0xDEAD
21842228#define DS5_HW_RESET_DFU_MAGIC_LSW 0x0201 /* Lower 16 bits of 0x04030201 */
21852229
2186- static void ds5_config_cache_clear (struct ds5_sensor * sensor )
2187- {
2188- sensor -> cached_dt_value = 0xFFFF ;
2189- sensor -> cached_md_value = 0xFFFF ;
2190- sensor -> cached_override_value = 0xFFFF ;
2191- sensor -> cached_fps_value = 0xFFFF ;
2192- sensor -> cached_width_value = 0xFFFF ;
2193- sensor -> cached_height_value = 0xFFFF ;
2194- }
2195-
21962230/*
21972231 * ds5_hw_reset_with_recovery - Perform hardware reset with GMSL recovery
21982232 * @state: Driver state structure
@@ -2255,6 +2289,8 @@ static int ds5_hw_reset_with_recovery(struct ds5 *state)
22552289 __func__ , ret );
22562290 return ret ;
22572291 }
2292+ atomic_inc (& ds5_reset_gen );
2293+ state -> reset_gen = atomic_read (& ds5_reset_gen );
22582294
22592295 dev_info (& state -> client -> dev , "%s(): HW reset command sent, waiting for device...\n" ,
22602296 __func__ );
@@ -5739,6 +5775,7 @@ static int ds5_probe(struct i2c_client *c, const struct i2c_device_id *id)
57395775 mutex_init (& state -> lock );
57405776
57415777 state -> client = c ;
5778+ state -> reset_gen = atomic_read (& ds5_reset_gen );
57425779 dev_warn (& c -> dev , "Probing driver for D4xx\n" );
57435780#ifdef CONFIG_OF
57445781 ret = of_property_read_u32 (c -> dev .of_node , "override_reg" , & override_addr );
0 commit comments