Home | History | Annotate | Line # | Download | only in pci
      1  1.7       chs /*	$NetBSD: pci_machdep.c,v 1.7 2012/10/27 17:18:05 chs Exp $	*/
      2  1.4     lukem 
      3  1.4     lukem #include <sys/cdefs.h>
      4  1.7       chs __KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.7 2012/10/27 17:18:05 chs Exp $");
      5  1.4     lukem 
      6  1.1      matt #include <sys/param.h>
      7  1.1      matt #include <sys/device.h>
      8  1.1      matt #include <dev/pci/pcireg.h>
      9  1.1      matt #include <dev/pci/pcivar.h>
     10  1.1      matt 
     11  1.3  rearnsha #include <arm/footbridge/dc21285reg.h>
     12  1.1      matt 
     13  1.1      matt void
     14  1.7       chs netwinder_pci_attach_hook(device_t parent, device_t self,
     15  1.7       chs     struct pcibus_attach_args *pba)
     16  1.1      matt {
     17  1.1      matt 	pcireg_t regval;
     18  1.1      matt 	pcireg_t intreg;
     19  1.1      matt 	pcitag_t tag;
     20  1.1      matt 
     21  1.1      matt 	/*
     22  1.1      matt 	 * Initialize the TULIP
     23  1.1      matt 	 */
     24  1.1      matt 	tag = pci_make_tag(pba->pba_pc, pba->pba_bus, 9, 0);
     25  1.1      matt 	pci_conf_write(pba->pba_pc, tag,
     26  1.1      matt 		PCI_COMMAND_STATUS_REG,
     27  1.1      matt 		PCI_COMMAND_IO_ENABLE|
     28  1.5  christos 		PCI_COMMAND_MEM_ENABLE|
     29  1.1      matt 		PCI_COMMAND_MASTER_ENABLE);
     30  1.1      matt 	intreg = pci_conf_read(pba->pba_pc, tag, PCI_INTERRUPT_REG);
     31  1.1      matt 	intreg = PCI_INTERRUPT_CODE(
     32  1.1      matt 		PCI_INTERRUPT_LATENCY(intreg),
     33  1.1      matt 		PCI_INTERRUPT_GRANT(intreg),
     34  1.1      matt 		PCI_INTERRUPT_PIN(intreg),
     35  1.1      matt 		0x40|IRQ_IN_L1);
     36  1.1      matt 	pci_conf_write(pba->pba_pc, tag, PCI_INTERRUPT_REG, intreg);
     37  1.1      matt 	pci_conf_write(pba->pba_pc, tag, 0x10, 0x400 | PCI_MAPREG_TYPE_IO);
     38  1.5  christos 	pci_conf_write(pba->pba_pc, tag, 0x14, 0x00800000);
     39  1.1      matt 
     40  1.1      matt 	/*
     41  1.1      matt 	 * Initialize the PCI NE2000
     42  1.1      matt 	 */
     43  1.1      matt 	tag = pci_make_tag(pba->pba_pc, pba->pba_bus, 12, 0);
     44  1.1      matt 	pci_conf_write(pba->pba_pc, tag,
     45  1.1      matt 				PCI_COMMAND_STATUS_REG,
     46  1.1      matt 				PCI_COMMAND_IO_ENABLE|
     47  1.1      matt 				PCI_COMMAND_MASTER_ENABLE);
     48  1.1      matt 	intreg = pci_conf_read(pba->pba_pc, tag, PCI_INTERRUPT_REG);
     49  1.1      matt 	intreg = PCI_INTERRUPT_CODE(
     50  1.1      matt 		PCI_INTERRUPT_LATENCY(intreg),
     51  1.1      matt 		PCI_INTERRUPT_GRANT(intreg),
     52  1.1      matt 		PCI_INTERRUPT_PIN(intreg),
     53  1.1      matt 		0x40|IRQ_IN_L0);
     54  1.1      matt 	pci_conf_write(pba->pba_pc, tag, PCI_INTERRUPT_REG, intreg);
     55  1.1      matt 	pci_conf_write(pba->pba_pc, tag, 0x10, 0x300 | PCI_MAPREG_TYPE_IO);
     56  1.1      matt 
     57  1.1      matt #if 0
     58  1.1      matt 	/*
     59  1.1      matt 	 * Initialize the PCI-ISA Bridge
     60  1.1      matt 	 */
     61  1.1      matt 	tag = pci_make_tag(pba->pba_pc, pba->pba_bus, 11, 0);
     62  1.1      matt 	pci_conf_write(pba->pba_pc, tag,
     63  1.1      matt 		PCI_COMMAND_STATUS_REG,
     64  1.1      matt 		PCI_COMMAND_IO_ENABLE|
     65  1.1      matt 		PCI_COMMAND_MEM_ENABLE|
     66  1.1      matt 		PCI_COMMAND_MASTER_ENABLE);
     67  1.1      matt 	pci_conf_write(pba->pba_pc, tag, 0x10, 0);
     68  1.1      matt 	pci_conf_write(pba->pba_pc, tag, 0x48,
     69  1.1      matt 		pci_conf_read(pba->pba_pc, tag, 0x48)|0xff);
     70  1.1      matt 
     71  1.1      matt 	regval = pci_conf_read(pba->pba_pc, tag, 0x40);
     72  1.1      matt 	regval &= 0xff00ff00;
     73  1.1      matt 	regval |= 0x00000022;
     74  1.1      matt 	pci_conf_write(pba->pba_pc, tag, 0x40, regval);
     75  1.1      matt 
     76  1.1      matt 	regval = pci_conf_read(pba->pba_pc, tag, 0x80);
     77  1.1      matt 	regval &= 0x0000ff00;
     78  1.1      matt 	regval |= 0xe0010002;
     79  1.1      matt 	pci_conf_write(pba->pba_pc, tag, 0x80, regval);
     80  1.1      matt #endif
     81  1.1      matt 
     82  1.1      matt 	/*
     83  1.1      matt 	 * Initialize the PCIIDE Controller
     84  1.1      matt 	 */
     85  1.1      matt 	tag = pci_make_tag(pba->pba_pc, pba->pba_bus, 11, 1);
     86  1.1      matt 	pci_conf_write(pba->pba_pc, tag,
     87  1.1      matt 		PCI_COMMAND_STATUS_REG,
     88  1.1      matt 		PCI_COMMAND_IO_ENABLE|
     89  1.1      matt 		PCI_COMMAND_MASTER_ENABLE);
     90  1.1      matt 
     91  1.1      matt 	regval = pci_conf_read(pba->pba_pc, tag, PCI_CLASS_REG);
     92  1.1      matt 	regval = PCI_CLASS_CODE(PCI_CLASS(regval), PCI_SUBCLASS(regval), 0x8A);
     93  1.1      matt 	pci_conf_write(pba->pba_pc, tag, PCI_CLASS_REG, regval);
     94  1.1      matt 
     95  1.2      matt 	regval = pci_conf_read(pba->pba_pc, tag, 0x40);
     96  1.2      matt 	regval &= ~0x10;	/* disable secondary port */
     97  1.2      matt 	pci_conf_write(pba->pba_pc, tag, 0x40, regval);
     98  1.2      matt 
     99  1.1      matt 	pci_conf_write(pba->pba_pc, tag, 0x10, 0x01f0 | PCI_MAPREG_TYPE_IO);
    100  1.1      matt 	pci_conf_write(pba->pba_pc, tag, 0x14, 0x03f4 | PCI_MAPREG_TYPE_IO);
    101  1.1      matt 	pci_conf_write(pba->pba_pc, tag, 0x18, 0x0170 | PCI_MAPREG_TYPE_IO);
    102  1.1      matt 	pci_conf_write(pba->pba_pc, tag, 0x1c, 0x0374 | PCI_MAPREG_TYPE_IO);
    103  1.1      matt 	pci_conf_write(pba->pba_pc, tag, 0x20, 0xe800 | PCI_MAPREG_TYPE_IO);
    104  1.1      matt 	intreg = pci_conf_read(pba->pba_pc, tag, PCI_INTERRUPT_REG);
    105  1.1      matt 	intreg = PCI_INTERRUPT_CODE(
    106  1.1      matt 		PCI_INTERRUPT_LATENCY(intreg),
    107  1.1      matt 		PCI_INTERRUPT_GRANT(intreg),
    108  1.1      matt 		PCI_INTERRUPT_PIN(intreg),
    109  1.1      matt 		0x8e);
    110  1.1      matt 	pci_conf_write(pba->pba_pc, tag, PCI_INTERRUPT_REG, intreg);
    111  1.1      matt 
    112  1.1      matt 	/*
    113  1.1      matt 	 * Make sure we are in legacy mode
    114  1.1      matt 	 */
    115  1.1      matt 	regval = pci_conf_read(pba->pba_pc, tag, 0x40);
    116  1.1      matt 	regval &= ~0x800;
    117  1.1      matt 	pci_conf_write(pba->pba_pc, tag, 0x40, regval);
    118  1.1      matt }
    119