Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 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 | |
Tomasz Figa | c836c90 | 2013-08-26 02:37:34 +0900 | [diff] [blame] | 14 | /* |
| 15 | * NOTE: Code in this file is not used on S3C64xx when booting with |
| 16 | * Device Tree support. |
| 17 | */ |
| 18 | |
Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 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> |
Tushar Behera | 334a1c7 | 2014-02-14 10:32:45 +0900 | [diff] [blame^] | 24 | #include <linux/serial_s3c.h> |
Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 25 | #include <linux/platform_device.h> |
Tomasz Figa | c836c90 | 2013-08-26 02:37:34 +0900 | [diff] [blame] | 26 | #include <linux/of.h> |
Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 27 | |
| 28 | #include <mach/hardware.h> |
| 29 | |
| 30 | #include <asm/mach/arch.h> |
| 31 | #include <asm/mach/map.h> |
| 32 | |
| 33 | #include <plat/cpu.h> |
| 34 | #include <plat/devs.h> |
| 35 | #include <plat/clock.h> |
| 36 | |
Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 37 | static struct cpu_table *cpu; |
| 38 | |
| 39 | static struct cpu_table * __init s3c_lookup_cpu(unsigned long idcode, |
| 40 | struct cpu_table *tab, |
| 41 | unsigned int count) |
| 42 | { |
| 43 | for (; count != 0; count--, tab++) { |
Kukjin Kim | 9d5fda6 | 2011-03-23 14:45:29 +0900 | [diff] [blame] | 44 | if ((idcode & tab->idmask) == (tab->idcode & tab->idmask)) |
Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 45 | return tab; |
| 46 | } |
| 47 | |
| 48 | return NULL; |
| 49 | } |
| 50 | |
| 51 | void __init s3c_init_cpu(unsigned long idcode, |
| 52 | struct cpu_table *cputab, unsigned int cputab_size) |
| 53 | { |
| 54 | cpu = s3c_lookup_cpu(idcode, cputab, cputab_size); |
| 55 | |
| 56 | if (cpu == NULL) { |
| 57 | printk(KERN_ERR "Unknown CPU type 0x%08lx\n", idcode); |
| 58 | panic("Unknown S3C24XX CPU"); |
| 59 | } |
| 60 | |
| 61 | printk("CPU %s (id 0x%08lx)\n", cpu->name, idcode); |
| 62 | |
Kukjin Kim | 35f8550 | 2013-07-30 11:32:40 +0900 | [diff] [blame] | 63 | if (cpu->init == NULL) { |
Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 64 | printk(KERN_ERR "CPU %s support not enabled\n", cpu->name); |
| 65 | panic("Unsupported Samsung CPU"); |
| 66 | } |
| 67 | |
Kukjin Kim | 35f8550 | 2013-07-30 11:32:40 +0900 | [diff] [blame] | 68 | if (cpu->map_io) |
| 69 | cpu->map_io(); |
Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | /* s3c24xx_init_clocks |
| 73 | * |
| 74 | * Initialise the clock subsystem and associated information from the |
| 75 | * given master crystal value. |
| 76 | * |
| 77 | * xtal = 0 -> use default PLL crystal value (normally 12MHz) |
| 78 | * != 0 -> PLL crystal value in Hz |
| 79 | */ |
| 80 | |
| 81 | void __init s3c24xx_init_clocks(int xtal) |
| 82 | { |
| 83 | if (xtal == 0) |
| 84 | xtal = 12*1000*1000; |
| 85 | |
| 86 | if (cpu == NULL) |
| 87 | panic("s3c24xx_init_clocks: no cpu setup?\n"); |
| 88 | |
| 89 | if (cpu->init_clocks == NULL) |
| 90 | panic("s3c24xx_init_clocks: cpu has no clock init\n"); |
| 91 | else |
| 92 | (cpu->init_clocks)(xtal); |
| 93 | } |
| 94 | |
| 95 | /* uart management */ |
Tomasz Figa | 1f72e4045 | 2013-06-15 09:03:49 +0900 | [diff] [blame] | 96 | #if IS_ENABLED(CONFIG_SAMSUNG_ATAGS) |
Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 97 | static int nr_uarts __initdata = 0; |
| 98 | |
Ben Dooks | bdd4915 | 2008-11-03 19:51:42 +0000 | [diff] [blame] | 99 | static struct s3c2410_uartcfg uart_cfgs[CONFIG_SERIAL_SAMSUNG_UARTS]; |
Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 100 | |
| 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 | |
| 110 | void __init s3c24xx_init_uartdevs(char *name, |
| 111 | struct s3c24xx_uart_resources *res, |
| 112 | struct s3c2410_uartcfg *cfg, int no) |
| 113 | { |
| 114 | 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; |
| 136 | } |
| 137 | |
| 138 | void __init s3c24xx_init_uarts(struct s3c2410_uartcfg *cfg, int no) |
| 139 | { |
| 140 | if (cpu == NULL) |
| 141 | return; |
| 142 | |
Tomasz Figa | 1f72e4045 | 2013-06-15 09:03:49 +0900 | [diff] [blame] | 143 | if (cpu->init_uarts == NULL && IS_ENABLED(CONFIG_SAMSUNG_ATAGS)) { |
Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 144 | printk(KERN_ERR "s3c24xx_init_uarts: cpu has no uart init\n"); |
| 145 | } else |
| 146 | (cpu->init_uarts)(cfg, no); |
| 147 | } |
Tomasz Figa | 1f72e4045 | 2013-06-15 09:03:49 +0900 | [diff] [blame] | 148 | #endif |
Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 149 | |
| 150 | static int __init s3c_arch_init(void) |
| 151 | { |
| 152 | int ret; |
| 153 | |
| 154 | // do the correct init for cpu |
| 155 | |
Tomasz Figa | c836c90 | 2013-08-26 02:37:34 +0900 | [diff] [blame] | 156 | if (cpu == NULL) { |
| 157 | /* Not needed when booting with device tree. */ |
| 158 | if (of_have_populated_dt()) |
| 159 | return 0; |
Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 160 | panic("s3c_arch_init: NULL cpu\n"); |
Tomasz Figa | c836c90 | 2013-08-26 02:37:34 +0900 | [diff] [blame] | 161 | } |
Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 162 | |
| 163 | ret = (cpu->init)(); |
| 164 | if (ret != 0) |
| 165 | return ret; |
Tomasz Figa | 1f72e4045 | 2013-06-15 09:03:49 +0900 | [diff] [blame] | 166 | #if IS_ENABLED(CONFIG_SAMSUNG_ATAGS) |
Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 167 | ret = platform_add_devices(s3c24xx_uart_devs, nr_uarts); |
Tomasz Figa | 1f72e4045 | 2013-06-15 09:03:49 +0900 | [diff] [blame] | 168 | #endif |
Ben Dooks | 74b265d | 2008-10-21 14:06:31 +0100 | [diff] [blame] | 169 | return ret; |
| 170 | } |
| 171 | |
| 172 | arch_initcall(s3c_arch_init); |