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