i2c-core-smbus.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  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>
  20. #define CREATE_TRACE_POINTS
  21. #include <trace/events/smbus.h>
  22. /* The SMBus parts */
  23. #define POLY (0x1070U << 3)
  24. static u8 crc8(u16 data)
  25. {
  26. int i;
  27. for (i = 0; i < 8; i++) {
  28. if (data & 0x8000)
  29. data = data ^ POLY;
  30. data = data << 1;
  31. }
  32. return (u8)(data >> 8);
  33. }
  34. /* Incremental CRC8 over count bytes in the array pointed to by p */
  35. static u8 i2c_smbus_pec(u8 crc, u8 *p, size_t count)
  36. {
  37. int i;
  38. for (i = 0; i < count; i++)
  39. crc = crc8((crc ^ p[i]) << 8);
  40. return crc;
  41. }
  42. /* Assume a 7-bit address, which is reasonable for SMBus */
  43. static u8 i2c_smbus_msg_pec(u8 pec, struct i2c_msg *msg)
  44. {
  45. /* The address will be sent first */
  46. u8 addr = i2c_8bit_addr_from_msg(msg);
  47. pec = i2c_smbus_pec(pec, &addr, 1);
  48. /* The data buffer follows */
  49. return i2c_smbus_pec(pec, msg->buf, msg->len);
  50. }
  51. /* Used for write only transactions */
  52. static inline void i2c_smbus_add_pec(struct i2c_msg *msg)
  53. {
  54. msg->buf[msg->len] = i2c_smbus_msg_pec(0, msg);
  55. msg->len++;
  56. }
  57. /* Return <0 on CRC error
  58. If there was a write before this read (most cases) we need to take the
  59. partial CRC from the write part into account.
  60. Note that this function does modify the message (we need to decrease the
  61. message length to hide the CRC byte from the caller). */
  62. static int i2c_smbus_check_pec(u8 cpec, struct i2c_msg *msg)
  63. {
  64. u8 rpec = msg->buf[--msg->len];
  65. cpec = i2c_smbus_msg_pec(cpec, msg);
  66. if (rpec != cpec) {
  67. pr_debug("Bad PEC 0x%02x vs. 0x%02x\n",
  68. rpec, cpec);
  69. return -EBADMSG;
  70. }
  71. return 0;
  72. }
  73. /**
  74. * i2c_smbus_read_byte - SMBus "receive byte" protocol
  75. * @client: Handle to slave device
  76. *
  77. * This executes the SMBus "receive byte" protocol, returning negative errno
  78. * else the byte received from the device.
  79. */
  80. s32 i2c_smbus_read_byte(const struct i2c_client *client)
  81. {
  82. union i2c_smbus_data data;
  83. int status;
  84. status = i2c_smbus_xfer(client->adapter, client->addr, client->flags,
  85. I2C_SMBUS_READ, 0,
  86. I2C_SMBUS_BYTE, &data);
  87. return (status < 0) ? status : data.byte;
  88. }
  89. EXPORT_SYMBOL(i2c_smbus_read_byte);
  90. /**
  91. * i2c_smbus_write_byte - SMBus "send byte" protocol
  92. * @client: Handle to slave device
  93. * @value: Byte to be sent
  94. *
  95. * This executes the SMBus "send byte" protocol, returning negative errno
  96. * else zero on success.
  97. */
  98. s32 i2c_smbus_write_byte(const struct i2c_client *client, u8 value)
  99. {
  100. return i2c_smbus_xfer(client->adapter, client->addr, client->flags,
  101. I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL);
  102. }
  103. EXPORT_SYMBOL(i2c_smbus_write_byte);
  104. /**
  105. * i2c_smbus_read_byte_data - SMBus "read byte" protocol
  106. * @client: Handle to slave device
  107. * @command: Byte interpreted by slave
  108. *
  109. * This executes the SMBus "read byte" protocol, returning negative errno
  110. * else a data byte received from the device.
  111. */
  112. s32 i2c_smbus_read_byte_data(const struct i2c_client *client, u8 command)
  113. {
  114. union i2c_smbus_data data;
  115. int status;
  116. status = i2c_smbus_xfer(client->adapter, client->addr, client->flags,
  117. I2C_SMBUS_READ, command,
  118. I2C_SMBUS_BYTE_DATA, &data);
  119. return (status < 0) ? status : data.byte;
  120. }
  121. EXPORT_SYMBOL(i2c_smbus_read_byte_data);
  122. /**
  123. * i2c_smbus_write_byte_data - SMBus "write byte" protocol
  124. * @client: Handle to slave device
  125. * @command: Byte interpreted by slave
  126. * @value: Byte being written
  127. *
  128. * This executes the SMBus "write byte" protocol, returning negative errno
  129. * else zero on success.
  130. */
  131. s32 i2c_smbus_write_byte_data(const struct i2c_client *client, u8 command,
  132. u8 value)
  133. {
  134. union i2c_smbus_data data;
  135. data.byte = value;
  136. return i2c_smbus_xfer(client->adapter, client->addr, client->flags,
  137. I2C_SMBUS_WRITE, command,
  138. I2C_SMBUS_BYTE_DATA, &data);
  139. }
  140. EXPORT_SYMBOL(i2c_smbus_write_byte_data);
  141. /**
  142. * i2c_smbus_read_word_data - SMBus "read word" protocol
  143. * @client: Handle to slave device
  144. * @command: Byte interpreted by slave
  145. *
  146. * This executes the SMBus "read word" protocol, returning negative errno
  147. * else a 16-bit unsigned "word" received from the device.
  148. */
  149. s32 i2c_smbus_read_word_data(const struct i2c_client *client, u8 command)
  150. {
  151. union i2c_smbus_data data;
  152. int status;
  153. status = i2c_smbus_xfer(client->adapter, client->addr, client->flags,
  154. I2C_SMBUS_READ, command,
  155. I2C_SMBUS_WORD_DATA, &data);
  156. return (status < 0) ? status : data.word;
  157. }
  158. EXPORT_SYMBOL(i2c_smbus_read_word_data);
  159. /**
  160. * i2c_smbus_write_word_data - SMBus "write word" protocol
  161. * @client: Handle to slave device
  162. * @command: Byte interpreted by slave
  163. * @value: 16-bit "word" being written
  164. *
  165. * This executes the SMBus "write word" protocol, returning negative errno
  166. * else zero on success.
  167. */
  168. s32 i2c_smbus_write_word_data(const struct i2c_client *client, u8 command,
  169. u16 value)
  170. {
  171. union i2c_smbus_data data;
  172. data.word = value;
  173. return i2c_smbus_xfer(client->adapter, client->addr, client->flags,
  174. I2C_SMBUS_WRITE, command,
  175. I2C_SMBUS_WORD_DATA, &data);
  176. }
  177. EXPORT_SYMBOL(i2c_smbus_write_word_data);
  178. /**
  179. * i2c_smbus_read_block_data - SMBus "block read" protocol
  180. * @client: Handle to slave device
  181. * @command: Byte interpreted by slave
  182. * @values: Byte array into which data will be read; big enough to hold
  183. * the data returned by the slave. SMBus allows at most 32 bytes.
  184. *
  185. * This executes the SMBus "block read" protocol, returning negative errno
  186. * else the number of data bytes in the slave's response.
  187. *
  188. * Note that using this function requires that the client's adapter support
  189. * the I2C_FUNC_SMBUS_READ_BLOCK_DATA functionality. Not all adapter drivers
  190. * support this; its emulation through I2C messaging relies on a specific
  191. * mechanism (I2C_M_RECV_LEN) which may not be implemented.
  192. */
  193. s32 i2c_smbus_read_block_data(const struct i2c_client *client, u8 command,
  194. u8 *values)
  195. {
  196. union i2c_smbus_data data;
  197. int status;
  198. status = i2c_smbus_xfer(client->adapter, client->addr, client->flags,
  199. I2C_SMBUS_READ, command,
  200. I2C_SMBUS_BLOCK_DATA, &data);
  201. if (status)
  202. return status;
  203. memcpy(values, &data.block[1], data.block[0]);
  204. return data.block[0];
  205. }
  206. EXPORT_SYMBOL(i2c_smbus_read_block_data);
  207. /**
  208. * i2c_smbus_write_block_data - SMBus "block write" protocol
  209. * @client: Handle to slave device
  210. * @command: Byte interpreted by slave
  211. * @length: Size of data block; SMBus allows at most 32 bytes
  212. * @values: Byte array which will be written.
  213. *
  214. * This executes the SMBus "block write" protocol, returning negative errno
  215. * else zero on success.
  216. */
  217. s32 i2c_smbus_write_block_data(const struct i2c_client *client, u8 command,
  218. u8 length, const u8 *values)
  219. {
  220. union i2c_smbus_data data;
  221. if (length > I2C_SMBUS_BLOCK_MAX)
  222. length = I2C_SMBUS_BLOCK_MAX;
  223. data.block[0] = length;
  224. memcpy(&data.block[1], values, length);
  225. return i2c_smbus_xfer(client->adapter, client->addr, client->flags,
  226. I2C_SMBUS_WRITE, command,
  227. I2C_SMBUS_BLOCK_DATA, &data);
  228. }
  229. EXPORT_SYMBOL(i2c_smbus_write_block_data);
  230. /* Returns the number of read bytes */
  231. s32 i2c_smbus_read_i2c_block_data(const struct i2c_client *client, u8 command,
  232. u8 length, u8 *values)
  233. {
  234. union i2c_smbus_data data;
  235. int status;
  236. if (length > I2C_SMBUS_BLOCK_MAX)
  237. length = I2C_SMBUS_BLOCK_MAX;
  238. data.block[0] = length;
  239. status = i2c_smbus_xfer(client->adapter, client->addr, client->flags,
  240. I2C_SMBUS_READ, command,
  241. I2C_SMBUS_I2C_BLOCK_DATA, &data);
  242. if (status < 0)
  243. return status;
  244. memcpy(values, &data.block[1], data.block[0]);
  245. return data.block[0];
  246. }
  247. EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data);
  248. s32 i2c_smbus_write_i2c_block_data(const struct i2c_client *client, u8 command,
  249. u8 length, const u8 *values)
  250. {
  251. union i2c_smbus_data data;
  252. if (length > I2C_SMBUS_BLOCK_MAX)
  253. length = I2C_SMBUS_BLOCK_MAX;
  254. data.block[0] = length;
  255. memcpy(data.block + 1, values, length);
  256. return i2c_smbus_xfer(client->adapter, client->addr, client->flags,
  257. I2C_SMBUS_WRITE, command,
  258. I2C_SMBUS_I2C_BLOCK_DATA, &data);
  259. }
  260. EXPORT_SYMBOL(i2c_smbus_write_i2c_block_data);
  261. /* Simulate a SMBus command using the i2c protocol
  262. No checking of parameters is done! */
  263. static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr,
  264. unsigned short flags,
  265. char read_write, u8 command, int size,
  266. union i2c_smbus_data *data)
  267. {
  268. /* So we need to generate a series of msgs. In the case of writing, we
  269. need to use only one message; when reading, we need two. We initialize
  270. most things with sane defaults, to keep the code below somewhat
  271. simpler. */
  272. unsigned char msgbuf0[I2C_SMBUS_BLOCK_MAX+3];
  273. unsigned char msgbuf1[I2C_SMBUS_BLOCK_MAX+2];
  274. int num = read_write == I2C_SMBUS_READ ? 2 : 1;
  275. int i;
  276. u8 partial_pec = 0;
  277. int status;
  278. struct i2c_msg msg[2] = {
  279. {
  280. .addr = addr,
  281. .flags = flags,
  282. .len = 1,
  283. .buf = msgbuf0,
  284. }, {
  285. .addr = addr,
  286. .flags = flags | I2C_M_RD,
  287. .len = 0,
  288. .buf = msgbuf1,
  289. },
  290. };
  291. msgbuf0[0] = command;
  292. switch (size) {
  293. case I2C_SMBUS_QUICK:
  294. msg[0].len = 0;
  295. /* Special case: The read/write field is used as data */
  296. msg[0].flags = flags | (read_write == I2C_SMBUS_READ ?
  297. I2C_M_RD : 0);
  298. num = 1;
  299. break;
  300. case I2C_SMBUS_BYTE:
  301. if (read_write == I2C_SMBUS_READ) {
  302. /* Special case: only a read! */
  303. msg[0].flags = I2C_M_RD | flags;
  304. num = 1;
  305. }
  306. break;
  307. case I2C_SMBUS_BYTE_DATA:
  308. if (read_write == I2C_SMBUS_READ)
  309. msg[1].len = 1;
  310. else {
  311. msg[0].len = 2;
  312. msgbuf0[1] = data->byte;
  313. }
  314. break;
  315. case I2C_SMBUS_WORD_DATA:
  316. if (read_write == I2C_SMBUS_READ)
  317. msg[1].len = 2;
  318. else {
  319. msg[0].len = 3;
  320. msgbuf0[1] = data->word & 0xff;
  321. msgbuf0[2] = data->word >> 8;
  322. }
  323. break;
  324. case I2C_SMBUS_PROC_CALL:
  325. num = 2; /* Special case */
  326. read_write = I2C_SMBUS_READ;
  327. msg[0].len = 3;
  328. msg[1].len = 2;
  329. msgbuf0[1] = data->word & 0xff;
  330. msgbuf0[2] = data->word >> 8;
  331. break;
  332. case I2C_SMBUS_BLOCK_DATA:
  333. if (read_write == I2C_SMBUS_READ) {
  334. msg[1].flags |= I2C_M_RECV_LEN;
  335. msg[1].len = 1; /* block length will be added by
  336. the underlying bus driver */
  337. } else {
  338. msg[0].len = data->block[0] + 2;
  339. if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 2) {
  340. dev_err(&adapter->dev,
  341. "Invalid block write size %d\n",
  342. data->block[0]);
  343. return -EINVAL;
  344. }
  345. for (i = 1; i < msg[0].len; i++)
  346. msgbuf0[i] = data->block[i-1];
  347. }
  348. break;
  349. case I2C_SMBUS_BLOCK_PROC_CALL:
  350. num = 2; /* Another special case */
  351. read_write = I2C_SMBUS_READ;
  352. if (data->block[0] > I2C_SMBUS_BLOCK_MAX) {
  353. dev_err(&adapter->dev,
  354. "Invalid block write size %d\n",
  355. data->block[0]);
  356. return -EINVAL;
  357. }
  358. msg[0].len = data->block[0] + 2;
  359. for (i = 1; i < msg[0].len; i++)
  360. msgbuf0[i] = data->block[i-1];
  361. msg[1].flags |= I2C_M_RECV_LEN;
  362. msg[1].len = 1; /* block length will be added by
  363. the underlying bus driver */
  364. break;
  365. case I2C_SMBUS_I2C_BLOCK_DATA:
  366. if (data->block[0] > I2C_SMBUS_BLOCK_MAX) {
  367. dev_err(&adapter->dev, "Invalid block %s size %d\n",
  368. read_write == I2C_SMBUS_READ ? "read" : "write",
  369. data->block[0]);
  370. return -EINVAL;
  371. }
  372. if (read_write == I2C_SMBUS_READ) {
  373. msg[1].len = data->block[0];
  374. } else {
  375. msg[0].len = data->block[0] + 1;
  376. for (i = 1; i <= data->block[0]; i++)
  377. msgbuf0[i] = data->block[i];
  378. }
  379. break;
  380. default:
  381. dev_err(&adapter->dev, "Unsupported transaction %d\n", size);
  382. return -EOPNOTSUPP;
  383. }
  384. i = ((flags & I2C_CLIENT_PEC) && size != I2C_SMBUS_QUICK
  385. && size != I2C_SMBUS_I2C_BLOCK_DATA);
  386. if (i) {
  387. /* Compute PEC if first message is a write */
  388. if (!(msg[0].flags & I2C_M_RD)) {
  389. if (num == 1) /* Write only */
  390. i2c_smbus_add_pec(&msg[0]);
  391. else /* Write followed by read */
  392. partial_pec = i2c_smbus_msg_pec(0, &msg[0]);
  393. }
  394. /* Ask for PEC if last message is a read */
  395. if (msg[num-1].flags & I2C_M_RD)
  396. msg[num-1].len++;
  397. }
  398. status = i2c_transfer(adapter, msg, num);
  399. if (status < 0)
  400. return status;
  401. /* Check PEC if last message is a read */
  402. if (i && (msg[num-1].flags & I2C_M_RD)) {
  403. status = i2c_smbus_check_pec(partial_pec, &msg[num-1]);
  404. if (status < 0)
  405. return status;
  406. }
  407. if (read_write == I2C_SMBUS_READ)
  408. switch (size) {
  409. case I2C_SMBUS_BYTE:
  410. data->byte = msgbuf0[0];
  411. break;
  412. case I2C_SMBUS_BYTE_DATA:
  413. data->byte = msgbuf1[0];
  414. break;
  415. case I2C_SMBUS_WORD_DATA:
  416. case I2C_SMBUS_PROC_CALL:
  417. data->word = msgbuf1[0] | (msgbuf1[1] << 8);
  418. break;
  419. case I2C_SMBUS_I2C_BLOCK_DATA:
  420. for (i = 0; i < data->block[0]; i++)
  421. data->block[i+1] = msgbuf1[i];
  422. break;
  423. case I2C_SMBUS_BLOCK_DATA:
  424. case I2C_SMBUS_BLOCK_PROC_CALL:
  425. for (i = 0; i < msgbuf1[0] + 1; i++)
  426. data->block[i] = msgbuf1[i];
  427. break;
  428. }
  429. return 0;
  430. }
  431. /**
  432. * i2c_smbus_xfer - execute SMBus protocol operations
  433. * @adapter: Handle to I2C bus
  434. * @addr: Address of SMBus slave on that bus
  435. * @flags: I2C_CLIENT_* flags (usually zero or I2C_CLIENT_PEC)
  436. * @read_write: I2C_SMBUS_READ or I2C_SMBUS_WRITE
  437. * @command: Byte interpreted by slave, for protocols which use such bytes
  438. * @protocol: SMBus protocol operation to execute, such as I2C_SMBUS_PROC_CALL
  439. * @data: Data to be read or written
  440. *
  441. * This executes an SMBus protocol operation, and returns a negative
  442. * errno code else zero on success.
  443. */
  444. s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags,
  445. char read_write, u8 command, int protocol,
  446. union i2c_smbus_data *data)
  447. {
  448. unsigned long orig_jiffies;
  449. int try;
  450. s32 res;
  451. /* If enabled, the following two tracepoints are conditional on
  452. * read_write and protocol.
  453. */
  454. trace_smbus_write(adapter, addr, flags, read_write,
  455. command, protocol, data);
  456. trace_smbus_read(adapter, addr, flags, read_write,
  457. command, protocol);
  458. flags &= I2C_M_TEN | I2C_CLIENT_PEC | I2C_CLIENT_SCCB;
  459. if (adapter->algo->smbus_xfer) {
  460. i2c_lock_bus(adapter, I2C_LOCK_SEGMENT);
  461. /* Retry automatically on arbitration loss */
  462. orig_jiffies = jiffies;
  463. for (res = 0, try = 0; try <= adapter->retries; try++) {
  464. res = adapter->algo->smbus_xfer(adapter, addr, flags,
  465. read_write, command,
  466. protocol, data);
  467. if (res != -EAGAIN)
  468. break;
  469. if (time_after(jiffies,
  470. orig_jiffies + adapter->timeout))
  471. break;
  472. }
  473. i2c_unlock_bus(adapter, I2C_LOCK_SEGMENT);
  474. if (res != -EOPNOTSUPP || !adapter->algo->master_xfer)
  475. goto trace;
  476. /*
  477. * Fall back to i2c_smbus_xfer_emulated if the adapter doesn't
  478. * implement native support for the SMBus operation.
  479. */
  480. }
  481. res = i2c_smbus_xfer_emulated(adapter, addr, flags, read_write,
  482. command, protocol, data);
  483. trace:
  484. /* If enabled, the reply tracepoint is conditional on read_write. */
  485. trace_smbus_reply(adapter, addr, flags, read_write,
  486. command, protocol, data);
  487. trace_smbus_result(adapter, addr, flags, read_write,
  488. command, protocol, res);
  489. return res;
  490. }
  491. EXPORT_SYMBOL(i2c_smbus_xfer);
  492. /**
  493. * i2c_smbus_read_i2c_block_data_or_emulated - read block or emulate
  494. * @client: Handle to slave device
  495. * @command: Byte interpreted by slave
  496. * @length: Size of data block; SMBus allows at most I2C_SMBUS_BLOCK_MAX bytes
  497. * @values: Byte array into which data will be read; big enough to hold
  498. * the data returned by the slave. SMBus allows at most
  499. * I2C_SMBUS_BLOCK_MAX bytes.
  500. *
  501. * This executes the SMBus "block read" protocol if supported by the adapter.
  502. * If block read is not supported, it emulates it using either word or byte
  503. * read protocols depending on availability.
  504. *
  505. * The addresses of the I2C slave device that are accessed with this function
  506. * must be mapped to a linear region, so that a block read will have the same
  507. * effect as a byte read. Before using this function you must double-check
  508. * if the I2C slave does support exchanging a block transfer with a byte
  509. * transfer.
  510. */
  511. s32 i2c_smbus_read_i2c_block_data_or_emulated(const struct i2c_client *client,
  512. u8 command, u8 length, u8 *values)
  513. {
  514. u8 i = 0;
  515. int status;
  516. if (length > I2C_SMBUS_BLOCK_MAX)
  517. length = I2C_SMBUS_BLOCK_MAX;
  518. if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK))
  519. return i2c_smbus_read_i2c_block_data(client, command, length, values);
  520. if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_BYTE_DATA))
  521. return -EOPNOTSUPP;
  522. if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_WORD_DATA)) {
  523. while ((i + 2) <= length) {
  524. status = i2c_smbus_read_word_data(client, command + i);
  525. if (status < 0)
  526. return status;
  527. values[i] = status & 0xff;
  528. values[i + 1] = status >> 8;
  529. i += 2;
  530. }
  531. }
  532. while (i < length) {
  533. status = i2c_smbus_read_byte_data(client, command + i);
  534. if (status < 0)
  535. return status;
  536. values[i] = status;
  537. i++;
  538. }
  539. return i;
  540. }
  541. EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data_or_emulated);