blob: a1f925f3121f19fe5d14da8d5184b5423eb3d9b5 [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>
33#include <plat/clock.h>
34
Ben Dooks74b265d2008-10-21 14:06:31 +010035static struct cpu_table *cpu;
36
37static struct cpu_table * __init s3c_lookup_cpu(unsigned long idcode,
38 struct cpu_table *tab,
39 unsigned int count)
40{
41 for (; count != 0; count--, tab++) {
Kukjin Kim9d5fda62011-03-23 14:45:29 +090042 if ((idcode & tab->idmask) == (tab->idcode & tab->idmask))
Ben Dooks74b265d2008-10-21 14:06:31 +010043 return tab;
44 }
45
46 return NULL;
47}
48
49void __init s3c_init_cpu(unsigned long idcode,
50 struct cpu_table *cputab, unsigned int cputab_size)
51{
52 cpu = s3c_lookup_cpu(idcode, cputab, cputab_size);
53
54 if (cpu == NULL) {
55 printk(KERN_ERR "Unknown CPU type 0x%08lx\n", idcode);
56 panic("Unknown S3C24XX CPU");
57 }
58
59 printk("CPU %s (id 0x%08lx)\n", cpu->name, idcode);
60
Kukjin Kim35f85502013-07-30 11:32:40 +090061 if (cpu->init == NULL) {
Ben Dooks74b265d2008-10-21 14:06:31 +010062 printk(KERN_ERR "CPU %s support not enabled\n", cpu->name);
63 panic("Unsupported Samsung CPU");
64 }
65
Kukjin Kim35f85502013-07-30 11:32:40 +090066 if (cpu->map_io)
67 cpu->map_io();
Ben Dooks74b265d2008-10-21 14:06:31 +010068}
69
70/* s3c24xx_init_clocks
71 *
72 * Initialise the clock subsystem and associated information from the
73 * given master crystal value.
74 *
75 * xtal = 0 -> use default PLL crystal value (normally 12MHz)
76 * != 0 -> PLL crystal value in Hz
77*/
78
79void __init s3c24xx_init_clocks(int xtal)
80{
81 if (xtal == 0)
82 xtal = 12*1000*1000;
83
84 if (cpu == NULL)
85 panic("s3c24xx_init_clocks: no cpu setup?\n");
86
87 if (cpu->init_clocks == NULL)
88 panic("s3c24xx_init_clocks: cpu has no clock init\n");
89 else
90 (cpu->init_clocks)(xtal);
91}
92
93/* uart management */
Tomasz Figa1f72e402013-06-15 09:03:49 +090094#if IS_ENABLED(CONFIG_SAMSUNG_ATAGS)
Ben Dooks74b265d2008-10-21 14:06:31 +010095static int nr_uarts __initdata = 0;
96
Arnd Bergmann0443a652014-02-26 17:55:35 +010097#ifdef CONFIG_SERIAL_SAMSUNG_UARTS
Ben Dooksbdd49152008-11-03 19:51:42 +000098static struct s3c2410_uartcfg uart_cfgs[CONFIG_SERIAL_SAMSUNG_UARTS];
Arnd Bergmann0443a652014-02-26 17:55:35 +010099#endif
Ben Dooks74b265d2008-10-21 14:06:31 +0100100
101/* s3c24xx_init_uartdevs
102 *
103 * copy the specified platform data and configuration into our central
104 * set of devices, before the data is thrown away after the init process.
105 *
106 * This also fills in the array passed to the serial driver for the
107 * early initialisation of the console.
108*/
109
110void __init s3c24xx_init_uartdevs(char *name,
111 struct s3c24xx_uart_resources *res,
112 struct s3c2410_uartcfg *cfg, int no)
113{
Arnd Bergmann0443a652014-02-26 17:55:35 +0100114#ifdef CONFIG_SERIAL_SAMSUNG_UARTS
Ben Dooks74b265d2008-10-21 14:06:31 +0100115 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;
Arnd Bergmann0443a652014-02-26 17:55:35 +0100137#endif
Ben Dooks74b265d2008-10-21 14:06:31 +0100138}
139
140void __init s3c24xx_init_uarts(struct s3c2410_uartcfg *cfg, int no)
141{
142 if (cpu == NULL)
143 return;
144
Tomasz Figa1f72e402013-06-15 09:03:49 +0900145 if (cpu->init_uarts == NULL && IS_ENABLED(CONFIG_SAMSUNG_ATAGS)) {
Ben Dooks74b265d2008-10-21 14:06:31 +0100146 printk(KERN_ERR "s3c24xx_init_uarts: cpu has no uart init\n");
147 } else
148 (cpu->init_uarts)(cfg, no);
149}
Tomasz Figa1f72e402013-06-15 09:03:49 +0900150#endif
Ben Dooks74b265d2008-10-21 14:06:31 +0100151
152static int __init s3c_arch_init(void)
153{
154 int ret;
155
156 // do the correct init for cpu
157
Tomasz Figac836c902013-08-26 02:37:34 +0900158 if (cpu == NULL) {
159 /* Not needed when booting with device tree. */
160 if (of_have_populated_dt())
161 return 0;
Ben Dooks74b265d2008-10-21 14:06:31 +0100162 panic("s3c_arch_init: NULL cpu\n");
Tomasz Figac836c902013-08-26 02:37:34 +0900163 }
Ben Dooks74b265d2008-10-21 14:06:31 +0100164
165 ret = (cpu->init)();
166 if (ret != 0)
167 return ret;
Tomasz Figa1f72e402013-06-15 09:03:49 +0900168#if IS_ENABLED(CONFIG_SAMSUNG_ATAGS)
Ben Dooks74b265d2008-10-21 14:06:31 +0100169 ret = platform_add_devices(s3c24xx_uart_devs, nr_uarts);
Tomasz Figa1f72e402013-06-15 09:03:49 +0900170#endif
Ben Dooks74b265d2008-10-21 14:06:31 +0100171 return ret;
172}
173
174arch_initcall(s3c_arch_init);