init.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 <plat/cpu.h>
  23. #include <plat/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. }
  51. /* s3c24xx_init_clocks
  52. *
  53. * Initialise the clock subsystem and associated information from the
  54. * given master crystal value.
  55. *
  56. * xtal = 0 -> use default PLL crystal value (normally 12MHz)
  57. * != 0 -> PLL crystal value in Hz
  58. */
  59. void __init s3c24xx_init_clocks(int xtal)
  60. {
  61. if (xtal == 0)
  62. xtal = 12*1000*1000;
  63. if (cpu == NULL)
  64. panic("s3c24xx_init_clocks: no cpu setup?\n");
  65. if (cpu->init_clocks == NULL)
  66. panic("s3c24xx_init_clocks: cpu has no clock init\n");
  67. else
  68. (cpu->init_clocks)(xtal);
  69. }
  70. /* uart management */
  71. #if IS_ENABLED(CONFIG_SAMSUNG_ATAGS)
  72. static int nr_uarts __initdata = 0;
  73. #ifdef CONFIG_SERIAL_SAMSUNG_UARTS
  74. static struct s3c2410_uartcfg uart_cfgs[CONFIG_SERIAL_SAMSUNG_UARTS];
  75. #endif
  76. /* s3c24xx_init_uartdevs
  77. *
  78. * copy the specified platform data and configuration into our central
  79. * set of devices, before the data is thrown away after the init process.
  80. *
  81. * This also fills in the array passed to the serial driver for the
  82. * early initialisation of the console.
  83. */
  84. void __init s3c24xx_init_uartdevs(char *name,
  85. struct s3c24xx_uart_resources *res,
  86. struct s3c2410_uartcfg *cfg, int no)
  87. {
  88. #ifdef CONFIG_SERIAL_SAMSUNG_UARTS
  89. struct platform_device *platdev;
  90. struct s3c2410_uartcfg *cfgptr = uart_cfgs;
  91. struct s3c24xx_uart_resources *resp;
  92. int uart;
  93. memcpy(cfgptr, cfg, sizeof(struct s3c2410_uartcfg) * no);
  94. for (uart = 0; uart < no; uart++, cfg++, cfgptr++) {
  95. platdev = s3c24xx_uart_src[cfgptr->hwport];
  96. resp = res + cfgptr->hwport;
  97. s3c24xx_uart_devs[uart] = platdev;
  98. platdev->name = name;
  99. platdev->resource = resp->resources;
  100. platdev->num_resources = resp->nr_resources;
  101. platdev->dev.platform_data = cfgptr;
  102. }
  103. nr_uarts = no;
  104. #endif
  105. }
  106. void __init s3c24xx_init_uarts(struct s3c2410_uartcfg *cfg, int no)
  107. {
  108. if (cpu == NULL)
  109. return;
  110. if (cpu->init_uarts == NULL && IS_ENABLED(CONFIG_SAMSUNG_ATAGS)) {
  111. printk(KERN_ERR "s3c24xx_init_uarts: cpu has no uart init\n");
  112. } else
  113. (cpu->init_uarts)(cfg, no);
  114. }
  115. #endif
  116. static int __init s3c_arch_init(void)
  117. {
  118. int ret;
  119. /* init is only needed for ATAGS based platforms */
  120. if (!IS_ENABLED(CONFIG_ATAGS) ||
  121. (!soc_is_s3c24xx() && !soc_is_s3c64xx()))
  122. return 0;
  123. // do the correct init for cpu
  124. if (cpu == NULL) {
  125. /* Not needed when booting with device tree. */
  126. if (of_have_populated_dt())
  127. return 0;
  128. panic("s3c_arch_init: NULL cpu\n");
  129. }
  130. ret = (cpu->init)();
  131. if (ret != 0)
  132. return ret;
  133. #if IS_ENABLED(CONFIG_SAMSUNG_ATAGS)
  134. ret = platform_add_devices(s3c24xx_uart_devs, nr_uarts);
  135. #endif
  136. return ret;
  137. }
  138. arch_initcall(s3c_arch_init);