Path: blob/master/arch/powerpc/sysdev/mv64x60_pci.c
10817 views
/*1* PCI bus setup for Marvell mv64360/mv64460 host bridges (Discovery)2*3* Author: Dale Farnsworth <[email protected]>4*5* 2007 (c) MontaVista, Software, Inc. This file is licensed under6* the terms of the GNU General Public License version 2. This program7* is licensed "as is" without any warranty of any kind, whether express8* or implied.9*/1011#include <linux/stddef.h>12#include <linux/kernel.h>13#include <linux/init.h>14#include <linux/pci.h>1516#include <asm/prom.h>17#include <asm/pci-bridge.h>1819#define PCI_HEADER_TYPE_INVALID 0x7f /* Invalid PCI header type */2021#ifdef CONFIG_SYSFS22/* 32-bit hex or dec stringified number + '\n' */23#define MV64X60_VAL_LEN_MAX 1124#define MV64X60_PCICFG_CPCI_HOTSWAP 0x682526static ssize_t mv64x60_hs_reg_read(struct file *filp, struct kobject *kobj,27struct bin_attribute *attr, char *buf,28loff_t off, size_t count)29{30struct pci_dev *phb;31u32 v;3233if (off > 0)34return 0;35if (count < MV64X60_VAL_LEN_MAX)36return -EINVAL;3738phb = pci_get_bus_and_slot(0, PCI_DEVFN(0, 0));39if (!phb)40return -ENODEV;41pci_read_config_dword(phb, MV64X60_PCICFG_CPCI_HOTSWAP, &v);42pci_dev_put(phb);4344return sprintf(buf, "0x%08x\n", v);45}4647static ssize_t mv64x60_hs_reg_write(struct file *filp, struct kobject *kobj,48struct bin_attribute *attr, char *buf,49loff_t off, size_t count)50{51struct pci_dev *phb;52u32 v;5354if (off > 0)55return 0;56if (count <= 0)57return -EINVAL;5859if (sscanf(buf, "%i", &v) != 1)60return -EINVAL;6162phb = pci_get_bus_and_slot(0, PCI_DEVFN(0, 0));63if (!phb)64return -ENODEV;65pci_write_config_dword(phb, MV64X60_PCICFG_CPCI_HOTSWAP, v);66pci_dev_put(phb);6768return count;69}7071static struct bin_attribute mv64x60_hs_reg_attr = { /* Hotswap register */72.attr = {73.name = "hs_reg",74.mode = S_IRUGO | S_IWUSR,75},76.size = MV64X60_VAL_LEN_MAX,77.read = mv64x60_hs_reg_read,78.write = mv64x60_hs_reg_write,79};8081static int __init mv64x60_sysfs_init(void)82{83struct device_node *np;84struct platform_device *pdev;85const unsigned int *prop;8687np = of_find_compatible_node(NULL, NULL, "marvell,mv64360");88if (!np)89return 0;9091prop = of_get_property(np, "hs_reg_valid", NULL);92of_node_put(np);9394pdev = platform_device_register_simple("marvell,mv64360", 0, NULL, 0);95if (IS_ERR(pdev))96return PTR_ERR(pdev);9798return sysfs_create_bin_file(&pdev->dev.kobj, &mv64x60_hs_reg_attr);99}100101subsys_initcall(mv64x60_sysfs_init);102103#endif /* CONFIG_SYSFS */104105static void __init mv64x60_pci_fixup_early(struct pci_dev *dev)106{107/*108* Set the host bridge hdr_type to an invalid value so that109* pci_setup_device() will ignore the host bridge.110*/111dev->hdr_type = PCI_HEADER_TYPE_INVALID;112}113DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_MARVELL, PCI_DEVICE_ID_MARVELL_MV64360,114mv64x60_pci_fixup_early);115DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_MARVELL, PCI_DEVICE_ID_MARVELL_MV64460,116mv64x60_pci_fixup_early);117118static int __init mv64x60_add_bridge(struct device_node *dev)119{120int len;121struct pci_controller *hose;122struct resource rsrc;123const int *bus_range;124int primary;125126memset(&rsrc, 0, sizeof(rsrc));127128/* Fetch host bridge registers address */129if (of_address_to_resource(dev, 0, &rsrc)) {130printk(KERN_ERR "No PCI reg property in device tree\n");131return -ENODEV;132}133134/* Get bus range if any */135bus_range = of_get_property(dev, "bus-range", &len);136if (bus_range == NULL || len < 2 * sizeof(int))137printk(KERN_WARNING "Can't get bus-range for %s, assume"138" bus 0\n", dev->full_name);139140hose = pcibios_alloc_controller(dev);141if (!hose)142return -ENOMEM;143144hose->first_busno = bus_range ? bus_range[0] : 0;145hose->last_busno = bus_range ? bus_range[1] : 0xff;146147setup_indirect_pci(hose, rsrc.start, rsrc.start + 4, 0);148hose->self_busno = hose->first_busno;149150printk(KERN_INFO "Found MV64x60 PCI host bridge at 0x%016llx. "151"Firmware bus number: %d->%d\n",152(unsigned long long)rsrc.start, hose->first_busno,153hose->last_busno);154155/* Interpret the "ranges" property */156/* This also maps the I/O region and sets isa_io/mem_base */157primary = (hose->first_busno == 0);158pci_process_bridge_OF_ranges(hose, dev, primary);159160return 0;161}162163void __init mv64x60_pci_init(void)164{165struct device_node *np;166167for_each_compatible_node(np, "pci", "marvell,mv64360-pci")168mv64x60_add_bridge(np);169}170171172