4 * Copyright (C) 2014 MEN Mikroelektronik GmbH (www.men.de)
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; version 2 of the License.
12 #include <linux/module.h>
13 #include <linux/pci.h>
14 #include <linux/mcb.h>
16 #include "mcb-internal.h"
24 static int mcb_pci_get_irq(struct mcb_device *mdev)
26 struct mcb_bus *mbus = mdev->bus;
27 struct device *dev = mbus->carrier;
28 struct pci_dev *pdev = to_pci_dev(dev);
33 static int mcb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
41 priv = devm_kzalloc(&pdev->dev, sizeof(struct priv), GFP_KERNEL);
45 ret = pci_enable_device(pdev);
47 dev_err(&pdev->dev, "Failed to enable PCI device\n");
51 priv->mapbase = pci_resource_start(pdev, 0);
53 dev_err(&pdev->dev, "No PCI resource\n");
58 res = request_mem_region(priv->mapbase, CHAM_HEADER_SIZE,
61 dev_err(&pdev->dev, "Failed to request PCI memory\n");
66 priv->base = ioremap(priv->mapbase, CHAM_HEADER_SIZE);
68 dev_err(&pdev->dev, "Cannot ioremap\n");
73 flags = pci_resource_flags(pdev, 0);
74 if (flags & IORESOURCE_IO) {
77 "IO mapped PCI devices are not supported\n");
81 pci_set_drvdata(pdev, priv);
83 priv->bus = mcb_alloc_bus(&pdev->dev);
84 if (IS_ERR(priv->bus)) {
85 ret = PTR_ERR(priv->bus);
89 priv->bus->get_irq = mcb_pci_get_irq;
91 ret = chameleon_parse_cells(priv->bus, priv->mapbase, priv->base);
96 dev_dbg(&pdev->dev, "Found %d cells\n", num_cells);
98 mcb_bus_add_devices(priv->bus);
103 mcb_release_bus(priv->bus);
107 pci_release_region(pdev, 0);
109 pci_disable_device(pdev);
113 static void mcb_pci_remove(struct pci_dev *pdev)
115 struct priv *priv = pci_get_drvdata(pdev);
117 mcb_release_bus(priv->bus);
120 release_region(priv->mapbase, CHAM_HEADER_SIZE);
121 pci_disable_device(pdev);
124 static const struct pci_device_id mcb_pci_tbl[] = {
125 { PCI_DEVICE(PCI_VENDOR_ID_MEN, PCI_DEVICE_ID_MEN_CHAMELEON) },
128 MODULE_DEVICE_TABLE(pci, mcb_pci_tbl);
130 static struct pci_driver mcb_pci_driver = {
132 .id_table = mcb_pci_tbl,
133 .probe = mcb_pci_probe,
134 .remove = mcb_pci_remove,
137 module_pci_driver(mcb_pci_driver);
140 MODULE_LICENSE("GPL");
141 MODULE_DESCRIPTION("MCB over PCI support");