/arch/powerpc/platforms/52xx/efika.c

http://github.com/mirrors/linux · C · 236 lines · 170 code · 45 blank · 21 comment · 19 complexity · 98effae039055ee6e7b95be2d42dc881 MD5 · raw file

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