blob: ae614b2aca7e27347d71996de949fa9224731e37 [file] [log] [blame]
Denis Turischeve82c60a2010-02-19 11:26:25 +01001/*
2 * lpc_sch.c - LPC interface for Intel Poulsbo SCH
3 *
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.
8 *
9 * Copyright (c) 2010 CompuLab Ltd
10 * Author: Denis Turischev <denis@compulab.co.il>
11 *
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.
15 *
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.
20 *
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.
24 */
25
Denis Turischeve82c60a2010-02-19 11:26:25 +010026#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>
32
33#define SMBASE 0x40
34#define SMBUS_IO_SIZE 64
35
36#define GPIOBASE 0x44
37#define GPIO_IO_SIZE 64
Seth Heasley8ee3c2a2012-04-17 14:09:22 -070038#define GPIO_IO_SIZE_CENTERTON 128
Denis Turischeve82c60a2010-02-19 11:26:25 +010039
Andy Shevchenkoec689a82014-09-02 13:45:21 +030040/* Intel Quark X1000 GPIO IRQ Number */
41#define GPIO_IRQ_QUARK_X1000 9
42
Alexander Stein19921ef2011-06-16 13:05:49 +020043#define WDTBASE 0x84
44#define WDT_IO_SIZE 64
45
Andy Shevchenkob24512c2014-09-02 13:45:19 +030046enum sch_chipsets {
47 LPC_SCH = 0, /* Intel Poulsbo SCH */
48 LPC_ITC, /* Intel Tunnel Creek */
49 LPC_CENTERTON, /* Intel Centerton */
Andy Shevchenkoec689a82014-09-02 13:45:21 +030050 LPC_QUARK_X1000, /* Intel Quark X1000 */
Denis Turischeve82c60a2010-02-19 11:26:25 +010051};
52
Andy Shevchenkob24512c2014-09-02 13:45:19 +030053struct lpc_sch_info {
54 unsigned int io_size_smbus;
55 unsigned int io_size_gpio;
56 unsigned int io_size_wdt;
Andy Shevchenkoec689a82014-09-02 13:45:21 +030057 int irq_gpio;
Denis Turischeve82c60a2010-02-19 11:26:25 +010058};
59
Andy Shevchenkob24512c2014-09-02 13:45:19 +030060static struct lpc_sch_info sch_chipset_info[] = {
61 [LPC_SCH] = {
62 .io_size_smbus = SMBUS_IO_SIZE,
63 .io_size_gpio = GPIO_IO_SIZE,
Andy Shevchenkoec689a82014-09-02 13:45:21 +030064 .irq_gpio = -1,
Andy Shevchenkob24512c2014-09-02 13:45:19 +030065 },
66 [LPC_ITC] = {
67 .io_size_smbus = SMBUS_IO_SIZE,
68 .io_size_gpio = GPIO_IO_SIZE,
69 .io_size_wdt = WDT_IO_SIZE,
Andy Shevchenkoec689a82014-09-02 13:45:21 +030070 .irq_gpio = -1,
Andy Shevchenkob24512c2014-09-02 13:45:19 +030071 },
72 [LPC_CENTERTON] = {
73 .io_size_smbus = SMBUS_IO_SIZE,
74 .io_size_gpio = GPIO_IO_SIZE_CENTERTON,
75 .io_size_wdt = WDT_IO_SIZE,
Andy Shevchenkoec689a82014-09-02 13:45:21 +030076 .irq_gpio = -1,
77 },
78 [LPC_QUARK_X1000] = {
79 .io_size_gpio = GPIO_IO_SIZE,
80 .irq_gpio = GPIO_IRQ_QUARK_X1000,
Andy Shevchenkob24512c2014-09-02 13:45:19 +030081 },
Alexander Stein19921ef2011-06-16 13:05:49 +020082};
83
Jingoo Han36fcd062013-12-03 08:15:39 +090084static const struct pci_device_id lpc_sch_ids[] = {
Andy Shevchenkob24512c2014-09-02 13:45:19 +030085 { 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 },
Andy Shevchenkoec689a82014-09-02 13:45:21 +030088 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_QUARK_X1000_ILB), LPC_QUARK_X1000 },
Denis Turischeve82c60a2010-02-19 11:26:25 +010089 { 0, }
90};
91MODULE_DEVICE_TABLE(pci, lpc_sch_ids);
92
Andy Shevchenkob24512c2014-09-02 13:45:19 +030093#define LPC_NO_RESOURCE 1
94#define LPC_SKIP_RESOURCE 2
95
96static int lpc_sch_get_io(struct pci_dev *pdev, int where, const char *name,
97 struct resource *res, int size)
Denis Turischeve82c60a2010-02-19 11:26:25 +010098{
99 unsigned int base_addr_cfg;
100 unsigned short base_addr;
Andy Shevchenkob24512c2014-09-02 13:45:19 +0300101
102 if (size == 0)
103 return LPC_NO_RESOURCE;
104
105 pci_read_config_dword(pdev, where, &base_addr_cfg);
106 base_addr = 0;
107 if (!(base_addr_cfg & (1 << 31)))
108 dev_warn(&pdev->dev, "Decode of the %s I/O range disabled\n",
109 name);
110 else
111 base_addr = (unsigned short)base_addr_cfg;
112
113 if (base_addr == 0) {
114 dev_warn(&pdev->dev, "I/O space for %s uninitialized\n", name);
115 return LPC_SKIP_RESOURCE;
116 }
117
118 res->start = base_addr;
119 res->end = base_addr + size - 1;
120 res->flags = IORESOURCE_IO;
121
122 return 0;
123}
124
125static int lpc_sch_populate_cell(struct pci_dev *pdev, int where,
Andy Shevchenkoec689a82014-09-02 13:45:21 +0300126 const char *name, int size, int irq,
127 int id, struct mfd_cell *cell)
Andy Shevchenkob24512c2014-09-02 13:45:19 +0300128{
129 struct resource *res;
Alexander Stein19921ef2011-06-16 13:05:49 +0200130 int ret;
Denis Turischeve82c60a2010-02-19 11:26:25 +0100131
Andy Shevchenkoec689a82014-09-02 13:45:21 +0300132 res = devm_kcalloc(&pdev->dev, 2, sizeof(*res), GFP_KERNEL);
Andy Shevchenkob24512c2014-09-02 13:45:19 +0300133 if (!res)
134 return -ENOMEM;
Denis Turischeve82c60a2010-02-19 11:26:25 +0100135
Andy Shevchenkob24512c2014-09-02 13:45:19 +0300136 ret = lpc_sch_get_io(pdev, where, name, res, size);
137 if (ret)
138 return ret;
Denis Turischeve82c60a2010-02-19 11:26:25 +0100139
Andy Shevchenkob24512c2014-09-02 13:45:19 +0300140 memset(cell, 0, sizeof(*cell));
Denis Turischeve82c60a2010-02-19 11:26:25 +0100141
Andy Shevchenkob24512c2014-09-02 13:45:19 +0300142 cell->name = name;
143 cell->resources = res;
144 cell->num_resources = 1;
145 cell->ignore_resource_conflicts = true;
146 cell->id = id;
Alexander Stein19921ef2011-06-16 13:05:49 +0200147
Andy Shevchenkoec689a82014-09-02 13:45:21 +0300148 /* Check if we need to add an IRQ resource */
149 if (irq < 0)
150 return 0;
151
152 res++;
153
154 res->start = irq;
155 res->end = irq;
156 res->flags = IORESOURCE_IRQ;
157
158 cell->num_resources++;
159
Andy Shevchenkob24512c2014-09-02 13:45:19 +0300160 return 0;
161}
Alexander Stein19921ef2011-06-16 13:05:49 +0200162
Andy Shevchenkob24512c2014-09-02 13:45:19 +0300163static int lpc_sch_probe(struct pci_dev *dev, const struct pci_device_id *id)
164{
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;
168 int ret;
169
170 ret = lpc_sch_populate_cell(dev, SMBASE, "isch_smbus",
Andy Shevchenkoec689a82014-09-02 13:45:21 +0300171 info->io_size_smbus, -1,
Andy Shevchenkob24512c2014-09-02 13:45:19 +0300172 id->device, &lpc_sch_cells[cells]);
173 if (ret < 0)
174 return ret;
175 if (ret == 0)
176 cells++;
177
178 ret = lpc_sch_populate_cell(dev, GPIOBASE, "sch_gpio",
Andy Shevchenkoec689a82014-09-02 13:45:21 +0300179 info->io_size_gpio, info->irq_gpio,
Andy Shevchenkob24512c2014-09-02 13:45:19 +0300180 id->device, &lpc_sch_cells[cells]);
181 if (ret < 0)
182 return ret;
183 if (ret == 0)
184 cells++;
185
186 ret = lpc_sch_populate_cell(dev, WDTBASE, "ie6xx_wdt",
Andy Shevchenkoec689a82014-09-02 13:45:21 +0300187 info->io_size_wdt, -1,
Andy Shevchenkob24512c2014-09-02 13:45:19 +0300188 id->device, &lpc_sch_cells[cells]);
189 if (ret < 0)
190 return ret;
191 if (ret == 0)
192 cells++;
Darren Hart5829e9b2013-02-08 15:20:36 -0800193
194 if (cells == 0) {
195 dev_err(&dev->dev, "All decode registers disabled.\n");
196 return -ENODEV;
197 }
198
Darren Hart5829e9b2013-02-08 15:20:36 -0800199 ret = mfd_add_devices(&dev->dev, 0, lpc_sch_cells, cells, NULL, 0, NULL);
200 if (ret)
201 mfd_remove_devices(&dev->dev);
202
Alexander Stein19921ef2011-06-16 13:05:49 +0200203 return ret;
Denis Turischeve82c60a2010-02-19 11:26:25 +0100204}
205
Bill Pemberton4740f732012-11-19 13:26:01 -0500206static void lpc_sch_remove(struct pci_dev *dev)
Denis Turischeve82c60a2010-02-19 11:26:25 +0100207{
208 mfd_remove_devices(&dev->dev);
209}
210
211static struct pci_driver lpc_sch_driver = {
212 .name = "lpc_sch",
213 .id_table = lpc_sch_ids,
214 .probe = lpc_sch_probe,
Bill Pemberton84449212012-11-19 13:20:24 -0500215 .remove = lpc_sch_remove,
Denis Turischeve82c60a2010-02-19 11:26:25 +0100216};
217
Axel Lin38a36f52012-04-03 09:09:19 +0800218module_pci_driver(lpc_sch_driver);
Denis Turischeve82c60a2010-02-19 11:26:25 +0100219
220MODULE_AUTHOR("Denis Turischev <denis@compulab.co.il>");
221MODULE_DESCRIPTION("LPC interface for Intel Poulsbo SCH");
222MODULE_LICENSE("GPL");