blob: 5906986d013b1d9018a8ac4b8a130fb70890776b [file] [log] [blame]
Roel Kluin0c168ce2009-03-28 21:34:42 +01001/*
2 * i2c-algo-pcf.c i2c driver algorithms for PCF8584 adapters
3 *
4 * Copyright (C) 1995-1997 Simon G. Vogl
5 * 1998-2000 Hans Berglund
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 *
21 * With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and
22 * Frodo Looijaard <frodol@dds.nl>, and also from Martin Bailey
23 * <mbailey@littlefeet-inc.com>
24 *
25 * Partially rewriten by Oleg I. Vdovikin <vdovikin@jscc.ru> to handle multiple
26 * messages, proper stop/repstart signaling during receive, added detect code
27 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29#include <linux/kernel.h>
30#include <linux/module.h>
31#include <linux/delay.h>
32#include <linux/slab.h>
33#include <linux/init.h>
34#include <linux/errno.h>
35#include <linux/i2c.h>
36#include <linux/i2c-algo-pcf.h>
37#include "i2c-algo-pcf.h"
38
39
Roel Kluin0c168ce2009-03-28 21:34:42 +010040#define DEB2(x) if (i2c_debug >= 2) x
41#define DEB3(x) if (i2c_debug >= 3) x /* print several statistical values */
42#define DEBPROTO(x) if (i2c_debug >= 9) x;
43 /* debug the protocol by showing transferred bits */
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#define DEF_TIMEOUT 16
45
Roel Kluin0c168ce2009-03-28 21:34:42 +010046/*
47 * module parameters:
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 */
49static int i2c_debug;
50
Roel Kluin0c168ce2009-03-28 21:34:42 +010051/* setting states on the bus with the right timing: */
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53#define set_pcf(adap, ctl, val) adap->setpcf(adap->data, ctl, val)
54#define get_pcf(adap, ctl) adap->getpcf(adap->data, ctl)
55#define get_own(adap) adap->getown(adap->data)
56#define get_clock(adap) adap->getclock(adap->data)
57#define i2c_outb(adap, val) adap->setpcf(adap->data, 0, val)
58#define i2c_inb(adap) adap->getpcf(adap->data, 0)
59
Roel Kluin0c168ce2009-03-28 21:34:42 +010060/* other auxiliary functions */
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Roel Kluin0c168ce2009-03-28 21:34:42 +010062static void i2c_start(struct i2c_algo_pcf_data *adap)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063{
64 DEBPROTO(printk("S "));
65 set_pcf(adap, 1, I2C_PCF_START);
66}
67
Roel Kluin0c168ce2009-03-28 21:34:42 +010068static void i2c_repstart(struct i2c_algo_pcf_data *adap)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069{
70 DEBPROTO(printk(" Sr "));
71 set_pcf(adap, 1, I2C_PCF_REPSTART);
72}
73
Roel Kluin0c168ce2009-03-28 21:34:42 +010074static void i2c_stop(struct i2c_algo_pcf_data *adap)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
76 DEBPROTO(printk("P\n"));
77 set_pcf(adap, 1, I2C_PCF_STOP);
78}
79
Eric Brower0573d112008-07-14 22:38:31 +020080static void handle_lab(struct i2c_algo_pcf_data *adap, const int *status)
81{
82 DEB2(printk(KERN_INFO
83 "i2c-algo-pcf.o: lost arbitration (CSR 0x%02x)\n",
Roel Kluin0c168ce2009-03-28 21:34:42 +010084 *status));
85 /*
86 * Cleanup from LAB -- reset and enable ESO.
Eric Brower0573d112008-07-14 22:38:31 +020087 * This resets the PCF8584; since we've lost the bus, no
88 * further attempts should be made by callers to clean up
89 * (no i2c_stop() etc.)
90 */
91 set_pcf(adap, 1, I2C_PCF_PIN);
92 set_pcf(adap, 1, I2C_PCF_ESO);
Roel Kluin0c168ce2009-03-28 21:34:42 +010093 /*
94 * We pause for a time period sufficient for any running
Eric Brower0573d112008-07-14 22:38:31 +020095 * I2C transaction to complete -- the arbitration logic won't
96 * work properly until the next START is seen.
97 * It is assumed the bus driver or client has set a proper value.
98 *
99 * REVISIT: should probably use msleep instead of mdelay if we
100 * know we can sleep.
101 */
102 if (adap->lab_mdelay)
103 mdelay(adap->lab_mdelay);
104
105 DEB2(printk(KERN_INFO
106 "i2c-algo-pcf.o: reset LAB condition (CSR 0x%02x)\n",
107 get_pcf(adap, 1)));
108}
109
Roel Kluin0c168ce2009-03-28 21:34:42 +0100110static int wait_for_bb(struct i2c_algo_pcf_data *adap)
111{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
113 int timeout = DEF_TIMEOUT;
114 int status;
115
116 status = get_pcf(adap, 1);
Roel Kluin0c168ce2009-03-28 21:34:42 +0100117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 while (timeout-- && !(status & I2C_PCF_BB)) {
119 udelay(100); /* wait for 100 us */
120 status = get_pcf(adap, 1);
121 }
Roel Kluin0c168ce2009-03-28 21:34:42 +0100122
123 if (timeout <= 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 printk(KERN_ERR "Timeout waiting for Bus Busy\n");
Roel Kluin0c168ce2009-03-28 21:34:42 +0100125
126 return timeout <= 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127}
128
Roel Kluin0c168ce2009-03-28 21:34:42 +0100129static int wait_for_pin(struct i2c_algo_pcf_data *adap, int *status)
130{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132 int timeout = DEF_TIMEOUT;
133
134 *status = get_pcf(adap, 1);
Roel Kluin0c168ce2009-03-28 21:34:42 +0100135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 while (timeout-- && (*status & I2C_PCF_PIN)) {
David Miller08e53382008-10-22 20:21:29 +0200137 adap->waitforpin(adap->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 *status = get_pcf(adap, 1);
139 }
140 if (*status & I2C_PCF_LAB) {
Eric Brower0573d112008-07-14 22:38:31 +0200141 handle_lab(adap, status);
Roel Kluin0c168ce2009-03-28 21:34:42 +0100142 return -EINTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 }
Roel Kluin0c168ce2009-03-28 21:34:42 +0100144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 if (timeout <= 0)
Roel Kluin0c168ce2009-03-28 21:34:42 +0100146 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 else
Roel Kluin0c168ce2009-03-28 21:34:42 +0100148 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149}
150
Roel Kluin0c168ce2009-03-28 21:34:42 +0100151/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 * This should perform the 'PCF8584 initialization sequence' as described
153 * in the Philips IC12 data book (1995, Aug 29).
154 * There should be a 30 clock cycle wait after reset, I assume this
155 * has been fulfilled.
156 * There should be a delay at the end equal to the longest I2C message
157 * to synchronize the BB-bit (in multimaster systems). How long is
158 * this? I assume 1 second is always long enough.
159 *
160 * vdovikin: added detect code for PCF8584
161 */
162static int pcf_init_8584 (struct i2c_algo_pcf_data *adap)
163{
164 unsigned char temp;
165
Roel Kluin0c168ce2009-03-28 21:34:42 +0100166 DEB3(printk(KERN_DEBUG "i2c-algo-pcf.o: PCF state 0x%02x\n",
167 get_pcf(adap, 1)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
169 /* S1=0x80: S0 selected, serial interface off */
170 set_pcf(adap, 1, I2C_PCF_PIN);
Roel Kluin0c168ce2009-03-28 21:34:42 +0100171 /*
172 * check to see S1 now used as R/W ctrl -
173 * PCF8584 does that when ESO is zero
174 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 if (((temp = get_pcf(adap, 1)) & 0x7f) != (0)) {
176 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S0 (0x%02x).\n", temp));
177 return -ENXIO; /* definetly not PCF8584 */
178 }
179
Roel Kluin0c168ce2009-03-28 21:34:42 +0100180 /* load own address in S0, effective address is (own << 1) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 i2c_outb(adap, get_own(adap));
182 /* check it's really written */
183 if ((temp = i2c_inb(adap)) != get_own(adap)) {
184 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't set S0 (0x%02x).\n", temp));
185 return -ENXIO;
186 }
187
Roel Kluin0c168ce2009-03-28 21:34:42 +0100188 /* S1=0xA0, next byte in S2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 set_pcf(adap, 1, I2C_PCF_PIN | I2C_PCF_ES1);
190 /* check to see S2 now selected */
191 if (((temp = get_pcf(adap, 1)) & 0x7f) != I2C_PCF_ES1) {
192 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S2 (0x%02x).\n", temp));
193 return -ENXIO;
194 }
195
Roel Kluin0c168ce2009-03-28 21:34:42 +0100196 /* load clock register S2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 i2c_outb(adap, get_clock(adap));
198 /* check it's really written, the only 5 lowest bits does matter */
199 if (((temp = i2c_inb(adap)) & 0x1f) != get_clock(adap)) {
200 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't set S2 (0x%02x).\n", temp));
201 return -ENXIO;
202 }
203
Roel Kluin0c168ce2009-03-28 21:34:42 +0100204 /* Enable serial interface, idle, S0 selected */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 set_pcf(adap, 1, I2C_PCF_IDLE);
206
207 /* check to see PCF is really idled and we can access status register */
208 if ((temp = get_pcf(adap, 1)) != (I2C_PCF_PIN | I2C_PCF_BB)) {
209 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S1` (0x%02x).\n", temp));
210 return -ENXIO;
211 }
Roel Kluin0c168ce2009-03-28 21:34:42 +0100212
David Millera672b4c2008-10-22 20:21:30 +0200213 printk(KERN_DEBUG "i2c-algo-pcf.o: detected and initialized PCF8584.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
215 return 0;
216}
217
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218static int pcf_sendbytes(struct i2c_adapter *i2c_adap, const char *buf,
Roel Kluin0c168ce2009-03-28 21:34:42 +0100219 int count, int last)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220{
221 struct i2c_algo_pcf_data *adap = i2c_adap->algo_data;
222 int wrcount, status, timeout;
Roel Kluin0c168ce2009-03-28 21:34:42 +0100223
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 for (wrcount=0; wrcount<count; ++wrcount) {
225 DEB2(dev_dbg(&i2c_adap->dev, "i2c_write: writing %2.2X\n",
Roel Kluin0c168ce2009-03-28 21:34:42 +0100226 buf[wrcount] & 0xff));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 i2c_outb(adap, buf[wrcount]);
228 timeout = wait_for_pin(adap, &status);
229 if (timeout) {
Roel Kluin0c168ce2009-03-28 21:34:42 +0100230 if (timeout == -EINTR)
231 return -EINTR; /* arbitration lost */
232
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 i2c_stop(adap);
234 dev_err(&i2c_adap->dev, "i2c_write: error - timeout.\n");
235 return -EREMOTEIO; /* got a better one ?? */
236 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 if (status & I2C_PCF_LRB) {
238 i2c_stop(adap);
239 dev_err(&i2c_adap->dev, "i2c_write: error - no ack.\n");
240 return -EREMOTEIO; /* got a better one ?? */
241 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 }
Roel Kluin0c168ce2009-03-28 21:34:42 +0100243 if (last)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 i2c_stop(adap);
Roel Kluin0c168ce2009-03-28 21:34:42 +0100245 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 i2c_repstart(adap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
Roel Kluin0c168ce2009-03-28 21:34:42 +0100248 return wrcount;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249}
250
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251static int pcf_readbytes(struct i2c_adapter *i2c_adap, char *buf,
Roel Kluin0c168ce2009-03-28 21:34:42 +0100252 int count, int last)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253{
254 int i, status;
255 struct i2c_algo_pcf_data *adap = i2c_adap->algo_data;
256 int wfp;
257
258 /* increment number of bytes to read by one -- read dummy byte */
259 for (i = 0; i <= count; i++) {
260
261 if ((wfp = wait_for_pin(adap, &status))) {
Roel Kluin0c168ce2009-03-28 21:34:42 +0100262 if (wfp == -EINTR)
263 return -EINTR; /* arbitration lost */
264
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 i2c_stop(adap);
266 dev_err(&i2c_adap->dev, "pcf_readbytes timed out.\n");
Roel Kluin0c168ce2009-03-28 21:34:42 +0100267 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 }
269
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 if ((status & I2C_PCF_LRB) && (i != count)) {
271 i2c_stop(adap);
272 dev_err(&i2c_adap->dev, "i2c_read: i2c_inb, No ack.\n");
Roel Kluin0c168ce2009-03-28 21:34:42 +0100273 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 }
Roel Kluin0c168ce2009-03-28 21:34:42 +0100275
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 if (i == count - 1) {
277 set_pcf(adap, 1, I2C_PCF_ESO);
Roel Kluin0c168ce2009-03-28 21:34:42 +0100278 } else if (i == count) {
279 if (last)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 i2c_stop(adap);
Roel Kluin0c168ce2009-03-28 21:34:42 +0100281 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 i2c_repstart(adap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 }
Roel Kluin0c168ce2009-03-28 21:34:42 +0100284
285 if (i)
286 buf[i - 1] = i2c_inb(adap);
287 else
288 i2c_inb(adap); /* dummy read */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 }
290
Roel Kluin0c168ce2009-03-28 21:34:42 +0100291 return i - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292}
293
294
Jean Delvare6408a832008-01-27 18:14:46 +0100295static int pcf_doAddress(struct i2c_algo_pcf_data *adap,
296 struct i2c_msg *msg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297{
298 unsigned short flags = msg->flags;
299 unsigned char addr;
Jean Delvare6408a832008-01-27 18:14:46 +0100300
301 addr = msg->addr << 1;
302 if (flags & I2C_M_RD)
303 addr |= 1;
304 if (flags & I2C_M_REV_DIR_ADDR)
305 addr ^= 1;
306 i2c_outb(adap, addr);
307
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 return 0;
309}
310
311static int pcf_xfer(struct i2c_adapter *i2c_adap,
Roel Kluin0c168ce2009-03-28 21:34:42 +0100312 struct i2c_msg *msgs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 int num)
314{
315 struct i2c_algo_pcf_data *adap = i2c_adap->algo_data;
316 struct i2c_msg *pmsg;
317 int i;
318 int ret=0, timeout, status;
Roel Kluin0c168ce2009-03-28 21:34:42 +0100319
David Miller30091402008-10-22 20:21:30 +0200320 if (adap->xfer_begin)
321 adap->xfer_begin(adap->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
323 /* Check for bus busy */
324 timeout = wait_for_bb(adap);
325 if (timeout) {
326 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: "
Roel Kluin0c168ce2009-03-28 21:34:42 +0100327 "Timeout waiting for BB in pcf_xfer\n");)
David Miller30091402008-10-22 20:21:30 +0200328 i = -EIO;
329 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 }
Roel Kluin0c168ce2009-03-28 21:34:42 +0100331
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 for (i = 0;ret >= 0 && i < num; i++) {
333 pmsg = &msgs[i];
334
335 DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: Doing %s %d bytes to 0x%02x - %d of %d messages\n",
336 pmsg->flags & I2C_M_RD ? "read" : "write",
Roel Kluin0c168ce2009-03-28 21:34:42 +0100337 pmsg->len, pmsg->addr, i + 1, num);)
338
Jean Delvare6408a832008-01-27 18:14:46 +0100339 ret = pcf_doAddress(adap, pmsg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
341 /* Send START */
Roel Kluin0c168ce2009-03-28 21:34:42 +0100342 if (i == 0)
343 i2c_start(adap);
344
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 /* Wait for PIN (pending interrupt NOT) */
346 timeout = wait_for_pin(adap, &status);
347 if (timeout) {
348 if (timeout == -EINTR) {
349 /* arbitration lost */
David Miller30091402008-10-22 20:21:30 +0200350 i = -EINTR;
351 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 }
353 i2c_stop(adap);
354 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: Timeout waiting "
355 "for PIN(1) in pcf_xfer\n");)
David Miller30091402008-10-22 20:21:30 +0200356 i = -EREMOTEIO;
357 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 }
Roel Kluin0c168ce2009-03-28 21:34:42 +0100359
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 /* Check LRB (last rcvd bit - slave ack) */
361 if (status & I2C_PCF_LRB) {
362 i2c_stop(adap);
363 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: No LRB(1) in pcf_xfer\n");)
David Miller30091402008-10-22 20:21:30 +0200364 i = -EREMOTEIO;
365 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 }
Roel Kluin0c168ce2009-03-28 21:34:42 +0100367
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 DEB3(printk(KERN_DEBUG "i2c-algo-pcf.o: Msg %d, addr=0x%x, flags=0x%x, len=%d\n",
369 i, msgs[i].addr, msgs[i].flags, msgs[i].len);)
Roel Kluin0c168ce2009-03-28 21:34:42 +0100370
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 if (pmsg->flags & I2C_M_RD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 ret = pcf_readbytes(i2c_adap, pmsg->buf, pmsg->len,
Roel Kluin0c168ce2009-03-28 21:34:42 +0100373 (i + 1 == num));
374
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 if (ret != pmsg->len) {
376 DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: fail: "
377 "only read %d bytes.\n",ret));
378 } else {
379 DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: read %d bytes.\n",ret));
380 }
Roel Kluin0c168ce2009-03-28 21:34:42 +0100381 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 ret = pcf_sendbytes(i2c_adap, pmsg->buf, pmsg->len,
Roel Kluin0c168ce2009-03-28 21:34:42 +0100383 (i + 1 == num));
384
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 if (ret != pmsg->len) {
386 DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: fail: "
387 "only wrote %d bytes.\n",ret));
388 } else {
389 DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: wrote %d bytes.\n",ret));
390 }
391 }
392 }
393
David Miller30091402008-10-22 20:21:30 +0200394out:
395 if (adap->xfer_end)
396 adap->xfer_end(adap->data);
Roel Kluin0c168ce2009-03-28 21:34:42 +0100397 return i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398}
399
400static u32 pcf_func(struct i2c_adapter *adap)
401{
Roel Kluin0c168ce2009-03-28 21:34:42 +0100402 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL |
Jean Delvare6408a832008-01-27 18:14:46 +0100403 I2C_FUNC_PROTOCOL_MANGLING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404}
405
Roel Kluin0c168ce2009-03-28 21:34:42 +0100406/* exported algorithm data: */
Jean Delvare9e11a9f2006-09-03 22:38:52 +0200407static const struct i2c_algorithm pcf_algo = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 .master_xfer = pcf_xfer,
409 .functionality = pcf_func,
410};
411
Roel Kluin0c168ce2009-03-28 21:34:42 +0100412/*
413 * registering functions to load algorithms at runtime
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 */
415int i2c_pcf_add_bus(struct i2c_adapter *adap)
416{
417 struct i2c_algo_pcf_data *pcf_adap = adap->algo_data;
418 int rval;
419
420 DEB2(dev_dbg(&adap->dev, "hw routines registered.\n"));
421
422 /* register new adapter to i2c module... */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 adap->algo = &pcf_algo;
Jean Delvare6408a832008-01-27 18:14:46 +0100424 adap->timeout = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
Mark M. Hoffmanb39ad0c2006-07-01 17:16:06 +0200426 if ((rval = pcf_init_8584(pcf_adap)))
427 return rval;
428
429 rval = i2c_add_adapter(adap);
430
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 return rval;
432}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433EXPORT_SYMBOL(i2c_pcf_add_bus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
435MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>");
436MODULE_DESCRIPTION("I2C-Bus PCF8584 algorithm");
437MODULE_LICENSE("GPL");
438
439module_param(i2c_debug, int, S_IRUGO | S_IWUSR);
440MODULE_PARM_DESC(i2c_debug,
Roel Kluin0c168ce2009-03-28 21:34:42 +0100441 "debug level - 0 off; 1 normal; 2,3 more verbose; 9 pcf-protocol");