blob: 7a01f2687b4cc716830b2a1753a142db6aa5d588 [file] [log] [blame]
Thomas Gleixnerc942fdd2019-05-27 08:55:06 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Roel Kluin0c168ce2009-03-28 21:34:42 +01002/*
3 * i2c-algo-pcf.c i2c driver algorithms for PCF8584 adapters
4 *
5 * Copyright (C) 1995-1997 Simon G. Vogl
6 * 1998-2000 Hans Berglund
7 *
Roel Kluin0c168ce2009-03-28 21:34:42 +01008 * With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and
9 * Frodo Looijaard <frodol@dds.nl>, and also from Martin Bailey
10 * <mbailey@littlefeet-inc.com>
11 *
12 * Partially rewriten by Oleg I. Vdovikin <vdovikin@jscc.ru> to handle multiple
13 * messages, proper stop/repstart signaling during receive, added detect code
14 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
16#include <linux/kernel.h>
17#include <linux/module.h>
18#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/errno.h>
20#include <linux/i2c.h>
21#include <linux/i2c-algo-pcf.h>
22#include "i2c-algo-pcf.h"
23
24
Roel Kluin0c168ce2009-03-28 21:34:42 +010025#define DEB2(x) if (i2c_debug >= 2) x
26#define DEB3(x) if (i2c_debug >= 3) x /* print several statistical values */
27#define DEBPROTO(x) if (i2c_debug >= 9) x;
28 /* debug the protocol by showing transferred bits */
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#define DEF_TIMEOUT 16
30
Roel Kluin0c168ce2009-03-28 21:34:42 +010031/*
32 * module parameters:
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 */
34static int i2c_debug;
35
Roel Kluin0c168ce2009-03-28 21:34:42 +010036/* setting states on the bus with the right timing: */
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38#define set_pcf(adap, ctl, val) adap->setpcf(adap->data, ctl, val)
39#define get_pcf(adap, ctl) adap->getpcf(adap->data, ctl)
40#define get_own(adap) adap->getown(adap->data)
41#define get_clock(adap) adap->getclock(adap->data)
42#define i2c_outb(adap, val) adap->setpcf(adap->data, 0, val)
43#define i2c_inb(adap) adap->getpcf(adap->data, 0)
44
Roel Kluin0c168ce2009-03-28 21:34:42 +010045/* other auxiliary functions */
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Roel Kluin0c168ce2009-03-28 21:34:42 +010047static void i2c_start(struct i2c_algo_pcf_data *adap)
Linus Torvalds1da177e2005-04-16 15:20:36 -070048{
Frank Seidel154d22b2009-03-28 21:34:42 +010049 DEBPROTO(printk(KERN_DEBUG "S "));
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 set_pcf(adap, 1, I2C_PCF_START);
51}
52
Roel Kluin0c168ce2009-03-28 21:34:42 +010053static void i2c_repstart(struct i2c_algo_pcf_data *adap)
Linus Torvalds1da177e2005-04-16 15:20:36 -070054{
55 DEBPROTO(printk(" Sr "));
56 set_pcf(adap, 1, I2C_PCF_REPSTART);
57}
58
Roel Kluin0c168ce2009-03-28 21:34:42 +010059static void i2c_stop(struct i2c_algo_pcf_data *adap)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
61 DEBPROTO(printk("P\n"));
62 set_pcf(adap, 1, I2C_PCF_STOP);
63}
64
Eric Brower0573d112008-07-14 22:38:31 +020065static void handle_lab(struct i2c_algo_pcf_data *adap, const int *status)
66{
67 DEB2(printk(KERN_INFO
68 "i2c-algo-pcf.o: lost arbitration (CSR 0x%02x)\n",
Roel Kluin0c168ce2009-03-28 21:34:42 +010069 *status));
70 /*
71 * Cleanup from LAB -- reset and enable ESO.
Eric Brower0573d112008-07-14 22:38:31 +020072 * This resets the PCF8584; since we've lost the bus, no
73 * further attempts should be made by callers to clean up
74 * (no i2c_stop() etc.)
75 */
76 set_pcf(adap, 1, I2C_PCF_PIN);
77 set_pcf(adap, 1, I2C_PCF_ESO);
Roel Kluin0c168ce2009-03-28 21:34:42 +010078 /*
79 * We pause for a time period sufficient for any running
Eric Brower0573d112008-07-14 22:38:31 +020080 * I2C transaction to complete -- the arbitration logic won't
81 * work properly until the next START is seen.
82 * It is assumed the bus driver or client has set a proper value.
83 *
84 * REVISIT: should probably use msleep instead of mdelay if we
85 * know we can sleep.
86 */
87 if (adap->lab_mdelay)
88 mdelay(adap->lab_mdelay);
89
90 DEB2(printk(KERN_INFO
91 "i2c-algo-pcf.o: reset LAB condition (CSR 0x%02x)\n",
92 get_pcf(adap, 1)));
93}
94
Roel Kluin0c168ce2009-03-28 21:34:42 +010095static int wait_for_bb(struct i2c_algo_pcf_data *adap)
96{
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
98 int timeout = DEF_TIMEOUT;
99 int status;
100
101 status = get_pcf(adap, 1);
Roel Kluin0c168ce2009-03-28 21:34:42 +0100102
Roel Kluin94d78e12009-03-28 21:34:42 +0100103 while (!(status & I2C_PCF_BB) && --timeout) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 udelay(100); /* wait for 100 us */
105 status = get_pcf(adap, 1);
106 }
Roel Kluin0c168ce2009-03-28 21:34:42 +0100107
Roel Kluin94d78e12009-03-28 21:34:42 +0100108 if (timeout == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 printk(KERN_ERR "Timeout waiting for Bus Busy\n");
Roel Kluin94d78e12009-03-28 21:34:42 +0100110 return -ETIMEDOUT;
111 }
Roel Kluin0c168ce2009-03-28 21:34:42 +0100112
Roel Kluin94d78e12009-03-28 21:34:42 +0100113 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114}
115
Roel Kluin0c168ce2009-03-28 21:34:42 +0100116static int wait_for_pin(struct i2c_algo_pcf_data *adap, int *status)
117{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
119 int timeout = DEF_TIMEOUT;
120
121 *status = get_pcf(adap, 1);
Roel Kluin0c168ce2009-03-28 21:34:42 +0100122
Roel Kluin94d78e12009-03-28 21:34:42 +0100123 while ((*status & I2C_PCF_PIN) && --timeout) {
David Miller08e53382008-10-22 20:21:29 +0200124 adap->waitforpin(adap->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 *status = get_pcf(adap, 1);
126 }
127 if (*status & I2C_PCF_LAB) {
Eric Brower0573d112008-07-14 22:38:31 +0200128 handle_lab(adap, status);
Roel Kluin0c168ce2009-03-28 21:34:42 +0100129 return -EINTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 }
Roel Kluin0c168ce2009-03-28 21:34:42 +0100131
Roel Kluin94d78e12009-03-28 21:34:42 +0100132 if (timeout == 0)
133 return -ETIMEDOUT;
134
135 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136}
137
Roel Kluin0c168ce2009-03-28 21:34:42 +0100138/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 * This should perform the 'PCF8584 initialization sequence' as described
140 * in the Philips IC12 data book (1995, Aug 29).
141 * There should be a 30 clock cycle wait after reset, I assume this
142 * has been fulfilled.
143 * There should be a delay at the end equal to the longest I2C message
144 * to synchronize the BB-bit (in multimaster systems). How long is
145 * this? I assume 1 second is always long enough.
146 *
147 * vdovikin: added detect code for PCF8584
148 */
149static int pcf_init_8584 (struct i2c_algo_pcf_data *adap)
150{
151 unsigned char temp;
152
Roel Kluin0c168ce2009-03-28 21:34:42 +0100153 DEB3(printk(KERN_DEBUG "i2c-algo-pcf.o: PCF state 0x%02x\n",
154 get_pcf(adap, 1)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
156 /* S1=0x80: S0 selected, serial interface off */
157 set_pcf(adap, 1, I2C_PCF_PIN);
Roel Kluin0c168ce2009-03-28 21:34:42 +0100158 /*
159 * check to see S1 now used as R/W ctrl -
160 * PCF8584 does that when ESO is zero
161 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 if (((temp = get_pcf(adap, 1)) & 0x7f) != (0)) {
163 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S0 (0x%02x).\n", temp));
Uwe Kleine-König7d9b48e2010-01-28 22:09:43 +0100164 return -ENXIO; /* definitely not PCF8584 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 }
166
Roel Kluin0c168ce2009-03-28 21:34:42 +0100167 /* load own address in S0, effective address is (own << 1) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 i2c_outb(adap, get_own(adap));
169 /* check it's really written */
170 if ((temp = i2c_inb(adap)) != get_own(adap)) {
171 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't set S0 (0x%02x).\n", temp));
172 return -ENXIO;
173 }
174
Roel Kluin0c168ce2009-03-28 21:34:42 +0100175 /* S1=0xA0, next byte in S2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 set_pcf(adap, 1, I2C_PCF_PIN | I2C_PCF_ES1);
177 /* check to see S2 now selected */
178 if (((temp = get_pcf(adap, 1)) & 0x7f) != I2C_PCF_ES1) {
179 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S2 (0x%02x).\n", temp));
180 return -ENXIO;
181 }
182
Roel Kluin0c168ce2009-03-28 21:34:42 +0100183 /* load clock register S2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 i2c_outb(adap, get_clock(adap));
185 /* check it's really written, the only 5 lowest bits does matter */
186 if (((temp = i2c_inb(adap)) & 0x1f) != get_clock(adap)) {
187 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't set S2 (0x%02x).\n", temp));
188 return -ENXIO;
189 }
190
Roel Kluin0c168ce2009-03-28 21:34:42 +0100191 /* Enable serial interface, idle, S0 selected */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 set_pcf(adap, 1, I2C_PCF_IDLE);
193
194 /* check to see PCF is really idled and we can access status register */
195 if ((temp = get_pcf(adap, 1)) != (I2C_PCF_PIN | I2C_PCF_BB)) {
196 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S1` (0x%02x).\n", temp));
197 return -ENXIO;
198 }
Roel Kluin0c168ce2009-03-28 21:34:42 +0100199
David Millera672b4c2008-10-22 20:21:30 +0200200 printk(KERN_DEBUG "i2c-algo-pcf.o: detected and initialized PCF8584.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
202 return 0;
203}
204
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205static int pcf_sendbytes(struct i2c_adapter *i2c_adap, const char *buf,
Roel Kluin0c168ce2009-03-28 21:34:42 +0100206 int count, int last)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207{
208 struct i2c_algo_pcf_data *adap = i2c_adap->algo_data;
209 int wrcount, status, timeout;
Roel Kluin0c168ce2009-03-28 21:34:42 +0100210
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 for (wrcount=0; wrcount<count; ++wrcount) {
212 DEB2(dev_dbg(&i2c_adap->dev, "i2c_write: writing %2.2X\n",
Roel Kluin0c168ce2009-03-28 21:34:42 +0100213 buf[wrcount] & 0xff));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 i2c_outb(adap, buf[wrcount]);
215 timeout = wait_for_pin(adap, &status);
216 if (timeout) {
Roel Kluin0c168ce2009-03-28 21:34:42 +0100217 if (timeout == -EINTR)
218 return -EINTR; /* arbitration lost */
219
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 i2c_stop(adap);
221 dev_err(&i2c_adap->dev, "i2c_write: error - timeout.\n");
222 return -EREMOTEIO; /* got a better one ?? */
223 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 if (status & I2C_PCF_LRB) {
225 i2c_stop(adap);
226 dev_err(&i2c_adap->dev, "i2c_write: error - no ack.\n");
227 return -EREMOTEIO; /* got a better one ?? */
228 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 }
Roel Kluin0c168ce2009-03-28 21:34:42 +0100230 if (last)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 i2c_stop(adap);
Roel Kluin0c168ce2009-03-28 21:34:42 +0100232 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 i2c_repstart(adap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
Roel Kluin0c168ce2009-03-28 21:34:42 +0100235 return wrcount;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236}
237
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238static int pcf_readbytes(struct i2c_adapter *i2c_adap, char *buf,
Roel Kluin0c168ce2009-03-28 21:34:42 +0100239 int count, int last)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240{
241 int i, status;
242 struct i2c_algo_pcf_data *adap = i2c_adap->algo_data;
243 int wfp;
244
245 /* increment number of bytes to read by one -- read dummy byte */
246 for (i = 0; i <= count; i++) {
247
248 if ((wfp = wait_for_pin(adap, &status))) {
Roel Kluin0c168ce2009-03-28 21:34:42 +0100249 if (wfp == -EINTR)
250 return -EINTR; /* arbitration lost */
251
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 i2c_stop(adap);
253 dev_err(&i2c_adap->dev, "pcf_readbytes timed out.\n");
Roel Kluin0c168ce2009-03-28 21:34:42 +0100254 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 }
256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 if ((status & I2C_PCF_LRB) && (i != count)) {
258 i2c_stop(adap);
259 dev_err(&i2c_adap->dev, "i2c_read: i2c_inb, No ack.\n");
Roel Kluin0c168ce2009-03-28 21:34:42 +0100260 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 }
Roel Kluin0c168ce2009-03-28 21:34:42 +0100262
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 if (i == count - 1) {
264 set_pcf(adap, 1, I2C_PCF_ESO);
Roel Kluin0c168ce2009-03-28 21:34:42 +0100265 } else if (i == count) {
266 if (last)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 i2c_stop(adap);
Roel Kluin0c168ce2009-03-28 21:34:42 +0100268 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 i2c_repstart(adap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 }
Roel Kluin0c168ce2009-03-28 21:34:42 +0100271
272 if (i)
273 buf[i - 1] = i2c_inb(adap);
274 else
275 i2c_inb(adap); /* dummy read */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 }
277
Roel Kluin0c168ce2009-03-28 21:34:42 +0100278 return i - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279}
280
281
Jean Delvare6408a832008-01-27 18:14:46 +0100282static int pcf_doAddress(struct i2c_algo_pcf_data *adap,
283 struct i2c_msg *msg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284{
Peter Rosinac6d5292018-05-16 09:16:46 +0200285 unsigned char addr = i2c_8bit_addr_from_msg(msg);
Jean Delvare6408a832008-01-27 18:14:46 +0100286
Peter Rosinac6d5292018-05-16 09:16:46 +0200287 if (msg->flags & I2C_M_REV_DIR_ADDR)
Jean Delvare6408a832008-01-27 18:14:46 +0100288 addr ^= 1;
289 i2c_outb(adap, addr);
290
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 return 0;
292}
293
294static int pcf_xfer(struct i2c_adapter *i2c_adap,
Roel Kluin0c168ce2009-03-28 21:34:42 +0100295 struct i2c_msg *msgs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 int num)
297{
298 struct i2c_algo_pcf_data *adap = i2c_adap->algo_data;
299 struct i2c_msg *pmsg;
300 int i;
301 int ret=0, timeout, status;
Roel Kluin0c168ce2009-03-28 21:34:42 +0100302
David Miller30091402008-10-22 20:21:30 +0200303 if (adap->xfer_begin)
304 adap->xfer_begin(adap->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
306 /* Check for bus busy */
307 timeout = wait_for_bb(adap);
308 if (timeout) {
309 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: "
Roel Kluin0c168ce2009-03-28 21:34:42 +0100310 "Timeout waiting for BB in pcf_xfer\n");)
David Miller30091402008-10-22 20:21:30 +0200311 i = -EIO;
312 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 }
Roel Kluin0c168ce2009-03-28 21:34:42 +0100314
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 for (i = 0;ret >= 0 && i < num; i++) {
316 pmsg = &msgs[i];
317
318 DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: Doing %s %d bytes to 0x%02x - %d of %d messages\n",
319 pmsg->flags & I2C_M_RD ? "read" : "write",
Roel Kluin0c168ce2009-03-28 21:34:42 +0100320 pmsg->len, pmsg->addr, i + 1, num);)
321
Jean Delvare6408a832008-01-27 18:14:46 +0100322 ret = pcf_doAddress(adap, pmsg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
324 /* Send START */
Roel Kluin0c168ce2009-03-28 21:34:42 +0100325 if (i == 0)
326 i2c_start(adap);
327
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 /* Wait for PIN (pending interrupt NOT) */
329 timeout = wait_for_pin(adap, &status);
330 if (timeout) {
331 if (timeout == -EINTR) {
332 /* arbitration lost */
David Miller30091402008-10-22 20:21:30 +0200333 i = -EINTR;
334 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 }
336 i2c_stop(adap);
337 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: Timeout waiting "
338 "for PIN(1) in pcf_xfer\n");)
David Miller30091402008-10-22 20:21:30 +0200339 i = -EREMOTEIO;
340 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 }
Roel Kluin0c168ce2009-03-28 21:34:42 +0100342
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 /* Check LRB (last rcvd bit - slave ack) */
344 if (status & I2C_PCF_LRB) {
345 i2c_stop(adap);
346 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: No LRB(1) in pcf_xfer\n");)
David Miller30091402008-10-22 20:21:30 +0200347 i = -EREMOTEIO;
348 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 }
Roel Kluin0c168ce2009-03-28 21:34:42 +0100350
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 DEB3(printk(KERN_DEBUG "i2c-algo-pcf.o: Msg %d, addr=0x%x, flags=0x%x, len=%d\n",
352 i, msgs[i].addr, msgs[i].flags, msgs[i].len);)
Roel Kluin0c168ce2009-03-28 21:34:42 +0100353
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 if (pmsg->flags & I2C_M_RD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 ret = pcf_readbytes(i2c_adap, pmsg->buf, pmsg->len,
Roel Kluin0c168ce2009-03-28 21:34:42 +0100356 (i + 1 == num));
357
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 if (ret != pmsg->len) {
359 DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: fail: "
360 "only read %d bytes.\n",ret));
361 } else {
362 DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: read %d bytes.\n",ret));
363 }
Roel Kluin0c168ce2009-03-28 21:34:42 +0100364 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 ret = pcf_sendbytes(i2c_adap, pmsg->buf, pmsg->len,
Roel Kluin0c168ce2009-03-28 21:34:42 +0100366 (i + 1 == num));
367
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 if (ret != pmsg->len) {
369 DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: fail: "
370 "only wrote %d bytes.\n",ret));
371 } else {
372 DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: wrote %d bytes.\n",ret));
373 }
374 }
375 }
376
David Miller30091402008-10-22 20:21:30 +0200377out:
378 if (adap->xfer_end)
379 adap->xfer_end(adap->data);
Roel Kluin0c168ce2009-03-28 21:34:42 +0100380 return i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381}
382
383static u32 pcf_func(struct i2c_adapter *adap)
384{
Roel Kluin0c168ce2009-03-28 21:34:42 +0100385 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL |
Jean Delvare6408a832008-01-27 18:14:46 +0100386 I2C_FUNC_PROTOCOL_MANGLING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387}
388
Roel Kluin0c168ce2009-03-28 21:34:42 +0100389/* exported algorithm data: */
Jean Delvare9e11a9f2006-09-03 22:38:52 +0200390static const struct i2c_algorithm pcf_algo = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 .master_xfer = pcf_xfer,
392 .functionality = pcf_func,
393};
394
Roel Kluin0c168ce2009-03-28 21:34:42 +0100395/*
396 * registering functions to load algorithms at runtime
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 */
398int i2c_pcf_add_bus(struct i2c_adapter *adap)
399{
400 struct i2c_algo_pcf_data *pcf_adap = adap->algo_data;
401 int rval;
402
403 DEB2(dev_dbg(&adap->dev, "hw routines registered.\n"));
404
405 /* register new adapter to i2c module... */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 adap->algo = &pcf_algo;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Mark M. Hoffmanb39ad0c2006-07-01 17:16:06 +0200408 if ((rval = pcf_init_8584(pcf_adap)))
409 return rval;
410
411 rval = i2c_add_adapter(adap);
412
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 return rval;
414}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415EXPORT_SYMBOL(i2c_pcf_add_bus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
417MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>");
418MODULE_DESCRIPTION("I2C-Bus PCF8584 algorithm");
419MODULE_LICENSE("GPL");
420
421module_param(i2c_debug, int, S_IRUGO | S_IWUSR);
422MODULE_PARM_DESC(i2c_debug,
Roel Kluin0c168ce2009-03-28 21:34:42 +0100423 "debug level - 0 off; 1 normal; 2,3 more verbose; 9 pcf-protocol");