blob: 3f491815e2c4759a5d0b7d850de20abeafe42381 [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.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Linus Torvalds1da177e2005-04-16 15:20:36 -070021*/
22
23/*
24 This is the driver for the SMB Host controller on
25 Acer Labs Inc. (ALI) M1535 South Bridge.
26
27 The M1535 is a South bridge for portable systems.
28 It is very similar to the M15x3 South bridges also produced
29 by Acer Labs Inc. Some of the registers within the part
30 have moved and some have been redefined slightly. Additionally,
31 the sequencing of the SMBus transactions has been modified
32 to be more consistent with the sequencing recommended by
33 the manufacturer and observed through testing. These
34 changes are reflected in this driver and can be identified
35 by comparing this driver to the i2c-ali15x3 driver.
36 For an overview of these chips see http://www.acerlabs.com
37
38 The SMB controller is part of the 7101 device, which is an
39 ACPI-compliant Power Management Unit (PMU).
40
41 The whole 7101 device has to be enabled for the SMB to work.
42 You can't just enable the SMB alone.
43 The SMB and the ACPI have separate I/O spaces.
44 We make sure that the SMB is enabled. We leave the ACPI alone.
45
46 This driver controls the SMB Host only.
47
48 This driver does not use interrupts.
49*/
50
51
52/* Note: we assume there can only be one ALI1535, with one SMBus interface */
53
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#include <linux/module.h>
55#include <linux/pci.h>
56#include <linux/kernel.h>
57#include <linux/stddef.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#include <linux/delay.h>
59#include <linux/ioport.h>
60#include <linux/i2c.h>
61#include <linux/init.h>
Jean Delvare54fb4a052008-07-14 22:38:33 +020062#include <linux/acpi.h>
H Hartley Sweeten21782182010-05-21 18:41:01 +020063#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65
66/* ALI1535 SMBus address offsets */
67#define SMBHSTSTS (0 + ali1535_smba)
68#define SMBHSTTYP (1 + ali1535_smba)
69#define SMBHSTPORT (2 + ali1535_smba)
70#define SMBHSTCMD (7 + ali1535_smba)
71#define SMBHSTADD (3 + ali1535_smba)
72#define SMBHSTDAT0 (4 + ali1535_smba)
73#define SMBHSTDAT1 (5 + ali1535_smba)
74#define SMBBLKDAT (6 + ali1535_smba)
75
76/* PCI Address Constants */
77#define SMBCOM 0x004
78#define SMBREV 0x008
79#define SMBCFG 0x0D1
80#define SMBBA 0x0E2
81#define SMBHSTCFG 0x0F0
82#define SMBCLK 0x0F2
83
84/* Other settings */
85#define MAX_TIMEOUT 500 /* times 1/100 sec */
86#define ALI1535_SMB_IOSIZE 32
87
88#define ALI1535_SMB_DEFAULTBASE 0x8040
89
90/* ALI1535 address lock bits */
91#define ALI1535_LOCK 0x06 /* dwe */
92
93/* ALI1535 command constants */
94#define ALI1535_QUICK 0x00
95#define ALI1535_BYTE 0x10
96#define ALI1535_BYTE_DATA 0x20
97#define ALI1535_WORD_DATA 0x30
98#define ALI1535_BLOCK_DATA 0x40
99#define ALI1535_I2C_READ 0x60
100
101#define ALI1535_DEV10B_EN 0x80 /* Enable 10-bit addressing in */
102 /* I2C read */
103#define ALI1535_T_OUT 0x08 /* Time-out Command (write) */
104#define ALI1535_A_HIGH_BIT9 0x08 /* Bit 9 of 10-bit address in */
105 /* Alert-Response-Address */
106 /* (read) */
107#define ALI1535_KILL 0x04 /* Kill Command (write) */
108#define ALI1535_A_HIGH_BIT8 0x04 /* Bit 8 of 10-bit address in */
109 /* Alert-Response-Address */
110 /* (read) */
111
112#define ALI1535_D_HI_MASK 0x03 /* Mask for isolating bits 9-8 */
113 /* of 10-bit address in I2C */
114 /* Read Command */
115
116/* ALI1535 status register bits */
117#define ALI1535_STS_IDLE 0x04
118#define ALI1535_STS_BUSY 0x08 /* host busy */
119#define ALI1535_STS_DONE 0x10 /* transaction complete */
120#define ALI1535_STS_DEV 0x20 /* device error */
121#define ALI1535_STS_BUSERR 0x40 /* bus error */
122#define ALI1535_STS_FAIL 0x80 /* failed bus transaction */
123#define ALI1535_STS_ERR 0xE0 /* all the bad error bits */
124
125#define ALI1535_BLOCK_CLR 0x04 /* reset block data index */
126
127/* ALI1535 device address register bits */
128#define ALI1535_RD_ADDR 0x01 /* Read/Write Bit in Device */
129 /* Address field */
130 /* -> Write = 0 */
131 /* -> Read = 1 */
132#define ALI1535_SMBIO_EN 0x04 /* SMB I/O Space enable */
133
Jean Delvared6072f82005-09-25 16:37:04 +0200134static struct pci_driver ali1535_driver;
corentin.labbe65a2d742012-01-12 20:32:04 +0100135static unsigned long ali1535_smba;
136static unsigned short ali1535_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
138/* Detect whether a ALI1535 can be found, and initialize it, where necessary.
139 Note the differences between kernels with the old PCI BIOS interface and
140 newer kernels with the real PCI interface. In compat.h some things are
141 defined to make the transition easier. */
Bill Pemberton0b255e92012-11-27 15:59:38 -0500142static int ali1535_setup(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143{
Jean Delvare7c1f59c2012-01-12 20:32:03 +0100144 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 unsigned char temp;
146
147 /* Check the following things:
148 - SMB I/O address is initialized
149 - Device is enabled
150 - We can use the addresses
151 */
152
corentin.labbe65a2d742012-01-12 20:32:04 +0100153 retval = pci_enable_device(dev);
154 if (retval) {
155 dev_err(&dev->dev, "ALI1535_smb can't enable device\n");
156 goto exit;
157 }
158
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 /* Determine the address of the SMBus area */
corentin.labbe65a2d742012-01-12 20:32:04 +0100160 pci_read_config_word(dev, SMBBA, &ali1535_offset);
161 dev_dbg(&dev->dev, "ALI1535_smb is at offset 0x%04x\n", ali1535_offset);
162 ali1535_offset &= (0xffff & ~(ALI1535_SMB_IOSIZE - 1));
163 if (ali1535_offset == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 dev_warn(&dev->dev,
165 "ALI1535_smb region uninitialized - upgrade BIOS?\n");
Jean Delvare7c1f59c2012-01-12 20:32:03 +0100166 retval = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 goto exit;
168 }
169
corentin.labbe65a2d742012-01-12 20:32:04 +0100170 if (pci_resource_flags(dev, 0) & IORESOURCE_IO)
171 ali1535_smba = pci_resource_start(dev, 0) + ali1535_offset;
172 else
173 ali1535_smba = ali1535_offset;
174
Jean Delvare54fb4a052008-07-14 22:38:33 +0200175 retval = acpi_check_region(ali1535_smba, ALI1535_SMB_IOSIZE,
176 ali1535_driver.name);
177 if (retval)
178 goto exit;
179
Jean Delvared6072f82005-09-25 16:37:04 +0200180 if (!request_region(ali1535_smba, ALI1535_SMB_IOSIZE,
181 ali1535_driver.name)) {
corentin.labbe65a2d742012-01-12 20:32:04 +0100182 dev_err(&dev->dev, "ALI1535_smb region 0x%lx already in use!\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 ali1535_smba);
Jean Delvare7c1f59c2012-01-12 20:32:03 +0100184 retval = -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 goto exit;
186 }
187
188 /* check if whole device is enabled */
189 pci_read_config_byte(dev, SMBCFG, &temp);
190 if ((temp & ALI1535_SMBIO_EN) == 0) {
191 dev_err(&dev->dev, "SMB device not enabled - upgrade BIOS?\n");
Jean Delvare7c1f59c2012-01-12 20:32:03 +0100192 retval = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 goto exit_free;
194 }
195
196 /* Is SMB Host controller enabled? */
197 pci_read_config_byte(dev, SMBHSTCFG, &temp);
198 if ((temp & 1) == 0) {
199 dev_err(&dev->dev, "SMBus controller not enabled - upgrade BIOS?\n");
Jean Delvare7c1f59c2012-01-12 20:32:03 +0100200 retval = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 goto exit_free;
202 }
203
204 /* set SMB clock to 74KHz as recommended in data sheet */
205 pci_write_config_byte(dev, SMBCLK, 0x20);
206
207 /*
208 The interrupt routing for SMB is set up in register 0x77 in the
209 1533 ISA Bridge device, NOT in the 7101 device.
210 Don't bother with finding the 1533 device and reading the register.
211 if ((....... & 0x0F) == 1)
212 dev_dbg(&dev->dev, "ALI1535 using Interrupt 9 for SMBus.\n");
213 */
214 pci_read_config_byte(dev, SMBREV, &temp);
215 dev_dbg(&dev->dev, "SMBREV = 0x%X\n", temp);
corentin.labbe65a2d742012-01-12 20:32:04 +0100216 dev_dbg(&dev->dev, "ALI1535_smba = 0x%lx\n", ali1535_smba);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
Jean Delvare7c1f59c2012-01-12 20:32:03 +0100218 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
220exit_free:
221 release_region(ali1535_smba, ALI1535_SMB_IOSIZE);
Jean Delvare7c1f59c2012-01-12 20:32:03 +0100222exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 return retval;
224}
225
226static int ali1535_transaction(struct i2c_adapter *adap)
227{
228 int temp;
229 int result = 0;
230 int timeout = 0;
231
232 dev_dbg(&adap->dev, "Transaction (pre): STS=%02x, TYP=%02x, "
233 "CMD=%02x, ADD=%02x, DAT0=%02x, DAT1=%02x\n",
234 inb_p(SMBHSTSTS), inb_p(SMBHSTTYP), inb_p(SMBHSTCMD),
235 inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), inb_p(SMBHSTDAT1));
236
237 /* get status */
238 temp = inb_p(SMBHSTSTS);
239
240 /* Make sure the SMBus host is ready to start transmitting */
241 /* Check the busy bit first */
242 if (temp & ALI1535_STS_BUSY) {
243 /* If the host controller is still busy, it may have timed out
244 * in the previous transaction, resulting in a "SMBus Timeout"
245 * printk. I've tried the following to reset a stuck busy bit.
246 * 1. Reset the controller with an KILL command. (this
247 * doesn't seem to clear the controller if an external
248 * device is hung)
249 * 2. Reset the controller and the other SMBus devices with a
250 * T_OUT command. (this clears the host busy bit if an
251 * external device is hung, but it comes back upon a new
252 * access to a device)
253 * 3. Disable and reenable the controller in SMBHSTCFG. Worst
254 * case, nothing seems to work except power reset.
255 */
256
257 /* Try resetting entire SMB bus, including other devices - This
258 * may not work either - it clears the BUSY bit but then the
259 * BUSY bit may come back on when you try and use the chip
260 * again. If that's the case you are stuck.
261 */
262 dev_info(&adap->dev,
263 "Resetting entire SMB Bus to clear busy condition (%02x)\n",
264 temp);
265 outb_p(ALI1535_T_OUT, SMBHSTTYP);
266 temp = inb_p(SMBHSTSTS);
267 }
268
269 /* now check the error bits and the busy bit */
270 if (temp & (ALI1535_STS_ERR | ALI1535_STS_BUSY)) {
271 /* do a clear-on-write */
272 outb_p(0xFF, SMBHSTSTS);
LABBE Corentin3fea5df2011-07-25 17:49:42 +0200273 temp = inb_p(SMBHSTSTS);
274 if (temp & (ALI1535_STS_ERR | ALI1535_STS_BUSY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 /* This is probably going to be correctable only by a
276 * power reset as one of the bits now appears to be
277 * stuck */
278 /* This may be a bus or device with electrical problems. */
279 dev_err(&adap->dev,
280 "SMBus reset failed! (0x%02x) - controller or "
281 "device on bus is probably hung\n", temp);
David Brownell97140342008-07-14 22:38:25 +0200282 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 }
284 } else {
285 /* check and clear done bit */
LABBE Corentin3fea5df2011-07-25 17:49:42 +0200286 if (temp & ALI1535_STS_DONE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 outb_p(temp, SMBHSTSTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 }
289
290 /* start the transaction by writing anything to the start register */
291 outb_p(0xFF, SMBHSTPORT);
292
293 /* We will always wait for a fraction of a second! */
294 timeout = 0;
295 do {
LABBE Corentin3fea5df2011-07-25 17:49:42 +0200296 usleep_range(1000, 2000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 temp = inb_p(SMBHSTSTS);
298 } while (((temp & ALI1535_STS_BUSY) && !(temp & ALI1535_STS_IDLE))
299 && (timeout++ < MAX_TIMEOUT));
300
301 /* If the SMBus is still busy, we give up */
Roel Kluin4ccc28f2009-05-05 08:39:24 +0200302 if (timeout > MAX_TIMEOUT) {
David Brownell97140342008-07-14 22:38:25 +0200303 result = -ETIMEDOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 dev_err(&adap->dev, "SMBus Timeout!\n");
305 }
306
307 if (temp & ALI1535_STS_FAIL) {
David Brownell97140342008-07-14 22:38:25 +0200308 result = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 dev_dbg(&adap->dev, "Error: Failed bus transaction\n");
310 }
311
312 /* Unfortunately the ALI SMB controller maps "no response" and "bus
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300313 * collision" into a single bit. No response is the usual case so don't
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 * do a printk. This means that bus collisions go unreported.
315 */
316 if (temp & ALI1535_STS_BUSERR) {
David Brownell97140342008-07-14 22:38:25 +0200317 result = -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 dev_dbg(&adap->dev,
319 "Error: no response or bus collision ADD=%02x\n",
320 inb_p(SMBHSTADD));
321 }
322
323 /* haven't ever seen this */
324 if (temp & ALI1535_STS_DEV) {
David Brownell97140342008-07-14 22:38:25 +0200325 result = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 dev_err(&adap->dev, "Error: device error\n");
327 }
328
329 /* check to see if the "command complete" indication is set */
330 if (!(temp & ALI1535_STS_DONE)) {
David Brownell97140342008-07-14 22:38:25 +0200331 result = -ETIMEDOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 dev_err(&adap->dev, "Error: command never completed\n");
333 }
334
335 dev_dbg(&adap->dev, "Transaction (post): STS=%02x, TYP=%02x, "
336 "CMD=%02x, ADD=%02x, DAT0=%02x, DAT1=%02x\n",
337 inb_p(SMBHSTSTS), inb_p(SMBHSTTYP), inb_p(SMBHSTCMD),
338 inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), inb_p(SMBHSTDAT1));
339
340 /* take consequent actions for error conditions */
341 if (!(temp & ALI1535_STS_DONE)) {
342 /* issue "kill" to reset host controller */
LABBE Corentin3fea5df2011-07-25 17:49:42 +0200343 outb_p(ALI1535_KILL, SMBHSTTYP);
344 outb_p(0xFF, SMBHSTSTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 } else if (temp & ALI1535_STS_ERR) {
346 /* issue "timeout" to reset all devices on bus */
LABBE Corentin3fea5df2011-07-25 17:49:42 +0200347 outb_p(ALI1535_T_OUT, SMBHSTTYP);
348 outb_p(0xFF, SMBHSTSTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 }
350
351 return result;
352}
353
David Brownell97140342008-07-14 22:38:25 +0200354/* Return negative errno on error. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355static s32 ali1535_access(struct i2c_adapter *adap, u16 addr,
356 unsigned short flags, char read_write, u8 command,
357 int size, union i2c_smbus_data *data)
358{
359 int i, len;
360 int temp;
361 int timeout;
362 s32 result = 0;
363
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 /* make sure SMBus is idle */
365 temp = inb_p(SMBHSTSTS);
366 for (timeout = 0;
367 (timeout < MAX_TIMEOUT) && !(temp & ALI1535_STS_IDLE);
368 timeout++) {
LABBE Corentin3fea5df2011-07-25 17:49:42 +0200369 usleep_range(1000, 2000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 temp = inb_p(SMBHSTSTS);
371 }
372 if (timeout >= MAX_TIMEOUT)
373 dev_warn(&adap->dev, "Idle wait Timeout! STS=0x%02x\n", temp);
374
375 /* clear status register (clear-on-write) */
376 outb_p(0xFF, SMBHSTSTS);
377
378 switch (size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 case I2C_SMBUS_QUICK:
380 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
381 SMBHSTADD);
382 size = ALI1535_QUICK;
383 outb_p(size, SMBHSTTYP); /* output command */
384 break;
385 case I2C_SMBUS_BYTE:
386 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
387 SMBHSTADD);
388 size = ALI1535_BYTE;
389 outb_p(size, SMBHSTTYP); /* output command */
390 if (read_write == I2C_SMBUS_WRITE)
391 outb_p(command, SMBHSTCMD);
392 break;
393 case I2C_SMBUS_BYTE_DATA:
394 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
395 SMBHSTADD);
396 size = ALI1535_BYTE_DATA;
397 outb_p(size, SMBHSTTYP); /* output command */
398 outb_p(command, SMBHSTCMD);
399 if (read_write == I2C_SMBUS_WRITE)
400 outb_p(data->byte, SMBHSTDAT0);
401 break;
402 case I2C_SMBUS_WORD_DATA:
403 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
404 SMBHSTADD);
405 size = ALI1535_WORD_DATA;
406 outb_p(size, SMBHSTTYP); /* output command */
407 outb_p(command, SMBHSTCMD);
408 if (read_write == I2C_SMBUS_WRITE) {
409 outb_p(data->word & 0xff, SMBHSTDAT0);
410 outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1);
411 }
412 break;
413 case I2C_SMBUS_BLOCK_DATA:
414 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
415 SMBHSTADD);
416 size = ALI1535_BLOCK_DATA;
417 outb_p(size, SMBHSTTYP); /* output command */
418 outb_p(command, SMBHSTCMD);
419 if (read_write == I2C_SMBUS_WRITE) {
420 len = data->block[0];
421 if (len < 0) {
422 len = 0;
423 data->block[0] = len;
424 }
425 if (len > 32) {
426 len = 32;
427 data->block[0] = len;
428 }
429 outb_p(len, SMBHSTDAT0);
430 /* Reset SMBBLKDAT */
431 outb_p(inb_p(SMBHSTTYP) | ALI1535_BLOCK_CLR, SMBHSTTYP);
432 for (i = 1; i <= len; i++)
433 outb_p(data->block[i], SMBBLKDAT);
434 }
435 break;
Jean Delvareac7fc4f2008-07-14 22:38:25 +0200436 default:
437 dev_warn(&adap->dev, "Unsupported transaction %d\n", size);
438 result = -EOPNOTSUPP;
439 goto EXIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 }
441
David Brownell97140342008-07-14 22:38:25 +0200442 result = ali1535_transaction(adap);
443 if (result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 goto EXIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
446 if ((read_write == I2C_SMBUS_WRITE) || (size == ALI1535_QUICK)) {
447 result = 0;
448 goto EXIT;
449 }
450
451 switch (size) {
452 case ALI1535_BYTE: /* Result put in SMBHSTDAT0 */
453 data->byte = inb_p(SMBHSTDAT0);
454 break;
455 case ALI1535_BYTE_DATA:
456 data->byte = inb_p(SMBHSTDAT0);
457 break;
458 case ALI1535_WORD_DATA:
459 data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8);
460 break;
461 case ALI1535_BLOCK_DATA:
462 len = inb_p(SMBHSTDAT0);
463 if (len > 32)
464 len = 32;
465 data->block[0] = len;
466 /* Reset SMBBLKDAT */
467 outb_p(inb_p(SMBHSTTYP) | ALI1535_BLOCK_CLR, SMBHSTTYP);
468 for (i = 1; i <= data->block[0]; i++) {
469 data->block[i] = inb_p(SMBBLKDAT);
470 dev_dbg(&adap->dev, "Blk: len=%d, i=%d, data=%02x\n",
471 len, i, data->block[i]);
472 }
473 break;
474 }
475EXIT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 return result;
477}
478
479
480static u32 ali1535_func(struct i2c_adapter *adapter)
481{
482 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
483 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
484 I2C_FUNC_SMBUS_BLOCK_DATA;
485}
486
Jean Delvare8f9082c2006-09-03 22:39:46 +0200487static const struct i2c_algorithm smbus_algorithm = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 .smbus_xfer = ali1535_access,
489 .functionality = ali1535_func,
490};
491
492static struct i2c_adapter ali1535_adapter = {
493 .owner = THIS_MODULE,
Jean Delvare3401b2f2008-07-14 22:38:29 +0200494 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 .algo = &smbus_algorithm,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496};
497
LABBE Corentin3fea5df2011-07-25 17:49:42 +0200498static DEFINE_PCI_DEVICE_TABLE(ali1535_ids) = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 { PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101) },
500 { },
501};
502
LABBE Corentin3fea5df2011-07-25 17:49:42 +0200503MODULE_DEVICE_TABLE(pci, ali1535_ids);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
Bill Pemberton0b255e92012-11-27 15:59:38 -0500505static int ali1535_probe(struct pci_dev *dev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506{
507 if (ali1535_setup(dev)) {
508 dev_warn(&dev->dev,
509 "ALI1535 not detected, module not inserted.\n");
510 return -ENODEV;
511 }
512
Robert P. J. Day405ae7d2007-02-17 19:13:42 +0100513 /* set up the sysfs linkage to our parent device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 ali1535_adapter.dev.parent = &dev->dev;
515
David Brownell2096b952007-05-01 23:26:28 +0200516 snprintf(ali1535_adapter.name, sizeof(ali1535_adapter.name),
corentin.labbe65a2d742012-01-12 20:32:04 +0100517 "SMBus ALI1535 adapter at %04x", ali1535_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 return i2c_add_adapter(&ali1535_adapter);
519}
520
Bill Pemberton0b255e92012-11-27 15:59:38 -0500521static void ali1535_remove(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522{
523 i2c_del_adapter(&ali1535_adapter);
524 release_region(ali1535_smba, ALI1535_SMB_IOSIZE);
525}
526
527static struct pci_driver ali1535_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 .name = "ali1535_smbus",
529 .id_table = ali1535_ids,
530 .probe = ali1535_probe,
Bill Pemberton0b255e92012-11-27 15:59:38 -0500531 .remove = ali1535_remove,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532};
533
Axel Lin56f21782012-07-24 14:13:56 +0200534module_pci_driver(ali1535_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
536MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, "
537 "Philip Edelbrock <phil@netroedge.com>, "
538 "Mark D. Studebaker <mdsxyz123@yahoo.com> "
539 "and Dan Eaton <dan.eaton@rocketlogix.com>");
540MODULE_DESCRIPTION("ALI1535 SMBus driver");
541MODULE_LICENSE("GPL");