i2c-pxa.c 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  1. /*
  2. * i2c_adap_pxa.c
  3. *
  4. * I2C adapter for the PXA I2C bus access.
  5. *
  6. * Copyright (C) 2002 Intrinsyc Software Inc.
  7. * Copyright (C) 2004-2005 Deep Blue Solutions Ltd.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. *
  13. * History:
  14. * Apr 2002: Initial version [CS]
  15. * Jun 2002: Properly separated algo/adap [FB]
  16. * Jan 2003: Fixed several bugs concerning interrupt handling [Kai-Uwe Bloem]
  17. * Jan 2003: added limited signal handling [Kai-Uwe Bloem]
  18. * Sep 2004: Major rework to ensure efficient bus handling [RMK]
  19. * Dec 2004: Added support for PXA27x and slave device probing [Liam Girdwood]
  20. * Feb 2005: Rework slave mode handling [RMK]
  21. */
  22. #include <linux/kernel.h>
  23. #include <linux/module.h>
  24. #include <linux/i2c.h>
  25. #include <linux/init.h>
  26. #include <linux/time.h>
  27. #include <linux/sched.h>
  28. #include <linux/delay.h>
  29. #include <linux/errno.h>
  30. #include <linux/interrupt.h>
  31. #include <linux/i2c-pxa.h>
  32. #include <linux/platform_device.h>
  33. #include <linux/err.h>
  34. #include <linux/clk.h>
  35. #include <linux/slab.h>
  36. #include <linux/io.h>
  37. #include <linux/i2c/pxa-i2c.h>
  38. #include <asm/irq.h>
  39. #ifndef CONFIG_HAVE_CLK
  40. #define clk_get(dev, id) NULL
  41. #define clk_put(clk) do { } while (0)
  42. #define clk_disable(clk) do { } while (0)
  43. #define clk_enable(clk) do { } while (0)
  44. #endif
  45. struct pxa_reg_layout {
  46. u32 ibmr;
  47. u32 idbr;
  48. u32 icr;
  49. u32 isr;
  50. u32 isar;
  51. };
  52. enum pxa_i2c_types {
  53. REGS_PXA2XX,
  54. REGS_PXA3XX,
  55. REGS_CE4100,
  56. };
  57. /*
  58. * I2C registers definitions
  59. */
  60. static struct pxa_reg_layout pxa_reg_layout[] = {
  61. [REGS_PXA2XX] = {
  62. .ibmr = 0x00,
  63. .idbr = 0x10,
  64. .icr = 0x20,
  65. .isr = 0x30,
  66. .isar = 0x40,
  67. },
  68. [REGS_PXA3XX] = {
  69. .ibmr = 0x00,
  70. .idbr = 0x08,
  71. .icr = 0x10,
  72. .isr = 0x18,
  73. .isar = 0x20,
  74. },
  75. [REGS_CE4100] = {
  76. .ibmr = 0x14,
  77. .idbr = 0x0c,
  78. .icr = 0x00,
  79. .isr = 0x04,
  80. /* no isar register */
  81. },
  82. };
  83. static const struct platform_device_id i2c_pxa_id_table[] = {
  84. { "pxa2xx-i2c", REGS_PXA2XX },
  85. { "pxa3xx-pwri2c", REGS_PXA3XX },
  86. { "ce4100-i2c", REGS_CE4100 },
  87. { },
  88. };
  89. MODULE_DEVICE_TABLE(platform, i2c_pxa_id_table);
  90. /*
  91. * I2C bit definitions
  92. */
  93. #define ICR_START (1 << 0) /* start bit */
  94. #define ICR_STOP (1 << 1) /* stop bit */
  95. #define ICR_ACKNAK (1 << 2) /* send ACK(0) or NAK(1) */
  96. #define ICR_TB (1 << 3) /* transfer byte bit */
  97. #define ICR_MA (1 << 4) /* master abort */
  98. #define ICR_SCLE (1 << 5) /* master clock enable */
  99. #define ICR_IUE (1 << 6) /* unit enable */
  100. #define ICR_GCD (1 << 7) /* general call disable */
  101. #define ICR_ITEIE (1 << 8) /* enable tx interrupts */
  102. #define ICR_IRFIE (1 << 9) /* enable rx interrupts */
  103. #define ICR_BEIE (1 << 10) /* enable bus error ints */
  104. #define ICR_SSDIE (1 << 11) /* slave STOP detected int enable */
  105. #define ICR_ALDIE (1 << 12) /* enable arbitration interrupt */
  106. #define ICR_SADIE (1 << 13) /* slave address detected int enable */
  107. #define ICR_UR (1 << 14) /* unit reset */
  108. #define ICR_FM (1 << 15) /* fast mode */
  109. #define ISR_RWM (1 << 0) /* read/write mode */
  110. #define ISR_ACKNAK (1 << 1) /* ack/nak status */
  111. #define ISR_UB (1 << 2) /* unit busy */
  112. #define ISR_IBB (1 << 3) /* bus busy */
  113. #define ISR_SSD (1 << 4) /* slave stop detected */
  114. #define ISR_ALD (1 << 5) /* arbitration loss detected */
  115. #define ISR_ITE (1 << 6) /* tx buffer empty */
  116. #define ISR_IRF (1 << 7) /* rx buffer full */
  117. #define ISR_GCAD (1 << 8) /* general call address detected */
  118. #define ISR_SAD (1 << 9) /* slave address detected */
  119. #define ISR_BED (1 << 10) /* bus error no ACK/NAK */
  120. struct pxa_i2c {
  121. spinlock_t lock;
  122. wait_queue_head_t wait;
  123. struct i2c_msg *msg;
  124. unsigned int msg_num;
  125. unsigned int msg_idx;
  126. unsigned int msg_ptr;
  127. unsigned int slave_addr;
  128. struct i2c_adapter adap;
  129. struct clk *clk;
  130. #ifdef CONFIG_I2C_PXA_SLAVE
  131. struct i2c_slave_client *slave;
  132. #endif
  133. unsigned int irqlogidx;
  134. u32 isrlog[32];
  135. u32 icrlog[32];
  136. void __iomem *reg_base;
  137. void __iomem *reg_ibmr;
  138. void __iomem *reg_idbr;
  139. void __iomem *reg_icr;
  140. void __iomem *reg_isr;
  141. void __iomem *reg_isar;
  142. unsigned long iobase;
  143. unsigned long iosize;
  144. int irq;
  145. unsigned int use_pio :1;
  146. unsigned int fast_mode :1;
  147. };
  148. #define _IBMR(i2c) ((i2c)->reg_ibmr)
  149. #define _IDBR(i2c) ((i2c)->reg_idbr)
  150. #define _ICR(i2c) ((i2c)->reg_icr)
  151. #define _ISR(i2c) ((i2c)->reg_isr)
  152. #define _ISAR(i2c) ((i2c)->reg_isar)
  153. /*
  154. * I2C Slave mode address
  155. */
  156. #define I2C_PXA_SLAVE_ADDR 0x1
  157. #ifdef DEBUG
  158. struct bits {
  159. u32 mask;
  160. const char *set;
  161. const char *unset;
  162. };
  163. #define PXA_BIT(m, s, u) { .mask = m, .set = s, .unset = u }
  164. static inline void
  165. decode_bits(const char *prefix, const struct bits *bits, int num, u32 val)
  166. {
  167. printk("%s %08x: ", prefix, val);
  168. while (num--) {
  169. const char *str = val & bits->mask ? bits->set : bits->unset;
  170. if (str)
  171. printk("%s ", str);
  172. bits++;
  173. }
  174. }
  175. static const struct bits isr_bits[] = {
  176. PXA_BIT(ISR_RWM, "RX", "TX"),
  177. PXA_BIT(ISR_ACKNAK, "NAK", "ACK"),
  178. PXA_BIT(ISR_UB, "Bsy", "Rdy"),
  179. PXA_BIT(ISR_IBB, "BusBsy", "BusRdy"),
  180. PXA_BIT(ISR_SSD, "SlaveStop", NULL),
  181. PXA_BIT(ISR_ALD, "ALD", NULL),
  182. PXA_BIT(ISR_ITE, "TxEmpty", NULL),
  183. PXA_BIT(ISR_IRF, "RxFull", NULL),
  184. PXA_BIT(ISR_GCAD, "GenCall", NULL),
  185. PXA_BIT(ISR_SAD, "SlaveAddr", NULL),
  186. PXA_BIT(ISR_BED, "BusErr", NULL),
  187. };
  188. static void decode_ISR(unsigned int val)
  189. {
  190. decode_bits(KERN_DEBUG "ISR", isr_bits, ARRAY_SIZE(isr_bits), val);
  191. printk("\n");
  192. }
  193. static const struct bits icr_bits[] = {
  194. PXA_BIT(ICR_START, "START", NULL),
  195. PXA_BIT(ICR_STOP, "STOP", NULL),
  196. PXA_BIT(ICR_ACKNAK, "ACKNAK", NULL),
  197. PXA_BIT(ICR_TB, "TB", NULL),
  198. PXA_BIT(ICR_MA, "MA", NULL),
  199. PXA_BIT(ICR_SCLE, "SCLE", "scle"),
  200. PXA_BIT(ICR_IUE, "IUE", "iue"),
  201. PXA_BIT(ICR_GCD, "GCD", NULL),
  202. PXA_BIT(ICR_ITEIE, "ITEIE", NULL),
  203. PXA_BIT(ICR_IRFIE, "IRFIE", NULL),
  204. PXA_BIT(ICR_BEIE, "BEIE", NULL),
  205. PXA_BIT(ICR_SSDIE, "SSDIE", NULL),
  206. PXA_BIT(ICR_ALDIE, "ALDIE", NULL),
  207. PXA_BIT(ICR_SADIE, "SADIE", NULL),
  208. PXA_BIT(ICR_UR, "UR", "ur"),
  209. };
  210. #ifdef CONFIG_I2C_PXA_SLAVE
  211. static void decode_ICR(unsigned int val)
  212. {
  213. decode_bits(KERN_DEBUG "ICR", icr_bits, ARRAY_SIZE(icr_bits), val);
  214. printk("\n");
  215. }
  216. #endif
  217. static unsigned int i2c_debug = DEBUG;
  218. static void i2c_pxa_show_state(struct pxa_i2c *i2c, int lno, const char *fname)
  219. {
  220. dev_dbg(&i2c->adap.dev, "state:%s:%d: ISR=%08x, ICR=%08x, IBMR=%02x\n", fname, lno,
  221. readl(_ISR(i2c)), readl(_ICR(i2c)), readl(_IBMR(i2c)));
  222. }
  223. #define show_state(i2c) i2c_pxa_show_state(i2c, __LINE__, __func__)
  224. static void i2c_pxa_scream_blue_murder(struct pxa_i2c *i2c, const char *why)
  225. {
  226. unsigned int i;
  227. printk(KERN_ERR "i2c: error: %s\n", why);
  228. printk(KERN_ERR "i2c: msg_num: %d msg_idx: %d msg_ptr: %d\n",
  229. i2c->msg_num, i2c->msg_idx, i2c->msg_ptr);
  230. printk(KERN_ERR "i2c: ICR: %08x ISR: %08x\n",
  231. readl(_ICR(i2c)), readl(_ISR(i2c)));
  232. printk(KERN_DEBUG "i2c: log: ");
  233. for (i = 0; i < i2c->irqlogidx; i++)
  234. printk("[%08x:%08x] ", i2c->isrlog[i], i2c->icrlog[i]);
  235. printk("\n");
  236. }
  237. #else /* ifdef DEBUG */
  238. #define i2c_debug 0
  239. #define show_state(i2c) do { } while (0)
  240. #define decode_ISR(val) do { } while (0)
  241. #define decode_ICR(val) do { } while (0)
  242. #define i2c_pxa_scream_blue_murder(i2c, why) do { } while (0)
  243. #endif /* ifdef DEBUG / else */
  244. static void i2c_pxa_master_complete(struct pxa_i2c *i2c, int ret);
  245. static irqreturn_t i2c_pxa_handler(int this_irq, void *dev_id);
  246. static inline int i2c_pxa_is_slavemode(struct pxa_i2c *i2c)
  247. {
  248. return !(readl(_ICR(i2c)) & ICR_SCLE);
  249. }
  250. static void i2c_pxa_abort(struct pxa_i2c *i2c)
  251. {
  252. int i = 250;
  253. if (i2c_pxa_is_slavemode(i2c)) {
  254. dev_dbg(&i2c->adap.dev, "%s: called in slave mode\n", __func__);
  255. return;
  256. }
  257. while ((i > 0) && (readl(_IBMR(i2c)) & 0x1) == 0) {
  258. unsigned long icr = readl(_ICR(i2c));
  259. icr &= ~ICR_START;
  260. icr |= ICR_ACKNAK | ICR_STOP | ICR_TB;
  261. writel(icr, _ICR(i2c));
  262. show_state(i2c);
  263. mdelay(1);
  264. i --;
  265. }
  266. writel(readl(_ICR(i2c)) & ~(ICR_MA | ICR_START | ICR_STOP),
  267. _ICR(i2c));
  268. }
  269. static int i2c_pxa_wait_bus_not_busy(struct pxa_i2c *i2c)
  270. {
  271. int timeout = DEF_TIMEOUT;
  272. while (timeout-- && readl(_ISR(i2c)) & (ISR_IBB | ISR_UB)) {
  273. if ((readl(_ISR(i2c)) & ISR_SAD) != 0)
  274. timeout += 4;
  275. msleep(2);
  276. show_state(i2c);
  277. }
  278. if (timeout < 0)
  279. show_state(i2c);
  280. return timeout < 0 ? I2C_RETRY : 0;
  281. }
  282. static int i2c_pxa_wait_master(struct pxa_i2c *i2c)
  283. {
  284. unsigned long timeout = jiffies + HZ*4;
  285. while (time_before(jiffies, timeout)) {
  286. if (i2c_debug > 1)
  287. dev_dbg(&i2c->adap.dev, "%s: %ld: ISR=%08x, ICR=%08x, IBMR=%02x\n",
  288. __func__, (long)jiffies, readl(_ISR(i2c)), readl(_ICR(i2c)), readl(_IBMR(i2c)));
  289. if (readl(_ISR(i2c)) & ISR_SAD) {
  290. if (i2c_debug > 0)
  291. dev_dbg(&i2c->adap.dev, "%s: Slave detected\n", __func__);
  292. goto out;
  293. }
  294. /* wait for unit and bus being not busy, and we also do a
  295. * quick check of the i2c lines themselves to ensure they've
  296. * gone high...
  297. */
  298. if ((readl(_ISR(i2c)) & (ISR_UB | ISR_IBB)) == 0 && readl(_IBMR(i2c)) == 3) {
  299. if (i2c_debug > 0)
  300. dev_dbg(&i2c->adap.dev, "%s: done\n", __func__);
  301. return 1;
  302. }
  303. msleep(1);
  304. }
  305. if (i2c_debug > 0)
  306. dev_dbg(&i2c->adap.dev, "%s: did not free\n", __func__);
  307. out:
  308. return 0;
  309. }
  310. static int i2c_pxa_set_master(struct pxa_i2c *i2c)
  311. {
  312. if (i2c_debug)
  313. dev_dbg(&i2c->adap.dev, "setting to bus master\n");
  314. if ((readl(_ISR(i2c)) & (ISR_UB | ISR_IBB)) != 0) {
  315. dev_dbg(&i2c->adap.dev, "%s: unit is busy\n", __func__);
  316. if (!i2c_pxa_wait_master(i2c)) {
  317. dev_dbg(&i2c->adap.dev, "%s: error: unit busy\n", __func__);
  318. return I2C_RETRY;
  319. }
  320. }
  321. writel(readl(_ICR(i2c)) | ICR_SCLE, _ICR(i2c));
  322. return 0;
  323. }
  324. #ifdef CONFIG_I2C_PXA_SLAVE
  325. static int i2c_pxa_wait_slave(struct pxa_i2c *i2c)
  326. {
  327. unsigned long timeout = jiffies + HZ*1;
  328. /* wait for stop */
  329. show_state(i2c);
  330. while (time_before(jiffies, timeout)) {
  331. if (i2c_debug > 1)
  332. dev_dbg(&i2c->adap.dev, "%s: %ld: ISR=%08x, ICR=%08x, IBMR=%02x\n",
  333. __func__, (long)jiffies, readl(_ISR(i2c)), readl(_ICR(i2c)), readl(_IBMR(i2c)));
  334. if ((readl(_ISR(i2c)) & (ISR_UB|ISR_IBB)) == 0 ||
  335. (readl(_ISR(i2c)) & ISR_SAD) != 0 ||
  336. (readl(_ICR(i2c)) & ICR_SCLE) == 0) {
  337. if (i2c_debug > 1)
  338. dev_dbg(&i2c->adap.dev, "%s: done\n", __func__);
  339. return 1;
  340. }
  341. msleep(1);
  342. }
  343. if (i2c_debug > 0)
  344. dev_dbg(&i2c->adap.dev, "%s: did not free\n", __func__);
  345. return 0;
  346. }
  347. /*
  348. * clear the hold on the bus, and take of anything else
  349. * that has been configured
  350. */
  351. static void i2c_pxa_set_slave(struct pxa_i2c *i2c, int errcode)
  352. {
  353. show_state(i2c);
  354. if (errcode < 0) {
  355. udelay(100); /* simple delay */
  356. } else {
  357. /* we need to wait for the stop condition to end */
  358. /* if we where in stop, then clear... */
  359. if (readl(_ICR(i2c)) & ICR_STOP) {
  360. udelay(100);
  361. writel(readl(_ICR(i2c)) & ~ICR_STOP, _ICR(i2c));
  362. }
  363. if (!i2c_pxa_wait_slave(i2c)) {
  364. dev_err(&i2c->adap.dev, "%s: wait timedout\n",
  365. __func__);
  366. return;
  367. }
  368. }
  369. writel(readl(_ICR(i2c)) & ~(ICR_STOP|ICR_ACKNAK|ICR_MA), _ICR(i2c));
  370. writel(readl(_ICR(i2c)) & ~ICR_SCLE, _ICR(i2c));
  371. if (i2c_debug) {
  372. dev_dbg(&i2c->adap.dev, "ICR now %08x, ISR %08x\n", readl(_ICR(i2c)), readl(_ISR(i2c)));
  373. decode_ICR(readl(_ICR(i2c)));
  374. }
  375. }
  376. #else
  377. #define i2c_pxa_set_slave(i2c, err) do { } while (0)
  378. #endif
  379. static void i2c_pxa_reset(struct pxa_i2c *i2c)
  380. {
  381. pr_debug("Resetting I2C Controller Unit\n");
  382. /* abort any transfer currently under way */
  383. i2c_pxa_abort(i2c);
  384. /* reset according to 9.8 */
  385. writel(ICR_UR, _ICR(i2c));
  386. writel(I2C_ISR_INIT, _ISR(i2c));
  387. writel(readl(_ICR(i2c)) & ~ICR_UR, _ICR(i2c));
  388. if (i2c->reg_isar)
  389. writel(i2c->slave_addr, _ISAR(i2c));
  390. /* set control register values */
  391. writel(I2C_ICR_INIT | (i2c->fast_mode ? ICR_FM : 0), _ICR(i2c));
  392. #ifdef CONFIG_I2C_PXA_SLAVE
  393. dev_info(&i2c->adap.dev, "Enabling slave mode\n");
  394. writel(readl(_ICR(i2c)) | ICR_SADIE | ICR_ALDIE | ICR_SSDIE, _ICR(i2c));
  395. #endif
  396. i2c_pxa_set_slave(i2c, 0);
  397. /* enable unit */
  398. writel(readl(_ICR(i2c)) | ICR_IUE, _ICR(i2c));
  399. udelay(100);
  400. }
  401. #ifdef CONFIG_I2C_PXA_SLAVE
  402. /*
  403. * PXA I2C Slave mode
  404. */
  405. static void i2c_pxa_slave_txempty(struct pxa_i2c *i2c, u32 isr)
  406. {
  407. if (isr & ISR_BED) {
  408. /* what should we do here? */
  409. } else {
  410. int ret = 0;
  411. if (i2c->slave != NULL)
  412. ret = i2c->slave->read(i2c->slave->data);
  413. writel(ret, _IDBR(i2c));
  414. writel(readl(_ICR(i2c)) | ICR_TB, _ICR(i2c)); /* allow next byte */
  415. }
  416. }
  417. static void i2c_pxa_slave_rxfull(struct pxa_i2c *i2c, u32 isr)
  418. {
  419. unsigned int byte = readl(_IDBR(i2c));
  420. if (i2c->slave != NULL)
  421. i2c->slave->write(i2c->slave->data, byte);
  422. writel(readl(_ICR(i2c)) | ICR_TB, _ICR(i2c));
  423. }
  424. static void i2c_pxa_slave_start(struct pxa_i2c *i2c, u32 isr)
  425. {
  426. int timeout;
  427. if (i2c_debug > 0)
  428. dev_dbg(&i2c->adap.dev, "SAD, mode is slave-%cx\n",
  429. (isr & ISR_RWM) ? 'r' : 't');
  430. if (i2c->slave != NULL)
  431. i2c->slave->event(i2c->slave->data,
  432. (isr & ISR_RWM) ? I2C_SLAVE_EVENT_START_READ : I2C_SLAVE_EVENT_START_WRITE);
  433. /*
  434. * slave could interrupt in the middle of us generating a
  435. * start condition... if this happens, we'd better back off
  436. * and stop holding the poor thing up
  437. */
  438. writel(readl(_ICR(i2c)) & ~(ICR_START|ICR_STOP), _ICR(i2c));
  439. writel(readl(_ICR(i2c)) | ICR_TB, _ICR(i2c));
  440. timeout = 0x10000;
  441. while (1) {
  442. if ((readl(_IBMR(i2c)) & 2) == 2)
  443. break;
  444. timeout--;
  445. if (timeout <= 0) {
  446. dev_err(&i2c->adap.dev, "timeout waiting for SCL high\n");
  447. break;
  448. }
  449. }
  450. writel(readl(_ICR(i2c)) & ~ICR_SCLE, _ICR(i2c));
  451. }
  452. static void i2c_pxa_slave_stop(struct pxa_i2c *i2c)
  453. {
  454. if (i2c_debug > 2)
  455. dev_dbg(&i2c->adap.dev, "ISR: SSD (Slave Stop)\n");
  456. if (i2c->slave != NULL)
  457. i2c->slave->event(i2c->slave->data, I2C_SLAVE_EVENT_STOP);
  458. if (i2c_debug > 2)
  459. dev_dbg(&i2c->adap.dev, "ISR: SSD (Slave Stop) acked\n");
  460. /*
  461. * If we have a master-mode message waiting,
  462. * kick it off now that the slave has completed.
  463. */
  464. if (i2c->msg)
  465. i2c_pxa_master_complete(i2c, I2C_RETRY);
  466. }
  467. #else
  468. static void i2c_pxa_slave_txempty(struct pxa_i2c *i2c, u32 isr)
  469. {
  470. if (isr & ISR_BED) {
  471. /* what should we do here? */
  472. } else {
  473. writel(0, _IDBR(i2c));
  474. writel(readl(_ICR(i2c)) | ICR_TB, _ICR(i2c));
  475. }
  476. }
  477. static void i2c_pxa_slave_rxfull(struct pxa_i2c *i2c, u32 isr)
  478. {
  479. writel(readl(_ICR(i2c)) | ICR_TB | ICR_ACKNAK, _ICR(i2c));
  480. }
  481. static void i2c_pxa_slave_start(struct pxa_i2c *i2c, u32 isr)
  482. {
  483. int timeout;
  484. /*
  485. * slave could interrupt in the middle of us generating a
  486. * start condition... if this happens, we'd better back off
  487. * and stop holding the poor thing up
  488. */
  489. writel(readl(_ICR(i2c)) & ~(ICR_START|ICR_STOP), _ICR(i2c));
  490. writel(readl(_ICR(i2c)) | ICR_TB | ICR_ACKNAK, _ICR(i2c));
  491. timeout = 0x10000;
  492. while (1) {
  493. if ((readl(_IBMR(i2c)) & 2) == 2)
  494. break;
  495. timeout--;
  496. if (timeout <= 0) {
  497. dev_err(&i2c->adap.dev, "timeout waiting for SCL high\n");
  498. break;
  499. }
  500. }
  501. writel(readl(_ICR(i2c)) & ~ICR_SCLE, _ICR(i2c));
  502. }
  503. static void i2c_pxa_slave_stop(struct pxa_i2c *i2c)
  504. {
  505. if (i2c->msg)
  506. i2c_pxa_master_complete(i2c, I2C_RETRY);
  507. }
  508. #endif
  509. /*
  510. * PXA I2C Master mode
  511. */
  512. static inline unsigned int i2c_pxa_addr_byte(struct i2c_msg *msg)
  513. {
  514. unsigned int addr = (msg->addr & 0x7f) << 1;
  515. if (msg->flags & I2C_M_RD)
  516. addr |= 1;
  517. return addr;
  518. }
  519. static inline void i2c_pxa_start_message(struct pxa_i2c *i2c)
  520. {
  521. u32 icr;
  522. /*
  523. * Step 1: target slave address into IDBR
  524. */
  525. writel(i2c_pxa_addr_byte(i2c->msg), _IDBR(i2c));
  526. /*
  527. * Step 2: initiate the write.
  528. */
  529. icr = readl(_ICR(i2c)) & ~(ICR_STOP | ICR_ALDIE);
  530. writel(icr | ICR_START | ICR_TB, _ICR(i2c));
  531. }
  532. static inline void i2c_pxa_stop_message(struct pxa_i2c *i2c)
  533. {
  534. u32 icr;
  535. /*
  536. * Clear the STOP and ACK flags
  537. */
  538. icr = readl(_ICR(i2c));
  539. icr &= ~(ICR_STOP | ICR_ACKNAK);
  540. writel(icr, _ICR(i2c));
  541. }
  542. static int i2c_pxa_pio_set_master(struct pxa_i2c *i2c)
  543. {
  544. /* make timeout the same as for interrupt based functions */
  545. long timeout = 2 * DEF_TIMEOUT;
  546. /*
  547. * Wait for the bus to become free.
  548. */
  549. while (timeout-- && readl(_ISR(i2c)) & (ISR_IBB | ISR_UB)) {
  550. udelay(1000);
  551. show_state(i2c);
  552. }
  553. if (timeout < 0) {
  554. show_state(i2c);
  555. dev_err(&i2c->adap.dev,
  556. "i2c_pxa: timeout waiting for bus free\n");
  557. return I2C_RETRY;
  558. }
  559. /*
  560. * Set master mode.
  561. */
  562. writel(readl(_ICR(i2c)) | ICR_SCLE, _ICR(i2c));
  563. return 0;
  564. }
  565. static int i2c_pxa_do_pio_xfer(struct pxa_i2c *i2c,
  566. struct i2c_msg *msg, int num)
  567. {
  568. unsigned long timeout = 500000; /* 5 seconds */
  569. int ret = 0;
  570. ret = i2c_pxa_pio_set_master(i2c);
  571. if (ret)
  572. goto out;
  573. i2c->msg = msg;
  574. i2c->msg_num = num;
  575. i2c->msg_idx = 0;
  576. i2c->msg_ptr = 0;
  577. i2c->irqlogidx = 0;
  578. i2c_pxa_start_message(i2c);
  579. while (i2c->msg_num > 0 && --timeout) {
  580. i2c_pxa_handler(0, i2c);
  581. udelay(10);
  582. }
  583. i2c_pxa_stop_message(i2c);
  584. /*
  585. * We place the return code in i2c->msg_idx.
  586. */
  587. ret = i2c->msg_idx;
  588. out:
  589. if (timeout == 0)
  590. i2c_pxa_scream_blue_murder(i2c, "timeout");
  591. return ret;
  592. }
  593. /*
  594. * We are protected by the adapter bus mutex.
  595. */
  596. static int i2c_pxa_do_xfer(struct pxa_i2c *i2c, struct i2c_msg *msg, int num)
  597. {
  598. long timeout;
  599. int ret;
  600. /*
  601. * Wait for the bus to become free.
  602. */
  603. ret = i2c_pxa_wait_bus_not_busy(i2c);
  604. if (ret) {
  605. dev_err(&i2c->adap.dev, "i2c_pxa: timeout waiting for bus free\n");
  606. goto out;
  607. }
  608. /*
  609. * Set master mode.
  610. */
  611. ret = i2c_pxa_set_master(i2c);
  612. if (ret) {
  613. dev_err(&i2c->adap.dev, "i2c_pxa_set_master: error %d\n", ret);
  614. goto out;
  615. }
  616. spin_lock_irq(&i2c->lock);
  617. i2c->msg = msg;
  618. i2c->msg_num = num;
  619. i2c->msg_idx = 0;
  620. i2c->msg_ptr = 0;
  621. i2c->irqlogidx = 0;
  622. i2c_pxa_start_message(i2c);
  623. spin_unlock_irq(&i2c->lock);
  624. /*
  625. * The rest of the processing occurs in the interrupt handler.
  626. */
  627. timeout = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5);
  628. i2c_pxa_stop_message(i2c);
  629. /*
  630. * We place the return code in i2c->msg_idx.
  631. */
  632. ret = i2c->msg_idx;
  633. if (timeout == 0)
  634. i2c_pxa_scream_blue_murder(i2c, "timeout");
  635. out:
  636. return ret;
  637. }
  638. static int i2c_pxa_pio_xfer(struct i2c_adapter *adap,
  639. struct i2c_msg msgs[], int num)
  640. {
  641. struct pxa_i2c *i2c = adap->algo_data;
  642. int ret, i;
  643. /* If the I2C controller is disabled we need to reset it
  644. (probably due to a suspend/resume destroying state). We do
  645. this here as we can then avoid worrying about resuming the
  646. controller before its users. */
  647. if (!(readl(_ICR(i2c)) & ICR_IUE))
  648. i2c_pxa_reset(i2c);
  649. for (i = adap->retries; i >= 0; i--) {
  650. ret = i2c_pxa_do_pio_xfer(i2c, msgs, num);
  651. if (ret != I2C_RETRY)
  652. goto out;
  653. if (i2c_debug)
  654. dev_dbg(&adap->dev, "Retrying transmission\n");
  655. udelay(100);
  656. }
  657. i2c_pxa_scream_blue_murder(i2c, "exhausted retries");
  658. ret = -EREMOTEIO;
  659. out:
  660. i2c_pxa_set_slave(i2c, ret);
  661. return ret;
  662. }
  663. /*
  664. * i2c_pxa_master_complete - complete the message and wake up.
  665. */
  666. static void i2c_pxa_master_complete(struct pxa_i2c *i2c, int ret)
  667. {
  668. i2c->msg_ptr = 0;
  669. i2c->msg = NULL;
  670. i2c->msg_idx ++;
  671. i2c->msg_num = 0;
  672. if (ret)
  673. i2c->msg_idx = ret;
  674. if (!i2c->use_pio)
  675. wake_up(&i2c->wait);
  676. }
  677. static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c, u32 isr)
  678. {
  679. u32 icr = readl(_ICR(i2c)) & ~(ICR_START|ICR_STOP|ICR_ACKNAK|ICR_TB);
  680. again:
  681. /*
  682. * If ISR_ALD is set, we lost arbitration.
  683. */
  684. if (isr & ISR_ALD) {
  685. /*
  686. * Do we need to do anything here? The PXA docs
  687. * are vague about what happens.
  688. */
  689. i2c_pxa_scream_blue_murder(i2c, "ALD set");
  690. /*
  691. * We ignore this error. We seem to see spurious ALDs
  692. * for seemingly no reason. If we handle them as I think
  693. * they should, we end up causing an I2C error, which
  694. * is painful for some systems.
  695. */
  696. return; /* ignore */
  697. }
  698. if (isr & ISR_BED) {
  699. int ret = BUS_ERROR;
  700. /*
  701. * I2C bus error - either the device NAK'd us, or
  702. * something more serious happened. If we were NAK'd
  703. * on the initial address phase, we can retry.
  704. */
  705. if (isr & ISR_ACKNAK) {
  706. if (i2c->msg_ptr == 0 && i2c->msg_idx == 0)
  707. ret = I2C_RETRY;
  708. else
  709. ret = XFER_NAKED;
  710. }
  711. i2c_pxa_master_complete(i2c, ret);
  712. } else if (isr & ISR_RWM) {
  713. /*
  714. * Read mode. We have just sent the address byte, and
  715. * now we must initiate the transfer.
  716. */
  717. if (i2c->msg_ptr == i2c->msg->len - 1 &&
  718. i2c->msg_idx == i2c->msg_num - 1)
  719. icr |= ICR_STOP | ICR_ACKNAK;
  720. icr |= ICR_ALDIE | ICR_TB;
  721. } else if (i2c->msg_ptr < i2c->msg->len) {
  722. /*
  723. * Write mode. Write the next data byte.
  724. */
  725. writel(i2c->msg->buf[i2c->msg_ptr++], _IDBR(i2c));
  726. icr |= ICR_ALDIE | ICR_TB;
  727. /*
  728. * If this is the last byte of the last message, send
  729. * a STOP.
  730. */
  731. if (i2c->msg_ptr == i2c->msg->len &&
  732. i2c->msg_idx == i2c->msg_num - 1)
  733. icr |= ICR_STOP;
  734. } else if (i2c->msg_idx < i2c->msg_num - 1) {
  735. /*
  736. * Next segment of the message.
  737. */
  738. i2c->msg_ptr = 0;
  739. i2c->msg_idx ++;
  740. i2c->msg++;
  741. /*
  742. * If we aren't doing a repeated start and address,
  743. * go back and try to send the next byte. Note that
  744. * we do not support switching the R/W direction here.
  745. */
  746. if (i2c->msg->flags & I2C_M_NOSTART)
  747. goto again;
  748. /*
  749. * Write the next address.
  750. */
  751. writel(i2c_pxa_addr_byte(i2c->msg), _IDBR(i2c));
  752. /*
  753. * And trigger a repeated start, and send the byte.
  754. */
  755. icr &= ~ICR_ALDIE;
  756. icr |= ICR_START | ICR_TB;
  757. } else {
  758. if (i2c->msg->len == 0) {
  759. /*
  760. * Device probes have a message length of zero
  761. * and need the bus to be reset before it can
  762. * be used again.
  763. */
  764. i2c_pxa_reset(i2c);
  765. }
  766. i2c_pxa_master_complete(i2c, 0);
  767. }
  768. i2c->icrlog[i2c->irqlogidx-1] = icr;
  769. writel(icr, _ICR(i2c));
  770. show_state(i2c);
  771. }
  772. static void i2c_pxa_irq_rxfull(struct pxa_i2c *i2c, u32 isr)
  773. {
  774. u32 icr = readl(_ICR(i2c)) & ~(ICR_START|ICR_STOP|ICR_ACKNAK|ICR_TB);
  775. /*
  776. * Read the byte.
  777. */
  778. i2c->msg->buf[i2c->msg_ptr++] = readl(_IDBR(i2c));
  779. if (i2c->msg_ptr < i2c->msg->len) {
  780. /*
  781. * If this is the last byte of the last
  782. * message, send a STOP.
  783. */
  784. if (i2c->msg_ptr == i2c->msg->len - 1)
  785. icr |= ICR_STOP | ICR_ACKNAK;
  786. icr |= ICR_ALDIE | ICR_TB;
  787. } else {
  788. i2c_pxa_master_complete(i2c, 0);
  789. }
  790. i2c->icrlog[i2c->irqlogidx-1] = icr;
  791. writel(icr, _ICR(i2c));
  792. }
  793. static irqreturn_t i2c_pxa_handler(int this_irq, void *dev_id)
  794. {
  795. struct pxa_i2c *i2c = dev_id;
  796. u32 isr = readl(_ISR(i2c));
  797. if (i2c_debug > 2 && 0) {
  798. dev_dbg(&i2c->adap.dev, "%s: ISR=%08x, ICR=%08x, IBMR=%02x\n",
  799. __func__, isr, readl(_ICR(i2c)), readl(_IBMR(i2c)));
  800. decode_ISR(isr);
  801. }
  802. if (i2c->irqlogidx < ARRAY_SIZE(i2c->isrlog))
  803. i2c->isrlog[i2c->irqlogidx++] = isr;
  804. show_state(i2c);
  805. /*
  806. * Always clear all pending IRQs.
  807. */
  808. writel(isr & (ISR_SSD|ISR_ALD|ISR_ITE|ISR_IRF|ISR_SAD|ISR_BED), _ISR(i2c));
  809. if (isr & ISR_SAD)
  810. i2c_pxa_slave_start(i2c, isr);
  811. if (isr & ISR_SSD)
  812. i2c_pxa_slave_stop(i2c);
  813. if (i2c_pxa_is_slavemode(i2c)) {
  814. if (isr & ISR_ITE)
  815. i2c_pxa_slave_txempty(i2c, isr);
  816. if (isr & ISR_IRF)
  817. i2c_pxa_slave_rxfull(i2c, isr);
  818. } else if (i2c->msg) {
  819. if (isr & ISR_ITE)
  820. i2c_pxa_irq_txempty(i2c, isr);
  821. if (isr & ISR_IRF)
  822. i2c_pxa_irq_rxfull(i2c, isr);
  823. } else {
  824. i2c_pxa_scream_blue_murder(i2c, "spurious irq");
  825. }
  826. return IRQ_HANDLED;
  827. }
  828. static int i2c_pxa_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
  829. {
  830. struct pxa_i2c *i2c = adap->algo_data;
  831. int ret, i;
  832. for (i = adap->retries; i >= 0; i--) {
  833. ret = i2c_pxa_do_xfer(i2c, msgs, num);
  834. if (ret != I2C_RETRY)
  835. goto out;
  836. if (i2c_debug)
  837. dev_dbg(&adap->dev, "Retrying transmission\n");
  838. udelay(100);
  839. }
  840. i2c_pxa_scream_blue_murder(i2c, "exhausted retries");
  841. ret = -EREMOTEIO;
  842. out:
  843. i2c_pxa_set_slave(i2c, ret);
  844. return ret;
  845. }
  846. static u32 i2c_pxa_functionality(struct i2c_adapter *adap)
  847. {
  848. return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
  849. }
  850. static const struct i2c_algorithm i2c_pxa_algorithm = {
  851. .master_xfer = i2c_pxa_xfer,
  852. .functionality = i2c_pxa_functionality,
  853. };
  854. static const struct i2c_algorithm i2c_pxa_pio_algorithm = {
  855. .master_xfer = i2c_pxa_pio_xfer,
  856. .functionality = i2c_pxa_functionality,
  857. };
  858. static int i2c_pxa_probe(struct platform_device *dev)
  859. {
  860. struct pxa_i2c *i2c;
  861. struct resource *res;
  862. struct i2c_pxa_platform_data *plat = dev->dev.platform_data;
  863. const struct platform_device_id *id = platform_get_device_id(dev);
  864. enum pxa_i2c_types i2c_type = id->driver_data;
  865. int ret;
  866. int irq;
  867. res = platform_get_resource(dev, IORESOURCE_MEM, 0);
  868. irq = platform_get_irq(dev, 0);
  869. if (res == NULL || irq < 0)
  870. return -ENODEV;
  871. if (!request_mem_region(res->start, resource_size(res), res->name))
  872. return -ENOMEM;
  873. i2c = kzalloc(sizeof(struct pxa_i2c), GFP_KERNEL);
  874. if (!i2c) {
  875. ret = -ENOMEM;
  876. goto emalloc;
  877. }
  878. i2c->adap.owner = THIS_MODULE;
  879. i2c->adap.retries = 5;
  880. spin_lock_init(&i2c->lock);
  881. init_waitqueue_head(&i2c->wait);
  882. /*
  883. * If "dev->id" is negative we consider it as zero.
  884. * The reason to do so is to avoid sysfs names that only make
  885. * sense when there are multiple adapters.
  886. */
  887. i2c->adap.nr = dev->id != -1 ? dev->id : 0;
  888. snprintf(i2c->adap.name, sizeof(i2c->adap.name), "pxa_i2c-i2c.%u",
  889. i2c->adap.nr);
  890. i2c->clk = clk_get(&dev->dev, NULL);
  891. if (IS_ERR(i2c->clk)) {
  892. ret = PTR_ERR(i2c->clk);
  893. goto eclk;
  894. }
  895. i2c->reg_base = ioremap(res->start, resource_size(res));
  896. if (!i2c->reg_base) {
  897. ret = -EIO;
  898. goto eremap;
  899. }
  900. i2c->reg_ibmr = i2c->reg_base + pxa_reg_layout[i2c_type].ibmr;
  901. i2c->reg_idbr = i2c->reg_base + pxa_reg_layout[i2c_type].idbr;
  902. i2c->reg_icr = i2c->reg_base + pxa_reg_layout[i2c_type].icr;
  903. i2c->reg_isr = i2c->reg_base + pxa_reg_layout[i2c_type].isr;
  904. if (i2c_type != REGS_CE4100)
  905. i2c->reg_isar = i2c->reg_base + pxa_reg_layout[i2c_type].isar;
  906. i2c->iobase = res->start;
  907. i2c->iosize = resource_size(res);
  908. i2c->irq = irq;
  909. i2c->slave_addr = I2C_PXA_SLAVE_ADDR;
  910. #ifdef CONFIG_I2C_PXA_SLAVE
  911. if (plat) {
  912. i2c->slave_addr = plat->slave_addr;
  913. i2c->slave = plat->slave;
  914. }
  915. #endif
  916. clk_enable(i2c->clk);
  917. if (plat) {
  918. i2c->adap.class = plat->class;
  919. i2c->use_pio = plat->use_pio;
  920. i2c->fast_mode = plat->fast_mode;
  921. }
  922. if (i2c->use_pio) {
  923. i2c->adap.algo = &i2c_pxa_pio_algorithm;
  924. } else {
  925. i2c->adap.algo = &i2c_pxa_algorithm;
  926. ret = request_irq(irq, i2c_pxa_handler, IRQF_DISABLED,
  927. i2c->adap.name, i2c);
  928. if (ret)
  929. goto ereqirq;
  930. }
  931. i2c_pxa_reset(i2c);
  932. i2c->adap.algo_data = i2c;
  933. i2c->adap.dev.parent = &dev->dev;
  934. if (i2c_type == REGS_CE4100)
  935. ret = i2c_add_adapter(&i2c->adap);
  936. else
  937. ret = i2c_add_numbered_adapter(&i2c->adap);
  938. if (ret < 0) {
  939. printk(KERN_INFO "I2C: Failed to add bus\n");
  940. goto eadapt;
  941. }
  942. platform_set_drvdata(dev, i2c);
  943. #ifdef CONFIG_I2C_PXA_SLAVE
  944. printk(KERN_INFO "I2C: %s: PXA I2C adapter, slave address %d\n",
  945. dev_name(&i2c->adap.dev), i2c->slave_addr);
  946. #else
  947. printk(KERN_INFO "I2C: %s: PXA I2C adapter\n",
  948. dev_name(&i2c->adap.dev));
  949. #endif
  950. return 0;
  951. eadapt:
  952. if (!i2c->use_pio)
  953. free_irq(irq, i2c);
  954. ereqirq:
  955. clk_disable(i2c->clk);
  956. iounmap(i2c->reg_base);
  957. eremap:
  958. clk_put(i2c->clk);
  959. eclk:
  960. kfree(i2c);
  961. emalloc:
  962. release_mem_region(res->start, resource_size(res));
  963. return ret;
  964. }
  965. static int __exit i2c_pxa_remove(struct platform_device *dev)
  966. {
  967. struct pxa_i2c *i2c = platform_get_drvdata(dev);
  968. platform_set_drvdata(dev, NULL);
  969. i2c_del_adapter(&i2c->adap);
  970. if (!i2c->use_pio)
  971. free_irq(i2c->irq, i2c);
  972. clk_disable(i2c->clk);
  973. clk_put(i2c->clk);
  974. iounmap(i2c->reg_base);
  975. release_mem_region(i2c->iobase, i2c->iosize);
  976. kfree(i2c);
  977. return 0;
  978. }
  979. #ifdef CONFIG_PM
  980. static int i2c_pxa_suspend_noirq(struct device *dev)
  981. {
  982. struct platform_device *pdev = to_platform_device(dev);
  983. struct pxa_i2c *i2c = platform_get_drvdata(pdev);
  984. clk_disable(i2c->clk);
  985. return 0;
  986. }
  987. static int i2c_pxa_resume_noirq(struct device *dev)
  988. {
  989. struct platform_device *pdev = to_platform_device(dev);
  990. struct pxa_i2c *i2c = platform_get_drvdata(pdev);
  991. clk_enable(i2c->clk);
  992. i2c_pxa_reset(i2c);
  993. return 0;
  994. }
  995. static const struct dev_pm_ops i2c_pxa_dev_pm_ops = {
  996. .suspend_noirq = i2c_pxa_suspend_noirq,
  997. .resume_noirq = i2c_pxa_resume_noirq,
  998. };
  999. #define I2C_PXA_DEV_PM_OPS (&i2c_pxa_dev_pm_ops)
  1000. #else
  1001. #define I2C_PXA_DEV_PM_OPS NULL
  1002. #endif
  1003. static struct platform_driver i2c_pxa_driver = {
  1004. .probe = i2c_pxa_probe,
  1005. .remove = __exit_p(i2c_pxa_remove),
  1006. .driver = {
  1007. .name = "pxa2xx-i2c",
  1008. .owner = THIS_MODULE,
  1009. .pm = I2C_PXA_DEV_PM_OPS,
  1010. },
  1011. .id_table = i2c_pxa_id_table,
  1012. };
  1013. static int __init i2c_adap_pxa_init(void)
  1014. {
  1015. return platform_driver_register(&i2c_pxa_driver);
  1016. }
  1017. static void __exit i2c_adap_pxa_exit(void)
  1018. {
  1019. platform_driver_unregister(&i2c_pxa_driver);
  1020. }
  1021. MODULE_LICENSE("GPL");
  1022. MODULE_ALIAS("platform:pxa2xx-i2c");
  1023. subsys_initcall(i2c_adap_pxa_init);
  1024. module_exit(i2c_adap_pxa_exit);