]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - drivers/pci/pci-uclass.c
ddr: altera: Remove unnecessary update of the SCC
[people/ms/u-boot.git] / drivers / pci / pci-uclass.c
index 478bdc99b7518fd377e05fd4c5890a00d89f8060..c7fbf7bf669102bd20755e60997ef8528a3c6124 100644 (file)
@@ -22,7 +22,7 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-static int pci_get_bus(int busnum, struct udevice **busp)
+int pci_get_bus(int busnum, struct udevice **busp)
 {
        int ret;
 
@@ -30,31 +30,15 @@ static int pci_get_bus(int busnum, struct udevice **busp)
 
        /* Since buses may not be numbered yet try a little harder with bus 0 */
        if (ret == -ENODEV) {
-               ret = uclass_first_device(UCLASS_PCI, busp);
+               ret = uclass_first_device_err(UCLASS_PCI, busp);
                if (ret)
                        return ret;
-               else if (!*busp)
-                       return -ENODEV;
                ret = uclass_get_device_by_seq(UCLASS_PCI, busnum, busp);
        }
 
        return ret;
 }
 
-struct pci_controller *pci_bus_to_hose(int busnum)
-{
-       struct udevice *bus;
-       int ret;
-
-       ret = pci_get_bus(busnum, &bus);
-       if (ret) {
-               debug("%s: Cannot get bus %d: ret=%d\n", __func__, busnum, ret);
-               return NULL;
-       }
-
-       return dev_get_uclass_priv(bus);
-}
-
 struct udevice *pci_get_controller(struct udevice *dev)
 {
        while (device_is_on_pci_bus(dev))
@@ -266,6 +250,21 @@ int pci_bus_write_config(struct udevice *bus, pci_dev_t bdf, int offset,
        return ops->write_config(bus, bdf, offset, value, size);
 }
 
+int pci_bus_clrset_config32(struct udevice *bus, pci_dev_t bdf, int offset,
+                           u32 clr, u32 set)
+{
+       ulong val;
+       int ret;
+
+       ret = pci_bus_read_config(bus, bdf, offset, &val, PCI_SIZE_32);
+       if (ret)
+               return ret;
+       val &= ~clr;
+       val |= set;
+
+       return pci_bus_write_config(bus, bdf, offset, val, PCI_SIZE_32);
+}
+
 int pci_write_config(pci_dev_t bdf, int offset, unsigned long value,
                     enum pci_size_t size)
 {
@@ -290,7 +289,6 @@ int dm_pci_write_config(struct udevice *dev, int offset, unsigned long value,
                                    size);
 }
 
-
 int pci_write_config32(pci_dev_t bdf, int offset, u32 value)
 {
        return pci_write_config(bdf, offset, value, PCI_SIZE_32);
@@ -434,6 +432,48 @@ int dm_pci_read_config32(struct udevice *dev, int offset, u32 *valuep)
        return 0;
 }
 
+int dm_pci_clrset_config8(struct udevice *dev, int offset, u32 clr, u32 set)
+{
+       u8 val;
+       int ret;
+
+       ret = dm_pci_read_config8(dev, offset, &val);
+       if (ret)
+               return ret;
+       val &= ~clr;
+       val |= set;
+
+       return dm_pci_write_config8(dev, offset, val);
+}
+
+int dm_pci_clrset_config16(struct udevice *dev, int offset, u32 clr, u32 set)
+{
+       u16 val;
+       int ret;
+
+       ret = dm_pci_read_config16(dev, offset, &val);
+       if (ret)
+               return ret;
+       val &= ~clr;
+       val |= set;
+
+       return dm_pci_write_config16(dev, offset, val);
+}
+
+int dm_pci_clrset_config32(struct udevice *dev, int offset, u32 clr, u32 set)
+{
+       u32 val;
+       int ret;
+
+       ret = dm_pci_read_config32(dev, offset, &val);
+       if (ret)
+               return ret;
+       val &= ~clr;
+       val |= set;
+
+       return dm_pci_write_config32(dev, offset, val);
+}
+
 static void set_vga_bridge_bits(struct udevice *dev)
 {
        struct udevice *parent = dev->parent;
@@ -674,9 +714,7 @@ int pci_bind_bus_devices(struct udevice *bus)
                /* Find this device in the device tree */
                ret = pci_bus_find_devfn(bus, PCI_MASK_BUS(bdf), &dev);
 
-               /* Search for a driver */
-
-               /* If nothing in the device tree, bind a generic device */
+               /* If nothing in the device tree, bind a device */
                if (ret == -ENODEV) {
                        struct pci_device_id find_id;
                        ulong val;
@@ -1069,6 +1107,14 @@ u32 dm_pci_read_bar32(struct udevice *dev, int barnum)
                return addr & PCI_BASE_ADDRESS_MEM_MASK;
 }
 
+void dm_pci_write_bar32(struct udevice *dev, int barnum, u32 addr)
+{
+       int bar;
+
+       bar = PCI_BASE_ADDRESS_0 + barnum * 4;
+       dm_pci_write_config32(dev, bar, addr);
+}
+
 static int _dm_pci_bus_to_phys(struct udevice *ctlr,
                               pci_addr_t bus_addr, unsigned long flags,
                               unsigned long skip_mask, phys_addr_t *pa)
@@ -1249,3 +1295,18 @@ U_BOOT_DRIVER(pci_generic_drv) = {
        .id             = UCLASS_PCI_GENERIC,
        .of_match       = pci_generic_ids,
 };
+
+void pci_init(void)
+{
+       struct udevice *bus;
+
+       /*
+        * Enumerate all known controller devices. Enumeration has the side-
+        * effect of probing them, so PCIe devices will be enumerated too.
+        */
+       for (uclass_first_device(UCLASS_PCI, &bus);
+            bus;
+            uclass_next_device(&bus)) {
+               ;
+       }
+}