Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Daniel Drake | 375fc77 | 2010-09-30 21:55:41 +0100 | [diff] [blame] | 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. |
Daniel Drake | 375fc77 | 2010-09-30 21:55:41 +0100 | [diff] [blame] | 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 | |
Geert Uytterhoeven | 5ac9855 | 2013-11-18 14:33:06 +0100 | [diff] [blame] | 48 | static const struct mfd_cell vx855_cells[] = { |
Daniel Drake | 375fc77 | 2010-09-30 21:55:41 +0100 | [diff] [blame] | 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 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 60 | static int vx855_probe(struct pci_dev *pdev, |
Daniel Drake | 375fc77 | 2010-09-30 21:55:41 +0100 | [diff] [blame] | 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), |
Mark Brown | 0848c94 | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 90 | NULL, 0, NULL); |
Daniel Drake | 375fc77 | 2010-09-30 21:55:41 +0100 | [diff] [blame] | 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 | |
Bill Pemberton | 4740f73 | 2012-11-19 13:26:01 -0500 | [diff] [blame] | 100 | static void vx855_remove(struct pci_dev *pdev) |
Daniel Drake | 375fc77 | 2010-09-30 21:55:41 +0100 | [diff] [blame] | 101 | { |
| 102 | mfd_remove_devices(&pdev->dev); |
| 103 | pci_disable_device(pdev); |
| 104 | } |
| 105 | |
Jingoo Han | 36fcd06 | 2013-12-03 08:15:39 +0900 | [diff] [blame] | 106 | static const struct pci_device_id vx855_pci_tbl[] = { |
Daniel Drake | 375fc77 | 2010-09-30 21:55:41 +0100 | [diff] [blame] | 107 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_VX855) }, |
| 108 | { 0, } |
| 109 | }; |
Axel Lin | bcd2f63 | 2011-02-28 14:34:27 +0800 | [diff] [blame] | 110 | MODULE_DEVICE_TABLE(pci, vx855_pci_tbl); |
Daniel Drake | 375fc77 | 2010-09-30 21:55:41 +0100 | [diff] [blame] | 111 | |
| 112 | static struct pci_driver vx855_pci_driver = { |
| 113 | .name = "vx855", |
| 114 | .id_table = vx855_pci_tbl, |
| 115 | .probe = vx855_probe, |
Bill Pemberton | 8444921 | 2012-11-19 13:20:24 -0500 | [diff] [blame] | 116 | .remove = vx855_remove, |
Daniel Drake | 375fc77 | 2010-09-30 21:55:41 +0100 | [diff] [blame] | 117 | }; |
| 118 | |
Axel Lin | 38a36f5 | 2012-04-03 09:09:19 +0800 | [diff] [blame] | 119 | module_pci_driver(vx855_pci_driver); |
Daniel Drake | 375fc77 | 2010-09-30 21:55:41 +0100 | [diff] [blame] | 120 | |
| 121 | MODULE_LICENSE("GPL"); |
| 122 | MODULE_AUTHOR("Harald Welte <HaraldWelte@viatech.com>"); |
| 123 | MODULE_DESCRIPTION("Driver for the VIA VX855 chipset"); |