xref: /openbmc/linux/drivers/mfd/vx855.c (revision 1a59d1b8)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Linux multi-function-device driver (MFD) for the integrated peripherals
4  * of the VIA VX855 chipset
5  *
6  * Copyright (C) 2009 VIA Technologies, Inc.
7  * Copyright (C) 2010 One Laptop per Child
8  * Author: Harald Welte <HaraldWelte@viatech.com>
9  * All rights reserved.
10  */
11 
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/device.h>
15 #include <linux/platform_device.h>
16 #include <linux/pci.h>
17 #include <linux/mfd/core.h>
18 
19 /* offset into pci config space indicating the 16bit register containing
20  * the power management IO space base */
21 #define VX855_CFG_PMIO_OFFSET	0x88
22 
23 /* ACPI I/O Space registers */
24 #define VX855_PMIO_ACPI		0x00
25 #define VX855_PMIO_ACPI_LEN	0x0b
26 
27 /* Processor Power Management */
28 #define VX855_PMIO_PPM		0x10
29 #define VX855_PMIO_PPM_LEN	0x08
30 
31 /* General Purpose Power Management */
32 #define VX855_PMIO_GPPM		0x20
33 #define VX855_PMIO_R_GPI	0x48
34 #define VX855_PMIO_R_GPO	0x4c
35 #define VX855_PMIO_GPPM_LEN	0x33
36 
37 #define VSPIC_MMIO_SIZE	0x1000
38 
39 static struct resource vx855_gpio_resources[] = {
40 	{
41 		.flags = IORESOURCE_IO,
42 	},
43 	{
44 		.flags = IORESOURCE_IO,
45 	},
46 };
47 
48 static const struct mfd_cell vx855_cells[] = {
49 	{
50 		.name = "vx855_gpio",
51 		.num_resources = ARRAY_SIZE(vx855_gpio_resources),
52 		.resources = vx855_gpio_resources,
53 
54 		/* we must ignore resource conflicts, for reasons outlined in
55 		 * the vx855_gpio driver */
56 		.ignore_resource_conflicts = true,
57 	},
58 };
59 
vx855_probe(struct pci_dev * pdev,const struct pci_device_id * id)60 static int vx855_probe(struct pci_dev *pdev,
61 				 const struct pci_device_id *id)
62 {
63 	int ret;
64 	u16 gpio_io_offset;
65 
66 	ret = pci_enable_device(pdev);
67 	if (ret)
68 		return -ENODEV;
69 
70 	pci_read_config_word(pdev, VX855_CFG_PMIO_OFFSET, &gpio_io_offset);
71 	if (!gpio_io_offset) {
72 		dev_warn(&pdev->dev,
73 			"BIOS did not assign PMIO base offset?!?\n");
74 		ret = -ENODEV;
75 		goto out;
76 	}
77 
78 	/* mask out the lowest seven bits, as they are always zero, but
79 	 * hardware returns them as 0x01 */
80 	gpio_io_offset &= 0xff80;
81 
82 	/* As the region identified here includes many non-GPIO things, we
83 	 * only work with the specific registers that concern us. */
84 	vx855_gpio_resources[0].start = gpio_io_offset + VX855_PMIO_R_GPI;
85 	vx855_gpio_resources[0].end = vx855_gpio_resources[0].start + 3;
86 	vx855_gpio_resources[1].start = gpio_io_offset + VX855_PMIO_R_GPO;
87 	vx855_gpio_resources[1].end = vx855_gpio_resources[1].start + 3;
88 
89 	ret = mfd_add_devices(&pdev->dev, -1, vx855_cells, ARRAY_SIZE(vx855_cells),
90 			NULL, 0, NULL);
91 
92 	/* we always return -ENODEV here in order to enable other
93 	 * drivers like old, not-yet-platform_device ported i2c-viapro */
94 	return -ENODEV;
95 out:
96 	pci_disable_device(pdev);
97 	return ret;
98 }
99 
vx855_remove(struct pci_dev * pdev)100 static void vx855_remove(struct pci_dev *pdev)
101 {
102 	mfd_remove_devices(&pdev->dev);
103 	pci_disable_device(pdev);
104 }
105 
106 static const struct pci_device_id vx855_pci_tbl[] = {
107 	{ PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_VX855) },
108 	{ 0, }
109 };
110 MODULE_DEVICE_TABLE(pci, vx855_pci_tbl);
111 
112 static struct pci_driver vx855_pci_driver = {
113 	.name		= "vx855",
114 	.id_table	= vx855_pci_tbl,
115 	.probe		= vx855_probe,
116 	.remove		= vx855_remove,
117 };
118 
119 module_pci_driver(vx855_pci_driver);
120 
121 MODULE_LICENSE("GPL");
122 MODULE_AUTHOR("Harald Welte <HaraldWelte@viatech.com>");
123 MODULE_DESCRIPTION("Driver for the VIA VX855 chipset");
124