18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ci#include <linux/module.h>
48c2ecf20Sopenharmony_ci#include <linux/pci.h>
58c2ecf20Sopenharmony_ci#include "fdomain.h"
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_cistatic int fdomain_pci_probe(struct pci_dev *pdev,
88c2ecf20Sopenharmony_ci			     const struct pci_device_id *d)
98c2ecf20Sopenharmony_ci{
108c2ecf20Sopenharmony_ci	int err;
118c2ecf20Sopenharmony_ci	struct Scsi_Host *sh;
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci	err = pci_enable_device(pdev);
148c2ecf20Sopenharmony_ci	if (err)
158c2ecf20Sopenharmony_ci		goto fail;
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci	err = pci_request_regions(pdev, "fdomain_pci");
188c2ecf20Sopenharmony_ci	if (err)
198c2ecf20Sopenharmony_ci		goto disable_device;
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci	err = -ENODEV;
228c2ecf20Sopenharmony_ci	if (pci_resource_len(pdev, 0) == 0)
238c2ecf20Sopenharmony_ci		goto release_region;
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci	sh = fdomain_create(pci_resource_start(pdev, 0), pdev->irq, 7,
268c2ecf20Sopenharmony_ci			    &pdev->dev);
278c2ecf20Sopenharmony_ci	if (!sh)
288c2ecf20Sopenharmony_ci		goto release_region;
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci	pci_set_drvdata(pdev, sh);
318c2ecf20Sopenharmony_ci	return 0;
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_cirelease_region:
348c2ecf20Sopenharmony_ci	pci_release_regions(pdev);
358c2ecf20Sopenharmony_cidisable_device:
368c2ecf20Sopenharmony_ci	pci_disable_device(pdev);
378c2ecf20Sopenharmony_cifail:
388c2ecf20Sopenharmony_ci	return err;
398c2ecf20Sopenharmony_ci}
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_cistatic void fdomain_pci_remove(struct pci_dev *pdev)
428c2ecf20Sopenharmony_ci{
438c2ecf20Sopenharmony_ci	struct Scsi_Host *sh = pci_get_drvdata(pdev);
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci	fdomain_destroy(sh);
468c2ecf20Sopenharmony_ci	pci_release_regions(pdev);
478c2ecf20Sopenharmony_ci	pci_disable_device(pdev);
488c2ecf20Sopenharmony_ci}
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_cistatic struct pci_device_id fdomain_pci_table[] = {
518c2ecf20Sopenharmony_ci	{ PCI_DEVICE(PCI_VENDOR_ID_FD, PCI_DEVICE_ID_FD_36C70) },
528c2ecf20Sopenharmony_ci	{}
538c2ecf20Sopenharmony_ci};
548c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(pci, fdomain_pci_table);
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_cistatic struct pci_driver fdomain_pci_driver = {
578c2ecf20Sopenharmony_ci	.name		= "fdomain_pci",
588c2ecf20Sopenharmony_ci	.id_table	= fdomain_pci_table,
598c2ecf20Sopenharmony_ci	.probe		= fdomain_pci_probe,
608c2ecf20Sopenharmony_ci	.remove		= fdomain_pci_remove,
618c2ecf20Sopenharmony_ci	.driver.pm	= FDOMAIN_PM_OPS,
628c2ecf20Sopenharmony_ci};
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_cimodule_pci_driver(fdomain_pci_driver);
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ciMODULE_AUTHOR("Ondrej Zary, Rickard E. Faith");
678c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Future Domain TMC-3260 PCI SCSI driver");
688c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
69