i2c-pxa.c 28 KB

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