2 * Freescale STMP37XX/STMP378X core routines
4 * Embedded Alley Solutions, Inc <source@embeddedalley.com>
6 * Copyright 2008 Freescale Semiconductor, Inc. All Rights Reserved.
7 * Copyright 2008 Embedded Alley Solutions, Inc All Rights Reserved.
11 * The code contained herein is licensed under the GNU General Public
12 * License. You may obtain a copy of the GNU General Public License
13 * Version 2 or later at the following locations:
15 * http://www.opensource.org/licenses/gpl-license.html
16 * http://www.gnu.org/copyleft/gpl.html
18 #include <linux/kernel.h>
19 #include <linux/init.h>
22 #include <mach/stmp3xxx.h>
23 #include <mach/platform.h>
25 #include <mach/regs-clkctrl.h>
27 static int __stmp3xxx_reset_block(void __iomem
*hwreg
, int just_enable
)
32 /* the process of software reset of IP block is done
35 - clear SFTRST and wait for block is enabled;
36 - clear clock gating (CLKGATE bit);
37 - set the SFTRST again and wait for block is in reset;
38 - clear SFTRST and wait for reset completion.
40 c
= __raw_readl(hwreg
);
41 c
&= ~(1<<31); /* clear SFTRST */
42 __raw_writel(c
, hwreg
);
43 for (timeout
= 1000000; timeout
> 0; timeout
--)
44 /* still in SFTRST state ? */
45 if ((__raw_readl(hwreg
) & (1<<31)) == 0)
48 printk(KERN_ERR
"%s(%p): timeout when enabling\n",
53 c
= __raw_readl(hwreg
);
54 c
&= ~(1<<30); /* clear CLKGATE */
55 __raw_writel(c
, hwreg
);
58 c
= __raw_readl(hwreg
);
59 c
|= (1<<31); /* now again set SFTRST */
60 __raw_writel(c
, hwreg
);
61 for (timeout
= 1000000; timeout
> 0; timeout
--)
62 /* poll until CLKGATE set */
63 if (__raw_readl(hwreg
) & (1<<30))
66 printk(KERN_ERR
"%s(%p): timeout when resetting\n",
71 c
= __raw_readl(hwreg
);
72 c
&= ~(1<<31); /* clear SFTRST */
73 __raw_writel(c
, hwreg
);
74 for (timeout
= 1000000; timeout
> 0; timeout
--)
75 /* still in SFTRST state ? */
76 if ((__raw_readl(hwreg
) & (1<<31)) == 0)
79 printk(KERN_ERR
"%s(%p): timeout when enabling "
80 "after reset\n", __func__
, hwreg
);
84 c
= __raw_readl(hwreg
);
85 c
&= ~(1<<30); /* clear CLKGATE */
86 __raw_writel(c
, hwreg
);
88 for (timeout
= 1000000; timeout
> 0; timeout
--)
89 /* still in SFTRST state ? */
90 if ((__raw_readl(hwreg
) & (1<<30)) == 0)
94 printk(KERN_ERR
"%s(%p): timeout when unclockgating\n",
102 int stmp3xxx_reset_block(void __iomem
*hwreg
, int just_enable
)
108 r
= __stmp3xxx_reset_block(hwreg
, just_enable
);
111 pr_debug("%s: try %d failed\n", __func__
, 10 - try);
115 EXPORT_SYMBOL(stmp3xxx_reset_block
);
117 struct platform_device stmp3xxx_dbguart
= {
118 .name
= "stmp3xxx-dbguart",
122 void __init
stmp3xxx_init(void)
124 /* Turn off auto-slow and other tricks */
125 stmp3xxx_clearl(0x7f00000, REGS_CLKCTRL_BASE
+ HW_CLKCTRL_HBUS
);