19f806850SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2e82c60aeSDenis Turischev /*
3e82c60aeSDenis Turischev * lpc_sch.c - LPC interface for Intel Poulsbo SCH
4e82c60aeSDenis Turischev *
5e82c60aeSDenis Turischev * LPC bridge function of the Intel SCH contains many other
6e82c60aeSDenis Turischev * functional units, such as Interrupt controllers, Timers,
7e82c60aeSDenis Turischev * Power Management, System Management, GPIO, RTC, and LPC
8e82c60aeSDenis Turischev * Configuration Registers.
9e82c60aeSDenis Turischev *
10e82c60aeSDenis Turischev * Copyright (c) 2010 CompuLab Ltd
1185de80e8SAndy Shevchenko * Copyright (c) 2014 Intel Corp.
12e82c60aeSDenis Turischev * Author: Denis Turischev <denis@compulab.co.il>
13e82c60aeSDenis Turischev */
14e82c60aeSDenis Turischev
15e82c60aeSDenis Turischev #include <linux/kernel.h>
16e82c60aeSDenis Turischev #include <linux/module.h>
17e82c60aeSDenis Turischev #include <linux/errno.h>
18e82c60aeSDenis Turischev #include <linux/acpi.h>
19e82c60aeSDenis Turischev #include <linux/pci.h>
20e82c60aeSDenis Turischev #include <linux/mfd/core.h>
21e82c60aeSDenis Turischev
22e82c60aeSDenis Turischev #define SMBASE 0x40
23e82c60aeSDenis Turischev #define SMBUS_IO_SIZE 64
24e82c60aeSDenis Turischev
25*cdff1edaSRandy Dunlap #define GPIO_BASE 0x44
26e82c60aeSDenis Turischev #define GPIO_IO_SIZE 64
278ee3c2a7SSeth Heasley #define GPIO_IO_SIZE_CENTERTON 128
28e82c60aeSDenis Turischev
2919921ef6SAlexander Stein #define WDTBASE 0x84
3019921ef6SAlexander Stein #define WDT_IO_SIZE 64
3119921ef6SAlexander Stein
32b24512c8SAndy Shevchenko enum sch_chipsets {
33b24512c8SAndy Shevchenko LPC_SCH = 0, /* Intel Poulsbo SCH */
34b24512c8SAndy Shevchenko LPC_ITC, /* Intel Tunnel Creek */
35b24512c8SAndy Shevchenko LPC_CENTERTON, /* Intel Centerton */
36ec689a8aSAndy Shevchenko LPC_QUARK_X1000, /* Intel Quark X1000 */
37e82c60aeSDenis Turischev };
38e82c60aeSDenis Turischev
39b24512c8SAndy Shevchenko struct lpc_sch_info {
40b24512c8SAndy Shevchenko unsigned int io_size_smbus;
41b24512c8SAndy Shevchenko unsigned int io_size_gpio;
42b24512c8SAndy Shevchenko unsigned int io_size_wdt;
43e82c60aeSDenis Turischev };
44e82c60aeSDenis Turischev
45b24512c8SAndy Shevchenko static struct lpc_sch_info sch_chipset_info[] = {
46b24512c8SAndy Shevchenko [LPC_SCH] = {
47b24512c8SAndy Shevchenko .io_size_smbus = SMBUS_IO_SIZE,
48b24512c8SAndy Shevchenko .io_size_gpio = GPIO_IO_SIZE,
49b24512c8SAndy Shevchenko },
50b24512c8SAndy Shevchenko [LPC_ITC] = {
51b24512c8SAndy Shevchenko .io_size_smbus = SMBUS_IO_SIZE,
52b24512c8SAndy Shevchenko .io_size_gpio = GPIO_IO_SIZE,
53b24512c8SAndy Shevchenko .io_size_wdt = WDT_IO_SIZE,
54b24512c8SAndy Shevchenko },
55b24512c8SAndy Shevchenko [LPC_CENTERTON] = {
56b24512c8SAndy Shevchenko .io_size_smbus = SMBUS_IO_SIZE,
57b24512c8SAndy Shevchenko .io_size_gpio = GPIO_IO_SIZE_CENTERTON,
58b24512c8SAndy Shevchenko .io_size_wdt = WDT_IO_SIZE,
59ec689a8aSAndy Shevchenko },
60ec689a8aSAndy Shevchenko [LPC_QUARK_X1000] = {
61ec689a8aSAndy Shevchenko .io_size_gpio = GPIO_IO_SIZE,
62c68a8658SOng Boon Leong .io_size_wdt = WDT_IO_SIZE,
63b24512c8SAndy Shevchenko },
6419921ef6SAlexander Stein };
6519921ef6SAlexander Stein
6636fcd06cSJingoo Han static const struct pci_device_id lpc_sch_ids[] = {
67b24512c8SAndy Shevchenko { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_SCH_LPC), LPC_SCH },
68b24512c8SAndy Shevchenko { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ITC_LPC), LPC_ITC },
69b24512c8SAndy Shevchenko { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_CENTERTON_ILB), LPC_CENTERTON },
70ec689a8aSAndy Shevchenko { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_QUARK_X1000_ILB), LPC_QUARK_X1000 },
71e82c60aeSDenis Turischev { 0, }
72e82c60aeSDenis Turischev };
73e82c60aeSDenis Turischev MODULE_DEVICE_TABLE(pci, lpc_sch_ids);
74e82c60aeSDenis Turischev
75b24512c8SAndy Shevchenko #define LPC_NO_RESOURCE 1
76b24512c8SAndy Shevchenko #define LPC_SKIP_RESOURCE 2
77b24512c8SAndy Shevchenko
lpc_sch_get_io(struct pci_dev * pdev,int where,const char * name,struct resource * res,int size)78b24512c8SAndy Shevchenko static int lpc_sch_get_io(struct pci_dev *pdev, int where, const char *name,
79b24512c8SAndy Shevchenko struct resource *res, int size)
80e82c60aeSDenis Turischev {
81e82c60aeSDenis Turischev unsigned int base_addr_cfg;
82e82c60aeSDenis Turischev unsigned short base_addr;
83b24512c8SAndy Shevchenko
84b24512c8SAndy Shevchenko if (size == 0)
85b24512c8SAndy Shevchenko return LPC_NO_RESOURCE;
86b24512c8SAndy Shevchenko
87b24512c8SAndy Shevchenko pci_read_config_dword(pdev, where, &base_addr_cfg);
88b24512c8SAndy Shevchenko base_addr = 0;
89b24512c8SAndy Shevchenko if (!(base_addr_cfg & (1 << 31)))
90b24512c8SAndy Shevchenko dev_warn(&pdev->dev, "Decode of the %s I/O range disabled\n",
91b24512c8SAndy Shevchenko name);
92b24512c8SAndy Shevchenko else
93b24512c8SAndy Shevchenko base_addr = (unsigned short)base_addr_cfg;
94b24512c8SAndy Shevchenko
95b24512c8SAndy Shevchenko if (base_addr == 0) {
96b24512c8SAndy Shevchenko dev_warn(&pdev->dev, "I/O space for %s uninitialized\n", name);
97b24512c8SAndy Shevchenko return LPC_SKIP_RESOURCE;
98b24512c8SAndy Shevchenko }
99b24512c8SAndy Shevchenko
100b24512c8SAndy Shevchenko res->start = base_addr;
101b24512c8SAndy Shevchenko res->end = base_addr + size - 1;
102b24512c8SAndy Shevchenko res->flags = IORESOURCE_IO;
103b24512c8SAndy Shevchenko
104b24512c8SAndy Shevchenko return 0;
105b24512c8SAndy Shevchenko }
106b24512c8SAndy Shevchenko
lpc_sch_populate_cell(struct pci_dev * pdev,int where,const char * name,int size,int id,struct mfd_cell * cell)107b24512c8SAndy Shevchenko static int lpc_sch_populate_cell(struct pci_dev *pdev, int where,
108922e8ce8SAndy Shevchenko const char *name, int size, int id,
109922e8ce8SAndy Shevchenko struct mfd_cell *cell)
110b24512c8SAndy Shevchenko {
111b24512c8SAndy Shevchenko struct resource *res;
11219921ef6SAlexander Stein int ret;
113e82c60aeSDenis Turischev
114922e8ce8SAndy Shevchenko res = devm_kzalloc(&pdev->dev, sizeof(*res), GFP_KERNEL);
115b24512c8SAndy Shevchenko if (!res)
116b24512c8SAndy Shevchenko return -ENOMEM;
117e82c60aeSDenis Turischev
118b24512c8SAndy Shevchenko ret = lpc_sch_get_io(pdev, where, name, res, size);
119b24512c8SAndy Shevchenko if (ret)
120b24512c8SAndy Shevchenko return ret;
121b24512c8SAndy Shevchenko
122b24512c8SAndy Shevchenko memset(cell, 0, sizeof(*cell));
123b24512c8SAndy Shevchenko
124b24512c8SAndy Shevchenko cell->name = name;
125b24512c8SAndy Shevchenko cell->resources = res;
126b24512c8SAndy Shevchenko cell->num_resources = 1;
127b24512c8SAndy Shevchenko cell->ignore_resource_conflicts = true;
128b24512c8SAndy Shevchenko cell->id = id;
129b24512c8SAndy Shevchenko
130b24512c8SAndy Shevchenko return 0;
1315829e9b6SDarren Hart }
132e82c60aeSDenis Turischev
lpc_sch_probe(struct pci_dev * dev,const struct pci_device_id * id)133b24512c8SAndy Shevchenko static int lpc_sch_probe(struct pci_dev *dev, const struct pci_device_id *id)
134b24512c8SAndy Shevchenko {
135b24512c8SAndy Shevchenko struct mfd_cell lpc_sch_cells[3];
136b24512c8SAndy Shevchenko struct lpc_sch_info *info = &sch_chipset_info[id->driver_data];
137b24512c8SAndy Shevchenko unsigned int cells = 0;
138b24512c8SAndy Shevchenko int ret;
1395829e9b6SDarren Hart
140b24512c8SAndy Shevchenko ret = lpc_sch_populate_cell(dev, SMBASE, "isch_smbus",
141922e8ce8SAndy Shevchenko info->io_size_smbus,
142b24512c8SAndy Shevchenko id->device, &lpc_sch_cells[cells]);
143b24512c8SAndy Shevchenko if (ret < 0)
144b24512c8SAndy Shevchenko return ret;
145b24512c8SAndy Shevchenko if (ret == 0)
146b24512c8SAndy Shevchenko cells++;
14719921ef6SAlexander Stein
148*cdff1edaSRandy Dunlap ret = lpc_sch_populate_cell(dev, GPIO_BASE, "sch_gpio",
149922e8ce8SAndy Shevchenko info->io_size_gpio,
150b24512c8SAndy Shevchenko id->device, &lpc_sch_cells[cells]);
151b24512c8SAndy Shevchenko if (ret < 0)
152b24512c8SAndy Shevchenko return ret;
153b24512c8SAndy Shevchenko if (ret == 0)
154b24512c8SAndy Shevchenko cells++;
15519921ef6SAlexander Stein
156b24512c8SAndy Shevchenko ret = lpc_sch_populate_cell(dev, WDTBASE, "ie6xx_wdt",
157922e8ce8SAndy Shevchenko info->io_size_wdt,
158b24512c8SAndy Shevchenko id->device, &lpc_sch_cells[cells]);
159b24512c8SAndy Shevchenko if (ret < 0)
160b24512c8SAndy Shevchenko return ret;
161b24512c8SAndy Shevchenko if (ret == 0)
162b24512c8SAndy Shevchenko cells++;
1635829e9b6SDarren Hart
1645829e9b6SDarren Hart if (cells == 0) {
1655829e9b6SDarren Hart dev_err(&dev->dev, "All decode registers disabled.\n");
1665829e9b6SDarren Hart return -ENODEV;
1675829e9b6SDarren Hart }
1685829e9b6SDarren Hart
169bde3e706SAndy Shevchenko return mfd_add_devices(&dev->dev, 0, lpc_sch_cells, cells, NULL, 0, NULL);
170e82c60aeSDenis Turischev }
171e82c60aeSDenis Turischev
lpc_sch_remove(struct pci_dev * dev)1724740f73fSBill Pemberton static void lpc_sch_remove(struct pci_dev *dev)
173e82c60aeSDenis Turischev {
174e82c60aeSDenis Turischev mfd_remove_devices(&dev->dev);
175e82c60aeSDenis Turischev }
176e82c60aeSDenis Turischev
177e82c60aeSDenis Turischev static struct pci_driver lpc_sch_driver = {
178e82c60aeSDenis Turischev .name = "lpc_sch",
179e82c60aeSDenis Turischev .id_table = lpc_sch_ids,
180e82c60aeSDenis Turischev .probe = lpc_sch_probe,
18184449216SBill Pemberton .remove = lpc_sch_remove,
182e82c60aeSDenis Turischev };
183e82c60aeSDenis Turischev
18438a36f5aSAxel Lin module_pci_driver(lpc_sch_driver);
185e82c60aeSDenis Turischev
186e82c60aeSDenis Turischev MODULE_AUTHOR("Denis Turischev <denis@compulab.co.il>");
187e82c60aeSDenis Turischev MODULE_DESCRIPTION("LPC interface for Intel Poulsbo SCH");
188e82c60aeSDenis Turischev MODULE_LICENSE("GPL");
189