2 * lpc_sch.c - LPC interface for Intel Poulsbo SCH
4 * LPC bridge function of the Intel SCH contains many other
5 * functional units, such as Interrupt controllers, Timers,
6 * Power Management, System Management, GPIO, RTC, and LPC
7 * Configuration Registers.
9 * Copyright (c) 2010 CompuLab Ltd
10 * Author: Denis Turischev <denis@compulab.co.il>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License 2 as published
14 * by the Free Software Foundation.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; see the file COPYING. If not, write to
23 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <linux/kernel.h>
27 #include <linux/module.h>
28 #include <linux/errno.h>
29 #include <linux/acpi.h>
30 #include <linux/pci.h>
31 #include <linux/mfd/core.h>
34 #define SMBUS_IO_SIZE 64
37 #define GPIO_IO_SIZE 64
38 #define GPIO_IO_SIZE_CENTERTON 128
40 /* Intel Quark X1000 GPIO IRQ Number */
41 #define GPIO_IRQ_QUARK_X1000 9
44 #define WDT_IO_SIZE 64
47 LPC_SCH = 0, /* Intel Poulsbo SCH */
48 LPC_ITC, /* Intel Tunnel Creek */
49 LPC_CENTERTON, /* Intel Centerton */
50 LPC_QUARK_X1000, /* Intel Quark X1000 */
54 unsigned int io_size_smbus;
55 unsigned int io_size_gpio;
56 unsigned int io_size_wdt;
60 static struct lpc_sch_info sch_chipset_info[] = {
62 .io_size_smbus = SMBUS_IO_SIZE,
63 .io_size_gpio = GPIO_IO_SIZE,
67 .io_size_smbus = SMBUS_IO_SIZE,
68 .io_size_gpio = GPIO_IO_SIZE,
69 .io_size_wdt = WDT_IO_SIZE,
73 .io_size_smbus = SMBUS_IO_SIZE,
74 .io_size_gpio = GPIO_IO_SIZE_CENTERTON,
75 .io_size_wdt = WDT_IO_SIZE,
79 .io_size_gpio = GPIO_IO_SIZE,
80 .irq_gpio = GPIO_IRQ_QUARK_X1000,
84 static const struct pci_device_id lpc_sch_ids[] = {
85 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_SCH_LPC), LPC_SCH },
86 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ITC_LPC), LPC_ITC },
87 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_CENTERTON_ILB), LPC_CENTERTON },
88 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_QUARK_X1000_ILB), LPC_QUARK_X1000 },
91 MODULE_DEVICE_TABLE(pci, lpc_sch_ids);
93 #define LPC_NO_RESOURCE 1
94 #define LPC_SKIP_RESOURCE 2
96 static int lpc_sch_get_io(struct pci_dev *pdev, int where, const char *name,
97 struct resource *res, int size)
99 unsigned int base_addr_cfg;
100 unsigned short base_addr;
103 return LPC_NO_RESOURCE;
105 pci_read_config_dword(pdev, where, &base_addr_cfg);
107 if (!(base_addr_cfg & (1 << 31)))
108 dev_warn(&pdev->dev, "Decode of the %s I/O range disabled\n",
111 base_addr = (unsigned short)base_addr_cfg;
113 if (base_addr == 0) {
114 dev_warn(&pdev->dev, "I/O space for %s uninitialized\n", name);
115 return LPC_SKIP_RESOURCE;
118 res->start = base_addr;
119 res->end = base_addr + size - 1;
120 res->flags = IORESOURCE_IO;
125 static int lpc_sch_populate_cell(struct pci_dev *pdev, int where,
126 const char *name, int size, int irq,
127 int id, struct mfd_cell *cell)
129 struct resource *res;
132 res = devm_kcalloc(&pdev->dev, 2, sizeof(*res), GFP_KERNEL);
136 ret = lpc_sch_get_io(pdev, where, name, res, size);
140 memset(cell, 0, sizeof(*cell));
143 cell->resources = res;
144 cell->num_resources = 1;
145 cell->ignore_resource_conflicts = true;
148 /* Check if we need to add an IRQ resource */
156 res->flags = IORESOURCE_IRQ;
158 cell->num_resources++;
163 static int lpc_sch_probe(struct pci_dev *dev, const struct pci_device_id *id)
165 struct mfd_cell lpc_sch_cells[3];
166 struct lpc_sch_info *info = &sch_chipset_info[id->driver_data];
167 unsigned int cells = 0;
170 ret = lpc_sch_populate_cell(dev, SMBASE, "isch_smbus",
171 info->io_size_smbus, -1,
172 id->device, &lpc_sch_cells[cells]);
178 ret = lpc_sch_populate_cell(dev, GPIOBASE, "sch_gpio",
179 info->io_size_gpio, info->irq_gpio,
180 id->device, &lpc_sch_cells[cells]);
186 ret = lpc_sch_populate_cell(dev, WDTBASE, "ie6xx_wdt",
187 info->io_size_wdt, -1,
188 id->device, &lpc_sch_cells[cells]);
195 dev_err(&dev->dev, "All decode registers disabled.\n");
199 ret = mfd_add_devices(&dev->dev, 0, lpc_sch_cells, cells, NULL, 0, NULL);
201 mfd_remove_devices(&dev->dev);
206 static void lpc_sch_remove(struct pci_dev *dev)
208 mfd_remove_devices(&dev->dev);
211 static struct pci_driver lpc_sch_driver = {
213 .id_table = lpc_sch_ids,
214 .probe = lpc_sch_probe,
215 .remove = lpc_sch_remove,
218 module_pci_driver(lpc_sch_driver);
220 MODULE_AUTHOR("Denis Turischev <denis@compulab.co.il>");
221 MODULE_DESCRIPTION("LPC interface for Intel Poulsbo SCH");
222 MODULE_LICENSE("GPL");