init.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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->map_io == NULL || cpu->init == NULL) {
  47. printk(KERN_ERR "CPU %s support not enabled\n", cpu->name);
  48. panic("Unsupported Samsung CPU");
  49. }
  50. cpu->map_io();
  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. static struct s3c2410_uartcfg uart_cfgs[CONFIG_SERIAL_SAMSUNG_UARTS];
  75. /* s3c24xx_init_uartdevs
  76. *
  77. * copy the specified platform data and configuration into our central
  78. * set of devices, before the data is thrown away after the init process.
  79. *
  80. * This also fills in the array passed to the serial driver for the
  81. * early initialisation of the console.
  82. */
  83. void __init s3c24xx_init_uartdevs(char *name,
  84. struct s3c24xx_uart_resources *res,
  85. struct s3c2410_uartcfg *cfg, int no)
  86. {
  87. struct platform_device *platdev;
  88. struct s3c2410_uartcfg *cfgptr = uart_cfgs;
  89. struct s3c24xx_uart_resources *resp;
  90. int uart;
  91. memcpy(cfgptr, cfg, sizeof(struct s3c2410_uartcfg) * no);
  92. for (uart = 0; uart < no; uart++, cfg++, cfgptr++) {
  93. platdev = s3c24xx_uart_src[cfgptr->hwport];
  94. resp = res + cfgptr->hwport;
  95. s3c24xx_uart_devs[uart] = platdev;
  96. platdev->name = name;
  97. platdev->resource = resp->resources;
  98. platdev->num_resources = resp->nr_resources;
  99. platdev->dev.platform_data = cfgptr;
  100. }
  101. nr_uarts = no;
  102. }
  103. void __init s3c24xx_init_uarts(struct s3c2410_uartcfg *cfg, int no)
  104. {
  105. if (cpu == NULL)
  106. return;
  107. if (cpu->init_uarts == NULL && IS_ENABLED(CONFIG_SAMSUNG_ATAGS)) {
  108. printk(KERN_ERR "s3c24xx_init_uarts: cpu has no uart init\n");
  109. } else
  110. (cpu->init_uarts)(cfg, no);
  111. }
  112. #endif
  113. static int __init s3c_arch_init(void)
  114. {
  115. int ret;
  116. // do the correct init for cpu
  117. if (cpu == NULL)
  118. panic("s3c_arch_init: NULL cpu\n");
  119. ret = (cpu->init)();
  120. if (ret != 0)
  121. return ret;
  122. #if IS_ENABLED(CONFIG_SAMSUNG_ATAGS)
  123. ret = platform_add_devices(s3c24xx_uart_devs, nr_uarts);
  124. #endif
  125. return ret;
  126. }
  127. arch_initcall(s3c_arch_init);