Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  * Support routines for initializing a PCI subsystem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  * Extruded from code written by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  *      Dave Rusling (david.rusling@reo.mts.dec.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7)  *      David Mosberger (davidm@cs.arizona.edu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8)  *	David Miller (davem@redhat.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/ioport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/cache.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "pci.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) void pci_assign_irq(struct pci_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) 	u8 pin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) 	u8 slot = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 	int irq = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 	struct pci_host_bridge *hbrg = pci_find_host_bridge(dev->bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 	if (!(hbrg->map_irq)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 		pci_dbg(dev, "runtime IRQ mapping not provided by arch\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 	/* If this device is not on the primary bus, we need to figure out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 	   which interrupt pin it will come in on.   We know which slot it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 	   will come in on 'cos that slot is where the bridge is.   Each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 	   time the interrupt line passes through a PCI-PCI bridge we must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 	   apply the swizzle function.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 	pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 	/* Cope with illegal. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 	if (pin > 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 		pin = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 	if (pin) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 		/* Follow the chain of bridges, swizzling as we go.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 		if (hbrg->swizzle_irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 			slot = (*(hbrg->swizzle_irq))(dev, &pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 		 * If a swizzling function is not used map_irq must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 		 * ignore slot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 		irq = (*(hbrg->map_irq))(dev, slot, pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 		if (irq == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 			irq = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 	dev->irq = irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 	pci_dbg(dev, "assign IRQ: got %d\n", dev->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 	/* Always tell the device, so the driver knows what is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 	   the real IRQ to use; the device does not use it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 	pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) }