i2c-algo-bit.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. /* -------------------------------------------------------------------------
  2. * i2c-algo-bit.c i2c driver algorithms for bit-shift adapters
  3. * -------------------------------------------------------------------------
  4. * Copyright (C) 1995-2000 Simon G. Vogl
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  16. MA 02110-1301 USA.
  17. * ------------------------------------------------------------------------- */
  18. /* With some changes from Frodo Looijaard <frodol@dds.nl>, Kyösti Mälkki
  19. <kmalkki@cc.hut.fi> and Jean Delvare <khali@linux-fr.org> */
  20. #include <linux/kernel.h>
  21. #include <linux/module.h>
  22. #include <linux/delay.h>
  23. #include <linux/init.h>
  24. #include <linux/errno.h>
  25. #include <linux/sched.h>
  26. #include <linux/i2c.h>
  27. #include <linux/i2c-algo-bit.h>
  28. /* ----- global defines ----------------------------------------------- */
  29. #ifdef DEBUG
  30. #define bit_dbg(level, dev, format, args...) \
  31. do { \
  32. if (i2c_debug >= level) \
  33. dev_dbg(dev, format, ##args); \
  34. } while (0)
  35. #else
  36. #define bit_dbg(level, dev, format, args...) \
  37. do {} while (0)
  38. #endif /* DEBUG */
  39. /* ----- global variables --------------------------------------------- */
  40. static int bit_test; /* see if the line-setting functions work */
  41. module_param(bit_test, int, S_IRUGO);
  42. MODULE_PARM_DESC(bit_test, "lines testing - 0 off; 1 report; 2 fail if stuck");
  43. #ifdef DEBUG
  44. static int i2c_debug = 1;
  45. module_param(i2c_debug, int, S_IRUGO | S_IWUSR);
  46. MODULE_PARM_DESC(i2c_debug,
  47. "debug level - 0 off; 1 normal; 2 verbose; 3 very verbose");
  48. #endif
  49. /* --- setting states on the bus with the right timing: --------------- */
  50. #define setsda(adap, val) adap->setsda(adap->data, val)
  51. #define setscl(adap, val) adap->setscl(adap->data, val)
  52. #define getsda(adap) adap->getsda(adap->data)
  53. #define getscl(adap) adap->getscl(adap->data)
  54. static inline void sdalo(struct i2c_algo_bit_data *adap)
  55. {
  56. setsda(adap, 0);
  57. udelay((adap->udelay + 1) / 2);
  58. }
  59. static inline void sdahi(struct i2c_algo_bit_data *adap)
  60. {
  61. setsda(adap, 1);
  62. udelay((adap->udelay + 1) / 2);
  63. }
  64. static inline void scllo(struct i2c_algo_bit_data *adap)
  65. {
  66. setscl(adap, 0);
  67. udelay(adap->udelay / 2);
  68. }
  69. /*
  70. * Raise scl line, and do checking for delays. This is necessary for slower
  71. * devices.
  72. */
  73. static int sclhi(struct i2c_algo_bit_data *adap)
  74. {
  75. unsigned long start;
  76. setscl(adap, 1);
  77. /* Not all adapters have scl sense line... */
  78. if (!adap->getscl)
  79. goto done;
  80. start = jiffies;
  81. while (!getscl(adap)) {
  82. /* This hw knows how to read the clock line, so we wait
  83. * until it actually gets high. This is safer as some
  84. * chips may hold it low ("clock stretching") while they
  85. * are processing data internally.
  86. */
  87. if (time_after(jiffies, start + adap->timeout)) {
  88. /* Test one last time, as we may have been preempted
  89. * between last check and timeout test.
  90. */
  91. if (getscl(adap))
  92. break;
  93. return -ETIMEDOUT;
  94. }
  95. cpu_relax();
  96. }
  97. #ifdef DEBUG
  98. if (jiffies != start && i2c_debug >= 3)
  99. pr_debug("i2c-algo-bit: needed %ld jiffies for SCL to go "
  100. "high\n", jiffies - start);
  101. #endif
  102. done:
  103. udelay(adap->udelay);
  104. return 0;
  105. }
  106. /* --- other auxiliary functions -------------------------------------- */
  107. static void i2c_start(struct i2c_algo_bit_data *adap)
  108. {
  109. /* assert: scl, sda are high */
  110. setsda(adap, 0);
  111. udelay(adap->udelay);
  112. scllo(adap);
  113. }
  114. static void i2c_repstart(struct i2c_algo_bit_data *adap)
  115. {
  116. /* assert: scl is low */
  117. sdahi(adap);
  118. sclhi(adap);
  119. setsda(adap, 0);
  120. udelay(adap->udelay);
  121. scllo(adap);
  122. }
  123. static void i2c_stop(struct i2c_algo_bit_data *adap)
  124. {
  125. /* assert: scl is low */
  126. sdalo(adap);
  127. sclhi(adap);
  128. setsda(adap, 1);
  129. udelay(adap->udelay);
  130. }
  131. /* send a byte without start cond., look for arbitration,
  132. check ackn. from slave */
  133. /* returns:
  134. * 1 if the device acknowledged
  135. * 0 if the device did not ack
  136. * -ETIMEDOUT if an error occurred (while raising the scl line)
  137. */
  138. static int i2c_outb(struct i2c_adapter *i2c_adap, unsigned char c)
  139. {
  140. int i;
  141. int sb;
  142. int ack;
  143. struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
  144. /* assert: scl is low */
  145. for (i = 7; i >= 0; i--) {
  146. sb = (c >> i) & 1;
  147. setsda(adap, sb);
  148. udelay((adap->udelay + 1) / 2);
  149. if (sclhi(adap) < 0) { /* timed out */
  150. bit_dbg(1, &i2c_adap->dev, "i2c_outb: 0x%02x, "
  151. "timeout at bit #%d\n", (int)c, i);
  152. return -ETIMEDOUT;
  153. }
  154. /* FIXME do arbitration here:
  155. * if (sb && !getsda(adap)) -> ouch! Get out of here.
  156. *
  157. * Report a unique code, so higher level code can retry
  158. * the whole (combined) message and *NOT* issue STOP.
  159. */
  160. scllo(adap);
  161. }
  162. sdahi(adap);
  163. if (sclhi(adap) < 0) { /* timeout */
  164. bit_dbg(1, &i2c_adap->dev, "i2c_outb: 0x%02x, "
  165. "timeout at ack\n", (int)c);
  166. return -ETIMEDOUT;
  167. }
  168. /* read ack: SDA should be pulled down by slave, or it may
  169. * NAK (usually to report problems with the data we wrote).
  170. */
  171. ack = !getsda(adap); /* ack: sda is pulled low -> success */
  172. bit_dbg(2, &i2c_adap->dev, "i2c_outb: 0x%02x %s\n", (int)c,
  173. ack ? "A" : "NA");
  174. scllo(adap);
  175. return ack;
  176. /* assert: scl is low (sda undef) */
  177. }
  178. static int i2c_inb(struct i2c_adapter *i2c_adap)
  179. {
  180. /* read byte via i2c port, without start/stop sequence */
  181. /* acknowledge is sent in i2c_read. */
  182. int i;
  183. unsigned char indata = 0;
  184. struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
  185. /* assert: scl is low */
  186. sdahi(adap);
  187. for (i = 0; i < 8; i++) {
  188. if (sclhi(adap) < 0) { /* timeout */
  189. bit_dbg(1, &i2c_adap->dev, "i2c_inb: timeout at bit "
  190. "#%d\n", 7 - i);
  191. return -ETIMEDOUT;
  192. }
  193. indata *= 2;
  194. if (getsda(adap))
  195. indata |= 0x01;
  196. setscl(adap, 0);
  197. udelay(i == 7 ? adap->udelay / 2 : adap->udelay);
  198. }
  199. /* assert: scl is low */
  200. return indata;
  201. }
  202. /*
  203. * Sanity check for the adapter hardware - check the reaction of
  204. * the bus lines only if it seems to be idle.
  205. */
  206. static int test_bus(struct i2c_adapter *i2c_adap)
  207. {
  208. struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
  209. const char *name = i2c_adap->name;
  210. int scl, sda, ret;
  211. if (adap->pre_xfer) {
  212. ret = adap->pre_xfer(i2c_adap);
  213. if (ret < 0)
  214. return -ENODEV;
  215. }
  216. if (adap->getscl == NULL)
  217. pr_info("%s: Testing SDA only, SCL is not readable\n", name);
  218. sda = getsda(adap);
  219. scl = (adap->getscl == NULL) ? 1 : getscl(adap);
  220. if (!scl || !sda) {
  221. printk(KERN_WARNING
  222. "%s: bus seems to be busy (scl=%d, sda=%d)\n",
  223. name, scl, sda);
  224. goto bailout;
  225. }
  226. sdalo(adap);
  227. sda = getsda(adap);
  228. scl = (adap->getscl == NULL) ? 1 : getscl(adap);
  229. if (sda) {
  230. printk(KERN_WARNING "%s: SDA stuck high!\n", name);
  231. goto bailout;
  232. }
  233. if (!scl) {
  234. printk(KERN_WARNING "%s: SCL unexpected low "
  235. "while pulling SDA low!\n", name);
  236. goto bailout;
  237. }
  238. sdahi(adap);
  239. sda = getsda(adap);
  240. scl = (adap->getscl == NULL) ? 1 : getscl(adap);
  241. if (!sda) {
  242. printk(KERN_WARNING "%s: SDA stuck low!\n", name);
  243. goto bailout;
  244. }
  245. if (!scl) {
  246. printk(KERN_WARNING "%s: SCL unexpected low "
  247. "while pulling SDA high!\n", name);
  248. goto bailout;
  249. }
  250. scllo(adap);
  251. sda = getsda(adap);
  252. scl = (adap->getscl == NULL) ? 0 : getscl(adap);
  253. if (scl) {
  254. printk(KERN_WARNING "%s: SCL stuck high!\n", name);
  255. goto bailout;
  256. }
  257. if (!sda) {
  258. printk(KERN_WARNING "%s: SDA unexpected low "
  259. "while pulling SCL low!\n", name);
  260. goto bailout;
  261. }
  262. sclhi(adap);
  263. sda = getsda(adap);
  264. scl = (adap->getscl == NULL) ? 1 : getscl(adap);
  265. if (!scl) {
  266. printk(KERN_WARNING "%s: SCL stuck low!\n", name);
  267. goto bailout;
  268. }
  269. if (!sda) {
  270. printk(KERN_WARNING "%s: SDA unexpected low "
  271. "while pulling SCL high!\n", name);
  272. goto bailout;
  273. }
  274. if (adap->post_xfer)
  275. adap->post_xfer(i2c_adap);
  276. pr_info("%s: Test OK\n", name);
  277. return 0;
  278. bailout:
  279. sdahi(adap);
  280. sclhi(adap);
  281. if (adap->post_xfer)
  282. adap->post_xfer(i2c_adap);
  283. return -ENODEV;
  284. }
  285. /* ----- Utility functions
  286. */
  287. /* try_address tries to contact a chip for a number of
  288. * times before it gives up.
  289. * return values:
  290. * 1 chip answered
  291. * 0 chip did not answer
  292. * -x transmission error
  293. */
  294. static int try_address(struct i2c_adapter *i2c_adap,
  295. unsigned char addr, int retries)
  296. {
  297. struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
  298. int i, ret = 0;
  299. for (i = 0; i <= retries; i++) {
  300. ret = i2c_outb(i2c_adap, addr);
  301. if (ret == 1 || i == retries)
  302. break;
  303. bit_dbg(3, &i2c_adap->dev, "emitting stop condition\n");
  304. i2c_stop(adap);
  305. udelay(adap->udelay);
  306. yield();
  307. bit_dbg(3, &i2c_adap->dev, "emitting start condition\n");
  308. i2c_start(adap);
  309. }
  310. if (i && ret)
  311. bit_dbg(1, &i2c_adap->dev, "Used %d tries to %s client at "
  312. "0x%02x: %s\n", i + 1,
  313. addr & 1 ? "read from" : "write to", addr >> 1,
  314. ret == 1 ? "success" : "failed, timeout?");
  315. return ret;
  316. }
  317. static int sendbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
  318. {
  319. const unsigned char *temp = msg->buf;
  320. int count = msg->len;
  321. unsigned short nak_ok = msg->flags & I2C_M_IGNORE_NAK;
  322. int retval;
  323. int wrcount = 0;
  324. while (count > 0) {
  325. retval = i2c_outb(i2c_adap, *temp);
  326. /* OK/ACK; or ignored NAK */
  327. if ((retval > 0) || (nak_ok && (retval == 0))) {
  328. count--;
  329. temp++;
  330. wrcount++;
  331. /* A slave NAKing the master means the slave didn't like
  332. * something about the data it saw. For example, maybe
  333. * the SMBus PEC was wrong.
  334. */
  335. } else if (retval == 0) {
  336. dev_err(&i2c_adap->dev, "sendbytes: NAK bailout.\n");
  337. return -EIO;
  338. /* Timeout; or (someday) lost arbitration
  339. *
  340. * FIXME Lost ARB implies retrying the transaction from
  341. * the first message, after the "winning" master issues
  342. * its STOP. As a rule, upper layer code has no reason
  343. * to know or care about this ... it is *NOT* an error.
  344. */
  345. } else {
  346. dev_err(&i2c_adap->dev, "sendbytes: error %d\n",
  347. retval);
  348. return retval;
  349. }
  350. }
  351. return wrcount;
  352. }
  353. static int acknak(struct i2c_adapter *i2c_adap, int is_ack)
  354. {
  355. struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
  356. /* assert: sda is high */
  357. if (is_ack) /* send ack */
  358. setsda(adap, 0);
  359. udelay((adap->udelay + 1) / 2);
  360. if (sclhi(adap) < 0) { /* timeout */
  361. dev_err(&i2c_adap->dev, "readbytes: ack/nak timeout\n");
  362. return -ETIMEDOUT;
  363. }
  364. scllo(adap);
  365. return 0;
  366. }
  367. static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
  368. {
  369. int inval;
  370. int rdcount = 0; /* counts bytes read */
  371. unsigned char *temp = msg->buf;
  372. int count = msg->len;
  373. const unsigned flags = msg->flags;
  374. while (count > 0) {
  375. inval = i2c_inb(i2c_adap);
  376. if (inval >= 0) {
  377. *temp = inval;
  378. rdcount++;
  379. } else { /* read timed out */
  380. break;
  381. }
  382. temp++;
  383. count--;
  384. /* Some SMBus transactions require that we receive the
  385. transaction length as the first read byte. */
  386. if (rdcount == 1 && (flags & I2C_M_RECV_LEN)) {
  387. if (inval <= 0 || inval > I2C_SMBUS_BLOCK_MAX) {
  388. if (!(flags & I2C_M_NO_RD_ACK))
  389. acknak(i2c_adap, 0);
  390. dev_err(&i2c_adap->dev, "readbytes: invalid "
  391. "block length (%d)\n", inval);
  392. return -EPROTO;
  393. }
  394. /* The original count value accounts for the extra
  395. bytes, that is, either 1 for a regular transaction,
  396. or 2 for a PEC transaction. */
  397. count += inval;
  398. msg->len += inval;
  399. }
  400. bit_dbg(2, &i2c_adap->dev, "readbytes: 0x%02x %s\n",
  401. inval,
  402. (flags & I2C_M_NO_RD_ACK)
  403. ? "(no ack/nak)"
  404. : (count ? "A" : "NA"));
  405. if (!(flags & I2C_M_NO_RD_ACK)) {
  406. inval = acknak(i2c_adap, count);
  407. if (inval < 0)
  408. return inval;
  409. }
  410. }
  411. return rdcount;
  412. }
  413. /* doAddress initiates the transfer by generating the start condition (in
  414. * try_address) and transmits the address in the necessary format to handle
  415. * reads, writes as well as 10bit-addresses.
  416. * returns:
  417. * 0 everything went okay, the chip ack'ed, or IGNORE_NAK flag was set
  418. * -x an error occurred (like: -ENXIO if the device did not answer, or
  419. * -ETIMEDOUT, for example if the lines are stuck...)
  420. */
  421. static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
  422. {
  423. unsigned short flags = msg->flags;
  424. unsigned short nak_ok = msg->flags & I2C_M_IGNORE_NAK;
  425. struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
  426. unsigned char addr;
  427. int ret, retries;
  428. retries = nak_ok ? 0 : i2c_adap->retries;
  429. if (flags & I2C_M_TEN) {
  430. /* a ten bit address */
  431. addr = 0xf0 | ((msg->addr >> 7) & 0x06);
  432. bit_dbg(2, &i2c_adap->dev, "addr0: %d\n", addr);
  433. /* try extended address code...*/
  434. ret = try_address(i2c_adap, addr, retries);
  435. if ((ret != 1) && !nak_ok) {
  436. dev_err(&i2c_adap->dev,
  437. "died at extended address code\n");
  438. return -ENXIO;
  439. }
  440. /* the remaining 8 bit address */
  441. ret = i2c_outb(i2c_adap, msg->addr & 0xff);
  442. if ((ret != 1) && !nak_ok) {
  443. /* the chip did not ack / xmission error occurred */
  444. dev_err(&i2c_adap->dev, "died at 2nd address code\n");
  445. return -ENXIO;
  446. }
  447. if (flags & I2C_M_RD) {
  448. bit_dbg(3, &i2c_adap->dev, "emitting repeated "
  449. "start condition\n");
  450. i2c_repstart(adap);
  451. /* okay, now switch into reading mode */
  452. addr |= 0x01;
  453. ret = try_address(i2c_adap, addr, retries);
  454. if ((ret != 1) && !nak_ok) {
  455. dev_err(&i2c_adap->dev,
  456. "died at repeated address code\n");
  457. return -EIO;
  458. }
  459. }
  460. } else { /* normal 7bit address */
  461. addr = msg->addr << 1;
  462. if (flags & I2C_M_RD)
  463. addr |= 1;
  464. if (flags & I2C_M_REV_DIR_ADDR)
  465. addr ^= 1;
  466. ret = try_address(i2c_adap, addr, retries);
  467. if ((ret != 1) && !nak_ok)
  468. return -ENXIO;
  469. }
  470. return 0;
  471. }
  472. static int bit_xfer(struct i2c_adapter *i2c_adap,
  473. struct i2c_msg msgs[], int num)
  474. {
  475. struct i2c_msg *pmsg;
  476. struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
  477. int i, ret;
  478. unsigned short nak_ok;
  479. if (adap->pre_xfer) {
  480. ret = adap->pre_xfer(i2c_adap);
  481. if (ret < 0)
  482. return ret;
  483. }
  484. bit_dbg(3, &i2c_adap->dev, "emitting start condition\n");
  485. i2c_start(adap);
  486. for (i = 0; i < num; i++) {
  487. pmsg = &msgs[i];
  488. nak_ok = pmsg->flags & I2C_M_IGNORE_NAK;
  489. if (!(pmsg->flags & I2C_M_NOSTART)) {
  490. if (i) {
  491. bit_dbg(3, &i2c_adap->dev, "emitting "
  492. "repeated start condition\n");
  493. i2c_repstart(adap);
  494. }
  495. ret = bit_doAddress(i2c_adap, pmsg);
  496. if ((ret != 0) && !nak_ok) {
  497. bit_dbg(1, &i2c_adap->dev, "NAK from "
  498. "device addr 0x%02x msg #%d\n",
  499. msgs[i].addr, i);
  500. goto bailout;
  501. }
  502. }
  503. if (pmsg->flags & I2C_M_RD) {
  504. /* read bytes into buffer*/
  505. ret = readbytes(i2c_adap, pmsg);
  506. if (ret >= 1)
  507. bit_dbg(2, &i2c_adap->dev, "read %d byte%s\n",
  508. ret, ret == 1 ? "" : "s");
  509. if (ret < pmsg->len) {
  510. if (ret >= 0)
  511. ret = -EIO;
  512. goto bailout;
  513. }
  514. } else {
  515. /* write bytes from buffer */
  516. ret = sendbytes(i2c_adap, pmsg);
  517. if (ret >= 1)
  518. bit_dbg(2, &i2c_adap->dev, "wrote %d byte%s\n",
  519. ret, ret == 1 ? "" : "s");
  520. if (ret < pmsg->len) {
  521. if (ret >= 0)
  522. ret = -EIO;
  523. goto bailout;
  524. }
  525. }
  526. }
  527. ret = i;
  528. bailout:
  529. bit_dbg(3, &i2c_adap->dev, "emitting stop condition\n");
  530. i2c_stop(adap);
  531. if (adap->post_xfer)
  532. adap->post_xfer(i2c_adap);
  533. return ret;
  534. }
  535. static u32 bit_func(struct i2c_adapter *adap)
  536. {
  537. return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL |
  538. I2C_FUNC_SMBUS_READ_BLOCK_DATA |
  539. I2C_FUNC_SMBUS_BLOCK_PROC_CALL |
  540. I2C_FUNC_10BIT_ADDR | I2C_FUNC_PROTOCOL_MANGLING;
  541. }
  542. /* -----exported algorithm data: ------------------------------------- */
  543. const struct i2c_algorithm i2c_bit_algo = {
  544. .master_xfer = bit_xfer,
  545. .functionality = bit_func,
  546. };
  547. EXPORT_SYMBOL(i2c_bit_algo);
  548. /*
  549. * registering functions to load algorithms at runtime
  550. */
  551. static int __i2c_bit_add_bus(struct i2c_adapter *adap,
  552. int (*add_adapter)(struct i2c_adapter *))
  553. {
  554. struct i2c_algo_bit_data *bit_adap = adap->algo_data;
  555. int ret;
  556. if (bit_test) {
  557. ret = test_bus(adap);
  558. if (bit_test >= 2 && ret < 0)
  559. return -ENODEV;
  560. }
  561. /* register new adapter to i2c module... */
  562. adap->algo = &i2c_bit_algo;
  563. adap->retries = 3;
  564. ret = add_adapter(adap);
  565. if (ret < 0)
  566. return ret;
  567. /* Complain if SCL can't be read */
  568. if (bit_adap->getscl == NULL) {
  569. dev_warn(&adap->dev, "Not I2C compliant: can't read SCL\n");
  570. dev_warn(&adap->dev, "Bus may be unreliable\n");
  571. }
  572. return 0;
  573. }
  574. int i2c_bit_add_bus(struct i2c_adapter *adap)
  575. {
  576. return __i2c_bit_add_bus(adap, i2c_add_adapter);
  577. }
  578. EXPORT_SYMBOL(i2c_bit_add_bus);
  579. int i2c_bit_add_numbered_bus(struct i2c_adapter *adap)
  580. {
  581. return __i2c_bit_add_bus(adap, i2c_add_numbered_adapter);
  582. }
  583. EXPORT_SYMBOL(i2c_bit_add_numbered_bus);
  584. MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
  585. MODULE_DESCRIPTION("I2C-Bus bit-banging algorithm");
  586. MODULE_LICENSE("GPL");