xref: /linux/arch/arm/mach-s3c/init.c (revision 9a87ffc99ec8eb8d35eed7c4f816d75f5cc9662e)
171b9114dSArnd Bergmann // SPDX-License-Identifier: GPL-2.0
271b9114dSArnd Bergmann //
371b9114dSArnd Bergmann // Copyright (c) 2008 Simtec Electronics
471b9114dSArnd Bergmann //	Ben Dooks <ben@simtec.co.uk>
571b9114dSArnd Bergmann //	http://armlinux.simtec.co.uk/
671b9114dSArnd Bergmann //
771b9114dSArnd Bergmann // S3C series CPU initialisation
871b9114dSArnd Bergmann 
971b9114dSArnd Bergmann /*
1071b9114dSArnd Bergmann  * NOTE: Code in this file is not used on S3C64xx when booting with
1171b9114dSArnd Bergmann  * Device Tree support.
1271b9114dSArnd Bergmann  */
1371b9114dSArnd Bergmann 
1471b9114dSArnd Bergmann #include <linux/init.h>
1571b9114dSArnd Bergmann #include <linux/module.h>
1671b9114dSArnd Bergmann #include <linux/interrupt.h>
1771b9114dSArnd Bergmann #include <linux/ioport.h>
1871b9114dSArnd Bergmann #include <linux/serial_core.h>
1971b9114dSArnd Bergmann #include <linux/serial_s3c.h>
2071b9114dSArnd Bergmann #include <linux/platform_device.h>
2171b9114dSArnd Bergmann #include <linux/of.h>
2271b9114dSArnd Bergmann 
2371b9114dSArnd Bergmann #include <asm/mach/arch.h>
2471b9114dSArnd Bergmann #include <asm/mach/map.h>
2571b9114dSArnd Bergmann 
26c6ff132dSArnd Bergmann #include "cpu.h"
27c6ff132dSArnd Bergmann #include "devs.h"
2871b9114dSArnd Bergmann 
2971b9114dSArnd Bergmann static struct cpu_table *cpu;
3071b9114dSArnd Bergmann 
s3c_lookup_cpu(unsigned long idcode,struct cpu_table * tab,unsigned int count)3171b9114dSArnd Bergmann static struct cpu_table * __init s3c_lookup_cpu(unsigned long idcode,
3271b9114dSArnd Bergmann 						struct cpu_table *tab,
3371b9114dSArnd Bergmann 						unsigned int count)
3471b9114dSArnd Bergmann {
3571b9114dSArnd Bergmann 	for (; count != 0; count--, tab++) {
3671b9114dSArnd Bergmann 		if ((idcode & tab->idmask) == (tab->idcode & tab->idmask))
3771b9114dSArnd Bergmann 			return tab;
3871b9114dSArnd Bergmann 	}
3971b9114dSArnd Bergmann 
4071b9114dSArnd Bergmann 	return NULL;
4171b9114dSArnd Bergmann }
4271b9114dSArnd Bergmann 
s3c_init_cpu(unsigned long idcode,struct cpu_table * cputab,unsigned int cputab_size)4371b9114dSArnd Bergmann void __init s3c_init_cpu(unsigned long idcode,
4471b9114dSArnd Bergmann 			 struct cpu_table *cputab, unsigned int cputab_size)
4571b9114dSArnd Bergmann {
4671b9114dSArnd Bergmann 	cpu = s3c_lookup_cpu(idcode, cputab, cputab_size);
4771b9114dSArnd Bergmann 
4871b9114dSArnd Bergmann 	if (cpu == NULL) {
4971b9114dSArnd Bergmann 		printk(KERN_ERR "Unknown CPU type 0x%08lx\n", idcode);
5071b9114dSArnd Bergmann 		panic("Unknown S3C24XX CPU");
5171b9114dSArnd Bergmann 	}
5271b9114dSArnd Bergmann 
5371b9114dSArnd Bergmann 	printk("CPU %s (id 0x%08lx)\n", cpu->name, idcode);
5471b9114dSArnd Bergmann 
5571b9114dSArnd Bergmann 	if (cpu->init == NULL) {
5671b9114dSArnd Bergmann 		printk(KERN_ERR "CPU %s support not enabled\n", cpu->name);
5771b9114dSArnd Bergmann 		panic("Unsupported Samsung CPU");
5871b9114dSArnd Bergmann 	}
5971b9114dSArnd Bergmann 
6071b9114dSArnd Bergmann 	if (cpu->map_io)
6171b9114dSArnd Bergmann 		cpu->map_io();
626a5e69c7SKrzysztof Kozlowski 
636a5e69c7SKrzysztof Kozlowski 	pr_err("The platform is deprecated and scheduled for removal. Please reach to the maintainers of the platform and linux-samsung-soc@vger.kernel.org if you still use it.  Without such feedback, the platform will be removed after 2022.\n");
6471b9114dSArnd Bergmann }
6571b9114dSArnd Bergmann 
6671b9114dSArnd Bergmann /* uart management */
6771b9114dSArnd Bergmann #if IS_ENABLED(CONFIG_SAMSUNG_ATAGS)
6871b9114dSArnd Bergmann static int nr_uarts __initdata = 0;
6971b9114dSArnd Bergmann 
7071b9114dSArnd Bergmann #ifdef CONFIG_SERIAL_SAMSUNG_UARTS
7171b9114dSArnd Bergmann static struct s3c2410_uartcfg uart_cfgs[CONFIG_SERIAL_SAMSUNG_UARTS];
7271b9114dSArnd Bergmann #endif
7371b9114dSArnd Bergmann 
7471b9114dSArnd Bergmann /* s3c24xx_init_uartdevs
7571b9114dSArnd Bergmann  *
7671b9114dSArnd Bergmann  * copy the specified platform data and configuration into our central
7771b9114dSArnd Bergmann  * set of devices, before the data is thrown away after the init process.
7871b9114dSArnd Bergmann  *
7971b9114dSArnd Bergmann  * This also fills in the array passed to the serial driver for the
8071b9114dSArnd Bergmann  * early initialisation of the console.
8171b9114dSArnd Bergmann */
8271b9114dSArnd Bergmann 
s3c24xx_init_uartdevs(char * name,struct s3c24xx_uart_resources * res,struct s3c2410_uartcfg * cfg,int no)8371b9114dSArnd Bergmann void __init s3c24xx_init_uartdevs(char *name,
8471b9114dSArnd Bergmann 				  struct s3c24xx_uart_resources *res,
8571b9114dSArnd Bergmann 				  struct s3c2410_uartcfg *cfg, int no)
8671b9114dSArnd Bergmann {
8771b9114dSArnd Bergmann #ifdef CONFIG_SERIAL_SAMSUNG_UARTS
8871b9114dSArnd Bergmann 	struct platform_device *platdev;
8971b9114dSArnd Bergmann 	struct s3c2410_uartcfg *cfgptr = uart_cfgs;
9071b9114dSArnd Bergmann 	struct s3c24xx_uart_resources *resp;
9171b9114dSArnd Bergmann 	int uart;
9271b9114dSArnd Bergmann 
9371b9114dSArnd Bergmann 	memcpy(cfgptr, cfg, sizeof(struct s3c2410_uartcfg) * no);
9471b9114dSArnd Bergmann 
9571b9114dSArnd Bergmann 	for (uart = 0; uart < no; uart++, cfg++, cfgptr++) {
9671b9114dSArnd Bergmann 		platdev = s3c24xx_uart_src[cfgptr->hwport];
9771b9114dSArnd Bergmann 
9871b9114dSArnd Bergmann 		resp = res + cfgptr->hwport;
9971b9114dSArnd Bergmann 
10071b9114dSArnd Bergmann 		s3c24xx_uart_devs[uart] = platdev;
10171b9114dSArnd Bergmann 
10271b9114dSArnd Bergmann 		platdev->name = name;
10371b9114dSArnd Bergmann 		platdev->resource = resp->resources;
10471b9114dSArnd Bergmann 		platdev->num_resources = resp->nr_resources;
10571b9114dSArnd Bergmann 
10671b9114dSArnd Bergmann 		platdev->dev.platform_data = cfgptr;
10771b9114dSArnd Bergmann 	}
10871b9114dSArnd Bergmann 
10971b9114dSArnd Bergmann 	nr_uarts = no;
11071b9114dSArnd Bergmann #endif
11171b9114dSArnd Bergmann }
11271b9114dSArnd Bergmann 
s3c24xx_init_uarts(struct s3c2410_uartcfg * cfg,int no)11371b9114dSArnd Bergmann void __init s3c24xx_init_uarts(struct s3c2410_uartcfg *cfg, int no)
11471b9114dSArnd Bergmann {
11571b9114dSArnd Bergmann 	if (cpu == NULL)
11671b9114dSArnd Bergmann 		return;
11771b9114dSArnd Bergmann 
11871b9114dSArnd Bergmann 	if (cpu->init_uarts == NULL && IS_ENABLED(CONFIG_SAMSUNG_ATAGS)) {
11971b9114dSArnd Bergmann 		printk(KERN_ERR "s3c24xx_init_uarts: cpu has no uart init\n");
12071b9114dSArnd Bergmann 	} else
12171b9114dSArnd Bergmann 		(cpu->init_uarts)(cfg, no);
12271b9114dSArnd Bergmann }
12371b9114dSArnd Bergmann #endif
12471b9114dSArnd Bergmann 
s3c_arch_init(void)12571b9114dSArnd Bergmann static int __init s3c_arch_init(void)
12671b9114dSArnd Bergmann {
12771b9114dSArnd Bergmann 	int ret;
12871b9114dSArnd Bergmann 
12971b9114dSArnd Bergmann 	/* init is only needed for ATAGS based platforms */
130*0d297df0SArnd Bergmann 	if (!IS_ENABLED(CONFIG_ATAGS))
13171b9114dSArnd Bergmann 		return 0;
13271b9114dSArnd Bergmann 
13371b9114dSArnd Bergmann 	// do the correct init for cpu
13471b9114dSArnd Bergmann 
13571b9114dSArnd Bergmann 	if (cpu == NULL) {
13671b9114dSArnd Bergmann 		/* Not needed when booting with device tree. */
13771b9114dSArnd Bergmann 		if (of_have_populated_dt())
13871b9114dSArnd Bergmann 			return 0;
13971b9114dSArnd Bergmann 		panic("s3c_arch_init: NULL cpu\n");
14071b9114dSArnd Bergmann 	}
14171b9114dSArnd Bergmann 
14271b9114dSArnd Bergmann 	ret = (cpu->init)();
14371b9114dSArnd Bergmann 	if (ret != 0)
14471b9114dSArnd Bergmann 		return ret;
14571b9114dSArnd Bergmann #if IS_ENABLED(CONFIG_SAMSUNG_ATAGS)
14671b9114dSArnd Bergmann 	ret = platform_add_devices(s3c24xx_uart_devs, nr_uarts);
14771b9114dSArnd Bergmann #endif
14871b9114dSArnd Bergmann 	return ret;
14971b9114dSArnd Bergmann }
15071b9114dSArnd Bergmann 
15171b9114dSArnd Bergmann arch_initcall(s3c_arch_init);
152