@@ -105,6 +105,8 @@ struct riic_dev {
105
105
struct completion msg_done ;
106
106
struct i2c_adapter adapter ;
107
107
struct clk * clk ;
108
+ struct reset_control * rstc ;
109
+ struct i2c_timings i2c_t ;
108
110
};
109
111
110
112
struct riic_irq_desc {
@@ -302,11 +304,12 @@ static const struct i2c_algorithm riic_algo = {
302
304
.functionality = riic_func ,
303
305
};
304
306
305
- static int riic_init_hw (struct riic_dev * riic , struct i2c_timings * t )
307
+ static int riic_init_hw (struct riic_dev * riic )
306
308
{
307
309
int ret ;
308
310
unsigned long rate ;
309
311
int total_ticks , cks , brl , brh ;
312
+ struct i2c_timings * t = & riic -> i2c_t ;
310
313
struct device * dev = riic -> adapter .dev .parent ;
311
314
312
315
if (t -> bus_freq_hz > I2C_MAX_FAST_MODE_FREQ ) {
@@ -423,8 +426,6 @@ static int riic_i2c_probe(struct platform_device *pdev)
423
426
struct device * dev = & pdev -> dev ;
424
427
struct riic_dev * riic ;
425
428
struct i2c_adapter * adap ;
426
- struct i2c_timings i2c_t ;
427
- struct reset_control * rstc ;
428
429
int i , ret ;
429
430
430
431
riic = devm_kzalloc (dev , sizeof (* riic ), GFP_KERNEL );
@@ -441,16 +442,16 @@ static int riic_i2c_probe(struct platform_device *pdev)
441
442
return PTR_ERR (riic -> clk );
442
443
}
443
444
444
- rstc = devm_reset_control_get_optional_exclusive (dev , NULL );
445
- if (IS_ERR (rstc ))
446
- return dev_err_probe (dev , PTR_ERR (rstc ),
445
+ riic -> rstc = devm_reset_control_get_optional_exclusive (dev , NULL );
446
+ if (IS_ERR (riic -> rstc ))
447
+ return dev_err_probe (dev , PTR_ERR (riic -> rstc ),
447
448
"Error: missing reset ctrl\n" );
448
449
449
- ret = reset_control_deassert (rstc );
450
+ ret = reset_control_deassert (riic -> rstc );
450
451
if (ret )
451
452
return ret ;
452
453
453
- ret = devm_add_action_or_reset (dev , riic_reset_control_assert , rstc );
454
+ ret = devm_add_action_or_reset (dev , riic_reset_control_assert , riic -> rstc );
454
455
if (ret )
455
456
return ret ;
456
457
@@ -479,14 +480,14 @@ static int riic_i2c_probe(struct platform_device *pdev)
479
480
480
481
init_completion (& riic -> msg_done );
481
482
482
- i2c_parse_fw_timings (dev , & i2c_t , true);
483
+ i2c_parse_fw_timings (dev , & riic -> i2c_t , true);
483
484
484
485
/* Default 0 to save power. Can be overridden via sysfs for lower latency. */
485
486
pm_runtime_set_autosuspend_delay (dev , 0 );
486
487
pm_runtime_use_autosuspend (dev );
487
488
pm_runtime_enable (dev );
488
489
489
- ret = riic_init_hw (riic , & i2c_t );
490
+ ret = riic_init_hw (riic );
490
491
if (ret )
491
492
goto out ;
492
493
@@ -496,7 +497,7 @@ static int riic_i2c_probe(struct platform_device *pdev)
496
497
497
498
platform_set_drvdata (pdev , riic );
498
499
499
- dev_info (dev , "registered with %dHz bus speed\n" , i2c_t .bus_freq_hz );
500
+ dev_info (dev , "registered with %dHz bus speed\n" , riic -> i2c_t .bus_freq_hz );
500
501
return 0 ;
501
502
502
503
out :
@@ -553,6 +554,55 @@ static const struct riic_of_data riic_rz_v2h_info = {
553
554
},
554
555
};
555
556
557
+ static int riic_i2c_suspend (struct device * dev )
558
+ {
559
+ struct riic_dev * riic = dev_get_drvdata (dev );
560
+ int ret ;
561
+
562
+ ret = pm_runtime_resume_and_get (dev );
563
+ if (ret )
564
+ return ret ;
565
+
566
+ i2c_mark_adapter_suspended (& riic -> adapter );
567
+
568
+ /* Disable output on SDA, SCL pins. */
569
+ riic_clear_set_bit (riic , ICCR1_ICE , 0 , RIIC_ICCR1 );
570
+
571
+ pm_runtime_mark_last_busy (dev );
572
+ pm_runtime_put_sync (dev );
573
+
574
+ return reset_control_assert (riic -> rstc );
575
+ }
576
+
577
+ static int riic_i2c_resume (struct device * dev )
578
+ {
579
+ struct riic_dev * riic = dev_get_drvdata (dev );
580
+ int ret ;
581
+
582
+ ret = reset_control_deassert (riic -> rstc );
583
+ if (ret )
584
+ return ret ;
585
+
586
+ ret = riic_init_hw (riic );
587
+ if (ret ) {
588
+ /*
589
+ * In case this happens there is no way to recover from this
590
+ * state. The driver will remain loaded. We want to avoid
591
+ * keeping the reset line de-asserted for no reason.
592
+ */
593
+ reset_control_assert (riic -> rstc );
594
+ return ret ;
595
+ }
596
+
597
+ i2c_mark_adapter_resumed (& riic -> adapter );
598
+
599
+ return 0 ;
600
+ }
601
+
602
+ static const struct dev_pm_ops riic_i2c_pm_ops = {
603
+ SYSTEM_SLEEP_PM_OPS (riic_i2c_suspend , riic_i2c_resume )
604
+ };
605
+
556
606
static const struct of_device_id riic_i2c_dt_ids [] = {
557
607
{ .compatible = "renesas,riic-rz" , .data = & riic_rz_a_info },
558
608
{ .compatible = "renesas,riic-r9a09g057" , .data = & riic_rz_v2h_info },
@@ -565,6 +615,7 @@ static struct platform_driver riic_i2c_driver = {
565
615
.driver = {
566
616
.name = "i2c-riic" ,
567
617
.of_match_table = riic_i2c_dt_ids ,
618
+ .pm = pm_ptr (& riic_i2c_pm_ops ),
568
619
},
569
620
};
570
621
0 commit comments