blob: 11fbbc26e49fdd85273edc996504a189065d94cf [file] [log] [blame]
Ben Dooks74b265d2008-10-21 14:06:31 +01001/* 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
Tomasz Figac836c902013-08-26 02:37:34 +090014/*
15 * NOTE: Code in this file is not used on S3C64xx when booting with
16 * Device Tree support.
17 */
18
Ben Dooks74b265d2008-10-21 14:06:31 +010019#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>
Tushar Behera334a1c72014-02-14 10:32:45 +090024#include <linux/serial_s3c.h>
Ben Dooks74b265d2008-10-21 14:06:31 +010025#include <linux/platform_device.h>
Tomasz Figac836c902013-08-26 02:37:34 +090026#include <linux/of.h>
Ben Dooks74b265d2008-10-21 14:06:31 +010027
Ben Dooks74b265d2008-10-21 14:06:31 +010028#include <asm/mach/arch.h>
29#include <asm/mach/map.h>
30
31#include <plat/cpu.h>
32#include <plat/devs.h>
Ben Dooks74b265d2008-10-21 14:06:31 +010033
Ben Dooks74b265d2008-10-21 14:06:31 +010034static struct cpu_table *cpu;
35
36static struct cpu_table * __init s3c_lookup_cpu(unsigned long idcode,
37 struct cpu_table *tab,
38 unsigned int count)
39{
40 for (; count != 0; count--, tab++) {
Kukjin Kim9d5fda62011-03-23 14:45:29 +090041 if ((idcode & tab->idmask) == (tab->idcode & tab->idmask))
Ben Dooks74b265d2008-10-21 14:06:31 +010042 return tab;
43 }
44
45 return NULL;
46}
47
48void __init s3c_init_cpu(unsigned long idcode,
49 struct cpu_table *cputab, unsigned int cputab_size)
50{
51 cpu = s3c_lookup_cpu(idcode, cputab, cputab_size);
52
53 if (cpu == NULL) {
54 printk(KERN_ERR "Unknown CPU type 0x%08lx\n", idcode);
55 panic("Unknown S3C24XX CPU");
56 }
57
58 printk("CPU %s (id 0x%08lx)\n", cpu->name, idcode);
59
Kukjin Kim35f85502013-07-30 11:32:40 +090060 if (cpu->init == NULL) {
Ben Dooks74b265d2008-10-21 14:06:31 +010061 printk(KERN_ERR "CPU %s support not enabled\n", cpu->name);
62 panic("Unsupported Samsung CPU");
63 }
64
Kukjin Kim35f85502013-07-30 11:32:40 +090065 if (cpu->map_io)
66 cpu->map_io();
Ben Dooks74b265d2008-10-21 14:06:31 +010067}
68
69/* s3c24xx_init_clocks
70 *
71 * Initialise the clock subsystem and associated information from the
72 * given master crystal value.
73 *
74 * xtal = 0 -> use default PLL crystal value (normally 12MHz)
75 * != 0 -> PLL crystal value in Hz
76*/
77
78void __init s3c24xx_init_clocks(int xtal)
79{
80 if (xtal == 0)
81 xtal = 12*1000*1000;
82
83 if (cpu == NULL)
84 panic("s3c24xx_init_clocks: no cpu setup?\n");
85
86 if (cpu->init_clocks == NULL)
87 panic("s3c24xx_init_clocks: cpu has no clock init\n");
88 else
89 (cpu->init_clocks)(xtal);
90}
91
92/* uart management */
Tomasz Figa1f72e40452013-06-15 09:03:49 +090093#if IS_ENABLED(CONFIG_SAMSUNG_ATAGS)
Ben Dooks74b265d2008-10-21 14:06:31 +010094static int nr_uarts __initdata = 0;
95
Arnd Bergmann0443a652014-02-26 17:55:35 +010096#ifdef CONFIG_SERIAL_SAMSUNG_UARTS
Ben Dooksbdd49152008-11-03 19:51:42 +000097static struct s3c2410_uartcfg uart_cfgs[CONFIG_SERIAL_SAMSUNG_UARTS];
Arnd Bergmann0443a652014-02-26 17:55:35 +010098#endif
Ben Dooks74b265d2008-10-21 14:06:31 +010099
100/* s3c24xx_init_uartdevs
101 *
102 * copy the specified platform data and configuration into our central
103 * set of devices, before the data is thrown away after the init process.
104 *
105 * This also fills in the array passed to the serial driver for the
106 * early initialisation of the console.
107*/
108
109void __init s3c24xx_init_uartdevs(char *name,
110 struct s3c24xx_uart_resources *res,
111 struct s3c2410_uartcfg *cfg, int no)
112{
Arnd Bergmann0443a652014-02-26 17:55:35 +0100113#ifdef CONFIG_SERIAL_SAMSUNG_UARTS
Ben Dooks74b265d2008-10-21 14:06:31 +0100114 struct platform_device *platdev;
115 struct s3c2410_uartcfg *cfgptr = uart_cfgs;
116 struct s3c24xx_uart_resources *resp;
117 int uart;
118
119 memcpy(cfgptr, cfg, sizeof(struct s3c2410_uartcfg) * no);
120
121 for (uart = 0; uart < no; uart++, cfg++, cfgptr++) {
122 platdev = s3c24xx_uart_src[cfgptr->hwport];
123
124 resp = res + cfgptr->hwport;
125
126 s3c24xx_uart_devs[uart] = platdev;
127
128 platdev->name = name;
129 platdev->resource = resp->resources;
130 platdev->num_resources = resp->nr_resources;
131
132 platdev->dev.platform_data = cfgptr;
133 }
134
135 nr_uarts = no;
Arnd Bergmann0443a652014-02-26 17:55:35 +0100136#endif
Ben Dooks74b265d2008-10-21 14:06:31 +0100137}
138
139void __init s3c24xx_init_uarts(struct s3c2410_uartcfg *cfg, int no)
140{
141 if (cpu == NULL)
142 return;
143
Tomasz Figa1f72e40452013-06-15 09:03:49 +0900144 if (cpu->init_uarts == NULL && IS_ENABLED(CONFIG_SAMSUNG_ATAGS)) {
Ben Dooks74b265d2008-10-21 14:06:31 +0100145 printk(KERN_ERR "s3c24xx_init_uarts: cpu has no uart init\n");
146 } else
147 (cpu->init_uarts)(cfg, no);
148}
Tomasz Figa1f72e40452013-06-15 09:03:49 +0900149#endif
Ben Dooks74b265d2008-10-21 14:06:31 +0100150
151static int __init s3c_arch_init(void)
152{
153 int ret;
154
155 // do the correct init for cpu
156
Tomasz Figac836c902013-08-26 02:37:34 +0900157 if (cpu == NULL) {
158 /* Not needed when booting with device tree. */
159 if (of_have_populated_dt())
160 return 0;
Ben Dooks74b265d2008-10-21 14:06:31 +0100161 panic("s3c_arch_init: NULL cpu\n");
Tomasz Figac836c902013-08-26 02:37:34 +0900162 }
Ben Dooks74b265d2008-10-21 14:06:31 +0100163
164 ret = (cpu->init)();
165 if (ret != 0)
166 return ret;
Tomasz Figa1f72e40452013-06-15 09:03:49 +0900167#if IS_ENABLED(CONFIG_SAMSUNG_ATAGS)
Ben Dooks74b265d2008-10-21 14:06:31 +0100168 ret = platform_add_devices(s3c24xx_uart_devs, nr_uarts);
Tomasz Figa1f72e40452013-06-15 09:03:49 +0900169#endif
Ben Dooks74b265d2008-10-21 14:06:31 +0100170 return ret;
171}
172
173arch_initcall(s3c_arch_init);