]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/i2c/i2c-core-smbus.c
x86/speculation/mds: Add mitigation control for MDS
[mirror_ubuntu-bionic-kernel.git] / drivers / i2c / i2c-core-smbus.c
CommitLineData
22c78d1c
WS
1/*
2 * Linux I2C core SMBus and SMBus emulation code
3 *
4 * This file contains the SMBus functions which are always included in the I2C
5 * core because they can be emulated via I2C. SMBus specific extensions
6 * (e.g. smbalert) are handled in a seperate i2c-smbus module.
7 *
8 * All SMBus-related things are written by Frodo Looijaard <frodol@dds.nl>
9 * SMBus 2.0 support by Mark Studebaker <mdsxyz123@yahoo.com> and
10 * Jean Delvare <jdelvare@suse.de>
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the Free
14 * Software Foundation; either version 2 of the License, or (at your option)
15 * any later version.
16 */
17#include <linux/device.h>
18#include <linux/err.h>
19#include <linux/i2c.h>
3c0a60be 20#include <linux/i2c-smbus.h>
22c78d1c
WS
21
22#define CREATE_TRACE_POINTS
23#include <trace/events/smbus.h>
24
25
26/* The SMBus parts */
27
28#define POLY (0x1070U << 3)
29static u8 crc8(u16 data)
30{
31 int i;
32
33 for (i = 0; i < 8; i++) {
34 if (data & 0x8000)
35 data = data ^ POLY;
36 data = data << 1;
37 }
38 return (u8)(data >> 8);
39}
40
41/* Incremental CRC8 over count bytes in the array pointed to by p */
42static u8 i2c_smbus_pec(u8 crc, u8 *p, size_t count)
43{
44 int i;
45
46 for (i = 0; i < count; i++)
47 crc = crc8((crc ^ p[i]) << 8);
48 return crc;
49}
50
51/* Assume a 7-bit address, which is reasonable for SMBus */
52static u8 i2c_smbus_msg_pec(u8 pec, struct i2c_msg *msg)
53{
54 /* The address will be sent first */
55 u8 addr = i2c_8bit_addr_from_msg(msg);
56 pec = i2c_smbus_pec(pec, &addr, 1);
57
58 /* The data buffer follows */
59 return i2c_smbus_pec(pec, msg->buf, msg->len);
60}
61
62/* Used for write only transactions */
63static inline void i2c_smbus_add_pec(struct i2c_msg *msg)
64{
65 msg->buf[msg->len] = i2c_smbus_msg_pec(0, msg);
66 msg->len++;
67}
68
69/* Return <0 on CRC error
70 If there was a write before this read (most cases) we need to take the
71 partial CRC from the write part into account.
72 Note that this function does modify the message (we need to decrease the
73 message length to hide the CRC byte from the caller). */
74static int i2c_smbus_check_pec(u8 cpec, struct i2c_msg *msg)
75{
76 u8 rpec = msg->buf[--msg->len];
77 cpec = i2c_smbus_msg_pec(cpec, msg);
78
79 if (rpec != cpec) {
80 pr_debug("Bad PEC 0x%02x vs. 0x%02x\n",
81 rpec, cpec);
82 return -EBADMSG;
83 }
84 return 0;
85}
86
87/**
88 * i2c_smbus_read_byte - SMBus "receive byte" protocol
89 * @client: Handle to slave device
90 *
91 * This executes the SMBus "receive byte" protocol, returning negative errno
92 * else the byte received from the device.
93 */
94s32 i2c_smbus_read_byte(const struct i2c_client *client)
95{
96 union i2c_smbus_data data;
97 int status;
98
99 status = i2c_smbus_xfer(client->adapter, client->addr, client->flags,
100 I2C_SMBUS_READ, 0,
101 I2C_SMBUS_BYTE, &data);
102 return (status < 0) ? status : data.byte;
103}
104EXPORT_SYMBOL(i2c_smbus_read_byte);
105
106/**
107 * i2c_smbus_write_byte - SMBus "send byte" protocol
108 * @client: Handle to slave device
109 * @value: Byte to be sent
110 *
111 * This executes the SMBus "send byte" protocol, returning negative errno
112 * else zero on success.
113 */
114s32 i2c_smbus_write_byte(const struct i2c_client *client, u8 value)
115{
116 return i2c_smbus_xfer(client->adapter, client->addr, client->flags,
117 I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL);
118}
119EXPORT_SYMBOL(i2c_smbus_write_byte);
120
121/**
122 * i2c_smbus_read_byte_data - SMBus "read byte" protocol
123 * @client: Handle to slave device
124 * @command: Byte interpreted by slave
125 *
126 * This executes the SMBus "read byte" protocol, returning negative errno
127 * else a data byte received from the device.
128 */
129s32 i2c_smbus_read_byte_data(const struct i2c_client *client, u8 command)
130{
131 union i2c_smbus_data data;
132 int status;
133
134 status = i2c_smbus_xfer(client->adapter, client->addr, client->flags,
135 I2C_SMBUS_READ, command,
136 I2C_SMBUS_BYTE_DATA, &data);
137 return (status < 0) ? status : data.byte;
138}
139EXPORT_SYMBOL(i2c_smbus_read_byte_data);
140
141/**
142 * i2c_smbus_write_byte_data - SMBus "write byte" protocol
143 * @client: Handle to slave device
144 * @command: Byte interpreted by slave
145 * @value: Byte being written
146 *
147 * This executes the SMBus "write byte" protocol, returning negative errno
148 * else zero on success.
149 */
150s32 i2c_smbus_write_byte_data(const struct i2c_client *client, u8 command,
151 u8 value)
152{
153 union i2c_smbus_data data;
154 data.byte = value;
155 return i2c_smbus_xfer(client->adapter, client->addr, client->flags,
156 I2C_SMBUS_WRITE, command,
157 I2C_SMBUS_BYTE_DATA, &data);
158}
159EXPORT_SYMBOL(i2c_smbus_write_byte_data);
160
161/**
162 * i2c_smbus_read_word_data - SMBus "read word" protocol
163 * @client: Handle to slave device
164 * @command: Byte interpreted by slave
165 *
166 * This executes the SMBus "read word" protocol, returning negative errno
167 * else a 16-bit unsigned "word" received from the device.
168 */
169s32 i2c_smbus_read_word_data(const struct i2c_client *client, u8 command)
170{
171 union i2c_smbus_data data;
172 int status;
173
174 status = i2c_smbus_xfer(client->adapter, client->addr, client->flags,
175 I2C_SMBUS_READ, command,
176 I2C_SMBUS_WORD_DATA, &data);
177 return (status < 0) ? status : data.word;
178}
179EXPORT_SYMBOL(i2c_smbus_read_word_data);
180
181/**
182 * i2c_smbus_write_word_data - SMBus "write word" protocol
183 * @client: Handle to slave device
184 * @command: Byte interpreted by slave
185 * @value: 16-bit "word" being written
186 *
187 * This executes the SMBus "write word" protocol, returning negative errno
188 * else zero on success.
189 */
190s32 i2c_smbus_write_word_data(const struct i2c_client *client, u8 command,
191 u16 value)
192{
193 union i2c_smbus_data data;
194 data.word = value;
195 return i2c_smbus_xfer(client->adapter, client->addr, client->flags,
196 I2C_SMBUS_WRITE, command,
197 I2C_SMBUS_WORD_DATA, &data);
198}
199EXPORT_SYMBOL(i2c_smbus_write_word_data);
200
201/**
202 * i2c_smbus_read_block_data - SMBus "block read" protocol
203 * @client: Handle to slave device
204 * @command: Byte interpreted by slave
205 * @values: Byte array into which data will be read; big enough to hold
206 * the data returned by the slave. SMBus allows at most 32 bytes.
207 *
208 * This executes the SMBus "block read" protocol, returning negative errno
209 * else the number of data bytes in the slave's response.
210 *
211 * Note that using this function requires that the client's adapter support
212 * the I2C_FUNC_SMBUS_READ_BLOCK_DATA functionality. Not all adapter drivers
213 * support this; its emulation through I2C messaging relies on a specific
214 * mechanism (I2C_M_RECV_LEN) which may not be implemented.
215 */
216s32 i2c_smbus_read_block_data(const struct i2c_client *client, u8 command,
217 u8 *values)
218{
219 union i2c_smbus_data data;
220 int status;
221
222 status = i2c_smbus_xfer(client->adapter, client->addr, client->flags,
223 I2C_SMBUS_READ, command,
224 I2C_SMBUS_BLOCK_DATA, &data);
225 if (status)
226 return status;
227
228 memcpy(values, &data.block[1], data.block[0]);
229 return data.block[0];
230}
231EXPORT_SYMBOL(i2c_smbus_read_block_data);
232
233/**
234 * i2c_smbus_write_block_data - SMBus "block write" protocol
235 * @client: Handle to slave device
236 * @command: Byte interpreted by slave
237 * @length: Size of data block; SMBus allows at most 32 bytes
238 * @values: Byte array which will be written.
239 *
240 * This executes the SMBus "block write" protocol, returning negative errno
241 * else zero on success.
242 */
243s32 i2c_smbus_write_block_data(const struct i2c_client *client, u8 command,
244 u8 length, const u8 *values)
245{
246 union i2c_smbus_data data;
247
248 if (length > I2C_SMBUS_BLOCK_MAX)
249 length = I2C_SMBUS_BLOCK_MAX;
250 data.block[0] = length;
251 memcpy(&data.block[1], values, length);
252 return i2c_smbus_xfer(client->adapter, client->addr, client->flags,
253 I2C_SMBUS_WRITE, command,
254 I2C_SMBUS_BLOCK_DATA, &data);
255}
256EXPORT_SYMBOL(i2c_smbus_write_block_data);
257
258/* Returns the number of read bytes */
259s32 i2c_smbus_read_i2c_block_data(const struct i2c_client *client, u8 command,
260 u8 length, u8 *values)
261{
262 union i2c_smbus_data data;
263 int status;
264
265 if (length > I2C_SMBUS_BLOCK_MAX)
266 length = I2C_SMBUS_BLOCK_MAX;
267 data.block[0] = length;
268 status = i2c_smbus_xfer(client->adapter, client->addr, client->flags,
269 I2C_SMBUS_READ, command,
270 I2C_SMBUS_I2C_BLOCK_DATA, &data);
271 if (status < 0)
272 return status;
273
274 memcpy(values, &data.block[1], data.block[0]);
275 return data.block[0];
276}
277EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data);
278
279s32 i2c_smbus_write_i2c_block_data(const struct i2c_client *client, u8 command,
280 u8 length, const u8 *values)
281{
282 union i2c_smbus_data data;
283
284 if (length > I2C_SMBUS_BLOCK_MAX)
285 length = I2C_SMBUS_BLOCK_MAX;
286 data.block[0] = length;
287 memcpy(data.block + 1, values, length);
288 return i2c_smbus_xfer(client->adapter, client->addr, client->flags,
289 I2C_SMBUS_WRITE, command,
290 I2C_SMBUS_I2C_BLOCK_DATA, &data);
291}
292EXPORT_SYMBOL(i2c_smbus_write_i2c_block_data);
293
294/* Simulate a SMBus command using the i2c protocol
295 No checking of parameters is done! */
296static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr,
297 unsigned short flags,
298 char read_write, u8 command, int size,
299 union i2c_smbus_data *data)
300{
301 /* So we need to generate a series of msgs. In the case of writing, we
302 need to use only one message; when reading, we need two. We initialize
303 most things with sane defaults, to keep the code below somewhat
304 simpler. */
305 unsigned char msgbuf0[I2C_SMBUS_BLOCK_MAX+3];
306 unsigned char msgbuf1[I2C_SMBUS_BLOCK_MAX+2];
307 int num = read_write == I2C_SMBUS_READ ? 2 : 1;
308 int i;
309 u8 partial_pec = 0;
310 int status;
311 struct i2c_msg msg[2] = {
312 {
313 .addr = addr,
314 .flags = flags,
315 .len = 1,
316 .buf = msgbuf0,
317 }, {
318 .addr = addr,
319 .flags = flags | I2C_M_RD,
320 .len = 0,
321 .buf = msgbuf1,
322 },
323 };
324
325 msgbuf0[0] = command;
326 switch (size) {
327 case I2C_SMBUS_QUICK:
328 msg[0].len = 0;
329 /* Special case: The read/write field is used as data */
330 msg[0].flags = flags | (read_write == I2C_SMBUS_READ ?
331 I2C_M_RD : 0);
332 num = 1;
333 break;
334 case I2C_SMBUS_BYTE:
335 if (read_write == I2C_SMBUS_READ) {
336 /* Special case: only a read! */
337 msg[0].flags = I2C_M_RD | flags;
338 num = 1;
339 }
340 break;
341 case I2C_SMBUS_BYTE_DATA:
342 if (read_write == I2C_SMBUS_READ)
343 msg[1].len = 1;
344 else {
345 msg[0].len = 2;
346 msgbuf0[1] = data->byte;
347 }
348 break;
349 case I2C_SMBUS_WORD_DATA:
350 if (read_write == I2C_SMBUS_READ)
351 msg[1].len = 2;
352 else {
353 msg[0].len = 3;
354 msgbuf0[1] = data->word & 0xff;
355 msgbuf0[2] = data->word >> 8;
356 }
357 break;
358 case I2C_SMBUS_PROC_CALL:
359 num = 2; /* Special case */
360 read_write = I2C_SMBUS_READ;
361 msg[0].len = 3;
362 msg[1].len = 2;
363 msgbuf0[1] = data->word & 0xff;
364 msgbuf0[2] = data->word >> 8;
365 break;
366 case I2C_SMBUS_BLOCK_DATA:
367 if (read_write == I2C_SMBUS_READ) {
368 msg[1].flags |= I2C_M_RECV_LEN;
369 msg[1].len = 1; /* block length will be added by
370 the underlying bus driver */
371 } else {
372 msg[0].len = data->block[0] + 2;
373 if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 2) {
374 dev_err(&adapter->dev,
375 "Invalid block write size %d\n",
376 data->block[0]);
377 return -EINVAL;
378 }
379 for (i = 1; i < msg[0].len; i++)
380 msgbuf0[i] = data->block[i-1];
381 }
382 break;
383 case I2C_SMBUS_BLOCK_PROC_CALL:
384 num = 2; /* Another special case */
385 read_write = I2C_SMBUS_READ;
386 if (data->block[0] > I2C_SMBUS_BLOCK_MAX) {
387 dev_err(&adapter->dev,
388 "Invalid block write size %d\n",
389 data->block[0]);
390 return -EINVAL;
391 }
392 msg[0].len = data->block[0] + 2;
393 for (i = 1; i < msg[0].len; i++)
394 msgbuf0[i] = data->block[i-1];
395 msg[1].flags |= I2C_M_RECV_LEN;
396 msg[1].len = 1; /* block length will be added by
397 the underlying bus driver */
398 break;
399 case I2C_SMBUS_I2C_BLOCK_DATA:
89c6efa6
JC
400 if (data->block[0] > I2C_SMBUS_BLOCK_MAX) {
401 dev_err(&adapter->dev, "Invalid block %s size %d\n",
402 read_write == I2C_SMBUS_READ ? "read" : "write",
403 data->block[0]);
404 return -EINVAL;
405 }
406
22c78d1c
WS
407 if (read_write == I2C_SMBUS_READ) {
408 msg[1].len = data->block[0];
409 } else {
410 msg[0].len = data->block[0] + 1;
22c78d1c
WS
411 for (i = 1; i <= data->block[0]; i++)
412 msgbuf0[i] = data->block[i];
413 }
414 break;
415 default:
416 dev_err(&adapter->dev, "Unsupported transaction %d\n", size);
417 return -EOPNOTSUPP;
418 }
419
420 i = ((flags & I2C_CLIENT_PEC) && size != I2C_SMBUS_QUICK
421 && size != I2C_SMBUS_I2C_BLOCK_DATA);
422 if (i) {
423 /* Compute PEC if first message is a write */
424 if (!(msg[0].flags & I2C_M_RD)) {
425 if (num == 1) /* Write only */
426 i2c_smbus_add_pec(&msg[0]);
427 else /* Write followed by read */
428 partial_pec = i2c_smbus_msg_pec(0, &msg[0]);
429 }
430 /* Ask for PEC if last message is a read */
431 if (msg[num-1].flags & I2C_M_RD)
432 msg[num-1].len++;
433 }
434
435 status = i2c_transfer(adapter, msg, num);
436 if (status < 0)
437 return status;
67f3efd5
WW
438 if (status != num)
439 return -EIO;
22c78d1c
WS
440
441 /* Check PEC if last message is a read */
442 if (i && (msg[num-1].flags & I2C_M_RD)) {
443 status = i2c_smbus_check_pec(partial_pec, &msg[num-1]);
444 if (status < 0)
445 return status;
446 }
447
448 if (read_write == I2C_SMBUS_READ)
449 switch (size) {
450 case I2C_SMBUS_BYTE:
451 data->byte = msgbuf0[0];
452 break;
453 case I2C_SMBUS_BYTE_DATA:
454 data->byte = msgbuf1[0];
455 break;
456 case I2C_SMBUS_WORD_DATA:
457 case I2C_SMBUS_PROC_CALL:
458 data->word = msgbuf1[0] | (msgbuf1[1] << 8);
459 break;
460 case I2C_SMBUS_I2C_BLOCK_DATA:
461 for (i = 0; i < data->block[0]; i++)
462 data->block[i+1] = msgbuf1[i];
463 break;
464 case I2C_SMBUS_BLOCK_DATA:
465 case I2C_SMBUS_BLOCK_PROC_CALL:
466 for (i = 0; i < msgbuf1[0] + 1; i++)
467 data->block[i] = msgbuf1[i];
468 break;
469 }
470 return 0;
471}
472
473/**
474 * i2c_smbus_xfer - execute SMBus protocol operations
475 * @adapter: Handle to I2C bus
476 * @addr: Address of SMBus slave on that bus
477 * @flags: I2C_CLIENT_* flags (usually zero or I2C_CLIENT_PEC)
478 * @read_write: I2C_SMBUS_READ or I2C_SMBUS_WRITE
479 * @command: Byte interpreted by slave, for protocols which use such bytes
480 * @protocol: SMBus protocol operation to execute, such as I2C_SMBUS_PROC_CALL
481 * @data: Data to be read or written
482 *
483 * This executes an SMBus protocol operation, and returns a negative
484 * errno code else zero on success.
485 */
486s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags,
487 char read_write, u8 command, int protocol,
488 union i2c_smbus_data *data)
489{
490 unsigned long orig_jiffies;
491 int try;
492 s32 res;
493
494 /* If enabled, the following two tracepoints are conditional on
495 * read_write and protocol.
496 */
497 trace_smbus_write(adapter, addr, flags, read_write,
498 command, protocol, data);
499 trace_smbus_read(adapter, addr, flags, read_write,
500 command, protocol);
501
502 flags &= I2C_M_TEN | I2C_CLIENT_PEC | I2C_CLIENT_SCCB;
503
504 if (adapter->algo->smbus_xfer) {
505 i2c_lock_bus(adapter, I2C_LOCK_SEGMENT);
506
507 /* Retry automatically on arbitration loss */
508 orig_jiffies = jiffies;
509 for (res = 0, try = 0; try <= adapter->retries; try++) {
510 res = adapter->algo->smbus_xfer(adapter, addr, flags,
511 read_write, command,
512 protocol, data);
513 if (res != -EAGAIN)
514 break;
515 if (time_after(jiffies,
516 orig_jiffies + adapter->timeout))
517 break;
518 }
519 i2c_unlock_bus(adapter, I2C_LOCK_SEGMENT);
520
521 if (res != -EOPNOTSUPP || !adapter->algo->master_xfer)
522 goto trace;
523 /*
524 * Fall back to i2c_smbus_xfer_emulated if the adapter doesn't
525 * implement native support for the SMBus operation.
526 */
527 }
528
529 res = i2c_smbus_xfer_emulated(adapter, addr, flags, read_write,
530 command, protocol, data);
531
532trace:
533 /* If enabled, the reply tracepoint is conditional on read_write. */
534 trace_smbus_reply(adapter, addr, flags, read_write,
535 command, protocol, data);
536 trace_smbus_result(adapter, addr, flags, read_write,
537 command, protocol, res);
538
539 return res;
540}
541EXPORT_SYMBOL(i2c_smbus_xfer);
542
543/**
544 * i2c_smbus_read_i2c_block_data_or_emulated - read block or emulate
545 * @client: Handle to slave device
546 * @command: Byte interpreted by slave
547 * @length: Size of data block; SMBus allows at most I2C_SMBUS_BLOCK_MAX bytes
548 * @values: Byte array into which data will be read; big enough to hold
549 * the data returned by the slave. SMBus allows at most
550 * I2C_SMBUS_BLOCK_MAX bytes.
551 *
552 * This executes the SMBus "block read" protocol if supported by the adapter.
553 * If block read is not supported, it emulates it using either word or byte
554 * read protocols depending on availability.
555 *
556 * The addresses of the I2C slave device that are accessed with this function
557 * must be mapped to a linear region, so that a block read will have the same
558 * effect as a byte read. Before using this function you must double-check
559 * if the I2C slave does support exchanging a block transfer with a byte
560 * transfer.
561 */
562s32 i2c_smbus_read_i2c_block_data_or_emulated(const struct i2c_client *client,
563 u8 command, u8 length, u8 *values)
564{
565 u8 i = 0;
566 int status;
567
568 if (length > I2C_SMBUS_BLOCK_MAX)
569 length = I2C_SMBUS_BLOCK_MAX;
570
571 if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK))
572 return i2c_smbus_read_i2c_block_data(client, command, length, values);
573
574 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_BYTE_DATA))
575 return -EOPNOTSUPP;
576
577 if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_WORD_DATA)) {
578 while ((i + 2) <= length) {
579 status = i2c_smbus_read_word_data(client, command + i);
580 if (status < 0)
581 return status;
582 values[i] = status & 0xff;
583 values[i + 1] = status >> 8;
584 i += 2;
585 }
586 }
587
588 while (i < length) {
589 status = i2c_smbus_read_byte_data(client, command + i);
590 if (status < 0)
591 return status;
592 values[i] = status;
593 i++;
594 }
595
596 return i;
597}
598EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data_or_emulated);
3c0a60be
PR
599
600/**
601 * i2c_setup_smbus_alert - Setup SMBus alert support
602 * @adapter: the target adapter
603 * @setup: setup data for the SMBus alert handler
604 * Context: can sleep
605 *
606 * Setup handling of the SMBus alert protocol on a given I2C bus segment.
607 *
608 * Handling can be done either through our IRQ handler, or by the
609 * adapter (from its handler, periodic polling, or whatever).
610 *
611 * NOTE that if we manage the IRQ, we *MUST* know if it's level or
612 * edge triggered in order to hand it to the workqueue correctly.
613 * If triggering the alert seems to wedge the system, you probably
614 * should have said it's level triggered.
615 *
616 * This returns the ara client, which should be saved for later use with
617 * i2c_handle_smbus_alert() and ultimately i2c_unregister_device(); or NULL
618 * to indicate an error.
619 */
620struct i2c_client *i2c_setup_smbus_alert(struct i2c_adapter *adapter,
621 struct i2c_smbus_alert_setup *setup)
622{
623 struct i2c_board_info ara_board_info = {
624 I2C_BOARD_INFO("smbus_alert", 0x0c),
625 .platform_data = setup,
626 };
627
628 return i2c_new_device(adapter, &ara_board_info);
629}
630EXPORT_SYMBOL_GPL(i2c_setup_smbus_alert);
69d17246
PR
631
632#if IS_ENABLED(CONFIG_I2C_SMBUS) && IS_ENABLED(CONFIG_OF)
633int of_i2c_setup_smbus_alert(struct i2c_adapter *adapter)
634{
635 struct i2c_client *client;
636 int irq;
637
638 irq = of_property_match_string(adapter->dev.of_node, "interrupt-names",
639 "smbus_alert");
640 if (irq == -EINVAL || irq == -ENODATA)
641 return 0;
642 else if (irq < 0)
643 return irq;
644
645 client = i2c_setup_smbus_alert(adapter, NULL);
646 if (!client)
647 return -ENODEV;
648
649 return 0;
650}
651EXPORT_SYMBOL_GPL(of_i2c_setup_smbus_alert);
652#endif