init.c 4.1 KB

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