18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * arch/arch/mach-ixp4xx/fsg-pci.c
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * FSG board-level PCI initialization
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Author: Rod Whitby <rod@whitby.id.au>
88c2ecf20Sopenharmony_ci * Maintainer: http://www.nslu2-linux.org/
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci * based on ixdp425-pci.c:
118c2ecf20Sopenharmony_ci *	Copyright (C) 2002 Intel Corporation.
128c2ecf20Sopenharmony_ci *	Copyright (C) 2003-2004 MontaVista Software, Inc.
138c2ecf20Sopenharmony_ci */
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include <linux/pci.h>
168c2ecf20Sopenharmony_ci#include <linux/init.h>
178c2ecf20Sopenharmony_ci#include <linux/irq.h>
188c2ecf20Sopenharmony_ci#include <asm/mach/pci.h>
198c2ecf20Sopenharmony_ci#include <asm/mach-types.h>
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#include "irqs.h"
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#define MAX_DEV		3
248c2ecf20Sopenharmony_ci#define IRQ_LINES	3
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci/* PCI controller GPIO to IRQ pin mappings */
278c2ecf20Sopenharmony_ci#define INTA	6
288c2ecf20Sopenharmony_ci#define INTB	7
298c2ecf20Sopenharmony_ci#define INTC	5
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_civoid __init fsg_pci_preinit(void)
328c2ecf20Sopenharmony_ci{
338c2ecf20Sopenharmony_ci	irq_set_irq_type(IXP4XX_GPIO_IRQ(INTA), IRQ_TYPE_LEVEL_LOW);
348c2ecf20Sopenharmony_ci	irq_set_irq_type(IXP4XX_GPIO_IRQ(INTB), IRQ_TYPE_LEVEL_LOW);
358c2ecf20Sopenharmony_ci	irq_set_irq_type(IXP4XX_GPIO_IRQ(INTC), IRQ_TYPE_LEVEL_LOW);
368c2ecf20Sopenharmony_ci	ixp4xx_pci_preinit();
378c2ecf20Sopenharmony_ci}
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_cistatic int __init fsg_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
408c2ecf20Sopenharmony_ci{
418c2ecf20Sopenharmony_ci	static int pci_irq_table[IRQ_LINES] = {
428c2ecf20Sopenharmony_ci		IXP4XX_GPIO_IRQ(INTC),
438c2ecf20Sopenharmony_ci		IXP4XX_GPIO_IRQ(INTB),
448c2ecf20Sopenharmony_ci		IXP4XX_GPIO_IRQ(INTA),
458c2ecf20Sopenharmony_ci	};
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci	int irq = -1;
488c2ecf20Sopenharmony_ci	slot -= 11;
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci	if (slot >= 1 && slot <= MAX_DEV && pin >= 1 && pin <= IRQ_LINES)
518c2ecf20Sopenharmony_ci		irq = pci_irq_table[slot - 1];
528c2ecf20Sopenharmony_ci	printk(KERN_INFO "%s: Mapped slot %d pin %d to IRQ %d\n",
538c2ecf20Sopenharmony_ci	       __func__, slot, pin, irq);
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci	return irq;
568c2ecf20Sopenharmony_ci}
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_cistruct hw_pci fsg_pci __initdata = {
598c2ecf20Sopenharmony_ci	.nr_controllers = 1,
608c2ecf20Sopenharmony_ci	.ops		= &ixp4xx_ops,
618c2ecf20Sopenharmony_ci	.preinit =	  fsg_pci_preinit,
628c2ecf20Sopenharmony_ci	.setup =	  ixp4xx_setup,
638c2ecf20Sopenharmony_ci	.map_irq =	  fsg_map_irq,
648c2ecf20Sopenharmony_ci};
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ciint __init fsg_pci_init(void)
678c2ecf20Sopenharmony_ci{
688c2ecf20Sopenharmony_ci	if (machine_is_fsg())
698c2ecf20Sopenharmony_ci		pci_common_init(&fsg_pci);
708c2ecf20Sopenharmony_ci	return 0;
718c2ecf20Sopenharmony_ci}
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_cisubsys_initcall(fsg_pci_init);
74