70 #include <linux/module.h>
71 #include <linux/pci.h>
72 #include <linux/kernel.h>
73 #include <linux/stddef.h>
77 #include <linux/i2c.h>
81 #include <linux/slab.h>
82 #include <linux/wait.h>
85 #if (defined CONFIG_I2C_MUX_GPIO || defined CONFIG_I2C_MUX_GPIO_MODULE) && \
93 #define SMBHSTSTS(p) (0 + (p)->smba)
94 #define SMBHSTCNT(p) (2 + (p)->smba)
95 #define SMBHSTCMD(p) (3 + (p)->smba)
96 #define SMBHSTADD(p) (4 + (p)->smba)
97 #define SMBHSTDAT0(p) (5 + (p)->smba)
98 #define SMBHSTDAT1(p) (6 + (p)->smba)
99 #define SMBBLKDAT(p) (7 + (p)->smba)
100 #define SMBPEC(p) (8 + (p)->smba)
101 #define SMBAUXSTS(p) (12 + (p)->smba)
102 #define SMBAUXCTL(p) (13 + (p)->smba)
106 #define SMBPCISTS 0x006
107 #define SMBHSTCFG 0x040
110 #define SMBPCISTS_INTS 0x08
113 #define SMBHSTCFG_HST_EN 1
114 #define SMBHSTCFG_SMB_SMI_EN 2
115 #define SMBHSTCFG_I2C_EN 4
118 #define SMBAUXCTL_CRC 1
119 #define SMBAUXCTL_E32B 2
122 #define MAX_RETRIES 400
125 #define I801_QUICK 0x00
126 #define I801_BYTE 0x04
127 #define I801_BYTE_DATA 0x08
128 #define I801_WORD_DATA 0x0C
129 #define I801_PROC_CALL 0x10
130 #define I801_BLOCK_DATA 0x14
131 #define I801_I2C_BLOCK_DATA 0x18
134 #define SMBHSTCNT_INTREN 0x01
135 #define SMBHSTCNT_KILL 0x02
136 #define SMBHSTCNT_LAST_BYTE 0x20
137 #define SMBHSTCNT_START 0x40
138 #define SMBHSTCNT_PEC_EN 0x80
141 #define SMBHSTSTS_BYTE_DONE 0x80
142 #define SMBHSTSTS_INUSE_STS 0x40
143 #define SMBHSTSTS_SMBALERT_STS 0x20
144 #define SMBHSTSTS_FAILED 0x10
145 #define SMBHSTSTS_BUS_ERR 0x08
146 #define SMBHSTSTS_DEV_ERR 0x04
147 #define SMBHSTSTS_INTR 0x02
148 #define SMBHSTSTS_HOST_BUSY 0x01
150 #define STATUS_ERROR_FLAGS (SMBHSTSTS_FAILED | SMBHSTSTS_BUS_ERR | \
153 #define STATUS_FLAGS (SMBHSTSTS_BYTE_DONE | SMBHSTSTS_INTR | \
157 #define PCI_DEVICE_ID_INTEL_COUGARPOINT_SMBUS 0x1c22
158 #define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS 0x1d22
160 #define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF0 0x1d70
161 #define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF1 0x1d71
162 #define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF2 0x1d72
163 #define PCI_DEVICE_ID_INTEL_PANTHERPOINT_SMBUS 0x1e22
164 #define PCI_DEVICE_ID_INTEL_DH89XXCC_SMBUS 0x2330
165 #define PCI_DEVICE_ID_INTEL_5_3400_SERIES_SMBUS 0x3b30
166 #define PCI_DEVICE_ID_INTEL_LYNXPOINT_SMBUS 0x8c22
167 #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_SMBUS 0x9c22
196 #if (defined CONFIG_I2C_MUX_GPIO || defined CONFIG_I2C_MUX_GPIO_MODULE) && \
205 #define FEATURE_SMBUS_PEC (1 << 0)
206 #define FEATURE_BLOCK_BUFFER (1 << 1)
207 #define FEATURE_BLOCK_PROC (1 << 2)
208 #define FEATURE_I2C_BLOCK_READ (1 << 3)
209 #define FEATURE_IRQ (1 << 4)
211 #define FEATURE_IDF (1 << 15)
213 static const char *i801_feature_names[] = {
216 "Block process call",
221 static unsigned int disable_features;
245 "Failed clearing status flags (%02x)\n",
259 static int i801_check_post(
struct i801_priv *priv,
int status)
272 dev_dbg(&priv->
pci_dev->dev,
"Terminating the current operation\n");
281 if ((status & SMBHSTSTS_HOST_BUSY) ||
284 "Failed terminating the transaction\n");
289 if (status & SMBHSTSTS_FAILED) {
309 static int i801_wait_intr(
struct i801_priv *priv)
318 }
while (((status & SMBHSTSTS_HOST_BUSY) ||
330 static int i801_wait_byte_done(
struct i801_priv *priv)
349 static int i801_transaction(
struct i801_priv *priv,
int xact)
354 result = i801_check_pre(priv);
363 return i801_check_post(priv, status);
370 status = i801_wait_intr(priv);
371 return i801_check_post(priv, status);
374 static int i801_block_transaction_by_block(
struct i801_priv *priv,
376 char read_write,
int hwpec)
385 len = data->
block[0];
387 for (i = 0; i < len; i++)
401 data->
block[0] = len;
402 for (i = 0; i < len; i++)
408 static void i801_isr_byte_done(
struct i801_priv *priv)
413 (priv->
count == 0)) {
415 if (priv->
len < 1 || priv->
len > I2C_SMBUS_BLOCK_MAX) {
417 "Illegal SMBus block read size %d\n",
423 "SMBus block read size is %d\n",
434 "Discarding extra byte on block read\n");
440 }
else if (priv->
count < priv->
len - 1) {
479 i801_isr_byte_done(priv);
500 static int i801_block_transaction_byte_by_byte(
struct i801_priv *priv,
510 result = i801_check_pre(priv);
514 len = data->
block[0];
539 return i801_check_post(priv, status);
542 for (i = 1; i <=
len; i++) {
551 status = i801_wait_byte_done(priv);
558 if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) {
560 "Illegal SMBus block read size %d\n",
565 outb_p(SMBHSTSTS_BYTE_DONE,
583 status = i801_wait_intr(priv);
585 return i801_check_post(priv, status);
588 static int i801_set_block_buffer_mode(
struct i801_priv *priv)
597 static int i801_block_transaction(
struct i801_priv *priv,
599 int command,
int hwpec)
612 "I2C block read is unsupported!\n");
619 if (data->
block[0] < 1)
621 if (data->
block[0] > I2C_SMBUS_BLOCK_MAX)
632 && i801_set_block_buffer_mode(priv) == 0)
633 result = i801_block_transaction_by_block(priv, data,
636 result = i801_block_transaction_byte_by_byte(priv, data,
650 unsigned short flags,
char read_write,
u8 command,
656 struct i801_priv *priv = i2c_get_adapdata(adap);
664 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
669 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
676 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
684 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
694 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
724 ret = i801_block_transaction(priv, data, read_write, size,
727 ret = i801_transaction(priv, xact);
743 switch (xact & 0x7f) {
759 struct i801_priv *priv = i2c_get_adapdata(adapter);
770 .smbus_xfer = i801_access,
771 .functionality = i801_func,
805 #if defined CONFIG_X86 && defined CONFIG_DMI
806 static unsigned char apanel_addr;
812 const unsigned char signature[] =
"FJKEYINF";
814 for (offset = 0; offset < 0x10000; offset += 0x10) {
816 sizeof(signature)-1))
822 static void __init input_apanel_init(
void)
827 bios =
ioremap(0xF0000, 0x10000);
828 p = bios_signature(bios);
831 apanel_addr =
readb(p + 8 + 3) >> 1;
836 struct dmi_onboard_device_info {
839 unsigned short i2c_addr;
843 static struct dmi_onboard_device_info
__devinitdata dmi_devices[] = {
855 for (i = 0; i <
ARRAY_SIZE(dmi_devices); i++) {
857 if ((type & ~0x80) != dmi_devices[
i].type)
863 info.addr = dmi_devices[
i].i2c_addr;
882 for (i = 0; i <
count; i++) {
883 const u8 *
d = (
char *)(dm + 1) + (i * 2);
884 const char *name = ((
char *) dm) + dm->
length;
891 while (s > 0 && name[0]) {
898 dmi_check_onboard_device(type, name, adap);
913 info.addr = apanel_addr;
922 static void __init input_apanel_init(
void) {}
926 #if (defined CONFIG_I2C_MUX_GPIO || defined CONFIG_I2C_MUX_GPIO_MODULE) && \
930 .values = { 0x02, 0x03 },
939 .values = { 0x02, 0x03, 0x01 },
952 .driver_data = &i801_mux_config_asus_z8_d12,
959 .driver_data = &i801_mux_config_asus_z8_d12,
966 .driver_data = &i801_mux_config_asus_z8_d12,
973 .driver_data = &i801_mux_config_asus_z8_d12,
980 .driver_data = &i801_mux_config_asus_z8_d12,
987 .driver_data = &i801_mux_config_asus_z8_d12,
994 .driver_data = &i801_mux_config_asus_z8_d18,
1001 .driver_data = &i801_mux_config_asus_z8_d18,
1008 .driver_data = &i801_mux_config_asus_z8_d12,
1021 if (!priv->mux_drvdata)
1023 mux_config = priv->mux_drvdata;
1027 gpio_data.parent = priv->
adapter.nr;
1028 gpio_data.values = mux_config->
values;
1029 gpio_data.n_values = mux_config->
n_values;
1030 gpio_data.classes = mux_config->
classes;
1031 gpio_data.gpio_chip = mux_config->
gpio_chip;
1032 gpio_data.gpios = mux_config->
gpios;
1033 gpio_data.n_gpios = mux_config->
n_gpios;
1037 priv->mux_pdev = platform_device_register_data(dev,
"i2c-mux-gpio",
1040 if (IS_ERR(priv->mux_pdev)) {
1041 err = PTR_ERR(priv->mux_pdev);
1042 priv->mux_pdev =
NULL;
1043 dev_err(dev,
"Failed to register i2c-mux-gpio device\n");
1066 mux_config =
id->driver_data;
1067 for (i = 0; i < mux_config->
n_values; i++)
1068 class &= ~mux_config->
classes[i];
1071 priv->mux_drvdata = mux_config;
1077 static inline int i801_add_mux(
struct i801_priv *priv) {
return 0; }
1078 static inline void i801_del_mux(
struct i801_priv *priv) { }
1080 static inline unsigned int i801_get_adapter_class(
struct i801_priv *priv)
1097 i2c_set_adapdata(&priv->
adapter, priv);
1099 priv->
adapter.class = i801_get_adapter_class(priv);
1100 priv->
adapter.algo = &smbus_algorithm;
1134 for (i = 0; i <
ARRAY_SIZE(i801_feature_names); i++) {
1135 if (priv->
features & disable_features & (1 << i))
1136 dev_notice(&dev->
dev,
"%s disabled by user\n",
1137 i801_feature_names[i]);
1139 priv->
features &= ~disable_features;
1143 dev_err(&dev->
dev,
"Failed to enable SMBus PCI device (%d)\n",
1151 dev_err(&dev->
dev,
"SMBus base address uninitialized, "
1165 dev_err(&dev->
dev,
"Failed to request SMBus region "
1166 "0x%lx-0x%Lx\n", priv->
smba,
1181 dev_dbg(&dev->
dev,
"SMBus using interrupt SMI#\n");
1195 i801_driver.name, priv);
1197 dev_err(&dev->
dev,
"Failed to allocate irq %d: %d\n",
1201 dev_info(&dev->
dev,
"SMBus using PCI Interrupt\n");
1211 "SMBus I801 adapter at %04lx", priv->
smba);
1214 dev_err(&dev->
dev,
"Failed to add SMBus adapter\n");
1218 i801_probe_optional_slaves(priv);
1222 pci_set_drvdata(dev, priv);
1238 struct i801_priv *priv = pci_get_drvdata(dev);
1248 pci_set_drvdata(dev,
NULL);
1259 struct i801_priv *priv = pci_get_drvdata(dev);
1274 #define i801_suspend NULL
1275 #define i801_resume NULL
1279 .name =
"i801_smbus",
1280 .id_table = i801_ids,
1281 .probe = i801_probe,
1287 static int __init i2c_i801_init(
void)
1290 input_apanel_init();
1291 return pci_register_driver(&i801_driver);
1294 static void __exit i2c_i801_exit(
void)