i2c-mpc.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. /*
  2. * (C) Copyright 2003-2004
  3. * Humboldt Solutions Ltd, adrian@humboldt.co.uk.
  4. * This is a combined i2c adapter and algorithm driver for the
  5. * MPC107/Tsi107 PowerPC northbridge and processors that include
  6. * the same I2C unit (8240, 8245, 85xx).
  7. *
  8. * Release 0.8
  9. *
  10. * This file is licensed under the terms of the GNU General Public
  11. * License version 2. This program is licensed "as is" without any
  12. * warranty of any kind, whether express or implied.
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <linux/sched.h>
  17. #include <linux/init.h>
  18. #include <linux/of_platform.h>
  19. #include <linux/of_i2c.h>
  20. #include <linux/io.h>
  21. #include <linux/fsl_devices.h>
  22. #include <linux/i2c.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/delay.h>
  25. #include <asm/mpc52xx.h>
  26. #include <sysdev/fsl_soc.h>
  27. #define DRV_NAME "mpc-i2c"
  28. #define MPC_I2C_FDR 0x04
  29. #define MPC_I2C_CR 0x08
  30. #define MPC_I2C_SR 0x0c
  31. #define MPC_I2C_DR 0x10
  32. #define MPC_I2C_DFSRR 0x14
  33. #define CCR_MEN 0x80
  34. #define CCR_MIEN 0x40
  35. #define CCR_MSTA 0x20
  36. #define CCR_MTX 0x10
  37. #define CCR_TXAK 0x08
  38. #define CCR_RSTA 0x04
  39. #define CSR_MCF 0x80
  40. #define CSR_MAAS 0x40
  41. #define CSR_MBB 0x20
  42. #define CSR_MAL 0x10
  43. #define CSR_SRW 0x04
  44. #define CSR_MIF 0x02
  45. #define CSR_RXAK 0x01
  46. struct mpc_i2c {
  47. struct device *dev;
  48. void __iomem *base;
  49. u32 interrupt;
  50. wait_queue_head_t queue;
  51. struct i2c_adapter adap;
  52. int irq;
  53. };
  54. struct mpc_i2c_divider {
  55. u16 divider;
  56. u16 fdr; /* including dfsrr */
  57. };
  58. struct mpc_i2c_match_data {
  59. void (*setclock)(struct device_node *node,
  60. struct mpc_i2c *i2c,
  61. u32 clock, u32 prescaler);
  62. u32 prescaler;
  63. };
  64. static inline void writeccr(struct mpc_i2c *i2c, u32 x)
  65. {
  66. writeb(x, i2c->base + MPC_I2C_CR);
  67. }
  68. static irqreturn_t mpc_i2c_isr(int irq, void *dev_id)
  69. {
  70. struct mpc_i2c *i2c = dev_id;
  71. if (readb(i2c->base + MPC_I2C_SR) & CSR_MIF) {
  72. /* Read again to allow register to stabilise */
  73. i2c->interrupt = readb(i2c->base + MPC_I2C_SR);
  74. writeb(0, i2c->base + MPC_I2C_SR);
  75. wake_up(&i2c->queue);
  76. }
  77. return IRQ_HANDLED;
  78. }
  79. /* Sometimes 9th clock pulse isn't generated, and slave doesn't release
  80. * the bus, because it wants to send ACK.
  81. * Following sequence of enabling/disabling and sending start/stop generates
  82. * the pulse, so it's all OK.
  83. */
  84. static void mpc_i2c_fixup(struct mpc_i2c *i2c)
  85. {
  86. writeccr(i2c, 0);
  87. udelay(30);
  88. writeccr(i2c, CCR_MEN);
  89. udelay(30);
  90. writeccr(i2c, CCR_MSTA | CCR_MTX);
  91. udelay(30);
  92. writeccr(i2c, CCR_MSTA | CCR_MTX | CCR_MEN);
  93. udelay(30);
  94. writeccr(i2c, CCR_MEN);
  95. udelay(30);
  96. }
  97. static int i2c_wait(struct mpc_i2c *i2c, unsigned timeout, int writing)
  98. {
  99. unsigned long orig_jiffies = jiffies;
  100. u32 x;
  101. int result = 0;
  102. if (i2c->irq == NO_IRQ) {
  103. while (!(readb(i2c->base + MPC_I2C_SR) & CSR_MIF)) {
  104. schedule();
  105. if (time_after(jiffies, orig_jiffies + timeout)) {
  106. dev_dbg(i2c->dev, "timeout\n");
  107. writeccr(i2c, 0);
  108. result = -EIO;
  109. break;
  110. }
  111. }
  112. x = readb(i2c->base + MPC_I2C_SR);
  113. writeb(0, i2c->base + MPC_I2C_SR);
  114. } else {
  115. /* Interrupt mode */
  116. result = wait_event_timeout(i2c->queue,
  117. (i2c->interrupt & CSR_MIF), timeout);
  118. if (unlikely(!(i2c->interrupt & CSR_MIF))) {
  119. dev_dbg(i2c->dev, "wait timeout\n");
  120. writeccr(i2c, 0);
  121. result = -ETIMEDOUT;
  122. }
  123. x = i2c->interrupt;
  124. i2c->interrupt = 0;
  125. }
  126. if (result < 0)
  127. return result;
  128. if (!(x & CSR_MCF)) {
  129. dev_dbg(i2c->dev, "unfinished\n");
  130. return -EIO;
  131. }
  132. if (x & CSR_MAL) {
  133. dev_dbg(i2c->dev, "MAL\n");
  134. return -EIO;
  135. }
  136. if (writing && (x & CSR_RXAK)) {
  137. dev_dbg(i2c->dev, "No RXAK\n");
  138. /* generate stop */
  139. writeccr(i2c, CCR_MEN);
  140. return -EIO;
  141. }
  142. return 0;
  143. }
  144. #ifdef CONFIG_PPC_MPC52xx
  145. static const struct mpc_i2c_divider mpc_i2c_dividers_52xx[] = {
  146. {20, 0x20}, {22, 0x21}, {24, 0x22}, {26, 0x23},
  147. {28, 0x24}, {30, 0x01}, {32, 0x25}, {34, 0x02},
  148. {36, 0x26}, {40, 0x27}, {44, 0x04}, {48, 0x28},
  149. {52, 0x63}, {56, 0x29}, {60, 0x41}, {64, 0x2a},
  150. {68, 0x07}, {72, 0x2b}, {80, 0x2c}, {88, 0x09},
  151. {96, 0x2d}, {104, 0x0a}, {112, 0x2e}, {120, 0x81},
  152. {128, 0x2f}, {136, 0x47}, {144, 0x0c}, {160, 0x30},
  153. {176, 0x49}, {192, 0x31}, {208, 0x4a}, {224, 0x32},
  154. {240, 0x0f}, {256, 0x33}, {272, 0x87}, {288, 0x10},
  155. {320, 0x34}, {352, 0x89}, {384, 0x35}, {416, 0x8a},
  156. {448, 0x36}, {480, 0x13}, {512, 0x37}, {576, 0x14},
  157. {640, 0x38}, {768, 0x39}, {896, 0x3a}, {960, 0x17},
  158. {1024, 0x3b}, {1152, 0x18}, {1280, 0x3c}, {1536, 0x3d},
  159. {1792, 0x3e}, {1920, 0x1b}, {2048, 0x3f}, {2304, 0x1c},
  160. {2560, 0x1d}, {3072, 0x1e}, {3584, 0x7e}, {3840, 0x1f},
  161. {4096, 0x7f}, {4608, 0x5c}, {5120, 0x5d}, {6144, 0x5e},
  162. {7168, 0xbe}, {7680, 0x5f}, {8192, 0xbf}, {9216, 0x9c},
  163. {10240, 0x9d}, {12288, 0x9e}, {15360, 0x9f}
  164. };
  165. int mpc_i2c_get_fdr_52xx(struct device_node *node, u32 clock, int prescaler)
  166. {
  167. const struct mpc_i2c_divider *div = NULL;
  168. unsigned int pvr = mfspr(SPRN_PVR);
  169. u32 divider;
  170. int i;
  171. if (!clock)
  172. return -EINVAL;
  173. /* Determine divider value */
  174. divider = mpc52xx_find_ipb_freq(node) / clock;
  175. /*
  176. * We want to choose an FDR/DFSR that generates an I2C bus speed that
  177. * is equal to or lower than the requested speed.
  178. */
  179. for (i = 0; i < ARRAY_SIZE(mpc_i2c_dividers_52xx); i++) {
  180. div = &mpc_i2c_dividers_52xx[i];
  181. /* Old MPC5200 rev A CPUs do not support the high bits */
  182. if (div->fdr & 0xc0 && pvr == 0x80822011)
  183. continue;
  184. if (div->divider >= divider)
  185. break;
  186. }
  187. return div ? (int)div->fdr : -EINVAL;
  188. }
  189. static void mpc_i2c_setclock_52xx(struct device_node *node,
  190. struct mpc_i2c *i2c,
  191. u32 clock, u32 prescaler)
  192. {
  193. int ret, fdr;
  194. ret = mpc_i2c_get_fdr_52xx(node, clock, prescaler);
  195. fdr = (ret >= 0) ? ret : 0x3f; /* backward compatibility */
  196. writeb(fdr & 0xff, i2c->base + MPC_I2C_FDR);
  197. if (ret >= 0)
  198. dev_info(i2c->dev, "clock %d Hz (fdr=%d)\n", clock, fdr);
  199. }
  200. #else /* !CONFIG_PPC_MPC52xx */
  201. static void mpc_i2c_setclock_52xx(struct device_node *node,
  202. struct mpc_i2c *i2c,
  203. u32 clock, u32 prescaler)
  204. {
  205. }
  206. #endif /* CONFIG_PPC_MPC52xx*/
  207. #ifdef CONFIG_FSL_SOC
  208. static const struct mpc_i2c_divider mpc_i2c_dividers_8xxx[] = {
  209. {160, 0x0120}, {192, 0x0121}, {224, 0x0122}, {256, 0x0123},
  210. {288, 0x0100}, {320, 0x0101}, {352, 0x0601}, {384, 0x0102},
  211. {416, 0x0602}, {448, 0x0126}, {480, 0x0103}, {512, 0x0127},
  212. {544, 0x0b03}, {576, 0x0104}, {608, 0x1603}, {640, 0x0105},
  213. {672, 0x2003}, {704, 0x0b05}, {736, 0x2b03}, {768, 0x0106},
  214. {800, 0x3603}, {832, 0x0b06}, {896, 0x012a}, {960, 0x0107},
  215. {1024, 0x012b}, {1088, 0x1607}, {1152, 0x0108}, {1216, 0x2b07},
  216. {1280, 0x0109}, {1408, 0x1609}, {1536, 0x010a}, {1664, 0x160a},
  217. {1792, 0x012e}, {1920, 0x010b}, {2048, 0x012f}, {2176, 0x2b0b},
  218. {2304, 0x010c}, {2560, 0x010d}, {2816, 0x2b0d}, {3072, 0x010e},
  219. {3328, 0x2b0e}, {3584, 0x0132}, {3840, 0x010f}, {4096, 0x0133},
  220. {4608, 0x0110}, {5120, 0x0111}, {6144, 0x0112}, {7168, 0x0136},
  221. {7680, 0x0113}, {8192, 0x0137}, {9216, 0x0114}, {10240, 0x0115},
  222. {12288, 0x0116}, {14336, 0x013a}, {15360, 0x0117}, {16384, 0x013b},
  223. {18432, 0x0118}, {20480, 0x0119}, {24576, 0x011a}, {28672, 0x013e},
  224. {30720, 0x011b}, {32768, 0x013f}, {36864, 0x011c}, {40960, 0x011d},
  225. {49152, 0x011e}, {61440, 0x011f}
  226. };
  227. u32 mpc_i2c_get_sec_cfg_8xxx(void)
  228. {
  229. struct device_node *node = NULL;
  230. u32 __iomem *reg;
  231. u32 val = 0;
  232. node = of_find_node_by_name(NULL, "global-utilities");
  233. if (node) {
  234. const u32 *prop = of_get_property(node, "reg", NULL);
  235. if (prop) {
  236. /*
  237. * Map and check POR Device Status Register 2
  238. * (PORDEVSR2) at 0xE0014
  239. */
  240. reg = ioremap(get_immrbase() + *prop + 0x14, 0x4);
  241. if (!reg)
  242. printk(KERN_ERR
  243. "Error: couldn't map PORDEVSR2\n");
  244. else
  245. val = in_be32(reg) & 0x00000080; /* sec-cfg */
  246. iounmap(reg);
  247. }
  248. }
  249. if (node)
  250. of_node_put(node);
  251. return val;
  252. }
  253. int mpc_i2c_get_fdr_8xxx(struct device_node *node, u32 clock, u32 prescaler)
  254. {
  255. const struct mpc_i2c_divider *div = NULL;
  256. u32 divider;
  257. int i;
  258. if (!clock)
  259. return -EINVAL;
  260. /* Determine proper divider value */
  261. if (of_device_is_compatible(node, "fsl,mpc8544-i2c"))
  262. prescaler = mpc_i2c_get_sec_cfg_8xxx() ? 3 : 2;
  263. if (!prescaler)
  264. prescaler = 1;
  265. divider = fsl_get_sys_freq() / clock / prescaler;
  266. pr_debug("I2C: src_clock=%d clock=%d divider=%d\n",
  267. fsl_get_sys_freq(), clock, divider);
  268. /*
  269. * We want to choose an FDR/DFSR that generates an I2C bus speed that
  270. * is equal to or lower than the requested speed.
  271. */
  272. for (i = 0; i < ARRAY_SIZE(mpc_i2c_dividers_8xxx); i++) {
  273. div = &mpc_i2c_dividers_8xxx[i];
  274. if (div->divider >= divider)
  275. break;
  276. }
  277. return div ? (int)div->fdr : -EINVAL;
  278. }
  279. static void mpc_i2c_setclock_8xxx(struct device_node *node,
  280. struct mpc_i2c *i2c,
  281. u32 clock, u32 prescaler)
  282. {
  283. int ret, fdr;
  284. ret = mpc_i2c_get_fdr_8xxx(node, clock, prescaler);
  285. fdr = (ret >= 0) ? ret : 0x1031; /* backward compatibility */
  286. writeb(fdr & 0xff, i2c->base + MPC_I2C_FDR);
  287. writeb((fdr >> 8) & 0xff, i2c->base + MPC_I2C_DFSRR);
  288. if (ret >= 0)
  289. dev_info(i2c->dev, "clock %d Hz (dfsrr=%d fdr=%d)\n",
  290. clock, fdr >> 8, fdr & 0xff);
  291. }
  292. #else /* !CONFIG_FSL_SOC */
  293. static void mpc_i2c_setclock_8xxx(struct device_node *node,
  294. struct mpc_i2c *i2c,
  295. u32 clock, u32 prescaler)
  296. {
  297. }
  298. #endif /* CONFIG_FSL_SOC */
  299. static void mpc_i2c_start(struct mpc_i2c *i2c)
  300. {
  301. /* Clear arbitration */
  302. writeb(0, i2c->base + MPC_I2C_SR);
  303. /* Start with MEN */
  304. writeccr(i2c, CCR_MEN);
  305. }
  306. static void mpc_i2c_stop(struct mpc_i2c *i2c)
  307. {
  308. writeccr(i2c, CCR_MEN);
  309. }
  310. static int mpc_write(struct mpc_i2c *i2c, int target,
  311. const u8 *data, int length, int restart)
  312. {
  313. int i, result;
  314. unsigned timeout = i2c->adap.timeout;
  315. u32 flags = restart ? CCR_RSTA : 0;
  316. /* Start with MEN */
  317. if (!restart)
  318. writeccr(i2c, CCR_MEN);
  319. /* Start as master */
  320. writeccr(i2c, CCR_MIEN | CCR_MEN | CCR_MSTA | CCR_MTX | flags);
  321. /* Write target byte */
  322. writeb((target << 1), i2c->base + MPC_I2C_DR);
  323. result = i2c_wait(i2c, timeout, 1);
  324. if (result < 0)
  325. return result;
  326. for (i = 0; i < length; i++) {
  327. /* Write data byte */
  328. writeb(data[i], i2c->base + MPC_I2C_DR);
  329. result = i2c_wait(i2c, timeout, 1);
  330. if (result < 0)
  331. return result;
  332. }
  333. return 0;
  334. }
  335. static int mpc_read(struct mpc_i2c *i2c, int target,
  336. u8 *data, int length, int restart)
  337. {
  338. unsigned timeout = i2c->adap.timeout;
  339. int i, result;
  340. u32 flags = restart ? CCR_RSTA : 0;
  341. /* Start with MEN */
  342. if (!restart)
  343. writeccr(i2c, CCR_MEN);
  344. /* Switch to read - restart */
  345. writeccr(i2c, CCR_MIEN | CCR_MEN | CCR_MSTA | CCR_MTX | flags);
  346. /* Write target address byte - this time with the read flag set */
  347. writeb((target << 1) | 1, i2c->base + MPC_I2C_DR);
  348. result = i2c_wait(i2c, timeout, 1);
  349. if (result < 0)
  350. return result;
  351. if (length) {
  352. if (length == 1)
  353. writeccr(i2c, CCR_MIEN | CCR_MEN | CCR_MSTA | CCR_TXAK);
  354. else
  355. writeccr(i2c, CCR_MIEN | CCR_MEN | CCR_MSTA);
  356. /* Dummy read */
  357. readb(i2c->base + MPC_I2C_DR);
  358. }
  359. for (i = 0; i < length; i++) {
  360. result = i2c_wait(i2c, timeout, 0);
  361. if (result < 0)
  362. return result;
  363. /* Generate txack on next to last byte */
  364. if (i == length - 2)
  365. writeccr(i2c, CCR_MIEN | CCR_MEN | CCR_MSTA | CCR_TXAK);
  366. /* Generate stop on last byte */
  367. if (i == length - 1)
  368. writeccr(i2c, CCR_MIEN | CCR_MEN | CCR_TXAK);
  369. data[i] = readb(i2c->base + MPC_I2C_DR);
  370. }
  371. return length;
  372. }
  373. static int mpc_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
  374. {
  375. struct i2c_msg *pmsg;
  376. int i;
  377. int ret = 0;
  378. unsigned long orig_jiffies = jiffies;
  379. struct mpc_i2c *i2c = i2c_get_adapdata(adap);
  380. mpc_i2c_start(i2c);
  381. /* Allow bus up to 1s to become not busy */
  382. while (readb(i2c->base + MPC_I2C_SR) & CSR_MBB) {
  383. if (signal_pending(current)) {
  384. dev_dbg(i2c->dev, "Interrupted\n");
  385. writeccr(i2c, 0);
  386. return -EINTR;
  387. }
  388. if (time_after(jiffies, orig_jiffies + HZ)) {
  389. dev_dbg(i2c->dev, "timeout\n");
  390. if (readb(i2c->base + MPC_I2C_SR) ==
  391. (CSR_MCF | CSR_MBB | CSR_RXAK))
  392. mpc_i2c_fixup(i2c);
  393. return -EIO;
  394. }
  395. schedule();
  396. }
  397. for (i = 0; ret >= 0 && i < num; i++) {
  398. pmsg = &msgs[i];
  399. dev_dbg(i2c->dev,
  400. "Doing %s %d bytes to 0x%02x - %d of %d messages\n",
  401. pmsg->flags & I2C_M_RD ? "read" : "write",
  402. pmsg->len, pmsg->addr, i + 1, num);
  403. if (pmsg->flags & I2C_M_RD)
  404. ret =
  405. mpc_read(i2c, pmsg->addr, pmsg->buf, pmsg->len, i);
  406. else
  407. ret =
  408. mpc_write(i2c, pmsg->addr, pmsg->buf, pmsg->len, i);
  409. }
  410. mpc_i2c_stop(i2c);
  411. return (ret < 0) ? ret : num;
  412. }
  413. static u32 mpc_functionality(struct i2c_adapter *adap)
  414. {
  415. return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
  416. }
  417. static const struct i2c_algorithm mpc_algo = {
  418. .master_xfer = mpc_xfer,
  419. .functionality = mpc_functionality,
  420. };
  421. static struct i2c_adapter mpc_ops = {
  422. .owner = THIS_MODULE,
  423. .name = "MPC adapter",
  424. .algo = &mpc_algo,
  425. .timeout = HZ,
  426. };
  427. static int __devinit fsl_i2c_probe(struct of_device *op,
  428. const struct of_device_id *match)
  429. {
  430. struct mpc_i2c *i2c;
  431. const u32 *prop;
  432. u32 clock = 0;
  433. int result = 0;
  434. int plen;
  435. i2c = kzalloc(sizeof(*i2c), GFP_KERNEL);
  436. if (!i2c)
  437. return -ENOMEM;
  438. i2c->dev = &op->dev; /* for debug and error output */
  439. init_waitqueue_head(&i2c->queue);
  440. i2c->base = of_iomap(op->node, 0);
  441. if (!i2c->base) {
  442. dev_err(i2c->dev, "failed to map controller\n");
  443. result = -ENOMEM;
  444. goto fail_map;
  445. }
  446. i2c->irq = irq_of_parse_and_map(op->node, 0);
  447. if (i2c->irq != NO_IRQ) { /* i2c->irq = NO_IRQ implies polling */
  448. result = request_irq(i2c->irq, mpc_i2c_isr,
  449. IRQF_SHARED, "i2c-mpc", i2c);
  450. if (result < 0) {
  451. dev_err(i2c->dev, "failed to attach interrupt\n");
  452. goto fail_request;
  453. }
  454. }
  455. if (!of_get_property(op->node, "fsl,preserve-clocking", NULL)) {
  456. prop = of_get_property(op->node, "clock-frequency", &plen);
  457. if (prop && plen == sizeof(u32))
  458. clock = *prop;
  459. if (match->data) {
  460. struct mpc_i2c_match_data *data =
  461. (struct mpc_i2c_match_data *)match->data;
  462. data->setclock(op->node, i2c, clock, data->prescaler);
  463. } else {
  464. /* Backwards compatibility */
  465. if (of_get_property(op->node, "dfsrr", NULL))
  466. mpc_i2c_setclock_8xxx(op->node, i2c,
  467. clock, 0);
  468. }
  469. }
  470. dev_set_drvdata(&op->dev, i2c);
  471. i2c->adap = mpc_ops;
  472. i2c_set_adapdata(&i2c->adap, i2c);
  473. i2c->adap.dev.parent = &op->dev;
  474. result = i2c_add_adapter(&i2c->adap);
  475. if (result < 0) {
  476. dev_err(i2c->dev, "failed to add adapter\n");
  477. goto fail_add;
  478. }
  479. of_register_i2c_devices(&i2c->adap, op->node);
  480. return result;
  481. fail_add:
  482. dev_set_drvdata(&op->dev, NULL);
  483. free_irq(i2c->irq, i2c);
  484. fail_request:
  485. irq_dispose_mapping(i2c->irq);
  486. iounmap(i2c->base);
  487. fail_map:
  488. kfree(i2c);
  489. return result;
  490. };
  491. static int __devexit fsl_i2c_remove(struct of_device *op)
  492. {
  493. struct mpc_i2c *i2c = dev_get_drvdata(&op->dev);
  494. i2c_del_adapter(&i2c->adap);
  495. dev_set_drvdata(&op->dev, NULL);
  496. if (i2c->irq != NO_IRQ)
  497. free_irq(i2c->irq, i2c);
  498. irq_dispose_mapping(i2c->irq);
  499. iounmap(i2c->base);
  500. kfree(i2c);
  501. return 0;
  502. };
  503. static const struct of_device_id mpc_i2c_of_match[] = {
  504. {.compatible = "mpc5200-i2c",
  505. .data = &(struct mpc_i2c_match_data) {
  506. .setclock = mpc_i2c_setclock_52xx,
  507. },
  508. },
  509. {.compatible = "fsl,mpc5200b-i2c",
  510. .data = &(struct mpc_i2c_match_data) {
  511. .setclock = mpc_i2c_setclock_52xx,
  512. },
  513. },
  514. {.compatible = "fsl,mpc5200-i2c",
  515. .data = &(struct mpc_i2c_match_data) {
  516. .setclock = mpc_i2c_setclock_52xx,
  517. },
  518. },
  519. {.compatible = "fsl,mpc8313-i2c",
  520. .data = &(struct mpc_i2c_match_data) {
  521. .setclock = mpc_i2c_setclock_8xxx,
  522. },
  523. },
  524. {.compatible = "fsl,mpc8543-i2c",
  525. .data = &(struct mpc_i2c_match_data) {
  526. .setclock = mpc_i2c_setclock_8xxx,
  527. .prescaler = 2,
  528. },
  529. },
  530. {.compatible = "fsl,mpc8544-i2c",
  531. .data = &(struct mpc_i2c_match_data) {
  532. .setclock = mpc_i2c_setclock_8xxx,
  533. .prescaler = 3,
  534. },
  535. /* Backward compatibility */
  536. },
  537. {.compatible = "fsl-i2c", },
  538. {},
  539. };
  540. MODULE_DEVICE_TABLE(of, mpc_i2c_of_match);
  541. /* Structure for a device driver */
  542. static struct of_platform_driver mpc_i2c_driver = {
  543. .match_table = mpc_i2c_of_match,
  544. .probe = fsl_i2c_probe,
  545. .remove = __devexit_p(fsl_i2c_remove),
  546. .driver = {
  547. .owner = THIS_MODULE,
  548. .name = DRV_NAME,
  549. },
  550. };
  551. static int __init fsl_i2c_init(void)
  552. {
  553. int rv;
  554. rv = of_register_platform_driver(&mpc_i2c_driver);
  555. if (rv)
  556. printk(KERN_ERR DRV_NAME
  557. " of_register_platform_driver failed (%i)\n", rv);
  558. return rv;
  559. }
  560. static void __exit fsl_i2c_exit(void)
  561. {
  562. of_unregister_platform_driver(&mpc_i2c_driver);
  563. }
  564. module_init(fsl_i2c_init);
  565. module_exit(fsl_i2c_exit);
  566. MODULE_AUTHOR("Adrian Cox <adrian@humboldt.co.uk>");
  567. MODULE_DESCRIPTION("I2C-Bus adapter for MPC107 bridge and "
  568. "MPC824x/85xx/52xx processors");
  569. MODULE_LICENSE("GPL");