@@ -92,6 +92,7 @@ struct lpspi_config {
92
92
u8 prescale ;
93
93
u16 mode ;
94
94
u32 speed_hz ;
95
+ u32 effective_speed_hz ;
95
96
};
96
97
97
98
struct fsl_lpspi_data {
@@ -315,9 +316,10 @@ static void fsl_lpspi_set_watermark(struct fsl_lpspi_data *fsl_lpspi)
315
316
static int fsl_lpspi_set_bitrate (struct fsl_lpspi_data * fsl_lpspi )
316
317
{
317
318
struct lpspi_config config = fsl_lpspi -> config ;
318
- unsigned int perclk_rate , scldiv , div ;
319
+ unsigned int perclk_rate , div ;
319
320
u8 prescale_max ;
320
321
u8 prescale ;
322
+ int scldiv ;
321
323
322
324
perclk_rate = clk_get_rate (fsl_lpspi -> clk_per );
323
325
prescale_max = fsl_lpspi -> devtype_data -> prescale_max ;
@@ -338,19 +340,22 @@ static int fsl_lpspi_set_bitrate(struct fsl_lpspi_data *fsl_lpspi)
338
340
339
341
for (prescale = 0 ; prescale <= prescale_max ; prescale ++ ) {
340
342
scldiv = div / (1 << prescale ) - 2 ;
341
- if (scldiv < 256 ) {
343
+ if (scldiv >= 0 && scldiv < 256 ) {
342
344
fsl_lpspi -> config .prescale = prescale ;
343
345
break ;
344
346
}
345
347
}
346
348
347
- if (scldiv >= 256 )
349
+ if (scldiv < 0 || scldiv >= 256 )
348
350
return - EINVAL ;
349
351
350
352
writel (scldiv | (scldiv << 8 ) | ((scldiv >> 1 ) << 16 ),
351
353
fsl_lpspi -> base + IMX7ULP_CCR );
352
354
353
- dev_dbg (fsl_lpspi -> dev , "perclk=%d, speed=%d, prescale=%d, scldiv=%d\n" ,
355
+ fsl_lpspi -> config .effective_speed_hz = perclk_rate / (scldiv + 2 ) *
356
+ (1 << prescale );
357
+
358
+ dev_dbg (fsl_lpspi -> dev , "perclk=%u, speed=%u, prescale=%u, scldiv=%d\n" ,
354
359
perclk_rate , config .speed_hz , prescale , scldiv );
355
360
356
361
return 0 ;
@@ -749,6 +754,8 @@ static int fsl_lpspi_transfer_one(struct spi_controller *controller,
749
754
if (ret < 0 )
750
755
return ret ;
751
756
757
+ t -> effective_speed_hz = fsl_lpspi -> config .effective_speed_hz ;
758
+
752
759
fsl_lpspi_set_cmd (fsl_lpspi );
753
760
fsl_lpspi -> is_first_byte = false;
754
761
0 commit comments