i2c-designware.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. /*
  2. * Synopsys Designware I2C adapter driver (master only).
  3. *
  4. * Based on the TI DAVINCI I2C adapter driver.
  5. *
  6. * Copyright (C) 2006 Texas Instruments.
  7. * Copyright (C) 2007 MontaVista Software Inc.
  8. * Copyright (C) 2009 Provigent Ltd.
  9. *
  10. * ----------------------------------------------------------------------------
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  25. * ----------------------------------------------------------------------------
  26. *
  27. */
  28. #include <linux/kernel.h>
  29. #include <linux/module.h>
  30. #include <linux/delay.h>
  31. #include <linux/i2c.h>
  32. #include <linux/clk.h>
  33. #include <linux/errno.h>
  34. #include <linux/sched.h>
  35. #include <linux/err.h>
  36. #include <linux/interrupt.h>
  37. #include <linux/platform_device.h>
  38. #include <linux/io.h>
  39. /*
  40. * Registers offset
  41. */
  42. #define DW_IC_CON 0x0
  43. #define DW_IC_TAR 0x4
  44. #define DW_IC_DATA_CMD 0x10
  45. #define DW_IC_SS_SCL_HCNT 0x14
  46. #define DW_IC_SS_SCL_LCNT 0x18
  47. #define DW_IC_FS_SCL_HCNT 0x1c
  48. #define DW_IC_FS_SCL_LCNT 0x20
  49. #define DW_IC_INTR_STAT 0x2c
  50. #define DW_IC_INTR_MASK 0x30
  51. #define DW_IC_CLR_INTR 0x40
  52. #define DW_IC_ENABLE 0x6c
  53. #define DW_IC_STATUS 0x70
  54. #define DW_IC_TXFLR 0x74
  55. #define DW_IC_RXFLR 0x78
  56. #define DW_IC_COMP_PARAM_1 0xf4
  57. #define DW_IC_TX_ABRT_SOURCE 0x80
  58. #define DW_IC_CON_MASTER 0x1
  59. #define DW_IC_CON_SPEED_STD 0x2
  60. #define DW_IC_CON_SPEED_FAST 0x4
  61. #define DW_IC_CON_10BITADDR_MASTER 0x10
  62. #define DW_IC_CON_RESTART_EN 0x20
  63. #define DW_IC_CON_SLAVE_DISABLE 0x40
  64. #define DW_IC_INTR_TX_EMPTY 0x10
  65. #define DW_IC_INTR_TX_ABRT 0x40
  66. #define DW_IC_INTR_STOP_DET 0x200
  67. #define DW_IC_STATUS_ACTIVITY 0x1
  68. #define DW_IC_ERR_TX_ABRT 0x1
  69. /*
  70. * status codes
  71. */
  72. #define STATUS_IDLE 0x0
  73. #define STATUS_WRITE_IN_PROGRESS 0x1
  74. #define STATUS_READ_IN_PROGRESS 0x2
  75. #define TIMEOUT 20 /* ms */
  76. /*
  77. * hardware abort codes from the DW_IC_TX_ABRT_SOURCE register
  78. *
  79. * only expected abort codes are listed here
  80. * refer to the datasheet for the full list
  81. */
  82. #define ABRT_7B_ADDR_NOACK 0
  83. #define ABRT_10ADDR1_NOACK 1
  84. #define ABRT_10ADDR2_NOACK 2
  85. #define ABRT_TXDATA_NOACK 3
  86. #define ABRT_GCALL_NOACK 4
  87. #define ABRT_GCALL_READ 5
  88. #define ABRT_SBYTE_ACKDET 7
  89. #define ABRT_SBYTE_NORSTRT 9
  90. #define ABRT_10B_RD_NORSTRT 10
  91. #define ARB_MASTER_DIS 11
  92. #define ARB_LOST 12
  93. static char *abort_sources[] = {
  94. [ABRT_7B_ADDR_NOACK] =
  95. "slave address not acknowledged (7bit mode)",
  96. [ABRT_10ADDR1_NOACK] =
  97. "first address byte not acknowledged (10bit mode)",
  98. [ABRT_10ADDR2_NOACK] =
  99. "second address byte not acknowledged (10bit mode)",
  100. [ABRT_TXDATA_NOACK] =
  101. "data not acknowledged",
  102. [ABRT_GCALL_NOACK] =
  103. "no acknowledgement for a general call",
  104. [ABRT_GCALL_READ] =
  105. "read after general call",
  106. [ABRT_SBYTE_ACKDET] =
  107. "start byte acknowledged",
  108. [ABRT_SBYTE_NORSTRT] =
  109. "trying to send start byte when restart is disabled",
  110. [ABRT_10B_RD_NORSTRT] =
  111. "trying to read when restart is disabled (10bit mode)",
  112. [ARB_MASTER_DIS] =
  113. "trying to use disabled adapter",
  114. [ARB_LOST] =
  115. "lost arbitration",
  116. };
  117. /**
  118. * struct dw_i2c_dev - private i2c-designware data
  119. * @dev: driver model device node
  120. * @base: IO registers pointer
  121. * @cmd_complete: tx completion indicator
  122. * @pump_msg: continue in progress transfers
  123. * @lock: protect this struct and IO registers
  124. * @clk: input reference clock
  125. * @cmd_err: run time hadware error code
  126. * @msgs: points to an array of messages currently being transfered
  127. * @msgs_num: the number of elements in msgs
  128. * @msg_write_idx: the element index of the current tx message in the msgs
  129. * array
  130. * @tx_buf_len: the length of the current tx buffer
  131. * @tx_buf: the current tx buffer
  132. * @msg_read_idx: the element index of the current rx message in the msgs
  133. * array
  134. * @rx_buf_len: the length of the current rx buffer
  135. * @rx_buf: the current rx buffer
  136. * @msg_err: error status of the current transfer
  137. * @status: i2c master status, one of STATUS_*
  138. * @abort_source: copy of the TX_ABRT_SOURCE register
  139. * @irq: interrupt number for the i2c master
  140. * @adapter: i2c subsystem adapter node
  141. * @tx_fifo_depth: depth of the hardware tx fifo
  142. * @rx_fifo_depth: depth of the hardware rx fifo
  143. */
  144. struct dw_i2c_dev {
  145. struct device *dev;
  146. void __iomem *base;
  147. struct completion cmd_complete;
  148. struct tasklet_struct pump_msg;
  149. struct mutex lock;
  150. struct clk *clk;
  151. int cmd_err;
  152. struct i2c_msg *msgs;
  153. int msgs_num;
  154. int msg_write_idx;
  155. u16 tx_buf_len;
  156. u8 *tx_buf;
  157. int msg_read_idx;
  158. u16 rx_buf_len;
  159. u8 *rx_buf;
  160. int msg_err;
  161. unsigned int status;
  162. u16 abort_source;
  163. int irq;
  164. struct i2c_adapter adapter;
  165. unsigned int tx_fifo_depth;
  166. unsigned int rx_fifo_depth;
  167. };
  168. /**
  169. * i2c_dw_init() - initialize the designware i2c master hardware
  170. * @dev: device private data
  171. *
  172. * This functions configures and enables the I2C master.
  173. * This function is called during I2C init function, and in case of timeout at
  174. * run time.
  175. */
  176. static void i2c_dw_init(struct dw_i2c_dev *dev)
  177. {
  178. u32 input_clock_khz = clk_get_rate(dev->clk) / 1000;
  179. u16 ic_con;
  180. /* Disable the adapter */
  181. writeb(0, dev->base + DW_IC_ENABLE);
  182. /* set standard and fast speed deviders for high/low periods */
  183. writew((input_clock_khz * 40 / 10000)+1, /* std speed high, 4us */
  184. dev->base + DW_IC_SS_SCL_HCNT);
  185. writew((input_clock_khz * 47 / 10000)+1, /* std speed low, 4.7us */
  186. dev->base + DW_IC_SS_SCL_LCNT);
  187. writew((input_clock_khz * 6 / 10000)+1, /* fast speed high, 0.6us */
  188. dev->base + DW_IC_FS_SCL_HCNT);
  189. writew((input_clock_khz * 13 / 10000)+1, /* fast speed low, 1.3us */
  190. dev->base + DW_IC_FS_SCL_LCNT);
  191. /* configure the i2c master */
  192. ic_con = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE |
  193. DW_IC_CON_RESTART_EN | DW_IC_CON_SPEED_FAST;
  194. writew(ic_con, dev->base + DW_IC_CON);
  195. }
  196. /*
  197. * Waiting for bus not busy
  198. */
  199. static int i2c_dw_wait_bus_not_busy(struct dw_i2c_dev *dev)
  200. {
  201. int timeout = TIMEOUT;
  202. while (readb(dev->base + DW_IC_STATUS) & DW_IC_STATUS_ACTIVITY) {
  203. if (timeout <= 0) {
  204. dev_warn(dev->dev, "timeout waiting for bus ready\n");
  205. return -ETIMEDOUT;
  206. }
  207. timeout--;
  208. mdelay(1);
  209. }
  210. return 0;
  211. }
  212. /*
  213. * Initiate low level master read/write transaction.
  214. * This function is called from i2c_dw_xfer when starting a transfer.
  215. * This function is also called from dw_i2c_pump_msg to continue a transfer
  216. * that is longer than the size of the TX FIFO.
  217. */
  218. static void
  219. i2c_dw_xfer_msg(struct i2c_adapter *adap)
  220. {
  221. struct dw_i2c_dev *dev = i2c_get_adapdata(adap);
  222. struct i2c_msg *msgs = dev->msgs;
  223. int num = dev->msgs_num;
  224. u16 ic_con, intr_mask;
  225. int tx_limit = dev->tx_fifo_depth - readb(dev->base + DW_IC_TXFLR);
  226. int rx_limit = dev->rx_fifo_depth - readb(dev->base + DW_IC_RXFLR);
  227. u16 addr = msgs[dev->msg_write_idx].addr;
  228. u16 buf_len = dev->tx_buf_len;
  229. if (!(dev->status & STATUS_WRITE_IN_PROGRESS)) {
  230. /* Disable the adapter */
  231. writeb(0, dev->base + DW_IC_ENABLE);
  232. /* set the slave (target) address */
  233. writew(msgs[dev->msg_write_idx].addr, dev->base + DW_IC_TAR);
  234. /* if the slave address is ten bit address, enable 10BITADDR */
  235. ic_con = readw(dev->base + DW_IC_CON);
  236. if (msgs[dev->msg_write_idx].flags & I2C_M_TEN)
  237. ic_con |= DW_IC_CON_10BITADDR_MASTER;
  238. else
  239. ic_con &= ~DW_IC_CON_10BITADDR_MASTER;
  240. writew(ic_con, dev->base + DW_IC_CON);
  241. /* Enable the adapter */
  242. writeb(1, dev->base + DW_IC_ENABLE);
  243. }
  244. for (; dev->msg_write_idx < num; dev->msg_write_idx++) {
  245. /* if target address has changed, we need to
  246. * reprogram the target address in the i2c
  247. * adapter when we are done with this transfer
  248. */
  249. if (msgs[dev->msg_write_idx].addr != addr)
  250. return;
  251. if (msgs[dev->msg_write_idx].len == 0) {
  252. dev_err(dev->dev,
  253. "%s: invalid message length\n", __func__);
  254. dev->msg_err = -EINVAL;
  255. return;
  256. }
  257. if (!(dev->status & STATUS_WRITE_IN_PROGRESS)) {
  258. /* new i2c_msg */
  259. dev->tx_buf = msgs[dev->msg_write_idx].buf;
  260. buf_len = msgs[dev->msg_write_idx].len;
  261. }
  262. while (buf_len > 0 && tx_limit > 0 && rx_limit > 0) {
  263. if (msgs[dev->msg_write_idx].flags & I2C_M_RD) {
  264. writew(0x100, dev->base + DW_IC_DATA_CMD);
  265. rx_limit--;
  266. } else
  267. writew(*(dev->tx_buf++),
  268. dev->base + DW_IC_DATA_CMD);
  269. tx_limit--; buf_len--;
  270. }
  271. }
  272. intr_mask = DW_IC_INTR_STOP_DET | DW_IC_INTR_TX_ABRT;
  273. if (buf_len > 0) { /* more bytes to be written */
  274. intr_mask |= DW_IC_INTR_TX_EMPTY;
  275. dev->status |= STATUS_WRITE_IN_PROGRESS;
  276. } else
  277. dev->status &= ~STATUS_WRITE_IN_PROGRESS;
  278. writew(intr_mask, dev->base + DW_IC_INTR_MASK);
  279. dev->tx_buf_len = buf_len;
  280. }
  281. static void
  282. i2c_dw_read(struct i2c_adapter *adap)
  283. {
  284. struct dw_i2c_dev *dev = i2c_get_adapdata(adap);
  285. struct i2c_msg *msgs = dev->msgs;
  286. int num = dev->msgs_num;
  287. u16 addr = msgs[dev->msg_read_idx].addr;
  288. int rx_valid = readw(dev->base + DW_IC_RXFLR);
  289. for (; dev->msg_read_idx < num; dev->msg_read_idx++) {
  290. u16 len;
  291. u8 *buf;
  292. if (!(msgs[dev->msg_read_idx].flags & I2C_M_RD))
  293. continue;
  294. /* different i2c client, reprogram the i2c adapter */
  295. if (msgs[dev->msg_read_idx].addr != addr)
  296. return;
  297. if (!(dev->status & STATUS_READ_IN_PROGRESS)) {
  298. len = msgs[dev->msg_read_idx].len;
  299. buf = msgs[dev->msg_read_idx].buf;
  300. } else {
  301. len = dev->rx_buf_len;
  302. buf = dev->rx_buf;
  303. }
  304. for (; len > 0 && rx_valid > 0; len--, rx_valid--)
  305. *buf++ = readb(dev->base + DW_IC_DATA_CMD);
  306. if (len > 0) {
  307. dev->status |= STATUS_READ_IN_PROGRESS;
  308. dev->rx_buf_len = len;
  309. dev->rx_buf = buf;
  310. return;
  311. } else
  312. dev->status &= ~STATUS_READ_IN_PROGRESS;
  313. }
  314. }
  315. /*
  316. * Prepare controller for a transaction and call i2c_dw_xfer_msg
  317. */
  318. static int
  319. i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
  320. {
  321. struct dw_i2c_dev *dev = i2c_get_adapdata(adap);
  322. int ret;
  323. dev_dbg(dev->dev, "%s: msgs: %d\n", __func__, num);
  324. mutex_lock(&dev->lock);
  325. INIT_COMPLETION(dev->cmd_complete);
  326. dev->msgs = msgs;
  327. dev->msgs_num = num;
  328. dev->cmd_err = 0;
  329. dev->msg_write_idx = 0;
  330. dev->msg_read_idx = 0;
  331. dev->msg_err = 0;
  332. dev->status = STATUS_IDLE;
  333. ret = i2c_dw_wait_bus_not_busy(dev);
  334. if (ret < 0)
  335. goto done;
  336. /* start the transfers */
  337. i2c_dw_xfer_msg(adap);
  338. /* wait for tx to complete */
  339. ret = wait_for_completion_interruptible_timeout(&dev->cmd_complete, HZ);
  340. if (ret == 0) {
  341. dev_err(dev->dev, "controller timed out\n");
  342. i2c_dw_init(dev);
  343. ret = -ETIMEDOUT;
  344. goto done;
  345. } else if (ret < 0)
  346. goto done;
  347. if (dev->msg_err) {
  348. ret = dev->msg_err;
  349. goto done;
  350. }
  351. /* no error */
  352. if (likely(!dev->cmd_err)) {
  353. /* read rx fifo, and disable the adapter */
  354. do {
  355. i2c_dw_read(adap);
  356. } while (dev->status & STATUS_READ_IN_PROGRESS);
  357. writeb(0, dev->base + DW_IC_ENABLE);
  358. ret = num;
  359. goto done;
  360. }
  361. /* We have an error */
  362. if (dev->cmd_err == DW_IC_ERR_TX_ABRT) {
  363. unsigned long abort_source = dev->abort_source;
  364. int i;
  365. for_each_bit(i, &abort_source, ARRAY_SIZE(abort_sources)) {
  366. dev_err(dev->dev, "%s: %s\n", __func__, abort_sources[i]);
  367. }
  368. }
  369. ret = -EIO;
  370. done:
  371. mutex_unlock(&dev->lock);
  372. return ret;
  373. }
  374. static u32 i2c_dw_func(struct i2c_adapter *adap)
  375. {
  376. return I2C_FUNC_I2C | I2C_FUNC_10BIT_ADDR;
  377. }
  378. static void dw_i2c_pump_msg(unsigned long data)
  379. {
  380. struct dw_i2c_dev *dev = (struct dw_i2c_dev *) data;
  381. u16 intr_mask;
  382. i2c_dw_read(&dev->adapter);
  383. i2c_dw_xfer_msg(&dev->adapter);
  384. intr_mask = DW_IC_INTR_STOP_DET | DW_IC_INTR_TX_ABRT;
  385. if (dev->status & STATUS_WRITE_IN_PROGRESS)
  386. intr_mask |= DW_IC_INTR_TX_EMPTY;
  387. writew(intr_mask, dev->base + DW_IC_INTR_MASK);
  388. }
  389. /*
  390. * Interrupt service routine. This gets called whenever an I2C interrupt
  391. * occurs.
  392. */
  393. static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id)
  394. {
  395. struct dw_i2c_dev *dev = dev_id;
  396. u16 stat;
  397. stat = readw(dev->base + DW_IC_INTR_STAT);
  398. dev_dbg(dev->dev, "%s: stat=0x%x\n", __func__, stat);
  399. if (stat & DW_IC_INTR_TX_ABRT) {
  400. dev->abort_source = readw(dev->base + DW_IC_TX_ABRT_SOURCE);
  401. dev->cmd_err |= DW_IC_ERR_TX_ABRT;
  402. dev->status = STATUS_IDLE;
  403. } else if (stat & DW_IC_INTR_TX_EMPTY)
  404. tasklet_schedule(&dev->pump_msg);
  405. readb(dev->base + DW_IC_CLR_INTR); /* clear interrupts */
  406. writew(0, dev->base + DW_IC_INTR_MASK); /* disable interrupts */
  407. if (stat & (DW_IC_INTR_TX_ABRT | DW_IC_INTR_STOP_DET))
  408. complete(&dev->cmd_complete);
  409. return IRQ_HANDLED;
  410. }
  411. static struct i2c_algorithm i2c_dw_algo = {
  412. .master_xfer = i2c_dw_xfer,
  413. .functionality = i2c_dw_func,
  414. };
  415. static int __devinit dw_i2c_probe(struct platform_device *pdev)
  416. {
  417. struct dw_i2c_dev *dev;
  418. struct i2c_adapter *adap;
  419. struct resource *mem, *irq, *ioarea;
  420. int r;
  421. /* NOTE: driver uses the static register mapping */
  422. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  423. if (!mem) {
  424. dev_err(&pdev->dev, "no mem resource?\n");
  425. return -EINVAL;
  426. }
  427. irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  428. if (!irq) {
  429. dev_err(&pdev->dev, "no irq resource?\n");
  430. return -EINVAL;
  431. }
  432. ioarea = request_mem_region(mem->start, resource_size(mem),
  433. pdev->name);
  434. if (!ioarea) {
  435. dev_err(&pdev->dev, "I2C region already claimed\n");
  436. return -EBUSY;
  437. }
  438. dev = kzalloc(sizeof(struct dw_i2c_dev), GFP_KERNEL);
  439. if (!dev) {
  440. r = -ENOMEM;
  441. goto err_release_region;
  442. }
  443. init_completion(&dev->cmd_complete);
  444. tasklet_init(&dev->pump_msg, dw_i2c_pump_msg, (unsigned long) dev);
  445. mutex_init(&dev->lock);
  446. dev->dev = get_device(&pdev->dev);
  447. dev->irq = irq->start;
  448. platform_set_drvdata(pdev, dev);
  449. dev->clk = clk_get(&pdev->dev, NULL);
  450. if (IS_ERR(dev->clk)) {
  451. r = -ENODEV;
  452. goto err_free_mem;
  453. }
  454. clk_enable(dev->clk);
  455. dev->base = ioremap(mem->start, resource_size(mem));
  456. if (dev->base == NULL) {
  457. dev_err(&pdev->dev, "failure mapping io resources\n");
  458. r = -EBUSY;
  459. goto err_unuse_clocks;
  460. }
  461. {
  462. u32 param1 = readl(dev->base + DW_IC_COMP_PARAM_1);
  463. dev->tx_fifo_depth = ((param1 >> 16) & 0xff) + 1;
  464. dev->rx_fifo_depth = ((param1 >> 8) & 0xff) + 1;
  465. }
  466. i2c_dw_init(dev);
  467. writew(0, dev->base + DW_IC_INTR_MASK); /* disable IRQ */
  468. r = request_irq(dev->irq, i2c_dw_isr, 0, pdev->name, dev);
  469. if (r) {
  470. dev_err(&pdev->dev, "failure requesting irq %i\n", dev->irq);
  471. goto err_iounmap;
  472. }
  473. adap = &dev->adapter;
  474. i2c_set_adapdata(adap, dev);
  475. adap->owner = THIS_MODULE;
  476. adap->class = I2C_CLASS_HWMON;
  477. strlcpy(adap->name, "Synopsys DesignWare I2C adapter",
  478. sizeof(adap->name));
  479. adap->algo = &i2c_dw_algo;
  480. adap->dev.parent = &pdev->dev;
  481. adap->nr = pdev->id;
  482. r = i2c_add_numbered_adapter(adap);
  483. if (r) {
  484. dev_err(&pdev->dev, "failure adding adapter\n");
  485. goto err_free_irq;
  486. }
  487. return 0;
  488. err_free_irq:
  489. free_irq(dev->irq, dev);
  490. err_iounmap:
  491. iounmap(dev->base);
  492. err_unuse_clocks:
  493. clk_disable(dev->clk);
  494. clk_put(dev->clk);
  495. dev->clk = NULL;
  496. err_free_mem:
  497. platform_set_drvdata(pdev, NULL);
  498. put_device(&pdev->dev);
  499. kfree(dev);
  500. err_release_region:
  501. release_mem_region(mem->start, resource_size(mem));
  502. return r;
  503. }
  504. static int __devexit dw_i2c_remove(struct platform_device *pdev)
  505. {
  506. struct dw_i2c_dev *dev = platform_get_drvdata(pdev);
  507. struct resource *mem;
  508. platform_set_drvdata(pdev, NULL);
  509. i2c_del_adapter(&dev->adapter);
  510. put_device(&pdev->dev);
  511. clk_disable(dev->clk);
  512. clk_put(dev->clk);
  513. dev->clk = NULL;
  514. writeb(0, dev->base + DW_IC_ENABLE);
  515. free_irq(dev->irq, dev);
  516. kfree(dev);
  517. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  518. release_mem_region(mem->start, resource_size(mem));
  519. return 0;
  520. }
  521. /* work with hotplug and coldplug */
  522. MODULE_ALIAS("platform:i2c_designware");
  523. static struct platform_driver dw_i2c_driver = {
  524. .remove = __devexit_p(dw_i2c_remove),
  525. .driver = {
  526. .name = "i2c_designware",
  527. .owner = THIS_MODULE,
  528. },
  529. };
  530. static int __init dw_i2c_init_driver(void)
  531. {
  532. return platform_driver_probe(&dw_i2c_driver, dw_i2c_probe);
  533. }
  534. module_init(dw_i2c_init_driver);
  535. static void __exit dw_i2c_exit_driver(void)
  536. {
  537. platform_driver_unregister(&dw_i2c_driver);
  538. }
  539. module_exit(dw_i2c_exit_driver);
  540. MODULE_AUTHOR("Baruch Siach <baruch@tkos.co.il>");
  541. MODULE_DESCRIPTION("Synopsys DesignWare I2C bus adapter");
  542. MODULE_LICENSE("GPL");