blob: 4f2d78868281ef7eda0e11bc03518f10089a2aff [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
LABBE Corentin3fea5df2011-07-25 17:49:42 +02002 * Copyright (c) 2000 Frodo Looijaard <frodol@dds.nl>,
3 * Philip Edelbrock <phil@netroedge.com>,
4 * Mark D. Studebaker <mdsxyz123@yahoo.com>,
5 * Dan Eaton <dan.eaton@rocketlogix.com> and
6 * Stephen Rousset <stephen.rousset@rocketlogix.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
Linus Torvalds1da177e2005-04-16 15:20:36 -070017*/
18
19/*
20 This is the driver for the SMB Host controller on
21 Acer Labs Inc. (ALI) M1535 South Bridge.
22
23 The M1535 is a South bridge for portable systems.
24 It is very similar to the M15x3 South bridges also produced
25 by Acer Labs Inc. Some of the registers within the part
26 have moved and some have been redefined slightly. Additionally,
27 the sequencing of the SMBus transactions has been modified
28 to be more consistent with the sequencing recommended by
29 the manufacturer and observed through testing. These
30 changes are reflected in this driver and can be identified
31 by comparing this driver to the i2c-ali15x3 driver.
32 For an overview of these chips see http://www.acerlabs.com
33
34 The SMB controller is part of the 7101 device, which is an
35 ACPI-compliant Power Management Unit (PMU).
36
37 The whole 7101 device has to be enabled for the SMB to work.
38 You can't just enable the SMB alone.
39 The SMB and the ACPI have separate I/O spaces.
40 We make sure that the SMB is enabled. We leave the ACPI alone.
41
42 This driver controls the SMB Host only.
43
44 This driver does not use interrupts.
45*/
46
47
48/* Note: we assume there can only be one ALI1535, with one SMBus interface */
49
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#include <linux/module.h>
51#include <linux/pci.h>
52#include <linux/kernel.h>
53#include <linux/stddef.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#include <linux/delay.h>
55#include <linux/ioport.h>
56#include <linux/i2c.h>
Jean Delvare54fb4a052008-07-14 22:38:33 +020057#include <linux/acpi.h>
H Hartley Sweeten21782182010-05-21 18:41:01 +020058#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60
61/* ALI1535 SMBus address offsets */
62#define SMBHSTSTS (0 + ali1535_smba)
63#define SMBHSTTYP (1 + ali1535_smba)
64#define SMBHSTPORT (2 + ali1535_smba)
65#define SMBHSTCMD (7 + ali1535_smba)
66#define SMBHSTADD (3 + ali1535_smba)
67#define SMBHSTDAT0 (4 + ali1535_smba)
68#define SMBHSTDAT1 (5 + ali1535_smba)
69#define SMBBLKDAT (6 + ali1535_smba)
70
71/* PCI Address Constants */
72#define SMBCOM 0x004
73#define SMBREV 0x008
74#define SMBCFG 0x0D1
75#define SMBBA 0x0E2
76#define SMBHSTCFG 0x0F0
77#define SMBCLK 0x0F2
78
79/* Other settings */
80#define MAX_TIMEOUT 500 /* times 1/100 sec */
81#define ALI1535_SMB_IOSIZE 32
82
83#define ALI1535_SMB_DEFAULTBASE 0x8040
84
85/* ALI1535 address lock bits */
86#define ALI1535_LOCK 0x06 /* dwe */
87
88/* ALI1535 command constants */
89#define ALI1535_QUICK 0x00
90#define ALI1535_BYTE 0x10
91#define ALI1535_BYTE_DATA 0x20
92#define ALI1535_WORD_DATA 0x30
93#define ALI1535_BLOCK_DATA 0x40
94#define ALI1535_I2C_READ 0x60
95
96#define ALI1535_DEV10B_EN 0x80 /* Enable 10-bit addressing in */
97 /* I2C read */
98#define ALI1535_T_OUT 0x08 /* Time-out Command (write) */
99#define ALI1535_A_HIGH_BIT9 0x08 /* Bit 9 of 10-bit address in */
100 /* Alert-Response-Address */
101 /* (read) */
102#define ALI1535_KILL 0x04 /* Kill Command (write) */
103#define ALI1535_A_HIGH_BIT8 0x04 /* Bit 8 of 10-bit address in */
104 /* Alert-Response-Address */
105 /* (read) */
106
107#define ALI1535_D_HI_MASK 0x03 /* Mask for isolating bits 9-8 */
108 /* of 10-bit address in I2C */
109 /* Read Command */
110
111/* ALI1535 status register bits */
112#define ALI1535_STS_IDLE 0x04
113#define ALI1535_STS_BUSY 0x08 /* host busy */
114#define ALI1535_STS_DONE 0x10 /* transaction complete */
115#define ALI1535_STS_DEV 0x20 /* device error */
116#define ALI1535_STS_BUSERR 0x40 /* bus error */
117#define ALI1535_STS_FAIL 0x80 /* failed bus transaction */
118#define ALI1535_STS_ERR 0xE0 /* all the bad error bits */
119
120#define ALI1535_BLOCK_CLR 0x04 /* reset block data index */
121
122/* ALI1535 device address register bits */
123#define ALI1535_RD_ADDR 0x01 /* Read/Write Bit in Device */
124 /* Address field */
125 /* -> Write = 0 */
126 /* -> Read = 1 */
127#define ALI1535_SMBIO_EN 0x04 /* SMB I/O Space enable */
128
Jean Delvared6072f82005-09-25 16:37:04 +0200129static struct pci_driver ali1535_driver;
corentin.labbe65a2d742012-01-12 20:32:04 +0100130static unsigned long ali1535_smba;
131static unsigned short ali1535_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133/* Detect whether a ALI1535 can be found, and initialize it, where necessary.
134 Note the differences between kernels with the old PCI BIOS interface and
135 newer kernels with the real PCI interface. In compat.h some things are
136 defined to make the transition easier. */
Bill Pemberton0b255e92012-11-27 15:59:38 -0500137static int ali1535_setup(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138{
Jean Delvare7c1f59c2012-01-12 20:32:03 +0100139 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 unsigned char temp;
141
142 /* Check the following things:
143 - SMB I/O address is initialized
144 - Device is enabled
145 - We can use the addresses
146 */
147
corentin.labbe65a2d742012-01-12 20:32:04 +0100148 retval = pci_enable_device(dev);
149 if (retval) {
150 dev_err(&dev->dev, "ALI1535_smb can't enable device\n");
151 goto exit;
152 }
153
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 /* Determine the address of the SMBus area */
corentin.labbe65a2d742012-01-12 20:32:04 +0100155 pci_read_config_word(dev, SMBBA, &ali1535_offset);
156 dev_dbg(&dev->dev, "ALI1535_smb is at offset 0x%04x\n", ali1535_offset);
157 ali1535_offset &= (0xffff & ~(ALI1535_SMB_IOSIZE - 1));
158 if (ali1535_offset == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 dev_warn(&dev->dev,
160 "ALI1535_smb region uninitialized - upgrade BIOS?\n");
Jean Delvare7c1f59c2012-01-12 20:32:03 +0100161 retval = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 goto exit;
163 }
164
corentin.labbe65a2d742012-01-12 20:32:04 +0100165 if (pci_resource_flags(dev, 0) & IORESOURCE_IO)
166 ali1535_smba = pci_resource_start(dev, 0) + ali1535_offset;
167 else
168 ali1535_smba = ali1535_offset;
169
Jean Delvare54fb4a052008-07-14 22:38:33 +0200170 retval = acpi_check_region(ali1535_smba, ALI1535_SMB_IOSIZE,
171 ali1535_driver.name);
172 if (retval)
173 goto exit;
174
Jean Delvared6072f82005-09-25 16:37:04 +0200175 if (!request_region(ali1535_smba, ALI1535_SMB_IOSIZE,
176 ali1535_driver.name)) {
corentin.labbe65a2d742012-01-12 20:32:04 +0100177 dev_err(&dev->dev, "ALI1535_smb region 0x%lx already in use!\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 ali1535_smba);
Jean Delvare7c1f59c2012-01-12 20:32:03 +0100179 retval = -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 goto exit;
181 }
182
183 /* check if whole device is enabled */
184 pci_read_config_byte(dev, SMBCFG, &temp);
185 if ((temp & ALI1535_SMBIO_EN) == 0) {
186 dev_err(&dev->dev, "SMB device not enabled - upgrade BIOS?\n");
Jean Delvare7c1f59c2012-01-12 20:32:03 +0100187 retval = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 goto exit_free;
189 }
190
191 /* Is SMB Host controller enabled? */
192 pci_read_config_byte(dev, SMBHSTCFG, &temp);
193 if ((temp & 1) == 0) {
194 dev_err(&dev->dev, "SMBus controller not enabled - upgrade BIOS?\n");
Jean Delvare7c1f59c2012-01-12 20:32:03 +0100195 retval = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 goto exit_free;
197 }
198
199 /* set SMB clock to 74KHz as recommended in data sheet */
200 pci_write_config_byte(dev, SMBCLK, 0x20);
201
202 /*
203 The interrupt routing for SMB is set up in register 0x77 in the
204 1533 ISA Bridge device, NOT in the 7101 device.
205 Don't bother with finding the 1533 device and reading the register.
206 if ((....... & 0x0F) == 1)
207 dev_dbg(&dev->dev, "ALI1535 using Interrupt 9 for SMBus.\n");
208 */
209 pci_read_config_byte(dev, SMBREV, &temp);
210 dev_dbg(&dev->dev, "SMBREV = 0x%X\n", temp);
corentin.labbe65a2d742012-01-12 20:32:04 +0100211 dev_dbg(&dev->dev, "ALI1535_smba = 0x%lx\n", ali1535_smba);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
Jean Delvare7c1f59c2012-01-12 20:32:03 +0100213 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
215exit_free:
216 release_region(ali1535_smba, ALI1535_SMB_IOSIZE);
Jean Delvare7c1f59c2012-01-12 20:32:03 +0100217exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 return retval;
219}
220
221static int ali1535_transaction(struct i2c_adapter *adap)
222{
223 int temp;
224 int result = 0;
225 int timeout = 0;
226
227 dev_dbg(&adap->dev, "Transaction (pre): STS=%02x, TYP=%02x, "
228 "CMD=%02x, ADD=%02x, DAT0=%02x, DAT1=%02x\n",
229 inb_p(SMBHSTSTS), inb_p(SMBHSTTYP), inb_p(SMBHSTCMD),
230 inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), inb_p(SMBHSTDAT1));
231
232 /* get status */
233 temp = inb_p(SMBHSTSTS);
234
235 /* Make sure the SMBus host is ready to start transmitting */
236 /* Check the busy bit first */
237 if (temp & ALI1535_STS_BUSY) {
238 /* If the host controller is still busy, it may have timed out
239 * in the previous transaction, resulting in a "SMBus Timeout"
240 * printk. I've tried the following to reset a stuck busy bit.
241 * 1. Reset the controller with an KILL command. (this
242 * doesn't seem to clear the controller if an external
243 * device is hung)
244 * 2. Reset the controller and the other SMBus devices with a
245 * T_OUT command. (this clears the host busy bit if an
246 * external device is hung, but it comes back upon a new
247 * access to a device)
248 * 3. Disable and reenable the controller in SMBHSTCFG. Worst
249 * case, nothing seems to work except power reset.
250 */
251
252 /* Try resetting entire SMB bus, including other devices - This
253 * may not work either - it clears the BUSY bit but then the
254 * BUSY bit may come back on when you try and use the chip
255 * again. If that's the case you are stuck.
256 */
257 dev_info(&adap->dev,
258 "Resetting entire SMB Bus to clear busy condition (%02x)\n",
259 temp);
260 outb_p(ALI1535_T_OUT, SMBHSTTYP);
261 temp = inb_p(SMBHSTSTS);
262 }
263
264 /* now check the error bits and the busy bit */
265 if (temp & (ALI1535_STS_ERR | ALI1535_STS_BUSY)) {
266 /* do a clear-on-write */
267 outb_p(0xFF, SMBHSTSTS);
LABBE Corentin3fea5df2011-07-25 17:49:42 +0200268 temp = inb_p(SMBHSTSTS);
269 if (temp & (ALI1535_STS_ERR | ALI1535_STS_BUSY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 /* This is probably going to be correctable only by a
271 * power reset as one of the bits now appears to be
272 * stuck */
273 /* This may be a bus or device with electrical problems. */
274 dev_err(&adap->dev,
275 "SMBus reset failed! (0x%02x) - controller or "
276 "device on bus is probably hung\n", temp);
David Brownell97140342008-07-14 22:38:25 +0200277 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 }
279 } else {
280 /* check and clear done bit */
LABBE Corentin3fea5df2011-07-25 17:49:42 +0200281 if (temp & ALI1535_STS_DONE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 outb_p(temp, SMBHSTSTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 }
284
285 /* start the transaction by writing anything to the start register */
286 outb_p(0xFF, SMBHSTPORT);
287
288 /* We will always wait for a fraction of a second! */
289 timeout = 0;
290 do {
LABBE Corentin3fea5df2011-07-25 17:49:42 +0200291 usleep_range(1000, 2000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 temp = inb_p(SMBHSTSTS);
293 } while (((temp & ALI1535_STS_BUSY) && !(temp & ALI1535_STS_IDLE))
294 && (timeout++ < MAX_TIMEOUT));
295
296 /* If the SMBus is still busy, we give up */
Roel Kluin4ccc28f2009-05-05 08:39:24 +0200297 if (timeout > MAX_TIMEOUT) {
David Brownell97140342008-07-14 22:38:25 +0200298 result = -ETIMEDOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 dev_err(&adap->dev, "SMBus Timeout!\n");
300 }
301
302 if (temp & ALI1535_STS_FAIL) {
David Brownell97140342008-07-14 22:38:25 +0200303 result = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 dev_dbg(&adap->dev, "Error: Failed bus transaction\n");
305 }
306
307 /* Unfortunately the ALI SMB controller maps "no response" and "bus
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300308 * collision" into a single bit. No response is the usual case so don't
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 * do a printk. This means that bus collisions go unreported.
310 */
311 if (temp & ALI1535_STS_BUSERR) {
David Brownell97140342008-07-14 22:38:25 +0200312 result = -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 dev_dbg(&adap->dev,
314 "Error: no response or bus collision ADD=%02x\n",
315 inb_p(SMBHSTADD));
316 }
317
318 /* haven't ever seen this */
319 if (temp & ALI1535_STS_DEV) {
David Brownell97140342008-07-14 22:38:25 +0200320 result = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 dev_err(&adap->dev, "Error: device error\n");
322 }
323
324 /* check to see if the "command complete" indication is set */
325 if (!(temp & ALI1535_STS_DONE)) {
David Brownell97140342008-07-14 22:38:25 +0200326 result = -ETIMEDOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 dev_err(&adap->dev, "Error: command never completed\n");
328 }
329
330 dev_dbg(&adap->dev, "Transaction (post): STS=%02x, TYP=%02x, "
331 "CMD=%02x, ADD=%02x, DAT0=%02x, DAT1=%02x\n",
332 inb_p(SMBHSTSTS), inb_p(SMBHSTTYP), inb_p(SMBHSTCMD),
333 inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), inb_p(SMBHSTDAT1));
334
335 /* take consequent actions for error conditions */
336 if (!(temp & ALI1535_STS_DONE)) {
337 /* issue "kill" to reset host controller */
LABBE Corentin3fea5df2011-07-25 17:49:42 +0200338 outb_p(ALI1535_KILL, SMBHSTTYP);
339 outb_p(0xFF, SMBHSTSTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 } else if (temp & ALI1535_STS_ERR) {
341 /* issue "timeout" to reset all devices on bus */
LABBE Corentin3fea5df2011-07-25 17:49:42 +0200342 outb_p(ALI1535_T_OUT, SMBHSTTYP);
343 outb_p(0xFF, SMBHSTSTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 }
345
346 return result;
347}
348
David Brownell97140342008-07-14 22:38:25 +0200349/* Return negative errno on error. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350static s32 ali1535_access(struct i2c_adapter *adap, u16 addr,
351 unsigned short flags, char read_write, u8 command,
352 int size, union i2c_smbus_data *data)
353{
354 int i, len;
355 int temp;
356 int timeout;
357 s32 result = 0;
358
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 /* make sure SMBus is idle */
360 temp = inb_p(SMBHSTSTS);
361 for (timeout = 0;
362 (timeout < MAX_TIMEOUT) && !(temp & ALI1535_STS_IDLE);
363 timeout++) {
LABBE Corentin3fea5df2011-07-25 17:49:42 +0200364 usleep_range(1000, 2000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 temp = inb_p(SMBHSTSTS);
366 }
367 if (timeout >= MAX_TIMEOUT)
368 dev_warn(&adap->dev, "Idle wait Timeout! STS=0x%02x\n", temp);
369
370 /* clear status register (clear-on-write) */
371 outb_p(0xFF, SMBHSTSTS);
372
373 switch (size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 case I2C_SMBUS_QUICK:
375 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
376 SMBHSTADD);
377 size = ALI1535_QUICK;
378 outb_p(size, SMBHSTTYP); /* output command */
379 break;
380 case I2C_SMBUS_BYTE:
381 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
382 SMBHSTADD);
383 size = ALI1535_BYTE;
384 outb_p(size, SMBHSTTYP); /* output command */
385 if (read_write == I2C_SMBUS_WRITE)
386 outb_p(command, SMBHSTCMD);
387 break;
388 case I2C_SMBUS_BYTE_DATA:
389 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
390 SMBHSTADD);
391 size = ALI1535_BYTE_DATA;
392 outb_p(size, SMBHSTTYP); /* output command */
393 outb_p(command, SMBHSTCMD);
394 if (read_write == I2C_SMBUS_WRITE)
395 outb_p(data->byte, SMBHSTDAT0);
396 break;
397 case I2C_SMBUS_WORD_DATA:
398 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
399 SMBHSTADD);
400 size = ALI1535_WORD_DATA;
401 outb_p(size, SMBHSTTYP); /* output command */
402 outb_p(command, SMBHSTCMD);
403 if (read_write == I2C_SMBUS_WRITE) {
404 outb_p(data->word & 0xff, SMBHSTDAT0);
405 outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1);
406 }
407 break;
408 case I2C_SMBUS_BLOCK_DATA:
409 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
410 SMBHSTADD);
411 size = ALI1535_BLOCK_DATA;
412 outb_p(size, SMBHSTTYP); /* output command */
413 outb_p(command, SMBHSTCMD);
414 if (read_write == I2C_SMBUS_WRITE) {
415 len = data->block[0];
416 if (len < 0) {
417 len = 0;
418 data->block[0] = len;
419 }
420 if (len > 32) {
421 len = 32;
422 data->block[0] = len;
423 }
424 outb_p(len, SMBHSTDAT0);
425 /* Reset SMBBLKDAT */
426 outb_p(inb_p(SMBHSTTYP) | ALI1535_BLOCK_CLR, SMBHSTTYP);
427 for (i = 1; i <= len; i++)
428 outb_p(data->block[i], SMBBLKDAT);
429 }
430 break;
Jean Delvareac7fc4f2008-07-14 22:38:25 +0200431 default:
432 dev_warn(&adap->dev, "Unsupported transaction %d\n", size);
433 result = -EOPNOTSUPP;
434 goto EXIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 }
436
David Brownell97140342008-07-14 22:38:25 +0200437 result = ali1535_transaction(adap);
438 if (result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 goto EXIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
441 if ((read_write == I2C_SMBUS_WRITE) || (size == ALI1535_QUICK)) {
442 result = 0;
443 goto EXIT;
444 }
445
446 switch (size) {
447 case ALI1535_BYTE: /* Result put in SMBHSTDAT0 */
448 data->byte = inb_p(SMBHSTDAT0);
449 break;
450 case ALI1535_BYTE_DATA:
451 data->byte = inb_p(SMBHSTDAT0);
452 break;
453 case ALI1535_WORD_DATA:
454 data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8);
455 break;
456 case ALI1535_BLOCK_DATA:
457 len = inb_p(SMBHSTDAT0);
458 if (len > 32)
459 len = 32;
460 data->block[0] = len;
461 /* Reset SMBBLKDAT */
462 outb_p(inb_p(SMBHSTTYP) | ALI1535_BLOCK_CLR, SMBHSTTYP);
463 for (i = 1; i <= data->block[0]; i++) {
464 data->block[i] = inb_p(SMBBLKDAT);
465 dev_dbg(&adap->dev, "Blk: len=%d, i=%d, data=%02x\n",
466 len, i, data->block[i]);
467 }
468 break;
469 }
470EXIT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 return result;
472}
473
474
475static u32 ali1535_func(struct i2c_adapter *adapter)
476{
477 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
478 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
479 I2C_FUNC_SMBUS_BLOCK_DATA;
480}
481
Jean Delvare8f9082c2006-09-03 22:39:46 +0200482static const struct i2c_algorithm smbus_algorithm = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 .smbus_xfer = ali1535_access,
484 .functionality = ali1535_func,
485};
486
487static struct i2c_adapter ali1535_adapter = {
488 .owner = THIS_MODULE,
Jean Delvare3401b2f2008-07-14 22:38:29 +0200489 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 .algo = &smbus_algorithm,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491};
492
Jingoo Han392debf2013-12-03 08:11:20 +0900493static const struct pci_device_id ali1535_ids[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 { PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101) },
495 { },
496};
497
LABBE Corentin3fea5df2011-07-25 17:49:42 +0200498MODULE_DEVICE_TABLE(pci, ali1535_ids);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499
Bill Pemberton0b255e92012-11-27 15:59:38 -0500500static int ali1535_probe(struct pci_dev *dev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501{
502 if (ali1535_setup(dev)) {
503 dev_warn(&dev->dev,
504 "ALI1535 not detected, module not inserted.\n");
505 return -ENODEV;
506 }
507
Robert P. J. Day405ae7d2007-02-17 19:13:42 +0100508 /* set up the sysfs linkage to our parent device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 ali1535_adapter.dev.parent = &dev->dev;
510
David Brownell2096b952007-05-01 23:26:28 +0200511 snprintf(ali1535_adapter.name, sizeof(ali1535_adapter.name),
corentin.labbe65a2d742012-01-12 20:32:04 +0100512 "SMBus ALI1535 adapter at %04x", ali1535_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 return i2c_add_adapter(&ali1535_adapter);
514}
515
Bill Pemberton0b255e92012-11-27 15:59:38 -0500516static void ali1535_remove(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517{
518 i2c_del_adapter(&ali1535_adapter);
519 release_region(ali1535_smba, ALI1535_SMB_IOSIZE);
520}
521
522static struct pci_driver ali1535_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 .name = "ali1535_smbus",
524 .id_table = ali1535_ids,
525 .probe = ali1535_probe,
Bill Pemberton0b255e92012-11-27 15:59:38 -0500526 .remove = ali1535_remove,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527};
528
Axel Lin56f21782012-07-24 14:13:56 +0200529module_pci_driver(ali1535_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530
531MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, "
532 "Philip Edelbrock <phil@netroedge.com>, "
533 "Mark D. Studebaker <mdsxyz123@yahoo.com> "
534 "and Dan Eaton <dan.eaton@rocketlogix.com>");
535MODULE_DESCRIPTION("ALI1535 SMBus driver");
536MODULE_LICENSE("GPL");