mv64x60_pci.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * PCI bus setup for Marvell mv64360/mv64460 host bridges (Discovery)
  3. *
  4. * Author: Dale Farnsworth <dale@farnsworth.org>
  5. *
  6. * 2007 (c) MontaVista, Software, Inc. This file is licensed under
  7. * the terms of the GNU General Public License version 2. This program
  8. * is licensed "as is" without any warranty of any kind, whether express
  9. * or implied.
  10. */
  11. #include <linux/stddef.h>
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/pci.h>
  15. #include <asm/prom.h>
  16. #include <asm/pci-bridge.h>
  17. #define PCI_HEADER_TYPE_INVALID 0x7f /* Invalid PCI header type */
  18. #ifdef CONFIG_SYSFS
  19. /* 32-bit hex or dec stringified number + '\n' */
  20. #define MV64X60_VAL_LEN_MAX 11
  21. #define MV64X60_PCICFG_CPCI_HOTSWAP 0x68
  22. static ssize_t mv64x60_hs_reg_read(struct file *filp, struct kobject *kobj,
  23. struct bin_attribute *attr, char *buf,
  24. loff_t off, size_t count)
  25. {
  26. struct pci_dev *phb;
  27. u32 v;
  28. if (off > 0)
  29. return 0;
  30. if (count < MV64X60_VAL_LEN_MAX)
  31. return -EINVAL;
  32. phb = pci_get_bus_and_slot(0, PCI_DEVFN(0, 0));
  33. if (!phb)
  34. return -ENODEV;
  35. pci_read_config_dword(phb, MV64X60_PCICFG_CPCI_HOTSWAP, &v);
  36. pci_dev_put(phb);
  37. return sprintf(buf, "0x%08x\n", v);
  38. }
  39. static ssize_t mv64x60_hs_reg_write(struct file *filp, struct kobject *kobj,
  40. struct bin_attribute *attr, char *buf,
  41. loff_t off, size_t count)
  42. {
  43. struct pci_dev *phb;
  44. u32 v;
  45. if (off > 0)
  46. return 0;
  47. if (count <= 0)
  48. return -EINVAL;
  49. if (sscanf(buf, "%i", &v) != 1)
  50. return -EINVAL;
  51. phb = pci_get_bus_and_slot(0, PCI_DEVFN(0, 0));
  52. if (!phb)
  53. return -ENODEV;
  54. pci_write_config_dword(phb, MV64X60_PCICFG_CPCI_HOTSWAP, v);
  55. pci_dev_put(phb);
  56. return count;
  57. }
  58. static struct bin_attribute mv64x60_hs_reg_attr = { /* Hotswap register */
  59. .attr = {
  60. .name = "hs_reg",
  61. .mode = S_IRUGO | S_IWUSR,
  62. },
  63. .size = MV64X60_VAL_LEN_MAX,
  64. .read = mv64x60_hs_reg_read,
  65. .write = mv64x60_hs_reg_write,
  66. };
  67. static int __init mv64x60_sysfs_init(void)
  68. {
  69. struct device_node *np;
  70. struct platform_device *pdev;
  71. const unsigned int *prop;
  72. np = of_find_compatible_node(NULL, NULL, "marvell,mv64360");
  73. if (!np)
  74. return 0;
  75. prop = of_get_property(np, "hs_reg_valid", NULL);
  76. of_node_put(np);
  77. pdev = platform_device_register_simple("marvell,mv64360", 0, NULL, 0);
  78. if (IS_ERR(pdev))
  79. return PTR_ERR(pdev);
  80. return sysfs_create_bin_file(&pdev->dev.kobj, &mv64x60_hs_reg_attr);
  81. }
  82. subsys_initcall(mv64x60_sysfs_init);
  83. #endif /* CONFIG_SYSFS */
  84. static void __init mv64x60_pci_fixup_early(struct pci_dev *dev)
  85. {
  86. /*
  87. * Set the host bridge hdr_type to an invalid value so that
  88. * pci_setup_device() will ignore the host bridge.
  89. */
  90. dev->hdr_type = PCI_HEADER_TYPE_INVALID;
  91. }
  92. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_MARVELL, PCI_DEVICE_ID_MARVELL_MV64360,
  93. mv64x60_pci_fixup_early);
  94. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_MARVELL, PCI_DEVICE_ID_MARVELL_MV64460,
  95. mv64x60_pci_fixup_early);
  96. static int __init mv64x60_add_bridge(struct device_node *dev)
  97. {
  98. int len;
  99. struct pci_controller *hose;
  100. struct resource rsrc;
  101. const int *bus_range;
  102. int primary;
  103. memset(&rsrc, 0, sizeof(rsrc));
  104. /* Fetch host bridge registers address */
  105. if (of_address_to_resource(dev, 0, &rsrc)) {
  106. printk(KERN_ERR "No PCI reg property in device tree\n");
  107. return -ENODEV;
  108. }
  109. /* Get bus range if any */
  110. bus_range = of_get_property(dev, "bus-range", &len);
  111. if (bus_range == NULL || len < 2 * sizeof(int))
  112. printk(KERN_WARNING "Can't get bus-range for %s, assume"
  113. " bus 0\n", dev->full_name);
  114. hose = pcibios_alloc_controller(dev);
  115. if (!hose)
  116. return -ENOMEM;
  117. hose->first_busno = bus_range ? bus_range[0] : 0;
  118. hose->last_busno = bus_range ? bus_range[1] : 0xff;
  119. setup_indirect_pci(hose, rsrc.start, rsrc.start + 4, 0);
  120. hose->self_busno = hose->first_busno;
  121. printk(KERN_INFO "Found MV64x60 PCI host bridge at 0x%016llx. "
  122. "Firmware bus number: %d->%d\n",
  123. (unsigned long long)rsrc.start, hose->first_busno,
  124. hose->last_busno);
  125. /* Interpret the "ranges" property */
  126. /* This also maps the I/O region and sets isa_io/mem_base */
  127. primary = (hose->first_busno == 0);
  128. pci_process_bridge_OF_ranges(hose, dev, primary);
  129. return 0;
  130. }
  131. void __init mv64x60_pci_init(void)
  132. {
  133. struct device_node *np;
  134. for_each_compatible_node(np, "pci", "marvell,mv64360-pci")
  135. mv64x60_add_bridge(np);
  136. }