i2c-sh_mobile.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. /*
  2. * SuperH Mobile I2C Controller
  3. *
  4. * Copyright (C) 2008 Magnus Damm
  5. *
  6. * Portions of the code based on out-of-tree driver i2c-sh7343.c
  7. * Copyright (c) 2006 Carlos Munoz <carlos@kenati.com>
  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 as published by
  11. * the Free Software Foundation; either version 2 of the License
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <linux/kernel.h>
  23. #include <linux/module.h>
  24. #include <linux/init.h>
  25. #include <linux/delay.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/i2c.h>
  29. #include <linux/err.h>
  30. #include <linux/pm_runtime.h>
  31. #include <linux/clk.h>
  32. #include <linux/io.h>
  33. /* Transmit operation: */
  34. /* */
  35. /* 0 byte transmit */
  36. /* BUS: S A8 ACK P */
  37. /* IRQ: DTE WAIT */
  38. /* ICIC: */
  39. /* ICCR: 0x94 0x90 */
  40. /* ICDR: A8 */
  41. /* */
  42. /* 1 byte transmit */
  43. /* BUS: S A8 ACK D8(1) ACK P */
  44. /* IRQ: DTE WAIT WAIT */
  45. /* ICIC: -DTE */
  46. /* ICCR: 0x94 0x90 */
  47. /* ICDR: A8 D8(1) */
  48. /* */
  49. /* 2 byte transmit */
  50. /* BUS: S A8 ACK D8(1) ACK D8(2) ACK P */
  51. /* IRQ: DTE WAIT WAIT WAIT */
  52. /* ICIC: -DTE */
  53. /* ICCR: 0x94 0x90 */
  54. /* ICDR: A8 D8(1) D8(2) */
  55. /* */
  56. /* 3 bytes or more, +---------+ gets repeated */
  57. /* */
  58. /* */
  59. /* Receive operation: */
  60. /* */
  61. /* 0 byte receive - not supported since slave may hold SDA low */
  62. /* */
  63. /* 1 byte receive [TX] | [RX] */
  64. /* BUS: S A8 ACK | D8(1) ACK P */
  65. /* IRQ: DTE WAIT | WAIT DTE */
  66. /* ICIC: -DTE | +DTE */
  67. /* ICCR: 0x94 0x81 | 0xc0 */
  68. /* ICDR: A8 | D8(1) */
  69. /* */
  70. /* 2 byte receive [TX]| [RX] */
  71. /* BUS: S A8 ACK | D8(1) ACK D8(2) ACK P */
  72. /* IRQ: DTE WAIT | WAIT WAIT DTE */
  73. /* ICIC: -DTE | +DTE */
  74. /* ICCR: 0x94 0x81 | 0xc0 */
  75. /* ICDR: A8 | D8(1) D8(2) */
  76. /* */
  77. /* 3 byte receive [TX] | [RX] */
  78. /* BUS: S A8 ACK | D8(1) ACK D8(2) ACK D8(3) ACK P */
  79. /* IRQ: DTE WAIT | WAIT WAIT WAIT DTE */
  80. /* ICIC: -DTE | +DTE */
  81. /* ICCR: 0x94 0x81 | 0xc0 */
  82. /* ICDR: A8 | D8(1) D8(2) D8(3) */
  83. /* */
  84. /* 4 bytes or more, this part is repeated +---------+ */
  85. /* */
  86. /* */
  87. /* Interrupt order and BUSY flag */
  88. /* ___ _ */
  89. /* SDA ___\___XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXAAAAAAAAA___/ */
  90. /* SCL \_/1\_/2\_/3\_/4\_/5\_/6\_/7\_/8\___/9\_____/ */
  91. /* */
  92. /* S D7 D6 D5 D4 D3 D2 D1 D0 P */
  93. /* ___ */
  94. /* WAIT IRQ ________________________________/ \___________ */
  95. /* TACK IRQ ____________________________________/ \_______ */
  96. /* DTE IRQ __________________________________________/ \_ */
  97. /* AL IRQ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
  98. /* _______________________________________________ */
  99. /* BUSY __/ \_ */
  100. /* */
  101. enum sh_mobile_i2c_op {
  102. OP_START = 0,
  103. OP_TX_FIRST,
  104. OP_TX,
  105. OP_TX_STOP,
  106. OP_TX_TO_RX,
  107. OP_RX,
  108. OP_RX_STOP,
  109. OP_RX_STOP_DATA,
  110. };
  111. struct sh_mobile_i2c_data {
  112. struct device *dev;
  113. void __iomem *reg;
  114. struct i2c_adapter adap;
  115. struct clk *clk;
  116. u_int8_t iccl;
  117. u_int8_t icch;
  118. spinlock_t lock;
  119. wait_queue_head_t wait;
  120. struct i2c_msg *msg;
  121. int pos;
  122. int sr;
  123. };
  124. #define NORMAL_SPEED 100000 /* FAST_SPEED 400000 */
  125. /* Register offsets */
  126. #define ICDR(pd) (pd->reg + 0x00)
  127. #define ICCR(pd) (pd->reg + 0x04)
  128. #define ICSR(pd) (pd->reg + 0x08)
  129. #define ICIC(pd) (pd->reg + 0x0c)
  130. #define ICCL(pd) (pd->reg + 0x10)
  131. #define ICCH(pd) (pd->reg + 0x14)
  132. /* Register bits */
  133. #define ICCR_ICE 0x80
  134. #define ICCR_RACK 0x40
  135. #define ICCR_TRS 0x10
  136. #define ICCR_BBSY 0x04
  137. #define ICCR_SCP 0x01
  138. #define ICSR_SCLM 0x80
  139. #define ICSR_SDAM 0x40
  140. #define SW_DONE 0x20
  141. #define ICSR_BUSY 0x10
  142. #define ICSR_AL 0x08
  143. #define ICSR_TACK 0x04
  144. #define ICSR_WAIT 0x02
  145. #define ICSR_DTE 0x01
  146. #define ICIC_ALE 0x08
  147. #define ICIC_TACKE 0x04
  148. #define ICIC_WAITE 0x02
  149. #define ICIC_DTEE 0x01
  150. static void activate_ch(struct sh_mobile_i2c_data *pd)
  151. {
  152. unsigned long i2c_clk;
  153. u_int32_t num;
  154. u_int32_t denom;
  155. u_int32_t tmp;
  156. /* Wake up device and enable clock */
  157. pm_runtime_get_sync(pd->dev);
  158. clk_enable(pd->clk);
  159. /* Get clock rate after clock is enabled */
  160. i2c_clk = clk_get_rate(pd->clk);
  161. /* Calculate the value for iccl. From the data sheet:
  162. * iccl = (p clock / transfer rate) * (L / (L + H))
  163. * where L and H are the SCL low/high ratio (5/4 in this case).
  164. * We also round off the result.
  165. */
  166. num = i2c_clk * 5;
  167. denom = NORMAL_SPEED * 9;
  168. tmp = num * 10 / denom;
  169. if (tmp % 10 >= 5)
  170. pd->iccl = (u_int8_t)((num/denom) + 1);
  171. else
  172. pd->iccl = (u_int8_t)(num/denom);
  173. /* Calculate the value for icch. From the data sheet:
  174. icch = (p clock / transfer rate) * (H / (L + H)) */
  175. num = i2c_clk * 4;
  176. tmp = num * 10 / denom;
  177. if (tmp % 10 >= 5)
  178. pd->icch = (u_int8_t)((num/denom) + 1);
  179. else
  180. pd->icch = (u_int8_t)(num/denom);
  181. /* Enable channel and configure rx ack */
  182. iowrite8(ioread8(ICCR(pd)) | ICCR_ICE, ICCR(pd));
  183. /* Mask all interrupts */
  184. iowrite8(0, ICIC(pd));
  185. /* Set the clock */
  186. iowrite8(pd->iccl, ICCL(pd));
  187. iowrite8(pd->icch, ICCH(pd));
  188. }
  189. static void deactivate_ch(struct sh_mobile_i2c_data *pd)
  190. {
  191. /* Clear/disable interrupts */
  192. iowrite8(0, ICSR(pd));
  193. iowrite8(0, ICIC(pd));
  194. /* Disable channel */
  195. iowrite8(ioread8(ICCR(pd)) & ~ICCR_ICE, ICCR(pd));
  196. /* Disable clock and mark device as idle */
  197. clk_disable(pd->clk);
  198. pm_runtime_put_sync(pd->dev);
  199. }
  200. static unsigned char i2c_op(struct sh_mobile_i2c_data *pd,
  201. enum sh_mobile_i2c_op op, unsigned char data)
  202. {
  203. unsigned char ret = 0;
  204. unsigned long flags;
  205. dev_dbg(pd->dev, "op %d, data in 0x%02x\n", op, data);
  206. spin_lock_irqsave(&pd->lock, flags);
  207. switch (op) {
  208. case OP_START: /* issue start and trigger DTE interrupt */
  209. iowrite8(0x94, ICCR(pd));
  210. break;
  211. case OP_TX_FIRST: /* disable DTE interrupt and write data */
  212. iowrite8(ICIC_WAITE | ICIC_ALE | ICIC_TACKE, ICIC(pd));
  213. iowrite8(data, ICDR(pd));
  214. break;
  215. case OP_TX: /* write data */
  216. iowrite8(data, ICDR(pd));
  217. break;
  218. case OP_TX_STOP: /* write data and issue a stop afterwards */
  219. iowrite8(data, ICDR(pd));
  220. iowrite8(0x90, ICCR(pd));
  221. break;
  222. case OP_TX_TO_RX: /* select read mode */
  223. iowrite8(0x81, ICCR(pd));
  224. break;
  225. case OP_RX: /* just read data */
  226. ret = ioread8(ICDR(pd));
  227. break;
  228. case OP_RX_STOP: /* enable DTE interrupt, issue stop */
  229. iowrite8(ICIC_DTEE | ICIC_WAITE | ICIC_ALE | ICIC_TACKE,
  230. ICIC(pd));
  231. iowrite8(0xc0, ICCR(pd));
  232. break;
  233. case OP_RX_STOP_DATA: /* enable DTE interrupt, read data, issue stop */
  234. iowrite8(ICIC_DTEE | ICIC_WAITE | ICIC_ALE | ICIC_TACKE,
  235. ICIC(pd));
  236. ret = ioread8(ICDR(pd));
  237. iowrite8(0xc0, ICCR(pd));
  238. break;
  239. }
  240. spin_unlock_irqrestore(&pd->lock, flags);
  241. dev_dbg(pd->dev, "op %d, data out 0x%02x\n", op, ret);
  242. return ret;
  243. }
  244. static int sh_mobile_i2c_is_first_byte(struct sh_mobile_i2c_data *pd)
  245. {
  246. if (pd->pos == -1)
  247. return 1;
  248. return 0;
  249. }
  250. static int sh_mobile_i2c_is_last_byte(struct sh_mobile_i2c_data *pd)
  251. {
  252. if (pd->pos == (pd->msg->len - 1))
  253. return 1;
  254. return 0;
  255. }
  256. static void sh_mobile_i2c_get_data(struct sh_mobile_i2c_data *pd,
  257. unsigned char *buf)
  258. {
  259. switch (pd->pos) {
  260. case -1:
  261. *buf = (pd->msg->addr & 0x7f) << 1;
  262. *buf |= (pd->msg->flags & I2C_M_RD) ? 1 : 0;
  263. break;
  264. default:
  265. *buf = pd->msg->buf[pd->pos];
  266. }
  267. }
  268. static int sh_mobile_i2c_isr_tx(struct sh_mobile_i2c_data *pd)
  269. {
  270. unsigned char data;
  271. if (pd->pos == pd->msg->len)
  272. return 1;
  273. sh_mobile_i2c_get_data(pd, &data);
  274. if (sh_mobile_i2c_is_last_byte(pd))
  275. i2c_op(pd, OP_TX_STOP, data);
  276. else if (sh_mobile_i2c_is_first_byte(pd))
  277. i2c_op(pd, OP_TX_FIRST, data);
  278. else
  279. i2c_op(pd, OP_TX, data);
  280. pd->pos++;
  281. return 0;
  282. }
  283. static int sh_mobile_i2c_isr_rx(struct sh_mobile_i2c_data *pd)
  284. {
  285. unsigned char data;
  286. int real_pos;
  287. do {
  288. if (pd->pos <= -1) {
  289. sh_mobile_i2c_get_data(pd, &data);
  290. if (sh_mobile_i2c_is_first_byte(pd))
  291. i2c_op(pd, OP_TX_FIRST, data);
  292. else
  293. i2c_op(pd, OP_TX, data);
  294. break;
  295. }
  296. if (pd->pos == 0) {
  297. i2c_op(pd, OP_TX_TO_RX, 0);
  298. break;
  299. }
  300. real_pos = pd->pos - 2;
  301. if (pd->pos == pd->msg->len) {
  302. if (real_pos < 0) {
  303. i2c_op(pd, OP_RX_STOP, 0);
  304. break;
  305. }
  306. data = i2c_op(pd, OP_RX_STOP_DATA, 0);
  307. } else
  308. data = i2c_op(pd, OP_RX, 0);
  309. if (real_pos >= 0)
  310. pd->msg->buf[real_pos] = data;
  311. } while (0);
  312. pd->pos++;
  313. return pd->pos == (pd->msg->len + 2);
  314. }
  315. static irqreturn_t sh_mobile_i2c_isr(int irq, void *dev_id)
  316. {
  317. struct platform_device *dev = dev_id;
  318. struct sh_mobile_i2c_data *pd = platform_get_drvdata(dev);
  319. unsigned char sr;
  320. int wakeup;
  321. sr = ioread8(ICSR(pd));
  322. pd->sr |= sr; /* remember state */
  323. dev_dbg(pd->dev, "i2c_isr 0x%02x 0x%02x %s %d %d!\n", sr, pd->sr,
  324. (pd->msg->flags & I2C_M_RD) ? "read" : "write",
  325. pd->pos, pd->msg->len);
  326. if (sr & (ICSR_AL | ICSR_TACK)) {
  327. /* don't interrupt transaction - continue to issue stop */
  328. iowrite8(sr & ~(ICSR_AL | ICSR_TACK), ICSR(pd));
  329. wakeup = 0;
  330. } else if (pd->msg->flags & I2C_M_RD)
  331. wakeup = sh_mobile_i2c_isr_rx(pd);
  332. else
  333. wakeup = sh_mobile_i2c_isr_tx(pd);
  334. if (sr & ICSR_WAIT) /* TODO: add delay here to support slow acks */
  335. iowrite8(sr & ~ICSR_WAIT, ICSR(pd));
  336. if (wakeup) {
  337. pd->sr |= SW_DONE;
  338. wake_up(&pd->wait);
  339. }
  340. return IRQ_HANDLED;
  341. }
  342. static int start_ch(struct sh_mobile_i2c_data *pd, struct i2c_msg *usr_msg)
  343. {
  344. if (usr_msg->len == 0 && (usr_msg->flags & I2C_M_RD)) {
  345. dev_err(pd->dev, "Unsupported zero length i2c read\n");
  346. return -EIO;
  347. }
  348. /* Initialize channel registers */
  349. iowrite8(ioread8(ICCR(pd)) & ~ICCR_ICE, ICCR(pd));
  350. /* Enable channel and configure rx ack */
  351. iowrite8(ioread8(ICCR(pd)) | ICCR_ICE, ICCR(pd));
  352. /* Set the clock */
  353. iowrite8(pd->iccl, ICCL(pd));
  354. iowrite8(pd->icch, ICCH(pd));
  355. pd->msg = usr_msg;
  356. pd->pos = -1;
  357. pd->sr = 0;
  358. /* Enable all interrupts to begin with */
  359. iowrite8(ICIC_WAITE | ICIC_ALE | ICIC_TACKE | ICIC_DTEE, ICIC(pd));
  360. return 0;
  361. }
  362. static int sh_mobile_i2c_xfer(struct i2c_adapter *adapter,
  363. struct i2c_msg *msgs,
  364. int num)
  365. {
  366. struct sh_mobile_i2c_data *pd = i2c_get_adapdata(adapter);
  367. struct i2c_msg *msg;
  368. int err = 0;
  369. u_int8_t val;
  370. int i, k, retry_count;
  371. activate_ch(pd);
  372. /* Process all messages */
  373. for (i = 0; i < num; i++) {
  374. msg = &msgs[i];
  375. err = start_ch(pd, msg);
  376. if (err)
  377. break;
  378. i2c_op(pd, OP_START, 0);
  379. /* The interrupt handler takes care of the rest... */
  380. k = wait_event_timeout(pd->wait,
  381. pd->sr & (ICSR_TACK | SW_DONE),
  382. 5 * HZ);
  383. if (!k)
  384. dev_err(pd->dev, "Transfer request timed out\n");
  385. retry_count = 1000;
  386. again:
  387. val = ioread8(ICSR(pd));
  388. dev_dbg(pd->dev, "val 0x%02x pd->sr 0x%02x\n", val, pd->sr);
  389. /* the interrupt handler may wake us up before the
  390. * transfer is finished, so poll the hardware
  391. * until we're done.
  392. */
  393. if (val & ICSR_BUSY) {
  394. udelay(10);
  395. if (retry_count--)
  396. goto again;
  397. err = -EIO;
  398. dev_err(pd->dev, "Polling timed out\n");
  399. break;
  400. }
  401. /* handle missing acknowledge and arbitration lost */
  402. if ((val | pd->sr) & (ICSR_TACK | ICSR_AL)) {
  403. err = -EIO;
  404. break;
  405. }
  406. }
  407. deactivate_ch(pd);
  408. if (!err)
  409. err = num;
  410. return err;
  411. }
  412. static u32 sh_mobile_i2c_func(struct i2c_adapter *adapter)
  413. {
  414. return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
  415. }
  416. static struct i2c_algorithm sh_mobile_i2c_algorithm = {
  417. .functionality = sh_mobile_i2c_func,
  418. .master_xfer = sh_mobile_i2c_xfer,
  419. };
  420. static int sh_mobile_i2c_hook_irqs(struct platform_device *dev, int hook)
  421. {
  422. struct resource *res;
  423. int ret = -ENXIO;
  424. int q, m;
  425. int k = 0;
  426. int n = 0;
  427. while ((res = platform_get_resource(dev, IORESOURCE_IRQ, k))) {
  428. for (n = res->start; hook && n <= res->end; n++) {
  429. if (request_irq(n, sh_mobile_i2c_isr, IRQF_DISABLED,
  430. dev_name(&dev->dev), dev))
  431. goto rollback;
  432. }
  433. k++;
  434. }
  435. if (hook)
  436. return k > 0 ? 0 : -ENOENT;
  437. k--;
  438. ret = 0;
  439. rollback:
  440. for (q = k; k >= 0; k--) {
  441. for (m = n; m >= res->start; m--)
  442. free_irq(m, dev);
  443. res = platform_get_resource(dev, IORESOURCE_IRQ, k - 1);
  444. m = res->end;
  445. }
  446. return ret;
  447. }
  448. static int sh_mobile_i2c_probe(struct platform_device *dev)
  449. {
  450. struct sh_mobile_i2c_data *pd;
  451. struct i2c_adapter *adap;
  452. struct resource *res;
  453. char clk_name[8];
  454. int size;
  455. int ret;
  456. pd = kzalloc(sizeof(struct sh_mobile_i2c_data), GFP_KERNEL);
  457. if (pd == NULL) {
  458. dev_err(&dev->dev, "cannot allocate private data\n");
  459. return -ENOMEM;
  460. }
  461. snprintf(clk_name, sizeof(clk_name), "i2c%d", dev->id);
  462. pd->clk = clk_get(&dev->dev, clk_name);
  463. if (IS_ERR(pd->clk)) {
  464. dev_err(&dev->dev, "cannot get clock \"%s\"\n", clk_name);
  465. ret = PTR_ERR(pd->clk);
  466. goto err;
  467. }
  468. ret = sh_mobile_i2c_hook_irqs(dev, 1);
  469. if (ret) {
  470. dev_err(&dev->dev, "cannot request IRQ\n");
  471. goto err_clk;
  472. }
  473. pd->dev = &dev->dev;
  474. platform_set_drvdata(dev, pd);
  475. res = platform_get_resource(dev, IORESOURCE_MEM, 0);
  476. if (res == NULL) {
  477. dev_err(&dev->dev, "cannot find IO resource\n");
  478. ret = -ENOENT;
  479. goto err_irq;
  480. }
  481. size = resource_size(res);
  482. pd->reg = ioremap(res->start, size);
  483. if (pd->reg == NULL) {
  484. dev_err(&dev->dev, "cannot map IO\n");
  485. ret = -ENXIO;
  486. goto err_irq;
  487. }
  488. /* Enable Runtime PM for this device.
  489. *
  490. * Also tell the Runtime PM core to ignore children
  491. * for this device since it is valid for us to suspend
  492. * this I2C master driver even though the slave devices
  493. * on the I2C bus may not be suspended.
  494. *
  495. * The state of the I2C hardware bus is unaffected by
  496. * the Runtime PM state.
  497. */
  498. pm_suspend_ignore_children(&dev->dev, true);
  499. pm_runtime_enable(&dev->dev);
  500. /* setup the private data */
  501. adap = &pd->adap;
  502. i2c_set_adapdata(adap, pd);
  503. adap->owner = THIS_MODULE;
  504. adap->algo = &sh_mobile_i2c_algorithm;
  505. adap->dev.parent = &dev->dev;
  506. adap->retries = 5;
  507. adap->nr = dev->id;
  508. strlcpy(adap->name, dev->name, sizeof(adap->name));
  509. spin_lock_init(&pd->lock);
  510. init_waitqueue_head(&pd->wait);
  511. ret = i2c_add_numbered_adapter(adap);
  512. if (ret < 0) {
  513. dev_err(&dev->dev, "cannot add numbered adapter\n");
  514. goto err_all;
  515. }
  516. return 0;
  517. err_all:
  518. iounmap(pd->reg);
  519. err_irq:
  520. sh_mobile_i2c_hook_irqs(dev, 0);
  521. err_clk:
  522. clk_put(pd->clk);
  523. err:
  524. kfree(pd);
  525. return ret;
  526. }
  527. static int sh_mobile_i2c_remove(struct platform_device *dev)
  528. {
  529. struct sh_mobile_i2c_data *pd = platform_get_drvdata(dev);
  530. i2c_del_adapter(&pd->adap);
  531. iounmap(pd->reg);
  532. sh_mobile_i2c_hook_irqs(dev, 0);
  533. clk_put(pd->clk);
  534. pm_runtime_disable(&dev->dev);
  535. kfree(pd);
  536. return 0;
  537. }
  538. static int sh_mobile_i2c_runtime_nop(struct device *dev)
  539. {
  540. /* Runtime PM callback shared between ->runtime_suspend()
  541. * and ->runtime_resume(). Simply returns success.
  542. *
  543. * This driver re-initializes all registers after
  544. * pm_runtime_get_sync() anyway so there is no need
  545. * to save and restore registers here.
  546. */
  547. return 0;
  548. }
  549. static const struct dev_pm_ops sh_mobile_i2c_dev_pm_ops = {
  550. .runtime_suspend = sh_mobile_i2c_runtime_nop,
  551. .runtime_resume = sh_mobile_i2c_runtime_nop,
  552. };
  553. static struct platform_driver sh_mobile_i2c_driver = {
  554. .driver = {
  555. .name = "i2c-sh_mobile",
  556. .owner = THIS_MODULE,
  557. .pm = &sh_mobile_i2c_dev_pm_ops,
  558. },
  559. .probe = sh_mobile_i2c_probe,
  560. .remove = sh_mobile_i2c_remove,
  561. };
  562. static int __init sh_mobile_i2c_adap_init(void)
  563. {
  564. return platform_driver_register(&sh_mobile_i2c_driver);
  565. }
  566. static void __exit sh_mobile_i2c_adap_exit(void)
  567. {
  568. platform_driver_unregister(&sh_mobile_i2c_driver);
  569. }
  570. subsys_initcall(sh_mobile_i2c_adap_init);
  571. module_exit(sh_mobile_i2c_adap_exit);
  572. MODULE_DESCRIPTION("SuperH Mobile I2C Bus Controller driver");
  573. MODULE_AUTHOR("Magnus Damm");
  574. MODULE_LICENSE("GPL v2");