Krzysztof Kozlowski | 4490e3c | 2017-12-25 20:54:35 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 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 |
Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 8 | |
Tomasz Figa | c836c90 | 2013-08-26 02:37:34 +0900 | [diff] [blame] | 9 | /* |
| 10 | * NOTE: Code in this file is not used on S3C64xx when booting with |
| 11 | * Device Tree support. |
| 12 | */ |
| 13 | |
Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 14 | #include <linux/init.h> |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/interrupt.h> |
| 17 | #include <linux/ioport.h> |
| 18 | #include <linux/serial_core.h> |
Tushar Behera | 334a1c7 | 2014-02-14 10:32:45 +0900 | [diff] [blame] | 19 | #include <linux/serial_s3c.h> |
Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 20 | #include <linux/platform_device.h> |
Tomasz Figa | c836c90 | 2013-08-26 02:37:34 +0900 | [diff] [blame] | 21 | #include <linux/of.h> |
Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 22 | |
Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 23 | #include <asm/mach/arch.h> |
| 24 | #include <asm/mach/map.h> |
| 25 | |
| 26 | #include <plat/cpu.h> |
| 27 | #include <plat/devs.h> |
Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 28 | |
Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 29 | static struct cpu_table *cpu; |
| 30 | |
| 31 | static struct cpu_table * __init s3c_lookup_cpu(unsigned long idcode, |
| 32 | struct cpu_table *tab, |
| 33 | unsigned int count) |
| 34 | { |
| 35 | for (; count != 0; count--, tab++) { |
Kukjin Kim | 9d5fda6 | 2011-03-23 14:45:29 +0900 | [diff] [blame] | 36 | if ((idcode & tab->idmask) == (tab->idcode & tab->idmask)) |
Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 37 | return tab; |
| 38 | } |
| 39 | |
| 40 | return NULL; |
| 41 | } |
| 42 | |
| 43 | void __init s3c_init_cpu(unsigned long idcode, |
| 44 | struct cpu_table *cputab, unsigned int cputab_size) |
| 45 | { |
| 46 | cpu = s3c_lookup_cpu(idcode, cputab, cputab_size); |
| 47 | |
| 48 | if (cpu == NULL) { |
| 49 | printk(KERN_ERR "Unknown CPU type 0x%08lx\n", idcode); |
| 50 | panic("Unknown S3C24XX CPU"); |
| 51 | } |
| 52 | |
| 53 | printk("CPU %s (id 0x%08lx)\n", cpu->name, idcode); |
| 54 | |
Kukjin Kim | 35f8550 | 2013-07-30 11:32:40 +0900 | [diff] [blame] | 55 | if (cpu->init == NULL) { |
Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 56 | printk(KERN_ERR "CPU %s support not enabled\n", cpu->name); |
| 57 | panic("Unsupported Samsung CPU"); |
| 58 | } |
| 59 | |
Kukjin Kim | 35f8550 | 2013-07-30 11:32:40 +0900 | [diff] [blame] | 60 | if (cpu->map_io) |
| 61 | cpu->map_io(); |
Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | /* s3c24xx_init_clocks |
| 65 | * |
| 66 | * Initialise the clock subsystem and associated information from the |
| 67 | * given master crystal value. |
| 68 | * |
| 69 | * xtal = 0 -> use default PLL crystal value (normally 12MHz) |
| 70 | * != 0 -> PLL crystal value in Hz |
| 71 | */ |
| 72 | |
| 73 | void __init s3c24xx_init_clocks(int xtal) |
| 74 | { |
| 75 | if (xtal == 0) |
| 76 | xtal = 12*1000*1000; |
| 77 | |
| 78 | if (cpu == NULL) |
| 79 | panic("s3c24xx_init_clocks: no cpu setup?\n"); |
| 80 | |
| 81 | if (cpu->init_clocks == NULL) |
| 82 | panic("s3c24xx_init_clocks: cpu has no clock init\n"); |
| 83 | else |
| 84 | (cpu->init_clocks)(xtal); |
| 85 | } |
| 86 | |
| 87 | /* uart management */ |
Tomasz Figa | 1f72e4045 | 2013-06-15 09:03:49 +0900 | [diff] [blame] | 88 | #if IS_ENABLED(CONFIG_SAMSUNG_ATAGS) |
Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 89 | static int nr_uarts __initdata = 0; |
| 90 | |
Arnd Bergmann | 0443a65 | 2014-02-26 17:55:35 +0100 | [diff] [blame] | 91 | #ifdef CONFIG_SERIAL_SAMSUNG_UARTS |
Ben Dooks | bdd4915 | 2008-11-03 19:51:42 +0000 | [diff] [blame] | 92 | static struct s3c2410_uartcfg uart_cfgs[CONFIG_SERIAL_SAMSUNG_UARTS]; |
Arnd Bergmann | 0443a65 | 2014-02-26 17:55:35 +0100 | [diff] [blame] | 93 | #endif |
Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 94 | |
| 95 | /* s3c24xx_init_uartdevs |
| 96 | * |
| 97 | * copy the specified platform data and configuration into our central |
| 98 | * set of devices, before the data is thrown away after the init process. |
| 99 | * |
| 100 | * This also fills in the array passed to the serial driver for the |
| 101 | * early initialisation of the console. |
| 102 | */ |
| 103 | |
| 104 | void __init s3c24xx_init_uartdevs(char *name, |
| 105 | struct s3c24xx_uart_resources *res, |
| 106 | struct s3c2410_uartcfg *cfg, int no) |
| 107 | { |
Arnd Bergmann | 0443a65 | 2014-02-26 17:55:35 +0100 | [diff] [blame] | 108 | #ifdef CONFIG_SERIAL_SAMSUNG_UARTS |
Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 109 | struct platform_device *platdev; |
| 110 | struct s3c2410_uartcfg *cfgptr = uart_cfgs; |
| 111 | struct s3c24xx_uart_resources *resp; |
| 112 | int uart; |
| 113 | |
| 114 | memcpy(cfgptr, cfg, sizeof(struct s3c2410_uartcfg) * no); |
| 115 | |
| 116 | for (uart = 0; uart < no; uart++, cfg++, cfgptr++) { |
| 117 | platdev = s3c24xx_uart_src[cfgptr->hwport]; |
| 118 | |
| 119 | resp = res + cfgptr->hwport; |
| 120 | |
| 121 | s3c24xx_uart_devs[uart] = platdev; |
| 122 | |
| 123 | platdev->name = name; |
| 124 | platdev->resource = resp->resources; |
| 125 | platdev->num_resources = resp->nr_resources; |
| 126 | |
| 127 | platdev->dev.platform_data = cfgptr; |
| 128 | } |
| 129 | |
| 130 | nr_uarts = no; |
Arnd Bergmann | 0443a65 | 2014-02-26 17:55:35 +0100 | [diff] [blame] | 131 | #endif |
Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | void __init s3c24xx_init_uarts(struct s3c2410_uartcfg *cfg, int no) |
| 135 | { |
| 136 | if (cpu == NULL) |
| 137 | return; |
| 138 | |
Tomasz Figa | 1f72e4045 | 2013-06-15 09:03:49 +0900 | [diff] [blame] | 139 | if (cpu->init_uarts == NULL && IS_ENABLED(CONFIG_SAMSUNG_ATAGS)) { |
Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 140 | printk(KERN_ERR "s3c24xx_init_uarts: cpu has no uart init\n"); |
| 141 | } else |
| 142 | (cpu->init_uarts)(cfg, no); |
| 143 | } |
Tomasz Figa | 1f72e4045 | 2013-06-15 09:03:49 +0900 | [diff] [blame] | 144 | #endif |
Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 145 | |
| 146 | static int __init s3c_arch_init(void) |
| 147 | { |
| 148 | int ret; |
| 149 | |
Arnd Bergmann | a0e157a | 2015-02-27 20:31:51 +0100 | [diff] [blame] | 150 | /* init is only needed for ATAGS based platforms */ |
| 151 | if (!IS_ENABLED(CONFIG_ATAGS) || |
| 152 | (!soc_is_s3c24xx() && !soc_is_s3c64xx())) |
| 153 | return 0; |
| 154 | |
Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 155 | // do the correct init for cpu |
| 156 | |
Tomasz Figa | c836c90 | 2013-08-26 02:37:34 +0900 | [diff] [blame] | 157 | if (cpu == NULL) { |
| 158 | /* Not needed when booting with device tree. */ |
| 159 | if (of_have_populated_dt()) |
| 160 | return 0; |
Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 161 | panic("s3c_arch_init: NULL cpu\n"); |
Tomasz Figa | c836c90 | 2013-08-26 02:37:34 +0900 | [diff] [blame] | 162 | } |
Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 163 | |
| 164 | ret = (cpu->init)(); |
| 165 | if (ret != 0) |
| 166 | return ret; |
Tomasz Figa | 1f72e4045 | 2013-06-15 09:03:49 +0900 | [diff] [blame] | 167 | #if IS_ENABLED(CONFIG_SAMSUNG_ATAGS) |
Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 168 | ret = platform_add_devices(s3c24xx_uart_devs, nr_uarts); |
Tomasz Figa | 1f72e4045 | 2013-06-15 09:03:49 +0900 | [diff] [blame] | 169 | #endif |
Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 170 | return ret; |
| 171 | } |
| 172 | |
| 173 | arch_initcall(s3c_arch_init); |