i2c-s3c2410.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /* linux/drivers/i2c/busses/i2c-s3c2410.c
  3. *
  4. * Copyright (C) 2004,2005,2009 Simtec Electronics
  5. * Ben Dooks <[email protected]>
  6. *
  7. * S3C2410 I2C Controller
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/module.h>
  11. #include <linux/i2c.h>
  12. #include <linux/init.h>
  13. #include <linux/time.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/delay.h>
  16. #include <linux/errno.h>
  17. #include <linux/err.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/pm_runtime.h>
  20. #include <linux/clk.h>
  21. #include <linux/cpufreq.h>
  22. #include <linux/slab.h>
  23. #include <linux/io.h>
  24. #include <linux/of.h>
  25. #include <linux/of_device.h>
  26. #include <linux/gpio/consumer.h>
  27. #include <linux/pinctrl/consumer.h>
  28. #include <linux/mfd/syscon.h>
  29. #include <linux/regmap.h>
  30. #include <asm/irq.h>
  31. #include <linux/platform_data/i2c-s3c2410.h>
  32. /* see s3c2410x user guide, v1.1, section 9 (p447) for more info */
  33. #define S3C2410_IICCON 0x00
  34. #define S3C2410_IICSTAT 0x04
  35. #define S3C2410_IICADD 0x08
  36. #define S3C2410_IICDS 0x0C
  37. #define S3C2440_IICLC 0x10
  38. #define S3C2410_IICCON_ACKEN (1 << 7)
  39. #define S3C2410_IICCON_TXDIV_16 (0 << 6)
  40. #define S3C2410_IICCON_TXDIV_512 (1 << 6)
  41. #define S3C2410_IICCON_IRQEN (1 << 5)
  42. #define S3C2410_IICCON_IRQPEND (1 << 4)
  43. #define S3C2410_IICCON_SCALE(x) ((x) & 0xf)
  44. #define S3C2410_IICCON_SCALEMASK (0xf)
  45. #define S3C2410_IICSTAT_MASTER_RX (2 << 6)
  46. #define S3C2410_IICSTAT_MASTER_TX (3 << 6)
  47. #define S3C2410_IICSTAT_SLAVE_RX (0 << 6)
  48. #define S3C2410_IICSTAT_SLAVE_TX (1 << 6)
  49. #define S3C2410_IICSTAT_MODEMASK (3 << 6)
  50. #define S3C2410_IICSTAT_START (1 << 5)
  51. #define S3C2410_IICSTAT_BUSBUSY (1 << 5)
  52. #define S3C2410_IICSTAT_TXRXEN (1 << 4)
  53. #define S3C2410_IICSTAT_ARBITR (1 << 3)
  54. #define S3C2410_IICSTAT_ASSLAVE (1 << 2)
  55. #define S3C2410_IICSTAT_ADDR0 (1 << 1)
  56. #define S3C2410_IICSTAT_LASTBIT (1 << 0)
  57. #define S3C2410_IICLC_SDA_DELAY0 (0 << 0)
  58. #define S3C2410_IICLC_SDA_DELAY5 (1 << 0)
  59. #define S3C2410_IICLC_SDA_DELAY10 (2 << 0)
  60. #define S3C2410_IICLC_SDA_DELAY15 (3 << 0)
  61. #define S3C2410_IICLC_SDA_DELAY_MASK (3 << 0)
  62. #define S3C2410_IICLC_FILTER_ON (1 << 2)
  63. /* Treat S3C2410 as baseline hardware, anything else is supported via quirks */
  64. #define QUIRK_S3C2440 (1 << 0)
  65. #define QUIRK_HDMIPHY (1 << 1)
  66. #define QUIRK_NO_GPIO (1 << 2)
  67. #define QUIRK_POLL (1 << 3)
  68. /* Max time to wait for bus to become idle after a xfer (in us) */
  69. #define S3C2410_IDLE_TIMEOUT 5000
  70. /* Exynos5 Sysreg offset */
  71. #define EXYNOS5_SYS_I2C_CFG 0x0234
  72. /* i2c controller state */
  73. enum s3c24xx_i2c_state {
  74. STATE_IDLE,
  75. STATE_START,
  76. STATE_READ,
  77. STATE_WRITE,
  78. STATE_STOP
  79. };
  80. struct s3c24xx_i2c {
  81. wait_queue_head_t wait;
  82. kernel_ulong_t quirks;
  83. struct i2c_msg *msg;
  84. unsigned int msg_num;
  85. unsigned int msg_idx;
  86. unsigned int msg_ptr;
  87. unsigned int tx_setup;
  88. unsigned int irq;
  89. enum s3c24xx_i2c_state state;
  90. unsigned long clkrate;
  91. void __iomem *regs;
  92. struct clk *clk;
  93. struct device *dev;
  94. struct i2c_adapter adap;
  95. struct s3c2410_platform_i2c *pdata;
  96. struct gpio_desc *gpios[2];
  97. struct pinctrl *pctrl;
  98. #if defined(CONFIG_ARM_S3C24XX_CPUFREQ)
  99. struct notifier_block freq_transition;
  100. #endif
  101. struct regmap *sysreg;
  102. unsigned int sys_i2c_cfg;
  103. };
  104. static const struct platform_device_id s3c24xx_driver_ids[] = {
  105. {
  106. .name = "s3c2410-i2c",
  107. .driver_data = 0,
  108. }, {
  109. .name = "s3c2440-i2c",
  110. .driver_data = QUIRK_S3C2440,
  111. }, {
  112. .name = "s3c2440-hdmiphy-i2c",
  113. .driver_data = QUIRK_S3C2440 | QUIRK_HDMIPHY | QUIRK_NO_GPIO,
  114. }, { },
  115. };
  116. MODULE_DEVICE_TABLE(platform, s3c24xx_driver_ids);
  117. static int i2c_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat);
  118. #ifdef CONFIG_OF
  119. static const struct of_device_id s3c24xx_i2c_match[] = {
  120. { .compatible = "samsung,s3c2410-i2c", .data = (void *)0 },
  121. { .compatible = "samsung,s3c2440-i2c", .data = (void *)QUIRK_S3C2440 },
  122. { .compatible = "samsung,s3c2440-hdmiphy-i2c",
  123. .data = (void *)(QUIRK_S3C2440 | QUIRK_HDMIPHY | QUIRK_NO_GPIO) },
  124. { .compatible = "samsung,exynos5-sata-phy-i2c",
  125. .data = (void *)(QUIRK_S3C2440 | QUIRK_POLL | QUIRK_NO_GPIO) },
  126. {},
  127. };
  128. MODULE_DEVICE_TABLE(of, s3c24xx_i2c_match);
  129. #endif
  130. /*
  131. * Get controller type either from device tree or platform device variant.
  132. */
  133. static inline kernel_ulong_t s3c24xx_get_device_quirks(struct platform_device *pdev)
  134. {
  135. if (pdev->dev.of_node)
  136. return (kernel_ulong_t)of_device_get_match_data(&pdev->dev);
  137. return platform_get_device_id(pdev)->driver_data;
  138. }
  139. /*
  140. * Complete the message and wake up the caller, using the given return code,
  141. * or zero to mean ok.
  142. */
  143. static inline void s3c24xx_i2c_master_complete(struct s3c24xx_i2c *i2c, int ret)
  144. {
  145. dev_dbg(i2c->dev, "master_complete %d\n", ret);
  146. i2c->msg_ptr = 0;
  147. i2c->msg = NULL;
  148. i2c->msg_idx++;
  149. i2c->msg_num = 0;
  150. if (ret)
  151. i2c->msg_idx = ret;
  152. if (!(i2c->quirks & QUIRK_POLL))
  153. wake_up(&i2c->wait);
  154. }
  155. static inline void s3c24xx_i2c_disable_ack(struct s3c24xx_i2c *i2c)
  156. {
  157. unsigned long tmp;
  158. tmp = readl(i2c->regs + S3C2410_IICCON);
  159. writel(tmp & ~S3C2410_IICCON_ACKEN, i2c->regs + S3C2410_IICCON);
  160. }
  161. static inline void s3c24xx_i2c_enable_ack(struct s3c24xx_i2c *i2c)
  162. {
  163. unsigned long tmp;
  164. tmp = readl(i2c->regs + S3C2410_IICCON);
  165. writel(tmp | S3C2410_IICCON_ACKEN, i2c->regs + S3C2410_IICCON);
  166. }
  167. /* irq enable/disable functions */
  168. static inline void s3c24xx_i2c_disable_irq(struct s3c24xx_i2c *i2c)
  169. {
  170. unsigned long tmp;
  171. tmp = readl(i2c->regs + S3C2410_IICCON);
  172. writel(tmp & ~S3C2410_IICCON_IRQEN, i2c->regs + S3C2410_IICCON);
  173. }
  174. static inline void s3c24xx_i2c_enable_irq(struct s3c24xx_i2c *i2c)
  175. {
  176. unsigned long tmp;
  177. tmp = readl(i2c->regs + S3C2410_IICCON);
  178. writel(tmp | S3C2410_IICCON_IRQEN, i2c->regs + S3C2410_IICCON);
  179. }
  180. static bool is_ack(struct s3c24xx_i2c *i2c)
  181. {
  182. int tries;
  183. for (tries = 50; tries; --tries) {
  184. if (readl(i2c->regs + S3C2410_IICCON)
  185. & S3C2410_IICCON_IRQPEND) {
  186. if (!(readl(i2c->regs + S3C2410_IICSTAT)
  187. & S3C2410_IICSTAT_LASTBIT))
  188. return true;
  189. }
  190. usleep_range(1000, 2000);
  191. }
  192. dev_err(i2c->dev, "ack was not received\n");
  193. return false;
  194. }
  195. /*
  196. * put the start of a message onto the bus
  197. */
  198. static void s3c24xx_i2c_message_start(struct s3c24xx_i2c *i2c,
  199. struct i2c_msg *msg)
  200. {
  201. unsigned int addr = (msg->addr & 0x7f) << 1;
  202. unsigned long stat;
  203. unsigned long iiccon;
  204. stat = 0;
  205. stat |= S3C2410_IICSTAT_TXRXEN;
  206. if (msg->flags & I2C_M_RD) {
  207. stat |= S3C2410_IICSTAT_MASTER_RX;
  208. addr |= 1;
  209. } else
  210. stat |= S3C2410_IICSTAT_MASTER_TX;
  211. if (msg->flags & I2C_M_REV_DIR_ADDR)
  212. addr ^= 1;
  213. /* todo - check for whether ack wanted or not */
  214. s3c24xx_i2c_enable_ack(i2c);
  215. iiccon = readl(i2c->regs + S3C2410_IICCON);
  216. writel(stat, i2c->regs + S3C2410_IICSTAT);
  217. dev_dbg(i2c->dev, "START: %08lx to IICSTAT, %02x to DS\n", stat, addr);
  218. writeb(addr, i2c->regs + S3C2410_IICDS);
  219. /*
  220. * delay here to ensure the data byte has gotten onto the bus
  221. * before the transaction is started
  222. */
  223. ndelay(i2c->tx_setup);
  224. dev_dbg(i2c->dev, "iiccon, %08lx\n", iiccon);
  225. writel(iiccon, i2c->regs + S3C2410_IICCON);
  226. stat |= S3C2410_IICSTAT_START;
  227. writel(stat, i2c->regs + S3C2410_IICSTAT);
  228. if (i2c->quirks & QUIRK_POLL) {
  229. while ((i2c->msg_num != 0) && is_ack(i2c)) {
  230. i2c_s3c_irq_nextbyte(i2c, stat);
  231. stat = readl(i2c->regs + S3C2410_IICSTAT);
  232. if (stat & S3C2410_IICSTAT_ARBITR)
  233. dev_err(i2c->dev, "deal with arbitration loss\n");
  234. }
  235. }
  236. }
  237. static inline void s3c24xx_i2c_stop(struct s3c24xx_i2c *i2c, int ret)
  238. {
  239. unsigned long iicstat = readl(i2c->regs + S3C2410_IICSTAT);
  240. dev_dbg(i2c->dev, "STOP\n");
  241. /*
  242. * The datasheet says that the STOP sequence should be:
  243. * 1) I2CSTAT.5 = 0 - Clear BUSY (or 'generate STOP')
  244. * 2) I2CCON.4 = 0 - Clear IRQPEND
  245. * 3) Wait until the stop condition takes effect.
  246. * 4*) I2CSTAT.4 = 0 - Clear TXRXEN
  247. *
  248. * Where, step "4*" is only for buses with the "HDMIPHY" quirk.
  249. *
  250. * However, after much experimentation, it appears that:
  251. * a) normal buses automatically clear BUSY and transition from
  252. * Master->Slave when they complete generating a STOP condition.
  253. * Therefore, step (3) can be done in doxfer() by polling I2CCON.4
  254. * after starting the STOP generation here.
  255. * b) HDMIPHY bus does neither, so there is no way to do step 3.
  256. * There is no indication when this bus has finished generating
  257. * STOP.
  258. *
  259. * In fact, we have found that as soon as the IRQPEND bit is cleared in
  260. * step 2, the HDMIPHY bus generates the STOP condition, and then
  261. * immediately starts transferring another data byte, even though the
  262. * bus is supposedly stopped. This is presumably because the bus is
  263. * still in "Master" mode, and its BUSY bit is still set.
  264. *
  265. * To avoid these extra post-STOP transactions on HDMI phy devices, we
  266. * just disable Serial Output on the bus (I2CSTAT.4 = 0) directly,
  267. * instead of first generating a proper STOP condition. This should
  268. * float SDA & SCK terminating the transfer. Subsequent transfers
  269. * start with a proper START condition, and proceed normally.
  270. *
  271. * The HDMIPHY bus is an internal bus that always has exactly two
  272. * devices, the host as Master and the HDMIPHY device as the slave.
  273. * Skipping the STOP condition has been tested on this bus and works.
  274. */
  275. if (i2c->quirks & QUIRK_HDMIPHY) {
  276. /* Stop driving the I2C pins */
  277. iicstat &= ~S3C2410_IICSTAT_TXRXEN;
  278. } else {
  279. /* stop the transfer */
  280. iicstat &= ~S3C2410_IICSTAT_START;
  281. }
  282. writel(iicstat, i2c->regs + S3C2410_IICSTAT);
  283. i2c->state = STATE_STOP;
  284. s3c24xx_i2c_master_complete(i2c, ret);
  285. s3c24xx_i2c_disable_irq(i2c);
  286. }
  287. /*
  288. * helper functions to determine the current state in the set of
  289. * messages we are sending
  290. */
  291. /*
  292. * returns TRUE if the current message is the last in the set
  293. */
  294. static inline int is_lastmsg(struct s3c24xx_i2c *i2c)
  295. {
  296. return i2c->msg_idx >= (i2c->msg_num - 1);
  297. }
  298. /*
  299. * returns TRUE if we this is the last byte in the current message
  300. */
  301. static inline int is_msglast(struct s3c24xx_i2c *i2c)
  302. {
  303. /*
  304. * msg->len is always 1 for the first byte of smbus block read.
  305. * Actual length will be read from slave. More bytes will be
  306. * read according to the length then.
  307. */
  308. if (i2c->msg->flags & I2C_M_RECV_LEN && i2c->msg->len == 1)
  309. return 0;
  310. return i2c->msg_ptr == i2c->msg->len-1;
  311. }
  312. /*
  313. * returns TRUE if we reached the end of the current message
  314. */
  315. static inline int is_msgend(struct s3c24xx_i2c *i2c)
  316. {
  317. return i2c->msg_ptr >= i2c->msg->len;
  318. }
  319. /*
  320. * process an interrupt and work out what to do
  321. */
  322. static int i2c_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat)
  323. {
  324. unsigned long tmp;
  325. unsigned char byte;
  326. int ret = 0;
  327. switch (i2c->state) {
  328. case STATE_IDLE:
  329. dev_err(i2c->dev, "%s: called in STATE_IDLE\n", __func__);
  330. goto out;
  331. case STATE_STOP:
  332. dev_err(i2c->dev, "%s: called in STATE_STOP\n", __func__);
  333. s3c24xx_i2c_disable_irq(i2c);
  334. goto out_ack;
  335. case STATE_START:
  336. /*
  337. * last thing we did was send a start condition on the
  338. * bus, or started a new i2c message
  339. */
  340. if (iicstat & S3C2410_IICSTAT_LASTBIT &&
  341. !(i2c->msg->flags & I2C_M_IGNORE_NAK)) {
  342. /* ack was not received... */
  343. dev_dbg(i2c->dev, "ack was not received\n");
  344. s3c24xx_i2c_stop(i2c, -ENXIO);
  345. goto out_ack;
  346. }
  347. if (i2c->msg->flags & I2C_M_RD)
  348. i2c->state = STATE_READ;
  349. else
  350. i2c->state = STATE_WRITE;
  351. /*
  352. * Terminate the transfer if there is nothing to do
  353. * as this is used by the i2c probe to find devices.
  354. */
  355. if (is_lastmsg(i2c) && i2c->msg->len == 0) {
  356. s3c24xx_i2c_stop(i2c, 0);
  357. goto out_ack;
  358. }
  359. if (i2c->state == STATE_READ)
  360. goto prepare_read;
  361. /*
  362. * fall through to the write state, as we will need to
  363. * send a byte as well
  364. */
  365. fallthrough;
  366. case STATE_WRITE:
  367. /*
  368. * we are writing data to the device... check for the
  369. * end of the message, and if so, work out what to do
  370. */
  371. if (!(i2c->msg->flags & I2C_M_IGNORE_NAK)) {
  372. if (iicstat & S3C2410_IICSTAT_LASTBIT) {
  373. dev_dbg(i2c->dev, "WRITE: No Ack\n");
  374. s3c24xx_i2c_stop(i2c, -ECONNREFUSED);
  375. goto out_ack;
  376. }
  377. }
  378. retry_write:
  379. if (!is_msgend(i2c)) {
  380. byte = i2c->msg->buf[i2c->msg_ptr++];
  381. writeb(byte, i2c->regs + S3C2410_IICDS);
  382. /*
  383. * delay after writing the byte to allow the
  384. * data setup time on the bus, as writing the
  385. * data to the register causes the first bit
  386. * to appear on SDA, and SCL will change as
  387. * soon as the interrupt is acknowledged
  388. */
  389. ndelay(i2c->tx_setup);
  390. } else if (!is_lastmsg(i2c)) {
  391. /* we need to go to the next i2c message */
  392. dev_dbg(i2c->dev, "WRITE: Next Message\n");
  393. i2c->msg_ptr = 0;
  394. i2c->msg_idx++;
  395. i2c->msg++;
  396. /* check to see if we need to do another message */
  397. if (i2c->msg->flags & I2C_M_NOSTART) {
  398. if (i2c->msg->flags & I2C_M_RD) {
  399. /*
  400. * cannot do this, the controller
  401. * forces us to send a new START
  402. * when we change direction
  403. */
  404. dev_dbg(i2c->dev,
  405. "missing START before write->read\n");
  406. s3c24xx_i2c_stop(i2c, -EINVAL);
  407. break;
  408. }
  409. goto retry_write;
  410. } else {
  411. /* send the new start */
  412. s3c24xx_i2c_message_start(i2c, i2c->msg);
  413. i2c->state = STATE_START;
  414. }
  415. } else {
  416. /* send stop */
  417. s3c24xx_i2c_stop(i2c, 0);
  418. }
  419. break;
  420. case STATE_READ:
  421. /*
  422. * we have a byte of data in the data register, do
  423. * something with it, and then work out whether we are
  424. * going to do any more read/write
  425. */
  426. byte = readb(i2c->regs + S3C2410_IICDS);
  427. i2c->msg->buf[i2c->msg_ptr++] = byte;
  428. /* Add actual length to read for smbus block read */
  429. if (i2c->msg->flags & I2C_M_RECV_LEN && i2c->msg->len == 1)
  430. i2c->msg->len += byte;
  431. prepare_read:
  432. if (is_msglast(i2c)) {
  433. /* last byte of buffer */
  434. if (is_lastmsg(i2c))
  435. s3c24xx_i2c_disable_ack(i2c);
  436. } else if (is_msgend(i2c)) {
  437. /*
  438. * ok, we've read the entire buffer, see if there
  439. * is anything else we need to do
  440. */
  441. if (is_lastmsg(i2c)) {
  442. /* last message, send stop and complete */
  443. dev_dbg(i2c->dev, "READ: Send Stop\n");
  444. s3c24xx_i2c_stop(i2c, 0);
  445. } else {
  446. /* go to the next transfer */
  447. dev_dbg(i2c->dev, "READ: Next Transfer\n");
  448. i2c->msg_ptr = 0;
  449. i2c->msg_idx++;
  450. i2c->msg++;
  451. }
  452. }
  453. break;
  454. }
  455. /* acknowlegde the IRQ and get back on with the work */
  456. out_ack:
  457. tmp = readl(i2c->regs + S3C2410_IICCON);
  458. tmp &= ~S3C2410_IICCON_IRQPEND;
  459. writel(tmp, i2c->regs + S3C2410_IICCON);
  460. out:
  461. return ret;
  462. }
  463. /*
  464. * top level IRQ servicing routine
  465. */
  466. static irqreturn_t s3c24xx_i2c_irq(int irqno, void *dev_id)
  467. {
  468. struct s3c24xx_i2c *i2c = dev_id;
  469. unsigned long status;
  470. unsigned long tmp;
  471. status = readl(i2c->regs + S3C2410_IICSTAT);
  472. if (status & S3C2410_IICSTAT_ARBITR) {
  473. /* deal with arbitration loss */
  474. dev_err(i2c->dev, "deal with arbitration loss\n");
  475. }
  476. if (i2c->state == STATE_IDLE) {
  477. dev_dbg(i2c->dev, "IRQ: error i2c->state == IDLE\n");
  478. tmp = readl(i2c->regs + S3C2410_IICCON);
  479. tmp &= ~S3C2410_IICCON_IRQPEND;
  480. writel(tmp, i2c->regs + S3C2410_IICCON);
  481. goto out;
  482. }
  483. /*
  484. * pretty much this leaves us with the fact that we've
  485. * transmitted or received whatever byte we last sent
  486. */
  487. i2c_s3c_irq_nextbyte(i2c, status);
  488. out:
  489. return IRQ_HANDLED;
  490. }
  491. /*
  492. * Disable the bus so that we won't get any interrupts from now on, or try
  493. * to drive any lines. This is the default state when we don't have
  494. * anything to send/receive.
  495. *
  496. * If there is an event on the bus, or we have a pre-existing event at
  497. * kernel boot time, we may not notice the event and the I2C controller
  498. * will lock the bus with the I2C clock line low indefinitely.
  499. */
  500. static inline void s3c24xx_i2c_disable_bus(struct s3c24xx_i2c *i2c)
  501. {
  502. unsigned long tmp;
  503. /* Stop driving the I2C pins */
  504. tmp = readl(i2c->regs + S3C2410_IICSTAT);
  505. tmp &= ~S3C2410_IICSTAT_TXRXEN;
  506. writel(tmp, i2c->regs + S3C2410_IICSTAT);
  507. /* We don't expect any interrupts now, and don't want send acks */
  508. tmp = readl(i2c->regs + S3C2410_IICCON);
  509. tmp &= ~(S3C2410_IICCON_IRQEN | S3C2410_IICCON_IRQPEND |
  510. S3C2410_IICCON_ACKEN);
  511. writel(tmp, i2c->regs + S3C2410_IICCON);
  512. }
  513. /*
  514. * get the i2c bus for a master transaction
  515. */
  516. static int s3c24xx_i2c_set_master(struct s3c24xx_i2c *i2c)
  517. {
  518. unsigned long iicstat;
  519. int timeout = 400;
  520. while (timeout-- > 0) {
  521. iicstat = readl(i2c->regs + S3C2410_IICSTAT);
  522. if (!(iicstat & S3C2410_IICSTAT_BUSBUSY))
  523. return 0;
  524. msleep(1);
  525. }
  526. return -ETIMEDOUT;
  527. }
  528. /*
  529. * wait for the i2c bus to become idle.
  530. */
  531. static void s3c24xx_i2c_wait_idle(struct s3c24xx_i2c *i2c)
  532. {
  533. unsigned long iicstat;
  534. ktime_t start, now;
  535. unsigned long delay;
  536. int spins;
  537. /* ensure the stop has been through the bus */
  538. dev_dbg(i2c->dev, "waiting for bus idle\n");
  539. start = now = ktime_get();
  540. /*
  541. * Most of the time, the bus is already idle within a few usec of the
  542. * end of a transaction. However, really slow i2c devices can stretch
  543. * the clock, delaying STOP generation.
  544. *
  545. * On slower SoCs this typically happens within a very small number of
  546. * instructions so busy wait briefly to avoid scheduling overhead.
  547. */
  548. spins = 3;
  549. iicstat = readl(i2c->regs + S3C2410_IICSTAT);
  550. while ((iicstat & S3C2410_IICSTAT_START) && --spins) {
  551. cpu_relax();
  552. iicstat = readl(i2c->regs + S3C2410_IICSTAT);
  553. }
  554. /*
  555. * If we do get an appreciable delay as a compromise between idle
  556. * detection latency for the normal, fast case, and system load in the
  557. * slow device case, use an exponential back off in the polling loop,
  558. * up to 1/10th of the total timeout, then continue to poll at a
  559. * constant rate up to the timeout.
  560. */
  561. delay = 1;
  562. while ((iicstat & S3C2410_IICSTAT_START) &&
  563. ktime_us_delta(now, start) < S3C2410_IDLE_TIMEOUT) {
  564. usleep_range(delay, 2 * delay);
  565. if (delay < S3C2410_IDLE_TIMEOUT / 10)
  566. delay <<= 1;
  567. now = ktime_get();
  568. iicstat = readl(i2c->regs + S3C2410_IICSTAT);
  569. }
  570. if (iicstat & S3C2410_IICSTAT_START)
  571. dev_warn(i2c->dev, "timeout waiting for bus idle\n");
  572. }
  573. /*
  574. * this starts an i2c transfer
  575. */
  576. static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c,
  577. struct i2c_msg *msgs, int num)
  578. {
  579. unsigned long timeout;
  580. int ret;
  581. ret = s3c24xx_i2c_set_master(i2c);
  582. if (ret != 0) {
  583. dev_err(i2c->dev, "cannot get bus (error %d)\n", ret);
  584. ret = -EAGAIN;
  585. goto out;
  586. }
  587. i2c->msg = msgs;
  588. i2c->msg_num = num;
  589. i2c->msg_ptr = 0;
  590. i2c->msg_idx = 0;
  591. i2c->state = STATE_START;
  592. s3c24xx_i2c_enable_irq(i2c);
  593. s3c24xx_i2c_message_start(i2c, msgs);
  594. if (i2c->quirks & QUIRK_POLL) {
  595. ret = i2c->msg_idx;
  596. if (ret != num)
  597. dev_dbg(i2c->dev, "incomplete xfer (%d)\n", ret);
  598. goto out;
  599. }
  600. timeout = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5);
  601. ret = i2c->msg_idx;
  602. /*
  603. * Having these next two as dev_err() makes life very
  604. * noisy when doing an i2cdetect
  605. */
  606. if (timeout == 0)
  607. dev_dbg(i2c->dev, "timeout\n");
  608. else if (ret != num)
  609. dev_dbg(i2c->dev, "incomplete xfer (%d)\n", ret);
  610. /* For QUIRK_HDMIPHY, bus is already disabled */
  611. if (i2c->quirks & QUIRK_HDMIPHY)
  612. goto out;
  613. s3c24xx_i2c_wait_idle(i2c);
  614. s3c24xx_i2c_disable_bus(i2c);
  615. out:
  616. i2c->state = STATE_IDLE;
  617. return ret;
  618. }
  619. /*
  620. * first port of call from the i2c bus code when an message needs
  621. * transferring across the i2c bus.
  622. */
  623. static int s3c24xx_i2c_xfer(struct i2c_adapter *adap,
  624. struct i2c_msg *msgs, int num)
  625. {
  626. struct s3c24xx_i2c *i2c = (struct s3c24xx_i2c *)adap->algo_data;
  627. int retry;
  628. int ret;
  629. ret = clk_enable(i2c->clk);
  630. if (ret)
  631. return ret;
  632. for (retry = 0; retry < adap->retries; retry++) {
  633. ret = s3c24xx_i2c_doxfer(i2c, msgs, num);
  634. if (ret != -EAGAIN) {
  635. clk_disable(i2c->clk);
  636. return ret;
  637. }
  638. dev_dbg(i2c->dev, "Retrying transmission (%d)\n", retry);
  639. udelay(100);
  640. }
  641. clk_disable(i2c->clk);
  642. return -EREMOTEIO;
  643. }
  644. /* declare our i2c functionality */
  645. static u32 s3c24xx_i2c_func(struct i2c_adapter *adap)
  646. {
  647. return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL_ALL | I2C_FUNC_NOSTART |
  648. I2C_FUNC_PROTOCOL_MANGLING;
  649. }
  650. /* i2c bus registration info */
  651. static const struct i2c_algorithm s3c24xx_i2c_algorithm = {
  652. .master_xfer = s3c24xx_i2c_xfer,
  653. .functionality = s3c24xx_i2c_func,
  654. };
  655. /*
  656. * return the divisor settings for a given frequency
  657. */
  658. static int s3c24xx_i2c_calcdivisor(unsigned long clkin, unsigned int wanted,
  659. unsigned int *div1, unsigned int *divs)
  660. {
  661. unsigned int calc_divs = clkin / wanted;
  662. unsigned int calc_div1;
  663. if (calc_divs > (16*16))
  664. calc_div1 = 512;
  665. else
  666. calc_div1 = 16;
  667. calc_divs += calc_div1-1;
  668. calc_divs /= calc_div1;
  669. if (calc_divs == 0)
  670. calc_divs = 1;
  671. if (calc_divs > 17)
  672. calc_divs = 17;
  673. *divs = calc_divs;
  674. *div1 = calc_div1;
  675. return clkin / (calc_divs * calc_div1);
  676. }
  677. /*
  678. * work out a divisor for the user requested frequency setting,
  679. * either by the requested frequency, or scanning the acceptable
  680. * range of frequencies until something is found
  681. */
  682. static int s3c24xx_i2c_clockrate(struct s3c24xx_i2c *i2c, unsigned int *got)
  683. {
  684. struct s3c2410_platform_i2c *pdata = i2c->pdata;
  685. unsigned long clkin = clk_get_rate(i2c->clk);
  686. unsigned int divs, div1;
  687. unsigned long target_frequency;
  688. u32 iiccon;
  689. int freq;
  690. i2c->clkrate = clkin;
  691. clkin /= 1000; /* clkin now in KHz */
  692. dev_dbg(i2c->dev, "pdata desired frequency %lu\n", pdata->frequency);
  693. target_frequency = pdata->frequency ?: I2C_MAX_STANDARD_MODE_FREQ;
  694. target_frequency /= 1000; /* Target frequency now in KHz */
  695. freq = s3c24xx_i2c_calcdivisor(clkin, target_frequency, &div1, &divs);
  696. if (freq > target_frequency) {
  697. dev_err(i2c->dev,
  698. "Unable to achieve desired frequency %luKHz." \
  699. " Lowest achievable %dKHz\n", target_frequency, freq);
  700. return -EINVAL;
  701. }
  702. *got = freq;
  703. iiccon = readl(i2c->regs + S3C2410_IICCON);
  704. iiccon &= ~(S3C2410_IICCON_SCALEMASK | S3C2410_IICCON_TXDIV_512);
  705. iiccon |= (divs-1);
  706. if (div1 == 512)
  707. iiccon |= S3C2410_IICCON_TXDIV_512;
  708. if (i2c->quirks & QUIRK_POLL)
  709. iiccon |= S3C2410_IICCON_SCALE(2);
  710. writel(iiccon, i2c->regs + S3C2410_IICCON);
  711. if (i2c->quirks & QUIRK_S3C2440) {
  712. unsigned long sda_delay;
  713. if (pdata->sda_delay) {
  714. sda_delay = clkin * pdata->sda_delay;
  715. sda_delay = DIV_ROUND_UP(sda_delay, 1000000);
  716. sda_delay = DIV_ROUND_UP(sda_delay, 5);
  717. if (sda_delay > 3)
  718. sda_delay = 3;
  719. sda_delay |= S3C2410_IICLC_FILTER_ON;
  720. } else
  721. sda_delay = 0;
  722. dev_dbg(i2c->dev, "IICLC=%08lx\n", sda_delay);
  723. writel(sda_delay, i2c->regs + S3C2440_IICLC);
  724. }
  725. return 0;
  726. }
  727. #if defined(CONFIG_ARM_S3C24XX_CPUFREQ)
  728. #define freq_to_i2c(_n) container_of(_n, struct s3c24xx_i2c, freq_transition)
  729. static int s3c24xx_i2c_cpufreq_transition(struct notifier_block *nb,
  730. unsigned long val, void *data)
  731. {
  732. struct s3c24xx_i2c *i2c = freq_to_i2c(nb);
  733. unsigned int got;
  734. int delta_f;
  735. int ret;
  736. delta_f = clk_get_rate(i2c->clk) - i2c->clkrate;
  737. /* if we're post-change and the input clock has slowed down
  738. * or at pre-change and the clock is about to speed up, then
  739. * adjust our clock rate. <0 is slow, >0 speedup.
  740. */
  741. if ((val == CPUFREQ_POSTCHANGE && delta_f < 0) ||
  742. (val == CPUFREQ_PRECHANGE && delta_f > 0)) {
  743. i2c_lock_bus(&i2c->adap, I2C_LOCK_ROOT_ADAPTER);
  744. ret = s3c24xx_i2c_clockrate(i2c, &got);
  745. i2c_unlock_bus(&i2c->adap, I2C_LOCK_ROOT_ADAPTER);
  746. if (ret < 0)
  747. dev_err(i2c->dev, "cannot find frequency (%d)\n", ret);
  748. else
  749. dev_info(i2c->dev, "setting freq %d\n", got);
  750. }
  751. return 0;
  752. }
  753. static inline int s3c24xx_i2c_register_cpufreq(struct s3c24xx_i2c *i2c)
  754. {
  755. i2c->freq_transition.notifier_call = s3c24xx_i2c_cpufreq_transition;
  756. return cpufreq_register_notifier(&i2c->freq_transition,
  757. CPUFREQ_TRANSITION_NOTIFIER);
  758. }
  759. static inline void s3c24xx_i2c_deregister_cpufreq(struct s3c24xx_i2c *i2c)
  760. {
  761. cpufreq_unregister_notifier(&i2c->freq_transition,
  762. CPUFREQ_TRANSITION_NOTIFIER);
  763. }
  764. #else
  765. static inline int s3c24xx_i2c_register_cpufreq(struct s3c24xx_i2c *i2c)
  766. {
  767. return 0;
  768. }
  769. static inline void s3c24xx_i2c_deregister_cpufreq(struct s3c24xx_i2c *i2c)
  770. {
  771. }
  772. #endif
  773. #ifdef CONFIG_OF
  774. static int s3c24xx_i2c_parse_dt_gpio(struct s3c24xx_i2c *i2c)
  775. {
  776. int i;
  777. if (i2c->quirks & QUIRK_NO_GPIO)
  778. return 0;
  779. for (i = 0; i < 2; i++) {
  780. i2c->gpios[i] = devm_gpiod_get_index(i2c->dev, NULL,
  781. i, GPIOD_ASIS);
  782. if (IS_ERR(i2c->gpios[i])) {
  783. dev_err(i2c->dev, "i2c gpio invalid at index %d\n", i);
  784. return -EINVAL;
  785. }
  786. }
  787. return 0;
  788. }
  789. #else
  790. static int s3c24xx_i2c_parse_dt_gpio(struct s3c24xx_i2c *i2c)
  791. {
  792. return 0;
  793. }
  794. #endif
  795. /*
  796. * initialise the controller, set the IO lines and frequency
  797. */
  798. static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c)
  799. {
  800. struct s3c2410_platform_i2c *pdata;
  801. unsigned int freq;
  802. /* get the plafrom data */
  803. pdata = i2c->pdata;
  804. /* write slave address */
  805. writeb(pdata->slave_addr, i2c->regs + S3C2410_IICADD);
  806. dev_info(i2c->dev, "slave address 0x%02x\n", pdata->slave_addr);
  807. writel(0, i2c->regs + S3C2410_IICCON);
  808. writel(0, i2c->regs + S3C2410_IICSTAT);
  809. /* we need to work out the divisors for the clock... */
  810. if (s3c24xx_i2c_clockrate(i2c, &freq) != 0) {
  811. dev_err(i2c->dev, "cannot meet bus frequency required\n");
  812. return -EINVAL;
  813. }
  814. /* todo - check that the i2c lines aren't being dragged anywhere */
  815. dev_info(i2c->dev, "bus frequency set to %d KHz\n", freq);
  816. dev_dbg(i2c->dev, "S3C2410_IICCON=0x%02x\n",
  817. readl(i2c->regs + S3C2410_IICCON));
  818. return 0;
  819. }
  820. #ifdef CONFIG_OF
  821. /*
  822. * Parse the device tree node and retreive the platform data.
  823. */
  824. static void
  825. s3c24xx_i2c_parse_dt(struct device_node *np, struct s3c24xx_i2c *i2c)
  826. {
  827. struct s3c2410_platform_i2c *pdata = i2c->pdata;
  828. int id;
  829. if (!np)
  830. return;
  831. pdata->bus_num = -1; /* i2c bus number is dynamically assigned */
  832. of_property_read_u32(np, "samsung,i2c-sda-delay", &pdata->sda_delay);
  833. of_property_read_u32(np, "samsung,i2c-slave-addr", &pdata->slave_addr);
  834. of_property_read_u32(np, "samsung,i2c-max-bus-freq",
  835. (u32 *)&pdata->frequency);
  836. /*
  837. * Exynos5's legacy i2c controller and new high speed i2c
  838. * controller have muxed interrupt sources. By default the
  839. * interrupts for 4-channel HS-I2C controller are enabled.
  840. * If nodes for first four channels of legacy i2c controller
  841. * are available then re-configure the interrupts via the
  842. * system register.
  843. */
  844. id = of_alias_get_id(np, "i2c");
  845. i2c->sysreg = syscon_regmap_lookup_by_phandle(np,
  846. "samsung,sysreg-phandle");
  847. if (IS_ERR(i2c->sysreg))
  848. return;
  849. regmap_update_bits(i2c->sysreg, EXYNOS5_SYS_I2C_CFG, BIT(id), 0);
  850. }
  851. #else
  852. static void
  853. s3c24xx_i2c_parse_dt(struct device_node *np, struct s3c24xx_i2c *i2c) { }
  854. #endif
  855. static int s3c24xx_i2c_probe(struct platform_device *pdev)
  856. {
  857. struct s3c24xx_i2c *i2c;
  858. struct s3c2410_platform_i2c *pdata = NULL;
  859. struct resource *res;
  860. int ret;
  861. if (!pdev->dev.of_node) {
  862. pdata = dev_get_platdata(&pdev->dev);
  863. if (!pdata) {
  864. dev_err(&pdev->dev, "no platform data\n");
  865. return -EINVAL;
  866. }
  867. }
  868. i2c = devm_kzalloc(&pdev->dev, sizeof(struct s3c24xx_i2c), GFP_KERNEL);
  869. if (!i2c)
  870. return -ENOMEM;
  871. i2c->pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
  872. if (!i2c->pdata)
  873. return -ENOMEM;
  874. i2c->quirks = s3c24xx_get_device_quirks(pdev);
  875. i2c->sysreg = ERR_PTR(-ENOENT);
  876. if (pdata)
  877. memcpy(i2c->pdata, pdata, sizeof(*pdata));
  878. else
  879. s3c24xx_i2c_parse_dt(pdev->dev.of_node, i2c);
  880. strscpy(i2c->adap.name, "s3c2410-i2c", sizeof(i2c->adap.name));
  881. i2c->adap.owner = THIS_MODULE;
  882. i2c->adap.algo = &s3c24xx_i2c_algorithm;
  883. i2c->adap.retries = 2;
  884. i2c->adap.class = I2C_CLASS_DEPRECATED;
  885. i2c->tx_setup = 50;
  886. init_waitqueue_head(&i2c->wait);
  887. /* find the clock and enable it */
  888. i2c->dev = &pdev->dev;
  889. i2c->clk = devm_clk_get(&pdev->dev, "i2c");
  890. if (IS_ERR(i2c->clk)) {
  891. dev_err(&pdev->dev, "cannot get clock\n");
  892. return -ENOENT;
  893. }
  894. dev_dbg(&pdev->dev, "clock source %p\n", i2c->clk);
  895. /* map the registers */
  896. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  897. i2c->regs = devm_ioremap_resource(&pdev->dev, res);
  898. if (IS_ERR(i2c->regs))
  899. return PTR_ERR(i2c->regs);
  900. dev_dbg(&pdev->dev, "registers %p (%p)\n",
  901. i2c->regs, res);
  902. /* setup info block for the i2c core */
  903. i2c->adap.algo_data = i2c;
  904. i2c->adap.dev.parent = &pdev->dev;
  905. i2c->pctrl = devm_pinctrl_get_select_default(i2c->dev);
  906. /* inititalise the i2c gpio lines */
  907. if (i2c->pdata->cfg_gpio)
  908. i2c->pdata->cfg_gpio(to_platform_device(i2c->dev));
  909. else if (IS_ERR(i2c->pctrl) && s3c24xx_i2c_parse_dt_gpio(i2c))
  910. return -EINVAL;
  911. /* initialise the i2c controller */
  912. ret = clk_prepare_enable(i2c->clk);
  913. if (ret) {
  914. dev_err(&pdev->dev, "I2C clock enable failed\n");
  915. return ret;
  916. }
  917. ret = s3c24xx_i2c_init(i2c);
  918. clk_disable(i2c->clk);
  919. if (ret != 0) {
  920. dev_err(&pdev->dev, "I2C controller init failed\n");
  921. clk_unprepare(i2c->clk);
  922. return ret;
  923. }
  924. /*
  925. * find the IRQ for this unit (note, this relies on the init call to
  926. * ensure no current IRQs pending
  927. */
  928. if (!(i2c->quirks & QUIRK_POLL)) {
  929. i2c->irq = ret = platform_get_irq(pdev, 0);
  930. if (ret < 0) {
  931. dev_err(&pdev->dev, "cannot find IRQ\n");
  932. clk_unprepare(i2c->clk);
  933. return ret;
  934. }
  935. ret = devm_request_irq(&pdev->dev, i2c->irq, s3c24xx_i2c_irq,
  936. 0, dev_name(&pdev->dev), i2c);
  937. if (ret != 0) {
  938. dev_err(&pdev->dev, "cannot claim IRQ %d\n", i2c->irq);
  939. clk_unprepare(i2c->clk);
  940. return ret;
  941. }
  942. }
  943. ret = s3c24xx_i2c_register_cpufreq(i2c);
  944. if (ret < 0) {
  945. dev_err(&pdev->dev, "failed to register cpufreq notifier\n");
  946. clk_unprepare(i2c->clk);
  947. return ret;
  948. }
  949. /*
  950. * Note, previous versions of the driver used i2c_add_adapter()
  951. * to add the bus at any number. We now pass the bus number via
  952. * the platform data, so if unset it will now default to always
  953. * being bus 0.
  954. */
  955. i2c->adap.nr = i2c->pdata->bus_num;
  956. i2c->adap.dev.of_node = pdev->dev.of_node;
  957. platform_set_drvdata(pdev, i2c);
  958. pm_runtime_enable(&pdev->dev);
  959. ret = i2c_add_numbered_adapter(&i2c->adap);
  960. if (ret < 0) {
  961. pm_runtime_disable(&pdev->dev);
  962. s3c24xx_i2c_deregister_cpufreq(i2c);
  963. clk_unprepare(i2c->clk);
  964. return ret;
  965. }
  966. dev_info(&pdev->dev, "%s: S3C I2C adapter\n", dev_name(&i2c->adap.dev));
  967. return 0;
  968. }
  969. static int s3c24xx_i2c_remove(struct platform_device *pdev)
  970. {
  971. struct s3c24xx_i2c *i2c = platform_get_drvdata(pdev);
  972. clk_unprepare(i2c->clk);
  973. pm_runtime_disable(&pdev->dev);
  974. s3c24xx_i2c_deregister_cpufreq(i2c);
  975. i2c_del_adapter(&i2c->adap);
  976. return 0;
  977. }
  978. #ifdef CONFIG_PM_SLEEP
  979. static int s3c24xx_i2c_suspend_noirq(struct device *dev)
  980. {
  981. struct s3c24xx_i2c *i2c = dev_get_drvdata(dev);
  982. i2c_mark_adapter_suspended(&i2c->adap);
  983. if (!IS_ERR(i2c->sysreg))
  984. regmap_read(i2c->sysreg, EXYNOS5_SYS_I2C_CFG, &i2c->sys_i2c_cfg);
  985. return 0;
  986. }
  987. static int s3c24xx_i2c_resume_noirq(struct device *dev)
  988. {
  989. struct s3c24xx_i2c *i2c = dev_get_drvdata(dev);
  990. int ret;
  991. if (!IS_ERR(i2c->sysreg))
  992. regmap_write(i2c->sysreg, EXYNOS5_SYS_I2C_CFG, i2c->sys_i2c_cfg);
  993. ret = clk_enable(i2c->clk);
  994. if (ret)
  995. return ret;
  996. s3c24xx_i2c_init(i2c);
  997. clk_disable(i2c->clk);
  998. i2c_mark_adapter_resumed(&i2c->adap);
  999. return 0;
  1000. }
  1001. #endif
  1002. #ifdef CONFIG_PM
  1003. static const struct dev_pm_ops s3c24xx_i2c_dev_pm_ops = {
  1004. SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(s3c24xx_i2c_suspend_noirq,
  1005. s3c24xx_i2c_resume_noirq)
  1006. };
  1007. #define S3C24XX_DEV_PM_OPS (&s3c24xx_i2c_dev_pm_ops)
  1008. #else
  1009. #define S3C24XX_DEV_PM_OPS NULL
  1010. #endif
  1011. static struct platform_driver s3c24xx_i2c_driver = {
  1012. .probe = s3c24xx_i2c_probe,
  1013. .remove = s3c24xx_i2c_remove,
  1014. .id_table = s3c24xx_driver_ids,
  1015. .driver = {
  1016. .name = "s3c-i2c",
  1017. .pm = S3C24XX_DEV_PM_OPS,
  1018. .of_match_table = of_match_ptr(s3c24xx_i2c_match),
  1019. },
  1020. };
  1021. static int __init i2c_adap_s3c_init(void)
  1022. {
  1023. return platform_driver_register(&s3c24xx_i2c_driver);
  1024. }
  1025. subsys_initcall(i2c_adap_s3c_init);
  1026. static void __exit i2c_adap_s3c_exit(void)
  1027. {
  1028. platform_driver_unregister(&s3c24xx_i2c_driver);
  1029. }
  1030. module_exit(i2c_adap_s3c_exit);
  1031. MODULE_DESCRIPTION("S3C24XX I2C Bus driver");
  1032. MODULE_AUTHOR("Ben Dooks <[email protected]>");
  1033. MODULE_LICENSE("GPL");