xref: /linux/arch/mips/alchemy/common/vss.c (revision 58e16d792a6a8c6b750f637a4649967fcac853dc)
1*457c8996SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2809f36c6SManuel Lauss /*
3809f36c6SManuel Lauss  * Au1300 media block power gating (VSS)
4809f36c6SManuel Lauss  *
5809f36c6SManuel Lauss  * This is a stop-gap solution until I have the clock framework integration
6809f36c6SManuel Lauss  * ready. This stuff here really must be handled transparently when clocks
7809f36c6SManuel Lauss  * for various media blocks are enabled/disabled.
8809f36c6SManuel Lauss  */
9809f36c6SManuel Lauss 
1026dd3e4fSPaul Gortmaker #include <linux/export.h>
11809f36c6SManuel Lauss #include <linux/spinlock.h>
12809f36c6SManuel Lauss #include <asm/mach-au1x00/au1000.h>
13809f36c6SManuel Lauss 
14809f36c6SManuel Lauss #define VSS_GATE	0x00	/* gate wait timers */
15809f36c6SManuel Lauss #define VSS_CLKRST	0x04	/* clock/block control */
16809f36c6SManuel Lauss #define VSS_FTR		0x08	/* footers */
17809f36c6SManuel Lauss 
18809f36c6SManuel Lauss #define VSS_ADDR(blk)	(KSEG1ADDR(AU1300_VSS_PHYS_ADDR) + (blk * 0x0c))
19809f36c6SManuel Lauss 
20809f36c6SManuel Lauss static DEFINE_SPINLOCK(au1300_vss_lock);
21809f36c6SManuel Lauss 
22809f36c6SManuel Lauss /* enable a block as outlined in the databook */
__enable_block(int block)23809f36c6SManuel Lauss static inline void __enable_block(int block)
24809f36c6SManuel Lauss {
25809f36c6SManuel Lauss 	void __iomem *base = (void __iomem *)VSS_ADDR(block);
26809f36c6SManuel Lauss 
27809f36c6SManuel Lauss 	__raw_writel(3, base + VSS_CLKRST);	/* enable clock, assert reset */
28809f36c6SManuel Lauss 	wmb();
29809f36c6SManuel Lauss 
30809f36c6SManuel Lauss 	__raw_writel(0x01fffffe, base + VSS_GATE); /* maximum setup time */
31809f36c6SManuel Lauss 	wmb();
32809f36c6SManuel Lauss 
33809f36c6SManuel Lauss 	/* enable footers in sequence */
34809f36c6SManuel Lauss 	__raw_writel(0x01, base + VSS_FTR);
35809f36c6SManuel Lauss 	wmb();
36809f36c6SManuel Lauss 	__raw_writel(0x03, base + VSS_FTR);
37809f36c6SManuel Lauss 	wmb();
38809f36c6SManuel Lauss 	__raw_writel(0x07, base + VSS_FTR);
39809f36c6SManuel Lauss 	wmb();
40809f36c6SManuel Lauss 	__raw_writel(0x0f, base + VSS_FTR);
41809f36c6SManuel Lauss 	wmb();
42809f36c6SManuel Lauss 
43809f36c6SManuel Lauss 	__raw_writel(0x01ffffff, base + VSS_GATE); /* start FSM too */
44809f36c6SManuel Lauss 	wmb();
45809f36c6SManuel Lauss 
46809f36c6SManuel Lauss 	__raw_writel(2, base + VSS_CLKRST);	/* deassert reset */
47809f36c6SManuel Lauss 	wmb();
48809f36c6SManuel Lauss 
49809f36c6SManuel Lauss 	__raw_writel(0x1f, base + VSS_FTR);	/* enable isolation cells */
50809f36c6SManuel Lauss 	wmb();
51809f36c6SManuel Lauss }
52809f36c6SManuel Lauss 
53809f36c6SManuel Lauss /* disable a block as outlined in the databook */
__disable_block(int block)54809f36c6SManuel Lauss static inline void __disable_block(int block)
55809f36c6SManuel Lauss {
56809f36c6SManuel Lauss 	void __iomem *base = (void __iomem *)VSS_ADDR(block);
57809f36c6SManuel Lauss 
58809f36c6SManuel Lauss 	__raw_writel(0x0f, base + VSS_FTR);	/* disable isolation cells */
59809f36c6SManuel Lauss 	wmb();
60809f36c6SManuel Lauss 	__raw_writel(0, base + VSS_GATE);	/* disable FSM */
61809f36c6SManuel Lauss 	wmb();
62809f36c6SManuel Lauss 	__raw_writel(3, base + VSS_CLKRST);	/* assert reset */
63809f36c6SManuel Lauss 	wmb();
64809f36c6SManuel Lauss 	__raw_writel(1, base + VSS_CLKRST);	/* disable clock */
65809f36c6SManuel Lauss 	wmb();
66809f36c6SManuel Lauss 	__raw_writel(0, base + VSS_FTR);	/* disable all footers */
67809f36c6SManuel Lauss 	wmb();
68809f36c6SManuel Lauss }
69809f36c6SManuel Lauss 
au1300_vss_block_control(int block,int enable)70809f36c6SManuel Lauss void au1300_vss_block_control(int block, int enable)
71809f36c6SManuel Lauss {
72809f36c6SManuel Lauss 	unsigned long flags;
73809f36c6SManuel Lauss 
74809f36c6SManuel Lauss 	if (alchemy_get_cputype() != ALCHEMY_CPU_AU1300)
75809f36c6SManuel Lauss 		return;
76809f36c6SManuel Lauss 
77809f36c6SManuel Lauss 	/* only one block at a time */
78809f36c6SManuel Lauss 	spin_lock_irqsave(&au1300_vss_lock, flags);
79809f36c6SManuel Lauss 	if (enable)
80809f36c6SManuel Lauss 		__enable_block(block);
81809f36c6SManuel Lauss 	else
82809f36c6SManuel Lauss 		__disable_block(block);
83809f36c6SManuel Lauss 	spin_unlock_irqrestore(&au1300_vss_lock, flags);
84809f36c6SManuel Lauss }
85809f36c6SManuel Lauss EXPORT_SYMBOL_GPL(au1300_vss_block_control);
86