2 * R-Car SYSC Power management support
4 * Copyright (C) 2014 Magnus Damm
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
11 #include <linux/delay.h>
12 #include <linux/err.h>
14 #include <linux/spinlock.h>
16 #include <mach/pm-rcar.h>
18 static void __iomem
*rcar_sysc_base
;
25 #define PWRSR_OFFS 0x00
26 #define PWROFFCR_OFFS 0x04
27 #define PWRONCR_OFFS 0x0c
28 #define PWRER_OFFS 0x14
30 #define SYSCSR_RETRIES 100
31 #define SYSCSR_DELAY_US 1
33 #define SYSCISR_RETRIES 1000
34 #define SYSCISR_DELAY_US 1
36 #if defined(CONFIG_PM) || defined(CONFIG_SMP)
38 static DEFINE_SPINLOCK(rcar_sysc_lock
); /* SMP CPUs + I/O devices */
40 static int rcar_sysc_pwr_on_off(struct rcar_sysc_ch
*sysc_ch
,
41 int sr_bit
, int reg_offs
)
45 for (k
= 0; k
< SYSCSR_RETRIES
; k
++) {
46 if (ioread32(rcar_sysc_base
+ SYSCSR
) & (1 << sr_bit
))
48 udelay(SYSCSR_DELAY_US
);
51 if (k
== SYSCSR_RETRIES
)
54 iowrite32(1 << sysc_ch
->chan_bit
,
55 rcar_sysc_base
+ sysc_ch
->chan_offs
+ reg_offs
);
60 static int rcar_sysc_pwr_off(struct rcar_sysc_ch
*sysc_ch
)
62 return rcar_sysc_pwr_on_off(sysc_ch
, 0, PWROFFCR_OFFS
);
65 static int rcar_sysc_pwr_on(struct rcar_sysc_ch
*sysc_ch
)
67 return rcar_sysc_pwr_on_off(sysc_ch
, 1, PWRONCR_OFFS
);
70 static int rcar_sysc_update(struct rcar_sysc_ch
*sysc_ch
,
71 int (*on_off_fn
)(struct rcar_sysc_ch
*))
73 unsigned int isr_mask
= 1 << sysc_ch
->isr_bit
;
74 unsigned int chan_mask
= 1 << sysc_ch
->chan_bit
;
80 spin_lock_irqsave(&rcar_sysc_lock
, flags
);
82 iowrite32(isr_mask
, rcar_sysc_base
+ SYSCISCR
);
85 ret
= on_off_fn(sysc_ch
);
89 status
= ioread32(rcar_sysc_base
+
90 sysc_ch
->chan_offs
+ PWRER_OFFS
);
91 } while (status
& chan_mask
);
93 for (k
= 0; k
< SYSCISR_RETRIES
; k
++) {
94 if (ioread32(rcar_sysc_base
+ SYSCISR
) & isr_mask
)
96 udelay(SYSCISR_DELAY_US
);
99 if (k
== SYSCISR_RETRIES
)
102 iowrite32(isr_mask
, rcar_sysc_base
+ SYSCISCR
);
105 spin_unlock_irqrestore(&rcar_sysc_lock
, flags
);
107 pr_debug("sysc power domain %d: %08x -> %d\n",
108 sysc_ch
->isr_bit
, ioread32(rcar_sysc_base
+ SYSCISR
), ret
);
112 int rcar_sysc_power_down(struct rcar_sysc_ch
*sysc_ch
)
114 return rcar_sysc_update(sysc_ch
, rcar_sysc_pwr_off
);
117 int rcar_sysc_power_up(struct rcar_sysc_ch
*sysc_ch
)
119 return rcar_sysc_update(sysc_ch
, rcar_sysc_pwr_on
);
122 bool rcar_sysc_power_is_off(struct rcar_sysc_ch
*sysc_ch
)
126 st
= ioread32(rcar_sysc_base
+ sysc_ch
->chan_offs
+ PWRSR_OFFS
);
127 if (st
& (1 << sysc_ch
->chan_bit
))
133 void __iomem
*rcar_sysc_init(phys_addr_t base
)
135 rcar_sysc_base
= ioremap_nocache(base
, PAGE_SIZE
);
137 panic("unable to ioremap R-Car SYSC hardware block\n");
139 return rcar_sysc_base
;
142 #endif /* CONFIG_PM || CONFIG_SMP */
This page took 0.040248 seconds and 5 git commands to generate.