4 * Copyright (C) 2014 MEN Mikroelektronik GmbH (www.men.de)
5 * Author: Johannes Thumshirn <johannes.thumshirn@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"
23 static int mcb_pci_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
31 priv
= devm_kzalloc(&pdev
->dev
, sizeof(struct priv
), GFP_KERNEL
);
35 ret
= pci_enable_device(pdev
);
37 dev_err(&pdev
->dev
, "Failed to enable PCI device\n");
41 mapbase
= pci_resource_start(pdev
, 0);
43 dev_err(&pdev
->dev
, "No PCI resource\n");
47 ret
= pci_request_region(pdev
, 0, KBUILD_MODNAME
);
49 dev_err(&pdev
->dev
, "Failed to request PCI BARs\n");
53 priv
->base
= pci_iomap(pdev
, 0, 0);
55 dev_err(&pdev
->dev
, "Cannot ioremap\n");
60 flags
= pci_resource_flags(pdev
, 0);
61 if (flags
& IORESOURCE_IO
) {
64 "IO mapped PCI devices are not supported\n");
68 pci_set_drvdata(pdev
, priv
);
70 priv
->bus
= mcb_alloc_bus();
72 ret
= chameleon_parse_cells(priv
->bus
, mapbase
, priv
->base
);
77 dev_dbg(&pdev
->dev
, "Found %d cells\n", num_cells
);
79 mcb_bus_add_devices(priv
->bus
);
82 pci_iounmap(pdev
, priv
->base
);
84 pci_release_region(pdev
, 0);
86 pci_disable_device(pdev
);
90 static void mcb_pci_remove(struct pci_dev
*pdev
)
92 struct priv
*priv
= pci_get_drvdata(pdev
);
94 mcb_release_bus(priv
->bus
);
97 static const struct pci_device_id mcb_pci_tbl
[] = {
98 { PCI_DEVICE(PCI_VENDOR_ID_MEN
, PCI_DEVICE_ID_MEN_CHAMELEON
) },
101 MODULE_DEVICE_TABLE(pci
, mcb_pci_tbl
);
103 static struct pci_driver mcb_pci_driver
= {
105 .id_table
= mcb_pci_tbl
,
106 .probe
= mcb_pci_probe
,
107 .remove
= mcb_pci_remove
,
110 module_pci_driver(mcb_pci_driver
);
112 MODULE_AUTHOR("Johannes Thumshirn <johannes.thumshirn@men.de>");
113 MODULE_LICENSE("GPL");
114 MODULE_DESCRIPTION("MCB over PCI support");