xref: /linux/drivers/spi/spi-loongson-pci.c (revision 7a5f93ea5862da91488975acaa0c7abd508f192b)
1 // SPDX-License-Identifier: GPL-2.0+
2 // PCI interface driver for Loongson SPI Support
3 // Copyright (C) 2023 Loongson Technology Corporation Limited
4 
5 #include <linux/mod_devicetable.h>
6 #include <linux/pci.h>
7 
8 #include "spi-loongson.h"
9 
10 static int loongson_spi_pci_register(struct pci_dev *pdev,
11 			const struct pci_device_id *ent)
12 {
13 	int ret;
14 	void __iomem *reg_base;
15 	struct device *dev = &pdev->dev;
16 	int pci_bar = 0;
17 
18 	ret = pcim_enable_device(pdev);
19 	if (ret < 0)
20 		return dev_err_probe(dev, ret, "cannot enable pci device\n");
21 
22 	reg_base = pcim_iomap_region(pdev, pci_bar, pci_name(pdev));
23 	ret = PTR_ERR_OR_ZERO(reg_base);
24 	if (ret)
25 		return dev_err_probe(dev, ret, "failed to request and remap memory\n");
26 
27 	ret = loongson_spi_init_controller(dev, reg_base);
28 	if (ret)
29 		return dev_err_probe(dev, ret, "failed to initialize controller\n");
30 
31 	return 0;
32 }
33 
34 static struct pci_device_id loongson_spi_devices[] = {
35 	{ PCI_DEVICE(PCI_VENDOR_ID_LOONGSON, 0x7a0b) },
36 	{ PCI_DEVICE(PCI_VENDOR_ID_LOONGSON, 0x7a1b) },
37 	{ }
38 };
39 MODULE_DEVICE_TABLE(pci, loongson_spi_devices);
40 
41 static struct pci_driver loongson_spi_pci_driver = {
42 	.name       = "loongson-spi-pci",
43 	.id_table   = loongson_spi_devices,
44 	.probe      = loongson_spi_pci_register,
45 	.driver	= {
46 		.bus = &pci_bus_type,
47 		.pm = &loongson_spi_dev_pm_ops,
48 	},
49 };
50 module_pci_driver(loongson_spi_pci_driver);
51 
52 MODULE_DESCRIPTION("Loongson spi pci driver");
53 MODULE_LICENSE("GPL");
54 MODULE_IMPORT_NS("SPI_LOONGSON_CORE");
55