efika.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /*
  2. * Efika 5K2 platform code
  3. * Some code really inspired from the lite5200b platform.
  4. *
  5. * Copyright (C) 2006 bplan GmbH
  6. *
  7. * This file is licensed under the terms of the GNU General Public License
  8. * version 2. This program is licensed "as is" without any warranty of any
  9. * kind, whether express or implied.
  10. */
  11. #include <linux/errno.h>
  12. #include <linux/kernel.h>
  13. #include <linux/slab.h>
  14. #include <linux/reboot.h>
  15. #include <linux/init.h>
  16. #include <linux/utsrelease.h>
  17. #include <linux/seq_file.h>
  18. #include <linux/string.h>
  19. #include <linux/root_dev.h>
  20. #include <linux/initrd.h>
  21. #include <linux/timer.h>
  22. #include <linux/pci.h>
  23. #include <linux/console.h>
  24. #include <asm/io.h>
  25. #include <asm/irq.h>
  26. #include <asm/sections.h>
  27. #include <asm/pci-bridge.h>
  28. #include <asm/pgtable.h>
  29. #include <asm/prom.h>
  30. #include <asm/time.h>
  31. #include <asm/machdep.h>
  32. #include <asm/rtas.h>
  33. #include <asm/of_device.h>
  34. #include <asm/of_platform.h>
  35. #include <asm/mpc52xx.h>
  36. #define EFIKA_PLATFORM_NAME "Efika"
  37. /* ------------------------------------------------------------------------ */
  38. /* PCI accesses thru RTAS */
  39. /* ------------------------------------------------------------------------ */
  40. #ifdef CONFIG_PCI
  41. /*
  42. * Access functions for PCI config space using RTAS calls.
  43. */
  44. static int rtas_read_config(struct pci_bus *bus, unsigned int devfn, int offset,
  45. int len, u32 * val)
  46. {
  47. struct pci_controller *hose = bus->sysdata;
  48. unsigned long addr = (offset & 0xff) | ((devfn & 0xff) << 8)
  49. | (((bus->number - hose->first_busno) & 0xff) << 16)
  50. | (hose->index << 24);
  51. int ret = -1;
  52. int rval;
  53. rval = rtas_call(rtas_token("read-pci-config"), 2, 2, &ret, addr, len);
  54. *val = ret;
  55. return rval ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
  56. }
  57. static int rtas_write_config(struct pci_bus *bus, unsigned int devfn,
  58. int offset, int len, u32 val)
  59. {
  60. struct pci_controller *hose = bus->sysdata;
  61. unsigned long addr = (offset & 0xff) | ((devfn & 0xff) << 8)
  62. | (((bus->number - hose->first_busno) & 0xff) << 16)
  63. | (hose->index << 24);
  64. int rval;
  65. rval = rtas_call(rtas_token("write-pci-config"), 3, 1, NULL,
  66. addr, len, val);
  67. return rval ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
  68. }
  69. static struct pci_ops rtas_pci_ops = {
  70. rtas_read_config,
  71. rtas_write_config
  72. };
  73. void __init efika_pcisetup(void)
  74. {
  75. const int *bus_range;
  76. int len;
  77. struct pci_controller *hose;
  78. struct device_node *root;
  79. struct device_node *pcictrl;
  80. root = of_find_node_by_path("/");
  81. if (root == NULL) {
  82. printk(KERN_WARNING EFIKA_PLATFORM_NAME
  83. ": Unable to find the root node\n");
  84. return;
  85. }
  86. for (pcictrl = NULL;;) {
  87. pcictrl = of_get_next_child(root, pcictrl);
  88. if ((pcictrl == NULL) || (strcmp(pcictrl->name, "pci") == 0))
  89. break;
  90. }
  91. of_node_put(root);
  92. if (pcictrl == NULL) {
  93. printk(KERN_WARNING EFIKA_PLATFORM_NAME
  94. ": Unable to find the PCI bridge node\n");
  95. return;
  96. }
  97. bus_range = of_get_property(pcictrl, "bus-range", &len);
  98. if (bus_range == NULL || len < 2 * sizeof(int)) {
  99. printk(KERN_WARNING EFIKA_PLATFORM_NAME
  100. ": Can't get bus-range for %s\n", pcictrl->full_name);
  101. return;
  102. }
  103. if (bus_range[1] == bus_range[0])
  104. printk(KERN_INFO EFIKA_PLATFORM_NAME ": PCI bus %d",
  105. bus_range[0]);
  106. else
  107. printk(KERN_INFO EFIKA_PLATFORM_NAME ": PCI buses %d..%d",
  108. bus_range[0], bus_range[1]);
  109. printk(" controlled by %s\n", pcictrl->full_name);
  110. printk("\n");
  111. hose = pcibios_alloc_controller();
  112. if (!hose) {
  113. printk(KERN_WARNING EFIKA_PLATFORM_NAME
  114. ": Can't allocate PCI controller structure for %s\n",
  115. pcictrl->full_name);
  116. return;
  117. }
  118. hose->arch_data = of_node_get(pcictrl);
  119. hose->first_busno = bus_range[0];
  120. hose->last_busno = bus_range[1];
  121. hose->ops = &rtas_pci_ops;
  122. pci_process_bridge_OF_ranges(hose, pcictrl, 0);
  123. }
  124. #else
  125. void __init efika_pcisetup(void)
  126. {}
  127. #endif
  128. /* ------------------------------------------------------------------------ */
  129. /* Platform setup */
  130. /* ------------------------------------------------------------------------ */
  131. static void efika_show_cpuinfo(struct seq_file *m)
  132. {
  133. struct device_node *root;
  134. const char *revision;
  135. const char *codegendescription;
  136. const char *codegenvendor;
  137. root = of_find_node_by_path("/");
  138. if (!root)
  139. return;
  140. revision = of_get_property(root, "revision", NULL);
  141. codegendescription = of_get_property(root, "CODEGEN,description", NULL);
  142. codegenvendor = of_get_property(root, "CODEGEN,vendor", NULL);
  143. if (codegendescription)
  144. seq_printf(m, "machine\t\t: %s\n", codegendescription);
  145. else
  146. seq_printf(m, "machine\t\t: Efika\n");
  147. if (revision)
  148. seq_printf(m, "revision\t: %s\n", revision);
  149. if (codegenvendor)
  150. seq_printf(m, "vendor\t\t: %s\n", codegenvendor);
  151. of_node_put(root);
  152. }
  153. static void __init efika_setup_arch(void)
  154. {
  155. rtas_initialize();
  156. #ifdef CONFIG_BLK_DEV_INITRD
  157. initrd_below_start_ok = 1;
  158. if (initrd_start)
  159. ROOT_DEV = Root_RAM0;
  160. else
  161. #endif
  162. ROOT_DEV = Root_SDA2; /* sda2 (sda1 is for the kernel) */
  163. efika_pcisetup();
  164. if (ppc_md.progress)
  165. ppc_md.progress("Linux/PPC " UTS_RELEASE " running on Efika ;-)\n", 0x0);
  166. }
  167. static int __init efika_probe(void)
  168. {
  169. char *model = of_get_flat_dt_prop(of_get_flat_dt_root(),
  170. "model", NULL);
  171. if (model == NULL)
  172. return 0;
  173. if (strcmp(model, "EFIKA5K2"))
  174. return 0;
  175. ISA_DMA_THRESHOLD = ~0L;
  176. DMA_MODE_READ = 0x44;
  177. DMA_MODE_WRITE = 0x48;
  178. return 1;
  179. }
  180. static void __init efika_init_early(void)
  181. {
  182. #ifdef CONFIG_SERIAL_MPC52xx
  183. struct device_node *stdout_node;
  184. const char *device_type;
  185. if (strstr(cmd_line, "console="))
  186. return;
  187. /* find the boot console from /chosen/stdout */
  188. if (!of_chosen)
  189. return;
  190. device_type = of_get_property(of_chosen, "linux,stdout-path", NULL);
  191. if (!device_type)
  192. return;
  193. stdout_node = of_find_node_by_path(device_type);
  194. if (stdout_node) {
  195. device_type = of_get_property(stdout_node, "device_type", NULL);
  196. if (device_type && strcmp(device_type, "serial") == 0)
  197. add_preferred_console("ttyPSC", 0, NULL);
  198. of_node_put(stdout_node);
  199. }
  200. #endif
  201. }
  202. define_machine(efika)
  203. {
  204. .name = EFIKA_PLATFORM_NAME,
  205. .probe = efika_probe,
  206. .setup_arch = efika_setup_arch,
  207. .init = mpc52xx_declare_of_platform_devices,
  208. .init_early = efika_init_early,
  209. .show_cpuinfo = efika_show_cpuinfo,
  210. .init_IRQ = mpc52xx_init_irq,
  211. .get_irq = mpc52xx_get_irq,
  212. .restart = rtas_restart,
  213. .power_off = rtas_power_off,
  214. .halt = rtas_halt,
  215. .set_rtc_time = rtas_set_rtc_time,
  216. .get_rtc_time = rtas_get_rtc_time,
  217. .progress = rtas_progress,
  218. .get_boot_time = rtas_get_boot_time,
  219. .calibrate_decr = generic_calibrate_decr,
  220. .phys_mem_access_prot = pci_phys_mem_access_prot,
  221. };