efika.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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/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 = pci_bus_to_host(bus);
  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 = pci_bus_to_host(bus);
  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_each_child_of_node(root, pcictrl)
  71. if (of_node_name_eq(pcictrl, "pci"))
  72. break;
  73. of_node_put(root);
  74. if (pcictrl == NULL) {
  75. printk(KERN_WARNING EFIKA_PLATFORM_NAME
  76. ": Unable to find the PCI bridge node\n");
  77. return;
  78. }
  79. bus_range = of_get_property(pcictrl, "bus-range", &len);
  80. if (bus_range == NULL || len < 2 * sizeof(int)) {
  81. printk(KERN_WARNING EFIKA_PLATFORM_NAME
  82. ": Can't get bus-range for %pOF\n", pcictrl);
  83. goto out_put;
  84. }
  85. if (bus_range[1] == bus_range[0])
  86. printk(KERN_INFO EFIKA_PLATFORM_NAME ": PCI bus %d",
  87. bus_range[0]);
  88. else
  89. printk(KERN_INFO EFIKA_PLATFORM_NAME ": PCI buses %d..%d",
  90. bus_range[0], bus_range[1]);
  91. printk(" controlled by %pOF\n", pcictrl);
  92. printk("\n");
  93. hose = pcibios_alloc_controller(pcictrl);
  94. if (!hose) {
  95. printk(KERN_WARNING EFIKA_PLATFORM_NAME
  96. ": Can't allocate PCI controller structure for %pOF\n",
  97. pcictrl);
  98. goto out_put;
  99. }
  100. hose->first_busno = bus_range[0];
  101. hose->last_busno = bus_range[1];
  102. hose->ops = &rtas_pci_ops;
  103. pci_process_bridge_OF_ranges(hose, pcictrl, 0);
  104. return;
  105. out_put:
  106. of_node_put(pcictrl);
  107. }
  108. #else
  109. static void __init efika_pcisetup(void)
  110. {}
  111. #endif
  112. /* ------------------------------------------------------------------------ */
  113. /* Platform setup */
  114. /* ------------------------------------------------------------------------ */
  115. static void efika_show_cpuinfo(struct seq_file *m)
  116. {
  117. struct device_node *root;
  118. const char *revision;
  119. const char *codegendescription;
  120. const char *codegenvendor;
  121. root = of_find_node_by_path("/");
  122. if (!root)
  123. return;
  124. revision = of_get_property(root, "revision", NULL);
  125. codegendescription = of_get_property(root, "CODEGEN,description", NULL);
  126. codegenvendor = of_get_property(root, "CODEGEN,vendor", NULL);
  127. if (codegendescription)
  128. seq_printf(m, "machine\t\t: %s\n", codegendescription);
  129. else
  130. seq_printf(m, "machine\t\t: Efika\n");
  131. if (revision)
  132. seq_printf(m, "revision\t: %s\n", revision);
  133. if (codegenvendor)
  134. seq_printf(m, "vendor\t\t: %s\n", codegenvendor);
  135. of_node_put(root);
  136. }
  137. #ifdef CONFIG_PM
  138. static void efika_suspend_prepare(void __iomem *mbar)
  139. {
  140. u8 pin = 4; /* GPIO_WKUP_4 (GPIO_PSC6_0 - IRDA_RX) */
  141. u8 level = 1; /* wakeup on high level */
  142. /* IOW. to wake it up, short pins 1 and 3 on IRDA connector */
  143. mpc52xx_set_wakeup_gpio(pin, level);
  144. }
  145. #endif
  146. static void __init efika_setup_arch(void)
  147. {
  148. rtas_initialize();
  149. /* Map important registers from the internal memory map */
  150. mpc52xx_map_common_devices();
  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. const char *model = of_get_property(of_root, "model", NULL);
  161. if (model == NULL)
  162. return 0;
  163. if (strcmp(model, "EFIKA5K2"))
  164. return 0;
  165. DMA_MODE_READ = 0x44;
  166. DMA_MODE_WRITE = 0x48;
  167. pm_power_off = rtas_power_off;
  168. return 1;
  169. }
  170. define_machine(efika)
  171. {
  172. .name = EFIKA_PLATFORM_NAME,
  173. .probe = efika_probe,
  174. .setup_arch = efika_setup_arch,
  175. .discover_phbs = efika_pcisetup,
  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. .halt = rtas_halt,
  182. .set_rtc_time = rtas_set_rtc_time,
  183. .get_rtc_time = rtas_get_rtc_time,
  184. .progress = rtas_progress,
  185. .get_boot_time = rtas_get_boot_time,
  186. .calibrate_decr = generic_calibrate_decr,
  187. #ifdef CONFIG_PCI
  188. .phys_mem_access_prot = pci_phys_mem_access_prot,
  189. #endif
  190. };