init.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. #include <linux/init.h>
  14. #include <linux/module.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/ioport.h>
  17. #include <linux/serial_core.h>
  18. #include <linux/platform_device.h>
  19. #include <mach/hardware.h>
  20. #include <asm/mach/arch.h>
  21. #include <asm/mach/map.h>
  22. #include <plat/cpu.h>
  23. #include <plat/devs.h>
  24. #include <plat/clock.h>
  25. #include <plat/regs-serial.h>
  26. static struct cpu_table *cpu;
  27. static struct cpu_table * __init s3c_lookup_cpu(unsigned long idcode,
  28. struct cpu_table *tab,
  29. unsigned int count)
  30. {
  31. for (; count != 0; count--, tab++) {
  32. if ((idcode & tab->idmask) == (tab->idcode & tab->idmask))
  33. return tab;
  34. }
  35. return NULL;
  36. }
  37. void __init s3c_init_cpu(unsigned long idcode,
  38. struct cpu_table *cputab, unsigned int cputab_size)
  39. {
  40. cpu = s3c_lookup_cpu(idcode, cputab, cputab_size);
  41. if (cpu == NULL) {
  42. printk(KERN_ERR "Unknown CPU type 0x%08lx\n", idcode);
  43. panic("Unknown S3C24XX CPU");
  44. }
  45. printk("CPU %s (id 0x%08lx)\n", cpu->name, idcode);
  46. if (cpu->init == NULL) {
  47. printk(KERN_ERR "CPU %s support not enabled\n", cpu->name);
  48. panic("Unsupported Samsung CPU");
  49. }
  50. if (cpu->map_io)
  51. cpu->map_io();
  52. }
  53. /* s3c24xx_init_clocks
  54. *
  55. * Initialise the clock subsystem and associated information from the
  56. * given master crystal value.
  57. *
  58. * xtal = 0 -> use default PLL crystal value (normally 12MHz)
  59. * != 0 -> PLL crystal value in Hz
  60. */
  61. void __init s3c24xx_init_clocks(int xtal)
  62. {
  63. if (xtal == 0)
  64. xtal = 12*1000*1000;
  65. if (cpu == NULL)
  66. panic("s3c24xx_init_clocks: no cpu setup?\n");
  67. if (cpu->init_clocks == NULL)
  68. panic("s3c24xx_init_clocks: cpu has no clock init\n");
  69. else
  70. (cpu->init_clocks)(xtal);
  71. }
  72. /* uart management */
  73. #if IS_ENABLED(CONFIG_SAMSUNG_ATAGS)
  74. static int nr_uarts __initdata = 0;
  75. static struct s3c2410_uartcfg uart_cfgs[CONFIG_SERIAL_SAMSUNG_UARTS];
  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. struct platform_device *platdev;
  89. struct s3c2410_uartcfg *cfgptr = uart_cfgs;
  90. struct s3c24xx_uart_resources *resp;
  91. int uart;
  92. memcpy(cfgptr, cfg, sizeof(struct s3c2410_uartcfg) * no);
  93. for (uart = 0; uart < no; uart++, cfg++, cfgptr++) {
  94. platdev = s3c24xx_uart_src[cfgptr->hwport];
  95. resp = res + cfgptr->hwport;
  96. s3c24xx_uart_devs[uart] = platdev;
  97. platdev->name = name;
  98. platdev->resource = resp->resources;
  99. platdev->num_resources = resp->nr_resources;
  100. platdev->dev.platform_data = cfgptr;
  101. }
  102. nr_uarts = no;
  103. }
  104. void __init s3c24xx_init_uarts(struct s3c2410_uartcfg *cfg, int no)
  105. {
  106. if (cpu == NULL)
  107. return;
  108. if (cpu->init_uarts == NULL && IS_ENABLED(CONFIG_SAMSUNG_ATAGS)) {
  109. printk(KERN_ERR "s3c24xx_init_uarts: cpu has no uart init\n");
  110. } else
  111. (cpu->init_uarts)(cfg, no);
  112. }
  113. #endif
  114. static int __init s3c_arch_init(void)
  115. {
  116. int ret;
  117. // do the correct init for cpu
  118. if (cpu == NULL)
  119. panic("s3c_arch_init: NULL cpu\n");
  120. ret = (cpu->init)();
  121. if (ret != 0)
  122. return ret;
  123. #if IS_ENABLED(CONFIG_SAMSUNG_ATAGS)
  124. ret = platform_add_devices(s3c24xx_uart_devs, nr_uarts);
  125. #endif
  126. return ret;
  127. }
  128. arch_initcall(s3c_arch_init);