11
11
12
12
#include <linux/clk.h>
13
13
#include <linux/clk/tegra.h>
14
- #include <linux/completion.h>
15
14
#include <linux/debugfs.h>
16
15
#include <linux/delay.h>
17
16
#include <linux/err.h>
@@ -327,7 +326,6 @@ struct emc_timing {
327
326
struct tegra_emc {
328
327
struct device * dev ;
329
328
struct tegra_mc * mc ;
330
- struct completion clk_handshake_complete ;
331
329
struct notifier_block clk_nb ;
332
330
struct clk * clk ;
333
331
void __iomem * regs ;
@@ -374,52 +372,10 @@ static int emc_seq_update_timing(struct tegra_emc *emc)
374
372
return 0 ;
375
373
}
376
374
377
- static void emc_complete_clk_change (struct tegra_emc * emc )
378
- {
379
- struct emc_timing * timing = emc -> new_timing ;
380
- unsigned int dram_num ;
381
- bool failed = false;
382
- int err ;
383
-
384
- /* re-enable auto-refresh */
385
- dram_num = tegra_mc_get_emem_device_count (emc -> mc );
386
- writel_relaxed (EMC_REFCTRL_ENABLE_ALL (dram_num ),
387
- emc -> regs + EMC_REFCTRL );
388
-
389
- /* restore auto-calibration */
390
- if (emc -> vref_cal_toggle )
391
- writel_relaxed (timing -> emc_auto_cal_interval ,
392
- emc -> regs + EMC_AUTO_CAL_INTERVAL );
393
-
394
- /* restore dynamic self-refresh */
395
- if (timing -> emc_cfg_dyn_self_ref ) {
396
- emc -> emc_cfg |= EMC_CFG_DYN_SREF_ENABLE ;
397
- writel_relaxed (emc -> emc_cfg , emc -> regs + EMC_CFG );
398
- }
399
-
400
- /* set number of clocks to wait after each ZQ command */
401
- if (emc -> zcal_long )
402
- writel_relaxed (timing -> emc_zcal_cnt_long ,
403
- emc -> regs + EMC_ZCAL_WAIT_CNT );
404
-
405
- /* wait for writes to settle */
406
- udelay (2 );
407
-
408
- /* update restored timing */
409
- err = emc_seq_update_timing (emc );
410
- if (err )
411
- failed = true;
412
-
413
- /* restore early ACK */
414
- mc_writel (emc -> mc , emc -> mc_override , MC_EMEM_ARB_OVERRIDE );
415
-
416
- WRITE_ONCE (emc -> bad_state , failed );
417
- }
418
-
419
375
static irqreturn_t tegra_emc_isr (int irq , void * data )
420
376
{
421
377
struct tegra_emc * emc = data ;
422
- u32 intmask = EMC_REFRESH_OVERFLOW_INT | EMC_CLKCHANGE_COMPLETE_INT ;
378
+ u32 intmask = EMC_REFRESH_OVERFLOW_INT ;
423
379
u32 status ;
424
380
425
381
status = readl_relaxed (emc -> regs + EMC_INTSTATUS ) & intmask ;
@@ -434,18 +390,6 @@ static irqreturn_t tegra_emc_isr(int irq, void *data)
434
390
/* clear interrupts */
435
391
writel_relaxed (status , emc -> regs + EMC_INTSTATUS );
436
392
437
- /* notify about EMC-CAR handshake completion */
438
- if (status & EMC_CLKCHANGE_COMPLETE_INT ) {
439
- if (completion_done (& emc -> clk_handshake_complete )) {
440
- dev_err_ratelimited (emc -> dev ,
441
- "bogus handshake interrupt\n" );
442
- return IRQ_NONE ;
443
- }
444
-
445
- emc_complete_clk_change (emc );
446
- complete (& emc -> clk_handshake_complete );
447
- }
448
-
449
393
return IRQ_HANDLED ;
450
394
}
451
395
@@ -801,29 +745,58 @@ static int emc_prepare_timing_change(struct tegra_emc *emc, unsigned long rate)
801
745
*/
802
746
mc_readl (emc -> mc , MC_EMEM_ARB_OVERRIDE );
803
747
804
- reinit_completion (& emc -> clk_handshake_complete );
805
-
806
- emc -> new_timing = timing ;
807
-
808
748
return 0 ;
809
749
}
810
750
811
751
static int emc_complete_timing_change (struct tegra_emc * emc ,
812
752
unsigned long rate )
813
753
{
814
- unsigned long timeout ;
754
+ struct emc_timing * timing = emc_find_timing (emc , rate );
755
+ unsigned int dram_num ;
756
+ int err ;
757
+ u32 v ;
815
758
816
- timeout = wait_for_completion_timeout (& emc -> clk_handshake_complete ,
817
- msecs_to_jiffies (100 ));
818
- if (timeout == 0 ) {
819
- dev_err (emc -> dev , "emc-car handshake failed\n" );
820
- return - EIO ;
759
+ err = readl_relaxed_poll_timeout_atomic (emc -> regs + EMC_INTSTATUS , v ,
760
+ v & EMC_CLKCHANGE_COMPLETE_INT ,
761
+ 1 , 100 );
762
+ if (err ) {
763
+ dev_err (emc -> dev , "emc-car handshake timeout: %d\n" , err );
764
+ return err ;
821
765
}
822
766
823
- if (READ_ONCE (emc -> bad_state ))
824
- return - EIO ;
767
+ /* re-enable auto-refresh */
768
+ dram_num = tegra_mc_get_emem_device_count (emc -> mc );
769
+ writel_relaxed (EMC_REFCTRL_ENABLE_ALL (dram_num ),
770
+ emc -> regs + EMC_REFCTRL );
771
+
772
+ /* restore auto-calibration */
773
+ if (emc -> vref_cal_toggle )
774
+ writel_relaxed (timing -> emc_auto_cal_interval ,
775
+ emc -> regs + EMC_AUTO_CAL_INTERVAL );
825
776
826
- return 0 ;
777
+ /* restore dynamic self-refresh */
778
+ if (timing -> emc_cfg_dyn_self_ref ) {
779
+ emc -> emc_cfg |= EMC_CFG_DYN_SREF_ENABLE ;
780
+ writel_relaxed (emc -> emc_cfg , emc -> regs + EMC_CFG );
781
+ }
782
+
783
+ /* set number of clocks to wait after each ZQ command */
784
+ if (emc -> zcal_long )
785
+ writel_relaxed (timing -> emc_zcal_cnt_long ,
786
+ emc -> regs + EMC_ZCAL_WAIT_CNT );
787
+
788
+ /* wait for writes to settle */
789
+ udelay (2 );
790
+
791
+ /* update restored timing */
792
+ err = emc_seq_update_timing (emc );
793
+ if (!err )
794
+ emc -> bad_state = false;
795
+
796
+ /* restore early ACK */
797
+ mc_writel (emc -> mc , emc -> mc_override , MC_EMEM_ARB_OVERRIDE );
798
+
799
+ return err ;
827
800
}
828
801
829
802
static int emc_unprepare_timing_change (struct tegra_emc * emc ,
@@ -1033,7 +1006,7 @@ static struct device_node *emc_find_node_by_ram_code(struct device *dev)
1033
1006
1034
1007
static int emc_setup_hw (struct tegra_emc * emc )
1035
1008
{
1036
- u32 intmask = EMC_REFRESH_OVERFLOW_INT | EMC_CLKCHANGE_COMPLETE_INT ;
1009
+ u32 intmask = EMC_REFRESH_OVERFLOW_INT ;
1037
1010
u32 fbio_cfg5 , emc_cfg , emc_dbg ;
1038
1011
enum emc_dram_type dram_type ;
1039
1012
@@ -1321,7 +1294,6 @@ static int tegra_emc_probe(struct platform_device *pdev)
1321
1294
if (!emc -> mc )
1322
1295
return - EPROBE_DEFER ;
1323
1296
1324
- init_completion (& emc -> clk_handshake_complete );
1325
1297
emc -> clk_nb .notifier_call = emc_clk_change_notify ;
1326
1298
emc -> dev = & pdev -> dev ;
1327
1299
0 commit comments