Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 //
0003 // Copyright (c) 2008 Simtec Electronics
0004 //  Ben Dooks <ben@simtec.co.uk>
0005 //  http://armlinux.simtec.co.uk/
0006 //
0007 // S3C series CPU initialisation
0008 
0009 /*
0010  * NOTE: Code in this file is not used on S3C64xx when booting with
0011  * Device Tree support.
0012  */
0013 
0014 #include <linux/init.h>
0015 #include <linux/module.h>
0016 #include <linux/interrupt.h>
0017 #include <linux/ioport.h>
0018 #include <linux/serial_core.h>
0019 #include <linux/serial_s3c.h>
0020 #include <linux/platform_device.h>
0021 #include <linux/of.h>
0022 
0023 #include <asm/mach/arch.h>
0024 #include <asm/mach/map.h>
0025 
0026 #include "cpu.h"
0027 #include "devs.h"
0028 
0029 static struct cpu_table *cpu;
0030 
0031 static struct cpu_table * __init s3c_lookup_cpu(unsigned long idcode,
0032                         struct cpu_table *tab,
0033                         unsigned int count)
0034 {
0035     for (; count != 0; count--, tab++) {
0036         if ((idcode & tab->idmask) == (tab->idcode & tab->idmask))
0037             return tab;
0038     }
0039 
0040     return NULL;
0041 }
0042 
0043 void __init s3c_init_cpu(unsigned long idcode,
0044              struct cpu_table *cputab, unsigned int cputab_size)
0045 {
0046     cpu = s3c_lookup_cpu(idcode, cputab, cputab_size);
0047 
0048     if (cpu == NULL) {
0049         printk(KERN_ERR "Unknown CPU type 0x%08lx\n", idcode);
0050         panic("Unknown S3C24XX CPU");
0051     }
0052 
0053     printk("CPU %s (id 0x%08lx)\n", cpu->name, idcode);
0054 
0055     if (cpu->init == NULL) {
0056         printk(KERN_ERR "CPU %s support not enabled\n", cpu->name);
0057         panic("Unsupported Samsung CPU");
0058     }
0059 
0060     if (cpu->map_io)
0061         cpu->map_io();
0062 
0063     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");
0064 }
0065 
0066 /* s3c24xx_init_clocks
0067  *
0068  * Initialise the clock subsystem and associated information from the
0069  * given master crystal value.
0070  *
0071  * xtal  = 0 -> use default PLL crystal value (normally 12MHz)
0072  *      != 0 -> PLL crystal value in Hz
0073 */
0074 
0075 void __init s3c24xx_init_clocks(int xtal)
0076 {
0077     if (xtal == 0)
0078         xtal = 12*1000*1000;
0079 
0080     if (cpu == NULL)
0081         panic("s3c24xx_init_clocks: no cpu setup?\n");
0082 
0083     if (cpu->init_clocks == NULL)
0084         panic("s3c24xx_init_clocks: cpu has no clock init\n");
0085     else
0086         (cpu->init_clocks)(xtal);
0087 }
0088 
0089 /* uart management */
0090 #if IS_ENABLED(CONFIG_SAMSUNG_ATAGS)
0091 static int nr_uarts __initdata = 0;
0092 
0093 #ifdef CONFIG_SERIAL_SAMSUNG_UARTS
0094 static struct s3c2410_uartcfg uart_cfgs[CONFIG_SERIAL_SAMSUNG_UARTS];
0095 #endif
0096 
0097 /* s3c24xx_init_uartdevs
0098  *
0099  * copy the specified platform data and configuration into our central
0100  * set of devices, before the data is thrown away after the init process.
0101  *
0102  * This also fills in the array passed to the serial driver for the
0103  * early initialisation of the console.
0104 */
0105 
0106 void __init s3c24xx_init_uartdevs(char *name,
0107                   struct s3c24xx_uart_resources *res,
0108                   struct s3c2410_uartcfg *cfg, int no)
0109 {
0110 #ifdef CONFIG_SERIAL_SAMSUNG_UARTS
0111     struct platform_device *platdev;
0112     struct s3c2410_uartcfg *cfgptr = uart_cfgs;
0113     struct s3c24xx_uart_resources *resp;
0114     int uart;
0115 
0116     memcpy(cfgptr, cfg, sizeof(struct s3c2410_uartcfg) * no);
0117 
0118     for (uart = 0; uart < no; uart++, cfg++, cfgptr++) {
0119         platdev = s3c24xx_uart_src[cfgptr->hwport];
0120 
0121         resp = res + cfgptr->hwport;
0122 
0123         s3c24xx_uart_devs[uart] = platdev;
0124 
0125         platdev->name = name;
0126         platdev->resource = resp->resources;
0127         platdev->num_resources = resp->nr_resources;
0128 
0129         platdev->dev.platform_data = cfgptr;
0130     }
0131 
0132     nr_uarts = no;
0133 #endif
0134 }
0135 
0136 void __init s3c24xx_init_uarts(struct s3c2410_uartcfg *cfg, int no)
0137 {
0138     if (cpu == NULL)
0139         return;
0140 
0141     if (cpu->init_uarts == NULL && IS_ENABLED(CONFIG_SAMSUNG_ATAGS)) {
0142         printk(KERN_ERR "s3c24xx_init_uarts: cpu has no uart init\n");
0143     } else
0144         (cpu->init_uarts)(cfg, no);
0145 }
0146 #endif
0147 
0148 static int __init s3c_arch_init(void)
0149 {
0150     int ret;
0151 
0152     /* init is only needed for ATAGS based platforms */
0153     if (!IS_ENABLED(CONFIG_ATAGS) ||
0154         (!soc_is_s3c24xx() && !soc_is_s3c64xx()))
0155         return 0;
0156 
0157     // do the correct init for cpu
0158 
0159     if (cpu == NULL) {
0160         /* Not needed when booting with device tree. */
0161         if (of_have_populated_dt())
0162             return 0;
0163         panic("s3c_arch_init: NULL cpu\n");
0164     }
0165 
0166     ret = (cpu->init)();
0167     if (ret != 0)
0168         return ret;
0169 #if IS_ENABLED(CONFIG_SAMSUNG_ATAGS)
0170     ret = platform_add_devices(s3c24xx_uart_devs, nr_uarts);
0171 #endif
0172     return ret;
0173 }
0174 
0175 arch_initcall(s3c_arch_init);