]> git.karo-electronics.de Git - linux-beck.git/blob - drivers/mfd/lpc_sch.c
mfd: lpc_sch: Add support for Intel Quark X1000
[linux-beck.git] / drivers / mfd / lpc_sch.c
1 /*
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
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>
32
33 #define SMBASE          0x40
34 #define SMBUS_IO_SIZE   64
35
36 #define GPIOBASE        0x44
37 #define GPIO_IO_SIZE    64
38 #define GPIO_IO_SIZE_CENTERTON  128
39
40 /* Intel Quark X1000 GPIO IRQ Number */
41 #define GPIO_IRQ_QUARK_X1000    9
42
43 #define WDTBASE         0x84
44 #define WDT_IO_SIZE     64
45
46 enum sch_chipsets {
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 */
51 };
52
53 struct lpc_sch_info {
54         unsigned int io_size_smbus;
55         unsigned int io_size_gpio;
56         unsigned int io_size_wdt;
57         int irq_gpio;
58 };
59
60 static struct lpc_sch_info sch_chipset_info[] = {
61         [LPC_SCH] = {
62                 .io_size_smbus = SMBUS_IO_SIZE,
63                 .io_size_gpio = GPIO_IO_SIZE,
64                 .irq_gpio = -1,
65         },
66         [LPC_ITC] = {
67                 .io_size_smbus = SMBUS_IO_SIZE,
68                 .io_size_gpio = GPIO_IO_SIZE,
69                 .io_size_wdt = WDT_IO_SIZE,
70                 .irq_gpio = -1,
71         },
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,
76                 .irq_gpio = -1,
77         },
78         [LPC_QUARK_X1000] = {
79                 .io_size_gpio = GPIO_IO_SIZE,
80                 .irq_gpio = GPIO_IRQ_QUARK_X1000,
81         },
82 };
83
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 },
89         { 0, }
90 };
91 MODULE_DEVICE_TABLE(pci, lpc_sch_ids);
92
93 #define LPC_NO_RESOURCE         1
94 #define LPC_SKIP_RESOURCE       2
95
96 static int lpc_sch_get_io(struct pci_dev *pdev, int where, const char *name,
97                           struct resource *res, int size)
98 {
99         unsigned int base_addr_cfg;
100         unsigned short base_addr;
101
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
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)
128 {
129         struct resource *res;
130         int ret;
131
132         res = devm_kcalloc(&pdev->dev, 2, sizeof(*res), GFP_KERNEL);
133         if (!res)
134                 return -ENOMEM;
135
136         ret = lpc_sch_get_io(pdev, where, name, res, size);
137         if (ret)
138                 return ret;
139
140         memset(cell, 0, sizeof(*cell));
141
142         cell->name = name;
143         cell->resources = res;
144         cell->num_resources = 1;
145         cell->ignore_resource_conflicts = true;
146         cell->id = id;
147
148         /* 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
160         return 0;
161 }
162
163 static 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",
171                                     info->io_size_smbus, -1,
172                                     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",
179                                     info->io_size_gpio, info->irq_gpio,
180                                     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",
187                                     info->io_size_wdt, -1,
188                                     id->device, &lpc_sch_cells[cells]);
189         if (ret < 0)
190                 return ret;
191         if (ret == 0)
192                 cells++;
193
194         if (cells == 0) {
195                 dev_err(&dev->dev, "All decode registers disabled.\n");
196                 return -ENODEV;
197         }
198
199         ret = mfd_add_devices(&dev->dev, 0, lpc_sch_cells, cells, NULL, 0, NULL);
200         if (ret)
201                 mfd_remove_devices(&dev->dev);
202
203         return ret;
204 }
205
206 static void lpc_sch_remove(struct pci_dev *dev)
207 {
208         mfd_remove_devices(&dev->dev);
209 }
210
211 static struct pci_driver lpc_sch_driver = {
212         .name           = "lpc_sch",
213         .id_table       = lpc_sch_ids,
214         .probe          = lpc_sch_probe,
215         .remove         = lpc_sch_remove,
216 };
217
218 module_pci_driver(lpc_sch_driver);
219
220 MODULE_AUTHOR("Denis Turischev <denis@compulab.co.il>");
221 MODULE_DESCRIPTION("LPC interface for Intel Poulsbo SCH");
222 MODULE_LICENSE("GPL");