@@ -1833,18 +1833,24 @@ static int ds5_get_hwmc(struct ds5 *state, unsigned char *data,
18331833 }
18341834
18351835 ret = regmap_raw_read (state -> regmap , DS5_HWMC_RESP_LEN ,
1836- & tmp_len , sizeof (tmp_len ));
1836+ & tmp_len , sizeof (tmp_len )); /* Read response length */
18371837 if (ret )
18381838 return - EBADMSG ;
18391839
18401840 if (tmp_len > cmdDataLen )
18411841 return - ENOBUFS ;
18421842
1843+ if (tmp_len == 0 ) {
1844+ dev_err (& state -> client -> dev ,
1845+ "%s(): HWMC response length is 0\n" , __func__ );
1846+ return - ENODATA ;
1847+ }
1848+
18431849 dev_dbg (& state -> client -> dev ,
18441850 "%s(): HWMC read len: %d, lrs_len: %d\n" ,
18451851 __func__ , tmp_len , tmp_len - 4 );
18461852
1847- ds5_raw_read_with_check (state , DS5_HWMC_DATA , data , tmp_len );
1853+ ds5_raw_read_with_check (state , DS5_HWMC_DATA , data , tmp_len ); /* Read response data */
18481854 if (dataLen )
18491855 * dataLen = tmp_len ;
18501856 return ret ;
@@ -1860,8 +1866,8 @@ static int ds5_send_hwmc(struct ds5 *state,
18601866 __func__ , cmd -> header , cmd -> magic_word , cmd -> opcode ,
18611867 cmdLen , cmd -> param1 , cmd -> param2 , cmd -> param3 , cmd -> param4 );
18621868
1863- ds5_raw_write_with_check (state , DS5_HWMC_DATA , cmd , cmdLen );
1864-
1869+ ds5_raw_write_with_check (state , DS5_HWMC_DATA , cmd , cmdLen ); /* Write command data */
1870+
18651871 ds5_write_with_check (state , DS5_HWMC_EXEC , 0x01 ); /* execute cmd */
18661872
18671873 return 0 ;
@@ -1874,7 +1880,7 @@ static int ds5_set_calibration_data(struct ds5 *state,
18741880 int retries = 10 ;
18751881 u16 status = 2 ;
18761882
1877- ds5_raw_write_with_check (state , DS5_HWMC_DATA , cmd , length );
1883+ ds5_raw_write_with_check (state , DS5_HWMC_DATA , cmd , length ); /* Write command data */
18781884
18791885 ds5_write_with_check (state , DS5_HWMC_EXEC , 0x01 ); /* execute cmd */
18801886 do {
@@ -2248,12 +2254,12 @@ static int ds5_get_calibration_data(struct ds5 *state, enum table_id id,
22482254
22492255 memcpy (cmd , & get_calib_data , sizeof (get_calib_data ));
22502256 cmd -> param1 = id ;
2251- ds5_raw_write_with_check (state , 0x4900 , cmd , sizeof (struct hwm_cmd ));
2252- ds5_write_with_check (state , 0x490c , 0x01 ); /* execute cmd */
2257+ ds5_raw_write_with_check (state , DS5_HWMC_DATA , cmd , sizeof (struct hwm_cmd )); /* Write command data */
2258+ ds5_write_with_check (state , DS5_HWMC_EXEC , 0x01 ); /* execute cmd */
22532259 do {
22542260 if (retries != 3 )
22552261 msleep_range (10 );
2256- ret = ds5_read (state , 0x4904 , & status );
2262+ ret = ds5_read (state , DS5_HWMC_STATUS , & status );
22572263 } while (ret && retries -- && status != 0 );
22582264
22592265 if (ret || status != 0 ) {
@@ -2265,11 +2271,11 @@ static int ds5_get_calibration_data(struct ds5 *state, enum table_id id,
22652271 }
22662272
22672273 // get table length from fw
2268- ret = regmap_raw_read (state -> regmap , 0x4908 ,
2269- & table_length , sizeof (table_length ));
2274+ ret = regmap_raw_read (state -> regmap , DS5_HWMC_RESP_LEN ,
2275+ & table_length , sizeof (table_length )); /* Read response length */
22702276
22712277 // read table
2272- ds5_raw_read_with_check (state , 0x4900 , cmd -> Data , table_length );
2278+ ds5_raw_read_with_check (state , DS5_HWMC_DATA , cmd -> Data , table_length ); /* Read table data */
22732279
22742280 // first 4 bytes are opcode HWM, not part of calibration table
22752281 memcpy (table , cmd -> Data + 4 , length );
@@ -2286,13 +2292,13 @@ static int ds5_gvd(struct ds5 *state, unsigned char *data)
22862292 u8 retries = 3 ;
22872293
22882294 memcpy (& cmd , & gvd , sizeof (gvd ));
2289- ds5_raw_write_with_check (state , 0x4900 , & cmd , sizeof (cmd ));
2290- ds5_write_with_check (state , 0x490c , 0x01 ); /* execute cmd */
2295+ ds5_raw_write_with_check (state , DS5_HWMC_DATA , & cmd , sizeof (cmd )); /* Write command data */
2296+ ds5_write_with_check (state , DS5_HWMC_EXEC , 0x01 ); /* execute cmd */
22912297 do {
22922298 if (retries != 3 )
22932299 msleep_range (10 );
22942300
2295- ret = ds5_read (state , 0x4904 , & status );
2301+ ret = ds5_read (state , DS5_HWMC_STATUS , & status );
22962302 } while (ret && retries -- && status != 0 );
22972303
22982304 if (ret || status != 0 ) {
@@ -2302,8 +2308,8 @@ static int ds5_gvd(struct ds5 *state, unsigned char *data)
23022308 return status ;
23032309 }
23042310
2305- ret = regmap_raw_read (state -> regmap , 0x4908 , & length , sizeof (length ));
2306- ds5_raw_read_with_check (state , 0x4900 , data , length );
2311+ ret = regmap_raw_read (state -> regmap , DS5_HWMC_RESP_LEN , & length , sizeof (length )); /* Read response length */
2312+ ds5_raw_read_with_check (state , DS5_HWMC_DATA , data , length ); /* Read response data */
23072313
23082314 return ret ;
23092315}
@@ -2418,19 +2424,19 @@ static int ds5_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
24182424 // 1. prepare and send command
24192425 // 2. send command
24202426 // 3. execute command
2421- // 4. wait for ccompletion
2422- ret = regmap_raw_write (state -> regmap , 0x4900 ,
2427+ // 4. wait for completion
2428+ ret = regmap_raw_write (state -> regmap , DS5_HWMC_DATA , /* Write command data */
24232429 log_prepare , sizeof (log_prepare ));
24242430 if (ret < 0 )
24252431 return ret ;
24262432
2427- ret = regmap_raw_write (state -> regmap , 0x490C ,
2428- & execute_cmd , sizeof (execute_cmd ));
2433+ ret = regmap_raw_write (state -> regmap , DS5_HWMC_EXEC ,
2434+ & execute_cmd , sizeof (execute_cmd )); /* execute cmd */
24292435 if (ret < 0 )
24302436 return ret ;
24312437
24322438 for (i = 0 ; i < DS5_MAX_LOG_POLL ; i ++ ) {
2433- ret = regmap_raw_read (state -> regmap , 0x4904 ,
2439+ ret = regmap_raw_read (state -> regmap , DS5_HWMC_STATUS ,
24342440 & data , sizeof (data ));
24352441 dev_dbg (& state -> client -> dev , "%s(): log ready 0x%x\n" ,
24362442 __func__ , data );
@@ -2444,15 +2450,15 @@ static int ds5_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
24442450// if (i == DS5_MAX_LOG_POLL)
24452451// return -ETIMEDOUT;
24462452
2447- ret = regmap_raw_read (state -> regmap , 0x4908 , & data , sizeof (data ));
2453+ ret = regmap_raw_read (state -> regmap , DS5_HWMC_RESP_LEN , & data , sizeof (data )); /* Read response length */
24482454 dev_dbg (& state -> client -> dev , "%s(): log size 0x%x\n" , __func__ , data );
24492455 if (ret < 0 )
24502456 return ret ;
24512457 if (!data )
24522458 return 0 ;
24532459 if (data > 1024 )
24542460 return - ENOBUFS ;
2455- ret = regmap_raw_read (state -> regmap , 0x4900 ,
2461+ ret = regmap_raw_read (state -> regmap , DS5_HWMC_DATA ,
24562462 ctrl -> p_new .p_u8 , data );
24572463 break ;
24582464 case DS5_CAMERA_DEPTH_CALIBRATION_TABLE_GET :
@@ -4731,9 +4737,9 @@ static int ds5_dfu_switch_to_dfu(struct ds5 *state)
47314737 int i = DS5_START_MAX_COUNT ;
47324738 u16 status ;
47334739
4734- ds5_raw_write_with_check (state , 0x4900 ,
4735- & cmd_switch_to_dfu , sizeof (cmd_switch_to_dfu ));
4736- ds5_write_with_check (state , 0x490c , 0x01 ); /* execute cmd */
4740+ ds5_raw_write_with_check (state , DS5_HWMC_DATA ,
4741+ & cmd_switch_to_dfu , sizeof (cmd_switch_to_dfu )); /* Write command data */
4742+ ds5_write_with_check (state , DS5_HWMC_EXEC , 0x01 ); /* execute cmd */
47374743 /*Wait for DFU fw to boot*/
47384744 do {
47394745 msleep_range (DS5_START_POLL_TIME * 10 );
0 commit comments