Merge remote-tracking branch 'regulator/fix/doc' into regulator-enable-invert
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-s3c24xx / s3c2410.c
1 /* linux/arch/arm/mach-s3c2410/s3c2410.c
2  *
3  * Copyright (c) 2003-2005 Simtec Electronics
4  *      Ben Dooks <ben@simtec.co.uk>
5  *
6  * http://www.simtec.co.uk/products/EB2410ITX/
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11 */
12
13 #include <linux/kernel.h>
14 #include <linux/types.h>
15 #include <linux/interrupt.h>
16 #include <linux/list.h>
17 #include <linux/timer.h>
18 #include <linux/init.h>
19 #include <linux/gpio.h>
20 #include <linux/clk.h>
21 #include <linux/device.h>
22 #include <linux/syscore_ops.h>
23 #include <linux/serial_core.h>
24 #include <linux/platform_device.h>
25 #include <linux/io.h>
26
27 #include <asm/mach/arch.h>
28 #include <asm/mach/map.h>
29 #include <asm/mach/irq.h>
30
31 #include <mach/hardware.h>
32 #include <asm/irq.h>
33 #include <asm/system_misc.h>
34
35 #include <plat/cpu-freq.h>
36
37 #include <mach/regs-clock.h>
38 #include <plat/regs-serial.h>
39
40 #include <plat/s3c2410.h>
41 #include <plat/cpu.h>
42 #include <plat/devs.h>
43 #include <plat/clock.h>
44 #include <plat/pll.h>
45 #include <plat/pm.h>
46 #include <plat/watchdog-reset.h>
47
48 #include <plat/gpio-core.h>
49 #include <plat/gpio-cfg.h>
50 #include <plat/gpio-cfg-helpers.h>
51
52 #include "common.h"
53
54 /* Initial IO mappings */
55
56 static struct map_desc s3c2410_iodesc[] __initdata = {
57         IODESC_ENT(CLKPWR),
58         IODESC_ENT(TIMER),
59         IODESC_ENT(WATCHDOG),
60 };
61
62 /* our uart devices */
63
64 /* uart registration process */
65
66 void __init s3c2410_init_uarts(struct s3c2410_uartcfg *cfg, int no)
67 {
68         s3c24xx_init_uartdevs("s3c2410-uart", s3c2410_uart_resources, cfg, no);
69 }
70
71 /* s3c2410_map_io
72  *
73  * register the standard cpu IO areas, and any passed in from the
74  * machine specific initialisation.
75 */
76
77 void __init s3c2410_map_io(void)
78 {
79         s3c24xx_gpiocfg_default.set_pull = s3c24xx_gpio_setpull_1up;
80         s3c24xx_gpiocfg_default.get_pull = s3c24xx_gpio_getpull_1up;
81
82         iotable_init(s3c2410_iodesc, ARRAY_SIZE(s3c2410_iodesc));
83 }
84
85 void __init_or_cpufreq s3c2410_setup_clocks(void)
86 {
87         struct clk *xtal_clk;
88         unsigned long tmp;
89         unsigned long xtal;
90         unsigned long fclk;
91         unsigned long hclk;
92         unsigned long pclk;
93
94         xtal_clk = clk_get(NULL, "xtal");
95         xtal = clk_get_rate(xtal_clk);
96         clk_put(xtal_clk);
97
98         /* now we've got our machine bits initialised, work out what
99          * clocks we've got */
100
101         fclk = s3c24xx_get_pll(__raw_readl(S3C2410_MPLLCON), xtal);
102
103         tmp = __raw_readl(S3C2410_CLKDIVN);
104
105         /* work out clock scalings */
106
107         hclk = fclk / ((tmp & S3C2410_CLKDIVN_HDIVN) ? 2 : 1);
108         pclk = hclk / ((tmp & S3C2410_CLKDIVN_PDIVN) ? 2 : 1);
109
110         /* print brieft summary of clocks, etc */
111
112         printk("S3C2410: core %ld.%03ld MHz, memory %ld.%03ld MHz, peripheral %ld.%03ld MHz\n",
113                print_mhz(fclk), print_mhz(hclk), print_mhz(pclk));
114
115         /* initialise the clocks here, to allow other things like the
116          * console to use them
117          */
118
119         s3c24xx_setup_clocks(fclk, hclk, pclk);
120 }
121
122 /* fake ARMCLK for use with cpufreq, etc. */
123
124 static struct clk s3c2410_armclk = {
125         .name   = "armclk",
126         .parent = &clk_f,
127         .id     = -1,
128 };
129
130 static struct clk_lookup s3c2410_clk_lookup[] = {
131         CLKDEV_INIT(NULL, "clk_uart_baud0", &clk_p),
132         CLKDEV_INIT(NULL, "clk_uart_baud1", &s3c24xx_uclk),
133 };
134
135 void __init s3c2410_init_clocks(int xtal)
136 {
137         s3c24xx_register_baseclocks(xtal);
138         s3c2410_setup_clocks();
139         s3c2410_baseclk_add();
140         s3c24xx_register_clock(&s3c2410_armclk);
141         clkdev_add_table(s3c2410_clk_lookup, ARRAY_SIZE(s3c2410_clk_lookup));
142 }
143
144 struct bus_type s3c2410_subsys = {
145         .name = "s3c2410-core",
146         .dev_name = "s3c2410-core",
147 };
148
149 /* Note, we would have liked to name this s3c2410-core, but we cannot
150  * register two subsystems with the same name.
151  */
152 struct bus_type s3c2410a_subsys = {
153         .name = "s3c2410a-core",
154         .dev_name = "s3c2410a-core",
155 };
156
157 static struct device s3c2410_dev = {
158         .bus            = &s3c2410_subsys,
159 };
160
161 /* need to register the subsystem before we actually register the device, and
162  * we also need to ensure that it has been initialised before any of the
163  * drivers even try to use it (even if not on an s3c2410 based system)
164  * as a driver which may support both 2410 and 2440 may try and use it.
165 */
166
167 static int __init s3c2410_core_init(void)
168 {
169         return subsys_system_register(&s3c2410_subsys, NULL);
170 }
171
172 core_initcall(s3c2410_core_init);
173
174 static int __init s3c2410a_core_init(void)
175 {
176         return subsys_system_register(&s3c2410a_subsys, NULL);
177 }
178
179 core_initcall(s3c2410a_core_init);
180
181 int __init s3c2410_init(void)
182 {
183         printk("S3C2410: Initialising architecture\n");
184
185 #ifdef CONFIG_PM
186         register_syscore_ops(&s3c2410_pm_syscore_ops);
187         register_syscore_ops(&s3c24xx_irq_syscore_ops);
188 #endif
189
190         return device_register(&s3c2410_dev);
191 }
192
193 int __init s3c2410a_init(void)
194 {
195         s3c2410_dev.bus = &s3c2410a_subsys;
196         return s3c2410_init();
197 }
198
199 void s3c2410_restart(char mode, const char *cmd)
200 {
201         if (mode == 's') {
202                 soft_restart(0);
203         }
204
205         arch_wdt_reset();
206
207         /* we'll take a jump through zero as a poor second */
208         soft_restart(0);
209 }