init.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. // SPDX-License-Identifier: GPL-2.0
  2. //
  3. // Copyright (c) 2008 Simtec Electronics
  4. // Ben Dooks <[email protected]>
  5. // http://armlinux.simtec.co.uk/
  6. //
  7. // S3C series CPU initialisation
  8. /*
  9. * NOTE: Code in this file is not used on S3C64xx when booting with
  10. * Device Tree support.
  11. */
  12. #include <linux/init.h>
  13. #include <linux/module.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/ioport.h>
  16. #include <linux/serial_core.h>
  17. #include <linux/serial_s3c.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/of.h>
  20. #include <asm/mach/arch.h>
  21. #include <asm/mach/map.h>
  22. #include "cpu.h"
  23. #include "devs.h"
  24. static struct cpu_table *cpu;
  25. static struct cpu_table * __init s3c_lookup_cpu(unsigned long idcode,
  26. struct cpu_table *tab,
  27. unsigned int count)
  28. {
  29. for (; count != 0; count--, tab++) {
  30. if ((idcode & tab->idmask) == (tab->idcode & tab->idmask))
  31. return tab;
  32. }
  33. return NULL;
  34. }
  35. void __init s3c_init_cpu(unsigned long idcode,
  36. struct cpu_table *cputab, unsigned int cputab_size)
  37. {
  38. cpu = s3c_lookup_cpu(idcode, cputab, cputab_size);
  39. if (cpu == NULL) {
  40. printk(KERN_ERR "Unknown CPU type 0x%08lx\n", idcode);
  41. panic("Unknown S3C24XX CPU");
  42. }
  43. printk("CPU %s (id 0x%08lx)\n", cpu->name, idcode);
  44. if (cpu->init == NULL) {
  45. printk(KERN_ERR "CPU %s support not enabled\n", cpu->name);
  46. panic("Unsupported Samsung CPU");
  47. }
  48. if (cpu->map_io)
  49. cpu->map_io();
  50. pr_err("The platform is deprecated and scheduled for removal. Please reach to the maintainers of the platform and [email protected] if you still use it. Without such feedback, the platform will be removed after 2022.\n");
  51. }
  52. /* s3c24xx_init_clocks
  53. *
  54. * Initialise the clock subsystem and associated information from the
  55. * given master crystal value.
  56. *
  57. * xtal = 0 -> use default PLL crystal value (normally 12MHz)
  58. * != 0 -> PLL crystal value in Hz
  59. */
  60. void __init s3c24xx_init_clocks(int xtal)
  61. {
  62. if (xtal == 0)
  63. xtal = 12*1000*1000;
  64. if (cpu == NULL)
  65. panic("s3c24xx_init_clocks: no cpu setup?\n");
  66. if (cpu->init_clocks == NULL)
  67. panic("s3c24xx_init_clocks: cpu has no clock init\n");
  68. else
  69. (cpu->init_clocks)(xtal);
  70. }
  71. /* uart management */
  72. #if IS_ENABLED(CONFIG_SAMSUNG_ATAGS)
  73. static int nr_uarts __initdata = 0;
  74. #ifdef CONFIG_SERIAL_SAMSUNG_UARTS
  75. static struct s3c2410_uartcfg uart_cfgs[CONFIG_SERIAL_SAMSUNG_UARTS];
  76. #endif
  77. /* s3c24xx_init_uartdevs
  78. *
  79. * copy the specified platform data and configuration into our central
  80. * set of devices, before the data is thrown away after the init process.
  81. *
  82. * This also fills in the array passed to the serial driver for the
  83. * early initialisation of the console.
  84. */
  85. void __init s3c24xx_init_uartdevs(char *name,
  86. struct s3c24xx_uart_resources *res,
  87. struct s3c2410_uartcfg *cfg, int no)
  88. {
  89. #ifdef CONFIG_SERIAL_SAMSUNG_UARTS
  90. struct platform_device *platdev;
  91. struct s3c2410_uartcfg *cfgptr = uart_cfgs;
  92. struct s3c24xx_uart_resources *resp;
  93. int uart;
  94. memcpy(cfgptr, cfg, sizeof(struct s3c2410_uartcfg) * no);
  95. for (uart = 0; uart < no; uart++, cfg++, cfgptr++) {
  96. platdev = s3c24xx_uart_src[cfgptr->hwport];
  97. resp = res + cfgptr->hwport;
  98. s3c24xx_uart_devs[uart] = platdev;
  99. platdev->name = name;
  100. platdev->resource = resp->resources;
  101. platdev->num_resources = resp->nr_resources;
  102. platdev->dev.platform_data = cfgptr;
  103. }
  104. nr_uarts = no;
  105. #endif
  106. }
  107. void __init s3c24xx_init_uarts(struct s3c2410_uartcfg *cfg, int no)
  108. {
  109. if (cpu == NULL)
  110. return;
  111. if (cpu->init_uarts == NULL && IS_ENABLED(CONFIG_SAMSUNG_ATAGS)) {
  112. printk(KERN_ERR "s3c24xx_init_uarts: cpu has no uart init\n");
  113. } else
  114. (cpu->init_uarts)(cfg, no);
  115. }
  116. #endif
  117. static int __init s3c_arch_init(void)
  118. {
  119. int ret;
  120. /* init is only needed for ATAGS based platforms */
  121. if (!IS_ENABLED(CONFIG_ATAGS) ||
  122. (!soc_is_s3c24xx() && !soc_is_s3c64xx()))
  123. return 0;
  124. // do the correct init for cpu
  125. if (cpu == NULL) {
  126. /* Not needed when booting with device tree. */
  127. if (of_have_populated_dt())
  128. return 0;
  129. panic("s3c_arch_init: NULL cpu\n");
  130. }
  131. ret = (cpu->init)();
  132. if (ret != 0)
  133. return ret;
  134. #if IS_ENABLED(CONFIG_SAMSUNG_ATAGS)
  135. ret = platform_add_devices(s3c24xx_uart_devs, nr_uarts);
  136. #endif
  137. return ret;
  138. }
  139. arch_initcall(s3c_arch_init);