efika.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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/init.h>
  12. #include <linux/utsrelease.h>
  13. #include <linux/pci.h>
  14. #include <linux/of.h>
  15. #include <asm/prom.h>
  16. #include <asm/time.h>
  17. #include <asm/machdep.h>
  18. #include <asm/rtas.h>
  19. #include <asm/mpc52xx.h>
  20. #define EFIKA_PLATFORM_NAME "Efika"
  21. /* ------------------------------------------------------------------------ */
  22. /* PCI accesses thru RTAS */
  23. /* ------------------------------------------------------------------------ */
  24. #ifdef CONFIG_PCI
  25. /*
  26. * Access functions for PCI config space using RTAS calls.
  27. */
  28. static int rtas_read_config(struct pci_bus *bus, unsigned int devfn, int offset,
  29. int len, u32 * val)
  30. {
  31. struct pci_controller *hose = bus->sysdata;
  32. unsigned long addr = (offset & 0xff) | ((devfn & 0xff) << 8)
  33. | (((bus->number - hose->first_busno) & 0xff) << 16)
  34. | (hose->global_number << 24);
  35. int ret = -1;
  36. int rval;
  37. rval = rtas_call(rtas_token("read-pci-config"), 2, 2, &ret, addr, len);
  38. *val = ret;
  39. return rval ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
  40. }
  41. static int rtas_write_config(struct pci_bus *bus, unsigned int devfn,
  42. int offset, int len, u32 val)
  43. {
  44. struct pci_controller *hose = bus->sysdata;
  45. unsigned long addr = (offset & 0xff) | ((devfn & 0xff) << 8)
  46. | (((bus->number - hose->first_busno) & 0xff) << 16)
  47. | (hose->global_number << 24);
  48. int rval;
  49. rval = rtas_call(rtas_token("write-pci-config"), 3, 1, NULL,
  50. addr, len, val);
  51. return rval ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
  52. }
  53. static struct pci_ops rtas_pci_ops = {
  54. .read = rtas_read_config,
  55. .write = rtas_write_config,
  56. };
  57. static void __init efika_pcisetup(void)
  58. {
  59. const int *bus_range;
  60. int len;
  61. struct pci_controller *hose;
  62. struct device_node *root;
  63. struct device_node *pcictrl;
  64. root = of_find_node_by_path("/");
  65. if (root == NULL) {
  66. printk(KERN_WARNING EFIKA_PLATFORM_NAME
  67. ": Unable to find the root node\n");
  68. return;
  69. }
  70. for (pcictrl = NULL;;) {
  71. pcictrl = of_get_next_child(root, pcictrl);
  72. if ((pcictrl == NULL) || (strcmp(pcictrl->name, "pci") == 0))
  73. break;
  74. }
  75. of_node_put(root);
  76. if (pcictrl == NULL) {
  77. printk(KERN_WARNING EFIKA_PLATFORM_NAME
  78. ": Unable to find the PCI bridge node\n");
  79. return;
  80. }
  81. bus_range = of_get_property(pcictrl, "bus-range", &len);
  82. if (bus_range == NULL || len < 2 * sizeof(int)) {
  83. printk(KERN_WARNING EFIKA_PLATFORM_NAME
  84. ": Can't get bus-range for %s\n", pcictrl->full_name);
  85. return;
  86. }
  87. if (bus_range[1] == bus_range[0])
  88. printk(KERN_INFO EFIKA_PLATFORM_NAME ": PCI bus %d",
  89. bus_range[0]);
  90. else
  91. printk(KERN_INFO EFIKA_PLATFORM_NAME ": PCI buses %d..%d",
  92. bus_range[0], bus_range[1]);
  93. printk(" controlled by %s\n", pcictrl->full_name);
  94. printk("\n");
  95. hose = pcibios_alloc_controller(of_node_get(pcictrl));
  96. if (!hose) {
  97. printk(KERN_WARNING EFIKA_PLATFORM_NAME
  98. ": Can't allocate PCI controller structure for %s\n",
  99. pcictrl->full_name);
  100. return;
  101. }
  102. hose->first_busno = bus_range[0];
  103. hose->last_busno = bus_range[1];
  104. hose->ops = &rtas_pci_ops;
  105. pci_process_bridge_OF_ranges(hose, pcictrl, 0);
  106. }
  107. #else
  108. static void __init efika_pcisetup(void)
  109. {}
  110. #endif
  111. /* ------------------------------------------------------------------------ */
  112. /* Platform setup */
  113. /* ------------------------------------------------------------------------ */
  114. static void efika_show_cpuinfo(struct seq_file *m)
  115. {
  116. struct device_node *root;
  117. const char *revision;
  118. const char *codegendescription;
  119. const char *codegenvendor;
  120. root = of_find_node_by_path("/");
  121. if (!root)
  122. return;
  123. revision = of_get_property(root, "revision", NULL);
  124. codegendescription = of_get_property(root, "CODEGEN,description", NULL);
  125. codegenvendor = of_get_property(root, "CODEGEN,vendor", NULL);
  126. if (codegendescription)
  127. seq_printf(m, "machine\t\t: %s\n", codegendescription);
  128. else
  129. seq_printf(m, "machine\t\t: Efika\n");
  130. if (revision)
  131. seq_printf(m, "revision\t: %s\n", revision);
  132. if (codegenvendor)
  133. seq_printf(m, "vendor\t\t: %s\n", codegenvendor);
  134. of_node_put(root);
  135. }
  136. #ifdef CONFIG_PM
  137. static void efika_suspend_prepare(void __iomem *mbar)
  138. {
  139. u8 pin = 4; /* GPIO_WKUP_4 (GPIO_PSC6_0 - IRDA_RX) */
  140. u8 level = 1; /* wakeup on high level */
  141. /* IOW. to wake it up, short pins 1 and 3 on IRDA connector */
  142. mpc52xx_set_wakeup_gpio(pin, level);
  143. }
  144. #endif
  145. static void __init efika_setup_arch(void)
  146. {
  147. rtas_initialize();
  148. /* Map important registers from the internal memory map */
  149. mpc52xx_map_common_devices();
  150. efika_pcisetup();
  151. #ifdef CONFIG_PM
  152. mpc52xx_suspend.board_suspend_prepare = efika_suspend_prepare;
  153. mpc52xx_pm_init();
  154. #endif
  155. if (ppc_md.progress)
  156. ppc_md.progress("Linux/PPC " UTS_RELEASE " running on Efika ;-)\n", 0x0);
  157. }
  158. static int __init efika_probe(void)
  159. {
  160. char *model = of_get_flat_dt_prop(of_get_flat_dt_root(),
  161. "model", NULL);
  162. if (model == NULL)
  163. return 0;
  164. if (strcmp(model, "EFIKA5K2"))
  165. return 0;
  166. ISA_DMA_THRESHOLD = ~0L;
  167. DMA_MODE_READ = 0x44;
  168. DMA_MODE_WRITE = 0x48;
  169. return 1;
  170. }
  171. define_machine(efika)
  172. {
  173. .name = EFIKA_PLATFORM_NAME,
  174. .probe = efika_probe,
  175. .setup_arch = efika_setup_arch,
  176. .init = mpc52xx_declare_of_platform_devices,
  177. .show_cpuinfo = efika_show_cpuinfo,
  178. .init_IRQ = mpc52xx_init_irq,
  179. .get_irq = mpc52xx_get_irq,
  180. .restart = rtas_restart,
  181. .power_off = rtas_power_off,
  182. .halt = rtas_halt,
  183. .set_rtc_time = rtas_set_rtc_time,
  184. .get_rtc_time = rtas_get_rtc_time,
  185. .progress = rtas_progress,
  186. .get_boot_time = rtas_get_boot_time,
  187. .calibrate_decr = generic_calibrate_decr,
  188. #ifdef CONFIG_PCI
  189. .phys_mem_access_prot = pci_phys_mem_access_prot,
  190. #endif
  191. };