linux/drivers/i2c/busses/i2c-i801.c
<<
>>
Prefs
   1/*
   2    Copyright (c) 1998 - 2002  Frodo Looijaard <frodol@dds.nl>,
   3    Philip Edelbrock <phil@netroedge.com>, and Mark D. Studebaker
   4    <mdsxyz123@yahoo.com>
   5    Copyright (C) 2007 - 2014  Jean Delvare <jdelvare@suse.de>
   6    Copyright (C) 2010         Intel Corporation,
   7                               David Woodhouse <dwmw2@infradead.org>
   8
   9    This program is free software; you can redistribute it and/or modify
  10    it under the terms of the GNU General Public License as published by
  11    the Free Software Foundation; either version 2 of the License, or
  12    (at your option) any later version.
  13
  14    This program is distributed in the hope that it will be useful,
  15    but WITHOUT ANY WARRANTY; without even the implied warranty of
  16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17    GNU General Public License for more details.
  18*/
  19
  20/*
  21 * Supports the following Intel I/O Controller Hubs (ICH):
  22 *
  23 *                                      I/O                     Block   I2C
  24 *                                      region  SMBus   Block   proc.   block
  25 * Chip name                    PCI ID  size    PEC     buffer  call    read
  26 * ---------------------------------------------------------------------------
  27 * 82801AA (ICH)                0x2413  16      no      no      no      no
  28 * 82801AB (ICH0)               0x2423  16      no      no      no      no
  29 * 82801BA (ICH2)               0x2443  16      no      no      no      no
  30 * 82801CA (ICH3)               0x2483  32      soft    no      no      no
  31 * 82801DB (ICH4)               0x24c3  32      hard    yes     no      no
  32 * 82801E (ICH5)                0x24d3  32      hard    yes     yes     yes
  33 * 6300ESB                      0x25a4  32      hard    yes     yes     yes
  34 * 82801F (ICH6)                0x266a  32      hard    yes     yes     yes
  35 * 6310ESB/6320ESB              0x269b  32      hard    yes     yes     yes
  36 * 82801G (ICH7)                0x27da  32      hard    yes     yes     yes
  37 * 82801H (ICH8)                0x283e  32      hard    yes     yes     yes
  38 * 82801I (ICH9)                0x2930  32      hard    yes     yes     yes
  39 * EP80579 (Tolapai)            0x5032  32      hard    yes     yes     yes
  40 * ICH10                        0x3a30  32      hard    yes     yes     yes
  41 * ICH10                        0x3a60  32      hard    yes     yes     yes
  42 * 5/3400 Series (PCH)          0x3b30  32      hard    yes     yes     yes
  43 * 6 Series (PCH)               0x1c22  32      hard    yes     yes     yes
  44 * Patsburg (PCH)               0x1d22  32      hard    yes     yes     yes
  45 * Patsburg (PCH) IDF           0x1d70  32      hard    yes     yes     yes
  46 * Patsburg (PCH) IDF           0x1d71  32      hard    yes     yes     yes
  47 * Patsburg (PCH) IDF           0x1d72  32      hard    yes     yes     yes
  48 * DH89xxCC (PCH)               0x2330  32      hard    yes     yes     yes
  49 * Panther Point (PCH)          0x1e22  32      hard    yes     yes     yes
  50 * Lynx Point (PCH)             0x8c22  32      hard    yes     yes     yes
  51 * Lynx Point-LP (PCH)          0x9c22  32      hard    yes     yes     yes
  52 * Avoton (SOC)                 0x1f3c  32      hard    yes     yes     yes
  53 * Wellsburg (PCH)              0x8d22  32      hard    yes     yes     yes
  54 * Wellsburg (PCH) MS           0x8d7d  32      hard    yes     yes     yes
  55 * Wellsburg (PCH) MS           0x8d7e  32      hard    yes     yes     yes
  56 * Wellsburg (PCH) MS           0x8d7f  32      hard    yes     yes     yes
  57 * Coleto Creek (PCH)           0x23b0  32      hard    yes     yes     yes
  58 * Wildcat Point-LP (PCH)       0x9ca2  32      hard    yes     yes     yes
  59 * BayTrail (SOC)        0x0f12     32     hard     yes     yes     yes
  60 * Sunrise Point-H (PCH)        0xa123  32      hard    yes     yes     yes
  61 * Sunrise Point-LP (PCH)       0x9d23  32      hard    yes     yes     yes
  62 * DNV (SOC)                    0x19df  32      hard    yes     yes     yes
  63 * Lewisburg (PCH)              0xa1a3  32      hard    yes     yes     yes
  64 * Lewisburg Supersku (PCH)     0xa223  32      hard    yes     yes     yes
  65 * Kaby Lake PCH-H (PCH)        0xa2a3  32      hard    yes     yes     yes
  66 * Gemini Lake (SOC)            0x31d4  32      hard    yes     yes     yes
  67 * Cannon Lake-H (PCH)          0xa323  32      hard    yes     yes     yes
  68 * Cannon Lake-LP (PCH)         0x9da3  32      hard    yes     yes     yes
  69 *
  70 * Features supported by this driver:
  71 * Software PEC                         no
  72 * Hardware PEC                         yes
  73 * Block buffer                         yes
  74 * Block process call transaction       no
  75 * I2C block read transaction           yes (doesn't use the block buffer)
  76 * Slave mode                           no
  77 * Interrupt processing                 yes
  78 *
  79 * See the file Documentation/i2c/busses/i2c-i801 for details.
  80 */
  81
  82#include <linux/interrupt.h>
  83#include <linux/module.h>
  84#include <linux/pci.h>
  85#include <linux/kernel.h>
  86#include <linux/stddef.h>
  87#include <linux/delay.h>
  88#include <linux/ioport.h>
  89#include <linux/init.h>
  90#include <linux/i2c.h>
  91#include <linux/acpi.h>
  92#include <linux/io.h>
  93#include <linux/dmi.h>
  94#include <linux/slab.h>
  95#include <linux/wait.h>
  96#include <linux/err.h>
  97#include <linux/platform_device.h>
  98#include <linux/platform_data/itco_wdt.h>
  99#include <linux/pm_runtime.h>
 100
 101#if (defined CONFIG_I2C_MUX_GPIO || defined CONFIG_I2C_MUX_GPIO_MODULE) && \
 102                defined CONFIG_DMI
 103#include <linux/gpio.h>
 104#include <linux/i2c-mux-gpio.h>
 105#endif
 106
 107/* I801 SMBus address offsets */
 108#define SMBHSTSTS(p)    (0 + (p)->smba)
 109#define SMBHSTCNT(p)    (2 + (p)->smba)
 110#define SMBHSTCMD(p)    (3 + (p)->smba)
 111#define SMBHSTADD(p)    (4 + (p)->smba)
 112#define SMBHSTDAT0(p)   (5 + (p)->smba)
 113#define SMBHSTDAT1(p)   (6 + (p)->smba)
 114#define SMBBLKDAT(p)    (7 + (p)->smba)
 115#define SMBPEC(p)       (8 + (p)->smba)         /* ICH3 and later */
 116#define SMBAUXSTS(p)    (12 + (p)->smba)        /* ICH4 and later */
 117#define SMBAUXCTL(p)    (13 + (p)->smba)        /* ICH4 and later */
 118
 119/* PCI Address Constants */
 120#define SMBBAR          4
 121#define SMBPCICTL       0x004
 122#define SMBPCISTS       0x006
 123#define SMBHSTCFG       0x040
 124#define TCOBASE         0x050
 125#define TCOCTL          0x054
 126
 127#define ACPIBASE                0x040
 128#define ACPIBASE_SMI_OFF        0x030
 129#define ACPICTRL                0x044
 130#define ACPICTRL_EN             0x080
 131
 132#define SBREG_BAR               0x10
 133#define SBREG_SMBCTRL           0xc6000c
 134
 135/* Host status bits for SMBPCISTS */
 136#define SMBPCISTS_INTS          0x08
 137
 138/* Control bits for SMBPCICTL */
 139#define SMBPCICTL_INTDIS        0x0400
 140
 141/* Host configuration bits for SMBHSTCFG */
 142#define SMBHSTCFG_HST_EN        1
 143#define SMBHSTCFG_SMB_SMI_EN    2
 144#define SMBHSTCFG_I2C_EN        4
 145
 146/* TCO configuration bits for TCOCTL */
 147#define TCOCTL_EN               0x0100
 148
 149/* Auxiliary control register bits, ICH4+ only */
 150#define SMBAUXCTL_CRC           1
 151#define SMBAUXCTL_E32B          2
 152
 153/* Other settings */
 154#define MAX_RETRIES             400
 155
 156/* I801 command constants */
 157#define I801_QUICK              0x00
 158#define I801_BYTE               0x04
 159#define I801_BYTE_DATA          0x08
 160#define I801_WORD_DATA          0x0C
 161#define I801_PROC_CALL          0x10    /* unimplemented */
 162#define I801_BLOCK_DATA         0x14
 163#define I801_I2C_BLOCK_DATA     0x18    /* ICH5 and later */
 164
 165/* I801 Host Control register bits */
 166#define SMBHSTCNT_INTREN        0x01
 167#define SMBHSTCNT_KILL          0x02
 168#define SMBHSTCNT_LAST_BYTE     0x20
 169#define SMBHSTCNT_START         0x40
 170#define SMBHSTCNT_PEC_EN        0x80    /* ICH3 and later */
 171
 172/* I801 Hosts Status register bits */
 173#define SMBHSTSTS_BYTE_DONE     0x80
 174#define SMBHSTSTS_INUSE_STS     0x40
 175#define SMBHSTSTS_SMBALERT_STS  0x20
 176#define SMBHSTSTS_FAILED        0x10
 177#define SMBHSTSTS_BUS_ERR       0x08
 178#define SMBHSTSTS_DEV_ERR       0x04
 179#define SMBHSTSTS_INTR          0x02
 180#define SMBHSTSTS_HOST_BUSY     0x01
 181
 182#define STATUS_ERROR_FLAGS      (SMBHSTSTS_FAILED | SMBHSTSTS_BUS_ERR | \
 183                                 SMBHSTSTS_DEV_ERR)
 184
 185#define STATUS_FLAGS            (SMBHSTSTS_BYTE_DONE | SMBHSTSTS_INTR | \
 186                                 STATUS_ERROR_FLAGS)
 187
 188/* Older devices have their ID defined in <linux/pci_ids.h> */
 189#define PCI_DEVICE_ID_INTEL_BAYTRAIL_SMBUS              0x0f12
 190#define PCI_DEVICE_ID_INTEL_DNV_SMBUS                   0x19df
 191#define PCI_DEVICE_ID_INTEL_COUGARPOINT_SMBUS           0x1c22
 192#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS              0x1d22
 193/* Patsburg also has three 'Integrated Device Function' SMBus controllers */
 194#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF0         0x1d70
 195#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF1         0x1d71
 196#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF2         0x1d72
 197#define PCI_DEVICE_ID_INTEL_PANTHERPOINT_SMBUS          0x1e22
 198#define PCI_DEVICE_ID_INTEL_AVOTON_SMBUS                0x1f3c
 199#define PCI_DEVICE_ID_INTEL_BRASWELL_SMBUS              0x2292
 200#define PCI_DEVICE_ID_INTEL_DH89XXCC_SMBUS              0x2330
 201#define PCI_DEVICE_ID_INTEL_COLETOCREEK_SMBUS           0x23b0
 202#define PCI_DEVICE_ID_INTEL_GEMINILAKE_SMBUS            0x31d4
 203#define PCI_DEVICE_ID_INTEL_5_3400_SERIES_SMBUS         0x3b30
 204#define PCI_DEVICE_ID_INTEL_BROXTON_SMBUS               0x5ad4
 205#define PCI_DEVICE_ID_INTEL_LYNXPOINT_SMBUS             0x8c22
 206#define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS             0x8d22
 207#define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS0         0x8d7d
 208#define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS1         0x8d7e
 209#define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS2         0x8d7f
 210#define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_SMBUS          0x9c22
 211#define PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_SMBUS       0x9ca2
 212#define PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_SMBUS       0x9d23
 213#define PCI_DEVICE_ID_INTEL_CANNONLAKE_LP_SMBUS         0x9da3
 214#define PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_SMBUS        0xa123
 215#define PCI_DEVICE_ID_INTEL_LEWISBURG_SMBUS             0xa1a3
 216#define PCI_DEVICE_ID_INTEL_LEWISBURG_SSKU_SMBUS        0xa223
 217#define PCI_DEVICE_ID_INTEL_KABYLAKE_PCH_H_SMBUS        0xa2a3
 218#define PCI_DEVICE_ID_INTEL_CANNONLAKE_H_SMBUS          0xa323
 219
 220struct i801_mux_config {
 221        char *gpio_chip;
 222        unsigned values[3];
 223        int n_values;
 224        unsigned classes[3];
 225        unsigned gpios[2];              /* Relative to gpio_chip->base */
 226        int n_gpios;
 227};
 228
 229struct i801_priv {
 230        struct i2c_adapter adapter;
 231        unsigned long smba;
 232        unsigned char original_hstcfg;
 233        struct pci_dev *pci_dev;
 234        unsigned int features;
 235
 236        /* isr processing */
 237        wait_queue_head_t waitq;
 238        u8 status;
 239
 240        /* Command state used by isr for byte-by-byte block transactions */
 241        u8 cmd;
 242        bool is_read;
 243        int count;
 244        int len;
 245        u8 *data;
 246
 247#if (defined CONFIG_I2C_MUX_GPIO || defined CONFIG_I2C_MUX_GPIO_MODULE) && \
 248                defined CONFIG_DMI
 249        const struct i801_mux_config *mux_drvdata;
 250        struct platform_device *mux_pdev;
 251#endif
 252        struct platform_device *tco_pdev;
 253
 254        /*
 255         * If set to true the host controller registers are reserved for
 256         * ACPI AML use. Protected by acpi_lock.
 257         */
 258        bool acpi_reserved;
 259        struct mutex acpi_lock;
 260};
 261
 262static struct pci_driver i801_driver;
 263
 264#define FEATURE_SMBUS_PEC       (1 << 0)
 265#define FEATURE_BLOCK_BUFFER    (1 << 1)
 266#define FEATURE_BLOCK_PROC      (1 << 2)
 267#define FEATURE_I2C_BLOCK_READ  (1 << 3)
 268#define FEATURE_IRQ             (1 << 4)
 269/* Not really a feature, but it's convenient to handle it as such */
 270#define FEATURE_IDF             (1 << 15)
 271#define FEATURE_TCO             (1 << 16)
 272
 273static const char *i801_feature_names[] = {
 274        "SMBus PEC",
 275        "Block buffer",
 276        "Block process call",
 277        "I2C block read",
 278        "Interrupt",
 279};
 280
 281static unsigned int disable_features;
 282module_param(disable_features, uint, S_IRUGO | S_IWUSR);
 283MODULE_PARM_DESC(disable_features, "Disable selected driver features:\n"
 284        "\t\t  0x01  disable SMBus PEC\n"
 285        "\t\t  0x02  disable the block buffer\n"
 286        "\t\t  0x08  disable the I2C block read functionality\n"
 287        "\t\t  0x10  don't use interrupts ");
 288
 289/* Make sure the SMBus host is ready to start transmitting.
 290   Return 0 if it is, -EBUSY if it is not. */
 291static int i801_check_pre(struct i801_priv *priv)
 292{
 293        int status;
 294
 295        status = inb_p(SMBHSTSTS(priv));
 296        if (status & SMBHSTSTS_HOST_BUSY) {
 297                dev_err(&priv->pci_dev->dev, "SMBus is busy, can't use it!\n");
 298                return -EBUSY;
 299        }
 300
 301        status &= STATUS_FLAGS;
 302        if (status) {
 303                dev_dbg(&priv->pci_dev->dev, "Clearing status flags (%02x)\n",
 304                        status);
 305                outb_p(status, SMBHSTSTS(priv));
 306                status = inb_p(SMBHSTSTS(priv)) & STATUS_FLAGS;
 307                if (status) {
 308                        dev_err(&priv->pci_dev->dev,
 309                                "Failed clearing status flags (%02x)\n",
 310                                status);
 311                        return -EBUSY;
 312                }
 313        }
 314
 315        return 0;
 316}
 317
 318/*
 319 * Convert the status register to an error code, and clear it.
 320 * Note that status only contains the bits we want to clear, not the
 321 * actual register value.
 322 */
 323static int i801_check_post(struct i801_priv *priv, int status)
 324{
 325        int result = 0;
 326
 327        /*
 328         * If the SMBus is still busy, we give up
 329         * Note: This timeout condition only happens when using polling
 330         * transactions.  For interrupt operation, NAK/timeout is indicated by
 331         * DEV_ERR.
 332         */
 333        if (unlikely(status < 0)) {
 334                dev_err(&priv->pci_dev->dev, "Transaction timeout\n");
 335                /* try to stop the current command */
 336                dev_dbg(&priv->pci_dev->dev, "Terminating the current operation\n");
 337                outb_p(inb_p(SMBHSTCNT(priv)) | SMBHSTCNT_KILL,
 338                       SMBHSTCNT(priv));
 339                usleep_range(1000, 2000);
 340                outb_p(inb_p(SMBHSTCNT(priv)) & (~SMBHSTCNT_KILL),
 341                       SMBHSTCNT(priv));
 342
 343                /* Check if it worked */
 344                status = inb_p(SMBHSTSTS(priv));
 345                if ((status & SMBHSTSTS_HOST_BUSY) ||
 346                    !(status & SMBHSTSTS_FAILED))
 347                        dev_err(&priv->pci_dev->dev,
 348                                "Failed terminating the transaction\n");
 349                outb_p(STATUS_FLAGS, SMBHSTSTS(priv));
 350                return -ETIMEDOUT;
 351        }
 352
 353        if (status & SMBHSTSTS_FAILED) {
 354                result = -EIO;
 355                dev_err(&priv->pci_dev->dev, "Transaction failed\n");
 356        }
 357        if (status & SMBHSTSTS_DEV_ERR) {
 358                result = -ENXIO;
 359                dev_dbg(&priv->pci_dev->dev, "No response\n");
 360        }
 361        if (status & SMBHSTSTS_BUS_ERR) {
 362                result = -EAGAIN;
 363                dev_dbg(&priv->pci_dev->dev, "Lost arbitration\n");
 364        }
 365
 366        /* Clear status flags except BYTE_DONE, to be cleared by caller */
 367        outb_p(status, SMBHSTSTS(priv));
 368
 369        return result;
 370}
 371
 372/* Wait for BUSY being cleared and either INTR or an error flag being set */
 373static int i801_wait_intr(struct i801_priv *priv)
 374{
 375        int timeout = 0;
 376        int status;
 377
 378        /* We will always wait for a fraction of a second! */
 379        do {
 380                usleep_range(250, 500);
 381                status = inb_p(SMBHSTSTS(priv));
 382        } while (((status & SMBHSTSTS_HOST_BUSY) ||
 383                  !(status & (STATUS_ERROR_FLAGS | SMBHSTSTS_INTR))) &&
 384                 (timeout++ < MAX_RETRIES));
 385
 386        if (timeout > MAX_RETRIES) {
 387                dev_dbg(&priv->pci_dev->dev, "INTR Timeout!\n");
 388                return -ETIMEDOUT;
 389        }
 390        return status & (STATUS_ERROR_FLAGS | SMBHSTSTS_INTR);
 391}
 392
 393/* Wait for either BYTE_DONE or an error flag being set */
 394static int i801_wait_byte_done(struct i801_priv *priv)
 395{
 396        int timeout = 0;
 397        int status;
 398
 399        /* We will always wait for a fraction of a second! */
 400        do {
 401                usleep_range(250, 500);
 402                status = inb_p(SMBHSTSTS(priv));
 403        } while (!(status & (STATUS_ERROR_FLAGS | SMBHSTSTS_BYTE_DONE)) &&
 404                 (timeout++ < MAX_RETRIES));
 405
 406        if (timeout > MAX_RETRIES) {
 407                dev_dbg(&priv->pci_dev->dev, "BYTE_DONE Timeout!\n");
 408                return -ETIMEDOUT;
 409        }
 410        return status & STATUS_ERROR_FLAGS;
 411}
 412
 413static int i801_transaction(struct i801_priv *priv, int xact)
 414{
 415        int status;
 416        int result;
 417        const struct i2c_adapter *adap = &priv->adapter;
 418
 419        result = i801_check_pre(priv);
 420        if (result < 0)
 421                return result;
 422
 423        if (priv->features & FEATURE_IRQ) {
 424                outb_p(xact | SMBHSTCNT_INTREN | SMBHSTCNT_START,
 425                       SMBHSTCNT(priv));
 426                result = wait_event_timeout(priv->waitq,
 427                                            (status = priv->status),
 428                                            adap->timeout);
 429                if (!result) {
 430                        status = -ETIMEDOUT;
 431                        dev_warn(&priv->pci_dev->dev,
 432                                 "Timeout waiting for interrupt!\n");
 433                }
 434                priv->status = 0;
 435                return i801_check_post(priv, status);
 436        }
 437
 438        /* the current contents of SMBHSTCNT can be overwritten, since PEC,
 439         * SMBSCMD are passed in xact */
 440        outb_p(xact | SMBHSTCNT_START, SMBHSTCNT(priv));
 441
 442        status = i801_wait_intr(priv);
 443        return i801_check_post(priv, status);
 444}
 445
 446static int i801_block_transaction_by_block(struct i801_priv *priv,
 447                                           union i2c_smbus_data *data,
 448                                           char read_write, int hwpec)
 449{
 450        int i, len;
 451        int status;
 452
 453        inb_p(SMBHSTCNT(priv)); /* reset the data buffer index */
 454
 455        /* Use 32-byte buffer to process this transaction */
 456        if (read_write == I2C_SMBUS_WRITE) {
 457                len = data->block[0];
 458                outb_p(len, SMBHSTDAT0(priv));
 459                for (i = 0; i < len; i++)
 460                        outb_p(data->block[i+1], SMBBLKDAT(priv));
 461        }
 462
 463        status = i801_transaction(priv, I801_BLOCK_DATA |
 464                                  (hwpec ? SMBHSTCNT_PEC_EN : 0));
 465        if (status)
 466                return status;
 467
 468        if (read_write == I2C_SMBUS_READ) {
 469                len = inb_p(SMBHSTDAT0(priv));
 470                if (len < 1 || len > I2C_SMBUS_BLOCK_MAX)
 471                        return -EPROTO;
 472
 473                data->block[0] = len;
 474                for (i = 0; i < len; i++)
 475                        data->block[i + 1] = inb_p(SMBBLKDAT(priv));
 476        }
 477        return 0;
 478}
 479
 480static void i801_isr_byte_done(struct i801_priv *priv)
 481{
 482        if (priv->is_read) {
 483                /* For SMBus block reads, length is received with first byte */
 484                if (((priv->cmd & 0x1c) == I801_BLOCK_DATA) &&
 485                    (priv->count == 0)) {
 486                        priv->len = inb_p(SMBHSTDAT0(priv));
 487                        if (priv->len < 1 || priv->len > I2C_SMBUS_BLOCK_MAX) {
 488                                dev_err(&priv->pci_dev->dev,
 489                                        "Illegal SMBus block read size %d\n",
 490                                        priv->len);
 491                                /* FIXME: Recover */
 492                                priv->len = I2C_SMBUS_BLOCK_MAX;
 493                        } else {
 494                                dev_dbg(&priv->pci_dev->dev,
 495                                        "SMBus block read size is %d\n",
 496                                        priv->len);
 497                        }
 498                        priv->data[-1] = priv->len;
 499                }
 500
 501                /* Read next byte */
 502                if (priv->count < priv->len)
 503                        priv->data[priv->count++] = inb(SMBBLKDAT(priv));
 504                else
 505                        dev_dbg(&priv->pci_dev->dev,
 506                                "Discarding extra byte on block read\n");
 507
 508                /* Set LAST_BYTE for last byte of read transaction */
 509                if (priv->count == priv->len - 1)
 510                        outb_p(priv->cmd | SMBHSTCNT_LAST_BYTE,
 511                               SMBHSTCNT(priv));
 512        } else if (priv->count < priv->len - 1) {
 513                /* Write next byte, except for IRQ after last byte */
 514                outb_p(priv->data[++priv->count], SMBBLKDAT(priv));
 515        }
 516
 517        /* Clear BYTE_DONE to continue with next byte */
 518        outb_p(SMBHSTSTS_BYTE_DONE, SMBHSTSTS(priv));
 519}
 520
 521/*
 522 * There are two kinds of interrupts:
 523 *
 524 * 1) i801 signals transaction completion with one of these interrupts:
 525 *      INTR - Success
 526 *      DEV_ERR - Invalid command, NAK or communication timeout
 527 *      BUS_ERR - SMI# transaction collision
 528 *      FAILED - transaction was canceled due to a KILL request
 529 *    When any of these occur, update ->status and wake up the waitq.
 530 *    ->status must be cleared before kicking off the next transaction.
 531 *
 532 * 2) For byte-by-byte (I2C read/write) transactions, one BYTE_DONE interrupt
 533 *    occurs for each byte of a byte-by-byte to prepare the next byte.
 534 */
 535static irqreturn_t i801_isr(int irq, void *dev_id)
 536{
 537        struct i801_priv *priv = dev_id;
 538        u16 pcists;
 539        u8 status;
 540
 541        /* Confirm this is our interrupt */
 542        pci_read_config_word(priv->pci_dev, SMBPCISTS, &pcists);
 543        if (!(pcists & SMBPCISTS_INTS))
 544                return IRQ_NONE;
 545
 546        status = inb_p(SMBHSTSTS(priv));
 547        if (status != 0x42)
 548                dev_dbg(&priv->pci_dev->dev, "irq: status = %02x\n", status);
 549
 550        if (status & SMBHSTSTS_BYTE_DONE)
 551                i801_isr_byte_done(priv);
 552
 553        /*
 554         * Clear irq sources and report transaction result.
 555         * ->status must be cleared before the next transaction is started.
 556         */
 557        status &= SMBHSTSTS_INTR | STATUS_ERROR_FLAGS;
 558        if (status) {
 559                outb_p(status, SMBHSTSTS(priv));
 560                priv->status |= status;
 561                wake_up(&priv->waitq);
 562        }
 563
 564        return IRQ_HANDLED;
 565}
 566
 567/*
 568 * For "byte-by-byte" block transactions:
 569 *   I2C write uses cmd=I801_BLOCK_DATA, I2C_EN=1
 570 *   I2C read uses cmd=I801_I2C_BLOCK_DATA
 571 */
 572static int i801_block_transaction_byte_by_byte(struct i801_priv *priv,
 573                                               union i2c_smbus_data *data,
 574                                               char read_write, int command,
 575                                               int hwpec)
 576{
 577        int i, len;
 578        int smbcmd;
 579        int status;
 580        int result;
 581        const struct i2c_adapter *adap = &priv->adapter;
 582
 583        result = i801_check_pre(priv);
 584        if (result < 0)
 585                return result;
 586
 587        len = data->block[0];
 588
 589        if (read_write == I2C_SMBUS_WRITE) {
 590                outb_p(len, SMBHSTDAT0(priv));
 591                outb_p(data->block[1], SMBBLKDAT(priv));
 592        }
 593
 594        if (command == I2C_SMBUS_I2C_BLOCK_DATA &&
 595            read_write == I2C_SMBUS_READ)
 596                smbcmd = I801_I2C_BLOCK_DATA;
 597        else
 598                smbcmd = I801_BLOCK_DATA;
 599
 600        if (priv->features & FEATURE_IRQ) {
 601                priv->is_read = (read_write == I2C_SMBUS_READ);
 602                if (len == 1 && priv->is_read)
 603                        smbcmd |= SMBHSTCNT_LAST_BYTE;
 604                priv->cmd = smbcmd | SMBHSTCNT_INTREN;
 605                priv->len = len;
 606                priv->count = 0;
 607                priv->data = &data->block[1];
 608
 609                outb_p(priv->cmd | SMBHSTCNT_START, SMBHSTCNT(priv));
 610                result = wait_event_timeout(priv->waitq,
 611                                            (status = priv->status),
 612                                            adap->timeout);
 613                if (!result) {
 614                        status = -ETIMEDOUT;
 615                        dev_warn(&priv->pci_dev->dev,
 616                                 "Timeout waiting for interrupt!\n");
 617                }
 618                priv->status = 0;
 619                return i801_check_post(priv, status);
 620        }
 621
 622        for (i = 1; i <= len; i++) {
 623                if (i == len && read_write == I2C_SMBUS_READ)
 624                        smbcmd |= SMBHSTCNT_LAST_BYTE;
 625                outb_p(smbcmd, SMBHSTCNT(priv));
 626
 627                if (i == 1)
 628                        outb_p(inb(SMBHSTCNT(priv)) | SMBHSTCNT_START,
 629                               SMBHSTCNT(priv));
 630
 631                status = i801_wait_byte_done(priv);
 632                if (status)
 633                        goto exit;
 634
 635                if (i == 1 && read_write == I2C_SMBUS_READ
 636                 && command != I2C_SMBUS_I2C_BLOCK_DATA) {
 637                        len = inb_p(SMBHSTDAT0(priv));
 638                        if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) {
 639                                dev_err(&priv->pci_dev->dev,
 640                                        "Illegal SMBus block read size %d\n",
 641                                        len);
 642                                /* Recover */
 643                                while (inb_p(SMBHSTSTS(priv)) &
 644                                       SMBHSTSTS_HOST_BUSY)
 645                                        outb_p(SMBHSTSTS_BYTE_DONE,
 646                                               SMBHSTSTS(priv));
 647                                outb_p(SMBHSTSTS_INTR, SMBHSTSTS(priv));
 648                                return -EPROTO;
 649                        }
 650                        data->block[0] = len;
 651                }
 652
 653                /* Retrieve/store value in SMBBLKDAT */
 654                if (read_write == I2C_SMBUS_READ)
 655                        data->block[i] = inb_p(SMBBLKDAT(priv));
 656                if (read_write == I2C_SMBUS_WRITE && i+1 <= len)
 657                        outb_p(data->block[i+1], SMBBLKDAT(priv));
 658
 659                /* signals SMBBLKDAT ready */
 660                outb_p(SMBHSTSTS_BYTE_DONE, SMBHSTSTS(priv));
 661        }
 662
 663        status = i801_wait_intr(priv);
 664exit:
 665        return i801_check_post(priv, status);
 666}
 667
 668static int i801_set_block_buffer_mode(struct i801_priv *priv)
 669{
 670        outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_E32B, SMBAUXCTL(priv));
 671        if ((inb_p(SMBAUXCTL(priv)) & SMBAUXCTL_E32B) == 0)
 672                return -EIO;
 673        return 0;
 674}
 675
 676/* Block transaction function */
 677static int i801_block_transaction(struct i801_priv *priv,
 678                                  union i2c_smbus_data *data, char read_write,
 679                                  int command, int hwpec)
 680{
 681        int result = 0;
 682        unsigned char hostc;
 683
 684        if (command == I2C_SMBUS_I2C_BLOCK_DATA) {
 685                if (read_write == I2C_SMBUS_WRITE) {
 686                        /* set I2C_EN bit in configuration register */
 687                        pci_read_config_byte(priv->pci_dev, SMBHSTCFG, &hostc);
 688                        pci_write_config_byte(priv->pci_dev, SMBHSTCFG,
 689                                              hostc | SMBHSTCFG_I2C_EN);
 690                } else if (!(priv->features & FEATURE_I2C_BLOCK_READ)) {
 691                        dev_err(&priv->pci_dev->dev,
 692                                "I2C block read is unsupported!\n");
 693                        return -EOPNOTSUPP;
 694                }
 695        }
 696
 697        if (read_write == I2C_SMBUS_WRITE
 698         || command == I2C_SMBUS_I2C_BLOCK_DATA) {
 699                if (data->block[0] < 1)
 700                        data->block[0] = 1;
 701                if (data->block[0] > I2C_SMBUS_BLOCK_MAX)
 702                        data->block[0] = I2C_SMBUS_BLOCK_MAX;
 703        } else {
 704                data->block[0] = 32;    /* max for SMBus block reads */
 705        }
 706
 707        /* Experience has shown that the block buffer can only be used for
 708           SMBus (not I2C) block transactions, even though the datasheet
 709           doesn't mention this limitation. */
 710        if ((priv->features & FEATURE_BLOCK_BUFFER)
 711         && command != I2C_SMBUS_I2C_BLOCK_DATA
 712         && i801_set_block_buffer_mode(priv) == 0)
 713                result = i801_block_transaction_by_block(priv, data,
 714                                                         read_write, hwpec);
 715        else
 716                result = i801_block_transaction_byte_by_byte(priv, data,
 717                                                             read_write,
 718                                                             command, hwpec);
 719
 720        if (command == I2C_SMBUS_I2C_BLOCK_DATA
 721         && read_write == I2C_SMBUS_WRITE) {
 722                /* restore saved configuration register value */
 723                pci_write_config_byte(priv->pci_dev, SMBHSTCFG, hostc);
 724        }
 725        return result;
 726}
 727
 728/* Return negative errno on error. */
 729static s32 i801_access(struct i2c_adapter *adap, u16 addr,
 730                       unsigned short flags, char read_write, u8 command,
 731                       int size, union i2c_smbus_data *data)
 732{
 733        int hwpec;
 734        int block = 0;
 735        int ret = 0, xact = 0;
 736        struct i801_priv *priv = i2c_get_adapdata(adap);
 737
 738        mutex_lock(&priv->acpi_lock);
 739        if (priv->acpi_reserved) {
 740                mutex_unlock(&priv->acpi_lock);
 741                return -EBUSY;
 742        }
 743
 744        pm_runtime_get_sync(&priv->pci_dev->dev);
 745
 746        hwpec = (priv->features & FEATURE_SMBUS_PEC) && (flags & I2C_CLIENT_PEC)
 747                && size != I2C_SMBUS_QUICK
 748                && size != I2C_SMBUS_I2C_BLOCK_DATA;
 749
 750        switch (size) {
 751        case I2C_SMBUS_QUICK:
 752                outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
 753                       SMBHSTADD(priv));
 754                xact = I801_QUICK;
 755                break;
 756        case I2C_SMBUS_BYTE:
 757                outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
 758                       SMBHSTADD(priv));
 759                if (read_write == I2C_SMBUS_WRITE)
 760                        outb_p(command, SMBHSTCMD(priv));
 761                xact = I801_BYTE;
 762                break;
 763        case I2C_SMBUS_BYTE_DATA:
 764                outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
 765                       SMBHSTADD(priv));
 766                outb_p(command, SMBHSTCMD(priv));
 767                if (read_write == I2C_SMBUS_WRITE)
 768                        outb_p(data->byte, SMBHSTDAT0(priv));
 769                xact = I801_BYTE_DATA;
 770                break;
 771        case I2C_SMBUS_WORD_DATA:
 772                outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
 773                       SMBHSTADD(priv));
 774                outb_p(command, SMBHSTCMD(priv));
 775                if (read_write == I2C_SMBUS_WRITE) {
 776                        outb_p(data->word & 0xff, SMBHSTDAT0(priv));
 777                        outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1(priv));
 778                }
 779                xact = I801_WORD_DATA;
 780                break;
 781        case I2C_SMBUS_BLOCK_DATA:
 782                outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
 783                       SMBHSTADD(priv));
 784                outb_p(command, SMBHSTCMD(priv));
 785                block = 1;
 786                break;
 787        case I2C_SMBUS_I2C_BLOCK_DATA:
 788                /* NB: page 240 of ICH5 datasheet shows that the R/#W
 789                 * bit should be cleared here, even when reading */
 790                outb_p((addr & 0x7f) << 1, SMBHSTADD(priv));
 791                if (read_write == I2C_SMBUS_READ) {
 792                        /* NB: page 240 of ICH5 datasheet also shows
 793                         * that DATA1 is the cmd field when reading */
 794                        outb_p(command, SMBHSTDAT1(priv));
 795                } else
 796                        outb_p(command, SMBHSTCMD(priv));
 797                block = 1;
 798                break;
 799        default:
 800                dev_err(&priv->pci_dev->dev, "Unsupported transaction %d\n",
 801                        size);
 802                ret = -EOPNOTSUPP;
 803                goto out;
 804        }
 805
 806        if (hwpec)      /* enable/disable hardware PEC */
 807                outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_CRC, SMBAUXCTL(priv));
 808        else
 809                outb_p(inb_p(SMBAUXCTL(priv)) & (~SMBAUXCTL_CRC),
 810                       SMBAUXCTL(priv));
 811
 812        if (block)
 813                ret = i801_block_transaction(priv, data, read_write, size,
 814                                             hwpec);
 815        else
 816                ret = i801_transaction(priv, xact);
 817
 818        /* Some BIOSes don't like it when PEC is enabled at reboot or resume
 819           time, so we forcibly disable it after every transaction. Turn off
 820           E32B for the same reason. */
 821        if (hwpec || block)
 822                outb_p(inb_p(SMBAUXCTL(priv)) &
 823                       ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), SMBAUXCTL(priv));
 824
 825        if (block)
 826                goto out;
 827        if (ret)
 828                goto out;
 829        if ((read_write == I2C_SMBUS_WRITE) || (xact == I801_QUICK))
 830                goto out;
 831
 832        switch (xact & 0x7f) {
 833        case I801_BYTE: /* Result put in SMBHSTDAT0 */
 834        case I801_BYTE_DATA:
 835                data->byte = inb_p(SMBHSTDAT0(priv));
 836                break;
 837        case I801_WORD_DATA:
 838                data->word = inb_p(SMBHSTDAT0(priv)) +
 839                             (inb_p(SMBHSTDAT1(priv)) << 8);
 840                break;
 841        }
 842
 843out:
 844        pm_runtime_mark_last_busy(&priv->pci_dev->dev);
 845        pm_runtime_put_autosuspend(&priv->pci_dev->dev);
 846        mutex_unlock(&priv->acpi_lock);
 847        return ret;
 848}
 849
 850
 851static u32 i801_func(struct i2c_adapter *adapter)
 852{
 853        struct i801_priv *priv = i2c_get_adapdata(adapter);
 854
 855        return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
 856               I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
 857               I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK |
 858               ((priv->features & FEATURE_SMBUS_PEC) ? I2C_FUNC_SMBUS_PEC : 0) |
 859               ((priv->features & FEATURE_I2C_BLOCK_READ) ?
 860                I2C_FUNC_SMBUS_READ_I2C_BLOCK : 0);
 861}
 862
 863static const struct i2c_algorithm smbus_algorithm = {
 864        .smbus_xfer     = i801_access,
 865        .functionality  = i801_func,
 866};
 867
 868static const struct pci_device_id i801_ids[] = {
 869        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_3) },
 870        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_3) },
 871        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_2) },
 872        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_3) },
 873        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_3) },
 874        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_3) },
 875        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_4) },
 876        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_16) },
 877        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_17) },
 878        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB2_17) },
 879        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_5) },
 880        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9_6) },
 881        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_EP80579_1) },
 882        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_4) },
 883        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_5) },
 884        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5_3400_SERIES_SMBUS) },
 885        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_COUGARPOINT_SMBUS) },
 886        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS) },
 887        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF0) },
 888        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF1) },
 889        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF2) },
 890        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_DH89XXCC_SMBUS) },
 891        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PANTHERPOINT_SMBUS) },
 892        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNXPOINT_SMBUS) },
 893        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_SMBUS) },
 894        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_AVOTON_SMBUS) },
 895        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS) },
 896        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS0) },
 897        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS1) },
 898        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS2) },
 899        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_COLETOCREEK_SMBUS) },
 900        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_GEMINILAKE_SMBUS) },
 901        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_SMBUS) },
 902        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BAYTRAIL_SMBUS) },
 903        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_SMBUS) },
 904        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_SMBUS) },
 905        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_DNV_SMBUS) },
 906        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LEWISBURG_SMBUS) },
 907        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LEWISBURG_SSKU_SMBUS) },
 908        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_KABYLAKE_PCH_H_SMBUS) },
 909        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CANNONLAKE_H_SMBUS) },
 910        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CANNONLAKE_LP_SMBUS) },
 911        { 0, }
 912};
 913
 914MODULE_DEVICE_TABLE(pci, i801_ids);
 915
 916#if defined CONFIG_X86 && defined CONFIG_DMI
 917static unsigned char apanel_addr;
 918
 919/* Scan the system ROM for the signature "FJKEYINF" */
 920static __init const void __iomem *bios_signature(const void __iomem *bios)
 921{
 922        ssize_t offset;
 923        const unsigned char signature[] = "FJKEYINF";
 924
 925        for (offset = 0; offset < 0x10000; offset += 0x10) {
 926                if (check_signature(bios + offset, signature,
 927                                    sizeof(signature)-1))
 928                        return bios + offset;
 929        }
 930        return NULL;
 931}
 932
 933static void __init input_apanel_init(void)
 934{
 935        void __iomem *bios;
 936        const void __iomem *p;
 937
 938        bios = ioremap(0xF0000, 0x10000); /* Can't fail */
 939        p = bios_signature(bios);
 940        if (p) {
 941                /* just use the first address */
 942                apanel_addr = readb(p + 8 + 3) >> 1;
 943        }
 944        iounmap(bios);
 945}
 946
 947struct dmi_onboard_device_info {
 948        const char *name;
 949        u8 type;
 950        unsigned short i2c_addr;
 951        const char *i2c_type;
 952};
 953
 954static const struct dmi_onboard_device_info dmi_devices[] = {
 955        { "Syleus", DMI_DEV_TYPE_OTHER, 0x73, "fscsyl" },
 956        { "Hermes", DMI_DEV_TYPE_OTHER, 0x73, "fscher" },
 957        { "Hades",  DMI_DEV_TYPE_OTHER, 0x73, "fschds" },
 958};
 959
 960static void dmi_check_onboard_device(u8 type, const char *name,
 961                                     struct i2c_adapter *adap)
 962{
 963        int i;
 964        struct i2c_board_info info;
 965
 966        for (i = 0; i < ARRAY_SIZE(dmi_devices); i++) {
 967                /* & ~0x80, ignore enabled/disabled bit */
 968                if ((type & ~0x80) != dmi_devices[i].type)
 969                        continue;
 970                if (strcasecmp(name, dmi_devices[i].name))
 971                        continue;
 972
 973                memset(&info, 0, sizeof(struct i2c_board_info));
 974                info.addr = dmi_devices[i].i2c_addr;
 975                strlcpy(info.type, dmi_devices[i].i2c_type, I2C_NAME_SIZE);
 976                i2c_new_device(adap, &info);
 977                break;
 978        }
 979}
 980
 981/* We use our own function to check for onboard devices instead of
 982   dmi_find_device() as some buggy BIOS's have the devices we are interested
 983   in marked as disabled */
 984static void dmi_check_onboard_devices(const struct dmi_header *dm, void *adap)
 985{
 986        int i, count;
 987
 988        if (dm->type != 10)
 989                return;
 990
 991        count = (dm->length - sizeof(struct dmi_header)) / 2;
 992        for (i = 0; i < count; i++) {
 993                const u8 *d = (char *)(dm + 1) + (i * 2);
 994                const char *name = ((char *) dm) + dm->length;
 995                u8 type = d[0];
 996                u8 s = d[1];
 997
 998                if (!s)
 999                        continue;
1000                s--;
1001                while (s > 0 && name[0]) {
1002                        name += strlen(name) + 1;
1003                        s--;
1004                }
1005                if (name[0] == 0) /* Bogus string reference */
1006                        continue;
1007
1008                dmi_check_onboard_device(type, name, adap);
1009        }
1010}
1011
1012/* Register optional slaves */
1013static void i801_probe_optional_slaves(struct i801_priv *priv)
1014{
1015        /* Only register slaves on main SMBus channel */
1016        if (priv->features & FEATURE_IDF)
1017                return;
1018
1019        if (apanel_addr) {
1020                struct i2c_board_info info;
1021
1022                memset(&info, 0, sizeof(struct i2c_board_info));
1023                info.addr = apanel_addr;
1024                strlcpy(info.type, "fujitsu_apanel", I2C_NAME_SIZE);
1025                i2c_new_device(&priv->adapter, &info);
1026        }
1027
1028        if (dmi_name_in_vendors("FUJITSU"))
1029                dmi_walk(dmi_check_onboard_devices, &priv->adapter);
1030}
1031#else
1032static void __init input_apanel_init(void) {}
1033static void i801_probe_optional_slaves(struct i801_priv *priv) {}
1034#endif  /* CONFIG_X86 && CONFIG_DMI */
1035
1036#if (defined CONFIG_I2C_MUX_GPIO || defined CONFIG_I2C_MUX_GPIO_MODULE) && \
1037                defined CONFIG_DMI
1038static struct i801_mux_config i801_mux_config_asus_z8_d12 = {
1039        .gpio_chip = "gpio_ich",
1040        .values = { 0x02, 0x03 },
1041        .n_values = 2,
1042        .classes = { I2C_CLASS_SPD, I2C_CLASS_SPD },
1043        .gpios = { 52, 53 },
1044        .n_gpios = 2,
1045};
1046
1047static struct i801_mux_config i801_mux_config_asus_z8_d18 = {
1048        .gpio_chip = "gpio_ich",
1049        .values = { 0x02, 0x03, 0x01 },
1050        .n_values = 3,
1051        .classes = { I2C_CLASS_SPD, I2C_CLASS_SPD, I2C_CLASS_SPD },
1052        .gpios = { 52, 53 },
1053        .n_gpios = 2,
1054};
1055
1056static const struct dmi_system_id mux_dmi_table[] = {
1057        {
1058                .matches = {
1059                        DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1060                        DMI_MATCH(DMI_BOARD_NAME, "Z8NA-D6(C)"),
1061                },
1062                .driver_data = &i801_mux_config_asus_z8_d12,
1063        },
1064        {
1065                .matches = {
1066                        DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1067                        DMI_MATCH(DMI_BOARD_NAME, "Z8P(N)E-D12(X)"),
1068                },
1069                .driver_data = &i801_mux_config_asus_z8_d12,
1070        },
1071        {
1072                .matches = {
1073                        DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1074                        DMI_MATCH(DMI_BOARD_NAME, "Z8NH-D12"),
1075                },
1076                .driver_data = &i801_mux_config_asus_z8_d12,
1077        },
1078        {
1079                .matches = {
1080                        DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1081                        DMI_MATCH(DMI_BOARD_NAME, "Z8PH-D12/IFB"),
1082                },
1083                .driver_data = &i801_mux_config_asus_z8_d12,
1084        },
1085        {
1086                .matches = {
1087                        DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1088                        DMI_MATCH(DMI_BOARD_NAME, "Z8NR-D12"),
1089                },
1090                .driver_data = &i801_mux_config_asus_z8_d12,
1091        },
1092        {
1093                .matches = {
1094                        DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1095                        DMI_MATCH(DMI_BOARD_NAME, "Z8P(N)H-D12"),
1096                },
1097                .driver_data = &i801_mux_config_asus_z8_d12,
1098        },
1099        {
1100                .matches = {
1101                        DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1102                        DMI_MATCH(DMI_BOARD_NAME, "Z8PG-D18"),
1103                },
1104                .driver_data = &i801_mux_config_asus_z8_d18,
1105        },
1106        {
1107                .matches = {
1108                        DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1109                        DMI_MATCH(DMI_BOARD_NAME, "Z8PE-D18"),
1110                },
1111                .driver_data = &i801_mux_config_asus_z8_d18,
1112        },
1113        {
1114                .matches = {
1115                        DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1116                        DMI_MATCH(DMI_BOARD_NAME, "Z8PS-D12"),
1117                },
1118                .driver_data = &i801_mux_config_asus_z8_d12,
1119        },
1120        { }
1121};
1122
1123/* Setup multiplexing if needed */
1124static int i801_add_mux(struct i801_priv *priv)
1125{
1126        struct device *dev = &priv->adapter.dev;
1127        const struct i801_mux_config *mux_config;
1128        struct i2c_mux_gpio_platform_data gpio_data;
1129        int err;
1130
1131        if (!priv->mux_drvdata)
1132                return 0;
1133        mux_config = priv->mux_drvdata;
1134
1135        /* Prepare the platform data */
1136        memset(&gpio_data, 0, sizeof(struct i2c_mux_gpio_platform_data));
1137        gpio_data.parent = priv->adapter.nr;
1138        gpio_data.values = mux_config->values;
1139        gpio_data.n_values = mux_config->n_values;
1140        gpio_data.classes = mux_config->classes;
1141        gpio_data.gpio_chip = mux_config->gpio_chip;
1142        gpio_data.gpios = mux_config->gpios;
1143        gpio_data.n_gpios = mux_config->n_gpios;
1144        gpio_data.idle = I2C_MUX_GPIO_NO_IDLE;
1145
1146        /* Register the mux device */
1147        priv->mux_pdev = platform_device_register_data(dev, "i2c-mux-gpio",
1148                                PLATFORM_DEVID_AUTO, &gpio_data,
1149                                sizeof(struct i2c_mux_gpio_platform_data));
1150        if (IS_ERR(priv->mux_pdev)) {
1151                err = PTR_ERR(priv->mux_pdev);
1152                priv->mux_pdev = NULL;
1153                dev_err(dev, "Failed to register i2c-mux-gpio device\n");
1154                return err;
1155        }
1156
1157        return 0;
1158}
1159
1160static void i801_del_mux(struct i801_priv *priv)
1161{
1162        if (priv->mux_pdev)
1163                platform_device_unregister(priv->mux_pdev);
1164}
1165
1166static unsigned int i801_get_adapter_class(struct i801_priv *priv)
1167{
1168        const struct dmi_system_id *id;
1169        const struct i801_mux_config *mux_config;
1170        unsigned int class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
1171        int i;
1172
1173        id = dmi_first_match(mux_dmi_table);
1174        if (id) {
1175                /* Remove branch classes from trunk */
1176                mux_config = id->driver_data;
1177                for (i = 0; i < mux_config->n_values; i++)
1178                        class &= ~mux_config->classes[i];
1179
1180                /* Remember for later */
1181                priv->mux_drvdata = mux_config;
1182        }
1183
1184        return class;
1185}
1186#else
1187static inline int i801_add_mux(struct i801_priv *priv) { return 0; }
1188static inline void i801_del_mux(struct i801_priv *priv) { }
1189
1190static inline unsigned int i801_get_adapter_class(struct i801_priv *priv)
1191{
1192        return I2C_CLASS_HWMON | I2C_CLASS_SPD;
1193}
1194#endif
1195
1196static const struct itco_wdt_platform_data tco_platform_data = {
1197        .name = "Intel PCH",
1198        .version = 4,
1199};
1200
1201static DEFINE_SPINLOCK(p2sb_spinlock);
1202
1203static void i801_add_tco(struct i801_priv *priv)
1204{
1205        struct pci_dev *pci_dev = priv->pci_dev;
1206        struct resource tco_res[3], *res;
1207        struct platform_device *pdev;
1208        unsigned int devfn;
1209        u32 tco_base, tco_ctl;
1210        u32 base_addr, ctrl_val;
1211        u64 base64_addr;
1212
1213        if (!(priv->features & FEATURE_TCO))
1214                return;
1215
1216        pci_read_config_dword(pci_dev, TCOBASE, &tco_base);
1217        pci_read_config_dword(pci_dev, TCOCTL, &tco_ctl);
1218        if (!(tco_ctl & TCOCTL_EN))
1219                return;
1220
1221        memset(tco_res, 0, sizeof(tco_res));
1222
1223        res = &tco_res[ICH_RES_IO_TCO];
1224        res->start = tco_base & ~1;
1225        res->end = res->start + 32 - 1;
1226        res->flags = IORESOURCE_IO;
1227
1228        /*
1229         * Power Management registers.
1230         */
1231        devfn = PCI_DEVFN(PCI_SLOT(pci_dev->devfn), 2);
1232        pci_bus_read_config_dword(pci_dev->bus, devfn, ACPIBASE, &base_addr);
1233
1234        res = &tco_res[ICH_RES_IO_SMI];
1235        res->start = (base_addr & ~1) + ACPIBASE_SMI_OFF;
1236        res->end = res->start + 3;
1237        res->flags = IORESOURCE_IO;
1238
1239        /*
1240         * Enable the ACPI I/O space.
1241         */
1242        pci_bus_read_config_dword(pci_dev->bus, devfn, ACPICTRL, &ctrl_val);
1243        ctrl_val |= ACPICTRL_EN;
1244        pci_bus_write_config_dword(pci_dev->bus, devfn, ACPICTRL, ctrl_val);
1245
1246        /*
1247         * We must access the NO_REBOOT bit over the Primary to Sideband
1248         * bridge (P2SB). The BIOS prevents the P2SB device from being
1249         * enumerated by the PCI subsystem, so we need to unhide/hide it
1250         * to lookup the P2SB BAR.
1251         */
1252        spin_lock(&p2sb_spinlock);
1253
1254        devfn = PCI_DEVFN(PCI_SLOT(pci_dev->devfn), 1);
1255
1256        /* Unhide the P2SB device */
1257        pci_bus_write_config_byte(pci_dev->bus, devfn, 0xe1, 0x0);
1258
1259        pci_bus_read_config_dword(pci_dev->bus, devfn, SBREG_BAR, &base_addr);
1260        base64_addr = base_addr & 0xfffffff0;
1261
1262        pci_bus_read_config_dword(pci_dev->bus, devfn, SBREG_BAR + 0x4, &base_addr);
1263        base64_addr |= (u64)base_addr << 32;
1264
1265        /* Hide the P2SB device */
1266        pci_bus_write_config_byte(pci_dev->bus, devfn, 0xe1, 0x1);
1267        spin_unlock(&p2sb_spinlock);
1268
1269        res = &tco_res[ICH_RES_MEM_OFF];
1270        res->start = (resource_size_t)base64_addr + SBREG_SMBCTRL;
1271        res->end = res->start + 3;
1272        res->flags = IORESOURCE_MEM;
1273
1274        pdev = platform_device_register_resndata(&pci_dev->dev, "iTCO_wdt", -1,
1275                                                 tco_res, 3, &tco_platform_data,
1276                                                 sizeof(tco_platform_data));
1277        if (IS_ERR(pdev)) {
1278                dev_warn(&pci_dev->dev, "failed to create iTCO device\n");
1279                return;
1280        }
1281
1282        priv->tco_pdev = pdev;
1283}
1284
1285#ifdef CONFIG_ACPI
1286static acpi_status
1287i801_acpi_io_handler(u32 function, acpi_physical_address address, u32 bits,
1288                     u64 *value, void *handler_context, void *region_context)
1289{
1290        struct i801_priv *priv = handler_context;
1291        struct pci_dev *pdev = priv->pci_dev;
1292        acpi_status status;
1293
1294        /*
1295         * Once BIOS AML code touches the OpRegion we warn and inhibit any
1296         * further access from the driver itself. This device is now owned
1297         * by the system firmware.
1298         */
1299        mutex_lock(&priv->acpi_lock);
1300
1301        if (!priv->acpi_reserved) {
1302                priv->acpi_reserved = true;
1303
1304                dev_warn(&pdev->dev, "BIOS is accessing SMBus registers\n");
1305                dev_warn(&pdev->dev, "Driver SMBus register access inhibited\n");
1306
1307                /*
1308                 * BIOS is accessing the host controller so prevent it from
1309                 * suspending automatically from now on.
1310                 */
1311                pm_runtime_get_sync(&pdev->dev);
1312        }
1313
1314        if ((function & ACPI_IO_MASK) == ACPI_READ)
1315                status = acpi_os_read_port(address, (u32 *)value, bits);
1316        else
1317                status = acpi_os_write_port(address, (u32)*value, bits);
1318
1319        mutex_unlock(&priv->acpi_lock);
1320
1321        return status;
1322}
1323
1324static int i801_acpi_probe(struct i801_priv *priv)
1325{
1326        struct acpi_device *adev;
1327        acpi_status status;
1328
1329        adev = ACPI_COMPANION(&priv->pci_dev->dev);
1330        if (adev) {
1331                status = acpi_install_address_space_handler(adev->handle,
1332                                ACPI_ADR_SPACE_SYSTEM_IO, i801_acpi_io_handler,
1333                                NULL, priv);
1334                if (ACPI_SUCCESS(status))
1335                        return 0;
1336        }
1337
1338        return acpi_check_resource_conflict(&priv->pci_dev->resource[SMBBAR]);
1339}
1340
1341static void i801_acpi_remove(struct i801_priv *priv)
1342{
1343        struct acpi_device *adev;
1344
1345        adev = ACPI_COMPANION(&priv->pci_dev->dev);
1346        if (!adev)
1347                return;
1348
1349        acpi_remove_address_space_handler(adev->handle,
1350                ACPI_ADR_SPACE_SYSTEM_IO, i801_acpi_io_handler);
1351
1352        mutex_lock(&priv->acpi_lock);
1353        if (priv->acpi_reserved)
1354                pm_runtime_put(&priv->pci_dev->dev);
1355        mutex_unlock(&priv->acpi_lock);
1356}
1357#else
1358static inline int i801_acpi_probe(struct i801_priv *priv) { return 0; }
1359static inline void i801_acpi_remove(struct i801_priv *priv) { }
1360#endif
1361
1362static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
1363{
1364        unsigned char temp;
1365        int err, i;
1366        struct i801_priv *priv;
1367
1368        priv = kzalloc(sizeof(*priv), GFP_KERNEL);
1369        if (!priv)
1370                return -ENOMEM;
1371
1372        i2c_set_adapdata(&priv->adapter, priv);
1373        priv->adapter.owner = THIS_MODULE;
1374        priv->adapter.class = i801_get_adapter_class(priv);
1375        priv->adapter.algo = &smbus_algorithm;
1376        priv->adapter.dev.parent = &dev->dev;
1377        device_rh_alloc(&priv->adapter.dev);
1378        ACPI_COMPANION_SET(&priv->adapter.dev, ACPI_COMPANION(&dev->dev));
1379        priv->adapter.retries = 3;
1380        mutex_init(&priv->acpi_lock);
1381
1382        priv->pci_dev = dev;
1383        switch (dev->device) {
1384        case PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_SMBUS:
1385        case PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_SMBUS:
1386        case PCI_DEVICE_ID_INTEL_CANNONLAKE_H_SMBUS:
1387        case PCI_DEVICE_ID_INTEL_CANNONLAKE_LP_SMBUS:
1388        case PCI_DEVICE_ID_INTEL_LEWISBURG_SMBUS:
1389        case PCI_DEVICE_ID_INTEL_LEWISBURG_SSKU_SMBUS:
1390        case PCI_DEVICE_ID_INTEL_DNV_SMBUS:
1391        case PCI_DEVICE_ID_INTEL_KABYLAKE_PCH_H_SMBUS:
1392                priv->features |= FEATURE_I2C_BLOCK_READ;
1393                priv->features |= FEATURE_IRQ;
1394                priv->features |= FEATURE_SMBUS_PEC;
1395                priv->features |= FEATURE_BLOCK_BUFFER;
1396                priv->features |= FEATURE_TCO;
1397                break;
1398
1399        case PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF0:
1400        case PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF1:
1401        case PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF2:
1402        case PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS0:
1403        case PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS1:
1404        case PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS2:
1405                priv->features |= FEATURE_IDF;
1406                /* fall through */
1407        default:
1408                priv->features |= FEATURE_I2C_BLOCK_READ;
1409                priv->features |= FEATURE_IRQ;
1410                /* fall through */
1411        case PCI_DEVICE_ID_INTEL_82801DB_3:
1412                priv->features |= FEATURE_SMBUS_PEC;
1413                priv->features |= FEATURE_BLOCK_BUFFER;
1414                /* fall through */
1415        case PCI_DEVICE_ID_INTEL_82801CA_3:
1416        case PCI_DEVICE_ID_INTEL_82801BA_2:
1417        case PCI_DEVICE_ID_INTEL_82801AB_3:
1418        case PCI_DEVICE_ID_INTEL_82801AA_3:
1419                break;
1420        }
1421
1422        /* Disable features on user request */
1423        for (i = 0; i < ARRAY_SIZE(i801_feature_names); i++) {
1424                if (priv->features & disable_features & (1 << i))
1425                        dev_notice(&dev->dev, "%s disabled by user\n",
1426                                   i801_feature_names[i]);
1427        }
1428        priv->features &= ~disable_features;
1429
1430        err = pci_enable_device(dev);
1431        if (err) {
1432                dev_err(&dev->dev, "Failed to enable SMBus PCI device (%d)\n",
1433                        err);
1434                goto exit;
1435        }
1436
1437        /* Determine the address of the SMBus area */
1438        priv->smba = pci_resource_start(dev, SMBBAR);
1439        if (!priv->smba) {
1440                dev_err(&dev->dev, "SMBus base address uninitialized, "
1441                        "upgrade BIOS\n");
1442                err = -ENODEV;
1443                goto exit;
1444        }
1445
1446        if (i801_acpi_probe(priv)) {
1447                err = -ENODEV;
1448                goto exit;
1449        }
1450
1451        err = pci_request_region(dev, SMBBAR, i801_driver.name);
1452        if (err) {
1453                dev_err(&dev->dev, "Failed to request SMBus region "
1454                        "0x%lx-0x%Lx\n", priv->smba,
1455                        (unsigned long long)pci_resource_end(dev, SMBBAR));
1456                i801_acpi_remove(priv);
1457                goto exit;
1458        }
1459
1460        pci_read_config_byte(priv->pci_dev, SMBHSTCFG, &temp);
1461        priv->original_hstcfg = temp;
1462        temp &= ~SMBHSTCFG_I2C_EN;      /* SMBus timing */
1463        if (!(temp & SMBHSTCFG_HST_EN)) {
1464                dev_info(&dev->dev, "Enabling SMBus device\n");
1465                temp |= SMBHSTCFG_HST_EN;
1466        }
1467        pci_write_config_byte(priv->pci_dev, SMBHSTCFG, temp);
1468
1469        if (temp & SMBHSTCFG_SMB_SMI_EN) {
1470                dev_dbg(&dev->dev, "SMBus using interrupt SMI#\n");
1471                /* Disable SMBus interrupt feature if SMBus using SMI# */
1472                priv->features &= ~FEATURE_IRQ;
1473        }
1474
1475        /* Clear special mode bits */
1476        if (priv->features & (FEATURE_SMBUS_PEC | FEATURE_BLOCK_BUFFER))
1477                outb_p(inb_p(SMBAUXCTL(priv)) &
1478                       ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), SMBAUXCTL(priv));
1479
1480        /* Default timeout in interrupt mode: 200 ms */
1481        priv->adapter.timeout = HZ / 5;
1482
1483        if (priv->features & FEATURE_IRQ) {
1484                u16 pcictl, pcists;
1485
1486                /* Complain if an interrupt is already pending */
1487                pci_read_config_word(priv->pci_dev, SMBPCISTS, &pcists);
1488                if (pcists & SMBPCISTS_INTS)
1489                        dev_warn(&dev->dev, "An interrupt is pending!\n");
1490
1491                /* Check if interrupts have been disabled */
1492                pci_read_config_word(priv->pci_dev, SMBPCICTL, &pcictl);
1493                if (pcictl & SMBPCICTL_INTDIS) {
1494                        dev_info(&dev->dev, "Interrupts are disabled\n");
1495                        priv->features &= ~FEATURE_IRQ;
1496                }
1497        }
1498
1499        if (priv->features & FEATURE_IRQ) {
1500                init_waitqueue_head(&priv->waitq);
1501
1502                err = request_irq(dev->irq, i801_isr, IRQF_SHARED,
1503                                  i801_driver.name, priv);
1504                if (err) {
1505                        dev_err(&dev->dev, "Failed to allocate irq %d: %d\n",
1506                                dev->irq, err);
1507                        priv->features &= ~FEATURE_IRQ;
1508                }
1509        }
1510        dev_info(&dev->dev, "SMBus using %s\n",
1511                 priv->features & FEATURE_IRQ ? "PCI interrupt" : "polling");
1512
1513        i801_add_tco(priv);
1514
1515        snprintf(priv->adapter.name, sizeof(priv->adapter.name),
1516                "SMBus I801 adapter at %04lx", priv->smba);
1517        err = i2c_add_adapter(&priv->adapter);
1518        if (err) {
1519                dev_err(&dev->dev, "Failed to add SMBus adapter\n");
1520                i801_acpi_remove(priv);
1521                goto exit_free_irq;
1522        }
1523
1524        i801_probe_optional_slaves(priv);
1525        /* We ignore errors - multiplexing is optional */
1526        i801_add_mux(priv);
1527
1528        pci_set_drvdata(dev, priv);
1529
1530        pm_runtime_set_autosuspend_delay(&dev->dev, 1000);
1531        pm_runtime_use_autosuspend(&dev->dev);
1532        pm_runtime_put_autosuspend(&dev->dev);
1533        pm_runtime_allow(&dev->dev);
1534
1535        return 0;
1536
1537exit_free_irq:
1538        if (priv->features & FEATURE_IRQ)
1539                free_irq(dev->irq, priv);
1540        pci_release_region(dev, SMBBAR);
1541exit:
1542        kfree(priv);
1543        return err;
1544}
1545
1546static void i801_remove(struct pci_dev *dev)
1547{
1548        struct i801_priv *priv = pci_get_drvdata(dev);
1549
1550        pm_runtime_forbid(&dev->dev);
1551        pm_runtime_get_noresume(&dev->dev);
1552
1553        i801_del_mux(priv);
1554        i2c_del_adapter(&priv->adapter);
1555        i801_acpi_remove(priv);
1556        pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg);
1557
1558        if (priv->features & FEATURE_IRQ)
1559                free_irq(dev->irq, priv);
1560        pci_release_region(dev, SMBBAR);
1561
1562        platform_device_unregister(priv->tco_pdev);
1563
1564        kfree(priv);
1565        /*
1566         * do not call pci_disable_device(dev) since it can cause hard hangs on
1567         * some systems during power-off (eg. Fujitsu-Siemens Lifebook E8010)
1568         */
1569}
1570
1571#ifdef CONFIG_PM
1572static int i801_suspend(struct pci_dev *dev, pm_message_t mesg)
1573{
1574        struct i801_priv *priv = pci_get_drvdata(dev);
1575
1576        pci_save_state(dev);
1577        pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg);
1578        pci_set_power_state(dev, pci_choose_state(dev, mesg));
1579        return 0;
1580}
1581
1582static int i801_resume(struct pci_dev *dev)
1583{
1584        pci_set_power_state(dev, PCI_D0);
1585        pci_restore_state(dev);
1586        return pci_enable_device(dev);
1587}
1588#else
1589#define i801_suspend NULL
1590#define i801_resume NULL
1591#endif
1592
1593static struct pci_driver i801_driver = {
1594        .name           = "i801_smbus",
1595        .id_table       = i801_ids,
1596        .probe          = i801_probe,
1597        .remove         = i801_remove,
1598        .suspend        = i801_suspend,
1599        .resume         = i801_resume,
1600};
1601
1602static int __init i2c_i801_init(void)
1603{
1604        if (dmi_name_in_vendors("FUJITSU"))
1605                input_apanel_init();
1606        return pci_register_driver(&i801_driver);
1607}
1608
1609static void __exit i2c_i801_exit(void)
1610{
1611        pci_unregister_driver(&i801_driver);
1612}
1613
1614MODULE_AUTHOR("Mark D. Studebaker <mdsxyz123@yahoo.com>, "
1615              "Jean Delvare <khali@linux-fr.org>");
1616MODULE_DESCRIPTION("I801 SMBus driver");
1617MODULE_LICENSE("GPL");
1618
1619module_init(i2c_i801_init);
1620module_exit(i2c_i801_exit);
1621