xref: /openbmc/linux/drivers/mfd/vx855.c (revision 1a59d1b8)
11a59d1b8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2375fc77bSDaniel Drake /*
3375fc77bSDaniel Drake  * Linux multi-function-device driver (MFD) for the integrated peripherals
4375fc77bSDaniel Drake  * of the VIA VX855 chipset
5375fc77bSDaniel Drake  *
6375fc77bSDaniel Drake  * Copyright (C) 2009 VIA Technologies, Inc.
7375fc77bSDaniel Drake  * Copyright (C) 2010 One Laptop per Child
8375fc77bSDaniel Drake  * Author: Harald Welte <HaraldWelte@viatech.com>
9375fc77bSDaniel Drake  * All rights reserved.
10375fc77bSDaniel Drake  */
11375fc77bSDaniel Drake 
12375fc77bSDaniel Drake #include <linux/kernel.h>
13375fc77bSDaniel Drake #include <linux/module.h>
14375fc77bSDaniel Drake #include <linux/device.h>
15375fc77bSDaniel Drake #include <linux/platform_device.h>
16375fc77bSDaniel Drake #include <linux/pci.h>
17375fc77bSDaniel Drake #include <linux/mfd/core.h>
18375fc77bSDaniel Drake 
19375fc77bSDaniel Drake /* offset into pci config space indicating the 16bit register containing
20375fc77bSDaniel Drake  * the power management IO space base */
21375fc77bSDaniel Drake #define VX855_CFG_PMIO_OFFSET	0x88
22375fc77bSDaniel Drake 
23375fc77bSDaniel Drake /* ACPI I/O Space registers */
24375fc77bSDaniel Drake #define VX855_PMIO_ACPI		0x00
25375fc77bSDaniel Drake #define VX855_PMIO_ACPI_LEN	0x0b
26375fc77bSDaniel Drake 
27375fc77bSDaniel Drake /* Processor Power Management */
28375fc77bSDaniel Drake #define VX855_PMIO_PPM		0x10
29375fc77bSDaniel Drake #define VX855_PMIO_PPM_LEN	0x08
30375fc77bSDaniel Drake 
31375fc77bSDaniel Drake /* General Purpose Power Management */
32375fc77bSDaniel Drake #define VX855_PMIO_GPPM		0x20
33375fc77bSDaniel Drake #define VX855_PMIO_R_GPI	0x48
34375fc77bSDaniel Drake #define VX855_PMIO_R_GPO	0x4c
35375fc77bSDaniel Drake #define VX855_PMIO_GPPM_LEN	0x33
36375fc77bSDaniel Drake 
37375fc77bSDaniel Drake #define VSPIC_MMIO_SIZE	0x1000
38375fc77bSDaniel Drake 
39375fc77bSDaniel Drake static struct resource vx855_gpio_resources[] = {
40375fc77bSDaniel Drake 	{
41375fc77bSDaniel Drake 		.flags = IORESOURCE_IO,
42375fc77bSDaniel Drake 	},
43375fc77bSDaniel Drake 	{
44375fc77bSDaniel Drake 		.flags = IORESOURCE_IO,
45375fc77bSDaniel Drake 	},
46375fc77bSDaniel Drake };
47375fc77bSDaniel Drake 
485ac98553SGeert Uytterhoeven static const struct mfd_cell vx855_cells[] = {
49375fc77bSDaniel Drake 	{
50375fc77bSDaniel Drake 		.name = "vx855_gpio",
51375fc77bSDaniel Drake 		.num_resources = ARRAY_SIZE(vx855_gpio_resources),
52375fc77bSDaniel Drake 		.resources = vx855_gpio_resources,
53375fc77bSDaniel Drake 
54375fc77bSDaniel Drake 		/* we must ignore resource conflicts, for reasons outlined in
55375fc77bSDaniel Drake 		 * the vx855_gpio driver */
56375fc77bSDaniel Drake 		.ignore_resource_conflicts = true,
57375fc77bSDaniel Drake 	},
58375fc77bSDaniel Drake };
59375fc77bSDaniel Drake 
vx855_probe(struct pci_dev * pdev,const struct pci_device_id * id)60f791be49SBill Pemberton static int vx855_probe(struct pci_dev *pdev,
61375fc77bSDaniel Drake 				 const struct pci_device_id *id)
62375fc77bSDaniel Drake {
63375fc77bSDaniel Drake 	int ret;
64375fc77bSDaniel Drake 	u16 gpio_io_offset;
65375fc77bSDaniel Drake 
66375fc77bSDaniel Drake 	ret = pci_enable_device(pdev);
67375fc77bSDaniel Drake 	if (ret)
68375fc77bSDaniel Drake 		return -ENODEV;
69375fc77bSDaniel Drake 
70375fc77bSDaniel Drake 	pci_read_config_word(pdev, VX855_CFG_PMIO_OFFSET, &gpio_io_offset);
71375fc77bSDaniel Drake 	if (!gpio_io_offset) {
72375fc77bSDaniel Drake 		dev_warn(&pdev->dev,
73375fc77bSDaniel Drake 			"BIOS did not assign PMIO base offset?!?\n");
74375fc77bSDaniel Drake 		ret = -ENODEV;
75375fc77bSDaniel Drake 		goto out;
76375fc77bSDaniel Drake 	}
77375fc77bSDaniel Drake 
78375fc77bSDaniel Drake 	/* mask out the lowest seven bits, as they are always zero, but
79375fc77bSDaniel Drake 	 * hardware returns them as 0x01 */
80375fc77bSDaniel Drake 	gpio_io_offset &= 0xff80;
81375fc77bSDaniel Drake 
82375fc77bSDaniel Drake 	/* As the region identified here includes many non-GPIO things, we
83375fc77bSDaniel Drake 	 * only work with the specific registers that concern us. */
84375fc77bSDaniel Drake 	vx855_gpio_resources[0].start = gpio_io_offset + VX855_PMIO_R_GPI;
85375fc77bSDaniel Drake 	vx855_gpio_resources[0].end = vx855_gpio_resources[0].start + 3;
86375fc77bSDaniel Drake 	vx855_gpio_resources[1].start = gpio_io_offset + VX855_PMIO_R_GPO;
87375fc77bSDaniel Drake 	vx855_gpio_resources[1].end = vx855_gpio_resources[1].start + 3;
88375fc77bSDaniel Drake 
89375fc77bSDaniel Drake 	ret = mfd_add_devices(&pdev->dev, -1, vx855_cells, ARRAY_SIZE(vx855_cells),
900848c94fSMark Brown 			NULL, 0, NULL);
91375fc77bSDaniel Drake 
92375fc77bSDaniel Drake 	/* we always return -ENODEV here in order to enable other
93375fc77bSDaniel Drake 	 * drivers like old, not-yet-platform_device ported i2c-viapro */
94375fc77bSDaniel Drake 	return -ENODEV;
95375fc77bSDaniel Drake out:
96375fc77bSDaniel Drake 	pci_disable_device(pdev);
97375fc77bSDaniel Drake 	return ret;
98375fc77bSDaniel Drake }
99375fc77bSDaniel Drake 
vx855_remove(struct pci_dev * pdev)1004740f73fSBill Pemberton static void vx855_remove(struct pci_dev *pdev)
101375fc77bSDaniel Drake {
102375fc77bSDaniel Drake 	mfd_remove_devices(&pdev->dev);
103375fc77bSDaniel Drake 	pci_disable_device(pdev);
104375fc77bSDaniel Drake }
105375fc77bSDaniel Drake 
10636fcd06cSJingoo Han static const struct pci_device_id vx855_pci_tbl[] = {
107375fc77bSDaniel Drake 	{ PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_VX855) },
108375fc77bSDaniel Drake 	{ 0, }
109375fc77bSDaniel Drake };
110bcd2f639SAxel Lin MODULE_DEVICE_TABLE(pci, vx855_pci_tbl);
111375fc77bSDaniel Drake 
112375fc77bSDaniel Drake static struct pci_driver vx855_pci_driver = {
113375fc77bSDaniel Drake 	.name		= "vx855",
114375fc77bSDaniel Drake 	.id_table	= vx855_pci_tbl,
115375fc77bSDaniel Drake 	.probe		= vx855_probe,
11684449216SBill Pemberton 	.remove		= vx855_remove,
117375fc77bSDaniel Drake };
118375fc77bSDaniel Drake 
11938a36f5aSAxel Lin module_pci_driver(vx855_pci_driver);
120375fc77bSDaniel Drake 
121375fc77bSDaniel Drake MODULE_LICENSE("GPL");
122375fc77bSDaniel Drake MODULE_AUTHOR("Harald Welte <HaraldWelte@viatech.com>");
123375fc77bSDaniel Drake MODULE_DESCRIPTION("Driver for the VIA VX855 chipset");
124