Merge tag 'stable/for-linus-3.14-rc2-tag' of git://git.kernel.org/pub/scm/linux/kerne...
[deliverable/linux.git] / arch / arm / plat-samsung / init.c
1 /* linux/arch/arm/plat-s3c/init.c
2 *
3 * Copyright (c) 2008 Simtec Electronics
4 * Ben Dooks <ben@simtec.co.uk>
5 * http://armlinux.simtec.co.uk/
6 *
7 * S3C series CPU initialisation
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14 /*
15 * NOTE: Code in this file is not used on S3C64xx when booting with
16 * Device Tree support.
17 */
18
19 #include <linux/init.h>
20 #include <linux/module.h>
21 #include <linux/interrupt.h>
22 #include <linux/ioport.h>
23 #include <linux/serial_core.h>
24 #include <linux/platform_device.h>
25 #include <linux/of.h>
26
27 #include <mach/hardware.h>
28
29 #include <asm/mach/arch.h>
30 #include <asm/mach/map.h>
31
32 #include <plat/cpu.h>
33 #include <plat/devs.h>
34 #include <plat/clock.h>
35
36 #include <plat/regs-serial.h>
37
38 static struct cpu_table *cpu;
39
40 static struct cpu_table * __init s3c_lookup_cpu(unsigned long idcode,
41 struct cpu_table *tab,
42 unsigned int count)
43 {
44 for (; count != 0; count--, tab++) {
45 if ((idcode & tab->idmask) == (tab->idcode & tab->idmask))
46 return tab;
47 }
48
49 return NULL;
50 }
51
52 void __init s3c_init_cpu(unsigned long idcode,
53 struct cpu_table *cputab, unsigned int cputab_size)
54 {
55 cpu = s3c_lookup_cpu(idcode, cputab, cputab_size);
56
57 if (cpu == NULL) {
58 printk(KERN_ERR "Unknown CPU type 0x%08lx\n", idcode);
59 panic("Unknown S3C24XX CPU");
60 }
61
62 printk("CPU %s (id 0x%08lx)\n", cpu->name, idcode);
63
64 if (cpu->init == NULL) {
65 printk(KERN_ERR "CPU %s support not enabled\n", cpu->name);
66 panic("Unsupported Samsung CPU");
67 }
68
69 if (cpu->map_io)
70 cpu->map_io();
71 }
72
73 /* s3c24xx_init_clocks
74 *
75 * Initialise the clock subsystem and associated information from the
76 * given master crystal value.
77 *
78 * xtal = 0 -> use default PLL crystal value (normally 12MHz)
79 * != 0 -> PLL crystal value in Hz
80 */
81
82 void __init s3c24xx_init_clocks(int xtal)
83 {
84 if (xtal == 0)
85 xtal = 12*1000*1000;
86
87 if (cpu == NULL)
88 panic("s3c24xx_init_clocks: no cpu setup?\n");
89
90 if (cpu->init_clocks == NULL)
91 panic("s3c24xx_init_clocks: cpu has no clock init\n");
92 else
93 (cpu->init_clocks)(xtal);
94 }
95
96 /* uart management */
97 #if IS_ENABLED(CONFIG_SAMSUNG_ATAGS)
98 static int nr_uarts __initdata = 0;
99
100 static struct s3c2410_uartcfg uart_cfgs[CONFIG_SERIAL_SAMSUNG_UARTS];
101
102 /* s3c24xx_init_uartdevs
103 *
104 * copy the specified platform data and configuration into our central
105 * set of devices, before the data is thrown away after the init process.
106 *
107 * This also fills in the array passed to the serial driver for the
108 * early initialisation of the console.
109 */
110
111 void __init s3c24xx_init_uartdevs(char *name,
112 struct s3c24xx_uart_resources *res,
113 struct s3c2410_uartcfg *cfg, int no)
114 {
115 struct platform_device *platdev;
116 struct s3c2410_uartcfg *cfgptr = uart_cfgs;
117 struct s3c24xx_uart_resources *resp;
118 int uart;
119
120 memcpy(cfgptr, cfg, sizeof(struct s3c2410_uartcfg) * no);
121
122 for (uart = 0; uart < no; uart++, cfg++, cfgptr++) {
123 platdev = s3c24xx_uart_src[cfgptr->hwport];
124
125 resp = res + cfgptr->hwport;
126
127 s3c24xx_uart_devs[uart] = platdev;
128
129 platdev->name = name;
130 platdev->resource = resp->resources;
131 platdev->num_resources = resp->nr_resources;
132
133 platdev->dev.platform_data = cfgptr;
134 }
135
136 nr_uarts = no;
137 }
138
139 void __init s3c24xx_init_uarts(struct s3c2410_uartcfg *cfg, int no)
140 {
141 if (cpu == NULL)
142 return;
143
144 if (cpu->init_uarts == NULL && IS_ENABLED(CONFIG_SAMSUNG_ATAGS)) {
145 printk(KERN_ERR "s3c24xx_init_uarts: cpu has no uart init\n");
146 } else
147 (cpu->init_uarts)(cfg, no);
148 }
149 #endif
150
151 static int __init s3c_arch_init(void)
152 {
153 int ret;
154
155 // do the correct init for cpu
156
157 if (cpu == NULL) {
158 /* Not needed when booting with device tree. */
159 if (of_have_populated_dt())
160 return 0;
161 panic("s3c_arch_init: NULL cpu\n");
162 }
163
164 ret = (cpu->init)();
165 if (ret != 0)
166 return ret;
167 #if IS_ENABLED(CONFIG_SAMSUNG_ATAGS)
168 ret = platform_add_devices(s3c24xx_uart_devs, nr_uarts);
169 #endif
170 return ret;
171 }
172
173 arch_initcall(s3c_arch_init);
This page took 0.048929 seconds and 5 git commands to generate.