efika.c 6.0 KB

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