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