| lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * Linux multi-function-device driver (MFD) for the integrated peripherals | 
 | 3 |  * of the VIA VX855 chipset | 
 | 4 |  * | 
 | 5 |  * Copyright (C) 2009 VIA Technologies, Inc. | 
 | 6 |  * Copyright (C) 2010 One Laptop per Child | 
 | 7 |  * Author: Harald Welte <HaraldWelte@viatech.com> | 
 | 8 |  * All rights reserved. | 
 | 9 |  * | 
 | 10 |  * This program is free software; you can redistribute it and/or | 
 | 11 |  * modify it under the terms of the GNU General Public License as | 
 | 12 |  * published by the Free Software Foundation; either version 2 of | 
 | 13 |  * the License, or (at your option) any later version. | 
 | 14 |  * | 
 | 15 |  * This program is distributed in the hope that it will be useful, | 
 | 16 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
 | 17 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
 | 18 |  * GNU General Public License for more details. | 
 | 19 |  * | 
 | 20 |  * You should have received a copy of the GNU General Public License | 
 | 21 |  * along with this program; if not, write to the Free Software | 
 | 22 |  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, | 
 | 23 |  * MA 02111-1307 USA | 
 | 24 |  * | 
 | 25 |  */ | 
 | 26 |  | 
 | 27 | #include <linux/kernel.h> | 
 | 28 | #include <linux/module.h> | 
 | 29 | #include <linux/device.h> | 
 | 30 | #include <linux/platform_device.h> | 
 | 31 | #include <linux/pci.h> | 
 | 32 | #include <linux/mfd/core.h> | 
 | 33 |  | 
 | 34 | /* offset into pci config space indicating the 16bit register containing | 
 | 35 |  * the power management IO space base */ | 
 | 36 | #define VX855_CFG_PMIO_OFFSET	0x88 | 
 | 37 |  | 
 | 38 | /* ACPI I/O Space registers */ | 
 | 39 | #define VX855_PMIO_ACPI		0x00 | 
 | 40 | #define VX855_PMIO_ACPI_LEN	0x0b | 
 | 41 |  | 
 | 42 | /* Processor Power Management */ | 
 | 43 | #define VX855_PMIO_PPM		0x10 | 
 | 44 | #define VX855_PMIO_PPM_LEN	0x08 | 
 | 45 |  | 
 | 46 | /* General Purpose Power Management */ | 
 | 47 | #define VX855_PMIO_GPPM		0x20 | 
 | 48 | #define VX855_PMIO_R_GPI	0x48 | 
 | 49 | #define VX855_PMIO_R_GPO	0x4c | 
 | 50 | #define VX855_PMIO_GPPM_LEN	0x33 | 
 | 51 |  | 
 | 52 | #define VSPIC_MMIO_SIZE	0x1000 | 
 | 53 |  | 
 | 54 | static struct resource vx855_gpio_resources[] = { | 
 | 55 | 	{ | 
 | 56 | 		.flags = IORESOURCE_IO, | 
 | 57 | 	}, | 
 | 58 | 	{ | 
 | 59 | 		.flags = IORESOURCE_IO, | 
 | 60 | 	}, | 
 | 61 | }; | 
 | 62 |  | 
 | 63 | static struct mfd_cell vx855_cells[] = { | 
 | 64 | 	{ | 
 | 65 | 		.name = "vx855_gpio", | 
 | 66 | 		.num_resources = ARRAY_SIZE(vx855_gpio_resources), | 
 | 67 | 		.resources = vx855_gpio_resources, | 
 | 68 |  | 
 | 69 | 		/* we must ignore resource conflicts, for reasons outlined in | 
 | 70 | 		 * the vx855_gpio driver */ | 
 | 71 | 		.ignore_resource_conflicts = true, | 
 | 72 | 	}, | 
 | 73 | }; | 
 | 74 |  | 
 | 75 | static __devinit int vx855_probe(struct pci_dev *pdev, | 
 | 76 | 				 const struct pci_device_id *id) | 
 | 77 | { | 
 | 78 | 	int ret; | 
 | 79 | 	u16 gpio_io_offset; | 
 | 80 |  | 
 | 81 | 	ret = pci_enable_device(pdev); | 
 | 82 | 	if (ret) | 
 | 83 | 		return -ENODEV; | 
 | 84 |  | 
 | 85 | 	pci_read_config_word(pdev, VX855_CFG_PMIO_OFFSET, &gpio_io_offset); | 
 | 86 | 	if (!gpio_io_offset) { | 
 | 87 | 		dev_warn(&pdev->dev, | 
 | 88 | 			"BIOS did not assign PMIO base offset?!?\n"); | 
 | 89 | 		ret = -ENODEV; | 
 | 90 | 		goto out; | 
 | 91 | 	} | 
 | 92 |  | 
 | 93 | 	/* mask out the lowest seven bits, as they are always zero, but | 
 | 94 | 	 * hardware returns them as 0x01 */ | 
 | 95 | 	gpio_io_offset &= 0xff80; | 
 | 96 |  | 
 | 97 | 	/* As the region identified here includes many non-GPIO things, we | 
 | 98 | 	 * only work with the specific registers that concern us. */ | 
 | 99 | 	vx855_gpio_resources[0].start = gpio_io_offset + VX855_PMIO_R_GPI; | 
 | 100 | 	vx855_gpio_resources[0].end = vx855_gpio_resources[0].start + 3; | 
 | 101 | 	vx855_gpio_resources[1].start = gpio_io_offset + VX855_PMIO_R_GPO; | 
 | 102 | 	vx855_gpio_resources[1].end = vx855_gpio_resources[1].start + 3; | 
 | 103 |  | 
 | 104 | 	ret = mfd_add_devices(&pdev->dev, -1, vx855_cells, ARRAY_SIZE(vx855_cells), | 
 | 105 | 			NULL, 0); | 
 | 106 |  | 
 | 107 | 	/* we always return -ENODEV here in order to enable other | 
 | 108 | 	 * drivers like old, not-yet-platform_device ported i2c-viapro */ | 
 | 109 | 	return -ENODEV; | 
 | 110 | out: | 
 | 111 | 	pci_disable_device(pdev); | 
 | 112 | 	return ret; | 
 | 113 | } | 
 | 114 |  | 
 | 115 | static void __devexit vx855_remove(struct pci_dev *pdev) | 
 | 116 | { | 
 | 117 | 	mfd_remove_devices(&pdev->dev); | 
 | 118 | 	pci_disable_device(pdev); | 
 | 119 | } | 
 | 120 |  | 
 | 121 | static DEFINE_PCI_DEVICE_TABLE(vx855_pci_tbl) = { | 
 | 122 | 	{ PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_VX855) }, | 
 | 123 | 	{ 0, } | 
 | 124 | }; | 
 | 125 | MODULE_DEVICE_TABLE(pci, vx855_pci_tbl); | 
 | 126 |  | 
 | 127 | static struct pci_driver vx855_pci_driver = { | 
 | 128 | 	.name		= "vx855", | 
 | 129 | 	.id_table	= vx855_pci_tbl, | 
 | 130 | 	.probe		= vx855_probe, | 
 | 131 | 	.remove		= __devexit_p(vx855_remove), | 
 | 132 | }; | 
 | 133 |  | 
 | 134 | static int vx855_init(void) | 
 | 135 | { | 
 | 136 | 	return pci_register_driver(&vx855_pci_driver); | 
 | 137 | } | 
 | 138 | module_init(vx855_init); | 
 | 139 |  | 
 | 140 | static void vx855_exit(void) | 
 | 141 | { | 
 | 142 | 	pci_unregister_driver(&vx855_pci_driver); | 
 | 143 | } | 
 | 144 | module_exit(vx855_exit); | 
 | 145 |  | 
 | 146 | MODULE_LICENSE("GPL"); | 
 | 147 | MODULE_AUTHOR("Harald Welte <HaraldWelte@viatech.com>"); | 
 | 148 | MODULE_DESCRIPTION("Driver for the VIA VX855 chipset"); |