init.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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
  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 linux-samsung-soc@vger.kernel.org if you still use it. Without such feedback, the platform will be removed after 2022.\n");
  51. }
  52. /* uart management */
  53. #if IS_ENABLED(CONFIG_SAMSUNG_ATAGS)
  54. static int nr_uarts __initdata = 0;
  55. #ifdef CONFIG_SERIAL_SAMSUNG_UARTS
  56. static struct s3c2410_uartcfg uart_cfgs[CONFIG_SERIAL_SAMSUNG_UARTS];
  57. #endif
  58. /* s3c24xx_init_uartdevs
  59. *
  60. * copy the specified platform data and configuration into our central
  61. * set of devices, before the data is thrown away after the init process.
  62. *
  63. * This also fills in the array passed to the serial driver for the
  64. * early initialisation of the console.
  65. */
  66. void __init s3c24xx_init_uartdevs(char *name,
  67. struct s3c24xx_uart_resources *res,
  68. struct s3c2410_uartcfg *cfg, int no)
  69. {
  70. #ifdef CONFIG_SERIAL_SAMSUNG_UARTS
  71. struct platform_device *platdev;
  72. struct s3c2410_uartcfg *cfgptr = uart_cfgs;
  73. struct s3c24xx_uart_resources *resp;
  74. int uart;
  75. memcpy(cfgptr, cfg, sizeof(struct s3c2410_uartcfg) * no);
  76. for (uart = 0; uart < no; uart++, cfg++, cfgptr++) {
  77. platdev = s3c24xx_uart_src[cfgptr->hwport];
  78. resp = res + cfgptr->hwport;
  79. s3c24xx_uart_devs[uart] = platdev;
  80. platdev->name = name;
  81. platdev->resource = resp->resources;
  82. platdev->num_resources = resp->nr_resources;
  83. platdev->dev.platform_data = cfgptr;
  84. }
  85. nr_uarts = no;
  86. #endif
  87. }
  88. void __init s3c24xx_init_uarts(struct s3c2410_uartcfg *cfg, int no)
  89. {
  90. if (cpu == NULL)
  91. return;
  92. if (cpu->init_uarts == NULL && IS_ENABLED(CONFIG_SAMSUNG_ATAGS)) {
  93. printk(KERN_ERR "s3c24xx_init_uarts: cpu has no uart init\n");
  94. } else
  95. (cpu->init_uarts)(cfg, no);
  96. }
  97. #endif
  98. static int __init s3c_arch_init(void)
  99. {
  100. int ret;
  101. /* init is only needed for ATAGS based platforms */
  102. if (!IS_ENABLED(CONFIG_ATAGS))
  103. return 0;
  104. // do the correct init for cpu
  105. if (cpu == NULL) {
  106. /* Not needed when booting with device tree. */
  107. if (of_have_populated_dt())
  108. return 0;
  109. panic("s3c_arch_init: NULL cpu\n");
  110. }
  111. ret = (cpu->init)();
  112. if (ret != 0)
  113. return ret;
  114. #if IS_ENABLED(CONFIG_SAMSUNG_ATAGS)
  115. ret = platform_add_devices(s3c24xx_uart_devs, nr_uarts);
  116. #endif
  117. return ret;
  118. }
  119. arch_initcall(s3c_arch_init);