init.c 3.6 KB

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