iq80331-pci.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * arch/arm/mach-iop3xx/iq80331-pci.c
  3. *
  4. * PCI support for the Intel IQ80331 reference board
  5. *
  6. * Author: Dave Jiang <dave.jiang@intel.com>
  7. * Copyright (C) 2003, 2004 Intel Corp.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/pci.h>
  15. #include <linux/init.h>
  16. #include <linux/string.h>
  17. #include <linux/slab.h>
  18. #include <asm/hardware.h>
  19. #include <asm/irq.h>
  20. #include <asm/mach/pci.h>
  21. #include <asm/mach-types.h>
  22. /*
  23. * The following macro is used to lookup irqs in a standard table
  24. * format for those systems that do not already have PCI
  25. * interrupts properly routed. We assume 1 <= pin <= 4
  26. */
  27. #define PCI_IRQ_TABLE_LOOKUP(minid,maxid) \
  28. ({ int _ctl_ = -1; \
  29. unsigned int _idsel = idsel - minid; \
  30. if (_idsel <= maxid) \
  31. _ctl_ = pci_irq_table[_idsel][pin-1]; \
  32. _ctl_; })
  33. #define INTA IRQ_IQ80331_INTA
  34. #define INTB IRQ_IQ80331_INTB
  35. #define INTC IRQ_IQ80331_INTC
  36. #define INTD IRQ_IQ80331_INTD
  37. //#define INTE IRQ_IQ80331_I82544
  38. static inline int __init
  39. iq80331_map_irq(struct pci_dev *dev, u8 idsel, u8 pin)
  40. {
  41. static int pci_irq_table[][4] = {
  42. /*
  43. * PCI IDSEL/INTPIN->INTLINE
  44. * A B C D
  45. */
  46. {INTB, INTC, INTD, INTA}, /* PCI-X Slot */
  47. {INTC, INTC, INTC, INTC}, /* GigE */
  48. };
  49. BUG_ON(pin < 1 || pin > 4);
  50. return PCI_IRQ_TABLE_LOOKUP(1, 7);
  51. }
  52. static int iq80331_setup(int nr, struct pci_sys_data *sys)
  53. {
  54. struct resource *res;
  55. if(nr != 0)
  56. return 0;
  57. res = kzalloc(sizeof(struct resource) * 2, GFP_KERNEL);
  58. if (!res)
  59. panic("PCI: unable to alloc resources");
  60. res[0].start = IOP331_PCI_LOWER_IO_VA;
  61. res[0].end = IOP331_PCI_UPPER_IO_VA;
  62. res[0].name = "IQ80331 PCI I/O Space";
  63. res[0].flags = IORESOURCE_IO;
  64. res[1].start = IOP331_PCI_LOWER_MEM_PA;
  65. res[1].end = IOP331_PCI_UPPER_MEM_PA;
  66. res[1].name = "IQ80331 PCI Memory Space";
  67. res[1].flags = IORESOURCE_MEM;
  68. request_resource(&ioport_resource, &res[0]);
  69. request_resource(&iomem_resource, &res[1]);
  70. sys->mem_offset = IOP331_PCI_MEM_OFFSET;
  71. sys->io_offset = IOP331_PCI_IO_OFFSET;
  72. sys->resource[0] = &res[0];
  73. sys->resource[1] = &res[1];
  74. sys->resource[2] = NULL;
  75. return 1;
  76. }
  77. static void iq80331_preinit(void)
  78. {
  79. iop331_init();
  80. }
  81. static struct hw_pci iq80331_pci __initdata = {
  82. .swizzle = pci_std_swizzle,
  83. .nr_controllers = 1,
  84. .setup = iq80331_setup,
  85. .scan = iop331_scan_bus,
  86. .preinit = iq80331_preinit,
  87. .map_irq = iq80331_map_irq
  88. };
  89. static int __init iq80331_pci_init(void)
  90. {
  91. if (machine_is_iq80331())
  92. pci_common_init(&iq80331_pci);
  93. return 0;
  94. }
  95. subsys_initcall(iq80331_pci_init);